Skip to content

Commit ed93d56

Browse files
committed
feat(ast): Enhance AST classes with additional methods for expression handling
1 parent ea7f048 commit ed93d56

File tree

5 files changed

+63
-13
lines changed

5 files changed

+63
-13
lines changed

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

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,37 @@ final class Expr extends AstNode instanceof ExprImpl { }
3030
/**
3131
* A AssignmentExpression expression in the AST.
3232
*/
33-
final class AssignmentExpression extends Expr instanceof AssignmentExpressionImpl { }
33+
class AssignmentExpression extends Expr instanceof AssignmentExpressionImpl {
34+
/**
35+
* Gets the left operand of the assignment expression.
36+
*/
37+
Expr getLeft() { result = AssignmentExpressionImpl.super.getLeft() }
38+
39+
/**
40+
* Gets the right operand of the assignment expression.
41+
*/
42+
Expr getRight() { result = AssignmentExpressionImpl.super.getRight() }
43+
}
3444

3545
/**
3646
* A BinaryExpression expression in the AST.
3747
*/
38-
final class BinaryExpression extends Expr instanceof BinaryExpressionImpl { }
48+
class BinaryExpression extends Expr instanceof BinaryExpressionImpl {
49+
/**
50+
* Gets the left operand of the binary expression.
51+
*/
52+
Expr getLeft() { result = BinaryExpressionImpl.super.getLeft() }
53+
54+
/**
55+
* Gets the right operand of the binary expression.
56+
*/
57+
Expr getRight() { result = BinaryExpressionImpl.super.getRight() }
58+
59+
/**
60+
* Gets the operator of the binary expression.
61+
*/
62+
string getOperator() { result = BinaryExpressionImpl.super.getOperator() }
63+
}
3964

4065
/**
4166
* A Expression expression in the AST.
@@ -45,7 +70,18 @@ final class Expression extends Expr instanceof ExpressionImpl { }
4570
/**
4671
* A Interpolation literal in the AST.
4772
*/
48-
final class Interpolation extends Expr instanceof InterpolationImpl { }
73+
final class Interpolation extends Expr instanceof InterpolationImpl {
74+
/**
75+
* Gets the expression contained within the interpolation.
76+
*/
77+
Expr getExpression() {
78+
result = InterpolationImpl.super.getExpression()
79+
}
80+
81+
string getValue() {
82+
result = "${" + this.getExpression().toString() + "}"
83+
}
84+
}
4985

5086
/**
5187
* A LambdaExpression expression in the AST.
@@ -69,9 +105,7 @@ class MemberExpression extends Expr instanceof MemberExpressionImpl {
69105
/**
70106
* Gets the full name of the member expression, which includes the namespace and the member name.
71107
*/
72-
string getFullName() {
73-
result = this.getNamespace().getName() + "." + this.getName().getName()
74-
}
108+
string getFullName() { result = this.getNamespace().getName() + "." + this.getName().getName() }
75109
}
76110

77111
/**

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ final class ForStatementStmt extends Stmts instanceof ForStatementImpl { }
5050
/**
5151
* A IfStatement statement
5252
*/
53-
final class IfStatementStmt extends Stmts instanceof IfStatementImpl { }
53+
class IfStatement extends Stmts instanceof IfStatementImpl {
54+
/** Gets the condition of the if statement. */
55+
Expr getCondition() { result = IfStatementImpl.super.getCondition() }
56+
57+
/** Gets the body of the if statement. */
58+
Expr getBody() { result = IfStatementImpl.super.getBody() }
59+
}
5460

5561
/**
5662
* A ImportStatement statement

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
*
44
* WARNING: this file is generated, do not edit manually
55
*/
6+
67
private import AstNodes
78
private import TreeSitter
89
private import codeql.bicep.ast.AstNodes
910
private import Expr
1011

11-
1212
/**
1313
* A AssignmentExpression AST Node.
1414
*/
@@ -21,6 +21,7 @@ class AssignmentExpressionImpl extends TAssignmentExpression, ExprImpl {
2121

2222
override string toString() { result = ast.toString() }
2323

24+
ExprImpl getLeft() { toTreeSitter(result) = ast.getLeft() }
2425

25-
26-
}
26+
ExprImpl getRight() { toTreeSitter(result) = ast.getRight() }
27+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ class BinaryExpressionImpl extends TBinaryExpression, ExprImpl {
2121

2222
override string toString() { result = ast.toString() }
2323

24+
ExprImpl getLeft() { toTreeSitter(result) = ast.getLeft() }
2425

26+
ExprImpl getRight() { toTreeSitter(result) = ast.getRight() }
27+
28+
string getOperator() {
29+
result = ast.getOperator()
30+
}
2531

2632
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
*
44
* WARNING: this file is generated, do not edit manually
55
*/
6+
67
private import AstNodes
78
private import TreeSitter
89
private import codeql.bicep.ast.AstNodes
910
private import Stmts
10-
11+
private import ParenthesizedExpression
12+
private import Object
1113

1214
/**
1315
* A IfStatement AST Node.
@@ -21,6 +23,7 @@ class IfStatementImpl extends TIfStatement, StmtsImpl {
2123

2224
override string toString() { result = ast.toString() }
2325

26+
ParenthesizedExpressionImpl getCondition() { toTreeSitter(result) = ast.getChild(0) }
2427

25-
26-
}
28+
ObjectImpl getBody() { toTreeSitter(result) = ast.getChild(1) }
29+
}

0 commit comments

Comments
 (0)