Skip to content

Commit

Permalink
Merge pull request #597 from smeup/bugfix/LS24003783/array-in-ds-inz
Browse files Browse the repository at this point in the history
Bugfix/ls24003783/array in ds inz
  • Loading branch information
lanarimarco authored Aug 26, 2024
2 parents cd4adce + 6702a45 commit edd4de4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,4 +572,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(List(99) { "0" }.toString())
assertEquals(expected, "smeup/MUDRNRAPU00249".outputOf(configuration = smeupConfig))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
* 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 £6I DSPLY

0 comments on commit edd4de4

Please sign in to comment.