Skip to content

Commit d201a6a

Browse files
author
Jens Frenkel
committed
- use Expression.splitRecord instead of trying to match all combinations of crefs and calls that are possible to split
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13887 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent d2e5bd1 commit d201a6a

File tree

3 files changed

+117
-147
lines changed

3 files changed

+117
-147
lines changed

Compiler/BackEnd/BackendDAECreate.mo

Lines changed: 30 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,85 +1301,53 @@ protected function lowerextendedRecordEqn "
13011301
Author: Frenkel TUD 2012-06"
13021302
input DAE.Exp inExp1;
13031303
input DAE.Exp inExp2;
1304-
input DAE.ElementSource isource;
1304+
input DAE.ElementSource source;
13051305
input DAE.FunctionTree functionTree;
13061306
input list<BackendDAE.Equation> inEqns;
13071307
output list<BackendDAE.Equation> outEqns;
13081308
algorithm
1309-
outEqns := matchcontinue(inExp1,inExp2,isource,functionTree,inEqns)
1309+
outEqns := matchcontinue(inExp1,inExp2,source,functionTree,inEqns)
13101310
local
1311-
DAE.Exp e1,e2;
1312-
DAE.ElementSource source;
1313-
DAE.ComponentRef cr1,cr2;
13141311
Expression.Type tp;
13151312
Integer size;
1316-
list<DAE.Exp> expvarlst,expvarlst1,explst;
1317-
Boolean b1,b2;
1318-
list<DAE.Var> varLst;
1319-
Absyn.Path path,fname,path1;
13201313
DAE.Dimensions dims;
1321-
1322-
// a=b
1323-
case (DAE.CREF(componentRef=cr1,ty= DAE.T_COMPLEX(varLst=varLst,complexClassType=ClassInf.RECORD(_))),DAE.CREF(componentRef=cr2),source,_,_)
1324-
equation
1325-
// create as many equations as the dimension of the record
1326-
expvarlst = List.map1(varLst,Expression.generateCrefsExpFromExpVar,cr1);
1327-
expvarlst1 = List.map1(varLst,Expression.generateCrefsExpFromExpVar,cr2);
1328-
then
1329-
lowerextendedRecordEqns(expvarlst,expvarlst1,source,functionTree,inEqns);
1330-
1331-
// a=Record()
1332-
case (DAE.CREF(componentRef=cr1,ty= DAE.T_COMPLEX(varLst=varLst,complexClassType=ClassInf.RECORD(_))),DAE.CALL(path=path,expLst=explst),source,_,_)
1333-
equation
1334-
SOME(DAE.RECORD_CONSTRUCTOR(path=fname)) = DAEUtil.avlTreeGet(functionTree,path);
1335-
// create as many equations as the dimension of the record
1336-
expvarlst = List.map1(varLst,Expression.generateCrefsExpFromExpVar,cr1);
1337-
then
1338-
lowerextendedRecordEqns(expvarlst,explst,source,functionTree,inEqns);
1339-
1340-
// Record()=a
1341-
case (DAE.CALL(path=path,expLst=explst),DAE.CREF(componentRef=cr1,ty= DAE.T_COMPLEX(varLst=varLst,complexClassType=ClassInf.RECORD(_))),source,_,_)
1342-
equation
1343-
SOME(DAE.RECORD_CONSTRUCTOR(path=fname)) = DAEUtil.avlTreeGet(functionTree,path);
1344-
// create as many equations as the dimension of the record
1345-
expvarlst = List.map1(varLst,Expression.generateCrefsExpFromExpVar,cr1);
1346-
then
1347-
lowerextendedRecordEqns(expvarlst,explst,source,functionTree,inEqns);
1348-
1349-
// Record()=Record()
1350-
case (DAE.CALL(path=path,expLst=expvarlst,attr=DAE.CALL_ATTR(ty= DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(_)))),DAE.CALL(path=path1,expLst=explst),source,_,_)
1314+
list<DAE.Exp> explst1,explst2;
1315+
Boolean b1,b2;
1316+
// a,Record(),CAST(Record())
1317+
case (_,_,_,_,_)
13511318
equation
1352-
SOME(DAE.RECORD_CONSTRUCTOR(path=fname)) = DAEUtil.avlTreeGet(functionTree,path);
1319+
explst1 = Expression.splitRecord(inExp1,Expression.typeof(inExp1));
1320+
explst2 = Expression.splitRecord(inExp2,Expression.typeof(inExp2));
13531321
then
1354-
lowerextendedRecordEqns(expvarlst,explst,source,functionTree,inEqns);
1322+
lowerextendedRecordEqns(explst1,explst2,source,functionTree,inEqns);
13551323

13561324
// complex types to complex equations
1357-
case (e1,e2,source,_,_)
1325+
case (_,_,_,_,_)
13581326
equation
1359-
tp = Expression.typeof(e1);
1327+
tp = Expression.typeof(inExp1);
13601328
true = DAEUtil.expTypeComplex(tp);
13611329
size = Expression.sizeOf(tp);
13621330
then
1363-
BackendDAE.COMPLEX_EQUATION(size,e1,e2,source)::inEqns;
1331+
BackendDAE.COMPLEX_EQUATION(size,inExp1,inExp2,source)::inEqns;
13641332

13651333
// array types to array equations
1366-
case (e1,e2,source,_,_)
1334+
case (_,_,_,_,_)
13671335
equation
1368-
tp = Expression.typeof(e1);
1336+
tp = Expression.typeof(inExp1);
13691337
true = DAEUtil.expTypeArray(tp);
13701338
dims = Expression.arrayDimension(tp);
13711339
then
1372-
lowerArrayEqn(dims,e1,e2,source,inEqns);
1340+
lowerArrayEqn(dims,inExp1,inExp2,source,inEqns);
13731341
// other types
1374-
case (e1,e2,source,_,_)
1342+
case (_,_,_,_,_)
13751343
equation
1376-
tp = Expression.typeof(e1);
1344+
tp = Expression.typeof(inExp1);
13771345
b1 = DAEUtil.expTypeComplex(tp);
13781346
b2 = DAEUtil.expTypeArray(tp);
13791347
false = b1 or b2;
13801348
//Error.assertionOrAddSourceMessage(not b1,Error.INTERNAL_ERROR,{str}, Absyn.dummyInfo);
13811349
then
1382-
BackendDAE.EQUATION(e1,e2,source)::inEqns;
1350+
BackendDAE.EQUATION(inExp1,inExp2,source)::inEqns;
13831351
else
13841352
equation
13851353
// show only on failtrace!
@@ -2362,49 +2330,6 @@ algorithm
23622330
(vars,knvars,extvars,avars,repl,eqns) = selectAliasLst(List.flatten(explstlst1),List.flatten(explstlst2),source,iVars,iKnVars,iExtVars,iAVars,iRepl,iEqns);
23632331
then
23642332
(vars,knvars,extvars,avars,repl,eqns);
2365-
// cref complex cref complex
2366-
case (DAE.CREF(componentRef=cr1,ty=DAE.T_COMPLEX(varLst=varLst1,complexClassType=ClassInf.RECORD(_))),
2367-
DAE.CREF(componentRef=cr2,ty=DAE.T_COMPLEX(varLst=varLst2,complexClassType=ClassInf.RECORD(_))),_,_,_,_,_,_,_)
2368-
equation
2369-
// Create a list of crefs from names
2370-
crefs1 = List.map(varLst1,ComponentReference.creffromVar);
2371-
crefs1 = List.map1r(crefs1,ComponentReference.joinCrefs,cr1);
2372-
explst1 = List.map(crefs1,Expression.crefExp);
2373-
crefs2 = List.map(varLst2,ComponentReference.creffromVar);
2374-
crefs2 = List.map1r(crefs2,ComponentReference.joinCrefs,cr2);
2375-
explst2 = List.map(crefs2,Expression.crefExp);
2376-
(vars,knvars,extvars,avars,repl,eqns) = selectAliasLst(explst1,explst2,source,iVars,iKnVars,iExtVars,iAVars,iRepl,iEqns);
2377-
then
2378-
(vars,knvars,extvars,avars,repl,eqns);
2379-
// call complex call complex
2380-
case (DAE.CALL(expLst=explst1,attr=DAE.CALL_ATTR(ty= DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(_)))),
2381-
DAE.CALL(expLst=explst2,attr=DAE.CALL_ATTR(ty= DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(_)))),_,_,_,_,_,_,_)
2382-
equation
2383-
(vars,knvars,extvars,avars,repl,eqns) = selectAliasLst(explst1,explst2,source,iVars,iKnVars,iExtVars,iAVars,iRepl,iEqns);
2384-
then
2385-
(vars,knvars,extvars,avars,repl,eqns);
2386-
// call complex cref complex
2387-
case (DAE.CALL(expLst=explst1,attr=DAE.CALL_ATTR(ty= DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(_)))),
2388-
DAE.CREF(componentRef=cr2,ty=DAE.T_COMPLEX(varLst=varLst2,complexClassType=ClassInf.RECORD(_))),_,_,_,_,_,_,_)
2389-
equation
2390-
// Create a list of crefs from names
2391-
crefs2 = List.map(varLst2,ComponentReference.creffromVar);
2392-
crefs2 = List.map1r(crefs2,ComponentReference.joinCrefs,cr2);
2393-
explst2 = List.map(crefs2,Expression.crefExp);
2394-
(vars,knvars,extvars,avars,repl,eqns) = selectAliasLst(explst1,explst2,source,iVars,iKnVars,iExtVars,iAVars,iRepl,iEqns);
2395-
then
2396-
(vars,knvars,extvars,avars,repl,eqns);
2397-
// cref complex CALL complex
2398-
case (DAE.CREF(componentRef=cr1,ty=DAE.T_COMPLEX(varLst=varLst1,complexClassType=ClassInf.RECORD(_))),
2399-
DAE.CALL(expLst=explst2,attr=DAE.CALL_ATTR(ty= DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(_)))),_,_,_,_,_,_,_)
2400-
equation
2401-
// Create a list of crefs from names
2402-
crefs1 = List.map(varLst1,ComponentReference.creffromVar);
2403-
crefs1 = List.map1r(crefs1,ComponentReference.joinCrefs,cr1);
2404-
explst1 = List.map(crefs1,Expression.crefExp);
2405-
(vars,knvars,extvars,avars,repl,eqns) = selectAliasLst(explst1,explst2,source,iVars,iKnVars,iExtVars,iAVars,iRepl,iEqns);
2406-
then
2407-
(vars,knvars,extvars,avars,repl,eqns);
24082333
// scalar case
24092334
case (DAE.CREF(componentRef=cr1),
24102335
DAE.CREF(componentRef=cr2),_,_,_,_,_,_,_)
@@ -2414,6 +2339,15 @@ algorithm
24142339
(vars,knvars,extvars,avars,repl) = selectAliasVar(v1,i1,arrayTyp1,exp1,v2,i2,arrayTyp2,exp2,source,iVars,iKnVars,iExtVars,iAVars,iRepl);
24152340
then
24162341
(vars,knvars,extvars,avars,repl,iEqns);
2342+
// complex
2343+
case (_,_,_,_,_,_,_,_,_)
2344+
equation
2345+
// Create a list of crefs from names
2346+
explst1 = Expression.splitRecord(exp1,Expression.typeof(exp1));
2347+
explst2 = Expression.splitRecord(exp2,Expression.typeof(exp2));
2348+
(vars,knvars,extvars,avars,repl,eqns) = selectAliasLst(explst1,explst2,source,iVars,iKnVars,iExtVars,iAVars,iRepl,iEqns);
2349+
then
2350+
(vars,knvars,extvars,avars,repl,eqns);
24172351
// if no alias selectable add as equation
24182352
case (_,_,_,_,_,_,_,_,_)
24192353
then
@@ -3238,6 +3172,7 @@ algorithm
32383172
(outVars,oExp) := matchcontinue(inVars,var,iExp)
32393173
local
32403174
BackendDAE.Variables vars;
3175+
BackendDAE.Var var1;
32413176
case(_,_,_)
32423177
equation
32433178
true = BackendVariable.isVarDiscrete(var) "do not change discrete vars to states, because they have no derivative" ;
@@ -3246,8 +3181,8 @@ algorithm
32463181
equation
32473182
false = BackendVariable.isVarDiscrete(var) "do not change discrete vars to states, because they have no derivative" ;
32483183
false = BackendVariable.isStateVar(var);
3249-
var = BackendVariable.setVarKind(var,BackendDAE.STATE());
3250-
vars = BackendVariable.addVar(var, inVars);
3184+
var1 = BackendVariable.setVarKind(var,BackendDAE.STATE());
3185+
vars = BackendVariable.addVar(var1, inVars);
32513186
then (vars,iExp);
32523187
case(_,_,_)
32533188
equation

0 commit comments

Comments
 (0)