Skip to content

Commit

Permalink
Applied refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
davidepalladino-apuliasoft committed Dec 4, 2024
1 parent d1edabe commit 61284de
Showing 1 changed file with 41 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,9 @@ open class InternalInterpreter(
* In accord to documentation (see https://www.ibm.com/docs/en/i/7.5?topic=codes-plist-identify-parameter-list):
* when control transfers to called program, at the beginning, the contents of the Result field is placed in
* the Factor 1 field.
* TODO: IS NECESSARY A REFACTORING!!!
*/
compilationUnit.entryPlist?.params
?.filter { plistParam -> plistParam.factor1 is DataRefExpr }
?.any { plistParamFiltered -> (plistParamFiltered.factor1 as DataRefExpr).variable.name.equals(it.name, true) } == true -> {

val resultName = compilationUnit.entryPlist?.params
?.filter { plistParam -> plistParam.factor1 is DataRefExpr }
?.firstOrNull { plistParamFiltered -> (plistParamFiltered.factor1 as DataRefExpr).variable.name.equals(it.name, true) }
?.result?.name

it.isInPlist(compilationUnit) -> {
val resultName = it.getResultNameByFactor1(compilationUnit)
if (resultName == null || initialValues[resultName] is NullValue) {
blankValue(it)
} else {
Expand Down Expand Up @@ -405,6 +397,45 @@ open class InternalInterpreter(
}
}

/**
* Retrieves the result name associated with the current `AbstractDataDefinition` instance
* from the parameter list (PList) of the specified `CompilationUnit`.
*
* This function searches the PList for the first parameter where `factor1` is of type `DataRefExpr`
* and its variable name matches the name of the current `AbstractDataDefinition` (case-insensitively).
* If such a parameter is found, its associated result name is returned.
*
* @param compilationUnit the compilation unit whose entry PList is to be checked
* @return the result name associated with the matching parameter, or `null` if no match is found
*/
private fun AbstractDataDefinition.getResultNameByFactor1(compilationUnit: CompilationUnit): String? {
val resultName = compilationUnit.entryPlist?.params
?.filter { plistParam -> plistParam.factor1 is DataRefExpr }
?.firstOrNull { plistParamFiltered ->
(plistParamFiltered.factor1 as DataRefExpr).variable.name.equals(
this.name,
true
)
}
?.result?.name
return resultName
}

/**
* Checks if the current `AbstractDataDefinition` instance is present in the parameter list (PList)
* of the specified `CompilationUnit`.
*
* This function evaluates whether the `AbstractDataDefinition` matches any parameter in the PList
* by comparing their names (case-insensitively). Parameters in the PList are filtered to include
* only those with a `factor1` of type `DataRefExpr`.
*
* @param compilationUnit the compilation unit whose entry PList is to be checked
* @return `true` if the `AbstractDataDefinition` is present in the PList, otherwise `false`
*/
private fun AbstractDataDefinition.isInPlist(compilationUnit: CompilationUnit) = compilationUnit.entryPlist?.params
?.filter { plistParam -> plistParam.factor1 is DataRefExpr }
?.any { plistParamFiltered -> (plistParamFiltered.factor1 as DataRefExpr).variable.name.equals(this.name, true) } == true

private fun toArrayValue(compileTimeArray: CompileTimeArray, arrayType: ArrayType): Value {
// It is not clear why the compileTimeRecordsPerLine on the array type is null
// probably it is an error during the ast processing.
Expand Down

0 comments on commit 61284de

Please sign in to comment.