From f09482aa88ea3d4d55a240b70742629bcea30c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Sj=C3=B6lund?= Date: Sun, 17 Oct 2010 21:00:01 +0000 Subject: [PATCH] - Force lists to be built of boxed types - 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 --- Compiler/DAE.mo | 1 + Compiler/MetaUtil.mo | 2 +- Compiler/Static.mo | 9 +++++---- Compiler/Types.mo | 19 ++++++++++++------- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Compiler/DAE.mo b/Compiler/DAE.mo index 518ee384e00..773b7f0f8c2 100644 --- a/Compiler/DAE.mo +++ b/Compiler/DAE.mo @@ -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 diff --git a/Compiler/MetaUtil.mo b/Compiler/MetaUtil.mo index baa3ef61539..df7f4105d25 100644 --- a/Compiler/MetaUtil.mo +++ b/Compiler/MetaUtil.mo @@ -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 diff --git a/Compiler/Static.mo b/Compiler/Static.mo index 292cd01624e..b9baa6a7d1a 100644 --- a/Compiler/Static.mo +++ b/Compiler/Static.mo @@ -581,8 +581,7 @@ 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); @@ -590,6 +589,7 @@ algorithm 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); @@ -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); diff --git a/Compiler/Types.mo b/Compiler/Types.mo index 0bc7e1626d1..380517845d8 100644 --- a/Compiler/Types.mo +++ b/Compiler/Types.mo @@ -2119,7 +2119,9 @@ algorithm case ((DAE.T_METATUPLE(types = tys),_)) local list 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; @@ -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 @@ -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); @@ -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;