Skip to content

Commit

Permalink
Fixes for bugs: #1272 #1130 #1270 #1120
Browse files Browse the repository at this point in the history
- finished the expandable connectors implementation
- added tests for expandable connectors:
  testsuite/expandable/* [many thanks to Pavol.Privitzer for providing the models]
  testsuite/libraries/msl31/Modelica.Blocks.mos [BusUsage]
  testsuite/libraries/multibody/systems/RobotR3.mos [oneAxis and fullRobot]
- other small edits, comments and formatting.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6337 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Oct 11, 2010
1 parent bd2e2f8 commit bc24b96
Show file tree
Hide file tree
Showing 13 changed files with 732 additions and 159 deletions.
6 changes: 3 additions & 3 deletions Compiler/Ceval.mo
Expand Up @@ -1426,7 +1426,7 @@ algorithm
false = RTOpts.debugFlag("nogen");
failure(cevalIsExternalObjectConstructor(cache,funcpath,env));
// we might actually have a function loaded here already!
cevalHashTable = System.getFromRoots(1);
cevalHashTable = System.getFromRoots(2);
// see if we have it in the ceval cache
Interactive.CFunction(funcHandle=funcHandle, buildTime=buildTime, loadedFromFile=fOld) = get(funcpath, cevalHashTable);
funcstr = ModUtil.pathStringReplaceDot(funcpath, "_");
Expand All @@ -1450,10 +1450,10 @@ algorithm
System.freeFunction(funcHandle);
System.freeLibrary(libHandle);
// add to cache!
//cevalHashTable = System.getFromRoots(1);
//cevalHashTable = System.getFromRoots(2);
//buildTime = System.getCurrentTime();
//cevalHashTable = add((funcpath,Interactive.CFunction(funcpath,(DAE.T_NOTYPE(),SOME(funcpath)),funcHandle,buildTime,"")), cevalHashTable);
//System.addToRoots(1, cevalHashTable);
//System.addToRoots(2, cevalHashTable);
then
(cache,newval,NONE());

Expand Down
37 changes: 29 additions & 8 deletions Compiler/CevalScript.mo
Expand Up @@ -670,20 +670,41 @@ algorithm
Absyn.ComponentRef crefCName;
Real t1, t2, t;
equation
//System.startTimer();
//print("\nExists+Dependency");

crefCName = Absyn.pathToCref(className);
true = Interactive.existClass(crefCName, p);
ptot = Dependency.getTotalProgram(className,p);
// t1 = clock();

//System.stopTimer();
//print("\nExists+Dependency: " +& realString(System.getTimerIntervalTime()));

//System.startTimer();
//print("\nAbsyn->SCode");

p_1 = SCodeUtil.translateAbsyn2SCode(ptot);
// t2 = clock();
// t = t2 -. t1;
// print("SCodeUtil.translateAbsyn2SCode: " +& Absyn.pathString(className) +& " time: " +& realString(t) +& "\n");
(cache,env,_,dae) =
Inst.instantiateClass(cache,InnerOuter.emptyInstHierarchy,p_1,className);

//System.stopTimer();
//print("\nAbsyn->SCode: " +& realString(System.getTimerIntervalTime()));

//System.startTimer();
//print("\nInst.instantiateClass");

(cache,env,_,dae) = Inst.instantiateClass(cache,InnerOuter.emptyInstHierarchy,p_1,className);

//System.stopTimer();
//print("\nInst.instantiateClass: " +& realString(System.getTimerIntervalTime()));

// adrpo: do not add it to the instantiated classes, it just consumes memory for nothing.
// ic_1 = Interactive.addInstantiatedClass(ic, Interactive.INSTCLASS(className,dae,env));
ic_1 = ic;
// ic_1 = ic;
ic_1 = Interactive.addInstantiatedClass(ic, Interactive.INSTCLASS(className,dae,env));

// System.startTimer();
// print("\nFlatModelica");
str = DAEDump.dumpStr(dae);
// System.stopTimer();
// print("\nFlatModelica: " +& realString(System.getTimerIntervalTime()));
then
(cache,Values.STRING(str),Interactive.SYMBOLTABLE(p,aDep,sp,ic_1,iv,cf,lf));

Expand Down
14 changes: 12 additions & 2 deletions Compiler/ConnectUtil.mo
Expand Up @@ -66,6 +66,7 @@ protected import Error;
protected import Dump;
protected import PrefixUtil;
protected import RTOpts;
protected import System;

public
type Env = Env.Env;
Expand Down Expand Up @@ -1276,6 +1277,12 @@ algorithm
list<tuple<DAE.ComponentRef, Option<DAE.ComponentRef>, Connect.Face, DAE.ElementSource>> streamRest1,streamRest2;
Connect.Face face1,face2;

// pointer equality testing first.
case (inSet1, inSet2)
equation
true = System.refEqual(inSet1, inSet2);
then true;

// deal with empty case
case (Connect.EQU({}), Connect.EQU({})) then true;
case (Connect.FLOW({}), Connect.FLOW({})) then true;
Expand Down Expand Up @@ -1666,9 +1673,12 @@ algorithm

case(vars,Connect.SETS(s,crs,deletedComp::deletedComps,outerConn),prefix)
equation
//print("\n\nvars:" +& Util.stringDelimitList(Util.listMap(vars, Exp.printComponentRefStr), ", ") +& "\n\n");
//print("\n\ndeleted:" +& Util.stringDelimitList(Util.listMap(deletedComp::deletedComps, Exp.printComponentRefStr), ", ") +& "\n\n");
//print("\n\nprefix:" +& PrefixUtil.printPrefixStr(prefix) +& "\n\n");
vars = Util.listSelect2(vars, deletedComp, prefix, crefNotPrefixOf);
// print("Deleting: " +& Exp.printComponentRefStr(deletedComp) +& "\n");
// print("Result unconnected vars after remove -> prefix: " +& PrefixUtil.printPrefixStr(prefix) +& "/" +& Util.stringDelimitList(Util.listMap(vars, Exp.printComponentRefStr), ", ") +& "\n");
//print("Deleting: " +& Exp.printComponentRefStr(deletedComp) +& "\n");
//print("Result unconnected vars after remove -> prefix: " +& PrefixUtil.printPrefixStr(prefix) +& "/" +& Util.stringDelimitList(Util.listMap(vars, Exp.printComponentRefStr), ", ") +& "\n");
vars = removeUnconnectedDeletedComponents(vars,Connect.SETS(s,crs,deletedComps,outerConn),prefix);
then vars;
end matchcontinue;
Expand Down
40 changes: 20 additions & 20 deletions Compiler/DAEUtil.mo
Expand Up @@ -469,7 +469,7 @@ algorithm

case(var,DAE.DAE((v as DAE.VAR(componentRef = cr))::elist,funcs))
equation
true = Exp.crefEqual(var,cr);
true = Exp.crefEqualNoStringCompare(var,cr);
then DAE.DAE(elist,funcs);

case(var,DAE.DAE(DAE.COMP(id,elist,source,cmt)::elist2,funcs))
Expand Down Expand Up @@ -531,7 +531,7 @@ algorithm

case(var,DAE.DAE(DAE.VAR(cr,kind,dir,prot,tp,bind,dim,flow_,st,source,attr,cmt,io)::elist,funcs))
equation
true = Exp.crefEqual(var,cr);
true = Exp.crefEqualNoStringCompare(var,cr);
io2 = removeInnerAttribute(io);
then
DAE.DAE(DAE.VAR(cr,kind,dir,prot,tp,bind,dim,flow_,st,source,attr,cmt,io2)::elist,funcs);
Expand Down Expand Up @@ -625,8 +625,7 @@ end unNameInnerouterUniqueCref;

protected function getOuterBinding "
Author: BZ, 2008-11
Aquire the binding on the outer/innerouter variable, to transfer to inner variable.
"
Aquire the binding on the outer/innerouter variable, to transfer to inner variable."
input DAE.ComponentRef currVar;
input list<tuple<DAE.ComponentRef, DAE.Exp>> inlst;
output Option<DAE.Exp> binding;
Expand All @@ -635,7 +634,7 @@ algorithm binding := matchcontinue(currVar,inlst)
case(_,{}) then NONE;
case(cr1,(cr2,e)::inlst)
equation
true = Exp.crefEqual(cr1,cr2);
true = Exp.crefEqualNoStringCompare(cr1,cr2);
then
SOME(e);
case(cr1,(_,_)::inlst) then getOuterBinding(cr1,inlst);
Expand Down Expand Up @@ -943,22 +942,8 @@ algorithm
end matchcontinue;
end boolVarProtection;

public function varHasName "returns true if variable equals name passed as argument"
input DAE.Element var;
input DAE.ComponentRef cr;
output Boolean res;
algorithm
res := matchcontinue(var,cr)
local DAE.ComponentRef cr2;
case(DAE.VAR(componentRef=cr2),cr) equation
res = Exp.crefEqual(cr2,cr);
then res;
end matchcontinue;
end varHasName;

public function hasStartAttr "
Returns true if variable attributes defines a start value.
"
Returns true if variable attributes defines a start value."
input Option<DAE.VariableAttributes> inVariableAttributesOption;
output Boolean hasStart;
algorithm
Expand Down Expand Up @@ -5332,3 +5317,18 @@ algorithm
end collectFunctionRefVarPaths;

end DAEUtil;

/* adrpo: 2010-10-04 never used by OpenModelica!
public function varHasName "returns true if variable equals name passed as argument"
input DAE.Element var;
input DAE.ComponentRef cr;
output Boolean res;
algorithm
res := matchcontinue(var,cr)
local DAE.ComponentRef cr2;
case(DAE.VAR(componentRef=cr2),cr) equation
res = Exp.crefEqualNoStringCompare(cr2,cr);
then res;
end matchcontinue;
end varHasName;
*/
15 changes: 6 additions & 9 deletions Compiler/Derive.mo
Expand Up @@ -1107,20 +1107,16 @@ algorithm
outExp := differentiateExp(inExp,inComponentRef,false);
end differentiateExpCont;

public function differentiateExp "function: differenatiate_exp

This function differentiates expressions with respect to a given variable,
given as second argument.
For example.
differentiateExp(\'2xy+2x+y\',x) => 2x+2
"
public function differentiateExp "function: differentiateExp
This function differentiates expressions with respect
to a given variable,given as second argument.
For example: differentiateExp(2xy+2x+y,x) => 2x+2"
input DAE.Exp inExp;
input DAE.ComponentRef inComponentRef;
input Boolean differentiateIfExp "If true, allow differentiation of if-expressions";
output DAE.Exp outExp;
algorithm
outExp:=
matchcontinue (inExp,inComponentRef,differentiateIfExp)
outExp := matchcontinue (inExp,inComponentRef,differentiateIfExp)
local
Real rval;
DAE.ComponentRef cr,crx,tv;
Expand All @@ -1133,6 +1129,7 @@ algorithm
String e_str,s,s2,str;
list<DAE.Exp> expl_1,expl,sub;
Integer i;

case (DAE.ICONST(integer = _),_,_) then DAE.RCONST(0.0);

case (DAE.RCONST(real = _),_,_) then DAE.RCONST(0.0);
Expand Down
43 changes: 43 additions & 0 deletions Compiler/Dump.mo
Expand Up @@ -554,6 +554,49 @@ algorithm
end matchcontinue;
end unparseRestrictionStr;

public function printIstmtStr
"function: printIstmtStr
Prints an interactive statement to a string."
input Interactive.InteractiveStmts inInteractiveStmts;
output String strIstmt;
algorithm
strIstmt := matchcontinue (inInteractiveStmts)
local
Absyn.AlgorithmItem alg;
Absyn.Exp expr;
list<Interactive.InteractiveStmt> l;
Boolean sc;
String str;

case (Interactive.ISTMTS(interactiveStmtLst = {Interactive.IALG(algItem = alg)}))
equation
str = unparseAlgorithmStr(0, alg);
then
str;

case (Interactive.ISTMTS(interactiveStmtLst = {Interactive.IEXP(exp = expr)}))
equation
str = printExpStr(expr);
then
str;

case (Interactive.ISTMTS(interactiveStmtLst = (Interactive.IALG(algItem = alg) :: l),semicolon = sc))
equation
str = unparseAlgorithmStr(0, alg);
str = str +& "; " +& printIstmtStr(Interactive.ISTMTS(l,sc));
then
str;

case (Interactive.ISTMTS(interactiveStmtLst = (Interactive.IEXP(exp = expr) :: l),semicolon = sc))
equation
str = printExpStr(expr);
str = str +& "; " +& printIstmtStr(Interactive.ISTMTS(l,sc));
then
str;
case (_) then "unknown";
end matchcontinue;
end printIstmtStr;

public function dumpIstmt
"function: dumpIstmt
Dumps an interactive statement to the Print buffer."
Expand Down
30 changes: 30 additions & 0 deletions Compiler/Env.mo
Expand Up @@ -463,6 +463,36 @@ algorithm
end matchcontinue;
end extendFrameClasses;

public function removeComponentsFromFrameV "function: removeComponentsFromFrameV
This function removes all components from frame."
input Env inEnv;
output Env outEnv;
algorithm
outEnv := matchcontinue (inEnv)
local
AvlTree httypes;
AvlTree ht,ht_1;
Option<Ident> id;
Option<ScopeType> st;
list<AvlValue> imps;
Env fs,env,remember;
tuple<list<DAE.ComponentRef>,DAE.ComponentRef> crs;
Boolean encflag;
InstStatus i;
DAE.Var v;
Ident n;
Option<tuple<SCode.Element, DAE.Mod>> c;
list<SCode.Element> defineUnits;

case ((FRAME(id,st,_,httypes,imps,crs,encflag,defineUnits) :: fs))
equation
// make an empty component env!
ht = avlTreeNew();
then
(FRAME(id,st,ht,httypes,imps,crs,encflag,defineUnits) :: fs);
end matchcontinue;
end removeComponentsFromFrameV;

public function extendFrameV "function: extendFrameV
This function adds a component to the environment."
input Env inEnv1;
Expand Down
36 changes: 23 additions & 13 deletions Compiler/Exp.mo
Expand Up @@ -660,19 +660,20 @@ public function expStripLastSubs
input Exp inExp;
output Exp outExp;
algorithm
outExp:=
matchcontinue (inExp)
outExp := matchcontinue (inExp)
local
ComponentRef cr,cr_1;
Type ty;
Operator op,op1;
Exp e,e_1;
Boolean b;

case (DAE.CREF(componentRef=cr))
equation
ty = crefLastType(cr);
cr_1 = crefStripLastSubs(cr);
then DAE.CREF(cr_1,ty);

case (DAE.UNARY(operator=op,exp=e))
equation
e_1 = expStripLastSubs(e);
Expand Down Expand Up @@ -733,26 +734,36 @@ end crefStripLastSubsStringified;
public function crefContainedIn
"function: crefContainedIn
author: PA
Returns true if y is a sub component ref of x.
Returns true if second arg is a sub component ref of first arg.
For instance, b.c. is a sub_component of a.b.c."
input ComponentRef inComponentRef1;
input ComponentRef inComponentRef2;
input ComponentRef containerCref "the cref that might contain";
input ComponentRef containedCref "cref that might be contained";
output Boolean outBoolean;
algorithm
outBoolean := matchcontinue (inComponentRef1,inComponentRef2)
outBoolean := matchcontinue (containerCref, containedCref)
local
ComponentRef x,y,cr2;
ComponentRef full,partOf,cr2;
Boolean res;
case (x,y) /* x y */

// a qualified cref cannot be contained in an ident cref.
case (DAE.CREF_IDENT(ident = _), DAE.CREF_QUAL(componentRef = _)) then false;

// see if they are equal
case (full, partOf)
equation
true = crefEqualNoStringCompare(x, y);
true = crefEqualNoStringCompare(full, partOf);
then
true;
case (DAE.CREF_QUAL(componentRef = cr2),y)

// dive into
case (full as DAE.CREF_QUAL(componentRef = cr2), partOf)
equation
res = crefContainedIn(cr2,y);
false = crefEqualNoStringCompare(full, partOf);
res = crefContainedIn(cr2,partOf);
then
res;

// anything else is false
case (_,_) then false;
end matchcontinue;
end crefContainedIn;
Expand Down Expand Up @@ -1524,8 +1535,7 @@ Takes an arbitrary expression and applies subscripts to it. This is done by crea
expressions given the original expression and then simplify them.
Note: The subscripts must be INDEX

alternative names: subsriptExp (but already taken), subscriptToAsub
"
alternative names: subsriptExp (but already taken), subscriptToAsub"
input Exp e;
input list<DAE.Subscript> subs;
output Exp res;
Expand Down

0 comments on commit bc24b96

Please sign in to comment.