mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
remove unneeded check for duplicate module names as this is now caught by the logic in Program.addModule itself
This commit is contained in:
parent
552e0c2248
commit
7f15b7b716
@ -3,7 +3,6 @@ package prog8.compiler.astprocessing
|
|||||||
import prog8.ast.Node
|
import prog8.ast.Node
|
||||||
import prog8.ast.Program
|
import prog8.ast.Program
|
||||||
import prog8.ast.base.DataType
|
import prog8.ast.base.DataType
|
||||||
import prog8.ast.base.FatalAstException
|
|
||||||
import prog8.ast.expressions.CharLiteral
|
import prog8.ast.expressions.CharLiteral
|
||||||
import prog8.ast.expressions.NumericLiteralValue
|
import prog8.ast.expressions.NumericLiteralValue
|
||||||
import prog8.ast.expressions.RangeExpr
|
import prog8.ast.expressions.RangeExpr
|
||||||
@ -127,26 +126,6 @@ internal fun Program.checkIdentifiers(errors: IErrorReporter, options: Compilati
|
|||||||
lit2decl.visit(this)
|
lit2decl.visit(this)
|
||||||
lit2decl.applyModifications()
|
lit2decl.applyModifications()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if each module has a unique name.
|
|
||||||
// If not report those that haven't.
|
|
||||||
// TODO: move check for unique module names to earlier stage and/or to unit tests
|
|
||||||
val namesToModules = mapOf<String, MutableList<prog8.ast.Module>>().toMutableMap()
|
|
||||||
for (m in modules) {
|
|
||||||
val others = namesToModules[m.name]
|
|
||||||
if (others == null) {
|
|
||||||
namesToModules[m.name] = listOf(m).toMutableList()
|
|
||||||
} else {
|
|
||||||
others.add(m)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val nonUniqueNames = namesToModules.keys
|
|
||||||
.map { Pair(it, namesToModules[it]!!.size) }
|
|
||||||
.filter { it.second > 1 }
|
|
||||||
.map { "\"${it.first}\" (x${it.second})"}
|
|
||||||
if (nonUniqueNames.isNotEmpty()) {
|
|
||||||
throw FatalAstException("modules must have unique names; of the ttl ${modules.size} these have not: $nonUniqueNames")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun Program.variousCleanups(program: Program, errors: IErrorReporter) {
|
internal fun Program.variousCleanups(program: Program, errors: IErrorReporter) {
|
||||||
|
@ -95,8 +95,7 @@ object Prog8Parser {
|
|||||||
private class AntlrErrorListener(val src: SourceCode): BaseErrorListener() {
|
private class AntlrErrorListener(val src: SourceCode): BaseErrorListener() {
|
||||||
override fun syntaxError(recognizer: Recognizer<*, *>?, offendingSymbol: Any?, line: Int, charPositionInLine: Int, msg: String, e: RecognitionException?) {
|
override fun syntaxError(recognizer: Recognizer<*, *>?, offendingSymbol: Any?, line: Int, charPositionInLine: Int, msg: String, e: RecognitionException?) {
|
||||||
if (e == null) {
|
if (e == null) {
|
||||||
TODO("no RecognitionException - create your own ParseError")
|
throw ParseError(msg, Position(src.origin, line, charPositionInLine, charPositionInLine), RuntimeException("parse error"))
|
||||||
//throw ParseError()
|
|
||||||
} else {
|
} else {
|
||||||
if(e.offendingToken==null) {
|
if(e.offendingToken==null) {
|
||||||
throw ParseError(msg, Position(src.origin, line, charPositionInLine, charPositionInLine), e)
|
throw ParseError(msg, Position(src.origin, line, charPositionInLine, charPositionInLine), e)
|
||||||
@ -111,7 +110,7 @@ object Prog8Parser {
|
|||||||
val offending = this.offendingToken
|
val offending = this.offendingToken
|
||||||
val line = offending.line
|
val line = offending.line
|
||||||
val beginCol = offending.charPositionInLine
|
val beginCol = offending.charPositionInLine
|
||||||
val endCol = beginCol + offending.stopIndex - offending.startIndex // TODO: point to col *after* token?
|
val endCol = beginCol + offending.stopIndex - offending.startIndex // TODO: point to col *after* token? / why, what's wrong with endCol being inclusive
|
||||||
return Position(file, line, beginCol, endCol)
|
return Position(file, line, beginCol, endCol)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,12 +50,12 @@ class ProgramTests {
|
|||||||
assertSame(program, m1.program)
|
assertSame(program, m1.program)
|
||||||
assertSame(program.namespace, m1.parent)
|
assertSame(program.namespace, m1.parent)
|
||||||
|
|
||||||
assertFailsWith<IllegalArgumentException> { program.addModule(m1) }
|
assertThat("module may not occur multiple times",
|
||||||
.let { assertThat(it.message, containsString(m1.name)) }
|
assertFailsWith<IllegalArgumentException> { program.addModule(m1) }.message, containsString(m1.name))
|
||||||
|
|
||||||
val m2 = Module(mutableListOf(), m1.position, m1.source)
|
val m2 = Module(mutableListOf(), m1.position, m1.source)
|
||||||
assertFailsWith<IllegalArgumentException> { program.addModule(m2) }
|
assertThat("other module but with same name may not occur multiple times",
|
||||||
.let { assertThat(it.message, containsString(m2.name)) }
|
assertFailsWith<IllegalArgumentException> { program.addModule(m2) }.message, containsString(m2.name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user