Skip to content

Commit

Permalink
Remove Cpp error ASUB_EASY_CASE -- apply regular case instead (#7592)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranke committed Jun 21, 2021
1 parent 26de721 commit 055c5fb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
18 changes: 8 additions & 10 deletions OMCompiler/Compiler/Template/CodegenCppCommon.tpl
Expand Up @@ -1572,27 +1572,25 @@ template daeExpAsub(Exp inExp, Context context, Text &preExp, Text &varDecls, Si
>>
'<%res%>'

case ASUB(exp=RANGE(ty=t), sub={idx}) then
error(sourceInfo(),'ASUB_EASY_CASE <%ExpressionDumpTpl.dumpExp(exp,"\"")%>')

case ASUB(exp=ecr as CREF(__), sub=subs) then
case ASUB(exp=ecr as CREF(__), sub=subs) then
let arrName = daeExpCrefRhs(buildCrefExpFromAsub(ecr, subs), context, &preExp, &varDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
match context case FUNCTION_CONTEXT(__) then
arrName
else
'<%arrayScalarRhs(ecr.ty, subs, arrName, context, &preExp, &varDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)%>'

case ASUB(exp=e, sub=indexes) then
let exp = daeExp(e, context, &preExp, &varDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
// let typeShort = expTypeFromExpShort(e)
let expIndexes = (indexes |> index => '<%daeExpASubIndex(index, context, &preExp, &varDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)%>' ;separator=",")
//'<%typeShort%>_get<%match listLength(indexes) case 1 then "" case i then '_<%i%>D'%>(&<%exp%>, <%expIndexes%>)'
'(<%exp%>)(<%expIndexes%>)'
let exp = daeExp(e, context, &preExp, &varDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
// let typeShort = expTypeFromExpShort(e)
let expIndexes = (indexes |> index => '<%daeExpASubIndex(index, context, &preExp, &varDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)%>' ;separator=",")
//'<%typeShort%>_get<%match listLength(indexes) case 1 then "" case i then '_<%i%>D'%>(&<%exp%>, <%expIndexes%>)'
'(<%exp%>)(<%expIndexes%>)'

case exp then
error(sourceInfo(),'OTHER_ASUB <%ExpressionDumpTpl.dumpExp(exp,"\"")%>')
end daeExpAsub;



template daeExpASubIndex(Exp exp, Context context, Text &preExp, Text &varDecls, SimCode simCode, Text& extraFuncs, Text& extraFuncsDecl,
Text extraFuncsNamespace, Text stateDerVectorName /*=__zDot*/, Boolean useFlatArrayNotation)
::=
Expand Down
1 change: 1 addition & 0 deletions testsuite/openmodelica/cppruntime/Makefile
Expand Up @@ -17,6 +17,7 @@ mathFunctionsTest.mos \
mslDistributionsTest.mos \
mslElectricalMachinesTest.mos \
mslElectricalSensorsTest.mos \
mslMathFFT1Test.mos \
nameClashTest.mos \
functionPointerTest.mos \
recordTupleReturnTest.mos \
Expand Down
37 changes: 37 additions & 0 deletions testsuite/openmodelica/cppruntime/mslMathFFT1Test.mos
@@ -0,0 +1,37 @@
// name: mslMathFFT1Test
// keywords: array slice asub
// status: correct
// teardown_command: rm -f *RealFFT1*
// cflags: -d=newInst

setCommandLineOptions("+simCodeTarget=Cpp");

loadModel(Modelica, {"3.2.3"}); getErrorString();

// simulate without echo to avoid a message with absolute path name
echo(false);
simulate(Modelica.Math.FastFourierTransform.Examples.RealFFT1);
echo(true);

// log some test results
val(Ai[1], 6.0);
val(Ai[11], 6.0);
val(Ai[16], 6.0);
val(fi[1], 6.0);
val(fi[11], 6.0);
val(fi[16], 6.0);
getErrorString();

// Result:
// true
// true
// ""
// true
// 4.999999999999999
// 2.97029702970297
// 1.485148514851486
// 0.0
// 2.0
// 3.0
// ""
// endResult

0 comments on commit 055c5fb

Please sign in to comment.