Skip to content

Commit 4ccdaad

Browse files
committed
feat(cfg): Update CFG
1 parent 578894f commit 4ccdaad

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

ql/lib/codeql/bicep/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ private module CfgImpl = Make<Location, Implementation>;
6363

6464
import CfgImpl
6565

66+
class InfrastructureScopeTree extends StandardTree, PreOrderTree, PostOrderTree, Scope::InfrastructureScope {
67+
override AstNode getChildNode(int i) { result = super.getStatement(i) }
68+
}
69+
6670
/**
6771
* A literal value in a Bicep program.
6872
*/
@@ -87,3 +91,38 @@ class StringLiteralTree extends LeafTree instanceof StringLiteral { }
8791
* A StringContent literal value in a Bicep program.
8892
*/
8993
class StringContentLiteralTree extends LeafTree instanceof StringContentLiteral { }
94+
95+
/**
96+
* ParameterDeclarationTree represents a parameter declaration in a Bicep program.
97+
*/
98+
class ParameterDeclarationTree extends StandardPostOrderTree instanceof ParameterDeclaration {
99+
override AstNode getChildNode(int i) {
100+
i = 0 and result = super.getIdentifier()
101+
or
102+
i = 1 and result = super.getType()
103+
or
104+
i = 2 and result = super.getDefaultValue()
105+
}
106+
}
107+
108+
class UserDefinedFunctionTree extends StandardPostOrderTree instanceof UserDefinedFunction {
109+
override AstNode getChildNode(int i) {
110+
i = 0 and result = super.getIdentifier()
111+
or
112+
i = 1 and result = super.getParameters()
113+
or
114+
i = 2 and result = super.getReturnType()
115+
or
116+
i = 3 and result = super.getBody()
117+
}
118+
}
119+
120+
class OutputDeclarationTree extends StandardPostOrderTree instanceof OutputDeclaration {
121+
override AstNode getChildNode(int i) {
122+
i = 0 and result = super.getIdentifier()
123+
or
124+
i = 1 and result = super.getType()
125+
or
126+
i = 2 and result = super.getValue()
127+
}
128+
}

ql/lib/codeql/bicep/controlflow/internal/Scope.qll

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,21 @@ private import codeql.bicep.AST
33
private import Completion
44
private import ControlFlowGraphImpl
55

6-
abstract class CfgScope extends AstNode {
6+
abstract private class CfgScopeImpl extends AstNode {
77
/** Holds if `first` is executed first when entering scope. */
88
abstract predicate scopeFirst(AstNode first);
99

1010
/** Holds if scope is exited when `last` finishes with completion `c`. */
1111
abstract predicate scopeLast(AstNode last, Completion c);
1212
}
13+
14+
final class CfgScope = CfgScopeImpl;
15+
16+
/**
17+
* A Infrastructure is a Sequence of statements.
18+
*/
19+
final class InfrastructureScope extends CfgScopeImpl, Infrastructure {
20+
override predicate scopeFirst(AstNode first) { first(this.getStatement(0), first) }
21+
22+
override predicate scopeLast(AstNode last, Completion c) { last(this, last, c) }
23+
}

0 commit comments

Comments
 (0)