Skip to content

Commit

Permalink
- Force lists to be built of boxed types
Browse files Browse the repository at this point in the history
  - Fixes Util.splitTuple2List (which has been added as a testcase in UtilTest.mos


git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/sjoelund-functiontree@6402 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 17, 2010
1 parent 8a8514b commit f09482a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions Compiler/DAE.mo
Expand Up @@ -665,6 +665,7 @@ public constant Type T_STRING_DEFAULT = (T_STRING({}),NONE());
public constant Type T_BOOL_DEFAULT = (T_BOOL({}),NONE());
public constant Type T_ENUMERATION_DEFAULT =
(T_ENUMERATION(NONE, Absyn.IDENT(""), {}, {}, {}), NONE);
public constant Type T_BOXED_DEFAULT = (T_BOXED((T_NOTYPE(),NONE())),NONE());

public uniontype TType "-TType contains the actual type"
record T_INTEGER
Expand Down
2 changes: 1 addition & 1 deletion Compiler/MetaUtil.mo
Expand Up @@ -1496,7 +1496,7 @@ algorithm
true = RTOpts.acceptMetaModelicaGrammar();
(flatType,_) = Types.flattenArrayType(ty);
true = Types.isBoxedType(flatType) or RTOpts.debugFlag("rml") "debug flag to produce better error messages by converting all arrays into lists; the compiler does not use Modelica-style arrays anyway";
(exp,ty) = Types.matchType(exp, ty, (DAE.T_LIST((DAE.T_NOTYPE(),NONE())),NONE()), false);
(exp,ty) = Types.matchType(exp, ty, (DAE.T_LIST(DAE.T_BOXED_DEFAULT),NONE()), false);
then (exp,ty);
case (exp,ty)
equation
Expand Down
9 changes: 5 additions & 4 deletions Compiler/Static.mo
Expand Up @@ -581,15 +581,15 @@ algorithm
Boolean correctTypes;
DAE.Type t;
equation
(e1 :: _) = MetaUtil.transformArrayNodesToListNodes({e1},{});
(e2 :: _) = MetaUtil.transformArrayNodesToListNodes({e2},{});
{e1,e2} = MetaUtil.transformArrayNodesToListNodes({e1,e2},{});

(cache,e1_1,prop1,st_1) = elabExp(cache,env, e1, impl, st,doVect,pre,info);
(cache,e2_1,DAE.PROP((DAE.T_LIST(t2),_),c2),st_1) = elabExp(cache,env, e2, impl, st,doVect,pre,info);

t1 = Types.getPropType(prop1);
c1 = Types.propAllConst(prop1);
t = Types.superType(t1,t2);
t = Types.superType(t,t); // For example TUPLE should be META_TUPLE; if it's only 1 argument, it might not be

(e1_1,_) = Types.matchType(e1_1, t1, t, true);
(e2_1,_) = Types.matchType(e2_1, t2, t, true);
Expand Down Expand Up @@ -4093,11 +4093,12 @@ algorithm
(cache,s2_1,prop2,_) = elabExp(cache, env, s2, impl, NONE, impl,pre,info);
t1 = Types.getPropType(prop1);
t2 = Types.getPropType(prop2);
(s1_1,t1) = Types.matchType(s1_1, t1, (DAE.T_BOXED((DAE.T_NOTYPE,NONE)),NONE), true);
(s2_1,t2) = Types.matchType(s2_1, t2, (DAE.T_BOXED((DAE.T_NOTYPE,NONE)),NONE), true);
(s1_1,t1) = Types.matchType(s1_1, t1, DAE.T_BOXED_DEFAULT, true);
(s2_1,t2) = Types.matchType(s2_1, t2, DAE.T_BOXED_DEFAULT, true);
t1 = Types.unboxedType(t1);
t2 = Types.unboxedType(t2);
ty = Types.superType(t1, t2);
ty = Types.superType(ty, ty);
tp = Types.elabType(ty);
ty = if_exp(Types.isBoxedType(ty), ty, (DAE.T_BOXED(ty),NONE));
c1 = Types.propAllConst(prop1);
Expand Down
19 changes: 12 additions & 7 deletions Compiler/Types.mo
Expand Up @@ -2119,7 +2119,9 @@ algorithm
case ((DAE.T_METATUPLE(types = tys),_))
local list<Type> tys;
equation
res = unparseType((DAE.T_TUPLE(tys),NONE));
tystrs = Util.listMap(tys, unparseType);
tystr = Util.stringDelimitList(tystrs, ", ");
res = Util.stringAppendList({"tuple<",tystr,">"});
then
res;

Expand Down Expand Up @@ -4030,14 +4032,14 @@ algorithm
(elist_1,tys_1) = matchTypeTuple(elist, tys1, tys2, printFailtrace);
then
(DAE.META_TUPLE(elist_1),(DAE.T_METATUPLE(tys_1),p2));
case (DAE.TUPLE(elist),(DAE.T_TUPLE(tupleType = tys1),_),(DAE.T_BOXED(ty2),p2),printFailtrace)
case (DAE.TUPLE(elist),(DAE.T_TUPLE(tupleType = tys1),_),ty2 as (DAE.T_BOXED((DAE.T_NOTYPE(),_)),p2),printFailtrace)
equation
true = RTOpts.acceptMetaModelicaGrammar();
e_1 = DAE.META_TUPLE(elist);
ty1 = (DAE.T_METATUPLE(tys1),p2);
(e_1,t_1) = matchType(e_1, ty1, ty2, printFailtrace);
tys2 = Util.listFill(ty2, listLength(tys1));
(elist_1,tys_1) = matchTypeTuple(elist, tys1, tys2, printFailtrace);
then
(e_1,t_1);
(DAE.META_TUPLE(elist_1),(DAE.T_METATUPLE(tys_1),p2));

/*
The automatic type conversion will convert any array that can be
Expand Down Expand Up @@ -5074,7 +5076,7 @@ algorithm
case ((DAE.T_TUPLE(type_list1),_),(DAE.T_TUPLE(type_list2),_))
equation
type_list1 = Util.listThreadMap(type_list1,type_list2,superType);
then ((DAE.T_TUPLE(type_list1),NONE));
then ((DAE.T_METATUPLE(type_list1),NONE));
case ((DAE.T_TUPLE(type_list1),_),(DAE.T_METATUPLE(type_list2),_))
equation
type_list1 = Util.listThreadMap(type_list1,type_list2,superType);
Expand Down Expand Up @@ -5839,9 +5841,12 @@ algorithm
Absyn.Path path,path1,path2;
case (actual,(DAE.T_POLYMORPHIC(id),_),bindings)
then addPolymorphicBinding(id,boxIfUnboxedType(actual),bindings);
case ((DAE.T_BOXED(ty1),_),(DAE.T_BOXED(ty2),_),bindings)
case ((DAE.T_BOXED(ty1),_),ty2,bindings)
equation
ty1 = unboxedType(ty1);
then subtypePolymorphic(ty1,ty2,bindings);
case (ty1,(DAE.T_BOXED(ty2),_),bindings)
equation
ty2 = unboxedType(ty2);
then subtypePolymorphic(ty1,ty2,bindings);
case ((DAE.T_NORETCALL(),_),(DAE.T_NORETCALL(),_),bindings) then bindings;
Expand Down

0 comments on commit f09482a

Please sign in to comment.