mirror of
https://github.com/github/codeql.git
synced 2026-05-24 16:17:07 +02:00
Add File as a CFG root to support file-level declarations
Agent-Logs-Url: https://github.com/github/codeql/sessions/2867f173-c3f1-4564-9885-3ff4517bbf30 Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
This commit is contained in:
committed by
Owen Mansel-Chan
parent
478b75e054
commit
84b03b2b1a
@@ -9,17 +9,26 @@ private import ControlFlowGraphShared
|
||||
|
||||
/** Provides helper predicates for mapping between CFG nodes and the AST. */
|
||||
module ControlFlow {
|
||||
/** A function with which a CFG is associated. */
|
||||
/** A file or function with which a CFG is associated. */
|
||||
class Root extends AstNode {
|
||||
Root() { exists(this.(FuncDef).getBody()) }
|
||||
Root() {
|
||||
exists(this.(FuncDef).getBody())
|
||||
or
|
||||
exists(this.(File).getADecl())
|
||||
}
|
||||
|
||||
/** Holds if `nd` belongs to this function. */
|
||||
predicate isRootOf(AstNode nd) { this = nd.getEnclosingFunction() }
|
||||
/** Holds if `nd` belongs to this file or function. */
|
||||
predicate isRootOf(AstNode nd) {
|
||||
this = nd.getEnclosingFunction()
|
||||
or
|
||||
not exists(nd.getEnclosingFunction()) and
|
||||
this = nd.getFile()
|
||||
}
|
||||
|
||||
/** Gets the synthetic entry node of the CFG for this function. */
|
||||
/** Gets the synthetic entry node of the CFG for this file or function. */
|
||||
EntryNode getEntryNode() { result = ControlFlow::entryNode(this) }
|
||||
|
||||
/** Gets the synthetic exit node of the CFG for this function. */
|
||||
/** Gets the synthetic exit node of the CFG for this file or function. */
|
||||
ExitNode getExitNode() { result = ControlFlow::exitNode(this) }
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,11 @@ module GoCfg {
|
||||
}
|
||||
|
||||
class Callable extends AstNode {
|
||||
Callable() { exists(this.(Go::FuncDef).getBody()) }
|
||||
Callable() {
|
||||
exists(this.(Go::FuncDef).getBody())
|
||||
or
|
||||
exists(this.(Go::File).getADecl())
|
||||
}
|
||||
}
|
||||
|
||||
AstNode callableGetBody(Callable c) { result = c }
|
||||
@@ -72,6 +76,11 @@ module GoCfg {
|
||||
result = node and node instanceof Callable
|
||||
or
|
||||
not node instanceof Callable and result = node.getEnclosingFunction()
|
||||
or
|
||||
not node instanceof Callable and
|
||||
not exists(node.getEnclosingFunction()) and
|
||||
result = node.getFile() and
|
||||
result instanceof Callable
|
||||
}
|
||||
|
||||
class Stmt = Go::Stmt;
|
||||
|
||||
Reference in New Issue
Block a user