File tree Expand file tree Collapse file tree 2 files changed +25
-7
lines changed
go/ql/lib/semmle/go/controlflow Expand file tree Collapse file tree 2 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -9,17 +9,26 @@ private import ControlFlowGraphShared
99
1010/** Provides helper predicates for mapping between CFG nodes and the AST. */
1111module ControlFlow {
12- /** A function with which a CFG is associated. */
12+ /** A file or function with which a CFG is associated. */
1313 class Root extends AstNode {
14- Root ( ) { exists ( this .( FuncDef ) .getBody ( ) ) }
14+ Root ( ) {
15+ exists ( this .( FuncDef ) .getBody ( ) )
16+ or
17+ exists ( this .( File ) .getADecl ( ) )
18+ }
1519
16- /** Holds if `nd` belongs to this function. */
17- predicate isRootOf ( AstNode nd ) { this = nd .getEnclosingFunction ( ) }
20+ /** Holds if `nd` belongs to this file or function. */
21+ predicate isRootOf ( AstNode nd ) {
22+ this = nd .getEnclosingFunction ( )
23+ or
24+ not exists ( nd .getEnclosingFunction ( ) ) and
25+ this = nd .getFile ( )
26+ }
1827
19- /** Gets the synthetic entry node of the CFG for this function. */
28+ /** Gets the synthetic entry node of the CFG for this file or function. */
2029 EntryNode getEntryNode ( ) { result = ControlFlow:: entryNode ( this ) }
2130
22- /** Gets the synthetic exit node of the CFG for this function. */
31+ /** Gets the synthetic exit node of the CFG for this file or function. */
2332 ExitNode getExitNode ( ) { result = ControlFlow:: exitNode ( this ) }
2433 }
2534
Original file line number Diff line number Diff line change @@ -63,7 +63,11 @@ module GoCfg {
6363 }
6464
6565 class Callable extends AstNode {
66- Callable ( ) { exists ( this .( Go:: FuncDef ) .getBody ( ) ) }
66+ Callable ( ) {
67+ exists ( this .( Go:: FuncDef ) .getBody ( ) )
68+ or
69+ exists ( this .( Go:: File ) .getADecl ( ) )
70+ }
6771 }
6872
6973 AstNode callableGetBody ( Callable c ) { result = c }
@@ -72,6 +76,11 @@ module GoCfg {
7276 result = node and node instanceof Callable
7377 or
7478 not node instanceof Callable and result = node .getEnclosingFunction ( )
79+ or
80+ not node instanceof Callable and
81+ not exists ( node .getEnclosingFunction ( ) ) and
82+ result = node .getFile ( ) and
83+ result instanceof Callable
7584 }
7685
7786 class Stmt = Go:: Stmt ;
You can’t perform that action at this time.
0 commit comments