Skip to content

Commit 47353f6

Browse files
authored
Merge pull request #10067 from erik-krogh/paramSig
QL: support signature parameters in QL-for-QL
2 parents 44e1ecd + 37f6fec commit 47353f6

File tree

11 files changed

+48
-12
lines changed

11 files changed

+48
-12
lines changed

.github/workflows/ql-for-ql-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
CODEQL: ${{ steps.find-codeql.outputs.codeql-path }}
4545
- name: Check QL formatting
4646
run: |
47-
find ql/ql "(" -name "*.ql" -or -name "*.qll" ")" -print0 | xargs -0 "${CODEQL}" query format --check-only
47+
find ql/ql/src "(" -name "*.ql" -or -name "*.qll" ")" -print0 | xargs -0 "${CODEQL}" query format --check-only
4848
env:
4949
CODEQL: ${{ steps.find-codeql.outputs.codeql-path }}
5050
- name: Check QL compilation

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: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,9 @@ class Module extends TModule, ModuleDeclaration {
743743
}
744744

745745
/** Gets a ref to the module that this module implements. */
746-
TypeExpr getImplements(int i) { toQL(result) = mod.getImplements(i).getTypeExpr() }
746+
TypeRef getImplements(int i) {
747+
exists(SignatureExpr sig | sig.toQL() = mod.getImplements(i) | result = sig.asType())
748+
}
747749

748750
/** Gets the module expression that this module is an alias for, if any. */
749751
ModuleExpr getAlias() { toQL(result) = mod.getAFieldOrChild().(QL::ModuleAliasBody).getChild() }
@@ -2293,7 +2295,7 @@ class ModuleExpr extends TModuleExpr, TypeRef {
22932295

22942296
/**
22952297
* Gets the `i`th type argument if this module is a module instantiation.
2296-
* The result is either a `PredicateExpr` or a `TypeExpr`.
2298+
* The result is either a `PredicateExpr`, `TypeExpr`, or `ModuleExpr`.
22972299
*/
22982300
SignatureExpr getArgument(int i) {
22992301
result.toQL() = me.getAFieldOrChild().(QL::ModuleInstantiation).getChild(i)
@@ -2313,14 +2315,16 @@ class ModuleExpr extends TModuleExpr, TypeRef {
23132315
}
23142316
}
23152317

2316-
/** A signature expression, either a `PredicateExpr` or a `TypeExpr`. */
2318+
/** A signature expression, either a `PredicateExpr`, a `TypeExpr`, or a `ModuleExpr`. */
23172319
class SignatureExpr extends TSignatureExpr, AstNode {
23182320
QL::SignatureExpr sig;
23192321

23202322
SignatureExpr() {
23212323
toQL(this) = sig.getPredicate()
23222324
or
23232325
toQL(this) = sig.getTypeExpr()
2326+
or
2327+
toQL(this) = sig.getModExpr()
23242328
}
23252329

23262330
/** Gets the generated AST node that contains this signature expression. */
@@ -2329,8 +2333,8 @@ class SignatureExpr extends TSignatureExpr, AstNode {
23292333
/** Gets this signature expression if it represents a predicate expression. */
23302334
PredicateExpr asPredicate() { result = this }
23312335

2332-
/** Gets this signature expression if it represents a type expression. */
2333-
TypeExpr asType() { result = this }
2336+
/** Gets this signature expression if it represents a type expression (either a `TypeExpr` or a `ModuleExpr`). */
2337+
TypeRef asType() { result = this }
23342338
}
23352339

23362340
/** 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() }

0 commit comments

Comments
 (0)