Skip to content

Commit

Permalink
Inline.mo: Handle inlining of functions with record output that is sp…
Browse files Browse the repository at this point in the history
…lit into assignments like:

{{{#!mo
  output RecType rec;
algorithm
  rec.r1 := 1.0;
  rec.r2 := 2.0;
  rec.r3 := 1.5;
}}}


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@20582 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed May 13, 2014
1 parent 6c537e9 commit feee3c0
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions Compiler/FrontEnd/Inline.mo
Expand Up @@ -55,6 +55,7 @@ public import Values;
protected type Ident = String;
public type Functiontuple = tuple<Option<DAE.FunctionTree>,list<DAE.InlineType>>;

protected import ClassInf;
protected import ComponentReference;
protected import Config;
protected import DAEUtil;
Expand Down Expand Up @@ -1429,6 +1430,7 @@ algorithm
VarTransform.VariableReplacements repl;
Boolean generateEvents;
Option<SCode.Comment> comment;
DAE.Type ty;

/* If we disable inlining by use of flags, we still inline builtin functions */
case ((DAE.CALL(attr=DAE.CALL_ATTR(inlineType=inlineType)),_))
Expand Down Expand Up @@ -1460,7 +1462,7 @@ algorithm
then
((newExp1,(fns,true,assrtLst)));

case ((e1 as DAE.CALL(p,args,DAE.CALL_ATTR(inlineType=inlineType)),(fns,_,assrtLstIn)))
case ((e1 as DAE.CALL(p,args,DAE.CALL_ATTR(ty=ty,inlineType=inlineType)),(fns,_,assrtLstIn)))
// no assert detected
equation
false = Config.acceptMetaModelicaGrammar();
Expand All @@ -1472,7 +1474,7 @@ algorithm
// merge statements to one line
(repl,assrtStmts) = mergeFunctionBody(stmts,repl,{});
true = List.isEmpty(assrtStmts);
newExp = VarTransform.getReplacement(repl,cr);
newExp = getReplacementCheckComplex(repl,cr,ty);
argmap = List.threadTuple(crefs,args);
(argmap,checkcr) = extendCrefRecords(argmap,HashTableCG.emptyHashTable());
// compare types
Expand All @@ -1487,7 +1489,7 @@ algorithm
then
((newExp1,(fns,true,assrtLst)));

case ((e1 as DAE.CALL(p,args,DAE.CALL_ATTR(inlineType=inlineType)),(fns,_,assrtLstIn)))
case ((e1 as DAE.CALL(p,args,DAE.CALL_ATTR(ty=ty,inlineType=inlineType)),(fns,_,assrtLstIn)))
// assert detected
equation
false = Config.acceptMetaModelicaGrammar();
Expand All @@ -1502,7 +1504,7 @@ algorithm
true = listLength(assrtStmts) == 1;
assrt = listGet(assrtStmts,1);
DAE.STMT_ASSERT(source=_) = assrt;
newExp = VarTransform.getReplacement(repl,cr); // the function that replaces the output variable
newExp = getReplacementCheckComplex(repl,cr,ty); // the function that replaces the output variable
argmap = List.threadTuple(crefs,args);
(argmap,checkcr) = extendCrefRecords(argmap,HashTableCG.emptyHashTable());
// compare types
Expand Down Expand Up @@ -2259,4 +2261,26 @@ algorithm
end match;
end inlineEquationExp;

protected function getReplacementCheckComplex
input VarTransform.VariableReplacements repl;
input DAE.ComponentRef cr;
input DAE.Type ty;
output DAE.Exp exp;
algorithm
exp := matchcontinue (repl,cr,ty)
local
list<DAE.Var> vars;
list<DAE.ComponentRef> crs;
list<String> strs;
list<DAE.Exp> exps;
Absyn.Path path;
case (_,_,_) then VarTransform.getReplacement(repl,cr);
case (_,_,DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(path),varLst=vars))
equation
crs = List.map1(List.map(vars,Types.varName),ComponentReference.appendStringCref,cr);
exps = List.map1r(crs, VarTransform.getReplacement, repl);
then DAE.CALL(path,exps,DAE.CALL_ATTR(ty,false,false,false,DAE.NO_INLINE(),DAE.NO_TAIL()));
end matchcontinue;
end getReplacementCheckComplex;

end Inline;

0 comments on commit feee3c0

Please sign in to comment.