From 16cbf0409b60088d859a5808888c9996432fa2a1 Mon Sep 17 00:00:00 2001 From: domenico Date: Wed, 11 Dec 2024 12:16:33 +0100 Subject: [PATCH 1/4] Add test cases --- .../rpgparser/smeup/MULANGT10BaseCodopTest.kt | 20 ++++++++++++ .../test/resources/smeup/MUDRNRAPU00279.rpgle | 29 +++++++++++++++++ .../test/resources/smeup/MUDRNRAPU00280.rpgle | 31 +++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00279.rpgle create mode 100644 rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00280.rpgle diff --git a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT10BaseCodopTest.kt b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT10BaseCodopTest.kt index 325bd1da1..624034f08 100644 --- a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT10BaseCodopTest.kt +++ b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT10BaseCodopTest.kt @@ -830,4 +830,24 @@ open class MULANGT10BaseCodopTest : MULANGTTest() { val expected = listOf("", "FOO", "BAR", "BARX") assertEquals(expected, "smeup/MUDRNRAPU00182".outputOf(configuration = smeupConfig)) } + + /** + * SCAN followed by %FOUND + * @see #LS24005347 + */ + @Test + fun executeMUDRNRAPU00279() { + val expected = listOf("3", "FOUND", "0", "NOT FOUND") + assertEquals(expected, "smeup/MUDRNRAPU00279".outputOf(configuration = smeupConfig)) + } + + /** + * LOOKUP followed by %FOUND + * @see #LS24005347 + */ + @Test + fun executeMUDRNRAPU00280() { + val expected = listOf("1", "0", "1", "0") + assertEquals(expected, "smeup/MUDRNRAPU00280".outputOf(configuration = smeupConfig)) + } } \ No newline at end of file diff --git a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00279.rpgle b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00279.rpgle new file mode 100644 index 000000000..af462f8e8 --- /dev/null +++ b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00279.rpgle @@ -0,0 +1,29 @@ + V* ============================================================== + V* 11/12/2024 APU002 Creation + V* ============================================================== + O * PROGRAM GOAL + O * SCAN followed by %FOUND + V* ============================================================== + O * JARIKO ANOMALY + O * Before the fix, jariko did not consider SCAN accountable for %FOUND + V* ============================================================== + D RESULT S 1 0 + D BASE S 6 INZ('XCABCD') + + C 'ABC' SCAN BASE RESULT + C RESULT DSPLY + C IF %FOUND + C 'FOUND' DSPLY + C ELSE + C 'NOT FOUND' DSPLY + C ENDIF + + C 'FOO' SCAN BASE RESULT + C RESULT DSPLY + C IF %FOUND + C 'FOUND' DSPLY + C ELSE + C 'NOT FOUND' DSPLY + C ENDIF + + C SETON RT \ No newline at end of file diff --git a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00280.rpgle b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00280.rpgle new file mode 100644 index 000000000..620e9cfd7 --- /dev/null +++ b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00280.rpgle @@ -0,0 +1,31 @@ + V* ============================================================== + V* 11/12/2024 APU002 Creation + V* ============================================================== + O * PROGRAM GOAL + O * LOOKUP followed by %FOUND + V* ============================================================== + O * JARIKO ANOMALY + O * Before the fix, jariko did not consider LOOKUP accountable for %FOUND + V* ============================================================== + D RESULT S 1 0 + D FND S N + D ARY S 3 DIM(10) + C EVAL ARY(1)='ABC' + C* Lookup opcode found + C 'ABC' LOOKUP ARY 26 + C EVAL FND=%FOUND + C FND DSPLY + C* Lookup opcode not found + C 'FOO' LOOKUP ARY 26 + C EVAL FND=%FOUND + C FND DSPLY + C* Lookup expression found + C EVAL RESULT=%LOOKUP('ABC':ARY) + C EVAL FND=%FOUND + C FND DSPLY + C* Lookup expression not found + C EVAL RESULT=%LOOKUP('FOO':ARY) + C EVAL FND=%FOUND + C FND DSPLY + + C SETON RT \ No newline at end of file From 35efcb99621dcb974fa493e5cdd74c1c50698a4f Mon Sep 17 00:00:00 2001 From: domenico Date: Wed, 11 Dec 2024 12:16:47 +0100 Subject: [PATCH 2/4] Cleanup leftover in old test case --- .../src/test/resources/smeup/MUDRNRAPU00275.rpgle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00275.rpgle b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00275.rpgle index 27e162a82..7c2203cb9 100644 --- a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00275.rpgle +++ b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00275.rpgle @@ -6,7 +6,7 @@ V* ============================================================== O * JARIKO ANOMALY O * Before the fix, jariko throw a syntax error - V* ============================================================== DA1 S 1 + V* ============================================================== DN2 S 2 0 D T$C5MD S 15 DA1 S 2 From 17134ce2db44e5c2ae144558f98d7eb1530b2833 Mon Sep 17 00:00:00 2001 From: domenico Date: Wed, 11 Dec 2024 12:17:04 +0100 Subject: [PATCH 3/4] Add missing lastFound logic --- .../smeup/rpgparser/interpreter/ExpressionEvaluation.kt | 9 +++++++-- .../kotlin/com/smeup/rpgparser/interpreter/lookup.kt | 3 +++ .../kotlin/com/smeup/rpgparser/parsing/ast/statements.kt | 6 ++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/ExpressionEvaluation.kt b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/ExpressionEvaluation.kt index cb2c50a31..4c428a43a 100644 --- a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/ExpressionEvaluation.kt +++ b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/ExpressionEvaluation.kt @@ -261,7 +261,7 @@ class ExpressionEvaluation( } override fun eval(expression: LookupExpr): Value = proxyLogging(expression) { - lookup( + val result = lookup( array = expression.array.evalWith(this) as ArrayValue, arrayType = expression.array.type() as ArrayType, searchedValue = expression.searchedValued.evalWith(this), @@ -269,6 +269,11 @@ class ExpressionEvaluation( length = expression.length?.evalWith(this)?.asInt(), operator = ComparisonOperator.EQ ) + + // %LOOKUP is relevant for %FOUND + interpreterStatus.lastFound = result != IntValue.ZERO + + result } override fun eval(expression: LookupGtExpr): Value = proxyLogging(expression) { @@ -961,7 +966,7 @@ class ExpressionEvaluation( start: IntValue?, length: IntValue?, operator: ComparisonOperator - ): Value { + ): IntValue { val arrayLength = arrayType.numberOfElements() val isSequenced = arrayType.ascend != null diff --git a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/lookup.kt b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/lookup.kt index c25c6c153..f5d405716 100644 --- a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/lookup.kt +++ b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/lookup.kt @@ -115,6 +115,9 @@ fun lookUp(statement: LookupStmt, interpreterCore: InterpreterCore, charset: Cha arraySearchingParameters.indexVar?.let { interpreterCore.assign(it, searchResult.oneBasedIndex.asValue()) } + + // Lookup is relevant for %FOUND + interpreterCore.getStatus().lastFound = searchResult !is NotFound } class FoundIndexes(var hi: Int, var lo: Int, var eq: Int) { diff --git a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/ast/statements.kt b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/ast/statements.kt index 2590694e0..6aa2c198f 100644 --- a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/ast/statements.kt +++ b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/ast/statements.kt @@ -2369,6 +2369,9 @@ data class ScanStmt( val leftLength = leftLengthExpression?.let { interpreter.eval(it).asString().value.toInt() } val start = startPosition?.let { interpreter.eval(it).asString().value.toInt() } ?: 1 + // SCAN is relevant for %FOUND calls + interpreter.getStatus().lastFound = false + val stringToSearch = interpreter.eval(left).asString().value.substringOfLength(leftLength) val searchInto = interpreter.eval(right).asString().value.substring(start - 1) val occurrences = mutableListOf() @@ -2391,6 +2394,9 @@ data class ScanStmt( interpreter.assign(it, occurrences[0]) } } + + // Update found status + interpreter.getStatus().lastFound = true } } From d4507ecb353c5b6e0abe23692e61db51ebef3dff Mon Sep 17 00:00:00 2001 From: domenico Date: Wed, 11 Dec 2024 12:55:06 +0100 Subject: [PATCH 4/4] Revert lastFound logic on %LOOKUP --- .../smeup/rpgparser/interpreter/ExpressionEvaluation.kt | 7 +------ .../com/smeup/rpgparser/smeup/MULANGT10BaseCodopTest.kt | 2 +- .../src/test/resources/smeup/MUDRNRAPU00280.rpgle | 8 -------- 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/ExpressionEvaluation.kt b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/ExpressionEvaluation.kt index 4c428a43a..af96b4816 100644 --- a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/ExpressionEvaluation.kt +++ b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/ExpressionEvaluation.kt @@ -261,7 +261,7 @@ class ExpressionEvaluation( } override fun eval(expression: LookupExpr): Value = proxyLogging(expression) { - val result = lookup( + lookup( array = expression.array.evalWith(this) as ArrayValue, arrayType = expression.array.type() as ArrayType, searchedValue = expression.searchedValued.evalWith(this), @@ -269,11 +269,6 @@ class ExpressionEvaluation( length = expression.length?.evalWith(this)?.asInt(), operator = ComparisonOperator.EQ ) - - // %LOOKUP is relevant for %FOUND - interpreterStatus.lastFound = result != IntValue.ZERO - - result } override fun eval(expression: LookupGtExpr): Value = proxyLogging(expression) { diff --git a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT10BaseCodopTest.kt b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT10BaseCodopTest.kt index 624034f08..59fd9d430 100644 --- a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT10BaseCodopTest.kt +++ b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT10BaseCodopTest.kt @@ -847,7 +847,7 @@ open class MULANGT10BaseCodopTest : MULANGTTest() { */ @Test fun executeMUDRNRAPU00280() { - val expected = listOf("1", "0", "1", "0") + val expected = listOf("1", "0") assertEquals(expected, "smeup/MUDRNRAPU00280".outputOf(configuration = smeupConfig)) } } \ No newline at end of file diff --git a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00280.rpgle b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00280.rpgle index 620e9cfd7..a43fbed95 100644 --- a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00280.rpgle +++ b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00280.rpgle @@ -19,13 +19,5 @@ C 'FOO' LOOKUP ARY 26 C EVAL FND=%FOUND C FND DSPLY - C* Lookup expression found - C EVAL RESULT=%LOOKUP('ABC':ARY) - C EVAL FND=%FOUND - C FND DSPLY - C* Lookup expression not found - C EVAL RESULT=%LOOKUP('FOO':ARY) - C EVAL FND=%FOUND - C FND DSPLY C SETON RT \ No newline at end of file