Skip to content

Commit

Permalink
Merge pull request #552 from smeup/feature/LS24003047/pointer-variables
Browse files Browse the repository at this point in the history
Feature/ls24003047/pointer variables
  • Loading branch information
lanarimarco authored Jun 25, 2024
2 parents 0d69f8e + f230f9b commit 0a73821
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,6 @@ interface Evaluator {
fun eval(expression: ParmsExpr): Value
fun eval(expression: OpenExpr): Value
fun eval(expression: SizeExpr): Value
fun eval(expression: NullValExpr): Value
fun eval(expression: MockExpression): Value
}
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,8 @@ class ExpressionEvaluation(
}
}

override fun eval(expression: NullValExpr): Value = proxyLogging(expression) { NullValue }

override fun eval(expression: MockExpression): Value {
MainExecutionContext.getConfiguration().jarikoCallback.onMockExpression(expression)
return NullValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,24 @@ data class NumberType(val entireDigits: Int, val decimalDigits: Int, val rpgType
constructor(entireDigits: Int, decimalDigits: Int, rpgType: RpgType) : this(entireDigits, decimalDigits, rpgType.rpgType)

init {
if (rpgType == RpgType.INTEGER.rpgType || rpgType == RpgType.UNSIGNED.rpgType) {
require(entireDigits <= 20) { "Integer or Unsigned integer can have only length up to 20. Value specified: $this" }
require(decimalDigits == 0)
if (rpgType == RpgType.INTEGER.rpgType || rpgType == RpgType.UNSIGNED.rpgType || rpgType == RpgType.POINTER.rpgType) {
require(entireDigits <= MAX_INTEGER_DIGITS) {
"Integer or Unsigned integer can have only length up to 20. Value specified: $this"
}
require(decimalDigits == INTEGER_DECIMAL_DIGITS)
}
}

companion object {
const val MAX_INTEGER_DIGITS = 20
const val INTEGER_DECIMAL_DIGITS = 0
}

override val size: Int
get() {
return when (rpgType) {
RpgType.PACKED.rpgType -> ceil((numberOfDigits + 1).toDouble() / 2.toFloat()).toInt()
RpgType.INTEGER.rpgType, RpgType.UNSIGNED.rpgType -> {
RpgType.INTEGER.rpgType, RpgType.UNSIGNED.rpgType, RpgType.POINTER.rpgType -> {
when (entireDigits) {
in 1..3 -> 1
in 4..5 -> 2
Expand All @@ -249,7 +256,7 @@ data class NumberType(val entireDigits: Int, val decimalDigits: Int, val rpgType
}

val integer: Boolean
get() = decimalDigits == 0
get() = decimalDigits == INTEGER_DECIMAL_DIGITS
val decimal: Boolean
get() = !integer
val numberOfDigits: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ data class JulFormatExpr(override val position: Position? = null) : FigurativeCo
override fun evalWith(evaluator: Evaluator): Value = evaluator.eval(this)
}

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

// /
// / Comparisons
// /
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ private val modules = SerializersModule {
subclass(MinusExpr::class)
subclass(MultExpr::class)
subclass(NotExpr::class)
subclass(NullValExpr::class)
subclass(NumberOfElementsExpr::class)
subclass(OnRefExpr::class)
subclass(OffRefExpr::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ enum class RpgType(val rpgType: String) {
INTEGER("I"),
UNSIGNED("U"),
BINARY("B"),
UNLIMITED_STRING("0")
UNLIMITED_STRING("0"),
POINTER("*")
}

/**
Expand Down Expand Up @@ -446,6 +447,9 @@ internal fun RpgParser.DspecContext.toAst(
RpgType.UNLIMITED_STRING.rpgType -> {
UnlimitedStringType
}
RpgType.POINTER.rpgType -> {
NumberType(NumberType.MAX_INTEGER_DIGITS, NumberType.INTEGER_DECIMAL_DIGITS, RpgType.POINTER.rpgType)
}
else -> todo("Unknown type: <${this.DATA_TYPE().text}>", conf)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ internal fun RpgParser.IdentifierContext.toAst(conf: ToAstConfiguration = ToAstC
"*OFF" -> OffRefExpr(toPosition(conf.considerPosition))
"*ISO" -> IsoFormatExpr(toPosition(conf.considerPosition))
"*JUL" -> JulFormatExpr(toPosition(conf.considerPosition))
"*NULL" -> NullValExpr(toPosition(conf.considerPosition))
else -> variableExpression(conf)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,14 @@ open class MULANGT02ConstAndDSpecTest : MULANGTTest() {
val expected = listOf("ok")
assertEquals(expected, "smeup/MUDRNRAPU00218".outputOf(configuration = smeupConfig))
}

/**
* Reassign value to pointer variable
* @see #LS24003047
*/
@Test
fun executeMUDRNRAPU00219() {
val expected = listOf("ok")
assertEquals(expected, "smeup/MUDRNRAPU00219".outputOf(configuration = smeupConfig))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ open class MULANGT50FileAccess1Test : MULANGTTest() {
* @see #LS24002987
*/
@Test
fun executeMUDRNRAPU00219() {
fun executeMUDRNRAPU00220() {
val expected = listOf("ok")
assertEquals(expected, "smeup/MUDRNRAPU00219".outputOf(configuration = smeupConfig))
assertEquals(expected, "smeup/MUDRNRAPU00220".outputOf(configuration = smeupConfig))
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
D £DBG_Str S 2
D STR132 S 132
FPRT132 O F 132 PRINTER OFLIND(*INOG) USROPN
OPRT132 E RIGA 1
O STR132
D SRIG_PTR S * Inz(*Null)
C EVAL SRIG_PTR = *NULL
C EVAL £DBG_Str='ok'
C £DBG_Str DSPLY
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
D £DBG_Str S 2
D STR132 S 132
FPRT132 O F 132 PRINTER OFLIND(*INOG) USROPN
OPRT132 E RIGA 1
O STR132
C EVAL £DBG_Str='ok'
C £DBG_Str DSPLY

0 comments on commit 0a73821

Please sign in to comment.