Skip to content

Commit 62e0510

Browse files
committed
feat: Update to remove unneeded AST classes + update CFG
1 parent 308bb29 commit 62e0510

File tree

11 files changed

+50
-154
lines changed

11 files changed

+50
-154
lines changed

ql/lib/codeql/bicep/ast/Expr.qll

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ private import internal.Expr
99
private import internal.Arguments
1010
private import internal.AssignmentExpression
1111
private import internal.BinaryExpression
12-
private import internal.Expression
1312
private import internal.Interpolation
1413
private import internal.LambdaExpression
1514
private import internal.MemberExpression
1615
private import internal.NullableType
1716
private import internal.ParenthesizedExpression
18-
private import internal.PrimaryExpression
1917
private import internal.ResourceExpression
2018
private import internal.TernaryExpression
2119
private import internal.UnaryExpression
@@ -112,15 +110,6 @@ class BinaryExpression extends Expr instanceof BinaryExpressionImpl {
112110
string getOperator() { result = BinaryExpressionImpl.super.getOperator() }
113111
}
114112

115-
/**
116-
* A generic expression in the AST.
117-
*
118-
* This class represents any expression that doesn't fit into other more
119-
* specific expression categories. It serves as a base implementation for
120-
* expressions in the Bicep language.
121-
*/
122-
class Expression extends Expr instanceof ExpressionImpl { }
123-
124113
/**
125114
* An interpolation expression in the AST.
126115
*
@@ -237,15 +226,6 @@ class ParenthesizedExpression extends Expr instanceof ParenthesizedExpressionImp
237226
}
238227
}
239228

240-
/**
241-
* A primary expression in the AST.
242-
*
243-
* Represents a basic, self-contained expression such as a literal value,
244-
* identifier, or other fundamental expression type. Primary expressions
245-
* serve as the building blocks for more complex expressions.
246-
*/
247-
class PrimaryExpression extends Expr instanceof PrimaryExpressionImpl { }
248-
249229
/**
250230
* A resource expression in the AST.
251231
*

ql/lib/codeql/bicep/ast/Misc.qll

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ private import internal.Array
33
private import internal.ArrayType
44
private import internal.Boolean
55
private import internal.CompatibleIdentifier
6-
private import internal.Declaration
76
private import internal.Decorator
87
private import internal.Decorators
98
private import internal.DiagnosticComment
@@ -38,11 +37,6 @@ class ArrayType extends AstNode instanceof ArrayTypeImpl { }
3837
*/
3938
class CompatibleIdentifier extends AstNode instanceof CompatibleIdentifierImpl { }
4039

41-
/**
42-
* A Declaration unknown AST node.
43-
*/
44-
class Declaration extends AstNode instanceof DeclarationImpl { }
45-
4640
/**
4741
* A Decorator unknown AST node.
4842
*/

ql/lib/codeql/bicep/ast/Stmts.qll

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
private import AstNodes
66
private import Idents
77
private import Expr
8+
private import Calls
89
private import Misc
910
private import internal.AstNodes
1011
private import internal.TreeSitter
@@ -15,7 +16,6 @@ private import internal.IfStatement
1516
private import internal.ImportStatement
1617
private import internal.ImportWithStatement
1718
private import internal.Infrastructure
18-
private import internal.Statement
1919
private import internal.UsingStatement
2020
private import internal.Parameter
2121
private import internal.Parameters
@@ -55,6 +55,47 @@ class Stmts extends AstNode instanceof StmtsImpl {
5555
AstNode getAControlFlowEntryNode() { result = CfgImpl::getAControlFlowEntryNode(this) }
5656
}
5757

58+
/**
59+
* A sequence of statements in the PHP AST.
60+
*
61+
* This represents a list of statements that appear together in sequence.
62+
*/
63+
class StmtSequence extends AstNode instanceof StmtSequenceImpl {
64+
/**
65+
* Gets all statements in this sequence.
66+
*/
67+
Stmts getStmts() { none() }
68+
69+
/**
70+
* Gets the statement at the specified index within this sequence.
71+
*/
72+
Stmts getStmt(int index) { none() }
73+
74+
/**
75+
* Get all callables defined in this program.
76+
*/
77+
Callable getCallables() {
78+
result = this.getStmts()
79+
}
80+
81+
/**
82+
* Get a callable by its name.
83+
*/
84+
Callable getCallable(string name) {
85+
exists(Callable c | c = this.getCallables() and c.getName() = name | result = c)
86+
}
87+
88+
/**
89+
* Gets the number of statements in this sequence.
90+
*/
91+
int getNumberOfStatements() { result = count(int i | exists(this.getStmt(i))) }
92+
93+
/**
94+
* Gets the last statement of the sequence
95+
*/
96+
Stmts getLastStmt() { result = this.getStmt(this.getNumberOfStatements() - 1) }
97+
}
98+
5899
/**
59100
* An assert statement in the AST.
60101
*
@@ -118,14 +159,10 @@ final class ImportStatementStmt extends Stmts instanceof ImportStatementImpl { }
118159
* statements and declarations that define the infrastructure to be deployed.
119160
* This is essentially the entry point of a Bicep program.
120161
*/
121-
class Infrastructure extends AstNode instanceof InfrastructureImpl {
122-
/**
123-
* Gets the statement at the specified index in the infrastructure.
124-
*
125-
* @param index The index of the statement to retrieve
126-
* @return The statement at the specified index
127-
*/
128-
Stmts getStatement(int index) { result = InfrastructureImpl.super.getStatement(index) }
162+
class Infrastructure extends StmtSequence instanceof InfrastructureImpl {
163+
override Stmts getStmts() { result = InfrastructureImpl.super.getStmts() }
164+
165+
override Stmts getStmt(int index) { result = InfrastructureImpl.super.getStmt(index) }
129166
}
130167

131168
/**
@@ -360,15 +397,6 @@ class Parameters extends AstNode instanceof ParametersImpl {
360397
*/
361398
final class ImportWithStatementStmt extends Stmts instanceof ImportWithStatementImpl { }
362399

363-
/**
364-
* A generic statement in the AST.
365-
*
366-
* This class represents any statement that doesn't fit into other more specific
367-
* statement categories. It serves as a base implementation for statements
368-
* in the Bicep language.
369-
*/
370-
final class StatementStmt extends Stmts instanceof StatementImpl { }
371-
372400
/**
373401
* A using statement in the AST.
374402
*

ql/lib/codeql/bicep/ast/internal/CallExpression.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ private import TreeSitter
88
private import codeql.bicep.ast.AstNodes
99
private import Expr
1010
private import Calls
11-
private import Expression
1211
private import Idents
1312
private import Arguments
1413
private import NullableReturnType

ql/lib/codeql/bicep/ast/internal/Declaration.qll

Lines changed: 0 additions & 24 deletions
This file was deleted.

ql/lib/codeql/bicep/ast/internal/Expression.qll

Lines changed: 0 additions & 26 deletions
This file was deleted.

ql/lib/codeql/bicep/ast/internal/Infrastructure.qll

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ private import AstNodes
88
private import TreeSitter
99
private import codeql.bicep.ast.AstNodes
1010
private import Stmts
11-
private import Statement
1211

1312
/**
1413
* A Infrastructure AST Node.
@@ -22,9 +21,7 @@ class InfrastructureImpl extends TInfrastructure, StmtSequenceImpl {
2221

2322
override string toString() { result = ast.toString() }
2423

25-
override StmtsImpl getStmt(int index) { result = this.getStatement(index) }
24+
override StmtsImpl getStmt(int index) { toTreeSitter(result) = ast.getChild(index) }
2625

27-
override StmtsImpl getStmts() { result = this.getStatement(_) }
28-
29-
StatementImpl getStatement(int index) { toTreeSitter(result) = ast.getChild(index) }
26+
override StmtsImpl getStmts() { result = this.getStmt(_) }
3027
}

ql/lib/codeql/bicep/ast/internal/PrimaryExpression.qll

Lines changed: 0 additions & 26 deletions
This file was deleted.

ql/lib/codeql/bicep/ast/internal/Statement.qll

Lines changed: 0 additions & 26 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private module CfgImpl = Make<Location, Implementation>;
6464
import CfgImpl
6565

6666
class InfrastructureScopeTree extends StandardTree, PreOrderTree, PostOrderTree, Scope::InfrastructureScope {
67-
override AstNode getChildNode(int i) { result = super.getStatement(i) }
67+
override AstNode getChildNode(int i) { result = super.getStmt(i) }
6868
}
6969

7070
class StmtsTree extends StandardPostOrderTree instanceof Stmts {

0 commit comments

Comments
 (0)