Skip to content

Commit 48813ac

Browse files
authored
Merge pull request #474 from smeup/bugfix/NW23001440/262-mock-oc-feod
Bugfix/nw23001440/262 mock oc feod
2 parents fa7fc7b + 094838f commit 48813ac

File tree

7 files changed

+60
-18
lines changed

7 files changed

+60
-18
lines changed

rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/execution/Configuration.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.smeup.rpgparser.execution
1919
import com.smeup.dbnative.DBNativeAccessConfig
2020
import com.smeup.rpgparser.interpreter.*
2121
import com.smeup.rpgparser.parsing.ast.CompilationUnit
22+
import com.smeup.rpgparser.parsing.ast.MockStatement
2223
import com.smeup.rpgparser.parsing.facade.CopyBlocks
2324
import com.smeup.rpgparser.parsing.facade.CopyId
2425
import com.smeup.rpgparser.parsing.facade.SourceReference
@@ -162,7 +163,12 @@ data class JarikoCallback(
162163
},
163164
var onCallPgmError: (errorEvent: ErrorEvent) -> Unit = { },
164165
var logInfo: ((channel: String, message: String) -> Unit)? = null,
165-
var channelLoggingEnabled: ((channel: String) -> Boolean)? = null
166+
var channelLoggingEnabled: ((channel: String) -> Boolean)? = null,
167+
/**
168+
* This is called for those statements mocked.
169+
* @param mockStatement "Statement" where is get its name for the `println`.
170+
*/
171+
var onMockStatement: ((mockStatement: MockStatement) -> Unit) = { System.err.println("Executing mock: ${it.javaClass.simpleName}") }
166172
)
167173

168174
/**

rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/interpreter/internal_interpreter.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,12 @@ open class InternalInterpreter(
411411
MainExecutionContext.getConfiguration().jarikoCallback.onEnterStatement(it.first, it.second)
412412
}
413413
}
414-
statement.execute(this)
414+
415+
if (statement is MockStatement) {
416+
MainExecutionContext.getConfiguration().jarikoCallback.onMockStatement
417+
} else {
418+
statement.execute(this)
419+
}
415420
}
416421
} catch (e: ControlFlowException) {
417422
throw e

rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/ast/serialization.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ private val modules = SerializersModule {
6060
subclass(DOWxxStmt::class)
6161
subclass(EvalStmt::class)
6262
subclass(ExecuteSubroutine::class)
63+
subclass(ExfmtStmt::class)
64+
subclass(FeodStmt::class)
6365
subclass(ForStmt::class)
6466
subclass(GotoStmt::class)
6567
subclass(IfStmt::class)
@@ -78,15 +80,13 @@ private val modules = SerializersModule {
7880
subclass(OccurStmt::class)
7981
subclass(OpenStmt::class)
8082
subclass(PlistStmt::class)
83+
subclass(ReadcStmt::class)
8184
subclass(ReadEqualStmt::class)
8285
subclass(ReadPreviousStmt::class)
8386
subclass(ReadPreviousEqualStmt::class)
8487
subclass(ReadStmt::class)
8588
subclass(ResetStmt::class)
86-
subclass(ExfmtStmt::class)
87-
subclass(ReadcStmt::class)
8889
subclass(ReturnStmt::class)
89-
subclass(UnlockStmt::class)
9090
subclass(ScanStmt::class)
9191
subclass(SelectStmt::class)
9292
subclass(CaseStmt::class)
@@ -99,6 +99,7 @@ private val modules = SerializersModule {
9999
subclass(SubstStmt::class)
100100
subclass(TagStmt::class)
101101
subclass(TimeStmt::class)
102+
subclass(UnlockStmt::class)
102103
subclass(UpdateStmt::class)
103104
subclass(XFootStmt::class)
104105
subclass(XlateStmt::class)

rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/ast/statements.kt

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ abstract class Statement(
8585
abstract fun execute(interpreter: InterpreterCore)
8686
}
8787

88+
/**
89+
* For statements with this interface there isn't execution but will be called the callback `onMockStatement`.
90+
*/
91+
interface MockStatement
92+
8893
interface CompositeStatement {
8994
val body: List<Statement>
9095
}
@@ -2055,26 +2060,27 @@ data class ResetStmt(
20552060
@Serializable
20562061
data class ExfmtStmt(
20572062
override val position: Position? = null
2058-
) : Statement(position) {
2059-
override fun execute(interpreter: InterpreterCore) {
2060-
// TODO
2061-
}
2063+
) : Statement(position), MockStatement {
2064+
override fun execute(interpreter: InterpreterCore) { }
20622065
}
20632066

20642067
@Serializable
20652068
data class ReadcStmt(
20662069
override val position: Position? = null
2067-
) : Statement(position) {
2068-
override fun execute(interpreter: InterpreterCore) {
2069-
// TODO
2070-
}
2070+
) : Statement(position), MockStatement {
2071+
override fun execute(interpreter: InterpreterCore) { }
20712072
}
20722073

20732074
@Serializable
20742075
data class UnlockStmt(
20752076
override val position: Position? = null
2076-
) : Statement(position) {
2077-
override fun execute(interpreter: InterpreterCore) {
2078-
// TODO
2079-
}
2077+
) : Statement(position), MockStatement {
2078+
override fun execute(interpreter: InterpreterCore) { }
2079+
}
2080+
2081+
@Serializable
2082+
data class FeodStmt(
2083+
override val position: Position? = null
2084+
) : Statement(position), MockStatement {
2085+
override fun execute(interpreter: InterpreterCore) { }
20802086
}

rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/misc.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,9 @@ internal fun Cspec_fixed_standardContext.toAst(conf: ToAstConfiguration = ToAstC
921921
this.csUNLOCK() != null -> this.csUNLOCK()
922922
.let { it.cspec_fixed_standard_parts().validate(stmt = it.toAst(conf), conf = conf) }
923923

924+
this.csFEOD() != null -> this.csFEOD()
925+
.let { it.cspec_fixed_standard_parts().validate(stmt = it.toAst(conf), conf = conf) }
926+
924927
else -> todo(conf = conf)
925928
}
926929
}
@@ -1997,6 +2000,12 @@ internal fun CsUNLOCKContext.toAst(conf: ToAstConfiguration = ToAstConfiguration
19972000
return UnlockStmt(position)
19982001
}
19992002

2003+
// TODO
2004+
internal fun CsFEODContext.toAst(conf: ToAstConfiguration = ToAstConfiguration()): Statement {
2005+
val position = toPosition(conf.considerPosition)
2006+
return FeodStmt(position)
2007+
}
2008+
20002009
/**
20012010
* Run a block. In case of error throws an error encapsulating useful information
20022011
* like node position
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
package com.smeup.rpgparser.smeup
22

3-
open class MULANGT52FileAccess2Test : MULANGTTest()
3+
import org.junit.Test
4+
import kotlin.test.assertEquals
5+
6+
open class MULANGT52FileAccess2Test : MULANGTTest() {
7+
/**
8+
* Mock FEOD operation code
9+
* @see #262
10+
*/
11+
@Test
12+
fun executeT52_A07_P02() {
13+
val expected = listOf("")
14+
assertEquals(expected, "smeup/T52_A07_P02".outputOf())
15+
}
16+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
C FEOD MULANGTL
2+
C '' DSPLY

0 commit comments

Comments
 (0)