Skip to content

Commit

Permalink
Merge pull request #671 from smeup/feature/LS24005143/indicators-with…
Browse files Browse the repository at this point in the history
…-define

Feature/ls24005143/indicators with define
  • Loading branch information
lanarimarco authored Dec 3, 2024
2 parents 4db3051 + 9c7e1c1 commit 2f5298f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,21 @@ data class DefineStmt(
val containingCU = this.ancestor(CompilationUnit::class.java)
?: return emptyList()

val indicatorPattern = Regex("\\*IN\\d\\d")
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)
}

// 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
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,16 @@ open class MULANGT02ConstAndDSpecTest : MULANGTTest() {
assertEquals(expected, "smeup/MUDRNRAPU00270".outputOf(configuration = smeupConfig))
}

/**
* DEFINE with indicator as original name
* @see #LS24005143
*/
@Test
fun executeMUDRNRAPU00273() {
val expected = listOf("1", "0")
assertEquals(expected, "smeup/MUDRNRAPU00273".outputOf(configuration = smeupConfig))
}

/**
* Truncation of number by using Z-ADD. The source is greater than destination.
* Source and destination are integer.
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
V* ==============================================================
V* 28/11/2024 APU002 Creation
V* ==============================================================
O * PROGRAM GOAL
O * DEFINE on an indicator
V* ==============================================================
O * JARIKO ANOMALY
O * Before the fix, jariko throw a DataReference error
V* ==============================================================
C SETON 10
C EVAL XIN10=*ON
C XIN10 DSPLY
C EVAL XIN10=*OFF
C XIN10 DSPLY
C *LIKE DEFINE *IN10 XIN10

0 comments on commit 2f5298f

Please sign in to comment.