Skip to content

Commit 8d59e09

Browse files
committed
PS: Shorter predicate names and better toString messages.
1 parent c69d70a commit 8d59e09

File tree

8 files changed

+44
-44
lines changed

8 files changed

+44
-44
lines changed

powershell/ql/lib/semmle/code/powershell/AssignmentStatement.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ class AssignStmt extends @assignment_statement, Stmt {
99

1010
Stmt getRightHandSide() { assignment_statement(this, _, _, result) }
1111

12-
override string toString() { result = "AssignmentStatement at: " + this.getLocation().toString() }
12+
override string toString() { result = "...=..." }
1313
}

powershell/ql/lib/semmle/code/powershell/CommandExpression.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import powershell
33
class CmdExpr extends @command_expression, CmdBase {
44
override SourceLocation getLocation() { command_expression_location(this, result) }
55

6-
Expr getExpression() { command_expression(this, result, _) }
6+
Expr getExpr() { command_expression(this, result, _) }
77

88
int getNumRedirections() { command_expression(this, _, result) }
99

1010
Redirection getRedirection(int i) { command_expression_redirection(this, i, result) }
1111

1212
Redirection getARedirection() { result = this.getRedirection(_) }
1313

14-
override string toString() { result = "CommandExpression at: " + this.getLocation().toString() }
14+
override string toString() { result = this.getExpr().toString() }
1515
}

powershell/ql/lib/semmle/code/powershell/ConstantExpression.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ class ConstExpr extends @constant_expression, BaseConstExpr {
77

88
StringLiteral getValue() { constant_expression_value(this, result) }
99

10-
override string toString() { result = "ConstantExpression at: " + this.getLocation().toString() }
10+
override string toString() { result = this.getValue().toString() }
1111
}

powershell/ql/lib/semmle/code/powershell/ScriptBlock.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import powershell
22

33
class ScriptBlock extends @script_block, Ast {
4-
override string toString() { result = "ScriptBlock at: " + this.getLocation().toString() }
4+
override string toString() { result = this.getLocation().getFile().getBaseName() }
55

66
override SourceLocation getLocation() { script_block_location(this, result) }
77

powershell/ql/test/library-tests/ast/Arrays/arrays.expected

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ arrayExpr
22
| Arrays.ps1:11:11:11:25 | ArrayExpression at: Arrays.ps1:11:11:11:25 | Arrays.ps1:11:13:11:24 | StatementBlock at: Arrays.ps1:11:13:11:24 |
33
| Arrays.ps1:14:41:14:44 | ArrayExpression at: Arrays.ps1:14:41:14:44 | Arrays.ps1:0:0:0:0 | StatementBlock at: Arrays.ps1:0:0:0:0 |
44
arrayLiteral
5-
| Arrays.ps1:1:11:1:37 | ArrayLiteral at: Arrays.ps1:1:11:1:37 | 0 | Arrays.ps1:1:11:1:12 | ConstantExpression at: Arrays.ps1:1:11:1:12 |
6-
| Arrays.ps1:1:11:1:37 | ArrayLiteral at: Arrays.ps1:1:11:1:37 | 1 | Arrays.ps1:1:13:1:14 | ConstantExpression at: Arrays.ps1:1:13:1:14 |
5+
| Arrays.ps1:1:11:1:37 | ArrayLiteral at: Arrays.ps1:1:11:1:37 | 0 | Arrays.ps1:1:11:1:12 | 1 |
6+
| Arrays.ps1:1:11:1:37 | ArrayLiteral at: Arrays.ps1:1:11:1:37 | 1 | Arrays.ps1:1:13:1:14 | 2 |
77
| Arrays.ps1:1:11:1:37 | ArrayLiteral at: Arrays.ps1:1:11:1:37 | 2 | Arrays.ps1:1:15:1:18 | a |
88
| Arrays.ps1:1:11:1:37 | ArrayLiteral at: Arrays.ps1:1:11:1:37 | 3 | Arrays.ps1:1:19:1:24 | true |
99
| Arrays.ps1:1:11:1:37 | ArrayLiteral at: Arrays.ps1:1:11:1:37 | 4 | Arrays.ps1:1:25:1:31 | false |
1010
| Arrays.ps1:1:11:1:37 | ArrayLiteral at: Arrays.ps1:1:11:1:37 | 5 | Arrays.ps1:1:32:1:37 | null |
11-
| Arrays.ps1:5:34:5:37 | ArrayLiteral at: Arrays.ps1:5:34:5:37 | 0 | Arrays.ps1:5:34:5:35 | ConstantExpression at: Arrays.ps1:5:34:5:35 |
12-
| Arrays.ps1:5:34:5:37 | ArrayLiteral at: Arrays.ps1:5:34:5:37 | 1 | Arrays.ps1:5:36:5:37 | ConstantExpression at: Arrays.ps1:5:36:5:37 |
13-
| Arrays.ps1:6:9:6:12 | ArrayLiteral at: Arrays.ps1:6:9:6:12 | 0 | Arrays.ps1:6:9:6:10 | ConstantExpression at: Arrays.ps1:6:9:6:10 |
14-
| Arrays.ps1:6:9:6:12 | ArrayLiteral at: Arrays.ps1:6:9:6:12 | 1 | Arrays.ps1:6:11:6:12 | ConstantExpression at: Arrays.ps1:6:11:6:12 |
15-
| Arrays.ps1:7:9:7:12 | ArrayLiteral at: Arrays.ps1:7:9:7:12 | 0 | Arrays.ps1:7:9:7:10 | ConstantExpression at: Arrays.ps1:7:9:7:10 |
16-
| Arrays.ps1:7:9:7:12 | ArrayLiteral at: Arrays.ps1:7:9:7:12 | 1 | Arrays.ps1:7:11:7:12 | ConstantExpression at: Arrays.ps1:7:11:7:12 |
17-
| Arrays.ps1:8:9:8:12 | ArrayLiteral at: Arrays.ps1:8:9:8:12 | 0 | Arrays.ps1:8:9:8:10 | ConstantExpression at: Arrays.ps1:8:9:8:10 |
18-
| Arrays.ps1:8:9:8:12 | ArrayLiteral at: Arrays.ps1:8:9:8:12 | 1 | Arrays.ps1:8:11:8:12 | ConstantExpression at: Arrays.ps1:8:11:8:12 |
19-
| Arrays.ps1:9:9:9:12 | ArrayLiteral at: Arrays.ps1:9:9:9:12 | 0 | Arrays.ps1:9:9:9:10 | ConstantExpression at: Arrays.ps1:9:9:9:10 |
20-
| Arrays.ps1:9:9:9:12 | ArrayLiteral at: Arrays.ps1:9:9:9:12 | 1 | Arrays.ps1:9:11:9:12 | ConstantExpression at: Arrays.ps1:9:11:9:12 |
11+
| Arrays.ps1:5:34:5:37 | ArrayLiteral at: Arrays.ps1:5:34:5:37 | 0 | Arrays.ps1:5:34:5:35 | 2 |
12+
| Arrays.ps1:5:34:5:37 | ArrayLiteral at: Arrays.ps1:5:34:5:37 | 1 | Arrays.ps1:5:36:5:37 | 2 |
13+
| Arrays.ps1:6:9:6:12 | ArrayLiteral at: Arrays.ps1:6:9:6:12 | 0 | Arrays.ps1:6:9:6:10 | 0 |
14+
| Arrays.ps1:6:9:6:12 | ArrayLiteral at: Arrays.ps1:6:9:6:12 | 1 | Arrays.ps1:6:11:6:12 | 0 |
15+
| Arrays.ps1:7:9:7:12 | ArrayLiteral at: Arrays.ps1:7:9:7:12 | 0 | Arrays.ps1:7:9:7:10 | 1 |
16+
| Arrays.ps1:7:9:7:12 | ArrayLiteral at: Arrays.ps1:7:9:7:12 | 1 | Arrays.ps1:7:11:7:12 | 0 |
17+
| Arrays.ps1:8:9:8:12 | ArrayLiteral at: Arrays.ps1:8:9:8:12 | 0 | Arrays.ps1:8:9:8:10 | 0 |
18+
| Arrays.ps1:8:9:8:12 | ArrayLiteral at: Arrays.ps1:8:9:8:12 | 1 | Arrays.ps1:8:11:8:12 | 1 |
19+
| Arrays.ps1:9:9:9:12 | ArrayLiteral at: Arrays.ps1:9:9:9:12 | 0 | Arrays.ps1:9:9:9:10 | 1 |
20+
| Arrays.ps1:9:9:9:12 | ArrayLiteral at: Arrays.ps1:9:9:9:12 | 1 | Arrays.ps1:9:11:9:12 | 1 |
2121
| Arrays.ps1:11:13:11:24 | ArrayLiteral at: Arrays.ps1:11:13:11:24 | 0 | Arrays.ps1:11:13:11:16 | a |
2222
| Arrays.ps1:11:13:11:24 | ArrayLiteral at: Arrays.ps1:11:13:11:24 | 1 | Arrays.ps1:11:17:11:20 | b |
2323
| Arrays.ps1:11:13:11:24 | ArrayLiteral at: Arrays.ps1:11:13:11:24 | 2 | Arrays.ps1:11:21:11:24 | c |
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
binaryExpr
22
| BinaryExpression.ps1:3:11:3:24 | ...+... | BinaryExpression.ps1:3:11:3:16 | val1 | BinaryExpression.ps1:3:19:3:24 | val2 |
3-
| TernaryExpression.ps1:1:9:1:16 | ...+... | TernaryExpression.ps1:1:9:1:10 | ConstantExpression at: TernaryExpression.ps1:1:9:1:10 | TernaryExpression.ps1:1:15:1:16 | ConstantExpression at: TernaryExpression.ps1:1:15:1:16 |
3+
| TernaryExpression.ps1:1:9:1:16 | ...+... | TernaryExpression.ps1:1:9:1:10 | 6 | TernaryExpression.ps1:1:15:1:16 | 7 |
44
cmdExpr
5-
| BinaryExpression.ps1:1:9:1:10 | CommandExpression at: BinaryExpression.ps1:1:9:1:10 | BinaryExpression.ps1:1:9:1:10 | ConstantExpression at: BinaryExpression.ps1:1:9:1:10 |
6-
| BinaryExpression.ps1:2:9:2:10 | CommandExpression at: BinaryExpression.ps1:2:9:2:10 | BinaryExpression.ps1:2:9:2:10 | ConstantExpression at: BinaryExpression.ps1:2:9:2:10 |
7-
| BinaryExpression.ps1:3:11:3:24 | CommandExpression at: BinaryExpression.ps1:3:11:3:24 | BinaryExpression.ps1:3:11:3:24 | ...+... |
8-
| BinaryExpression.ps1:4:1:4:8 | CommandExpression at: BinaryExpression.ps1:4:1:4:8 | BinaryExpression.ps1:4:1:4:8 | result |
9-
| ExpandableString.ps1:1:1:1:40 | CommandExpression at: ExpandableString.ps1:1:1:1:40 | ExpandableString.ps1:1:1:1:40 | ExpandableStringExpression at: ExpandableString.ps1:1:1:1:40 |
10-
| ExpandableString.ps1:1:23:1:38 | CommandExpression at: ExpandableString.ps1:1:23:1:38 | file://:0:0:0:0 | (no string representation) |
11-
| SubExpression.ps1:1:1:1:24 | CommandExpression at: SubExpression.ps1:1:1:1:24 | SubExpression.ps1:1:1:1:24 | ArrayExpression at: SubExpression.ps1:1:1:1:24 |
12-
| SubExpression.ps1:2:1:2:22 | CommandExpression at: SubExpression.ps1:2:1:2:22 | SubExpression.ps1:2:1:2:22 | ArrayExpression at: SubExpression.ps1:2:1:2:22 |
13-
| TernaryExpression.ps1:1:8:1:23 | CommandExpression at: TernaryExpression.ps1:1:8:1:23 | TernaryExpression.ps1:1:8:1:23 | ...?...:... |
14-
| TernaryExpression.ps1:1:9:1:16 | CommandExpression at: TernaryExpression.ps1:1:9:1:16 | TernaryExpression.ps1:1:9:1:16 | ...+... |
5+
| BinaryExpression.ps1:1:9:1:10 | 1 | BinaryExpression.ps1:1:9:1:10 | 1 |
6+
| BinaryExpression.ps1:2:9:2:10 | 2 | BinaryExpression.ps1:2:9:2:10 | 2 |
7+
| BinaryExpression.ps1:3:11:3:24 | ...+... | BinaryExpression.ps1:3:11:3:24 | ...+... |
8+
| BinaryExpression.ps1:4:1:4:8 | result | BinaryExpression.ps1:4:1:4:8 | result |
9+
| ExpandableString.ps1:1:1:1:40 | ExpandableStringExpression at: ExpandableString.ps1:1:1:1:40 | ExpandableString.ps1:1:1:1:40 | ExpandableStringExpression at: ExpandableString.ps1:1:1:1:40 |
10+
| ExpandableString.ps1:1:23:1:38 | (no string representation) | file://:0:0:0:0 | (no string representation) |
11+
| SubExpression.ps1:1:1:1:24 | ArrayExpression at: SubExpression.ps1:1:1:1:24 | SubExpression.ps1:1:1:1:24 | ArrayExpression at: SubExpression.ps1:1:1:1:24 |
12+
| SubExpression.ps1:2:1:2:22 | ArrayExpression at: SubExpression.ps1:2:1:2:22 | SubExpression.ps1:2:1:2:22 | ArrayExpression at: SubExpression.ps1:2:1:2:22 |
13+
| TernaryExpression.ps1:1:8:1:23 | ...?...:... | TernaryExpression.ps1:1:8:1:23 | ...?...:... |
14+
| TernaryExpression.ps1:1:9:1:16 | ...+... | TernaryExpression.ps1:1:9:1:16 | ...+... |
1515
invokeMemoryExpression
16-
| SubExpression.ps1:1:1:1:24 | ArrayExpression at: SubExpression.ps1:1:1:1:24 | file://:0:0:0:0 | (no string representation) | 0 | SubExpression.ps1:1:21:1:23 | ConstantExpression at: SubExpression.ps1:1:21:1:23 |
16+
| SubExpression.ps1:1:1:1:24 | ArrayExpression at: SubExpression.ps1:1:1:1:24 | file://:0:0:0:0 | (no string representation) | 0 | SubExpression.ps1:1:21:1:23 | 10 |
1717
expandableString
1818
| ExpandableString.ps1:1:1:1:40 | ExpandableStringExpression at: ExpandableString.ps1:1:1:1:40 | 0 | ExpandableString.ps1:1:8:1:13 | name |
1919
| ExpandableString.ps1:1:1:1:40 | ExpandableStringExpression at: ExpandableString.ps1:1:1:1:40 | 1 | file://:0:0:0:0 | (no string representation) |

powershell/ql/test/library-tests/ast/Expressions/expressions.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ query predicate binaryExpr(BinaryExpr e, Expr e1, Expr e2) {
66
}
77

88
query predicate cmdExpr(CmdExpr cmd, Expr e) {
9-
e = cmd.getExpression()
9+
e = cmd.getExpr()
1010
}
1111

1212
query predicate invokeMemoryExpression(InvokeMemberExpression invoke, Expr e, int i, Expr arg) {
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
| ExitStatement.ps1:1:1:1:8 | exit ... |
2+
| ExitStatement.ps1:1:6:1:8 | -1 |
23
| ExitStatement.ps1:1:6:1:8 | ...\|... |
3-
| ExitStatement.ps1:1:6:1:8 | CommandExpression at: ExitStatement.ps1:1:6:1:8 |
4-
| IfStatement.ps1:1:1:1:7 | AssignmentStatement at: IfStatement.ps1:1:1:1:7 |
5-
| IfStatement.ps1:1:6:1:7 | CommandExpression at: IfStatement.ps1:1:6:1:7 |
4+
| IfStatement.ps1:1:1:1:7 | ...=... |
5+
| IfStatement.ps1:1:6:1:7 | 4 |
66
| IfStatement.ps1:3:1:8:2 | if (...) {...} else {...} |
7+
| IfStatement.ps1:3:5:3:13 | ...+... |
78
| IfStatement.ps1:3:5:3:13 | ...\|... |
8-
| IfStatement.ps1:3:5:3:13 | CommandExpression at: IfStatement.ps1:3:5:3:13 |
99
| IfStatement.ps1:4:2:4:36 | ...\|... |
10-
| IfStatement.ps1:4:2:4:36 | CommandExpression at: IfStatement.ps1:4:2:4:36 |
10+
| IfStatement.ps1:4:2:4:36 | ExpandableStringExpression at: IfStatement.ps1:4:2:4:36 |
1111
| IfStatement.ps1:7:2:7:21 | ...\|... |
12-
| IfStatement.ps1:7:2:7:21 | CommandExpression at: IfStatement.ps1:7:2:7:21 |
12+
| IfStatement.ps1:7:2:7:21 | ExpandableStringExpression at: IfStatement.ps1:7:2:7:21 |
1313
| TrapStatement.ps1:1:1:4:2 | FunctionDefinition at: TrapStatement.ps1:1:1:4:2 |
1414
| TrapStatement.ps1:2:5:2:26 | TrapStatement at: TrapStatement.ps1:2:5:2:26 |
1515
| TrapStatement.ps1:2:11:2:25 | ...\|... |
16-
| TrapStatement.ps1:2:11:2:25 | CommandExpression at: TrapStatement.ps1:2:11:2:25 |
16+
| TrapStatement.ps1:2:11:2:25 | Error found. |
1717
| TrapStatement.ps1:3:5:3:19 | ...\|... |
1818
| TrapStatement.ps1:3:5:3:19 | nonsenseString |
1919
| TrapStatement.ps1:6:1:6:9 | ...\|... |
2020
| TrapStatement.ps1:6:1:6:9 | TrapTest |
2121
| Try.ps1:1:1:13:2 | try {...} |
22-
| Try.ps1:2:4:2:95 | AssignmentStatement at: Try.ps1:2:4:2:95 |
22+
| Try.ps1:2:4:2:95 | ...=... |
2323
| Try.ps1:2:17:2:95 | ...\|... |
2424
| Try.ps1:2:17:2:95 | New-Object |
2525
| Try.ps1:2:69:2:94 | ...\|... |
26-
| Try.ps1:2:69:2:94 | CommandExpression at: Try.ps1:2:69:2:94 |
26+
| Try.ps1:2:69:2:94 | ArrayLiteral at: Try.ps1:2:69:2:94 |
2727
| Try.ps1:3:11:3:21 | ...\|... |
28-
| Try.ps1:3:11:3:21 | CommandExpression at: Try.ps1:3:11:3:21 |
28+
| Try.ps1:3:11:3:21 | Exception |
2929
| Try.ps1:6:5:6:64 | ...\|... |
30-
| Try.ps1:6:5:6:64 | CommandExpression at: Try.ps1:6:5:6:64 |
30+
| Try.ps1:6:5:6:64 | Unable to download MyDoc.doc from http://www.contoso.com. |
3131
| Try.ps1:9:5:9:52 | ...\|... |
32-
| Try.ps1:9:5:9:52 | CommandExpression at: Try.ps1:9:5:9:52 |
32+
| Try.ps1:9:5:9:52 | An error occurred that could not be resolved. |
3333
| Try.ps1:12:5:12:37 | ...\|... |
34-
| Try.ps1:12:5:12:37 | CommandExpression at: Try.ps1:12:5:12:37 |
34+
| Try.ps1:12:5:12:37 | The finally block is executed. |
3535
| UseProcessBlockForPipelineCommand.ps1:1:1:11:2 | FunctionDefinition at: UseProcessBlockForPipelineCommand.ps1:1:1:11:2 |
3636
| UseProcessBlockForPipelineCommand.ps1:10:5:10:12 | ...\|... |
37-
| UseProcessBlockForPipelineCommand.ps1:10:5:10:12 | CommandExpression at: UseProcessBlockForPipelineCommand.ps1:10:5:10:12 |
37+
| UseProcessBlockForPipelineCommand.ps1:10:5:10:12 | Number |
3838
| file://:0:0:0:0 | (no string representation) |

0 commit comments

Comments
 (0)