Skip to content

Commit 4900e40

Browse files
committed
Swift: MethodLookupExpr.getMethodRef() [hand-written]
This refactors SelfApplyExpr.getFunction() as MethodLookupExpr().getMethodRef(). This is simpler, because we are not hiding DeclRefExprs or reinventing hidden AST resolution.
1 parent 1c64bf4 commit 4900e40

File tree

6 files changed

+15
-29
lines changed

6 files changed

+15
-29
lines changed

swift/ql/lib/codeql/swift/elements/expr/ArgumentConstructor.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ private import codeql.swift.elements.expr.MethodLookupExpr
44
predicate constructArgument(Raw::Argument id) {
55
// exclude an argument that will be part of a SelfApplyExpr
66
// that will be transformed into a MethodLookupExpr
7-
not exists(Raw::SelfApplyExpr e | id.getExpr() = e.getBase())
7+
not exists(Raw::SelfApplyExpr e | id = e.getArgument(0))
88
}
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1+
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
12
private import codeql.swift.generated.Raw
2-
private import codeql.swift.elements.expr.MethodLookupExprConstructor
33

4-
predicate constructDeclRefExpr(Raw::DeclRefExpr id) {
5-
// exclude an argument that will be part of a SelfApplyExpr
6-
// that will be transformed into a MethodLookupExpr
7-
not exists(Raw::SelfApplyExpr e | id.getDecl() = extractDeclFromSelfApplyExpr(e))
8-
}
4+
predicate constructDeclRefExpr(Raw::DeclRefExpr id) { any() }

swift/ql/lib/codeql/swift/elements/expr/MethodLookupExpr.qll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
private import codeql.swift.generated.expr.MethodLookupExpr
22
private import codeql.swift.elements.expr.MethodLookupExprConstructor
33
private import codeql.swift.elements.expr.Expr
4+
private import codeql.swift.elements.expr.DeclRefExpr
5+
private import codeql.swift.elements.expr.OtherConstructorDeclRefExpr
46
private import codeql.swift.elements.decl.Decl
57
private import codeql.swift.elements.decl.MethodDecl
68
private import codeql.swift.generated.Raw
@@ -14,7 +16,13 @@ class MethodLookupExpr extends Generated::MethodLookupExpr {
1416
}
1517

1618
override Decl getImmediateMember() {
17-
result = Synth::convertDeclFromRaw(extractDeclFromSelfApplyExpr(this.getUnderlying()))
19+
result = this.getMethodRef().(DeclRefExpr).getDecl()
20+
or
21+
result = this.getMethodRef().(OtherConstructorDeclRefExpr).getConstructorDecl()
22+
}
23+
24+
override Expr getImmediateMethodRef() {
25+
result = Synth::convertExprFromRaw(this.getUnderlying().getFunction())
1826
}
1927

2028
MethodDecl getMethod() { result = this.getMember() }
Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
11
private import codeql.swift.generated.Raw
22

33
predicate constructMethodLookupExpr(Raw::SelfApplyExpr id) { any() }
4-
5-
Raw::Decl extractDeclFromSelfApplyExpr(Raw::SelfApplyExpr e) {
6-
exists(Raw::Expr unwrappedFunction | unwrappedFunction = unwrapConversion*(e.getFunction()) |
7-
result =
8-
[
9-
unwrappedFunction.(Raw::DeclRefExpr).getDecl(),
10-
unwrappedFunction.(Raw::OtherConstructorDeclRefExpr).getConstructorDecl()
11-
]
12-
)
13-
}
14-
15-
private Raw::Expr unwrapConversion(Raw::Expr e) {
16-
e.(Raw::ImplicitConversionExpr).getSubExpr() = result
17-
}
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1+
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
12
private import codeql.swift.generated.Raw
2-
private import codeql.swift.elements.expr.MethodLookupExprConstructor
33

4-
predicate constructOtherConstructorDeclRefExpr(Raw::OtherConstructorDeclRefExpr id) {
5-
// exclude an argument that will be part of a SelfApplyExpr
6-
// that will be transformed into a MethodLookupExpr
7-
not exists(Raw::SelfApplyExpr e | id.getConstructorDecl() = extractDeclFromSelfApplyExpr(e))
8-
}
4+
predicate constructOtherConstructorDeclRefExpr(Raw::OtherConstructorDeclRefExpr id) { any() }

swift/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ class DotSyntaxCallExpr(SelfApplyExpr):
677677

678678
@synth.from_class(SelfApplyExpr)
679679
class MethodLookupExpr(LookupExpr):
680-
pass
680+
method_ref: Expr | child | doc("the underlying method declaration reference expression")
681681

682682
class DynamicMemberRefExpr(DynamicLookupExpr):
683683
pass

0 commit comments

Comments
 (0)