Skip to content

Commit cf0fc58

Browse files
committed
Swift: extract extension declarations
1 parent f7cc46b commit cf0fc58

File tree

7 files changed

+40
-2
lines changed

7 files changed

+40
-2
lines changed

swift/extractor/visitors/DeclVisitor.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ class DeclVisitor : public AstVisitorBase<DeclVisitor> {
193193
emitAbstractStorageDecl(decl, label);
194194
}
195195

196+
void visitExtensionDecl(swift::ExtensionDecl* decl) {
197+
auto label = dispatcher_.assignNewLabel(decl);
198+
dispatcher_.emit(ExtensionDeclsTrap{label});
199+
emitGenericContext(decl, label);
200+
emitIterableDeclContext(decl, label);
201+
}
202+
196203
private:
197204
void emitConstructorDecl(swift::ConstructorDecl* decl, TrapLabel<ConstructorDeclTag> label) {
198205
emitAbstractFunctionDecl(decl, label);

swift/ql/test/extractor-tests/declarations/all.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,7 @@
205205
| declarations.swift:132:5:132:5 | newValue |
206206
| declarations.swift:132:5:132:15 | willSet |
207207
| declarations.swift:134:5:134:14 | didSet |
208+
| declarations.swift:138:1:142:1 | extension |
209+
| declarations.swift:139:3:141:3 | id |
210+
| declarations.swift:139:8:139:8 | self |
211+
| declarations.swift:144:1:144:7 | { ... } |

swift/ql/test/extractor-tests/declarations/declarations.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,13 @@ struct HasPropertyAndObserver {
133133

134134
didSet { }
135135
}
136-
}
136+
}
137+
138+
extension Int {
139+
func id() -> Int {
140+
return self
141+
}
142+
}
143+
144+
42.id()
145+

swift/ql/test/extractor-tests/declarations/func.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@
5555
| declarations.swift:131:7:131:7 | set | (unnamed function decl) |
5656
| declarations.swift:132:5:132:15 | willSet | (unnamed function decl) |
5757
| declarations.swift:134:5:134:14 | didSet | (unnamed function decl) |
58+
| declarations.swift:139:3:141:3 | id | id |

swift/ql/test/extractor-tests/declarations/func_body.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@
5050
| declarations.swift:131:7:131:7 | set | declarations.swift:131:7:131:7 | { ... } |
5151
| declarations.swift:132:5:132:15 | willSet | declarations.swift:132:13:132:15 | { ... } |
5252
| declarations.swift:134:5:134:14 | didSet | declarations.swift:134:12:134:14 | { ... } |
53+
| declarations.swift:139:3:141:3 | id | declarations.swift:139:20:141:3 | { ... } |

swift/ql/test/library-tests/parent/declarations.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,13 @@ struct HasPropertyAndObserver {
133133

134134
didSet { }
135135
}
136-
}
136+
}
137+
138+
extension Int {
139+
func id() -> Int {
140+
return self
141+
}
142+
}
143+
144+
42.id()
145+

swift/ql/test/library-tests/parent/parent.expected

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,13 @@
326326
| declarations.swift:132:5:132:15 | willSet | AccessorDecl | declarations.swift:132:5:132:5 | newValue | ParamDecl |
327327
| declarations.swift:132:5:132:15 | willSet | AccessorDecl | declarations.swift:132:13:132:15 | { ... } | BraceStmt |
328328
| declarations.swift:134:5:134:14 | didSet | AccessorDecl | declarations.swift:134:12:134:14 | { ... } | BraceStmt |
329+
| declarations.swift:139:3:141:3 | id | ConcreteFuncDecl | declarations.swift:139:20:141:3 | { ... } | BraceStmt |
330+
| declarations.swift:139:20:141:3 | { ... } | BraceStmt | declarations.swift:140:5:140:12 | return ... | ReturnStmt |
331+
| declarations.swift:140:5:140:12 | return ... | ReturnStmt | declarations.swift:140:12:140:12 | self | DeclRefExpr |
332+
| declarations.swift:144:1:144:4 | call to id | DotSyntaxCallExpr | declarations.swift:144:4:144:4 | id | DeclRefExpr |
333+
| declarations.swift:144:1:144:7 | call to ... | CallExpr | declarations.swift:144:1:144:4 | call to id | DotSyntaxCallExpr |
334+
| declarations.swift:144:1:144:7 | { ... } | BraceStmt | declarations.swift:144:1:144:7 | call to ... | CallExpr |
335+
| declarations.swift:144:1:144:7 | { ... } | TopLevelCodeDecl | declarations.swift:144:1:144:7 | { ... } | BraceStmt |
329336
| expressions.swift:1:1:1:9 | var ... = ... | PatternBindingDecl | expressions.swift:1:5:1:5 | a | NamedPattern |
330337
| expressions.swift:1:1:1:9 | var ... = ... | PatternBindingDecl | expressions.swift:1:9:1:9 | 15 | IntegerLiteralExpr |
331338
| expressions.swift:1:1:1:9 | { ... } | BraceStmt | expressions.swift:1:1:1:9 | var ... = ... | PatternBindingDecl |

0 commit comments

Comments
 (0)