Skip to content

Commit

Permalink
AvlSet instead of HashSet for structural params
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Oct 19, 2016
1 parent 1ccc53d commit f97e445
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 46 deletions.
12 changes: 5 additions & 7 deletions Compiler/FFrontEnd/FCore.mo
Expand Up @@ -41,14 +41,12 @@ encapsulated package FCore

public
import Absyn;
import BaseAvlTree;
import AvlSetCR;
import DAE;
import SCode;
import Prefix;
import HashSet;

protected
import BaseHashSet;
import DAEUtil;
import Config;

Expand Down Expand Up @@ -406,7 +404,7 @@ public constant Id firstId = 0;
// ************************ Cache structures ***************************
// ************************ Cache structures ***************************

public type StructuralParameters = tuple<HashSet.HashSet,list<list<DAE.ComponentRef>>>;
public type StructuralParameters = tuple<AvlSetCR.Tree,list<list<DAE.ComponentRef>>>;
public uniontype Cache
record CACHE
Option<Graph> initialGraph "and the initial environment";
Expand Down Expand Up @@ -443,7 +441,7 @@ protected
StructuralParameters ht;
algorithm
instFuncs := arrayCreate(1, DAE.AvlTreePathFunction.Tree.EMPTY());
ht := (HashSet.emptyHashSetSized(BaseHashSet.lowBucketSize),{});
ht := (AvlSetCR.EMPTY(),{});
cache := CACHE(NONE(),instFuncs,ht,Absyn.IDENT("##UNDEFINED##"),Absyn.dummyProgram);
end emptyCache;

Expand All @@ -464,7 +462,7 @@ algorithm
local
Option<Graph> initialGraph;
array<DAE.FunctionTree> functions;
HashSet.HashSet ht;
AvlSetCR.Tree ht;
list<list<DAE.ComponentRef>> st;
list<DAE.ComponentRef> crs;
Absyn.Path p;
Expand All @@ -480,7 +478,7 @@ end addEvaluatedCref;

public function getEvaluatedParams
input Cache cache;
output HashSet.HashSet ht;
output AvlSetCR.Tree ht;
algorithm
CACHE(evaluatedParams=(ht,_)) := cache;
end getEvaluatedParams;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Ceval.mo
Expand Up @@ -5379,7 +5379,7 @@ protected
FCore.StructuralParameters structuralParameters;
array<DAE.FunctionTree> functionTree;
algorithm
structuralParameters := (HashSet.emptyHashSetSized(BaseHashSet.lowBucketSize),{});
structuralParameters := (AvlSetCR.EMPTY(),{});
functionTree := arrayCreate(1,functions);
cache := FCore.CACHE(NONE(), functionTree, structuralParameters, Absyn.IDENT(""), Absyn.dummyProgram);
(_,val,_) := ceval(cache, FGraph.empty(), exp, false, NONE(), Absyn.NO_MSG(),0);
Expand Down
41 changes: 28 additions & 13 deletions Compiler/FrontEnd/ComponentReference.mo
Expand Up @@ -680,7 +680,7 @@ end crefFirstIdentEqual;

protected

type CompareWithSubsType = enumeration(WithoutSubscripts, WithGenericSubscript, WithIntSubscript);
type CompareWithSubsType = enumeration(WithoutSubscripts, WithGenericSubscript, WithGenericSubscriptNotAlphabetic, WithIntSubscript);

package CompareWithGenericSubscript "Package that can be modified to do different kinds of comparisons"
constant CompareWithSubsType compareSubscript=CompareWithSubsType.WithGenericSubscript;
Expand Down Expand Up @@ -756,6 +756,10 @@ package CompareWithGenericSubscript "Package that can be modified to do differen
e1 := Expression.getSubscriptExp(s1);
e2 := Expression.getSubscriptExp(s2);
res := stringCompare(ExpressionDump.printExpStr(e1),ExpressionDump.printExpStr(e2));
elseif compareSubscript == CompareWithSubsType.WithGenericSubscriptNotAlphabetic then
e1 := Expression.getSubscriptExp(s1);
e2 := Expression.getSubscriptExp(s2);
res := Expression.compare(e1, e2);
else
i1 := Expression.subscriptInt(s1);
i2 := Expression.subscriptInt(s2);
Expand All @@ -771,6 +775,9 @@ package CompareWithGenericSubscript "Package that can be modified to do differen
end compareSubs;
end CompareWithGenericSubscript;

package CompareWithGenericSubscriptNotAlphabetic
extends CompareWithGenericSubscript(compareSubscript=CompareWithSubsType.WithGenericSubscriptNotAlphabetic);
end CompareWithGenericSubscriptNotAlphabetic;
package CompareWithoutSubscripts
extends CompareWithGenericSubscript(compareSubscript=CompareWithSubsType.WithoutSubscripts);
end CompareWithoutSubscripts;
Expand All @@ -794,6 +801,14 @@ algorithm
comp := CompareWithGenericSubscript.compare(cr1,cr2);
end crefCompareGeneric;

public function crefCompareGenericNotAlphabetic "A sorting function for crefs"
input DAE.ComponentRef cr1;
input DAE.ComponentRef cr2;
output Integer comp;
algorithm
comp := CompareWithGenericSubscriptNotAlphabetic.compare(cr1,cr2);
end crefCompareGenericNotAlphabetic;

public function crefLexicalGreaterSubsAtEnd
"mahge:
Compares two crefs lexically. Subscripts are treated as if they are
Expand Down Expand Up @@ -3278,18 +3293,18 @@ public function makeCrefsFromSubScriptLst
algorithm
for subScript in inSubscriptLst loop
outCref := match(subScript)
local
DAE.ComponentRef cr;
DAE.Exp e;
String str;
case DAE.INDEX(exp = e) equation
cr = makeCrefsFromSubScriptExp(e);
then
joinCrefs(outCref, cr);

// all other should probably fails or evaluated before
else equation
str = ExpressionDump.printSubscriptStr(subScript);
local
DAE.ComponentRef cr;
DAE.Exp e;
String str;
case DAE.INDEX(exp = e) equation
cr = makeCrefsFromSubScriptExp(e);
then
joinCrefs(outCref, cr);

// all other should probably fails or evaluated before
else equation
str = ExpressionDump.printSubscriptStr(subScript);
Error.addInternalError("function ComponentReference.makeCrefsFromSubScriptLst for:" + str + "\n", sourceInfo());
then
fail();
Expand Down
35 changes: 15 additions & 20 deletions Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -5303,7 +5303,7 @@ public function transformationsBeforeBackend
protected
DAE.DAElist dAElist;
list<DAE.Element> elts;
HashSet.HashSet ht;
AvlSetCR.Tree ht;
algorithm
// Transform Modelica state machines to flat data-flow equations
dAElist := StateMachineFlatten.stateMachineToDataFlow(cache, env, inDAElist);
Expand All @@ -5322,29 +5322,24 @@ algorithm
end transformationsBeforeBackend;

protected function transformationsBeforeBackendNotification
input HashSet.HashSet ht;
algorithm
_ := matchcontinue ht
local
list<DAE.ComponentRef> crs;
list<String> strs;
String str;
case _
equation
(crs as _::_) = BaseHashSet.hashSetList(ht);
strs = List.map(crs, ComponentReference.printComponentRefStr);
strs = List.sort(strs, Util.strcmpBool);
str = stringDelimitList(strs, ", ");
Error.addMessage(Error.NOTIFY_FRONTEND_STRUCTURAL_PARAMETERS, {str});
then ();
else ();
end matchcontinue;
input AvlSetCR.Tree ht;
protected
list<DAE.ComponentRef> crs;
list<String> strs;
String str;
algorithm
crs := AvlSetCR.listKeys(ht);
if not listEmpty(crs) then
strs := List.map(crs, ComponentReference.printComponentRefStr);
str := stringDelimitList(strs, ", ");
Error.addMessage(Error.NOTIFY_FRONTEND_STRUCTURAL_PARAMETERS, {str});
end if;
end transformationsBeforeBackendNotification;

protected function makeEvaluatedParamFinal "
This function makes all evaluated parameters final."
input DAE.Element inElement;
input HashSet.HashSet ht "evaluated parameters";
input AvlSetCR.Tree ht "evaluated parameters";
output DAE.Element outElement;
algorithm
outElement := match (inElement, ht)
Expand All @@ -5358,7 +5353,7 @@ algorithm
DAE.Element elt;

case (DAE.VAR(componentRef=cr, kind=DAE.PARAM(), variableAttributesOption=varOpt), _) equation
elt = if BaseHashSet.has(cr, ht) then setVariableAttributes(inElement, setFinalAttr(varOpt, true)) else inElement;
elt = if AvlSetCR.hasKey(ht, cr) then setVariableAttributes(inElement, setFinalAttr(varOpt, true)) else inElement;
then elt;

case (DAE.COMP(id, elts, source, cmt), _) equation
Expand Down
8 changes: 4 additions & 4 deletions Compiler/FrontEnd/InstUtil.mo
Expand Up @@ -7721,7 +7721,7 @@ algorithm
local
Option<FCore.Graph> ie;
array<DAE.FunctionTree> f;
HashSet.HashSet ht;
AvlSetCR.Tree ht;
list<list<DAE.ComponentRef>> crs;
Absyn.Path p;
Absyn.Program program;
Expand All @@ -7740,7 +7740,7 @@ algorithm
local
Option<FCore.Graph> ie;
array<DAE.FunctionTree> f;
HashSet.HashSet ht;
AvlSetCR.Tree ht;
list<DAE.ComponentRef> crs;
list<list<DAE.ComponentRef>> crss;
Absyn.Path p;
Expand All @@ -7756,13 +7756,13 @@ end popStructuralParameters;
protected function prefixAndAddCrefsToHt
"Cannot be part of Env due to RML issues"
input FCore.Cache cache;
input output HashSet.HashSet set;
input output AvlSetCR.Tree set;
input Prefix.Prefix pre;
input list<DAE.ComponentRef> icrs;
algorithm
for cr in icrs loop
(_,cr) := PrefixUtil.prefixCref(cache, FGraph.empty(), InnerOuter.emptyInstHierarchy, pre, cr);
set := BaseHashSet.add(cr,set);
set := AvlSetCR.add(set,cr);
end for;
end prefixAndAddCrefsToHt;

Expand Down
1 change: 0 additions & 1 deletion Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -1420,7 +1420,6 @@ algorithm

b = Flags.getConfigBool(Flags.GENERATE_SYMBOLIC_LINEARIZATION);
Flags.setConfigBool(Flags.GENERATE_SYMBOLIC_LINEARIZATION, true);

(cache,st,compileDir,executable,_,outputFormat_str,_,simflags,resultValues) = buildModel(cache,env,vals,st_1,msg);
Values.REAL(linearizeTime) = getListNthShowError(vals,"try to get stop time",0,2);
executableSuffixedExe = stringAppend(executable, System.getExeExt());
Expand Down
47 changes: 47 additions & 0 deletions Compiler/Util/AvlSetCR.mo
@@ -0,0 +1,47 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/

encapsulated package AvlSetCR
import BaseAvlSet;
extends BaseAvlSet;
import DAE;
import ComponentReference;
redeclare type Key = DAE.ComponentRef;
redeclare function extends keyStr
algorithm
outString := ComponentReference.printComponentRefStr(inKey);
end keyStr;
redeclare function extends keyCompare
algorithm
outResult := ComponentReference.crefCompareGenericNotAlphabetic(inKey1, inKey2);
end keyCompare;
annotation(__OpenModelica_Interface="frontend");
end AvlSetCR;
1 change: 1 addition & 0 deletions Compiler/boot/LoadCompilerSources.mos
Expand Up @@ -154,6 +154,7 @@ if true then /* Suppress output */

// "Util";
"../Util/Array.mo",
"../Util/AvlSetCR.mo",
"../Util/AvlSetString.mo",
"../Util/BaseAvlTree.mo",
"../Util/BaseAvlSet.mo",
Expand Down

0 comments on commit f97e445

Please sign in to comment.