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

Bugfix/LS24004086/MOVEA from Array field to Standalone #614

Merged
merged 16 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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 @@ -925,9 +925,7 @@ class ProjectedArrayValue(
}
}

override fun elementSize(): Int {
TODO("not implemented") // To change body of created functions use File | Settings | File Templates.
}
override fun elementSize(): Int = elementType.size

override fun arrayLength() = arrayLength

Expand Down Expand Up @@ -965,6 +963,18 @@ class ProjectedArrayValue(
override fun asString(): StringValue {
TODO("Not yet implemented")
}

fun takeAll(): Value {
var result = elements()[0]
for (i in 1 until arrayLength()) {
result = result.concatenate(elements()[i])
}
return result
}

override fun takeLast(n: Int): Value = takeAll().takeLast(n)

override fun takeFirst(n: Int): Value = takeAll().takeFirst(n)
}

fun createArrayValue(elementType: Type, n: Int, creator: (Int) -> Value) = ConcreteArrayValue(Array(n, creator).toMutableList(), elementType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,10 @@ internal fun RpgParser.Dcl_dsContext.calculateFieldInfos(
val caughtErrors = mutableListOf<Throwable>()
val fieldsList = FieldsList(fieldsExtname + this.parm_fixed().mapNotNull {
kotlin.runCatching {
it.toFieldInfo(knownDataDefinitions = knownDataDefinitions)
it.toFieldInfo(
knownDataDefinitions = knownDataDefinitions,
fieldsExtname = fieldsExtname
)
}.onFailure {
caughtErrors.add(it)
}.getOrNull()
Expand All @@ -854,7 +857,11 @@ internal fun RpgParser.Dcl_dsContext.calculateFieldInfos(
return fieldsList
}

private fun RpgParser.Parm_fixedContext.toFieldInfo(conf: ToAstConfiguration = ToAstConfiguration(), knownDataDefinitions: Collection<DataDefinition>): FieldInfo {
private fun RpgParser.Parm_fixedContext.toFieldInfo(
conf: ToAstConfiguration = ToAstConfiguration(),
knownDataDefinitions: Collection<DataDefinition>,
fieldsExtname: List<FieldInfo>? = emptyList()
): FieldInfo {
var overlayInfo: FieldInfo.OverlayInfo? = null
val overlay = this.keyword().find { it.keyword_overlay() != null }
val like = this.keyword()
Expand Down Expand Up @@ -882,6 +889,7 @@ private fun RpgParser.Parm_fixedContext.toFieldInfo(conf: ToAstConfiguration = T
val explicitElementType: Type? = this.calculateExplicitElementType(arraySizeDeclared, conf)
?: knownDataDefinitions.firstOrNull { it.name.equals(varName, ignoreCase = true) }?.type
?: knownDataDefinitions.flatMap { it.fields }.firstOrNull { fe -> fe.name.equals(varName, ignoreCase = true) }?.type
?: fieldsExtname?.firstOrNull { it.name.equals(varName, ignoreCase = true) }?.elementType
?: like?.let {
InjectableCompileTimeInterpreter(
knownDataDefinitions = knownDataDefinitions.toList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private fun List<StatementContext?>.getDataDefinition(

fileDefinitions?.let {
val postProcessedFileDefinitions = it.processWithSpecifications(inputSpecifications)
postProcessedFileDefinitions.values.flatten().removeDuplicatedDataDefinition().forEach { def ->
postProcessedFileDefinitions.filter { !it.key.justExtName }.values.flatten().removeDuplicatedDataDefinition().forEach { def ->
dataDefinitionProviders.add(def.updateKnownDataDefinitionsAndGetHolder(knownDataDefinitions))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,22 @@ open class MULANGT10BaseCodopTest : MULANGTTest() {
assertEquals(expected, "smeup/MUDRNRAPU00115".outputOf(configuration = smeupConfig))
}

/**
* Assignment of an array, defined as field of DS, to a Standalone variable with MOVEA.
* @see #LS24004086
*/
@Test
fun executeMUDRNRAPU00116() {
val expected = listOf(
"AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH", "II", "LL",
"AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH", "II", "LL",
"AABBCCDDEEFFGGHHIILL",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", ""
)
assertEquals(expected, "smeup/MUDRNRAPU00116".outputOf(configuration = smeupConfig))
}

/**
* Z-ADD to a Standalone defined as array.
* @see #LS24004081
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
V* ==============================================================
V* 18/09/2024 APU001 Creation
V* ==============================================================
O * PROGRAM GOAL
O * Assignment of an array, defined as field of DS,
O * to a Standalone variable with MOVEA.
V* ==============================================================
O * JARIKO ANOMALY
O * Before the fix, the error occurred was
O * Issue executing MoveAStmt at line 32. An operation
O * is not implemented: takeFirst not yet implemented
O * for ProjectedArrayValue.
V* ==============================================================
D MSG S 30
D COUNT S 2 0 INZ(1)
D AU1_SIZE S 2 0 INZ(10)

D AUTOAP E DS EXTNAME(AUTOAP0F)
D AU1 61 80 DIM(10)
D £AUATI S 20

C EVAL AU1(1)='AA'
C EVAL AU1(2)='BB'
C EVAL AU1(3)='CC'
C EVAL AU1(4)='DD'
C EVAL AU1(5)='EE'
C EVAL AU1(6)='FF'
C EVAL AU1(7)='GG'
C EVAL AU1(8)='HH'
C EVAL AU1(9)='II'
C EVAL AU1(10)='LL'
C MOVEA AU1 £AUATI #An operation is not implemented: takeFirst not yet implemented for ProjectedArrayValue

C EXSR SHOW_RES

C CLEAR £AUATI
C MOVEL *BLANKS AU1
C MOVEA AU1 £AUATI

C EXSR SHOW_RES

C SETON LR



C SHOW_RES BEGSR
*
C EVAL COUNT=1
C AU1_SIZE DOULT COUNT
C AU1(COUNT) DSPLY
C EVAL COUNT+=1
C ENDDO
C AA£O01 DSPLY
C AA£O02 DSPLY
C AA£O03 DSPLY
C AA£O04 DSPLY
C AA£O05 DSPLY
C AA£O06 DSPLY
C AA£O07 DSPLY
C AA£O08 DSPLY
C AA£O09 DSPLY
C AA£O10 DSPLY
C £AUATI DSPLY
*
C ENDSR
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
V* ==============================================================
V* 19/09/2024 APU001 Creation
V* ==============================================================
O * PROGRAM GOAL
O * Assignment of scalar to a Standalone variable,
O * defined as decimal array, with MOVEA.
O * The left value number of digits is lower than right
O * decimal digits.
V* ==============================================================
D MSG S 30
D COUNT S 3 0 INZ(1)

D A146 S 14 6 DIM(9) INZ

C EXSR SHOR_RES
C MOVEA 123 A146
C EXSR SHOR_RES

C SETON LR



C SHOR_RES BEGSR

C EVAL COUNT=1
C 10 DOUEQ COUNT
C EVAL MSG=%CHAR(A146(COUNT))
C MSG DSPLY
C EVAL COUNT+=1
C ENDDO

C ENDSR
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
V* ==============================================================
V* 19/09/2024 APU001 Creation
V* ==============================================================
O * PROGRAM GOAL
O * Assignment of scalar to a Standalone variable,
O * defined as decimal array, with MOVEA.
O * The left value number of digits is greater than right
O * decimal digits.
V* ==============================================================
D MSG S 30
D COUNT S 3 0 INZ(1)

D A142 S 14 2 DIM(9) INZ

C EXSR SHOR_RES
C MOVEA 12345 A142
C EXSR SHOR_RES

C SETON LR



C SHOR_RES BEGSR

C EVAL COUNT=1
C 10 DOUEQ COUNT
C EVAL MSG=%CHAR(A142(COUNT))
C MSG DSPLY
C EVAL COUNT+=1
C ENDDO

C ENDSR
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
V* ==============================================================
V* 19/09/2024 APU001 Creation
V* ==============================================================
O * PROGRAM GOAL
O * Assignment of scalar to a Standalone variable,
O * defined as integer array, with MOVEA.
V* ==============================================================
D MSG S 30
D COUNT S 3 0 INZ(1)

D A140 S 14 0 DIM(9) INZ

C EXSR SHOR_RES
C MOVEA 123 A140
C EXSR SHOR_RES

C SETON LR



C SHOR_RES BEGSR

C EVAL COUNT=1
C 10 DOUEQ COUNT
C EVAL MSG=%CHAR(A140(COUNT))
C MSG DSPLY
C EVAL COUNT+=1
C ENDDO

C ENDSR