Skip to content

Commit

Permalink
Merge pull request #639 from smeup/bugfix/LS24004491/dim-on-constant
Browse files Browse the repository at this point in the history
Bugfix/ls24004491/dim on constant
  • Loading branch information
lanarimarco authored Oct 17, 2024
2 parents 0cbb848 + 03d059f commit b92140e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,12 @@ private fun List<StatementContext?>.getDataDefinition(
}
}

// Move the D specs with like because depending on other D specs definitions
val sortedStatements = this.filterNotNull().moveLikeStatementToTheEnd(conf = conf)
/**
* Statements sorting to accommodate processing needs
* Step 1: Move the D specs with like because depending on other D specs definitions
* Step 2: Move statements marked as CONST to the start because they might be used as a dependency
*/
val sortedStatements = this.filterNotNull().moveLikeStatementToTheEnd(conf = conf).moveConstantsToStart()

// First pass ignore exception and all the know definitions
val firstPassProviders = sortedStatements.mapNotNull {
Expand Down Expand Up @@ -183,6 +187,19 @@ private fun List<StatementContext>.moveLikeStatementToTheEnd(conf: ToAstConfigur
return otherStatements + likeStatements
}

private fun List<StatementContext>.moveConstantsToStart(): List<StatementContext> {
val constantStatements = this.filter { it.isConstant() }
val otherStatements = this.filter { !it.isConstant() }

return constantStatements + otherStatements
}

private fun StatementContext.isConstant() = when {
this.dcl_c() != null -> this.dcl_c().keyword_const() != null
this.dspec() != null -> this.dspec().keyword().any { keyword -> keyword.keyword_const() != null }
else -> false
}

private fun DataDefinition.updateKnownDataDefinitionsAndGetHolder(
knownDataDefinitions: MutableMap<String, DataDefinition>
): DataDefinitionHolder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,16 @@ open class MULANGT02ConstAndDSpecTest : MULANGTTest() {
assertEquals(expected, "smeup/MUDRNRAPU00264".outputOf(configuration = smeupConfig))
}

/**
* Declaration with DIM based on a constant whose definition is not known yet
* @see #LS24004491
*/
@Test
fun executeMUDRNRAPU00267() {
val expected = listOf("ok")
assertEquals(expected, "smeup/MUDRNRAPU00267".outputOf(configuration = smeupConfig))
}

/**
* Allows for the correct handling of composed (nested) statements during execution, ensuring that `TagStmts`
* can be found even within complex structures.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
* Test declarations
D DS
D £RITEL 1 15

* Declaration with DIM based on a constant whose definition is not known yet
D CDOR S 2 DIM(Q£DOC)
D Q£DOC C CONST(500)

* Values setup
C Z-ADD 1 J 4 0
C EVAL £RITEL = 'ok'

* Assign value to the definition being tested
C MOVEL £RITEL CDOR(J)

* Test output
C CDOR(J) DSPLY

0 comments on commit b92140e

Please sign in to comment.