Skip to content

Commit

Permalink
Merge branch 'develop' into bugfix/LS24003783/array-in-ds-inz
Browse files Browse the repository at this point in the history
  • Loading branch information
dom-apuliasoft committed Aug 23, 2024
2 parents 7c285f9 + cd4adce commit 6702a45
Show file tree
Hide file tree
Showing 20 changed files with 591 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@ fun Expression.createKList(fileMetadata: FileMetadata, interpreter: InterpreterC
return if (type() is KListType) {
interpreter.toSearchValues(this, fileMetadata)
} else {
val value = interpreter.eval(this)
listOf(value.asString(fileMetadata.accessFieldsType[0]))
when (val value = interpreter.eval(this)) {
is StartValValue, is EndValValue -> throw NotImplementedError("$value constant not yet supported.")
else -> listOf(value.asString(fileMetadata.accessFieldsType.first()))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ interface Evaluator {
fun eval(expression: ArrayAccessExpr): Value
fun eval(expression: HiValExpr): HiValValue
fun eval(expression: LowValExpr): LowValValue
fun eval(expression: StartValExpr): StartValValue
fun eval(expression: EndValExpr): EndValValue
fun eval(expression: ZeroExpr): ZeroValue
fun eval(expression: AllExpr): AllValue
fun eval(expression: TranslateExpr): Value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ class ExpressionEvaluation(

override fun eval(expression: HiValExpr) = proxyLogging(expression) { HiValValue } as HiValValue
override fun eval(expression: LowValExpr) = proxyLogging(expression) { LowValValue } as LowValValue
override fun eval(expression: StartValExpr) = proxyLogging(expression) { StartValValue } as StartValValue
override fun eval(expression: EndValExpr) = proxyLogging(expression) { EndValValue } as EndValValue
override fun eval(expression: ZeroExpr) = proxyLogging(expression) { ZeroValue } as ZeroValue
override fun eval(expression: AllExpr) = proxyLogging(expression) {
AllValue(eval(expression.charsToRepeat).asString().value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,24 @@ object LowValType : Type() {
override fun isNumeric() = true
}

@Serializable
object StartValType : Type() {
override val size: Int
get() = throw IllegalStateException("Has variable size")

override fun hasVariableSize() = true
override fun isNumeric() = false
}

@Serializable
object EndValType : Type() {
override val size: Int
get() = throw IllegalStateException("Has variable size")

override fun hasVariableSize() = true
override fun isNumeric() = false
}

@Serializable
object TimeStampType : Type() {
override val size: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,12 @@ data class StringValue(var value: String, var varying: Boolean = false) : Abstra

override fun asTimeStamp(): TimeStampValue = TimeStampValue.of(value)

fun setSubstring(startOffset: Int, endOffset: Int, substringValue: StringValue) {
fun setSubstring(startOffset: Int, endOffset: Int) {
require(startOffset >= 0)
require(startOffset <= value.length)
require(endOffset >= startOffset)
require(endOffset <= value.length) { "Asked startOffset=$startOffset, endOffset=$endOffset on string of length ${value.length}" }
substringValue.pad(endOffset - startOffset)
value = value.substring(0, startOffset) + substringValue.value + value.substring(endOffset)
value = value.substring(startOffset, endOffset)
}

fun getSubstring(startOffset: Int, endOffset: Int): StringValue {
Expand Down Expand Up @@ -633,26 +632,32 @@ data class ConcreteArrayValue(val elements: MutableList<Value>, override val ele
override fun setElement(index: Int, value: Value) {
require(index >= 1)
require(index <= arrayLength())
if (!value.assignableTo(elementType)) {
println("boom")
}
require(value.assignableTo(elementType)) {
"Cannot assign ${value::class.qualifiedName} to ${elementType::class.qualifiedName}"
}
if (elementType is StringType && !elementType.varying) {
val v = when (value) {
is AbstractStringValue -> {
(value as StringValue).copy()
when (elementType) {
is StringType -> {
val v = when (value) {
is AbstractStringValue -> {
(value as StringValue).copy()
}
is DataStructValue -> {
value.asString().copy()
}
else -> TODO("Not yet implemented")
}
is DataStructValue -> {
value.asString().copy()

/*
* Setting the value based of varying flag and length of target.
*/
if (!elementType.varying && v.length() < elementType.length) {
v.pad(elementType.length)
} else if (v.length() > elementType.length) {
v.setSubstring(0, elementType.length)
}
else -> TODO("Not yet implemented")
elements[index - 1] = v
}
v.pad(elementType.length)
elements[index - 1] = v
} else {
elements[index - 1] = value
else -> elements[index - 1] = value
}
}

Expand Down Expand Up @@ -766,6 +771,32 @@ object LowValValue : Value {
}
}

object StartValValue : Value {
override fun toString() = "StartValValue"

// FIXME
override fun assignableTo(expectedType: Type) = true
override fun copy(): StartValValue = this

override operator fun compareTo(other: Value): Int =
if (other is StartValValue) 0 else -1

override fun asString() = "*START".asValue()
}

object EndValValue : Value {
override fun toString() = "EndValValue"

// FIXME
override fun assignableTo(expectedType: Type) = true
override fun copy(): EndValValue = this

override operator fun compareTo(other: Value): Int =
if (other is EndValValue) 0 else 1

override fun asString() = "*END".asValue()
}

object ZeroValue : Value {

override fun copy() = this
Expand Down Expand Up @@ -949,7 +980,7 @@ fun Type.blank(): Value {
is KListType -> throw UnsupportedOperationException("Blank value not supported for KList")
is CharacterType -> CharacterValue(Array(this.nChars) { ' ' })
is FigurativeType -> BlanksValue
is LowValType, is HiValType -> TODO()
is LowValType, is HiValType, is StartValType, is EndValType -> TODO()
is UnlimitedStringType -> UnlimitedStringValue("")
is RecordFormatType -> BlanksValue
}
Expand All @@ -971,7 +1002,7 @@ data class DataStructValue(var value: String, private val optionalExternalLen: I
// Check if the size of the value matches the expected size within the DS
// TO REVIEW
is DataStructureType -> true
is StringType -> expectedType.size >= this.value.length
is StringType -> true
else -> false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ data class LowValExpr(override val position: Position? = null) : FigurativeConst
override fun evalWith(evaluator: Evaluator): Value = evaluator.eval(this)
}

@Serializable
data class StartValExpr(override val position: Position? = null) : FigurativeConstantRef(position) {
override fun evalWith(evaluator: Evaluator): Value = evaluator.eval(this)
}

@Serializable
data class EndValExpr(override val position: Position? = null) : FigurativeConstantRef(position) {
override fun evalWith(evaluator: Evaluator): Value = evaluator.eval(this)
}

@Serializable
data class ZeroExpr(override val position: Position? = null) : FigurativeConstantRef(position) {
override fun evalWith(evaluator: Evaluator): Value = evaluator.eval(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

package com.smeup.rpgparser.parsing.ast

import com.smeup.rpgparser.interpreter.AbstractDataDefinition
import com.smeup.rpgparser.interpreter.DataDefinition
import com.smeup.rpgparser.interpreter.FieldDefinition
import com.smeup.rpgparser.interpreter.InStatementDataDefinition
import com.smeup.rpgparser.interpreter.*
import com.smeup.rpgparser.parsing.parsetreetoast.LogicalCondition
import com.smeup.rpgparser.serialization.BigDecimalSerializer
import com.smeup.rpgparser.serialization.LocalDateTimeSerializer
Expand Down Expand Up @@ -142,6 +139,7 @@ private val modules = SerializersModule {
subclass(NegationExpr::class)
subclass(EditcExpr::class)
subclass(EditwExpr::class)
subclass(EndValExpr::class)
subclass(EofExpr::class)
subclass(EqualExpr::class)
subclass(EqualityExpr::class)
Expand Down Expand Up @@ -186,6 +184,7 @@ private val modules = SerializersModule {
subclass(ReplaceExpr::class)
subclass(ScanExpr::class)
subclass(SqrtExpr::class)
subclass(StartValExpr::class)
subclass(StringLiteral::class)
subclass(SubstExpr::class)
subclass(SubarrExpr::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,8 @@ internal fun SymbolicConstantsContext.toAst(conf: ToAstConfiguration = ToAstConf
return when {
this.SPLAT_HIVAL() != null -> HiValExpr(position)
this.SPLAT_LOVAL() != null -> LowValExpr(position)
this.SPLAT_START() != null -> StartValExpr(position)
this.SPLAT_END() != null -> EndValExpr(position)
this.SPLAT_BLANKS() != null -> BlanksRefExpr(position)
this.SPLAT_ZEROS() != null -> ZeroExpr(position)
this.SPLAT_OFF() != null -> OffRefExpr(position)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.smeup.rpgparser.parsing.facade.SourceReference
import com.smeup.rpgparser.parsing.facade.SourceReferenceType
import com.smeup.rpgparser.parsing.parsetreetoast.ToAstConfiguration
import com.smeup.rpgparser.rpginterop.DirRpgProgramFinder
import com.smeup.rpgparser.smeup.dbmock.TABDS01LDbMock
import com.smeup.rpgparser.utils.Format
import com.smeup.rpgparser.utils.compile
import org.junit.Assert
Expand Down Expand Up @@ -660,6 +661,31 @@ class JarikoCallbackTest : AbstractTest() {
executeSourceLineTest(pgm = "ERROR35")
}

/**
* NOTE: This is error is thrown because Reload does not support '*START' and '*END' constants yet.
* When this feature gets supported please restore it on Jariko side by following these steps:
* - Remove this test or mark it as ignored
* - Remove the [@Ignore] decorator from the [MULANGT50FileAccess1Test.executeMUDRNRAPU00248] test
* - Remove the runtime error (it should be in [Expression.createKList] if not moved)
*/
@Test
fun executeERROR36CallBackTest() {
TABDS01LDbMock().usePopulated {
executePgmCallBackTest(
pgm = "ERROR36",
sourceReferenceType = SourceReferenceType.Program,
sourceId = "ERROR36",
lines = listOf(6),
reloadConfig = it.createReloadConfig()
)
}
}

@Test
fun executeERROR36SourceLineTest() {
executeSourceLineTest(pgm = "ERROR36")
}

@Test
fun bypassSyntaxErrorTest() {
val configuration = Configuration().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ open class MULANGT02ConstAndDSpecTest : MULANGTTest() {
*/
@Test
fun executeMUDRNRAPU00101() {
MULANGTLDbMock().use {
com.smeup.rpgparser.db.utilities.execute(listOf(it.createTable(), it.populateTable()))
MULANGTLDbMock().usePopulated {
val expected = listOf("HELLO THERE")
assertEquals(
expected = expected,
Expand Down Expand Up @@ -267,8 +266,7 @@ open class MULANGT02ConstAndDSpecTest : MULANGTTest() {

@Test
fun executeMUDRNRAPU00202() {
MULANGTLDbMock().use {
com.smeup.rpgparser.db.utilities.execute(listOf(it.createTable(), it.populateTable()))
MULANGTLDbMock().usePopulated {
val expected = listOf("ok")
assertEquals(expected, "smeup/MUDRNRAPU00202".outputOf(configuration = smeupConfig))
}
Expand Down Expand Up @@ -584,4 +582,4 @@ open class MULANGT02ConstAndDSpecTest : MULANGTTest() {
val expected = listOf(List(99) { "0" }.toString())
assertEquals(expected, "smeup/MUDRNRAPU00249".outputOf(configuration = smeupConfig))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ open class MULANGT04EssentialsCodopAndBifTest : MULANGTTest() {
}

/**
*Assigns content of DS to a String VARYING in EVAL
*Assigns content of DS to a String VARYING in EVAL
* @see #LS24003679
*/
@Test
Expand All @@ -54,6 +54,26 @@ open class MULANGT04EssentialsCodopAndBifTest : MULANGTTest() {
assertEquals(expected, "smeup/MU044014".outputOf())
}

/**
*Assigns content of DS to a String not VARYING in EVAL where, size of DS is greater than String
* @see #LS24003755
*/
@Test
fun executeMUDRNRAPU00106() {
val expected = listOf("Lorem ipsum dolor sit amet, consectetuer adipiscin")
assertEquals(expected, "smeup/MUDRNRAPU00106".outputOf())
}

/**
*Assigns content of DS to a String not VARYING in EVAL where, size of DS is greater than String
* @see #LS24003755
*/
@Test
fun executeMUDRNRAPU00107() {
val expected = listOf("Lorem ipsum dolor sit amet, consectetuer adipiscin")
assertEquals(expected, "smeup/MUDRNRAPU00107".outputOf())
}

/**
* %DIFF with several DurationCodes
* @see #LS24003282
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.smeup.rpgparser.smeup
import com.smeup.rpgparser.db.utilities.DBServer
import org.junit.Test
import kotlin.test.BeforeTest
import kotlin.test.Ignore
import kotlin.test.assertEquals

open class MULANGT50FileAccess1Test : MULANGTTest() {
Expand Down Expand Up @@ -56,4 +57,14 @@ open class MULANGT50FileAccess1Test : MULANGTTest() {
mockSmeupConfig.dspfConfig = null
assertEquals(expected, "smeup/MUDRNRAPU00220".outputOf(configuration = mockSmeupConfig))
}
}

/**
* SetLL with '*START' and '*END' symbolic constants
* @see #LS24003777
*/
@Test @Ignore
fun executeMUDRNRAPU00248() {
val expected = listOf("ok")
assertEquals(expected, "smeup/MUDRNRAPU00248".outputOf(configuration = smeupConfig))
}
}
Loading

0 comments on commit 6702a45

Please sign in to comment.