Skip to content

Commit

Permalink
- Implemented assignments on the form cref := function_returning_tupl…
Browse files Browse the repository at this point in the history
…e(...),

  which is possibly needed for bug #1274.
- Added test case mofiles/TupleSingleAssign.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6094 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Sep 13, 2010
1 parent 7fa4d43 commit 9777e95
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
38 changes: 37 additions & 1 deletion Compiler/Inst.mo
Expand Up @@ -12640,7 +12640,7 @@ algorithm
(cache, e_1, eprop) = Ceval.cevalIfConstant(cache, env, e_1, eprop, impl);
(cache,e_2) = PrefixUtil.prefixExp(cache, env, ih, e_1, pre);
source = DAEUtil.addElementSourceFileInfo(source, info);
stmt = Algorithm.makeAssignment(DAE.CREF(ce_1,t), cprop, e_2, eprop, acc, initial_, source);
stmt = makeAssignment(DAE.CREF(ce_1,t), cprop, e_2, eprop, acc, initial_, source);
dae = DAEUtil.joinDaes(dae1,dae2);
then
(cache,{stmt},dae);
Expand Down Expand Up @@ -12968,6 +12968,42 @@ algorithm
end matchcontinue;
end instStatement;

protected function makeAssignment
"Wrapper for Algorithm that calls either makeAssignment or makeTupleAssignment
depending on whether the right side is a tuple or not. This makes it possible
to do cref := function_that_returns_tuple(...)."
input DAE.Exp inLhs;
input DAE.Properties inLhsProps;
input DAE.Exp inRhs;
input DAE.Properties inRhsProps;
input SCode.Accessibility inAccessibility;
input SCode.Initial inInitial;
input DAE.ElementSource inSource;
output Algorithm.Statement outStatement;
algorithm
outStatement := matchcontinue(inLhs, inLhsProps, inRhs, inRhsProps,
inAccessibility, inInitial, inSource)
local
list<DAE.Properties> wild_props;
Integer wild_count;
list<DAE.Exp> wilds;
// If the RHS is a function that returns a tuple while the LHS is a single
// value, make a tuple of the LHS and fill in the missing elements with
// wildcards.
case (_, DAE.PROP(type_ = _), DAE.CALL(path = _), DAE.PROP_TUPLE(type_ = _), _, _, _)
equation
_ :: wild_props = Types.propTuplePropList(inRhsProps);
wild_count = listLength(wild_props);
wilds = Util.listFill(DAE.CREF(DAE.WILD, DAE.ET_OTHER), wild_count);
wild_props = Util.listFill(DAE.PROP((DAE.T_ANYTYPE(NONE), NONE), DAE.C_VAR), wild_count);
then 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;
end makeAssignment;

protected function containsWhenStatements
"@author: adrpo
this functions returns true if the given
Expand Down
3 changes: 1 addition & 2 deletions Compiler/Types.mo
Expand Up @@ -365,11 +365,9 @@ algorithm
list<String> names;
list<DAE.ExpVar> evars;
list<Var> tvars;
// case(Exp.ENUM)
equation
tvars = Util.listMap(evars, convertFromExpToTypesVar);
ty = (DAE.T_ENUMERATION(index,path,names,tvars),NONE());
// ty = (DAE.T_ENUM,NONE);
then ty;
case(DAE.ET_ARRAY(at,dim::ad))
local DAE.ExpType at;
Expand Down Expand Up @@ -3593,6 +3591,7 @@ algorithm
c = constTupleAnd(c1, c2);
then
(e_1,DAE.PROP_TUPLE(t_1,c));

/* The problem with MetaModelica tuple is that it is a datatype (should use PROP instead of PROP_TUPLE)
* this case converts a TUPLE to META_TUPLE */
case (e,DAE.PROP_TUPLE(type_ = (gt as (DAE.T_TUPLE(_),_)),tupleConst = c1), DAE.PROP(type_ = (et as (DAE.T_METATUPLE(_),_)),constFlag = c2),printFailtrace)
Expand Down

0 comments on commit 9777e95

Please sign in to comment.