Skip to content

Commit

Permalink
Merge branch 'develop' into feature/LS24003289/bif-dec-with-time
Browse files Browse the repository at this point in the history
  • Loading branch information
dom-apuliasoft committed Jul 11, 2024
2 parents 4894dec + 7156791 commit c57eea2
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 31 deletions.
22 changes: 11 additions & 11 deletions rpgJavaInterpreter-core/src/main/antlr/RpgLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -373,21 +373,21 @@ SPLAT_LOCK: '*'[lL][oO][cC][kK];
SPLAT_PROGRAM: '*'[pP][rR][oO][gG][rR][aA][mM];
SPLAT_EXTDESC: '*'[eE][xX][tT][dD][eE][sS][cC];
//Durations
SPLAT_D: '*'{getLastTokenType() == COLON}? [dD];
SPLAT_H: '*'{getLastTokenType() == COLON}? [hH];
SPLAT_HOURS: '*'{getLastTokenType() == COLON}? [hH][oO][uU][rR][sS];
SPLAT_YEARS: SPLAT_YEAR[sS]{getLastTokenType() == COLON}?;
SPLAT_MONTHS: SPLAT_MONTH[sS];
SPLAT_DAYS: SPLAT_DAY[sS]{getLastTokenType() == COLON}?;
SPLAT_M: '*'{getLastTokenType() == COLON}? [mM];
SPLAT_HOURS: '*'{getLastTokenType() == COLON}? [hH][oO][uU][rR][sS];
SPLAT_MINUTES: '*'{getLastTokenType() == COLON}? [mM][iI][nN][uU][tT][eE][sS];
SPLAT_MONTHS: SPLAT_MONTH[sS];
SPLAT_MN: '*'{getLastTokenType() == COLON}? [mM][nN]; //Minutes
SPLAT_MS: '*'{getLastTokenType() == COLON}? [mM][sS]; //Minutes
SPLAT_MSECONDS: '*'{getLastTokenType() == COLON}? [mM][sS][eE][cC][oO][nN][dD][sS];
SPLAT_S: '*'{getLastTokenType() == COLON}? [sS];
SPLAT_SECONDS: '*'{getLastTokenType() == COLON}? [sS][eE][cC][oO][nN][dD][sS];
SPLAT_Y: '*'{getLastTokenType() == COLON}? [yY];
SPLAT_YEARS: SPLAT_YEAR[sS]{getLastTokenType() == COLON}?;
SPLAT_MSECONDS: '*'{getLastTokenType() == COLON}? [mM][sS][eE][cC][oO][nN][dD][sS];

SPLAT_Y: '*'{getLastTokenType() == COLON}? [yY];
SPLAT_D: '*'{getLastTokenType() == COLON}? [dD];
SPLAT_H: '*'{getLastTokenType() == COLON}? [hH];
SPLAT_MN: '*'{getLastTokenType() == COLON}? [mM][nN]; // Minutes
SPLAT_MS: '*'{getLastTokenType() == COLON}? [mM][sS]; // Microseconds
SPLAT_M: '*'{getLastTokenType() == COLON}? [mM]; // Months
SPLAT_S: '*'{getLastTokenType() == COLON}? [sS];

// Reserved Words
UDATE : [uU] [dD] [aA] [tT] [eE] ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,31 +275,31 @@ fun coerce(value: Value, type: Type): Value {
}

fun Type.lowValue(): Value {
when (this) {
is NumberType -> {
return computeLowValue(this)
}
is StringType -> {
return computeLowValue(this)
}
is ArrayType -> {
return createArrayValue(this.element, this.nElements) { coerce(LowValValue, this.element) }
return when (this) {
is NumberType -> computeLowValue(this)
is StringType -> computeLowValue(this)
is ArrayType -> createArrayValue(this.element, this.nElements) { coerce(LowValValue, this.element) }
is DataStructureType -> {
val fields = this.fields.associateWith { field -> field.type.lowValue() }
DataStructValue.fromFields(fields)
}
is BooleanType -> BooleanValue.FALSE
is RecordFormatType -> BlanksValue
else -> TODO("Converting LowValValue to $this")
}
}

fun Type.hiValue(): Value {
when (this) {
is NumberType -> {
return computeHiValue(this)
}
is StringType -> {
return computeHiValue(this)
}
is ArrayType -> {
return createArrayValue(this.element, this.nElements) { coerce(HiValValue, this.element) }
return when (this) {
is NumberType -> computeHiValue(this)
is StringType -> computeHiValue(this)
is ArrayType -> createArrayValue(this.element, this.nElements) { coerce(HiValValue, this.element) }
is DataStructureType -> {
val fields = this.fields.associateWith { field -> field.type.hiValue() }
DataStructValue.fromFields(fields)
}
is BooleanType -> BooleanValue.TRUE
is RecordFormatType -> BlanksValue
else -> TODO("Converting HiValValue to $this")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ open class BaseCompileTimeInterpreter(
it.dcl_ds() != null -> {
val name = it.dcl_ds().name
val fields = fileDefinitions?.let { defs -> it.dcl_ds().getExtnameFields(defs, conf) } ?: emptyList()
if (name == declName) {
if (name.equals(declName, ignoreCase = true)) {
return it.dcl_ds().elementSizeOf(knownDataDefinitions, fields)
}
}
Expand Down Expand Up @@ -313,7 +313,7 @@ open class BaseCompileTimeInterpreter(
}
is StatementThatCanDefineData -> {
val dataDefinition = ast.dataDefinition()
dataDefinition.firstOrNull { it.name == declName }?.type
dataDefinition.firstOrNull { it.name.equals(declName, ignoreCase = true) }?.type
}
else -> null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@ fun Type.toDataStructureValue(value: Value): StringValue {
return StringValue("1")
return StringValue("0")
}
is DataStructureType -> {
return when (value) {
is DataStructValue -> value.asString()
else -> TODO("Not implemented")
}
}
is RecordFormatType -> return StringValue.blank(this.size)
else -> TODO("Conversion to data struct value not implemented for $this")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,14 @@ data class DataStructValue(var value: String, private val optionalExternalLen: I
}
return newInstance
}

internal fun fromFields(fields: Map<FieldType, Value>): DataStructValue {
val size = fields.entries.fold(0) { acc, entry -> acc + entry.key.type.size }
val newInstance = blank(size)
val fieldDefinitions = fields.map { it.key }.toFieldDefinitions()
fields.onEachIndexed { index, entry -> newInstance.set(fieldDefinitions[index], entry.value) }
return newInstance
}
}

override fun toString(): String {
Expand Down Expand Up @@ -1228,4 +1236,20 @@ data class OccurableDataStructValue(val occurs: Int) : Value {
this.values.putAll(values.mapValues { it.value.copy() })
}
}
}

internal fun List<FieldType>.toFieldDefinitions(): List<FieldDefinition> {
var start = 0
val definitions = this.map {
val newOffset = start + it.type.size
val fieldDef = FieldDefinition(
name = it.name,
type = it.type,
calculatedStartOffset = start,
calculatedEndOffset = start + newOffset
)
start = newOffset
fieldDef
}
return definitions
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,12 @@ internal fun RpgParser.Bif_diffContext.toAst(conf: ToAstConfiguration = ToAstCon
internal fun RpgParser.DurationCodeContext.toAst(conf: ToAstConfiguration = ToAstConfiguration()): DurationCode =
when {
SPLAT_MSECONDS() != null || SPLAT_MS() != null -> DurationInMSecs
SPLAT_SECONDS() != null || SPLAT_S() != null -> DurationInSecs
SPLAT_MINUTES() != null || SPLAT_MN() != null -> DurationInMinutes
SPLAT_HOURS() != null || SPLAT_H() != null -> DurationInHours
SPLAT_DAYS() != null || SPLAT_D() != null -> DurationInDays
SPLAT_MONTHS() != null || SPLAT_M() != null -> DurationInMonths
SPLAT_YEARS() != null || SPLAT_Y() != null -> DurationInYears
else -> todo(conf = conf)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,4 +402,34 @@ open class MULANGT02ConstAndDSpecTest : MULANGTTest() {
val expected = listOf("ok")
assertEquals(expected, "smeup/MUDRNRAPU00225".outputOf(configuration = smeupConfig))
}

/**
* Comptime DS with EXTNAME resolution and data structures INZ(*HIVAL)
* @see #LS24003257
*/
@Test
fun executeMUDRNRAPU00226() {
val expected = listOf("ok")
assertEquals(expected, "smeup/MUDRNRAPU00226".outputOf(configuration = smeupConfig))
}

/**
* Data structures INZ(*HIVAL) values test
* @see #LS24003257
*/
@Test
fun executeMUDRNRAPU00227() {
val expected = listOf("9991\uFFFF\uFFFF99999")
assertEquals(expected, "smeup/MUDRNRAPU00227".outputOf(configuration = smeupConfig))
}

/**
* LIKE on a PList with case in-sensitive lookup
* @see #LS24003296
*/
@Test
fun executeMUDRNRAPU00230() {
val expected = listOf("ok")
assertEquals(expected, "smeup/MUDRNRAPU00230".outputOf(configuration = smeupConfig))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.smeup.rpgparser.smeup
import com.smeup.rpgparser.parsing.parsetreetoast.AstResolutionError
import org.junit.Test
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.temporal.ChronoUnit
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith

Expand Down Expand Up @@ -31,6 +33,36 @@ open class MULANGT04EssentialsCodopAndBifTest : MULANGTTest() {
assertEquals(expected, "smeup/T04_A80_P05".outputOf())
}

/**
* %DIFF with several DurationCodes
* @see #LS24003282
*/
@Test
fun executeMUDRNRAPU00228() {
val referenceDate = TimeStampValue.of("2024-07-10-10.25.27.921456")
val epochDate = TimeStampValue.of("1970-01-01-00.00.00.000000")
val referenceInstant = referenceDate.asTimeStamp().value.atZone(ZoneId.systemDefault()).toInstant()
val epochInstant = epochDate.asTimeStamp().value.atZone(ZoneId.systemDefault()).toInstant()

val mseconds = ChronoUnit.MICROS.between(epochInstant, referenceInstant).toString()
val seconds = ChronoUnit.SECONDS.between(epochInstant, referenceInstant).toString()
val minutes = ChronoUnit.MINUTES.between(epochInstant, referenceInstant).toString()
val hours = ChronoUnit.HOURS.between(epochInstant, referenceInstant).toString()
val days = ChronoUnit.DAYS.between(epochInstant, referenceInstant).toString()
val months = ChronoUnit.MONTHS.between(epochDate.localDate, referenceDate.localDate).toString()
val years = ChronoUnit.YEARS.between(epochDate.localDate, referenceDate.localDate).toString()
val expected = listOf(
mseconds, mseconds,
seconds, seconds,
minutes, minutes,
hours, hours,
days, days,
months, months,
years, years
)
assertEquals(expected, "smeup/MUDRNRAPU00228".outputOf())
}

/**
* %DEC with dates and timestamps
* @see #LS24003289
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
D £DBG_Str S 2
D B£SLOT E DS EXTNAME(B£SLOT0F) INZ

D CSDS DS
D CSNR 5S 0

D CSLOTS S LIKE(B£SLOT) DIM(200) INZ(*HIVAL)
D CSLOTADS DS

D CSLOTA LIKE(CSDS) INZ(*HIVAL)
D DIM(%ELEM(CSLOTS)) ASCEND

C EVAL £DBG_Str='ok'
C £DBG_Str DSPLY
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
D £DBG_Str S 2
D CSDS DS
D NUM 3S 0
D BOOL N 0
D STR LIKE(£DBG_Str)
D NUM2 5S 0

D OUT S LIKE(CSDS) INZ(*HIVAL)
C OUT DSPLY
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
D ut S 30 0
D dt S Z INZ(Z'2024-07-10-10.25.27.921456')
D t S Z INZ(Z'1970-01-01-00.00.00.000000')

C EVAL ut=%diff(dt:t:*mseconds)
C ut DSPLY
C EVAL ut=%diff(dt:t:*ms)
C ut DSPLY
C EVAL ut=%diff(dt:t:*seconds)
C ut DSPLY
C EVAL ut=%diff(dt:t:*s)
C ut DSPLY
C EVAL ut=%diff(dt:t:*minutes)
C ut DSPLY
C EVAL ut=%diff(dt:t:*mn)
C ut DSPLY
C EVAL ut=%diff(dt:t:*hours)
C ut DSPLY
C EVAL ut=%diff(dt:t:*h)
C ut DSPLY
C EVAL ut=%diff(dt:t:*days)
C ut DSPLY
C EVAL ut=%diff(dt:t:*d)
C ut DSPLY
C EVAL ut=%diff(dt:t:*months)
C ut DSPLY
C EVAL ut=%diff(dt:t:*m)
C ut DSPLY
C EVAL ut=%diff(dt:t:*years)
C ut DSPLY
C EVAL ut=%diff(dt:t:*y)
C ut DSPLY
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
D £DBG_Str S 2

D $OavFU S Like(£OavFU)
D $OavME S Like(£OavME)
D §OavFU S Like(£OavFU)
D §OavME S Like(£OavME)

C *ENTRY PLIST
C PARM £OAVFU 10 Funzione
C PARM £OAVME 10 Metodo

C EVAL £DBG_Str='ok'
C £DBG_Str DSPLY

0 comments on commit c57eea2

Please sign in to comment.