mirror of
https://github.com/irmen/prog8.git
synced 2025-01-13 10:29:52 +00:00
allow when choice values to be replaced in ast (const-folding)
This commit is contained in:
parent
54fc9c91ac
commit
dde6919446
@ -627,7 +627,7 @@ private fun prog8Parser.When_choiceContext.toAst(): WhenChoice {
|
||||
if(stmt!=null)
|
||||
stmtBlock.add(stmt)
|
||||
val scope = AnonymousScope(stmtBlock, toPosition())
|
||||
return WhenChoice(values, scope, toPosition())
|
||||
return WhenChoice(values?.toMutableList(), scope, toPosition())
|
||||
}
|
||||
|
||||
private fun prog8Parser.VardeclContext.toAst(): VarDecl {
|
||||
|
@ -991,7 +991,7 @@ class WhenStatement(var condition: Expression,
|
||||
override fun accept(visitor: AstWalker, parent: Node) = visitor.visit(this, parent)
|
||||
}
|
||||
|
||||
class WhenChoice(var values: List<Expression>?, // if null, this is the 'else' part
|
||||
class WhenChoice(var values: MutableList<Expression>?, // if null, this is the 'else' part
|
||||
var statements: AnonymousScope,
|
||||
override val position: Position) : Node {
|
||||
override lateinit var parent: Node
|
||||
@ -1008,7 +1008,9 @@ class WhenChoice(var values: List<Expression>?, // if null, this is t
|
||||
statements = replacement
|
||||
replacement.parent = this
|
||||
} else if(choiceValues!=null && node in choiceValues) {
|
||||
throw FatalAstException("cannot replace choice values")
|
||||
val idx = choiceValues.indexOf(node)
|
||||
choiceValues[idx] = replacement as Expression
|
||||
replacement.parent = this
|
||||
} else {
|
||||
throw FatalAstException("invalid replacement")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user