Skip to content

Commit

Permalink
- Fixed Algorithm.makeIf to type-convert expression to Boolean (so it…
Browse files Browse the repository at this point in the history
… works for boxed Boolean values, e.g. when calling function references).

- 06_advanced added to the default testsuite. Tests polymorphic functions, e.g. listMap0, listMap1.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@4450 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Nov 4, 2009
1 parent bd76da3 commit 3f32995
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
8 changes: 5 additions & 3 deletions Compiler/Algorithm.mo
Expand Up @@ -489,8 +489,9 @@ algorithm
list<tuple<Exp.Exp, Types.Properties, list<Statement>>> eib;
Ident e_str,t_str;
tuple<Types.TType, Option<Absyn.Path>> t;
case (e,Types.PROP(type_ = (Types.T_BOOL(varLstBool = _),_)),tb,eib,fb)
equation
case (e,Types.PROP(type_ = t),tb,eib,fb)
equation
(e,_) = Types.matchType(e,t,(Types.T_BOOL({}),NONE));
else_ = makeElse(eib, fb);
then
IF(e,tb,else_);
Expand Down Expand Up @@ -521,8 +522,9 @@ algorithm
tuple<Types.TType, Option<Absyn.Path>> t;
case ({},{}) then NOELSE(); /* This removes empty else branches */
case ({},fb) then ELSE(fb);
case (((e,Types.PROP(type_ = (Types.T_BOOL(varLstBool = _),_)),b) :: xs),fb)
case (((e,Types.PROP(type_ = t),b) :: xs),fb)
equation
(e,_) = Types.matchType(e,t,(Types.T_BOOL({}),NONE));
else_ = makeElse(xs, fb);
then
ELSEIF(e,b,else_);
Expand Down
8 changes: 6 additions & 2 deletions Compiler/DFA.mo
Expand Up @@ -53,6 +53,7 @@ type SimpleStateArray = SimpleState[:];

protected import Lookup;
protected import Util;
protected import Dump;

public uniontype Dfa
record DFArec
Expand Down Expand Up @@ -1488,6 +1489,8 @@ algorithm
Env.Cache localCache;
Env.Env localEnv;
list<Absyn.Exp> restExps;
Absyn.Exp e;
String str;
case ({},localDfaEnv,localCache,_) then (localDfaEnv,localCache);
case (Absyn.CREF(Absyn.WILD) :: restExps,localDfaEnv,localCache,localEnv)
equation
Expand All @@ -1506,9 +1509,10 @@ algorithm
localDfaEnv = listAppend(localDfaEnv,dfaEnvElem);
(localDfaEnv,localCache) = addVarsToDfaEnv(restExps,localDfaEnv,localCache,localEnv);
then (localDfaEnv,localCache);
case (_,_,_,_)
case (e::_,_,_,_)
equation
Debug.fprintln("matchcase", "- DFA.addVarsToDfaEnv failed");
str = Dump.printExpStr(e);
Debug.fprintln("matchcase", "- DFA.addVarsToDfaEnv failed " +& str);
then fail();
end matchcontinue;
end addVarsToDfaEnv;
Expand Down
5 changes: 5 additions & 0 deletions Compiler/Types.mo
Expand Up @@ -4219,26 +4219,31 @@ algorithm

case (e,(T_BOXED(t1),_),t2 as (T_INTEGER(_),_),polymorphicBindings,matchFunc)
equation
true = subtype(t1,t2);
(e_1,_,polymorphicBindings) = matchFunc(e, t1, t2, polymorphicBindings);
then
(Exp.CALL(Absyn.IDENT("mmc_unbox_integer"),{e_1},false,true,Exp.INT,false),t2,polymorphicBindings);
case (e,(T_BOXED(t1),_),t2 as (T_REAL(_),_),polymorphicBindings,matchFunc)
equation
true = subtype(t1,t2);
(e_1,_,polymorphicBindings) = matchFunc(e, t1, t2, polymorphicBindings);
then
(Exp.CALL(Absyn.IDENT("mmc_unbox_real"),{e_1},false,true,Exp.REAL,false),t2,polymorphicBindings);
case (e,(T_BOXED(t1),_),t2 as (T_BOOL(_),_),polymorphicBindings,matchFunc)
equation
true = subtype(t1,t2);
(e_1,_,polymorphicBindings) = matchFunc(e, t1, t2, polymorphicBindings);
then
(Exp.CALL(Absyn.IDENT("mmc_unbox_integer"),{e_1},false,true,Exp.BOOL,false),t2,polymorphicBindings);
case (e,(T_BOXED(t1),_),t2 as (T_STRING(_),_),polymorphicBindings,matchFunc)
equation
true = subtype(t1,t2);
(e_1,_,polymorphicBindings) = matchFunc(e, t1, t2, polymorphicBindings);
then
(Exp.CALL(Absyn.IDENT("mmc_unbox_string"),{e_1},false,true,Exp.STRING,false),t2,polymorphicBindings);
case (e,(T_BOXED(t1),_),t2 as (T_COMPLEX(complexClassType = ClassInf.RECORD(_), complexVarLst = v),_),polymorphicBindings,matchFunc)
equation
true = subtype(t1,t2);
(e_1,t2,polymorphicBindings) = matchFunc(e, t1, t2, polymorphicBindings);
t = elabType(t2);
then
Expand Down

0 comments on commit 3f32995

Please sign in to comment.