mirror of
https://github.com/irmen/prog8.git
synced 2024-11-29 17:50:35 +00:00
remove Nop ast node.
This commit is contained in:
parent
e773be2f58
commit
ddf96943f0
@ -837,7 +837,6 @@ class AsmGen(private val program: Program,
|
|||||||
outputSourceLine(stmt)
|
outputSourceLine(stmt)
|
||||||
when(stmt) {
|
when(stmt) {
|
||||||
is VarDecl -> translate(stmt)
|
is VarDecl -> translate(stmt)
|
||||||
is Nop -> {}
|
|
||||||
is Directive -> translate(stmt)
|
is Directive -> translate(stmt)
|
||||||
is Return -> translate(stmt)
|
is Return -> translate(stmt)
|
||||||
is Subroutine -> translateSubroutine(stmt)
|
is Subroutine -> translateSubroutine(stmt)
|
||||||
@ -859,7 +858,7 @@ class AsmGen(private val program: Program,
|
|||||||
is GoSub -> translate(stmt)
|
is GoSub -> translate(stmt)
|
||||||
is PostIncrDecr -> postincrdecrAsmGen.translate(stmt)
|
is PostIncrDecr -> postincrdecrAsmGen.translate(stmt)
|
||||||
is Label -> translate(stmt)
|
is Label -> translate(stmt)
|
||||||
is Branch -> translate(stmt)
|
is ConditionalBranch -> translate(stmt)
|
||||||
is IfElse -> translate(stmt)
|
is IfElse -> translate(stmt)
|
||||||
is ForLoop -> forloopsAsmGen.translate(stmt)
|
is ForLoop -> forloopsAsmGen.translate(stmt)
|
||||||
is RepeatLoop -> translate(stmt)
|
is RepeatLoop -> translate(stmt)
|
||||||
@ -1536,7 +1535,7 @@ $repeatLabel lda $counterVar
|
|||||||
scope.statements.forEach{ translate(it) }
|
scope.statements.forEach{ translate(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun translate(stmt: Branch) {
|
private fun translate(stmt: ConditionalBranch) {
|
||||||
if(stmt.truepart.isEmpty() && stmt.elsepart.isNotEmpty())
|
if(stmt.truepart.isEmpty() && stmt.elsepart.isNotEmpty())
|
||||||
throw AssemblyError("only else part contains code, shoud have been switched already")
|
throw AssemblyError("only else part contains code, shoud have been switched already")
|
||||||
|
|
||||||
|
@ -205,8 +205,7 @@ internal class AstChecker(private val program: Program,
|
|||||||
is Label,
|
is Label,
|
||||||
is VarDecl,
|
is VarDecl,
|
||||||
is InlineAssembly,
|
is InlineAssembly,
|
||||||
is IStatementContainer,
|
is IStatementContainer -> true
|
||||||
is Nop -> true
|
|
||||||
is Assignment -> {
|
is Assignment -> {
|
||||||
val target = statement.target.identifier!!.targetStatement(program)
|
val target = statement.target.identifier!!.targetStatement(program)
|
||||||
target === statement.previousSibling() // an initializer assignment is okay
|
target === statement.previousSibling() // an initializer assignment is okay
|
||||||
|
@ -324,7 +324,7 @@ internal class BeforeAsmAstChanger(val program: Program, private val options: Co
|
|||||||
complexArrayIndexedExpressions.add(arrayIndexedExpression)
|
complexArrayIndexedExpressions.add(arrayIndexedExpression)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visit(branch: Branch) {}
|
override fun visit(branch: ConditionalBranch) {}
|
||||||
|
|
||||||
override fun visit(forLoop: ForLoop) {}
|
override fun visit(forLoop: ForLoop) {}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ internal class ParentNodeChecker: AstWalker() {
|
|||||||
return noModifications
|
return noModifications
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun before(branch: Branch, parent: Node): Iterable<IAstModification> {
|
override fun before(branch: ConditionalBranch, parent: Node): Iterable<IAstModification> {
|
||||||
if(branch.parent!==parent)
|
if(branch.parent!==parent)
|
||||||
throw FatalAstException("parent node mismatch at $branch")
|
throw FatalAstException("parent node mismatch at $branch")
|
||||||
return noModifications
|
return noModifications
|
||||||
@ -233,12 +233,6 @@ internal class ParentNodeChecker: AstWalker() {
|
|||||||
return noModifications
|
return noModifications
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun before(nop: Nop, parent: Node): Iterable<IAstModification> {
|
|
||||||
if(nop.parent!==parent)
|
|
||||||
throw FatalAstException("parent node mismatch at $nop")
|
|
||||||
return noModifications
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun before(scope: AnonymousScope, parent: Node): Iterable<IAstModification> {
|
override fun before(scope: AnonymousScope, parent: Node): Iterable<IAstModification> {
|
||||||
if(scope.parent!==parent)
|
if(scope.parent!==parent)
|
||||||
throw FatalAstException("parent node mismatch at $scope")
|
throw FatalAstException("parent node mismatch at $scope")
|
||||||
|
@ -17,10 +17,6 @@ import prog8.compilerinterface.IErrorReporter
|
|||||||
|
|
||||||
internal class VariousCleanups(val program: Program, val errors: IErrorReporter, val options: CompilationOptions): AstWalker() {
|
internal class VariousCleanups(val program: Program, val errors: IErrorReporter, val options: CompilationOptions): AstWalker() {
|
||||||
|
|
||||||
override fun before(nop: Nop, parent: Node): Iterable<IAstModification> {
|
|
||||||
return listOf(IAstModification.Remove(nop, parent as IStatementContainer))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun after(scope: AnonymousScope, parent: Node): Iterable<IAstModification> {
|
override fun after(scope: AnonymousScope, parent: Node): Iterable<IAstModification> {
|
||||||
return if(parent is IStatementContainer)
|
return if(parent is IStatementContainer)
|
||||||
listOf(ScopeFlatten(scope, parent as IStatementContainer))
|
listOf(ScopeFlatten(scope, parent as IStatementContainer))
|
||||||
|
@ -2,13 +2,11 @@ package prog8.ast
|
|||||||
|
|
||||||
import prog8.ast.antlr.escape
|
import prog8.ast.antlr.escape
|
||||||
import prog8.ast.base.DataType
|
import prog8.ast.base.DataType
|
||||||
import prog8.ast.base.FatalAstException
|
|
||||||
import prog8.ast.base.NumericDatatypes
|
import prog8.ast.base.NumericDatatypes
|
||||||
import prog8.ast.base.VarDeclType
|
import prog8.ast.base.VarDeclType
|
||||||
import prog8.ast.expressions.*
|
import prog8.ast.expressions.*
|
||||||
import prog8.ast.statements.*
|
import prog8.ast.statements.*
|
||||||
import prog8.ast.walk.IAstVisitor
|
import prog8.ast.walk.IAstVisitor
|
||||||
import prog8.compilerinterface.Encoding
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -259,7 +257,7 @@ class AstToSourceTextConverter(val output: (text: String) -> Unit, val program:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visit(branch: Branch) {
|
override fun visit(branch: ConditionalBranch) {
|
||||||
output("if_${branch.condition.toString().lowercase()} ")
|
output("if_${branch.condition.toString().lowercase()} ")
|
||||||
branch.truepart.accept(this)
|
branch.truepart.accept(this)
|
||||||
if(branch.elsepart.statements.isNotEmpty()) {
|
if(branch.elsepart.statements.isNotEmpty()) {
|
||||||
|
@ -92,7 +92,7 @@ interface IStatementContainer {
|
|||||||
if(found!=null)
|
if(found!=null)
|
||||||
return found
|
return found
|
||||||
}
|
}
|
||||||
is Branch -> {
|
is ConditionalBranch -> {
|
||||||
val found = stmt.truepart.searchSymbol(name) ?: stmt.elsepart.searchSymbol(name)
|
val found = stmt.truepart.searchSymbol(name) ?: stmt.elsepart.searchSymbol(name)
|
||||||
if(found!=null)
|
if(found!=null)
|
||||||
return found
|
return found
|
||||||
|
@ -518,14 +518,14 @@ private fun Prog8ANTLRParser.Else_partContext.toAst(): MutableList<Statement> {
|
|||||||
return statement_block()?.toAst() ?: mutableListOf(statement().toAst())
|
return statement_block()?.toAst() ?: mutableListOf(statement().toAst())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Prog8ANTLRParser.Branch_stmtContext.toAst(): Branch {
|
private fun Prog8ANTLRParser.Branch_stmtContext.toAst(): ConditionalBranch {
|
||||||
val branchcondition = branchcondition().toAst()
|
val branchcondition = branchcondition().toAst()
|
||||||
val trueStatements = statement_block()?.toAst() ?: mutableListOf(statement().toAst())
|
val trueStatements = statement_block()?.toAst() ?: mutableListOf(statement().toAst())
|
||||||
val elseStatements = else_part()?.toAst() ?: mutableListOf()
|
val elseStatements = else_part()?.toAst() ?: mutableListOf()
|
||||||
val trueScope = AnonymousScope(trueStatements, statement_block()?.toPosition()
|
val trueScope = AnonymousScope(trueStatements, statement_block()?.toPosition()
|
||||||
?: statement().toPosition())
|
?: statement().toPosition())
|
||||||
val elseScope = AnonymousScope(elseStatements, else_part()?.toPosition() ?: toPosition())
|
val elseScope = AnonymousScope(elseStatements, else_part()?.toPosition() ?: toPosition())
|
||||||
return Branch(branchcondition, trueScope, elseScope, toPosition())
|
return ConditionalBranch(branchcondition, trueScope, elseScope, toPosition())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Prog8ANTLRParser.BranchconditionContext.toAst() = BranchCondition.valueOf(
|
private fun Prog8ANTLRParser.BranchconditionContext.toAst() = BranchCondition.valueOf(
|
||||||
|
@ -639,19 +639,6 @@ class AnonymousScope(override var statements: MutableList<Statement>,
|
|||||||
override fun accept(visitor: AstWalker, parent: Node) = visitor.visit(this, parent)
|
override fun accept(visitor: AstWalker, parent: Node) = visitor.visit(this, parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
class Nop(override val position: Position): Statement() {
|
|
||||||
override lateinit var parent: Node
|
|
||||||
|
|
||||||
override fun linkParents(parent: Node) {
|
|
||||||
this.parent = parent
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun replaceChildNode(node: Node, replacement: Node) = throw FatalAstException("can't replace here")
|
|
||||||
override fun copy() = Nop(position)
|
|
||||||
override fun accept(visitor: IAstVisitor) = visitor.visit(this)
|
|
||||||
override fun accept(visitor: AstWalker, parent: Node) = visitor.visit(this, parent)
|
|
||||||
}
|
|
||||||
|
|
||||||
class AsmGenInfo {
|
class AsmGenInfo {
|
||||||
// This class contains various attributes that influence the assembly code generator.
|
// This class contains various attributes that influence the assembly code generator.
|
||||||
// Conceptually it should be part of any INameScope.
|
// Conceptually it should be part of any INameScope.
|
||||||
@ -818,7 +805,7 @@ class IfElse(var condition: Expression,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Branch(var condition: BranchCondition,
|
class ConditionalBranch(var condition: BranchCondition,
|
||||||
var truepart: AnonymousScope,
|
var truepart: AnonymousScope,
|
||||||
var elsepart: AnonymousScope,
|
var elsepart: AnonymousScope,
|
||||||
override val position: Position) : Statement() {
|
override val position: Position) : Statement() {
|
||||||
|
@ -85,7 +85,7 @@ abstract class AstWalker {
|
|||||||
open fun before(assignTarget: AssignTarget, parent: Node): Iterable<IAstModification> = noModifications
|
open fun before(assignTarget: AssignTarget, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun before(assignment: Assignment, parent: Node): Iterable<IAstModification> = noModifications
|
open fun before(assignment: Assignment, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun before(block: Block, parent: Node): Iterable<IAstModification> = noModifications
|
open fun before(block: Block, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun before(branch: Branch, parent: Node): Iterable<IAstModification> = noModifications
|
open fun before(branch: ConditionalBranch, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun before(breakStmt: Break, parent: Node): Iterable<IAstModification> = noModifications
|
open fun before(breakStmt: Break, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun before(containment: ContainmentCheck, parent: Node): Iterable<IAstModification> = noModifications
|
open fun before(containment: ContainmentCheck, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun before(decl: VarDecl, parent: Node): Iterable<IAstModification> = noModifications
|
open fun before(decl: VarDecl, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
@ -105,7 +105,6 @@ abstract class AstWalker {
|
|||||||
open fun before(memread: DirectMemoryRead, parent: Node): Iterable<IAstModification> = noModifications
|
open fun before(memread: DirectMemoryRead, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun before(memwrite: DirectMemoryWrite, parent: Node): Iterable<IAstModification> = noModifications
|
open fun before(memwrite: DirectMemoryWrite, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun before(module: Module, parent: Node): Iterable<IAstModification> = noModifications
|
open fun before(module: Module, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun before(nop: Nop, parent: Node): Iterable<IAstModification> = noModifications
|
|
||||||
open fun before(numLiteral: NumericLiteralValue, parent: Node): Iterable<IAstModification> = noModifications
|
open fun before(numLiteral: NumericLiteralValue, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun before(postIncrDecr: PostIncrDecr, parent: Node): Iterable<IAstModification> = noModifications
|
open fun before(postIncrDecr: PostIncrDecr, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun before(program: Program): Iterable<IAstModification> = noModifications
|
open fun before(program: Program): Iterable<IAstModification> = noModifications
|
||||||
@ -129,7 +128,7 @@ abstract class AstWalker {
|
|||||||
open fun after(assignTarget: AssignTarget, parent: Node): Iterable<IAstModification> = noModifications
|
open fun after(assignTarget: AssignTarget, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun after(assignment: Assignment, parent: Node): Iterable<IAstModification> = noModifications
|
open fun after(assignment: Assignment, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun after(block: Block, parent: Node): Iterable<IAstModification> = noModifications
|
open fun after(block: Block, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun after(branch: Branch, parent: Node): Iterable<IAstModification> = noModifications
|
open fun after(branch: ConditionalBranch, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun after(breakStmt: Break, parent: Node): Iterable<IAstModification> = noModifications
|
open fun after(breakStmt: Break, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun after(containment: ContainmentCheck, parent: Node): Iterable<IAstModification> = noModifications
|
open fun after(containment: ContainmentCheck, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun after(builtinFunctionPlaceholder: BuiltinFunctionPlaceholder, parent: Node): Iterable<IAstModification> = noModifications
|
open fun after(builtinFunctionPlaceholder: BuiltinFunctionPlaceholder, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
@ -150,7 +149,6 @@ abstract class AstWalker {
|
|||||||
open fun after(memread: DirectMemoryRead, parent: Node): Iterable<IAstModification> = noModifications
|
open fun after(memread: DirectMemoryRead, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun after(memwrite: DirectMemoryWrite, parent: Node): Iterable<IAstModification> = noModifications
|
open fun after(memwrite: DirectMemoryWrite, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun after(module: Module, parent: Node): Iterable<IAstModification> = noModifications
|
open fun after(module: Module, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun after(nop: Nop, parent: Node): Iterable<IAstModification> = noModifications
|
|
||||||
open fun after(numLiteral: NumericLiteralValue, parent: Node): Iterable<IAstModification> = noModifications
|
open fun after(numLiteral: NumericLiteralValue, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun after(postIncrDecr: PostIncrDecr, parent: Node): Iterable<IAstModification> = noModifications
|
open fun after(postIncrDecr: PostIncrDecr, parent: Node): Iterable<IAstModification> = noModifications
|
||||||
open fun after(program: Program): Iterable<IAstModification> = noModifications
|
open fun after(program: Program): Iterable<IAstModification> = noModifications
|
||||||
@ -299,7 +297,7 @@ abstract class AstWalker {
|
|||||||
track(after(ifElse, parent), ifElse, parent)
|
track(after(ifElse, parent), ifElse, parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun visit(branch: Branch, parent: Node) {
|
fun visit(branch: ConditionalBranch, parent: Node) {
|
||||||
track(before(branch, parent), branch, parent)
|
track(before(branch, parent), branch, parent)
|
||||||
branch.truepart.accept(this, branch)
|
branch.truepart.accept(this, branch)
|
||||||
branch.elsepart.accept(this, branch)
|
branch.elsepart.accept(this, branch)
|
||||||
@ -443,11 +441,6 @@ abstract class AstWalker {
|
|||||||
track(after(inlineAssembly, parent), inlineAssembly, parent)
|
track(after(inlineAssembly, parent), inlineAssembly, parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun visit(nop: Nop, parent: Node) {
|
|
||||||
track(before(nop, parent), nop, parent)
|
|
||||||
track(after(nop, parent), nop, parent)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun visit(whenStmt: When, parent: Node) {
|
fun visit(whenStmt: When, parent: Node) {
|
||||||
track(before(whenStmt, parent), whenStmt, parent)
|
track(before(whenStmt, parent), whenStmt, parent)
|
||||||
whenStmt.condition.accept(this, whenStmt)
|
whenStmt.condition.accept(this, whenStmt)
|
||||||
|
@ -71,7 +71,7 @@ interface IAstVisitor {
|
|||||||
ifElse.elsepart.accept(this)
|
ifElse.elsepart.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun visit(branch: Branch) {
|
fun visit(branch: ConditionalBranch) {
|
||||||
branch.truepart.accept(this)
|
branch.truepart.accept(this)
|
||||||
branch.elsepart.accept(this)
|
branch.elsepart.accept(this)
|
||||||
}
|
}
|
||||||
@ -169,9 +169,6 @@ interface IAstVisitor {
|
|||||||
fun visit(inlineAssembly: InlineAssembly) {
|
fun visit(inlineAssembly: InlineAssembly) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun visit(nop: Nop) {
|
|
||||||
}
|
|
||||||
|
|
||||||
fun visit(whenStmt: When) {
|
fun visit(whenStmt: When) {
|
||||||
whenStmt.condition.accept(this)
|
whenStmt.condition.accept(this)
|
||||||
whenStmt.choices.forEach { it.accept(this) }
|
whenStmt.choices.forEach { it.accept(this) }
|
||||||
|
Loading…
Reference in New Issue
Block a user