Skip to content

Commit

Permalink
- Fixes for bug: #1954
Browse files Browse the repository at this point in the history
Static.mo
- perform vectorization on inStream and actualStream

ComponentReference.mo, ExpressionDump.mo
- better debug printing of expressions and crefs

ExpressionDumpTpl.tpl
- prefix exps with /*asub*/ or /*tsub*/ so we know which one it is.

CodegenC.tpl
- use // as expressions can have /* */ in them!

SCodeAnalyseRedeclare.mo
- merge modifiers of derived classes on chain (more work is needed) 
  but it seems to fix issues for some Fluid examples already

ConnectUtil.mo
- use the types of the input expressions/crefs to build the types of expressions needed for
  evaluation of inStream and actualStream.

- Some tests will fail due to changes in ExpressionDumpTpl.tpl, I'll fix them with the output from Hudson.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14068 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Nov 26, 2012
1 parent 4a75005 commit 221881a
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 65 deletions.
25 changes: 13 additions & 12 deletions Compiler/FrontEnd/ComponentReference.mo
Expand Up @@ -648,36 +648,37 @@ algorithm

case DAE.CREF_IDENT(ident = s,identType=ty,subscriptLst = subs)
equation
str_1 = ExpressionDump.printListStr(subs, ExpressionDump.debugPrintSubscriptStr, ",");
str = s +& Util.if_(stringLength(str_1) > 0, "["+& str_1 +& "}" , "");
// this printing way will be useful when adressin the 'crefEqual' bug.
// str = ComponentReference.printComponentRef2Str(s, subs);
str_1 = ExpressionDump.printListStr(subs, ExpressionDump.debugPrintSubscriptStr, ", ");
str = s +& Util.if_(stringLength(str_1) > 0, "["+& str_1 +& "]", "");
str2 = Types.unparseType(ty);
str = stringAppendList({str," [",str2,"]"});
then
str;

case DAE.CREF_QUAL(ident = s,identType=ty,subscriptLst = subs,componentRef = cr) /* Does not handle names with underscores */
case DAE.CREF_QUAL(ident = s,identType=ty,subscriptLst = subs,componentRef = cr)
equation
true = Config.modelicaOutput();
str = printComponentRef2Str(s, subs);
false = Config.modelicaOutput();
str_1 = ExpressionDump.printListStr(subs, ExpressionDump.debugPrintSubscriptStr, ", ");
str = s +& Util.if_(stringLength(str_1) > 0, "["+& str_1 +& "]", "");
str2 = Types.unparseType(ty);
strrest = debugPrintComponentRefTypeStr(cr);
str = stringAppendList({str," [",str2,"] ", "__", strrest});
str = stringAppendList({str," [",str2,"] ", ".", strrest});
then
str;

case DAE.WILD() then "_";

// Does not handle names with underscores
case DAE.CREF_QUAL(ident = s,identType=ty,subscriptLst = subs,componentRef = cr)
equation
false = Config.modelicaOutput();
true = Config.modelicaOutput();
str = printComponentRef2Str(s, subs);
str2 = Types.unparseType(ty);
strrest = debugPrintComponentRefTypeStr(cr);
str = stringAppendList({str," [",str2,"] ", ".", strrest});
str = stringAppendList({str," [",str2,"] ", "__", strrest});
then
str;

case DAE.WILD() then "_";

end matchcontinue;
end debugPrintComponentRefTypeStr;

Expand Down
107 changes: 91 additions & 16 deletions Compiler/FrontEnd/ConnectUtil.mo
Expand Up @@ -71,6 +71,7 @@ protected import System;
protected import Types;
protected import Util;
protected import InstSection;
protected import ExpressionDump;

// Import some types from Connect.
public type Face = Connect.Face;
Expand Down Expand Up @@ -2957,9 +2958,11 @@ protected function sumInside1
output DAE.Exp outExp;
protected
DAE.Exp stream_exp, flow_exp;
DAE.Type flowTy, streamTy;
algorithm
(stream_exp, flow_exp) := streamFlowExp(inElement);
flow_exp := DAE.UNARY(DAE.UMINUS(DAE.T_REAL_DEFAULT), flow_exp);
flowTy := Expression.typeof(flow_exp);
flow_exp := DAE.UNARY(DAE.UMINUS(flowTy), flow_exp);
outExp := Expression.expMul(makePositiveMaxCall(flow_exp), stream_exp);
end sumInside1;

Expand All @@ -2984,9 +2987,11 @@ protected function sumInside2
output DAE.Exp outExp;
protected
DAE.Exp flow_exp;
DAE.Type flowTy;
algorithm
flow_exp := flowExp(inElement);
flow_exp := DAE.UNARY(DAE.UMINUS(DAE.T_REAL_DEFAULT), flow_exp);
flowTy := Expression.typeof(flow_exp);
flow_exp := DAE.UNARY(DAE.UMINUS(flowTy), flow_exp);
outExp := makePositiveMaxCall(flow_exp);
end sumInside2;

Expand All @@ -3008,19 +3013,41 @@ protected function makeInStreamCall
input DAE.Exp inStreamExp;
output DAE.Exp outInStreamCall;
annotation(__OpenModelica_EarlyInline = true);
algorithm
outInStreamCall := DAE.CALL(Absyn.IDENT("inStream"), {inStreamExp},
DAE.CALL_ATTR(DAE.T_REAL_DEFAULT, false, false, DAE.NO_INLINE(), DAE.NO_TAIL()));
protected
DAE.Type ty;
algorithm
ty := Expression.typeof(inStreamExp);
outInStreamCall :=
DAE.CALL(
Absyn.IDENT("inStream"),
{inStreamExp},
DAE.CALL_ATTR(
ty,
false,
false,
DAE.NO_INLINE(),
DAE.NO_TAIL()));
end makeInStreamCall;

protected function makePositiveMaxCall
"Generates a max(flow_exp, eps) call."
input DAE.Exp inFlowExp;
output DAE.Exp outPositiveMaxCall;
annotation(__OpenModelica_EarlyInline = true);
algorithm
outPositiveMaxCall := DAE.CALL(Absyn.IDENT("max"),
{inFlowExp, DAE.RCONST(1e-15)}, DAE.CALL_ATTR(DAE.T_REAL_DEFAULT, false, true, DAE.NO_INLINE(), DAE.NO_TAIL()));
protected
DAE.Type ty;
algorithm
ty := Expression.typeof(inFlowExp);
outPositiveMaxCall :=
DAE.CALL(
Absyn.IDENT("max"),
{inFlowExp, DAE.RCONST(1e-15)},
DAE.CALL_ATTR(
ty,
false,
true,
DAE.NO_INLINE(),
DAE.NO_TAIL()));
end makePositiveMaxCall;

protected function evaluateStreamOperators
Expand Down Expand Up @@ -3074,21 +3101,69 @@ protected function evaluateStreamOperatorsExp
input tuple<DAE.Exp, tuple<Connect.Sets, array<Set>>> inTuple;
output tuple<DAE.Exp, tuple<Connect.Sets, array<Set>>> outTuple;
algorithm
outTuple := match(inTuple)
outTuple := matchcontinue(inTuple)
local
DAE.ComponentRef cr;
tuple<Connect.Sets, array<Set>> sets;
DAE.Exp e;
DAE.Type ty;
String s;

// sometimes we get ASUB(inStream/actualStream, 1) so we should remove that
/*/ TODO! FIXME! make this work correctly without this workaround!
case ((DAE.ASUB(e, _), sets))
equation
DAE.CALL(path = Absyn.IDENT(s)) = e;
true = listMember(s, {"inStream", "actualStream"});
((e, sets)) = evaluateStreamOperatorsExp((e, sets));
print("Evaluated ASUB(" +& ExpressionDump.dumpExpStr(e, 0) +& ")\n");
then
((e, sets));*/

case ((DAE.CALL(path = Absyn.IDENT("inStream"),
expLst = {DAE.CREF(componentRef = cr)}), sets))
then ((evaluateInStream(cr, sets), sets));
case ((DAE.CALL(path = Absyn.IDENT("actualStream"),
expLst = {DAE.CREF(componentRef = cr)}), sets))
then ((evaluateActualStream(cr, sets), sets));
case ((DAE.CALL(path = Absyn.IDENT("inStream"),
expLst = {DAE.CREF(componentRef = cr, ty = ty)}), sets))
equation
e = evaluateInStream(cr, sets);
// print("Evaluated inStream(" +& ExpressionDump.dumpExpStr(DAE.CREF(cr, ty), 0) +& ") ->\n" +& ExpressionDump.dumpExpStr(e, 0) +& "\n");
then
((e, sets));
case ((DAE.CALL(path = Absyn.IDENT("actualStream"),
expLst = {DAE.CREF(componentRef = cr, ty = ty)}), sets))
equation
e = evaluateActualStream(cr, sets);
// print("Evaluated actualStream(" +& ExpressionDump.dumpExpStr(DAE.CREF(cr, ty), 0) +& ") ->\n" +& ExpressionDump.dumpExpStr(e, 0) +& "\n");
then
((e, sets));

else inTuple;
end match;

end matchcontinue;
end evaluateStreamOperatorsExp;

protected function mkArrayIfNeeded
"@author: adrpo
does an array out of exp if needed"
input DAE.Type inTy;
input DAE.Exp inExp;
output DAE.Exp outExp;
algorithm
outExp := matchcontinue(inTy, inExp)
local
DAE.Exp exp;
DAE.Dimensions dims;

case (_, _)
equation
dims = Types.getDimensions(inTy);
exp = Expression.arrayFill(dims, inExp);
then
exp;

else inExp;

end matchcontinue;
end mkArrayIfNeeded;

public function evaluateInStream
"This function evaluates the inStream operator for a component reference,
given the connection sets."
Expand Down

0 comments on commit 221881a

Please sign in to comment.