@@ -43,27 +43,31 @@ encapsulated package Inline
4343 "
4444
4545public import Absyn ;
46+ public import Algorithm ;
4647public import BackendDAE ;
48+ public import BaseHashTable ;
4749public import DAE ;
50+ public import HashTableCG ;
4851public import SCode ;
4952public import Util ;
5053public import Values ;
51- public import Algorithm ;
5254
5355type Ident = String ;
5456
5557public type Functiontuple = tuple< Option < DAE . FunctionTree > ,list< DAE . InlineType >> ;
5658
5759protected import ComponentReference ;
58- protected import Debug ;
60+ protected import Config ;
5961protected import DAEUtil ;
62+ protected import Debug ;
6063protected import Error ;
6164protected import Expression ;
65+ protected import ExpressionDump ;
6266protected import ExpressionSimplify ;
6367protected import Flags ;
6468protected import List ;
6569protected import Types ;
66- protected import Config ;
70+
6771
6872public function inlineCalls
6973"function: inlineCalls
@@ -1080,6 +1084,7 @@ algorithm
10801084 DAE . Exp newExp,newExp1, e1;
10811085 DAE . InlineType inlineType;
10821086 DAE . Type ty1,ty2;
1087+ HashTableCG . HashTable checkcr;
10831088 case ((e1 as DAE . CALL (p,args,DAE . CALL_ATTR (inlineType= inlineType)),(fns,_)))
10841089 equation
10851090 true = DAEUtil . convertInlineTypeToBool(inlineType);
@@ -1088,11 +1093,11 @@ algorithm
10881093 crefs = List . map(fn,getInputCrefs);
10891094 crefs = List . select(crefs,removeWilds);
10901095 argmap = List . threadTuple(crefs,args);
1091- argmap = extendCrefRecords(argmap);
1096+ ( argmap,checkcr) = extendCrefRecords(argmap, HashTableCG . emptyHashTable() );
10921097 newExp = getRhsExp(fn);
10931098 // compare types
10941099 true = checkExpsTypeEquiv(e1, newExp);
1095- ((newExp,argmap)) = Expression . traverseExp(newExp,replaceArgs,argmap);
1100+ ((newExp,(_,_, true ))) = Expression . traverseExp(newExp,replaceArgs,( argmap,checkcr, true ) );
10961101 // for inlinecalls in functions
10971102 ((newExp1,(fns1,_))) = Expression . traverseExp(newExp,inlineCall,(fns,true ));
10981103 then
@@ -1101,6 +1106,16 @@ algorithm
11011106 end matchcontinue;
11021107end inlineCall;
11031108
1109+ protected function dumpArgmap
1110+ input tuple< DAE . ComponentRef , DAE . Exp > inTpl;
1111+ protected
1112+ DAE . ComponentRef cr;
1113+ DAE . Exp exp;
1114+ algorithm
1115+ (cr,exp) := inTpl;
1116+ print(ComponentReference . printComponentRefStr(cr) +& " -> " +& ExpressionDump . printExpStr(exp) +& " \n " );
1117+ end dumpArgmap;
1118+
11041119public function forceInlineCall
11051120"function: inlineCall
11061121 replaces an inline call with the expression from the function"
@@ -1120,16 +1135,18 @@ algorithm
11201135 DAE . Exp newExp,newExp1, e1;
11211136 DAE . InlineType inlineType;
11221137 DAE . Type ty1,ty2;
1138+ HashTableCG . HashTable checkcr;
11231139 case ((e1 as DAE . CALL (p,args,DAE . CALL_ATTR (inlineType= inlineType)),(fns,_)))
11241140 equation
11251141 false = Config . acceptMetaModelicaGrammar();
1126- fn = getFunctionBody(p,fns);
1142+ true = checkInlineType(inlineType,fns);
1143+ fn = getFunctionBody(p,fns);
11271144 crefs = List . map(fn,getInputCrefs);
11281145 crefs = List . select(crefs,removeWilds);
11291146 argmap = List . threadTuple(crefs,args);
1130- argmap = extendCrefRecords(argmap);
1131- newExp = getRhsExp (fn);
1132- ((newExp,argmap)) = Expression . traverseExp(newExp,replaceArgs,argmap);
1147+ ( argmap,checkcr) = extendCrefRecords(argmap, HashTableCG . emptyHashTable() );
1148+ newExp::{} = getRhsExp1 (fn);
1149+ ((newExp,(_,_, true ))) = Expression . traverseExp(newExp,replaceArgs,( argmap,checkcr, true ) );
11331150 // compare types
11341151 true = checkExpsTypeEquiv(e1, newExp);
11351152 // for inlinecalls in functions
@@ -1163,49 +1180,94 @@ protected function extendCrefRecords
11631180"function: extendCrefRecords
11641181 extends crefs from records"
11651182 input list< tuple< DAE . ComponentRef , DAE . Exp >> inArgmap;
1183+ input HashTableCG . HashTable inCheckCr;
11661184 output list< tuple< DAE . ComponentRef , DAE . Exp >> outArgmap;
1185+ output HashTableCG . HashTable outCheckCr;
11671186algorithm
1168- outArgmap := matchcontinue(inArgmap)
1187+ ( outArgmap,outCheckCr) := matchcontinue(inArgmap,inCheckCr )
11691188 local
1189+ HashTableCG . HashTable ht,ht1,ht2,ht3;
11701190 list< tuple< DAE . ComponentRef , DAE . Exp >> res,res1,res2,new,new1;
11711191 DAE . ComponentRef c,cref;
11721192 DAE . Exp e;
11731193 list< DAE . Var > varLst;
11741194 list< DAE . Exp > expl;
11751195 list< DAE . ComponentRef > crlst;
1176- case ({}) then {};
1177- case ((c,e as (DAE . CREF (componentRef = cref,ty= DAE . T_COMPLEX (varLst= varLst))))::res)
1196+ list< tuple< DAE . ComponentRef ,DAE . ComponentRef >> creftpllst;
1197+ case ({},ht) then ({},ht);
1198+ case ((c,e as (DAE . CREF (componentRef = cref,ty= DAE . T_COMPLEX (varLst= varLst))))::res,ht)
11781199 equation
1179- res1 = extendCrefRecords(res);
1200+ ( res1,ht1) = extendCrefRecords(res,ht );
11801201 new = List . map2(varLst,extendCrefRecords1,c,cref);
1181- new1 = extendCrefRecords(new);
1202+ ( new1,ht2) = extendCrefRecords(new,ht1 );
11821203 res2 = listAppend(new1,res1);
1183- then ((c,e)::res2);
1204+ then ((c,e)::res2,ht2 );
11841205 /* cause of an error somewhere the type of the expression CREF is not equal to the componentreference type
11851206 this case is needed. */
1186- case ((c,e as (DAE . CREF (componentRef = cref)))::res)
1207+ case ((c,e as (DAE . CREF (componentRef = cref)))::res,ht )
11871208 equation
11881209 DAE . T_COMPLEX (varLst= varLst) = ComponentReference . crefLastType(cref);
1189- res1 = extendCrefRecords(res);
1210+ ( res1,ht1) = extendCrefRecords(res,ht );
11901211 new = List . map2(varLst,extendCrefRecords1,c,cref);
1191- new1 = extendCrefRecords(new);
1212+ ( new1,ht2) = extendCrefRecords(new,ht1 );
11921213 res2 = listAppend(new1,res1);
1193- then ((c,e)::res2);
1194- case ((c,e as (DAE . CALL (expLst = expl,attr= DAE . CALL_ATTR (ty= DAE . T_COMPLEX (varLst= varLst)))))::res)
1214+ then ((c,e)::res2,ht2 );
1215+ case ((c,e as (DAE . CALL (expLst = expl,attr= DAE . CALL_ATTR (ty= DAE . T_COMPLEX (varLst= varLst)))))::res,ht )
11951216 equation
1196- res1 = extendCrefRecords(res);
1217+ ( res1,ht1) = extendCrefRecords(res,ht );
11971218 crlst = List . map1(varLst,extendCrefRecords2,c);
11981219 new = List . threadTuple(crlst,expl);
1199- new1 = extendCrefRecords(new);
1220+ ( new1,ht2) = extendCrefRecords(new,ht1 );
12001221 res2 = listAppend(new1,res1);
1201- then ((c,e)::res2);
1202- case ((c,e)::res)
1222+ then ((c,e)::res2,ht2 );
1223+ case ((c,e)::res,ht )
12031224 equation
1204- res1 = extendCrefRecords(res);
1205- then ((c,e)::res1);
1225+ DAE . T_COMPLEX (varLst= varLst) = Expression . typeof(e);
1226+ crlst = List . map1(varLst,extendCrefRecords2,c);
1227+ creftpllst = List . map1(crlst,Util . makeTuple,c);
1228+ ht1 = List . fold(creftpllst,BaseHashTable . add,ht);
1229+ ht2 = getCheckCref(crlst,ht1);
1230+ (res1,ht3) = extendCrefRecords(res,ht2);
1231+ then ((c,e)::res1,ht3);
1232+ case ((c,e)::res,ht)
1233+ equation
1234+ (res1,ht1) = extendCrefRecords(res,ht);
1235+ then ((c,e)::res1,ht1);
12061236 end matchcontinue;
12071237end extendCrefRecords;
12081238
1239+ protected function getCheckCref
1240+ input list< DAE . ComponentRef > inCrefs;
1241+ input HashTableCG . HashTable inCheckCr;
1242+ output HashTableCG . HashTable outCheckCr;
1243+ algorithm
1244+ outCheckCr := matchcontinue(inCrefs,inCheckCr)
1245+ local
1246+ HashTableCG . HashTable ht,ht1,ht2,ht3;
1247+ list< DAE . ComponentRef > rest,crlst;
1248+ DAE . ComponentRef cr;
1249+ list< DAE . Var > varLst;
1250+ list< tuple< DAE . ComponentRef ,DAE . ComponentRef >> creftpllst;
1251+ case ({},ht)
1252+ then ht;
1253+ case (cr::rest,ht)
1254+ equation
1255+ DAE . T_COMPLEX (varLst= varLst) = ComponentReference . crefLastType(cr);
1256+ crlst = List . map1(varLst,extendCrefRecords2,cr);
1257+ ht1 = getCheckCref(crlst,ht);
1258+ creftpllst = List . map1(crlst,Util . makeTuple,cr);
1259+ ht2 = List . fold(creftpllst,BaseHashTable . add,ht1);
1260+ ht3 = getCheckCref(rest,ht2);
1261+ then
1262+ ht3;
1263+ case (cr::rest,ht)
1264+ equation
1265+ ht1 = getCheckCref(rest,ht);
1266+ then
1267+ ht1;
1268+ end matchcontinue;
1269+ end getCheckCref;
1270+
12091271protected function extendCrefRecords1
12101272"function: extendCrefRecords1
12111273 helper for extendCrefRecords"
@@ -1310,11 +1372,48 @@ algorithm
13101372 end matchcontinue;
13111373end getRhsExp;
13121374
1375+ protected function getRhsExp1
1376+ "function: getRhsExp1
1377+ returns the right hand side of an assignment from a function"
1378+ input list< DAE . Element > inElementList;
1379+ output list< DAE . Exp > outExps;
1380+ algorithm
1381+ outExps := matchcontinue(inElementList)
1382+ local
1383+ list< DAE . Element > cdr;
1384+ DAE . Exp exp;
1385+ list< DAE . Exp > res;
1386+ case ({})
1387+ then
1388+ {};
1389+ case (DAE . ALGORITHM (algorithm_ = DAE . ALGORITHM_STMTS ({DAE . STMT_ASSIGN (exp= exp)})) :: cdr)
1390+ equation
1391+ res = getRhsExp1(cdr);
1392+ then
1393+ exp::res;
1394+ case (DAE . ALGORITHM (algorithm_ = DAE . ALGORITHM_STMTS ({DAE . STMT_TUPLE_ASSIGN (exp= exp)})) :: cdr)
1395+ equation
1396+ res = getRhsExp1(cdr);
1397+ then
1398+ exp::res;
1399+ case (DAE . ALGORITHM (algorithm_ = DAE . ALGORITHM_STMTS ({DAE . STMT_ASSIGN_ARR (exp= exp)})) :: cdr)
1400+ equation
1401+ res = getRhsExp1(cdr);
1402+ then
1403+ exp::res;
1404+ case (_ :: cdr)
1405+ equation
1406+ res = getRhsExp1(cdr);
1407+ then
1408+ res;
1409+ end matchcontinue;
1410+ end getRhsExp1;
1411+
13131412protected function replaceArgs
13141413"function: replaceArgs
13151414 finds DAE.CREF and replaces them with new exps if the cref is in the argmap"
1316- input tuple< DAE . Exp , list< tuple< DAE . ComponentRef ,DAE . Exp >>> inTuple;
1317- output tuple< DAE . Exp , list< tuple< DAE . ComponentRef ,DAE . Exp >>> outTuple;
1415+ input tuple< DAE . Exp , tuple < list< tuple< DAE . ComponentRef ,DAE . Exp >> , HashTableCG . HashTable , Boolean >> inTuple;
1416+ output tuple< DAE . Exp , tuple < list< tuple< DAE . ComponentRef ,DAE . Exp >> , HashTableCG . HashTable , Boolean >> outTuple;
13181417algorithm
13191418 outTuple := matchcontinue(inTuple)
13201419 local
@@ -1327,13 +1426,20 @@ algorithm
13271426 DAE . Type ty,ty2;
13281427 DAE . InlineType inlineType;
13291428 DAE . TailCall tc;
1330- case ((DAE . CREF (componentRef = cref),argmap))
1429+ HashTableCG . HashTable checkcr;
1430+ Boolean replacedfailed;
1431+ case ((DAE . CREF (componentRef = cref),(argmap,checkcr,true )))
13311432 equation
13321433 e = getExpFromArgMap(argmap,cref);
13331434 (e,_) = ExpressionSimplify . simplify(e);
13341435 then
1335- ((e,argmap));
1336- case ((DAE . UNBOX (DAE . CALL (path,expLst,DAE . CALL_ATTR (_,tuple_,false ,inlineType,tc)),ty),argmap))
1436+ ((e,(argmap,checkcr,true )));
1437+ case ((e as DAE . CREF (componentRef = cref),(argmap,checkcr,true )))
1438+ equation
1439+ _ = BaseHashTable . get(cref,checkcr);
1440+ then
1441+ ((e,(argmap,checkcr,false )));
1442+ case ((DAE . UNBOX (DAE . CALL (path,expLst,DAE . CALL_ATTR (_,tuple_,false ,inlineType,tc)),ty),(argmap,checkcr,true )))
13371443 equation
13381444 cref = ComponentReference . pathToCref(path);
13391445 (e as DAE . CREF (componentRef= cref)) = getExpFromArgMap(argmap,cref);
@@ -1343,9 +1449,15 @@ algorithm
13431449 e = DAE . CALL (path,expLst,DAE . CALL_ATTR (ty,tuple_,b,inlineType,tc));
13441450 (e,_) = ExpressionSimplify . simplify(e);
13451451 then
1346- ((e,argmap));
1452+ ((e,(argmap,checkcr,true )));
1453+ case ((e as DAE . UNBOX (DAE . CALL (path,expLst,DAE . CALL_ATTR (_,tuple_,false ,inlineType,tc)),ty),(argmap,checkcr,true )))
1454+ equation
1455+ cref = ComponentReference . pathToCref(path);
1456+ _ = BaseHashTable . get(cref,checkcr);
1457+ then
1458+ ((e,(argmap,checkcr,false )));
13471459 /* TODO: Use the inlineType of the function reference! */
1348- case ((DAE . CALL (path,expLst,DAE . CALL_ATTR (DAE . T_METATYPE (ty = _),tuple_,false ,_,tc)),argmap))
1460+ case ((e as DAE . CALL (path,expLst,DAE . CALL_ATTR (DAE . T_METATYPE (ty = _),tuple_,false ,_,tc)),( argmap,checkcr, true ) ))
13491461 equation
13501462 cref = ComponentReference . pathToCref(path);
13511463 (e as DAE . CREF (componentRef= cref,ty= ty)) = getExpFromArgMap(argmap,cref);
@@ -1356,8 +1468,14 @@ algorithm
13561468 e = DAE . CALL (path,expLst,DAE . CALL_ATTR (ty2,tuple_,b,inlineType,tc));
13571469 e = boxIfUnboxedFunRef(e,ty);
13581470 (e,_) = ExpressionSimplify . simplify(e);
1359- then ((e,argmap));
1360- case ((e,argmap)) then ((e,argmap));
1471+ then ((e,(argmap,checkcr,true )));
1472+ case ((e as DAE . CALL (path,expLst,DAE . CALL_ATTR (DAE . T_METATYPE (ty = _),tuple_,false ,_,tc)),(argmap,checkcr,true )))
1473+ equation
1474+ cref = ComponentReference . pathToCref(path);
1475+ _ = BaseHashTable . get(cref,checkcr);
1476+ then
1477+ ((e,(argmap,checkcr,false )));
1478+ case ((e,(argmap,checkcr,replacedfailed))) then ((e,(argmap,checkcr,replacedfailed)));
13611479 end matchcontinue;
13621480end replaceArgs;
13631481
0 commit comments