Skip to content

Commit

Permalink
- Changed tuple-assignments to use subtype instead of matchType (sinc…
Browse files Browse the repository at this point in the history
…e the type-casting rules do not become part of the DAE)

  - All testcases still work (because only MetaModelica uses this feature, and when using MM, we have access to pattern-matching assignments, which do work properly)


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8062 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Mar 2, 2011
1 parent 4c043e5 commit fca7b30
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/Algorithm.mo
Expand Up @@ -361,7 +361,7 @@ algorithm
fail();
// a normal prop in rhs that contains a T_TUPLE!
case (expl,lhprops,rhs,DAE.PROP(type_ = (DAE.T_TUPLE(tupleType = tpl),_)),_,source)
equation
equation
bvals = Util.listMap(lhprops, Types.propAnyConst);
DAE.C_VAR() = Util.listReduce(bvals, Types.constOr);
lhrtypes = Util.listMap(lhprops, Types.getPropType);
Expand All @@ -376,7 +376,7 @@ algorithm
bvals = Util.listMap(lhprops, Types.propAnyConst);
DAE.C_VAR() = Util.listReduce(bvals, Types.constOr);
lhrtypes = Util.listMap(lhprops, Types.getPropType);
Types.matchTypeTupleCall(rhs, tpl, lhrtypes);
Types.matchTypeTupleCall(rhs, tpl, lhrtypes);
/* Don\'t use new rhs\', since type conversions of several output args are not clearly defined. */
then
DAE.STMT_TUPLE_ASSIGN(DAE.ET_OTHER(),expl,rhs,source);
Expand Down
7 changes: 3 additions & 4 deletions Compiler/FrontEnd/InstSection.mo
Expand Up @@ -2592,7 +2592,7 @@ protected function makeAssignment
input DAE.ElementSource inSource;
output Algorithm.Statement outStatement;
algorithm
outStatement := matchcontinue(inLhs, inLhsProps, inRhs, inRhsProps,
outStatement := match (inLhs, inLhsProps, inRhs, inRhsProps,
inAccessibility, inInitial, inSource)
local
list<DAE.Properties> wild_props;
Expand All @@ -2614,9 +2614,8 @@ algorithm
Algorithm.makeTupleAssignment(inLhs :: wilds, inLhsProps :: wild_props, inRhs, inRhsProps, inInitial, inSource);

// Otherwise, call Algorithm.makeAssignment as usual.
case (_, _, _, _, _, _, _)
then Algorithm.makeAssignment(inLhs, inLhsProps, inRhs, inRhsProps, inAccessibility, inInitial, inSource);
end matchcontinue;
else Algorithm.makeAssignment(inLhs, inLhsProps, inRhs, inRhsProps, inAccessibility, inInitial, inSource);
end match;
end makeAssignment;

protected function containsWhenStatements
Expand Down
7 changes: 5 additions & 2 deletions Compiler/FrontEnd/Types.mo
Expand Up @@ -3876,13 +3876,16 @@ algorithm
_ :=
matchcontinue (inExp1,inTypeLst2,inTypeLst3)
local
DAE.Exp e;
DAE.Exp e,oe;
Type t1,t2;
list<Type> ts1,ts2;
case (_,_,{}) then ();
case (e,(t1 :: ts1),(t2 :: ts2))
equation
(_,_) = matchType(e, t1, t2, true);
// We cannot use matchType here because it does not cast tuple calls properly
true = subtype(t1, t2);
/* (oe,_) = matchType(e, t1, t2, true);
true = Expression.expEqual(e,oe); */
matchTypeTupleCall(e, ts1, ts2);
then ();
case (_,(t1 :: ts1),(t2 :: ts2))
Expand Down
5 changes: 4 additions & 1 deletion Compiler/susan_codegen/SimCode/SimCodeC.tpl
Expand Up @@ -1705,6 +1705,7 @@ template functionDAE( list<SimEqSystem> allEquationsPlusWhen,
;separator="\n")

let reinit = (whenClauses |> when hasindex i0 =>

genreinits(when, &varDecls,i0)
;separator="\n")
<<
Expand Down Expand Up @@ -5431,6 +5432,7 @@ template daeExpMatrixRow(list<tuple<Exp,Boolean>> row, String arrayTypeStr,
"Helper to daeExpMatrix."
::=
let &varLstStr = buffer "" /*BUFD*/

let preExp2 = (row |> col as (e, b) =>
let scalarStr = if b then "scalar_" else ""
let scalarRefStr = if b then "" else "&"
Expand Down Expand Up @@ -6228,7 +6230,8 @@ template algStmtAssignPattern(DAE.Statement stmt, Context context, Text &varDecl
let &preExp = buffer ""
let &assignments = buffer ""
let expPart = daeExp(s.exp, context, &preExp, &varDecls)
<<<%preExp%>
<</* Pattern-matching assignment */
<%preExp%>
<%patternMatch(lhs.pattern,expPart,"MMC_THROW()",&varDecls,&assignments)%><%assignments%>>>
end algStmtAssignPattern;

Expand Down

0 comments on commit fca7b30

Please sign in to comment.