Skip to content

Commit

Permalink
enumerations part 1
Browse files Browse the repository at this point in the history
- what does not work
    -  redeclaration
    -  Integer(Enumeration)
    -  String(Enumeration)
    -  ... (perhaps more i have not yet finished all enumeration testcases)  

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@4464 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Nov 6, 2009
1 parent 4716949 commit ddcdd1d
Show file tree
Hide file tree
Showing 17 changed files with 914 additions and 212 deletions.
42 changes: 26 additions & 16 deletions Compiler/Ceval.mo
Expand Up @@ -4127,29 +4127,34 @@ algorithm
case (Values.BOOL(boolean = _),Exp.LESS(ty = Exp.BOOL()),Values.BOOL(boolean = _)) then Values.BOOL(false);

/* Enumerations */
case (Values.ENUM(cr1,i1),Exp.LESS(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
case (Values.ENUM(cr1,i1),Exp.LESS(ty = Exp.ENUMERATION(index = SOME(_))),Values.ENUM(cr2,i2))
// case (Values.ENUM(cr1,i1),Exp.LESS(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
equation
b = (i1 < i2);
then
Values.BOOL(b);
case (Values.ENUM(cr1,i1),Exp.LESSEQ(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
case (Values.ENUM(cr1,i1),Exp.LESSEQ(ty = Exp.ENUMERATION(index = SOME(_))),Values.ENUM(cr2,i2))
// case (Values.ENUM(cr1,i1),Exp.LESSEQ(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
equation
b = (i1 <= i2);
then
Values.BOOL(b);
case (Values.ENUM(cr1,i1),Exp.GREATEREQ(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
case (Values.ENUM(cr1,i1),Exp.GREATEREQ(ty = Exp.ENUMERATION(index = SOME(_))),Values.ENUM(cr2,i2))
// case (Values.ENUM(cr1,i1),Exp.GREATEREQ(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
equation
b = (i1 >= i2);
then
Values.BOOL(b);
case (Values.ENUM(cr1,i1),Exp.EQUAL(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
case (Values.ENUM(cr1,i1),Exp.EQUAL(ty = Exp.ENUMERATION(index = SOME(_))),Values.ENUM(cr2,i2))
// case (Values.ENUM(cr1,i1),Exp.EQUAL(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
equation
ba = Exp.crefEqual(cr1, cr2);
bb = (i1 == i2);
b = boolAnd(ba, bb);
then
Values.BOOL(b);
case (Values.ENUM(cr1,i1),Exp.NEQUAL(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
case (Values.ENUM(cr1,i1),Exp.NEQUAL(ty = Exp.ENUMERATION(index = SOME(_))),Values.ENUM(cr2,i2))
// case (Values.ENUM(cr1,i1),Exp.NEQUAL(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
equation
ba = boolNot(Exp.crefEqual(cr1, cr2));
bb = (i1 <> i2);
Expand Down Expand Up @@ -4364,17 +4369,22 @@ algorithm
/* Special rule for enumerations, the cr does not have a value since it -is- a value.
* This is ONLY used when we don't have an environment.
*/
case (cache,env as {},c as Exp.CREF_QUAL(_,expTy as Exp.ENUM(),_,_),impl,msg)
then
(cache,Values.ENUM(c, 0));

/* Search in env for binding, special rule for enumerations, the cr does not have a value since it -is- a value. */
case (cache,env,c,impl,msg)
equation
(cache,attr,ty as (Types.T_ENUM(),_),binding,_,_) = Lookup.lookupVar(cache, env, c);
then
(cache,Values.ENUM(c, 0));

case (cache,env as {},c as Exp.CREF_QUAL(_,expTy as Exp.ENUMERATION(_,_,_,_),_,Exp.CREF_IDENT(_,Exp.ENUMERATION(SOME(index),_,_,_),_)),impl,msg)
local Integer index;
// case (cache,env as {},c as Exp.CREF_QUAL(_,expTy as Exp.ENUM(),_,_),impl,msg)
then
(cache,Values.ENUM(c, index));
case (cache,env as {},c as Exp.CREF_IDENT(_,Exp.ENUMERATION(SOME(index),_,_,_),_),impl,msg)
local Integer index;
// case (cache,env as {},c as Exp.CREF_QUAL(_,expTy as Exp.ENUM(),_,_),impl,msg)
then
(cache,Values.ENUM(c, index));
/* Enumerationtyp -> no lookup necesery */
case (cache,env,c as Exp.CREF_QUAL(_,expTy as Exp.ENUMERATION(_,_,_,_),_,Exp.CREF_IDENT(_,Exp.ENUMERATION(SOME(index),_,_,_),_)),impl,msg)
local Integer index;
then
(cache,Values.ENUM(c, index));

/* Search in env for binding. */
case (cache,env,c,impl,msg)
equation
Expand Down
9 changes: 8 additions & 1 deletion Compiler/Cevalfunc.mo
Expand Up @@ -1110,7 +1110,14 @@ algorithm oval := matchcontinue(inType)
case((Types.T_REAL(_),_)) then Values.REAL(0.0);
case((Types.T_STRING(_),_)) then Values.STRING("");
case((Types.T_BOOL(_),_)) then Values.BOOL(false);
case((Types.T_ENUM,_)) then Values.ENUM(Exp.CREF_IDENT("",Exp.ENUM(),{}),0);
case((Types.T_ENUMERATION(SOME(idx),path,names,_),_))
local
Integer idx;
Absyn.Path path;
list<String> names;
then Values.ENUM(Exp.CREF_IDENT("",Exp.ENUMERATION(SOME(idx),path,names,{}),{}),0);
// then Values.ENUM(Exp.CREF_IDENT("",Exp.ENUM(),{}),0);
// case((Types.T_ENUM,_)) then Values.ENUM(Exp.CREF_IDENT("",Exp.ENUM(),{}),0);
case((Types.T_COMPLEX(ClassInf.RECORD(str), typesVar,_,_),_))
local
list<Types.Var> typesVar;
Expand Down
73 changes: 69 additions & 4 deletions Compiler/Codegen.mo
Expand Up @@ -1775,12 +1775,13 @@ protected function daeExpType
algorithm
outType:=
matchcontinue (inType)
local String name; Absyn.Path path; list<DAE.Var> varLst;
local String name; Absyn.Path path; list<DAE.Var> varLst; list<String> strLst;
case DAE.INT() then Exp.INT();
case DAE.REAL() then Exp.REAL();
case DAE.STRING() then Exp.STRING();
case DAE.BOOL() then Exp.BOOL();
case DAE.ENUM() then Exp.ENUM();
case DAE.ENUMERATION(strLst) then Exp.ENUMERATION(NONE(),Absyn.IDENT(""),strLst,{});
// case DAE.ENUM() then Exp.ENUM();
case DAE.LIST() then Exp.T_LIST(Exp.OTHER()); // MetaModelica list
case DAE.COMPLEX(path,varLst)
local
Expand Down Expand Up @@ -1844,7 +1845,8 @@ algorithm
case Exp.STRING() then "string";
case Exp.BOOL() then "boolean";
case Exp.OTHER() then "complex"; // Only use is currently for external objects. Perhaps in future also records.
case Exp.ENUM() then "ENUM_NOT_IMPLEMENTED";
case Exp.ENUMERATION(_,_,_,_) then "enumeration";
// case Exp.ENUM() then "ENUM_NOT_IMPLEMENTED";
case Exp.T_FUNCTION_REFERENCE_VAR() then "fnptr";
case Exp.T_FUNCTION_REFERENCE_FUNC() then "fnptr";
case Exp.T_ARRAY(ty = t)
Expand Down Expand Up @@ -2022,7 +2024,7 @@ algorithm
case ((Types.T_REAL(varLstReal = _),_)) then "real";
case ((Types.T_STRING(varLstString = _),_)) then "string";
case ((Types.T_BOOL(varLstBool = _),_)) then "boolean";
case ((Types.T_ENUM(),_)) then "T_ENUM_NOT_IMPLEMENTED";
// case ((Types.T_ENUM(),_)) then "T_ENUM_NOT_IMPLEMENTED";
end matchcontinue;
end generateTypeInternalNamepart;

Expand Down Expand Up @@ -6277,6 +6279,19 @@ 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;
equation
// no dots
cref_str_1 = Util.stringReplaceChar(id, ".", "_");
then
(cref_str_1,subs);
case Exp.CREF_QUAL(id, _, {}, Exp.CREF_IDENT(id1, Exp.ENUMERATION(_,_,_,_), {}))
local Lib id1;
equation
cref_str = Util.stringAppendList({id, "_",id1});
then
(cref_str,{});
case Exp.CREF_IDENT(ident = id,subscriptLst = subs) then (id,subs);
case Exp.CREF_QUAL(ident = id,subscriptLst = subs,componentRef = cref)
equation
Expand Down Expand Up @@ -6455,6 +6470,14 @@ algorithm
cfn = cMergeFn(cfn1, cfn2);
then
(cfn,var,tnr2);
case (e1,Exp.LESS(ty = Exp.ENUMERATION(_,_,_,_)),e2,tnr,context)
equation
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
(cfn2,var2,tnr2) = generateExpression(e2, tnr1, context);
var = Util.stringAppendList({"(",var1," < ",var2,")"});
cfn = cMergeFn(cfn1, cfn2);
then
(cfn,var,tnr2);
case (e1,Exp.GREATER(ty = Exp.BOOL()),e2,tnr,context)
equation
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
Expand Down Expand Up @@ -6484,6 +6507,14 @@ algorithm
cfn = cMergeFn(cfn1, cfn2);
then
(cfn,var,tnr2);
case (e1,Exp.GREATER(ty = Exp.ENUMERATION(_,_,_,_)),e2,tnr,context)
equation
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
(cfn2,var2,tnr2) = generateExpression(e2, tnr1, context);
var = Util.stringAppendList({"(",var1," > ",var2,")"});
cfn = cMergeFn(cfn1, cfn2);
then
(cfn,var,tnr2);
case (e1,Exp.LESSEQ(ty = Exp.BOOL()),e2,tnr,context)
equation
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
Expand Down Expand Up @@ -6513,6 +6544,14 @@ algorithm
cfn = cMergeFn(cfn1, cfn2);
then
(cfn,var,tnr2);
case (e1,Exp.LESSEQ(ty = Exp.ENUMERATION(_,_,_,_)),e2,tnr,context)
equation
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
(cfn2,var2,tnr2) = generateExpression(e2, tnr1, context);
var = Util.stringAppendList({"(",var1," <= ",var2,")"});
cfn = cMergeFn(cfn1, cfn2);
then
(cfn,var,tnr2);
case (e1,Exp.GREATEREQ(ty = Exp.BOOL()),e2,tnr,context)
equation
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
Expand Down Expand Up @@ -6542,6 +6581,14 @@ algorithm
cfn = cMergeFn(cfn1, cfn2);
then
(cfn,var,tnr2);
case (e1,Exp.GREATEREQ(ty = Exp.ENUMERATION(_,_,_,_)),e2,tnr,context)
equation
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
(cfn2,var2,tnr2) = generateExpression(e2, tnr1, context);
var = Util.stringAppendList({"(",var1," >= ",var2,")"});
cfn = cMergeFn(cfn1, cfn2);
then
(cfn,var,tnr2);
case (e1,Exp.EQUAL(ty = Exp.BOOL()),e2,tnr,context)
equation
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
Expand Down Expand Up @@ -6588,6 +6635,15 @@ algorithm
cfn = cMergeFn(cfn1, cfn2);
then
(cfn,var,tnr2);
case (e1,Exp.EQUAL(ty = Exp.ENUMERATION(_,_,_,_)),e2,tnr,context)
// case (e1,Exp.EQUAL(ty = Exp.ENUM()),e2,tnr,context)
equation
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
(cfn2,var2,tnr2) = generateExpression(e2, tnr1, context);
var = Util.stringAppendList({"(",var1," == ",var2,")"});
cfn = cMergeFn(cfn1, cfn2);
then
(cfn,var,tnr2);
case (e1,Exp.NEQUAL(ty = Exp.BOOL()),e2,tnr,context)
equation
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
Expand Down Expand Up @@ -6634,6 +6690,15 @@ algorithm
cfn = cMergeFn(cfn1, cfn2);
then
(cfn,var,tnr2);
case (e1,Exp.NEQUAL(ty = Exp.ENUMERATION(_,_,_,_)),e2,tnr,context)
equation
true = RTOpts.acceptMetaModelicaGrammar();
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
(cfn2,var2,tnr2) = generateExpression(e2, tnr1, context);
var = Util.stringAppendList({"(",var1," != ",var2,")"});
cfn = cMergeFn(cfn1, cfn2);
then
(cfn,var,tnr);
case (_,_,_,_,_)
equation
Debug.fprint("failtrace", "# generate_relation failed\n");
Expand Down
31 changes: 16 additions & 15 deletions Compiler/Convert.mo
Expand Up @@ -309,7 +309,8 @@ algorithm
case (DAE.INT()) equation then Exp.INTEXP();
case (DAE.BOOL()) equation then Exp.BOOLEXP();
case (DAE.STRING()) equation then Exp.STRINGEXP();
case (DAE.ENUM()) equation then Exp.ENUMEXP();
case (DAE.ENUMERATION(_)) equation then Exp.ENUMEXP();
// case (DAE.ENUM()) equation then Exp.ENUMEXP();
case (DAE.LIST()) equation then Exp.LISTEXP();
case (DAE.METATUPLE()) equation then Exp.METATUPLEEXP();
case (DAE.METAOPTION()) equation then Exp.METAOPTIONEXP();
Expand Down Expand Up @@ -1356,19 +1357,22 @@ algorithm
ret = ((Types.T_UNIONTYPE(records),p));
then ret;

case ((Exp.T_ENUMTYPES(),p))
equation
ret = ((Types.T_ENUM(),p));
then ret;
// case ((Exp.T_ENUMTYPES(),p))
// equation
// ret = ((Types.T_ENUMERATION(SOME(0),Absyn.IDENT(""),{},{}),p));
// ret = ((Types.T_ENUM(),p));
// then ret;

case ((Exp.T_ENUMERATIONTYPES(lst1,lst2),p))
case ((Exp.T_ENUMERATIONTYPES(idx,pp,lst1,lst2),p))
local
Option<Integer> idx;
Absyn.Path pp;
list<String> lst1 "names" ;
list<Exp.VarTypes> lst2 "varLst" ;
list<Types.Var> lst3;
equation
lst3 = fromVarTypesListToVarList(lst2,{});
ret = ((Types.T_ENUMERATION(lst1,lst3),p));
ret = ((Types.T_ENUMERATION(idx,pp,lst1,lst3),p));
then ret;

case ((Exp.T_ARRAYTYPES(arrDim,arrType),p))
Expand Down Expand Up @@ -1829,20 +1833,17 @@ algorithm
ret = (Exp.T_UNIONTYPETYPES(records),p);
then ret;

case ((Types.T_ENUM(),p))
local
equation
ret = ((Exp.T_ENUMTYPES(),p));
then ret;

case ((Types.T_ENUMERATION(lst1,lst2),p))
case ((Types.T_ENUMERATION(idx,tp,lst1,lst2),p))
// case ((Types.T_ENUM(),p))
local
Option<Integer> idx;
Absyn.Path tp;
list<String> lst1 "names" ;
list<Types.Var> lst2 "varLst" ;
list<Exp.VarTypes> temp;
equation
temp = fromVarListToVarTypesList(lst2,{});
ret = ((Exp.T_ENUMERATIONTYPES(lst1,temp),p));
ret = ((Exp.T_ENUMERATIONTYPES(idx,tp,lst1,temp),p));
then ret;

case ((Types.T_ARRAY(arrDim,arrType),p))
Expand Down
16 changes: 9 additions & 7 deletions Compiler/DAE.mo
Expand Up @@ -88,7 +88,7 @@ uniontype Type

record STRING end STRING;

record ENUM end ENUM;
// record ENUM end ENUM;

record LIST end LIST; // MetaModelica list. KS

Expand Down Expand Up @@ -2183,11 +2183,11 @@ algorithm
then
();

case ENUM()
equation
Print.printBuf("Enum ");
then
();
// case ENUM()
// equation
// Print.printBuf("Enum ");
// then
// ();
case ENUMERATION(stringLst = l)
equation
Print.printBuf("Enumeration(");
Expand Down Expand Up @@ -2224,7 +2224,7 @@ algorithm
case REAL() then "Real ";
case BOOL() then "Boolean ";
case STRING() then "String ";
case ENUM() then "Enum ";
// case ENUM() then "Enum ";

case ENUMERATION(stringLst = l)
equation
Expand Down Expand Up @@ -3496,10 +3496,12 @@ public function generateDaeType "function generateDaeType
algorithm
outType:=
matchcontinue (inType)
local list<String> strlst;
case (REAL()) then ((Types.T_REAL({}),NONE));
case (INT()) then ((Types.T_INTEGER({}),NONE));
case (BOOL()) then ((Types.T_BOOL({}),NONE));
case (STRING()) then ((Types.T_STRING({}),NONE));
case (ENUMERATION(strlst)) then ((Types.T_ENUMERATION(SOME(0),Absyn.IDENT(""),strlst, {}),NONE));
end matchcontinue;
end generateDaeType;

Expand Down

0 comments on commit ddcdd1d

Please sign in to comment.