Skip to content

Commit 71349af

Browse files
committed
PS: Add more AST classes.
1 parent 023c88a commit 71349af

28 files changed

+358
-0
lines changed

powershell/ql/lib/powershell.qll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import semmle.code.powershell.ConstantExpression
1212
import semmle.code.powershell.MemberExpressionBase
1313
import semmle.code.powershell.Attribute
1414
import semmle.code.powershell.NamedAttributeArgument
15+
import semmle.code.powershell.TypeConstraint
1516
import semmle.code.powershell.VariableExpression
1617
import semmle.code.powershell.Parameter
1718
import semmle.code.powershell.ModuleSpecification
@@ -21,13 +22,40 @@ import semmle.code.powershell.ScriptBlock
2122
import semmle.code.powershell.StringLiteral
2223
import semmle.code.powershell.AssignmentStatement
2324
import semmle.code.powershell.BinaryExpression
25+
import semmle.code.powershell.ScriptBlockExpr
2426
import semmle.code.powershell.TernaryExpression
27+
import semmle.code.powershell.UsingExpression
2528
import semmle.code.powershell.TrapStatement
2629
import semmle.code.powershell.StatementBlock
2730
import semmle.code.powershell.ArrayExpression
2831
import semmle.code.powershell.ArrayLiteral
2932
import semmle.code.powershell.CommandElement
3033
import semmle.code.powershell.Redirection
34+
import semmle.code.powershell.FileRedirection
35+
import semmle.code.powershell.MergingRedirection
36+
import semmle.code.powershell.LoopStmt
37+
import semmle.code.powershell.DoWhileStmt
38+
import semmle.code.powershell.DoUntilStmt
39+
import semmle.code.powershell.WhileStmt
40+
import semmle.code.powershell.ForStmt
41+
import semmle.code.powershell.ForEachStmt
42+
import semmle.code.powershell.GotoStmt
43+
import semmle.code.powershell.ContinueStmt
44+
import semmle.code.powershell.BreakStmt
45+
import semmle.code.powershell.ReturnStmt
46+
import semmle.code.powershell.UsingStmt
47+
import semmle.code.powershell.Type
48+
import semmle.code.powershell.Member
49+
import semmle.code.powershell.PropertyMember
50+
import semmle.code.powershell.FunctionMember
51+
import semmle.code.powershell.TryStmt
52+
import semmle.code.powershell.IfStmt
53+
import semmle.code.powershell.ExitStmt
54+
import semmle.code.powershell.LabeledStmt
55+
import semmle.code.powershell.DynamicStmt
56+
import semmle.code.powershell.DataStmt
57+
import semmle.code.powershell.Configuration
58+
import semmle.code.powershell.CatchClause
3159
import semmle.code.powershell.Command
3260
import semmle.code.powershell.CommandExpression
3361
import semmle.code.powershell.CommandParameter
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import powershell
2+
3+
class BreakStmt extends GotoStmt, Stmt {
4+
override SourceLocation getLocation() { break_statement_location(this, result) }
5+
6+
override string toString() { result = "continue" }
7+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import powershell
2+
3+
class CatchClause extends @catch_clause, Ast {
4+
override SourceLocation getLocation() { catch_clause_location(this, result) }
5+
6+
override string toString() { result = "catch {...}" }
7+
8+
StmtBlock getBody() { catch_clause(this, result, _) } // TODO: Change @ast to @stmt_block in dbscheme
9+
10+
TypeConstraint getCatchType(int i) { catch_clause_catch_type(this, i, result) } // TODO: Change @ast to @type_constraint in dbscheme
11+
12+
TypeConstraint getACatchType() { result = this.getCatchType(_) }
13+
14+
predicate isCatchAll() { catch_clause(this, _, true) } // TODO: Should be equivalent to not exists(this.getACatchType())
15+
16+
TryStmt getTryStmt() { result.getACatchClause() = this }
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import powershell
2+
3+
class Configuration extends @configuration_definition, Stmt {
4+
override SourceLocation getLocation() { configuration_definition_location(this, result) }
5+
6+
override string toString() { result = "Configuration" }
7+
8+
Expr getName() { configuration_definition(this, _, _, result) } // TODO: Change @ast to @expression in dbscheme
9+
10+
ScriptBlockExpr getBody() { configuration_definition(this, result, _, _) } // TODO: Change @ast to @script_block in dbscheme
11+
12+
predicate isMeta() { configuration_definition(this, _, 1, _) }
13+
14+
predicate isResource() { configuration_definition(this, _, 0, _) }
15+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import powershell
2+
3+
class ContinueStmt extends GotoStmt, Stmt {
4+
override SourceLocation getLocation() { continue_statement_location(this, result) }
5+
6+
override string toString() { result = "continue" }
7+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import powershell
2+
3+
class DataStmt extends @data_statement, Stmt {
4+
override SourceLocation getLocation() { data_statement_location(this, result) }
5+
6+
override string toString() { result = "data {...}" }
7+
8+
string getVariableName() { data_statement_variable(this, result) }
9+
10+
Expr getCmdAllowed(int i) { data_statement_commands_allowed(this, i, result) }
11+
12+
Expr getACmdAllowed() { result = this.getCmdAllowed(_) }
13+
14+
StmtBlock getBody() { data_statement(this, result) } // TODO: Change @ast to @stmt_block in dbscheme
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import powershell
2+
3+
class DoUntilStmt extends @do_until_statement, LoopStmt {
4+
override SourceLocation getLocation() { do_until_statement_location(this, result) }
5+
6+
override string toString() { result = "DoUntil" }
7+
8+
PipelineBase getCondition() { do_until_statement_condition(this, result) } // TODO: Change @ast to @pipeline_base in dbscheme
9+
10+
StmtBlock getBody() { do_until_statement(this, result) } // TODO: Change @ast to @stmt_block in dbscheme
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import powershell
2+
3+
class DoWhileStmt extends @do_while_statement, LoopStmt {
4+
override SourceLocation getLocation() { do_while_statement_location(this, result) }
5+
6+
override string toString() { result = "DoWhile" }
7+
8+
PipelineBase getCondition() { do_while_statement_condition(this, result) } // TODO: Change @ast to @pipeline_base in dbscheme
9+
10+
StmtBlock getBody() { do_while_statement(this, result) } // TODO: Change @ast to @stmt_block in dbscheme
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import powershell
2+
3+
class DynamicStmt extends @dynamic_keyword_statement, Stmt {
4+
override SourceLocation getLocation() { dynamic_keyword_statement_location(this, result) }
5+
6+
override string toString() { result = "&..." }
7+
8+
CmdElement getCmd(int i) { dynamic_keyword_statement_command_elements(this, i, result) }
9+
10+
CmdElement getACmd() { result = this.getCmd(_) }
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import powershell
2+
3+
class ExitStmt extends @exit_statement, Stmt {
4+
override SourceLocation getLocation() { exit_statement_location(this, result) }
5+
6+
override string toString() { if this.hasPipeline() then result = "exit ..." else result = "exit" }
7+
8+
/** ..., if any. */
9+
PipelineBase getPipeline() { exit_statement_pipeline(this, result) } // TODO: Change @ast to @pipeline_base in dbscheme
10+
11+
predicate hasPipeline() { exists(this.getPipeline()) }
12+
}

0 commit comments

Comments
 (0)