Skip to content

Commit 762c3d8

Browse files
authored
Merge branch 'main' into dataflow
2 parents 1967edb + 55aae52 commit 762c3d8

File tree

9 files changed

+63
-8
lines changed

9 files changed

+63
-8
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Infrastructure extends AstNode instanceof InfrastructureImpl {
7575
* Represents a parameter declaration node in the AST.
7676
* Provides access to the identifier, name, type, and default value of the parameter.
7777
*/
78-
class ParameterDeclaration extends AstNode instanceof ParameterDeclarationImpl {
78+
class ParameterDeclaration extends Stmts instanceof ParameterDeclarationImpl {
7979
/** Gets the identifier of the parameter declaration. */
8080
Identifier getIdentifier() { result = ParameterDeclarationImpl.super.getName() }
8181

@@ -94,7 +94,7 @@ class ParameterDeclaration extends AstNode instanceof ParameterDeclarationImpl {
9494
* Represents an output declaration node in the AST.
9595
* Provides access to the identifier, name, type, and value of the output.
9696
*/
97-
class OutputDeclaration extends AstNode instanceof OutputDeclarationImpl {
97+
class OutputDeclaration extends Stmts instanceof OutputDeclarationImpl {
9898
/** Gets the identifier of the output declaration. */
9999
Identifier getIdentifier() { result = OutputDeclarationImpl.super.getIdentifier() }
100100

@@ -112,7 +112,7 @@ class OutputDeclaration extends AstNode instanceof OutputDeclarationImpl {
112112
* Represents a user-defined function node in the AST.
113113
* Provides access to the identifier, name, return type, parameters, and body of the function.
114114
*/
115-
class UserDefinedFunction extends AstNode instanceof UserDefinedFunctionImpl {
115+
class UserDefinedFunction extends Stmts instanceof UserDefinedFunctionImpl {
116116
/** Gets the identifier of the user-defined function. */
117117
Identifier getIdentifier() { result = UserDefinedFunctionImpl.super.getName() }
118118

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ class TIdents = TIdentifier or TPropertyIdentifier;
8888
*/
8989
class TStmts =
9090
TInfrastructure or TAssertStatement or TForStatement or TIfStatement or TImportStatement or
91-
TImportWithStatement or TStatement or TUsingStatement or TVariableDeclaration;
91+
TImportWithStatement or TStatement or TUsingStatement or TVariableDeclaration or
92+
TParameterDeclaration or TOutputDeclaration or TUserDefinedFunction;
9293

9394
/**
9495
* A expersion value in a Bicep program

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ private import AstNodes
77
private import TreeSitter
88
private import codeql.bicep.ast.AstNodes
99
private import Stmts
10+
private import Statement
1011

1112

1213
/**
@@ -21,7 +22,7 @@ class InfrastructureImpl extends TInfrastructure, AstNode {
2122

2223
override string toString() { result = ast.toString() }
2324

24-
StmtsImpl getStatement(int index) {
25+
StatementImpl getStatement(int index) {
2526
toTreeSitter(result) = ast.getChild(index)
2627
}
2728
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
private import AstNodes
77
private import TreeSitter
88
private import codeql.bicep.ast.AstNodes
9+
private import Stmts
910
private import Idents
1011
private import Expr
1112
private import Type
1213

1314
/**
1415
* A OutputDeclaration AST Node.
1516
*/
16-
class OutputDeclarationImpl extends TOutputDeclaration, AstNode {
17+
class OutputDeclarationImpl extends TOutputDeclaration, StmtsImpl {
1718
private BICEP::OutputDeclaration ast;
1819

1920
override string getAPrimaryQlClass() { result = "OutputDeclaration" }

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
private import AstNodes
88
private import TreeSitter
99
private import codeql.bicep.ast.AstNodes
10+
private import Stmts
1011
private import Identifier
1112
private import Type
1213
private import Expr
1314

1415
/**
1516
* A ParameterDeclaration AST Node.
1617
*/
17-
class ParameterDeclarationImpl extends TParameterDeclaration, AstNode {
18+
class ParameterDeclarationImpl extends TParameterDeclaration, StmtsImpl {
1819
private BICEP::ParameterDeclaration ast;
1920

2021
override string getAPrimaryQlClass() { result = "ParameterDeclaration" }

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
private import AstNodes
88
private import TreeSitter
99
private import codeql.bicep.ast.AstNodes
10+
private import Stmts
1011
private import Identifier
1112
private import Stmts
1213
private import Type
@@ -16,7 +17,7 @@ private import Parameters
1617
/**
1718
* A UserDefinedFunction AST Node.
1819
*/
19-
class UserDefinedFunctionImpl extends TUserDefinedFunction, AstNode {
20+
class UserDefinedFunctionImpl extends TUserDefinedFunction, StmtsImpl {
2021
private BICEP::UserDefinedFunction ast;
2122

2223
override string getAPrimaryQlClass() { result = "UserDefinedFunction" }

ql/test/library-tests/ast/AST.expected

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,44 @@ ast
11101110
| sample.bicep:98:15:98:20 | MemberExpression |
11111111
| sample.bicep:98:15:98:20 | MemberExpression |
11121112
| sample.bicep:98:19:98:20 | id |
1113+
infra
1114+
| conditions.bicep:1:1:12:2 | Infrastructure | 0 | conditions.bicep:1:1:1:39 | ParameterDeclaration |
1115+
| conditions.bicep:1:1:12:2 | Infrastructure | 1 | conditions.bicep:2:1:2:54 | ParameterDeclaration |
1116+
| conditions.bicep:1:1:12:2 | Infrastructure | 2 | conditions.bicep:4:1:12:1 | ResourceDeclaration |
1117+
| data.bicep:1:1:62:4 | Infrastructure | 0 | data.bicep:2:1:6:1 | VariableDeclaration |
1118+
| data.bicep:1:1:62:4 | Infrastructure | 1 | data.bicep:8:1:8:43 | VariableDeclaration |
1119+
| data.bicep:1:1:62:4 | Infrastructure | 2 | data.bicep:10:1:11:10 | VariableDeclaration |
1120+
| data.bicep:1:1:62:4 | Infrastructure | 3 | data.bicep:13:1:13:28 | VariableDeclaration |
1121+
| data.bicep:1:1:62:4 | Infrastructure | 4 | data.bicep:14:1:14:41 | OutputDeclaration |
1122+
| data.bicep:1:1:62:4 | Infrastructure | 5 | data.bicep:15:1:15:41 | OutputDeclaration |
1123+
| data.bicep:1:1:62:4 | Infrastructure | 6 | data.bicep:17:1:17:13 | VariableDeclaration |
1124+
| data.bicep:1:1:62:4 | Infrastructure | 7 | data.bicep:18:1:18:46 | OutputDeclaration |
1125+
| data.bicep:1:1:62:4 | Infrastructure | 8 | data.bicep:21:1:21:29 | ParameterDeclaration |
1126+
| data.bicep:1:1:62:4 | Infrastructure | 9 | data.bicep:24:1:24:24 | ParameterDeclaration |
1127+
| data.bicep:1:1:62:4 | Infrastructure | 10 | data.bicep:27:1:27:92 | ParameterDeclaration |
1128+
| data.bicep:1:1:62:4 | Infrastructure | 11 | data.bicep:29:1:34:1 | ParameterDeclaration |
1129+
| data.bicep:1:1:62:4 | Infrastructure | 12 | data.bicep:36:1:37:12 | ParameterDeclaration |
1130+
| data.bicep:1:1:62:4 | Infrastructure | 13 | data.bicep:41:1:41:25 | VariableDeclaration |
1131+
| data.bicep:1:1:62:4 | Infrastructure | 14 | data.bicep:42:1:42:52 | TypeDeclaration |
1132+
| data.bicep:1:1:62:4 | Infrastructure | 15 | data.bicep:43:1:43:62 | VariableDeclaration |
1133+
| data.bicep:1:1:62:4 | Infrastructure | 16 | data.bicep:46:1:46:24 | VariableDeclaration |
1134+
| data.bicep:1:1:62:4 | Infrastructure | 17 | data.bicep:49:1:50:9 | VariableDeclaration |
1135+
| data.bicep:1:1:62:4 | Infrastructure | 18 | data.bicep:53:1:55:3 | VariableDeclaration |
1136+
| data.bicep:1:1:62:4 | Infrastructure | 19 | data.bicep:58:1:62:3 | VariableDeclaration |
1137+
| sample.bicep:1:1:103:1 | Infrastructure | 0 | sample.bicep:1:1:1:48 | ParameterDeclaration |
1138+
| sample.bicep:1:1:103:1 | Infrastructure | 1 | sample.bicep:2:1:2:80 | ParameterDeclaration |
1139+
| sample.bicep:1:1:103:1 | Infrastructure | 2 | sample.bicep:3:1:3:28 | ParameterDeclaration |
1140+
| sample.bicep:1:1:103:1 | Infrastructure | 3 | sample.bicep:4:1:4:40 | ParameterDeclaration |
1141+
| sample.bicep:1:1:103:1 | Infrastructure | 4 | sample.bicep:5:1:5:43 | ParameterDeclaration |
1142+
| sample.bicep:1:1:103:1 | Infrastructure | 5 | sample.bicep:6:1:6:32 | ParameterDeclaration |
1143+
| sample.bicep:1:1:103:1 | Infrastructure | 6 | sample.bicep:7:1:7:36 | ParameterDeclaration |
1144+
| sample.bicep:1:1:103:1 | Infrastructure | 7 | sample.bicep:8:1:8:40 | ParameterDeclaration |
1145+
| sample.bicep:1:1:103:1 | Infrastructure | 8 | sample.bicep:9:1:9:30 | ParameterDeclaration |
1146+
| sample.bicep:1:1:103:1 | Infrastructure | 9 | sample.bicep:11:1:21:1 | ResourceDeclaration |
1147+
| sample.bicep:1:1:103:1 | Infrastructure | 10 | sample.bicep:23:1:41:1 | ResourceDeclaration |
1148+
| sample.bicep:1:1:103:1 | Infrastructure | 11 | sample.bicep:43:1:49:1 | ResourceDeclaration |
1149+
| sample.bicep:1:1:103:1 | Infrastructure | 12 | sample.bicep:51:1:70:1 | ResourceDeclaration |
1150+
| sample.bicep:1:1:103:1 | Infrastructure | 13 | sample.bicep:72:1:103:1 | ResourceDeclaration |
11131151
strings
11141152
| conditions.bicep:2:35:2:54 | String | examplestorageacct |
11151153
| conditions.bicep:4:25:4:70 | String | Microsoft.Storage/storageAccounts@2022-09-01 |

ql/test/library-tests/ast/AST.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ private import bicep
22

33
query predicate ast(AstNode ast) { any() }
44

5+
query predicate infra(Infrastructure infra, int index, Stmts stmts) {
6+
stmts = infra.getStatement(index)
7+
}
8+
59
query predicate strings(String str, string output) { output = str.getValue() }
610

711
query predicate ifCondition(IfStatement ifStmt, Expr condition, Expr body) {

ql/test/library-tests/cfg/Cfg.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
| sample.bicep:1:1:1:48 | ParameterDeclaration | sample.bicep:1:1:103:1 | Infrastructure | |
2+
| sample.bicep:1:1:1:48 | ParameterDeclaration | sample.bicep:1:1:103:1 | Infrastructure | |
3+
| sample.bicep:1:1:1:48 | ParameterDeclaration | sample.bicep:1:7:1:14 | location | |
24
| sample.bicep:1:1:103:1 | Infrastructure | sample.bicep:1:1:103:1 | exit Infrastructure (normal) | |
35
| sample.bicep:1:1:103:1 | enter Infrastructure | sample.bicep:1:7:1:14 | location | |
46
| sample.bicep:1:1:103:1 | enter Infrastructure | sample.bicep:1:7:1:14 | location | |
@@ -11,6 +13,9 @@
1113
| sample.bicep:1:7:1:14 | location | sample.bicep:1:1:1:48 | ParameterDeclaration | |
1214
| sample.bicep:1:7:1:14 | location | sample.bicep:1:1:1:48 | ParameterDeclaration | |
1315
| sample.bicep:1:7:1:14 | location | sample.bicep:1:1:1:48 | ParameterDeclaration | |
16+
| sample.bicep:1:7:1:14 | location | sample.bicep:1:1:1:48 | ParameterDeclaration | |
17+
| sample.bicep:1:7:1:14 | location | sample.bicep:1:1:1:48 | ParameterDeclaration | |
18+
| sample.bicep:1:7:1:14 | location | sample.bicep:1:1:1:48 | ParameterDeclaration | |
1419
| sample.bicep:1:7:1:14 | location | sample.bicep:1:25:1:37 | resourceGroup | |
1520
| sample.bicep:1:7:1:14 | location | sample.bicep:1:25:1:37 | resourceGroup | |
1621
| sample.bicep:1:7:1:14 | location | sample.bicep:1:25:1:37 | resourceGroup | |
@@ -36,6 +41,9 @@
3641
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:1:48 | ParameterDeclaration | |
3742
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:1:48 | ParameterDeclaration | |
3843
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:1:48 | ParameterDeclaration | |
44+
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:1:48 | ParameterDeclaration | |
45+
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:1:48 | ParameterDeclaration | |
46+
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:1:48 | ParameterDeclaration | |
3947
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:103:1 | Infrastructure | , BooleanSuccessor, BooleanSuccessor |
4048
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:103:1 | Infrastructure | , BooleanSuccessor, BooleanSuccessor |
4149
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:103:1 | Infrastructure | , BooleanSuccessor, BooleanSuccessor |

0 commit comments

Comments
 (0)