From 31d0d8a1a3b28d49212d4d81e6a3d477c78aee35 Mon Sep 17 00:00:00 2001 From: domenico Date: Tue, 20 Aug 2024 11:20:11 +0200 Subject: [PATCH 1/5] Add test case --- .../rpgparser/smeup/MULANGT02ConstAndDSpecTest.kt | 10 ++++++++++ .../src/test/resources/smeup/MUDRNRAPU00249.rpgle | 11 +++++++++++ 2 files changed, 21 insertions(+) create mode 100644 rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00249.rpgle diff --git a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT02ConstAndDSpecTest.kt b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT02ConstAndDSpecTest.kt index c4d85edd7..39fde48ae 100644 --- a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT02ConstAndDSpecTest.kt +++ b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT02ConstAndDSpecTest.kt @@ -574,4 +574,14 @@ open class MULANGT02ConstAndDSpecTest : MULANGTTest() { val expected = listOf("ok") assertEquals(expected, "smeup/MUDRNRAPU00247".outputOf(configuration = smeupConfig)) } + + /** + * Array declaration inside a DS with an empty INZ keyword + * @see #LS24003783 + */ + @Test + fun executeMUDRNRAPU00249() { + val expected = listOf("ok") + assertEquals(expected, "smeup/MUDRNRAPU00249".outputOf(configuration = smeupConfig)) + } } \ No newline at end of file diff --git a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00249.rpgle b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00249.rpgle new file mode 100644 index 000000000..e82fac636 --- /dev/null +++ b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00249.rpgle @@ -0,0 +1,11 @@ + * Helper declarations + D £DBG_Str S 2 + + * Declaring an array field (£6I) in a data structure with an empty INZ keyword. + * Should not be assigned to a numeric + D £C6MIM DS + D £6I 20P 6 DIM(99) INZ Importi + + * Test output + C EVAL £DBG_Str='ok' + C £DBG_Str DSPLY From ced9a17aaac8f889b580cc0eacaacc5979f3eeeb Mon Sep 17 00:00:00 2001 From: domenico Date: Tue, 20 Aug 2024 11:21:10 +0200 Subject: [PATCH 2/5] Fix initializationValue for arrays --- .../parsetreetoast/data_definitions.kt | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/data_definitions.kt b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/data_definitions.kt index 909135787..f3f9d008a 100644 --- a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/data_definitions.kt +++ b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/data_definitions.kt @@ -872,26 +872,9 @@ private fun RpgParser.Parm_fixedContext.toFieldInfo(conf: ToAstConfiguration = T } var initializationValue: Expression? = null + val arraySizeDeclared = this.arraySizeDeclared(conf) val hasInitValue = this.keyword().find { it.keyword_inz() != null } - if (hasInitValue != null) { - if (hasInitValue.keyword_inz().simpleExpression() != null) { - initializationValue = hasInitValue.keyword_inz().simpleExpression()?.toAst(conf) as Expression - } else { - // TODO handle initializations for any other variables type (es. 'Z' for timestamp) - initializationValue = if (null != this.toTypeInfo().decimalPositions) { - RealLiteral(BigDecimal.ZERO, position = toPosition()) - } else { - StringLiteral("", position = toPosition()) - } - } - } else { - this.toDSFieldInitKeyword(conf = conf)?.apply { - initializationValue = this.toAst() - } - } - // compileTimeInterpreter.evaluate(this.rContext(), dim!!).asInt().value.toInt(), - val arraySizeDeclared = this.arraySizeDeclared(conf) val varName = like?.variable?.name ?: this.name val explicitElementType: Type? = this.calculateExplicitElementType(arraySizeDeclared, conf) ?: knownDataDefinitions.firstOrNull { it.name.equals(varName, ignoreCase = true) }?.type @@ -903,6 +886,23 @@ private fun RpgParser.Parm_fixedContext.toFieldInfo(conf: ToAstConfiguration = T ).evaluateTypeOf(this.rContext(), it, conf) } + if (hasInitValue != null) { + initializationValue = if (hasInitValue.keyword_inz().simpleExpression() != null) { + hasInitValue.keyword_inz().simpleExpression()?.toAst(conf) as Expression + } else { + // TODO handle initializations for any other variables type (es. 'Z' for timestamp) + when { + arraySizeDeclared != null -> null + this.toTypeInfo().decimalPositions != null -> RealLiteral(BigDecimal.ZERO, position = toPosition()) + else -> StringLiteral("", position = toPosition()) + } + } + } else { + this.toDSFieldInitKeyword(conf = conf)?.apply { + initializationValue = this.toAst() + } + } + return FieldInfo(this.name, overlayInfo = overlayInfo, explicitStartOffset = this.explicitStartOffset(), explicitEndOffset = if (explicitStartOffset() != null) this.explicitEndOffset() else null, From 68d714fdedfa6dc02f7158c69f0ae4959b4222f9 Mon Sep 17 00:00:00 2001 From: domenico Date: Tue, 20 Aug 2024 11:21:22 +0200 Subject: [PATCH 3/5] Remove unreachable code --- .../src/main/kotlin/com/smeup/rpgparser/interpreter/coercing.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/coercing.kt b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/coercing.kt index e646472ec..2bf572a32 100644 --- a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/coercing.kt +++ b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/coercing.kt @@ -243,7 +243,6 @@ fun coerce(value: Value, type: Type): Value { } else { return DecimalValue(value.value.setScale(type.decimalDigits)) } - return value } else -> TODO("Converting DecimalValue to $type") } From 18213b2ba5c2c3b7cb134f4f266e115e53ffd895 Mon Sep 17 00:00:00 2001 From: domenico Date: Fri, 23 Aug 2024 12:43:31 +0200 Subject: [PATCH 4/5] Improve test case with value check --- .../com/smeup/rpgparser/smeup/MULANGT02ConstAndDSpecTest.kt | 2 +- .../src/test/resources/smeup/MUDRNRAPU00249.rpgle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT02ConstAndDSpecTest.kt b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT02ConstAndDSpecTest.kt index 39fde48ae..06a792d77 100644 --- a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT02ConstAndDSpecTest.kt +++ b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT02ConstAndDSpecTest.kt @@ -581,7 +581,7 @@ open class MULANGT02ConstAndDSpecTest : MULANGTTest() { */ @Test fun executeMUDRNRAPU00249() { - val expected = listOf("ok") + val expected = listOf(List(99) { "0" }.toString()) assertEquals(expected, "smeup/MUDRNRAPU00249".outputOf(configuration = smeupConfig)) } } \ No newline at end of file diff --git a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00249.rpgle b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00249.rpgle index e82fac636..872329ae1 100644 --- a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00249.rpgle +++ b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00249.rpgle @@ -8,4 +8,4 @@ * Test output C EVAL £DBG_Str='ok' - C £DBG_Str DSPLY + C £6I DSPLY From 7c285f90a72abc9ee01cc109fb24281d7c80ee2a Mon Sep 17 00:00:00 2001 From: domenico Date: Fri, 23 Aug 2024 12:49:43 +0200 Subject: [PATCH 5/5] Cleanup test case --- .../src/test/resources/smeup/MUDRNRAPU00249.rpgle | 4 ---- 1 file changed, 4 deletions(-) diff --git a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00249.rpgle b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00249.rpgle index 872329ae1..7733f128f 100644 --- a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00249.rpgle +++ b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00249.rpgle @@ -1,11 +1,7 @@ - * Helper declarations - D £DBG_Str S 2 - * Declaring an array field (£6I) in a data structure with an empty INZ keyword. * Should not be assigned to a numeric D £C6MIM DS D £6I 20P 6 DIM(99) INZ Importi * Test output - C EVAL £DBG_Str='ok' C £6I DSPLY