Skip to content

Commit 37c1263

Browse files
committed
PS: Improve constant expression AST hierachy.
1 parent c8d7047 commit 37c1263

File tree

3 files changed

+17
-9
lines changed

3 files changed

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

3-
class BaseConstExpr extends @base_constant_expression, Expr { }
3+
/** The base class for constant expressions. */
4+
class BaseConstExpr extends @base_constant_expression, Expr {
5+
/** Gets the type of this constant expression. */
6+
string getType() { none() }
7+
8+
/** Gets a string literal of this constant expression. */
9+
StringLiteral getValue() { none() }
10+
11+
/** Gets a string literal representing this constant expression. */
12+
final override string toString() { result = this.getValue().toString() }
13+
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ import powershell
33
class ConstExpr extends @constant_expression, BaseConstExpr {
44
override SourceLocation getLocation() { constant_expression_location(this, result) }
55

6-
string getType() { constant_expression(this, result) }
6+
override string getType() { constant_expression(this, result) }
77

8-
StringLiteral getValue() { constant_expression_value(this, result) }
9-
10-
override string toString() { result = this.getValue().toString() }
8+
override StringLiteral getValue() { constant_expression_value(this, result) }
119
}
1210

1311
private newtype TConstantValue =
@@ -97,7 +95,7 @@ class ConstString extends ConstantValue, TConstString {
9795
result = "\"" + this.asString().replaceAll("\"", "\\\"") + "\""
9896
}
9997

100-
final override ConstExpr getAnExpr() { result.getValue().getValue() = this.getValue() }
98+
final override BaseConstExpr getAnExpr() { result.getValue().getValue() = this.getValue() }
10199
}
102100

103101
/** A constant boolean value. */
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import powershell
22

3+
/** A string constant. */
34
class StringConstExpr extends @string_constant_expression, BaseConstExpr {
4-
StringLiteral getValue() { string_constant_expression(this, result) }
5+
override StringLiteral getValue() { string_constant_expression(this, result) }
56

6-
/** Get the full string literal with all its parts concatenated */
7-
override string toString() { result = this.getValue().toString() }
7+
override string getType() { result = "String" }
88

99
override SourceLocation getLocation() { string_constant_expression_location(this, result) }
1010
}

0 commit comments

Comments
 (0)