Skip to content

Commit

Permalink
Fix listAppend usage to get rid of some warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
perost authored and OpenModelica-Hudson committed Mar 15, 2016
1 parent a5957dc commit 91127f1
Show file tree
Hide file tree
Showing 21 changed files with 386 additions and 495 deletions.
37 changes: 14 additions & 23 deletions Compiler/BackEnd/UnitCheck.mo
Expand Up @@ -1016,29 +1016,20 @@ protected function foldCallArg "help-function for CALL case in function insertUn
input HashTableCrToUnit.HashTable inHtCr2U;
input HashTableStringToUnit.HashTable inHtS2U;
input HashTableUnitToString.HashTable inHtU2S;
output HashTableCrToUnit.HashTable outHtCr2U;
output HashTableStringToUnit.HashTable outHtS2U;
output HashTableUnitToString.HashTable outHtU2S;
output list<list<tuple<DAE.Exp, Unit.Unit>>> outExpListList;
output HashTableCrToUnit.HashTable outHtCr2U = inHtCr2U;
output HashTableStringToUnit.HashTable outHtS2U = inHtS2U;
output HashTableUnitToString.HashTable outHtU2S = inHtU2S;
output list<list<tuple<DAE.Exp, Unit.Unit>>> outExpListList = {};
protected
list<list<tuple<DAE.Exp, Unit.Unit>>> expListList;
algorithm
(outHtCr2U, outHtS2U, outHtU2S, outExpListList) := match(inExpList, inHtCr2U, inHtS2U, inHtU2S)
local
DAE.Exp exp1;
list<DAE.Exp> rest;
list<list<tuple<DAE.Exp, Unit.Unit>>> expListList, expListList2;
HashTableCrToUnit.HashTable HtCr2U;
HashTableStringToUnit.HashTable HtS2U;
HashTableUnitToString.HashTable HtU2S;

case ({}, _, _, _)
then (inHtCr2U, inHtS2U, inHtU2S, {});
for exp in inExpList loop
(_, (outHtCr2U, outHtS2U, outHtU2S), expListList) :=
insertUnitInEquation(exp, (outHtCr2U, outHtS2U, outHtU2S), Unit.MASTER({}));
outExpListList := List.append_reverse(expListList, outExpListList);
end for;

case (exp1::rest, _, _, _) equation
(_, (HtCr2U, HtS2U, HtU2S), expListList) = insertUnitInEquation(exp1, (inHtCr2U, inHtS2U, inHtU2S), Unit.MASTER({}));
(HtCr2U, HtS2U, HtU2S, expListList2) = foldCallArg(rest, HtCr2U, HtS2U, HtU2S);
expListList = listAppend(expListList, expListList2);
then (HtCr2U, HtS2U, HtU2S, expListList);
end match;
outExpListList := listReverse(outExpListList);
end foldCallArg;

//
Expand Down Expand Up @@ -1093,8 +1084,8 @@ algorithm
then (true, ut, HtCr2U);

case (Unit.MASTER(lcr), Unit.MASTER(lcr2), _) equation
lcr = listAppend(lcr, lcr2);
then (true, Unit.MASTER(lcr), inHtCr2U);
lcr2 = listAppend(lcr, lcr2);
then (true, Unit.MASTER(lcr2), inHtCr2U);

case (Unit.UNKNOWN(s), Unit.UNKNOWN(s2), _) equation
true = stringEqual(s, s2);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FFrontEnd/FNode.mo
Expand Up @@ -402,7 +402,7 @@ protected
Ref r;
algorithm
FCore.N(n, id, p, c, FCore.FS(it)) := fromRef(ref);
it := listAppend(it, inIterators);
it := listAppend(inIterators, it);
// update the child
r := updateRef(ref, FCore.N(n, id, p, c, FCore.FS(it)));
end addIteratorsToRef;
Expand Down
28 changes: 10 additions & 18 deletions Compiler/FrontEnd/Absyn.mo
Expand Up @@ -3153,11 +3153,10 @@ algorithm
list<Subscript> subs;
String id;
ComponentRef cr;

case (CREF_IDENT(id,subs),_)
equation
subs = listAppend(subs,i);
then
CREF_IDENT(id,subs);
then CREF_IDENT(id, listAppend(subs, i));

case (CREF_QUAL(id,subs,cr),_)
equation
cr = addSubscriptsLast(cr,i);
Expand Down Expand Up @@ -3466,9 +3465,8 @@ algorithm
equation
crefs1 = getCrefsFromSubs(subs,includeSubs,includeFunctions);
crefs = getCrefFromExp(exp,includeSubs,includeFunctions);
crefs = listAppend(crefs,crefs1);
then
crefs;
listAppend(crefs,crefs1);
end match;
end getCrefsFromSubs;

Expand Down Expand Up @@ -3544,15 +3542,12 @@ algorithm
then
res;

// TODO: Handle else if-branches.
case (IFEXP(ifExp = e1,trueBranch = e2,elseBranch = e3),_,_)
equation
l1 = getCrefFromExp(e1,includeSubs,includeFunctions);
l2 = getCrefFromExp(e2,includeSubs,includeFunctions);
l1 = listAppend(l1, l2);
l2 = getCrefFromExp(e3,includeSubs,includeFunctions);
res = listAppend(l1, l2) "TODO elseif\'s e4";
then
res;
then List.flatten({
getCrefFromExp(e1, includeSubs, includeFunctions),
getCrefFromExp(e2, includeSubs, includeFunctions),
getCrefFromExp(e3, includeSubs, includeFunctions)});

case (CALL(function_ = cr, functionArgs = farg),_,_)
equation
Expand Down Expand Up @@ -6249,10 +6244,7 @@ algorithm
end while;

if changed then
outList := listReverse(outList);
if not outContinue then
outList := listAppend(outList, rest_e);
end if;
outList := List.append_reverse(outList, rest_e);
else
outList := inList;
end if;
Expand Down
46 changes: 19 additions & 27 deletions Compiler/FrontEnd/ComponentReference.mo
Expand Up @@ -1656,29 +1656,33 @@ end crefRest;
public function crefTypeFull2
"Helper function to crefTypeFull."
input DAE.ComponentRef inCref;
input list<DAE.Dimension> accumDims = {};
output DAE.Type outType;
output list<DAE.Dimension> outDims;
algorithm
(outType, outDims) := match(inCref)
local
DAE.ComponentRef cr;
DAE.Type ty, basety;
list<DAE.Dimension> dims, restdims;
list<DAE.Dimension> dims;
list<DAE.Subscript> subs;

case DAE.CREF_IDENT(identType = ty, subscriptLst = subs)
equation
(ty,dims) = Types.flattenArrayType(ty);
dims = List.stripN(dims,listLength(subs));
then (ty,dims);
dims = List.stripN(dims, listLength(subs));

if not listEmpty(accumDims) then
dims = listReverse(List.append_reverse(dims, accumDims));
end if;
then (ty, dims);

case DAE.CREF_QUAL(identType = ty, subscriptLst = subs, componentRef = cr)
equation
(ty,dims) = Types.flattenArrayType(ty);
dims = List.stripN(dims,listLength(subs));

(basety, restdims) = crefTypeFull2(cr);
dims = listAppend(dims, restdims);
(basety, dims) = crefTypeFull2(cr, List.append_reverse(dims, accumDims));
then (basety, dims);

else
Expand Down Expand Up @@ -2296,7 +2300,7 @@ algorithm
case (DAE.CREF_IDENT(ident = id, subscriptLst = subs, identType = ty), _)
equation
new_sub = DAE.INDEX(DAE.ICONST(inSubscript));
subs = listAppend(subs, {new_sub});
subs = List.appendElt(new_sub, subs);
ty = Expression.unliftArray(ty);
then
makeCrefIdent(id, ty, subs);
Expand Down Expand Up @@ -2444,9 +2448,8 @@ algorithm
case(DAE.CREF_QUAL(name,identType,subs,child),_)
equation
true = (listLength(Expression.arrayTypeDimensions(identType)) >= (listLength(subs)+1));
subs = listAppend(subs,newSub);
then
makeCrefQual(name,identType,subs,child);
makeCrefQual(name, identType, listAppend(subs, newSub), child);

// DAE.CREF_QUAL without DAE.SLICE, search child
case(DAE.CREF_QUAL(name,identType,subs,child),_)
Expand Down Expand Up @@ -3126,7 +3129,7 @@ algorithm
crefs2 = listReverse(crefs2);
// crefs2 = List.map1(crefs2,crefSetType,correctTy);
// Create all combinations of the two lists.
crefs = expandCrefQual(crefs2, crefs, {});
crefs = expandCrefQual(crefs2, crefs);
then
crefs;

Expand Down Expand Up @@ -3167,31 +3170,20 @@ algorithm
end match;
end expandCrefLst;


protected function expandCrefQual
"Helper function to expandCref_impl. Constructs all combinations of the head
and rest cref lists. E.g.:
expandCrefQual({x, y}, {a, b}) => {x.a, x.b, y.a, y.b} "
input list<DAE.ComponentRef> inHeadCrefs;
input list<DAE.ComponentRef> inRestCrefs;
input list<DAE.ComponentRef> inAccumCrefs;
output list<DAE.ComponentRef> outCrefs;
output list<DAE.ComponentRef> outCrefs = {};
protected
list<DAE.ComponentRef> crefs;
algorithm
outCrefs := match(inHeadCrefs, inRestCrefs, inAccumCrefs)
local
list<DAE.ComponentRef> crefs, rest_crefs;
DAE.ComponentRef cref;

case (cref :: rest_crefs, _, _)
equation
crefs = List.map1r(inRestCrefs, joinCrefs, cref);
crefs = listAppend(crefs, inAccumCrefs);
then
expandCrefQual(rest_crefs, inRestCrefs, crefs);

else inAccumCrefs;

end match;
for cref in inHeadCrefs loop
crefs := list(joinCrefs(cref, rest_cref) for rest_cref in inRestCrefs);
outCrefs := listAppend(crefs, outCrefs);
end for;
end expandCrefQual;

protected function expandCref2
Expand Down
5 changes: 2 additions & 3 deletions Compiler/FrontEnd/ConnectionGraph.mo
Expand Up @@ -769,10 +769,9 @@ algorithm
// see both ways!
b1 = listMember((sc1, sc2), inUserSelectedBreaking);
b2 = listMember((sc2, sc1), inUserSelectedBreaking);
if (boolOr(b1, b2))
then
if b1 or b2 then
// put them at the end to be tried last (more chance to be broken)
ordered = listAppend(ordered, {e});
ordered = List.appendElt(e, ordered);
else
// put them at the front to be tried first (less chance to be broken)
ordered = e::ordered;
Expand Down

0 comments on commit 91127f1

Please sign in to comment.