Skip to content

Commit efba031

Browse files
committed
PS: Fixup AST by adding missing imports. Also use extends instead of instanceof in AST classes.
1 parent 0c4a3f4 commit efba031

Some content is hidden

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

46 files changed

+1984
-1326
lines changed

powershell/ql/lib/powershell.qll

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
// File Metadata
21
import semmle.code.powershell.File
32
import semmle.code.powershell.Location
43
import semmle.code.powershell.SourceLocation
5-
// Base Classes
64
import semmle.code.powershell.Ast
7-
import semmle.code.powershell.TokenKind
85
import semmle.code.powershell.Statement
96
import semmle.code.powershell.Expression
107
import semmle.code.powershell.CommandBase
@@ -13,20 +10,15 @@ import semmle.code.powershell.PipelineBase
1310
import semmle.code.powershell.BaseConstantExpression
1411
import semmle.code.powershell.ConstantExpression
1512
import semmle.code.powershell.MemberExpressionBase
16-
1713
import semmle.code.powershell.Attribute
1814
import semmle.code.powershell.NamedAttributeArgument
1915
import semmle.code.powershell.VariableExpression
2016
import semmle.code.powershell.Parameter
21-
2217
import semmle.code.powershell.ModuleSpecification
2318
import semmle.code.powershell.ParamBlock
2419
import semmle.code.powershell.NamedBlock
2520
import semmle.code.powershell.ScriptBlock
26-
2721
import semmle.code.powershell.StringLiteral
28-
29-
// Inherited
3022
import semmle.code.powershell.AssignmentStatement
3123
import semmle.code.powershell.BinaryExpression
3224
import semmle.code.powershell.TernaryExpression
@@ -41,9 +33,10 @@ import semmle.code.powershell.CommandExpression
4133
import semmle.code.powershell.CommandParameter
4234
import semmle.code.powershell.ExpandableStringExpression
4335
import semmle.code.powershell.TypeExpression
44-
import semmle.code.powershell.VariableExpression
4536
import semmle.code.powershell.ParenExpression
37+
import semmle.code.powershell.Chainable
4638
import semmle.code.powershell.Pipeline
4739
import semmle.code.powershell.StringConstantExpression
40+
import semmle.code.powershell.FunctionDefinition
4841
import semmle.code.powershell.InvokeMemberExpression
49-
import semmle.code.powershell.CommentEntity
42+
import semmle.code.powershell.CommentEntity
Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
import powershell
22

3-
class ArrayExpression extends @array_expression instanceof Expression
4-
{
5-
SourceLocation getLocation()
6-
{
7-
array_expression_location(this, result)
8-
}
3+
class ArrayExpression extends @array_expression, Expression {
4+
override SourceLocation getLocation() { array_expression_location(this, result) }
95

10-
StatementBlock getStatementBlock()
11-
{
12-
array_expression(this, result)
13-
}
6+
StatementBlock getStatementBlock() { array_expression(this, result) }
147

15-
string toString(){
16-
result = "ArrayExpression at: " + this.getLocation().toString()
17-
}
18-
}
8+
override string toString() { result = "ArrayExpression at: " + this.getLocation().toString() }
9+
}
Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
import powershell
22

3-
class ArrayLiteral extends @array_literal instanceof Expression
4-
{
5-
SourceLocation getLocation()
6-
{
7-
array_literal_location(this, result)
8-
}
3+
class ArrayLiteral extends @array_literal, Expression {
4+
override SourceLocation getLocation() { array_literal_location(this, result) }
95

10-
Expression getElement(int index)
11-
{
12-
array_literal_element(this, index, result)
13-
}
6+
Expression getElement(int index) { array_literal_element(this, index, result) }
147

15-
Expression getAnElement()
16-
{
17-
array_literal_element(this, _, result)
18-
}
8+
Expression getAnElement() { array_literal_element(this, _, result) }
199

20-
string toString(){
21-
result = "ArrayLiteral at: " + this.getLocation().toString()
22-
}
23-
}
10+
override string toString() { result = "ArrayLiteral at: " + this.getLocation().toString() }
11+
}
Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
11
import powershell
22

3-
class AssignmentStatement extends @assignment_statement instanceof Statement
4-
{
5-
SourceLocation getLocation()
6-
{
7-
assignment_statement_location(this, result)
8-
}
3+
class AssignmentStatement extends @assignment_statement, Statement {
4+
override SourceLocation getLocation() { assignment_statement_location(this, result) }
95

10-
int getKind()
11-
{
12-
assignment_statement(this, result, _, _)
13-
}
6+
int getKind() { assignment_statement(this, result, _, _) }
147

15-
Expression getLeftHandSide()
16-
{
17-
assignment_statement(this, _, result, _)
18-
}
8+
Expression getLeftHandSide() { assignment_statement(this, _, result, _) }
199

20-
Statement getRightHandSide()
21-
{
22-
assignment_statement(this, _, _, result)
23-
}
10+
Statement getRightHandSide() { assignment_statement(this, _, _, result) }
2411

25-
string toString(){
26-
result = "AssignmentStatement at: " + this.getLocation().toString()
27-
}
28-
}
12+
override string toString() { result = "AssignmentStatement at: " + this.getLocation().toString() }
13+
}
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import powershell
22

3-
class Ast extends @ast
4-
{
5-
string toString(){none()}
6-
7-
Ast getParent()
8-
{
9-
parent(result, this)
10-
}
11-
}
3+
class Ast extends @ast {
4+
string toString() { none() }
5+
6+
Ast getParent() { parent(result, this) }
7+
8+
Location getLocation() { none() }
9+
}
Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,21 @@
11
import powershell
22

3-
class Attribute extends @attribute instanceof AttributeBase
4-
{
5-
string toString()
6-
{
7-
none()
8-
}
9-
10-
SourceLocation getLocation()
11-
{
12-
attribute_location(this, result)
13-
}
14-
15-
string getName()
16-
{
17-
attribute(this, result, _, _)
18-
}
19-
20-
int getNumNamedArguments()
21-
{
22-
attribute(this, _, result, _)
23-
}
24-
25-
int getNumPositionalArguments()
26-
{
27-
attribute(this, _, _, result)
28-
}
29-
30-
NamedAttributeArgument getNamedArgument(int i)
31-
{
32-
attribute_named_argument(this, i, result)
33-
}
34-
35-
NamedAttributeArgument getANamedArgument()
36-
{
37-
result = this.getNamedArgument(_)
38-
}
39-
40-
Expression getPositionalArgument(int i)
41-
{
42-
attribute_positional_argument(this, i, result)
43-
}
44-
45-
Expression getAPositionalArgument()
46-
{
47-
result = this.getPositionalArgument(_)
48-
}
49-
}
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+
Expression getPositionalArgument(int i) { attribute_positional_argument(this, i, result) }
19+
20+
Expression getAPositionalArgument() { result = this.getPositionalArgument(_) }
21+
}
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
import powershell
22

3-
class AttributeBase extends @attribute_base instanceof Ast
4-
{
5-
string toString(){none()}
6-
}
3+
class AttributeBase extends @attribute_base, Ast { }
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
import powershell
22

3-
class BaseConstantExpression extends @base_constant_expression instanceof Expression
4-
{
5-
string toString()
6-
{
7-
none()
8-
}
9-
}
3+
class BaseConstantExpression extends @base_constant_expression, Expression { }
Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
11
import powershell
22

3-
class BinaryExpression extends @binary_expression instanceof Expression
4-
{
5-
string toString() {none()}
3+
class BinaryExpression extends @binary_expression, Expression {
4+
override string toString() {
5+
result = "...+..." // TODO
6+
}
67

7-
SourceLocation getLocation()
8-
{
9-
binary_expression_location(this, result)
10-
}
8+
override SourceLocation getLocation() { binary_expression_location(this, result) }
119

12-
int getKind()
13-
{
14-
binary_expression(this, result, _, _)
15-
}
10+
int getKind() { binary_expression(this, result, _, _) }
1611

17-
Expression getLeftHandSide()
18-
{
19-
binary_expression(this, _, result, _)
20-
}
12+
Expression getLeftHandSide() { binary_expression(this, _, result, _) }
2113

22-
Expression getRightHandSide()
23-
{
24-
binary_expression(this, _, _, result)
25-
}
26-
}
14+
Expression getRightHandSide() { binary_expression(this, _, _, result) }
15+
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
import powershell
2-
class Chainable extends @chainable instanceof PipelineBase
3-
{
4-
string toString() {none()}
5-
}
2+
3+
class Chainable extends @chainable, PipelineBase { }

0 commit comments

Comments
 (0)