From 049dbf5a78c2ffeabbb4931b2e232d119341e3e3 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 4 Jul 2021 15:14:39 +0200 Subject: [PATCH] improve compiler error when defining duplicate block names --- .../astprocessing/AstIdentifiersChecker.kt | 22 +++++-------------- docs/source/todo.rst | 5 +++++ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/compiler/src/prog8/compiler/astprocessing/AstIdentifiersChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstIdentifiersChecker.kt index 9d93627a2..f9f173ce2 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstIdentifiersChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstIdentifiersChecker.kt @@ -1,6 +1,5 @@ package prog8.compiler.astprocessing -import prog8.ast.Module import prog8.ast.Program import prog8.ast.base.Position import prog8.ast.expressions.StringLiteralValue @@ -17,29 +16,20 @@ internal class AstIdentifiersChecker(private val program: Program, private val e errors.err("name conflict '$name', also defined in ${existing.position.file} line ${existing.position.line}", position) } - override fun visit(module: Module) { - blocks.clear() // blocks may be redefined within a different module - - super.visit(module) - } - override fun visit(block: Block) { if(block.name in compTarget.machine.opcodeNames) errors.err("can't use a cpu opcode name as a symbol: '${block.name}'", block.position) val existing = blocks[block.name] - if(existing!=null) - nameError(block.name, block.position, existing) + if(existing!=null) { + if(block.isInLibrary) + nameError(existing.name, existing.position, block) + else + nameError(block.name, block.position, existing) + } else blocks[block.name] = block - if(!block.isInLibrary) { - val libraries = program.modules.filter { it.isLibraryModule } - val libraryBlockNames = libraries.flatMap { it.statements.filterIsInstance().map { b -> b.name } } - if(block.name in libraryBlockNames) - errors.err("block is already defined in an included library module", block.position) - } - super.visit(block) } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 9991ff8a4..2fc4fe66a 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -4,6 +4,11 @@ TODO For next release ^^^^^^^^^^^^^^^^ +- rename libdirs option to srcdirs? +- can we derive module.name from module.source (taking just the filename base)? +- can Position.file be a Path- making the source variable for nodes unnecessary? + + - refactor code to improve testability and other things, see [CompilerDevelopment](CompilerDevelopment.md) - simplify cx16.joystick_get2() once this cx16 rom issue is resolved: https://github.com/commanderx16/x16-rom/issues/203 (I hope this will still be included into the final v39 roms release for the cx16)