Skip to content

Commit 98690c8

Browse files
committed
add support for class signatures in parameterized modules
1 parent e5d3a8f commit 98690c8

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

ql/ql/src/codeql_ql/ast/Ast.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,6 +2257,12 @@ class SignatureExpr extends TSignatureExpr, AstNode {
22572257

22582258
/** Gets the generated AST node that contains this signature expression. */
22592259
QL::SignatureExpr toQL() { result = sig }
2260+
2261+
/** Gets this signature expression if it represents a predicate expression. */
2262+
PredicateExpr asPredicate() { result = this }
2263+
2264+
/** Gets this signature expression if it represents a type expression. */
2265+
TypeExpr asType() { result = this }
22602266
}
22612267

22622268
/** An argument to an annotation. */

ql/ql/src/codeql_ql/ast/internal/Type.qll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,23 @@ private predicate defines(FileOrModule m, string name, Type t, boolean public) {
323323
public = getPublicBool(im) and
324324
defines(im.getResolvedModule(), name, t, true)
325325
)
326+
or
327+
// classes in parameterized modules.
328+
exists(Module mod, SignatureExpr param, int i |
329+
m.asModule() = mod and
330+
mod.hasParameter(i, name, param) and
331+
public = true
332+
|
333+
// we resolve it both to the signature type
334+
t = param.asType().getResolvedType()
335+
or
336+
// or any instantiated type
337+
exists(ModuleExpr inst, SignatureExpr arg |
338+
inst.getArgument(i) = arg and
339+
inst.getResolvedModule() = m and
340+
t = arg.asType().getResolvedType()
341+
)
342+
)
326343
}
327344

328345
module TyConsistency {

ql/ql/test/callgraph/ParamModules.qll

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,19 @@ module PredicateSig {
1111
}
1212

1313
module ClassSig {
14-
// TODO:
14+
signature class FooSig extends int;
15+
16+
module UsesFoo<FooSig FooImpl> {
17+
FooImpl getAnEven() { result % 2 = 0 }
18+
}
19+
20+
class MyFoo extends int {
21+
MyFoo() { this = [0 .. 10] }
22+
23+
string myFoo() { result = "myFoo" }
24+
}
25+
26+
string use() { result = UsesFoo<MyFoo>::getAnEven().myFoo() }
1527
}
1628

1729
module ModuleSig {

ql/ql/test/callgraph/callgraph.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ getTarget
2323
| Overrides.qll:29:3:29:10 | MemberCall | Overrides.qll:8:3:8:41 | ClassPredicate baz |
2424
| ParamModules.qll:5:28:5:41 | PredicateCall | ParamModules.qll:2:13:2:36 | ClasslessPredicate fooSig |
2525
| ParamModules.qll:10:26:10:49 | PredicateCall | ParamModules.qll:5:5:5:43 | ClasslessPredicate bar |
26+
| ParamModules.qll:26:27:26:53 | PredicateCall | ParamModules.qll:17:5:17:42 | ClasslessPredicate getAnEven |
27+
| ParamModules.qll:26:27:26:61 | MemberCall | ParamModules.qll:23:5:23:39 | ClassPredicate myFoo |
2628
| packs/other/OtherThing.qll:5:3:5:8 | PredicateCall | packs/lib/LibThing/Foo.qll:1:1:1:30 | ClasslessPredicate foo |
2729
| packs/other/OtherThing.qll:6:3:6:8 | PredicateCall | packs/src/SrcThing.qll:8:1:8:30 | ClasslessPredicate bar |
2830
| packs/src/SrcThing.qll:4:3:4:8 | PredicateCall | packs/lib/LibThing/Foo.qll:1:1:1:30 | ClasslessPredicate foo |

0 commit comments

Comments
 (0)