PS: Better toString in a couple of classes.

This commit is contained in:
Mathias Vorreiter Pedersen
2024-08-29 14:42:48 +01:00
parent c2f0c01f19
commit 844216afdc
9 changed files with 31 additions and 9 deletions

View File

@@ -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 = "...,..." }
}

View File

@@ -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" }
}

View File

@@ -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" }

View File

@@ -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. */

View File

@@ -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) }

View File

@@ -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) }

View File

@@ -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) }

View File

@@ -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 = "{...}" }
}

View File

@@ -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(_) }
}