Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 705b6a1

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Handle alias variables in Susan
Belonging to [master]: - #2097 - OpenModelica/OpenModelica-testsuite#814
1 parent 25d84d4 commit 705b6a1

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

Compiler/SimCode/SimCodeUtil.mo

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13321,16 +13321,8 @@ algorithm
1332113321
sv = BaseHashTable.get(cref, crefToSimVarHT);
1332213322
sv = match sv.aliasvar
1332313323
case SimCodeVar.NOALIAS() then sv;
13324-
/* The C++ runtime generates a different set of variables... */
13325-
case _ guard Config.simCodeTarget() == "Cpp" then sv;
13326-
case SimCodeVar.ALIAS(varName=cref)
13327-
algorithm
13328-
Error.addSourceMessage(Error.COMPILER_WARNING, {getInstanceName() + " got an alias variable " + ComponentReference.printComponentRefStr(inCref) + " to " + ComponentReference.printComponentRefStr(cref) + ", but before code generation these should have been removed"}, sv.source.info);
13329-
then cref2simvar(cref, simCode);
13330-
case SimCodeVar.NEGATEDALIAS(varName=cref)
13331-
algorithm
13332-
Error.addSourceMessage(Error.INTERNAL_ERROR, {getInstanceName() + " got a negated alias variable " + ComponentReference.printComponentRefStr(inCref) + " to " + ComponentReference.printComponentRefStr(cref) + ", but before code generation these should have been removed"}, sv.source.info);
13333-
then sv;
13324+
case SimCodeVar.ALIAS(varName=cref) then cref2simvar(cref, simCode); /* Possibly not needed; can't really hurt that much though */
13325+
case SimCodeVar.NEGATEDALIAS() then sv;
1333413326
end match;
1333513327
then sv;
1333613328

Compiler/Template/CodegenC.tpl

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,8 +1618,9 @@ template functionInput(SimCode simCode, ModelInfo modelInfo, String modelNamePre
16181618
16191619
<%vars.inputVars |> SIMVAR(__) hasindex i0 =>
16201620
match cref2simvar(name, simCode)
1621-
case SIMVAR(__) then
1621+
case SIMVAR(aliasvar=NOALIAS()) then
16221622
'data->simulationInfo->inputVars[<%i0%>] = data->modelData-><%expTypeShort(type_)%>VarsData[<%index%>].attribute.start;'
1623+
else error(sourceInfo(), 'Cannot get attributes of alias variable <%crefStr(name)%>. Alias variables should have been replaced by the compiler before SimCode')
16231624
;separator="\n"
16241625
%>
16251626
@@ -1633,8 +1634,9 @@ template functionInput(SimCode simCode, ModelInfo modelInfo, String modelNamePre
16331634
16341635
<%vars.inputVars |> SIMVAR(__) hasindex i0 =>
16351636
match cref2simvar(name, simCode)
1636-
case SIMVAR(__) then
1637+
case SIMVAR(aliasvar=NOALIAS()) then
16371638
'data->modelData-><%expTypeShort(type_)%>VarsData[<%index%>].attribute.start = data->simulationInfo->inputVars[<%i0%>];'
1639+
else error(sourceInfo(), 'Cannot get attributes of alias variable <%crefStr(name)%>. Alias variables should have been replaced by the compiler before SimCode')
16381640
;separator="\n"
16391641
%>
16401642
@@ -1647,8 +1649,9 @@ template functionInput(SimCode simCode, ModelInfo modelInfo, String modelNamePre
16471649
16481650
<%vars.inputVars |> simVar as SIMVAR(__) hasindex i0 =>
16491651
match cref2simvar(name, simCode)
1650-
case SIMVAR(__) then
1652+
case SIMVAR(aliasvar=NOALIAS()) then
16511653
'names[<%i0%>] = (char *) data->modelData-><%expTypeShort(type_)%>VarsData[<%index%>].info.name;'
1654+
else error(sourceInfo(), 'Cannot get attributes of alias variable <%crefStr(name)%>. Alias variables should have been replaced by the compiler before SimCode')
16521655
;separator="\n"
16531656
%>
16541657
@@ -2944,10 +2947,11 @@ template functionUpdateBoundParameters(list<SimEqSystem> simpleParameterEquation
29442947
<<
29452948
<%cref(cref)%> = <%daeExpSimpleLiteral(exp)%>;
29462949
<%match cref2simvar(cref, simCode)
2947-
case SIMVAR(varKind=PARAM()) then
2950+
case SIMVAR(aliasvar=NOALIAS(), varKind=PARAM()) then
29482951
'data->modelData-><%expTypeShort(type_)%>ParameterData[<%index%>].time_unvarying = 1;'
2949-
case SIMVAR(__) then
2950-
'data->modelData-><%expTypeShort(type_)%>VarsData[<%index%>].time_unvarying = 1;'%>
2952+
case SIMVAR(aliasvar=NOALIAS()) then
2953+
'data->modelData-><%expTypeShort(type_)%>VarsData[<%index%>].time_unvarying = 1;'
2954+
else error(sourceInfo(), 'Cannot get attributes of alias variable <%crefStr(cref)%>. Alias variables should have been replaced by the compiler before SimCode')%>
29512955
>> ; separator="\n" %>
29522956
<%fncalls%>
29532957
TRACE_POP
@@ -4459,12 +4463,6 @@ template crefShortType(ComponentRef cr) "template crefType
44594463
end match
44604464
end crefShortType;
44614465
4462-
template crefIndexInArray(ComponentRef cr, SimCode simCode)
4463-
::=
4464-
match cref2simvar(cr, simCode)
4465-
case SIMVAR(__) then index
4466-
end crefIndexInArray;
4467-
44684466
template functionAssertsforCheck(list<SimEqSystem> algAndEqAssertsEquations, String modelNamePrefix) "template functionAssertsforCheck
44694467
Generates function in simulation file.
44704468
This is a helper of template simulationFile."

Compiler/Template/CodegenCFunctions.tpl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4100,10 +4100,14 @@ template crefToCStr(ComponentRef cr, Integer ix, Boolean isPre, Boolean isStart)
41004100
case SIMVAR(varKind=ALG_STATE_OLD(), index=index)
41014101
then
41024102
'data->simulationInfo->inlineData->algOldVars[<%index%>]'
4103+
case SIMVAR(aliasvar=ALIAS(varName=varName)) then crefToCStr(varName, ix, isPre, isStart)
4104+
case SIMVAR(aliasvar=NEGATEDALIAS(varName=varName), type_=T_BOOL()) then '!(<%crefToCStr(varName, ix, isPre, isStart)%>)'
4105+
case SIMVAR(aliasvar=NEGATEDALIAS(varName=varName)) then '-(<%crefToCStr(varName, ix, isPre, isStart)%>)'
41034106
case SIMVAR(varKind=JAC_VAR())
41044107
case SIMVAR(varKind=JAC_DIFF_VAR())
41054108
case SIMVAR(varKind=SEED_VAR())
41064109
case SIMVAR(varKind=DAE_RESIDUAL_VAR())
4110+
case SIMVAR(varKind=DAE_RESIDUAL_VAR())
41074111
case SIMVAR(index=-2)
41084112
then
41094113
if intEq(ix,0) then (if isPre then "$P$PRE")+crefDefine(cr)
@@ -6982,9 +6986,9 @@ template crefAttributes(ComponentRef cr)
69826986
::=
69836987
match cref2simvar(cr, getSimCode())
69846988
case var as SIMVAR(index=-1, varKind=JAC_VAR()) then "dummyREAL_ATTRIBUTE"
6985-
case var as SIMVAR(index=-1) then error(sourceInfo(), 'varAttributes got index=-1 for <%crefStr(name)%>')
69866989
case var as SIMVAR(__) then
6987-
'data->modelData-><%varArrayName(var)%>Data[<%index%>].attribute /* <%escapeCComments(crefStrNoUnderscore(name))%> */'
6990+
if intLt(index,0) then error(sourceInfo(), 'varAttributes got negative index=<%index%> for <%crefStr(name)%>') else
6991+
'data->modelData-><%varArrayName(var)%>Data[<%index%>].attribute /* <%escapeCComments(crefStrNoUnderscore(name))%> */'
69886992
end crefAttributes;
69896993

69906994
annotation(__OpenModelica_Interface="backend");

0 commit comments

Comments
 (0)