mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Swift: extract DynamicLookupExpr
This commit is contained in:
@@ -543,6 +543,7 @@ codeql::OverloadedDeclRefExpr ExprTranslator::translateOverloadedDeclRefExpr(
|
||||
entry.possible_declarations = dispatcher.fetchRepeatedLabels(expr.getDecls());
|
||||
return entry;
|
||||
}
|
||||
|
||||
codeql::DynamicMemberRefExpr ExprTranslator::translateDynamicMemberRefExpr(
|
||||
const swift::DynamicMemberRefExpr& expr) {
|
||||
auto entry = createExprEntry(expr);
|
||||
@@ -550,4 +551,11 @@ codeql::DynamicMemberRefExpr ExprTranslator::translateDynamicMemberRefExpr(
|
||||
return entry;
|
||||
}
|
||||
|
||||
codeql::DynamicSubscriptExpr ExprTranslator::translateDynamicSubscriptExpr(
|
||||
const swift::DynamicSubscriptExpr& expr) {
|
||||
auto entry = createExprEntry(expr);
|
||||
fillLookupExpr(expr, entry);
|
||||
return entry;
|
||||
}
|
||||
|
||||
} // namespace codeql
|
||||
|
||||
@@ -107,6 +107,8 @@ class ExprTranslator : public AstTranslatorBase<ExprTranslator> {
|
||||
const swift::OverloadedDeclRefExpr& expr);
|
||||
codeql::DynamicMemberRefExpr translateDynamicMemberRefExpr(
|
||||
const swift::DynamicMemberRefExpr& expr);
|
||||
codeql::DynamicSubscriptExpr translateDynamicSubscriptExpr(
|
||||
const swift::DynamicSubscriptExpr& expr);
|
||||
|
||||
private:
|
||||
void fillAbstractClosureExpr(const swift::AbstractClosureExpr& expr,
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
| dynamic_lookup.swift:15:1:15:3 | .foo(_:) | DynamicMemberRefExpr | getBase: | dynamic_lookup.swift:15:1:15:1 | OpaqueValueExpr |
|
||||
| dynamic_lookup.swift:16:5:16:9 | subscript ...[...] | DynamicSubscriptExpr | getBase: | dynamic_lookup.swift:16:5:16:5 | OpaqueValueExpr |
|
||||
@@ -2,9 +2,9 @@
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from DynamicMemberRefExpr x, Expr getBase
|
||||
from DynamicLookupExpr x, Expr getBase
|
||||
where
|
||||
toBeTested(x) and
|
||||
not x.isUnknown() and
|
||||
getBase = x.getBase()
|
||||
select x, "getBase:", getBase
|
||||
select x, x.getPrimaryQlClasses(), "getBase:", getBase
|
||||
@@ -0,0 +1,2 @@
|
||||
| dynamic_lookup.swift:15:1:15:3 | .foo(_:) | dynamic_lookup.swift:6:9:6:28 | foo(_:) |
|
||||
| dynamic_lookup.swift:16:5:16:9 | subscript ...[...] | dynamic_lookup.swift:7:9:9:3 | subscript ... |
|
||||
@@ -2,6 +2,6 @@
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from DynamicMemberRefExpr x
|
||||
from DynamicLookupExpr x
|
||||
where toBeTested(x) and not x.isUnknown()
|
||||
select x, x.getMember()
|
||||
@@ -0,0 +1,2 @@
|
||||
| dynamic_lookup.swift:15:1:15:3 | .foo(_:) | ((Int) -> ())? |
|
||||
| dynamic_lookup.swift:16:5:16:9 | subscript ...[...] | Int? |
|
||||
@@ -2,6 +2,6 @@
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from DynamicMemberRefExpr x
|
||||
from DynamicLookupExpr x
|
||||
where toBeTested(x) and not x.isUnknown()
|
||||
select x, x.getType()
|
||||
@@ -4,9 +4,13 @@
|
||||
// Successful compilation would require importing Foundation for `@objc`
|
||||
class A {
|
||||
@objc func foo(_ : Int) {}
|
||||
@objc subscript(i : Int) -> Int {
|
||||
get { return 0 }
|
||||
}
|
||||
};
|
||||
|
||||
class B {}
|
||||
|
||||
var x : AnyObject = B()
|
||||
x.foo!(17)
|
||||
_ = x[17]!
|
||||
@@ -1 +0,0 @@
|
||||
| dynamic_member_ref.swift:12:1:12:3 | .foo(_:) | getBase: | dynamic_member_ref.swift:12:1:12:1 | OpaqueValueExpr |
|
||||
@@ -1 +0,0 @@
|
||||
| dynamic_member_ref.swift:12:1:12:3 | .foo(_:) | dynamic_member_ref.swift:6:9:6:28 | foo(_:) |
|
||||
@@ -1 +0,0 @@
|
||||
| dynamic_member_ref.swift:12:1:12:3 | .foo(_:) | ((Int) -> ())? |
|
||||
@@ -1,4 +0,0 @@
|
||||
// generated by codegen/codegen.py
|
||||
|
||||
After a swift source file is added in this directory and codegen/codegen.py is run again, test queries
|
||||
will appear and this file will be deleted
|
||||
@@ -523,6 +523,7 @@ class DifferentiableFunctionExtractOriginalExpr(ImplicitConversionExpr):
|
||||
class DotSelfExpr(IdentityExpr):
|
||||
pass
|
||||
|
||||
@qltest.collapse_hierarchy
|
||||
class DynamicLookupExpr(LookupExpr):
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user