diff --git a/powershell/ql/lib/semmle/code/powershell/ArrayLiteral.qll b/powershell/ql/lib/semmle/code/powershell/ArrayLiteral.qll index a5fd2fd177f..447d26b45e3 100644 --- a/powershell/ql/lib/semmle/code/powershell/ArrayLiteral.qll +++ b/powershell/ql/lib/semmle/code/powershell/ArrayLiteral.qll @@ -7,5 +7,5 @@ class ArrayLiteral extends @array_literal, Expr { Expr getAnElement() { array_literal_element(this, _, result) } - override string toString() { result = "ArrayLiteral at: " + this.getLocation().toString() } + override string toString() { result = "...,..." } } diff --git a/powershell/ql/lib/semmle/code/powershell/BreakStmt.qll b/powershell/ql/lib/semmle/code/powershell/BreakStmt.qll index dbec183d7b0..abd74f3e682 100644 --- a/powershell/ql/lib/semmle/code/powershell/BreakStmt.qll +++ b/powershell/ql/lib/semmle/code/powershell/BreakStmt.qll @@ -1,7 +1,7 @@ import powershell -class BreakStmt extends GotoStmt, Stmt { +class BreakStmt extends GotoStmt, @break_statement { override SourceLocation getLocation() { break_statement_location(this, result) } - override string toString() { result = "continue" } + override string toString() { result = "break" } } diff --git a/powershell/ql/lib/semmle/code/powershell/ContinueStmt.qll b/powershell/ql/lib/semmle/code/powershell/ContinueStmt.qll index 79cd8053f77..98fe1ba3fcb 100644 --- a/powershell/ql/lib/semmle/code/powershell/ContinueStmt.qll +++ b/powershell/ql/lib/semmle/code/powershell/ContinueStmt.qll @@ -1,6 +1,6 @@ import powershell -class ContinueStmt extends GotoStmt, Stmt { +class ContinueStmt extends GotoStmt, @continue_statement { override SourceLocation getLocation() { continue_statement_location(this, result) } override string toString() { result = "continue" } diff --git a/powershell/ql/lib/semmle/code/powershell/IfStmt.qll b/powershell/ql/lib/semmle/code/powershell/IfStmt.qll index 21ca8730cd5..019a811fa6d 100644 --- a/powershell/ql/lib/semmle/code/powershell/IfStmt.qll +++ b/powershell/ql/lib/semmle/code/powershell/IfStmt.qll @@ -9,6 +9,8 @@ class IfStmt extends @if_statement, Stmt { PipelineBase getCondition(int i) { if_statement_clause(this, i, result, _) } // TODO: Change @ast to @pipeline_base in dbscheme + PipelineBase getACondition() { result = this.getCondition(_) } + StmtBlock getThen(int i) { if_statement_clause(this, i, _, result) } // TODO: Change @ast to @statement_block in dbscheme /** ..., if any. */ diff --git a/powershell/ql/lib/semmle/code/powershell/ParamBlock.qll b/powershell/ql/lib/semmle/code/powershell/ParamBlock.qll index 5fd95828883..65baf93bfdd 100644 --- a/powershell/ql/lib/semmle/code/powershell/ParamBlock.qll +++ b/powershell/ql/lib/semmle/code/powershell/ParamBlock.qll @@ -1,7 +1,7 @@ import powershell class ParamBlock extends @param_block, Ast { - override string toString() { result = "ParamBlock" } + override string toString() { result = "param(...)" } override SourceLocation getLocation() { param_block_location(this, result) } diff --git a/powershell/ql/lib/semmle/code/powershell/Pipeline.qll b/powershell/ql/lib/semmle/code/powershell/Pipeline.qll index 0e37c658115..f630a117e54 100644 --- a/powershell/ql/lib/semmle/code/powershell/Pipeline.qll +++ b/powershell/ql/lib/semmle/code/powershell/Pipeline.qll @@ -1,11 +1,15 @@ import powershell class Pipeline extends @pipeline, Chainable { - override string toString() { result = "...|..." } + override string toString() { + if this.getNumberOfComponents() = 1 + then result = this.getComponent(0).toString() + else result = "...|..." + } override SourceLocation getLocation() { pipeline_location(this, result) } - int getNumComponents() { pipeline(this, result) } + int getNumberOfComponents() { result = count(this.getAComponent()) } CmdBase getComponent(int i) { pipeline_component(this, i, result) } diff --git a/powershell/ql/lib/semmle/code/powershell/ScriptBlock.qll b/powershell/ql/lib/semmle/code/powershell/ScriptBlock.qll index d2793e076ae..975525c6cbc 100644 --- a/powershell/ql/lib/semmle/code/powershell/ScriptBlock.qll +++ b/powershell/ql/lib/semmle/code/powershell/ScriptBlock.qll @@ -1,7 +1,13 @@ import powershell class ScriptBlock extends @script_block, Ast { - override string toString() { result = this.getLocation().getFile().getBaseName() } + predicate isTopLevel() { not exists(this.getParent()) } + + override string toString() { + if this.isTopLevel() + then result = this.getLocation().getFile().getBaseName() + else result = "{...}" + } override SourceLocation getLocation() { script_block_location(this, result) } diff --git a/powershell/ql/lib/semmle/code/powershell/StatementBlock.qll b/powershell/ql/lib/semmle/code/powershell/StatementBlock.qll index 4ea36e1e9ac..c493372b8a5 100644 --- a/powershell/ql/lib/semmle/code/powershell/StatementBlock.qll +++ b/powershell/ql/lib/semmle/code/powershell/StatementBlock.qll @@ -15,5 +15,5 @@ class StmtBlock extends @statement_block, Ast { TrapStmt getATrapStatement() { result = this.getTrapStatement(_) } - override string toString() { result = "StatementBlock at: " + this.getLocation().toString() } + override string toString() { result = "{...}" } } diff --git a/powershell/ql/lib/semmle/code/powershell/TernaryExpression.qll b/powershell/ql/lib/semmle/code/powershell/TernaryExpression.qll index 9df624d2d6c..19af31478fc 100644 --- a/powershell/ql/lib/semmle/code/powershell/TernaryExpression.qll +++ b/powershell/ql/lib/semmle/code/powershell/TernaryExpression.qll @@ -10,4 +10,14 @@ class ConditionalExpr extends @ternary_expression, Expr { Expr getIfFalse() { ternary_expression(this, _, result, _) } Expr getIfTrue() { ternary_expression(this, _, _, result) } + + Expr getBranch(boolean value) { + value = true and + result = this.getIfTrue() + or + value = false and + result = this.getIfFalse() + } + + Expr getABranch() { result = this.getBranch(_) } }