Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e7db2d

Browse files
committed
hook up the pretty AST of a parameterized module
1 parent 1caafb8 commit 6e7db2d

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,19 @@ class Module extends TModule, ModuleDeclaration {
719719
pred = directMember("getAlias") and result = this.getAlias()
720720
or
721721
pred = directMember("getAMember") and result = this.getAMember()
722+
or
723+
exists(int i | pred = indexedMember("hasParameter", i) and hasParameter(i, _, result))
724+
}
725+
726+
/** Holds if the `i`th parameter of this module has `name` and type `sig`. */
727+
predicate hasParameter(int i, string name, SignatureExpr sig) {
728+
exists(QL::ModuleParam param |
729+
param = mod.getParameter(i) and name = param.getParameter().getValue()
730+
|
731+
toQL(sig) = param.getSignature().getPredicate()
732+
or
733+
toQL(sig) = param.getSignature().getTypeExpr()
734+
)
722735
}
723736
}
724737

@@ -2225,7 +2238,7 @@ class ModuleExpr extends TModuleExpr, ModuleRef {
22252238
* Gets the `i`th type argument if this module is a module instantiation.
22262239
* The result is either a `PredicateExpr` or a `TypeExpr`.
22272240
*/
2228-
AstNode getArgument(int i) {
2241+
SignatureExpr getArgument(int i) {
22292242
exists(QL::ModuleInstantiation instantiation | instantiation.getParent() = me |
22302243
toQL(result) = instantiation.getChild(i).getPredicate()
22312244
or
@@ -2234,6 +2247,9 @@ class ModuleExpr extends TModuleExpr, ModuleRef {
22342247
}
22352248
}
22362249

2250+
/** A signature expression, either a `PredicateExpr` or a `TypeExpr`. */
2251+
class SignatureExpr extends TSignatureExpr, AstNode { }
2252+
22372253
/** An argument to an annotation. */
22382254
private class AnnotationArg extends TAnnotationArg, AstNode {
22392255
QL::AnnotArg arg;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ class TModuleRef = TImport or TModuleExpr;
8787

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

90+
class TSignatureExpr = TPredicateExpr or TType;
91+
9092
/** DEPRECATED: Alias for TYamlNode */
9193
deprecated class TYAMLNode = TYamlNode;
9294

0 commit comments

Comments
 (0)