From f91a132851ae26f877218c0c4beb93bc3a18a61e Mon Sep 17 00:00:00 2001 From: Jens Frenkel Date: Mon, 14 Dec 2009 23:07:59 +0000 Subject: [PATCH] - enumeration as loop var work now in algorithm sections - 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 --- Compiler/Ceval.mo | 9 +++++++++ Compiler/Mod.mo | 10 +++++++++- Compiler/Static.mo | 25 +++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/Compiler/Ceval.mo b/Compiler/Ceval.mo index 82ede7b0cc5..44be1a304c3 100644 --- a/Compiler/Ceval.mo +++ b/Compiler/Ceval.mo @@ -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 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; diff --git a/Compiler/Mod.mo b/Compiler/Mod.mo index 78d58a857eb..6cfe34249b1 100644 --- a/Compiler/Mod.mo +++ b/Compiler/Mod.mo @@ -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 enumLst; + Option comment; + Option 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); diff --git a/Compiler/Static.mo b/Compiler/Static.mo index 74fd28720d7..17185691e38 100644 --- a/Compiler/Static.mo +++ b/Compiler/Static.mo @@ -1670,8 +1670,18 @@ algorithm local DAE.Exp e1,e3,e2,e1_1,e3_1,e2_1; tuple> t1,t3,t2; + DAE.ExpType et; + list 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)}, @@ -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 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 @@ -10978,7 +10999,7 @@ algorithm tuple> 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,_)