Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions ql/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ql/extractor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tree-sitter = ">= 0.23.0"
tree-sitter-ql = { git = "https://github.com/tree-sitter/tree-sitter-ql.git", rev = "c73c31c89cb0019ef56fe8bc1723e7c36e0be607"}
tree-sitter = ">= 0.26.0"
tree-sitter-ql = { git = "https://github.com/tree-sitter/tree-sitter-ql.git", rev = "5b8ee9adaa1f2a1ea958064b61f8feb0a5a886c0"}
Comment thread
owen-mc marked this conversation as resolved.
tree-sitter-ql-dbscheme = { git = "https://github.com/tree-sitter/tree-sitter-ql-dbscheme.git", rev = "1980b4b6998a1138d326f863e6168f0f2c0c544d"}
tree-sitter-blame = {path = "../buramu/tree-sitter-blame"}
tree-sitter-json = {git = "https://github.com/tree-sitter/tree-sitter-json.git", rev = "8bfdb43f47ad805bb1ce093203cfcbaa8ed2c571"}
Expand Down
6 changes: 5 additions & 1 deletion ql/ql/src/codeql_ql/ast/Ast.qll
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,11 @@ class Module extends TModule, ModuleDeclaration {

Module() { this = TModule(mod) }

override Location getLocation() { result = mod.asLeft().getName().getLocation() }
override Location getLocation() {
result = mod.asLeft().getName().getLocation()
or
not exists(mod.asLeft().getName()) and result = mod.asLeft().getLocation()
}

override string getAPrimaryQlClass() { result = "Module" }

Expand Down
13 changes: 7 additions & 6 deletions ql/ql/src/codeql_ql/ast/internal/Module.qll
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ private predicate resolveImportQualifier(Import imp, ContainerOrModule m) {

cached
private module Cached {
private AstNode parent(AstNode n) {
result = n.getParent() and
not n instanceof Module
private Module getEnclosingModule0(AstNode n) {
result = n.getParent()
or
not n.getParent() instanceof Module and
result = getEnclosingModule0(n.getParent())
}

private Module getEnclosingModule0(AstNode n) { result = parent*(n.getParent()) }

cached
ContainerOrModule getEnclosingModule(AstNode n) {
result = TModule(getEnclosingModule0(n))
Expand Down Expand Up @@ -375,7 +375,8 @@ module ModConsistency {

query predicate noName(AstNode mod) {
mod instanceof Module and
not exists(mod.(Module).getName())
not exists(mod.(Module).getName()) and
not mod.getParent() instanceof TopLevel
or
mod instanceof ModuleExpr and
not exists(mod.(ModuleExpr).getName())
Expand Down
15 changes: 13 additions & 2 deletions ql/ql/src/codeql_ql/ast/internal/Predicate.qll
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,20 @@ private module Cached {
)
}

pragma[noinline]
private predicate builtin(BuiltinClassless pred, string name, int arity) {
name = pred.getName() and
arity = count(int i | exists(pred.getParameterType(i)))
}

pragma[noinline]
private predicate call(PredicateCall call, string name, int arity) {
name = call.getPredicateName() and
arity = call.getNumberOfArguments()
}

private predicate resolveBuiltinPredicateCall(PredicateCall call, BuiltinClassless pred) {
call.getNumberOfArguments() = pred.getArity() and
call.getPredicateName() = pred.getName()
exists(string name, int arity | builtin(pred, name, arity) and call(call, name, arity))
}

cached
Expand Down
4 changes: 2 additions & 2 deletions ql/ql/src/codeql_ql/ast/internal/TreeSitter.qll
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ module QL {
final F::SignatureExpr getAnImplements() { result = this.getImplements(_) }

/** Gets the node corresponding to the field `name`. */
final F::ModuleName getName() { ql_module_def(this, result) }
final F::ModuleName getName() { ql_module_name(this, result) }

/** Gets the node corresponding to the field `parameter`. */
final F::ModuleParam getParameter(int i) { ql_module_parameter(this, i, result) }
Expand All @@ -824,7 +824,7 @@ module QL {
/** Gets a field or child node of this node. */
final override F::AstNode getAFieldOrChild() {
ql_module_implements(this, _, result) or
ql_module_def(this, result) or
ql_module_name(this, result) or
ql_module_parameter(this, _, result) or
ql_module_child(this, _, result)
}
Expand Down
12 changes: 6 additions & 6 deletions ql/ql/src/codeql_ql/ast/internal/Variable.qll
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ class VariableScope extends TScope, AstNode {
}
}

private AstNode parent(AstNode child) {
result = child.getParent() and
not child instanceof VariableScope
}

pragma[nomagic]
VariableScope scopeOf(AstNode n) { result = parent*(n.getParent()) }
VariableScope scopeOf(AstNode n) {
result = n.getParent()
or
not n.getParent() instanceof VariableScope and
result = scopeOf(n.getParent())
}

private string getName(Identifier i) {
exists(QL::Variable v |
Expand Down
8 changes: 6 additions & 2 deletions ql/ql/src/ql.dbscheme
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,11 @@ ql_module_implements(
unique int implements: @ql_signature_expr ref
);

ql_module_name(
unique int ql_module: @ql_module ref,
unique int name: @ql_module_name ref
);

#keyset[ql_module, index]
ql_module_parameter(
int ql_module: @ql_module ref,
Expand All @@ -572,8 +577,7 @@ ql_module_child(
);

ql_module_def(
unique int id: @ql_module,
int name: @ql_module_name ref
unique int id: @ql_module
);

ql_module_alias_body_def(
Expand Down
Loading
Loading