Skip to content

Commit 99719d0

Browse files
committed
Swift: initial PrintAst test for Method Lookups
1 parent 33955ee commit 99719d0

File tree

3 files changed

+324
-0
lines changed

3 files changed

+324
-0
lines changed
Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
#-----| [ModuleDecl] __ObjC
2+
#-----| [ModuleDecl] methodlookup
3+
methodlookup.swift:
4+
# 1| [ClassDecl] Foo
5+
# 2| getMember(0): [ConstructorDecl] init()
6+
# 2| InterfaceType = (Foo.Type) -> () -> Foo
7+
# 2| getSelfParam(): [ParamDecl] self
8+
# 2| Type = Foo
9+
# 2| getBody(): [BraceStmt] { ... }
10+
# 2| getElement(0): [ReturnStmt] return
11+
# 3| getMember(1): [ConcreteFuncDecl] instanceMethod()
12+
# 3| InterfaceType = (Foo) -> () -> ()
13+
# 3| getSelfParam(): [ParamDecl] self
14+
# 3| Type = Foo
15+
# 3| getBody(): [BraceStmt] { ... }
16+
# 4| getMember(2): [ConcreteFuncDecl] staticMethod()
17+
# 4| InterfaceType = (Foo.Type) -> () -> ()
18+
# 4| getSelfParam(): [ParamDecl] self
19+
# 4| Type = Foo.Type
20+
# 4| getBody(): [BraceStmt] { ... }
21+
# 5| getMember(3): [ConcreteFuncDecl] classMethod()
22+
# 5| InterfaceType = (Foo.Type) -> () -> ()
23+
# 5| getSelfParam(): [ParamDecl] self
24+
# 5| Type = Foo.Type
25+
# 5| getBody(): [BraceStmt] { ... }
26+
# 1| getMember(4): [DestructorDecl] deinit()
27+
# 1| InterfaceType = (Foo) -> () -> ()
28+
# 1| getSelfParam(): [ParamDecl] self
29+
# 1| Type = Foo
30+
# 1| getBody(): [BraceStmt] { ... }
31+
# 8| [ClassDecl] Bar
32+
# 9| getMember(0): [ConstructorDecl] init()
33+
# 9| InterfaceType = (Bar.Type) -> () -> Bar
34+
# 9| getSelfParam(): [ParamDecl] self
35+
# 9| Type = Bar
36+
# 9| getBody(): [BraceStmt] { ... }
37+
# 9| getElement(0): [ReturnStmt] return
38+
# 10| getMember(1): [ConcreteFuncDecl] instanceMethod()
39+
# 10| InterfaceType = (isolated Bar) -> () -> ()
40+
# 10| getSelfParam(): [ParamDecl] self
41+
# 10| Type = Bar
42+
# 10| getBody(): [BraceStmt] { ... }
43+
# 11| getMember(2): [ConcreteFuncDecl] staticMethod()
44+
# 11| InterfaceType = (Bar.Type) -> () -> ()
45+
# 11| getSelfParam(): [ParamDecl] self
46+
# 11| Type = Bar.Type
47+
# 11| getBody(): [BraceStmt] { ... }
48+
#-----| getMember(3): [PatternBindingDecl] var ... = ...
49+
#-----| getPattern(0): [TypedPattern] ... as ...
50+
#-----| getSubPattern(): [NamedPattern] unownedExecutor
51+
# 8| getMember(4): [DestructorDecl] deinit()
52+
# 8| InterfaceType = (Bar) -> () -> ()
53+
# 8| getSelfParam(): [ParamDecl] self
54+
# 8| Type = Bar
55+
# 8| getBody(): [BraceStmt] { ... }
56+
#-----| getMember(5): [ConcreteVarDecl] unownedExecutor
57+
#-----| Type = UnownedSerialExecutor
58+
#-----| getAccessorDecl(0): [AccessorDecl] get
59+
#-----| InterfaceType = (Bar) -> () -> UnownedSerialExecutor
60+
#-----| getSelfParam(): [ParamDecl] self
61+
#-----| Type = Bar
62+
#-----| getBody(): [BraceStmt] { ... }
63+
#-----| getElement(0): [ReturnStmt] return ...
64+
#-----| getResult(): [CallExpr] call to init(_:)
65+
#-----| getFunction(): [ConstructorRefCallExpr] call to init(_:)
66+
#-----| getFunction(): [DeclRefExpr] init(_:)
67+
#-----| getArgument(0): [Argument] : UnownedSerialExecutor.Type
68+
#-----| getExpr(): [TypeExpr] UnownedSerialExecutor.Type
69+
#-----| getArgument(0): [Argument] : call to ...
70+
#-----| getExpr(): [CallExpr] call to ...
71+
#-----| getFunction(): (no string representation)
72+
#-----| getArgument(0): [Argument] : self
73+
#-----| getExpr(): [DeclRefExpr] self
74+
# 15| [ClassDecl] Baz
75+
# 16| getMember(0): [ConstructorDecl] init()
76+
# 16| InterfaceType = (Baz.Type) -> () -> Baz
77+
# 16| getSelfParam(): [ParamDecl] self
78+
# 16| Type = Baz
79+
# 16| getBody(): [BraceStmt] { ... }
80+
# 16| getElement(0): [ReturnStmt] return
81+
# 17| getMember(1): [ConcreteFuncDecl] instanceMethod()
82+
# 17| InterfaceType = (Baz) -> () -> ()
83+
# 17| getSelfParam(): [ParamDecl] self
84+
# 17| Type = Baz
85+
# 17| getBody(): [BraceStmt] { ... }
86+
# 18| getMember(2): [ConcreteFuncDecl] staticMethod()
87+
# 18| InterfaceType = (Baz.Type) -> () -> ()
88+
# 18| getSelfParam(): [ParamDecl] self
89+
# 18| Type = Baz.Type
90+
# 18| getBody(): [BraceStmt] { ... }
91+
# 19| getMember(3): [ConcreteFuncDecl] classMethod()
92+
# 19| InterfaceType = (Baz.Type) -> () -> ()
93+
# 19| getSelfParam(): [ParamDecl] self
94+
# 19| Type = Baz.Type
95+
# 19| getBody(): [BraceStmt] { ... }
96+
# 15| getMember(4): [DestructorDecl] deinit()
97+
# 15| InterfaceType = (Baz) -> () -> ()
98+
# 15| getSelfParam(): [ParamDecl] self
99+
# 15| Type = Baz
100+
# 15| getBody(): [BraceStmt] { ... }
101+
# 22| [TopLevelCodeDecl] { ... }
102+
# 22| getBody(): [BraceStmt] { ... }
103+
# 22| getElement(0): [DoStmt] do { ... }
104+
# 22| getBody(): [BraceStmt] { ... }
105+
# 23| getElement(0): [PatternBindingDecl] var ... = ...
106+
# 23| getInit(0): [CallExpr] call to init()
107+
# 23| getFunction(): [ConstructorRefCallExpr] call to init()
108+
# 23| getFunction(): [DeclRefExpr] init()
109+
# 23| getArgument(0): [Argument] : Foo.Type
110+
# 23| getExpr(): [TypeExpr] Foo.Type
111+
# 23| getTypeRepr(): [TypeRepr] Foo
112+
# 23| getPattern(0): [NamedPattern] foo
113+
# 23| getElement(1): [ConcreteVarDecl] foo
114+
# 23| Type = Foo
115+
# 24| getElement(2): [AssignExpr] ... = ...
116+
# 24| getDest(): [DiscardAssignmentExpr] _
117+
# 24| getSource(): [CallExpr] call to init()
118+
# 24| getFunction(): [ConstructorRefCallExpr] call to init()
119+
# 24| getFunction(): [DeclRefExpr] init()
120+
# 24| getArgument(0): [Argument] : Foo.Type
121+
# 24| getExpr(): [TypeExpr] Foo.Type
122+
# 24| getTypeRepr(): [TypeRepr] Foo
123+
# 26| getElement(3): [CallExpr] call to instanceMethod()
124+
# 26| getFunction(): [MethodRefExpr] .instanceMethod()
125+
# 26| getBase(): [DeclRefExpr] foo
126+
# 27| getElement(4): [CallExpr] call to ...
127+
# 27| getFunction(): [CallExpr] call to ...
128+
# 27| getFunction(): [DotSyntaxBaseIgnoredExpr] .{ ... }
129+
# 27| getQualifier(): [TypeExpr] Foo.Type
130+
# 27| getTypeRepr(): [TypeRepr] Foo
131+
# 27| getSubExpr(): [AutoClosureExpr] { ... }
132+
#-----| getParam(0): [ParamDecl] self
133+
#-----| Type = Foo
134+
# 27| getBody(): [BraceStmt] { ... }
135+
# 27| getElement(0): [ReturnStmt] return ...
136+
# 27| getResult(): [AutoClosureExpr] { ... }
137+
# 27| getBody(): [BraceStmt] { ... }
138+
# 27| getElement(0): [ReturnStmt] return ...
139+
# 27| getResult(): [CallExpr] call to instanceMethod()
140+
# 27| getFunction(): [MethodRefExpr] .instanceMethod()
141+
#-----| getBase(): [DeclRefExpr] self
142+
# 27| getArgument(0): [Argument] : foo
143+
# 27| getExpr(): [DeclRefExpr] foo
144+
# 29| getElement(5): [CallExpr] call to classMethod()
145+
# 29| getFunction(): [MethodRefExpr] .classMethod()
146+
# 29| getBase(): [TypeExpr] Foo.Type
147+
# 29| getTypeRepr(): [TypeRepr] Foo
148+
# 30| getElement(6): [CallExpr] call to staticMethod()
149+
# 30| getFunction(): [MethodRefExpr] .staticMethod()
150+
# 30| getBase(): [TypeExpr] Foo.Type
151+
# 30| getTypeRepr(): [TypeRepr] Foo
152+
# 33| [TopLevelCodeDecl] { ... }
153+
# 33| getBody(): [BraceStmt] { ... }
154+
# 33| getElement(0): [CallExpr] call to init(priority:operation:)
155+
# 33| getFunction(): [ConstructorRefCallExpr] call to init(priority:operation:)
156+
# 33| getFunction(): [DeclRefExpr] init(priority:operation:)
157+
# 33| getArgument(0): [Argument] : Task<(), Never>.Type
158+
# 33| getExpr(): [TypeExpr] Task<(), Never>.Type
159+
# 33| getTypeRepr(): [TypeRepr] Task<(), Never>
160+
# 33| getArgument(0): [Argument] priority: default priority
161+
# 33| getExpr(): [DefaultArgumentExpr] default priority
162+
# 33| getArgument(1): [Argument] operation: { ... }
163+
# 33| getExpr(): [ClosureExpr] { ... }
164+
# 33| getBody(): [BraceStmt] { ... }
165+
# 34| getElement(0): [PatternBindingDecl] var ... = ...
166+
# 34| getInit(0): [CallExpr] call to init()
167+
# 34| getFunction(): [ConstructorRefCallExpr] call to init()
168+
# 34| getFunction(): [DeclRefExpr] init()
169+
# 34| getArgument(0): [Argument] : Bar.Type
170+
# 34| getExpr(): [TypeExpr] Bar.Type
171+
# 34| getTypeRepr(): [TypeRepr] Bar
172+
# 34| getPattern(0): [NamedPattern] bar
173+
# 34| getElement(1): [ConcreteVarDecl] bar
174+
# 34| Type = Bar
175+
# 35| getElement(2): [AssignExpr] ... = ...
176+
# 35| getDest(): [DiscardAssignmentExpr] _
177+
# 35| getSource(): [CallExpr] call to init()
178+
# 35| getFunction(): [ConstructorRefCallExpr] call to init()
179+
# 35| getFunction(): [DeclRefExpr] init()
180+
# 35| getArgument(0): [Argument] : Bar.Type
181+
# 35| getExpr(): [TypeExpr] Bar.Type
182+
# 35| getTypeRepr(): [TypeRepr] Bar
183+
# 37| getElement(3): [CallExpr] call to instanceMethod()
184+
# 37| getFunction(): [MethodRefExpr] .instanceMethod()
185+
# 37| getBase(): [DeclRefExpr] bar
186+
# 37| getElement(3).getFullyConverted(): [AwaitExpr] await ...
187+
# 40| getElement(4): [CallExpr] call to staticMethod()
188+
# 40| getFunction(): [MethodRefExpr] .staticMethod()
189+
# 40| getBase(): [TypeExpr] Bar.Type
190+
# 40| getTypeRepr(): [TypeRepr] Bar
191+
# 33| [NilLiteralExpr] nil
192+
# 38| [Comment] // Bar.instanceMethod(bar2)() // error: actor-isolated instance method 'instanceMethod()' can not be referenced from a non-isolated context
193+
# 38|
194+
# 43| [TopLevelCodeDecl] { ... }
195+
# 43| getBody(): [BraceStmt] { ... }
196+
# 43| getElement(0): [CallExpr] call to init(priority:operation:)
197+
# 43| getFunction(): [ConstructorRefCallExpr] call to init(priority:operation:)
198+
# 43| getFunction(): [DeclRefExpr] init(priority:operation:)
199+
# 43| getArgument(0): [Argument] : Task<(), Never>.Type
200+
# 43| getExpr(): [TypeExpr] Task<(), Never>.Type
201+
# 43| getTypeRepr(): [TypeRepr] Task<(), Never>
202+
# 43| getArgument(0): [Argument] priority: default priority
203+
# 43| getExpr(): [DefaultArgumentExpr] default priority
204+
# 43| getArgument(1): [Argument] operation: { ... }
205+
# 43| getExpr(): [ClosureExpr] { ... }
206+
# 43| getBody(): [BraceStmt] { ... }
207+
# 44| getElement(0): [PatternBindingDecl] var ... = ...
208+
# 44| getInit(0): [CallExpr] call to init()
209+
# 44| getFunction(): [ConstructorRefCallExpr] call to init()
210+
# 44| getFunction(): [DeclRefExpr] init()
211+
# 44| getFunction().getFullyConverted(): [FunctionConversionExpr] ((Baz.Type) -> @MainActor () -> Baz) ...
212+
# 44| getArgument(0): [Argument] : Baz.Type
213+
# 44| getExpr(): [TypeExpr] Baz.Type
214+
# 44| getTypeRepr(): [TypeRepr] Baz
215+
# 44| getInit(0).getFullyConverted(): [AwaitExpr] await ...
216+
# 44| getPattern(0): [NamedPattern] baz
217+
# 44| getElement(1): [ConcreteVarDecl] baz
218+
# 44| Type = Baz
219+
# 45| getElement(2): [AssignExpr] ... = ...
220+
# 45| getDest(): [DiscardAssignmentExpr] _
221+
# 45| getSource(): [CallExpr] call to init()
222+
# 45| getFunction(): [ConstructorRefCallExpr] call to init()
223+
# 45| getFunction(): [DeclRefExpr] init()
224+
# 45| getFunction().getFullyConverted(): [FunctionConversionExpr] ((Baz.Type) -> @MainActor () -> Baz) ...
225+
# 45| getArgument(0): [Argument] : Baz.Type
226+
# 45| getExpr(): [TypeExpr] Baz.Type
227+
# 45| getTypeRepr(): [TypeRepr] Baz
228+
# 45| getSource().getFullyConverted(): [AwaitExpr] await ...
229+
# 47| getElement(3): [CallExpr] call to ...
230+
# 47| getFunction(): [DotSyntaxCallExpr] call to instanceMethod()
231+
# 47| getFunction(): [DeclRefExpr] instanceMethod()
232+
# 47| getFunction().getFullyConverted(): [FunctionConversionExpr] ((Baz) -> @MainActor () -> ()) ...
233+
# 47| getArgument(0): [Argument] : baz
234+
# 47| getExpr(): [DeclRefExpr] baz
235+
# 47| getElement(3).getFullyConverted(): [AwaitExpr] await ...
236+
# 48| getElement(4): [CallExpr] call to ...
237+
# 48| getFunction(): [CallExpr] call to ...
238+
# 48| getFunction(): [DotSyntaxBaseIgnoredExpr] .{ ... }
239+
# 48| getQualifier(): [TypeExpr] Baz.Type
240+
# 48| getTypeRepr(): [TypeRepr] Baz
241+
# 48| getSubExpr(): [AutoClosureExpr] { ... }
242+
#-----| getParam(0): [ParamDecl] self
243+
#-----| Type = Baz
244+
# 48| getBody(): [BraceStmt] { ... }
245+
# 48| getElement(0): [ReturnStmt] return ...
246+
# 48| getResult(): [AutoClosureExpr] { ... }
247+
# 48| getBody(): [BraceStmt] { ... }
248+
# 48| getElement(0): [ReturnStmt] return ...
249+
# 48| getResult(): [CallExpr] call to instanceMethod()
250+
# 48| getFunction(): [MethodRefExpr] .instanceMethod()
251+
#-----| getBase(): [DeclRefExpr] self
252+
# 48| getArgument(0): [Argument] : baz
253+
# 48| getExpr(): [DeclRefExpr] baz
254+
# 48| getElement(4).getFullyConverted(): [AwaitExpr] await ...
255+
# 50| getElement(5): [CallExpr] call to ...
256+
# 50| getFunction(): [DotSyntaxCallExpr] call to classMethod()
257+
# 50| getFunction(): [DeclRefExpr] classMethod()
258+
# 50| getFunction().getFullyConverted(): [FunctionConversionExpr] ((Baz.Type) -> @MainActor () -> ()) ...
259+
# 50| getArgument(0): [Argument] : Baz.Type
260+
# 50| getExpr(): [TypeExpr] Baz.Type
261+
# 50| getTypeRepr(): [TypeRepr] Baz
262+
# 50| getElement(5).getFullyConverted(): [AwaitExpr] await ...
263+
# 51| getElement(6): [CallExpr] call to ...
264+
# 51| getFunction(): [DotSyntaxCallExpr] call to staticMethod()
265+
# 51| getFunction(): [DeclRefExpr] staticMethod()
266+
# 51| getFunction().getFullyConverted(): [FunctionConversionExpr] ((Baz.Type) -> @MainActor () -> ()) ...
267+
# 51| getArgument(0): [Argument] : Baz.Type
268+
# 51| getExpr(): [TypeExpr] Baz.Type
269+
# 51| getTypeRepr(): [TypeRepr] Baz
270+
# 51| getElement(6).getFullyConverted(): [AwaitExpr] await ...
271+
# 43| [NilLiteralExpr] nil
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
library-tests/ast/PrintAst.ql
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
class Foo {
2+
init() {}
3+
func instanceMethod() {}
4+
static func staticMethod() {}
5+
class func classMethod() {}
6+
}
7+
8+
actor Bar {
9+
init() {}
10+
func instanceMethod() {}
11+
static func staticMethod() {}
12+
}
13+
14+
@MainActor
15+
class Baz {
16+
init() {}
17+
func instanceMethod() {}
18+
static func staticMethod() {}
19+
class func classMethod() {}
20+
}
21+
22+
do {
23+
let foo = Foo()
24+
_ = Foo.init()
25+
26+
foo.instanceMethod()
27+
Foo.instanceMethod(foo)()
28+
29+
Foo.classMethod()
30+
Foo.staticMethod()
31+
}
32+
33+
Task {
34+
let bar = Bar()
35+
_ = Bar.init()
36+
37+
await bar.instanceMethod()
38+
// Bar.instanceMethod(bar2)() // error: actor-isolated instance method 'instanceMethod()' can not be referenced from a non-isolated context
39+
40+
Bar.staticMethod()
41+
}
42+
43+
Task {
44+
let baz = await Baz()
45+
_ = await Baz.init()
46+
47+
await baz.instanceMethod()
48+
await Baz.instanceMethod(baz)()
49+
50+
await Baz.classMethod()
51+
await Baz.staticMethod()
52+
}

0 commit comments

Comments
 (0)