mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
Swift: fix PrintAst order, double parents, orphan decl refs
The main problem is that a lot of the old DotSyntaxApplyExpr->MethodRefExpr synth-constructor hacks were not fully generalized to SelfApplyExpr and OtherConstructorDeclRefExpr. Also: - Gave a index-in-parent-based ordering to PrintAst nodes(), to stabilize it more. - Use a slightly more general SelfApplyExpr->Decl conversion
This commit is contained in:
@@ -173,7 +173,6 @@ ql/lib/codeql/swift/elements/expr/OpenExistentialExprConstructor.qll c56e5e6f7ae
|
||||
ql/lib/codeql/swift/elements/expr/OptionalEvaluationExpr.qll 2f46c15d17a50b14e91552be8ac5b72dbdc9f39b8fac9fa068e519ae5c8aa99b 559902efedbf4c5ef24697267c7b48162129b4ab463b41d89bdfb8b94742fa9f
|
||||
ql/lib/codeql/swift/elements/expr/OptionalEvaluationExprConstructor.qll 4ba0af8f8b4b7920bc1106d069455eb754b7404d9a4bfc361d2ea22e8763f4fe 6d07e7838339290d1a2aec88addd511f01224d7e1d485b08ef4793e01f4b4421
|
||||
ql/lib/codeql/swift/elements/expr/OptionalTryExprConstructor.qll 60d2f88e2c6fc843353cc52ce1e1c9f7b80978750d0e780361f817b1b2fea895 4eabd9f03dc5c1f956e50e2a7af0535292484acc69692d7c7f771e213609fd04
|
||||
ql/lib/codeql/swift/elements/expr/OtherConstructorDeclRefExprConstructor.qll cf726ed7ed830e17aaedf1acddf1edc4efc7d72ab9f9580bc89cc8eefbd54d8a 4ef3010dc5500bd503db8aa531d5455a9c80bc30172fb005abc6459b6f66ea00
|
||||
ql/lib/codeql/swift/elements/expr/OverloadedDeclRefExpr.qll adb49e25cdd87d2e6259399a7ce3a1fbe6eb345f9b8f4e34eb23cb39eb3555da 47b1c6df5397de490f62e96edc0656b1f97c0be73c6b99ecd78b62d46106ce61
|
||||
ql/lib/codeql/swift/elements/expr/OverloadedDeclRefExprConstructor.qll 2cf79b483f942fbf8aaf9956429b92bf9536e212bb7f7940c2bc1d30e8e8dfd5 f4c16a90e3ab944dded491887779f960e3077f0a8823f17f50f82cf5b9803737
|
||||
ql/lib/codeql/swift/elements/expr/ParenExprConstructor.qll 6baaa592db57870f5ecd9be632bd3f653c44d72581efd41e8a837916e1590f9e 6f28988d04b2cb69ddcb63fba9ae3166b527803a61c250f97e48ff39a28379f6
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
private import codeql.swift.generated.Raw
|
||||
private import codeql.swift.elements.expr.MethodLookupExpr
|
||||
|
||||
predicate constructArgument(Raw::Argument id) {
|
||||
// exclude an argument that will be part of a DotSyntaxCallExpr
|
||||
// that will be transformed into a MethodRefCallExpr
|
||||
not exists(Raw::DotSyntaxCallExpr c |
|
||||
c.getFunction() instanceof Raw::DeclRefExpr and id = c.getArgument(0)
|
||||
)
|
||||
// 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())
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
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 DotSyntaxCallExpr
|
||||
// that will be transformed into a MethodRefCallExpr
|
||||
not exists(Raw::DotSyntaxCallExpr c | id = c.getFunction())
|
||||
// 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))
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
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.decl.Decl
|
||||
private import codeql.swift.elements.decl.MethodDecl
|
||||
@@ -13,17 +14,7 @@ class MethodLookupExpr extends Generated::MethodLookupExpr {
|
||||
}
|
||||
|
||||
override Decl getImmediateMember() {
|
||||
result =
|
||||
Synth::convertDeclFromRaw([
|
||||
this.getUnderlying().getFunction().(Raw::DeclRefExpr).getDecl(),
|
||||
this.getUnderlying()
|
||||
.getFunction()
|
||||
.(Raw::FunctionConversionExpr)
|
||||
.getSubExpr()
|
||||
.(Raw::DeclRefExpr)
|
||||
.getDecl(),
|
||||
this.getUnderlying().getFunction().(Raw::OtherConstructorDeclRefExpr).getConstructorDecl()
|
||||
])
|
||||
result = Synth::convertDeclFromRaw(extractDeclFromSelfApplyExpr(this.getUnderlying()))
|
||||
}
|
||||
|
||||
MethodDecl getMethod() { result = this.getMember() }
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
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,4 +1,8 @@
|
||||
// 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) { any() }
|
||||
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))
|
||||
}
|
||||
|
||||
@@ -7,13 +7,19 @@ import PrintAstNode
|
||||
cached
|
||||
private int getOrder(PrintAstNode node) {
|
||||
node =
|
||||
rank[result](PrintAstNode n, Location loc |
|
||||
loc = n.getLocation()
|
||||
rank[result](PrintAstNode n, Location loc, int index, string accessor |
|
||||
loc = n.getLocation() and
|
||||
if any(PrintAstNode p).hasChild(n, index, accessor)
|
||||
then any()
|
||||
else (
|
||||
index = -1 and
|
||||
accessor = ""
|
||||
)
|
||||
|
|
||||
n
|
||||
order by
|
||||
loc.getFile().getName(), loc.getStartLine(), loc.getStartColumn(), loc.getEndLine(),
|
||||
loc.getEndColumn()
|
||||
loc.getEndColumn(), index, accessor
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user