Skip to content

Commit

Permalink
Ugly hacks for unelabExp of empty arrays
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18680 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jan 17, 2014
1 parent cd1847b commit f17a938
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -163,6 +163,8 @@ algorithm
Absyn.CodeNode code;
DAE.ReductionIterators riters;
Absyn.ForIterators aiters;
DAE.Type ty;
DAE.Dimensions dims;

case (DAE.ICONST(integer = i)) then Absyn.INTEGER(i);
case (DAE.RCONST(real = r)) then Absyn.REAL(r);
Expand Down Expand Up @@ -232,6 +234,14 @@ algorithm
then
Absyn.PARTEVALFUNCTION(acref,Absyn.FUNCTIONARGS(aexpl,{}));

case (DAE.ARRAY(array = {}, ty = ty))
equation
(ty,dims) = Types.flattenArrayTypeOpt(ty);
ae1 = unleabZeroExpFromType(ty);
expl_1 = List.map(dims, unelabDimensionToFillExp);
then
Absyn.CALL(Absyn.CREF_IDENT("fill",{}),Absyn.FUNCTIONARGS(ae1::expl_1,{}));

case (DAE.ARRAY(array = expl))
equation
expl_1 = List.map(expl, unelabExp);
Expand Down Expand Up @@ -331,6 +341,38 @@ algorithm
end matchcontinue;
end unelabDimension;

protected function unleabZeroExpFromType
input DAE.Type ty;
output Absyn.Exp outExp;
algorithm
outExp := match ty
case DAE.T_BOOL(source=_) then Absyn.BOOL(false);
case DAE.T_STRING(source=_) then Absyn.STRING("");
case DAE.T_INTEGER(source=_) then Absyn.INTEGER(0);
case DAE.T_REAL(source=_) then Absyn.REAL(0.0);
case DAE.T_UNKNOWN(source=_) then Absyn.REAL(0.0); /* Look at the crap unelabMod needs... */
end match;
end unleabZeroExpFromType;

protected function unelabDimensionToFillExp
"Transform an DAE.Dimension into Absyn.Exp, if possible"
input DAE.Dimension inDim;
output Absyn.Exp outExp;
algorithm
outExp := matchcontinue (inDim)
local
Integer i;
DAE.Exp e;

case (DAE.DIM_INTEGER(i)) then Absyn.INTEGER(i);

case (DAE.DIM_EXP(e)) then unelabExp(e);

else Absyn.INTEGER(1); /* Probably bad, but only used with zero-length arrays */

end matchcontinue;
end unelabDimensionToFillExp;

protected function unelabReductionIterator
input DAE.ReductionIterator riter;
output Absyn.ForIterator aiter;
Expand Down

0 comments on commit f17a938

Please sign in to comment.