Skip to content

Commit

Permalink
Added List type to type system files. More to come ...
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2826 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Kristian Stavåker committed Jun 12, 2007
1 parent 7b04343 commit 616aa2b
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 5 deletions.
6 changes: 5 additions & 1 deletion Compiler/Exp.mo
Expand Up @@ -94,7 +94,11 @@ uniontype Type "- Basic types
Type ty;
list<Option<Integer>> arrayDimensions "arrayDimensions" ;
end T_ARRAY;


record T_LIST
Type ty;
end T_LIST;

end Type;

public
Expand Down
52 changes: 48 additions & 4 deletions Compiler/Types.mo
Expand Up @@ -140,6 +140,10 @@ uniontype TType "-TType contains the actual type"
ArrayDim arrayDim "arrayDim" ;
Type arrayType "arrayType" ;
end T_ARRAY;

record T_LIST
Type listType "listType";
end T_LIST;

record T_COMPLEX
ClassInf.State complexClassType "complexClassType ; The type of. a class" ;
Expand Down Expand Up @@ -699,7 +703,12 @@ algorithm
tp = typeOfValue(v);
dim1 = listLength((v :: vs));
then
((T_ARRAY(DIM(SOME(dim1)),tp),NONE));
((T_ARRAY(DIM(SOME(dim1)),tp),NONE));
case ((w as Values.LIST(valueLst = (v :: _))))
equation
tp = typeOfValue(v);
then
((T_LIST(tp),NONE));
case ((w as Values.TUPLE(valueLst = vs)))
equation
ts = Util.listMap(vs, typeOfValue);
Expand Down Expand Up @@ -736,7 +745,8 @@ algorithm
case ((T_STRING(varLstString = _),_)) then true;
case ((T_BOOL(varLstBool = _),_)) then true;
case ((T_ENUM(),_)) then true;
case ((T_ARRAY(arrayDim = _),_)) then false;
case ((T_ARRAY(arrayDim = _),_)) then false;
case ((T_LIST(_),_)) then false;
case ((T_COMPLEX(complexClassType = _),_)) then false;
case ((T_ENUMERATION(names = _),_)) then false;
end matchcontinue;
Expand Down Expand Up @@ -819,7 +829,8 @@ algorithm
case ((T_REAL(varLstReal = _),_),(T_REAL(varLstReal = _),_)) then true;
case ((T_STRING(varLstString = _),_),(T_STRING(varLstString = _),_)) then true;
case ((T_BOOL(varLstBool = _),_),(T_BOOL(varLstBool = _),_)) then true;
case ((T_ENUM(),_),(T_ENUM(),_)) then true;
case ((T_ENUM(),_),(T_ENUM(),_)) then true;
case ((T_LIST(_),_),(T_LIST(_),_)) then true;
case ((T_ENUMERATION(names = (l1 :: rest1),varLst = vl1),p1),(T_ENUMERATION(names = (l2 :: rest2),varLst = vl2),p2))
equation
equality(l2 = l1);
Expand Down Expand Up @@ -1001,6 +1012,13 @@ algorithm
ty_1 = (T_ARRAY(dim,ty),NONE);
then
VAR(n,attr,prot,ty_1,bnd);
case ((T_LIST(listType = (T_COMPLEX(complexClassType = st,complexVarLst = cs,complexTypeOption = bc),_)),_),id)
equation
VAR(n,attr,prot,ty,bnd) = lookupComponent2(cs, id);
ty_1 = (T_LIST(ty),NONE);
then
VAR(n,attr,prot,ty_1,bnd);

case (_,id) /* Print.print_buf \"- Looking up \" &
Print.print_buf id &
Print.print_buf \" in noncomplex type\\n\" */ then fail();
Expand Down Expand Up @@ -1380,6 +1398,11 @@ algorithm
res = Util.stringAppendList({tys,"[",dims,"]"});
then
res;
case ((t as (T_LIST(_),_)))
equation
res = "LIST";
then
res;
case (((t as T_COMPLEX(complexClassType = ClassInf.RECORD(string = name),complexVarLst = vs,complexTypeOption = bc)),_))
local TType t;
equation
Expand Down Expand Up @@ -1537,6 +1560,13 @@ algorithm
str = Util.stringAppendList({"array[", s1,", of type",s2,"]"});
then
str;
case ((T_LIST(listType = t),_))
equation
s2 = printTypeStr(t);
str = Util.stringAppendList({"list[of type",s2,"]"});
then
str;

case ((T_FUNCTION(funcArg = params,funcResultType = restype),_))
equation
s1 = printParamsStr(params);
Expand Down Expand Up @@ -2278,6 +2308,11 @@ algorithm
case ((T_REAL(varLstReal = _),_)) then "Real";
case ((T_STRING(varLstString = _),_)) then "String";
case ((T_BOOL(varLstBool = _),_)) then "Boolean";
case ((T_LIST(ty),_))
equation
tystr = getTypeName(ty);
str = Util.stringAppendList({"list<",tystr,">"});
then str;
case ((T_COMPLEX(complexClassType = st),_))
equation
n = ClassInf.getStateName(st);
Expand Down Expand Up @@ -2512,7 +2547,11 @@ algorithm
(_,dims) = flattenArrayTypeOpt(t);
then
Exp.T_ARRAY(t_1,dims);

case ((T_LIST(et),_))
equation
t_1 = elabType(et);
then
Exp.T_LIST(t_1);
// Complext type that is subtype of primitive type.
case ( (T_COMPLEX(_,_,SOME(t)),_))
then elabType(t);
Expand Down Expand Up @@ -3284,6 +3323,11 @@ algorithm
exps = getAllExps(ty);
then
exps;
case T_LIST(listType = ty)
equation
exps = getAllExps(ty);
then
exps;
case T_COMPLEX(complexClassType = cinf,complexVarLst = vars,complexTypeOption = bc)
equation
exps = getAllExpsVars(vars);
Expand Down
33 changes: 33 additions & 0 deletions Compiler/Values.mo
Expand Up @@ -82,6 +82,10 @@ uniontype Value
record ARRAY
list<Value> valueLst;
end ARRAY;

record LIST
list<Value> valueLst;
end LIST;

record TUPLE
list<Value> valueLst;
Expand Down Expand Up @@ -140,6 +144,12 @@ algorithm
vallst2 = typeConvert(from, to, vrest);
then
(ARRAY(vallst) :: vallst2);
case (from,to,(LIST(valueLst = vals) :: vrest))
equation
vallst = typeConvert(from, to, vals);
vallst2 = typeConvert(from, to, vrest);
then
(LIST(vallst) :: vallst2);
end matchcontinue;
end typeConvert;

Expand Down Expand Up @@ -174,6 +184,7 @@ algorithm
case (STRING(string = _)) then false;
case (BOOL(boolean = _)) then false;
case (TUPLE(valueLst = _)) then false;
case (LIST(valueLst = _)) then false;
case (ARRAY(valueLst = _)) then true;
end matchcontinue;
end isArray;
Expand Down Expand Up @@ -255,6 +266,13 @@ algorithm
res = stringAppend(s1, s2);
then
res;
case ((LIST(valueLst = lst) :: xs))
equation
s1 = unparseValueNumbers(lst);
s2 = unparseValueNumbers(xs);
res = stringAppend(s1, s2);
then
res;
case ((INTEGER(integer = i) :: xs))
equation
s1 = unparseValueNumbers(xs);
Expand Down Expand Up @@ -525,6 +543,14 @@ algorithm
str = stringAppend(s4, " \n");
then
str;
case ((LIST(valueLst = vallst) :: xs))
equation
s1 = unparseDescription(xs);
s2 = unparseDescription(vallst);
s4 = stringAppend(s2, s1);
str = stringAppend(s4, " \n");
then
str;
case ({}) then "";
end matchcontinue;
end unparseDescription;
Expand Down Expand Up @@ -1246,6 +1272,13 @@ algorithm
s_2 = stringAppend(s_1, "}");
then
s_2;
case LIST(valueLst = vs)
equation
s = valListString(vs);
s_1 = stringAppend("{", s);
s_2 = stringAppend(s_1, "}");
then
s_2;
case TUPLE(valueLst = vs)
equation
s = valListString(vs);
Expand Down

0 comments on commit 616aa2b

Please sign in to comment.