mirror of
https://github.com/irmen/prog8.git
synced 2024-10-16 18:23:59 +00:00
avoid compiler crash when evaluating const expressions fails due to things like integer out of bounds
This commit is contained in:
parent
96ba9f5902
commit
8dfe510883
@ -9,28 +9,32 @@ import kotlin.math.pow
|
|||||||
class ConstExprEvaluator {
|
class ConstExprEvaluator {
|
||||||
|
|
||||||
fun evaluate(left: NumericLiteralValue, operator: String, right: NumericLiteralValue): Expression {
|
fun evaluate(left: NumericLiteralValue, operator: String, right: NumericLiteralValue): Expression {
|
||||||
return when(operator) {
|
try {
|
||||||
"+" -> plus(left, right)
|
return when(operator) {
|
||||||
"-" -> minus(left, right)
|
"+" -> plus(left, right)
|
||||||
"*" -> multiply(left, right)
|
"-" -> minus(left, right)
|
||||||
"/" -> divide(left, right)
|
"*" -> multiply(left, right)
|
||||||
"%" -> remainder(left, right)
|
"/" -> divide(left, right)
|
||||||
"**" -> power(left, right)
|
"%" -> remainder(left, right)
|
||||||
"&" -> bitwiseand(left, right)
|
"**" -> power(left, right)
|
||||||
"|" -> bitwiseor(left, right)
|
"&" -> bitwiseand(left, right)
|
||||||
"^" -> bitwisexor(left, right)
|
"|" -> bitwiseor(left, right)
|
||||||
"and" -> logicaland(left, right)
|
"^" -> bitwisexor(left, right)
|
||||||
"or" -> logicalor(left, right)
|
"and" -> logicaland(left, right)
|
||||||
"xor" -> logicalxor(left, right)
|
"or" -> logicalor(left, right)
|
||||||
"<" -> NumericLiteralValue.fromBoolean(left < right, left.position)
|
"xor" -> logicalxor(left, right)
|
||||||
">" -> NumericLiteralValue.fromBoolean(left > right, left.position)
|
"<" -> NumericLiteralValue.fromBoolean(left < right, left.position)
|
||||||
"<=" -> NumericLiteralValue.fromBoolean(left <= right, left.position)
|
">" -> NumericLiteralValue.fromBoolean(left > right, left.position)
|
||||||
">=" -> NumericLiteralValue.fromBoolean(left >= right, left.position)
|
"<=" -> NumericLiteralValue.fromBoolean(left <= right, left.position)
|
||||||
"==" -> NumericLiteralValue.fromBoolean(left == right, left.position)
|
">=" -> NumericLiteralValue.fromBoolean(left >= right, left.position)
|
||||||
"!=" -> NumericLiteralValue.fromBoolean(left != right, left.position)
|
"==" -> NumericLiteralValue.fromBoolean(left == right, left.position)
|
||||||
"<<" -> shiftedleft(left, right)
|
"!=" -> NumericLiteralValue.fromBoolean(left != right, left.position)
|
||||||
">>" -> shiftedright(left, right)
|
"<<" -> shiftedleft(left, right)
|
||||||
else -> throw FatalAstException("const evaluation for invalid operator $operator")
|
">>" -> shiftedright(left, right)
|
||||||
|
else -> throw FatalAstException("const evaluation for invalid operator $operator")
|
||||||
|
}
|
||||||
|
} catch (ax: FatalAstException) {
|
||||||
|
throw ExpressionError(ax.message, left.position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user