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

Commit

Permalink
Fix listArrayLiteral
Browse files Browse the repository at this point in the history
The functionality had some bad logic previously that caused it to give
unexpected results (such as giving an array of size 1 when size 3 as
expected). listArrayLiteral now always contains one argument of size 1
which has a List type.

Belonging to [master]:
  - #2325
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Mar 28, 2018
1 parent 7199ae1 commit 11aa135
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
29 changes: 29 additions & 0 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -13190,5 +13190,34 @@ algorithm
end match;
end isSimpleLiteralValue;

public function consToListIgnoreSharedLiteral
input output DAE.Exp e;
protected
DAE.Exp exp;
algorithm
if match e
case DAE.SHARED_LITERAL() then true;
case DAE.LIST() then true;
case DAE.CONS() then true;
else false; end match then
try
e := consToListIgnoreSharedLiteralWork(e);
else
end try;
end if;
end consToListIgnoreSharedLiteral;

protected function consToListIgnoreSharedLiteralWork
input output DAE.Exp e;
input list<DAE.Exp> acc={};
algorithm
e := match (e,acc)
case (DAE.SHARED_LITERAL(),_) then consToListIgnoreSharedLiteralWork(e.exp, acc);
case (DAE.LIST(),{}) then e;
case (DAE.LIST(),_) then DAE.LIST(List.append_reverse(acc, e.valList));
case (DAE.CONS(),_) then consToListIgnoreSharedLiteralWork(e.cdr, e.car::acc);
end match;
end consToListIgnoreSharedLiteralWork;

annotation(__OpenModelica_Interface="frontend");
end Expression;
11 changes: 11 additions & 0 deletions Compiler/FrontEnd/Types.mo
Expand Up @@ -1184,6 +1184,17 @@ algorithm
ts = List.mapMap(vs, typeOfValue, boxIfUnboxedType);
then DAE.T_METATUPLE(ts);

case Values.META_ARRAY(valueLst = (v :: vs))
equation
tp = boxIfUnboxedType(typeOfValue(v));
tp = DAE.T_METAARRAY(tp);
then tp;

case Values.META_ARRAY(valueLst = {})
equation
tp = DAE.T_METAARRAY(DAE.T_UNKNOWN_DEFAULT);
then tp;

case Values.META_BOX(v)
equation
tp = typeOfValue(v);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/ValuesUtil.mo
Expand Up @@ -926,7 +926,7 @@ algorithm
typelist = List.map(vallist, Types.typeOfValue);
vt = Types.boxIfUnboxedType(List.reduce(typelist,Types.superType));
(explist,_) = Types.matchTypes(explist, typelist, vt, true);
then Expression.makeBuiltinCall("listArrayLiteral", explist, DAE.T_METAARRAY(vt), false);
then Expression.makeBuiltinCall("listArrayLiteral", {DAE.LIST(explist)}, DAE.T_METAARRAY(vt), false);

/* MetaRecord */
case (Values.RECORD(path,vallist,namelst,ix))
Expand Down
5 changes: 4 additions & 1 deletion Compiler/Template/CodegenCFunctions.tpl
Expand Up @@ -3431,13 +3431,16 @@ template literalExpConst(Exp lit, Integer litindex) "These should all be declare
%>static const MMC_DEFSTRUCTLIT(<%tmp%>,<%intAdd(1,listLength(args))%>,<%newIndex%>) {&<%underscorePath(path)%>__desc,<%args |> exp hasindex i0 => literalExpConstBoxedVal(exp,litindex+"_"+i0); separator=","%>}};
#define <%name%> MMC_REFSTRUCTLIT(<%tmp%>)
>>
case CALL(path=IDENT(name="listArrayLiteral"), expLst=args) then
case CALL(path=IDENT(name="listArrayLiteral"), expLst={e}) then
/* We need to use #define's to be C-compliant. Yea, total crap :) */
match consToListIgnoreSharedLiteral(e)
case LIST(valList=args) then
<<
<%args |> exp hasindex i0 => literalExpConstBoxedValPreLit(exp,litindex+"_"+i0) ; empty
%>static const MMC_DEFSTRUCTLIT(<%tmp%>,<%listLength(args)%>,MMC_ARRAY_TAG) {<%args |> exp hasindex i0 => literalExpConstBoxedVal(exp,litindex+"_"+i0); separator=","%>}};
#define <%name%> MMC_REFSTRUCTLIT(<%tmp%>)
>>
else error(sourceInfo(), 'literalExpConst failed; listArrayLiteral requires a list or cons-cells: <%ExpressionDumpTpl.dumpExp(e,"\"")%>')
else error(sourceInfo(), 'literalExpConst failed: <%ExpressionDumpTpl.dumpExp(lit,"\"")%>')
end literalExpConst;

Expand Down
6 changes: 6 additions & 0 deletions Compiler/Template/SimCodeTV.mo
Expand Up @@ -3419,6 +3419,12 @@ package Expression
input DAE.ClockKind inClk;
output DAE.Exp outIntvl;
end getClockInterval;

function consToListIgnoreSharedLiteral
input DAE.Exp e1;
output DAE.Exp ee;
end consToListIgnoreSharedLiteral;

end Expression;

package ExpressionDump
Expand Down

0 comments on commit 11aa135

Please sign in to comment.