Skip to content

Commit ddcdd1d

Browse files
author
Jens Frenkel
committed
enumerations part 1
- 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
1 parent 4716949 commit ddcdd1d

File tree

17 files changed

+914
-212
lines changed

17 files changed

+914
-212
lines changed

Compiler/Ceval.mo

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4127,29 +4127,34 @@ algorithm
41274127
case (Values.BOOL(boolean = _),Exp.LESS(ty = Exp.BOOL()),Values.BOOL(boolean = _)) then Values.BOOL(false);
41284128

41294129
/* Enumerations */
4130-
case (Values.ENUM(cr1,i1),Exp.LESS(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
4130+
case (Values.ENUM(cr1,i1),Exp.LESS(ty = Exp.ENUMERATION(index = SOME(_))),Values.ENUM(cr2,i2))
4131+
// case (Values.ENUM(cr1,i1),Exp.LESS(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
41314132
equation
41324133
b = (i1 < i2);
41334134
then
41344135
Values.BOOL(b);
4135-
case (Values.ENUM(cr1,i1),Exp.LESSEQ(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
4136+
case (Values.ENUM(cr1,i1),Exp.LESSEQ(ty = Exp.ENUMERATION(index = SOME(_))),Values.ENUM(cr2,i2))
4137+
// case (Values.ENUM(cr1,i1),Exp.LESSEQ(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
41364138
equation
41374139
b = (i1 <= i2);
41384140
then
41394141
Values.BOOL(b);
4140-
case (Values.ENUM(cr1,i1),Exp.GREATEREQ(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
4142+
case (Values.ENUM(cr1,i1),Exp.GREATEREQ(ty = Exp.ENUMERATION(index = SOME(_))),Values.ENUM(cr2,i2))
4143+
// case (Values.ENUM(cr1,i1),Exp.GREATEREQ(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
41414144
equation
41424145
b = (i1 >= i2);
41434146
then
41444147
Values.BOOL(b);
4145-
case (Values.ENUM(cr1,i1),Exp.EQUAL(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
4148+
case (Values.ENUM(cr1,i1),Exp.EQUAL(ty = Exp.ENUMERATION(index = SOME(_))),Values.ENUM(cr2,i2))
4149+
// case (Values.ENUM(cr1,i1),Exp.EQUAL(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
41464150
equation
41474151
ba = Exp.crefEqual(cr1, cr2);
41484152
bb = (i1 == i2);
41494153
b = boolAnd(ba, bb);
41504154
then
41514155
Values.BOOL(b);
4152-
case (Values.ENUM(cr1,i1),Exp.NEQUAL(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
4156+
case (Values.ENUM(cr1,i1),Exp.NEQUAL(ty = Exp.ENUMERATION(index = SOME(_))),Values.ENUM(cr2,i2))
4157+
// case (Values.ENUM(cr1,i1),Exp.NEQUAL(ty = Exp.ENUM()),Values.ENUM(cr2,i2))
41534158
equation
41544159
ba = boolNot(Exp.crefEqual(cr1, cr2));
41554160
bb = (i1 <> i2);
@@ -4364,17 +4369,22 @@ algorithm
43644369
/* Special rule for enumerations, the cr does not have a value since it -is- a value.
43654370
* This is ONLY used when we don't have an environment.
43664371
*/
4367-
case (cache,env as {},c as Exp.CREF_QUAL(_,expTy as Exp.ENUM(),_,_),impl,msg)
4368-
then
4369-
(cache,Values.ENUM(c, 0));
4370-
4371-
/* Search in env for binding, special rule for enumerations, the cr does not have a value since it -is- a value. */
4372-
case (cache,env,c,impl,msg)
4373-
equation
4374-
(cache,attr,ty as (Types.T_ENUM(),_),binding,_,_) = Lookup.lookupVar(cache, env, c);
4375-
then
4376-
(cache,Values.ENUM(c, 0));
4377-
4372+
case (cache,env as {},c as Exp.CREF_QUAL(_,expTy as Exp.ENUMERATION(_,_,_,_),_,Exp.CREF_IDENT(_,Exp.ENUMERATION(SOME(index),_,_,_),_)),impl,msg)
4373+
local Integer index;
4374+
// case (cache,env as {},c as Exp.CREF_QUAL(_,expTy as Exp.ENUM(),_,_),impl,msg)
4375+
then
4376+
(cache,Values.ENUM(c, index));
4377+
case (cache,env as {},c as Exp.CREF_IDENT(_,Exp.ENUMERATION(SOME(index),_,_,_),_),impl,msg)
4378+
local Integer index;
4379+
// case (cache,env as {},c as Exp.CREF_QUAL(_,expTy as Exp.ENUM(),_,_),impl,msg)
4380+
then
4381+
(cache,Values.ENUM(c, index));
4382+
/* Enumerationtyp -> no lookup necesery */
4383+
case (cache,env,c as Exp.CREF_QUAL(_,expTy as Exp.ENUMERATION(_,_,_,_),_,Exp.CREF_IDENT(_,Exp.ENUMERATION(SOME(index),_,_,_),_)),impl,msg)
4384+
local Integer index;
4385+
then
4386+
(cache,Values.ENUM(c, index));
4387+
43784388
/* Search in env for binding. */
43794389
case (cache,env,c,impl,msg)
43804390
equation

Compiler/Cevalfunc.mo

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,14 @@ algorithm oval := matchcontinue(inType)
11101110
case((Types.T_REAL(_),_)) then Values.REAL(0.0);
11111111
case((Types.T_STRING(_),_)) then Values.STRING("");
11121112
case((Types.T_BOOL(_),_)) then Values.BOOL(false);
1113-
case((Types.T_ENUM,_)) then Values.ENUM(Exp.CREF_IDENT("",Exp.ENUM(),{}),0);
1113+
case((Types.T_ENUMERATION(SOME(idx),path,names,_),_))
1114+
local
1115+
Integer idx;
1116+
Absyn.Path path;
1117+
list<String> names;
1118+
then Values.ENUM(Exp.CREF_IDENT("",Exp.ENUMERATION(SOME(idx),path,names,{}),{}),0);
1119+
// then Values.ENUM(Exp.CREF_IDENT("",Exp.ENUM(),{}),0);
1120+
// case((Types.T_ENUM,_)) then Values.ENUM(Exp.CREF_IDENT("",Exp.ENUM(),{}),0);
11141121
case((Types.T_COMPLEX(ClassInf.RECORD(str), typesVar,_,_),_))
11151122
local
11161123
list<Types.Var> typesVar;

Compiler/Codegen.mo

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,12 +1775,13 @@ protected function daeExpType
17751775
algorithm
17761776
outType:=
17771777
matchcontinue (inType)
1778-
local String name; Absyn.Path path; list<DAE.Var> varLst;
1778+
local String name; Absyn.Path path; list<DAE.Var> varLst; list<String> strLst;
17791779
case DAE.INT() then Exp.INT();
17801780
case DAE.REAL() then Exp.REAL();
17811781
case DAE.STRING() then Exp.STRING();
17821782
case DAE.BOOL() then Exp.BOOL();
1783-
case DAE.ENUM() then Exp.ENUM();
1783+
case DAE.ENUMERATION(strLst) then Exp.ENUMERATION(NONE(),Absyn.IDENT(""),strLst,{});
1784+
// case DAE.ENUM() then Exp.ENUM();
17841785
case DAE.LIST() then Exp.T_LIST(Exp.OTHER()); // MetaModelica list
17851786
case DAE.COMPLEX(path,varLst)
17861787
local
@@ -1844,7 +1845,8 @@ algorithm
18441845
case Exp.STRING() then "string";
18451846
case Exp.BOOL() then "boolean";
18461847
case Exp.OTHER() then "complex"; // Only use is currently for external objects. Perhaps in future also records.
1847-
case Exp.ENUM() then "ENUM_NOT_IMPLEMENTED";
1848+
case Exp.ENUMERATION(_,_,_,_) then "enumeration";
1849+
// case Exp.ENUM() then "ENUM_NOT_IMPLEMENTED";
18481850
case Exp.T_FUNCTION_REFERENCE_VAR() then "fnptr";
18491851
case Exp.T_FUNCTION_REFERENCE_FUNC() then "fnptr";
18501852
case Exp.T_ARRAY(ty = t)
@@ -2022,7 +2024,7 @@ algorithm
20222024
case ((Types.T_REAL(varLstReal = _),_)) then "real";
20232025
case ((Types.T_STRING(varLstString = _),_)) then "string";
20242026
case ((Types.T_BOOL(varLstBool = _),_)) then "boolean";
2025-
case ((Types.T_ENUM(),_)) then "T_ENUM_NOT_IMPLEMENTED";
2027+
// case ((Types.T_ENUM(),_)) then "T_ENUM_NOT_IMPLEMENTED";
20262028
end matchcontinue;
20272029
end generateTypeInternalNamepart;
20282030

@@ -6277,6 +6279,19 @@ algorithm
62776279
Lib id,cref_str,cref_str_1;
62786280
list<Exp.Subscript> subs,cref_subs,subs_1;
62796281
Exp.ComponentRef cref;
6282+
case Exp.CREF_IDENT(ident = id, identType = Exp.ENUMERATION(_,_,_,_), subscriptLst = subs)
6283+
local list<String> strlst, strlst1;
6284+
equation
6285+
// no dots
6286+
cref_str_1 = Util.stringReplaceChar(id, ".", "_");
6287+
then
6288+
(cref_str_1,subs);
6289+
case Exp.CREF_QUAL(id, _, {}, Exp.CREF_IDENT(id1, Exp.ENUMERATION(_,_,_,_), {}))
6290+
local Lib id1;
6291+
equation
6292+
cref_str = Util.stringAppendList({id, "_",id1});
6293+
then
6294+
(cref_str,{});
62806295
case Exp.CREF_IDENT(ident = id,subscriptLst = subs) then (id,subs);
62816296
case Exp.CREF_QUAL(ident = id,subscriptLst = subs,componentRef = cref)
62826297
equation
@@ -6455,6 +6470,14 @@ algorithm
64556470
cfn = cMergeFn(cfn1, cfn2);
64566471
then
64576472
(cfn,var,tnr2);
6473+
case (e1,Exp.LESS(ty = Exp.ENUMERATION(_,_,_,_)),e2,tnr,context)
6474+
equation
6475+
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
6476+
(cfn2,var2,tnr2) = generateExpression(e2, tnr1, context);
6477+
var = Util.stringAppendList({"(",var1," < ",var2,")"});
6478+
cfn = cMergeFn(cfn1, cfn2);
6479+
then
6480+
(cfn,var,tnr2);
64586481
case (e1,Exp.GREATER(ty = Exp.BOOL()),e2,tnr,context)
64596482
equation
64606483
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
@@ -6484,6 +6507,14 @@ algorithm
64846507
cfn = cMergeFn(cfn1, cfn2);
64856508
then
64866509
(cfn,var,tnr2);
6510+
case (e1,Exp.GREATER(ty = Exp.ENUMERATION(_,_,_,_)),e2,tnr,context)
6511+
equation
6512+
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
6513+
(cfn2,var2,tnr2) = generateExpression(e2, tnr1, context);
6514+
var = Util.stringAppendList({"(",var1," > ",var2,")"});
6515+
cfn = cMergeFn(cfn1, cfn2);
6516+
then
6517+
(cfn,var,tnr2);
64876518
case (e1,Exp.LESSEQ(ty = Exp.BOOL()),e2,tnr,context)
64886519
equation
64896520
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
@@ -6513,6 +6544,14 @@ algorithm
65136544
cfn = cMergeFn(cfn1, cfn2);
65146545
then
65156546
(cfn,var,tnr2);
6547+
case (e1,Exp.LESSEQ(ty = Exp.ENUMERATION(_,_,_,_)),e2,tnr,context)
6548+
equation
6549+
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
6550+
(cfn2,var2,tnr2) = generateExpression(e2, tnr1, context);
6551+
var = Util.stringAppendList({"(",var1," <= ",var2,")"});
6552+
cfn = cMergeFn(cfn1, cfn2);
6553+
then
6554+
(cfn,var,tnr2);
65166555
case (e1,Exp.GREATEREQ(ty = Exp.BOOL()),e2,tnr,context)
65176556
equation
65186557
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
@@ -6542,6 +6581,14 @@ algorithm
65426581
cfn = cMergeFn(cfn1, cfn2);
65436582
then
65446583
(cfn,var,tnr2);
6584+
case (e1,Exp.GREATEREQ(ty = Exp.ENUMERATION(_,_,_,_)),e2,tnr,context)
6585+
equation
6586+
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
6587+
(cfn2,var2,tnr2) = generateExpression(e2, tnr1, context);
6588+
var = Util.stringAppendList({"(",var1," >= ",var2,")"});
6589+
cfn = cMergeFn(cfn1, cfn2);
6590+
then
6591+
(cfn,var,tnr2);
65456592
case (e1,Exp.EQUAL(ty = Exp.BOOL()),e2,tnr,context)
65466593
equation
65476594
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
@@ -6588,6 +6635,15 @@ algorithm
65886635
cfn = cMergeFn(cfn1, cfn2);
65896636
then
65906637
(cfn,var,tnr2);
6638+
case (e1,Exp.EQUAL(ty = Exp.ENUMERATION(_,_,_,_)),e2,tnr,context)
6639+
// case (e1,Exp.EQUAL(ty = Exp.ENUM()),e2,tnr,context)
6640+
equation
6641+
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
6642+
(cfn2,var2,tnr2) = generateExpression(e2, tnr1, context);
6643+
var = Util.stringAppendList({"(",var1," == ",var2,")"});
6644+
cfn = cMergeFn(cfn1, cfn2);
6645+
then
6646+
(cfn,var,tnr2);
65916647
case (e1,Exp.NEQUAL(ty = Exp.BOOL()),e2,tnr,context)
65926648
equation
65936649
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
@@ -6634,6 +6690,15 @@ algorithm
66346690
cfn = cMergeFn(cfn1, cfn2);
66356691
then
66366692
(cfn,var,tnr2);
6693+
case (e1,Exp.NEQUAL(ty = Exp.ENUMERATION(_,_,_,_)),e2,tnr,context)
6694+
equation
6695+
true = RTOpts.acceptMetaModelicaGrammar();
6696+
(cfn1,var1,tnr1) = generateExpression(e1, tnr, context);
6697+
(cfn2,var2,tnr2) = generateExpression(e2, tnr1, context);
6698+
var = Util.stringAppendList({"(",var1," != ",var2,")"});
6699+
cfn = cMergeFn(cfn1, cfn2);
6700+
then
6701+
(cfn,var,tnr);
66376702
case (_,_,_,_,_)
66386703
equation
66396704
Debug.fprint("failtrace", "# generate_relation failed\n");

Compiler/Convert.mo

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ algorithm
309309
case (DAE.INT()) equation then Exp.INTEXP();
310310
case (DAE.BOOL()) equation then Exp.BOOLEXP();
311311
case (DAE.STRING()) equation then Exp.STRINGEXP();
312-
case (DAE.ENUM()) equation then Exp.ENUMEXP();
312+
case (DAE.ENUMERATION(_)) equation then Exp.ENUMEXP();
313+
// case (DAE.ENUM()) equation then Exp.ENUMEXP();
313314
case (DAE.LIST()) equation then Exp.LISTEXP();
314315
case (DAE.METATUPLE()) equation then Exp.METATUPLEEXP();
315316
case (DAE.METAOPTION()) equation then Exp.METAOPTIONEXP();
@@ -1356,19 +1357,22 @@ algorithm
13561357
ret = ((Types.T_UNIONTYPE(records),p));
13571358
then ret;
13581359

1359-
case ((Exp.T_ENUMTYPES(),p))
1360-
equation
1361-
ret = ((Types.T_ENUM(),p));
1362-
then ret;
1360+
// case ((Exp.T_ENUMTYPES(),p))
1361+
// equation
1362+
// ret = ((Types.T_ENUMERATION(SOME(0),Absyn.IDENT(""),{},{}),p));
1363+
// ret = ((Types.T_ENUM(),p));
1364+
// then ret;
13631365

1364-
case ((Exp.T_ENUMERATIONTYPES(lst1,lst2),p))
1366+
case ((Exp.T_ENUMERATIONTYPES(idx,pp,lst1,lst2),p))
13651367
local
1368+
Option<Integer> idx;
1369+
Absyn.Path pp;
13661370
list<String> lst1 "names" ;
13671371
list<Exp.VarTypes> lst2 "varLst" ;
13681372
list<Types.Var> lst3;
13691373
equation
13701374
lst3 = fromVarTypesListToVarList(lst2,{});
1371-
ret = ((Types.T_ENUMERATION(lst1,lst3),p));
1375+
ret = ((Types.T_ENUMERATION(idx,pp,lst1,lst3),p));
13721376
then ret;
13731377

13741378
case ((Exp.T_ARRAYTYPES(arrDim,arrType),p))
@@ -1829,20 +1833,17 @@ algorithm
18291833
ret = (Exp.T_UNIONTYPETYPES(records),p);
18301834
then ret;
18311835

1832-
case ((Types.T_ENUM(),p))
1833-
local
1834-
equation
1835-
ret = ((Exp.T_ENUMTYPES(),p));
1836-
then ret;
1837-
1838-
case ((Types.T_ENUMERATION(lst1,lst2),p))
1836+
case ((Types.T_ENUMERATION(idx,tp,lst1,lst2),p))
1837+
// case ((Types.T_ENUM(),p))
18391838
local
1839+
Option<Integer> idx;
1840+
Absyn.Path tp;
18401841
list<String> lst1 "names" ;
18411842
list<Types.Var> lst2 "varLst" ;
18421843
list<Exp.VarTypes> temp;
18431844
equation
18441845
temp = fromVarListToVarTypesList(lst2,{});
1845-
ret = ((Exp.T_ENUMERATIONTYPES(lst1,temp),p));
1846+
ret = ((Exp.T_ENUMERATIONTYPES(idx,tp,lst1,temp),p));
18461847
then ret;
18471848

18481849
case ((Types.T_ARRAY(arrDim,arrType),p))

Compiler/DAE.mo

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ uniontype Type
8888

8989
record STRING end STRING;
9090

91-
record ENUM end ENUM;
91+
// record ENUM end ENUM;
9292

9393
record LIST end LIST; // MetaModelica list. KS
9494

@@ -2183,11 +2183,11 @@ algorithm
21832183
then
21842184
();
21852185

2186-
case ENUM()
2187-
equation
2188-
Print.printBuf("Enum ");
2189-
then
2190-
();
2186+
// case ENUM()
2187+
// equation
2188+
// Print.printBuf("Enum ");
2189+
// then
2190+
// ();
21912191
case ENUMERATION(stringLst = l)
21922192
equation
21932193
Print.printBuf("Enumeration(");
@@ -2224,7 +2224,7 @@ algorithm
22242224
case REAL() then "Real ";
22252225
case BOOL() then "Boolean ";
22262226
case STRING() then "String ";
2227-
case ENUM() then "Enum ";
2227+
// case ENUM() then "Enum ";
22282228

22292229
case ENUMERATION(stringLst = l)
22302230
equation
@@ -3496,10 +3496,12 @@ public function generateDaeType "function generateDaeType
34963496
algorithm
34973497
outType:=
34983498
matchcontinue (inType)
3499+
local list<String> strlst;
34993500
case (REAL()) then ((Types.T_REAL({}),NONE));
35003501
case (INT()) then ((Types.T_INTEGER({}),NONE));
35013502
case (BOOL()) then ((Types.T_BOOL({}),NONE));
35023503
case (STRING()) then ((Types.T_STRING({}),NONE));
3504+
case (ENUMERATION(strlst)) then ((Types.T_ENUMERATION(SOME(0),Absyn.IDENT(""),strlst, {}),NONE));
35033505
end matchcontinue;
35043506
end generateDaeType;
35053507

0 commit comments

Comments
 (0)