Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ls24005102/read indicators #670

Merged
merged 6 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,10 @@ data class MoveLStmt(
abstract class AbstractReadEqualStmt(
@Transient open val searchArg: Expression? = null, // Factor1
@Transient open val name: String = "", // Factor 2
@Transient open val hiIndicator: IndicatorKey? = null, // HI indicator
@Transient open val loIndicator: IndicatorKey? = null, // LO indicator
@Transient open val eqIndicator: IndicatorKey? = null, // EQ indicator
@Transient override val position: Position? = null

) : Statement(position) {
override fun execute(interpreter: InterpreterCore) {
val dbFile = interpreter.dbFile(name, this)
Expand All @@ -491,6 +493,11 @@ abstract class AbstractReadEqualStmt(
null -> read(dbFile)
else -> read(dbFile, kList)
}

hiIndicator?.let { interpreter.getIndicators()[it] = result.indicatorHI.asValue() }
loIndicator?.let { interpreter.getIndicators()[it] = result.indicatorLO.asValue() }
eqIndicator?.let { interpreter.getIndicators()[it] = result.indicatorEQ.asValue() }

interpreter.fillDataFrom(dbFile, result.record)
}

Expand All @@ -500,11 +507,20 @@ abstract class AbstractReadEqualStmt(
@Serializable
abstract class AbstractReadStmt(
@Transient open val name: String = "", // Factor 2
@Transient open val hiIndicator: IndicatorKey? = null, // HI indicator
@Transient open val loIndicator: IndicatorKey? = null, // LO indicator
@Transient open val eqIndicator: IndicatorKey? = null, // EQ indicator
@Transient override val position: Position? = null
) : Statement(position) {
override fun execute(interpreter: InterpreterCore) {
val dbFile = interpreter.dbFile(name, this)
val result = readOp(dbFile)

// TODO: check if HI indicator is actually ever used on READ statements
hiIndicator?.let { interpreter.getIndicators()[it] = result.indicatorHI.asValue() }
loIndicator?.let { interpreter.getIndicators()[it] = result.indicatorLO.asValue() }
eqIndicator?.let { interpreter.getIndicators()[it] = result.indicatorEQ.asValue() }

interpreter.fillDataFrom(dbFile, result.record)
}

Expand Down Expand Up @@ -554,8 +570,16 @@ abstract class AbstractSetStmt(
data class ChainStmt(
override val searchArg: Expression, // Factor1
override val name: String, // Factor 2
override val hiIndicator: IndicatorKey?, // HI indicator
override val loIndicator: IndicatorKey?, // LO indicator
override val position: Position? = null
) : AbstractReadEqualStmt(searchArg, name, position) {
) : AbstractReadEqualStmt(
searchArg = searchArg,
name = name,
hiIndicator = hiIndicator,
loIndicator = loIndicator,
position = position
) {
override val loggableEntityName: String
get() = "CHAIN"

Expand All @@ -566,8 +590,16 @@ data class ChainStmt(
data class ReadEqualStmt(
override val searchArg: Expression?,
override val name: String,
override val loIndicator: IndicatorKey?, // LO indicator
override val eqIndicator: IndicatorKey?, // EQ indicator
override val position: Position? = null
) : AbstractReadEqualStmt(searchArg = searchArg, name = name, position = position) {
) : AbstractReadEqualStmt(
searchArg = searchArg,
name = name,
loIndicator = loIndicator,
eqIndicator = eqIndicator,
position = position
) {
override val loggableEntityName: String
get() = "READE"

Expand All @@ -584,8 +616,16 @@ data class ReadEqualStmt(
data class ReadPreviousEqualStmt(
override val searchArg: Expression?,
override val name: String,
override val loIndicator: IndicatorKey?, // LO indicator
override val eqIndicator: IndicatorKey?, // EQ indicator
override val position: Position? = null
) : AbstractReadEqualStmt(searchArg = searchArg, name = name, position = position) {
) : AbstractReadEqualStmt(
searchArg = searchArg,
name = name,
loIndicator = loIndicator,
eqIndicator = eqIndicator,
position = position
) {
override val loggableEntityName: String
get() = "READPE"

Expand All @@ -599,16 +639,36 @@ data class ReadPreviousEqualStmt(
}

@Serializable
data class ReadStmt(override val name: String, override val position: Position?) : AbstractReadStmt(name, position) {
data class ReadStmt(
override val name: String,
override val loIndicator: IndicatorKey?, // LO indicator
override val eqIndicator: IndicatorKey?, // EQ indicator
override val position: Position?
) : AbstractReadStmt(
name = name,
loIndicator = loIndicator,
eqIndicator = eqIndicator,
position = position
) {
override val loggableEntityName: String
get() = "READ"

override fun readOp(dbFile: DBFile) = dbFile.read()
}

@Serializable
data class ReadPreviousStmt(override val name: String, override val position: Position?) :
AbstractReadStmt(name, position) {
data class ReadPreviousStmt(
override val name: String,
override val loIndicator: IndicatorKey?, // LO indicator
override val eqIndicator: IndicatorKey?, // EQ indicator
override val position: Position?
) :
AbstractReadStmt(
name = name,
loIndicator = loIndicator,
eqIndicator = eqIndicator,
position = position
) {
override val loggableEntityName: String
get() = "READP"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1335,37 +1335,51 @@ internal fun CsCHAINContext.toAst(conf: ToAstConfiguration): Statement {
val position = toPosition(conf.considerPosition)
val factor1 = this.factor1Context()?.content?.toAst(conf) ?: throw UnsupportedOperationException("CHAIN operation requires factor 1: ${this.text} - ${position.atLine()}")
val factor2 = this.cspec_fixed_standard_parts().factor2.text ?: throw UnsupportedOperationException("CHAIN operation requires factor 2: ${this.text} - ${position.atLine()}")
return ChainStmt(factor1, factor2, position)
val hi = this.cspec_fixed_standard_parts().hi.toIndicatorKey()
val lo = this.cspec_fixed_standard_parts().lo.toIndicatorKey()
return ChainStmt(factor1, factor2, hi, lo, position)
}

internal fun CsREADContext.toAst(conf: ToAstConfiguration): Statement {
val position = toPosition(conf.considerPosition)
// TODO implement DS in result field
val factor2 = this.cspec_fixed_standard_parts().factor2.text ?: throw UnsupportedOperationException("READ operation requires factor 2: ${this.text} - ${position.atLine()}")
return ReadStmt(factor2, position)

val loIndicator = this.cspec_fixed_standard_parts().lo.toIndicatorKey()
val eqIndicator = this.cspec_fixed_standard_parts().eq.toIndicatorKey()
return ReadStmt(factor2, loIndicator, eqIndicator, position)
}

internal fun CsREADPContext.toAst(conf: ToAstConfiguration): Statement {
val position = toPosition(conf.considerPosition)
// TODO implement DS in result field
val factor2 = this.cspec_fixed_standard_parts().factor2.text ?: throw UnsupportedOperationException("READP operation requires factor 2: ${this.text} - ${position.atLine()}")
return ReadPreviousStmt(factor2, position)

val loIndicator = this.cspec_fixed_standard_parts().lo.toIndicatorKey()
val eqIndicator = this.cspec_fixed_standard_parts().eq.toIndicatorKey()
return ReadPreviousStmt(factor2, loIndicator, eqIndicator, position)
}

internal fun CsREADEContext.toAst(conf: ToAstConfiguration): Statement {
val position = toPosition(conf.considerPosition)
// TODO implement DS in result field
val factor1 = this.factor1Context()?.content?.toAst(conf)
val factor2 = this.cspec_fixed_standard_parts().factor2.text ?: throw UnsupportedOperationException("READE operation requires factor 2: ${this.text} - ${position.atLine()}")
return ReadEqualStmt(factor1, factor2, position)

val lo = this.cspec_fixed_standard_parts().lo.toIndicatorKey()
val eq = this.cspec_fixed_standard_parts().eq.toIndicatorKey()
return ReadEqualStmt(factor1, factor2, lo, eq, position)
}

internal fun CsREADPEContext.toAst(conf: ToAstConfiguration): Statement {
val position = toPosition(conf.considerPosition)
// TODO implement DS in result field
val factor1 = this.factor1Context()?.content?.toAst(conf)
val factor2 = this.cspec_fixed_standard_parts().factor2.text ?: throw UnsupportedOperationException("READPE operation requires factor 2: ${this.text} - ${position.atLine()}")
return ReadPreviousEqualStmt(factor1, factor2, position)

val lo = this.cspec_fixed_standard_parts().lo.toIndicatorKey()
val eq = this.cspec_fixed_standard_parts().eq.toIndicatorKey()
return ReadPreviousEqualStmt(factor1, factor2, lo, eq, position)
}

internal fun CsSETLLContext.toAst(conf: ToAstConfiguration): Statement {
Expand Down Expand Up @@ -2307,4 +2321,6 @@ private fun Map<FileDefinition, List<DataDefinition>>.processWithSpecifications(
return buffer
}

private fun String.isStringLiteral(): Boolean = startsWith('\'') && endsWith('\'')
private fun String.isStringLiteral(): Boolean = startsWith('\'') && endsWith('\'')

private fun ResultIndicatorContext.toIndicatorKey() = text.trim().takeIf { it.isNotBlank() }?.toIndicatorKey()
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.smeup.rpgparser.smeup

import com.smeup.rpgparser.smeup.dbmock.C5ADFF9LDbMock
import org.junit.Test
import kotlin.test.assertEquals

Expand Down Expand Up @@ -413,6 +414,18 @@ open class MULANGT10BaseCodopTest : MULANGTTest() {
assertEquals(expected, "smeup/MUDRNRAPU00271".outputOf(configuration = smeupConfig))
}

/**
* READ operations with EQ Indicator
* @see #LS24005102
*/
@Test
fun executeMUDRNRAPU00272() {
val expected = listOf("ok", "ok", "ok", "ok")
C5ADFF9LDbMock().usePopulated {
assertEquals(expected, "smeup/MUDRNRAPU00272".outputOf(configuration = smeupConfig))
}
}

/**
* Comparing number and `*ZEROS` by using `IFxx`.
* @see #LS24004528
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2019 Sme.UP S.p.A.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.smeup.rpgparser.smeup.dbmock

import com.smeup.rpgparser.interpreter.FileMetadata
import java.io.File

class C5ADFF9LDbMock : DbMock {
override val metadata =
FileMetadata.createInstance(File("src/test/resources/smeup/metadata/C5ADFF9L.json").inputStream())
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ interface DbMock : AutoCloseable {
is NumberType -> buildString {
append("\"${it.fieldName}\"")
val defaultValue = if ((it.type as NumberType).decimal) {
" DECIMAL(${(it.type as NumberType).entireDigits}, ${(it.type as NumberType).decimalDigits}) DEFAULT 0.0"
val type = it.type as NumberType
val totalSize = type.entireDigits + type.decimalDigits
" DECIMAL($totalSize, ${type.decimalDigits}) DEFAULT 0.0"
} else {
" BIGINT DEFAULT 0"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
V* ==============================================================
V* 26/11/2024 APU002 Creation
V* ==============================================================
O * PROGRAM GOAL
O * Perform READ operations with EQ indicator
V* ==============================================================
O * JARIKO ANOMALY
O * Before the fix, indicators on READ operations were ignored
V* ==============================================================
FC5ADFF9L IF E K DISK RENAME(C5ADFFR:C5ADFF9)
C* READE with eof indicator
C TAG1 TAG
C KSCEN READE C5ADFF9L 50
C N50 IF *ON
C 'ko' DSPLY
C GOTO TAG1
C ENDIF
C 'ok' DSPLY
C* READPE bof indicator
C *LOVAL SETLL C5ADFF9L
C TAG2 TAG
C KSCEN READPE C5ADFF9L 50
C N50 IF *ON
C 'ko' DSPLY
C GOTO TAG2
C ENDIF
C 'ok' DSPLY
C* READ eof indicator
C *HIVAL SETLL C5ADFF9L
C TAG3 TAG
C KSCEN READ C5ADFF9L 50
C N50 IF *ON
C 'ko' DSPLY
C GOTO TAG3
C ENDIF
C 'ok' DSPLY
C* READP bof indicator
C *LOVAL SETLL C5ADFF9L
C TAG4 TAG
C KSCEN READP C5ADFF9L 50
C N50 IF *ON
C 'ko' DSPLY
C GOTO TAG4
C ENDIF
C 'ok' DSPLY
C*
C *LIKE DEFINE D5SCEN KSCEN
Loading