Skip to content

Commit 844216a

Browse files
committed
PS: Better toString in a couple of classes.
1 parent c2f0c01 commit 844216a

File tree

9 files changed

+31
-9
lines changed

9 files changed

+31
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ class ArrayLiteral extends @array_literal, Expr {
77

88
Expr getAnElement() { array_literal_element(this, _, result) }
99

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

3-
class BreakStmt extends GotoStmt, Stmt {
3+
class BreakStmt extends GotoStmt, @break_statement {
44
override SourceLocation getLocation() { break_statement_location(this, result) }
55

6-
override string toString() { result = "continue" }
6+
override string toString() { result = "break" }
77
}

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

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

3-
class ContinueStmt extends GotoStmt, Stmt {
3+
class ContinueStmt extends GotoStmt, @continue_statement {
44
override SourceLocation getLocation() { continue_statement_location(this, result) }
55

66
override string toString() { result = "continue" }

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class IfStmt extends @if_statement, Stmt {
99

1010
PipelineBase getCondition(int i) { if_statement_clause(this, i, result, _) } // TODO: Change @ast to @pipeline_base in dbscheme
1111

12+
PipelineBase getACondition() { result = this.getCondition(_) }
13+
1214
StmtBlock getThen(int i) { if_statement_clause(this, i, _, result) } // TODO: Change @ast to @statement_block in dbscheme
1315

1416
/** ..., if any. */

powershell/ql/lib/semmle/code/powershell/ParamBlock.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 ParamBlock extends @param_block, Ast {
4-
override string toString() { result = "ParamBlock" }
4+
override string toString() { result = "param(...)" }
55

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

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import powershell
22

33
class Pipeline extends @pipeline, Chainable {
4-
override string toString() { result = "...|..." }
4+
override string toString() {
5+
if this.getNumberOfComponents() = 1
6+
then result = this.getComponent(0).toString()
7+
else result = "...|..."
8+
}
59

610
override SourceLocation getLocation() { pipeline_location(this, result) }
711

8-
int getNumComponents() { pipeline(this, result) }
12+
int getNumberOfComponents() { result = count(this.getAComponent()) }
913

1014
CmdBase getComponent(int i) { pipeline_component(this, i, result) }
1115

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

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

33
class ScriptBlock extends @script_block, Ast {
4-
override string toString() { result = this.getLocation().getFile().getBaseName() }
4+
predicate isTopLevel() { not exists(this.getParent()) }
5+
6+
override string toString() {
7+
if this.isTopLevel()
8+
then result = this.getLocation().getFile().getBaseName()
9+
else result = "{...}"
10+
}
511

612
override SourceLocation getLocation() { script_block_location(this, result) }
713

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ class StmtBlock extends @statement_block, Ast {
1515

1616
TrapStmt getATrapStatement() { result = this.getTrapStatement(_) }
1717

18-
override string toString() { result = "StatementBlock at: " + this.getLocation().toString() }
18+
override string toString() { result = "{...}" }
1919
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,14 @@ class ConditionalExpr extends @ternary_expression, Expr {
1010
Expr getIfFalse() { ternary_expression(this, _, result, _) }
1111

1212
Expr getIfTrue() { ternary_expression(this, _, _, result) }
13+
14+
Expr getBranch(boolean value) {
15+
value = true and
16+
result = this.getIfTrue()
17+
or
18+
value = false and
19+
result = this.getIfFalse()
20+
}
21+
22+
Expr getABranch() { result = this.getBranch(_) }
1323
}

0 commit comments

Comments
 (0)