Skip to content

Commit

Permalink
- enumerations part 2, new c-code generation, testcases
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@4477 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Nov 9, 2009
1 parent 20c43af commit 90c054d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
18 changes: 12 additions & 6 deletions Compiler/Codegen.mo
Expand Up @@ -5930,6 +5930,11 @@ algorithm
then
(cEmptyFunction,cref_str,tnr);

case (cref as Exp.CREF_IDENT(_, Exp.ENUMERATION(SOME(idx), _, names, _), _),Exp.ENUMERATION(_,_,_,_),tnr,context)
local Integer idx; list<String> names; String name;
equation
cref_str = intString(idx);
then (cEmptyFunction,cref_str,tnr);
case (cref,crt,tnr,context)
equation
(cref_str,{}) = compRefCstr(cref);
Expand Down Expand Up @@ -6327,19 +6332,20 @@ algorithm
Lib id,cref_str,cref_str_1;
list<Exp.Subscript> subs,cref_subs,subs_1;
Exp.ComponentRef cref;
case Exp.CREF_IDENT(ident = id, identType = Exp.ENUMERATION(_,_,_,_), subscriptLst = subs)
local list<String> strlst, strlst1;
case Exp.CREF_IDENT(ident = id, identType = Exp.ENUMERATION(SOME(idx),_,_,_), subscriptLst = subs)
local Integer idx;
equation
// no dots
cref_str_1 = Util.stringReplaceChar(id, ".", "_");
cref_str_1 = intString(idx);
then
(cref_str_1,subs);
case Exp.CREF_QUAL(id, _, {}, Exp.CREF_IDENT(id1, Exp.ENUMERATION(_,_,_,_), {}))
case Exp.CREF_QUAL(id, Exp.ENUMERATION(_,_,_,_), subs, cref)
local Lib id1;
equation
cref_str = Util.stringAppendList({id, "_",id1});
(cref_str,cref_subs) = compRefCstr(cref);
subs_1 = Util.listFlatten({subs,cref_subs});
then
(cref_str,{});
(cref_str,subs_1);
case Exp.CREF_IDENT(ident = id,subscriptLst = subs) then (id,subs);
case Exp.CREF_QUAL(ident = id,subscriptLst = subs,componentRef = cref)
equation
Expand Down
3 changes: 1 addition & 2 deletions Compiler/Exp.mo
Expand Up @@ -7109,8 +7109,7 @@ algorithm
Ident s,str,strrest,str_1,str_2;
list<Subscript> subs;
ComponentRef cr;
Type ty;

Type ty;
case (CREF_IDENT(ident = s,identType = ty,subscriptLst = {}))
then s; /* optimize */
case CREF_IDENT(ident = s,identType = ty, subscriptLst = subs)
Expand Down
16 changes: 8 additions & 8 deletions Compiler/SimCodegen.mo
Expand Up @@ -215,7 +215,7 @@ algorithm
(s_code2,nres) = generateInitialValueCode2(dlow2,ass1,ass2);
(s_code3) = generateInitialBoundParameterCode(dlow2);
cglobal = generateGlobalData(class_, dlow2, n_o, n_i, n_h, nres,fileDir); // CHANGED!!!
cenum = generateEnumDefinitions(dlow2);
cenum = ""; //generateEnumDefinitions(dlow2);
coutput = generateComputeOutput(cname, dae, dlow2, ass1, ass2,m,mt, blt_no_states);
cstate = generateComputeResidualState(cname, dae, dlow2, ass1, ass2, blt_states);
c_ode = generateOdeCode(dlow2, blt_states, ass1, ass2, m, mt, class_);
Expand Down Expand Up @@ -8807,14 +8807,14 @@ algorithm

case (Exp.BCONST(bool = true),_) then "true";


case (Exp.CREF(componentRef = c, ty = Exp.ENUMERATION(_,_,_,_)),_)
equation
res = Exp.printComponentRefStr(c);
res = Util.stringReplaceChar(res, ".", "_");
case (Exp.CREF(Exp.CREF_IDENT(_,Exp.ENUMERATION(SOME(idx),_,_,_),_),_),_)
local Integer idx;
then intString(idx);
case (Exp.CREF(Exp.CREF_QUAL(_,ty as Exp.ENUMERATION(_,_,_,_),_,c),_),pri1)
equation
res = printExp2Str(Exp.CREF(c, ty),pri1);
then
res;

res;
case (Exp.CREF(componentRef = c),_)
equation
res = Exp.printComponentRefStr(c);
Expand Down
11 changes: 9 additions & 2 deletions Compiler/Types.mo
Expand Up @@ -1421,7 +1421,14 @@ algorithm
case (Values.REAL(real = _)) then ((T_REAL({}),NONE));
case (Values.STRING(string = _)) then ((T_STRING({}),NONE));
case (Values.BOOL(boolean = _)) then ((T_BOOL({}),NONE));
case (Values.ENUM(value = _)) then ((T_ENUMERATION(SOME(0),Absyn.IDENT(""),{},{}),NONE));
case (Values.ENUM(Exp.CREF_IDENT(_, Exp.ENUMERATION(index, path, names, _), _),_))
local Option<Integer> index; Absyn.Path path; list<String> names;
then ((T_ENUMERATION(index,path,names,{}),NONE));
case (Values.ENUM(Exp.CREF_QUAL(_, _, _, cref), val))
local Exp.ComponentRef cref; Integer val;
equation
tp = typeOfValue(Values.ENUM(cref,val));
then tp;
// case (Values.ENUM(value = _)) then ((T_ENUM(),NONE));
case ((w as Values.ARRAY(valueLst = (v :: vs))))
equation
Expand Down Expand Up @@ -2883,7 +2890,7 @@ algorithm
((T_ENUMERATION(_,_,strs,{}),_)) = makeEnumerationType(p, xs);
then
// ((T_ENUMERATION(NONE(),Absyn.IDENT(""),(name :: strs),{}),SOME(p)));
((T_ENUMERATION(NONE(),p,(name :: strs),{}),SOME(p)));
((T_ENUMERATION(NONE(),Absyn.IDENT(""),(name :: strs),{}),SOME(p)));
case (p,{}) then ((T_ENUMERATION(NONE(),Absyn.IDENT(""),{},{}),SOME(p)));
end matchcontinue;
end makeEnumerationType;
Expand Down

0 comments on commit 90c054d

Please sign in to comment.