Skip to content

Commit

Permalink
Merge branch 'develop' into bugfix/LS24004104/error-movel-for-input-s…
Browse files Browse the repository at this point in the history
…tring
  • Loading branch information
lanarimarco authored Sep 24, 2024
2 parents e8a0cff + af9c863 commit 968242b
Show file tree
Hide file tree
Showing 14 changed files with 262 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ fun coerce(value: Value, type: Type): Value {
when (type) {
is StringType -> StringValue(value.value.toString(), varying = type.varying)
is DateType -> DateValue(value.value, type.format)
is ArrayType -> {
val coercedValue = coerce(value, type.element)
ConcreteArrayValue(MutableList(type.nElements) { coercedValue }, type.element)
}
else -> value
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,26 @@ open class InternalInterpreter(
var startOffset = data.startOffset
val size = data.endOffset - data.startOffset

// for (i in 1..data.declaredArrayInLine!!) {
// If the size of the arrays are different
val maxElements = min(value.asArray().arrayLength(), data.declaredArrayInLine!!)
for (i in 1..maxElements) {
fun assignValueToArray(value: Value, data: FieldDefinition) {
// Added coerce
val valueToAssign = coerce(value.asArray().getElement(i), data.type.asArray().element)
val valueToAssign = coerce(value, data.type.asArray().element)
dataStructValue.setSubstring(
startOffset, startOffset + size,
data.type.asArray().element.toDataStructureValue(valueToAssign)
)
startOffset += data.stepSize
}

if (value is ArrayValue) {
// If the size of the arrays are different
for (i in 1..min(value.asArray().arrayLength(), data.declaredArrayInLine!!)) {
assignValueToArray(value.asArray().getElement(i), data)
}
} else {
for (i in 1..data.declaredArrayInLine!!) {
assignValueToArray(value, data)
}
}
} else {
when (val containerValue = get(ds.name)) {
is ArrayValue -> {
Expand Down
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 @@ -33,6 +33,8 @@ val ELSE_PATTERN = Regex(""".{6}/ELSE\s*$""", RegexOption.IGNORE_CASE)
val ENDIF_PATTERN = Regex(""".{6}/ENDIF\s*$""", RegexOption.IGNORE_CASE)
val EOF_PATTERN = Regex(""".{6}/EOF\s*$""", RegexOption.IGNORE_CASE)

private const val SIX_COLUMNS_PADDING = " "

/**
* Resolve the EOF directive: after this directive, all rows are ignored until the end of the file
* and marked in the result string as comments.
Expand Down Expand Up @@ -220,14 +222,12 @@ internal fun String.resolveCompilerDirectives(): String {
}

private fun String.transformToComment(): String {
val newString: String
if (this.length >= 7) {
newString = this.substring(0, 6) + '*' + this.substring(7)
} else {
val padding = " "
newString = this + padding.substring(0, 7 - this.length) + '*'
// We expect to output [6 characters][*][remaining comment]
return when {
this.isBlank() -> "$SIX_COLUMNS_PADDING*"
this.length >= 7 -> "${this.substring(0, 6)}*${this.substring(7)}"
else -> "${this.padEnd(6, ' ')}*"
}
return newString
}

private fun containDirectives(inputString: String): Boolean {
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 @@ -2,6 +2,7 @@ package com.smeup.rpgparser.compilerDirectives

import com.smeup.rpgparser.AbstractTest
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertFails

class CompilerDirectivesTest : AbstractTest() {
Expand Down Expand Up @@ -32,4 +33,14 @@ class CompilerDirectivesTest : AbstractTest() {
"compilerDirectives/ERROR04".outputOf()
}.printStackTrace()
}

/**
* Duplicate definition in two different copies
* @see #LS24004074
*/
@Test
fun executeDUPDEF() {
val expected = listOf("ok")
assertEquals(expected, "compilerDirectives/DUPDEF".outputOf())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,40 @@ open class MULANGT10BaseCodopTest : MULANGTTest() {
val expected = listOf("*IN36: 0;*IN36: 0;*IN36: 1;*IN36: 0;*IN36: 1;*IN36: 0;*IN36: 0.")
assertEquals(expected, "smeup/MU101019".outputOf())
}

/**
* Z-ADD to a DS field defined as array and overlay.
* @see #LS24004081
*/
@Test
fun executeMUDRNRAPU00115() {
val expected = listOf("99.000000", ".000000")
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
*/
@Test
fun executeMUDRNRAPU00120() {
val expected = listOf("99.000000", ".000000")
assertEquals(expected, "smeup/MUDRNRAPU00120".outputOf(configuration = smeupConfig))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
* Helper declarations
D £DBG_Str S 2

* Copies containing a duplicate DEFINE
/COPY DUPDEF1
/COPY DUPDEF2

* Test output
C EVAL £DBG_Str='ok'
C £DBG_Str DSPLY
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/IF NOT DEFINED(DUPLICATE_DEF_INCLUDED)
/DEFINE DUPLICATE_DEF_INCLUDED
C SR1 BEGSR
C ENDSR

C SR2 BEGSR
C ENDSR
/ENDIF
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/IF NOT DEFINED(DUPLICATE_DEF_INCLUDED)
/DEFINE DUPLICATE_DEF_INCLUDED
C SR1 BEGSR
C ENDSR

C SR2 BEGSR
C ENDSR
/ENDIF
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
V* ==============================================================
V* 17/09/2024 APU001 Creation
V* ==============================================================
O * PROGRAM GOAL
O * Assignment, with Z-ADD, a value to a DS field defined as
O * array and overlay.
V* ==============================================================
O * JARIKO ANOMALY
O * Before the fix, the error occurred was
O * Issue executing ZAddStmt at line xyz. null..
V* ==============================================================
D MSG S 30
D COUNT S 3 0 INZ(1)
D SUM S 12 6 INZ(0)

D D5COSO E DS EXTNAME(D5COSO0F)
D D50 DIM(99) LIKE(D$C001) INZ
D OVERLAY(D5COSO:88)

C Z-ADD 1 D50 #Issue executing ZAddStmt at line 20
C EXSR SHOW_RES
C Z-ADD 0 D50
C EXSR SHOW_RES

C SETON LR



C SHOW_RES BEGSR

C EVAL SUM=0
C EVAL COUNT=1
C 100 DOUEQ COUNT
C EVAL SUM+=D50(COUNT)
C EVAL COUNT+=1
C ENDDO
C EVAL MSG=%CHAR(SUM)
C MSG DSPLY

C ENDSR
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,36 @@
V* ==============================================================
V* 19/09/2024 APU001 Creation
V* ==============================================================
O * PROGRAM GOAL
O * Assignment, with Z-ADD, a value to a S field defined
O * as array.
V* ==============================================================
D MSG S 30
D COUNT S 3 0 INZ(1)
D SUM S 12 6 INZ(0)


D D50 S 5 0 DIM(99) INZ

C Z-ADD 1 D50
C EXSR SHOW_RES

C EVAL SUM=0
C EVAL COUNT=1
C Z-ADD 0 D50
C EXSR SHOW_RES

C SETON LR



C SHOW_RES BEGSR

C 100 DOUEQ COUNT
C EVAL SUM+=D50(COUNT)
C EVAL COUNT+=1
C ENDDO
C EVAL MSG=%CHAR(SUM)
C MSG DSPLY

C ENDSR

0 comments on commit 968242b

Please sign in to comment.