diff --git a/Compiler/FFrontEnd/FCore.mo b/Compiler/FFrontEnd/FCore.mo index 74295afbddb..bef795689cc 100644 --- a/Compiler/FFrontEnd/FCore.mo +++ b/Compiler/FFrontEnd/FCore.mo @@ -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; @@ -406,7 +404,7 @@ public constant Id firstId = 0; // ************************ Cache structures *************************** // ************************ Cache structures *************************** -public type StructuralParameters = tuple>>; +public type StructuralParameters = tuple>>; public uniontype Cache record CACHE Option initialGraph "and the initial environment"; @@ -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; @@ -464,7 +462,7 @@ algorithm local Option initialGraph; array functions; - HashSet.HashSet ht; + AvlSetCR.Tree ht; list> st; list crs; Absyn.Path p; @@ -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; diff --git a/Compiler/FrontEnd/Ceval.mo b/Compiler/FrontEnd/Ceval.mo index 2250cb402dc..71fea00240e 100644 --- a/Compiler/FrontEnd/Ceval.mo +++ b/Compiler/FrontEnd/Ceval.mo @@ -5379,7 +5379,7 @@ protected FCore.StructuralParameters structuralParameters; array 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); diff --git a/Compiler/FrontEnd/ComponentReference.mo b/Compiler/FrontEnd/ComponentReference.mo index 51adc9ae21b..23d462903d6 100644 --- a/Compiler/FrontEnd/ComponentReference.mo +++ b/Compiler/FrontEnd/ComponentReference.mo @@ -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; @@ -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); @@ -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; @@ -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 @@ -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(); diff --git a/Compiler/FrontEnd/DAEUtil.mo b/Compiler/FrontEnd/DAEUtil.mo index 36c70b2c6b7..ebf327b9058 100644 --- a/Compiler/FrontEnd/DAEUtil.mo +++ b/Compiler/FrontEnd/DAEUtil.mo @@ -5303,7 +5303,7 @@ public function transformationsBeforeBackend protected DAE.DAElist dAElist; list elts; - HashSet.HashSet ht; + AvlSetCR.Tree ht; algorithm // Transform Modelica state machines to flat data-flow equations dAElist := StateMachineFlatten.stateMachineToDataFlow(cache, env, inDAElist); @@ -5322,29 +5322,24 @@ algorithm end transformationsBeforeBackend; protected function transformationsBeforeBackendNotification - input HashSet.HashSet ht; -algorithm - _ := matchcontinue ht - local - list crs; - list 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 crs; + list 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) @@ -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 diff --git a/Compiler/FrontEnd/InstUtil.mo b/Compiler/FrontEnd/InstUtil.mo index 8aef7935aab..8098f9c3610 100644 --- a/Compiler/FrontEnd/InstUtil.mo +++ b/Compiler/FrontEnd/InstUtil.mo @@ -7721,7 +7721,7 @@ algorithm local Option ie; array f; - HashSet.HashSet ht; + AvlSetCR.Tree ht; list> crs; Absyn.Path p; Absyn.Program program; @@ -7740,7 +7740,7 @@ algorithm local Option ie; array f; - HashSet.HashSet ht; + AvlSetCR.Tree ht; list crs; list> crss; Absyn.Path p; @@ -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 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; diff --git a/Compiler/Script/CevalScriptBackend.mo b/Compiler/Script/CevalScriptBackend.mo index d30dc67a7c9..9c4780f7982 100644 --- a/Compiler/Script/CevalScriptBackend.mo +++ b/Compiler/Script/CevalScriptBackend.mo @@ -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()); diff --git a/Compiler/Util/AvlSetCR.mo b/Compiler/Util/AvlSetCR.mo new file mode 100644 index 00000000000..ef00d220c46 --- /dev/null +++ b/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; diff --git a/Compiler/boot/LoadCompilerSources.mos b/Compiler/boot/LoadCompilerSources.mos index 8d5d6daa440..a1958dfaa4c 100644 --- a/Compiler/boot/LoadCompilerSources.mos +++ b/Compiler/boot/LoadCompilerSources.mos @@ -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",