@@ -16,48 +16,35 @@ import ASTBridging
1616/// The base class for all declarations in Swift.
1717@_semantics ( " arc.immortal " )
1818public class Decl : CustomStringConvertible , Hashable {
19- public var bridged : BridgedDeclObj { BridgedDeclObj ( SwiftObject ( self ) ) }
19+ final public var bridged : BridgedDeclObj { BridgedDeclObj ( SwiftObject ( self ) ) }
2020
21- public var description : String { String ( taking: bridged. getDebugDescription ( ) ) }
21+ final public var description : String { String ( taking: bridged. getDebugDescription ( ) ) }
2222
2323 /// The module in which this declaration resides.
24- public var parentModule : ModuleDecl { bridged. getModuleContext ( ) . getAs ( ModuleDecl . self) }
24+ final public var parentModule : ModuleDecl { bridged. getModuleContext ( ) . getAs ( ModuleDecl . self) }
2525
2626 /// The parent DeclContext if it is a Decl.
27- public var parent : Decl ? { bridged. getParent ( ) . decl }
27+ final public var parent : Decl ? { bridged. getParent ( ) . decl }
2828
2929 // True if this declaration is imported from C/C++/ObjC.
30- public var hasClangNode : Bool { bridged. hasClangNode ( ) }
30+ final public var hasClangNode : Bool { bridged. hasClangNode ( ) }
3131
32- public var declContext : DeclContext {
32+ final public var declContext : DeclContext {
3333 if let decl = parent {
3434 return decl as! DeclContext
3535 }
36- return DeclContextObj ( bridged: bridged. getDeclContext ( ) )
36+ return UnknownDeclContext ( bridged: bridged. getDeclContext ( ) )
3737 }
3838
39- public var bridgedDecl : BridgedDecl { BridgedDecl ( raw: bridged. obj) }
39+ final public var bridgedDecl : BridgedDecl { BridgedDecl ( raw: bridged. obj) }
4040
4141 public static func == ( lhs: Decl , rhs: Decl ) -> Bool { lhs === rhs }
4242
43- public func hash( into hasher: inout Hasher ) {
43+ final public func hash( into hasher: inout Hasher ) {
4444 hasher. combine ( ObjectIdentifier ( self ) )
4545 }
4646
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 }
47+ final public func setImplicit( ) { bridged. setImplicit ( ) }
6148}
6249
6350public protocol GenericContext : Decl , DeclContext { }
@@ -108,9 +95,9 @@ final public class EnumDecl: NominalTypeDecl {
10895 public var hasRawType : Bool { bridged. Enum_hasRawType ( ) }
10996
11097 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
98+ declContext: DeclContext , enumKeywordLoc: SourceLoc ? , name: String ,
99+ nameLoc: SourceLoc ? , genericParamList: GenericParameterList ? , inheritedTypes: [ Type ] ,
100+ genericWhereClause: TrailingWhereClause ? , braceRange: SourceRange , _ astContext : ASTContext
114101 ) -> EnumDecl {
115102 name. withCString { strPtr in
116103 inheritedTypes. withBridgedArrayRef { types in
@@ -208,10 +195,10 @@ final public class EnumElementDecl: ValueDecl {
208195 public var name : StringRef { StringRef ( bridged: bridged. EnumElementDecl_getNameStr ( ) ) }
209196
210197 public static func create(
211- _ astContext : ASTContext , declContext: DeclContext ,
198+ declContext: DeclContext ,
212199 name: Identifier , nameLoc: SourceLoc ? ,
213200 parameterList: ParameterList ? ,
214- equalsLoc: SourceLoc ? , rawValue: Expr ?
201+ equalsLoc: SourceLoc ? , rawValue: Expr ? , _ astContext : ASTContext
215202 ) -> EnumElementDecl {
216203 BridgedEnumElementDecl . createParsed (
217204 astContext, declContext: declContext. bridgedDeclContext,
@@ -282,48 +269,30 @@ public typealias SourceFile = BridgedSourceFile
282269
283270public typealias FileUnit = BridgedFileUnit
284271
285- public class GenericParamList {
272+ public class GenericParameterList {
286273 public var bridged : BridgedGenericParamList
287274 public init ( bridged: BridgedGenericParamList ) { self . bridged = bridged }
288275}
289276
290277public typealias TrailingWhereClause = BridgedTrailingWhereClause
291278
292279public 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 }
309-
310- public func makeIterator( ) -> Iterator {
311- Self . Iterator ( parameterList: self )
312- }
280+ public var startIndex : Int { 0 }
281+ public var endIndex : Int { bridged. size }
313282
314283 public var bridged : BridgedParameterList
315284
316285 public init ( bridged: BridgedParameterList ) {
317286 self . bridged = bridged
318287 }
319288
320- public subscript( _ index: Index ) -> ParamDecl {
289+ public subscript( _ index: Int ) -> ParamDecl {
321290 return bridged. get ( index) . asDecl. declObj. getAs ( ParamDecl . self)
322291 }
323292
324293 public static func create(
325- _ astContext : ASTContext , leftParenLoc: SourceLoc ? , parameters: [ ParamDecl ] ,
326- rightParenLoc: SourceLoc ?
294+ leftParenLoc: SourceLoc ? , parameters: [ ParamDecl ] ,
295+ rightParenLoc: SourceLoc ? , _ astContext : ASTContext
327296 ) -> ParameterList {
328297 ParameterList ( bridged: parameters. map { BridgedParamDecl ( raw: $0. bridged. obj) } . withBridgedArrayRef {
329298 BridgedParameterList . createParsed (
@@ -333,15 +302,15 @@ public class ParameterList : RandomAccessCollection {
333302 }
334303}
335304
336- extension GenericParamList {
305+ extension GenericParameterList {
337306 public static func create(
338- _ astContext : ASTContext , leftAngleLoc: SourceLoc ? , parameters: [ GenericTypeParamDecl ] ,
307+ leftAngleLoc: SourceLoc ? , parameters: [ GenericTypeParamDecl ] ,
339308 genericWhereClause: TrailingWhereClause ? ,
340- rightAngleLoc: SourceLoc ?
341- ) -> GenericParamList {
309+ rightAngleLoc: SourceLoc ? , _ astContext : ASTContext
310+ ) -> GenericParameterList {
342311 let paramsNew = parameters. map { ASTBridging . BridgedGenericTypeParamDecl ( raw: $0. bridged. obj) }
343312 return paramsNew. withBridgedArrayRef {
344- GenericParamList ( bridged: BridgedGenericParamList . createParsed (
313+ GenericParameterList ( bridged: BridgedGenericParamList . createParsed (
345314 astContext, leftAngleLoc: leftAngleLoc. bridgedLocation, parameters: $0,
346315 genericWhereClause: genericWhereClause. bridged, rightAngleLoc: rightAngleLoc. bridgedLocation
347316 ) )
@@ -371,10 +340,7 @@ extension FileUnit {
371340
372341extension ParameterList ? {
373342 public var bridged : BridgedParameterList ? {
374- if self == nil {
375- return nil
376- }
377- return self !. bridged
343+ return self ? . bridged
378344 }
379345}
380346
@@ -384,7 +350,7 @@ extension BridgedParameterList? {
384350 }
385351}
386352
387- extension GenericParamList ? {
353+ extension GenericParameterList ? {
388354 public var bridged : BridgedNullableGenericParamList {
389355 BridgedNullableGenericParamList ( raw: self ? . bridged. raw)
390356 }
0 commit comments