mirror of
https://github.com/irmen/prog8.git
synced 2024-11-19 11:32:17 +00:00
duplicate label check
This commit is contained in:
parent
dcab0d1e98
commit
8974a9cc2d
@ -48,6 +48,7 @@ data class Position(val file: String, val line: Int, val startCol: Int, val endC
|
||||
|
||||
|
||||
interface IAstProcessor {
|
||||
// override the ones you want to act upon
|
||||
fun process(module: Module) {
|
||||
}
|
||||
fun process(expr: PrefixExpression): IExpression {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package il65.ast
|
||||
|
||||
import il65.ParsingFailedError
|
||||
import javax.xml.crypto.Data
|
||||
|
||||
|
||||
fun Module.checkValid() {
|
||||
@ -50,6 +49,18 @@ class AstChecker : IAstProcessor {
|
||||
blockNames[block.name] = block.position
|
||||
}
|
||||
block.statements.forEach { it.process(this) }
|
||||
|
||||
// check if labels are unique
|
||||
val labels = block.statements.filter { it is Label }.map { it as Label }
|
||||
val labelnames = mutableMapOf<String, Position?>()
|
||||
labels.forEach {
|
||||
val existing = labelnames[it.name]
|
||||
if(existing!=null) {
|
||||
checkResult.add(SyntaxError("label name conflict, first defined on line ${existing.line}", it.position))
|
||||
} else {
|
||||
labelnames[it.name] = it.position
|
||||
}
|
||||
}
|
||||
return block
|
||||
}
|
||||
|
||||
@ -72,6 +83,18 @@ class AstChecker : IAstProcessor {
|
||||
|
||||
subroutine.statements.forEach { it.process(this) }
|
||||
|
||||
// check if labels are unique
|
||||
val labels = subroutine.statements.filter { it is Label }.map { it as Label }
|
||||
val labelnames = mutableMapOf<String, Position?>()
|
||||
labels.forEach {
|
||||
val existing = labelnames[it.name]
|
||||
if(existing!=null) {
|
||||
checkResult.add(SyntaxError("label name conflict, first defined on line ${existing.line}", it.position))
|
||||
} else {
|
||||
labelnames[it.name] = it.position
|
||||
}
|
||||
}
|
||||
|
||||
// subroutine must contain at least one 'return' or 'goto'
|
||||
// (or if it has an asm block, that must contain a 'rts' or 'jmp')
|
||||
if(subroutine.statements.count { it is Return || it is Jump } == 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user