mirror of
https://github.com/irmen/prog8.git
synced 2024-11-25 19:31:36 +00:00
added ast printing of when statement
This commit is contained in:
parent
9bc36b4d99
commit
3581017489
@ -1,5 +1,6 @@
|
||||
package prog8.compiler
|
||||
|
||||
import prog8.ast.antlr.escape
|
||||
import prog8.ast.IFunctionCall
|
||||
import prog8.ast.IStatement
|
||||
import prog8.ast.Module
|
||||
@ -245,7 +246,7 @@ class AstToSourceCode(val output: (text: String) -> Unit): IAstVisitor {
|
||||
override fun visit(literalValue: LiteralValue) {
|
||||
when {
|
||||
literalValue.isNumeric -> output(literalValue.asNumericValue.toString())
|
||||
literalValue.isString -> output("\"${literalValue.strvalue}\"")
|
||||
literalValue.isString -> output("\"${escape(literalValue.strvalue!!)}\"")
|
||||
literalValue.isArray -> {
|
||||
if(literalValue.arrayvalue!=null) {
|
||||
output("[")
|
||||
@ -385,6 +386,30 @@ class AstToSourceCode(val output: (text: String) -> Unit): IAstVisitor {
|
||||
output(builtinFunctionStatementPlaceholder.name)
|
||||
}
|
||||
|
||||
override fun visit(whenStatement: WhenStatement) {
|
||||
output("when ")
|
||||
whenStatement.condition.accept(this)
|
||||
outputln(" {")
|
||||
scopelevel++
|
||||
whenStatement.choices.forEach { it.accept(this) }
|
||||
scopelevel--
|
||||
outputlni("}")
|
||||
}
|
||||
|
||||
override fun visit(whenChoice: WhenChoice) {
|
||||
if(whenChoice.value==null)
|
||||
outputi("else -> ")
|
||||
else {
|
||||
outputi("")
|
||||
whenChoice.value.accept(this)
|
||||
output(" -> ")
|
||||
}
|
||||
if(whenChoice.statements.statements.size==1)
|
||||
whenChoice.statements.statements.single().accept(this)
|
||||
else
|
||||
whenChoice.statements.accept(this)
|
||||
outputln("")
|
||||
}
|
||||
override fun visit(nopStatement: NopStatement) {
|
||||
TODO("NOP???")
|
||||
}
|
||||
|
@ -65,7 +65,6 @@ fun compileProgram(filepath: Path,
|
||||
val time3 = measureTimeMillis {
|
||||
programAst.reorderStatements() // reorder statements and add type casts, to please the compiler later
|
||||
}
|
||||
printAst(programAst)
|
||||
//println(" time3: $time3")
|
||||
val time4 = measureTimeMillis {
|
||||
programAst.checkValid(compilerOptions) // check if tree is valid
|
||||
|
@ -9,6 +9,9 @@
|
||||
Y=22
|
||||
uword uw = A*Y
|
||||
|
||||
str teststring = "hello"
|
||||
c64scr.print(&teststring)
|
||||
|
||||
when uw {
|
||||
12345 -> {
|
||||
A=44
|
||||
|
Loading…
Reference in New Issue
Block a user