Skip to content

Commit

Permalink
Fixed connection of complex array types ;
Browse files Browse the repository at this point in the history
connect( arr1[1].conectorVar, arr2[7].secondConnectorVar)

Now non connected flow equations generate zero equation.

git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/MathCoreOSMC@4051 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Björn Zachrisson committed May 20, 2009
1 parent aac2cc7 commit a4e7757
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 28 deletions.
41 changes: 13 additions & 28 deletions Compiler/Connect.mo
Expand Up @@ -394,7 +394,7 @@ algorithm
s1 = findFlowSet(ss, r1_1,d1);
s2 = findFlowSet(ss, r2_1,d2);
ss_1 = merge(ss, s1, s2);
ss_2 = addArrayFlow(ss_1, r1,d1, r2,d2, i_1);
ss_2 = addArrayFlow(ss_1, r1,d1, r2,d2, i_1);
then
ss_2;
end matchcontinue;
Expand Down Expand Up @@ -1086,10 +1086,18 @@ algorithm
(v3,vSpecial) = extractOuterNonEnvDeclaredVars(ocl,true,flowCrefs);
vars = listAppend(v1, listAppend(v2,v3));
*/

//print(" v1: " +& Util.stringDelimitList(Util.listMap(v1,Exp.printComponentRefStr),", ") +& "\n");
//print(" v2: " +& Util.stringDelimitList(Util.listMap(v2,Exp.printComponentRefStr),", ") +& "\n");

vars = listAppend(v1, v2);
vars2 = getInnerFlowVariables(csets);
vars3 = getOuterConnectFlowVariables(csets,vars,prefix);
vars2 = getInnerFlowVariables(csets);
vars3 = getOuterConnectFlowVariables(csets,vars,prefix);
vars2 = listAppend(vars3,vars2);

//print(" vars2 : " +& Util.stringDelimitList(Util.listMap(vars2,Exp.printComponentRefStr),", ") +& "\n");

//print(" acquired: " +& Util.stringDelimitList(Util.listMap(vars2,Exp.printComponentRefStr),", ") +& "\n");
// last array subscripts are not present in vars, therefor removed from vars2 too.
vars2 = Util.listMap(vars2,Exp.crefStripLastSubs);
unconnectedvars = removeVariables(vars, vars2);
Expand All @@ -1098,7 +1106,6 @@ algorithm
// no prefix for top level
/* SE COMMENT ABOVE
unconnectedvars = Util.listUnion(vSpecial,unconnectedvars);*/

(cache,dae_1) = generateZeroflowEquations(cache,unconnectedvars,env,Prefix.NOPRE(),deletedComponents);
then
(cache,dae_1);
Expand Down Expand Up @@ -1418,7 +1425,7 @@ algorithm
Exp.Exp initExp;
case (indexSubscriptList, (cr, initExp))
equation
cr = Exp.subscriptCref(cr, indexSubscriptList);
cr = Exp.subscriptCref(cr, indexSubscriptList);
then
DAE.EQUATION(Exp.CREF(cr,Exp.REAL()), initExp);
end matchcontinue;
Expand Down Expand Up @@ -1708,28 +1715,6 @@ algorithm
Print.printBuf(printSetStr(inSet));
end printSet;

protected function pritnFlowRefStr ""
input tuple<Exp.ComponentRef, Face> inTplExpComponentRefFace;
output String os;
algorithm
os:=
matchcontinue (inTplExpComponentRefFace)
local Exp.ComponentRef c; String s1,s2;
case ((c,INNER()))
equation
s1 = Exp.printComponentRefStr(c);
s2 = s1 +& " INSIDE";
then
s2;
case ((c,OUTER()))
equation
s1 = Exp.printComponentRefStr(c);
s2 = s1 +& " OUTSIDE";
then
s2;
end matchcontinue;
end pritnFlowRefStr;

protected function printFlowRef
input tuple<Exp.ComponentRef, Face> inTplExpComponentRefFace;
algorithm
Expand Down Expand Up @@ -1812,7 +1797,7 @@ algorithm
end matchcontinue;
end printSetStr;

protected function printFlowRefStr
public function printFlowRefStr
input tuple<Exp.ComponentRef, Face> inTplExpComponentRefFace;
output String outString;
algorithm
Expand Down
163 changes: 163 additions & 0 deletions Compiler/Env.mo
Expand Up @@ -1436,6 +1436,35 @@ algorithm
Absyn.InnerOuter io;
case (NONE) then {};


/* Case where we have an array, assumed indexed which contains complex types. */
case (SOME(AVLTREENODE(SOME(AVLTREEVALUE(_,VAR(Types.VAR(id,(tatr as Types.ATTR(innerOuter=io)),b3,(tmpty as (Types.T_ARRAY(ad,at),_)),bind),_,_,_))),_,l,r)))
local
Types.ArrayDim ad;
Types.Type at,tmpty,flatArrayType;
Types.Attributes tatr;
Boolean b3;
Types.Binding bind;
list<Integer> adims;
list<Types.Var> tvars;
list<list<Integer>> indexIntegerLists;
list<list<Exp.Subscript>> indexSubscriptLists;
//list<Exp.ComponentRef> arrayComplex;
equation
(_,false) = Inst.innerOuterBooleans(io);
((flatArrayType as (Types.T_COMPLEX(_,tvars,_,_),_)),adims) = Types.flattenArrayType(tmpty);
false = Types.isComplexConnector(flatArrayType);

indexSubscriptLists = createSubs(adims);

lst1 = localInsideConnectorFlowvars3_2(tvars, id, indexSubscriptLists);
lst2 = localInsideConnectorFlowvars2(l);
lst3 = localInsideConnectorFlowvars2(r);
res = Util.listFlatten({lst1,lst2,lst3});
//print(" returning: " +& Util.stringDelimitList(Util.listMap(res,Exp.printComponentRefStr), ", ") +& "\n");
then
res;

/* If CONNECTOR then outside and not inside, skip.. */
case (SOME(AVLTREENODE(SOME(AVLTREEVALUE(_,VAR(Types.VAR(id,_,_,(Types.T_COMPLEX(ClassInf.CONNECTOR(_),_,_,_),_),_),_,_,_))),_,l,r)))
equation
Expand Down Expand Up @@ -1506,6 +1535,140 @@ algorithm
end matchcontinue;
end localInsideConnectorFlowvars3;

protected function localInsideConnectorFlowvars3_2 "
Author: BZ, 2009-05
Extract vars from complex types.
Helper function for array complex vars.
"
input list<Types.Var> inTypesVarLst;
input Ident inIdent;
input list<list<Exp.Subscript>> ssubs;
output list<Exp.ComponentRef> outExpComponentRefLst;
algorithm
outExpComponentRefLst:=
matchcontinue (inTypesVarLst,inIdent,ssubs)
local
list<Exp.ComponentRef> lst1,lst2,lst3,res;
Ident id,oid,name;
list<Types.Var> vars,xs;
Absyn.InnerOuter io;
list<Exp.Subscript> s;
Types.Var tv;
case ({},_,_) then {};
case (_,_,{}) then {};
case (((tv as Types.VAR(name = id,attributes=Types.ATTR(innerOuter=io),type_ = (Types.T_COMPLEX(complexClassType = ClassInf.CONNECTOR(string = name),complexVarLst = vars),_))) :: xs),oid,s::ssubs)
equation
lst3 = localInsideConnectorFlowvars3_2({tv},oid,ssubs);
lst1 = localInsideConnectorFlowvars3_2(xs, oid,s::ssubs);
(_,false) = Inst.innerOuterBooleans(io);
//lst2 = Types.flowVariables(vars, Exp.CREF_QUAL(oid,Exp.OTHER(),{},Exp.CREF_IDENT(id,Exp.OTHER(),{})));
lst2 = Types.flowVariables(vars, Exp.CREF_QUAL(oid,Exp.COMPLEX(name,{},ClassInf.CONNECTOR(name)),s,Exp.CREF_IDENT(id,Exp.COMPLEX(name,{},ClassInf.CONNECTOR(name)),{})));
res = Util.listFlatten({lst1, lst2,lst3});
then
res;
case ((_ :: xs),oid,ssubs)
equation
//print(" **** FAILURE localInsideConnectorFlowvars3\n **** ");
res = localInsideConnectorFlowvars3_2(xs, oid,ssubs);
then
res;
end matchcontinue;
end localInsideConnectorFlowvars3_2;

protected function createSubs "
Author: BZ, 2009-05
Create subscripts from given integerlist of dimensions, ex
{2,3} => {1,1},{1,2},{1,3},{2,1},{2,2},{2,3}.
"
input list<Integer> inInts;
output list<list<Exp.Subscript>> osubs;
algorithm osubs := matchcontinue(inInts)
local
list<Integer> ints;
Integer i;
list<Exp.Subscript> localSubs;
case({}) then {};
case(i::inInts)
equation
osubs = createSubs(inInts);
ints = Util.listIntRange(i);
localSubs = Util.listMap(ints,integer2Subscript);
osubs = createSubs2(localSubs,osubs);
//_ = Util.listMap(osubs,dummyDump);
then
osubs;
end matchcontinue;
end createSubs;

protected function dummyDump "
Author: BZ, 2009-05
Debug function, print subscripts.
"
input list<Exp.Subscript> subs;
output String str;
algorithm str := matchcontinue(subs)
local
Exp.Subscript s;
case(subs)
equation
str = " subs: " +& Util.stringDelimitList(Util.listMap(subs,Exp.printSubscriptStr),", ") +& "\n";
print(str);
then
str;
end matchcontinue;
end dummyDump;

protected function createSubs2
input list<Exp.Subscript> s;
input list<list<Exp.Subscript>> subs;
output list<list<Exp.Subscript>> osubs;
algorithm osubs := matchcontinue(s,subs)
local
list<Exp.Subscript> lsubs;
list<list<Exp.Subscript>> lssubs;
Exp.Subscript sub;
case({},_) then {};
case(sub::s,{}) // base case
equation
osubs = createSubs2(s,{});
then
{sub}::osubs;
case(sub::s,subs)
equation
lssubs = createSubs3(sub,subs);
osubs = createSubs2(s,subs);
osubs = listAppend(lssubs,osubs);
then
osubs;
end matchcontinue;
end createSubs2;

protected function createSubs3
input Exp.Subscript s;
input list<list<Exp.Subscript>> subs;
output list<list<Exp.Subscript>> osubs;
algorithm osubs := matchcontinue(s,subs)
local
list<Exp.Subscript> lsubs;
case(_,{}) then {};
case(s,lsubs::subs)
equation
osubs = createSubs3(s,subs);
lsubs = listAppend({s},lsubs);
then
lsubs::osubs;
end matchcontinue;
end createSubs3;

protected function integer2Subscript "
@author adrpo
given an integer transform it into an Exp.Subscript"
input Integer index;
output Exp.Subscript subscript;
algorithm
subscript := Exp.INDEX(Exp.ICONST(index));
end integer2Subscript;

/* AVL impementation */

public
Expand Down
9 changes: 9 additions & 0 deletions Compiler/Types.mo
Expand Up @@ -467,6 +467,15 @@ algorithm
end matchcontinue;
end simpleType;

public function isComplexConnector ""
input Type t;
output Boolean b;
algorithm b := matchcontinue(t)
case((T_COMPLEX(ClassInf.CONNECTOR(_),_,_,_),_)) then true;
case(_) then false;
end matchcontinue;
end isComplexConnector;

public function isComplexType "
Author: BZ, 2008-11
This function checks wheter a type is complex AND not extending a base type.
Expand Down

0 comments on commit a4e7757

Please sign in to comment.