Skip to content

Commit

Permalink
Fixed SCAN when is passed a literal as Factor 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidepalladino-apuliasoft committed Feb 1, 2024
1 parent 029b96e commit 5f4f2de
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,7 @@ data class ScanStmt(
} while (index >= 0)
if (occurrences.isEmpty()) {
interpreter.setIndicators(this, BooleanValue.FALSE, BooleanValue.FALSE, BooleanValue.FALSE)
interpreter.assign(target, IntValue(0))
} else {
interpreter.setIndicators(this, BooleanValue.FALSE, BooleanValue.FALSE, BooleanValue.TRUE)
if (target.type().isArray()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,8 @@ private fun FactorContext.toIndexedExpression(conf: ToAstConfiguration): Pair<Ex
if (this.text.contains(":")) this.text.toIndexedExpression(toPosition(conf.considerPosition)) else this.content.toAst(conf) to null

private fun String.toIndexedExpression(position: Position?): Pair<Expression, Int?> {
fun String.isLiteral(): Boolean { return (startsWith('\'') && endsWith('\'')) }

val baseStringTokens = this.split(":")
val startPosition =
when (baseStringTokens.size) {
Expand All @@ -1334,7 +1336,10 @@ private fun String.toIndexedExpression(position: Position?): Pair<Expression, In
else -> null
}
val reference = baseStringTokens[0]
return DataRefExpr(ReferenceByName(reference), position) to startPosition
return when {
reference.isLiteral() -> StringLiteral(reference.trim('\''), position)
else -> DataRefExpr(ReferenceByName(reference), position)
} to startPosition
}

internal fun CsMOVEAContext.toAst(conf: ToAstConfiguration = ToAstConfiguration()): MoveAStmt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,14 @@ open class SmeupInterpreterTest : AbstractTest() {
val expected = listOf("1020")
assertEquals(expected, "smeup/T10_A20_P19".outputOf())
}

@Test
fun executeT15_A20_P04_06() {
val expected = listOf(
"RicercaDaPos01(1)_Trovato(1); RicercaDaPos02(5)_Trovato(1); RicercaDaPos05(5)_Trovato(1); RicercaDaPos07(0)_Trovato(0);",
"RicercaDaPos01(5)_Trovato(1); RicercaDaPos01(1)_Trovato(1); RicercaDaPos01(5)_Trovato(1);",
"RicercaDaPos01(2)_Trovato(1);"
)
assertEquals(expected, "smeup/T15_A20_P04-06".outputOf())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
D A20_A20A S 20 INZ('!ABC!ABCDEF')
D A20_N20R S 2 0
D £DBG_Str S 100 VARYING

C SETOFF 202122
C '!':1 SCAN A20_A20A A20_N20R 20
C EVAL £DBG_Str='RicercaDaPos01('
C +%CHAR(A20_N20R)
C +')_Trovato('+%CHAR(*IN20)+');'
C '!':1 SCAN A20_A20A:2 A20_N20R 21
C EVAL £DBG_Str=%TRIM(£DBG_Str)
C +' RicercaDaPos02('+%CHAR(A20_N20R)
C +')_Trovato('+%CHAR(*IN21)+');'
C '!':1 SCAN A20_A20A:5 A20_N20R 22
C EVAL £DBG_Str=%TRIM(£DBG_Str)
C +' RicercaDaPos05('+%CHAR(A20_N20R)
C +')_Trovato('+%CHAR(*IN22)+');'
C SETOFF 20
C '!':1 SCAN A20_A20A:7 A20_N20R 20
C EVAL £DBG_Str=%TRIM(£DBG_Str)
C +' RicercaDaPos07('+%CHAR(A20_N20R)
C +')_Trovato('+%CHAR(*IN20)+');'
C £DBG_Str DSPLY

C SETOFF 202122
C '!ABCD' SCAN A20_A20A A20_N20R 20
C EVAL £DBG_Str='RicercaDaPos01('
C +%CHAR(A20_N20R)
C +')_Trovato('+%CHAR(*IN20)+');'
C '!ABCD':2 SCAN A20_A20A A20_N20R 21
C EVAL £DBG_Str=%TRIM(£DBG_Str)
C +' RicercaDaPos01('+%CHAR(A20_N20R)
C +')_Trovato('+%CHAR(*IN21)+');'
C '!ABCD':5 SCAN A20_A20A A20_N20R 22
C EVAL £DBG_Str=%TRIM(£DBG_Str)
C +' RicercaDaPos01('+%CHAR(A20_N20R)
C +')_Trovato('+%CHAR(*IN22)+');'
C £DBG_Str DSPLY


C SETOFF 20
C '!':1 SCAN '?!/' NW20_N20 2 0 20
C EVAL £DBG_Str='RicercaDaPos01('
C +%CHAR(NW20_N20)
C +')_Trovato('+%CHAR(*IN20)+');'
C £DBG_Str DSPLY

0 comments on commit 5f4f2de

Please sign in to comment.