mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
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.
This commit is contained in:
@@ -4,5 +4,5 @@ private import codeql.swift.elements.expr.MethodLookupExpr
|
||||
predicate constructArgument(Raw::Argument id) {
|
||||
// exclude an argument that will be part of a SelfApplyExpr
|
||||
// that will be transformed into a MethodLookupExpr
|
||||
not exists(Raw::SelfApplyExpr e | id.getExpr() = e.getBase())
|
||||
not exists(Raw::SelfApplyExpr e | id = e.getArgument(0))
|
||||
}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
|
||||
private import codeql.swift.generated.Raw
|
||||
private import codeql.swift.elements.expr.MethodLookupExprConstructor
|
||||
|
||||
predicate constructDeclRefExpr(Raw::DeclRefExpr id) {
|
||||
// exclude an argument that will be part of a SelfApplyExpr
|
||||
// that will be transformed into a MethodLookupExpr
|
||||
not exists(Raw::SelfApplyExpr e | id.getDecl() = extractDeclFromSelfApplyExpr(e))
|
||||
}
|
||||
predicate constructDeclRefExpr(Raw::DeclRefExpr id) { any() }
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
private import codeql.swift.generated.expr.MethodLookupExpr
|
||||
private import codeql.swift.elements.expr.MethodLookupExprConstructor
|
||||
private import codeql.swift.elements.expr.Expr
|
||||
private import codeql.swift.elements.expr.DeclRefExpr
|
||||
private import codeql.swift.elements.expr.OtherConstructorDeclRefExpr
|
||||
private import codeql.swift.elements.decl.Decl
|
||||
private import codeql.swift.elements.decl.MethodDecl
|
||||
private import codeql.swift.generated.Raw
|
||||
@@ -14,7 +16,13 @@ class MethodLookupExpr extends Generated::MethodLookupExpr {
|
||||
}
|
||||
|
||||
override Decl getImmediateMember() {
|
||||
result = Synth::convertDeclFromRaw(extractDeclFromSelfApplyExpr(this.getUnderlying()))
|
||||
result = this.getMethodRef().(DeclRefExpr).getDecl()
|
||||
or
|
||||
result = this.getMethodRef().(OtherConstructorDeclRefExpr).getConstructorDecl()
|
||||
}
|
||||
|
||||
override Expr getImmediateMethodRef() {
|
||||
result = Synth::convertExprFromRaw(this.getUnderlying().getFunction())
|
||||
}
|
||||
|
||||
MethodDecl getMethod() { result = this.getMember() }
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
private import codeql.swift.generated.Raw
|
||||
|
||||
predicate constructMethodLookupExpr(Raw::SelfApplyExpr id) { any() }
|
||||
|
||||
Raw::Decl extractDeclFromSelfApplyExpr(Raw::SelfApplyExpr e) {
|
||||
exists(Raw::Expr unwrappedFunction | unwrappedFunction = unwrapConversion*(e.getFunction()) |
|
||||
result =
|
||||
[
|
||||
unwrappedFunction.(Raw::DeclRefExpr).getDecl(),
|
||||
unwrappedFunction.(Raw::OtherConstructorDeclRefExpr).getConstructorDecl()
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
private Raw::Expr unwrapConversion(Raw::Expr e) {
|
||||
e.(Raw::ImplicitConversionExpr).getSubExpr() = result
|
||||
}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
|
||||
private import codeql.swift.generated.Raw
|
||||
private import codeql.swift.elements.expr.MethodLookupExprConstructor
|
||||
|
||||
predicate constructOtherConstructorDeclRefExpr(Raw::OtherConstructorDeclRefExpr id) {
|
||||
// exclude an argument that will be part of a SelfApplyExpr
|
||||
// that will be transformed into a MethodLookupExpr
|
||||
not exists(Raw::SelfApplyExpr e | id.getConstructorDecl() = extractDeclFromSelfApplyExpr(e))
|
||||
}
|
||||
predicate constructOtherConstructorDeclRefExpr(Raw::OtherConstructorDeclRefExpr id) { any() }
|
||||
|
||||
@@ -677,7 +677,7 @@ class DotSyntaxCallExpr(SelfApplyExpr):
|
||||
|
||||
@synth.from_class(SelfApplyExpr)
|
||||
class MethodLookupExpr(LookupExpr):
|
||||
pass
|
||||
method_ref: Expr | child | doc("the underlying method declaration reference expression")
|
||||
|
||||
class DynamicMemberRefExpr(DynamicLookupExpr):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user