mirror of
https://github.com/github/codeql.git
synced 2026-04-24 00:05:14 +02:00
Swift: initial PrintAst test for Method Lookups
This commit is contained in:
@@ -0,0 +1,271 @@
|
||||
#-----| [ModuleDecl] __ObjC
|
||||
#-----| [ModuleDecl] methodlookup
|
||||
methodlookup.swift:
|
||||
# 1| [ClassDecl] Foo
|
||||
# 2| getMember(0): [ConstructorDecl] init()
|
||||
# 2| InterfaceType = (Foo.Type) -> () -> Foo
|
||||
# 2| getSelfParam(): [ParamDecl] self
|
||||
# 2| Type = Foo
|
||||
# 2| getBody(): [BraceStmt] { ... }
|
||||
# 2| getElement(0): [ReturnStmt] return
|
||||
# 3| getMember(1): [ConcreteFuncDecl] instanceMethod()
|
||||
# 3| InterfaceType = (Foo) -> () -> ()
|
||||
# 3| getSelfParam(): [ParamDecl] self
|
||||
# 3| Type = Foo
|
||||
# 3| getBody(): [BraceStmt] { ... }
|
||||
# 4| getMember(2): [ConcreteFuncDecl] staticMethod()
|
||||
# 4| InterfaceType = (Foo.Type) -> () -> ()
|
||||
# 4| getSelfParam(): [ParamDecl] self
|
||||
# 4| Type = Foo.Type
|
||||
# 4| getBody(): [BraceStmt] { ... }
|
||||
# 5| getMember(3): [ConcreteFuncDecl] classMethod()
|
||||
# 5| InterfaceType = (Foo.Type) -> () -> ()
|
||||
# 5| getSelfParam(): [ParamDecl] self
|
||||
# 5| Type = Foo.Type
|
||||
# 5| getBody(): [BraceStmt] { ... }
|
||||
# 1| getMember(4): [DestructorDecl] deinit()
|
||||
# 1| InterfaceType = (Foo) -> () -> ()
|
||||
# 1| getSelfParam(): [ParamDecl] self
|
||||
# 1| Type = Foo
|
||||
# 1| getBody(): [BraceStmt] { ... }
|
||||
# 8| [ClassDecl] Bar
|
||||
# 9| getMember(0): [ConstructorDecl] init()
|
||||
# 9| InterfaceType = (Bar.Type) -> () -> Bar
|
||||
# 9| getSelfParam(): [ParamDecl] self
|
||||
# 9| Type = Bar
|
||||
# 9| getBody(): [BraceStmt] { ... }
|
||||
# 9| getElement(0): [ReturnStmt] return
|
||||
# 10| getMember(1): [ConcreteFuncDecl] instanceMethod()
|
||||
# 10| InterfaceType = (isolated Bar) -> () -> ()
|
||||
# 10| getSelfParam(): [ParamDecl] self
|
||||
# 10| Type = Bar
|
||||
# 10| getBody(): [BraceStmt] { ... }
|
||||
# 11| getMember(2): [ConcreteFuncDecl] staticMethod()
|
||||
# 11| InterfaceType = (Bar.Type) -> () -> ()
|
||||
# 11| getSelfParam(): [ParamDecl] self
|
||||
# 11| Type = Bar.Type
|
||||
# 11| getBody(): [BraceStmt] { ... }
|
||||
#-----| getMember(3): [PatternBindingDecl] var ... = ...
|
||||
#-----| getPattern(0): [TypedPattern] ... as ...
|
||||
#-----| getSubPattern(): [NamedPattern] unownedExecutor
|
||||
# 8| getMember(4): [DestructorDecl] deinit()
|
||||
# 8| InterfaceType = (Bar) -> () -> ()
|
||||
# 8| getSelfParam(): [ParamDecl] self
|
||||
# 8| Type = Bar
|
||||
# 8| getBody(): [BraceStmt] { ... }
|
||||
#-----| getMember(5): [ConcreteVarDecl] unownedExecutor
|
||||
#-----| Type = UnownedSerialExecutor
|
||||
#-----| getAccessorDecl(0): [AccessorDecl] get
|
||||
#-----| InterfaceType = (Bar) -> () -> UnownedSerialExecutor
|
||||
#-----| getSelfParam(): [ParamDecl] self
|
||||
#-----| Type = Bar
|
||||
#-----| getBody(): [BraceStmt] { ... }
|
||||
#-----| getElement(0): [ReturnStmt] return ...
|
||||
#-----| getResult(): [CallExpr] call to init(_:)
|
||||
#-----| getFunction(): [ConstructorRefCallExpr] call to init(_:)
|
||||
#-----| getFunction(): [DeclRefExpr] init(_:)
|
||||
#-----| getArgument(0): [Argument] : UnownedSerialExecutor.Type
|
||||
#-----| getExpr(): [TypeExpr] UnownedSerialExecutor.Type
|
||||
#-----| getArgument(0): [Argument] : call to ...
|
||||
#-----| getExpr(): [CallExpr] call to ...
|
||||
#-----| getFunction(): (no string representation)
|
||||
#-----| getArgument(0): [Argument] : self
|
||||
#-----| getExpr(): [DeclRefExpr] self
|
||||
# 15| [ClassDecl] Baz
|
||||
# 16| getMember(0): [ConstructorDecl] init()
|
||||
# 16| InterfaceType = (Baz.Type) -> () -> Baz
|
||||
# 16| getSelfParam(): [ParamDecl] self
|
||||
# 16| Type = Baz
|
||||
# 16| getBody(): [BraceStmt] { ... }
|
||||
# 16| getElement(0): [ReturnStmt] return
|
||||
# 17| getMember(1): [ConcreteFuncDecl] instanceMethod()
|
||||
# 17| InterfaceType = (Baz) -> () -> ()
|
||||
# 17| getSelfParam(): [ParamDecl] self
|
||||
# 17| Type = Baz
|
||||
# 17| getBody(): [BraceStmt] { ... }
|
||||
# 18| getMember(2): [ConcreteFuncDecl] staticMethod()
|
||||
# 18| InterfaceType = (Baz.Type) -> () -> ()
|
||||
# 18| getSelfParam(): [ParamDecl] self
|
||||
# 18| Type = Baz.Type
|
||||
# 18| getBody(): [BraceStmt] { ... }
|
||||
# 19| getMember(3): [ConcreteFuncDecl] classMethod()
|
||||
# 19| InterfaceType = (Baz.Type) -> () -> ()
|
||||
# 19| getSelfParam(): [ParamDecl] self
|
||||
# 19| Type = Baz.Type
|
||||
# 19| getBody(): [BraceStmt] { ... }
|
||||
# 15| getMember(4): [DestructorDecl] deinit()
|
||||
# 15| InterfaceType = (Baz) -> () -> ()
|
||||
# 15| getSelfParam(): [ParamDecl] self
|
||||
# 15| Type = Baz
|
||||
# 15| getBody(): [BraceStmt] { ... }
|
||||
# 22| [TopLevelCodeDecl] { ... }
|
||||
# 22| getBody(): [BraceStmt] { ... }
|
||||
# 22| getElement(0): [DoStmt] do { ... }
|
||||
# 22| getBody(): [BraceStmt] { ... }
|
||||
# 23| getElement(0): [PatternBindingDecl] var ... = ...
|
||||
# 23| getInit(0): [CallExpr] call to init()
|
||||
# 23| getFunction(): [ConstructorRefCallExpr] call to init()
|
||||
# 23| getFunction(): [DeclRefExpr] init()
|
||||
# 23| getArgument(0): [Argument] : Foo.Type
|
||||
# 23| getExpr(): [TypeExpr] Foo.Type
|
||||
# 23| getTypeRepr(): [TypeRepr] Foo
|
||||
# 23| getPattern(0): [NamedPattern] foo
|
||||
# 23| getElement(1): [ConcreteVarDecl] foo
|
||||
# 23| Type = Foo
|
||||
# 24| getElement(2): [AssignExpr] ... = ...
|
||||
# 24| getDest(): [DiscardAssignmentExpr] _
|
||||
# 24| getSource(): [CallExpr] call to init()
|
||||
# 24| getFunction(): [ConstructorRefCallExpr] call to init()
|
||||
# 24| getFunction(): [DeclRefExpr] init()
|
||||
# 24| getArgument(0): [Argument] : Foo.Type
|
||||
# 24| getExpr(): [TypeExpr] Foo.Type
|
||||
# 24| getTypeRepr(): [TypeRepr] Foo
|
||||
# 26| getElement(3): [CallExpr] call to instanceMethod()
|
||||
# 26| getFunction(): [MethodRefExpr] .instanceMethod()
|
||||
# 26| getBase(): [DeclRefExpr] foo
|
||||
# 27| getElement(4): [CallExpr] call to ...
|
||||
# 27| getFunction(): [CallExpr] call to ...
|
||||
# 27| getFunction(): [DotSyntaxBaseIgnoredExpr] .{ ... }
|
||||
# 27| getQualifier(): [TypeExpr] Foo.Type
|
||||
# 27| getTypeRepr(): [TypeRepr] Foo
|
||||
# 27| getSubExpr(): [AutoClosureExpr] { ... }
|
||||
#-----| getParam(0): [ParamDecl] self
|
||||
#-----| Type = Foo
|
||||
# 27| getBody(): [BraceStmt] { ... }
|
||||
# 27| getElement(0): [ReturnStmt] return ...
|
||||
# 27| getResult(): [AutoClosureExpr] { ... }
|
||||
# 27| getBody(): [BraceStmt] { ... }
|
||||
# 27| getElement(0): [ReturnStmt] return ...
|
||||
# 27| getResult(): [CallExpr] call to instanceMethod()
|
||||
# 27| getFunction(): [MethodRefExpr] .instanceMethod()
|
||||
#-----| getBase(): [DeclRefExpr] self
|
||||
# 27| getArgument(0): [Argument] : foo
|
||||
# 27| getExpr(): [DeclRefExpr] foo
|
||||
# 29| getElement(5): [CallExpr] call to classMethod()
|
||||
# 29| getFunction(): [MethodRefExpr] .classMethod()
|
||||
# 29| getBase(): [TypeExpr] Foo.Type
|
||||
# 29| getTypeRepr(): [TypeRepr] Foo
|
||||
# 30| getElement(6): [CallExpr] call to staticMethod()
|
||||
# 30| getFunction(): [MethodRefExpr] .staticMethod()
|
||||
# 30| getBase(): [TypeExpr] Foo.Type
|
||||
# 30| getTypeRepr(): [TypeRepr] Foo
|
||||
# 33| [TopLevelCodeDecl] { ... }
|
||||
# 33| getBody(): [BraceStmt] { ... }
|
||||
# 33| getElement(0): [CallExpr] call to init(priority:operation:)
|
||||
# 33| getFunction(): [ConstructorRefCallExpr] call to init(priority:operation:)
|
||||
# 33| getFunction(): [DeclRefExpr] init(priority:operation:)
|
||||
# 33| getArgument(0): [Argument] : Task<(), Never>.Type
|
||||
# 33| getExpr(): [TypeExpr] Task<(), Never>.Type
|
||||
# 33| getTypeRepr(): [TypeRepr] Task<(), Never>
|
||||
# 33| getArgument(0): [Argument] priority: default priority
|
||||
# 33| getExpr(): [DefaultArgumentExpr] default priority
|
||||
# 33| getArgument(1): [Argument] operation: { ... }
|
||||
# 33| getExpr(): [ClosureExpr] { ... }
|
||||
# 33| getBody(): [BraceStmt] { ... }
|
||||
# 34| getElement(0): [PatternBindingDecl] var ... = ...
|
||||
# 34| getInit(0): [CallExpr] call to init()
|
||||
# 34| getFunction(): [ConstructorRefCallExpr] call to init()
|
||||
# 34| getFunction(): [DeclRefExpr] init()
|
||||
# 34| getArgument(0): [Argument] : Bar.Type
|
||||
# 34| getExpr(): [TypeExpr] Bar.Type
|
||||
# 34| getTypeRepr(): [TypeRepr] Bar
|
||||
# 34| getPattern(0): [NamedPattern] bar
|
||||
# 34| getElement(1): [ConcreteVarDecl] bar
|
||||
# 34| Type = Bar
|
||||
# 35| getElement(2): [AssignExpr] ... = ...
|
||||
# 35| getDest(): [DiscardAssignmentExpr] _
|
||||
# 35| getSource(): [CallExpr] call to init()
|
||||
# 35| getFunction(): [ConstructorRefCallExpr] call to init()
|
||||
# 35| getFunction(): [DeclRefExpr] init()
|
||||
# 35| getArgument(0): [Argument] : Bar.Type
|
||||
# 35| getExpr(): [TypeExpr] Bar.Type
|
||||
# 35| getTypeRepr(): [TypeRepr] Bar
|
||||
# 37| getElement(3): [CallExpr] call to instanceMethod()
|
||||
# 37| getFunction(): [MethodRefExpr] .instanceMethod()
|
||||
# 37| getBase(): [DeclRefExpr] bar
|
||||
# 37| getElement(3).getFullyConverted(): [AwaitExpr] await ...
|
||||
# 40| getElement(4): [CallExpr] call to staticMethod()
|
||||
# 40| getFunction(): [MethodRefExpr] .staticMethod()
|
||||
# 40| getBase(): [TypeExpr] Bar.Type
|
||||
# 40| getTypeRepr(): [TypeRepr] Bar
|
||||
# 33| [NilLiteralExpr] nil
|
||||
# 38| [Comment] // Bar.instanceMethod(bar2)() // error: actor-isolated instance method 'instanceMethod()' can not be referenced from a non-isolated context
|
||||
# 38|
|
||||
# 43| [TopLevelCodeDecl] { ... }
|
||||
# 43| getBody(): [BraceStmt] { ... }
|
||||
# 43| getElement(0): [CallExpr] call to init(priority:operation:)
|
||||
# 43| getFunction(): [ConstructorRefCallExpr] call to init(priority:operation:)
|
||||
# 43| getFunction(): [DeclRefExpr] init(priority:operation:)
|
||||
# 43| getArgument(0): [Argument] : Task<(), Never>.Type
|
||||
# 43| getExpr(): [TypeExpr] Task<(), Never>.Type
|
||||
# 43| getTypeRepr(): [TypeRepr] Task<(), Never>
|
||||
# 43| getArgument(0): [Argument] priority: default priority
|
||||
# 43| getExpr(): [DefaultArgumentExpr] default priority
|
||||
# 43| getArgument(1): [Argument] operation: { ... }
|
||||
# 43| getExpr(): [ClosureExpr] { ... }
|
||||
# 43| getBody(): [BraceStmt] { ... }
|
||||
# 44| getElement(0): [PatternBindingDecl] var ... = ...
|
||||
# 44| getInit(0): [CallExpr] call to init()
|
||||
# 44| getFunction(): [ConstructorRefCallExpr] call to init()
|
||||
# 44| getFunction(): [DeclRefExpr] init()
|
||||
# 44| getFunction().getFullyConverted(): [FunctionConversionExpr] ((Baz.Type) -> @MainActor () -> Baz) ...
|
||||
# 44| getArgument(0): [Argument] : Baz.Type
|
||||
# 44| getExpr(): [TypeExpr] Baz.Type
|
||||
# 44| getTypeRepr(): [TypeRepr] Baz
|
||||
# 44| getInit(0).getFullyConverted(): [AwaitExpr] await ...
|
||||
# 44| getPattern(0): [NamedPattern] baz
|
||||
# 44| getElement(1): [ConcreteVarDecl] baz
|
||||
# 44| Type = Baz
|
||||
# 45| getElement(2): [AssignExpr] ... = ...
|
||||
# 45| getDest(): [DiscardAssignmentExpr] _
|
||||
# 45| getSource(): [CallExpr] call to init()
|
||||
# 45| getFunction(): [ConstructorRefCallExpr] call to init()
|
||||
# 45| getFunction(): [DeclRefExpr] init()
|
||||
# 45| getFunction().getFullyConverted(): [FunctionConversionExpr] ((Baz.Type) -> @MainActor () -> Baz) ...
|
||||
# 45| getArgument(0): [Argument] : Baz.Type
|
||||
# 45| getExpr(): [TypeExpr] Baz.Type
|
||||
# 45| getTypeRepr(): [TypeRepr] Baz
|
||||
# 45| getSource().getFullyConverted(): [AwaitExpr] await ...
|
||||
# 47| getElement(3): [CallExpr] call to ...
|
||||
# 47| getFunction(): [DotSyntaxCallExpr] call to instanceMethod()
|
||||
# 47| getFunction(): [DeclRefExpr] instanceMethod()
|
||||
# 47| getFunction().getFullyConverted(): [FunctionConversionExpr] ((Baz) -> @MainActor () -> ()) ...
|
||||
# 47| getArgument(0): [Argument] : baz
|
||||
# 47| getExpr(): [DeclRefExpr] baz
|
||||
# 47| getElement(3).getFullyConverted(): [AwaitExpr] await ...
|
||||
# 48| getElement(4): [CallExpr] call to ...
|
||||
# 48| getFunction(): [CallExpr] call to ...
|
||||
# 48| getFunction(): [DotSyntaxBaseIgnoredExpr] .{ ... }
|
||||
# 48| getQualifier(): [TypeExpr] Baz.Type
|
||||
# 48| getTypeRepr(): [TypeRepr] Baz
|
||||
# 48| getSubExpr(): [AutoClosureExpr] { ... }
|
||||
#-----| getParam(0): [ParamDecl] self
|
||||
#-----| Type = Baz
|
||||
# 48| getBody(): [BraceStmt] { ... }
|
||||
# 48| getElement(0): [ReturnStmt] return ...
|
||||
# 48| getResult(): [AutoClosureExpr] { ... }
|
||||
# 48| getBody(): [BraceStmt] { ... }
|
||||
# 48| getElement(0): [ReturnStmt] return ...
|
||||
# 48| getResult(): [CallExpr] call to instanceMethod()
|
||||
# 48| getFunction(): [MethodRefExpr] .instanceMethod()
|
||||
#-----| getBase(): [DeclRefExpr] self
|
||||
# 48| getArgument(0): [Argument] : baz
|
||||
# 48| getExpr(): [DeclRefExpr] baz
|
||||
# 48| getElement(4).getFullyConverted(): [AwaitExpr] await ...
|
||||
# 50| getElement(5): [CallExpr] call to ...
|
||||
# 50| getFunction(): [DotSyntaxCallExpr] call to classMethod()
|
||||
# 50| getFunction(): [DeclRefExpr] classMethod()
|
||||
# 50| getFunction().getFullyConverted(): [FunctionConversionExpr] ((Baz.Type) -> @MainActor () -> ()) ...
|
||||
# 50| getArgument(0): [Argument] : Baz.Type
|
||||
# 50| getExpr(): [TypeExpr] Baz.Type
|
||||
# 50| getTypeRepr(): [TypeRepr] Baz
|
||||
# 50| getElement(5).getFullyConverted(): [AwaitExpr] await ...
|
||||
# 51| getElement(6): [CallExpr] call to ...
|
||||
# 51| getFunction(): [DotSyntaxCallExpr] call to staticMethod()
|
||||
# 51| getFunction(): [DeclRefExpr] staticMethod()
|
||||
# 51| getFunction().getFullyConverted(): [FunctionConversionExpr] ((Baz.Type) -> @MainActor () -> ()) ...
|
||||
# 51| getArgument(0): [Argument] : Baz.Type
|
||||
# 51| getExpr(): [TypeExpr] Baz.Type
|
||||
# 51| getTypeRepr(): [TypeRepr] Baz
|
||||
# 51| getElement(6).getFullyConverted(): [AwaitExpr] await ...
|
||||
# 43| [NilLiteralExpr] nil
|
||||
@@ -0,0 +1 @@
|
||||
library-tests/ast/PrintAst.ql
|
||||
@@ -0,0 +1,52 @@
|
||||
class Foo {
|
||||
init() {}
|
||||
func instanceMethod() {}
|
||||
static func staticMethod() {}
|
||||
class func classMethod() {}
|
||||
}
|
||||
|
||||
actor Bar {
|
||||
init() {}
|
||||
func instanceMethod() {}
|
||||
static func staticMethod() {}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
class Baz {
|
||||
init() {}
|
||||
func instanceMethod() {}
|
||||
static func staticMethod() {}
|
||||
class func classMethod() {}
|
||||
}
|
||||
|
||||
do {
|
||||
let foo = Foo()
|
||||
_ = Foo.init()
|
||||
|
||||
foo.instanceMethod()
|
||||
Foo.instanceMethod(foo)()
|
||||
|
||||
Foo.classMethod()
|
||||
Foo.staticMethod()
|
||||
}
|
||||
|
||||
Task {
|
||||
let bar = Bar()
|
||||
_ = Bar.init()
|
||||
|
||||
await bar.instanceMethod()
|
||||
// Bar.instanceMethod(bar2)() // error: actor-isolated instance method 'instanceMethod()' can not be referenced from a non-isolated context
|
||||
|
||||
Bar.staticMethod()
|
||||
}
|
||||
|
||||
Task {
|
||||
let baz = await Baz()
|
||||
_ = await Baz.init()
|
||||
|
||||
await baz.instanceMethod()
|
||||
await Baz.instanceMethod(baz)()
|
||||
|
||||
await Baz.classMethod()
|
||||
await Baz.staticMethod()
|
||||
}
|
||||
Reference in New Issue
Block a user