Revert #8360, "Add CompileTimeConstantExpr.getStringified method"

This commit is contained in:
Chris Smowton
2022-03-11 11:12:16 +00:00
parent f006cd0e37
commit 46cd85c70b
14 changed files with 12 additions and 343 deletions

View File

@@ -1,6 +0,0 @@
---
category: minorAnalysis
---
* Add new predicate `CompileTimeConstantExpr.getStringifiedValue` which attempts to compute the
`String.valueOf` string rendering of a constant expression. This predicate is now used to
compute the string value of an `AddExpr` that has the type `String`.

View File

@@ -161,38 +161,6 @@ class CompileTimeConstantExpr extends Expr {
)
}
/**
* Gets the stringified value of this expression, where possible.
*
* The stringified version of a compile-time constant expression is the equivalent to
* the result of calling `String.valueOf(expr)` on the expression.
*
* Note that this does not handle the following cases:
*
* - mathematical computations of type `long`, `float`, or `double`.
*/
pragma[nomagic]
string getStringifiedValue() {
result = this.getStringValue()
or
result = this.(Literal).getValue()
or
result = this.getBooleanValue().toString()
or
result = this.getIntValue().toString()
or
// Ternary conditional, with compile-time constant condition.
exists(ConditionalExpr ce, boolean condition |
ce = this and
condition = ce.getCondition().(CompileTimeConstantExpr).getBooleanValue() and
result = ce.getBranchExpr(condition).(CompileTimeConstantExpr).getStringifiedValue()
)
or
exists(Variable v | this = v.getAnAccess() |
result = v.getInitializer().(CompileTimeConstantExpr).getStringifiedValue()
)
}
/**
* Gets the string value of this expression, where possible.
*/
@@ -200,11 +168,11 @@ class CompileTimeConstantExpr extends Expr {
string getStringValue() {
result = this.(StringLiteral).getValue()
or
this.getType() instanceof TypeString and // When the expression type is `String`
result = this.(CharacterLiteral).getValue()
or
result =
// Then the resultant string is the addition of both operands stringified value, regardless of type.
this.(AddExpr).getLeftOperand().(CompileTimeConstantExpr).getStringifiedValue() +
this.(AddExpr).getRightOperand().(CompileTimeConstantExpr).getStringifiedValue()
this.(AddExpr).getLeftOperand().(CompileTimeConstantExpr).getStringValue() +
this.(AddExpr).getRightOperand().(CompileTimeConstantExpr).getStringValue()
or
// Ternary conditional, with compile-time constant condition.
exists(ConditionalExpr ce, boolean condition |