mirror of
https://github.com/github/codeql.git
synced 2025-12-17 09:13:20 +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());
|
entry.possible_declarations = dispatcher.fetchRepeatedLabels(expr.getDecls());
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
codeql::DynamicMemberRefExpr ExprTranslator::translateDynamicMemberRefExpr(
|
codeql::DynamicMemberRefExpr ExprTranslator::translateDynamicMemberRefExpr(
|
||||||
const swift::DynamicMemberRefExpr& expr) {
|
const swift::DynamicMemberRefExpr& expr) {
|
||||||
auto entry = createExprEntry(expr);
|
auto entry = createExprEntry(expr);
|
||||||
@@ -550,4 +551,11 @@ codeql::DynamicMemberRefExpr ExprTranslator::translateDynamicMemberRefExpr(
|
|||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
codeql::DynamicSubscriptExpr ExprTranslator::translateDynamicSubscriptExpr(
|
||||||
|
const swift::DynamicSubscriptExpr& expr) {
|
||||||
|
auto entry = createExprEntry(expr);
|
||||||
|
fillLookupExpr(expr, entry);
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace codeql
|
} // namespace codeql
|
||||||
|
|||||||
@@ -107,6 +107,8 @@ class ExprTranslator : public AstTranslatorBase<ExprTranslator> {
|
|||||||
const swift::OverloadedDeclRefExpr& expr);
|
const swift::OverloadedDeclRefExpr& expr);
|
||||||
codeql::DynamicMemberRefExpr translateDynamicMemberRefExpr(
|
codeql::DynamicMemberRefExpr translateDynamicMemberRefExpr(
|
||||||
const swift::DynamicMemberRefExpr& expr);
|
const swift::DynamicMemberRefExpr& expr);
|
||||||
|
codeql::DynamicSubscriptExpr translateDynamicSubscriptExpr(
|
||||||
|
const swift::DynamicSubscriptExpr& expr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void fillAbstractClosureExpr(const swift::AbstractClosureExpr& expr,
|
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 codeql.swift.elements
|
||||||
import TestUtils
|
import TestUtils
|
||||||
|
|
||||||
from DynamicMemberRefExpr x, Expr getBase
|
from DynamicLookupExpr x, Expr getBase
|
||||||
where
|
where
|
||||||
toBeTested(x) and
|
toBeTested(x) and
|
||||||
not x.isUnknown() and
|
not x.isUnknown() and
|
||||||
getBase = x.getBase()
|
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 codeql.swift.elements
|
||||||
import TestUtils
|
import TestUtils
|
||||||
|
|
||||||
from DynamicMemberRefExpr x
|
from DynamicLookupExpr x
|
||||||
where toBeTested(x) and not x.isUnknown()
|
where toBeTested(x) and not x.isUnknown()
|
||||||
select x, x.getMember()
|
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 codeql.swift.elements
|
||||||
import TestUtils
|
import TestUtils
|
||||||
|
|
||||||
from DynamicMemberRefExpr x
|
from DynamicLookupExpr x
|
||||||
where toBeTested(x) and not x.isUnknown()
|
where toBeTested(x) and not x.isUnknown()
|
||||||
select x, x.getType()
|
select x, x.getType()
|
||||||
@@ -4,9 +4,13 @@
|
|||||||
// Successful compilation would require importing Foundation for `@objc`
|
// Successful compilation would require importing Foundation for `@objc`
|
||||||
class A {
|
class A {
|
||||||
@objc func foo(_ : Int) {}
|
@objc func foo(_ : Int) {}
|
||||||
|
@objc subscript(i : Int) -> Int {
|
||||||
|
get { return 0 }
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class B {}
|
class B {}
|
||||||
|
|
||||||
var x : AnyObject = B()
|
var x : AnyObject = B()
|
||||||
x.foo!(17)
|
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):
|
class DotSelfExpr(IdentityExpr):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@qltest.collapse_hierarchy
|
||||||
class DynamicLookupExpr(LookupExpr):
|
class DynamicLookupExpr(LookupExpr):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user