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
1 change: 1 addition & 0 deletions ql/lib/codeql/bicep/AST.qll
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ast.AstNodes
import ast.Literals
import ast.Calls
import ast.Expr
import ast.Stmts
import ast.Loops
Expand Down
119 changes: 118 additions & 1 deletion ql/lib/codeql/bicep/ast/Calls.qll
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
private import AstNodes
private import Expr
private import Idents
private import Misc
private import internal.Arguments
private import internal.CallExpression
private import internal.Parameter
private import internal.Parameters
private import internal.ParameterDeclaration
private import internal.UserDefinedFunction

abstract class Callable extends Expr {
/**
Expand All @@ -17,4 +24,114 @@ abstract class Callable extends Expr {
* Checks if the call expression has a specific name.
*/
predicate hasName(string name) { this.getName() = name }
}
}

/**
* A CallExpression expression in the AST.
*/
class CallExpression extends Callable instanceof CallExpressionImpl {
override Idents getIdentifier() {
result = CallExpressionImpl.super.getIdentifier()
}

Expr getArgument(int index) {
result = this.getDeclaredArguments().getArgument(index)
}

Expr getArguments() {
result = this.getDeclaredArguments().getArguments()
}

Arguments getDeclaredArguments() {
result = CallExpressionImpl.super.getArguments()
}
}


/**
* A Arguments unknown AST node.
*/
class Arguments extends AstNode instanceof ArgumentsImpl {

Expr getArgument(int index) {
result = ArgumentsImpl.super.getArgument(index)
}

Expr getArguments() {
result = ArgumentsImpl.super.getArguments()
}
}

/**
* A Parameter unknown AST node.
*/
class Parameter extends AstNode instanceof ParameterImpl {

Idents getName() {
result = ParameterImpl.super.getName()
}

Type getType() {
result = ParameterImpl.super.getType()
}
}

/**
* A Parameters unknown AST node.
*/
class Parameters extends AstNode instanceof ParametersImpl {
Parameter getParameter(int index) {
result = ParametersImpl.super.getParameter(index)
}
}


/**
* A ParameterDeclaration unknown AST node.
*/
class ParameterDeclaration extends AstNode instanceof ParameterDeclarationImpl {
Identifier getName() {
result = ParameterDeclarationImpl.super.getName()
}

Type getType() {
result = ParameterDeclarationImpl.super.getType()
}

Expr getDefaultValue() {
result = ParameterDeclarationImpl.super.getDefaultValue()
}
}

/**
* A UserDefinedFunction unknown AST node.
*/
class UserDefinedFunction extends AstNode instanceof UserDefinedFunctionImpl {
Identifier getIdentifier() {
result = UserDefinedFunctionImpl.super.getName()
}

string getName() {
result = this.getIdentifier().getName()
}

Type getReturnType() {
result = UserDefinedFunctionImpl.super.getReturnType()
}

Parameters getDeclaredParameters() {
result = UserDefinedFunctionImpl.super.getParameters()
}

Parameter getParameters() {
result = this.getDeclaredParameters().getParameter(_)
}

Parameter getParameter(int index) {
result = this.getDeclaredParameters().getParameter(index)
}

Expr getBody() {
result = UserDefinedFunctionImpl.super.getBody()
}
}
37 changes: 20 additions & 17 deletions ql/lib/codeql/bicep/ast/Expr.qll
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/**
* Bicep AST expressions.
*/

private import AstNodes
private import internal.AstNodes
private import internal.TreeSitter
private import internal.Expr
private import internal.AssignmentExpression
private import internal.BinaryExpression
private import internal.CallExpression
private import internal.Expression
private import internal.Interpolation
private import internal.LambdaExpression
Expand All @@ -16,7 +19,6 @@ private import internal.ResourceExpression
private import internal.SubscriptExpression
private import internal.TernaryExpression
private import internal.UnaryExpression

private import Idents
private import Resources

Expand All @@ -35,11 +37,6 @@ final class AssignmentExpression extends Expr instanceof AssignmentExpressionImp
*/
final class BinaryExpression extends Expr instanceof BinaryExpressionImpl { }

/**
* A CallExpression expression in the AST.
*/
final class CallExpression extends Expr instanceof CallExpressionImpl { }

/**
* A Expression expression in the AST.
*/
Expand All @@ -59,16 +56,22 @@ final class LambdaExpression extends Expr instanceof LambdaExpressionImpl { }
* A MemberExpression expression in the AST.
*/
class MemberExpression extends Expr instanceof MemberExpressionImpl {

/**
* The namespace of the member expression.
*/
Idents getNamespace() { result = MemberExpressionImpl.super.getObject() }

/**
* The member of the member expression.
*/
Idents getName() { result = MemberExpressionImpl.super.getProperty() }
/**
* The namespace of the member expression.
*/
Idents getNamespace() { result = MemberExpressionImpl.super.getObject() }

/**
* The member of the member expression.
*/
Idents getName() { result = MemberExpressionImpl.super.getProperty() }

/**
* Gets the full name of the member expression, which includes the namespace and the member name.
*/
string getFullName() {
result = this.getNamespace().getName() + "." + this.getName().getName()
}
}

/**
Expand Down
44 changes: 9 additions & 35 deletions ql/lib/codeql/bicep/ast/Misc.qll
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
private import AstNodes
private import internal.Arguments

private import internal.Array
private import internal.ArrayType
private import internal.Boolean
Expand All @@ -12,18 +12,14 @@ private import internal.EscapeSequence
private import internal.ForLoopParameters
private import internal.Identifier
private import internal.ImportFunctionality
private import internal.Infrastructure
private import internal.LoopEnumerator
private import internal.LoopVariable
private import internal.MetadataDeclaration
private import internal.ModuleDeclaration
private import internal.NegatedType
private import internal.ObjectProperty
private import internal.OutputDeclaration
private import internal.Parameter
private import internal.ParameterDeclaration
private import internal.ParameterizedType
private import internal.Parameters
private import internal.ParenthesizedType
private import internal.PrimitiveType
private import internal.PropertyIdentifier
Expand All @@ -33,14 +29,8 @@ private import internal.Type
private import internal.TypeArguments
private import internal.TypeDeclaration
private import internal.UnionType
private import internal.UserDefinedFunction
private import internal.VariableDeclaration

/**
* A Arguments unknown AST node.
*/
class Arguments extends AstNode instanceof ArgumentsImpl { }

/**
* A ArrayType unknown AST node.
*/
Expand Down Expand Up @@ -87,11 +77,6 @@ class ForLoopParameters extends AstNode instanceof ForLoopParametersImpl { }
*/
class ImportFunctionality extends AstNode instanceof ImportFunctionalityImpl { }

/**
* A Infrastructure unknown AST node.
*/
class Infrastructure extends AstNode instanceof InfrastructureImpl { }

/**
* A LoopEnumerator unknown AST node.
*/
Expand Down Expand Up @@ -122,25 +107,11 @@ class NegatedType extends AstNode instanceof NegatedTypeImpl { }
*/
class OutputDeclaration extends AstNode instanceof OutputDeclarationImpl { }

/**
* A Parameter unknown AST node.
*/
class Parameter extends AstNode instanceof ParameterImpl { }

/**
* A ParameterDeclaration unknown AST node.
*/
class ParameterDeclaration extends AstNode instanceof ParameterDeclarationImpl { }

/**
* A ParameterizedType unknown AST node.
*/
class ParameterizedType extends AstNode instanceof ParameterizedTypeImpl { }

/**
* A Parameters unknown AST node.
*/
class Parameters extends AstNode instanceof ParametersImpl { }

/**
* A ParenthesizedType unknown AST node.
Expand All @@ -165,7 +136,14 @@ class TestBlock extends AstNode instanceof TestBlockImpl { }
/**
* A Type unknown AST node.
*/
class Type extends AstNode instanceof TypeImpl { }
class Type extends AstNode instanceof TypeImpl {
/**
* Returns the type of this AST node.
*/
string getType() {
result = TypeImpl.super.getType()
}
}

/**
* A TypeArguments unknown AST node.
Expand All @@ -182,10 +160,6 @@ class TypeDeclaration extends AstNode instanceof TypeDeclarationImpl { }
*/
class UnionType extends AstNode instanceof UnionTypeImpl { }

/**
* A UserDefinedFunction unknown AST node.
*/
class UserDefinedFunction extends AstNode instanceof UserDefinedFunctionImpl { }

/**
* A VariableDeclaration unknown AST node.
Expand Down
20 changes: 17 additions & 3 deletions ql/lib/codeql/bicep/ast/Stmts.qll
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Statement nodes in the AST.
*/

private import AstNodes
private import internal.AstNodes
private import internal.TreeSitter
Expand All @@ -10,6 +11,7 @@ private import internal.ForStatement
private import internal.IfStatement
private import internal.ImportStatement
private import internal.ImportWithStatement
private import internal.Infrastructure
private import internal.Statement
private import internal.UsingStatement
// CFG
Expand All @@ -22,37 +24,49 @@ private import codeql.bicep.controlflow.internal.ControlFlowGraphImpl as CfgImpl
class Stmts extends AstNode instanceof StmtsImpl {
/** Gets a control-flow node for this statement, if any. */
CfgImpl::AstCfgNode getAControlFlowNode() { result.getAstNode() = this }

/** Gets a control-flow entry node for this statement, if any */
AstNode getAControlFlowEntryNode() { result = CfgImpl::getAControlFlowEntryNode(this) }
}



/**
* A AssertStatement statement
*/
final class AssertStatementStmt extends Stmts instanceof AssertStatementImpl { }

/**
* A ForStatement statement
*/
final class ForStatementStmt extends Stmts instanceof ForStatementImpl { }

/**
* A IfStatement statement
*/
final class IfStatementStmt extends Stmts instanceof IfStatementImpl { }

/**
* A ImportStatement statement
*/
final class ImportStatementStmt extends Stmts instanceof ImportStatementImpl { }

/**
* A Infrastructure unknown AST node.
*/
class Infrastructure extends AstNode instanceof InfrastructureImpl {
/** Gets the first statement in the infrastructure. */
Stmts getStatement(int index) { result = InfrastructureImpl.super.getStatement(index) }
}

/**
* A ImportWithStatement statement
*/
final class ImportWithStatementStmt extends Stmts instanceof ImportWithStatementImpl { }

/**
* A Statement statement
*/
final class StatementStmt extends Stmts instanceof StatementImpl { }

/**
* A UsingStatement statement
*/
Expand Down
Loading