mirror of
https://github.com/github/codeql.git
synced 2026-07-11 06:25:38 +02:00
unified: Add debug query for local scoping graph
This commit is contained in:
@@ -296,6 +296,31 @@ module LocalNameBinding<LocationSig Location, LocalNameBindingInputSig<Location>
|
||||
)
|
||||
}
|
||||
|
||||
/** Holds if `node` should be included in the debug tree. */
|
||||
private signature predicate relevantNodeSig(AstNode node);
|
||||
|
||||
module DebugScopeGraph<relevantNodeSig/1 relevantNode> {
|
||||
private string getANodeAnnotation(AstNode node) {
|
||||
result =
|
||||
"[scope=" +
|
||||
strictconcat(string name |
|
||||
declInScope(_, name, node) or implicitDeclInScope(name, node)
|
||||
|
|
||||
name, ","
|
||||
) + "]"
|
||||
}
|
||||
|
||||
query predicate nodes(AstNode node, string key, string value) {
|
||||
relevantNode(node) and
|
||||
key = "semmle.label" and
|
||||
value = node.toString() + concat(getANodeAnnotation(node))
|
||||
}
|
||||
|
||||
query predicate edges(AstNode node1, AstNode node2) {
|
||||
relevantNode(node2) and node2 = getParentForScoping(node1)
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the immediately enclosing variable scope of `n`. */
|
||||
private Scope getEnclosingScope(AstNode n) {
|
||||
result = getParentForScoping(n)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @name Debug scope graph
|
||||
* @description Renders the graph used to perform local variable lookups
|
||||
* @kind graph
|
||||
* @id unified/debug-scope-graph
|
||||
*/
|
||||
|
||||
private import unified
|
||||
private import codeql.unified.internal.Variables
|
||||
|
||||
/**
|
||||
* Holds if `node` should be shown in the graph.
|
||||
*/
|
||||
predicate relevantNode(AstNode node) {
|
||||
// Match an ancestor node by location so its whole subtree is shown.
|
||||
node.getParent*().getLocation().toString().matches("%test.swift@227:%")
|
||||
}
|
||||
|
||||
import LocalNameBindingOutput::DebugScopeGraph<relevantNode/1>
|
||||
Reference in New Issue
Block a user