Skip to content

Commit

Permalink
Merge pull request #554 from smeup/bugfix/LS24003137/caller-group-def…
Browse files Browse the repository at this point in the history
…ault

Bugfix/ls24003137/caller group default
  • Loading branch information
lanarimarco authored Jul 1, 2024
2 parents 0a73821 + c6cb177 commit 4abb66b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,14 @@ fun CompilationUnit.activationGroupType(): ActivationGroupType? {
}
}

fun ActivationGroupType.assignedName(current: RpgProgram, caller: RpgProgram?): String {
fun ActivationGroupType.assignedName(caller: RpgProgram?): String {
return when (this) {
is CallerActivationGroup -> {
require(caller != null) { "caller is mandatory" }
caller.activationGroup.assignedName
}
is NewActivationGroup -> UUID.randomUUID().toString()
is NamedActivationGroup -> groupName
else -> error("$this ActivationGroupType is not yet handled")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,21 @@ class RpgProgram(val cu: CompilationUnit, val name: String = "<UNNAMED RPG PROGR
} else {
null
}
val activationGroupType = cu.activationGroupType() ?: when (caller) {

// for main program, which does not have a caller, activation group is fixed by config
null -> NamedActivationGroup(MainExecutionContext.getConfiguration().defaultActivationGroupName)
else -> {
CallerActivationGroup
}
val activationGroupType = cu.activationGroupType()?.let {
when {
// When there is no caller use the default activation group
it is CallerActivationGroup && caller == null ->
NamedActivationGroup(MainExecutionContext.getConfiguration().defaultActivationGroupName)
else -> it
}
activationGroupType.let {
activationGroup = ActivationGroup(it, it.assignedName(this, caller))
} ?: when (caller) {
// for main program, which does not have a caller, activation group is fixed by config
null -> NamedActivationGroup(MainExecutionContext.getConfiguration().defaultActivationGroupName)
else -> CallerActivationGroup
}

activationGroup = ActivationGroup(activationGroupType, activationGroupType.assignedName(caller))
}
MainExecutionContext.getProgramStack().push(this)
MainExecutionContext.getConfiguration().jarikoCallback.onEnterPgm(name, interpreter.getGlobalSymbolTable())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ open class ActivationGroupTest : AbstractTest() {
commandLineProgram.singleCall(emptyList(), conf)
}

/**
* Assigned activation group name should be the default from configuration
* */
@Test
fun testUnspecifiedCaller() {
val pgm = " H ACTGRP(*CALLER)\n" +
" C SETON RT"

val conf = Configuration(
jarikoCallback = JarikoCallback(
getActivationGroup = {
_: String, associatedActivationGroup: ActivationGroup? ->
println("associatedActivationGroupName: ${associatedActivationGroup?.assignedName}")
assertEquals(Configuration().defaultActivationGroupName, associatedActivationGroup?.assignedName)
assertEquals(DEFAULT_ACTIVATION_GROUP_NAME, associatedActivationGroup?.assignedName)
null
}
)
)
conf.adaptForTestCase(this)
val commandLineProgram = getProgram(pgm)
commandLineProgram.singleCall(emptyList(), conf)
}

/**
* Assigned activation group name should be from declaration
* */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,14 @@ open class MULANGT02ConstAndDSpecTest : MULANGTTest() {
val expected = listOf("ok")
assertEquals(expected, "smeup/MUDRNRAPU00219".outputOf(configuration = smeupConfig))
}

/**
* Caller activation group with no actual caller
* @see #LS24003137
*/
@Test
fun executeMUDRNRAPU00221() {
val expected = listOf("ok")
assertEquals(expected, "smeup/MUDRNRAPU00221".outputOf(configuration = smeupConfig))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
D £DBG_Str S 2
H DECEDIT(*JOBRUN) DATEDIT(*DMY/) DFTACTGRP(*NO) ACTGRP(*CALLER)
H OPTION(*NODEBUGIO:*SRCSTMT:*NOUNREF) CCSID(*CHAR : *JOBRUN) DEBUG(*INPUT)
C EVAL £DBG_Str='ok'
C £DBG_Str DSPLY

0 comments on commit 4abb66b

Please sign in to comment.