Skip to content

Commit

Permalink
Add compile-time error case
Browse files Browse the repository at this point in the history
  • Loading branch information
dom-apuliasoft committed Dec 2, 2024
1 parent 6080198 commit 9c7e1c1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1302,17 +1302,24 @@ data class DefineStmt(
get() = "DEFINE"

override fun dataDefinition(): List<InStatementDataDefinition> {
// FIXME: If indicator was not priorly SET (SETON or SETOFF), program should error
val containingCU = this.ancestor(CompilationUnit::class.java)
?: return emptyList()

val indicatorPattern = Regex("\\*IN\\d\\d")
val isIndicator = originalName.trim().uppercase().matches(indicatorPattern)
val normalizedOriginalName = originalName.trim().uppercase()
val isIndicator = normalizedOriginalName.matches(indicatorPattern)
if (isIndicator) {
val indicatorKey = normalizedOriginalName.removePrefix("*IN").toIndicatorKey()
val setStatements = containingCU.main.stmts.explode(true).filterIsInstance<SetStmt>()
val definedIndicators = setStatements.map { it.indicators }.flatten().filterIsInstance<IndicatorExpr>()
val isIndicatorDefined = definedIndicators.any { it.index == indicatorKey }

if (!isIndicatorDefined) throw Error("Data reference $originalName not resolved")

val newDefinition = InStatementDataDefinition(newVarName, BooleanType, position)
return listOf(newDefinition)
}

val containingCU = this.ancestor(CompilationUnit::class.java)
?: return emptyList()

// Search standalone 'D spec' or InStatement definition
val originalDataDefinition = containingCU.dataDefinitions.find { it.name == originalName }
?: containingCU.getInStatementDataDefinitions().find { it.name == originalName }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,18 @@ class JarikoCallbackTest : AbstractTest() {
executeSourceLineTest("ERROR48")
}

@Test
fun executeERROR49CallBackTest() {
executePgmCallBackTest("ERROR49", SourceReferenceType.Program, "ERROR49", mapOf(
6 to "Data reference *IN10 not resolved"
))
}

@Test
fun executeERROR49SourceLineTest() {
executeSourceLineTest("ERROR49")
}

@Test
fun bypassSyntaxErrorTest() {
val configuration = Configuration().apply {
Expand Down
6 changes: 6 additions & 0 deletions rpgJavaInterpreter-core/src/test/resources/ERROR49.rpgle
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
V* ==============================================================
D* 02/12/24
D* Purpose: Must fire the following errors during execution of
D* line 6 - Data reference *IN10 not resolved
V* ==============================================================
C *LIKE DEFINE *IN10 XIN10

0 comments on commit 9c7e1c1

Please sign in to comment.