@@ -29,29 +29,62 @@ public class Decl: CustomStringConvertible, Hashable {
2929 // True if this declaration is imported from C/C++/ObjC.
3030 public var hasClangNode : Bool { bridged. hasClangNode ( ) }
3131
32- public var declContext : DeclContext { bridgedDecl. declContext }
32+ public var declContext : DeclContext {
33+ if let decl = parent {
34+ return decl as! DeclContext
35+ }
36+ return DeclContextObj ( bridged: bridged. getDeclContext ( ) )
37+ }
3338
34- var bridgedDecl : BridgedDecl { BridgedDecl ( raw: bridged. obj) }
39+ public var bridgedDecl : BridgedDecl { BridgedDecl ( raw: bridged. obj) }
3540
3641 public static func == ( lhs: Decl , rhs: Decl ) -> Bool { lhs === rhs }
3742
3843 public func hash( into hasher: inout Hasher ) {
3944 hasher. combine ( ObjectIdentifier ( self ) )
4045 }
46+
47+ public func setImplicit( ) { bridged. setImplicit ( ) }
48+ }
49+
50+ public protocol DeclContext {
51+ var bridgedDeclContext : BridgedDeclContext { get }
52+ }
53+
54+ extension DeclContext {
55+ public var astContext : ASTContext { bridgedDeclContext. astContext }
56+ }
57+
58+ fileprivate class DeclContextObj : DeclContext {
59+ public var bridgedDeclContext : BridgedDeclContext
60+ public init ( bridged: BridgedDeclContext ) { bridgedDeclContext = bridged }
61+ }
62+
63+ public protocol GenericContext : Decl , DeclContext { }
64+
65+ extension GenericContext {
66+ public func setGenericSignature( _ genericSignature: GenericSignature ) {
67+ bridged. GenericContext_setGenericSignature ( genericSignature. bridged)
68+ }
69+
70+ public var bridgedDeclContext : BridgedDeclContext { bridged. asGenericContext ( ) }
4171}
4272
4373public class ValueDecl : Decl {
4474 final public var nameLoc : SourceLoc ? { SourceLoc ( bridged: bridged. Value_getNameLoc ( ) ) }
4575 final public var userFacingName : StringRef { StringRef ( bridged: bridged. Value_getUserFacingName ( ) ) }
4676 final public var baseIdentifier : Identifier { bridged. Value_getBaseIdentifier ( ) }
4777 final public var isObjC : Bool { bridged. Value_isObjC ( ) }
78+ final public func setAccess( _ accessLevel : AccessLevel ) {
79+ bridged. ValueDecl_setAccess ( accessLevel)
80+ }
4881}
4982
5083public class TypeDecl : ValueDecl {
5184 final public var name : StringRef { StringRef ( bridged: bridged. Type_getName ( ) ) }
5285}
5386
54- public class GenericTypeDecl : TypeDecl {
87+ public class GenericTypeDecl : TypeDecl , GenericContext {
5588 final public var isGenericAtAnyLevel : Bool { bridged. GenericType_isGenericAtAnyLevel ( ) }
5689}
5790
@@ -65,10 +98,34 @@ public class NominalTypeDecl: GenericTypeDecl {
6598 public var declaredInterfaceType : Type {
6699 Type ( bridged: bridged. NominalType_getDeclaredInterfaceType ( ) )
67100 }
101+
102+ public func add( member: Decl ) {
103+ bridged. NominalTypeDecl_addMember ( member. bridged)
104+ }
68105}
69106
70107final public class EnumDecl : NominalTypeDecl {
71108 public var hasRawType : Bool { bridged. Enum_hasRawType ( ) }
109+
110+ public static func create(
111+ _ astContext: ASTContext , declContext: DeclContext , enumKeywordLoc: SourceLoc ? , name: String ,
112+ nameLoc: SourceLoc ? , genericParamList: GenericParamList ? , inheritedTypes: [ Type ] ,
113+ genericWhereClause: TrailingWhereClause ? , braceRange: SourceRange
114+ ) -> EnumDecl {
115+ name. withCString { strPtr in
116+ inheritedTypes. withBridgedArrayRef { types in
117+ ASTBridging . BridgedEnumDecl. createParsed (
118+ astContext, declContext: declContext. bridgedDeclContext,
119+ enumKeywordLoc: enumKeywordLoc. bridgedLocation,
120+ name: astContext. getIdentifier ( BridgedStringRef ( data: strPtr, count: name. count) ) ,
121+ nameLoc: nameLoc. bridgedLocation,
122+ genericParamList: genericParamList. bridged,
123+ inheritedTypes: types,
124+ genericWhereClause: genericWhereClause. bridged,
125+ braceRange: braceRange. bridged)
126+ }
127+ } . asDecl. declObj. getAs ( EnumDecl . self)
128+ }
72129}
73130
74131final public class StructDecl : NominalTypeDecl {
@@ -93,7 +150,19 @@ final public class OpaqueTypeDecl: GenericTypeDecl {}
93150
94151final public class TypeAliasDecl : GenericTypeDecl { }
95152
96- final public class GenericTypeParamDecl : TypeDecl { }
153+ final public class GenericTypeParamDecl : TypeDecl {
154+ public static func create(
155+ declContext: DeclContext ,
156+ name: Identifier ,
157+ depth: Int ,
158+ index: Int ,
159+ paramKind: GenericTypeParameterKind ) -> GenericTypeParamDecl {
160+ ASTBridging . BridgedGenericTypeParamDecl. createImplicit (
161+ declContext: declContext. bridgedDeclContext,
162+ name: name, depth: depth, index: index,
163+ paramKind: paramKind) . asDecl. declObj. getAs ( GenericTypeParamDecl . self)
164+ }
165+ }
97166
98167final public class AssociatedTypeDecl : TypeDecl { }
99168
@@ -105,7 +174,15 @@ public class AbstractStorageDecl: ValueDecl {
105174
106175public class VarDecl : AbstractStorageDecl { }
107176
108- final public class ParamDecl : VarDecl { }
177+ final public class ParamDecl : VarDecl {
178+ public func cloneWithoutType( ) -> ParamDecl {
179+ BridgedParamDecl ( raw: bridged. obj) . cloneWithoutType ( ) . asDecl. declObj. getAs ( ParamDecl . self)
180+ }
181+
182+ public func setInterfaceType( type: Type ) {
183+ BridgedParamDecl ( raw: bridged. obj) . setInterfaceType ( type. bridged)
184+ }
185+ }
109186
110187final public class SubscriptDecl : AbstractStorageDecl { }
111188
@@ -127,8 +204,22 @@ final public class MacroDecl: ValueDecl {}
127204
128205final public class EnumElementDecl : ValueDecl {
129206 public var hasAssociatedValues : Bool { bridged. EnumElementDecl_hasAssociatedValues ( ) }
130- public var parameterList : ParameterList { bridged. EnumElementDecl_getParameterList ( ) }
207+ public var parameterList : ParameterList { ParameterList ( bridged: bridged . EnumElementDecl_getParameterList ( ) ) }
131208 public var name : StringRef { StringRef ( bridged: bridged. EnumElementDecl_getNameStr ( ) ) }
209+
210+ public static func create(
211+ _ astContext: ASTContext , declContext: DeclContext ,
212+ name: Identifier , nameLoc: SourceLoc ? ,
213+ parameterList: ParameterList ? ,
214+ equalsLoc: SourceLoc ? , rawValue: Expr ?
215+ ) -> EnumElementDecl {
216+ BridgedEnumElementDecl . createParsed (
217+ astContext, declContext: declContext. bridgedDeclContext,
218+ name: name, nameLoc: nameLoc. bridgedLocation,
219+ parameterList: parameterList. bridged. bridged,
220+ equalsLoc: equalsLoc. bridgedLocation,
221+ rawValue: rawValue. bridged) . asDecl. declObj. getAs ( EnumElementDecl . self)
222+ }
132223}
133224
134225final public class ExtensionDecl : Decl { }
@@ -177,62 +268,83 @@ extension Optional where Wrapped == Decl {
177268 }
178269}
179270
271+ public typealias AccessLevel = swift . AccessLevel
272+
180273public typealias Identifier = swift . Identifier
181274
182275public typealias GenericTypeParamKind = swift . GenericTypeParamKind
183276
184277public typealias ASTContext = BridgedASTContext
185278
186- public typealias DeclContext = BridgedDeclContext
187-
188279public typealias Expr = BridgedExpr
189280
190- public typealias ParameterList = BridgedParameterList
191-
192281public typealias SourceFile = BridgedSourceFile
193282
194283public typealias FileUnit = BridgedFileUnit
195284
196- public typealias GenericParamList = BridgedGenericParamList
285+ public class GenericParamList {
286+ public var bridged : BridgedGenericParamList
287+ public init ( bridged: BridgedGenericParamList ) { self . bridged = bridged }
288+ }
197289
198290public typealias TrailingWhereClause = BridgedTrailingWhereClause
199291
200- public typealias BridgedParamDecl = ASTBridging . BridgedParamDecl
292+ public class ParameterList : RandomAccessCollection {
293+ public class Iterator : IteratorProtocol {
294+ public typealias Element = ParamDecl
295+ private var index : Int = 0
296+ private let parameterList : ParameterList
297+ init ( parameterList : ParameterList ) { self . parameterList = parameterList }
298+ public func next( ) -> Element ? {
299+ if index < parameterList. bridged. size {
300+ return parameterList. bridged. get ( index) . asDecl. declObj. getAs ( ParamDecl . self)
301+ }
302+ return nil
303+ }
304+ }
305+ public typealias Index = Int
306+ public var startIndex : Index { 0 }
307+ public var endIndex : Index { bridged. size }
308+ public func index( after i: Index ) -> Index { i + 1 }
201309
202- public typealias BridgedGenericTypeParamDecl = ASTBridging . BridgedGenericTypeParamDecl
310+ public func makeIterator( ) -> Iterator {
311+ Self . Iterator ( parameterList: self )
312+ }
203313
204- public typealias BridgedEnumDecl = ASTBridging . BridgedEnumDecl
314+ public var bridged : BridgedParameterList
205315
206- public typealias BridgedEnumElementDecl = ASTBridging . BridgedEnumElementDecl
316+ public init ( bridged: BridgedParameterList ) {
317+ self . bridged = bridged
318+ }
207319
208- extension ParameterList {
209- public subscript( _ index: Int ) -> BridgedParamDecl {
210- return get ( index)
320+ public subscript( _ index: Index ) -> ParamDecl {
321+ return bridged. get ( index) . asDecl. declObj. getAs ( ParamDecl . self)
211322 }
212323
213- public static func createParsed (
214- _ astContext: ASTContext , leftParenLoc: SourceLoc ? , parameters: [ BridgedParamDecl ] ,
324+ public static func create (
325+ _ astContext: ASTContext , leftParenLoc: SourceLoc ? , parameters: [ ParamDecl ] ,
215326 rightParenLoc: SourceLoc ?
216327 ) -> ParameterList {
217- parameters. withBridgedArrayRef {
218- ParameterList . createParsed (
328+ ParameterList ( bridged : parameters. map { BridgedParamDecl ( raw : $0 . bridged . obj ) } . withBridgedArrayRef {
329+ BridgedParameterList . createParsed (
219330 astContext, leftParenLoc: leftParenLoc. bridgedLocation, parameters: $0,
220331 rightParenLoc: rightParenLoc. bridgedLocation)
221- }
332+ } )
222333 }
223334}
224335
225336extension GenericParamList {
226- public static func createParsed (
227- _ astContext: ASTContext , leftAngleLoc: SourceLoc ? , parameters: [ BridgedGenericTypeParamDecl ] ,
337+ public static func create (
338+ _ astContext: ASTContext , leftAngleLoc: SourceLoc ? , parameters: [ GenericTypeParamDecl ] ,
228339 genericWhereClause: TrailingWhereClause ? ,
229340 rightAngleLoc: SourceLoc ?
230341 ) -> GenericParamList {
231- return parameters. withBridgedArrayRef {
232- GenericParamList . createParsed (
342+ let paramsNew = parameters. map { ASTBridging . BridgedGenericTypeParamDecl ( raw: $0. bridged. obj) }
343+ return paramsNew. withBridgedArrayRef {
344+ GenericParamList ( bridged: BridgedGenericParamList . createParsed (
233345 astContext, leftAngleLoc: leftAngleLoc. bridgedLocation, parameters: $0,
234346 genericWhereClause: genericWhereClause. bridged, rightAngleLoc: rightAngleLoc. bridgedLocation
235- )
347+ ) )
236348 }
237349 }
238350}
@@ -244,43 +356,6 @@ extension BridgedDecl {
244356 public var decl : Decl { declObj. decl }
245357}
246358
247- extension BridgedEnumDecl {
248- public static func createParsed(
249- _ astContext: ASTContext , declContext: DeclContext , enumKeywordLoc: SourceLoc ? , name: String ,
250- nameLoc: SourceLoc ? , genericParamList: GenericParamList ? , inheritedTypes: [ Type ] ,
251- genericWhereClause: TrailingWhereClause ? , braceRange: SourceRange
252- ) -> BridgedEnumDecl {
253- return name. withCString { strPtr in
254- inheritedTypes. withBridgedArrayRef { types in
255- BridgedEnumDecl . createParsed (
256- astContext, declContext: declContext,
257- enumKeywordLoc: enumKeywordLoc. bridgedLocation,
258- name: astContext. getIdentifier ( BridgedStringRef ( data: strPtr, count: name. count) ) ,
259- nameLoc: nameLoc. bridgedLocation,
260- genericParamList: genericParamList. bridged,
261- inheritedTypes: types,
262- genericWhereClause: genericWhereClause. bridged,
263- braceRange: braceRange. bridged)
264- }
265- }
266- }
267- }
268-
269- extension BridgedEnumElementDecl {
270- public static func createParsed(
271- _ astContext: ASTContext , declContext: DeclContext ,
272- name: Identifier , nameLoc: SourceLoc ? ,
273- parameterList: ParameterList ? ,
274- equalsLoc: SourceLoc ? , rawValue: Expr ?
275- ) -> BridgedEnumElementDecl {
276- BridgedEnumElementDecl . createParsed (
277- astContext, declContext: declContext,
278- name: name, nameLoc: nameLoc. bridgedLocation,
279- parameterList: parameterList. bridged,
280- equalsLoc: equalsLoc. bridgedLocation, rawValue: rawValue. bridged)
281- }
282- }
283-
284359extension SourceFile {
285360 public init ? ( bridged: BridgedNullableSourceFile ) {
286361 guard let raw = bridged. raw else {
@@ -294,21 +369,24 @@ extension FileUnit {
294369 public var asSourceFile : SourceFile ? { SourceFile ( bridged: self . castToSourceFile ( ) ) }
295370}
296371
297- extension BridgedParamDecl {
298- public func setInterfaceType( type: Type ) {
299- self . setInterfaceType ( type. bridged)
372+ extension ParameterList ? {
373+ public var bridged : BridgedParameterList ? {
374+ if self == nil {
375+ return nil
376+ }
377+ return self !. bridged
300378 }
301379}
302380
303- extension ParameterList ? {
381+ extension BridgedParameterList ? {
304382 public var bridged : BridgedNullableParameterList {
305383 BridgedNullableParameterList ( raw: self ? . raw)
306384 }
307385}
308386
309387extension GenericParamList ? {
310388 public var bridged : BridgedNullableGenericParamList {
311- BridgedNullableGenericParamList ( raw: self ? . raw)
389+ BridgedNullableGenericParamList ( raw: self ? . bridged . raw)
312390 }
313391}
314392
0 commit comments