Skip to content

Commit 0a73821

Browse files
authored
Merge pull request #552 from smeup/feature/LS24003047/pointer-variables
Feature/ls24003047/pointer variables
2 parents 0d69f8e + f230f9b commit 0a73821

File tree

11 files changed

+48
-12
lines changed

11 files changed

+48
-12
lines changed

rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/Evaluator.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,6 @@ interface Evaluator {
9595
fun eval(expression: ParmsExpr): Value
9696
fun eval(expression: OpenExpr): Value
9797
fun eval(expression: SizeExpr): Value
98+
fun eval(expression: NullValExpr): Value
9899
fun eval(expression: MockExpression): Value
99100
}

rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/ExpressionEvaluation.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,8 @@ class ExpressionEvaluation(
823823
}
824824
}
825825

826+
override fun eval(expression: NullValExpr): Value = proxyLogging(expression) { NullValue }
827+
826828
override fun eval(expression: MockExpression): Value {
827829
MainExecutionContext.getConfiguration().jarikoCallback.onMockExpression(expression)
828830
return NullValue

rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/typesystem.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,24 @@ data class NumberType(val entireDigits: Int, val decimalDigits: Int, val rpgType
218218
constructor(entireDigits: Int, decimalDigits: Int, rpgType: RpgType) : this(entireDigits, decimalDigits, rpgType.rpgType)
219219

220220
init {
221-
if (rpgType == RpgType.INTEGER.rpgType || rpgType == RpgType.UNSIGNED.rpgType) {
222-
require(entireDigits <= 20) { "Integer or Unsigned integer can have only length up to 20. Value specified: $this" }
223-
require(decimalDigits == 0)
221+
if (rpgType == RpgType.INTEGER.rpgType || rpgType == RpgType.UNSIGNED.rpgType || rpgType == RpgType.POINTER.rpgType) {
222+
require(entireDigits <= MAX_INTEGER_DIGITS) {
223+
"Integer or Unsigned integer can have only length up to 20. Value specified: $this"
224+
}
225+
require(decimalDigits == INTEGER_DECIMAL_DIGITS)
224226
}
225227
}
226228

229+
companion object {
230+
const val MAX_INTEGER_DIGITS = 20
231+
const val INTEGER_DECIMAL_DIGITS = 0
232+
}
233+
227234
override val size: Int
228235
get() {
229236
return when (rpgType) {
230237
RpgType.PACKED.rpgType -> ceil((numberOfDigits + 1).toDouble() / 2.toFloat()).toInt()
231-
RpgType.INTEGER.rpgType, RpgType.UNSIGNED.rpgType -> {
238+
RpgType.INTEGER.rpgType, RpgType.UNSIGNED.rpgType, RpgType.POINTER.rpgType -> {
232239
when (entireDigits) {
233240
in 1..3 -> 1
234241
in 4..5 -> 2
@@ -249,7 +256,7 @@ data class NumberType(val entireDigits: Int, val decimalDigits: Int, val rpgType
249256
}
250257

251258
val integer: Boolean
252-
get() = decimalDigits == 0
259+
get() = decimalDigits == INTEGER_DECIMAL_DIGITS
253260
val decimal: Boolean
254261
get() = !integer
255262
val numberOfDigits: Int

rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/ast/expressions.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ data class JulFormatExpr(override val position: Position? = null) : FigurativeCo
148148
override fun evalWith(evaluator: Evaluator): Value = evaluator.eval(this)
149149
}
150150

151+
@Serializable
152+
data class NullValExpr(override val position: Position? = null) : FigurativeConstantRef(position) {
153+
override fun evalWith(evaluator: Evaluator): Value = evaluator.eval(this)
154+
}
155+
151156
// /
152157
// / Comparisons
153158
// /

rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/ast/serialization.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ private val modules = SerializersModule {
165165
subclass(MinusExpr::class)
166166
subclass(MultExpr::class)
167167
subclass(NotExpr::class)
168+
subclass(NullValExpr::class)
168169
subclass(NumberOfElementsExpr::class)
169170
subclass(OnRefExpr::class)
170171
subclass(OffRefExpr::class)

rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/data_definitions.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ enum class RpgType(val rpgType: String) {
3737
INTEGER("I"),
3838
UNSIGNED("U"),
3939
BINARY("B"),
40-
UNLIMITED_STRING("0")
40+
UNLIMITED_STRING("0"),
41+
POINTER("*")
4142
}
4243

4344
/**
@@ -446,6 +447,9 @@ internal fun RpgParser.DspecContext.toAst(
446447
RpgType.UNLIMITED_STRING.rpgType -> {
447448
UnlimitedStringType
448449
}
450+
RpgType.POINTER.rpgType -> {
451+
NumberType(NumberType.MAX_INTEGER_DIGITS, NumberType.INTEGER_DECIMAL_DIGITS, RpgType.POINTER.rpgType)
452+
}
449453
else -> todo("Unknown type: <${this.DATA_TYPE().text}>", conf)
450454
}
451455

rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/expressions.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ internal fun RpgParser.IdentifierContext.toAst(conf: ToAstConfiguration = ToAstC
158158
"*OFF" -> OffRefExpr(toPosition(conf.considerPosition))
159159
"*ISO" -> IsoFormatExpr(toPosition(conf.considerPosition))
160160
"*JUL" -> JulFormatExpr(toPosition(conf.considerPosition))
161+
"*NULL" -> NullValExpr(toPosition(conf.considerPosition))
161162
else -> variableExpression(conf)
162163
}
163164
}

rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT02ConstAndDSpecTest.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,4 +342,14 @@ open class MULANGT02ConstAndDSpecTest : MULANGTTest() {
342342
val expected = listOf("ok")
343343
assertEquals(expected, "smeup/MUDRNRAPU00218".outputOf(configuration = smeupConfig))
344344
}
345+
346+
/**
347+
* Reassign value to pointer variable
348+
* @see #LS24003047
349+
*/
350+
@Test
351+
fun executeMUDRNRAPU00219() {
352+
val expected = listOf("ok")
353+
assertEquals(expected, "smeup/MUDRNRAPU00219".outputOf(configuration = smeupConfig))
354+
}
345355
}

rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT50FileAccess1Test.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ open class MULANGT50FileAccess1Test : MULANGTTest() {
4040
* @see #LS24002987
4141
*/
4242
@Test
43-
fun executeMUDRNRAPU00219() {
43+
fun executeMUDRNRAPU00220() {
4444
val expected = listOf("ok")
45-
assertEquals(expected, "smeup/MUDRNRAPU00219".outputOf(configuration = smeupConfig))
45+
assertEquals(expected, "smeup/MUDRNRAPU00220".outputOf(configuration = smeupConfig))
4646
}
4747
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
D £DBG_Str S 2
2-
D STR132 S 132
3-
FPRT132 O F 132 PRINTER OFLIND(*INOG) USROPN
4-
OPRT132 E RIGA 1
5-
O STR132
2+
D SRIG_PTR S * Inz(*Null)
3+
C EVAL SRIG_PTR = *NULL
64
C EVAL £DBG_Str='ok'
75
C £DBG_Str DSPLY

0 commit comments

Comments
 (0)