Skip to content

Commit

Permalink
- enumeration as loop var work now in algorithm sections
Browse files Browse the repository at this point in the history
   - ToDo do not replace the enumeration literals with it integer value
- start work on replaceable enumeration 

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@4694 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Dec 14, 2009
1 parent 83c48e6 commit f91a132
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
9 changes: 9 additions & 0 deletions Compiler/Ceval.mo
Expand Up @@ -698,6 +698,15 @@ algorithm
then
(cache,Values.ARRAY(arr),st_3);

case (cache,env,DAE.RANGE(ty = DAE.ET_ENUMERATION(_,_,_,_),exp = start,expOption = NONE,range = stop),impl,st,dim,msg) /* */
local Option<Integer> dim;
equation
(cache,Values.ENUM(start_1,_,_),st_1) = ceval(cache,env, start, impl, st, dim, msg);
(cache,Values.ENUM(stop_1,_,_),st_2) = ceval(cache,env, stop, impl, st_1, dim, msg);
arr = cevalRange(start_1, 1, stop_1);
then
(cache,Values.ARRAY(arr),st_1);

case (cache,env,DAE.RANGE(ty = DAE.ET_REAL(),exp = start,expOption = NONE,range = stop),impl,st,dim,msg)
local
Real start_1,stop_1,step;
Expand Down
10 changes: 9 additions & 1 deletion Compiler/Mod.mo
Expand Up @@ -191,7 +191,15 @@ algorithm
modElts = elabModRedeclareElements(cache,env,pre,f,elts,impl);
(cache,tp1) = elabModQualifyTypespec(cache,env,tp);
then (SCode.CLASSDEF(cn,fi,repl,SCode.CLASS(cn,p,enc,restr,SCode.DERIVED(tp1,mod,attr1,cmt)),bc,cc),emod)::modElts;

// replaceable type E=enumeration(e1,...,en), E=enumeration(:)
case(cache,env,pre,f,SCode.CLASSDEF(cn,fi,repl,SCode.CLASS(cn2,p,enc,restr,SCode.ENUMERATION(enumLst,comment)),bc,cc)::elts,impl)
local
list<SCode.Enum> enumLst;
Option<SCode.Comment> comment;
Option<Absyn.ConstrainClass> cc;
equation
modElts = elabModRedeclareElements(cache,env,pre,f,elts,impl);
then (SCode.CLASSDEF(cn,fi,repl,SCode.CLASS(cn,p,enc,restr,SCode.ENUMERATION(enumLst,comment)),bc,cc),DAE.NOMOD())::modElts;
// redeclare of component declaration
case(cache,env,pre,f,SCode.COMPONENT(compname,io,fi,repl,prot,attr,tp,mod,bc,cmt,cond,info,cc)::elts,impl) equation
(cache,emod) = elabMod(cache,env,pre,mod,impl);
Expand Down
25 changes: 23 additions & 2 deletions Compiler/Static.mo
Expand Up @@ -1670,8 +1670,18 @@ algorithm
local
DAE.Exp e1,e3,e2,e1_1,e3_1,e2_1;
tuple<DAE.TType, Option<Absyn.Path>> t1,t3,t2;
DAE.ExpType et;
list<String> ns,ne;
case ((e1,(DAE.T_INTEGER(varLstInt = _),_)),NONE,(e3,(DAE.T_INTEGER(varLstInt = _),_))) then (e1,NONE,e3,DAE.ET_INT());
case ((e1,(DAE.T_INTEGER(varLstInt = _),_)),SOME((e2,(DAE.T_INTEGER(_),_))),(e3,(DAE.T_INTEGER(varLstInt = _),_))) then (e1,SOME(e2),e3,DAE.ET_INT());
case ((e1,(DAE.T_INTEGER(varLstInt = _),_)),SOME((e2,(DAE.T_INTEGER(_),_))),(e3,(DAE.T_INTEGER(varLstInt = _),_))) then (e1,SOME(e2),e3,DAE.ET_INT());
// enumeration has no step value
case ((e1,t1 as (DAE.T_ENUMERATION(names = ns),_)),NONE,(e3,(DAE.T_ENUMERATION(names = ne),_)))
equation
// check if enumtyp start and end are equal
true = Util.isListEqual(ns,ne,true);
// convert vars
et = Types.elabType(t1);
then (e1,NONE,e3,et);
case ((e1,t1),NONE,(e3,t3))
equation
({e1_1,e3_1},_) = elabArglist({(DAE.T_REAL({}),NONE),(DAE.T_REAL({}),NONE)},
Expand Down Expand Up @@ -1736,6 +1746,17 @@ algorithm
then
(cache,(
DAE.T_ARRAY(DAE.DIM(SOME(n_2)),(DAE.T_INTEGER({}),NONE)),NONE));
/* enumeration has no step value */
case (cache,env,start,NONE,stop,const,_,impl) /* impl as false */
local list<String> names; Absyn.Path p;
equation
(cache,Values.ENUM(startv,p,names),_) = Ceval.ceval(cache,env, start, impl, NONE, NONE, Ceval.MSG());
(cache,Values.ENUM(stopv,_,_),_) = Ceval.ceval(cache,env, stop, impl, NONE, NONE, Ceval.MSG());
n = stopv - startv;
n_1 = n + 1;
then
(cache,(
DAE.T_ARRAY(DAE.DIM(SOME(n_1)),(DAE.T_ENUMERATION(NONE(),p,names,{}),NONE)),NONE));
case (cache,env,start,NONE,stop,const,_,impl) /* as false */
local Real startv,stopv,n,n_2;
equation
Expand Down Expand Up @@ -10978,7 +10999,7 @@ algorithm
tuple<DAE.TType, Option<Absyn.Path>> t;
Absyn.Exp e;
case ((DAE.T_INTEGER(varLstInt = _),_),_,sub) then DAE.INDEX(sub);
case ((DAE.T_ENUMERATION(SOME(_),_,_,_),_),_,sub) then DAE.INDEX(sub);
case ((DAE.T_ENUMERATION(_,_,_,_),_),_,sub) then DAE.INDEX(sub);
// case ((DAE.T_ENUM(),_),_,sub) then DAE.INDEX(sub);
case ((DAE.T_ARRAY(arrayType = (DAE.T_INTEGER(varLstInt = _),_)),_),_,sub) then DAE.SLICE(sub);
case (t,e,_)
Expand Down

0 comments on commit f91a132

Please sign in to comment.