@@ -19,7 +19,7 @@ public class Context: ContextRef {
1919 public var contextRef : LLVMContextRef { llvm }
2020
2121 /// Diagnostic handler type
22- public typealias DiagnosticHandler = @convention ( c) ( LLVMDiagnosticInfoRef , UnsafeMutableRawPointer ? ) -> Void
22+ public typealias DiagnosticHandler = @convention ( c) ( LLVMDiagnosticInfoRef ? , UnsafeMutableRawPointer ? ) -> Void
2323
2424 public typealias YieldCallback = @convention ( c) ( LLVMContextRef ? , UnsafeMutableRawPointer ? ) -> Void
2525
@@ -48,16 +48,12 @@ public class Context: ContextRef {
4848
4949 /// Get the diagnostic handler of current context.
5050 public var getDiagnosticHandler : DiagnosticHandler ? {
51- if let handler = LLVMContextGetDiagnosticHandler ( contextRef) {
52- return unsafeBitCast ( handler, to: DiagnosticHandler . self)
53- } else {
54- return nil
55- }
51+ LLVMContextGetDiagnosticHandler ( llvm)
5652 }
5753
5854 /// Set the diagnostic handler for current context.
59- public func setDiagnosticHandler( handler: LLVMDiagnosticHandler ? , diagnosticContext: UnsafeMutableRawPointer ? ) {
60- LLVMContextSetDiagnosticHandler ( contextRef , handler, diagnosticContext)
55+ public func setDiagnosticHandler( handler: DiagnosticHandler ? , diagnosticContext: UnsafeMutableRawPointer ? ) {
56+ LLVMContextSetDiagnosticHandler ( llvm , handler. self , diagnosticContext)
6157 }
6258
6359 /// Retrieve whether the given context is set to discard all value names.
@@ -100,14 +96,15 @@ public class Context: ContextRef {
10096
10197 /// Return a string representation of the DiagnosticInfo. Use
10298 /// LLVMDisposeMessage to free the string.
103- public func getDiagInfoDescription( diagnosticInfo: DiagnosticInfoRef ) -> String ? {
99+ public static func getDiagInfoDescription( diagnosticInfo: DiagnosticInfoRef ) -> String ? {
104100 guard let cString = LLVMGetDiagInfoDescription ( diagnosticInfo. diagnosticInfoRef) else { return nil }
101+ defer { LLVMDisposeMessage ( cString) }
105102 return String ( cString: cString)
106103 }
107104
108105 /// Return an enum LLVMDiagnosticSeverity.
109- public func getDiagInfoSeverity( diagnosticInfo: DiagnosticInfoRef ) -> LLVMDiagnosticSeverity {
110- LLVMGetDiagInfoSeverity ( diagnosticInfo. diagnosticInfoRef)
106+ public static func getDiagInfoSeverity( diagnosticInfo: DiagnosticInfoRef ) -> DiagnosticSeverity ? {
107+ DiagnosticSeverity ( from : LLVMGetDiagInfoSeverity ( diagnosticInfo. diagnosticInfoRef) )
111108 }
112109
113110 /// Get Metadata KindId by name in current Context.
@@ -118,7 +115,7 @@ public class Context: ContextRef {
118115 }
119116 }
120117
121- public func getMDKindID( name: String ) -> UInt32 {
118+ public static func getMDKindID( name: String ) -> UInt32 {
122119 name. withCString { cString in
123120 LLVMGetMDKindID ( cString, UInt32 ( name. utf8. count) )
124121 }
@@ -133,13 +130,14 @@ public class Context: ContextRef {
133130 ///
134131 /// NB: Attribute names and/or id are subject to change without
135132 /// going through the C API deprecation cycle.
136- public func getEnumAttributeKindForName( name: String ) -> UInt32 {
133+ public static func getEnumAttributeKindForName( name: String ) -> UInt32 {
137134 name. withCString { cString in
138135 LLVMGetEnumAttributeKindForName ( cString, name. utf8. count)
139136 }
140137 }
141138
142- public func getLastEnumAttributeKind( ) -> UInt32 {
139+ /// Get last enum attribute
140+ public static func getLastEnumAttributeKind( ) -> UInt32 {
143141 LLVMGetLastEnumAttributeKind ( )
144142 }
145143
@@ -154,12 +152,12 @@ public class Context: ContextRef {
154152 }
155153
156154 /// Get the unique id corresponding to the enum attribute passed as argument.
157- public func getEnumAttributeKind( attributeRef: AttributeRef ) -> UInt32 {
155+ public static func getEnumAttributeKind( attributeRef: AttributeRef ) -> UInt32 {
158156 LLVMGetEnumAttributeKind ( attributeRef. attributeRef)
159157 }
160158
161159 /// Get the enum attribute's value. 0 is returned if none exists.
162- public func getEnumAttributeValue( attributeRef: AttributeRef ) -> UInt64 {
160+ public static func getEnumAttributeValue( attributeRef: AttributeRef ) -> UInt64 {
163161 LLVMGetEnumAttributeValue ( attributeRef. attributeRef)
164162 }
165163
@@ -170,7 +168,7 @@ public class Context: ContextRef {
170168 }
171169
172170 /// Get the type attribute's value.
173- public func getTypeAttributeValue( attributeRef: AttributeRef ) -> TypeRef ? {
171+ public static func getTypeAttributeValue( attributeRef: AttributeRef ) -> TypeRef ? {
174172 guard let typeRef = LLVMGetTypeAttributeValue ( attributeRef. attributeRef) else { return nil }
175173 return Types ( llvm: typeRef)
176174 }
@@ -186,12 +184,8 @@ public class Context: ContextRef {
186184 return Attribute ( attributeRef: attributeRef)
187185 }
188186
189- //===============================
190- // ###############################
191- //===============================
192-
193187 /// Get the string attribute's kind.
194- public func getStringAttributeKind( attributeRef: AttributeRef , length: UInt32 ) -> String ? {
188+ public static func getStringAttributeKind( attributeRef: AttributeRef , length: UInt32 ) -> String ? {
195189 var mutLength = length
196190 guard let cString = withUnsafeMutablePointer ( to: & mutLength, { lengthPtr in
197191 LLVMGetStringAttributeKind ( attributeRef. attributeRef, lengthPtr)
@@ -200,7 +194,7 @@ public class Context: ContextRef {
200194 }
201195
202196 /// Get the string attribute's value.
203- public func getStringAttributeValue( attributeRef: AttributeRef , length: UInt32 ) -> String ? {
197+ public static func getStringAttributeValue( attributeRef: AttributeRef , length: UInt32 ) -> String ? {
204198 var mutLength = length
205199 guard let cString = withUnsafeMutablePointer ( to: & mutLength, { lengthPtr in
206200 LLVMGetStringAttributeValue ( attributeRef. attributeRef, lengthPtr)
@@ -209,17 +203,17 @@ public class Context: ContextRef {
209203 }
210204
211205 /// Check for the types of attributes.
212- public func isEnumAttribute( attributeRef: AttributeRef ) -> Bool {
206+ public static func isEnumAttribute( attributeRef: AttributeRef ) -> Bool {
213207 return LLVMIsEnumAttribute ( attributeRef. attributeRef) != 0
214208 }
215209
216210 /// Check for the types of attributes.
217- public func isStringAttribute( attributeRef: AttributeRef ) -> Bool {
211+ public static func isStringAttribute( attributeRef: AttributeRef ) -> Bool {
218212 return LLVMIsStringAttribute ( attributeRef. attributeRef) != 0
219213 }
220214
221215 /// Check for the types of attributes.
222- public func isTypeAttribute( attributeRef: AttributeRef ) -> Bool {
216+ public static func isTypeAttribute( attributeRef: AttributeRef ) -> Bool {
223217 return LLVMIsTypeAttribute ( attributeRef. attributeRef) != 0
224218 }
225219
0 commit comments