Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ql/lib/codeql/bicep/ast/Stmts.qll
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Infrastructure extends AstNode instanceof InfrastructureImpl {
* Represents a parameter declaration node in the AST.
* Provides access to the identifier, name, type, and default value of the parameter.
*/
class ParameterDeclaration extends AstNode instanceof ParameterDeclarationImpl {
class ParameterDeclaration extends Stmts instanceof ParameterDeclarationImpl {
/** Gets the identifier of the parameter declaration. */
Identifier getIdentifier() { result = ParameterDeclarationImpl.super.getName() }

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

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

Expand Down
3 changes: 2 additions & 1 deletion ql/lib/codeql/bicep/ast/internal/AstNodes.qll
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class TIdents = TIdentifier or TPropertyIdentifier;
*/
class TStmts =
TInfrastructure or TAssertStatement or TForStatement or TIfStatement or TImportStatement or
TImportWithStatement or TStatement or TUsingStatement or TVariableDeclaration;
TImportWithStatement or TStatement or TUsingStatement or TVariableDeclaration or
TParameterDeclaration or TOutputDeclaration or TUserDefinedFunction;

/**
* A expersion value in a Bicep program
Expand Down
3 changes: 2 additions & 1 deletion ql/lib/codeql/bicep/ast/internal/Infrastructure.qll
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ private import AstNodes
private import TreeSitter
private import codeql.bicep.ast.AstNodes
private import Stmts
private import Statement


/**
Expand All @@ -21,7 +22,7 @@ class InfrastructureImpl extends TInfrastructure, AstNode {

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

StmtsImpl getStatement(int index) {
StatementImpl getStatement(int index) {
toTreeSitter(result) = ast.getChild(index)
}
}
3 changes: 2 additions & 1 deletion ql/lib/codeql/bicep/ast/internal/OutputDeclaration.qll
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
private import AstNodes
private import TreeSitter
private import codeql.bicep.ast.AstNodes
private import Stmts
private import Idents
private import Expr
private import Type

/**
* A OutputDeclaration AST Node.
*/
class OutputDeclarationImpl extends TOutputDeclaration, AstNode {
class OutputDeclarationImpl extends TOutputDeclaration, StmtsImpl {
private BICEP::OutputDeclaration ast;

override string getAPrimaryQlClass() { result = "OutputDeclaration" }
Expand Down
3 changes: 2 additions & 1 deletion ql/lib/codeql/bicep/ast/internal/ParameterDeclaration.qll
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
private import AstNodes
private import TreeSitter
private import codeql.bicep.ast.AstNodes
private import Stmts
private import Identifier
private import Type
private import Expr

/**
* A ParameterDeclaration AST Node.
*/
class ParameterDeclarationImpl extends TParameterDeclaration, AstNode {
class ParameterDeclarationImpl extends TParameterDeclaration, StmtsImpl {
private BICEP::ParameterDeclaration ast;

override string getAPrimaryQlClass() { result = "ParameterDeclaration" }
Expand Down
3 changes: 2 additions & 1 deletion ql/lib/codeql/bicep/ast/internal/UserDefinedFunction.qll
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
private import AstNodes
private import TreeSitter
private import codeql.bicep.ast.AstNodes
private import Stmts
private import Identifier
private import Stmts
private import Type
Expand All @@ -16,7 +17,7 @@ private import Parameters
/**
* A UserDefinedFunction AST Node.
*/
class UserDefinedFunctionImpl extends TUserDefinedFunction, AstNode {
class UserDefinedFunctionImpl extends TUserDefinedFunction, StmtsImpl {
private BICEP::UserDefinedFunction ast;

override string getAPrimaryQlClass() { result = "UserDefinedFunction" }
Expand Down
38 changes: 38 additions & 0 deletions ql/test/library-tests/ast/AST.expected
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,44 @@ ast
| sample.bicep:98:15:98:20 | MemberExpression |
| sample.bicep:98:15:98:20 | MemberExpression |
| sample.bicep:98:19:98:20 | id |
infra
| conditions.bicep:1:1:12:2 | Infrastructure | 0 | conditions.bicep:1:1:1:39 | ParameterDeclaration |
| conditions.bicep:1:1:12:2 | Infrastructure | 1 | conditions.bicep:2:1:2:54 | ParameterDeclaration |
| conditions.bicep:1:1:12:2 | Infrastructure | 2 | conditions.bicep:4:1:12:1 | ResourceDeclaration |
| data.bicep:1:1:62:4 | Infrastructure | 0 | data.bicep:2:1:6:1 | VariableDeclaration |
| data.bicep:1:1:62:4 | Infrastructure | 1 | data.bicep:8:1:8:43 | VariableDeclaration |
| data.bicep:1:1:62:4 | Infrastructure | 2 | data.bicep:10:1:11:10 | VariableDeclaration |
| data.bicep:1:1:62:4 | Infrastructure | 3 | data.bicep:13:1:13:28 | VariableDeclaration |
| data.bicep:1:1:62:4 | Infrastructure | 4 | data.bicep:14:1:14:41 | OutputDeclaration |
| data.bicep:1:1:62:4 | Infrastructure | 5 | data.bicep:15:1:15:41 | OutputDeclaration |
| data.bicep:1:1:62:4 | Infrastructure | 6 | data.bicep:17:1:17:13 | VariableDeclaration |
| data.bicep:1:1:62:4 | Infrastructure | 7 | data.bicep:18:1:18:46 | OutputDeclaration |
| data.bicep:1:1:62:4 | Infrastructure | 8 | data.bicep:21:1:21:29 | ParameterDeclaration |
| data.bicep:1:1:62:4 | Infrastructure | 9 | data.bicep:24:1:24:24 | ParameterDeclaration |
| data.bicep:1:1:62:4 | Infrastructure | 10 | data.bicep:27:1:27:92 | ParameterDeclaration |
| data.bicep:1:1:62:4 | Infrastructure | 11 | data.bicep:29:1:34:1 | ParameterDeclaration |
| data.bicep:1:1:62:4 | Infrastructure | 12 | data.bicep:36:1:37:12 | ParameterDeclaration |
| data.bicep:1:1:62:4 | Infrastructure | 13 | data.bicep:41:1:41:25 | VariableDeclaration |
| data.bicep:1:1:62:4 | Infrastructure | 14 | data.bicep:42:1:42:52 | TypeDeclaration |
| data.bicep:1:1:62:4 | Infrastructure | 15 | data.bicep:43:1:43:62 | VariableDeclaration |
| data.bicep:1:1:62:4 | Infrastructure | 16 | data.bicep:46:1:46:24 | VariableDeclaration |
| data.bicep:1:1:62:4 | Infrastructure | 17 | data.bicep:49:1:50:9 | VariableDeclaration |
| data.bicep:1:1:62:4 | Infrastructure | 18 | data.bicep:53:1:55:3 | VariableDeclaration |
| data.bicep:1:1:62:4 | Infrastructure | 19 | data.bicep:58:1:62:3 | VariableDeclaration |
| sample.bicep:1:1:103:1 | Infrastructure | 0 | sample.bicep:1:1:1:48 | ParameterDeclaration |
| sample.bicep:1:1:103:1 | Infrastructure | 1 | sample.bicep:2:1:2:80 | ParameterDeclaration |
| sample.bicep:1:1:103:1 | Infrastructure | 2 | sample.bicep:3:1:3:28 | ParameterDeclaration |
| sample.bicep:1:1:103:1 | Infrastructure | 3 | sample.bicep:4:1:4:40 | ParameterDeclaration |
| sample.bicep:1:1:103:1 | Infrastructure | 4 | sample.bicep:5:1:5:43 | ParameterDeclaration |
| sample.bicep:1:1:103:1 | Infrastructure | 5 | sample.bicep:6:1:6:32 | ParameterDeclaration |
| sample.bicep:1:1:103:1 | Infrastructure | 6 | sample.bicep:7:1:7:36 | ParameterDeclaration |
| sample.bicep:1:1:103:1 | Infrastructure | 7 | sample.bicep:8:1:8:40 | ParameterDeclaration |
| sample.bicep:1:1:103:1 | Infrastructure | 8 | sample.bicep:9:1:9:30 | ParameterDeclaration |
| sample.bicep:1:1:103:1 | Infrastructure | 9 | sample.bicep:11:1:21:1 | ResourceDeclaration |
| sample.bicep:1:1:103:1 | Infrastructure | 10 | sample.bicep:23:1:41:1 | ResourceDeclaration |
| sample.bicep:1:1:103:1 | Infrastructure | 11 | sample.bicep:43:1:49:1 | ResourceDeclaration |
| sample.bicep:1:1:103:1 | Infrastructure | 12 | sample.bicep:51:1:70:1 | ResourceDeclaration |
| sample.bicep:1:1:103:1 | Infrastructure | 13 | sample.bicep:72:1:103:1 | ResourceDeclaration |
strings
| conditions.bicep:2:35:2:54 | String | examplestorageacct |
| conditions.bicep:4:25:4:70 | String | Microsoft.Storage/storageAccounts@2022-09-01 |
Expand Down
4 changes: 4 additions & 0 deletions ql/test/library-tests/ast/AST.ql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ private import bicep

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

query predicate infra(Infrastructure infra, int index, Stmts stmts) {
stmts = infra.getStatement(index)
}

query predicate strings(String str, string output) { output = str.getValue() }

query predicate ifCondition(IfStatement ifStmt, Expr condition, Expr body) {
Expand Down
8 changes: 8 additions & 0 deletions ql/test/library-tests/cfg/Cfg.expected
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
| sample.bicep:1:1:1:48 | ParameterDeclaration | sample.bicep:1:1:103:1 | Infrastructure | |
| sample.bicep:1:1:1:48 | ParameterDeclaration | sample.bicep:1:1:103:1 | Infrastructure | |
| sample.bicep:1:1:1:48 | ParameterDeclaration | sample.bicep:1:7:1:14 | location | |
| sample.bicep:1:1:103:1 | Infrastructure | sample.bicep:1:1:103:1 | exit Infrastructure (normal) | |
| sample.bicep:1:1:103:1 | enter Infrastructure | sample.bicep:1:7:1:14 | location | |
| sample.bicep:1:1:103:1 | enter Infrastructure | sample.bicep:1:7:1:14 | location | |
Expand All @@ -11,6 +13,9 @@
| sample.bicep:1:7:1:14 | location | sample.bicep:1:1:1:48 | ParameterDeclaration | |
| sample.bicep:1:7:1:14 | location | sample.bicep:1:1:1:48 | ParameterDeclaration | |
| sample.bicep:1:7:1:14 | location | sample.bicep:1:1:1:48 | ParameterDeclaration | |
| sample.bicep:1:7:1:14 | location | sample.bicep:1:1:1:48 | ParameterDeclaration | |
| sample.bicep:1:7:1:14 | location | sample.bicep:1:1:1:48 | ParameterDeclaration | |
| sample.bicep:1:7:1:14 | location | sample.bicep:1:1:1:48 | ParameterDeclaration | |
| sample.bicep:1:7:1:14 | location | sample.bicep:1:25:1:37 | resourceGroup | |
| sample.bicep:1:7:1:14 | location | sample.bicep:1:25:1:37 | resourceGroup | |
| sample.bicep:1:7:1:14 | location | sample.bicep:1:25:1:37 | resourceGroup | |
Expand All @@ -36,6 +41,9 @@
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:1:48 | ParameterDeclaration | |
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:1:48 | ParameterDeclaration | |
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:1:48 | ParameterDeclaration | |
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:1:48 | ParameterDeclaration | |
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:1:48 | ParameterDeclaration | |
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:1:48 | ParameterDeclaration | |
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:103:1 | Infrastructure | , BooleanSuccessor, BooleanSuccessor |
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:103:1 | Infrastructure | , BooleanSuccessor, BooleanSuccessor |
| sample.bicep:1:25:1:48 | MemberExpression | sample.bicep:1:1:103:1 | Infrastructure | , BooleanSuccessor, BooleanSuccessor |
Expand Down