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/ls24005143/indicators with define #671

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -1302,17 +1302,24 @@ data class DefineStmt(
get() = "DEFINE"

override fun dataDefinition(): List<InStatementDataDefinition> {
// FIXME: If indicator was not priorly SET (SETON or SETOFF), program should error
val containingCU = this.ancestor(CompilationUnit::class.java)
?: return emptyList()

val indicatorPattern = Regex("\\*IN\\d\\d")
val isIndicator = originalName.trim().uppercase().matches(indicatorPattern)
val normalizedOriginalName = originalName.trim().uppercase()
val isIndicator = normalizedOriginalName.matches(indicatorPattern)
if (isIndicator) {
val indicatorKey = normalizedOriginalName.removePrefix("*IN").toIndicatorKey()
val setStatements = containingCU.main.stmts.explode(true).filterIsInstance<SetStmt>()
val definedIndicators = setStatements.map { it.indicators }.flatten().filterIsInstance<IndicatorExpr>()
val isIndicatorDefined = definedIndicators.any { it.index == indicatorKey }

if (!isIndicatorDefined) throw Error("Data reference $originalName not resolved")
lanarimarco marked this conversation as resolved.
Show resolved Hide resolved

val newDefinition = InStatementDataDefinition(newVarName, BooleanType, position)
return listOf(newDefinition)
}

val containingCU = this.ancestor(CompilationUnit::class.java)
?: return emptyList()

// Search standalone 'D spec' or InStatement definition
val originalDataDefinition = containingCU.dataDefinitions.find { it.name == originalName }
?: containingCU.getInStatementDataDefinitions().find { it.name == originalName }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,18 @@ class JarikoCallbackTest : AbstractTest() {
executeSourceLineTest("ERROR48")
}

@Test
fun executeERROR49CallBackTest() {
executePgmCallBackTest("ERROR49", SourceReferenceType.Program, "ERROR49", mapOf(
6 to "Data reference *IN10 not resolved"
))
}

@Test
fun executeERROR49SourceLineTest() {
executeSourceLineTest("ERROR49")
}

@Test
fun bypassSyntaxErrorTest() {
val configuration = Configuration().apply {
Expand Down
6 changes: 6 additions & 0 deletions rpgJavaInterpreter-core/src/test/resources/ERROR49.rpgle
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
V* ==============================================================
D* 02/12/24
D* Purpose: Must fire the following errors during execution of
D* line 6 - Data reference *IN10 not resolved
V* ==============================================================
C *LIKE DEFINE *IN10 XIN10