Skip to content

Commit 22a30ab

Browse files
authored
Merge pull request #83 from microsoft/powershell-more-ast-classes
PS: Copy existing AST classes from internal repo
2 parents 9ba4ffd + fd4b2b2 commit 22a30ab

File tree

103 files changed

+2808
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+2808
-0
lines changed

powershell/ql/lib/powershell.qll

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import semmle.code.powershell.File
2+
import semmle.code.powershell.Location
3+
import semmle.code.powershell.SourceLocation
4+
import semmle.code.powershell.Ast
5+
import semmle.code.powershell.Statement
6+
import semmle.code.powershell.Expression
7+
import semmle.code.powershell.CommandBase
8+
import semmle.code.powershell.AttributeBase
9+
import semmle.code.powershell.PipelineBase
10+
import semmle.code.powershell.BaseConstantExpression
11+
import semmle.code.powershell.ConstantExpression
12+
import semmle.code.powershell.MemberExpressionBase
13+
import semmle.code.powershell.Attribute
14+
import semmle.code.powershell.NamedAttributeArgument
15+
import semmle.code.powershell.TypeConstraint
16+
import semmle.code.powershell.VariableExpression
17+
import semmle.code.powershell.Parameter
18+
import semmle.code.powershell.ModuleSpecification
19+
import semmle.code.powershell.ParamBlock
20+
import semmle.code.powershell.NamedBlock
21+
import semmle.code.powershell.ScriptBlock
22+
import semmle.code.powershell.StringLiteral
23+
import semmle.code.powershell.AssignmentStatement
24+
import semmle.code.powershell.BinaryExpression
25+
import semmle.code.powershell.ScriptBlockExpr
26+
import semmle.code.powershell.TernaryExpression
27+
import semmle.code.powershell.UsingExpression
28+
import semmle.code.powershell.TrapStatement
29+
import semmle.code.powershell.StatementBlock
30+
import semmle.code.powershell.ArrayExpression
31+
import semmle.code.powershell.ArrayLiteral
32+
import semmle.code.powershell.CommandElement
33+
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
59+
import semmle.code.powershell.Command
60+
import semmle.code.powershell.CommandExpression
61+
import semmle.code.powershell.CommandParameter
62+
import semmle.code.powershell.ExpandableStringExpression
63+
import semmle.code.powershell.TypeExpression
64+
import semmle.code.powershell.ParenExpression
65+
import semmle.code.powershell.Chainable
66+
import semmle.code.powershell.Pipeline
67+
import semmle.code.powershell.StringConstantExpression
68+
import semmle.code.powershell.FunctionDefinition
69+
import semmle.code.powershell.InvokeMemberExpression
70+
import semmle.code.powershell.CommentEntity

powershell/ql/lib/qlpack.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: microsoft-sdl/powershell-all
2+
version: 0.0.1
3+
groups:
4+
- powershell
5+
- microsoft-all
6+
dbscheme: semmlecode.powershell.dbscheme
7+
extractor: powershell
8+
library: true
9+
warnOnImplicitThis: true
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import powershell
2+
3+
class ArrayExpr extends @array_expression, Expr {
4+
override SourceLocation getLocation() { array_expression_location(this, result) }
5+
6+
StmtBlock getStatementBlock() { array_expression(this, result) }
7+
8+
override string toString() { result = "ArrayExpression at: " + this.getLocation().toString() }
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import powershell
2+
3+
class ArrayLiteral extends @array_literal, Expr {
4+
override SourceLocation getLocation() { array_literal_location(this, result) }
5+
6+
Expr getElement(int index) { array_literal_element(this, index, result) }
7+
8+
Expr getAnElement() { array_literal_element(this, _, result) }
9+
10+
override string toString() { result = "ArrayLiteral at: " + this.getLocation().toString() }
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import powershell
2+
3+
class AssignStmt extends @assignment_statement, Stmt {
4+
override SourceLocation getLocation() { assignment_statement_location(this, result) }
5+
6+
int getKind() { assignment_statement(this, result, _, _) }
7+
8+
Expr getLeftHandSide() { assignment_statement(this, _, result, _) }
9+
10+
Stmt getRightHandSide() { assignment_statement(this, _, _, result) }
11+
12+
override string toString() { result = "AssignmentStatement at: " + this.getLocation().toString() }
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import powershell
2+
3+
class Ast extends @ast {
4+
string toString() { none() }
5+
6+
Ast getParent() { parent(result, this) }
7+
8+
Location getLocation() { none() }
9+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import powershell
2+
3+
class Attribute extends @attribute, AttributeBase {
4+
override string toString() { result = this.getName() }
5+
6+
override SourceLocation getLocation() { attribute_location(this, result) }
7+
8+
string getName() { attribute(this, result, _, _) }
9+
10+
int getNumNamedArguments() { attribute(this, _, result, _) }
11+
12+
int getNumPositionalArguments() { attribute(this, _, _, result) }
13+
14+
NamedAttributeArgument getNamedArgument(int i) { attribute_named_argument(this, i, result) }
15+
16+
NamedAttributeArgument getANamedArgument() { result = this.getNamedArgument(_) }
17+
18+
Expr getPositionalArgument(int i) { attribute_positional_argument(this, i, result) }
19+
20+
Expr getAPositionalArgument() { result = this.getPositionalArgument(_) }
21+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import powershell
2+
3+
class AttributeBase extends @attribute_base, Ast { }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import powershell
2+
3+
class BaseConstExpr extends @base_constant_expression, Expr { }
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import powershell
2+
3+
class BinaryExpr extends @binary_expression, Expr {
4+
override string toString() {
5+
result = "...+..." // TODO
6+
}
7+
8+
override SourceLocation getLocation() { binary_expression_location(this, result) }
9+
10+
private int getKind() { binary_expression(this, result, _, _) }
11+
12+
Expr getLeft() { binary_expression(this, _, result, _) }
13+
14+
Expr getRight() { binary_expression(this, _, _, result) }
15+
}

0 commit comments

Comments
 (0)