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

Feature/ls24003257/data struct inz hival #561

Merged
merged 11 commits into from
Jul 11, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -275,31 +275,29 @@ fun coerce(value: Value, type: Type): Value {
}

fun Type.lowValue(): Value {
when (this) {
is NumberType -> {
return computeLowValue(this)
}
is StringType -> {
return computeLowValue(this)
}
is ArrayType -> {
return createArrayValue(this.element, this.nElements) { coerce(LowValValue, this.element) }
return when (this) {
is NumberType -> computeLowValue(this)
is StringType -> computeLowValue(this)
is ArrayType -> createArrayValue(this.element, this.nElements) { coerce(LowValValue, this.element) }
is DataStructureType -> {
val fields = this.fields.associateWith { field -> field.type.lowValue() }
DataStructValue.fromFields(fields)
}
is RecordFormatType -> BlanksValue
else -> TODO("Converting LowValValue to $this")
}
}

fun Type.hiValue(): Value {
when (this) {
is NumberType -> {
return computeHiValue(this)
}
is StringType -> {
return computeHiValue(this)
}
is ArrayType -> {
return createArrayValue(this.element, this.nElements) { coerce(HiValValue, this.element) }
return when (this) {
is NumberType -> computeHiValue(this)
is StringType -> computeHiValue(this)
is ArrayType -> createArrayValue(this.element, this.nElements) { coerce(HiValValue, this.element) }
is DataStructureType -> {
val fields = this.fields.associateWith { field -> field.type.hiValue() }
DataStructValue.fromFields(fields)
}
is RecordFormatType -> BlanksValue
else -> TODO("Converting HiValValue to $this")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@ fun Type.toDataStructureValue(value: Value): StringValue {
return StringValue("1")
return StringValue("0")
}
is DataStructureType -> {
return when (value) {
is DataStructValue -> value.asString()
else -> TODO("Not implemented")
}
}
is RecordFormatType -> return StringValue.blank(this.size)
else -> TODO("Conversion to data struct value not implemented for $this")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,14 @@ data class DataStructValue(var value: String, private val optionalExternalLen: I
}
return newInstance
}

fun fromFields(fields: Map<FieldType, Value>): DataStructValue {
lanarimarco marked this conversation as resolved.
Show resolved Hide resolved
val size = fields.entries.fold(0) { acc, entry -> acc + entry.key.type.size }
val newInstance = blank(size)
val fieldDefinitions = fields.map { it.key }.toFieldDefinitions()
fields.onEachIndexed { index, entry -> newInstance.set(fieldDefinitions[index], entry.value) }
return newInstance
}
}

override fun toString(): String {
Expand Down Expand Up @@ -1196,4 +1204,20 @@ data class OccurableDataStructValue(val occurs: Int) : Value {
this.values.putAll(values.mapValues { it.value.copy() })
}
}
}

fun List<FieldType>.toFieldDefinitions(): List<FieldDefinition> {
lanarimarco marked this conversation as resolved.
Show resolved Hide resolved
var start = 0
val definitions = this.map {
val newOffset = start + it.type.size
val fieldDef = FieldDefinition(
name = it.name,
type = it.type,
calculatedStartOffset = start,
calculatedEndOffset = start + newOffset
)
start = newOffset
fieldDef
}
return definitions
}
Original file line number Diff line number Diff line change
Expand Up @@ -402,4 +402,14 @@ open class MULANGT02ConstAndDSpecTest : MULANGTTest() {
val expected = listOf("ok")
assertEquals(expected, "smeup/MUDRNRAPU00225".outputOf(configuration = smeupConfig))
}

/**
* Comptime DS with EXTNAME resolution and data structures INZ(*HIVAL)
* @see #LS24003257
*/
@Test
fun executeMUDRNRAPU00226() {
val expected = listOf("ok")
assertEquals(expected, "smeup/MUDRNRAPU00226".outputOf(configuration = smeupConfig))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
D £DBG_Str S 2
D B£SLOT E DS EXTNAME(B£SLOT0F) INZ

D CSDS DS
D CSNR 5S 0

D CSLOTS S LIKE(B£SLOT) DIM(200) INZ(*HIVAL)
D CSLOTADS DS

D CSLOTA LIKE(CSDS) INZ(*HIVAL)
D DIM(%ELEM(CSLOTS)) ASCEND

C EVAL £DBG_Str='ok'
C £DBG_Str DSPLY