Skip to content

Commit

Permalink
-Implemented sorting of functions when printing DAE as preparation to…
Browse files Browse the repository at this point in the history
… make testsuite more robust. (All multibody tests updated because of this too)

-Changed how variability of for iterators are handled. They must be correct after the iterators have been elaborated to prevent false error messages later on. But this affects how e.g. indices are elaborated. Earlier they were always constant evaluated for const and param variability, but this is not the case when inside a for iterator scope, since the iterators do not have a value. Therefore added special scope name for for iterator scopes, and treat them separately, see Env.forIterScopeName and Static.elabSubscriptsDims2.
 

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5185 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Mar 23, 2010
1 parent 656c479 commit 547392d
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 43 deletions.
40 changes: 38 additions & 2 deletions Compiler/DAEUtil.mo
Expand Up @@ -47,6 +47,20 @@ public import Values;

public constant DAE.DAElist emptyDae = DAE.DAE({},DAE.AVLTREENODE(NONE,0,NONE,NONE));

public function constStr "return the DAE.Const as a string. (VAR|PARAM|CONST)
Used for debugging.
"
input DAE.Const const;
output String str;
algorithm
str := matchcontinue(const)
case(DAE.C_VAR()) then "VAR";
case(DAE.C_PARAM()) then "PARAM";
case(DAE.C_CONST()) then "CONST";

end matchcontinue;
end constStr;

public function expTypeSimple "returns true if type is simple type"
input DAE.ExpType tp;
output Boolean isSimple;
Expand Down Expand Up @@ -604,14 +618,36 @@ algorithm
case DAE.DAE(daelist,funcs)
equation
//print("dumping DAE, avltree list length:"+&intString(listLength(avlTreeToList(funcs)))+&"\n");
Util.listMap0(Util.listMap(avlTreeToList(funcs),Util.tuple22),dumpFunction);
Util.listMap0(sortFunctions(Util.listMap(avlTreeToList(funcs),Util.tuple22)),dumpFunction);
Util.listMap0(daelist, dumpExtObjectClass);
Util.listMap0(daelist, dumpCompElement);
then
();
end matchcontinue;
end dump;

protected function sortFunctions "sorts the functions in alphabetical order"
input list<DAE.Element> funcs;
output list<DAE.Element> sortedFuncs;
algorithm
sortedFuncs := Util.sort(funcs,funcGreaterThan);
end sortFunctions;

protected function funcGreaterThan "sorting function for two DAE.Element that are functions"
input DAE.Element func1;
input DAE.Element func2;
output Boolean res;
algorithm
res := matchcontinue(func1,func2)
local Absyn.Path p1,p2;
case(DAE.FUNCTION(path=p1),DAE.FUNCTION(path=p2)) equation
res = System.strcmp(Absyn.pathString(p1),Absyn.pathString(p2)) > 0;
then res;
case(_,_) then true;
end matchcontinue;
end funcGreaterThan;


public function dumpOperatorString "
Author bz printOperator
Dump operator to a string.
Expand Down Expand Up @@ -980,7 +1016,7 @@ algorithm
equation
//flist = Util.listMap(daelist, dumpFunctionStr);
//print("dumpStr, funcs list length="+&intString(listLength(avlTreeToList(funcs)))+&"\n");
flist = Util.listMap(Util.listMap(avlTreeToList(funcs),Util.tuple22),dumpFunctionStr);
flist = Util.listMap(sortFunctions(Util.listMap(avlTreeToList(funcs),Util.tuple22)),dumpFunctionStr);
extlist = Util.listMap(daelist, dumpExtObjClassStr);
clist = Util.listMap(daelist, dumpCompElementStr);
slist = Util.listFlatten({flist,extlist, clist});
Expand Down
28 changes: 28 additions & 0 deletions Compiler/Env.mo
Expand Up @@ -195,6 +195,7 @@ algorithm
end emptyCache;

public constant String forScopeName="$for loop scope$" "a unique scope used in for equations";
public constant String forIterScopeName="$foriter loop scope$" "a unique scope used in for iterators";
public constant String valueBlockScopeName="$valueblock scope$" "a unique scope used by valueblocks";

// functions for dealing with the environment
Expand Down Expand Up @@ -288,6 +289,33 @@ algorithm
end matchcontinue;
end nameScope;

public function inForLoopScope "returns true if environment has a frame that is a for loop"
input Env env;
output Boolean res;
algorithm
res := matchcontinue(env)
local String name;
case(FRAME(optName = SOME(name))::_) equation
equality(name=forScopeName);
then true;
case(_) then false;
end matchcontinue;
end inForLoopScope;

public function inForIterLoopScope "returns true if environment has a frame that is a for iterator 'loop'"
input Env env;
output Boolean res;
algorithm
res := matchcontinue(env)
local String name;
case(FRAME(optName = SOME(name))::_) equation
equality(name=forIterScopeName);
then true;
case(_) then false;
end matchcontinue;
end inForIterLoopScope;


public function stripForLoopScope "strips for loop scopes"
input Env env;
output Env outEnv;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Lookup.mo
Expand Up @@ -1254,7 +1254,7 @@ algorithm
b := matchcontinue(f)
local String name;
case(Env.FRAME(optName=SOME(name))) equation
true = name ==& Env.forScopeName or name ==& Env.valueBlockScopeName;
true = name ==& Env.forScopeName or name ==& Env.valueBlockScopeName or name ==& Env.forIterScopeName;
then true;
case(_) then false;
end matchcontinue;
Expand Down

0 comments on commit 547392d

Please sign in to comment.