Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ls24005143/indicators with define #671

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
lanarimarco marked this conversation as resolved.
Show resolved Hide 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