Skip to content

Commit 2329525

Browse files
committed
support signature parameters in QL-for-QL
1 parent 7a47551 commit 2329525

File tree

10 files changed

+44
-10
lines changed

10 files changed

+44
-10
lines changed

ql/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ql/extractor/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ edition = "2018"
1010
flate2 = "1.0"
1111
node-types = { path = "../node-types" }
1212
tree-sitter = ">= 0.20, < 0.21"
13-
tree-sitter-ql = { git = "https://github.com/tree-sitter/tree-sitter-ql.git", rev = "4b8078c7fdcce9d4ca06ce3cfec3a61e8c3f4555"}
13+
tree-sitter-ql = { git = "https://github.com/tree-sitter/tree-sitter-ql.git", rev = "d08db734f8dc52f6bc04db53a966603122bc6985"}
1414
tree-sitter-ql-dbscheme = { git = "https://github.com/erik-krogh/tree-sitter-ql-dbscheme.git", rev = "63e1344353f63931e88bfbc2faa2e78e1421b213"}
1515
tree-sitter-ql-yaml = {git = "https://github.com/erik-krogh/tree-sitter-ql.git", rev = "cf704bf3671e1ae148e173464fb65a4d2bbf5f99"}
1616
clap = "2.33"

ql/generator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ clap = "2.33"
1111
node-types = { path = "../node-types" }
1212
tracing = "0.1"
1313
tracing-subscriber = { version = "0.3.3", features = ["env-filter"] }
14-
tree-sitter-ql = { git = "https://github.com/tree-sitter/tree-sitter-ql.git", rev = "4b8078c7fdcce9d4ca06ce3cfec3a61e8c3f4555"}
14+
tree-sitter-ql = { git = "https://github.com/tree-sitter/tree-sitter-ql.git", rev = "d08db734f8dc52f6bc04db53a966603122bc6985"}
1515
tree-sitter-ql-dbscheme = { git = "https://github.com/erik-krogh/tree-sitter-ql-dbscheme.git", rev = "63e1344353f63931e88bfbc2faa2e78e1421b213"}
1616
tree-sitter-ql-yaml = {git = "https://github.com/erik-krogh/tree-sitter-ql.git", rev = "cf704bf3671e1ae148e173464fb65a4d2bbf5f99"}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,7 +2293,7 @@ class ModuleExpr extends TModuleExpr, TypeRef {
22932293

22942294
/**
22952295
* Gets the `i`th type argument if this module is a module instantiation.
2296-
* The result is either a `PredicateExpr` or a `TypeExpr`.
2296+
* The result is either a `PredicateExpr`, `TypeExpr`, or `ModuleExpr`.
22972297
*/
22982298
SignatureExpr getArgument(int i) {
22992299
result.toQL() = me.getAFieldOrChild().(QL::ModuleInstantiation).getChild(i)
@@ -2313,14 +2313,16 @@ class ModuleExpr extends TModuleExpr, TypeRef {
23132313
}
23142314
}
23152315

2316-
/** A signature expression, either a `PredicateExpr` or a `TypeExpr`. */
2316+
/** A signature expression, either a `PredicateExpr`, a `TypeExpr`, or a `ModuleExpr`. */
23172317
class SignatureExpr extends TSignatureExpr, AstNode {
23182318
QL::SignatureExpr sig;
23192319

23202320
SignatureExpr() {
23212321
toQL(this) = sig.getPredicate()
23222322
or
23232323
toQL(this) = sig.getTypeExpr()
2324+
or
2325+
toQL(this) = sig.getModExpr()
23242326
}
23252327

23262328
/** Gets the generated AST node that contains this signature expression. */
@@ -2329,8 +2331,8 @@ class SignatureExpr extends TSignatureExpr, AstNode {
23292331
/** Gets this signature expression if it represents a predicate expression. */
23302332
PredicateExpr asPredicate() { result = this }
23312333

2332-
/** Gets this signature expression if it represents a type expression. */
2333-
TypeExpr asType() { result = this }
2334+
/** Gets this signature expression if it represents a type expression (either a `TypeExpr` or a `ModuleExpr`). */
2335+
TypeRef asType() { result = this }
23342336
}
23352337

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class TTypeRef = TImport or TModuleExpr or TType;
8888

8989
class TYamlNode = TYamlCommemt or TYamlEntry or TYamlKey or TYamlListitem or TYamlValue;
9090

91-
class TSignatureExpr = TPredicateExpr or TType;
91+
class TSignatureExpr = TPredicateExpr or TType or TModuleExpr;
9292

9393
class TComment = TQLDoc or TBlockComment or TLineComment;
9494

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ private predicate definesModule(
314314
)
315315
or
316316
// signature module in a paramertized module
317-
exists(Module mod, SignatureExpr sig, TypeExpr ty, int i |
317+
exists(Module mod, SignatureExpr sig, TypeRef ty, int i |
318318
mod = container.asModule() and
319319
mod.hasParameter(i, name, sig) and
320320
public = false and

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,9 @@ module QL {
10691069
/** Gets the name of the primary QL class for this element. */
10701070
final override string getAPrimaryQlClass() { result = "SignatureExpr" }
10711071

1072+
/** Gets the node corresponding to the field `mod_expr`. */
1073+
final ModuleExpr getModExpr() { ql_signature_expr_mod_expr(this, result) }
1074+
10721075
/** Gets the node corresponding to the field `predicate`. */
10731076
final PredicateExpr getPredicate() { ql_signature_expr_predicate(this, result) }
10741077

@@ -1077,7 +1080,9 @@ module QL {
10771080

10781081
/** Gets a field or child node of this node. */
10791082
final override AstNode getAFieldOrChild() {
1080-
ql_signature_expr_predicate(this, result) or ql_signature_expr_type_expr(this, result)
1083+
ql_signature_expr_mod_expr(this, result) or
1084+
ql_signature_expr_predicate(this, result) or
1085+
ql_signature_expr_type_expr(this, result)
10811086
}
10821087
}
10831088

ql/ql/src/ql.dbscheme

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,11 @@ ql_set_literal_def(
737737
unique int id: @ql_set_literal
738738
);
739739

740+
ql_signature_expr_mod_expr(
741+
unique int ql_signature_expr: @ql_signature_expr ref,
742+
unique int mod_expr: @ql_module_expr ref
743+
);
744+
740745
ql_signature_expr_predicate(
741746
unique int ql_signature_expr: @ql_signature_expr ref,
742747
unique int predicate: @ql_predicate_expr ref

ql/ql/test/callgraph/ParamSig.qll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
signature class Foo;
2+
3+
class FooImpl extends string {
4+
FooImpl() { this = "foo" }
5+
}
6+
7+
signature module ParamSig<Foo F> {
8+
F getThing();
9+
}
10+
11+
module ParamImpl implements ParamSig<FooImpl> {
12+
FooImpl getThing() { any() }
13+
}
14+
15+
module ParamMod<ParamSig<FooImpl> Impl> {
16+
FooImpl getTheThing() { result = Impl::getThing() }
17+
}
18+
19+
FooImpl foo() { result = ParamMod<ParamImpl>::getTheThing() }

ql/ql/test/callgraph/callgraph.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ getTarget
3636
| ParamModules.qll:59:30:59:45 | PredicateCall | ParamModules.qll:37:7:37:14 | ClasslessPredicate getThing |
3737
| ParamModules.qll:59:30:59:53 | MemberCall | ParamModules.qll:46:14:46:18 | ClassPredicate myFoo |
3838
| ParamModules.qll:61:39:61:47 | MemberCall | ParamModules.qll:46:14:46:18 | ClassPredicate myFoo |
39+
| ParamSig.qll:16:36:16:51 | PredicateCall | ParamSig.qll:8:5:8:12 | ClasslessPredicate getThing |
40+
| ParamSig.qll:16:36:16:51 | PredicateCall | ParamSig.qll:12:11:12:18 | ClasslessPredicate getThing |
41+
| ParamSig.qll:19:26:19:59 | PredicateCall | ParamSig.qll:16:11:16:21 | ClasslessPredicate getTheThing |
3942
| packs/other/OtherThing.qll:5:3:5:8 | PredicateCall | packs/lib/LibThing/Foo.qll:1:11:1:13 | ClasslessPredicate foo |
4043
| packs/other/OtherThing.qll:6:3:6:8 | PredicateCall | packs/src/SrcThing.qll:8:11:8:13 | ClasslessPredicate bar |
4144
| packs/src/SrcThing.qll:4:3:4:8 | PredicateCall | packs/lib/LibThing/Foo.qll:1:11:1:13 | ClasslessPredicate foo |

0 commit comments

Comments
 (0)