Skip to content

Commit

Permalink
- Don't add inside flows for empty arrays.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13965 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Nov 19, 2012
1 parent be531da commit 9a2547a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 48 deletions.
8 changes: 5 additions & 3 deletions Compiler/FrontEnd/ConnectUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -311,21 +311,23 @@ end makeConnectorType;
public function addConnectorVariablesFromDAE
"If the class state indicates a connector, this function adds all flow
variables in the dae as inside connectors to the connection sets."
input Boolean inIgnore;
input ClassInf.State inClassState;
input Prefix.Prefix inPrefix;
input list<DAE.Var> inVars;
input Sets inConnectionSet;
input Absyn.Info info;
output Sets outConnectionSet;
algorithm
outConnectionSet := match(inClassState, inPrefix, inVars, inConnectionSet, info)
outConnectionSet :=
match(inIgnore, inClassState, inPrefix, inVars, inConnectionSet, info)
local
Absyn.Path class_path;
list<DAE.Var> streams, flows;
Sets cs;

// check balance of non expandable connectors!
case (ClassInf.CONNECTOR(path = class_path, isExpandable = false), _, _, cs, _)
case (false, ClassInf.CONNECTOR(path = class_path, isExpandable = false), _, _, cs, _)
equation
checkConnectorBalance(inVars, class_path, info);
(flows, streams) = getStreamAndFlowVariables(inVars, {}, {});
Expand All @@ -334,7 +336,7 @@ algorithm
then
cs;

else then inConnectionSet;
else inConnectionSet;
end match;
end addConnectorVariablesFromDAE;

Expand Down
86 changes: 43 additions & 43 deletions Compiler/FrontEnd/Expression.mo
Original file line number Diff line number Diff line change
Expand Up @@ -81,59 +81,59 @@ protected import Util;
/* transform to other types */
/***************************************************/

public function intSubscript
"Converts an integer into an index subscript."
input Integer inInteger;
output Subscript outSubscript;
algorithm
outSubscript := DAE.INDEX(DAE.ICONST(inInteger));
end intSubscript;

public function intSubscripts
"function: intSubscripts
This function describes the function between a list of integers
and a list of DAE.Subscript where each integer is converted to
an integer indexing expression."
input list<Integer> inIntegerLst;
output list<Subscript> outSubscriptLst;
"Converts a list of integers into index subscripts."
input list<Integer> inIntegers;
output list<Subscript> outSubscripts;
algorithm
outSubscriptLst := match (inIntegerLst)
local
list<Subscript> xs_1;
Integer x;
list<Integer> xs;

case {} then {};

case (x :: xs)
equation
xs_1 = intSubscripts(xs);
then
(DAE.INDEX(DAE.ICONST(x)) :: xs_1);
end match;
outSubscripts := List.map(inIntegers, intSubscript);
end intSubscripts;

public function subscriptsInt "
function: subscriptsInt
author: PA
This function creates a list of ints from
a subscript list, see also intSubscripts."
input list<Subscript> inSubscriptLst;
output list<Integer> outIntegerLst;
public function subscriptInt
"Tries to convert a subscript to an integer index."
input Subscript inSubscript;
output Integer outInteger;
algorithm
outIntegerLst := matchcontinue (inSubscriptLst)
outInteger := match(inSubscript)
local
list<Integer> xs_1;
Integer x;
list<Subscript> xs;

case {} then {};

case (DAE.INDEX(exp = DAE.ICONST(integer = x)) :: xs)
equation
xs_1 = subscriptsInt(xs);
then
(x :: xs_1);

case (DAE.INDEX(exp = DAE.ENUM_LITERAL(index = x)) :: xs)

case DAE.INDEX(exp = DAE.ICONST(integer = x)) then x;
case DAE.INDEX(exp = DAE.ENUM_LITERAL(index = x)) then x;

end match;
end subscriptInt;

public function subscriptsInt
"Tries to convert a list of subscripts to integer indices."
input list<Subscript> inSubscripts;
output list<Integer> outIntegers;
algorithm
outIntegers := List.map(inSubscripts, subscriptInt);
end subscriptsInt;

public function subscriptIsZero
input Subscript inSubscript;
output Boolean outIsZero;
algorithm
outIsZero := matchcontinue(inSubscript)
case _
equation
xs_1 = subscriptsInt(xs);
true = 0 == subscriptInt(inSubscript);
then
(x :: xs_1);
true;

else false;
end matchcontinue;
end subscriptsInt;
end subscriptIsZero;

public function unelabExp
"function: unelabExp
Expand Down
26 changes: 24 additions & 2 deletions Compiler/FrontEnd/Inst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3251,7 +3251,7 @@ algorithm
ConnectionGraph.ConnectionGraph graph;
InstanceHierarchy ih;
DAE.DAElist fdae;
Boolean unrollForLoops;
Boolean unrollForLoops, zero_dims;
Absyn.Info info2;
list<Absyn.TypeSpec> tSpecs;
list<DAE.Type> tys;
Expand Down Expand Up @@ -3435,7 +3435,8 @@ algorithm

// If we are currently instantiating a connector, add all flow variables
// in it as inside connectors.
csets1 = ConnectUtil.addConnectorVariablesFromDAE(ci_state1, pre, vars, csets, info);
zero_dims = instDimsHasZeroDims(inst_dims);
csets1 = ConnectUtil.addConnectorVariablesFromDAE(zero_dims, ci_state1, pre, vars, csets, info);

// Reorder the connect equations to have non-expandable connect first:
// connect(non_expandable, non_expandable);
Expand Down Expand Up @@ -18227,4 +18228,25 @@ algorithm
end matchcontinue;
end checkParallelismWRTEnv;

protected function instDimsHasZeroDims
input InstDims inInstDims;
output Boolean outHasZeroDims;
algorithm
outHasZeroDims := matchcontinue(inInstDims)
local
list<DAE.Subscript> dims;
InstDims rest_dims;

case (dims :: _)
equation
true = List.exist(dims, Expression.subscriptIsZero);
then
true;

case (_ :: rest_dims) then instDimsHasZeroDims(rest_dims);

else false;
end matchcontinue;
end instDimsHasZeroDims;

end Inst;

0 comments on commit 9a2547a

Please sign in to comment.