Skip to content

Commit

Permalink
- fixes for bug #1947
Browse files Browse the repository at this point in the history
Inst.mo
- send the connection graph to InnerOuter.retrieveOuterConnections 
  as it does InstSection.connectComponents and it can change graph!

InnerOuter.mo
- handle the connection graph in InnerOuter.retrieveOuterConnections 
  and down to InstSection.connectComponents

More prefixing for DAE.ElementSources in connect equations in InstSection.mo, 
also display prefix/component in ConnectUtil.mo when adding the unconnected 
inside flow comment to DAE.ElementSource to know where the prefix ends.

- 

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14011 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Nov 21, 2012
1 parent 89f929f commit 991b036
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/ConnectUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ algorithm
equation
sc = sc + 1;
src = DAEUtil.addAdditionalComment(inSource, " add inside flow(" +&
PrefixUtil.printPrefixStr(inPrefix) +& "." +&
PrefixUtil.printPrefixStr(inPrefix) +& "/" +&
ComponentReference.printComponentRefStr(inCref) +&
")");
e = newElement(inCref, Connect.INSIDE(), Connect.FLOW(), src, sc);
Expand Down
72 changes: 42 additions & 30 deletions Compiler/FrontEnd/InnerOuter.mo
Original file line number Diff line number Diff line change
Expand Up @@ -619,15 +619,17 @@ public function retrieveOuterConnections
input Prefix.Prefix inPrefix;
input Connect.Sets inSets;
input Boolean inTopCall;
input ConnectionGraph.ConnectionGraph inCGraph;
output Connect.Sets outSets;
output list<Connect.OuterConnect> outInnerOuterConnects;
output ConnectionGraph.ConnectionGraph outCGraph;
protected
list<Connect.OuterConnect> oc;
Connect.Sets csets;
algorithm
Connect.SETS(outerConnects = oc) := inSets;
(oc, csets, outInnerOuterConnects) :=
retrieveOuterConnections2(inCache, inEnv, inIH, inPrefix, oc, inSets, inTopCall);
(oc, csets, outInnerOuterConnects, outCGraph) :=
retrieveOuterConnections2(inCache, inEnv, inIH, inPrefix, oc, inSets, inTopCall, inCGraph);
outSets := ConnectUtil.setOuterConnects(csets, oc);
end retrieveOuterConnections;

Expand Down Expand Up @@ -675,12 +677,14 @@ protected function retrieveOuterConnections2
input list<Connect.OuterConnect> inOuterConnects;
input Connect.Sets inSets;
input Boolean inTopCall;
input ConnectionGraph.ConnectionGraph inCGraph;
output list<Connect.OuterConnect> outOuterConnects;
output Connect.Sets outSets;
output list<Connect.OuterConnect> outInnerOuterConnects;
output ConnectionGraph.ConnectionGraph outCGraph;
algorithm
(outOuterConnects, outSets, outInnerOuterConnects) :=
matchcontinue(inCache, inEnv, inIH, inPrefix, inOuterConnects, inSets, inTopCall)
(outOuterConnects, outSets, outInnerOuterConnects, outCGraph) :=
matchcontinue(inCache, inEnv, inIH, inPrefix, inOuterConnects, inSets, inTopCall, inCGraph)
local
DAE.ComponentRef cr1, cr2;
Absyn.InnerOuter io1, io2;
Expand All @@ -692,13 +696,14 @@ algorithm
DAE.ElementSource source "the origin of the element";
Absyn.Info info;
Connect.Sets sets;
ConnectionGraph.ConnectionGraph graph;

// handle empty
case (_, _, _, _, {}, _, _) then (inOuterConnects, inSets, {});
case (_, _, _, _, {}, _, _, _) then (inOuterConnects, inSets, {}, inCGraph);

// an inner only outer connect
case(_, _, _, _, Connect.OUTERCONNECT(scope, cr1, io1, f1, cr2, io2, f2,
source as DAE.SOURCE(info = info)) :: rest_oc, sets, _)
source as DAE.SOURCE(info = info)) :: rest_oc, sets, _, graph)
equation
(inner1, outer1) = lookupVarInnerOuterAttr(inCache, inEnv, inIH, cr1, cr2);

Expand All @@ -712,21 +717,21 @@ algorithm
(sets, added) = ConnectUtil.addOuterConnectToSets(cr1, cr2, io1, io2, f1, f2, sets, info);

// if no connection set available (added = false), create new one
sets = addOuterConnectIfEmpty(inCache, inEnv, inIH, inPrefix, sets,
added, cr1, io1, f1, cr2, io2, f2, info);
(sets, graph) = addOuterConnectIfEmpty(inCache, inEnv, inIH, inPrefix, sets,
added, cr1, io1, f1, cr2, io2, f2, info, graph);

(rest_oc, sets, ioc) =
retrieveOuterConnections2(inCache, inEnv, inIH, inPrefix, rest_oc, sets, inTopCall);
(rest_oc, sets, ioc, graph) =
retrieveOuterConnections2(inCache, inEnv, inIH, inPrefix, rest_oc, sets, inTopCall, graph);

// if is also outer, then keep it also in the outer connects
rest_oc = Util.if_(outer1,
Connect.OUTERCONNECT(scope, cr1, io1, f1, cr2, io2, f2, source) :: rest_oc, rest_oc);
then
(rest_oc, sets, ioc);
(rest_oc, sets, ioc, graph);

// this case is for innerouter declarations, since we do not have them in environment we need to treat them in a special way
case(_, _, _, _, Connect.OUTERCONNECT(scope, cr1, io1, f1, cr2, io2, f2,
source as DAE.SOURCE(info = info)) :: rest_oc, sets, true)
source as DAE.SOURCE(info = info)) :: rest_oc, sets, true, graph)
equation
(inner1, outer1) = innerOuterBooleans(io1);
(inner2, outer2) = innerOuterBooleans(io2);
Expand All @@ -738,20 +743,20 @@ algorithm

(sets, added) = ConnectUtil.addOuterConnectToSets(cr1, cr2, io1, io2, f1, f2, sets, info);
// If no connection set available (added = false), create new one
sets = addOuterConnectIfEmpty(inCache, inEnv, inIH, inPrefix, sets,
added, cr1, io1, f1, cr2, io2, f2, info);
(rest_oc, sets, ioc) =
retrieveOuterConnections2(inCache, inEnv, inIH, inPrefix, rest_oc, sets, true);
(sets, graph) = addOuterConnectIfEmpty(inCache, inEnv, inIH, inPrefix, sets,
added, cr1, io1, f1, cr2, io2, f2, info, graph);
(rest_oc, sets, ioc, graph) =
retrieveOuterConnections2(inCache, inEnv, inIH, inPrefix, rest_oc, sets, true, graph);
then
(rest_oc, sets, ioc);
(rest_oc, sets, ioc, graph);

// just keep the outer connects the same if we don't find them in the same scope
case(_, _, _, _, oc :: rest_oc, sets, _)
case(_, _, _, _, oc :: rest_oc, sets, _, graph)
equation
(rest_oc, sets, ioc) =
retrieveOuterConnections2(inCache, inEnv, inIH, inPrefix, rest_oc, sets, inTopCall);
(rest_oc, sets, ioc, graph) =
retrieveOuterConnections2(inCache, inEnv, inIH, inPrefix, rest_oc, sets, inTopCall, graph);
then
(oc :: rest_oc, sets, ioc);
(oc :: rest_oc, sets, ioc, graph);
end matchcontinue;
end retrieveOuterConnections2;

Expand Down Expand Up @@ -790,9 +795,11 @@ protected function addOuterConnectIfEmpty
input Absyn.InnerOuter iio2;
input Connect.Face f2;
input Absyn.Info info;
input ConnectionGraph.ConnectionGraph inCGraph;
output Connect.Sets outSets;
output ConnectionGraph.ConnectionGraph outCGraph;
algorithm
outSets := match(inCache,inEnv,inIH,pre,inSets,added,cr1,iio1,f1,cr2,iio2,f2,info)
(outSets, outCGraph) := match(inCache,inEnv,inIH,pre,inSets,added,cr1,iio1,f1,cr2,iio2,f2,info,inCGraph)
local
SCode.Variability vt1,vt2;
DAE.Type t1,t2;
Expand All @@ -806,27 +813,32 @@ algorithm
list<Connect.OuterConnect> oc;
Env.Cache cache;
Env.Env env;
Absyn.InnerOuter io1,io2;
Absyn.InnerOuter io1,io2;
ConnectionGraph.ConnectionGraph graph;

// if it was added, return the same
case(cache,env,ih,_,_,true,_,_,_,_,_,_,_)
then inSets;
case(cache,env,ih,_,_,true,_,_,_,_,_,_,_,_)
then (inSets, inCGraph);

// if it was not added, add it (search for both components)
case(cache,env,ih,_, Connect.SETS(sets, sc, cl, cc, oc),false,_,io1,_,_,io2,_,_)
case(cache,env,ih,_, Connect.SETS(sets, sc, cl, cc, oc),false,_,io1,_,_,io2,_,_, graph)
equation
(cache,DAE.ATTR(connectorType = ct, variability = vt1),t1,_,_,_,_,_,_) = Lookup.lookupVar(cache,env,cr1);
(cache,DAE.ATTR(variability = vt2),t2,_,_,_,_,_,_) = Lookup.lookupVar(cache,env,cr2);
io1 = removeOuter(io1);
io2 = removeOuter(io2);
(cache,env,ih, Connect.SETS(sets = sets, setCount = sc, connections = cl),dae,_) =
InstSection.connectComponents(cache,env,ih,Connect.SETS(sets, sc, cl, {}, {}),pre,cr1,f1,t1,vt1,cr2,f2,t2,vt2,ct,io1,io2,ConnectionGraph.EMPTY,info);
(cache,env,ih, Connect.SETS(sets = sets, setCount = sc, connections = cl),dae, graph) =
InstSection.connectComponents(
cache,env,ih,
Connect.SETS(sets, sc, cl, {}, {}),
pre,cr1,f1,t1,vt1,cr2,f2,t2,vt2,ct,io1,io2,
graph,info);
// TODO: take care of dae, can contain asserts from connections
then
Connect.SETS(sets, sc, cl, cc, oc);
(Connect.SETS(sets, sc, cl, cc, oc), graph);

// This can fail, for innerouter, the inner part is not declared in env so instead the call to addOuterConnectIfEmptyNoEnv will succed.
case(cache,env,ih,_,_,_,_,_,_,_,_,_,_)
case(cache,env,ih,_,_,_,_,_,_,_,_,_,_,_)
equation
//print("Failed lookup: " +& ComponentReference.printComponentRefStr(cr1) +& "\n");
//print("Failed lookup: " +& ComponentReference.printComponentRefStr(cr2) +& "\n");
Expand Down
12 changes: 8 additions & 4 deletions Compiler/FrontEnd/Inst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ algorithm
dae1_1 = DAEUtil.addComponentType(dae1, fq_class);

reportUnitConsistency(callscope_1,store);
(csets,_) = InnerOuter.retrieveOuterConnections(cache,env_3,ih,pre,csets,callscope_1);
(csets, _, graph) = InnerOuter.retrieveOuterConnections(cache,env_3,ih,pre,csets,callscope_1, graph);

//System.startTimer();
//print("\nConnect equations and the OverConstrained graph in one step");
Expand Down Expand Up @@ -5846,9 +5846,13 @@ algorithm
classmod = Mod.lookupModificationP(mods, t);
mm = Mod.lookupCompModification(mods, n);
*/
// A frequent used debugging line
//print("Instantiating element: " +& str +& " in scope " +& Env.getScopeName(env) +& ", elements to go: " +& intString(listLength(els)) +&
//"\t mods: " +& Mod.printModStr(mod) +& "\n");
/*// A frequent used debugging line
print("Instantiating element: " +& elementName +&
"\n\tin scope " +& Env.getScopeName(env) +&
"\n\telements to go: " +& intString(listLength(els)) +&
"\n\tmods: " +& Mod.printModStr(mod) +&
"\n\telement: " +& SCodeDump.shortElementStr(ele) +&
"\n");*/

(cache,env_1,ih,store,dae1,csets,ci_state_1,tys1,graph) =
instElement(cache,env,ih,store, mod, pre, ci_state, el, inst_dims, impl, callscope, graph, csets);
Expand Down
19 changes: 12 additions & 7 deletions Compiler/FrontEnd/InstSection.mo
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ algorithm
(cache, e2_1, prop2) = Ceval.cevalIfConstant(cache, env, e2_1, prop2, impl, info);

(cache,e1_1,e2_1,prop1) = condenseArrayEquation(cache,env,e1,e2,e1_1,e2_1,prop1,prop2,impl,pre,info);

(cache,e1_2) = PrefixUtil.prefixExp(cache,env, ih, e1_1, pre);
(cache,e2_2) = PrefixUtil.prefixExp(cache,env, ih, e2_1, pre);

Expand Down Expand Up @@ -3257,7 +3258,7 @@ algorithm
(outCache,outEnv,outIH,outSets,outDae,outGraph) :=
matchcontinue (inCache,inEnv,inIH,inSets,inPrefix,inComponentRefLeft,inComponentRefRight,inBoolean,inGraph,info)
local
DAE.ComponentRef c1_1,c2_1,c1_2,c2_2;
DAE.ComponentRef c1_1,c2_1,c1_2,c2_2, c1p,c2p;
DAE.Type t1,t2;
DAE.Properties prop1,prop2;
DAE.Attributes attr1,attr2,attr;
Expand Down Expand Up @@ -3514,7 +3515,9 @@ algorithm

// adrpo: TODO! FIXME! check if is OK
state = ClassInf.CONNECTOR(Absyn.IDENT("expandable connector"), true);
source = DAEUtil.createElementSource(info, Env.getEnvPath(env), PrefixUtil.prefixToCrefOpt(pre), SOME((c1_1,c2_1)), NONE());
(cache,c1p) = PrefixUtil.prefixCref(cache, env, ih, pre, c1_2);
(cache,c2p) = PrefixUtil.prefixCref(cache, env, ih, pre, c2_2);
source = DAEUtil.createElementSource(info, Env.getEnvPath(env), PrefixUtil.prefixToCrefOpt(pre), SOME((c1p,c2p)), NONE());
// declare the added component in the DAE!
(cache,c1_2) = PrefixUtil.prefixCref(cache, env, ih, pre, c1_2);
daeExpandable = Inst.daeDeclare(c1_2, state, ty1,
Expand Down Expand Up @@ -4052,7 +4055,7 @@ algorithm
(outCache,outEnv,outIH,outSets,outDae,outGraph) :=
matchcontinue (inCache,inEnv,inIH,inSets,inPrefix3,cr1,inFace5,inType6,vt1,cr2,inFace8,inType9,vt2,inConnectorType,io1,io2,inGraph,info)
local
DAE.ComponentRef c1_1,c2_1,c1,c2;
DAE.ComponentRef c1_1,c2_1,c1,c2,c1p,c2p;
Connect.Sets sets_1,sets;
list<Env.Frame> env;
Prefix.Prefix pre;
Expand Down Expand Up @@ -4137,11 +4140,11 @@ algorithm

// TODO: FIXME!
// adrpo 2012-10-14: should we not prefix here??!!
//(cache,c1) = PrefixUtil.prefixCref(cache,env,ih,pre, c1);
//(cache,c2) = PrefixUtil.prefixCref(cache,env,ih,pre, c2);
(cache,c1_1) = PrefixUtil.prefixCref(cache,env,ih,pre, c1);
(cache,c2_1) = PrefixUtil.prefixCref(cache,env,ih,pre, c2);

// set the source of this element
source = DAEUtil.createElementSource(info, Env.getEnvPath(env), PrefixUtil.prefixToCrefOpt(pre), SOME((c1,c2)), NONE());
source = DAEUtil.createElementSource(info, Env.getEnvPath(env), PrefixUtil.prefixToCrefOpt(pre), SOME((c1_1,c2_1)), NONE());

sets_1 = ConnectUtil.addConnection(sets, c1, f1, c2, f2, inConnectorType, source);
then
Expand Down Expand Up @@ -4178,7 +4181,9 @@ algorithm
true = List.isEqualOnTrue(dims, dims2, Expression.dimensionsKnownAndEqual);

// set the source of this element
source = DAEUtil.createElementSource(info, Env.getEnvPath(env), PrefixUtil.prefixToCrefOpt(pre), SOME((c1,c2)), NONE());
(cache,c1p) = PrefixUtil.prefixCref(cache, env, ih, pre, c1);
(cache,c2p) = PrefixUtil.prefixCref(cache, env, ih, pre, c2);
source = DAEUtil.createElementSource(info, Env.getEnvPath(env), PrefixUtil.prefixToCrefOpt(pre), SOME((c1p,c2p)), NONE());

sets_1 = ConnectUtil.addArrayConnection(sets, c1, f1, c2, f2, source, ct);
then
Expand Down

0 comments on commit 991b036

Please sign in to comment.