Skip to content

Commit

Permalink
Added missing DAE.DIM_BOOLEAN (analogous to DIM_ENUM)
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15954 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed May 2, 2013
1 parent 705fc3f commit 51201a0
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 57 deletions.
9 changes: 9 additions & 0 deletions Compiler/FrontEnd/Ceval.mo
Original file line number Diff line number Diff line change
Expand Up @@ -5381,6 +5381,12 @@ algorithm
then
(cache,DAE.INDEX(e1_1));

case (cache,env,DAE.INDEX(exp = e1),dim,impl,msg,_)
equation
(cache,v1 as Values.BOOL(_),_) = ceval(cache,env, e1, impl,NONE(),msg,numIter+1);
e1_1 = ValuesUtil.valueExp(v1);
then (cache,DAE.INDEX(e1_1));

// an expression slice that can be constant evaluated
case (cache,env,DAE.SLICE(exp = e1),dim,impl,msg,_)
equation
Expand Down Expand Up @@ -6855,6 +6861,9 @@ algorithm
case (_, _, DAE.DIM_ENUM(size = dim_int), _, _, _, _)
then (inCache, Values.INTEGER(dim_int), inST);

case (_, _, DAE.DIM_BOOLEAN(), _, _, _, _)
then (inCache, Values.INTEGER(2), inST);

// Dimension given by expression, evaluate the expression.
case (_, _, DAE.DIM_EXP(exp = exp), _, _, _, _)
equation
Expand Down
2 changes: 2 additions & 0 deletions Compiler/FrontEnd/ComponentReference.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2829,6 +2829,8 @@ algorithm
then
List.map(enum_expl, Expression.makeIndexSubscript);

case DAE.DIM_BOOLEAN() then DAE.INDEX(DAE.BCONST(false))::DAE.INDEX(DAE.BCONST(true))::{};

end match;
end expandDimension;

Expand Down
3 changes: 3 additions & 0 deletions Compiler/FrontEnd/DAE.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,9 @@ uniontype Dimension
Integer integer;
end DIM_INTEGER;

record DIM_BOOLEAN "Dimension given by Boolean"
end DIM_BOOLEAN;

record DIM_ENUM "Dimension given by an enumeration."
Absyn.Path enumTypeName "The enumeration type name.";
list<String> literals "A list of the literals in the enumeration.";
Expand Down
26 changes: 10 additions & 16 deletions Compiler/FrontEnd/Expression.mo
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ algorithm

case DAE.DIM_INTEGER(integer = i) then DAE.ICONST(i);
case DAE.DIM_ENUM(size = i) then DAE.ICONST(i);
case DAE.DIM_BOOLEAN() then DAE.ICONST(2);
case DAE.DIM_EXP(exp = e) then e;
end match;
end dimensionSizeExp;
Expand All @@ -509,6 +510,7 @@ algorithm

case DAE.DIM_INTEGER(integer = i) then DAE.INDEX(DAE.ICONST(i));
case DAE.DIM_ENUM(size = i) then DAE.INDEX(DAE.ICONST(i));
case DAE.DIM_BOOLEAN() then DAE.INDEX(DAE.ICONST(2));
case DAE.DIM_UNKNOWN() then DAE.WHOLEDIM();
end match;
end dimensionSubscript;
Expand Down Expand Up @@ -1816,6 +1818,7 @@ algorithm
Integer i;
case DAE.DIM_INTEGER(integer = i) then i;
case DAE.DIM_ENUM(size = i) then i;
case DAE.DIM_BOOLEAN() then 2;
case DAE.DIM_EXP(exp = DAE.ICONST(integer = i)) then i;
case DAE.DIM_EXP(exp = DAE.ENUM_LITERAL(index = i)) then i;
end match;
Expand All @@ -1826,27 +1829,15 @@ public function addDimensions
input DAE.Dimension dim2;
output DAE.Dimension dim;
algorithm
dim := match(dim1,dim2)
dim := matchcontinue (dim1,dim2)
local
Integer i1,i2,i;
case (DAE.DIM_INTEGER(integer = i1),DAE.DIM_INTEGER(integer = i2))
equation
i = i1+i2;
then DAE.DIM_INTEGER(i);
case (DAE.DIM_ENUM(size = i1),DAE.DIM_INTEGER(integer = i2))
equation
i = i1+i2;
then DAE.DIM_INTEGER(i);
case (DAE.DIM_INTEGER(integer = i1),DAE.DIM_ENUM(size = i2))
equation
i = i1+i2;
then DAE.DIM_INTEGER(i);
case (DAE.DIM_ENUM(size = i1),DAE.DIM_ENUM(size = i2))
case (_,_)
equation
i = i1+i2;
i = dimensionSize(dim1)+dimensionSize(dim2);
then DAE.DIM_INTEGER(i);
else DAE.DIM_UNKNOWN();
end match;
end matchcontinue;
end addDimensions;

public function dimensionSizeAll
Expand All @@ -1861,6 +1852,7 @@ algorithm
DAE.Exp e;
case DAE.DIM_INTEGER(integer = i) then i;
case DAE.DIM_ENUM(size = i) then i;
case DAE.DIM_BOOLEAN() then 2;
case DAE.DIM_EXP(exp = e) then expInt(e);
case DAE.DIM_EXP(exp = _)
equation
Expand Down Expand Up @@ -8298,6 +8290,7 @@ algorithm
known := matchcontinue(dim)
case DAE.DIM_UNKNOWN() then false;
case DAE.DIM_EXP(exp = DAE.ICONST(integer = _)) then true;
case DAE.DIM_EXP(exp = DAE.BCONST(bool = _)) then true;
case DAE.DIM_EXP(exp = DAE.ENUM_LITERAL(index = _)) then true;
case DAE.DIM_EXP(exp = _) then false;
case _ then true;
Expand Down Expand Up @@ -8875,6 +8868,7 @@ algorithm
i := match dim
case DAE.DIM_INTEGER(integer=i) then i;
case DAE.DIM_ENUM(size=i) then i;
case DAE.DIM_BOOLEAN() then 2;
else complexityDimLarge;
end match;
end dimComplexity;
Expand Down
2 changes: 2 additions & 0 deletions Compiler/FrontEnd/ExpressionDump.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1636,6 +1636,8 @@ algorithm
then
s;

case DAE.DIM_BOOLEAN() then "Boolean";

case DAE.DIM_INTEGER(integer = x)
equation
s = intString(x);
Expand Down
47 changes: 17 additions & 30 deletions Compiler/FrontEnd/Inst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -9380,35 +9380,8 @@ algorithm
DAE.Dimension dim;

case ({},ty) then ty;
case ((DAE.DIM_INTEGER(integer = i) :: xs),tty)
equation
ty_1 = makeArrayType(xs, tty);
ts = Types.getTypeSource(tty);
then
DAE.T_ARRAY(ty_1,{DAE.DIM_INTEGER(i)},ts);

case ((DAE.DIM_ENUM(size = i) :: xs), tty)
equation
ty_1 = makeArrayType(xs, tty);
ts = Types.getTypeSource(tty);
then
DAE.T_ARRAY(ty_1,{DAE.DIM_INTEGER(i)},ts);

/*case ((DAE.DIM_SUBSCRIPT(subscript = _) :: xs),tty)
equation
ty_1 = makeArrayType(xs, tty);
ts = Types.getTypeSource(tty);
then
DAE.T_ARRAY(ty_1,{DAE.DIM_UNKNOWN()},ts);*/

case (DAE.DIM_UNKNOWN() :: xs, tty)
equation
ty_1 = makeArrayType(xs, tty);
ts = Types.getTypeSource(tty);
then
DAE.T_ARRAY(ty_1, {DAE.DIM_UNKNOWN()}, ts);

case ((dim as DAE.DIM_EXP(exp = _)) :: xs, tty)
case (dim :: xs, tty)
equation
ty_1 = makeArrayType(xs, tty);
ts = Types.getTypeSource(tty);
Expand Down Expand Up @@ -10301,6 +10274,7 @@ algorithm
case (DAE.DIM_UNKNOWN(),_) then DAE.WHOLEDIM();
case (DAE.DIM_INTEGER(integer = i),_) then DAE.INDEX(DAE.ICONST(i));
case (DAE.DIM_ENUM(size = i), _) then DAE.INDEX(DAE.ICONST(i));
case (DAE.DIM_BOOLEAN(), _) then DAE.INDEX(DAE.ICONST(2));
case (DAE.DIM_EXP(exp = e), _) then DAE.INDEX(e);
end match;
end instDimExp;
Expand All @@ -10320,6 +10294,7 @@ algorithm
case (DAE.DIM_UNKNOWN(),_) then DAE.WHOLEDIM();
case (DAE.DIM_INTEGER(integer = i),_) then DAE.WHOLE_NONEXP(DAE.ICONST(i));
case (DAE.DIM_ENUM(size = i), _) then DAE.WHOLE_NONEXP(DAE.ICONST(i));
case (DAE.DIM_BOOLEAN(), _) then DAE.WHOLE_NONEXP(DAE.ICONST(2));
//case (DAE.DIM_EXP(exp = e as DAE.RANGE(exp = _)), _) then DAE.INDEX(e);
case (DAE.DIM_EXP(exp = e), _) then DAE.WHOLE_NONEXP(e);
end match;
Expand Down Expand Up @@ -10703,13 +10678,13 @@ algorithm
DAE.Exp e,lhs,rhs;
DAE.Properties p;
Env.Cache cache;
Env.Env env_1,env,compenv;
Env.Env env_1,env_2,env,compenv;
Connect.Sets csets;
DAE.Type ty;
ClassInf.State st,ci_state;
DAE.ComponentRef cr;
DAE.Type ty_1;
DAE.Mod mod,mod_1;
DAE.Mod mod,mod_1,mod_2;
Prefix.Prefix pre;
String n, str1, str2, str3, str4;
SCode.Element cl;
Expand Down Expand Up @@ -10865,6 +10840,18 @@ algorithm
then
(cache,env,ih,store,DAEUtil.emptyDae,csets,DAE.T_UNKNOWN_DEFAULT,graph);

case (cache, env, ih, store, ci_state, mod, pre, n, (cl, attr), pf, i, DAE.DIM_BOOLEAN(), dims, idxs, inst_dims, impl, comment, _, graph, csets)
equation
mod_1 = Mod.lookupIdxModification(mod, i);
mod_2 = Mod.lookupIdxModification(mod, i+1);
(cache, env_1, ih, store, dae1, csets, ty, graph) =
instVar2(cache, env, ih, store, ci_state, mod_1, pre, n, cl, attr, pf, dims, (DAE.INDEX(DAE.BCONST(false)) :: idxs), inst_dims, impl, comment, info, graph, csets);
(cache, _, ih, store, dae2, csets, ty, graph) =
instVar2(cache, env, ih, store, ci_state, mod_2, pre, n, cl, attr, pf, dims, (DAE.INDEX(DAE.BCONST(true)) :: idxs), inst_dims, impl, comment, info, graph, csets);
daeLst = DAEUtil.joinDaes(dae1, dae2);
then
(cache, env_1, ih, store, daeLst, csets, ty, graph);

case (cache,env,ih,store,ci_state,mod,pre,n,(cl,attr),pf,i,_,dims,idxs,inst_dims,impl,comment,_,graph,_)
equation
failure(_ = Mod.lookupIdxModification(mod, i));
Expand Down
5 changes: 5 additions & 0 deletions Compiler/FrontEnd/InstSection.mo
Original file line number Diff line number Diff line change
Expand Up @@ -4532,6 +4532,11 @@ algorithm
expl = List.map1(ints, makeAsubIndex, inArray);
then
expl;
case (DAE.DIM_BOOLEAN(), _)
equation
expl = DAE.BCONST(false)::DAE.BCONST(true)::{};
then
expl;
case (DAE.DIM_ENUM(enumTypeName = name, literals = ls), _)
equation
expl = makeEnumLiteralIndices(name, ls, 1, inArray);
Expand Down
5 changes: 5 additions & 0 deletions Compiler/FrontEnd/Lookup.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2890,6 +2890,11 @@ algorithm
expl = List.map(List.intRange(sz), Expression.makeIntegerExp);
then
DAE.SLICE(DAE.ARRAY(DAE.T_INTEGER_DEFAULT, true, expl));
case DAE.DIM_BOOLEAN()
equation
expl = DAE.BCONST(false)::DAE.BCONST(true)::{};
then
DAE.SLICE(DAE.ARRAY(DAE.T_BOOL_DEFAULT, true, expl));
// Array with enumeration dimension.
case DAE.DIM_ENUM(enumTypeName = enum_name, literals = l, size = sz)
equation
Expand Down
18 changes: 7 additions & 11 deletions Compiler/FrontEnd/Static.mo
Original file line number Diff line number Diff line change
Expand Up @@ -11666,8 +11666,7 @@ algorithm
case (_,_,_,_,_,pre,_)
equation
ErrorExt.setCheckpoint("elabSubscriptsDims");
(outCache, outSubs, outConst) = elabSubscriptsDims2(cache, env, subs,
dims, impl, pre, info, DAE.C_CONST(), {});
(outCache, outSubs, outConst) = elabSubscriptsDims2(cache, env, subs, dims, impl, pre, info, DAE.C_CONST(), {});
ErrorExt.rollBack("elabSubscriptsDims");
then (outCache,outSubs,outConst);

Expand Down Expand Up @@ -11718,14 +11717,11 @@ algorithm

case (_, _, asub :: rest_asub, dim :: rest_dims, _, _, _, _, _)
equation
(cache, dsub, const, prop) = elabSubscript(inCache, inEnv, asub, inImpl,
inPrefix, inInfo);
(cache, dsub, const, prop) = elabSubscript(inCache, inEnv, asub, inImpl, inPrefix, inInfo);
const = Types.constAnd(const, inConst);
(cache, dsub) = elabSubscriptsDims3(cache, inEnv, dsub, dim,
const, prop, inImpl, inInfo);
(cache, dsub) = elabSubscriptsDims3(cache, inEnv, dsub, dim, const, prop, inImpl, inInfo);
elabed_subs = dsub :: inElabSubscripts;
(cache, elabed_subs, const) = elabSubscriptsDims2(cache, inEnv,
rest_asub, rest_dims, inImpl, inPrefix, inInfo, const, elabed_subs);
(cache, elabed_subs, const) = elabSubscriptsDims2(cache, inEnv, rest_asub, rest_dims, inImpl, inPrefix, inInfo, const, elabed_subs);
then
(cache, elabed_subs, const);

Expand Down Expand Up @@ -11906,6 +11902,7 @@ algorithm

case (DAE.T_INTEGER(varLst = _),_,sub,_,_) then DAE.INDEX(sub);
case (DAE.T_ENUMERATION(path = _),_,sub,_,_) then DAE.INDEX(sub);
case (DAE.T_BOOL(varLst = _),_,sub,_,_) then DAE.INDEX(sub);
case (DAE.T_ARRAY(ty = DAE.T_INTEGER(varLst = _)),_,sub,_,_) then DAE.SLICE(sub);

// Modelica.Electrical.Analog.Lines.M_OLine.segment in MSL 3.1 uses a real
Expand Down Expand Up @@ -14328,10 +14325,9 @@ algorithm
then
(inCache, dim);

case (_, _, _, Absyn.SUBSCRIPT(subscript = Absyn.CREF(componentRef =
Absyn.CREF_IDENT(name = "Boolean"))), _, _, _, _, _)
case (_, _, _, Absyn.SUBSCRIPT(subscript = Absyn.CREF(componentRef = Absyn.CREF_IDENT(name = "Boolean"))), _, _, _, _, _)
then
(inCache, DAE.DIM_INTEGER(2));
(inCache, DAE.DIM_BOOLEAN());

// Array dimension from an enumeration.
case (_, _, _, Absyn.SUBSCRIPT(subscript = Absyn.CREF(cr)), _, _, _, _, _)
Expand Down
17 changes: 17 additions & 0 deletions Compiler/FrontEnd/Types.mo
Original file line number Diff line number Diff line change
Expand Up @@ -4978,6 +4978,15 @@ algorithm
DAE.PROP(t,c) = matchWithPromote(DAE.PROP(t1,c1), DAE.PROP(t2,c2), havereal);
then
DAE.PROP(DAE.T_ARRAY(t,{dim},ts2),c);
// match boolean, second
case (DAE.PROP(type_ = t1,constFlag = c1),
DAE.PROP(type_ = DAE.T_ARRAY(dims = {dim as DAE.DIM_BOOLEAN()},ty = t2, source = ts2),constFlag = c2),
havereal)
equation
false = isArray(t1,{});
DAE.PROP(t,c) = matchWithPromote(DAE.PROP(t1,c1), DAE.PROP(t2,c2), havereal);
then
DAE.PROP(DAE.T_ARRAY(t,{dim},ts2),c);
// match integer, first
case (DAE.PROP(type_ = DAE.T_ARRAY(dims = {DAE.DIM_INTEGER(1)},ty = t1, source = ts),constFlag = c1),
DAE.PROP(type_ = t2,constFlag = c2),havereal)
Expand All @@ -4994,6 +5003,14 @@ algorithm
DAE.PROP(t,c) = matchWithPromote(DAE.PROP(t1,c1), DAE.PROP(t2,c2), havereal);
then
DAE.PROP(DAE.T_ARRAY(t,{dim},ts),c);
// match boolean, first
case (DAE.PROP(type_ = DAE.T_ARRAY(dims = {dim as DAE.DIM_BOOLEAN()},ty = t1, source = ts),constFlag = c1),
DAE.PROP(type_ = t2,constFlag = c2),havereal)
equation
false = isArray(t2,{});
DAE.PROP(t,c) = matchWithPromote(DAE.PROP(t1,c1), DAE.PROP(t2,c2), havereal);
then
DAE.PROP(DAE.T_ARRAY(t,{dim},ts),c);
// equal types
case (DAE.PROP(type_ = t1,constFlag = c1),
DAE.PROP(type_ = t2,constFlag = c2),false)
Expand Down
1 change: 1 addition & 0 deletions Compiler/Template/CodegenC.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6524,6 +6524,7 @@ template threadDimSubList(list<Dimension> dims, list<Subscript> subs, Context co
dimrest |> dim =>
match dim
case DIM_INTEGER(__) then '*<%integer%>'
case DIM_BOOLEAN(__) then '*2'
case DIM_ENUM(__) then '*<%size%>'
else error(sourceInfo(),"Non-constant dimension in simulation context")
%>)<%match subrest case {} then "" else '+<%threadDimSubList(dimrest,subrest,context,&preExp,&varDecls)%>'%>'
Expand Down
3 changes: 3 additions & 0 deletions Compiler/Template/SimCodeTV.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,9 @@ package DAE
Integer integer;
end DIM_INTEGER;

record DIM_BOOLEAN
end DIM_BOOLEAN;

record DIM_ENUM
Absyn.Path enumTypeName;
list<String> literals;
Expand Down

0 comments on commit 51201a0

Please sign in to comment.