Skip to content

Commit 91c69bd

Browse files
authored
Merge pull request #606 from smeup/feature/LS24003953/parm-factor1
Feature/ls24003953/parm factor1
2 parents 597d0da + f814ee8 commit 91c69bd

File tree

10 files changed

+115
-6
lines changed

10 files changed

+115
-6
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ class ExpressionEvaluation(
212212
StringValue(s)
213213
}
214214
}
215+
left is StringValue && right is BooleanValue -> {
216+
val s = left.trimEndIfVarying() + right.asString().value
217+
s.asValue()
218+
}
215219
else -> {
216220
throw UnsupportedOperationException("I do not know how to sum $left and $right at ${expression.position}")
217221
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ data class StringValue(var value: String, var varying: Boolean = false) : Abstra
215215
else -> super.compareTo(other)
216216
}
217217

218+
internal fun trimEndIfVarying() = if (varying) value.trimEnd() else value
219+
218220
override fun getWrappedString() = value
219221
}
220222

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,11 @@ data class CallStmt(
793793
}
794794
paramValuesAtTheEnd?.forEachIndexed { index, value ->
795795
if (this.params.size > index) {
796-
interpreter.assign(this.params[index].param.referred!!, value)
796+
val currentParam = this.params[index]
797+
interpreter.assign(currentParam.param.referred!!, value)
798+
799+
// If we also have a result field, assign to it
800+
currentParam.result?.let { interpreter.assign(it, value) }
797801
}
798802
}
799803
}
@@ -1107,6 +1111,7 @@ data class PlistStmt(
11071111

11081112
@Serializable
11091113
data class PlistParam(
1114+
val result: AssignableExpression?,
11101115
val param: ReferenceByName<AbstractDataDefinition>,
11111116
// TODO @Derived????
11121117
@Derived val dataDefinition: InStatementDataDefinition? = null,

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,20 +1186,22 @@ internal fun CsPARMContext.toAst(conf: ToAstConfiguration = ToAstConfiguration()
11861186
if (paramName.contains(".")) {
11871187
val parts = paramName.split(".")
11881188
require(parts.isNotEmpty())
1189-
if (parts.size == 1) {
1190-
paramName = parts[0]
1191-
} else {
1192-
paramName = parts.last()
1193-
}
1189+
paramName = parts.last()
11941190
}
11951191
// initialization value valid only if there isn't a variable declaration
11961192
val initializationValue = if (this.cspec_fixed_standard_parts().len.asInt() == null) {
11971193
this.cspec_fixed_standard_parts().factor2Expression(conf)
11981194
} else {
11991195
null
12001196
}
1197+
1198+
val factor1Text = this.factor1.text.trim()
1199+
val factor1Position = this.factor1.toPosition(conf.considerPosition)
1200+
val result = if (factor1Text.isNotEmpty()) annidatedReferenceExpression(factor1Text, factor1Position) else null
1201+
12011202
val position = toPosition(conf.considerPosition)
12021203
return PlistParam(
1204+
result,
12031205
ReferenceByName(paramName),
12041206
this.cspec_fixed_standard_parts().toDataDefinition(
12051207
paramName,

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,4 +2459,16 @@ Test 6
24592459
val expected = listOf("ok")
24602460
assertEquals(expected, "EXCPCALLER".outputOf())
24612461
}
2462+
2463+
@Test
2464+
fun executePRSLTCALLER() {
2465+
val expected = listOf("(1,1)", "(0,0)", "(1,1,0,0,0)")
2466+
assertEquals(expected, "PRSLTCALLER".outputOf())
2467+
}
2468+
2469+
@Test
2470+
fun executePRSLTCALLERDUPLICATE() {
2471+
val expected = listOf("0", "0", "0", "1")
2472+
assertEquals(expected, "PRSLTCALLERDUPLICATE".outputOf())
2473+
}
24622474
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
* Called by PRSLTCALLER.rpgle
2+
* Takes $A as parameter and updates it's value
3+
C *ENTRY PLIST
4+
C PARM $A 1
5+
C PARM $B 1
6+
C PARM $C 1
7+
C EVAL $A = *ON
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
* Called by PRSLTCALLERDUPLICATE.rpgle
2+
C *ENTRY PLIST
3+
C PARM $A 1
4+
C PARM $B 1
5+
C PARM $C 1
6+
C EVAL $A = *ON
7+
C EVAL $B = *OFF
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
* Called by PRSLTCALLERDUPLICATE.rpgle
2+
C *ENTRY PLIST
3+
C PARM $A 1
4+
C PARM $B 1
5+
C PARM $C 1
6+
C EVAL $A = *ON
7+
C EVAL $B = *OFF
8+
C EVAL $A = *ON
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
* Helper declarations
2+
D £DBG_Str S 512
3+
4+
* Call PRSLTCALLEE passing parameter $A bound with *IN35 and $B bound with *IN36
5+
* If $A or $B get updated by PRSLTCALLEE, the new value must be
6+
* bound to the factor 1 of the param (*IN35 or *IN36)
7+
C CALL 'PRSLTCALLEE'
8+
C *IN35 PARM *OFF $A 1 Should be updated
9+
C *IN36 PARM *OFF $B 1 Should not be updated
10+
C PARM *OFF $C 1 Should have no influence
11+
12+
* Updated value output
13+
C EVAL £DBG_Str = '('+$A+','+*IN35+')'
14+
C £DBG_Str DSPLY
15+
* Not updated value output
16+
C EVAL £DBG_Str = '('+$B+','+*IN36+')'
17+
C £DBG_Str DSPLY
18+
* No influence output
19+
C EVAL £DBG_Str = '('+$A+','+*IN35+','+$B+','+
20+
C *IN36+','+$C+')'
21+
C £DBG_Str DSPLY
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
* Helper declarations
2+
D £DBG_Str S 512
3+
4+
* A variant of PRSLTCALLER binding the same identifier (*IN35) to parameters $A and $B
5+
* Assignment should happen sequentially from first to last on call exit
6+
7+
* Only update $A
8+
C CALL 'PRSLTCALLEE'
9+
C *IN35 PARM *OFF $A 1 Should be updated
10+
C *IN35 PARM *OFF $B 1 Should not be updated
11+
C PARM *OFF $C 1 Should have no influence
12+
13+
* $A is the last value updated output
14+
C *IN35 DSPLY
15+
16+
* Update $A then $B
17+
C CALL 'PRSLTCALLEE2'
18+
C *IN35 PARM *OFF $A 1 Should be updated
19+
C *IN35 PARM *OFF $B 1 Should be updated
20+
C PARM *OFF $C 1 Should have no influence
21+
22+
* $B is the last value updated output
23+
C *IN35 DSPLY
24+
25+
* Update $A then $B then $A again
26+
C CALL 'PRSLTCALLEE3'
27+
C *IN35 PARM *OFF $A 1 Should be updated
28+
C *IN35 PARM *OFF $B 1 Should be updated
29+
C PARM *OFF $C 1 Should have no influence
30+
31+
* Mixed update test
32+
C *IN35 DSPLY
33+
34+
* Update $A then $B then $A again without duplicate binding
35+
C CALL 'PRSLTCALLEE3'
36+
C *IN35 PARM *OFF $A 1 Should be updated
37+
C PARM *OFF $B 1 Should be updated
38+
C PARM *OFF $C 1 Should have no influence
39+
40+
* Mixed update test
41+
C *IN35 DSPLY

0 commit comments

Comments
 (0)