mirror of
https://github.com/irmen/prog8.git
synced 2024-07-14 18:29:42 +00:00
refactor interface
This commit is contained in:
parent
64032d766e
commit
dcab0d1e98
@ -48,15 +48,32 @@ data class Position(val file: String, val line: Int, val startCol: Int, val endC
|
|||||||
|
|
||||||
|
|
||||||
interface IAstProcessor {
|
interface IAstProcessor {
|
||||||
fun process(module: Module)
|
fun process(module: Module) {
|
||||||
fun process(expr: PrefixExpression): IExpression
|
}
|
||||||
fun process(expr: BinaryExpression): IExpression
|
fun process(expr: PrefixExpression): IExpression {
|
||||||
fun process(directive: Directive): IStatement
|
return expr
|
||||||
fun process(block: Block): IStatement
|
}
|
||||||
fun process(decl: VarDecl): IStatement
|
fun process(expr: BinaryExpression): IExpression {
|
||||||
fun process(subroutine: Subroutine): IStatement
|
return expr
|
||||||
fun process(jump: Jump): IStatement
|
}
|
||||||
fun process(functionCall: FunctionCall): IExpression
|
fun process(directive: Directive): IStatement {
|
||||||
|
return directive
|
||||||
|
}
|
||||||
|
fun process(block: Block): IStatement {
|
||||||
|
return block
|
||||||
|
}
|
||||||
|
fun process(decl: VarDecl): IStatement {
|
||||||
|
return decl
|
||||||
|
}
|
||||||
|
fun process(subroutine: Subroutine): IStatement {
|
||||||
|
return subroutine
|
||||||
|
}
|
||||||
|
fun process(jump: Jump): IStatement {
|
||||||
|
return jump
|
||||||
|
}
|
||||||
|
fun process(functionCall: FunctionCall): IExpression {
|
||||||
|
return functionCall
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -623,7 +640,7 @@ private fun il65Parser.UnconditionaljumpContext.toAst(withPosition: Boolean): IS
|
|||||||
|
|
||||||
|
|
||||||
private fun il65Parser.LabeldefContext.toAst(withPosition: Boolean): IStatement {
|
private fun il65Parser.LabeldefContext.toAst(withPosition: Boolean): IStatement {
|
||||||
val lbl = Label(text)
|
val lbl = Label(this.children[0].text)
|
||||||
lbl.position = toPosition(withPosition)
|
lbl.position = toPosition(withPosition)
|
||||||
return lbl
|
return lbl
|
||||||
}
|
}
|
||||||
|
@ -28,14 +28,6 @@ class AstChecker : IAstProcessor {
|
|||||||
module.lines.forEach { it.process(this) }
|
module.lines.forEach { it.process(this) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun process(expr: PrefixExpression): IExpression {
|
|
||||||
return expr
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun process(expr: BinaryExpression): IExpression {
|
|
||||||
return expr
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun process(functionCall: FunctionCall): IExpression {
|
override fun process(functionCall: FunctionCall): IExpression {
|
||||||
functionCall.arglist.map{it.process(this)}
|
functionCall.arglist.map{it.process(this)}
|
||||||
return functionCall
|
return functionCall
|
||||||
|
@ -44,11 +44,6 @@ class AstOptimizer : IAstProcessor {
|
|||||||
return functionCall
|
return functionCall
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun process(jump: Jump): IStatement {
|
|
||||||
return jump
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
override fun process(decl: VarDecl): IStatement {
|
override fun process(decl: VarDecl): IStatement {
|
||||||
decl.value = decl.value?.process(this)
|
decl.value = decl.value?.process(this)
|
||||||
decl.arrayspec?.process(this)
|
decl.arrayspec?.process(this)
|
||||||
@ -126,10 +121,6 @@ class AstOptimizer : IAstProcessor {
|
|||||||
else -> expr
|
else -> expr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun process(directive: Directive): IStatement {
|
|
||||||
return directive
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,37 +40,4 @@ class ImportedAstChecker : IAstProcessor {
|
|||||||
}
|
}
|
||||||
module.lines = newLines
|
module.lines = newLines
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun process(subroutine: Subroutine): IStatement {
|
|
||||||
return subroutine
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun process(expr: PrefixExpression): IExpression {
|
|
||||||
return expr
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun process(expr: BinaryExpression): IExpression {
|
|
||||||
return expr
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun process(block: Block): IStatement {
|
|
||||||
return block
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun process(decl: VarDecl): IStatement {
|
|
||||||
return decl
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun process(directive: Directive): IStatement {
|
|
||||||
return directive
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun process(functionCall: FunctionCall): IExpression {
|
|
||||||
return functionCall
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun process(jump: Jump): IStatement {
|
|
||||||
return jump
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user