OMCompiler/Compiler/FrontEnd/Inst.mo
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of OpenModelica. | ||
| 3 | * | ||
| 4 | * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), | ||
| 5 | * c/o Linköpings universitet, Department of Computer and Information Science, | ||
| 6 | * SE-58183 Linköping, Sweden. | ||
| 7 | * | ||
| 8 | * All rights reserved. | ||
| 9 | * | ||
| 10 | * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR | ||
| 11 | * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. | ||
| 12 | * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES | ||
| 13 | * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL | ||
| 14 | * VERSION 3, ACCORDING TO RECIPIENTS CHOICE. | ||
| 15 | * | ||
| 16 | * The OpenModelica software and the OSMC (Open Source Modelica Consortium) | ||
| 17 | * Public License (OSMC-PL) are obtained from OSMC, either from the above | ||
| 18 | * address, from the URLs: | ||
| 19 | * http://www.openmodelica.org or | ||
| 20 | * https://github.com/OpenModelica/ or | ||
| 21 | * http://www.ida.liu.se/projects/OpenModelica, | ||
| 22 | * and in the OpenModelica distribution. | ||
| 23 | * | ||
| 24 | * GNU AGPL version 3 is obtained from: | ||
| 25 | * https://www.gnu.org/licenses/licenses.html#GPL | ||
| 26 | * | ||
| 27 | * This program is distributed WITHOUT ANY WARRANTY; without | ||
| 28 | * even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 29 | * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH | ||
| 30 | * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. | ||
| 31 | * | ||
| 32 | * See the full OSMC Public License conditions for more details. | ||
| 33 | * | ||
| 34 | */ | ||
| 35 | |||
| 36 | encapsulated package Inst | ||
| 37 | " file: Inst.mo | ||
| 38 | package: Inst | ||
| 39 | description: Model instantiation | ||
| 40 | |||
| 41 | |||
| 42 | This module is responsible for instantiation of Modelica models. | ||
| 43 | The instantation is the process of instantiating model components, | ||
| 44 | flattening inheritance and generating equations from connect statements. | ||
| 45 | The instantiation process takes Modelica AST as defined in SCode and | ||
| 46 | produces variables and equations and algorithms, etc. as defined in DAE. | ||
| 47 | |||
| 48 | This module uses Lookup to lookup classes and variables from the | ||
| 49 | environment defined in Env. It uses Connect for generating equations from | ||
| 50 | connect statements. The type system defined in Types is used for | ||
| 51 | variable instantiation and type. DAE.Mod is used for modifiers and | ||
| 52 | merging of modifiers. | ||
| 53 | |||
| 54 | The extends language feature is performed by InstExtends. Instantiation of | ||
| 55 | algorithm sections and equation sections (including connections) is done | ||
| 56 | by InstSection. | ||
| 57 | |||
| 58 | There are basically four different ways/granularities of instantiation. | ||
| 59 | 1. Using partialInstClassIn which only instantiates class definitions. | ||
| 60 | This function is used for looking up class definitions in e.g. packages. | ||
| 61 | For example, if looking up the class A.B.C, a new scope is opened and | ||
| 62 | A is partially instantiated in that scope using partialInstClassIn. | ||
| 63 | |||
| 64 | 2. Function implicit instantiation. is the last argument of type bool to | ||
| 65 | instClassIn. It is needed since instantiation of functions is needed | ||
| 66 | to generate code for functions and there are cases where such | ||
| 67 | instantiations differ | ||
| 68 | from standard function instantiation. For example | ||
| 69 | function foo | ||
| 70 | input Real x{:}; | ||
| 71 | ... | ||
| 72 | end foo; | ||
| 73 | should be possible to instantiate even though the dimension size of x is | ||
| 74 | not known. | ||
| 75 | |||
| 76 | 3. Implicit instantiation controlled by the next last argument to | ||
| 77 | instClassIn. | ||
| 78 | This is also needed, when a DAE should not be generated. | ||
| 79 | It is not clear when this is needed, perhaps it can be removed in the | ||
| 80 | future. | ||
| 81 | |||
| 82 | 4. ???" | ||
| 83 | |||
| 84 | // public imports | ||
| 85 | public import Absyn; | ||
| 86 | public import AbsynUtil; | ||
| 87 | public import ClassInf; | ||
| 88 | public import DAE.Connect; | ||
| 89 | public import ConnectionGraph; | ||
| 90 | public import DAE; | ||
| 91 | public import FCore; | ||
| 92 | public import InnerOuter; | ||
| 93 | public import InstTypes; | ||
| 94 | public import Mod; | ||
| 95 | public import SCode; | ||
| 96 | public import UnitAbsyn; | ||
| 97 | |||
| 98 | // ** | ||
| 99 | // These type aliases are introduced to make the code a little more readable. | ||
| 100 | // ** | ||
| 101 | |||
| 102 | protected type Ident = DAE.Ident "an identifier"; | ||
| 103 | |||
| 104 | protected type InstanceHierarchy = InnerOuter.InstHierarchy "an instance hierarchy"; | ||
| 105 | |||
| 106 | protected type InstDims = InstTypes.InstDims; | ||
| 107 | |||
| 108 | protected partial function BasicTypeAttrTyper | ||
| 109 | input String inAttrName; | ||
| 110 | input DAE.Type inClassType; | ||
| 111 | input SourceInfo inInfo; | ||
| 112 | output DAE.Type outType; | ||
| 113 | end BasicTypeAttrTyper; | ||
| 114 | |||
| 115 | // protected imports | ||
| 116 | protected | ||
| 117 | |||
| 118 | import BaseHashTable; | ||
| 119 | import Builtin; | ||
| 120 | import Ceval; | ||
| 121 | import ConnectUtil; | ||
| 122 | import ComponentReference; | ||
| 123 | protected import ComponentReferenceBasics; | ||
| 124 | import Config; | ||
| 125 | import DAEUtil; | ||
| 126 | import Debug; | ||
| 127 | import Dump; | ||
| 128 | import ElementSource; | ||
| 129 | import Error; | ||
| 130 | import ErrorExt; | ||
| 131 | import ExecStat; | ||
| 132 | import Expression; | ||
| 133 | import Flags; | ||
| 134 | import FGraph; | ||
| 135 | import FGraphBuildEnv; | ||
| 136 | import FNode; | ||
| 137 | import GCExt; | ||
| 138 | import Global; | ||
| 139 | import HashTable; | ||
| 140 | import HashTable5; | ||
| 141 | import InstHashTable; | ||
| 142 | import InstMeta; | ||
| 143 | import InstSection; | ||
| 144 | import InstBinding; | ||
| 145 | import InstVar; | ||
| 146 | import InstFunction; | ||
| 147 | import InstUtil; | ||
| 148 | import InstExtends; | ||
| 149 | import List; | ||
| 150 | import Lookup; | ||
| 151 | import Mutable; | ||
| 152 | import PrefixUtil; | ||
| 153 | import SCodeUtil; | ||
| 154 | import SCodeInstUtil; | ||
| 155 | import Static; | ||
| 156 | import Types; | ||
| 157 | import UnitParserExt; | ||
| 158 | import Util; | ||
| 159 | import Values; | ||
| 160 | import ValuesDump; | ||
| 161 | import ValuesUtil; | ||
| 162 | import System; | ||
| 163 | import SCodeDump; | ||
| 164 | import UnitAbsynBuilder; | ||
| 165 | import InstStateMachineUtil; | ||
| 166 | import UnitCheck = FUnitCheck; | ||
| 167 | |||
| 168 | import DAEDump; // BTH | ||
| 169 | import ClassInfUtil; | ||
| 170 | import ExpressionBasics; | ||
| 171 | |||
| 172 | protected function instantiateClass_dispatch | ||
| 173 | " instantiate a class. | ||
| 174 | if this function fails with stack overflow, it will be caught in the caller" | ||
| 175 | input FCore.Cache inCache; | ||
| 176 | input InnerOuter.InstHierarchy inIH; | ||
| 177 | input SCode.Program inProgram; | ||
| 178 | input SCode.Path inPath; | ||
| 179 | input Boolean doSCodeDep "Do SCode dependency (if the debug flag is also enabled)"; | ||
| 180 | input Boolean relaxedFrontEnd=true "Do not check for illegal simulation models, so we allow instantation of packages, etc"; | ||
| 181 | input Boolean clearCache = true "Clear the inst cache when done"; | ||
| 182 | output FCore.Cache outCache; | ||
| 183 | output FCore.Graph outEnv; | ||
| 184 | output InnerOuter.InstHierarchy outIH; | ||
| 185 | output DAE.DAElist outDAElist; | ||
| 186 | algorithm | ||
| 187 | (outCache,outEnv,outIH,outDAElist) := match (inCache,inIH,inProgram,inPath) | ||
| 188 | local | ||
| 189 | Absyn.Path path; | ||
| 190 | FCore.Graph env; | ||
| 191 | DAE.DAElist dae,dae2; | ||
| 192 | list<SCode.Element> cdecls; | ||
| 193 | String n,pathstr,name; | ||
| 194 | SCode.Element cdef; | ||
| 195 | FCore.Cache cache; | ||
| 196 | InstanceHierarchy ih; | ||
| 197 | DAE.ElementSource source "the origin of the element"; | ||
| 198 | list<DAE.Element> daeElts; | ||
| 199 | Option<SCode.Comment> cmt; | ||
| 200 | |||
| 201 | // top level class | ||
| 202 | case (cache,ih,(cdecls as (_ :: _)),(path as Absyn.IDENT())) | ||
| 203 | algorithm | ||
| 204 | 876 | cache := FCore.setCacheClassName(cache,path); | |
| 205 |
1/2✓ Branch 0 taken 876 times.
✗ Branch 1 not taken.
|
876 | if doSCodeDep then |
| 206 | 876 | cdecls := InstUtil.scodeFlatten(cdecls, inPath); | |
| 207 | 861 | ExecStat.execStat("FrontEnd - scodeFlatten"); | |
| 208 | end if; | ||
| 209 | 861 | (cache,env) := Builtin.initialGraph(cache); | |
| 210 | 861 | env := FGraphBuildEnv.mkProgramGraph(cdecls, FCore.USERDEFINED(), env); | |
| 211 | |||
| 212 | // set the source of this element | ||
| 213 | 861 | source := ElementSource.addElementSourcePartOfOpt(DAE.emptyElementSource, FGraph.getScopePath(env)); | |
| 214 | |||
| 215 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 861 times.
|
861 | if Flags.isSet(Flags.GC_PROF) then |
| 216 | ✗ | print(GCExt.profStatsStr(GCExt.getProfStats(), head="GC stats after pre-frontend work (building graphs):") + "\n"); | |
| 217 | end if; | ||
| 218 | 861 | ExecStat.execStat("FrontEnd - mkProgramGraph"); | |
| 219 | |||
| 220 | 861 | (cache,env,ih,dae2) := instClassInProgram(cache, env, ih, cdecls, path, source, relaxedFrontEnd); | |
| 221 | // check the models for balancing | ||
| 222 | //Debug.fcall2(Flags.CHECK_MODEL_BALANCE, checkModelBalancing, SOME(path), dae1); | ||
| 223 | //Debug.fcall2(Flags.CHECK_MODEL_BALANCE, checkModelBalancing, SOME(path), dae2); | ||
| 224 | |||
| 225 | // let the GC collect these as they are used only by Inst! | ||
| 226 |
1/2✓ Branch 0 taken 775 times.
✗ Branch 1 not taken.
|
775 | if clearCache then |
| 227 | 775 | InstHashTable.release(); | |
| 228 | end if; | ||
| 229 | 775 | then | |
| 230 | (cache,env,ih,dae2); | ||
| 231 | |||
| 232 | // class in package | ||
| 233 | case (cache,ih,(cdecls as (_ :: _)),(path as Absyn.QUALIFIED())) | ||
| 234 | algorithm | ||
| 235 | 228 | cache := FCore.setCacheClassName(cache,path); | |
| 236 |
1/2✓ Branch 0 taken 228 times.
✗ Branch 1 not taken.
|
228 | if doSCodeDep then |
| 237 | 228 | cdecls := InstUtil.scodeFlatten(cdecls, inPath); | |
| 238 | 226 | ExecStat.execStat("FrontEnd - scodeFlatten"); | |
| 239 | end if; | ||
| 240 | 226 | pathstr := AbsynUtil.pathString(path); | |
| 241 | |||
| 242 | //System.startTimer(); | ||
| 243 | //print("\nBuiltinMaking"); | ||
| 244 | 226 | (cache,env) := Builtin.initialGraph(cache); | |
| 245 | //System.stopTimer(); | ||
| 246 | //print("\nBuiltinMaking: " + realString(System.getTimerIntervalTime())); | ||
| 247 | |||
| 248 | //System.startTimer(); | ||
| 249 | //print("\nInstClassDecls"); | ||
| 250 | 226 | env := FGraphBuildEnv.mkProgramGraph(cdecls, FCore.USERDEFINED(), env); | |
| 251 | //System.stopTimer(); | ||
| 252 | //print("\nInstClassDecls: " + realString(System.getTimerIntervalTime())); | ||
| 253 | |||
| 254 | //System.startTimer(); | ||
| 255 | //print("\nLookupClass"); | ||
| 256 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 226 times.
|
226 | (cache,(cdef as SCode.CLASS(name = n)),env) := Lookup.lookupClass(cache, env, path, SOME(Absyn.dummyInfo)); |
| 257 | |||
| 258 | // Check if we are trying to instantiate a function or pacakage when we should not. | ||
| 259 | 226 | checkInstanceRestriction(cdef, path, relaxedFrontEnd); | |
| 260 | |||
| 261 | //System.stopTimer(); | ||
| 262 | //print("\nLookupClass: " + realString(System.getTimerIntervalTime())); | ||
| 263 | |||
| 264 | //System.startTimer(); | ||
| 265 | //print("\nInstClass"); | ||
| 266 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 225 times.
|
225 | if Flags.isSet(Flags.GC_PROF) then |
| 267 | ✗ | print(GCExt.profStatsStr(GCExt.getProfStats(), head="GC stats after pre-frontend work (building graphs):") + "\n"); | |
| 268 | end if; | ||
| 269 | 225 | ExecStat.execStat("FrontEnd - mkProgramGraph"); | |
| 270 | |||
| 271 | 225 | (cache,env,ih,_,dae,_,_,_,_,_) := instClass(cache,env,ih, | |
| 272 | UnitAbsynBuilder.emptyInstStore(),DAE.NOMOD(), makeTopComponentPrefix(env, n), cdef, | ||
| 273 | {}, false, InstTypes.TOP_CALL(), ConnectionGraph.EMPTY, Connect.emptySet) "impl"; | ||
| 274 | //System.stopTimer(); | ||
| 275 | //print("\nInstClass: " + realString(System.getTimerIntervalTime())); | ||
| 276 | |||
| 277 | //System.startTimer(); | ||
| 278 | //print("\nReEvaluateIf"); | ||
| 279 | //print(" ********************** backpatch 1 **********************\n"); | ||
| 280 | 225 | dae := InstUtil.reEvaluateInitialIfEqns(cache,env,dae,true); | |
| 281 | //System.stopTimer(); | ||
| 282 | //print("\nReEvaluateIf: " + realString(System.getTimerIntervalTime())); | ||
| 283 | |||
| 284 | // check the model for balancing | ||
| 285 | // Debug.fcall2(Flags.CHECK_MODEL_BALANCE, checkModelBalancing, SOME(path), dae); | ||
| 286 | |||
| 287 | //System.startTimer(); | ||
| 288 | //print("\nSetSource+DAE"); | ||
| 289 | // set the source of this element | ||
| 290 | 225 | source := ElementSource.addElementSourcePartOfOpt(DAE.emptyElementSource, FGraph.getScopePath(env)); | |
| 291 | 225 | daeElts := DAEUtil.daeElements(dae); | |
| 292 | 225 | cmt := SCodeUtil.getElementComment(cdef); | |
| 293 | 450 | dae := DAE.DAE({DAE.COMP(pathstr,daeElts,source,cmt)}); | |
| 294 | //System.stopTimer(); | ||
| 295 | //print("\nSetSource+DAE: " + realString(System.getTimerIntervalTime())); | ||
| 296 | |||
| 297 | // let the GC collect these as they are used only by Inst! | ||
| 298 |
1/2✓ Branch 0 taken 225 times.
✗ Branch 1 not taken.
|
225 | if clearCache then |
| 299 | 225 | InstHashTable.release(); | |
| 300 | end if; | ||
| 301 | 225 | then | |
| 302 | (cache, env, ih, dae); | ||
| 303 | |||
| 304 | end match; | ||
| 305 | end instantiateClass_dispatch; | ||
| 306 | |||
| 307 | public function instantiateClass | ||
| 308 | "To enable interactive instantiation, an arbitrary class in the program | ||
| 309 | needs to be possible to instantiate. This function performs the same | ||
| 310 | action as instProgram, but given a specific class to instantiate. | ||
| 311 | |||
| 312 | First, all the class definitions are added to the environment without | ||
| 313 | modifications, and then the specified class is instantiated in the | ||
| 314 | function instClassInProgram" | ||
| 315 | input FCore.Cache inCache; | ||
| 316 | input InnerOuter.InstHierarchy inIH; | ||
| 317 | input SCode.Program inProgram; | ||
| 318 | input SCode.Path inPath; | ||
| 319 | input Boolean doSCodeDep=true "Do SCode dependency (if the debug flag is also enabled)"; | ||
| 320 | input Boolean relaxedFrontEnd=true "Do not check for illegal simulation models, so we allow instantation of packages, etc"; | ||
| 321 | input Boolean clearCache=true "Clear the inst cache when done"; | ||
| 322 | output FCore.Cache outCache; | ||
| 323 | output FCore.Graph outEnv; | ||
| 324 | output InnerOuter.InstHierarchy outIH; | ||
| 325 | output DAE.DAElist outDAElist; | ||
| 326 | algorithm | ||
| 327 | (outCache,outEnv,outIH,outDAElist) := matchcontinue (inCache,inIH,inProgram,inPath) | ||
| 328 | local | ||
| 329 | Absyn.Path path; | ||
| 330 | list<SCode.Element> cdecls; | ||
| 331 | String cname_str; | ||
| 332 | FCore.Cache cache; | ||
| 333 | InstanceHierarchy ih; | ||
| 334 | Boolean stackOverflow; | ||
| 335 | |||
| 336 | case (_,_,{},_) | ||
| 337 | algorithm | ||
| 338 | ✗ | Error.addMessage(Error.NO_CLASSES_LOADED, {}); | |
| 339 | ✗ | then | |
| 340 | fail(); | ||
| 341 | |||
| 342 | // instantiate a class | ||
| 343 | case (cache,ih,cdecls as _::_,path) | ||
| 344 | algorithm | ||
| 345 | 1104 | (outCache,outEnv,outIH,outDAElist) := instantiateClass_dispatch(cache,ih,cdecls,path,doSCodeDep,relaxedFrontEnd,clearCache); | |
| 346 | 1000 | outDAElist := UnitCheck.checkUnits(outDAElist,FCore.getFunctionTree(outCache)); | |
| 347 |
1/2✓ Branch 0 taken 1000 times.
✗ Branch 1 not taken.
|
1000 | then |
| 348 | (outCache,outEnv,outIH,outDAElist); | ||
| 349 | |||
| 350 | // error instantiating | ||
| 351 | case (_,_,_::_,path) | ||
| 352 | algorithm | ||
| 353 | // if we got a stack overflow remove the stack-overflow flag | ||
| 354 | // adrpo: NOTE THAT THE NEXT FUNCTION CALL MUST BE THE FIRST IN THIS CASE, otherwise the stack overflow will not be caught! | ||
| 355 | stackOverflow := setStackOverflowSignal(false); | ||
| 356 | |||
| 357 | 104 | cname_str := AbsynUtil.pathString(path) + (if stackOverflow then ". The compiler got into Stack Overflow!" else ""); | |
| 358 |
1/2✓ Branch 1 taken 104 times.
✗ Branch 2 not taken.
|
104 | if not Config.getGraphicsExpMode() then |
| 359 | 104 | Error.addMessage(Error.ERROR_FLATTENING, {cname_str}); | |
| 360 | end if; | ||
| 361 | |||
| 362 | // let the GC collect these as they are used only by Inst! | ||
| 363 | 104 | InstHashTable.release(); | |
| 364 | 104 | then | |
| 365 | fail(); | ||
| 366 | end matchcontinue; | ||
| 367 | end instantiateClass; | ||
| 368 | |||
| 369 | public function instantiatePartialClass | ||
| 370 | "Author: BZ, 2009-07 | ||
| 371 | This is a function for instantiating partial 'top' classes. | ||
| 372 | It does so by converting the partial class into a non partial class. | ||
| 373 | Currently used by: MathCore.modelEquations, CevalScript.checkModel" | ||
| 374 | input FCore.Cache inCache; | ||
| 375 | input InnerOuter.InstHierarchy inIH; | ||
| 376 | input SCode.Program inProgram; | ||
| 377 | input SCode.Path inPath; | ||
| 378 | output FCore.Cache outCache; | ||
| 379 | output FCore.Graph outEnv; | ||
| 380 | output InnerOuter.InstHierarchy outIH; | ||
| 381 | output DAE.DAElist outDAElist; | ||
| 382 | algorithm | ||
| 383 | (outCache,outEnv,outIH,outDAElist) := matchcontinue (inCache,inIH,inProgram,inPath) | ||
| 384 | local | ||
| 385 | Absyn.Path path; | ||
| 386 | FCore.Graph env,env_1,env_2; | ||
| 387 | DAE.DAElist dae; | ||
| 388 | list<SCode.Element> cdecls; | ||
| 389 | String n,pathstr,name,cname_str; | ||
| 390 | SCode.Element cdef; | ||
| 391 | FCore.Cache cache; | ||
| 392 | InstanceHierarchy ih; | ||
| 393 | DAE.ElementSource source "the origin of the element"; | ||
| 394 | list<DAE.Element> daeElts; | ||
| 395 | Option<SCode.Comment> cmt; | ||
| 396 | |||
| 397 | case (_,_,{},_) | ||
| 398 | algorithm | ||
| 399 | ✗ | Error.addMessage(Error.NO_CLASSES_LOADED, {}); | |
| 400 | ✗ | then | |
| 401 | fail(); | ||
| 402 | |||
| 403 | case (cache,ih,(cdecls as (_ :: _)),(path as Absyn.IDENT())) /* top level class */ | ||
| 404 | algorithm | ||
| 405 | ✗ | (cache,env) := Builtin.initialGraph(cache); | |
| 406 | ✗ | env_1 := FGraphBuildEnv.mkProgramGraph(cdecls, FCore.USERDEFINED(), env); | |
| 407 | ✗ | cdecls := List.map1(cdecls,SCodeUtil.classSetPartial,SCode.NOT_PARTIAL()); | |
| 408 | ✗ | source := ElementSource.addElementSourcePartOfOpt(DAE.emptyElementSource, FGraph.getScopePath(env)); | |
| 409 | ✗ | (cache,env_2,ih,dae) := instClassInProgram(cache, env_1, ih, cdecls, path, source); | |
| 410 | then | ||
| 411 | (cache,env_2,ih,dae); | ||
| 412 | |||
| 413 | case (cache,ih,(cdecls as (_ :: _)),(path as Absyn.QUALIFIED())) /* class in package */ | ||
| 414 | algorithm | ||
| 415 | ✗ | (cache,env) := Builtin.initialGraph(cache); | |
| 416 | ✗ | env_1 := FGraphBuildEnv.mkProgramGraph(cdecls, FCore.USERDEFINED(), env); | |
| 417 | ✗ | (cache,(cdef as SCode.CLASS(name = n)),env_2) := Lookup.lookupClass(cache,env_1, path, SOME(Absyn.dummyInfo)); | |
| 418 | |||
| 419 | ✗ | cdef := SCodeUtil.classSetPartial(cdef, SCode.NOT_PARTIAL()); | |
| 420 | |||
| 421 | ✗ | (cache,env_2,ih,_,dae,_,_,_,_,_) := | |
| 422 | instClass(cache, env_2, ih, UnitAbsynBuilder.emptyInstStore(),DAE.NOMOD(), makeTopComponentPrefix(env_2, n), | ||
| 423 | cdef, {}, false, InstTypes.TOP_CALL(), ConnectionGraph.EMPTY, Connect.emptySet) "impl" ; | ||
| 424 | ✗ | pathstr := AbsynUtil.pathString(path); | |
| 425 | |||
| 426 | // set the source of this element | ||
| 427 | ✗ | source := ElementSource.addElementSourcePartOfOpt(DAE.emptyElementSource, FGraph.getScopePath(env)); | |
| 428 | ✗ | daeElts := DAEUtil.daeElements(dae); | |
| 429 | ✗ | cmt := SCodeUtil.getElementComment(cdef); | |
| 430 | ✗ | dae := DAE.DAE({DAE.COMP(pathstr,daeElts,source,cmt)}); | |
| 431 | ✗ | then | |
| 432 | (cache,env_2,ih,dae); | ||
| 433 | |||
| 434 | case (_,_,_,path) /* error instantiating */ | ||
| 435 | guard not Config.getGraphicsExpMode() | ||
| 436 | algorithm | ||
| 437 | ✗ | cname_str := AbsynUtil.pathString(path); | |
| 438 | //print(" Error flattening partial, errors: " + ErrorExt.printMessagesStr() + "\n"); | ||
| 439 | ✗ | Error.addMessage(Error.ERROR_FLATTENING, {cname_str}); | |
| 440 | ✗ | then | |
| 441 | fail(); | ||
| 442 | end matchcontinue; | ||
| 443 | end instantiatePartialClass; | ||
| 444 | |||
| 445 | protected function makeTopComponentPrefix | ||
| 446 | input FGraph.Graph inGraph; | ||
| 447 | input Absyn.Ident inName; | ||
| 448 | output DAE.Prefix outPrefix; | ||
| 449 | algorithm | ||
| 450 | //p := FGraph.joinScopePath(inGraph, Absyn.IDENT(inName)); | ||
| 451 | //outPrefix := DAE.PREFIX(DAE.PRE("$i", {}, {}, DAE.NOCOMPPRE(), ClassInf.MODEL(p)), DAE.CLASSPRE(SCode.VAR())); | ||
| 452 | outPrefix := DAE.NOPRE(); | ||
| 453 | end makeTopComponentPrefix; | ||
| 454 | |||
| 455 | protected function instClassInProgram | ||
| 456 | "Instantiates a specific top level class in a Program." | ||
| 457 | input FCore.Cache inCache; | ||
| 458 | input FCore.Graph inEnv; | ||
| 459 | input InnerOuter.InstHierarchy inIH; | ||
| 460 | input SCode.Program inProgram; | ||
| 461 | input SCode.Path inPath; | ||
| 462 | input DAE.ElementSource inSource; | ||
| 463 | input Boolean relaxedFrontEnd = true "Do not check for illegal simulation models, so we allow instantation of packages, etc"; | ||
| 464 | output FCore.Cache outCache; | ||
| 465 | output FCore.Graph outEnv; | ||
| 466 | output InnerOuter.InstHierarchy outIH; | ||
| 467 | output DAE.DAElist outDae; | ||
| 468 | algorithm | ||
| 469 | (outCache, outEnv, outIH, outDae) := | ||
| 470 | matchcontinue(inProgram, inPath) | ||
| 471 | local | ||
| 472 | String name; | ||
| 473 | SCode.Element cls; | ||
| 474 | FCore.Cache cache; | ||
| 475 | FCore.Graph env; | ||
| 476 | InstanceHierarchy ih; | ||
| 477 | DAE.DAElist dae; | ||
| 478 | list<DAE.Element> elts; | ||
| 479 | Option<SCode.Comment> cmt; | ||
| 480 | |||
| 481 | case ({}, _) | ||
| 482 | then (inCache, inEnv, inIH, DAE.emptyDae); | ||
| 483 | |||
| 484 | case (_, Absyn.IDENT(name = "")) | ||
| 485 | then (inCache, inEnv, inIH, DAE.emptyDae); | ||
| 486 | |||
| 487 | case (_, Absyn.IDENT(name = name)) | ||
| 488 | algorithm | ||
| 489 | 861 | cls := InstUtil.lookupTopLevelClass(name, inProgram, true); | |
| 490 | |||
| 491 | // Disable this check since we have some test cases that instantiate | ||
| 492 | // TOP level functions and pacakges. | ||
| 493 | // checkInstanceRestriction(cls, inPath, relaxedFrontEnd); | ||
| 494 | |||
| 495 | 861 | (cache, env, ih, _, dae, _, _, _, _, _) := instClass(inCache, inEnv, | |
| 496 | inIH, UnitAbsynBuilder.emptyInstStore(), DAE.NOMOD(), makeTopComponentPrefix(inEnv, name), | ||
| 497 | cls, {}, false, InstTypes.TOP_CALL(), ConnectionGraph.EMPTY, Connect.emptySet); | ||
| 498 | 775 | dae := InstUtil.reEvaluateInitialIfEqns(cache, env, dae, true); | |
| 499 | 775 | elts := DAEUtil.daeElements(dae); | |
| 500 | |||
| 501 | 775 | cmt := SCodeUtil.getElementComment(cls); | |
| 502 | 1550 | dae := DAE.DAE({DAE.COMP(name, elts, inSource, cmt)}); | |
| 503 | 775 | then | |
| 504 | (cache, env, ih, dae); | ||
| 505 | |||
| 506 | else | ||
| 507 | algorithm | ||
| 508 |
1/2✓ Branch 1 taken 86 times.
✗ Branch 2 not taken.
|
86 | true := Flags.isSet(Flags.FAILTRACE); |
| 509 | ✗ | Debug.trace("Inst.instClassInProgram failed\n"); | |
| 510 | ✗ | then | |
| 511 | fail(); | ||
| 512 | |||
| 513 | end matchcontinue; | ||
| 514 | end instClassInProgram; | ||
| 515 | |||
| 516 | public function instClass | ||
| 517 | "Instantiation of a class can be either implicit or normal. | ||
| 518 | This function is used in both cases. When implicit instantiation | ||
| 519 | is performed, the last argument is true, otherwise it is false. | ||
| 520 | |||
| 521 | Instantiating a class consists of the following steps: | ||
| 522 | o Create a new frame on the environment | ||
| 523 | o Initialize the class inference state machine | ||
| 524 | o Instantiate all the elements and equations | ||
| 525 | o Generate equations from the connection sets built during instantiation" | ||
| 526 | input FCore.Cache inCache; | ||
| 527 | input FCore.Graph inEnv; | ||
| 528 | input InnerOuter.InstHierarchy inIH; | ||
| 529 | input UnitAbsyn.InstStore inStore; | ||
| 530 | input DAE.Mod inMod; | ||
| 531 | input DAE.Prefix inPrefix; | ||
| 532 | input SCode.Element inClass; | ||
| 533 | input list<list<DAE.Dimension>> inInstDims; | ||
| 534 | input Boolean inImplicit; | ||
| 535 | input InstTypes.CallingScope inCallingScope; | ||
| 536 | input ConnectionGraph.ConnectionGraph inGraph; | ||
| 537 | input Connect.Sets inSets; | ||
| 538 | output FCore.Cache cache; | ||
| 539 | output FCore.Graph outEnv; | ||
| 540 | output InnerOuter.InstHierarchy outIH; | ||
| 541 | output UnitAbsyn.InstStore outStore; | ||
| 542 | output DAE.DAElist outDae; | ||
| 543 | output Connect.Sets outSets; | ||
| 544 | output DAE.Type outType; | ||
| 545 | output ClassInf.State outState; | ||
| 546 | output Option<SCode.Attributes> optDerAttr; | ||
| 547 | output ConnectionGraph.ConnectionGraph outGraph; | ||
| 548 | algorithm | ||
| 549 | (cache,outEnv,outIH,outStore,outDae,outSets,outType,outState,optDerAttr,outGraph):= | ||
| 550 | matchcontinue (inCache, inEnv, inIH, inStore, inMod, inPrefix, inClass, inInstDims, inImplicit, inCallingScope, inGraph) | ||
| 551 | local | ||
| 552 | FCore.Graph env,env_1,env_3; | ||
| 553 | DAE.Mod mod; | ||
| 554 | DAE.Prefix pre; | ||
| 555 | Connect.Sets csets; | ||
| 556 | String n,scopeName,strDepth; | ||
| 557 | Boolean impl,callscope_1,isFn,notIsPartial,isPartialFn,recursionDepthReached; | ||
| 558 | SCode.Partial partialPrefix; | ||
| 559 | SCode.Encapsulated encflag; | ||
| 560 | ClassInf.State ci_state,ci_state_1; | ||
| 561 | DAE.DAElist dae1,dae1_1,dae; | ||
| 562 | list<DAE.Var> tys; | ||
| 563 | Option<DAE.Type> bc_ty; | ||
| 564 | Absyn.Path fq_class; | ||
| 565 | DAE.Type ty; | ||
| 566 | SCode.Element c; | ||
| 567 | SCode.Restriction r; | ||
| 568 | InstDims inst_dims; | ||
| 569 | InstTypes.CallingScope callscope; | ||
| 570 | Option<SCode.Attributes> oDA; | ||
| 571 | ConnectionGraph.ConnectionGraph graph; | ||
| 572 | InstanceHierarchy ih; | ||
| 573 | DAE.EqualityConstraint equalityConstraint; | ||
| 574 | SourceInfo info; | ||
| 575 | UnitAbsyn.InstStore store; | ||
| 576 | |||
| 577 | // adrpo: ONLY when running checkModel we should be able to instantiate partial classes | ||
| 578 | case (cache, _, _, store, _, _, SCode.CLASS(name=n, partialPrefix = SCode.PARTIAL(), restriction = r, info = info), _, _, _, _) | ||
| 579 | algorithm | ||
| 580 |
2/2✓ Branch 1 taken 506 times.
✓ Branch 2 taken 6 times.
|
512 | true := Flags.getConfigBool(Flags.CHECK_MODEL); |
| 581 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
|
6 | false := SCodeUtil.isFunctionRestriction(r); // Partial functions are handled below (used for partially evaluated functions; do not want the checkModel warning) |
| 582 | 6 | c := SCodeUtil.setClassPartialPrefix(SCode.NOT_PARTIAL(), inClass); | |
| 583 | // add a warning | ||
| 584 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | if not Config.getGraphicsExpMode() then |
| 585 | 6 | Error.addSourceMessage(Error.INST_PARTIAL_CLASS_CHECK_MODEL_WARNING, {n}, info); | |
| 586 | end if; | ||
| 587 | // call normal instantiation | ||
| 588 | 6 | (cache,env,ih,store,dae,csets,ty,ci_state_1,oDA,graph) := | |
| 589 | instClass(inCache, inEnv, inIH, store, inMod, inPrefix, c, inInstDims, inImplicit, inCallingScope, inGraph, inSets); | ||
| 590 | then | ||
| 591 | (cache,env,ih,store,dae,csets,ty,ci_state_1,oDA,graph); | ||
| 592 | |||
| 593 | // Instantiation of a class. Create new scope and call instClassIn. | ||
| 594 | // Then generate equations from connects. | ||
| 595 | case (cache, env, ih, store, mod, pre, (c as SCode.CLASS(name = n,encapsulatedPrefix = encflag,restriction = r, partialPrefix = partialPrefix, info = info)), inst_dims, impl, callscope, graph) | ||
| 596 | algorithm | ||
| 597 | 923803 | recursionDepthReached := listLength(FGraph.currentScope(env)) < Global.recursionDepthLimit; | |
| 598 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 923803 times.
|
923803 | if not recursionDepthReached then |
| 599 | ✗ | scopeName := FGraph.printGraphPathStr(env); | |
| 600 | strDepth := intString(Global.recursionDepthLimit); | ||
| 601 | ✗ | Error.addSourceMessage(Error.RECURSION_DEPTH_REACHED,{strDepth, scopeName},info); | |
| 602 | ✗ | fail(); | |
| 603 | end if; | ||
| 604 | //print("---- CLASS: "); print(n);print(" ----\n"); print(SCodeDump.printClassStr(c)); //Print out the input SCode class | ||
| 605 | //str = SCodeDump.printClassStr(c); print("------------------- CLASS instClass-----------------\n");print(str);print("\n===============================================\n"); | ||
| 606 | |||
| 607 | // First check if the class is non-partial or a partial function | ||
| 608 | 923803 | isFn := SCodeUtil.isFunctionRestriction(r); | |
| 609 | 923803 | notIsPartial := not SCodeUtil.partialBool(partialPrefix); | |
| 610 |
4/4✓ Branch 0 taken 93950 times.
✓ Branch 1 taken 829853 times.
✓ Branch 3 taken 93464 times.
✓ Branch 4 taken 486 times.
|
923803 | isPartialFn := isFn and SCodeUtil.partialBool(partialPrefix); |
| 611 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 923777 times.
|
923803 | true := notIsPartial or isPartialFn; |
| 612 | |||
| 613 | 923777 | env_1 := FGraph.openScope(env, encflag, n, FGraph.restrictionToScopeType(r)); | |
| 614 | |||
| 615 | 923777 | ci_state := ClassInfUtil.start(r,FGraph.getGraphName(env_1)); | |
| 616 | 923777 | csets := ConnectUtil.newSet(pre, inSets); | |
| 617 | 923777 | (cache,env_3,ih,store,dae1,csets,ci_state_1,tys,bc_ty,oDA,equalityConstraint, graph) | |
| 618 | := instClassIn(cache, env_1, ih, store, mod, pre, ci_state, c, SCode.PUBLIC(), inst_dims, impl, callscope, graph, csets, NONE()); | ||
| 619 | 898893 | csets := ConnectUtil.addSet(inSets, csets); | |
| 620 | 898893 | (cache,fq_class) := makeFullyQualifiedIdent(cache, env, n); | |
| 621 | |||
| 622 | // is top level? | ||
| 623 | 898893 | callscope_1 := InstUtil.isTopCall(callscope); | |
| 624 | |||
| 625 | 898893 | dae1_1 := DAEUtil.addComponentType(dae1, fq_class); | |
| 626 | |||
| 627 | // phi: very old unit checking | ||
| 628 | /* | ||
| 629 | InstUtil.reportUnitConsistency(callscope_1,store); | ||
| 630 | */ | ||
| 631 | 898893 | (csets, _, graph) := InnerOuter.retrieveOuterConnections(cache,env_3,ih,pre,csets,callscope_1, graph); | |
| 632 | |||
| 633 | //System.startTimer(); | ||
| 634 | //print("\nConnect equations and the OverConstrained graph in one step"); | ||
| 635 | 898893 | dae := ConnectUtil.equations(callscope_1, csets, dae1_1, graph, AbsynUtil.pathString(AbsynUtil.makeNotFullyQualified(fq_class))); | |
| 636 | //System.stopTimer(); | ||
| 637 | //print("\nConnect and Overconstrained: " + realString(System.getTimerIntervalTime()) + "\n"); | ||
| 638 | 898893 | ty := InstUtil.mktype(fq_class, ci_state_1, tys, bc_ty, equalityConstraint, c, InstUtil.extractComment(dae.elementLst)); | |
| 639 | 898893 | dae := InstUtil.updateDeducedUnits(callscope_1,store,dae); | |
| 640 | |||
| 641 | 898893 | ty := markDerivedRecordOutsideBindings(ty, c); | |
| 642 | 898893 | ty := markTypesVarsOutsideBindings(ty,mod); | |
| 643 | |||
| 644 | // Fixes partial functions. | ||
| 645 | 898893 | ty := InstUtil.fixInstClassType(ty,isPartialFn); | |
| 646 | // env_3 = FGraph.updateScope(env_3); | ||
| 647 | 898893 | then | |
| 648 | (cache,env_3,ih,store,dae,csets,ty,ci_state_1,oDA,graph); | ||
| 649 | |||
| 650 | // Classes with the keyword partial can not be instantiated. They can only be inherited | ||
| 651 | case (cache, _, _, _, _, _, SCode.CLASS(name = n,partialPrefix = SCode.PARTIAL(), info = info), _, (false), _, _) | ||
| 652 | algorithm | ||
| 653 |
1/2✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
|
26 | if not Config.getGraphicsExpMode() then |
| 654 | 26 | Error.addSourceMessage(Error.INST_PARTIAL_CLASS, {n}, info); | |
| 655 | end if; | ||
| 656 | 26 | then | |
| 657 | fail(); | ||
| 658 | |||
| 659 | case (_, env, _, _, _, _, SCode.CLASS(name = n), _, _, _, _) | ||
| 660 | algorithm | ||
| 661 |
2/2✓ Branch 1 taken 24896 times.
✓ Branch 2 taken 14 times.
|
24910 | true := Flags.isSet(Flags.FAILTRACE); |
| 662 | 14 | Debug.trace("- Inst.instClass: " + n + " in env: " + FGraph.printGraphPathStr(env) + " failed\n"); | |
| 663 | 14 | then | |
| 664 | fail(); | ||
| 665 | end matchcontinue; | ||
| 666 | end instClass; | ||
| 667 | |||
| 668 | protected function instClassBasictype | ||
| 669 | "author: PA | ||
| 670 | This function instantiates a basictype class, e.g. Real, Integer, Real[2], | ||
| 671 | etc. This function has the same functionality as instClass except that | ||
| 672 | it will create array types when needed. (instClass never creates array | ||
| 673 | types). This is needed because this function is used to instantiate classes | ||
| 674 | extending from basic types. See instBasictypeBaseclass. | ||
| 675 | NOTE: This function should only be called from instBasictypeBaseclass. | ||
| 676 | This is new functionality in Modelica v 2.2." | ||
| 677 | input FCore.Cache inCache; | ||
| 678 | input FCore.Graph inEnv; | ||
| 679 | input InnerOuter.InstHierarchy inIH; | ||
| 680 | input UnitAbsyn.InstStore inStore; | ||
| 681 | input DAE.Mod inMod; | ||
| 682 | input DAE.Prefix inPrefix; | ||
| 683 | input SCode.Element inClass; | ||
| 684 | input list<list<DAE.Dimension>> inInstDims; | ||
| 685 | input Boolean inImplicit; | ||
| 686 | input InstTypes.CallingScope inCallingScope; | ||
| 687 | input Connect.Sets inSets; | ||
| 688 | output FCore.Cache outCache; | ||
| 689 | output FCore.Graph outEnv; | ||
| 690 | output InnerOuter.InstHierarchy outIH; | ||
| 691 | output UnitAbsyn.InstStore outStore; | ||
| 692 | output DAE.DAElist outDae; | ||
| 693 | output Connect.Sets outSets; | ||
| 694 | output DAE.Type outType; | ||
| 695 | output list<DAE.Var> outTypeVars "attributes of builtin types"; | ||
| 696 | output ClassInf.State outState; | ||
| 697 | algorithm | ||
| 698 | (outCache,outEnv,outIH,outStore,outDae,outSets,outType,outTypeVars,outState):= | ||
| 699 | match (inCache, inEnv, inIH, inStore, inMod, inPrefix, inClass, inInstDims, inImplicit) | ||
| 700 | local | ||
| 701 | FCore.Graph env_1,env_3,env; | ||
| 702 | ClassInf.State ci_state,ci_state_1; | ||
| 703 | SCode.Element c_1,c; | ||
| 704 | DAE.DAElist dae1,dae1_1,dae; | ||
| 705 | Connect.Sets csets; | ||
| 706 | list<DAE.Var> tys; | ||
| 707 | Option<DAE.Type> bc_ty; | ||
| 708 | Absyn.Path fq_class; | ||
| 709 | SCode.Encapsulated encflag; | ||
| 710 | Boolean impl; | ||
| 711 | DAE.Type ty; | ||
| 712 | DAE.Mod mod; | ||
| 713 | DAE.Prefix pre; | ||
| 714 | String n; | ||
| 715 | SCode.Restriction r; | ||
| 716 | InstDims inst_dims; | ||
| 717 | FCore.Cache cache; | ||
| 718 | InstanceHierarchy ih; | ||
| 719 | UnitAbsyn.InstStore store; | ||
| 720 | |||
| 721 | case (cache, env, ih, store, mod, pre, (c as SCode.CLASS(name = n,encapsulatedPrefix = encflag,restriction = r)), inst_dims, impl) /* impl */ | ||
| 722 | algorithm | ||
| 723 | 4210 | env_1 := FGraph.openScope(env, encflag, n, FGraph.restrictionToScopeType(r)); | |
| 724 | 4210 | ci_state := ClassInfUtil.start(r, FGraph.getGraphName(env_1)); | |
| 725 | 4210 | c_1 := SCodeUtil.classSetPartial(c, SCode.NOT_PARTIAL()); | |
| 726 | 4210 | (cache,env_3,ih,store,dae1,csets,ci_state_1,tys,bc_ty,_,_,_) | |
| 727 | := instClassIn(cache, env_1, ih, store, mod, pre, ci_state, c_1, SCode.PUBLIC(), inst_dims, impl, InstTypes.INNER_CALL(), ConnectionGraph.EMPTY, inSets, NONE()); | ||
| 728 | 4209 | (cache,fq_class) := makeFullyQualifiedIdent(cache,env_3, n); | |
| 729 | 4209 | dae1_1 := DAEUtil.addComponentType(dae1, fq_class); | |
| 730 | dae := dae1_1; | ||
| 731 | 4209 | ty := InstUtil.mktypeWithArrays(fq_class, ci_state_1, tys, bc_ty, c, InstUtil.extractComment(dae.elementLst)); | |
| 732 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4209 times.
|
4209 | then |
| 733 | (cache,env_3,ih,store,dae,csets,ty,tys,ci_state_1); | ||
| 734 | |||
| 735 | case (_, _, _, _, _, _, SCode.CLASS(), _, _) | ||
| 736 | algorithm | ||
| 737 | //fprintln(Flags.FAILTRACE, "- Inst.instClassBasictype: " + n + " failed"); | ||
| 738 | then | ||
| 739 | fail(); | ||
| 740 | |||
| 741 | end match; | ||
| 742 | end instClassBasictype; | ||
| 743 | |||
| 744 | public function instClassIn " | ||
| 745 | This rule instantiates the contents of a class definition, with a new | ||
| 746 | environment already setup. | ||
| 747 | The *implicitInstantiation* boolean indicates if the class should be | ||
| 748 | instantiated implicit, i.e. without generating DAE. | ||
| 749 | The last option is a even stronger indication of implicit instantiation, | ||
| 750 | used when looking up variables in packages. This must be used because | ||
| 751 | generation of functions in implicit instanitation (according to | ||
| 752 | *implicitInstantiation* boolean) can cause circular dependencies | ||
| 753 | (e.g. if a function uses a constant in its body)" | ||
| 754 | input FCore.Cache inCache; | ||
| 755 | input FCore.Graph inEnv; | ||
| 756 | input InnerOuter.InstHierarchy inIH; | ||
| 757 | input UnitAbsyn.InstStore inStore; | ||
| 758 | input DAE.Mod inMod; | ||
| 759 | input DAE.Prefix inPrefix; | ||
| 760 | input ClassInf.State inState; | ||
| 761 | input SCode.Element inClass; | ||
| 762 | input SCode.Visibility inVisibility; | ||
| 763 | input list<list<DAE.Dimension>> inInstDims; | ||
| 764 | input Boolean implicitInstantiation; | ||
| 765 | input InstTypes.CallingScope inCallingScope; | ||
| 766 | input ConnectionGraph.ConnectionGraph inGraph; | ||
| 767 | input Connect.Sets inSets; | ||
| 768 | input Option<DAE.ComponentRef> instSingleCref; | ||
| 769 | output FCore.Cache outCache; | ||
| 770 | output FCore.Graph outEnv; | ||
| 771 | output InnerOuter.InstHierarchy outIH; | ||
| 772 | output UnitAbsyn.InstStore outStore; | ||
| 773 | output DAE.DAElist outDae; | ||
| 774 | output Connect.Sets outSets; | ||
| 775 | output ClassInf.State outState; | ||
| 776 | output list<DAE.Var> outVars; | ||
| 777 | output Option<DAE.Type> outType; | ||
| 778 | output Option<SCode.Attributes> optDerAttr; | ||
| 779 | output DAE.EqualityConstraint outEqualityConstraint; | ||
| 780 | output ConnectionGraph.ConnectionGraph outGraph; | ||
| 781 | algorithm | ||
| 782 | (outCache,outEnv,outIH,outStore,outDae,outSets,outState,outVars,outType,optDerAttr,outEqualityConstraint,outGraph):= | ||
| 783 | matchcontinue inClass | ||
| 784 | local | ||
| 785 | Option<DAE.Type> bc; | ||
| 786 | FCore.Graph env; | ||
| 787 | ClassInf.State ci_state; | ||
| 788 | SCode.Element c; | ||
| 789 | SCode.Restriction r; | ||
| 790 | String n; | ||
| 791 | DAE.DAElist dae; | ||
| 792 | Connect.Sets csets; | ||
| 793 | list<DAE.Var> tys; | ||
| 794 | FCore.Cache cache; | ||
| 795 | Option<SCode.Attributes> oDA; | ||
| 796 | DAE.EqualityConstraint equalityConstraint; | ||
| 797 | ConnectionGraph.ConnectionGraph graph; | ||
| 798 | InstanceHierarchy ih; | ||
| 799 | String s1, s2; | ||
| 800 | UnitAbsyn.InstStore store; | ||
| 801 | Absyn.InnerOuter io; | ||
| 802 | SourceInfo info; | ||
| 803 | SCode.Encapsulated encflag; | ||
| 804 | |||
| 805 | // if the class is no outer: regular, or inner | ||
| 806 | case SCode.CLASS(prefixes = SCode.PREFIXES(innerOuter = io)) | ||
| 807 | algorithm | ||
| 808 |
1/4✗ Branch 1 not taken.
✓ Branch 2 taken 1240469 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
1240469 | true := boolOr(AbsynUtil.isNotInnerOuter(io), AbsynUtil.isOnlyInner(io)); |
| 809 | 1240469 | (cache,env,ih,store,ci_state,graph,csets,dae,tys,bc,oDA,equalityConstraint) := | |
| 810 | instClassIn2(inCache,inEnv,inIH,inStore,inMod,inPrefix,inState,inClass,inVisibility,inInstDims,implicitInstantiation,inCallingScope,inGraph,inSets,instSingleCref); | ||
| 811 | 1215566 | then | |
| 812 | (cache,env,ih,store,dae,csets,ci_state,tys,bc,oDA,equalityConstraint,graph); | ||
| 813 | |||
| 814 | // if the class is inner or innerouter and an instance, use the original name and original scope | ||
| 815 | case SCode.CLASS(name = n, restriction=r, encapsulatedPrefix = encflag, prefixes = SCode.PREFIXES(innerOuter = io)) | ||
| 816 | algorithm | ||
| 817 |
2/4✓ Branch 1 taken 24903 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 24903 times.
✗ Branch 5 not taken.
|
24903 | true := boolOr(AbsynUtil.isInnerOuter(io), AbsynUtil.isOnlyOuter(io)); |
| 818 | ✗ | FCore.CL(status = FCore.CLS_INSTANCE(n)) := FNode.refData(FGraph.lastScopeRef(inEnv)); | |
| 819 | ✗ | (env, _) := FGraph.stripLastScopeRef(inEnv); | |
| 820 | |||
| 821 | ✗ | env := FGraph.openScope(env, encflag, n, FGraph.restrictionToScopeType(r)); | |
| 822 | ✗ | ci_state := ClassInfUtil.start(r,FGraph.getGraphName(env)); | |
| 823 | |||
| 824 | // lookup in IH | ||
| 825 | ✗ | InnerOuter.INST_INNER(innerElement = SOME(c)) := | |
| 826 | InnerOuter.lookupInnerVar(inCache, env, inIH, inPrefix, n, io); | ||
| 827 | |||
| 828 | ✗ | (cache,env,ih,store,ci_state,graph,csets,dae,tys,bc,oDA,equalityConstraint) := | |
| 829 | instClassIn2(inCache,env,inIH,inStore,inMod,inPrefix,ci_state,c,inVisibility,inInstDims,implicitInstantiation,inCallingScope,inGraph,inSets,instSingleCref); | ||
| 830 | ✗ | then | |
| 831 | (cache,env,ih,store,dae,csets,ci_state,tys,bc,oDA,equalityConstraint,graph); | ||
| 832 | |||
| 833 | // if the class is inner or innerouter we need to instantiate the inner! | ||
| 834 | case SCode.CLASS(name = n, prefixes = SCode.PREFIXES(innerOuter = io)) | ||
| 835 | algorithm | ||
| 836 |
2/4✓ Branch 1 taken 24903 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 24903 times.
✗ Branch 5 not taken.
|
24903 | true := boolOr(AbsynUtil.isInnerOuter(io), AbsynUtil.isOnlyOuter(io)); |
| 837 | ✗ | n := FGraph.getInstanceOriginalName(inEnv, n); | |
| 838 | |||
| 839 | // lookup in IH | ||
| 840 | ✗ | InnerOuter.INST_INNER(innerElement = SOME(c)) := | |
| 841 | InnerOuter.lookupInnerVar(inCache, inEnv, inIH, inPrefix, n, io); | ||
| 842 | |||
| 843 | ✗ | (cache,env,ih,store,ci_state,graph,csets,dae,tys,bc,oDA,equalityConstraint) := | |
| 844 | instClassIn2(inCache,inEnv,inIH,inStore,inMod,inPrefix,inState,c,inVisibility,inInstDims,implicitInstantiation,inCallingScope,inGraph,inSets,instSingleCref); | ||
| 845 | ✗ | then | |
| 846 | (cache,env,ih,store,dae,csets,ci_state,tys,bc,oDA,equalityConstraint,graph); | ||
| 847 | |||
| 848 | // we could not find the inner, use the outer as it is! | ||
| 849 | case SCode.CLASS(name = n, prefixes = SCode.PREFIXES(innerOuter = io), info = info) | ||
| 850 | algorithm | ||
| 851 |
2/4✓ Branch 1 taken 24903 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 24903 times.
✗ Branch 5 not taken.
|
24903 | true := boolOr(AbsynUtil.isInnerOuter(io), AbsynUtil.isOnlyOuter(io)); |
| 852 | |||
| 853 | ✗ | if not Config.getGraphicsExpMode() then | |
| 854 | s1 := n; | ||
| 855 | ✗ | s2 := AbsynUtil.innerOuterStr(io); | |
| 856 | ✗ | Error.addSourceMessage(Error.MISSING_INNER_CLASS,{s1, s2, ""}, info); | |
| 857 | end if; | ||
| 858 | |||
| 859 | ✗ | (cache,env,ih,store,ci_state,graph,csets,dae,tys,bc,oDA,equalityConstraint) := | |
| 860 | instClassIn2(inCache,inEnv,inIH,inStore,inMod,inPrefix,inState,inClass,inVisibility,inInstDims,implicitInstantiation,inCallingScope,inGraph,inSets,instSingleCref); | ||
| 861 | ✗ | then | |
| 862 | (cache,env,ih,store,dae,csets,ci_state,tys,bc,oDA,equalityConstraint,graph); | ||
| 863 | |||
| 864 | end matchcontinue; | ||
| 865 | end instClassIn; | ||
| 866 | |||
| 867 | public function instClassIn2 | ||
| 868 | "This rule instantiates the contents of a class definition, with a new | ||
| 869 | environment already setup. | ||
| 870 | The *implicitInstantiation* boolean indicates if the class should be | ||
| 871 | instantiated implicit, i.e. without generating DAE. | ||
| 872 | The last option is a even stronger indication of implicit instantiation, | ||
| 873 | used when looking up variables in packages. This must be used because | ||
| 874 | generation of functions in implicit instanitation (according to | ||
| 875 | *implicitInstantiation* boolean) can cause circular dependencies | ||
| 876 | (e.g. if a function uses a constant in its body)" | ||
| 877 | input output FCore.Cache cache; | ||
| 878 | input output FCore.Graph env; | ||
| 879 | input output InnerOuter.InstHierarchy ih; | ||
| 880 | input output UnitAbsyn.InstStore store; | ||
| 881 | input DAE.Mod mod; | ||
| 882 | input DAE.Prefix prefix; | ||
| 883 | input output ClassInf.State state; | ||
| 884 | input SCode.Element cls; | ||
| 885 | input SCode.Visibility visibility; | ||
| 886 | input list<list<DAE.Dimension>> instDims; | ||
| 887 | input Boolean implicitInst; | ||
| 888 | input InstTypes.CallingScope callingScope; | ||
| 889 | input output ConnectionGraph.ConnectionGraph graph; | ||
| 890 | input output Connect.Sets sets; | ||
| 891 | input Option<DAE.ComponentRef> instSingleCref; | ||
| 892 | output DAE.DAElist dae; | ||
| 893 | output list<DAE.Var> vars; | ||
| 894 | output Option<DAE.Type> ty; | ||
| 895 | output Option<SCode.Attributes> optDerAttr; | ||
| 896 | output DAE.EqualityConstraint equalityConstraint; | ||
| 897 | protected | ||
| 898 | Absyn.Path cache_path; | ||
| 899 | InstHashTable.CachedInstItemInputs inputs; | ||
| 900 | InstHashTable.CachedInstItemOutputs outputs; | ||
| 901 | DAE.Mod m; | ||
| 902 | DAE.Prefix pre; | ||
| 903 | Connect.Sets csets; | ||
| 904 | ClassInf.State st; | ||
| 905 | SCode.Element e; | ||
| 906 | InstDims dims; | ||
| 907 | Boolean impl; | ||
| 908 | Option<DAE.ComponentRef> scr; | ||
| 909 | InstTypes.CallingScope cs; | ||
| 910 | ConnectionGraph.ConnectionGraph cached_graph; | ||
| 911 | algorithm | ||
| 912 | // Packages derived from partial packages should do partialInstClass, since it | ||
| 913 | // filters out a lot of things. | ||
| 914 |
3/4✓ Branch 1 taken 76325 times.
✓ Branch 2 taken 1164144 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 76325 times.
|
1240469 | if SCodeUtil.isPackage(cls) and SCodeUtil.isPartial(cls) then |
| 915 | ✗ | (cache, env, ih, state) := partialInstClassIn(cache, env, ih, mod, prefix, | |
| 916 | state, cls, visibility, instDims, 0); | ||
| 917 | ✗ | dae := DAE.emptyDae; | |
| 918 | ✗ | vars := {}; | |
| 919 | ✗ | ty := NONE(); | |
| 920 | ✗ | optDerAttr := NONE(); | |
| 921 | ✗ | equalityConstraint := NONE(); | |
| 922 | ✗ | return; | |
| 923 | end if; | ||
| 924 | |||
| 925 | 1240469 | cache_path := generateCachePath(env, cls, prefix, callingScope); | |
| 926 | |||
| 927 | // See if we have it in the cache. | ||
| 928 |
1/2✓ Branch 1 taken 1240469 times.
✗ Branch 2 not taken.
|
1240469 | if Flags.isSet(Flags.CACHE) then |
| 929 | try | ||
| 930 |
7/12✗ Branch 1 not taken.
✓ Branch 2 taken 935511 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 935511 times.
✓ Branch 5 taken 501 times.
✓ Branch 6 taken 935010 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 935010 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 935010 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 935010 times.
|
1240469 | {SOME(InstHashTable.FUNC_instClassIn(inputs, outputs)), _} := InstHashTable.get(cache_path); |
| 931 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 935010 times.
|
935010 | (m, pre, csets, st, e as SCode.CLASS(), dims, impl, scr, cs) := inputs; |
| 932 | |||
| 933 | // Are the important inputs the same? | ||
| 934 | 935010 | InstUtil.prefixEqualUnlessBasicType(prefix, pre, cls); | |
| 935 |
13/16✓ Branch 1 taken 686117 times.
✓ Branch 2 taken 153865 times.
✓ Branch 3 taken 672974 times.
✓ Branch 4 taken 13143 times.
✓ Branch 6 taken 464216 times.
✓ Branch 7 taken 208758 times.
✓ Branch 9 taken 414208 times.
✓ Branch 10 taken 50008 times.
✓ Branch 12 taken 414208 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 412103 times.
✓ Branch 16 taken 2105 times.
✓ Branch 18 taken 412103 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 412103 times.
✗ Branch 22 not taken.
|
839982 | if (valueEq(dims,instDims) and (impl==implicitInst) and valueEq(m, mod) and valueEq(csets, sets) and valueEq(st, state) and valueEq(e, cls) and valueEq(scr, instSingleCref) and callingScopeCacheEq(cs, callingScope)) then |
| 936 | 412103 | (env, dae, sets, state, vars, ty, optDerAttr, equalityConstraint, cached_graph) := outputs; | |
| 937 | 412103 | graph := ConnectionGraph.merge(graph, cached_graph); | |
| 938 | 412103 | showCacheInfo("Full Inst Hit: ", cache_path); | |
| 939 | 412103 | return; | |
| 940 | end if; | ||
| 941 | else | ||
| 942 | // Not found in cache, continue. | ||
| 943 | end try; | ||
| 944 | end if; | ||
| 945 | |||
| 946 | // If not found in the cache, instantiate the class and add it to the cache. | ||
| 947 | try | ||
| 948 |
2/2✓ Branch 0 taken 490903 times.
✓ Branch 1 taken 337463 times.
|
1319269 | inputs := (mod, prefix, sets, state, cls, instDims, implicitInst, instSingleCref, callingScope); |
| 949 | |||
| 950 | 828366 | (cache, env, ih, store, dae, sets, state, vars, ty, optDerAttr, equalityConstraint, graph) := | |
| 951 | instClassIn_dispatch(cache, env, ih, store, mod, prefix, state, cls, | ||
| 952 | visibility, instDims, implicitInst, callingScope, graph, sets, instSingleCref); | ||
| 953 | |||
| 954 | 803463 | outputs := (env, dae, sets, state, vars, ty, optDerAttr, equalityConstraint, graph); | |
| 955 | |||
| 956 | 803463 | showCacheInfo("Full Inst Add: ", cache_path); | |
| 957 | 1606926 | InstHashTable.addToInstCache(cache_path, SOME(InstHashTable.FUNC_instClassIn(inputs, outputs)), NONE()); | |
| 958 | else | ||
| 959 |
2/2✓ Branch 1 taken 24889 times.
✓ Branch 2 taken 14 times.
|
24903 | true := Flags.isSet(Flags.FAILTRACE); |
| 960 | 14 | Debug.traceln("- Inst.instClassIn2 failed on class: " + SCodeUtil.elementName(cls) + | |
| 961 | " in environment: " + FGraph.printGraphPathStr(env)); | ||
| 962 | 14 | fail(); | |
| 963 | end try; | ||
| 964 | end instClassIn2; | ||
| 965 | |||
| 966 | |||
| 967 | protected function markDerivedRecordOutsideBindings | ||
| 968 | input DAE.Type inType; | ||
| 969 | input SCode.Element inClass; | ||
| 970 | output DAE.Type outType; | ||
| 971 | protected | ||
| 972 | SCode.Mod derMod; | ||
| 973 | list<SCode.SubMod> submods; | ||
| 974 | algorithm | ||
| 975 | |||
| 976 |
4/4✓ Branch 1 taken 17841 times.
✓ Branch 2 taken 881052 times.
✓ Branch 4 taken 16853 times.
✓ Branch 5 taken 988 times.
|
898893 | if not SCodeUtil.isRecord(inClass) |
| 977 | or not SCodeUtil.isDerivedClass(inClass) then | ||
| 978 | outType := inType; | ||
| 979 | 897905 | return; | |
| 980 | end if; | ||
| 981 | |||
| 982 | 988 | derMod := SCodeUtil.getDerivedMod(inClass); | |
| 983 |
2/2✓ Branch 1 taken 980 times.
✓ Branch 2 taken 8 times.
|
988 | if SCodeUtil.isEmptyMod(derMod) then |
| 984 | outType := inType; | ||
| 985 | 980 | return; | |
| 986 | end if; | ||
| 987 | |||
| 988 | try | ||
| 989 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | SCode.MOD(subModLst = submods) := derMod; |
| 990 | else | ||
| 991 | ✗ | Error.addMessage(Error.INTERNAL_ERROR, {"Unexpected Mod structure in collectAndFixDerivedComplexOutsideBindings."}); | |
| 992 | ✗ | fail(); | |
| 993 | end try; | ||
| 994 | |||
| 995 | outType := match inType | ||
| 996 | local | ||
| 997 | list<DAE.Var> tvars; | ||
| 998 | |||
| 999 | case DAE.T_COMPLEX() algorithm | ||
| 1000 | tvars := {}; | ||
| 1001 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 8 times.
|
32 | for var in inType.varLst loop |
| 1002 | |||
| 1003 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 4 times.
|
52 | for submod in submods loop |
| 1004 |
2/2✓ Branch 1 taken 20 times.
✓ Branch 2 taken 28 times.
|
48 | if varIsModifiedInDerivedMod(var.name, submod) then |
| 1005 | 20 | var.bind_from_outside := true; | |
| 1006 | 20 | var.binding := markBindingFromDerivedRecordMods(var.binding); | |
| 1007 | 20 | break; | |
| 1008 | end if; | ||
| 1009 | end for; | ||
| 1010 | |||
| 1011 | tvars := var::tvars; | ||
| 1012 | end for; | ||
| 1013 | 8 | tvars := listReverse(tvars); | |
| 1014 | |||
| 1015 | 8 | then DAE.T_COMPLEX(inType.complexClassType, tvars, inType.equalityConstraint, inType.usedExternally); | |
| 1016 | end match; | ||
| 1017 | |||
| 1018 | end markDerivedRecordOutsideBindings; | ||
| 1019 | |||
| 1020 | function markBindingFromDerivedRecordMods | ||
| 1021 | input output DAE.Binding bind; | ||
| 1022 | algorithm | ||
| 1023 | () := match bind | ||
| 1024 | case DAE.EQBOUND() algorithm | ||
| 1025 | 20 | bind.source := DAE.BINDING_FROM_DERIVED_RECORD_DECL(); | |
| 1026 | then (); | ||
| 1027 | |||
| 1028 | else (); | ||
| 1029 | end match; | ||
| 1030 | end markBindingFromDerivedRecordMods; | ||
| 1031 | |||
| 1032 | function varIsModifiedInDerivedMod | ||
| 1033 | input String inName; | ||
| 1034 | input SCode.SubMod inSubmod; | ||
| 1035 | output Boolean b; | ||
| 1036 | algorithm | ||
| 1037 | b := match inSubmod | ||
| 1038 | case SCode.NAMEMOD(mod=SCode.REDECL()) then false; | ||
| 1039 |
4/4✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 20 times.
|
48 | case SCode.NAMEMOD() then stringEqual(inSubmod.ident, inName); |
| 1040 | end match; | ||
| 1041 | end varIsModifiedInDerivedMod; | ||
| 1042 | |||
| 1043 | protected function markTypesVarsOutsideBindings | ||
| 1044 | input DAE.Type inType; | ||
| 1045 | input DAE.Mod inMod; | ||
| 1046 | output DAE.Type outType = inType; | ||
| 1047 | protected | ||
| 1048 | list<DAE.SubMod> submods; | ||
| 1049 | algorithm | ||
| 1050 | |||
| 1051 |
2/2✓ Branch 1 taken 881052 times.
✓ Branch 2 taken 17841 times.
|
898893 | if not Types.isRecord(inType) then |
| 1052 | 881052 | return; | |
| 1053 | end if; | ||
| 1054 | |||
| 1055 | try | ||
| 1056 |
4/4✓ Branch 0 taken 9698 times.
✓ Branch 1 taken 8143 times.
✓ Branch 2 taken 3105 times.
✓ Branch 3 taken 5038 times.
|
17841 | DAE.MOD(subModLst = submods) := inMod; |
| 1057 | else | ||
| 1058 | 9698 | return; | |
| 1059 | end try; | ||
| 1060 | |||
| 1061 |
2/2✓ Branch 0 taken 3105 times.
✓ Branch 1 taken 5038 times.
|
8143 | if listEmpty(submods) then |
| 1062 | 3105 | return; | |
| 1063 | end if; | ||
| 1064 | |||
| 1065 | |||
| 1066 | outType := match inType | ||
| 1067 | local | ||
| 1068 | list<DAE.Var> tvars; | ||
| 1069 | |||
| 1070 | case DAE.T_COMPLEX() algorithm | ||
| 1071 | tvars := {}; | ||
| 1072 |
2/2✓ Branch 0 taken 50780 times.
✓ Branch 1 taken 5038 times.
|
55818 | for var in inType.varLst loop |
| 1073 | |||
| 1074 |
2/2✓ Branch 0 taken 284315 times.
✓ Branch 1 taken 408 times.
|
284723 | for submod in submods loop |
| 1075 |
2/2✓ Branch 1 taken 50372 times.
✓ Branch 2 taken 233943 times.
|
284315 | if varIsModifiedInMod(var.name, submod) then |
| 1076 | 50372 | var.bind_from_outside := true; | |
| 1077 | 50372 | break; | |
| 1078 | end if; | ||
| 1079 | end for; | ||
| 1080 | |||
| 1081 | tvars := var::tvars; | ||
| 1082 | end for; | ||
| 1083 | 5038 | tvars := listReverse(tvars); | |
| 1084 | |||
| 1085 | 5038 | then DAE.T_COMPLEX(inType.complexClassType, tvars, inType.equalityConstraint, inType.usedExternally); | |
| 1086 | end match; | ||
| 1087 | |||
| 1088 | end markTypesVarsOutsideBindings; | ||
| 1089 | |||
| 1090 | function varIsModifiedInMod | ||
| 1091 | input String inName; | ||
| 1092 | input DAE.SubMod inSubmod; | ||
| 1093 | output Boolean b; | ||
| 1094 | algorithm | ||
| 1095 | b := match inSubmod | ||
| 1096 |
4/4✓ Branch 0 taken 85634 times.
✓ Branch 1 taken 198681 times.
✓ Branch 3 taken 35262 times.
✓ Branch 4 taken 50372 times.
|
284315 | case DAE.NAMEMOD() then stringEqual(inSubmod.ident, inName); |
| 1097 | end match; | ||
| 1098 | end varIsModifiedInMod; | ||
| 1099 | |||
| 1100 | |||
| 1101 | protected function callingScopeCacheEq | ||
| 1102 | input InstTypes.CallingScope inCallingScope1; | ||
| 1103 | input InstTypes.CallingScope inCallingScope2; | ||
| 1104 | output Boolean outIsEq; | ||
| 1105 | algorithm | ||
| 1106 | outIsEq := match(inCallingScope1, inCallingScope2) | ||
| 1107 | case (InstTypes.TYPE_CALL(), InstTypes.TYPE_CALL()) then true; | ||
| 1108 | case (InstTypes.TYPE_CALL(), _) then false; | ||
| 1109 | case (_, InstTypes.TYPE_CALL()) then false; | ||
| 1110 | else true; | ||
| 1111 | end match; | ||
| 1112 | end callingScopeCacheEq; | ||
| 1113 | |||
| 1114 | public function instClassIn_dispatch | ||
| 1115 | "This rule instantiates the contents of a class definition, with a new | ||
| 1116 | environment already setup. | ||
| 1117 | The *implicitInstantiation* boolean indicates if the class should be | ||
| 1118 | instantiated implicit, i.e. without generating DAE. | ||
| 1119 | The last option is a even stronger indication of implicit instantiation, | ||
| 1120 | used when looking up variables in packages. This must be used because | ||
| 1121 | generation of functions in implicit instanitation (according to | ||
| 1122 | *implicitInstantiation* boolean) can cause circular dependencies | ||
| 1123 | (e.g. if a function uses a constant in its body)" | ||
| 1124 | input FCore.Cache inCache; | ||
| 1125 | input FCore.Graph inEnv; | ||
| 1126 | input InnerOuter.InstHierarchy inIH; | ||
| 1127 | input UnitAbsyn.InstStore inStore; | ||
| 1128 | input DAE.Mod inMod; | ||
| 1129 | input DAE.Prefix inPrefix; | ||
| 1130 | input ClassInf.State inState; | ||
| 1131 | input SCode.Element inClass; | ||
| 1132 | input SCode.Visibility inVisibility; | ||
| 1133 | input list<list<DAE.Dimension>> inInstDims; | ||
| 1134 | input Boolean implicitInstantiation; | ||
| 1135 | input InstTypes.CallingScope inCallingScope; | ||
| 1136 | input ConnectionGraph.ConnectionGraph inGraph; | ||
| 1137 | input Connect.Sets inSets; | ||
| 1138 | input Option<DAE.ComponentRef> instSingleCref; | ||
| 1139 | output FCore.Cache outCache; | ||
| 1140 | output FCore.Graph outEnv; | ||
| 1141 | output InnerOuter.InstHierarchy outIH; | ||
| 1142 | output UnitAbsyn.InstStore outStore; | ||
| 1143 | output DAE.DAElist outDae; | ||
| 1144 | output Connect.Sets outSets; | ||
| 1145 | output ClassInf.State outState; | ||
| 1146 | output list<DAE.Var> outTypesVarLst; | ||
| 1147 | output Option<DAE.Type> outTypesTypeOption; | ||
| 1148 | output Option<SCode.Attributes> optDerAttr; | ||
| 1149 | output DAE.EqualityConstraint outEqualityConstraint; | ||
| 1150 | output ConnectionGraph.ConnectionGraph outGraph; | ||
| 1151 | algorithm | ||
| 1152 | (outCache,outEnv,outIH,outStore,outDae,outSets,outState,outTypesVarLst,outTypesTypeOption,optDerAttr,outEqualityConstraint,outGraph):= | ||
| 1153 | matchcontinue (inCache, inEnv, inIH, inStore, inMod, inPrefix, inState, inClass, inVisibility, inInstDims, implicitInstantiation, inCallingScope, inGraph) | ||
| 1154 | local | ||
| 1155 | Option<DAE.Type> bc; | ||
| 1156 | FCore.Graph env,env_1; | ||
| 1157 | DAE.Mod mods; | ||
| 1158 | DAE.Prefix pre; | ||
| 1159 | ClassInf.State ci_state,ci_state_1; | ||
| 1160 | SCode.Element c; | ||
| 1161 | InstDims inst_dims; | ||
| 1162 | Boolean impl; | ||
| 1163 | SCode.Visibility vis; | ||
| 1164 | String n; | ||
| 1165 | Connect.Sets csets; | ||
| 1166 | list<DAE.Var> tys; | ||
| 1167 | SCode.Restriction r; | ||
| 1168 | SCode.ClassDef d; | ||
| 1169 | FCore.Cache cache; | ||
| 1170 | Option<SCode.Attributes> oDA; | ||
| 1171 | InstTypes.CallingScope callscope; | ||
| 1172 | ConnectionGraph.ConnectionGraph graph; | ||
| 1173 | InstanceHierarchy ih; | ||
| 1174 | DAE.DAElist dae; | ||
| 1175 | SourceInfo info; | ||
| 1176 | FCore.Graph env_2, env_3; | ||
| 1177 | list<SCode.Element> els; | ||
| 1178 | list<tuple<SCode.Element, DAE.Mod>> comp; | ||
| 1179 | list<String> names; | ||
| 1180 | DAE.EqualityConstraint eqConstraint; | ||
| 1181 | DAE.Type ty, ty2; | ||
| 1182 | Absyn.Path fq_class; | ||
| 1183 | list<DAE.Var> tys1,tys2; | ||
| 1184 | SCode.Partial partialPrefix; | ||
| 1185 | SCode.Encapsulated encapsulatedPrefix; | ||
| 1186 | UnitAbsyn.InstStore store; | ||
| 1187 | Boolean b; | ||
| 1188 | BasicTypeAttrTyper typer; | ||
| 1189 | SCode.Comment comment; | ||
| 1190 | |||
| 1191 | // Builtin type (Real, Integer, etc.). | ||
| 1192 | case (cache, env, ih, store, mods, pre, ci_state, SCode.CLASS(name = n), _, inst_dims, _, _, graph) | ||
| 1193 | algorithm | ||
| 1194 | 828366 | ty := getBasicTypeType(n); | |
| 1195 | 455580 | typer := getBasicTypeAttrTyper(n); | |
| 1196 | 455580 | ty := liftNonExpType(ty, inst_dims, Config.splitArrays()); | |
| 1197 | 455580 | tys := instBasicTypeAttributes(cache, env, mods, ty, typer, pre); | |
| 1198 | 455555 | ty := Types.setTypeVars(ty, tys); | |
| 1199 | 455555 | bc := arrayBasictypeBaseclass(inst_dims, ty); | |
| 1200 | 455555 | then | |
| 1201 | (cache, env, ih, store, DAE.emptyDae, inSets, ci_state, tys, bc, NONE(), NONE(), graph); | ||
| 1202 | |||
| 1203 | // adrpo: 2010-09-27: here we do two things at once, but not correctly! | ||
| 1204 | // Instantiate enumeration class at top level DAE.NOPRE() | ||
| 1205 | // when we are instantiating with no prefix, it means we are instantiating the enumeration class! | ||
| 1206 | // and we don't care about modifications! | ||
| 1207 | // Instantiate enumeration VARIABLE with a prefix! | ||
| 1208 | // when we are instantiating with a prefix, it means we are instantiating a variable of an enumeration type! | ||
| 1209 | // and we care about modifications! | ||
| 1210 | // this does not work! | ||
| 1211 | // T = enumeration(x, y, z); | ||
| 1212 | // T c(start = T.x) should generate an enumeration variable with and the type should contain the | ||
| 1213 | // start value, but we have no place to put it as the var list in the T_ENUMERATION is for names! | ||
| 1214 | case (cache, env, ih, store, mods, pre, ci_state, (c as SCode.CLASS(name = n,restriction = SCode.R_ENUMERATION(),classDef = | ||
| 1215 | SCode.PARTS(elementLst = els),info = info)), _, inst_dims, impl, callscope, graph) | ||
| 1216 | algorithm | ||
| 1217 | 4390 | names := SCodeUtil.componentNames(c); | |
| 1218 | 4390 | Types.checkEnumDuplicateLiterals(names, info); | |
| 1219 | |||
| 1220 | 4390 | tys := instBasicTypeAttributes(cache, env, mods, | |
| 1221 | DAE.T_ENUMERATION_DEFAULT, getEnumAttributeType, pre); | ||
| 1222 | /* uncomment this and see how checkAllModelsRecursive(Modelica.Electrical.Digital) looks like | ||
| 1223 | especially MUX.Or1.auxiliary doesn't get its start/fixed bindings | ||
| 1224 | print("Inst enumeration class (empty prefix) / variable (some pre): " + n + | ||
| 1225 | "\npre: " + PrefixUtil.printPrefixStr(pre) + | ||
| 1226 | "\nenv: " + FGraph.printGraphPathStr(env) + | ||
| 1227 | "\nmods: " + Mod.printModStr(mods) + | ||
| 1228 | "\ninst_dims: [" + stringDelimitList(List.map1(inst_dims, DAEDump.unparseDimensions, true), ", ") + "]" + "\n"); | ||
| 1229 | */ | ||
| 1230 | 4390 | ci_state_1 := ClassInfUtil.trans(ci_state, ClassInf.NEWDEF()); | |
| 1231 | 4390 | comp := InstUtil.addNomod(els); | |
| 1232 | 4390 | (cache,env_1,ih) := InstUtil.addComponentsToEnv(cache,env,ih, mods, pre, ci_state_1, comp, impl); | |
| 1233 | |||
| 1234 | // we should instantiate with no modifications, they don't belong to the class, they belong to the component! | ||
| 1235 | 4390 | (cache,env_2,ih,store,_,csets,ci_state_1,tys1,graph,_) := | |
| 1236 | instElementList(cache,env_1,ih,store, /* DAE.NOMOD() */ mods, pre, | ||
| 1237 | ci_state_1, comp, inst_dims, impl,callscope,graph, inSets, true); | ||
| 1238 | |||
| 1239 | 4390 | (cache,fq_class) := makeFullyQualifiedIdent(cache,env_2, n); | |
| 1240 | 4390 | eqConstraint := InstUtil.equalityConstraint(env_2, els, info); | |
| 1241 | // DAEUtil.addComponentType(dae1, fq_class); | ||
| 1242 | 4390 | ty2 := DAE.T_ENUMERATION(NONE(), fq_class, names, tys1, tys); | |
| 1243 | 4390 | bc := arrayBasictypeBaseclass(inst_dims, ty2); | |
| 1244 |
3/4✗ Branch 0 not taken.
✓ Branch 1 taken 4390 times.
✓ Branch 2 taken 2197 times.
✓ Branch 3 taken 2193 times.
|
4390 | bc := if isSome(bc) then bc else SOME(ty2); |
| 1245 | 4390 | ty := InstUtil.mktype(fq_class, ci_state_1, tys1, bc, eqConstraint, c, SCode.noComment); | |
| 1246 | // update Enumerationtypes in environment | ||
| 1247 | 4390 | (cache,env_3) := InstUtil.updateEnumerationEnvironment(cache,env_2,ty,c,ci_state_1); | |
| 1248 | 4390 | tys2 := listAppend(tys, tys1); // <--- this is wrong as the tys belong to the component variable not the Enumeration Class! | |
| 1249 | 4390 | then | |
| 1250 | (cache,env_3,ih,store,DAE.emptyDae,csets,ci_state_1,tys2,bc /* NONE() */,NONE(),NONE(),graph); | ||
| 1251 | |||
| 1252 | // Instantiate a class definition made of parts | ||
| 1253 | case (cache, env, ih, store, mods, pre, ci_state, c as SCode.CLASS(name = n,restriction = r,classDef = d, cmt = comment, info=info, partialPrefix = partialPrefix,encapsulatedPrefix = encapsulatedPrefix), vis, inst_dims, impl, callscope, graph) | ||
| 1254 | algorithm | ||
| 1255 | 368421 | ErrorExt.setCheckpoint("instClassParts"); | |
| 1256 |
2/2✓ Branch 1 taken 25 times.
✓ Branch 2 taken 368396 times.
|
368421 | false := InstUtil.isBuiltInClass(n) "If failed above, no need to try again"; |
| 1257 | () := match r | ||
| 1258 | ✗ | case SCode.R_ENUMERATION() then fail(); | |
| 1259 | else (); | ||
| 1260 | end match; | ||
| 1261 | // fprint(Flags.INSTTR, "ICLASS ["); | ||
| 1262 | // _ = if_(impl, "impl] ", "expl] "); | ||
| 1263 | // fprint(Flags.INSTTR, implstr); | ||
| 1264 | // fprintln(Flags.INSTTR, FGraph.printGraphPathStr(env) + "." + n + " mods: " + Mod.printModStr(mods)); | ||
| 1265 | // t1 = clock(); | ||
| 1266 | 368396 | (cache,env_1,ih,store,dae,csets,ci_state_1,tys,bc,oDA,eqConstraint,graph) := | |
| 1267 | instClassdef(cache, env, ih, store, mods, pre, ci_state, n, d, r, vis, | ||
| 1268 | partialPrefix, encapsulatedPrefix, inst_dims, impl, callscope, | ||
| 1269 | graph, inSets, instSingleCref, comment, info); | ||
| 1270 | // t2 = clock(); | ||
| 1271 | // time = t2 -. t1; | ||
| 1272 | // b=realGt(time,0.05); | ||
| 1273 | // s = realString(time); | ||
| 1274 | // fprintln(Flags.INSTTR, " -> ICLASS " + n + " inst time: " + s + " in env: " + FGraph.printGraphPathStr(env) + " mods: " + Mod.printModStr(mods)); | ||
| 1275 |
4/4✓ Branch 1 taken 29501 times.
✓ Branch 2 taken 314017 times.
✓ Branch 3 taken 29475 times.
✓ Branch 4 taken 26 times.
|
343518 | dae := if SCodeUtil.isFunction(c) and not impl then DAE.DAE({}) else dae; |
| 1276 | 343518 | ErrorExt.delCheckpoint("instClassParts"); | |
| 1277 | 343518 | then | |
| 1278 | (cache,env_1,ih,store,dae,csets,ci_state_1,tys,bc,oDA,eqConstraint,graph); | ||
| 1279 | |||
| 1280 | /* Ignore functions if not implicit instantiation, and doing checkModel - some dimensions might not be complete... */ | ||
| 1281 | case (cache, env, ih, store, _, _, ci_state, c as SCode.CLASS(), _, _, impl, _, graph) | ||
| 1282 | algorithm | ||
| 1283 |
5/6✓ Branch 1 taken 105 times.
✓ Branch 2 taken 24798 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 96 times.
✓ Branch 6 taken 9 times.
✗ Branch 7 not taken.
|
24903 | b := Flags.getConfigBool(Flags.CHECK_MODEL) and (not impl) and SCodeUtil.isFunction(c); |
| 1284 | if not b then | ||
| 1285 | 24903 | ErrorExt.delCheckpoint("instClassParts"); | |
| 1286 | 24903 | fail(); | |
| 1287 | else | ||
| 1288 | ✗ | ErrorExt.rollBack("instClassParts"); | |
| 1289 | end if; | ||
| 1290 | // clsname = SCodeUtil.className(cls); | ||
| 1291 | // print("Ignore function" + clsname + "\n"); | ||
| 1292 | ✗ | then | |
| 1293 | (cache,env,ih,store,DAE.emptyDae, inSets,ci_state,{},NONE(),NONE(),NONE(),graph); | ||
| 1294 | |||
| 1295 | // failure | ||
| 1296 | else | ||
| 1297 | algorithm | ||
| 1298 | //print("instClassIn(");print(n);print(") failed\n"); | ||
| 1299 | //fprintln(Flags.FAILTRACE, "- Inst.instClassIn failed" + n); | ||
| 1300 | then | ||
| 1301 | fail(); | ||
| 1302 | end matchcontinue; | ||
| 1303 | end instClassIn_dispatch; | ||
| 1304 | |||
| 1305 | protected function liftNonExpType | ||
| 1306 | input DAE.Type inType; | ||
| 1307 | input InstDims inInstDims; | ||
| 1308 | input Boolean inSplitArrays; | ||
| 1309 | output DAE.Type outType; | ||
| 1310 | algorithm | ||
| 1311 | outType := match(inInstDims, inSplitArrays) | ||
| 1312 | local | ||
| 1313 | list<DAE.Dimension> dims; | ||
| 1314 | |||
| 1315 | case (dims :: _, false) | ||
| 1316 | ✗ | then Types.liftArrayListDims(inType, dims); | |
| 1317 | |||
| 1318 | else inType; | ||
| 1319 | |||
| 1320 | end match; | ||
| 1321 | end liftNonExpType; | ||
| 1322 | |||
| 1323 | protected function getBasicTypeType | ||
| 1324 | input String inName; | ||
| 1325 | output DAE.Type outType; | ||
| 1326 | algorithm | ||
| 1327 | outType := match inName | ||
| 1328 | case "Real" then DAE.T_REAL_DEFAULT; | ||
| 1329 | case "Integer" then DAE.T_INTEGER_DEFAULT; | ||
| 1330 | case "String" then DAE.T_STRING_DEFAULT; | ||
| 1331 | case "Boolean" then DAE.T_BOOL_DEFAULT; | ||
| 1332 | // BTH | ||
| 1333 | case "Clock" | ||
| 1334 | algorithm | ||
| 1335 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
|
26 | true := Config.synchronousFeaturesAllowed(); |
| 1336 | then DAE.T_CLOCK_DEFAULT; | ||
| 1337 | end match; | ||
| 1338 | end getBasicTypeType; | ||
| 1339 | |||
| 1340 | protected function getBasicTypeAttrTyper | ||
| 1341 | input String inName; | ||
| 1342 | output BasicTypeAttrTyper outTyper; | ||
| 1343 | algorithm | ||
| 1344 | outTyper := match inName | ||
| 1345 | case "Real" then getRealAttributeType; | ||
| 1346 | case "Integer" then getIntAttributeType; | ||
| 1347 | case "String" then getStringAttributeType; | ||
| 1348 | case "Boolean" then getBoolAttributeType; | ||
| 1349 | // BTH | ||
| 1350 | case "Clock" | ||
| 1351 | algorithm | ||
| 1352 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
|
26 | true := Config.synchronousFeaturesAllowed(); |
| 1353 | then getClockAttributeType; | ||
| 1354 | end match; | ||
| 1355 | end getBasicTypeAttrTyper; | ||
| 1356 | |||
| 1357 | protected function getRealAttributeType | ||
| 1358 | input String inAttrName; | ||
| 1359 | input DAE.Type inBaseType; | ||
| 1360 | input SourceInfo inInfo; | ||
| 1361 | output DAE.Type outType; | ||
| 1362 | algorithm | ||
| 1363 | outType := match inAttrName | ||
| 1364 | case "quantity" then DAE.T_STRING_DEFAULT; | ||
| 1365 | case "unit" then DAE.T_STRING_DEFAULT; | ||
| 1366 | case "displayUnit" then DAE.T_STRING_DEFAULT; | ||
| 1367 | case "min" then inBaseType; | ||
| 1368 | case "max" then inBaseType; | ||
| 1369 | case "start" then inBaseType; | ||
| 1370 | case "fixed" then DAE.T_BOOL_DEFAULT; | ||
| 1371 | case "nominal" then inBaseType; | ||
| 1372 | case "stateSelect" then InstBinding.stateSelectType; | ||
| 1373 | case "uncertain" then InstBinding.uncertaintyType; | ||
| 1374 | case "distribution" then InstBinding.distributionType; | ||
| 1375 | else | ||
| 1376 | algorithm | ||
| 1377 | ✗ | Error.addSourceMessage(Error.MISSING_MODIFIED_ELEMENT, | |
| 1378 | {inAttrName, "Real"}, inInfo); | ||
| 1379 | ✗ | then | |
| 1380 | fail(); | ||
| 1381 | end match; | ||
| 1382 | end getRealAttributeType; | ||
| 1383 | |||
| 1384 | protected function getIntAttributeType | ||
| 1385 | input String inAttrName; | ||
| 1386 | input DAE.Type inBaseType; | ||
| 1387 | input SourceInfo inInfo; | ||
| 1388 | output DAE.Type outType; | ||
| 1389 | algorithm | ||
| 1390 | outType := match inAttrName | ||
| 1391 | case "quantity" then DAE.T_STRING_DEFAULT; | ||
| 1392 | case "min" then inBaseType; | ||
| 1393 | case "max" then inBaseType; | ||
| 1394 | case "start" then inBaseType; | ||
| 1395 | case "fixed" then DAE.T_BOOL_DEFAULT; | ||
| 1396 | case "nominal" then inBaseType; | ||
| 1397 | case "uncertain" then InstBinding.uncertaintyType; | ||
| 1398 | case "distribution" then InstBinding.distributionType; | ||
| 1399 | else | ||
| 1400 | algorithm | ||
| 1401 | ✗ | Error.addSourceMessage(Error.MISSING_MODIFIED_ELEMENT, | |
| 1402 | {inAttrName, "Integer"}, inInfo); | ||
| 1403 | ✗ | then | |
| 1404 | fail(); | ||
| 1405 | end match; | ||
| 1406 | end getIntAttributeType; | ||
| 1407 | |||
| 1408 | protected function getStringAttributeType | ||
| 1409 | input String inAttrName; | ||
| 1410 | input DAE.Type inBaseType; | ||
| 1411 | input SourceInfo inInfo; | ||
| 1412 | output DAE.Type outType; | ||
| 1413 | algorithm | ||
| 1414 | outType := match inAttrName | ||
| 1415 | case "quantity" then DAE.T_STRING_DEFAULT; | ||
| 1416 | case "start" then inBaseType; | ||
| 1417 | else | ||
| 1418 | algorithm | ||
| 1419 | ✗ | Error.addSourceMessage(Error.MISSING_MODIFIED_ELEMENT, | |
| 1420 | {inAttrName, "String"}, inInfo); | ||
| 1421 | ✗ | then | |
| 1422 | fail(); | ||
| 1423 | end match; | ||
| 1424 | end getStringAttributeType; | ||
| 1425 | |||
| 1426 | protected function getBoolAttributeType | ||
| 1427 | input String inAttrName; | ||
| 1428 | input DAE.Type inBaseType; | ||
| 1429 | input SourceInfo inInfo; | ||
| 1430 | output DAE.Type outType; | ||
| 1431 | algorithm | ||
| 1432 | outType := match inAttrName | ||
| 1433 | case "quantity" then DAE.T_STRING_DEFAULT; | ||
| 1434 | case "start" then inBaseType; | ||
| 1435 | case "fixed" then DAE.T_BOOL_DEFAULT; | ||
| 1436 | else | ||
| 1437 | algorithm | ||
| 1438 | ✗ | Error.addSourceMessage(Error.MISSING_MODIFIED_ELEMENT, | |
| 1439 | {inAttrName, "Boolean"}, inInfo); | ||
| 1440 | ✗ | then | |
| 1441 | fail(); | ||
| 1442 | end match; | ||
| 1443 | end getBoolAttributeType; | ||
| 1444 | |||
| 1445 | |||
| 1446 | protected function getClockAttributeType " | ||
| 1447 | Author: BTH | ||
| 1448 | This function is supposed to fail since clock variables don't have attributes. | ||
| 1449 | " | ||
| 1450 | input String inAttrName; | ||
| 1451 | input DAE.Type inBaseType; | ||
| 1452 | input SourceInfo inInfo; | ||
| 1453 | output DAE.Type outType; | ||
| 1454 | algorithm | ||
| 1455 | outType := match inInfo | ||
| 1456 | case _ then fail(); | ||
| 1457 | end match; | ||
| 1458 | end getClockAttributeType; | ||
| 1459 | |||
| 1460 | |||
| 1461 | protected function getEnumAttributeType | ||
| 1462 | input String inAttrName; | ||
| 1463 | input DAE.Type inBaseType; | ||
| 1464 | input SourceInfo inInfo; | ||
| 1465 | output DAE.Type outType; | ||
| 1466 | algorithm | ||
| 1467 | outType := match inAttrName | ||
| 1468 | case "quantity" then DAE.T_STRING_DEFAULT; | ||
| 1469 | case "min" then inBaseType; | ||
| 1470 | case "max" then inBaseType; | ||
| 1471 | case "start" then inBaseType; | ||
| 1472 | case "fixed" then DAE.T_BOOL_DEFAULT; | ||
| 1473 | else | ||
| 1474 | algorithm | ||
| 1475 | ✗ | Error.addSourceMessage(Error.MISSING_MODIFIED_ELEMENT, | |
| 1476 | {inAttrName, "enumeration(:)"}, inInfo); | ||
| 1477 | ✗ | then | |
| 1478 | fail(); | ||
| 1479 | end match; | ||
| 1480 | end getEnumAttributeType; | ||
| 1481 | |||
| 1482 | protected function instBasicTypeAttributes | ||
| 1483 | input FCore.Cache inCache; | ||
| 1484 | input FCore.Graph inEnv; | ||
| 1485 | input DAE.Mod inMod; | ||
| 1486 | input DAE.Type inBaseType; | ||
| 1487 | input BasicTypeAttrTyper inTypeFunc; | ||
| 1488 | input DAE.Prefix inPrefix; | ||
| 1489 | output list<DAE.Var> outVars; | ||
| 1490 | algorithm | ||
| 1491 | outVars := match inMod | ||
| 1492 | local | ||
| 1493 | list<DAE.SubMod> submods; | ||
| 1494 | |||
| 1495 | case DAE.MOD(subModLst = submods) | ||
| 1496 | 377982 | then List.map4(submods, instBasicTypeAttributes2, inCache, inEnv, inBaseType, inTypeFunc); | |
| 1497 | |||
| 1498 | case DAE.NOMOD() then {}; | ||
| 1499 | case DAE.REDECL() then {}; | ||
| 1500 | end match; | ||
| 1501 | end instBasicTypeAttributes; | ||
| 1502 | |||
| 1503 | protected function instBasicTypeAttributes2 | ||
| 1504 | input DAE.SubMod inSubMod; | ||
| 1505 | input FCore.Cache inCache; | ||
| 1506 | input FCore.Graph inEnv; | ||
| 1507 | input DAE.Type inBaseType; | ||
| 1508 | input BasicTypeAttrTyper inTypeFunc; | ||
| 1509 | output DAE.Var outVar; | ||
| 1510 | algorithm | ||
| 1511 | outVar := match inSubMod | ||
| 1512 | local | ||
| 1513 | DAE.Ident name; | ||
| 1514 | DAE.Type ty; | ||
| 1515 | DAE.Exp exp; | ||
| 1516 | Option<Values.Value> val; | ||
| 1517 | DAE.Properties p; | ||
| 1518 | SourceInfo info; | ||
| 1519 | |||
| 1520 | case DAE.NAMEMOD(ident = name, mod = DAE.MOD(binding = SOME(DAE.TYPED( | ||
| 1521 | modifierAsExp = exp, modifierAsValue = val, properties = p)), info = info)) | ||
| 1522 | algorithm | ||
| 1523 | 416378 | ty := getRealAttributeType(name, inBaseType, info); | |
| 1524 | 416378 | then | |
| 1525 | instBuiltinAttribute(inCache, inEnv, name, val, exp, ty, p); | ||
| 1526 | |||
| 1527 | case DAE.NAMEMOD(ident = name) | ||
| 1528 | algorithm | ||
| 1529 |
1/2✓ Branch 1 taken 23 times.
✗ Branch 2 not taken.
|
23 | true := Flags.isSet(Flags.FAILTRACE); |
| 1530 | ✗ | Debug.traceln("- Inst.instBasicTypeAttributes2 failed on " + name); | |
| 1531 | ✗ | then | |
| 1532 | fail(); | ||
| 1533 | |||
| 1534 | end match; | ||
| 1535 | end instBasicTypeAttributes2; | ||
| 1536 | |||
| 1537 | protected function instBuiltinAttribute | ||
| 1538 | "Help function to e.g. instRealClass, etc." | ||
| 1539 | input FCore.Cache inCache; | ||
| 1540 | input FCore.Graph inEnv; | ||
| 1541 | input String id; | ||
| 1542 | input Option<Values.Value> optVal; | ||
| 1543 | input DAE.Exp bind; | ||
| 1544 | input DAE.Type inExpectedTp; | ||
| 1545 | input DAE.Properties bindProp; | ||
| 1546 | output DAE.Var var; | ||
| 1547 | algorithm | ||
| 1548 | var := matchcontinue(inCache, inEnv, optVal, inExpectedTp, bindProp) | ||
| 1549 | local | ||
| 1550 | Values.Value v; | ||
| 1551 | DAE.Type t_1,bindTp; | ||
| 1552 | DAE.Exp bind1,vbind; | ||
| 1553 | DAE.Const c; | ||
| 1554 | DAE.Dimension d; | ||
| 1555 | String s,s1,s2; | ||
| 1556 | DAE.Type expectedTp; | ||
| 1557 | FCore.Cache cache; | ||
| 1558 | FCore.Graph env; | ||
| 1559 | |||
| 1560 | case (_, _, SOME(v), expectedTp, DAE.PROP(bindTp,c)) | ||
| 1561 | algorithm | ||
| 1562 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 416365 times.
|
416365 | false := valueEq(c,DAE.C_VAR()); |
| 1563 | 416365 | (bind1,t_1) := Types.matchType(bind,bindTp,expectedTp,true); | |
| 1564 | // convert the value also if needed!! | ||
| 1565 | 416365 | (vbind,_) := Types.matchType(ValuesUtil.valueExp(v),bindTp,expectedTp,true); | |
| 1566 | 416365 | v := ValuesUtil.expValue(vbind); | |
| 1567 | 411699 | then DAE.TYPES_VAR(id,DAE.dummyAttrParam,t_1, | |
| 1568 | DAE.EQBOUND(bind1,SOME(v),DAE.C_PARAM(),DAE.BINDING_FROM_DEFAULT_VALUE()),false,NONE()); | ||
| 1569 | |||
| 1570 | case (_, _, SOME(v), expectedTp, DAE.PROP(bindTp as DAE.T_ARRAY(dims = {d}),c)) | ||
| 1571 | algorithm | ||
| 1572 | ✗ | false := valueEq(c,DAE.C_VAR()); | |
| 1573 | ✗ | true := Flags.getConfigBool(Flags.CHECK_MODEL); | |
| 1574 | ✗ | expectedTp := Types.liftArray(expectedTp, d); | |
| 1575 | ✗ | (bind1,t_1) := Types.matchType(bind,bindTp,expectedTp,true); | |
| 1576 | // convert the value also if needed!! | ||
| 1577 | ✗ | (vbind,_) := Types.matchType(ValuesUtil.valueExp(v),bindTp,expectedTp,true); | |
| 1578 | ✗ | v := ValuesUtil.expValue(vbind); | |
| 1579 | ✗ | then DAE.TYPES_VAR(id,DAE.dummyAttrParam,t_1, | |
| 1580 | DAE.EQBOUND(bind1,SOME(v),DAE.C_PARAM(),DAE.BINDING_FROM_DEFAULT_VALUE()),false,NONE()); | ||
| 1581 | |||
| 1582 | case (cache, env, _, expectedTp, DAE.PROP(bindTp,c)) | ||
| 1583 | algorithm | ||
| 1584 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4677 times.
|
4679 | false := valueEq(c,DAE.C_VAR()); |
| 1585 | 4677 | (bind1,t_1) := Types.matchType(bind,bindTp,expectedTp,true); | |
| 1586 | 4677 | (cache,v) := Ceval.ceval(cache, env, bind1, false, Absyn.NO_MSG(), 0); | |
| 1587 | 317 | then DAE.TYPES_VAR(id,DAE.dummyAttrParam,t_1, | |
| 1588 | DAE.EQBOUND(bind1,SOME(v),DAE.C_PARAM(),DAE.BINDING_FROM_DEFAULT_VALUE()),false,NONE()); | ||
| 1589 | |||
| 1590 | case (cache, env, _, expectedTp, DAE.PROP(bindTp as DAE.T_ARRAY(dims = {d}),c)) | ||
| 1591 | algorithm | ||
| 1592 | ✗ | false := valueEq(c,DAE.C_VAR()); | |
| 1593 | ✗ | true := Flags.getConfigBool(Flags.CHECK_MODEL); | |
| 1594 | ✗ | expectedTp := Types.liftArray(expectedTp, d); | |
| 1595 | ✗ | (bind1,t_1) := Types.matchType(bind,bindTp,expectedTp,true); | |
| 1596 | ✗ | (cache,v) := Ceval.ceval(cache,env, bind1, false, Absyn.NO_MSG(), 0); | |
| 1597 | ✗ | then DAE.TYPES_VAR(id,DAE.dummyAttrParam,t_1, | |
| 1598 | DAE.EQBOUND(bind1,SOME(v),DAE.C_PARAM(),DAE.BINDING_FROM_DEFAULT_VALUE()),false,NONE()); | ||
| 1599 | |||
| 1600 | case(_, _, _, expectedTp, DAE.PROP(bindTp,c)) | ||
| 1601 | algorithm | ||
| 1602 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4362 times.
|
4362 | if Flags.getConfigBool(Flags.CT_STATE_MACHINES) then |
| 1603 | // BTH Hack to allow variable modification of "start" attribute for ct SM re-initialization | ||
| 1604 | // This is is forbidden in standard Modelica! Standard Modelica is the "else" branch! | ||
| 1605 | ✗ | true := valueEq(c,DAE.C_VAR()); | |
| 1606 | else | ||
| 1607 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4360 times.
|
4362 | false := valueEq(c,DAE.C_VAR()); |
| 1608 | end if; | ||
| 1609 | 4360 | (bind1,t_1) := Types.matchType(bind,bindTp,expectedTp,true); | |
| 1610 | 4360 | then DAE.TYPES_VAR(id,DAE.dummyAttrParam,t_1, | |
| 1611 | DAE.EQBOUND(bind1,NONE(),DAE.C_PARAM(),DAE.BINDING_FROM_DEFAULT_VALUE()),false,NONE()); | ||
| 1612 | |||
| 1613 | case(_, _, _, _, DAE.PROP(_,c)) | ||
| 1614 | algorithm | ||
| 1615 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | true := valueEq(c,DAE.C_VAR()); |
| 1616 | 2 | s := ExpressionBasics.printExpStr(bind); | |
| 1617 | 2 | Error.addMessage(Error.HIGHER_VARIABILITY_BINDING,{id,"PARAM",s,"VAR"}); | |
| 1618 | 2 | then fail(); | |
| 1619 | |||
| 1620 | case(_, _, _, expectedTp, DAE.PROP(bindTp,_)) | ||
| 1621 | algorithm | ||
| 1622 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | failure(Types.matchType(bind,bindTp,expectedTp,true)); |
| 1623 | ✗ | s1 := "builtin attribute " + id + " of type "+TypesDump.unparseType(bindTp); | |
| 1624 | ✗ | s2 := TypesDump.unparseType(expectedTp); | |
| 1625 | ✗ | Error.addMessage(Error.TYPE_ERROR,{s1,s2}); | |
| 1626 | ✗ | then fail(); | |
| 1627 | |||
| 1628 | case(_, _, SOME(v), expectedTp, _) algorithm | ||
| 1629 | ✗ | true := Flags.isSet(Flags.FAILTRACE); | |
| 1630 | ✗ | Debug.traceln("instBuiltinAttribute failed for: " + id + | |
| 1631 | " value binding: " + ValuesDump.printValStr(v) + | ||
| 1632 | " binding: " + ExpressionBasics.printExpStr(bind) + | ||
| 1633 | " expected type: " + TypesDump.printTypeStr(expectedTp) + | ||
| 1634 | " type props: " + Types.printPropStr(bindProp)); | ||
| 1635 | ✗ | then fail(); | |
| 1636 | case(_, _, _, expectedTp, _) algorithm | ||
| 1637 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | true := Flags.isSet(Flags.FAILTRACE); |
| 1638 | ✗ | Debug.traceln("instBuiltinAttribute failed for: " + id + | |
| 1639 | " value binding: NONE()" + | ||
| 1640 | " binding: " + ExpressionBasics.printExpStr(bind) + | ||
| 1641 | " expected type: " + TypesDump.printTypeStr(expectedTp) + | ||
| 1642 | " type props: " + Types.printPropStr(bindProp)); | ||
| 1643 | ✗ | then fail(); | |
| 1644 | end matchcontinue; | ||
| 1645 | end instBuiltinAttribute; | ||
| 1646 | |||
| 1647 | protected function arrayBasictypeBaseclass | ||
| 1648 | "author: PA" | ||
| 1649 | input list<list<DAE.Dimension>> inInstDims; | ||
| 1650 | input DAE.Type inType; | ||
| 1651 | output Option<DAE.Type> outOptType; | ||
| 1652 | algorithm | ||
| 1653 | outOptType := match inInstDims | ||
| 1654 | local | ||
| 1655 | DAE.Type ty; | ||
| 1656 | DAE.Dimensions dims; | ||
| 1657 | |||
| 1658 | case {} then NONE(); | ||
| 1659 | |||
| 1660 | else | ||
| 1661 | algorithm | ||
| 1662 | 442577 | dims := List.last(inInstDims); | |
| 1663 | 442577 | ty := Expression.liftArrayLeftList(inType, dims); | |
| 1664 | then | ||
| 1665 | SOME(ty); | ||
| 1666 | |||
| 1667 | end match; | ||
| 1668 | end arrayBasictypeBaseclass; | ||
| 1669 | |||
| 1670 | public function partialInstClassIn | ||
| 1671 | "This function is used when instantiating classes in lookup of other classes. | ||
| 1672 | The only work performed by this function is to instantiate local classes and | ||
| 1673 | inherited classes." | ||
| 1674 | input output FCore.Cache cache; | ||
| 1675 | input output FCore.Graph env; | ||
| 1676 | input output InnerOuter.InstHierarchy ih; | ||
| 1677 | input DAE.Mod mod; | ||
| 1678 | input DAE.Prefix prefix; | ||
| 1679 | input output ClassInf.State state; | ||
| 1680 | input SCode.Element cls; | ||
| 1681 | input SCode.Visibility visibility; | ||
| 1682 | input list<list<DAE.Dimension>> instDims; | ||
| 1683 | input Integer numIter; | ||
| 1684 | output list<DAE.Var> vars; | ||
| 1685 | protected | ||
| 1686 | Absyn.Path cache_path; | ||
| 1687 | InstHashTable.CachedPartialInstItemInputs inputs; | ||
| 1688 | InstHashTable.CachedPartialInstItemOutputs outputs; | ||
| 1689 | DAE.Mod m; | ||
| 1690 | DAE.Prefix pre; | ||
| 1691 | ClassInf.State st; | ||
| 1692 | SCode.Element e; | ||
| 1693 | InstDims dims; | ||
| 1694 | Boolean partial_inst; | ||
| 1695 | algorithm | ||
| 1696 | 1058989 | cache_path := generateCachePath(env, cls, prefix, InstTypes.INNER_CALL()); | |
| 1697 | |||
| 1698 | // See if we have it in the cache. | ||
| 1699 |
1/2✓ Branch 1 taken 1058989 times.
✗ Branch 2 not taken.
|
1058989 | if Flags.isSet(Flags.CACHE) then |
| 1700 | |||
| 1701 | try | ||
| 1702 |
7/12✗ Branch 1 not taken.
✓ Branch 2 taken 1016965 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1016965 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1016965 times.
✓ Branch 7 taken 406 times.
✓ Branch 8 taken 1016559 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1016559 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1016559 times.
|
1058989 | {_, SOME(InstHashTable.FUNC_partialInstClassIn(inputs, outputs))} := InstHashTable.get(cache_path); |
| 1703 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1016559 times.
|
1016559 | (m, pre, st, e as SCode.CLASS(), dims) := inputs; |
| 1704 | |||
| 1705 | // Are the important inputs the same? | ||
| 1706 | 1016559 | InstUtil.prefixEqualUnlessBasicType(pre, prefix, cls); | |
| 1707 |
5/8✓ Branch 1 taken 1016559 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1016559 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1016559 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1016544 times.
✓ Branch 11 taken 15 times.
|
1016559 | if (valueEq(dims,instDims) and valueEq(m, mod) and valueEq(st, state) and valueEq(e, cls)) then |
| 1708 | 1016544 | (env, state, vars) := outputs; | |
| 1709 | 1016544 | showCacheInfo("Partial Inst Hit: ", cache_path); | |
| 1710 | 1016544 | return; | |
| 1711 | end if; | ||
| 1712 | else | ||
| 1713 | // Not in cache, continue. | ||
| 1714 | end try; | ||
| 1715 | end if; | ||
| 1716 | |||
| 1717 | // Check that we don't have an instantiation loop. | ||
| 1718 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 42445 times.
|
42445 | if numIter >= Global.recursionDepthLimit then |
| 1719 | ✗ | Error.addSourceMessage(Error.RECURSION_DEPTH_REACHED, | |
| 1720 | {String(Global.recursionDepthLimit), FGraph.printGraphPathStr(env)}, SCodeUtil.elementInfo(cls)); | ||
| 1721 | ✗ | fail(); | |
| 1722 | end if; | ||
| 1723 | |||
| 1724 | // Instantiate the class and add it to the cache. | ||
| 1725 | try | ||
| 1726 | 42445 | partial_inst := System.getPartialInstantiation(); | |
| 1727 | 42445 | System.setPartialInstantiation(true); | |
| 1728 | |||
| 1729 | 42445 | inputs := (mod, prefix, state, cls, instDims); | |
| 1730 | |||
| 1731 | 42445 | (cache, env, ih, state, vars) := | |
| 1732 | partialInstClassIn_dispatch(cache, env, ih, mod, prefix, state, cls, | ||
| 1733 | visibility, instDims, partial_inst, numIter + 1); | ||
| 1734 | |||
| 1735 | 42305 | outputs := (env, state, vars); | |
| 1736 | |||
| 1737 | 42305 | showCacheInfo("Partial Inst Add: ", cache_path); | |
| 1738 | 84610 | InstHashTable.addToInstCache(cache_path, NONE(), SOME(InstHashTable.FUNC_partialInstClassIn(inputs, outputs))); | |
| 1739 | else | ||
| 1740 |
1/2✓ Branch 1 taken 140 times.
✗ Branch 2 not taken.
|
140 | true := Flags.isSet(Flags.FAILTRACE); |
| 1741 | ✗ | Debug.traceln("- Inst.partialInstClassIn failed on class: " + | |
| 1742 | SCodeUtil.elementName(cls) + " in environment: " + FGraph.printGraphPathStr(env)); | ||
| 1743 | ✗ | fail(); | |
| 1744 | end try; | ||
| 1745 | end partialInstClassIn; | ||
| 1746 | |||
| 1747 | protected function partialInstClassIn_dispatch | ||
| 1748 | "This function is used when instantiating classes in lookup of other classes. | ||
| 1749 | The only work performed by this function is to instantiate local classes and | ||
| 1750 | inherited classes." | ||
| 1751 | input FCore.Cache inCache; | ||
| 1752 | input FCore.Graph inEnv; | ||
| 1753 | input InnerOuter.InstHierarchy inIH; | ||
| 1754 | input DAE.Mod inMod; | ||
| 1755 | input DAE.Prefix inPrefix; | ||
| 1756 | input ClassInf.State inState; | ||
| 1757 | input SCode.Element inClass; | ||
| 1758 | input SCode.Visibility inVisibility; | ||
| 1759 | input list<list<DAE.Dimension>> inInstDims; | ||
| 1760 | input Boolean partialInst; | ||
| 1761 | input Integer numIter; | ||
| 1762 | output FCore.Cache outCache = inCache; | ||
| 1763 | output FCore.Graph outEnv = inEnv; | ||
| 1764 | output InnerOuter.InstHierarchy outIH = inIH; | ||
| 1765 | output ClassInf.State outState = inState; | ||
| 1766 | output list<DAE.Var> outVars = {}; | ||
| 1767 | protected | ||
| 1768 | Boolean success; | ||
| 1769 | algorithm | ||
| 1770 | success := matchcontinue inClass | ||
| 1771 | case SCode.CLASS(name = "Real") then true; | ||
| 1772 | case SCode.CLASS(name = "Integer") then true; | ||
| 1773 | case SCode.CLASS(name = "String") then true; | ||
| 1774 | case SCode.CLASS(name = "Boolean") then true; | ||
| 1775 | // BTH | ||
| 1776 | case SCode.CLASS(name = "Clock") | ||
| 1777 | guard(Flags.getConfigEnum(Flags.LANGUAGE_STANDARD) == 33) then true; | ||
| 1778 | |||
| 1779 | case SCode.CLASS() | ||
| 1780 | algorithm | ||
| 1781 | 42445 | (outCache, outEnv, outIH, outState, outVars) := | |
| 1782 | partialInstClassdef(inCache, inEnv, inIH, inMod, inPrefix, inState, | ||
| 1783 | inClass, inClass.classDef, inVisibility, inInstDims, numIter); | ||
| 1784 | then | ||
| 1785 | true; | ||
| 1786 | |||
| 1787 | else false; | ||
| 1788 | end matchcontinue; | ||
| 1789 | |||
| 1790 | 42445 | System.setPartialInstantiation(partialInst); | |
| 1791 |
2/2✓ Branch 0 taken 140 times.
✓ Branch 1 taken 42305 times.
|
42445 | if not success then fail(); end if; |
| 1792 | end partialInstClassIn_dispatch; | ||
| 1793 | |||
| 1794 | public function instClassdef " | ||
| 1795 | There are two kinds of class definitions, either explicit | ||
| 1796 | definitions SCode.PARTS() or | ||
| 1797 | derived definitions SCode.DERIVED() or | ||
| 1798 | extended derived definitions SCode.CLASS_EXTENDS(). | ||
| 1799 | |||
| 1800 | When instantiating an explicit definition, the elements are first | ||
| 1801 | instantiated, using instElementList, and then the equations | ||
| 1802 | and finally the algorithms are instantiated using instEquation | ||
| 1803 | and instAlgorithm, respectively. The resulting lists of equations | ||
| 1804 | are concatenated to produce the result. | ||
| 1805 | The last two arguments are the same as for instClassIn: | ||
| 1806 | implicit instantiation and implicit package/function instantiation." | ||
| 1807 | input FCore.Cache inCache; | ||
| 1808 | input FCore.Graph inEnv; | ||
| 1809 | input InnerOuter.InstHierarchy inIH; | ||
| 1810 | input UnitAbsyn.InstStore store; | ||
| 1811 | input DAE.Mod inMod2; | ||
| 1812 | input DAE.Prefix inPrefix3; | ||
| 1813 | input ClassInf.State inState5; | ||
| 1814 | input String className; | ||
| 1815 | input SCode.ClassDef inClassDef6; | ||
| 1816 | input SCode.Restriction inRestriction7; | ||
| 1817 | input SCode.Visibility inVisibility; | ||
| 1818 | input SCode.Partial inPartialPrefix; | ||
| 1819 | input SCode.Encapsulated inEncapsulatedPrefix; | ||
| 1820 | input list<list<DAE.Dimension>> inInstDims9; | ||
| 1821 | input Boolean inImplicit; | ||
| 1822 | input InstTypes.CallingScope inCallingScope; | ||
| 1823 | input ConnectionGraph.ConnectionGraph inGraph; | ||
| 1824 | input Connect.Sets inSets; | ||
| 1825 | input Option<DAE.ComponentRef> instSingleCref; | ||
| 1826 | input SCode.Comment comment; | ||
| 1827 | input SourceInfo info; | ||
| 1828 | output FCore.Cache outCache; | ||
| 1829 | output FCore.Graph outEnv; | ||
| 1830 | output InnerOuter.InstHierarchy outIH; | ||
| 1831 | output UnitAbsyn.InstStore outStore; | ||
| 1832 | output DAE.DAElist outDae; | ||
| 1833 | output Connect.Sets outSets; | ||
| 1834 | output ClassInf.State outState; | ||
| 1835 | output list<DAE.Var> outTypesVarLst; | ||
| 1836 | output Option<DAE.Type> outTypesTypeOption; | ||
| 1837 | output Option<SCode.Attributes> optDerAttr; | ||
| 1838 | output DAE.EqualityConstraint outEqualityConstraint; | ||
| 1839 | output ConnectionGraph.ConnectionGraph outGraph; | ||
| 1840 | algorithm | ||
| 1841 | 415063 | (outCache,outEnv,outIH,outStore,outDae,outSets,outState,outTypesVarLst,outTypesTypeOption,optDerAttr,outEqualityConstraint,outGraph):= | |
| 1842 | instClassdef2(inCache,inEnv,inIH,store,inMod2,inPrefix3,inState5,className,inClassDef6,inRestriction7,inVisibility, | ||
| 1843 | inPartialPrefix,inEncapsulatedPrefix,inInstDims9,inImplicit,inCallingScope,inGraph,inSets,instSingleCref,comment,info,Mutable.create(false)); | ||
| 1844 | end instClassdef; | ||
| 1845 | |||
| 1846 | protected function instClassdefBasicType " | ||
| 1847 | This function will try to instantiate the | ||
| 1848 | class definition as a it would extend a basic | ||
| 1849 | type" | ||
| 1850 | input FCore.Cache inCache; | ||
| 1851 | input FCore.Graph inEnv; | ||
| 1852 | input InnerOuter.InstHierarchy inIH; | ||
| 1853 | input UnitAbsyn.InstStore inStore; | ||
| 1854 | input DAE.Mod inMod2; | ||
| 1855 | input DAE.Prefix inPrefix3; | ||
| 1856 | input ClassInf.State inState5; | ||
| 1857 | input String className; | ||
| 1858 | input SCode.ClassDef inClassDef6; | ||
| 1859 | input SCode.Restriction inRestriction7; | ||
| 1860 | input SCode.Visibility inVisibility; | ||
| 1861 | input list<list<DAE.Dimension>> inInstDims9; | ||
| 1862 | input Boolean inImplicit; | ||
| 1863 | input ConnectionGraph.ConnectionGraph inGraph; | ||
| 1864 | input Connect.Sets inSets; | ||
| 1865 | input Option<DAE.ComponentRef> instSingleCref; | ||
| 1866 | input SourceInfo info; | ||
| 1867 | input Mutable<Boolean> stopInst "prevent instantiation of classes adding components to primary types"; | ||
| 1868 | output FCore.Cache outCache; | ||
| 1869 | output FCore.Graph outEnv; | ||
| 1870 | output InnerOuter.InstHierarchy outIH; | ||
| 1871 | output UnitAbsyn.InstStore outStore; | ||
| 1872 | output DAE.DAElist outDae; | ||
| 1873 | output Connect.Sets outSets; | ||
| 1874 | output ClassInf.State outState; | ||
| 1875 | output list<DAE.Var> outTypesVarLst; | ||
| 1876 | output Option<DAE.Type> outTypesTypeOption; | ||
| 1877 | output Option<SCode.Attributes> optDerAttr; | ||
| 1878 | output DAE.EqualityConstraint outEqualityConstraint; | ||
| 1879 | output ConnectionGraph.ConnectionGraph outGraph; | ||
| 1880 | algorithm | ||
| 1881 | (outCache,outEnv,outIH,outStore,outDae,outSets,outState,outTypesVarLst,outTypesTypeOption,optDerAttr,outEqualityConstraint,outGraph):= | ||
| 1882 | matchcontinue (inCache, inEnv, inIH, inStore, inMod2, inPrefix3, inState5, inClassDef6, inInstDims9, inImplicit, inGraph) | ||
| 1883 | local | ||
| 1884 | list<SCode.Element> cdefelts,compelts,extendselts,els; | ||
| 1885 | FCore.Graph env1,env2,env3,env; | ||
| 1886 | list<tuple<SCode.Element, DAE.Mod>> cdefelts_1,cdefelts_2; | ||
| 1887 | Connect.Sets csets; | ||
| 1888 | DAE.DAElist dae1,dae2,dae; | ||
| 1889 | ClassInf.State ci_state; | ||
| 1890 | list<DAE.Var> tys; | ||
| 1891 | Option<DAE.Type> bc; | ||
| 1892 | DAE.Mod mods; | ||
| 1893 | DAE.Prefix pre; | ||
| 1894 | Boolean impl; | ||
| 1895 | InstDims inst_dims; | ||
| 1896 | FCore.Cache cache; | ||
| 1897 | DAE.EqualityConstraint eqConstraint; | ||
| 1898 | ConnectionGraph.ConnectionGraph graph; | ||
| 1899 | InstanceHierarchy ih; | ||
| 1900 | UnitAbsyn.InstStore store; | ||
| 1901 | |||
| 1902 | // This rule describes how to instantiate a class definition | ||
| 1903 | // that extends a basic type. (No equations or algorithms allowed) | ||
| 1904 | case (cache, env, ih, store, mods, pre, ci_state, SCode.PARTS(elementLst = els, | ||
| 1905 | normalEquationLst = {}, initialEquationLst = {}, | ||
| 1906 | normalAlgorithmLst = {}, initialAlgorithmLst = {}), inst_dims, impl, graph) | ||
| 1907 | algorithm | ||
| 1908 | // set this to get rid of the error messages that might happen and WE FAIL BEFORE we actually call instBasictypeBaseclass | ||
| 1909 | 4210 | ErrorExt.setCheckpoint("instClassdefBasicType1"); | |
| 1910 | |||
| 1911 | // we should have just ONE extends, but it might have more like one class containing just annotations | ||
| 1912 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 4210 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4210 times.
|
4210 | (cdefelts,{},extendselts as _::_ /*{one}*/,compelts) := InstUtil.splitElts(els) "components should be empty, checked in instBasictypeBaseclass type below"; |
| 1913 | // adrpo: TODO! DO SOME CHECKS HERE! | ||
| 1914 | // 1. a type extending basic types cannot have components, and only a function definition (equalityConstraint!) | ||
| 1915 | // {} = compelts; // no components! | ||
| 1916 | |||
| 1917 | // adrpo: VERY decisive check! | ||
| 1918 | // only CONNECTOR and TYPE can be extended by basic types! | ||
| 1919 | // true = listMember(re, {SCode.R_TYPE, SCode.R_CONNECTOR(false), SCode.R_CONNECTOR(true)}); | ||
| 1920 | |||
| 1921 | // InstUtil.checkExtendsForTypeRestiction(cache, env, ih, re, extendselts); | ||
| 1922 | |||
| 1923 | 4210 | (cache,env1,ih) := InstUtil.addClassdefsToEnv(cache, env, ih, pre, cdefelts, impl, SOME(mods)) "1. CLASS & IMPORT nodes and COMPONENT nodes(add to env)" ; | |
| 1924 | 4210 | cdefelts_1 := InstUtil.addNomod(cdefelts) "instantiate CDEFS so redeclares are carried out" ; | |
| 1925 | 4210 | env2 := env1; | |
| 1926 | cdefelts_2 := cdefelts_1; | ||
| 1927 | |||
| 1928 | //(cache, cdefelts_2) = removeConditionalComponents(cache, env2, cdefelts_2, pre); | ||
| 1929 | 4210 | (cache,env3,ih,store,dae1,csets,_,tys,graph,_) := | |
| 1930 | instElementList(cache, env2, ih, store, mods , pre, ci_state, | ||
| 1931 | cdefelts_2, inst_dims, impl, InstTypes.INNER_CALL(), graph, inSets, true); | ||
| 1932 | 4210 | mods := Mod.removeFirstSubsRedecl(mods); | |
| 1933 | |||
| 1934 | 4210 | ErrorExt.rollBack("instClassdefBasicType1"); // rollback before going into instBasictypeBaseclass | |
| 1935 | |||
| 1936 | // oh, the horror of backtracking! we need this to make sure that this case failed BEFORE or AFTER it went into instBasictypeBaseclass | ||
| 1937 | 4210 | (cache,ih,store,dae2,bc,tys):= instBasictypeBaseclass(cache, env3, ih, store, extendselts, compelts, mods, inst_dims, className, info, stopInst); | |
| 1938 | // Search for equalityConstraint | ||
| 1939 | 4084 | eqConstraint := InstUtil.equalityConstraint(env3, els, info); | |
| 1940 | 4084 | dae := DAEUtil.joinDaes(dae1,dae2); | |
| 1941 |
1/2✓ Branch 0 taken 4084 times.
✗ Branch 1 not taken.
|
4084 | then |
| 1942 | (cache,env3,ih,store,dae,csets,ci_state,tys,bc,NONE(),eqConstraint,graph); | ||
| 1943 | |||
| 1944 | // VERY COMPLICATED CHECKPOINT! TODO! try to simplify it, maybe by sending DAE.TYPE and checking in instVar! | ||
| 1945 | // did the previous | ||
| 1946 | case (_, _, _, _, _, _, _, SCode.PARTS( | ||
| 1947 | normalEquationLst = {}, initialEquationLst = {}, | ||
| 1948 | normalAlgorithmLst = {}, initialAlgorithmLst = {}), _, _, _) | ||
| 1949 | algorithm | ||
| 1950 |
1/2✓ Branch 1 taken 126 times.
✗ Branch 2 not taken.
|
126 | true := ErrorExt.isTopCheckpoint("instClassdefBasicType1"); |
| 1951 | ✗ | ErrorExt.rollBack("instClassdefBasicType1"); | |
| 1952 | ✗ | then | |
| 1953 | fail(); | ||
| 1954 | end matchcontinue; | ||
| 1955 | end instClassdefBasicType; | ||
| 1956 | |||
| 1957 | protected function instClassdef2 " | ||
| 1958 | There are two kinds of class definitions, either explicit | ||
| 1959 | definitions SCode.PARTS() or | ||
| 1960 | derived definitions SCode.DERIVED() or | ||
| 1961 | extended derived definitions SCode.CLASS_EXTENDS(). | ||
| 1962 | |||
| 1963 | When instantiating an explicit definition, the elements are first | ||
| 1964 | instantiated, using instElementList, and then the equations | ||
| 1965 | and finally the algorithms are instantiated using instEquation | ||
| 1966 | and instAlgorithm, respectively. The resulting lists of equations | ||
| 1967 | are concatenated to produce the result. | ||
| 1968 | The last two arguments are the same as for instClassIn: | ||
| 1969 | implicit instantiation and implicit package/function instantiation." | ||
| 1970 | input FCore.Cache inCache; | ||
| 1971 | input FCore.Graph inEnv; | ||
| 1972 | input InnerOuter.InstHierarchy inIH; | ||
| 1973 | input UnitAbsyn.InstStore inStore; | ||
| 1974 | input DAE.Mod inMod2; | ||
| 1975 | input DAE.Prefix inPrefix3; | ||
| 1976 | input ClassInf.State inState5; | ||
| 1977 | input String className; | ||
| 1978 | input SCode.ClassDef inClassDef6; | ||
| 1979 | input SCode.Restriction inRestriction7; | ||
| 1980 | input SCode.Visibility inVisibility; | ||
| 1981 | input SCode.Partial inPartialPrefix; | ||
| 1982 | input SCode.Encapsulated inEncapsulatedPrefix; | ||
| 1983 | input list<list<DAE.Dimension>> inInstDims9; | ||
| 1984 | input Boolean inImplicit; | ||
| 1985 | input InstTypes.CallingScope inCallingScope; | ||
| 1986 | input ConnectionGraph.ConnectionGraph inGraph; | ||
| 1987 | input Connect.Sets inSets; | ||
| 1988 | input Option<DAE.ComponentRef> instSingleCref; | ||
| 1989 | input SCode.Comment comment; | ||
| 1990 | input SourceInfo info; | ||
| 1991 | input Mutable<Boolean> stopInst "prevent instantiation of classes adding components to primary types"; | ||
| 1992 | output FCore.Cache outCache; | ||
| 1993 | output FCore.Graph outEnv; | ||
| 1994 | output InnerOuter.InstHierarchy outIH; | ||
| 1995 | output UnitAbsyn.InstStore outStore; | ||
| 1996 | output DAE.DAElist outDae; | ||
| 1997 | output Connect.Sets outSets; | ||
| 1998 | output ClassInf.State outState; | ||
| 1999 | output list<DAE.Var> outTypesVarLst; | ||
| 2000 | output Option<DAE.Type> oty; | ||
| 2001 | output Option<SCode.Attributes> optDerAttr; | ||
| 2002 | output DAE.EqualityConstraint outEqualityConstraint; | ||
| 2003 | output ConnectionGraph.ConnectionGraph outGraph; | ||
| 2004 | algorithm | ||
| 2005 | (outCache,outEnv,outIH,outStore,outDae,outSets,outState,outTypesVarLst,oty,optDerAttr,outEqualityConstraint,outGraph):= | ||
| 2006 | matchcontinue (inCache, inEnv, inIH, inStore, inMod2, inPrefix3, inState5, inClassDef6, inRestriction7, inVisibility, inPartialPrefix, inEncapsulatedPrefix, inInstDims9, inImplicit, inCallingScope, inGraph, inSets) | ||
| 2007 | local | ||
| 2008 | list<SCode.Element> cdefelts,compelts,extendselts,els,extendsclasselts,compelts_2_elem; | ||
| 2009 | FCore.Graph env1,env2,env3,env,env5,cenv,cenv_2,env_2,parentEnv,parentClassEnv; | ||
| 2010 | list<tuple<SCode.Element, DAE.Mod>> cdefelts_1,extcomps,compelts_1,compelts_2, comp_cond; | ||
| 2011 | Connect.Sets csets,csets1,csets2,csets3,csets4,csets5,csets_1; | ||
| 2012 | DAE.DAElist dae1,dae2,dae3,dae4,dae5,dae6,dae7,dae8,dae; | ||
| 2013 | ClassInf.State ci_state1,ci_state,ci_state2,ci_state3,ci_state4,ci_state5,ci_state6,new_ci_state,ci_state_1; | ||
| 2014 | list<DAE.Var> vars; | ||
| 2015 | Option<DAE.Type> bc; | ||
| 2016 | DAE.Mod mods,emods,mod_1,mods_1,checkMods; | ||
| 2017 | DAE.Prefix pre; | ||
| 2018 | list<SCode.Equation> eqs,initeqs,eqs2,initeqs2,eqs_1,initeqs_1; | ||
| 2019 | list<SCode.AlgorithmSection> alg,initalg,alg2,initalg2,alg_1,initalg_1; | ||
| 2020 | list<SCode.ConstraintSection> constrs; | ||
| 2021 | list<Absyn.NamedArg> clsattrs; | ||
| 2022 | SCode.Restriction re,r; | ||
| 2023 | Boolean impl, valid_connector; | ||
| 2024 | SCode.Visibility vis; | ||
| 2025 | SCode.Encapsulated enc2; | ||
| 2026 | SCode.Partial partialPrefix; | ||
| 2027 | SCode.Encapsulated encapsulatedPrefix; | ||
| 2028 | InstDims inst_dims,inst_dims_1; | ||
| 2029 | String cn2,cns,scope_str,s,str; | ||
| 2030 | SCode.Element c; | ||
| 2031 | SCode.ClassDef classDef, classDefParent; | ||
| 2032 | Option<DAE.EqMod> eq; | ||
| 2033 | DAE.Dimensions dims; | ||
| 2034 | Absyn.Path cn, fq_class; | ||
| 2035 | Option<list<Absyn.Subscript>> ad; | ||
| 2036 | SCode.Mod mod; | ||
| 2037 | FCore.Cache cache; | ||
| 2038 | Option<SCode.Attributes> oDA; | ||
| 2039 | list<SCode.Comment> comments; | ||
| 2040 | DAE.EqualityConstraint eqConstraint; | ||
| 2041 | InstTypes.CallingScope callscope; | ||
| 2042 | ConnectionGraph.ConnectionGraph graph; | ||
| 2043 | InstanceHierarchy ih; | ||
| 2044 | DAE.DAElist fdae; | ||
| 2045 | Boolean unrollForLoops, zero_dims; | ||
| 2046 | list<Absyn.TypeSpec> tSpecs; | ||
| 2047 | list<DAE.Type> tys; | ||
| 2048 | SCode.Attributes DA; | ||
| 2049 | DAE.Type ty; | ||
| 2050 | Absyn.TypeSpec tSpec; | ||
| 2051 | UnitAbsyn.InstStore store; | ||
| 2052 | Option<SCode.ExternalDecl> ed; | ||
| 2053 | DAE.ElementSource elementSource; | ||
| 2054 | list<DAE.ComponentRef> smCompCrefs "state machine components crefs"; | ||
| 2055 | list<DAE.ComponentRef> smInitialCrefs "state machine crefs of initial states"; | ||
| 2056 | InstStateMachineUtil.SMNodeToFlatSMGroupTable smCompToFlatSM; | ||
| 2057 | //List<tuple<Absyn.ComponentRef,DAE.ComponentRef>> fieldDomLst; | ||
| 2058 | InstUtil.DomainFieldsLst domainFieldsLst; | ||
| 2059 | list<String> typeVars; | ||
| 2060 | // list<tuple<String,Integer>> domainNLst; | ||
| 2061 | |||
| 2062 | /*// uncomment for debugging | ||
| 2063 | case (cache,env,ih,store,mods,pre,csets,ci_state,className,inClassDef6, | ||
| 2064 | re,vis,_,_,inst_dims,impl,_,graph,instSingleCref,info,stopInst) | ||
| 2065 | algorithm | ||
| 2066 | // fprintln(Flags.INST_TRACE, "ICD BEGIN: " + FGraph.printGraphPathStr(env) + " cn:" + className + " mods: " + Mod.printModStr(mods)); | ||
| 2067 | then | ||
| 2068 | fail();*/ | ||
| 2069 | |||
| 2070 | // This rule describes how to instantiate a class definition | ||
| 2071 | // that extends a basic type. (No equations or algorithms allowed) | ||
| 2072 | case (cache, env, ih, store, mods, pre, ci_state, SCode.PARTS(elementLst = els, | ||
| 2073 | normalEquationLst = {}, initialEquationLst = {}, | ||
| 2074 | normalAlgorithmLst = {}, initialAlgorithmLst = {}), re, vis, _, _, inst_dims, impl, _, graph, _) | ||
| 2075 | algorithm | ||
| 2076 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 172632 times.
|
341054 | false := Mutable.access(stopInst); |
| 2077 | // adpro: if is a model, package, function, external function, record is not a basic type! | ||
| 2078 |
2/2✓ Branch 1 taken 953 times.
✓ Branch 2 taken 171679 times.
|
172632 | false := valueEq(SCode.R_MODEL(), re); |
| 2079 |
2/2✓ Branch 1 taken 1871 times.
✓ Branch 2 taken 169808 times.
|
171679 | false := valueEq(SCode.R_PACKAGE(), re); |
| 2080 |
2/2✓ Branch 1 taken 88406 times.
✓ Branch 2 taken 81402 times.
|
169808 | false := SCodeUtil.isFunctionRestriction(re); |
| 2081 |
2/2✓ Branch 1 taken 34 times.
✓ Branch 2 taken 81368 times.
|
81402 | false := valueEq(SCode.R_RECORD(true), re); |
| 2082 |
2/2✓ Branch 1 taken 11121 times.
✓ Branch 2 taken 70247 times.
|
81368 | false := valueEq(SCode.R_RECORD(false), re); |
| 2083 | // no components and at least one extends! | ||
| 2084 | |||
| 2085 |
4/4✓ Branch 1 taken 63491 times.
✓ Branch 2 taken 6756 times.
✓ Branch 3 taken 58 times.
✓ Branch 4 taken 6698 times.
|
70247 | (cdefelts,extendsclasselts,extendselts as _::_,{}) := InstUtil.splitElts(els); |
| 2086 | 6698 | extendselts := SCodeInstUtil.addRedeclareAsElementsToExtends(extendselts, List.select(els, SCodeUtil.isRedeclareElement)); | |
| 2087 | 6698 | (cache,env1,ih) := InstUtil.addClassdefsToEnv(cache, env, ih, pre, cdefelts, impl, SOME(mods)); | |
| 2088 |
4/8✗ Branch 1 not taken.
✓ Branch 2 taken 6698 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6698 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6698 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6698 times.
|
6698 | (cache,_,_,_,extcomps,{},{},{},{},_) := |
| 2089 | InstExtends.instExtendsAndClassExtendsList(cache, env1, ih, mods, pre, extendselts, extendsclasselts, els, ci_state, className, impl, false); | ||
| 2090 | |||
| 2091 | 6698 | compelts_2_elem := List.map(extcomps,Util.tuple21); | |
| 2092 | // no components from the extends! | ||
| 2093 |
2/2✓ Branch 1 taken 2488 times.
✓ Branch 2 taken 4210 times.
|
6698 | (_, _, _, {}) := InstUtil.splitElts(compelts_2_elem); |
| 2094 | |||
| 2095 | 4210 | (cache,env,ih,store,fdae,csets,ci_state,vars,bc,oDA,eqConstraint,graph) := | |
| 2096 | instClassdefBasicType(cache,env,ih,store,mods,pre,ci_state,className,inClassDef6,re,vis,inst_dims,impl,graph, | ||
| 2097 | inSets, instSingleCref,info,stopInst); | ||
| 2098 | then | ||
| 2099 | (cache,env,ih,store,fdae,csets,ci_state,vars,bc,oDA,eqConstraint,graph); | ||
| 2100 | |||
| 2101 | /*// uncomment for debugging | ||
| 2102 | case (cache,env,ih,store,mods,pre,csets,ci_state,className,inClassDef6, | ||
| 2103 | re,vis,_,_,inst_dims,impl,_,graph,instSingleCref,info,stopInst) | ||
| 2104 | algorithm | ||
| 2105 | // fprintln(Flags.INST_TRACE, "ICD AFTER BASIC TYPE: " + FGraph.printGraphPathStr(env) + " cn:" + className + " mods: " + Mod.printModStr(mods)); | ||
| 2106 | then | ||
| 2107 | fail();*/ | ||
| 2108 | |||
| 2109 | // This case instantiates external objects. An external object inherits from ExternalObject | ||
| 2110 | // and have two local functions: constructor and destructor (and no other elements). | ||
| 2111 | case (cache, env, ih, store, mods, _, ci_state, SCode.PARTS(elementLst = els), _, _, _, _, _, impl, _, graph, _) | ||
| 2112 | algorithm | ||
| 2113 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 178368 times.
|
178368 | false := Mutable.access(stopInst); |
| 2114 |
2/2✓ Branch 1 taken 178278 times.
✓ Branch 2 taken 90 times.
|
178368 | true := SCodeUtil.isExternalObject(els); |
| 2115 | 90 | (cache,env,ih,dae,ci_state) := InstFunction.instantiateExternalObject(cache,env,ih,els,mods,impl,comment,info); | |
| 2116 | 89 | then | |
| 2117 | (cache,env,ih,store,dae,inSets,ci_state,{},NONE(),NONE(),NONE(),graph); | ||
| 2118 | |||
| 2119 | // This rule describes how to instantiate an explicit class definition, i.e. made of parts! | ||
| 2120 | case (cache, env, ih, store, mods, pre, ci_state, SCode.PARTS(elementLst = els, | ||
| 2121 | normalEquationLst = eqs, initialEquationLst = initeqs, | ||
| 2122 | normalAlgorithmLst = alg, initialAlgorithmLst = initalg, | ||
| 2123 | constraintLst = constrs, clsattrs = clsattrs, externalDecl = ed | ||
| 2124 | ), re, _, _, _, inst_dims, impl, callscope, graph, csets) | ||
| 2125 | algorithm | ||
| 2126 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 178279 times.
|
178279 | false := Mutable.access(stopInst); |
| 2127 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 178278 times.
|
178279 | false := SCodeUtil.isExternalObject(els); |
| 2128 | // phi: very old unit checking | ||
| 2129 | /* | ||
| 2130 | if Flags.getConfigBool(Flags.UNIT_CHECKING) then | ||
| 2131 | UnitParserExt.checkpoint(); | ||
| 2132 | end if; | ||
| 2133 | */ | ||
| 2134 | //Debug.traceln(" Instclassdef for: " + PrefixUtil.printPrefixStr(pre) + "." + className + " mods: " + Mod.printModStr(mods)); | ||
| 2135 | 178278 | ci_state1 := ClassInfUtil.trans(ci_state, ClassInf.NEWDEF()); | |
| 2136 | 178278 | els := InstUtil.extractConstantPlusDeps(els,instSingleCref,{},className); | |
| 2137 | |||
| 2138 | // split elements | ||
| 2139 | 178278 | (cdefelts,extendsclasselts,extendselts,compelts) := InstUtil.splitElts(els); | |
| 2140 | |||
| 2141 | // remove components from expandable connectors | ||
| 2142 | // compelts = if_(valueEq(re, SCode.R_CONNECTOR(true)), {}, compelts); | ||
| 2143 | |||
| 2144 | 178278 | extendselts := SCodeInstUtil.addRedeclareAsElementsToExtends(extendselts, List.select(els, SCodeUtil.isRedeclareElement)); | |
| 2145 | |||
| 2146 | 356556 | (cache, env1,ih) := InstUtil.addClassdefsToEnv(cache, env, ih, pre, | |
| 2147 | cdefelts, impl, SOME(mods), FGraph.isEmptyScope(env)); | ||
| 2148 | |||
| 2149 | //// fprintln(Flags.INST_TRACE, "after InstUtil.addClassdefsToEnv ENV: " + if_(stringEq(className, "PortVolume"), FGraph.printGraphStr(env1), " no env print ")); | ||
| 2150 | |||
| 2151 | // adrpo: TODO! DO SOME CHECKS HERE! | ||
| 2152 | // restriction on what can inherit what, see 7.1.3 Restrictions on the Kind of Base Class | ||
| 2153 | // if a type -> no components, can extends only another type | ||
| 2154 | // if a record -> components ok | ||
| 2155 | // checkRestrictionsOnTheKindOfBaseClass(cache, env, ih, re, extendselts); | ||
| 2156 | |||
| 2157 | 178278 | (cache,env2,ih,emods,extcomps,eqs2,initeqs2,alg2,initalg2,comments) := | |
| 2158 | InstExtends.instExtendsAndClassExtendsList(cache, env1, ih, mods, pre, extendselts, extendsclasselts, els, ci_state, className, impl, false) | ||
| 2159 | "2. EXTENDS Nodes inst_extends_list only flatten inhteritance structure. It does not perform component instantiations."; | ||
| 2160 | |||
| 2161 | |||
| 2162 | // print("Extended Elements inst:\n" + InstUtil.printElementAndModList(extcomps)); | ||
| 2163 | |||
| 2164 | //fprint(Flags.INST_EXT_TRACE, "EXTENDS RETURNS:\n" + Debug.fcallret1(Flags.INST_EXT_TRACE, printElementAndModList, extcomps, "") + "\n"); | ||
| 2165 | //fprint(Flags.INST_EXT_TRACE, "EXTENDS RETURNS EMODS: " + Mod.printModStr(emods) + "\n"); | ||
| 2166 | |||
| 2167 | 178276 | compelts_1 := InstUtil.addNomod(compelts) | |
| 2168 | "Problem. Modifiers on inherited components are unelabed, loosing their | ||
| 2169 | type information. This will not work, since the modifier type | ||
| 2170 | can not always be found. | ||
| 2171 | For instance. | ||
| 2172 | model B extends B2; end B; model B2 Integer ni=1; end B2; | ||
| 2173 | model test | ||
| 2174 | Integer n=2; | ||
| 2175 | B b(ni=n); | ||
| 2176 | end test; | ||
| 2177 | |||
| 2178 | The modifier (n=n) will be untypes when B is instantiated | ||
| 2179 | and the variable n can not be found, since the component b | ||
| 2180 | is instantiated in env of B. | ||
| 2181 | |||
| 2182 | Solution: | ||
| 2183 | Redesign instExtendsList to return (SCode.Element, Mod) list and | ||
| 2184 | convert other component elements to the same format, such that | ||
| 2185 | instElement can handle the new format uniformely." ; | ||
| 2186 | |||
| 2187 | 178276 | cdefelts_1 := InstUtil.addNomod(cdefelts); | |
| 2188 | |||
| 2189 | // Add components from base classes to be instantiated in 3 as well. | ||
| 2190 | 178276 | compelts_1 := List.flatten({extcomps,compelts_1,cdefelts_1}); | |
| 2191 | |||
| 2192 | // Add equation and algorithm sections from base classes. | ||
| 2193 | 178276 | eqs_1 := joinExtEquations(eqs, eqs2, callscope); | |
| 2194 | 178276 | initeqs_1 := joinExtEquations(initeqs, initeqs2, callscope); | |
| 2195 | 178276 | alg_1 := joinExtAlgorithms(alg, alg2, callscope); | |
| 2196 | 178276 | initalg_1 := joinExtAlgorithms(initalg, initalg2, callscope); | |
| 2197 | |||
| 2198 | 178276 | (compelts_1, eqs_1, initeqs_1, alg_1, initalg_1) := | |
| 2199 | InstUtil.extractConstantPlusDepsTpl(compelts_1, instSingleCref, {}, className, eqs_1, initeqs_1, alg_1, initalg_1); | ||
| 2200 |
2/2✓ Branch 1 taken 34 times.
✓ Branch 2 taken 178242 times.
|
178276 | if intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PDEMODELICA) then |
| 2201 | 34 | compelts_1 := InstUtil.addGhostCells(compelts_1, eqs_1); | |
| 2202 | end if; | ||
| 2203 | |||
| 2204 | //(csets, env2, ih) = InstUtil.addConnectionCrefsFromEqs(csets, eqs_1, pre, env2, ih); | ||
| 2205 | |||
| 2206 | //// fprintln(Flags.INST_TRACE, "Emods to InstUtil.addComponentsToEnv: " + Mod.printModStr(emods)); | ||
| 2207 | |||
| 2208 | //Add variables to env, wihtout type and binding, which will be added | ||
| 2209 | //later in instElementList (where update_variable is called)" | ||
| 2210 | 178276 | checkMods := Mod.merge(mods,emods, className); | |
| 2211 | mods := checkMods; | ||
| 2212 | 178276 | (cache,env3,ih) := InstUtil.addComponentsToEnv(cache, env2, ih, mods, pre, ci_state, compelts_1, impl); | |
| 2213 | |||
| 2214 | //Instantiate components | ||
| 2215 | 178276 | compelts_2_elem := List.map(compelts_1,Util.tuple21); | |
| 2216 | 178276 | InstUtil.matchModificationToComponents(compelts_2_elem,checkMods,FGraph.printGraphPathStr(env3)); | |
| 2217 | |||
| 2218 | // Move any conditional components to the end of the component list, to | ||
| 2219 | // make sure that any dependencies of the condition are instantiated first. | ||
| 2220 | 178259 | (comp_cond, compelts_1) := List.splitOnTrue(compelts_1, InstUtil.componentHasCondition); | |
| 2221 | 178259 | compelts_2 := listAppend(compelts_1, comp_cond); | |
| 2222 | |||
| 2223 | // BTH: Search for state machine components and update ih correspondingly. | ||
| 2224 | 178259 | (smCompCrefs, smInitialCrefs) := InstStateMachineUtil.getSMStatesInContext(eqs_1, pre); | |
| 2225 | //ih = List.fold1(smCompCrefs, InnerOuter.updateSMHierarchy, inPrefix3, ih); | ||
| 2226 | 178259 | ih := List.fold(smCompCrefs, InnerOuter.updateSMHierarchy, ih); | |
| 2227 | |||
| 2228 | 178259 | (cache,env5,ih,store,dae1,csets,ci_state2,vars,graph,domainFieldsLst) := | |
| 2229 | instElementList(cache, env3, ih, store, mods, pre, ci_state1, | ||
| 2230 | compelts_2, inst_dims, impl, callscope, graph, csets, true); | ||
| 2231 | |||
| 2232 | // If we are currently instantiating a connector, add all flow variables | ||
| 2233 | // in it as inside connectors. | ||
| 2234 | 159965 | zero_dims := InstUtil.instDimsHasZeroDims(inst_dims); | |
| 2235 | 159965 | elementSource := ElementSource.createElementSource(info, FGraph.getScopePath(env3), pre); | |
| 2236 | 159965 | csets1 := ConnectUtil.addConnectorVariablesFromDAE(zero_dims, ci_state1, pre, vars, info, elementSource, csets); | |
| 2237 | |||
| 2238 | 159965 | (cache, eqs_1) := InstUtil.reorderConnectEquationsExpandable(cache, env5, eqs_1); | |
| 2239 | |||
| 2240 | //Discretization of PDEs: | ||
| 2241 |
2/2✓ Branch 1 taken 34 times.
✓ Branch 2 taken 159931 times.
|
159965 | if intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PDEMODELICA) then |
| 2242 | 34 | eqs_1 := List.fold1(eqs_1, InstUtil.discretizePDE, domainFieldsLst, {}); | |
| 2243 | end if; | ||
| 2244 | //Instantiate equations (see function "instEquation") | ||
| 2245 | 159965 | (cache,env5,ih,dae2,csets2,ci_state3,graph) := | |
| 2246 | instList(cache, env5, ih, pre, csets1, ci_state2, InstSection.instEquation, eqs_1, impl, InstTypes.alwaysUnroll, graph); | ||
| 2247 | 159943 | DAEUtil.verifyEquationsDAE(dae2); | |
| 2248 | |||
| 2249 | //Discretization of initial equations of fields: | ||
| 2250 |
2/2✓ Branch 1 taken 34 times.
✓ Branch 2 taken 159909 times.
|
159943 | if intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PDEMODELICA) then |
| 2251 | 34 | initeqs_1 := List.fold1(initeqs_1, InstUtil.discretizePDE, domainFieldsLst,/* domainNLst,*/ {}); | |
| 2252 | end if; | ||
| 2253 | //Instantiate inital equations (see function "instInitialEquation") | ||
| 2254 | 159943 | (cache,env5,ih,dae3,csets3,ci_state4,graph) := | |
| 2255 | instList(cache, env5, ih, pre, csets2, ci_state3, InstSection.instInitialEquation, initeqs_1, impl, InstTypes.alwaysUnroll, graph); | ||
| 2256 | |||
| 2257 | // do NOT unroll for loops for functions! | ||
| 2258 | 159943 | unrollForLoops := if SCodeUtil.isFunctionRestriction(re) then InstTypes.neverUnroll else InstTypes.alwaysUnroll; | |
| 2259 | |||
| 2260 | //Instantiate algorithms (see function "instAlgorithm") | ||
| 2261 | 159943 | (cache,env5,ih,dae4,csets4,ci_state5,graph) := | |
| 2262 | instList(cache,env5,ih, pre, csets3, ci_state4, InstSection.instAlgorithm, alg_1, impl, unrollForLoops, graph); | ||
| 2263 | |||
| 2264 | //Instantiate algorithms (see function "instInitialAlgorithm") | ||
| 2265 | 159883 | (cache,env5,ih,dae5,csets5,ci_state6,graph) := | |
| 2266 | instList(cache,env5,ih, pre, csets4, ci_state5, InstSection.instInitialAlgorithm, initalg_1, impl, unrollForLoops, graph); | ||
| 2267 | |||
| 2268 | //Instantiate/Translate class Attributes (currently only allowed for Optimica extensions) | ||
| 2269 | 159882 | (cache,env5,dae6) := | |
| 2270 | instClassAttributes(cache,env5, pre, clsattrs, impl,info); | ||
| 2271 | |||
| 2272 | //Instantiate Constraints (see function "instConstraints") | ||
| 2273 | 159882 | (cache,env5,dae7,_) := | |
| 2274 | instConstraints(cache,env5, pre, ci_state6, constrs, impl); | ||
| 2275 | |||
| 2276 | 159882 | dae8 := instFunctionAnnotations(comment::comments, ci_state6); | |
| 2277 | |||
| 2278 | // BTH: Relate state machine components to the flat state machine that they are part of | ||
| 2279 | 159882 | smCompToFlatSM := InstStateMachineUtil.createSMNodeToFlatSMGroupTable(dae2); | |
| 2280 | // BTH: Wrap state machine components (including transition statements) into corresponding flat state machine containers | ||
| 2281 | 159882 | (dae1,dae2) := InstStateMachineUtil.wrapSMCompsInFlatSMs(ih, dae1, dae2, smCompToFlatSM, smInitialCrefs); | |
| 2282 | |||
| 2283 | //Collect the DAE's | ||
| 2284 | 159882 | dae := DAEUtil.joinDaeLst({dae1,dae2,dae3,dae4,dae5,dae6,dae7,dae8}); | |
| 2285 | |||
| 2286 | //Change outer references to corresponding inner reference | ||
| 2287 | // adrpo: TODO! FIXME! very very very expensive function, try to get rid of it! | ||
| 2288 | //t1 = clock(); | ||
| 2289 | //(dae,csets5,ih,graph) = InnerOuter.changeOuterReferences(dae,csets5,ih,graph); | ||
| 2290 | //t2 = clock(); | ||
| 2291 | //ti = t2 -. t1; | ||
| 2292 | //fprintln(Flags.INNER_OUTER, " INST_CLASS: (" + realString(ti) + ") -> " + PrefixUtil.printPrefixStr(pre) + "." + className + " mods: " + Mod.printModStr(mods) + " in env: " + FGraph.printGraphPathStr(env7)); | ||
| 2293 | |||
| 2294 | 159882 | csets5 := InnerOuter.changeInnerOuterInOuterConnect(csets5); | |
| 2295 | |||
| 2296 | // phi: very old unit checking | ||
| 2297 | /* | ||
| 2298 | // adrpo: moved bunch of a lot of expensive unit checking operations to this function | ||
| 2299 | (cache,env5,store) = InstUtil.handleUnitChecking(cache,env5,store,pre,dae1,{dae2,dae3,dae4,dae5},className); | ||
| 2300 | |||
| 2301 | if Flags.getConfigBool(Flags.UNIT_CHECKING) then | ||
| 2302 | UnitParserExt.rollback(); // print("rollback for "+className+"\n"); | ||
| 2303 | end if; | ||
| 2304 | */ | ||
| 2305 | |||
| 2306 | // Search for equalityConstraint | ||
| 2307 | 159882 | eqConstraint := InstUtil.equalityConstraint(env5, els, info); | |
| 2308 |
3/4✗ Branch 0 not taken.
✓ Branch 1 taken 159882 times.
✓ Branch 2 taken 95859 times.
✓ Branch 3 taken 64023 times.
|
159882 | ci_state6 := if isSome(ed) then ClassInfUtil.assertTrans(ci_state6,ClassInf.FOUND_EXT_DECL(),info) else ci_state6; |
| 2309 | 159881 | (cache,oty) := InstMeta.fixUniontype(cache, env5, ci_state6, inClassDef6); | |
| 2310 | () := match oty | ||
| 2311 | case SOME(ty as DAE.T_METAUNIONTYPE(typeVars=_::_)) | ||
| 2312 | algorithm | ||
| 2313 | ✗ | Error.addSourceMessage(Error.UNIONTYPE_MISSING_TYPEVARS, {TypesDump.unparseType(ty)}, info); | |
| 2314 | ✗ | then fail(); | |
| 2315 | else (); | ||
| 2316 | end match; | ||
| 2317 | 159881 | then | |
| 2318 | (cache,env5,ih,store,dae,csets5,ci_state6,vars,oty,NONE(),eqConstraint,graph); | ||
| 2319 | |||
| 2320 | // This rule describes how to instantiate class definition derived from an enumeration | ||
| 2321 | case (cache, env, ih, store, mods, pre, _, SCode.DERIVED(typeSpec=Absyn.TPATH(path = cn,arrayDim = ad),modifications = mod,attributes=DA), re, vis, _, _, inst_dims, impl, callscope, graph, _) | ||
| 2322 | algorithm | ||
| 2323 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 206495 times.
|
412808 | false := Mutable.access(stopInst); |
| 2324 | |||
| 2325 |
3/4✗ Branch 1 not taken.
✓ Branch 2 taken 206495 times.
✓ Branch 3 taken 206313 times.
✓ Branch 4 taken 182 times.
|
206495 | (cache,(c as SCode.CLASS(name=cn2,encapsulatedPrefix=enc2,restriction=r as SCode.R_ENUMERATION())), cenv) := |
| 2326 | Lookup.lookupClass(cache, env, cn, SOME(info)); | ||
| 2327 | |||
| 2328 | // keep the old behaviour | ||
| 2329 | 182 | env3 := FGraph.openScope(cenv, enc2, cn2, SOME(FCore.CLASS_SCOPE())); | |
| 2330 | 182 | ci_state2 := ClassInfUtil.start(r, FGraph.getGraphName(env3)); | |
| 2331 | 182 | new_ci_state := ClassInfUtil.start(r, FGraph.getGraphName(env3)); | |
| 2332 | |||
| 2333 | // print("Enum Env: " + FGraph.printGraphPathStr(env3) + "\n"); | ||
| 2334 | 182 | (cache,cenv_2,_,_,_,_,_,_,_,_,_,_) := | |
| 2335 | instClassIn( | ||
| 2336 | cache,env3,InnerOuter.emptyInstHierarchy,UnitAbsyn.noStore, | ||
| 2337 | DAE.NOMOD(), DAE.NOPRE(), ci_state2, c, SCode.PUBLIC(), {}, false, | ||
| 2338 | callscope, ConnectionGraph.EMPTY, Connect.emptySet, NONE()); | ||
| 2339 | |||
| 2340 | 182 | (cache,mod_1) := Mod.elabMod(cache, cenv_2, ih, pre, mod, impl, Mod.DERIVED(cn), info); | |
| 2341 | |||
| 2342 | 182 | mods_1 := Mod.merge(mods, mod_1, className); | |
| 2343 | 182 | eq := Mod.modEquation(mods_1) "instantiate array dimensions" ; | |
| 2344 | 182 | (cache,dims) := InstUtil.elabArraydimOpt(cache,cenv_2, Absyn.CREF_IDENT("",{}),cn, ad, eq, impl,true,pre,info,inst_dims) "owncref not valid here" ; | |
| 2345 | // inst_dims2 = InstUtil.instDimExpLst(dims, impl); | ||
| 2346 | 182 | inst_dims_1 := List.appendLastList(inst_dims, dims); | |
| 2347 | |||
| 2348 | 182 | (cache,env_2,ih,store,dae,csets_1,ci_state_1,vars,bc,oDA,eqConstraint,graph) := instClassIn(cache, cenv_2, ih, store, mods_1, pre, new_ci_state, c, vis, | |
| 2349 | inst_dims_1, impl, callscope, graph, inSets, instSingleCref) "instantiate class in opened scope."; | ||
| 2350 | 182 | ClassInfUtil.assertValid(ci_state_1, re, info) "Check for restriction violations"; | |
| 2351 | 182 | oDA := SCodeUtil.mergeAttributes(DA,oDA); | |
| 2352 | 182 | then | |
| 2353 | (cache,env_2,ih,store,dae,csets_1,ci_state_1,vars,bc,oDA,eqConstraint,graph); | ||
| 2354 | |||
| 2355 | // This rule describes how to instantiate a derived class definition from basic types | ||
| 2356 | case (cache, env, ih, store, mods, pre, ci_state, SCode.DERIVED(typeSpec=Absyn.TPATH(path = cn,arrayDim = ad),modifications = mod,attributes=DA), re, vis, _, _, inst_dims, impl, callscope, graph, _) | ||
| 2357 | algorithm | ||
| 2358 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 206313 times.
|
207591 | false := Mutable.access(stopInst); |
| 2359 | |||
| 2360 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 206313 times.
|
206313 | (cache,(c as SCode.CLASS(name=cn2,encapsulatedPrefix=enc2,restriction=r)),cenv) := Lookup.lookupClass(cache, env, cn, SOME(info)); |
| 2361 | |||
| 2362 | // if is a basic type or derived from it, follow the normal path | ||
| 2363 |
2/2✓ Branch 1 taken 1278 times.
✓ Branch 2 taken 205035 times.
|
206313 | true := InstUtil.checkDerivedRestriction(re, r, cn2); |
| 2364 | |||
| 2365 | // If it's a connector, check that it's valid. | ||
| 2366 | 205035 | valid_connector := ConnectUtil.checkShortConnectorDef(ci_state, DA, info); | |
| 2367 |
1/2✓ Branch 0 taken 205035 times.
✗ Branch 1 not taken.
|
410070 | Mutable.update(stopInst, not valid_connector); |
| 2368 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 205035 times.
|
205035 | true := valid_connector; |
| 2369 | |||
| 2370 | 205035 | cenv_2 := FGraph.openScope(cenv, enc2, cn2, FGraph.classInfToScopeType(ci_state)); | |
| 2371 | 205035 | new_ci_state := ClassInfUtil.start(r, FGraph.getGraphName(cenv_2)); | |
| 2372 | |||
| 2373 | // chain the redeclares | ||
| 2374 | 205035 | mod := InstUtil.chainRedeclares(mods, mod); | |
| 2375 | |||
| 2376 | // elab the modifiers in the parent environment! | ||
| 2377 | 205035 | (parentEnv, _) := FGraph.stripLastScopeRef(env); | |
| 2378 | 205035 | (cache,mod_1) := Mod.elabMod(cache, parentEnv, ih, pre, mod, impl, Mod.DERIVED(cn), info); | |
| 2379 | 205035 | mods_1 := Mod.merge(mods, mod_1, className); | |
| 2380 | |||
| 2381 | 205033 | eq := Mod.modEquation(mods_1) "instantiate array dimensions"; | |
| 2382 | 205033 | (cache,dims) := InstUtil.elabArraydimOpt(cache, parentEnv, Absyn.CREF_IDENT("",{}), cn, ad, eq, impl, true, pre, info, inst_dims) "owncref not valid here" ; | |
| 2383 | // inst_dims2 = InstUtil.instDimExpLst(dims, impl); | ||
| 2384 | 205033 | inst_dims_1 := List.appendLastList(inst_dims, dims); | |
| 2385 | |||
| 2386 | 205033 | (cache,env_2,ih,store,dae,csets_1,ci_state_1,vars,bc,oDA,eqConstraint,graph) := instClassIn(cache, cenv_2, ih, store, mods_1, pre, new_ci_state, c, vis, | |
| 2387 | inst_dims_1, impl, callscope, graph, inSets, instSingleCref) "instantiate class in opened scope. " ; | ||
| 2388 | |||
| 2389 | 205018 | ClassInfUtil.assertValid(ci_state_1, re, info) "Check for restriction violations" ; | |
| 2390 | 205015 | oDA := SCodeUtil.mergeAttributes(DA,oDA); | |
| 2391 | 205015 | then | |
| 2392 | (cache,env_2,ih,store,dae,csets_1,ci_state_1,vars,bc,oDA,eqConstraint,graph); | ||
| 2393 | |||
| 2394 | // This rule describes how to instantiate a derived class definition without array dims | ||
| 2395 | case (cache, env, ih, store, mods, pre, ci_state, SCode.DERIVED(typeSpec = Absyn.TPATH(path = cn,arrayDim = ad), modifications = mod, attributes=DA), re, vis, partialPrefix, encapsulatedPrefix, inst_dims, impl, callscope, graph, _) | ||
| 2396 | algorithm | ||
| 2397 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1298 times.
|
1591 | false := Mutable.access(stopInst); |
| 2398 |
2/2✓ Branch 1 taken 20 times.
✓ Branch 2 taken 1278 times.
|
1298 | false := valueEq(re, SCode.R_TYPE()); |
| 2399 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1278 times.
|
1278 | false := valueEq(re, SCode.R_ENUMERATION()); |
| 2400 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1278 times.
|
1278 | false := valueEq(re, SCode.R_PREDEFINED_ENUMERATION()); |
| 2401 |
2/2✓ Branch 1 taken 273 times.
✓ Branch 2 taken 1005 times.
|
1278 | false := SCodeUtil.isConnector(re); |
| 2402 | // check empty array dimensions | ||
| 2403 |
1/4✗ Branch 1 not taken.
✓ Branch 2 taken 1005 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
1005 | true := boolOr(valueEq(ad, NONE()), valueEq(ad, SOME({}))); |
| 2404 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1005 times.
|
1005 | (cache,SCode.CLASS(name=cn2,restriction=r,classDef=classDefParent),parentClassEnv) := Lookup.lookupClass(cache, env, cn, SOME(info)); |
| 2405 | |||
| 2406 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1005 times.
|
1005 | false := InstUtil.checkDerivedRestriction(re, r, cn2); |
| 2407 | |||
| 2408 | if match r | ||
| 2409 | case SCode.Restriction.R_PACKAGE() then false; | ||
| 2410 |
5/6✓ Branch 1 taken 867 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 823 times.
✓ Branch 5 taken 44 times.
✓ Branch 7 taken 640 times.
✓ Branch 8 taken 183 times.
|
867 | else if SCodeUtil.restrictionEqual(r,re) then Mod.isInvariantMod(mod) and Mod.isInvariantDAEMod(mods) else false; |
| 2411 | end match then | ||
| 2412 | // Is a very simple modification on an operator record; we do not need to handle it by adding SCode.EXTENDS | ||
| 2413 | // print("Short-circuit: " + SCodeDump.restrString(r)+" "+SCodeDump.restrString(re)+" : "+SCodeDump.printModStr(mod)+"\n"); | ||
| 2414 | |||
| 2415 | // TODO: Is this safe in more cases? | ||
| 2416 | |||
| 2417 | // chain the redeclares | ||
| 2418 | 183 | mod := InstUtil.chainRedeclares(mods, mod); | |
| 2419 | |||
| 2420 | // elab the modifiers in the parent environment!! | ||
| 2421 | 183 | (parentEnv,_) := FGraph.stripLastScopeRef(env); | |
| 2422 | // adrpo: as we do this IN THE SAME ENVIRONMENT (no open scope), clone it before doing changes | ||
| 2423 | // env = FGraph.pushScopeRef(parentEnv, FNode.copyRefNoUpdate(lastRef)); | ||
| 2424 | 183 | (cache, mod_1) := Mod.elabMod(cache, parentEnv, ih, pre, mod, false, Mod.DERIVED(cn), info); | |
| 2425 | // print("mods: " + AbsynUtil.pathString(cn) + " " + Mod.printModStr(mods_1) + "\n"); | ||
| 2426 | 183 | mods_1 := Mod.merge(mods, mod_1, className); | |
| 2427 | |||
| 2428 | 183 | (cache, env, ih, store, dae, csets, ci_state, vars, bc, oDA, eqConstraint, graph) := | |
| 2429 | instClassdef2(cache, parentClassEnv, ih, store, mods_1, pre, ci_state, className, classDefParent, | ||
| 2430 | re /* = r */, | ||
| 2431 | vis, partialPrefix, encapsulatedPrefix, // TODO: Do we need to merge these? | ||
| 2432 | inst_dims, impl, | ||
| 2433 | callscope, graph, inSets, instSingleCref,comment,info,stopInst); | ||
| 2434 | 183 | oDA := SCodeUtil.mergeAttributes(DA,oDA); | |
| 2435 | |||
| 2436 | else | ||
| 2437 | // chain the redeclares | ||
| 2438 | 822 | mod := InstUtil.chainRedeclares(mods, mod); | |
| 2439 | |||
| 2440 | // elab the modifiers in the parent environment!! | ||
| 2441 | 822 | (parentEnv,_) := FGraph.stripLastScopeRef(env); | |
| 2442 | // adrpo: as we do this IN THE SAME ENVIRONMENT (no open scope), clone it before doing changes | ||
| 2443 | // env = FGraph.pushScopeRef(parentEnv, FNode.copyRefNoUpdate(lastRef)); | ||
| 2444 | 822 | (cache, mod_1) := Mod.elabMod(cache, parentEnv, ih, pre, mod, false, Mod.DERIVED(cn), info); | |
| 2445 | // print("mods: " + AbsynUtil.pathString(cn) + " " + Mod.printModStr(mods_1) + "\n"); | ||
| 2446 | 822 | mods_1 := Mod.merge(mods, mod_1, className); | |
| 2447 | |||
| 2448 | 1644 | (cache, env, ih, store, dae, csets, ci_state, vars, bc, oDA, eqConstraint, graph) := | |
| 2449 | instClassdef2(cache, env, ih, store, mods_1, pre, ci_state, className, | ||
| 2450 | SCode.PARTS({SCode.EXTENDS(cn, vis, SCode.NOMOD(), NONE(), info)},{},{},{},{},{},{},NONE()), | ||
| 2451 | re, vis, partialPrefix, encapsulatedPrefix, inst_dims, impl, | ||
| 2452 | callscope, graph, inSets, instSingleCref,comment,info,stopInst); | ||
| 2453 | 821 | oDA := SCodeUtil.mergeAttributes(DA,oDA); | |
| 2454 | end if; | ||
| 2455 | 1004 | then | |
| 2456 | (cache,env,ih,store,dae,csets,ci_state,vars,bc,oDA,eqConstraint,graph); | ||
| 2457 | |||
| 2458 | // This rule describes how to instantiate a derived class definition with array dims | ||
| 2459 | case (cache, env, ih, store, mods, pre, ci_state, SCode.DERIVED(typeSpec=Absyn.TPATH(path = cn,arrayDim = ad),modifications = mod,attributes=DA), re, vis, _, _, inst_dims, impl, callscope, graph, _) | ||
| 2460 | algorithm | ||
| 2461 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 294 times.
|
314 | false := Mutable.access(stopInst); |
| 2462 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 294 times.
|
294 | (cache,(c as SCode.CLASS(name=cn2,encapsulatedPrefix=enc2,restriction=r)),cenv) := Lookup.lookupClass(cache, env, cn, SOME(info)); |
| 2463 | |||
| 2464 | // not a basic type, change class name! | ||
| 2465 |
2/2✓ Branch 1 taken 20 times.
✓ Branch 2 taken 274 times.
|
294 | false := InstUtil.checkDerivedRestriction(re, r, cn2); |
| 2466 | |||
| 2467 | 274 | cenv_2 := FGraph.openScope(cenv, enc2, className, FGraph.classInfToScopeType(ci_state)); | |
| 2468 | 274 | new_ci_state := ClassInfUtil.start(r, FGraph.getGraphName(cenv_2)); | |
| 2469 | |||
| 2470 | 274 | c := SCodeUtil.setClassName(className, c); | |
| 2471 | // chain the redeclares | ||
| 2472 | 274 | mod := InstUtil.chainRedeclares(mods, mod); | |
| 2473 | // elab the modifiers in the parent environment! | ||
| 2474 | 274 | (parentEnv, _) := FGraph.stripLastScopeRef(env); | |
| 2475 | 274 | (cache,mod_1) := Mod.elabMod(cache, parentEnv, ih, pre, mod, impl, Mod.DERIVED(cn), info); | |
| 2476 | 274 | mods_1 := Mod.merge(mods, mod_1, className); | |
| 2477 | 274 | eq := Mod.modEquation(mods_1) "instantiate array dimensions" ; | |
| 2478 | 274 | (cache,dims) := InstUtil.elabArraydimOpt(cache, parentEnv, Absyn.CREF_IDENT("",{}), cn, ad, eq, impl, true, pre, info, inst_dims) "owncref not valid here" ; | |
| 2479 | 274 | inst_dims_1 := List.appendLastList(inst_dims, dims); | |
| 2480 | 274 | (cache,env_2,ih,store,dae,csets_1,ci_state_1,vars,bc,oDA,eqConstraint,graph) := instClassIn(cache, cenv_2, ih, store, mods_1, pre, new_ci_state, c, vis, inst_dims_1, impl, callscope, graph, inSets, instSingleCref) "instantiate class in opened scope. " ; | |
| 2481 | 273 | ClassInfUtil.assertValid(ci_state_1, re, info) "Check for restriction violations" ; | |
| 2482 | 273 | oDA := SCodeUtil.mergeAttributes(DA,oDA); | |
| 2483 | 273 | then | |
| 2484 | (cache,env_2,ih,store,dae,csets_1,ci_state_1,vars,bc,oDA,eqConstraint,graph); | ||
| 2485 | |||
| 2486 | // MetaModelica extension | ||
| 2487 | case (_, _, _, _, mods, _, _, SCode.DERIVED(typeSpec=Absyn.TCOMPLEX(),modifications = mod), _, _, _, _, _, _, _, _, _) | ||
| 2488 | algorithm | ||
| 2489 |
2/2✓ Branch 1 taken 50 times.
✓ Branch 2 taken 21479 times.
|
21529 | true := Config.acceptMetaModelicaGrammar(); |
| 2490 |
2/4✓ Branch 1 taken 21479 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 21479 times.
|
21479 | false := Mod.emptyModOrEquality(mods) and SCodeUtil.emptyModOrEquality(mod); |
| 2491 | ✗ | Error.addSourceMessage(Error.META_COMPLEX_TYPE_MOD, {}, info); | |
| 2492 | ✗ | then fail(); | |
| 2493 | |||
| 2494 | case (cache, env, ih, store, mods, pre, _, SCode.DERIVED(typeSpec=Absyn.TCOMPLEX(Absyn.IDENT("list"),{tSpec},NONE()),modifications = mod, attributes=DA), _, _, _, _, inst_dims, impl, _, graph, _) | ||
| 2495 | algorithm | ||
| 2496 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12054 times.
|
12054 | true := Config.acceptMetaModelicaGrammar(); |
| 2497 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12054 times.
|
12054 | false := Mutable.access(stopInst); |
| 2498 |
2/4✓ Branch 1 taken 12054 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 12054 times.
|
12054 | true := Mod.emptyModOrEquality(mods) and SCodeUtil.emptyModOrEquality(mod); |
| 2499 | 12054 | (cache,_,ih,tys,csets,oDA) := | |
| 2500 | instClassDefHelper(cache,env,ih,{tSpec},pre,inst_dims,impl,{}, inSets,info); | ||
| 2501 | 12054 | ty := listHead(tys); | |
| 2502 | 12054 | ty := Types.boxIfUnboxedType(ty); | |
| 2503 | 12054 | bc := SOME(DAE.T_METALIST(ty)); | |
| 2504 | 12054 | oDA := SCodeUtil.mergeAttributes(DA,oDA); | |
| 2505 | 12054 | then (cache,env,ih,store,DAE.emptyDae,csets,ClassInf.META_LIST(Absyn.IDENT("")),{},bc,oDA,NONE(),graph); | |
| 2506 | |||
| 2507 | case (cache, env, ih, store, mods, pre, _, SCode.DERIVED(typeSpec=Absyn.TCOMPLEX(Absyn.IDENT("Option"),{tSpec},NONE()),modifications = mod, attributes=DA), _, _, _, _, inst_dims, impl, _, graph, _) | ||
| 2508 | algorithm | ||
| 2509 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 5879 times.
|
5879 | true := Config.acceptMetaModelicaGrammar(); |
| 2510 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 5879 times.
|
5879 | false := Mutable.access(stopInst); |
| 2511 |
2/4✓ Branch 1 taken 5879 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 5879 times.
|
5879 | true := Mod.emptyModOrEquality(mods) and SCodeUtil.emptyModOrEquality(mod); |
| 2512 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 5879 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5879 times.
|
5879 | (cache,_,ih,{ty},csets,oDA) := |
| 2513 | instClassDefHelper(cache,env,ih,{tSpec},pre,inst_dims,impl,{}, inSets,info); | ||
| 2514 | 5879 | ty := Types.boxIfUnboxedType(ty); | |
| 2515 | 5879 | bc := SOME(DAE.T_METAOPTION(ty)); | |
| 2516 | 5879 | oDA := SCodeUtil.mergeAttributes(DA,oDA); | |
| 2517 | 5879 | then (cache,env,ih,store,DAE.emptyDae,csets,ClassInf.META_OPTION(Absyn.IDENT("")),{},bc,oDA,NONE(),graph); | |
| 2518 | |||
| 2519 | case (cache, env, ih, store, mods, pre, _, SCode.DERIVED(typeSpec=Absyn.TCOMPLEX(Absyn.IDENT("tuple"),tSpecs,NONE()),modifications = mod, attributes=DA), _, _, _, _, inst_dims, impl, _, graph, _) | ||
| 2520 | algorithm | ||
| 2521 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1249 times.
|
1249 | true := Config.acceptMetaModelicaGrammar(); |
| 2522 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1249 times.
|
1249 | false := Mutable.access(stopInst); |
| 2523 |
2/4✓ Branch 1 taken 1249 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1249 times.
|
1249 | true := Mod.emptyModOrEquality(mods) and SCodeUtil.emptyModOrEquality(mod); |
| 2524 | 1249 | (cache,_,ih,tys,csets,oDA) := instClassDefHelper(cache,env,ih,tSpecs,pre,inst_dims,impl,{}, inSets,info); | |
| 2525 | 1249 | tys := List.map(tys, Types.boxIfUnboxedType); | |
| 2526 | 1249 | bc := SOME(DAE.T_METATUPLE(tys)); | |
| 2527 | 1249 | oDA := SCodeUtil.mergeAttributes(DA,oDA); | |
| 2528 | 1249 | then (cache,env,ih,store,DAE.emptyDae,csets,ClassInf.META_TUPLE(Absyn.IDENT("")),{},bc,oDA,NONE(),graph); | |
| 2529 | |||
| 2530 | case (cache, env, ih, store, mods, pre, _, SCode.DERIVED(typeSpec=Absyn.TCOMPLEX(Absyn.IDENT("array"),{tSpec},NONE()),modifications = mod, attributes=DA), _, _, _, _, inst_dims, impl, _, graph, _) | ||
| 2531 | algorithm | ||
| 2532 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 452 times.
|
452 | true := Config.acceptMetaModelicaGrammar(); |
| 2533 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 452 times.
|
452 | false := Mutable.access(stopInst); |
| 2534 |
2/4✓ Branch 1 taken 452 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 452 times.
|
452 | true := Mod.emptyModOrEquality(mods) and SCodeUtil.emptyModOrEquality(mod); |
| 2535 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 452 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 452 times.
|
452 | (cache,_,ih,{ty},csets,oDA) := instClassDefHelper(cache,env,ih,{tSpec},pre,inst_dims,impl,{}, inSets,info); |
| 2536 | 452 | ty := Types.boxIfUnboxedType(ty); | |
| 2537 | 452 | bc := SOME(DAE.T_METAARRAY(ty)); | |
| 2538 | 452 | oDA := SCodeUtil.mergeAttributes(DA,oDA); | |
| 2539 | 452 | then (cache,env,ih,store,DAE.emptyDae,csets,ClassInf.META_ARRAY(Absyn.IDENT(className)),{},bc,oDA,NONE(),graph); | |
| 2540 | |||
| 2541 | case (cache, env, ih, store, mods, pre, _, SCode.DERIVED(typeSpec=Absyn.TCOMPLEX(Absyn.IDENT("polymorphic"),{Absyn.TPATH(Absyn.IDENT("Any"),NONE())},NONE()),modifications = mod, attributes=DA), _, _, _, _, inst_dims, impl, _, graph, _) | ||
| 2542 | algorithm | ||
| 2543 | // true = Config.acceptMetaModelicaGrammar(); // We use this for builtins also | ||
| 2544 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 929 times.
|
929 | false := Mutable.access(stopInst); |
| 2545 |
2/4✓ Branch 1 taken 929 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 929 times.
|
929 | true := Mod.emptyModOrEquality(mods) and SCodeUtil.emptyModOrEquality(mod); |
| 2546 | 929 | (cache,_,ih,_,csets,oDA) := instClassDefHelper(cache,env,ih,{},pre,inst_dims,impl,{}, inSets,info); | |
| 2547 | 929 | bc := SOME(DAE.T_METAPOLYMORPHIC(className)); | |
| 2548 | 929 | oDA := SCodeUtil.mergeAttributes(DA,oDA); | |
| 2549 | 929 | then (cache,env,ih,store,DAE.emptyDae,csets,ClassInf.META_POLYMORPHIC(Absyn.IDENT(className)),{},bc,oDA,NONE(),graph); | |
| 2550 | |||
| 2551 | case (_, _, _, _, mods, _, _, SCode.DERIVED(typeSpec=Absyn.TCOMPLEX(path=Absyn.IDENT("polymorphic")),modifications=mod), _, _, _, _, _, _, _, _, _) | ||
| 2552 | algorithm | ||
| 2553 | // true = Config.acceptMetaModelicaGrammar(); // We use this for builtins also | ||
| 2554 | ✗ | true := Mod.emptyModOrEquality(mods) and SCodeUtil.emptyModOrEquality(mod); | |
| 2555 | ✗ | Error.addSourceMessage(Error.META_POLYMORPHIC, {className}, info); | |
| 2556 | ✗ | then fail(); | |
| 2557 | |||
| 2558 | case (cache, env, ih, store, mods, pre, ci_state, SCode.DERIVED(typeSpec=Absyn.TCOMPLEX(Absyn.IDENT(str),tSpecs,NONE()),modifications = mod, attributes=DA), re, vis, partialPrefix, encapsulatedPrefix, inst_dims, impl, _, graph, _) | ||
| 2559 | algorithm | ||
| 2560 | 963 | str := Util.assoc(str,{("List","list"),("Tuple","tuple"),("Array","array")}); | |
| 2561 | 867 | (outCache,outEnv,outIH,outStore,outDae,outSets,outState,outTypesVarLst,oty,optDerAttr,outEqualityConstraint,outGraph) | |
| 2562 | := instClassdef2(cache,env,ih,store,mods,pre,ci_state,className,SCode.DERIVED(Absyn.TCOMPLEX(Absyn.IDENT(str),tSpecs,NONE()),mod,DA),re,vis,partialPrefix,encapsulatedPrefix,inst_dims,impl,inCallingScope,graph,inSets,instSingleCref,comment,info,stopInst); | ||
| 2563 | then (outCache,outEnv,outIH,outStore,outDae,outSets,outState,outTypesVarLst,oty,optDerAttr,outEqualityConstraint,outGraph); | ||
| 2564 | |||
| 2565 | case (cache, env, ih, store, mods, pre, _, SCode.DERIVED(typeSpec=Absyn.TCOMPLEX(cn,tSpecs,NONE()),modifications = mod, attributes=DA), _, _, _, _, inst_dims, impl, _, graph, _) | ||
| 2566 | algorithm | ||
| 2567 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 99 times.
|
99 | true := Config.acceptMetaModelicaGrammar(); |
| 2568 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 99 times.
|
99 | false := Mutable.access(stopInst); |
| 2569 |
2/4✓ Branch 1 taken 99 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 99 times.
|
99 | true := Mod.emptyModOrEquality(mods) and SCodeUtil.emptyModOrEquality(mod); |
| 2570 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 99 times.
|
99 | false := listMember(AbsynUtil.pathString(cn), {"tuple","Tuple","array","Array","Option","list","List"}); |
| 2571 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 98 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 98 times.
|
99 | (cache,(SCode.CLASS(name=cn2,restriction=SCode.R_UNIONTYPE(typeVars=typeVars),classDef=classDef)),cenv) := Lookup.lookupClass(cache, env, cn, SOME(info)); |
| 2572 | 98 | (cache,fq_class) := makeFullyQualifiedIdent(cache,cenv,cn2); | |
| 2573 | 98 | new_ci_state := ClassInf.META_UNIONTYPE(fq_class, typeVars); | |
| 2574 |
3/6✗ Branch 1 not taken.
✓ Branch 2 taken 98 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 98 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 98 times.
|
98 | (cache,SOME(ty as DAE.T_METAUNIONTYPE())) := InstMeta.fixUniontype(cache, env, new_ci_state, classDef); |
| 2575 | 98 | (cache,_,ih,tys,csets,oDA) := instClassDefHelper(cache,env,ih,tSpecs,pre,inst_dims,impl,{}, inSets,info); | |
| 2576 |
4/4✓ Branch 0 taken 108 times.
✓ Branch 1 taken 98 times.
✓ Branch 2 taken 108 times.
✓ Branch 3 taken 98 times.
|
206 | tys := list(Types.boxIfUnboxedType(t) for t in tys); |
| 2577 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 98 times.
|
98 | if not (listLength(tys)==listLength(typeVars)) then |
| 2578 | ✗ | Error.addSourceMessage(Error.UNIONTYPE_WRONG_NUM_TYPEVARS,{AbsynUtil.pathString(fq_class),String(listLength(typeVars)),String(listLength(tys))},info); | |
| 2579 | ✗ | fail(); | |
| 2580 | end if; | ||
| 2581 | 98 | ty := Types.setTypeVariables(ty, tys); | |
| 2582 | 98 | oDA := SCodeUtil.mergeAttributes(DA,oDA); | |
| 2583 | bc := SOME(ty); | ||
| 2584 | 98 | then (cache,env,ih,store,DAE.emptyDae,csets,new_ci_state,{},bc,oDA,NONE(),graph); | |
| 2585 | |||
| 2586 | case (_, _, _, _, _, _, _, SCode.DERIVED(typeSpec=tSpec as Absyn.TCOMPLEX(arrayDim=SOME(_))), _, _, _, _, _, _, _, _, _) | ||
| 2587 | algorithm | ||
| 2588 | ✗ | true := Config.acceptMetaModelicaGrammar(); | |
| 2589 | ✗ | cns := Dump.unparseTypeSpec(tSpec); | |
| 2590 | ✗ | Error.addSourceMessage(Error.META_INVALID_COMPLEX_TYPE, {cns}, info); | |
| 2591 | ✗ | then fail(); | |
| 2592 | |||
| 2593 | case (_, _, _, _, _, _, _, SCode.DERIVED(typeSpec=tSpec as Absyn.TCOMPLEX(path=cn,typeSpecs=tSpecs)), _, _, _, _, _, _, _, _, _) | ||
| 2594 | algorithm | ||
| 2595 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
|
1 | true := Config.acceptMetaModelicaGrammar(); |
| 2596 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 time.
|
1 | false := listMember((AbsynUtil.pathString(cn),listLength(tSpecs)==1), {("tuple",false),("array",true),("Option",true),("list",true)}); |
| 2597 | 1 | cns := Dump.unparseTypeSpec(tSpec); | |
| 2598 | 1 | Error.addSourceMessage(Error.META_INVALID_COMPLEX_TYPE, {cns}, info); | |
| 2599 | 1 | then fail(); | |
| 2600 | |||
| 2601 | /* ----------------------- */ | ||
| 2602 | |||
| 2603 | /* If the class is derived from a class that can not be found in the environment, this rule prints an error message. */ | ||
| 2604 | case (cache, env, _, _, _, _, _, SCode.DERIVED(Absyn.TPATH(path = cn)), _, _, _, _, _, _, _, _, _) | ||
| 2605 | algorithm | ||
| 2606 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
|
21 | false := Mutable.access(stopInst); |
| 2607 |
1/2✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
|
21 | failure(Lookup.lookupClass(cache,env, cn)); |
| 2608 | ✗ | cns := AbsynUtil.pathString(cn); | |
| 2609 | ✗ | scope_str := FGraph.printGraphPathStr(env); | |
| 2610 | ✗ | Error.addSourceMessage(Error.LOOKUP_ERROR, {cns,scope_str}, info); | |
| 2611 | ✗ | then | |
| 2612 | fail(); | ||
| 2613 | |||
| 2614 | case (cache, env, _, _, _, _, _, SCode.DERIVED(Absyn.TPATH(path = cn)), _, _, _, _, _, _, _, _, _) | ||
| 2615 | algorithm | ||
| 2616 |
1/2✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
|
21 | true := Flags.isSet(Flags.FAILTRACE); |
| 2617 | ✗ | failure(Lookup.lookupClass(cache,env, cn)); | |
| 2618 | ✗ | Debug.trace("- Inst.instClassdef DERIVED( "); | |
| 2619 | ✗ | Debug.trace(AbsynUtil.pathString(cn)); | |
| 2620 | ✗ | Debug.trace(") lookup failed\n ENV:"); | |
| 2621 | ✗ | Debug.trace(FGraph.printGraphStr(env)); | |
| 2622 | ✗ | then | |
| 2623 | fail(); | ||
| 2624 | |||
| 2625 | else | ||
| 2626 | algorithm | ||
| 2627 |
2/2✓ Branch 1 taken 24865 times.
✓ Branch 2 taken 14 times.
|
24879 | true := Flags.isSet(Flags.FAILTRACE); |
| 2628 | 14 | Debug.traceln("- Inst.instClassdef failed"); | |
| 2629 | 14 | s := FGraph.printGraphPathStr(inEnv); | |
| 2630 | 14 | Debug.traceln(" class :" + s); | |
| 2631 | // Debug.traceln(" Env :" + FGraph.printGraphStr(env)); | ||
| 2632 | 14 | then | |
| 2633 | fail(); | ||
| 2634 | end matchcontinue; | ||
| 2635 | end instClassdef2; | ||
| 2636 | |||
| 2637 | protected function joinExtEquations | ||
| 2638 | input list<SCode.Equation> inEq; | ||
| 2639 | input list<SCode.Equation> inExtEq; | ||
| 2640 | input InstTypes.CallingScope inCallingScope; | ||
| 2641 | output list<SCode.Equation> outEq; | ||
| 2642 | algorithm | ||
| 2643 | outEq := match inCallingScope | ||
| 2644 | case InstTypes.TYPE_CALL() then {}; | ||
| 2645 | 344708 | else listAppend(inEq, inExtEq); | |
| 2646 | end match; | ||
| 2647 | end joinExtEquations; | ||
| 2648 | |||
| 2649 | protected function joinExtAlgorithms | ||
| 2650 | input list<SCode.AlgorithmSection> inAlg; | ||
| 2651 | input list<SCode.AlgorithmSection> inExtAlg; | ||
| 2652 | input InstTypes.CallingScope inCallingScope; | ||
| 2653 | output list<SCode.AlgorithmSection> outAlg; | ||
| 2654 | algorithm | ||
| 2655 | outAlg := match inCallingScope | ||
| 2656 | case InstTypes.TYPE_CALL() then {}; | ||
| 2657 | 344708 | else listAppend(inAlg, inExtAlg); | |
| 2658 | end match; | ||
| 2659 | end joinExtAlgorithms; | ||
| 2660 | |||
| 2661 | protected function instClassDefHelper | ||
| 2662 | "Function: instClassDefHelper | ||
| 2663 | MetaModelica extension. KS TODO: Document this function!!!!" | ||
| 2664 | input FCore.Cache inCache; | ||
| 2665 | input FCore.Graph inEnv; | ||
| 2666 | input InnerOuter.InstHierarchy inIH; | ||
| 2667 | input list<Absyn.TypeSpec> inSpecs; | ||
| 2668 | input DAE.Prefix inPre; | ||
| 2669 | input list<list<DAE.Dimension>> inInstDims; | ||
| 2670 | input Boolean inImpl; | ||
| 2671 | input list<DAE.Type> accTypes; | ||
| 2672 | input Connect.Sets inSets; | ||
| 2673 | input SourceInfo inInfo; | ||
| 2674 | output FCore.Cache outCache; | ||
| 2675 | output FCore.Graph outEnv; | ||
| 2676 | output InnerOuter.InstHierarchy outIH; | ||
| 2677 | output list<DAE.Type> outType; | ||
| 2678 | output Connect.Sets outSets; | ||
| 2679 | output Option<SCode.Attributes> outAttr; | ||
| 2680 | algorithm | ||
| 2681 | (outCache,outEnv,outIH,outType,outSets,outAttr) := | ||
| 2682 | matchcontinue (inCache, inEnv, inIH, inSpecs, inPre, inInstDims, inImpl, accTypes) | ||
| 2683 | local | ||
| 2684 | FCore.Cache cache; | ||
| 2685 | FCore.Graph env,cenv; | ||
| 2686 | DAE.Prefix pre; | ||
| 2687 | InstDims dims; | ||
| 2688 | Boolean impl; | ||
| 2689 | list<DAE.Type> localAccTypes; | ||
| 2690 | list<Absyn.TypeSpec> restTypeSpecs; | ||
| 2691 | Connect.Sets csets; | ||
| 2692 | Absyn.Path cn; | ||
| 2693 | DAE.Type ty; | ||
| 2694 | Absyn.Path p; | ||
| 2695 | SCode.Element c; | ||
| 2696 | Absyn.Ident id; | ||
| 2697 | Absyn.TypeSpec tSpec; | ||
| 2698 | Option<SCode.Attributes> oDA; | ||
| 2699 | InstanceHierarchy ih; | ||
| 2700 | |||
| 2701 | case (cache, env, ih, {}, _, _, _, localAccTypes) | ||
| 2702 | 20661 | then (cache,env,ih,listReverse(localAccTypes),inSets,NONE()); | |
| 2703 | |||
| 2704 | case (cache, env, ih, Absyn.TPATH(cn,_) :: restTypeSpecs, pre, dims, impl, localAccTypes) | ||
| 2705 | algorithm | ||
| 2706 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 19282 times.
|
19403 | (cache,(c as SCode.CLASS()),cenv) := Lookup.lookupClass(cache,env, cn, SOME(inInfo)); |
| 2707 |
2/2✓ Branch 1 taken 121 times.
✓ Branch 2 taken 19161 times.
|
19282 | false := SCodeUtil.isFunction(c); |
| 2708 | 19161 | (cache,cenv,ih,_,_,csets,ty,_,oDA,_):=instClass(cache,cenv,ih,UnitAbsyn.noStore,DAE.NOMOD(),pre,c,dims,impl,InstTypes.INNER_CALL(), ConnectionGraph.EMPTY, inSets); | |
| 2709 | 19161 | localAccTypes := ty::localAccTypes; | |
| 2710 | 19161 | (cache,env,ih,localAccTypes,csets,_) := | |
| 2711 | instClassDefHelper(cache,env,ih,restTypeSpecs,pre,dims,impl,localAccTypes, csets,inInfo); | ||
| 2712 | 19161 | then (cache,env,ih,localAccTypes,csets,oDA); | |
| 2713 | |||
| 2714 | case (cache, env, ih, Absyn.TPATH(cn,_) :: restTypeSpecs, pre, dims, impl, localAccTypes) | ||
| 2715 | algorithm | ||
| 2716 | 121 | (cache,ty,_) := Lookup.lookupType(cache,env,cn,NONE()) "For functions, etc"; | |
| 2717 | 121 | localAccTypes := ty::localAccTypes; | |
| 2718 | 121 | (cache,env,ih,localAccTypes,csets,_) := | |
| 2719 | instClassDefHelper(cache,env,ih,restTypeSpecs,pre,dims,impl,localAccTypes, inSets,inInfo); | ||
| 2720 | 121 | then (cache,env,ih,localAccTypes,csets,NONE()); | |
| 2721 | |||
| 2722 | case (cache, env, ih, (tSpec as Absyn.TCOMPLEX(p,_,_)) :: restTypeSpecs, pre, dims, impl, localAccTypes) | ||
| 2723 | algorithm | ||
| 2724 | 2222 | id:=AbsynUtil.pathString(p); | |
| 2725 | 2222 | c := SCode.CLASS(id,SCode.defaultPrefixes, | |
| 2726 | SCode.NOT_ENCAPSULATED(), | ||
| 2727 | SCode.NOT_PARTIAL(), | ||
| 2728 | SCode.R_TYPE(), | ||
| 2729 | SCode.DERIVED( | ||
| 2730 | tSpec,SCode.NOMOD(), | ||
| 2731 | SCode.ATTR({}, SCode.POTENTIAL(), SCode.NON_PARALLEL(), SCode.VAR(), Absyn.BIDIR(), Absyn.NONFIELD())), | ||
| 2732 | SCode.noComment, | ||
| 2733 | Absyn.dummyInfo); | ||
| 2734 | 2222 | (cache,_,ih,_,_,csets,ty,_,oDA,_):=instClass(cache,env,ih,UnitAbsyn.noStore,DAE.NOMOD(),pre,c,dims,impl,InstTypes.INNER_CALL(), ConnectionGraph.EMPTY, inSets); | |
| 2735 | 2222 | localAccTypes := ty::localAccTypes; | |
| 2736 | 2222 | (cache,env,ih,localAccTypes,csets,_) := | |
| 2737 | instClassDefHelper(cache,env,ih,restTypeSpecs,pre,dims,impl,localAccTypes, csets,inInfo); | ||
| 2738 | 2222 | then (cache,env,ih,localAccTypes,csets,oDA); | |
| 2739 | end matchcontinue; | ||
| 2740 | end instClassDefHelper; | ||
| 2741 | |||
| 2742 | protected function instBasictypeBaseclass | ||
| 2743 | "This function finds the type of classes that extends a basic type. | ||
| 2744 | For instance, | ||
| 2745 | connector RealSignal | ||
| 2746 | extends SignalType; | ||
| 2747 | replaceable type SignalType = Real; | ||
| 2748 | end RealSignal; | ||
| 2749 | Such classes can not have any other components, | ||
| 2750 | and can only inherit one basic type." | ||
| 2751 | input FCore.Cache inCache; | ||
| 2752 | input FCore.Graph inEnv; | ||
| 2753 | input InnerOuter.InstHierarchy inIH; | ||
| 2754 | input UnitAbsyn.InstStore inStore; | ||
| 2755 | input list<SCode.Element> inSCodeElementLst2; | ||
| 2756 | input list<SCode.Element> inSCodeElementLst3; | ||
| 2757 | input DAE.Mod inMod4; | ||
| 2758 | input list<list<DAE.Dimension>> inInstDims5; | ||
| 2759 | input String className; | ||
| 2760 | input SourceInfo info; | ||
| 2761 | input Mutable<Boolean> stopInst "prevent instantiation of classes adding components to primary types"; | ||
| 2762 | output FCore.Cache outCache; | ||
| 2763 | output InnerOuter.InstHierarchy outIH; | ||
| 2764 | output UnitAbsyn.InstStore outStore; | ||
| 2765 | output DAE.DAElist outDae "contain functions"; | ||
| 2766 | output Option<DAE.Type> outTypesTypeOption; | ||
| 2767 | output list<DAE.Var> outTypeVars; | ||
| 2768 | algorithm | ||
| 2769 | (outCache,outIH,outStore,outDae,outTypesTypeOption,outTypeVars) := | ||
| 2770 | matchcontinue (inCache, inEnv, inIH, inStore, inSCodeElementLst2, inSCodeElementLst3, inMod4, inInstDims5) | ||
| 2771 | local | ||
| 2772 | DAE.Mod m_1,m_2,mods; | ||
| 2773 | SCode.Element cdef; | ||
| 2774 | FCore.Graph cenv,env; | ||
| 2775 | DAE.DAElist dae; | ||
| 2776 | DAE.Type ty; | ||
| 2777 | list<DAE.Var> tys; | ||
| 2778 | Boolean b1,b2,b3; | ||
| 2779 | Absyn.Path path; | ||
| 2780 | SCode.Mod mod; | ||
| 2781 | InstDims inst_dims; | ||
| 2782 | FCore.Cache cache; | ||
| 2783 | InstanceHierarchy ih; | ||
| 2784 | UnitAbsyn.InstStore store; | ||
| 2785 | |||
| 2786 | case (cache, env, ih, store, {SCode.EXTENDS(baseClassPath = path,modifications = mod)}, {}, mods, inst_dims) | ||
| 2787 | algorithm | ||
| 2788 | //Debug.traceln("Try instbasic 1 " + AbsynUtil.pathString(path)); | ||
| 2789 | 4210 | ErrorExt.setCheckpoint("instBasictypeBaseclass"); | |
| 2790 | 4210 | (cache,m_1) := Mod.elabModForBasicType(cache, env, ih, DAE.NOPRE(), mod, true, Mod.DERIVED(path), info); | |
| 2791 | 4210 | m_2 := Mod.merge(mods, m_1, className); | |
| 2792 | 4210 | (cache,cdef,cenv) := Lookup.lookupClass(cache,env, path, SOME(info)); | |
| 2793 | //Debug.traceln("Try instbasic 2 " + AbsynUtil.pathString(path) + " " + Mod.printModStr(m_2)); | ||
| 2794 | 4210 | (cache,_,ih,store,dae,_,ty,tys,_) := | |
| 2795 | instClassBasictype(cache,cenv,ih, store,m_2, DAE.NOPRE(), cdef, inst_dims, false, InstTypes.INNER_CALL(), Connect.emptySet); | ||
| 2796 | //Debug.traceln("Try instbasic 3 " + AbsynUtil.pathString(path) + " " + Mod.printModStr(m_2)); | ||
| 2797 | 4209 | b1 := Types.basicType(ty); | |
| 2798 | 4209 | b2 := Types.arrayType(ty); | |
| 2799 | 4209 | b3 := Types.extendsBasicType(ty); | |
| 2800 |
4/4✓ Branch 0 taken 375 times.
✓ Branch 1 taken 3834 times.
✓ Branch 2 taken 125 times.
✓ Branch 3 taken 250 times.
|
4209 | true := boolOr(b1, boolOr(b2, b3)); |
| 2801 | |||
| 2802 | 4084 | ErrorExt.rollBack("instBasictypeBaseclass"); | |
| 2803 |
1/2✓ Branch 1 taken 4084 times.
✗ Branch 2 not taken.
|
4084 | then |
| 2804 | (cache,ih,store,dae,SOME(ty),tys); | ||
| 2805 | |||
| 2806 | case (_, _, _, _, {SCode.EXTENDS(baseClassPath = path)}, {}, _, _) | ||
| 2807 | algorithm | ||
| 2808 | 126 | rollbackCheck(path) "only rollback errors affecting basic types"; | |
| 2809 | 126 | then fail(); | |
| 2810 | |||
| 2811 | /* Inherits baseclass -and- has components */ | ||
| 2812 | case (cache, env, ih, store, {SCode.EXTENDS()}, _, mods, inst_dims) | ||
| 2813 | algorithm | ||
| 2814 |
1/2✓ Branch 0 taken 126 times.
✗ Branch 1 not taken.
|
126 | false := (listEmpty(inSCodeElementLst3)); |
| 2815 | ✗ | ErrorExt.setCheckpoint("instBasictypeBaseclass2") "rolled back or deleted inside call below"; | |
| 2816 | ✗ | instBasictypeBaseclass2(cache,env,ih,store,inSCodeElementLst2,inSCodeElementLst3,mods,inst_dims,className,info,stopInst); | |
| 2817 | ✗ | then | |
| 2818 | fail(); | ||
| 2819 | end matchcontinue; | ||
| 2820 | end instBasictypeBaseclass; | ||
| 2821 | |||
| 2822 | protected function rollbackCheck " | ||
| 2823 | Author BZ 2009-08 | ||
| 2824 | Rollsback errors on builtin classes and deletes checkpoint for other classes." | ||
| 2825 | input Absyn.Path p; | ||
| 2826 | algorithm () := matchcontinue p | ||
| 2827 | local String n; | ||
| 2828 | case _ | ||
| 2829 | algorithm | ||
| 2830 | 126 | n := AbsynUtil.pathString(p); | |
| 2831 |
1/2✓ Branch 1 taken 126 times.
✗ Branch 2 not taken.
|
126 | true := InstUtil.isBuiltInClass(n); |
| 2832 | ✗ | ErrorExt.rollBack("instBasictypeBaseclass"); | |
| 2833 | then (); | ||
| 2834 | case _ | ||
| 2835 | algorithm | ||
| 2836 | 126 | ErrorExt.rollBack("instBasictypeBaseclass"); // ErrorExt.delCheckpoint("instBasictypeBaseclass"); | |
| 2837 | then (); | ||
| 2838 | end matchcontinue; | ||
| 2839 | end rollbackCheck; | ||
| 2840 | |||
| 2841 | protected function instBasictypeBaseclass2 " | ||
| 2842 | Author: BZ, 2009-02 | ||
| 2843 | Helper function for instBasictypeBaseClass | ||
| 2844 | Handles the fail case rollbacks/deleteCheckpoint of errors." | ||
| 2845 | input FCore.Cache inCache; | ||
| 2846 | input FCore.Graph inEnv1; | ||
| 2847 | input InnerOuter.InstHierarchy inIH; | ||
| 2848 | input UnitAbsyn.InstStore store; | ||
| 2849 | input list<SCode.Element> inSCodeElementLst2; | ||
| 2850 | input list<SCode.Element> inSCodeElementLst3; | ||
| 2851 | input DAE.Mod inMod4; | ||
| 2852 | input list<list<DAE.Dimension>> inInstDims5; | ||
| 2853 | input String className; | ||
| 2854 | input SourceInfo inInfo; | ||
| 2855 | input Mutable<Boolean> stopInst "prevent instantiation of classes adding components to primary types"; | ||
| 2856 | algorithm | ||
| 2857 | () := matchcontinue(inCache, inEnv1, inIH, inSCodeElementLst2, inSCodeElementLst3, inInstDims5) | ||
| 2858 | local | ||
| 2859 | DAE.Mod m_1; | ||
| 2860 | SCode.Element cdef,cdef_1; | ||
| 2861 | FCore.Graph cenv,env; | ||
| 2862 | DAE.Type ty; | ||
| 2863 | Boolean b1,b2; | ||
| 2864 | Absyn.Path path; | ||
| 2865 | SCode.Mod mod; | ||
| 2866 | InstDims inst_dims; | ||
| 2867 | String classname; | ||
| 2868 | FCore.Cache cache; | ||
| 2869 | InstanceHierarchy ih; | ||
| 2870 | SourceInfo info; | ||
| 2871 | |||
| 2872 | case (cache, env, ih, {SCode.EXTENDS(baseClassPath = path,modifications = mod, info = info)}, (_ :: _), inst_dims) /* Inherits baseclass -and- has components */ | ||
| 2873 | algorithm | ||
| 2874 | ✗ | (cache,m_1) := Mod.elabModForBasicType(cache, env, ih, DAE.NOPRE(), mod, true, Mod.DERIVED(path), inInfo); | |
| 2875 | ✗ | (cache,cdef,cenv) := Lookup.lookupClass(cache,env, path, SOME(info)); | |
| 2876 | ✗ | cdef_1 := SCodeUtil.classSetPartial(cdef, SCode.NOT_PARTIAL()); | |
| 2877 | |||
| 2878 | ✗ | (cache,_,ih,_,_,_,ty,_,_,_) := instClass(cache,cenv,ih,store, m_1, | |
| 2879 | DAE.NOPRE(), cdef_1, inst_dims, false, InstTypes.INNER_CALL(), ConnectionGraph.EMPTY, Connect.emptySet) "impl" ; | ||
| 2880 | |||
| 2881 | ✗ | b1 := Types.basicType(ty); | |
| 2882 | ✗ | b2 := Types.arrayType(ty); | |
| 2883 | ✗ | true := boolOr(b1, b2); | |
| 2884 | ✗ | classname := FGraph.printGraphPathStr(env); | |
| 2885 | ✗ | ErrorExt.rollBack("instBasictypeBaseclass2"); | |
| 2886 | ✗ | Error.addSourceMessage(Error.INHERIT_BASIC_WITH_COMPS, {classname}, inInfo); | |
| 2887 | ✗ | Mutable.update(stopInst,true); | |
| 2888 | then | ||
| 2889 | (); | ||
| 2890 | |||
| 2891 | // if not error above, then do not report error at all, try another case in instClassdef. | ||
| 2892 | else | ||
| 2893 | algorithm | ||
| 2894 | ✗ | ErrorExt.rollBack("instBasictypeBaseclass2"); | |
| 2895 | then (); | ||
| 2896 | end matchcontinue; | ||
| 2897 | end instBasictypeBaseclass2; | ||
| 2898 | |||
| 2899 | protected function partialInstClassdef | ||
| 2900 | "This function is used by partialInstClassIn for instantiating local class | ||
| 2901 | definitions and inherited class definitions only." | ||
| 2902 | input FCore.Cache inCache; | ||
| 2903 | input FCore.Graph inEnv; | ||
| 2904 | input InnerOuter.InstHierarchy inIH; | ||
| 2905 | input DAE.Mod inMod; | ||
| 2906 | input DAE.Prefix inPrefix; | ||
| 2907 | input ClassInf.State inState; | ||
| 2908 | input SCode.Element inClass "The class this definition comes from."; | ||
| 2909 | input SCode.ClassDef inClassDef; | ||
| 2910 | input SCode.Visibility inVisibility; | ||
| 2911 | input list<list<DAE.Dimension>> inInstDims; | ||
| 2912 | input Integer numIter; | ||
| 2913 | output FCore.Cache outCache; | ||
| 2914 | output FCore.Graph outEnv; | ||
| 2915 | output InnerOuter.InstHierarchy outIH; | ||
| 2916 | output ClassInf.State outState; | ||
| 2917 | output list<DAE.Var> outVars; | ||
| 2918 | algorithm | ||
| 2919 | (outCache, outEnv, outIH, outState, outVars) := match inClassDef | ||
| 2920 | local | ||
| 2921 | SCode.Partial partial_prefix; | ||
| 2922 | String class_name, scope_str; | ||
| 2923 | list<SCode.Element> cdef_els, class_ext_els, extends_els; | ||
| 2924 | DAE.Mod emods, mod; | ||
| 2925 | SCode.Mod class_mod, smod; | ||
| 2926 | list<tuple<SCode.Element, DAE.Mod>> ext_comps, const_els; | ||
| 2927 | Absyn.Path class_path; | ||
| 2928 | Option<list<Absyn.Subscript>> class_dims; | ||
| 2929 | SCode.Element cls; | ||
| 2930 | SCode.ClassDef cdef; | ||
| 2931 | FCore.Graph cenv, parent_env; | ||
| 2932 | SCode.Restriction der_re, parent_re; | ||
| 2933 | SCode.Encapsulated enc; | ||
| 2934 | SourceInfo info; | ||
| 2935 | Option<DAE.EqMod> eq; | ||
| 2936 | list<DAE.Dimension> dims = {}; | ||
| 2937 | Boolean has_dims, is_basic_type; | ||
| 2938 | InstDims inst_dims; | ||
| 2939 | Option<FCore.ScopeType> scope_ty; | ||
| 2940 | |||
| 2941 | case SCode.PARTS() | ||
| 2942 | algorithm | ||
| 2943 | 42445 | partial_prefix := SCodeUtil.getClassPartialPrefix(inClass); | |
| 2944 | 42445 | partial_prefix := InstUtil.isPartial(partial_prefix, inMod); | |
| 2945 | 42445 | class_name := SCodeUtil.elementName(inClass); | |
| 2946 | 42445 | outState := ClassInfUtil.trans(inState, ClassInf.NEWDEF()); | |
| 2947 | |||
| 2948 | 42445 | (cdef_els, class_ext_els, extends_els) := InstUtil.splitElts(inClassDef.elementLst); | |
| 2949 | 42445 | extends_els := SCodeInstUtil.addRedeclareAsElementsToExtends(extends_els, | |
| 2950 | List.select(inClassDef.elementLst, SCodeUtil.isRedeclareElement)); | ||
| 2951 | |||
| 2952 | // Classes and imports are added to env. | ||
| 2953 | 84890 | (outCache, outEnv, outIH) := InstUtil.addClassdefsToEnv(inCache, inEnv, | |
| 2954 | inIH, inPrefix, cdef_els, true, SOME(inMod), FGraph.isEmptyScope(inEnv)); | ||
| 2955 | // Inherited elements are added to env. | ||
| 2956 | 42445 | (outCache, outEnv, outIH, emods, ext_comps) := InstExtends.instExtendsAndClassExtendsList( | |
| 2957 | outCache, outEnv, outIH, inMod, inPrefix, extends_els, class_ext_els, | ||
| 2958 | inClassDef.elementLst, inState, class_name, true, true); | ||
| 2959 | |||
| 2960 | // If we partially instantiate a partial package, we filter out | ||
| 2961 | // constants (maybe we should also filter out functions) /sjoelund | ||
| 2962 | 42445 | const_els := listAppend(ext_comps, | |
| 2963 | InstUtil.addNomod(InstUtil.constantEls(inClassDef.elementLst))); | ||
| 2964 | |||
| 2965 | // Since partial instantiation is done in lookup, we need to add | ||
| 2966 | // inherited classes here. Otherwise when looking up e.g. A.B where A | ||
| 2967 | // inherits the definition of B, and without having a base class context | ||
| 2968 | // (since we do not have any element to find it in), the class must be | ||
| 2969 | // added to the environment here. | ||
| 2970 | |||
| 2971 | 42445 | mod := Mod.merge(inMod, emods, class_name); | |
| 2972 | |||
| 2973 | 42445 | (cdef_els, ext_comps) := InstUtil.classdefElts2(ext_comps, partial_prefix); | |
| 2974 | 42445 | (outCache, outEnv, outIH) := InstUtil.addClassdefsToEnv(outCache, | |
| 2975 | outEnv, outIH, inPrefix, cdef_els, true, SOME(mod)); | ||
| 2976 | |||
| 2977 | // Add inherited classes to env. | ||
| 2978 | 42445 | (outCache, outEnv, outIH) := InstUtil.addComponentsToEnv(outCache, | |
| 2979 | outEnv, outIH, mod, inPrefix, inState, const_els, false); | ||
| 2980 | |||
| 2981 | // Instantiate constants. | ||
| 2982 | 42445 | (outCache, outEnv, outIH, _, _, _, outState, outVars, _, _) := instElementList( | |
| 2983 | outCache, outEnv, outIH, UnitAbsyn.noStore, mod, inPrefix, outState, | ||
| 2984 | const_els, inInstDims, true, InstTypes.INNER_CALL(), | ||
| 2985 | ConnectionGraph.EMPTY, Connect.emptySet, false); | ||
| 2986 | 42305 | then | |
| 2987 | (outCache, outEnv, outIH, outState, outVars); | ||
| 2988 | |||
| 2989 | case SCode.DERIVED(typeSpec = Absyn.TPATH(path = class_path, arrayDim = class_dims), | ||
| 2990 | modifications = class_mod) | ||
| 2991 | algorithm | ||
| 2992 | 167 | info := SCodeUtil.elementInfo(inClass); | |
| 2993 |
2/6✗ Branch 0 not taken.
✓ Branch 1 taken 167 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 167 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
167 | has_dims := not (isNone(class_dims) or valueEq(class_dims, SOME({}))); |
| 2994 | |||
| 2995 | try | ||
| 2996 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 167 times.
|
167 | (outCache, cls as SCode.CLASS(), cenv) := |
| 2997 | Lookup.lookupClass(inCache, inEnv, class_path, SOME(info)); | ||
| 2998 | else | ||
| 2999 | ✗ | class_name := AbsynUtil.pathString(class_path); | |
| 3000 | ✗ | scope_str := FGraph.printGraphPathStr(inEnv); | |
| 3001 | ✗ | Error.addSourceMessageAndFail(Error.LOOKUP_ERROR, {class_name, scope_str}, info); | |
| 3002 | end try; | ||
| 3003 | |||
| 3004 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 167 times.
|
167 | SCode.CLASS(name = class_name, encapsulatedPrefix = enc, restriction = der_re) := cls; |
| 3005 | 167 | parent_re := SCodeUtil.getClassRestriction(inClass); | |
| 3006 | 167 | is_basic_type := InstUtil.checkDerivedRestriction(parent_re, der_re, class_name); | |
| 3007 | |||
| 3008 | 167 | smod := InstUtil.chainRedeclares(inMod, class_mod); | |
| 3009 | |||
| 3010 | // The mod is elaborated in the parent of this class. | ||
| 3011 | 167 | parent_env := FGraph.stripLastScopeRef(inEnv); | |
| 3012 | 167 | (outCache, mod) := Mod.elabMod(outCache, parent_env, inIH, inPrefix, | |
| 3013 | smod, false, Mod.DERIVED(class_path), info); | ||
| 3014 | 167 | mod := Mod.merge(inMod, mod, class_name); | |
| 3015 | |||
| 3016 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 167 times.
|
167 | if has_dims and not is_basic_type then |
| 3017 | ✗ | cls := SCodeUtil.setClassName(class_name, cls); | |
| 3018 | ✗ | eq := Mod.modEquation(mod); | |
| 3019 | ✗ | (outCache, dims) := InstUtil.elabArraydimOpt(outCache, parent_env, | |
| 3020 | Absyn.CREF_IDENT("", {}), class_path, class_dims, eq, false, | ||
| 3021 | true, inPrefix, info, inInstDims); | ||
| 3022 | ✗ | inst_dims := List.appendLastList(inInstDims, dims); | |
| 3023 | else | ||
| 3024 | inst_dims := inInstDims; | ||
| 3025 | end if; | ||
| 3026 | |||
| 3027 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 167 times.
|
167 | if is_basic_type or has_dims then |
| 3028 | ✗ | scope_ty := if is_basic_type then FGraph.restrictionToScopeType(der_re) else | |
| 3029 | FGraph.classInfToScopeType(inState); | ||
| 3030 | ✗ | cenv := FGraph.openScope(cenv, enc, class_name, scope_ty); | |
| 3031 | ✗ | outState := ClassInfUtil.start(der_re, FGraph.getGraphName(cenv)); | |
| 3032 | ✗ | (outCache, outEnv, outIH, outState, outVars) := | |
| 3033 | partialInstClassIn(outCache, cenv, inIH, mod, inPrefix, outState, cls, | ||
| 3034 | inVisibility, inst_dims, numIter); | ||
| 3035 | else | ||
| 3036 | 334 | cdef := SCode.PARTS({SCode.EXTENDS(class_path, inVisibility, | |
| 3037 | SCode.NOMOD(), NONE(), info)}, {}, {}, {}, {}, {}, {}, NONE()); | ||
| 3038 | 167 | (outCache, outEnv, outIH, outState, outVars) := | |
| 3039 | partialInstClassdef(outCache, inEnv, inIH, mod, inPrefix, inState, | ||
| 3040 | inClass, cdef, inVisibility, inInstDims, numIter); | ||
| 3041 | end if; | ||
| 3042 | |||
| 3043 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 167 times.
|
167 | if SCodeUtil.isPartial(cls) then |
| 3044 | ✗ | outEnv := FGraph.makeScopePartial(inEnv); | |
| 3045 | end if; | ||
| 3046 | 167 | then | |
| 3047 | (outCache, outEnv, outIH, outState, outVars); | ||
| 3048 | |||
| 3049 | end match; | ||
| 3050 | end partialInstClassdef; | ||
| 3051 | |||
| 3052 | public function instElementList | ||
| 3053 | "Instantiates a list of elements." | ||
| 3054 | input FCore.Cache inCache; | ||
| 3055 | input FCore.Graph inEnv; | ||
| 3056 | input InnerOuter.InstHierarchy inIH; | ||
| 3057 | input UnitAbsyn.InstStore inStore; | ||
| 3058 | input DAE.Mod inMod; | ||
| 3059 | input DAE.Prefix inPrefix; | ||
| 3060 | input ClassInf.State inState; | ||
| 3061 | input list<tuple<SCode.Element, DAE.Mod>> inElements; | ||
| 3062 | input list<list<DAE.Dimension>> inInstDims; | ||
| 3063 | input Boolean inImplInst; | ||
| 3064 | input InstTypes.CallingScope inCallingScope; | ||
| 3065 | input ConnectionGraph.ConnectionGraph inGraph; | ||
| 3066 | input Connect.Sets inSets; | ||
| 3067 | input Boolean inStopOnError; | ||
| 3068 | output FCore.Cache outCache = inCache; | ||
| 3069 | output FCore.Graph outEnv = inEnv; | ||
| 3070 | output InnerOuter.InstHierarchy outIH = inIH; | ||
| 3071 | output UnitAbsyn.InstStore outStore = inStore; | ||
| 3072 | output DAE.DAElist outDae; | ||
| 3073 | output Connect.Sets outSets = inSets; | ||
| 3074 | output ClassInf.State outState = inState; | ||
| 3075 | output list<DAE.Var> outVars; | ||
| 3076 | output ConnectionGraph.ConnectionGraph outGraph = inGraph; | ||
| 3077 | //output List<tuple<Absyn.ComponentRef,DAE.ComponentRef>> fieldDomLst = {}; | ||
| 3078 | output InstUtil.DomainFieldsLst domainFieldsListOut = {}; | ||
| 3079 | protected | ||
| 3080 | list<tuple<SCode.Element, DAE.Mod>> el; | ||
| 3081 | FCore.Cache cache; | ||
| 3082 | list<DAE.Var> vars; | ||
| 3083 | list<DAE.Element> dae; | ||
| 3084 | list<list<DAE.Var>> varsl = {}; | ||
| 3085 | list<list<DAE.Element>> dael = {}; | ||
| 3086 | InstUtil.DomainFieldOpt fieldDomOpt; | ||
| 3087 | list<Integer> element_order; | ||
| 3088 | array<tuple<SCode.Element, DAE.Mod>> el_arr; | ||
| 3089 | array<list<DAE.Var>> var_arr; | ||
| 3090 | array<list<DAE.Element>> dae_arr; | ||
| 3091 | Integer length; | ||
| 3092 | algorithm | ||
| 3093 | 278992 | cache := InstUtil.pushStructuralParameters(inCache); | |
| 3094 | |||
| 3095 | // Sort elements based on their dependencies. This is not done for MetaModelica | ||
| 3096 | 278992 | el := InstUtil.sortElementList(inElements, inEnv, FGraph.inFunctionScope(inEnv)); | |
| 3097 | // adrpo: MAKE SURE inner objects ARE FIRST in the list for instantiation! | ||
| 3098 | 278850 | el := InstUtil.sortInnerFirstTplLstElementMod(el); | |
| 3099 | |||
| 3100 | // For non-functions, don't reorder the elements. | ||
| 3101 |
2/2✓ Branch 1 taken 183436 times.
✓ Branch 2 taken 95414 times.
|
278850 | if not ClassInfUtil.isFunction(inState) then |
| 3102 | // Figure out the ordering of the sorted elements, see getSortedElementOrdering. | ||
| 3103 | 183436 | element_order := getSortedElementOrdering(inElements, el); | |
| 3104 | |||
| 3105 | // Create arrays so that we can instantiate the elements in the sorted order, | ||
| 3106 | // while keeping the result in the same order as the elements are declared in. | ||
| 3107 | 183436 | el_arr := listArray(inElements); | |
| 3108 | 183436 | length := listLength(el); | |
| 3109 | 183436 | var_arr := arrayCreate(length, {}); | |
| 3110 | 183436 | dae_arr := arrayCreate(length, {}); | |
| 3111 | |||
| 3112 | // Instantiate the elements. | ||
| 3113 |
2/2✓ Branch 0 taken 908134 times.
✓ Branch 1 taken 183342 times.
|
1091476 | for idx in element_order loop |
| 3114 | 908134 | (cache, outEnv, outIH, outStore, dae, outSets, outState, vars, outGraph, fieldDomOpt) := | |
| 3115 | instElement2(cache, outEnv, outIH, outStore, inMod, inPrefix, outState, el_arr[idx], | ||
| 3116 | inInstDims, inImplInst, inCallingScope, outGraph, outSets, inStopOnError); | ||
| 3117 | // Store the elements in reverse order to make the list flattening simpler | ||
| 3118 | 908040 | arrayUpdate(var_arr, length-idx+1, vars); | |
| 3119 | 908040 | arrayUpdate(dae_arr, length-idx+1, dae); | |
| 3120 |
2/2✓ Branch 1 taken 26 times.
✓ Branch 2 taken 908014 times.
|
908040 | if intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PDEMODELICA) then |
| 3121 | 26 | domainFieldsListOut := InstUtil.optAppendField(domainFieldsListOut,fieldDomOpt); | |
| 3122 | end if; | ||
| 3123 | end for; | ||
| 3124 | |||
| 3125 |
4/4✓ Branch 0 taken 907834 times.
✓ Branch 1 taken 183342 times.
✓ Branch 3 taken 907834 times.
✓ Branch 4 taken 183342 times.
|
1091176 | outVars := listAppend(lst for lst in var_arr); |
| 3126 |
4/4✓ Branch 0 taken 907834 times.
✓ Branch 1 taken 183342 times.
✓ Branch 3 taken 907834 times.
✓ Branch 4 taken 183342 times.
|
1091176 | outDae := DAE.DAE(listAppend(lst for lst in dae_arr)); |
| 3127 | 183342 | GCExt.free(var_arr); | |
| 3128 | 183342 | GCExt.free(dae_arr); | |
| 3129 | else | ||
| 3130 | // For functions, use the sorted elements instead, otherwise things break. | ||
| 3131 |
2/2✓ Branch 0 taken 263000 times.
✓ Branch 1 taken 77194 times.
|
340194 | for e in el loop |
| 3132 | 263000 | (cache, outEnv, outIH, outStore, dae, outSets, outState, vars, outGraph, fieldDomOpt) := | |
| 3133 | instElement2(cache, outEnv, outIH, outStore, inMod, inPrefix, outState, e, | ||
| 3134 | inInstDims, inImplInst, inCallingScope, outGraph, outSets, inStopOnError); | ||
| 3135 | 244780 | varsl := vars :: varsl; | |
| 3136 | 244780 | dael := dae :: dael; | |
| 3137 | end for; | ||
| 3138 | |||
| 3139 | 77194 | outVars := List.flattenReverse(varsl); | |
| 3140 | 77194 | outDae := DAE.DAE(List.flattenReverse(dael)); | |
| 3141 | end if; | ||
| 3142 | |||
| 3143 | 260536 | outCache := InstUtil.popStructuralParameters(cache,inPrefix); | |
| 3144 | end instElementList; | ||
| 3145 | |||
| 3146 | protected function getSortedElementOrdering | ||
| 3147 | "Takes a list of unsorted elements and a list of sorted elements, and returns | ||
| 3148 | a list of the sorted elements indices in the unsorted list. E.g.: | ||
| 3149 | getSortedElementOrdering({a, b, c}, {b, c, a}) => {2, 3, 1}" | ||
| 3150 | input list<tuple<SCode.Element, DAE.Mod>> inElements; | ||
| 3151 | input list<tuple<SCode.Element, DAE.Mod>> inSortedElements; | ||
| 3152 | output list<Integer> outIndices = {}; | ||
| 3153 | protected | ||
| 3154 | list<tuple<SCode.Element, Integer>> index_map = {}; | ||
| 3155 | list<SCode.Element> sorted_el; | ||
| 3156 | Integer i = 1; | ||
| 3157 | algorithm | ||
| 3158 | // Pair each unsorted element with its index in the list. | ||
| 3159 |
2/2✓ Branch 1 taken 908169 times.
✓ Branch 2 taken 183436 times.
|
1091605 | for e in inElements loop |
| 3160 | 908169 | index_map := (Util.tuple21(e), i) :: index_map; | |
| 3161 | 908169 | i := i + 1; | |
| 3162 | end for; | ||
| 3163 | 183436 | index_map := listReverse(index_map); | |
| 3164 | |||
| 3165 | // Loop through the sorted elements. | ||
| 3166 |
4/4✓ Branch 0 taken 908169 times.
✓ Branch 1 taken 183436 times.
✓ Branch 2 taken 908169 times.
✓ Branch 3 taken 183436 times.
|
1091605 | sorted_el := list(Util.tuple21(e) for e in inSortedElements); |
| 3167 |
2/2✓ Branch 0 taken 908169 times.
✓ Branch 1 taken 183436 times.
|
1091605 | for e in sorted_el loop |
| 3168 | // Remove the element from the index map, and add its index to the list of | ||
| 3169 | // indices. Elements are usually not reordered much, so most of the time the | ||
| 3170 | // sought after element should be first in the list. | ||
| 3171 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 908169 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 908169 times.
|
908169 | (index_map, SOME((_, i))) := |
| 3172 | List.deleteMemberOnTrue(e, index_map, getSortedElementOrdering_comp); | ||
| 3173 | outIndices := i :: outIndices; | ||
| 3174 | end for; | ||
| 3175 | |||
| 3176 | 183436 | outIndices := listReverse(outIndices); | |
| 3177 | end getSortedElementOrdering; | ||
| 3178 | |||
| 3179 | protected function getSortedElementOrdering_comp | ||
| 3180 | input SCode.Element inElement1; | ||
| 3181 | input tuple<SCode.Element, Integer> inElement2; | ||
| 3182 | output Boolean outEqual = SCodeUtil.elementNameEqual(inElement1, Util.tuple21(inElement2)); | ||
| 3183 | end getSortedElementOrdering_comp; | ||
| 3184 | |||
| 3185 | public function instElement2 | ||
| 3186 | input FCore.Cache inCache; | ||
| 3187 | input FCore.Graph inEnv; | ||
| 3188 | input InnerOuter.InstHierarchy inIH; | ||
| 3189 | input UnitAbsyn.InstStore inStore; | ||
| 3190 | input DAE.Mod inMod; | ||
| 3191 | input DAE.Prefix inPrefix; | ||
| 3192 | input ClassInf.State inState; | ||
| 3193 | input tuple<SCode.Element, DAE.Mod> inElement; | ||
| 3194 | input list<list<DAE.Dimension>> inInstDims; | ||
| 3195 | input Boolean inImplicit; | ||
| 3196 | input InstTypes.CallingScope inCallingScope; | ||
| 3197 | input ConnectionGraph.ConnectionGraph inGraph; | ||
| 3198 | input Connect.Sets inSets; | ||
| 3199 | input Boolean inStopOnError; | ||
| 3200 | output FCore.Cache outCache; | ||
| 3201 | output FCore.Graph outEnv; | ||
| 3202 | output InnerOuter.InstHierarchy outIH = inIH; | ||
| 3203 | output UnitAbsyn.InstStore outStore = inStore; | ||
| 3204 | output list<DAE.Element> outDae = {}; | ||
| 3205 | output Connect.Sets outSets = inSets; | ||
| 3206 | output ClassInf.State outState = inState; | ||
| 3207 | output list<DAE.Var> outVars = {}; | ||
| 3208 | output ConnectionGraph.ConnectionGraph outGraph = inGraph; | ||
| 3209 | output InstUtil.DomainFieldOpt outFieldDomOpt = NONE(); | ||
| 3210 | protected | ||
| 3211 | tuple<SCode.Element, DAE.Mod> elt; | ||
| 3212 | Boolean is_deleted; | ||
| 3213 | algorithm | ||
| 3214 | // Check if the component has a conditional expression that evaluates to false. | ||
| 3215 | 1171134 | (is_deleted, outEnv, outCache) := isDeletedComponent(inElement, inPrefix, | |
| 3216 | inStopOnError, inEnv, inCache); | ||
| 3217 | |||
| 3218 | // Skip the component if it was deleted by a conditional expression. | ||
| 3219 |
2/2✓ Branch 0 taken 972 times.
✓ Branch 1 taken 1170162 times.
|
1171134 | if is_deleted then |
| 3220 | 972 | return; | |
| 3221 | end if; | ||
| 3222 | |||
| 3223 | try // Try to instantiate the element. | ||
| 3224 | 1170162 | ErrorExt.setCheckpoint("instElement2"); | |
| 3225 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 1170162 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1170162 times.
|
1170162 | (outCache, outEnv, outIH, {elt}) := updateCompeltsMods(inCache, outEnv, |
| 3226 | outIH, inPrefix, {inElement}, outState, inImplicit); | ||
| 3227 | 1170162 | (outCache, outEnv, outIH, outStore, DAE.DAE(outDae), outSets, outState, outVars, outGraph, outFieldDomOpt) := | |
| 3228 | instElement(outCache, outEnv, outIH, outStore, inMod, inPrefix, outState, elt, inInstDims, | ||
| 3229 | inImplicit, inCallingScope, outGraph, inSets); | ||
| 3230 | 1151825 | Error.clearCurrentComponent(); | |
| 3231 | 1151825 | ErrorExt.delCheckpoint("instElement2"); | |
| 3232 | else // Instantiation failed, fail or skip the element depending on inStopOnError. | ||
| 3233 |
2/2✓ Branch 0 taken 18314 times.
✓ Branch 1 taken 23 times.
|
18337 | if inStopOnError then |
| 3234 | 18314 | ErrorExt.delCheckpoint("instElement2"); | |
| 3235 | 18314 | fail(); | |
| 3236 | else | ||
| 3237 | 23 | ErrorExt.rollBack("instElement2"); | |
| 3238 | 23 | outCache := inCache; | |
| 3239 | 23 | outEnv := inEnv; | |
| 3240 | outIH := inIH; | ||
| 3241 | 23 | return; | |
| 3242 | end if; | ||
| 3243 | end try; | ||
| 3244 | end instElement2; | ||
| 3245 | |||
| 3246 | protected function isDeletedComponent | ||
| 3247 | "Checks if an element has a conditional expression that evaluates to false, | ||
| 3248 | and adds it to the set of deleted components if it does. Otherwise the | ||
| 3249 | function does nothing." | ||
| 3250 | input tuple<SCode.Element, DAE.Mod> element; | ||
| 3251 | input DAE.Prefix prefix; | ||
| 3252 | input Boolean stopOnError; | ||
| 3253 | output Boolean isDeleted; | ||
| 3254 | input output FCore.Graph env; | ||
| 3255 | input output FCore.Cache cache; | ||
| 3256 | protected | ||
| 3257 | SCode.Element el; | ||
| 3258 | String el_name; | ||
| 3259 | SourceInfo info; | ||
| 3260 | Option<Boolean> cond_val_opt; | ||
| 3261 | Boolean cond_val; | ||
| 3262 | DAE.Var var; | ||
| 3263 | algorithm | ||
| 3264 | // If the element has a conditional expression, try to evaluate it. | ||
| 3265 |
2/2✓ Branch 1 taken 1745 times.
✓ Branch 2 taken 1169389 times.
|
1171134 | if InstUtil.componentHasCondition(element) then |
| 3266 | 1745 | (el, _) := element; | |
| 3267 | 1745 | (el_name, info) := InstUtil.extractCurrentName(el); | |
| 3268 | |||
| 3269 | // An element redeclare may not have a condition. | ||
| 3270 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1745 times.
|
1745 | if SCodeUtil.isElementRedeclare(el) then |
| 3271 | ✗ | Error.addSourceMessage(Error.REDECLARE_CONDITION, {el_name}, info); | |
| 3272 | ✗ | fail(); | |
| 3273 | end if; | ||
| 3274 | |||
| 3275 | 1745 | (cond_val_opt, cache) := | |
| 3276 | InstUtil.instElementCondExp(cache, env, el, prefix, info); | ||
| 3277 | |||
| 3278 | // If a conditional expression was present but couldn't be instantiatied, stop. | ||
| 3279 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 1745 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1745 times.
|
1745 | if isNone(cond_val_opt) then |
| 3280 | ✗ | if stopOnError then // We should stop instantiation completely, fail. | |
| 3281 | ✗ | fail(); | |
| 3282 | else // We should continue instantiation, pretend that it was deleted. | ||
| 3283 | isDeleted := false; | ||
| 3284 | ✗ | return; | |
| 3285 | end if; | ||
| 3286 | end if; | ||
| 3287 | |||
| 3288 | // If we succeeded, check if the condition is true or false. | ||
| 3289 | 1745 | SOME(cond_val) := cond_val_opt; | |
| 3290 | 1745 | isDeleted := not cond_val; | |
| 3291 | |||
| 3292 | // The component was deleted, update its status in the environment so we can | ||
| 3293 | // look it up when instantiating connections. | ||
| 3294 |
2/2✓ Branch 0 taken 972 times.
✓ Branch 1 taken 773 times.
|
1745 | if isDeleted == true then |
| 3295 | 972 | var := DAE.TYPES_VAR(el_name, DAE.dummyAttrVar, DAE.T_UNKNOWN_DEFAULT, DAE.UNBOUND(), false, NONE()); | |
| 3296 | 972 | env := FGraph.updateComp(env, var, FCore.VAR_DELETED(), FGraph.emptyGraph); | |
| 3297 | end if; | ||
| 3298 | else | ||
| 3299 | isDeleted := false; | ||
| 3300 | end if; | ||
| 3301 | end isDeletedComponent; | ||
| 3302 | |||
| 3303 | public function instElement " | ||
| 3304 | This monster function instantiates an element of a class definition. An | ||
| 3305 | element is either a class definition, a variable, or an import clause." | ||
| 3306 | input FCore.Cache inCache; | ||
| 3307 | input FCore.Graph inEnv; | ||
| 3308 | input InnerOuter.InstHierarchy inIH; | ||
| 3309 | input UnitAbsyn.InstStore inUnitStore; | ||
| 3310 | input DAE.Mod inMod; | ||
| 3311 | input DAE.Prefix inPrefix; | ||
| 3312 | input ClassInf.State inState; | ||
| 3313 | input tuple<SCode.Element, DAE.Mod> inElement; | ||
| 3314 | input list<list<DAE.Dimension>> inInstDims; | ||
| 3315 | input Boolean inImplicit; | ||
| 3316 | input InstTypes.CallingScope inCallingScope; | ||
| 3317 | input ConnectionGraph.ConnectionGraph inGraph; | ||
| 3318 | input Connect.Sets inSets; | ||
| 3319 | output FCore.Cache outCache; | ||
| 3320 | output FCore.Graph outEnv; | ||
| 3321 | output InnerOuter.InstHierarchy outIH; | ||
| 3322 | output UnitAbsyn.InstStore outUnitStore; | ||
| 3323 | output DAE.DAElist outDae; | ||
| 3324 | output Connect.Sets outSets; | ||
| 3325 | output ClassInf.State outState; | ||
| 3326 | output list<DAE.Var> outVars; | ||
| 3327 | output ConnectionGraph.ConnectionGraph outGraph; | ||
| 3328 | output InstUtil.DomainFieldOpt outFieldDomOpt = NONE(); | ||
| 3329 | algorithm | ||
| 3330 | (outCache, outEnv, outIH, outUnitStore, outDae, outSets, outState, outVars, outGraph):= | ||
| 3331 | matchcontinue (inCache, inEnv, inIH, inUnitStore, inMod, inPrefix, inState, inElement, inInstDims, inImplicit, inGraph, inSets) | ||
| 3332 | local | ||
| 3333 | Absyn.ComponentRef own_cref; | ||
| 3334 | Absyn.Direction dir; | ||
| 3335 | SourceInfo info; | ||
| 3336 | Absyn.InnerOuter io; | ||
| 3337 | Absyn.Path t, type_name; | ||
| 3338 | Absyn.TypeSpec ts; | ||
| 3339 | Boolean already_declared, impl, is_function_input; | ||
| 3340 | ClassInf.State ci_state; | ||
| 3341 | ConnectionGraph.ConnectionGraph graph, graph_new; | ||
| 3342 | Connect.Sets csets; | ||
| 3343 | DAE.Attributes dae_attr; | ||
| 3344 | DAE.Binding binding; | ||
| 3345 | DAE.ComponentRef cref, cref2; | ||
| 3346 | DAE.DAElist dae; | ||
| 3347 | DAE.Mod mod, mods, class_mod, mm, cmod, mod_1, var_class_mod, m_1, cls_mod; | ||
| 3348 | DAE.Type ty; | ||
| 3349 | DAE.Var new_var; | ||
| 3350 | FCore.Cache cache; | ||
| 3351 | FCore.Graph env, env2, cenv, comp_env; | ||
| 3352 | InstanceHierarchy ih; | ||
| 3353 | InstDims inst_dims; | ||
| 3354 | list<Absyn.ComponentRef> crefs, crefs1, crefs2, crefs3; | ||
| 3355 | list<Absyn.Subscript> ad; | ||
| 3356 | DAE.Dimensions dims; | ||
| 3357 | list<DAE.Var> vars; | ||
| 3358 | Option<Absyn.Exp> cond; | ||
| 3359 | Option<DAE.EqMod> eq; | ||
| 3360 | SCode.Comment comment; | ||
| 3361 | DAE.Prefix pre; | ||
| 3362 | SCode.Attributes attr; | ||
| 3363 | SCode.Element cls, comp, el; | ||
| 3364 | SCode.Final final_prefix; | ||
| 3365 | SCode.ConnectorType ct; | ||
| 3366 | SCode.Mod m,oldmod; | ||
| 3367 | SCode.Prefixes prefixes; | ||
| 3368 | SCode.Variability vt; | ||
| 3369 | String name, id, ns, s, scope_str; | ||
| 3370 | UnitAbsyn.InstStore store; | ||
| 3371 | InnerOuter.TopInstance topInstance; // BTH | ||
| 3372 | HashSet.HashSet sm; // BTH | ||
| 3373 | Boolean isInSM; // BTH | ||
| 3374 | list<DAE.Element> elems; // BTH | ||
| 3375 | |||
| 3376 | |||
| 3377 | // Imports are simply added to the current frame, so that the lookup rule can find them. | ||
| 3378 | // Import have already been added to the environment so there is nothing more to do here. | ||
| 3379 | case (_, _, _, _, _, _, _, (SCode.IMPORT(),_), _, _, _, _) | ||
| 3380 | then (inCache, inEnv, inIH, inUnitStore, DAE.emptyDae, inSets, inState, {}, inGraph); | ||
| 3381 | |||
| 3382 | // class definitions, add the modifiers from the extends to the env | ||
| 3383 | case (_, _, _, _, _, _, _, (cls as SCode.CLASS(), cmod), _, _, _, _) | ||
| 3384 | algorithm | ||
| 3385 | //(cache, cenv, ih, store, dae, csets, ty, ci_state, _, graph) = instClass(cache, env, ih, inUnitStore, inMod, inPrefix, cls, inInstDims, inImplicit, inCallingScope, inGraph, inSets); | ||
| 3386 |
2/2✓ Branch 1 taken 5083 times.
✓ Branch 2 taken 608497 times.
|
613580 | if not Mod.isEmptyMod(cmod) then |
| 3387 | 5083 | env := FGraph.updateClass(inEnv, cls, inPrefix, cmod, FCore.CLS_UNTYPED(), inEnv); | |
| 3388 | else | ||
| 3389 | 608497 | env := inEnv; | |
| 3390 | end if; | ||
| 3391 | 613580 | then | |
| 3392 | (inCache, env, inIH, inUnitStore, DAE.emptyDae, inSets, inState, {}, inGraph); | ||
| 3393 | // (inCache, inEnv, inIH, inUnitStore, DAE.emptyDae, inSets, inState, {}, inGraph); | ||
| 3394 | |||
| 3395 | // A component | ||
| 3396 | // This is the rule for instantiating a model component. A component can be | ||
| 3397 | // a structured subcomponent or a variable, parameter or constant. All of | ||
| 3398 | // these are treated in a similar way. Lookup the class name, apply | ||
| 3399 | // modifications and add the variable to the current frame in the | ||
| 3400 | // environment. Then instantiate the class with an extended prefix. | ||
| 3401 | case (cache, env, ih, store, mods, pre, ci_state, ((el as SCode.COMPONENT(name = name, typeSpec = Absyn.TPATH())), cmod), inst_dims, impl, graph, csets) | ||
| 3402 | algorithm | ||
| 3403 | //print(" instElement: A component: " + name + "\n"); | ||
| 3404 | //print("instElement: " + name + " in s:" + FGraph.printGraphPathStr(env) + " m: " + SCodeDump.printModStr(m) + " cm: " + Mod.printModStr(cmod) + " mods:" + Mod.printModStr(mods) + "\n"); | ||
| 3405 | //print("Env:\n" + FGraph.printGraphStr(env) + "\n"); | ||
| 3406 | // lookup as it might have been redeclared | ||
| 3407 | // (_, _, el, _, _, _) = Lookup.lookupIdentLocal(cache, env, name); | ||
| 3408 | ✗ | SCode.COMPONENT( | |
| 3409 | name = name, | ||
| 3410 | prefixes = prefixes as SCode.PREFIXES( | ||
| 3411 | finalPrefix = final_prefix, | ||
| 3412 | innerOuter = io | ||
| 3413 | ), | ||
| 3414 | attributes = attr as SCode.ATTR(arrayDims = ad), | ||
| 3415 | typeSpec = (ts as Absyn.TPATH(path = t)), | ||
| 3416 | modifications = m, | ||
| 3417 | comment = comment, | ||
| 3418 | condition = cond, | ||
| 3419 | info = info) := el; | ||
| 3420 | |||
| 3421 |
1/4✗ Branch 1 not taken.
✓ Branch 2 taken 530014 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
530014 | true := if Config.acceptParModelicaGrammar() then InstUtil.checkParallelismWRTEnv(env,name,attr,info) else true; |
| 3422 | |||
| 3423 | // merge modifers from the component to the modifers from the constrained by | ||
| 3424 | 530014 | m := SCodeUtil.mergeModifiers(m, SCodeUtil.getConstrainedByModifiers(prefixes)); | |
| 3425 | |||
| 3426 |
2/2✓ Branch 1 taken 3276 times.
✓ Branch 2 taken 526738 times.
|
530014 | if SCodeUtil.finalBool(final_prefix) then |
| 3427 | 3276 | m := InstUtil.traverseModAddFinal(m); | |
| 3428 | end if; | ||
| 3429 |
2/2✓ Branch 0 taken 3221 times.
✓ Branch 1 taken 526793 times.
|
530014 | comp := if referenceEq(el.modifications, m) then el else SCode.COMPONENT(name, prefixes, attr, ts, m, comment, cond, info); |
| 3430 | oldmod := m; | ||
| 3431 | |||
| 3432 | // Fails if multiple decls not identical | ||
| 3433 | 530014 | already_declared := InstUtil.checkMultiplyDeclared(cache, env, mods, pre, ci_state, (comp, cmod), inst_dims, impl); | |
| 3434 | |||
| 3435 | // chain the redeclares AFTER checking of elements identical | ||
| 3436 | // if we have an outer modification: redeclare X = Y | ||
| 3437 | // and a component modification redeclare X = Z | ||
| 3438 | // update the component modification to redeclare X = Y | ||
| 3439 | 530010 | m := InstUtil.chainRedeclares(mods, m); | |
| 3440 | 530010 | m := SCodeInstUtil.expandEnumerationMod(m); | |
| 3441 | 530010 | m := InstUtil.traverseModAddDims(cache, env, pre, m, inst_dims); | |
| 3442 |
2/2✓ Branch 0 taken 177 times.
✓ Branch 1 taken 529833 times.
|
530010 | comp := if referenceEq(oldmod,m) then comp else SCode.COMPONENT(name, prefixes, attr, ts, m, comment, cond, info); |
| 3443 | 530010 | ci_state := ClassInfUtil.trans(ci_state, ClassInf.FOUND_COMPONENT(name)); | |
| 3444 | 530009 | cref := ComponentReferenceBasics.makeCrefIdent(name, DAE.T_UNKNOWN_DEFAULT, {}); | |
| 3445 | 530009 | (cache,_) := PrefixUtil.prefixCref(cache, env, ih, pre, cref); /*mahge: todo: remove me*/ | |
| 3446 | |||
| 3447 | // The class definition is fetched from the environment. Then the set of | ||
| 3448 | // modifications is calculated. The modificions is the result of merging | ||
| 3449 | // the modifications from several sources. The modification stored with | ||
| 3450 | // the class definition is put in the variable `classmod', the | ||
| 3451 | // modification passed to the function_ is extracted and put in the | ||
| 3452 | // variable `mm', and the modification that is included in the variable | ||
| 3453 | // declaration is in the variable `m'. All of these are merged so that | ||
| 3454 | // the correct precedence rules are followed." | ||
| 3455 | 530009 | class_mod := Mod.lookupModificationP(mods, t); | |
| 3456 | 530009 | mm := Mod.lookupCompModification(mods, name); | |
| 3457 | |||
| 3458 | // The types in the environment does not have correct Binding. | ||
| 3459 | // We must update those variables that is found in m into a new environment. | ||
| 3460 | 530009 | own_cref := Absyn.CREF_IDENT(name, {}); | |
| 3461 | 530009 | crefs1 := InstUtil.getCrefFromMod(m); | |
| 3462 | 530009 | crefs2 := InstUtil.getCrefFromDim(ad); | |
| 3463 | 530009 | crefs3 := InstUtil.getCrefFromCond(cond); | |
| 3464 | 530009 | crefs := List.unionList({crefs1, crefs2, crefs3}); | |
| 3465 | |||
| 3466 | // can call instVar | ||
| 3467 | 530009 | (cache, env, ih, store, crefs) := removeSelfReferenceAndUpdate(cache, | |
| 3468 | env, ih, store, crefs, own_cref, t, ci_state, attr, prefixes, | ||
| 3469 | impl, inst_dims, pre, mods, m, info); | ||
| 3470 | |||
| 3471 | // can call instVar | ||
| 3472 | 530009 | (cache, env2, ih) := updateComponentsInEnv(cache, env, ih, pre, mods, crefs, ci_state, impl); | |
| 3473 | // env2 = env; | ||
| 3474 | |||
| 3475 | // Update the untyped modifiers to typed ones, and extract class and | ||
| 3476 | // component modifiers again. | ||
| 3477 | 530009 | (cache, class_mod) := Mod.updateMod(cache, env2, ih, pre, class_mod, impl, info); | |
| 3478 | 530009 | (cache, mm) := Mod.updateMod(cache, env2, ih, pre, mm, impl, info); | |
| 3479 | |||
| 3480 | // (BZ part:1/2) | ||
| 3481 | // If we have a redeclaration of a inner model, we have lowest priority on it. | ||
| 3482 | // This is while if we instantiate an instance of this redeclared class with a | ||
| 3483 | // modifier, the modifier should be the value to use. | ||
| 3484 | 530009 | (var_class_mod, class_mod) := modifyInstantiateClass(class_mod, t); | |
| 3485 | |||
| 3486 | // print("Inst.instElement: before elabMod " + PrefixUtil.printPrefixStr(pre) + | ||
| 3487 | // "." + name + " component mod: " + SCodeDump.printModStr(m) + " in env: " + | ||
| 3488 | // FGraph.printGraphPathStr(env2) + "\n"); | ||
| 3489 | 530009 | (cache, m_1) := Mod.elabMod(cache, env2, ih, pre, m, impl, Mod.COMPONENT(name), info); | |
| 3490 | |||
| 3491 | // print("Inst.instElement: after elabMod " + PrefixUtil.printPrefixStr(pre) + "." + name + " component mod: " + Mod.printModStr(m_1) + " in env: " + FGraph.printGraphPathStr(env2) + "\n"); | ||
| 3492 | |||
| 3493 | 529962 | mod := Mod.merge(mm, class_mod, name); | |
| 3494 | 529962 | mod := Mod.merge(mod, m_1, name, not ClassInfUtil.isRecord(ci_state)); | |
| 3495 | 529960 | mod := Mod.merge(cmod, mod, name); | |
| 3496 | |||
| 3497 | /* (BZ part:2/2) here we merge the redeclared class modifier. | ||
| 3498 | * Redeclaration has lowest priority and if we have any local modifiers, | ||
| 3499 | * they will be used before "global" modifers. | ||
| 3500 | */ | ||
| 3501 | 529959 | mod := Mod.merge(mod, var_class_mod, name); | |
| 3502 | |||
| 3503 | // fprintln(Flags.INST_TRACE, "INST ELEMENT: name: " + name + " mod: " + Mod.printModStr(mod)); | ||
| 3504 | |||
| 3505 | // Apply redeclaration modifier to component | ||
| 3506 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 529959 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 529959 times.
|
529959 | (cache, env2, ih, SCode.COMPONENT(name, |
| 3507 | prefixes as SCode.PREFIXES(innerOuter = io), | ||
| 3508 | attr as SCode.ATTR(arrayDims = ad, direction = dir), | ||
| 3509 | Absyn.TPATH(t, _), _, comment, _, _), mod_1) | ||
| 3510 | := redeclareType(cache, env2, ih, mod, comp, pre, ci_state, impl, DAE.NOMOD()); | ||
| 3511 | |||
| 3512 | 529959 | (cache, cls, cenv) := Lookup.lookupClass(cache, env2 /* env */, t, SOME(info)); | |
| 3513 | |||
| 3514 | 529937 | cls_mod := Mod.getClassModifier(cenv, SCodeUtil.className(cls)); | |
| 3515 |
2/2✓ Branch 1 taken 5507 times.
✓ Branch 2 taken 524430 times.
|
529937 | if not Mod.isEmptyMod(cls_mod) |
| 3516 | then | ||
| 3517 |
2/2✓ Branch 0 taken 21 times.
✓ Branch 1 taken 5486 times.
|
5507 | if not listEmpty(ad) // add each if needed |
| 3518 | then | ||
| 3519 | 21 | cls_mod := Mod.addEachIfNeeded(cls_mod, {DAE.DIM_INTEGER(1)}); | |
| 3520 | end if; | ||
| 3521 | 5507 | mod_1 := Mod.merge(mod_1, cls_mod, name); | |
| 3522 | end if; | ||
| 3523 | 529937 | attr := SCodeUtil.mergeAttributesFromClass(attr, cls); | |
| 3524 | |||
| 3525 | // If the element is protected, and an external modification | ||
| 3526 | // is applied, it is an error. | ||
| 3527 | // this does not work as we don't know from where the modification came (component modif or extends modif) | ||
| 3528 | // checkProt(vis, mm, vn, info); | ||
| 3529 | |||
| 3530 | //Instantiate the component | ||
| 3531 | // Start a new "set" of inst_dims for this component (in instance hierarchy), see InstDims | ||
| 3532 | 529937 | inst_dims := List.appendElt({}, inst_dims); | |
| 3533 | |||
| 3534 | 529937 | (cache,mod) := Mod.updateMod(cache, env2 /* cenv */, ih, pre, mod, impl, info); | |
| 3535 | 529937 | (cache,mod_1) := Mod.updateMod(cache, env2 /* cenv */, ih, pre, mod_1, impl, info); | |
| 3536 | |||
| 3537 | // print("Before InstUtil.selectModifiers:\n\tmod: " + Mod.printModStr(mod) + "\n\t" +"mod_1: " + Mod.printModStr(mod_1) + "\n\t" +"comp: " + SCodeDump.unparseElementStr(comp) + "\n"); | ||
| 3538 | |||
| 3539 | 529937 | (mod, mod_1) := InstUtil.selectModifiers(mod, mod_1, t); | |
| 3540 | |||
| 3541 | // print("After InstUtil.selectModifiers:\n\tmod: " + Mod.printModStr(mod) + "\n\t" +"mod_1: " + Mod.printModStr(mod_1) + "\n"); | ||
| 3542 | |||
| 3543 | 529937 | eq := Mod.modEquation(mod); | |
| 3544 | // The variable declaration and the (optional) equation modification are inspected for array dimensions. | ||
| 3545 | 529937 | is_function_input := InstUtil.isFunctionInput(ci_state, dir); | |
| 3546 | 529937 | (cache, dims) := InstUtil.elabArraydim(cache, env2, own_cref, t, ad, eq, impl, | |
| 3547 | true, is_function_input, pre, info, inst_dims); | ||
| 3548 | |||
| 3549 | //PDEModelica: | ||
| 3550 |
2/2✓ Branch 1 taken 76 times.
✓ Branch 2 taken 529855 times.
|
529931 | if intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PDEMODELICA) then |
| 3551 | 76 | (dims, mod_1, outFieldDomOpt) := InstUtil.elabField(inCache, inEnv, name, attr, dims, mod_1, info); | |
| 3552 | end if; | ||
| 3553 | |||
| 3554 | // adrpo: 2011-11-18: see if the component is an INPUT or OUTPUT and class is a record | ||
| 3555 | // and add it to the cache! | ||
| 3556 | // (cache, _, _) = addRecordConstructorsToTheCache(cache, cenv, ih, mod_1, pre, ci_state, dir, cls, inst_dims); | ||
| 3557 | 529931 | (cenv, cls, ih) := FGraph.createVersionScope(env2, name, pre, mod_1, cenv, cls, ih); | |
| 3558 | |||
| 3559 | /* Check whether the current class is part of a state machine */ | ||
| 3560 | 529931 | (cache, cref2) := PrefixUtil.prefixCref(cache, cenv, ih, pre, cref); | |
| 3561 | //print("Inst.instElement: before SM check " + PrefixUtil.printPrefixStr(pre) + "." + name + " cref2: " + ComponentReference.crefStr(cref2) + " in env: " + FGraph.printGraphPathStr(env2) + "\n"); | ||
| 3562 |
2/2✓ Branch 0 taken 45572 times.
✓ Branch 1 taken 484359 times.
|
529931 | if not listEmpty(ih) then |
| 3563 | 45572 | topInstance := listHead(ih); | |
| 3564 | 45572 | InnerOuter.TOP_INSTANCE(sm=sm) := topInstance; | |
| 3565 | // print("Inst.instElement: START sm:\n"); BaseHashSet.printHashSet(sm); print("\nInst.instElement: STOP sm:\n"); | ||
| 3566 |
2/2✓ Branch 1 taken 45553 times.
✓ Branch 2 taken 19 times.
|
45572 | if BaseHashSet.has(cref2, sm) then |
| 3567 | //print("\n Inst.instElement: Found: "+ComponentReference.crefStr(cref2)+"\n"); | ||
| 3568 | isInSM := true; | ||
| 3569 | else | ||
| 3570 | isInSM := false; | ||
| 3571 | end if; | ||
| 3572 | else | ||
| 3573 | isInSM := false; | ||
| 3574 | end if; | ||
| 3575 | |||
| 3576 | 529931 | (cache, comp_env, ih, store, dae, csets, ty, graph_new) := InstVar.instVar(cache, | |
| 3577 | cenv, ih, store, ci_state, mod_1, pre, name, cls, attr, | ||
| 3578 | prefixes, dims, {}, inst_dims, impl, comment, info, graph, csets, env2); | ||
| 3579 | |||
| 3580 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 529869 times.
|
529888 | if isInSM then |
| 3581 | // If class is in state machine, wrap its content in a DAE.SM_COMP | ||
| 3582 | 19 | DAE.DAE(elementLst=elems) := dae; | |
| 3583 | 38 | dae := DAE.DAE({DAE.SM_COMP(cref2, elems)}); | |
| 3584 | //dae = DAE.DAE({DAE.COMP(ComponentReference.crefStr(cref), elems, DAE.emptyElementSource, NONE())}); | ||
| 3585 | end if; | ||
| 3586 | |||
| 3587 | // print("instElement -> component: " + name + " ty: " + TypesDump.printTypeStr(ty) + "\n"); | ||
| 3588 | //The environment is extended (updated) with the new variable binding. | ||
| 3589 | 529888 | (cache, binding) := InstBinding.makeBinding(cache, env2, attr, mod, ty, pre, name, info); | |
| 3590 | |||
| 3591 | /*// uncomment this for debugging of bindings from mods | ||
| 3592 | print("Created binding for var: " + | ||
| 3593 | PrefixUtil.printPrefixStr(pre) + "." + name + "\n\t" + | ||
| 3594 | " binding: " + TypesDump.printBindingStr(binding) + "\n\t" + | ||
| 3595 | " m: " + SCodeDump.printModStr(m) + "\n\t" + | ||
| 3596 | " class_mod: " + Mod.printModStr(class_mod) + "\n\t" + | ||
| 3597 | " mm: " + Mod.printModStr(mm) + "\n\t" + | ||
| 3598 | " var_class_mod: " + Mod.printModStr(mm) + "\n\t" + | ||
| 3599 | " m_1: " + Mod.printModStr(m_1) + "\n\t" + | ||
| 3600 | " cmod: " + Mod.printModStr(cmod) + "\n\t" + | ||
| 3601 | " mod: " + Mod.printModStr(mod) + "\n\t" + | ||
| 3602 | " mod_1: " + Mod.printModStr(mod_1) + | ||
| 3603 | "\n");*/ | ||
| 3604 | |||
| 3605 | 511692 | dae_attr := DAEUtil.translateSCodeAttrToDAEAttr(attr, prefixes); | |
| 3606 | 511692 | ty := Types.traverseType(ty, 1, Types.setIsFunctionPointer); | |
| 3607 | |||
| 3608 | 511692 | binding := removePrefixFromBinding(binding, pre); | |
| 3609 | 511692 | new_var := DAE.TYPES_VAR(name, dae_attr, ty, binding, false, NONE()); | |
| 3610 | |||
| 3611 | // Type info present. Now we can also put the binding into the dae. | ||
| 3612 | // If the type is one of the simple, predifined types a simple variable | ||
| 3613 | // declaration is added to the DAE. | ||
| 3614 | 511692 | env := FGraph.updateComp(env2, new_var, FCore.VAR_DAE(), comp_env); | |
| 3615 |
2/2✓ Branch 0 taken 505549 times.
✓ Branch 1 taken 6143 times.
|
511692 | vars := if already_declared then {} else {new_var}; |
| 3616 |
2/2✓ Branch 0 taken 505549 times.
✓ Branch 1 taken 6143 times.
|
511692 | dae := if already_declared then DAE.emptyDae else dae; |
| 3617 | 511692 | (_, ih, graph) := InnerOuter.handleInnerOuterEquations(io, DAE.emptyDae, ih, graph_new, graph); | |
| 3618 | |||
| 3619 | 511692 | then | |
| 3620 | (cache, env, ih, store, dae, csets, ci_state, vars, graph); | ||
| 3621 | |||
| 3622 | //------------------------------------------------------------------------ | ||
| 3623 | // MetaModelica Complex Types. Part of MetaModelica extension. | ||
| 3624 | //------------------------------------------------------------------------ | ||
| 3625 | case (cache, env, ih, store, mods, pre, ci_state, (comp as SCode.COMPONENT( | ||
| 3626 | name, | ||
| 3627 | prefixes as SCode.PREFIXES( | ||
| 3628 | finalPrefix = final_prefix, | ||
| 3629 | innerOuter = io | ||
| 3630 | ), | ||
| 3631 | attr as SCode.ATTR(arrayDims = ad, connectorType = ct), | ||
| 3632 | ts as Absyn.TCOMPLEX(path = type_name), m, comment, cond, info), cmod), inst_dims, impl, graph, csets) | ||
| 3633 | algorithm | ||
| 3634 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 26042 times.
|
26042 | true := Config.acceptMetaModelicaGrammar(); |
| 3635 | |||
| 3636 | // see if we have a modification on the inner component | ||
| 3637 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 26042 times.
|
26042 | if SCodeUtil.finalBool(final_prefix) then |
| 3638 | ✗ | m := InstUtil.traverseModAddFinal(m); | |
| 3639 | ✗ | comp := SCode.COMPONENT(name, prefixes, attr, ts, m, comment, cond, info); | |
| 3640 | end if; | ||
| 3641 | |||
| 3642 | // Fails if multiple decls not identical | ||
| 3643 | 26042 | already_declared := InstUtil.checkMultiplyDeclared(cache, env, mods, pre, | |
| 3644 | ci_state, (comp, cmod), inst_dims, impl); | ||
| 3645 | 26042 | cref := ComponentReferenceBasics.makeCrefIdent(name, DAE.T_UNKNOWN_DEFAULT, {}); | |
| 3646 | 26042 | (cache,_) := PrefixUtil.prefixCref(cache, env, ih, pre, cref); | |
| 3647 | |||
| 3648 | |||
| 3649 | // The types in the environment does not have correct Binding. | ||
| 3650 | // We must update those variables that is found in m into a new environment. | ||
| 3651 | 26042 | own_cref := Absyn.CREF_IDENT(name, {}) ; | |
| 3652 | // In case we want to EQBOUND a complex type, e.g. when declaring constants. /sjoelund 2009-10-30 | ||
| 3653 | 26042 | (cache, m_1) := Mod.elabMod(cache, env, ih, pre, m, impl, Mod.COMPONENT(name), info); | |
| 3654 | |||
| 3655 | //--------- | ||
| 3656 | // We build up a class structure for the complex type | ||
| 3657 | 26028 | id := AbsynUtil.pathString(type_name); | |
| 3658 | |||
| 3659 | 26028 | cls := SCode.CLASS(id, SCode.defaultPrefixes, SCode.NOT_ENCAPSULATED(), | |
| 3660 | SCode.NOT_PARTIAL(), SCode.R_TYPE(), SCode.DERIVED(ts, SCode.NOMOD(), | ||
| 3661 | SCode.ATTR(ad, ct, SCode.NON_PARALLEL(), SCode.VAR(), Absyn.BIDIR(), Absyn.NONFIELD())), SCode.noComment, info); | ||
| 3662 | |||
| 3663 | // The variable declaration and the (optional) equation modification are inspected for array dimensions. | ||
| 3664 | // Gather all the dimensions | ||
| 3665 | // (Absyn.IDENT("Integer") is used as a dummy) | ||
| 3666 | 26028 | (cache, dims) := InstUtil.elabArraydim(cache, env, own_cref, Absyn.IDENT("Integer"), | |
| 3667 | ad, NONE(), impl, true, false, pre, info, inst_dims); | ||
| 3668 | |||
| 3669 | // Instantiate the component | ||
| 3670 | 26028 | (cache, comp_env, ih, store, dae, csets, ty, graph_new) := | |
| 3671 | InstVar.instVar(cache, env, ih, store,ci_state, m_1, pre, name, cls, attr, | ||
| 3672 | prefixes, dims, {}, inst_dims, impl, comment, info, graph, csets, env); | ||
| 3673 | |||
| 3674 | // print("instElement -> component: " + n + " ty: " + TypesDump.printTypeStr(ty) + "\n"); | ||
| 3675 | |||
| 3676 | // The environment is extended (updated) with the new variable binding. | ||
| 3677 | 26027 | (cache, binding) := InstBinding.makeBinding(cache, env, attr, m_1, ty, pre, name, info); | |
| 3678 | |||
| 3679 | // true in update_frame means the variable is now instantiated. | ||
| 3680 | 26027 | dae_attr := DAEUtil.translateSCodeAttrToDAEAttr(attr, prefixes); | |
| 3681 | 26027 | ty := Types.traverseType(ty, 1, Types.setIsFunctionPointer); | |
| 3682 | 26027 | new_var := DAE.TYPES_VAR(name, dae_attr, ty, binding, false, NONE()) ; | |
| 3683 | |||
| 3684 | // type info present Now we can also put the binding into the dae. | ||
| 3685 | // If the type is one of the simple, predifined types a simple variable | ||
| 3686 | // declaration is added to the DAE. | ||
| 3687 | 26027 | env := FGraph.updateComp(env, new_var, FCore.VAR_DAE(), comp_env); | |
| 3688 |
1/2✓ Branch 0 taken 26027 times.
✗ Branch 1 not taken.
|
26027 | vars := if already_declared then {} else {new_var}; |
| 3689 |
1/2✓ Branch 0 taken 26027 times.
✗ Branch 1 not taken.
|
26027 | dae := if already_declared then DAE.emptyDae else dae; |
| 3690 | 26027 | (_, ih, graph) := InnerOuter.handleInnerOuterEquations(io, DAE.emptyDae, ih, graph_new, graph); | |
| 3691 | 26027 | then | |
| 3692 | (cache, env, ih, store, dae, csets, ci_state, vars, graph); | ||
| 3693 | |||
| 3694 | //------------------------------ | ||
| 3695 | // If the class lookup in the previous rule fails, this rule catches the error | ||
| 3696 | // and prints an error message about the unknown class. | ||
| 3697 | // Failure => ({},env,csets,ci_state,{}) | ||
| 3698 | case (cache, env, _, _, _, pre, ci_state, (SCode.COMPONENT( | ||
| 3699 | name = name, | ||
| 3700 | attributes = SCode.ATTR(variability = vt), | ||
| 3701 | typeSpec = Absyn.TPATH(t,_), | ||
| 3702 | info = info), _), _, _, _, _) | ||
| 3703 | algorithm | ||
| 3704 |
2/2✓ Branch 0 taken 18322 times.
✓ Branch 1 taken 22 times.
|
18344 | failure(Lookup.lookupClass(cache, env, t)); |
| 3705 | // good for GDB debugging to re-run the instElement again | ||
| 3706 | // (cache, env, ih, store, dae, csets, ci_state, vars, graph) = instElement(inCache, inEnv, inIH, inUnitStore, inMod, inPrefix, inState, inElement, inInstDims, inImplicit, inCallingScope, inGraph, inSets); | ||
| 3707 | 22 | s := AbsynUtil.pathString(t); | |
| 3708 | 22 | scope_str := FGraph.printGraphPathStr(env); | |
| 3709 | 22 | pre := PrefixUtil.prefixAdd(name, {}, {}, pre, vt, ci_state, info); | |
| 3710 | 22 | ns := PrefixUtil.printPrefixStrIgnoreNoPre(pre); | |
| 3711 | 22 | Error.addSourceMessage(Error.LOOKUP_ERROR_COMPNAME, {s, scope_str, ns}, info); | |
| 3712 |
1/2✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
|
22 | true := Flags.isSet(Flags.FAILTRACE); |
| 3713 | ✗ | Debug.traceln("Lookup class failed:" + AbsynUtil.pathString(t)); | |
| 3714 | ✗ | then | |
| 3715 | fail(); | ||
| 3716 | |||
| 3717 | case (_, env, _, _, _, _, _, (comp, _), _, _, _, _) | ||
| 3718 | algorithm | ||
| 3719 |
2/2✓ Branch 1 taken 18323 times.
✓ Branch 2 taken 14 times.
|
18337 | true := Flags.isSet(Flags.FAILTRACE); |
| 3720 | 14 | Debug.traceln("- Inst.instElement failed: " + SCodeDump.unparseElementStr(comp,SCodeDump.defaultOptions)); | |
| 3721 | 14 | Debug.traceln(" Scope: " + FGraph.printGraphPathStr(env)); | |
| 3722 | 14 | then | |
| 3723 | fail(); | ||
| 3724 | end matchcontinue; | ||
| 3725 | end instElement; | ||
| 3726 | |||
| 3727 | protected function removePrefixFromBinding | ||
| 3728 | input DAE.Binding inBind; | ||
| 3729 | input DAE.Prefix inPrefix; | ||
| 3730 | output DAE.Binding outBind; | ||
| 3731 | algorithm | ||
| 3732 | outBind := match (inBind, inPrefix) | ||
| 3733 | local | ||
| 3734 | DAE.Binding bind; | ||
| 3735 | DAE.Prefix pref; | ||
| 3736 | |||
| 3737 | case (bind as DAE.EQBOUND(), pref as DAE.PREFIX(compPre=DAE.PRE())) algorithm | ||
| 3738 | 100863 | bind.exp := PrefixUtil.removeCompPrefixFromExps(bind.exp, pref.compPre); | |
| 3739 | then | ||
| 3740 | bind; | ||
| 3741 | |||
| 3742 | else inBind; | ||
| 3743 | end match; | ||
| 3744 | end removePrefixFromBinding; | ||
| 3745 | |||
| 3746 | protected function updateCompeltsMods | ||
| 3747 | "never fail and *NEVER* display any error messages as this function | ||
| 3748 | prints non-true error messages and even so instElementList dependency | ||
| 3749 | analysis might work fine and still instantiate." | ||
| 3750 | input FCore.Cache inCache; | ||
| 3751 | input FCore.Graph inEnv; | ||
| 3752 | input InnerOuter.InstHierarchy inIH; | ||
| 3753 | input DAE.Prefix inPrefix; | ||
| 3754 | input list<tuple<SCode.Element, DAE.Mod>> inComponents; | ||
| 3755 | input ClassInf.State inState; | ||
| 3756 | input Boolean inImplicit; | ||
| 3757 | output FCore.Cache outCache; | ||
| 3758 | output FCore.Graph outEnv; | ||
| 3759 | output InnerOuter.InstHierarchy outIH; | ||
| 3760 | output list<tuple<SCode.Element, DAE.Mod>> outComponents; | ||
| 3761 | algorithm | ||
| 3762 | (outCache,outEnv,outIH,outComponents) := | ||
| 3763 | matchcontinue inImplicit | ||
| 3764 | |||
| 3765 | /* | ||
| 3766 | case (_,_,_,_,_,_,_) | ||
| 3767 | algorithm | ||
| 3768 | true = Config.acceptMetaModelicaGrammar(); | ||
| 3769 | then | ||
| 3770 | (inCache,inEnv,inIH,inComponents);*/ | ||
| 3771 | |||
| 3772 | case _ | ||
| 3773 | algorithm | ||
| 3774 | 1170162 | ErrorExt.setCheckpoint("updateCompeltsMods"); | |
| 3775 | 1170162 | (outCache,outEnv,outIH,outComponents) := | |
| 3776 | updateCompeltsMods_dispatch(inCache,inEnv,inIH,inPrefix,inComponents,inState,inImplicit); | ||
| 3777 | 1170162 | ErrorExt.rollBack("updateCompeltsMods") "roll back any errors"; | |
| 3778 | 1170162 | then | |
| 3779 | (outCache,outEnv,outIH,outComponents); | ||
| 3780 | |||
| 3781 | else | ||
| 3782 | algorithm | ||
| 3783 | ✗ | ErrorExt.rollBack("updateCompeltsMods") "roll back any errors"; | |
| 3784 | then | ||
| 3785 | (inCache,inEnv,inIH,inComponents); | ||
| 3786 | end matchcontinue; | ||
| 3787 | end updateCompeltsMods; | ||
| 3788 | |||
| 3789 | protected function updateCompeltsMods_dispatch | ||
| 3790 | "author: PA | ||
| 3791 | This function updates component modifiers to typed modifiers. | ||
| 3792 | Typed modifiers are needed to merge modifiers and to be able to | ||
| 3793 | fully instantiate a component." | ||
| 3794 | input FCore.Cache inCache; | ||
| 3795 | input FCore.Graph inEnv; | ||
| 3796 | input InnerOuter.InstHierarchy inIH; | ||
| 3797 | input DAE.Prefix inPrefix; | ||
| 3798 | input list<tuple<SCode.Element, DAE.Mod>> inComponents; | ||
| 3799 | input ClassInf.State inState; | ||
| 3800 | input Boolean inImplicit; | ||
| 3801 | output FCore.Cache outCache; | ||
| 3802 | output FCore.Graph outEnv; | ||
| 3803 | output InnerOuter.InstHierarchy outIH; | ||
| 3804 | output list<tuple<SCode.Element, DAE.Mod>> outComponents; | ||
| 3805 | algorithm | ||
| 3806 | (outCache,outEnv,outIH,outComponents):= | ||
| 3807 | matchcontinue (inCache,inEnv,inIH,inPrefix,inComponents,inState,inImplicit) | ||
| 3808 | local | ||
| 3809 | FCore.Graph env,env2,env3; | ||
| 3810 | DAE.Prefix pre; | ||
| 3811 | SCode.Mod umod; | ||
| 3812 | list<Absyn.ComponentRef> crefs,crefs_1; | ||
| 3813 | Absyn.ComponentRef cref; | ||
| 3814 | DAE.Mod cmod_1,cmod,cmod2; | ||
| 3815 | list<DAE.Mod> ltmod; | ||
| 3816 | list<tuple<SCode.Element, DAE.Mod>> res,xs; | ||
| 3817 | tuple<SCode.Element, DAE.Mod> elMod; | ||
| 3818 | SCode.Element comp,redComp; | ||
| 3819 | ClassInf.State ci_state; | ||
| 3820 | Boolean impl; | ||
| 3821 | FCore.Cache cache; | ||
| 3822 | InstanceHierarchy ih; | ||
| 3823 | String name; | ||
| 3824 | SourceInfo info; | ||
| 3825 | SCode.Final fprefix; | ||
| 3826 | |||
| 3827 | case (cache,env,ih,_,{},_,_) then (cache,env,ih,{}); | ||
| 3828 | |||
| 3829 | // Instantiate the element if there is no mod | ||
| 3830 | case (cache,env,ih,pre,((elMod as (_,DAE.NOMOD())) :: xs),ci_state,impl) | ||
| 3831 | algorithm | ||
| 3832 | /* | ||
| 3833 | name = SCodeUtil.elementName(comp); | ||
| 3834 | cref = Absyn.CREF_IDENT(name,{}); | ||
| 3835 | (cache,env,ih) = updateComponentsInEnv(cache, env, ih, pre, DAE.NOMOD(), {cref}, ci_state, impl); | ||
| 3836 | */ | ||
| 3837 | 1131574 | (cache,env,ih,res) := updateCompeltsMods_dispatch(cache, env, ih, pre, xs, ci_state, impl); | |
| 3838 | 1131574 | then | |
| 3839 | (cache,env,ih,elMod::res); | ||
| 3840 | |||
| 3841 | // Special case for components being redeclared, we might instantiate partial classes when instantiating var(-> instVar2->instClass) to update component in env. | ||
| 3842 | case (cache,env,ih,pre,((comp,(cmod as DAE.REDECL(element = redComp))) :: xs),ci_state,impl) | ||
| 3843 | algorithm | ||
| 3844 | 4491 | info := SCodeUtil.elementInfo(redComp); | |
| 3845 | 4491 | umod := Mod.unelabMod(cmod); | |
| 3846 | 4491 | crefs := InstUtil.getCrefFromMod(umod); | |
| 3847 | 4491 | crefs_1 := InstUtil.getCrefFromCompDim(comp) "get crefs from dimension arguments"; | |
| 3848 | 4491 | crefs := List.unionOnTrue(crefs,crefs_1,AbsynUtil.crefEqual); | |
| 3849 | 4491 | name := SCodeUtil.elementName(comp); | |
| 3850 | 4491 | cref := Absyn.CREF_IDENT(name,{}); | |
| 3851 | 4491 | ltmod := List.map1(crefs,InstUtil.getModsForDep,xs); | |
| 3852 | 4491 | cmod2 := List.fold2r(cmod::ltmod,Mod.merge,name,true,DAE.NOMOD()); | |
| 3853 | 4491 | SCode.PREFIXES(finalPrefix = fprefix) := SCodeUtil.elementPrefixes(comp); | |
| 3854 | |||
| 3855 | //print("("+intString(listLength(ltmod))+")UpdateCompeltsMods_(" + stringDelimitList(List.map(crefs,Dump.printComponentRefStr),",") + ") subs: " + stringDelimitList(List.map(crefs,Dump.printComponentRefStr),",")+ "\n"); | ||
| 3856 | //print("REDECL acquired mods: " + Mod.printModStr(cmod2) + "\n"); | ||
| 3857 | 4491 | (cache,env2,ih) := updateComponentsInEnv(cache, env, ih, pre, cmod2, crefs, ci_state, impl); | |
| 3858 | 13473 | (cache,env2,ih) := updateComponentsInEnv(cache, env2, ih, pre, | |
| 3859 | DAE.MOD(fprefix,SCode.NOT_EACH(),{DAE.NAMEMOD(name, cmod)},NONE(),info), | ||
| 3860 | {cref}, ci_state, impl); | ||
| 3861 | 4491 | (cache,cmod_1) := Mod.updateMod(cache, env2, ih, pre, cmod, impl, info); | |
| 3862 | 4491 | (cache,env3,ih,res) := updateCompeltsMods_dispatch(cache, env2, ih, pre, xs, ci_state, impl); | |
| 3863 | 4491 | then | |
| 3864 | (cache,env3,ih,((comp,cmod_1) :: res)); | ||
| 3865 | |||
| 3866 | // If the modifier has already been updated, just update the environment with it. | ||
| 3867 | case (cache,env,ih,pre,((comp, cmod as DAE.MOD()) :: xs),ci_state,impl) | ||
| 3868 | algorithm | ||
| 3869 |
2/2✓ Branch 1 taken 7405 times.
✓ Branch 2 taken 26691 times.
|
34097 | false := Mod.isUntypedMod(cmod); |
| 3870 | 26691 | name := SCodeUtil.elementName(comp); | |
| 3871 | 26691 | cref := Absyn.CREF_IDENT(name,{}); | |
| 3872 | 26691 | SCode.PREFIXES(finalPrefix = fprefix) := SCodeUtil.elementPrefixes(comp); | |
| 3873 | |||
| 3874 | 80073 | (cache,env2,ih) := updateComponentsInEnv(cache, env, ih, pre, | |
| 3875 | DAE.MOD(fprefix,SCode.NOT_EACH(),{DAE.NAMEMOD(name, cmod)},NONE(),cmod.info), | ||
| 3876 | {cref}, ci_state, impl); | ||
| 3877 | 26691 | (cache,env3,ih,res) := updateCompeltsMods_dispatch(cache, env2, ih, pre, xs, ci_state, impl); | |
| 3878 | 26691 | then | |
| 3879 | (cache,env3,ih,((comp,cmod) :: res)); | ||
| 3880 | |||
| 3881 | case (cache,env,ih,pre,((comp, cmod as DAE.MOD()) :: xs),ci_state,impl) | ||
| 3882 | algorithm | ||
| 3883 | 7406 | info := SCodeUtil.elementInfo(comp); | |
| 3884 | 7406 | umod := Mod.unelabMod(cmod); | |
| 3885 | 7406 | crefs := InstUtil.getCrefFromMod(umod); | |
| 3886 | 7406 | crefs_1 := InstUtil.getCrefFromCompDim(comp); | |
| 3887 | 7406 | crefs := List.unionOnTrue(crefs,crefs_1,AbsynUtil.crefEqual); | |
| 3888 | 7406 | name := SCodeUtil.elementName(comp); | |
| 3889 | 7406 | cref := Absyn.CREF_IDENT(name,{}); | |
| 3890 | |||
| 3891 | 7406 | ltmod := List.map1(crefs,InstUtil.getModsForDep,xs); | |
| 3892 | 7406 | cmod2 := List.fold2r(ltmod,Mod.merge,name,true,DAE.NOMOD()); | |
| 3893 | 7406 | SCode.PREFIXES(finalPrefix = fprefix) := SCodeUtil.elementPrefixes(comp); | |
| 3894 | |||
| 3895 | //print("("+intString(listLength(ltmod))+")UpdateCompeltsMods_(" + stringDelimitList(List.map(crefs,Dump.printComponentRefStr),",") + ") subs: " + stringDelimitList(List.map(crefs,Dump.printComponentRefStr),",")+ "\n"); | ||
| 3896 | //print(" acquired mods: " + Mod.printModStr(cmod2) + "\n"); | ||
| 3897 | |||
| 3898 | 7406 | (cache,env2,ih) := updateComponentsInEnv(cache, env, ih, pre, cmod2, crefs, ci_state, impl); | |
| 3899 | 22218 | (cache,env2,ih) := updateComponentsInEnv(cache, env2, ih, pre, | |
| 3900 | DAE.MOD(fprefix,SCode.NOT_EACH(),{DAE.NAMEMOD(name, cmod)},NONE(), cmod.info), | ||
| 3901 | {cref}, ci_state, impl); | ||
| 3902 | |||
| 3903 | 7406 | (cache,cmod_1) := Mod.updateMod(cache, env2, ih, pre, cmod, impl, info); | |
| 3904 | 7406 | (cache,env3,ih,res) := updateCompeltsMods_dispatch(cache, env2, ih, pre, xs, ci_state, impl); | |
| 3905 | 7406 | then | |
| 3906 | (cache,env3,ih,((comp,cmod_1) :: res)); | ||
| 3907 | |||
| 3908 | end matchcontinue; | ||
| 3909 | end updateCompeltsMods_dispatch; | ||
| 3910 | |||
| 3911 | public function redeclareType | ||
| 3912 | "This function takes a DAE.Mod and an SCode.Element and if the modification | ||
| 3913 | contains a redeclare of that element, the type is changed and an updated | ||
| 3914 | element is returned." | ||
| 3915 | input FCore.Cache inCache; | ||
| 3916 | input FCore.Graph inEnv; | ||
| 3917 | input InnerOuter.InstHierarchy inIH; | ||
| 3918 | input DAE.Mod inMod; | ||
| 3919 | input SCode.Element inElement; | ||
| 3920 | input DAE.Prefix inPrefix; | ||
| 3921 | input ClassInf.State inState; | ||
| 3922 | input Boolean inImpl; | ||
| 3923 | input DAE.Mod inCmod; | ||
| 3924 | output FCore.Cache outCache = inCache; | ||
| 3925 | output FCore.Graph outEnv = inEnv; | ||
| 3926 | output InnerOuter.InstHierarchy outIH = inIH; | ||
| 3927 | output SCode.Element outElement = inElement; | ||
| 3928 | output DAE.Mod outMod = DAE.NOMOD(); | ||
| 3929 | protected | ||
| 3930 | SCode.Element redecl_el; | ||
| 3931 | SCode.Mod mod; | ||
| 3932 | DAE.Mod redecl_mod, m, old_m; | ||
| 3933 | String redecl_name, name; | ||
| 3934 | SCode.Replaceable repl; | ||
| 3935 | Option<SCode.ConstrainClass> cc; | ||
| 3936 | list<SCode.Element> cc_comps; | ||
| 3937 | list<Absyn.ComponentRef> crefs; | ||
| 3938 | algorithm | ||
| 3939 |
2/2✓ Branch 1 taken 1214217 times.
✓ Branch 2 taken 3273 times.
|
1217490 | if not Mod.isRedeclareMod(inMod) then |
| 3940 | 1214217 | outMod := Mod.merge(inMod, inCmod); | |
| 3941 | 1214217 | return; | |
| 3942 | end if; | ||
| 3943 | |||
| 3944 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3273 times.
|
3273 | DAE.REDECL(element = redecl_el, mod = redecl_mod) := inMod; |
| 3945 | 3273 | redecl_name := SCodeUtil.elementName(redecl_el); | |
| 3946 | |||
| 3947 | (outElement, outMod) := matchcontinue (redecl_el, inElement) | ||
| 3948 | // Redeclaration of component. | ||
| 3949 | case (SCode.COMPONENT(), SCode.COMPONENT(prefixes = SCode.PREFIXES(replaceablePrefix = repl))) | ||
| 3950 | algorithm | ||
| 3951 |
2/4✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 50 times.
✗ Branch 4 not taken.
|
50 | true := redecl_name == inElement.name; |
| 3952 | |||
| 3953 | 50 | mod := InstUtil.chainRedeclares(inMod, redecl_el.modifications); | |
| 3954 | 50 | crefs := InstUtil.getCrefFromMod(mod); | |
| 3955 | 50 | (outCache, outEnv, outIH) := updateComponentsInEnv(inCache, inEnv, | |
| 3956 | inIH, inPrefix, DAE.NOMOD(), crefs, inState, inImpl); | ||
| 3957 | 50 | (outCache, m) := Mod.elabMod(outCache, outEnv, outIH, inPrefix, mod, | |
| 3958 | inImpl, Mod.COMPONENT(redecl_name), redecl_el.info); | ||
| 3959 | 50 | (outCache, old_m) := Mod.elabMod(outCache, outEnv, outIH, inPrefix, | |
| 3960 | inElement.modifications, inImpl, Mod.COMPONENT(inElement.name), inElement.info); | ||
| 3961 | |||
| 3962 | m := match repl | ||
| 3963 | case SCode.REPLACEABLE(cc = cc as SOME(_)) | ||
| 3964 | algorithm | ||
| 3965 | // Constraining type on the component: | ||
| 3966 | // Extract components belonging to constraining class. | ||
| 3967 | 6 | cc_comps := InstUtil.extractConstrainingComps(cc, inEnv, inPrefix); | |
| 3968 | // Keep previous constraining class mods. | ||
| 3969 | 6 | redecl_mod := InstUtil.keepConstrainingTypeModifersOnly(redecl_mod, cc_comps); | |
| 3970 | 6 | old_m := InstUtil.keepConstrainingTypeModifersOnly(old_m, cc_comps); | |
| 3971 | |||
| 3972 | 6 | m := Mod.merge(m, redecl_mod, redecl_name); | |
| 3973 | 6 | m := Mod.merge(m, old_m, redecl_name); | |
| 3974 | 6 | m := Mod.merge(m, inCmod, redecl_name); | |
| 3975 | then | ||
| 3976 | m; | ||
| 3977 | |||
| 3978 | else | ||
| 3979 | algorithm | ||
| 3980 | // No constraining type on comp, throw away modifiers prior to redeclaration: | ||
| 3981 | 44 | m := Mod.merge(redecl_mod, m, redecl_name); | |
| 3982 | 44 | m := Mod.merge(m, old_m, redecl_name); | |
| 3983 | 44 | m := Mod.merge(inCmod, m, redecl_name); | |
| 3984 | then | ||
| 3985 | m; | ||
| 3986 | end match; | ||
| 3987 | |||
| 3988 | 50 | (outCache, outElement) := | |
| 3989 | propagateRedeclCompAttr(outCache, outEnv, inElement, redecl_el); | ||
| 3990 | 50 | outElement := SCodeUtil.setComponentMod(outElement, mod); | |
| 3991 | 50 | then | |
| 3992 | (outElement, m); | ||
| 3993 | |||
| 3994 | // Redeclaration of class. | ||
| 3995 | case (SCode.CLASS(), SCode.CLASS()) | ||
| 3996 | algorithm | ||
| 3997 |
2/4✓ Branch 0 taken 3195 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3195 times.
|
3195 | true := redecl_name == inElement.name; |
| 3998 | 6390 | (outCache, outEnv, outIH) := updateComponentsInEnv(inCache, inEnv, inIH, | |
| 3999 | inPrefix, inMod, {Absyn.CREF_IDENT(inElement.name, {})}, inState, inImpl); | ||
| 4000 | 3195 | then | |
| 4001 | (inElement, redecl_mod); | ||
| 4002 | |||
| 4003 | // Local redeclaration of class type path is an id. | ||
| 4004 | case (SCode.CLASS(), SCode.COMPONENT()) | ||
| 4005 | algorithm | ||
| 4006 | 28 | name := AbsynUtil.typeSpecPathString(inElement.typeSpec); | |
| 4007 |
3/4✓ Branch 0 taken 26 times.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 26 times.
|
28 | true := redecl_name == name; |
| 4008 | 52 | (outCache, outEnv, outIH) := updateComponentsInEnv(inCache, inEnv, inIH, | |
| 4009 | inPrefix, inMod, {Absyn.CREF_IDENT(name, {})}, inState, inImpl); | ||
| 4010 | 26 | then | |
| 4011 | (inElement, redecl_mod); | ||
| 4012 | |||
| 4013 | // Local redeclaration of class, type is qualified. | ||
| 4014 | case (SCode.CLASS(), SCode.COMPONENT()) | ||
| 4015 | algorithm | ||
| 4016 | 2 | name := AbsynUtil.pathFirstIdent(AbsynUtil.typeSpecPath(inElement.typeSpec)); | |
| 4017 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
2 | true := redecl_name == name; |
| 4018 | ✗ | (outCache, outEnv, outIH) := updateComponentsInEnv(inCache, inEnv, inIH, | |
| 4019 | inPrefix, inMod, {Absyn.CREF_IDENT(name, {})}, inState, inImpl); | ||
| 4020 | ✗ | then | |
| 4021 | (inElement, redecl_mod); | ||
| 4022 | |||
| 4023 | else (inElement, DAE.NOMOD()); | ||
| 4024 | end matchcontinue; | ||
| 4025 | end redeclareType; | ||
| 4026 | |||
| 4027 | protected function propagateRedeclCompAttr | ||
| 4028 | "Helper function to redeclareType, propagates attributes from the old | ||
| 4029 | component to the new according to the rules for redeclare." | ||
| 4030 | input FCore.Cache inCache; | ||
| 4031 | input FCore.Graph inEnv; | ||
| 4032 | input SCode.Element inOldComponent; | ||
| 4033 | input SCode.Element inNewComponent; | ||
| 4034 | output FCore.Cache outCache = inCache; | ||
| 4035 | output SCode.Element outComponent; | ||
| 4036 | protected | ||
| 4037 | Boolean is_array = false; | ||
| 4038 | algorithm | ||
| 4039 | // If the old component has array dimensions but the new one doesn't, then we | ||
| 4040 | // need to check if the new component's type is an array type. If it is we | ||
| 4041 | // shouldn't propagate the dimensions from the old component. I.e. we should | ||
| 4042 | // treat: type Real3 = Real[3]; comp(redeclare Real3 x); | ||
| 4043 | // in the same way as: comp(redeclare Real x[3]). | ||
| 4044 |
3/4✓ Branch 1 taken 2 times.
✓ Branch 2 taken 48 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
50 | if SCodeUtil.isArrayComponent(inOldComponent) and not SCodeUtil.isArrayComponent(inNewComponent) then |
| 4045 | 2 | (outCache, is_array) := Lookup.isArrayType(outCache, inEnv, SCodeUtil.getElementTypePath(inNewComponent)); | |
| 4046 | end if; | ||
| 4047 | |||
| 4048 | 50 | outComponent := SCodeUtil.propagateAttributesVar(inOldComponent, inNewComponent, is_array); | |
| 4049 | end propagateRedeclCompAttr; | ||
| 4050 | |||
| 4051 | protected function updateComponentsInEnv | ||
| 4052 | "author: PA | ||
| 4053 | This function is the second pass of component instantiation, when a | ||
| 4054 | component can be instantiated fully and the type of the component can be | ||
| 4055 | determined. The type is added/updated to the environment such that other | ||
| 4056 | components can use it when they are instantiated." | ||
| 4057 | input FCore.Cache cache; | ||
| 4058 | input FCore.Graph env; | ||
| 4059 | input InnerOuter.InstHierarchy inIH; | ||
| 4060 | input DAE.Prefix pre; | ||
| 4061 | input DAE.Mod mod; | ||
| 4062 | input list<Absyn.ComponentRef> crefs; | ||
| 4063 | input ClassInf.State ci_state; | ||
| 4064 | input Boolean impl; | ||
| 4065 | output FCore.Cache outCache = cache; | ||
| 4066 | output FCore.Graph outEnv = env; | ||
| 4067 | output InnerOuter.InstHierarchy outIH = inIH; | ||
| 4068 | algorithm | ||
| 4069 | 583765 | ErrorExt.setCheckpoint("updateComponentsInEnv__"); | |
| 4070 | |||
| 4071 | // do NOT fail and do not display any errors from this function as it tries | ||
| 4072 | // to type and evaluate dependent things but not with enough information | ||
| 4073 | try | ||
| 4074 | 583765 | (outCache, outEnv, outIH) := | |
| 4075 | updateComponentsInEnv2(cache, env, inIH, pre, mod, crefs, ci_state, impl); | ||
| 4076 | else | ||
| 4077 | end try; | ||
| 4078 | |||
| 4079 | 583765 | ErrorExt.rollBack("updateComponentsInEnv__") "roll back any errors"; | |
| 4080 | end updateComponentsInEnv; | ||
| 4081 | |||
| 4082 | protected function getUpdatedCompsHashTable | ||
| 4083 | "Routine to lazily create the hashtable as it usually unused" | ||
| 4084 | input Option<HashTable5.HashTable> optHT; | ||
| 4085 | output HashTable5.HashTable ht; | ||
| 4086 | algorithm | ||
| 4087 | ht := match optHT | ||
| 4088 | case SOME(ht) then ht; | ||
| 4089 | 31826 | else HashTable5.emptyHashTableSized(BaseHashTable.lowBucketSize); | |
| 4090 | end match; | ||
| 4091 | end getUpdatedCompsHashTable; | ||
| 4092 | |||
| 4093 | protected function updateComponentInEnv | ||
| 4094 | "Helper function to updateComponentsInEnv. Does the work for one variable." | ||
| 4095 | input FCore.Cache inCache; | ||
| 4096 | input FCore.Graph inEnv; | ||
| 4097 | input InnerOuter.InstHierarchy inIH; | ||
| 4098 | input DAE.Prefix pre; | ||
| 4099 | input DAE.Mod mod; | ||
| 4100 | input Absyn.ComponentRef cref; | ||
| 4101 | input ClassInf.State inCIState; | ||
| 4102 | input Boolean impl; | ||
| 4103 | input Option<HashTable5.HashTable> inUpdatedComps; | ||
| 4104 | input Option<Absyn.ComponentRef> currentCref "The cref that caused this call to updateComponentInEnv."; | ||
| 4105 | output FCore.Cache outCache; | ||
| 4106 | output FCore.Graph outEnv; | ||
| 4107 | output InnerOuter.InstHierarchy outIH; | ||
| 4108 | output Option<HashTable5.HashTable> outUpdatedComps; | ||
| 4109 | algorithm | ||
| 4110 | (outCache,outEnv,outIH,outUpdatedComps) := | ||
| 4111 | matchcontinue (inCache, inEnv, inIH, mod) | ||
| 4112 | local | ||
| 4113 | String n,id, name; | ||
| 4114 | SCode.ConnectorType ct; | ||
| 4115 | Absyn.InnerOuter io; | ||
| 4116 | SCode.Attributes attr; | ||
| 4117 | list<Absyn.Subscript> ad; | ||
| 4118 | SCode.Parallelism prl1; | ||
| 4119 | SCode.Variability var1; | ||
| 4120 | Absyn.Direction dir; | ||
| 4121 | Absyn.Path t; | ||
| 4122 | SCode.Mod m; | ||
| 4123 | DAE.Mod cmod,mods; | ||
| 4124 | SCode.Element cl; | ||
| 4125 | FCore.Graph cenv,env2,env_1; | ||
| 4126 | list<Absyn.ComponentRef> crefs,crefs2,crefs3,crefs_1,crefs_2; | ||
| 4127 | Option<Absyn.Exp> cond; | ||
| 4128 | FCore.Status is; | ||
| 4129 | SourceInfo info; | ||
| 4130 | InstanceHierarchy ih; | ||
| 4131 | SCode.Prefixes pf; | ||
| 4132 | SCode.Visibility visibility "protected/public"; | ||
| 4133 | SCode.Mod smod; | ||
| 4134 | DAE.Mod daeMod; | ||
| 4135 | SCode.Prefixes prefixes; | ||
| 4136 | SCode.Attributes attributes; | ||
| 4137 | FCore.Graph env, idENV; | ||
| 4138 | FCore.Cache cache; | ||
| 4139 | HashTable5.HashTable updatedComps; | ||
| 4140 | ClassInf.State ci_state; | ||
| 4141 | |||
| 4142 | // if there are no modifications, return the same! | ||
| 4143 | //case (cache,env,ih,pre,DAE.NOMOD(),cref,ci_state,csets,impl,_) | ||
| 4144 | // then | ||
| 4145 | // (cache,env,ih,csets,updatedComps); | ||
| 4146 | |||
| 4147 | // if we have a redeclare for a component | ||
| 4148 | /*case (cache,env,ih,_, | ||
| 4149 | DAE.MOD(binding = NONE(), | ||
| 4150 | subModLst = { | ||
| 4151 | DAE.NAMEMOD(ident=n, | ||
| 4152 | mod = rmod as DAE.REDECL(_, _, {(SCode.COMPONENT(name = name),_)}))}),_,_,_,_,_) | ||
| 4153 | algorithm | ||
| 4154 | id = AbsynUtil.crefFirstIdent(cref); | ||
| 4155 | true = stringEq(id, name); | ||
| 4156 | true = stringEq(id, n); | ||
| 4157 | (outCache,outEnv,outIH,outUpdatedComps) = updateComponentInEnv(inCache,inEnv,inIH,pre,rmod,cref,inCIState,impl,inUpdatedComps,currentCref); | ||
| 4158 | then | ||
| 4159 | (outCache,outEnv,outIH,outUpdatedComps);*/ | ||
| 4160 | |||
| 4161 | // if we have a redeclare for a component | ||
| 4162 | case (cache, env, ih, DAE.REDECL(element = | ||
| 4163 | SCode.COMPONENT( | ||
| 4164 | name = name, | ||
| 4165 | prefixes = prefixes as SCode.PREFIXES(visibility = visibility), | ||
| 4166 | attributes = attributes, | ||
| 4167 | modifications = smod, | ||
| 4168 | info = info))) | ||
| 4169 | algorithm | ||
| 4170 | 1 | id := AbsynUtil.crefFirstIdent(cref); | |
| 4171 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | true := stringEq(id, name); |
| 4172 | // redeclare with modfication!! | ||
| 4173 | ✗ | false := valueEq(smod, SCode.NOMOD()); | |
| 4174 | |||
| 4175 | // get Var | ||
| 4176 | ✗ | (cache,DAE.TYPES_VAR(_,_,_,_,_),_,_,_,_) := Lookup.lookupIdentLocal(cache, env, name); | |
| 4177 | // types are the same, this means only the binding/visibility, etc was updated! | ||
| 4178 | //true = valueEq(tsOld, tsNew); | ||
| 4179 | |||
| 4180 | // update frame in env! | ||
| 4181 | // fprintln(Flags.INST_TRACE, "updateComponentInEnv: found a redeclaration that only changes bindings and prefixes: NEW:\n" + SCodeDump.unparseElementStr(compNew) + " in env:" + FGraph.printGraphPathStr(env)); | ||
| 4182 | |||
| 4183 | // update the mod then give it to | ||
| 4184 | ✗ | (cache, daeMod) := Mod.elabMod(cache, env, ih, pre, smod, impl, Mod.COMPONENT(name), info); | |
| 4185 | |||
| 4186 | // take the mods and attributes from the new comp! | ||
| 4187 | ✗ | mods := daeMod; | |
| 4188 | attr := attributes; | ||
| 4189 | ✗ | m := smod; | |
| 4190 | ✗ | cmod := DAE.NOMOD(); | |
| 4191 | pf := prefixes; | ||
| 4192 | ✗ | io := SCodeUtil.prefixesInnerOuter(pf); | |
| 4193 | ✗ | SCode.ATTR(ad,ct,prl1,var1,dir) := attr; | |
| 4194 | |||
| 4195 | ✗ | (cache,_,SCode.COMPONENT(n,_,_,Absyn.TPATH(t, _),_,_,cond,info),_,_,idENV) | |
| 4196 | := Lookup.lookupIdent(cache, env, id); | ||
| 4197 | |||
| 4198 | ✗ | ci_state := InstUtil.updateClassInfState(cache, idENV, env, inCIState); | |
| 4199 | |||
| 4200 | //Debug.traceln("update comp " + n + " with mods:" + Mod.printModStr(mods) + " m:" + SCodeDump.printModStr(m) + " cm:" + Mod.printModStr(cmod)); | ||
| 4201 | ✗ | (cache,cl,cenv) := Lookup.lookupClass(cache, env, t); | |
| 4202 | //Debug.traceln("got class " + SCodeDump.printClassStr(cl)); | ||
| 4203 | ✗ | updatedComps := getUpdatedCompsHashTable(inUpdatedComps); | |
| 4204 | ✗ | (mods,cmod,m) := InstUtil.noModForUpdatedComponents(var1,updatedComps,cref,mods,cmod,m); | |
| 4205 | ✗ | crefs := InstUtil.getCrefFromMod(m); | |
| 4206 | ✗ | crefs2 := InstUtil.getCrefFromDim(ad); | |
| 4207 | ✗ | crefs3 := InstUtil.getCrefFromCond(cond); | |
| 4208 | ✗ | crefs_1 := listAppend(crefs, listAppend(crefs2,crefs3)); | |
| 4209 | ✗ | crefs_2 := InstUtil.removeCrefFromCrefs(crefs_1, cref); | |
| 4210 | ✗ | updatedComps := BaseHashTable.add((cref,0),updatedComps); | |
| 4211 | ✗ | (cache,env2,ih,SOME(updatedComps)) := updateComponentsInEnv2(cache, env, ih, pre, DAE.NOMOD(), crefs_2, ci_state, impl, SOME(updatedComps), SOME(cref)); | |
| 4212 | |||
| 4213 | ✗ | (cache,env_1,ih,updatedComps) := updateComponentInEnv2(cache,env2,cenv,ih,pre,t,n,ad,cl,attr,pf,DAE.ATTR(DAEUtil.toConnectorTypeNoState(ct),prl1,var1,dir,io,visibility),info,m,cmod,mods,cref,ci_state,impl,updatedComps); | |
| 4214 | |||
| 4215 | //print("updateComponentInEnv: NEW ENV:\n" + FGraph.printGraphStr(env_1) + "\n"); | ||
| 4216 | ✗ | then | |
| 4217 | (cache,env_1,ih,SOME(updatedComps)); | ||
| 4218 | |||
| 4219 | // redeclare class! | ||
| 4220 | case (cache, env, ih, DAE.REDECL(element = SCode.CLASS(name = name))) | ||
| 4221 | algorithm | ||
| 4222 | 3221 | id := AbsynUtil.crefFirstIdent(cref); | |
| 4223 |
2/4✓ Branch 0 taken 3221 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3221 times.
|
3221 | true := stringEq(name, id); |
| 4224 | // fetch the original class! | ||
| 4225 | 3221 | (cl, _) := Lookup.lookupClassLocal(env, name); | |
| 4226 | 3221 | env := FGraph.updateClass(env, SCodeUtil.mergeWithOriginal(mod.element, cl), pre, mod, FCore.CLS_UNTYPED(), env); | |
| 4227 | 3221 | updatedComps := getUpdatedCompsHashTable(inUpdatedComps); | |
| 4228 | 3221 | updatedComps := BaseHashTable.add((cref,0),updatedComps); | |
| 4229 | then | ||
| 4230 | (cache,env,ih,SOME(updatedComps)); | ||
| 4231 | |||
| 4232 | // Variable with NONE() element is already instantiated. | ||
| 4233 | case (cache, env, ih, _) | ||
| 4234 | algorithm | ||
| 4235 | 86363 | id := AbsynUtil.crefFirstIdent(cref); | |
| 4236 | 86363 | (cache,_,_,_,is,_) := Lookup.lookupIdent(cache,env,id); | |
| 4237 |
2/2✓ Branch 1 taken 28642 times.
✓ Branch 2 taken 9538 times.
|
38180 | true := FCore.isTyped(is) "If InstStatus is typed, return"; |
| 4238 | then | ||
| 4239 | (cache,env,ih,inUpdatedComps); | ||
| 4240 | |||
| 4241 | // the default case | ||
| 4242 | case (cache, env, ih, mods) | ||
| 4243 | algorithm | ||
| 4244 | 76825 | id := AbsynUtil.crefFirstIdent(cref); | |
| 4245 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 28642 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 28642 times.
|
76825 | (cache,_, |
| 4246 | SCode.COMPONENT( | ||
| 4247 | n, | ||
| 4248 | pf as SCode.PREFIXES(innerOuter = io, visibility = visibility), | ||
| 4249 | attr as SCode.ATTR(ad,ct,prl1,var1,dir), | ||
| 4250 | Absyn.TPATH(t, _),m,_,cond,info),cmod,_,idENV) | ||
| 4251 | := Lookup.lookupIdent(cache, env, id); | ||
| 4252 | |||
| 4253 | 28642 | ci_state := InstUtil.updateClassInfState(cache, idENV, env, inCIState); | |
| 4254 | |||
| 4255 | //Debug.traceln("update comp " + n + " with mods:" + Mod.printModStr(mods) + " m:" + SCodeDump.printModStr(m) + " cm:" + Mod.printModStr(cmod)); | ||
| 4256 | 28642 | (cache,cl,cenv) := Lookup.lookupClass(cache, env, t); | |
| 4257 | //Debug.traceln("got class " + SCodeDump.printClassStr(cl)); | ||
| 4258 | 28642 | updatedComps := getUpdatedCompsHashTable(inUpdatedComps); | |
| 4259 | 28642 | (mods,cmod,m) := InstUtil.noModForUpdatedComponents(var1,updatedComps,cref,mods,cmod,m); | |
| 4260 | 143210 | crefs := List.flatten({ | |
| 4261 | InstUtil.getCrefFromMod(m), | ||
| 4262 | InstUtil.getCrefFromDim(ad), | ||
| 4263 | InstUtil.getCrefFromCond(cond), | ||
| 4264 | Mod.getUntypedCrefs(cmod)}); | ||
| 4265 | 28642 | crefs_2 := InstUtil.removeCrefFromCrefs(crefs, cref); | |
| 4266 | // Also remove the cref that caused this updateComponentInEnv call, to avoid | ||
| 4267 | // infinite loops. | ||
| 4268 | 28642 | crefs_2 := InstUtil.removeOptCrefFromCrefs(crefs_2, currentCref); | |
| 4269 | 28642 | updatedComps := BaseHashTable.add((cref,0),updatedComps); | |
| 4270 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 28642 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 28642 times.
|
28642 | (cache,env2,ih,SOME(updatedComps)) := updateComponentsInEnv2(cache, env, ih, pre, mods, crefs_2, ci_state, impl, SOME(updatedComps), SOME(cref)); |
| 4271 | 28642 | (cache,env_1,ih,updatedComps) := updateComponentInEnv2(cache,env2,cenv,ih,pre,t,n,ad,cl,attr,pf,DAE.ATTR(DAEUtil.toConnectorTypeNoState(ct),prl1,var1,dir,io,visibility),info,m,cmod,mods,cref,ci_state,impl,updatedComps); | |
| 4272 | 28540 | then | |
| 4273 | (cache,env_1,ih,SOME(updatedComps)); | ||
| 4274 | |||
| 4275 | // If first part of ident is a class, e.g StateSelect.None, nothing to update | ||
| 4276 | case (cache, env, ih, _) | ||
| 4277 | then | ||
| 4278 | (cache,env,ih,inUpdatedComps); | ||
| 4279 | // report an error! | ||
| 4280 | case (_, env, _, _) | ||
| 4281 | algorithm | ||
| 4282 | ✗ | true := Flags.isSet(Flags.FAILTRACE); | |
| 4283 | ✗ | Debug.traceln("- Inst.updateComponentInEnv failed, cref = " + Dump.printComponentRefStr(cref)); | |
| 4284 | ✗ | Debug.traceln(" mods: " + Mod.printModStr(mod)); | |
| 4285 | ✗ | Debug.traceln(" scope: " + FGraph.printGraphPathStr(env)); | |
| 4286 | ✗ | Debug.traceln(" prefix: " + PrefixUtil.printPrefixStr(pre)); | |
| 4287 | //print("Env:\n" + FGraph.printGraphStr(env) + "\n"); | ||
| 4288 | ✗ | then | |
| 4289 | fail(); | ||
| 4290 | |||
| 4291 | else (inCache,inEnv,inIH,inUpdatedComps); | ||
| 4292 | end matchcontinue; | ||
| 4293 | end updateComponentInEnv; | ||
| 4294 | |||
| 4295 | protected function updateComponentInEnv2 | ||
| 4296 | " Helper function, checks if the component was already instantiated. | ||
| 4297 | If it was, don't do it again." | ||
| 4298 | input FCore.Cache inCache; | ||
| 4299 | input FCore.Graph inEnv; | ||
| 4300 | input FCore.Graph cenv; | ||
| 4301 | input InnerOuter.InstHierarchy inIH; | ||
| 4302 | input DAE.Prefix pre; | ||
| 4303 | input Absyn.Path path; | ||
| 4304 | input String name; | ||
| 4305 | input list<Absyn.Subscript> ad; | ||
| 4306 | input SCode.Element cl; | ||
| 4307 | input SCode.Attributes attr; | ||
| 4308 | input SCode.Prefixes inPrefixes; | ||
| 4309 | input DAE.Attributes dattr; | ||
| 4310 | input SourceInfo info; | ||
| 4311 | input SCode.Mod m; | ||
| 4312 | input DAE.Mod cmod; | ||
| 4313 | input DAE.Mod mod; | ||
| 4314 | input Absyn.ComponentRef cref; | ||
| 4315 | input ClassInf.State ci_state; | ||
| 4316 | input Boolean impl; | ||
| 4317 | input HashTable5.HashTable inUpdatedComps; | ||
| 4318 | output FCore.Cache outCache; | ||
| 4319 | output FCore.Graph outEnv; | ||
| 4320 | output InnerOuter.InstHierarchy outIH; | ||
| 4321 | output HashTable5.HashTable outUpdatedComps; | ||
| 4322 | algorithm | ||
| 4323 | try | ||
| 4324 | 28642 | ErrorExt.setCheckpoint("Inst.updateComponentInEnv2"); | |
| 4325 | 28642 | (outCache, outEnv, outIH, outUpdatedComps) := | |
| 4326 | updateComponentInEnv2_dispatch(inCache, inEnv, cenv, inIH, pre, path, | ||
| 4327 | name, ad, cl, attr, inPrefixes, dattr, info, m, cmod, mod, cref, | ||
| 4328 | ci_state, impl, inUpdatedComps); | ||
| 4329 | 28540 | ErrorExt.delCheckpoint("Inst.updateComponentInEnv2"); | |
| 4330 | else | ||
| 4331 | 102 | ErrorExt.rollBack("Inst.updateComponentInEnv2"); | |
| 4332 | 102 | fail(); | |
| 4333 | end try; | ||
| 4334 | end updateComponentInEnv2; | ||
| 4335 | |||
| 4336 | protected function updateComponentInEnv2_dispatch | ||
| 4337 | input FCore.Cache inCache; | ||
| 4338 | input FCore.Graph inEnv; | ||
| 4339 | input FCore.Graph inClsEnv; | ||
| 4340 | input InnerOuter.InstHierarchy inIH; | ||
| 4341 | input DAE.Prefix inPrefix; | ||
| 4342 | input Absyn.Path inPath; | ||
| 4343 | input String inName; | ||
| 4344 | input list<Absyn.Subscript> inSubscripts; | ||
| 4345 | input SCode.Element inClass; | ||
| 4346 | input SCode.Attributes inAttr; | ||
| 4347 | input SCode.Prefixes inPrefixes; | ||
| 4348 | input DAE.Attributes inDAttr; | ||
| 4349 | input SourceInfo inInfo; | ||
| 4350 | input SCode.Mod inSMod; | ||
| 4351 | input DAE.Mod inClsMod; | ||
| 4352 | input DAE.Mod inMod; | ||
| 4353 | input Absyn.ComponentRef inCref; | ||
| 4354 | input ClassInf.State inState; | ||
| 4355 | input Boolean inImpl; | ||
| 4356 | input HashTable5.HashTable inUpdatedComps; | ||
| 4357 | output FCore.Cache outCache = inCache; | ||
| 4358 | output FCore.Graph outEnv = inEnv; | ||
| 4359 | output InnerOuter.InstHierarchy outIH = inIH; | ||
| 4360 | output HashTable5.HashTable outUpdatedComps = inUpdatedComps; | ||
| 4361 | protected | ||
| 4362 | SCode.Mod smod; | ||
| 4363 | DAE.Mod mod, mod1, mod2, class_mod; | ||
| 4364 | Option<DAE.EqMod> eq; | ||
| 4365 | Absyn.ComponentRef own_cref; | ||
| 4366 | list<DAE.Dimension> dims; | ||
| 4367 | FCore.Graph cls_env, comp_env; | ||
| 4368 | SCode.Element cls; | ||
| 4369 | DAE.Type ty; | ||
| 4370 | DAE.Binding binding; | ||
| 4371 | DAE.Var var; | ||
| 4372 | algorithm | ||
| 4373 | try | ||
| 4374 |
1/2✓ Branch 1 taken 28642 times.
✗ Branch 2 not taken.
|
28642 | 1 := BaseHashTable.get(inCref, inUpdatedComps); |
| 4375 | else | ||
| 4376 | 28642 | smod := SCodeUtil.mergeModifiers(inSMod, SCodeUtil.getConstrainedByModifiers(inPrefixes)); | |
| 4377 | 28642 | (outCache, mod1) := | |
| 4378 | updateComponentInEnv3(outCache, outEnv, outIH, smod, inImpl, Mod.COMPONENT(inName), inInfo); | ||
| 4379 | 28642 | class_mod := Mod.lookupModificationP(inMod, inPath); | |
| 4380 | //comp_mod := Mod.lookupCompModification(inMod, inName); | ||
| 4381 | //mod2 := Mod.merge(class_mod, comp_mod, inName); | ||
| 4382 | 28642 | mod2 := Mod.merge(class_mod, mod1, inName); | |
| 4383 | 28642 | mod2 := Mod.merge(inClsMod, mod2, inName); | |
| 4384 | 28639 | (outCache, mod2) := | |
| 4385 | Mod.updateMod(outCache, outEnv, outIH, DAE.NOPRE(), mod2, inImpl, inInfo); | ||
| 4386 | |||
| 4387 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 28638 times.
|
28639 | mod := if InstUtil.redeclareBasicType(inClsMod) then mod1 else mod2; |
| 4388 | 28639 | eq := Mod.modEquation(mod); | |
| 4389 | |||
| 4390 | 28639 | own_cref := Absyn.CREF_IDENT(inName, {}); | |
| 4391 | 28639 | (outCache, dims) := InstUtil.elabArraydim(outCache, outEnv, own_cref, inPath, | |
| 4392 | inSubscripts, eq, inImpl, true, false, inPrefix, inInfo, {}); | ||
| 4393 | |||
| 4394 | // Instantiate the component. | ||
| 4395 | 28637 | (cls_env, cls, outIH) := | |
| 4396 | FGraph.createVersionScope(outEnv, inName, inPrefix, mod, inClsEnv, inClass, outIH); | ||
| 4397 | 28637 | (outCache, comp_env, outIH, _, _, _, ty) := | |
| 4398 | InstVar.instVar(outCache, cls_env, outIH, UnitAbsyn.noStore, inState, mod, | ||
| 4399 | inPrefix, inName, cls, inAttr, inPrefixes, dims, {}, {}, inImpl, | ||
| 4400 | SCode.noComment, inInfo, ConnectionGraph.EMPTY, Connect.emptySet, outEnv); | ||
| 4401 | |||
| 4402 | // The environment is extended with the new variable binding. | ||
| 4403 | 28540 | (outCache, binding) := | |
| 4404 | InstBinding.makeBinding(outCache, outEnv, inAttr, mod, ty, inPrefix, inName, inInfo); | ||
| 4405 | 28540 | var := DAE.TYPES_VAR(inName, inDAttr, ty, binding, false, NONE()); | |
| 4406 | 28540 | outEnv := FGraph.updateComp(outEnv, var, FCore.VAR_TYPED(), comp_env); | |
| 4407 | 28540 | outUpdatedComps := BaseHashTable.add((inCref, 1), outUpdatedComps); | |
| 4408 | end try; | ||
| 4409 | end updateComponentInEnv2_dispatch; | ||
| 4410 | |||
| 4411 | protected function updateComponentInEnv3 | ||
| 4412 | input FCore.Cache inCache; | ||
| 4413 | input FCore.Graph inEnv; | ||
| 4414 | input InnerOuter.InstHierarchy inIH; | ||
| 4415 | input SCode.Mod inMod; | ||
| 4416 | input Boolean inImpl; | ||
| 4417 | input Mod.ModScope inModScope; | ||
| 4418 | input SourceInfo inInfo; | ||
| 4419 | output FCore.Cache outCache; | ||
| 4420 | output DAE.Mod outMod; | ||
| 4421 | algorithm | ||
| 4422 | (outCache, outMod) := | ||
| 4423 | matchcontinue inInfo | ||
| 4424 | local | ||
| 4425 | DAE.Mod mod; | ||
| 4426 | FCore.Cache cache; | ||
| 4427 | |||
| 4428 | case _ | ||
| 4429 | algorithm | ||
| 4430 | 28642 | ErrorExt.setCheckpoint("updateComponentInEnv3"); | |
| 4431 | 28642 | (cache, mod) := Mod.elabMod(inCache, inEnv, inIH, DAE.NOPRE(), inMod, inImpl, inModScope, inInfo) | |
| 4432 | "Prefix does not matter, since we only update types | ||
| 4433 | in env, and does not make any dae elements, etc.." ; | ||
| 4434 | 28642 | ErrorExt.rollBack("updateComponentInEnv3") | |
| 4435 | "Rollback all error since we are only interested in type, not value at | ||
| 4436 | this point. Errors that occur in elabMod which does not fail the | ||
| 4437 | function will be accepted."; | ||
| 4438 |
1/2✓ Branch 0 taken 28642 times.
✗ Branch 1 not taken.
|
28642 | then |
| 4439 | (cache, mod); | ||
| 4440 | |||
| 4441 | /*/ did not work, elab it untyped! | ||
| 4442 | case (cache, _, _, _, _, _) | ||
| 4443 | algorithm | ||
| 4444 | ErrorExt.rollBack("updateComponentInEnv3"); | ||
| 4445 | ErrorExt.setCheckpoint("updateComponentInEnv3"); | ||
| 4446 | mod = Mod.elabUntypedMod(inMod, inEnv, DAE.NOPRE()); | ||
| 4447 | ErrorExt.rollBack("updateComponentInEnv3") | ||
| 4448 | "Rollback all error since we are only interested in type, not value at | ||
| 4449 | this point. Errors that occur in elabMod which does not fail the | ||
| 4450 | function will be accepted."; | ||
| 4451 | then | ||
| 4452 | (cache, mod);*/ | ||
| 4453 | |||
| 4454 | else | ||
| 4455 | algorithm | ||
| 4456 | ✗ | ErrorExt.rollBack("updateComponentInEnv3"); | |
| 4457 | ✗ | then | |
| 4458 | fail(); | ||
| 4459 | end matchcontinue; | ||
| 4460 | end updateComponentInEnv3; | ||
| 4461 | |||
| 4462 | public function makeEnvFromProgram | ||
| 4463 | "This function takes a SCode.Program and builds an environment." | ||
| 4464 | input SCode.Program prog; | ||
| 4465 | output FCore.Cache outCache; | ||
| 4466 | output FCore.Graph env_1; | ||
| 4467 | protected | ||
| 4468 | FCore.Graph env; | ||
| 4469 | FCore.Cache cache; | ||
| 4470 | algorithm | ||
| 4471 | // prog := scodeFlatten(prog, path); | ||
| 4472 | 27961 | (cache, env) := Builtin.initialGraph(FCore.emptyCache()); | |
| 4473 | 27961 | env_1 := FGraphBuildEnv.mkProgramGraph(prog, FCore.USERDEFINED(),env); | |
| 4474 | outCache := cache; | ||
| 4475 | end makeEnvFromProgram; | ||
| 4476 | |||
| 4477 | public function makeFullyQualified | ||
| 4478 | "author: PA | ||
| 4479 | Transforms a class name to its fully qualified name by investigating the environment. | ||
| 4480 | For instance, the model Resistor in Modelica.Electrical.Analog.Basic will given the | ||
| 4481 | correct environment have the fully qualified name: Modelica.Electrical.Analog.Basic.Resistor" | ||
| 4482 | input output FCore.Cache cache; | ||
| 4483 | input FCore.Graph inEnv; | ||
| 4484 | input output Absyn.Path path; | ||
| 4485 | algorithm | ||
| 4486 | (cache,path) := match path | ||
| 4487 | |||
| 4488 | // Special cases: assert and reinit can not be handled by builtin.mo, since they do not have return type | ||
| 4489 | case Absyn.IDENT() | ||
| 4490 | algorithm | ||
| 4491 | 114056 | (cache,path) := makeFullyQualifiedIdent(cache,inEnv,path.name,path); | |
| 4492 | then (cache,path); | ||
| 4493 | |||
| 4494 | // do NOT fully quallify again a fully qualified path! | ||
| 4495 | 1895 | case Absyn.FULLYQUALIFIED() then (cache, path); | |
| 4496 | |||
| 4497 | // To make a class fully qualified, the class path is looked up in the environment. | ||
| 4498 | // The FQ path consist of the simple class name appended to the environment path of the looked up class. | ||
| 4499 | case Absyn.QUALIFIED() | ||
| 4500 | algorithm | ||
| 4501 | 26743 | (cache,path) := makeFullyQualifiedFromQual(cache,inEnv,path); | |
| 4502 | then (cache,path); | ||
| 4503 | end match; | ||
| 4504 | end makeFullyQualified; | ||
| 4505 | |||
| 4506 | protected function makeFullyQualifiedFromQual | ||
| 4507 | input output FCore.Cache cache; | ||
| 4508 | input FCore.Graph inEnv; | ||
| 4509 | input output Absyn.Path path; | ||
| 4510 | algorithm | ||
| 4511 | (cache,path) := matchcontinue path | ||
| 4512 | local | ||
| 4513 | FCore.Graph env,env_1; | ||
| 4514 | Absyn.Path path_2,path3; | ||
| 4515 | DAE.ComponentRef crPath; | ||
| 4516 | Absyn.Ident name; | ||
| 4517 | case _ | ||
| 4518 | algorithm | ||
| 4519 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 26739 times.
|
26743 | (cache,SCode.CLASS(name = name),env_1) := Lookup.lookupClass(cache, inEnv, path); |
| 4520 | 26739 | path_2 := makeFullyQualified2(env_1,name); | |
| 4521 | 26739 | then (cache,AbsynUtil.makeFullyQualified(path_2)); | |
| 4522 | case _ | ||
| 4523 | algorithm | ||
| 4524 | 4 | crPath := ComponentReference.pathToCref(path); | |
| 4525 | 4 | (cache,_,_,_,_,_,env,_,name) := Lookup.lookupVarInternal(cache, inEnv, crPath, InstTypes.SEARCH_ALSO_BUILTIN()); | |
| 4526 | ✗ | path3 := makeFullyQualified2(env,name); | |
| 4527 | ✗ | then (cache,AbsynUtil.makeFullyQualified(path3)); | |
| 4528 | case _ | ||
| 4529 | algorithm | ||
| 4530 | 4 | crPath := ComponentReference.pathToCref(path); | |
| 4531 | 4 | (cache,env,_,_,_,_,_,_,name) := Lookup.lookupVarInPackages(cache, inEnv, crPath, {}, Mutable.create(false)); | |
| 4532 | ✗ | path3 := makeFullyQualified2(env,name); | |
| 4533 | ✗ | then (cache,AbsynUtil.makeFullyQualified(path3)); | |
| 4534 | 4 | else (cache,path); | |
| 4535 | end matchcontinue; | ||
| 4536 | end makeFullyQualifiedFromQual; | ||
| 4537 | |||
| 4538 | public function makeFullyQualifiedIdent | ||
| 4539 | "author: PA | ||
| 4540 | Transforms a class name to its fully qualified name by investigating the environment. | ||
| 4541 | For instance, the model Resistor in Modelica.Electrical.Analog.Basic will given the | ||
| 4542 | correct environment have the fully qualified name: Modelica.Electrical.Analog.Basic.Resistor" | ||
| 4543 | input FCore.Cache inCache; | ||
| 4544 | input FCore.Graph inEnv; | ||
| 4545 | input String ident; | ||
| 4546 | input Absyn.Path inPath=Absyn.IDENT(""); | ||
| 4547 | output FCore.Cache outCache; | ||
| 4548 | output Absyn.Path outPath; | ||
| 4549 | protected | ||
| 4550 | Boolean isKnownBuiltin; | ||
| 4551 | algorithm | ||
| 4552 | 1096993 | (outPath,isKnownBuiltin) := makeFullyQualifiedIdentCheckBuiltin(ident); | |
| 4553 |
2/2✓ Branch 0 taken 579200 times.
✓ Branch 1 taken 517793 times.
|
1096993 | if isKnownBuiltin then |
| 4554 | outCache := inCache; | ||
| 4555 | 579200 | return; | |
| 4556 | end if; | ||
| 4557 | (outCache,outPath) := matchcontinue (inCache,inEnv,ident) | ||
| 4558 | local | ||
| 4559 | FCore.Graph env,env_1; | ||
| 4560 | Absyn.Path path_2,path3; | ||
| 4561 | String s; | ||
| 4562 | FCore.Cache cache; | ||
| 4563 | Absyn.Ident name; | ||
| 4564 | FCore.Ref r; | ||
| 4565 | |||
| 4566 | // To make a class fully qualified, the class path is looked up in the environment. | ||
| 4567 | // The FQ path consist of the simple class name appended to the environment path of the looked up class. | ||
| 4568 | case (cache,env,_) | ||
| 4569 | algorithm | ||
| 4570 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 502414 times.
|
517793 | (cache,SCode.CLASS(name = name),env_1) := Lookup.lookupClassIdent(cache, env, ident); |
| 4571 | 502414 | path_2 := makeFullyQualified2(env_1,name); | |
| 4572 | 502414 | then | |
| 4573 | (cache,AbsynUtil.makeFullyQualified(path_2)); | ||
| 4574 | |||
| 4575 | // Needed to make external objects fully-qualified | ||
| 4576 | case (cache,env,s) | ||
| 4577 | algorithm | ||
| 4578 | 15379 | r := FGraph.lastScopeRef(env); | |
| 4579 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 15379 times.
|
15379 | false := FNode.isRefTop(r); |
| 4580 | 15379 | name := FNode.refName(r); | |
| 4581 |
3/4✓ Branch 0 taken 36 times.
✓ Branch 1 taken 15343 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 36 times.
|
15379 | true := name == s; |
| 4582 | ✗ | SOME(path_2) := FGraph.getScopePath(env); | |
| 4583 | ✗ | then | |
| 4584 | (cache,AbsynUtil.makeFullyQualified(path_2)); | ||
| 4585 | |||
| 4586 | // A type can exist without a class (i.e. builtin functions) | ||
| 4587 | case (cache,env,s) | ||
| 4588 | algorithm | ||
| 4589 | 15379 | (cache,_,env_1) := Lookup.lookupTypeIdent(cache,env, s, NONE()); | |
| 4590 | ✗ | path_2 := makeFullyQualified2(env_1,s,inPath); | |
| 4591 | ✗ | then | |
| 4592 | (cache,AbsynUtil.makeFullyQualified(path_2)); | ||
| 4593 | |||
| 4594 | // A package constant, first try to look it up local (top frame) | ||
| 4595 | case (cache,env,_) | ||
| 4596 | algorithm | ||
| 4597 | 15379 | (cache,_,_,_,_,_,env,_,name) := Lookup.lookupVarInternalIdent(cache, env, ident, {}, InstTypes.SEARCH_ALSO_BUILTIN()); | |
| 4598 | ✗ | path3 := makeFullyQualified2(env,name); | |
| 4599 | ✗ | then | |
| 4600 | (cache,AbsynUtil.makeFullyQualified(path3)); | ||
| 4601 | |||
| 4602 | // TODO! FIXME! what do we do here??!! | ||
| 4603 | case (cache,env,_) | ||
| 4604 | algorithm | ||
| 4605 | 15379 | (cache,env,_,_,_,_,_,_,name) := Lookup.lookupVarInPackagesIdent(cache, env, ident, {}, {}, Mutable.create(false)); | |
| 4606 | ✗ | path3 := makeFullyQualified2(env,name); | |
| 4607 | ✗ | then | |
| 4608 | (cache,AbsynUtil.makeFullyQualified(path3)); | ||
| 4609 | |||
| 4610 | // If it fails, leave name unchanged. | ||
| 4611 | 452 | else (inCache,match inPath case Absyn.IDENT("") then Absyn.IDENT(ident); else inPath; end match); | |
| 4612 | end matchcontinue; | ||
| 4613 | end makeFullyQualifiedIdent; | ||
| 4614 | |||
| 4615 | protected function makeFullyQualifiedIdentCheckBuiltin | ||
| 4616 | input String ident; | ||
| 4617 | output Absyn.Path path; | ||
| 4618 | output Boolean isKnownBuiltin=true; | ||
| 4619 | algorithm | ||
| 4620 | path := match ident | ||
| 4621 | case "Boolean" then Absyn.FULLYQUALIFIED(Absyn.IDENT("Boolean")); | ||
| 4622 | case "Integer" then Absyn.FULLYQUALIFIED(Absyn.IDENT("Integer")); | ||
| 4623 | case "Real" then Absyn.FULLYQUALIFIED(Absyn.IDENT("Real")); | ||
| 4624 | case "String" then Absyn.FULLYQUALIFIED(Absyn.IDENT("String")); | ||
| 4625 | case "EnumType" then Absyn.FULLYQUALIFIED(Absyn.IDENT("EnumType")); | ||
| 4626 | |||
| 4627 | // Builtin functions are handled after lookup of class (in case it is shadowed) | ||
| 4628 | |||
| 4629 | case "assert" then Absyn.IDENT("assert"); | ||
| 4630 | case "reinit" then Absyn.IDENT("reinit"); | ||
| 4631 | |||
| 4632 | // Other functions that can not be represented in env due to e.g. applicable to any record | ||
| 4633 | case "smooth" then Absyn.IDENT("smooth"); | ||
| 4634 | |||
| 4635 | // MetaModelica extensions | ||
| 4636 | 15206 | case "list" algorithm isKnownBuiltin:=Config.acceptMetaModelicaGrammar(); then Absyn.IDENT("list"); | |
| 4637 | 9029 | case "Option" algorithm isKnownBuiltin:=Config.acceptMetaModelicaGrammar(); then Absyn.IDENT("Option"); | |
| 4638 | 1103 | case "tuple" algorithm isKnownBuiltin:=Config.acceptMetaModelicaGrammar(); then Absyn.IDENT("tuple"); | |
| 4639 | 14 | case "polymorphic" algorithm isKnownBuiltin:=Config.acceptMetaModelicaGrammar(); then Absyn.IDENT("polymorphic"); | |
| 4640 | 665 | case "array" algorithm isKnownBuiltin:=Config.acceptMetaModelicaGrammar(); then Absyn.IDENT("array"); | |
| 4641 | else algorithm isKnownBuiltin:=false; then Absyn.IDENT(""); | ||
| 4642 | end match; | ||
| 4643 | end makeFullyQualifiedIdentCheckBuiltin; | ||
| 4644 | |||
| 4645 | public function instList | ||
| 4646 | "This is a utility used to do instantiation of list | ||
| 4647 | of things, collecting the result in another list." | ||
| 4648 | input FCore.Cache inCache; | ||
| 4649 | input FCore.Graph inEnv; | ||
| 4650 | input InnerOuter.InstHierarchy inIH; | ||
| 4651 | input DAE.Prefix inPrefix; | ||
| 4652 | input Connect.Sets inSets; | ||
| 4653 | input ClassInf.State inState; | ||
| 4654 | input InstFunc instFunc; | ||
| 4655 | input list<Type_a> inTypeALst; | ||
| 4656 | input Boolean inImplicit; | ||
| 4657 | input Boolean unrollForLoops "we should unroll for loops if they are part of an algorithm in a model"; | ||
| 4658 | input ConnectionGraph.ConnectionGraph inGraph; | ||
| 4659 | output FCore.Cache outCache; | ||
| 4660 | output FCore.Graph outEnv; | ||
| 4661 | output InnerOuter.InstHierarchy outIH; | ||
| 4662 | output DAE.DAElist outDae; | ||
| 4663 | output Connect.Sets outSets; | ||
| 4664 | output ClassInf.State outState; | ||
| 4665 | output ConnectionGraph.ConnectionGraph outGraph; | ||
| 4666 | partial function InstFunc | ||
| 4667 | input FCore.Cache inCache; | ||
| 4668 | input FCore.Graph inEnv; | ||
| 4669 | input InnerOuter.InstHierarchy inIH; | ||
| 4670 | input DAE.Prefix inPrefix; | ||
| 4671 | input Connect.Sets inSets; | ||
| 4672 | input ClassInf.State inState; | ||
| 4673 | input Type_a inTypeA; | ||
| 4674 | input Boolean inImplicit; | ||
| 4675 | input Boolean unrollForLoops "we should unroll for loops if they are part of an algorithm in a model"; | ||
| 4676 | input ConnectionGraph.ConnectionGraph inGraph; | ||
| 4677 | output FCore.Cache outCache; | ||
| 4678 | output FCore.Graph outEnv; | ||
| 4679 | output InnerOuter.InstHierarchy outIH; | ||
| 4680 | output DAE.DAElist outDAe; | ||
| 4681 | output Connect.Sets outSets; | ||
| 4682 | output ClassInf.State outState; | ||
| 4683 | output ConnectionGraph.ConnectionGraph outGraph; | ||
| 4684 | replaceable type Type_a subtypeof Any; | ||
| 4685 | end InstFunc; | ||
| 4686 | replaceable type Type_a subtypeof Any; | ||
| 4687 | algorithm | ||
| 4688 | (outCache,outEnv,outIH,outDae,outSets,outState,outGraph):= | ||
| 4689 | match (inCache, inEnv, inIH, inPrefix, inSets, inState, inTypeALst, inImplicit, inGraph) | ||
| 4690 | local | ||
| 4691 | FCore.Graph env,env_1,env_2; | ||
| 4692 | DAE.Prefix pre; | ||
| 4693 | Connect.Sets csets,csets_1,csets_2; | ||
| 4694 | ClassInf.State ci_state,ci_state_1,ci_state_2; | ||
| 4695 | Boolean impl; | ||
| 4696 | DAE.DAElist dae1,dae2,dae; | ||
| 4697 | Type_a e; | ||
| 4698 | list<Type_a> es; | ||
| 4699 | FCore.Cache cache; | ||
| 4700 | ConnectionGraph.ConnectionGraph graph; | ||
| 4701 | InstanceHierarchy ih; | ||
| 4702 | |||
| 4703 | case (cache, env, ih, _, csets, ci_state, {}, _, graph) | ||
| 4704 | then (cache,env,ih,DAE.emptyDae,csets,ci_state,graph); | ||
| 4705 | |||
| 4706 | case (cache, env, ih, pre, csets, ci_state, (e :: es), impl, graph) | ||
| 4707 | algorithm | ||
| 4708 |
5/10✗ Branch 0 not taken.
✓ Branch 1 taken 33236 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 7 taken 6063 times.
✓ Branch 8 taken 27173 times.
✓ Branch 9 taken 27119 times.
✓ Branch 10 taken 6117 times.
|
66418 | (cache,env_1,ih,dae1,csets_1,ci_state_1,graph) := instFunc(cache, env, ih, pre, csets, ci_state, e, impl, unrollForLoops, graph); |
| 4709 | 33152 | (cache,env_2,ih,dae2,csets_2,ci_state_2,graph) := instList(cache, env_1, ih, pre, csets_1, ci_state_1, instFunc, es, impl, unrollForLoops, graph); | |
| 4710 | 33144 | dae := DAEUtil.joinDaes(dae1, dae2); | |
| 4711 | 33144 | then | |
| 4712 | (cache,env_2,ih,dae,csets_2,ci_state_2,graph); | ||
| 4713 | end match; | ||
| 4714 | end instList; | ||
| 4715 | |||
| 4716 | protected function instConstraints | ||
| 4717 | input FCore.Cache inCache; | ||
| 4718 | input FCore.Graph inEnv; | ||
| 4719 | input DAE.Prefix inPrefix; | ||
| 4720 | input ClassInf.State inState; | ||
| 4721 | input list<SCode.ConstraintSection> inConstraints; | ||
| 4722 | input Boolean inImpl; | ||
| 4723 | output FCore.Cache outCache; | ||
| 4724 | output FCore.Graph outEnv; | ||
| 4725 | output DAE.DAElist outDae; | ||
| 4726 | output ClassInf.State outState; | ||
| 4727 | algorithm | ||
| 4728 | (outCache,outEnv,outDae,outState) := match inConstraints | ||
| 4729 | local | ||
| 4730 | FCore.Graph env1,env2; | ||
| 4731 | DAE.DAElist constraints_1,constraints_2; | ||
| 4732 | ClassInf.State ci_state; | ||
| 4733 | list<SCode.ConstraintSection> rest; | ||
| 4734 | SCode.ConstraintSection constr; | ||
| 4735 | FCore.Cache cache; | ||
| 4736 | DAE.DAElist dae; | ||
| 4737 | |||
| 4738 | case {} | ||
| 4739 | then (inCache,inEnv,DAE.emptyDae,inState); | ||
| 4740 | |||
| 4741 | case constr::rest | ||
| 4742 | algorithm | ||
| 4743 | 3 | (cache,env1,constraints_1,ci_state) := InstSection.instConstraint(inCache,inEnv,inPrefix,inState,constr,inImpl); | |
| 4744 | 3 | (cache,env2,constraints_2,ci_state) := instConstraints(cache,env1,inPrefix,ci_state,rest,inImpl); | |
| 4745 | 3 | dae := DAEUtil.joinDaes(constraints_1, constraints_2); | |
| 4746 | 3 | then | |
| 4747 | (cache,env2,dae,ci_state); | ||
| 4748 | else | ||
| 4749 | algorithm | ||
| 4750 | ✗ | true := Flags.isSet(Flags.FAILTRACE); | |
| 4751 | ✗ | Debug.trace("- Inst.instConstraints failed\n"); | |
| 4752 | ✗ | then | |
| 4753 | fail(); | ||
| 4754 | |||
| 4755 | end match; | ||
| 4756 | end instConstraints; | ||
| 4757 | |||
| 4758 | protected function instClassAttributes | ||
| 4759 | input FCore.Cache inCache; | ||
| 4760 | input FCore.Graph inEnv; | ||
| 4761 | input DAE.Prefix inPrefix; | ||
| 4762 | input list<Absyn.NamedArg> inAttrs; | ||
| 4763 | input Boolean inImplicit; | ||
| 4764 | input SourceInfo inInfo; | ||
| 4765 | output FCore.Cache outCache; | ||
| 4766 | output FCore.Graph outEnv; | ||
| 4767 | output DAE.DAElist outDae; | ||
| 4768 | algorithm | ||
| 4769 | |||
| 4770 | (outCache,outEnv,outDae):= | ||
| 4771 | match (inCache, inEnv, inAttrs) | ||
| 4772 | local | ||
| 4773 | FCore.Cache cache; | ||
| 4774 | FCore.Graph env; | ||
| 4775 | DAE.DAElist clsAttrs, dae; | ||
| 4776 | |||
| 4777 | case (cache, env, {}) | ||
| 4778 | 159869 | then (cache,env,DAE.emptyDae); | |
| 4779 | |||
| 4780 | case (_, _, _) | ||
| 4781 | algorithm | ||
| 4782 | clsAttrs := DAE.DAE({DAE.CLASS_ATTRIBUTES(DAE.OPTIMIZATION_ATTRS(NONE(),NONE(),NONE(),NONE()))}); | ||
| 4783 | 13 | (cache,env,dae) := instClassAttributes2(inCache,inEnv,inPrefix,inAttrs,inImplicit,inInfo,clsAttrs); | |
| 4784 | then (cache,env,dae); | ||
| 4785 | else | ||
| 4786 | algorithm | ||
| 4787 | ✗ | true := Flags.isSet(Flags.FAILTRACE); | |
| 4788 | ✗ | Debug.trace("- Inst.instClassAttributes failed\n"); | |
| 4789 | ✗ | then | |
| 4790 | fail(); | ||
| 4791 | end match; | ||
| 4792 | end instClassAttributes; | ||
| 4793 | |||
| 4794 | protected function instClassAttributes2 | ||
| 4795 | input FCore.Cache inCache; | ||
| 4796 | input FCore.Graph inEnv; | ||
| 4797 | input DAE.Prefix inPrefix; | ||
| 4798 | input list<Absyn.NamedArg> inAttrs; | ||
| 4799 | input Boolean inImplicit; | ||
| 4800 | input SourceInfo inInfo; | ||
| 4801 | input DAE.DAElist inClsAttrs; | ||
| 4802 | output FCore.Cache outCache; | ||
| 4803 | output FCore.Graph outEnv; | ||
| 4804 | output DAE.DAElist outDae; | ||
| 4805 | algorithm | ||
| 4806 | |||
| 4807 | (outCache,outEnv,outDae):= | ||
| 4808 | match (inCache, inEnv, inPrefix, inAttrs, inImplicit, inClsAttrs) | ||
| 4809 | local | ||
| 4810 | FCore.Graph env,env_2; | ||
| 4811 | DAE.Prefix pre; | ||
| 4812 | Boolean impl; | ||
| 4813 | Absyn.NamedArg na; | ||
| 4814 | list<Absyn.NamedArg> rest; | ||
| 4815 | FCore.Cache cache; | ||
| 4816 | Absyn.Ident attrName; | ||
| 4817 | Absyn.Exp attrExp; | ||
| 4818 | DAE.Exp outExp; | ||
| 4819 | DAE.DAElist clsAttrs; | ||
| 4820 | |||
| 4821 | case (cache, env, _, {}, _, clsAttrs) | ||
| 4822 | then (cache,env,clsAttrs); | ||
| 4823 | |||
| 4824 | case (cache, env, pre, (na :: rest), impl, clsAttrs) | ||
| 4825 | algorithm | ||
| 4826 | 17 | Absyn.NAMEDARG(attrName, attrExp) := na; | |
| 4827 | 17 | (cache,outExp,_) := Static.elabExp(cache, env, attrExp, impl, false /*vectorize*/, pre, inInfo); | |
| 4828 | 17 | clsAttrs := insertClassAttribute(clsAttrs,attrName,outExp); | |
| 4829 | 17 | (cache,env_2,clsAttrs) := instClassAttributes2(cache, env, pre, rest, impl, inInfo,clsAttrs); | |
| 4830 | then | ||
| 4831 | (cache,env_2,clsAttrs); | ||
| 4832 | |||
| 4833 | else | ||
| 4834 | algorithm | ||
| 4835 | ✗ | Error.addMessage(Error.OPTIMICA_ERROR, {"Class Attributes allowed only for Optimization classes."}); | |
| 4836 | ✗ | then fail(); | |
| 4837 | end match; | ||
| 4838 | end instClassAttributes2; | ||
| 4839 | |||
| 4840 | protected function insertClassAttribute | ||
| 4841 | input DAE.DAElist inAttrs; | ||
| 4842 | input Absyn.Ident attrName; | ||
| 4843 | input DAE.Exp inAttrExp; | ||
| 4844 | output DAE.DAElist outAttrs; | ||
| 4845 | algorithm | ||
| 4846 | outAttrs := match(inAttrs, attrName) | ||
| 4847 | local | ||
| 4848 | Option<DAE.Exp> objectiveE,startTimeE,finalTimeE,objectiveIntegrandE; | ||
| 4849 | DAE.DAElist attrs; | ||
| 4850 | |||
| 4851 | case (attrs, "objective") | ||
| 4852 | algorithm | ||
| 4853 |
3/6✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
|
8 | DAE.DAE({DAE.CLASS_ATTRIBUTES(DAE.OPTIMIZATION_ATTRS(_,objectiveIntegrandE,startTimeE,finalTimeE))}) := attrs; |
| 4854 | 16 | attrs := DAE.DAE({DAE.CLASS_ATTRIBUTES(DAE.OPTIMIZATION_ATTRS(SOME(inAttrExp),objectiveIntegrandE,startTimeE,finalTimeE))}); | |
| 4855 | then attrs; | ||
| 4856 | |||
| 4857 | case (attrs, "objectiveIntegrand") | ||
| 4858 | algorithm | ||
| 4859 |
3/6✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
|
9 | DAE.DAE({DAE.CLASS_ATTRIBUTES(DAE.OPTIMIZATION_ATTRS(objectiveE,_,startTimeE,finalTimeE))}) := attrs; |
| 4860 | 18 | attrs := DAE.DAE({DAE.CLASS_ATTRIBUTES(DAE.OPTIMIZATION_ATTRS(objectiveE,SOME(inAttrExp),startTimeE,finalTimeE))}); | |
| 4861 | then attrs; | ||
| 4862 | |||
| 4863 | case (attrs, "startTime") | ||
| 4864 | algorithm | ||
| 4865 | ✗ | DAE.DAE({DAE.CLASS_ATTRIBUTES(DAE.OPTIMIZATION_ATTRS(objectiveE,objectiveIntegrandE,_,finalTimeE))}) := attrs; | |
| 4866 | ✗ | attrs := DAE.DAE({DAE.CLASS_ATTRIBUTES(DAE.OPTIMIZATION_ATTRS(objectiveE,objectiveIntegrandE,SOME(inAttrExp),finalTimeE))}); | |
| 4867 | then attrs; | ||
| 4868 | |||
| 4869 | case (attrs, "finalTime") | ||
| 4870 | algorithm | ||
| 4871 | ✗ | DAE.DAE({DAE.CLASS_ATTRIBUTES(DAE.OPTIMIZATION_ATTRS(objectiveE,objectiveIntegrandE,startTimeE,_))}) := attrs; | |
| 4872 | ✗ | attrs := DAE.DAE({DAE.CLASS_ATTRIBUTES(DAE.OPTIMIZATION_ATTRS(objectiveE,objectiveIntegrandE,startTimeE,SOME(inAttrExp)))}); | |
| 4873 | then attrs; | ||
| 4874 | else | ||
| 4875 | algorithm | ||
| 4876 | ✗ | true := Flags.isSet(Flags.FAILTRACE); | |
| 4877 | ✗ | Debug.trace("- Inst.insertClassAttribute failed\n"); | |
| 4878 | ✗ | then | |
| 4879 | fail(); | ||
| 4880 | |||
| 4881 | end match; | ||
| 4882 | end insertClassAttribute; | ||
| 4883 | |||
| 4884 | public function instantiateBoschClass " | ||
| 4885 | Author BZ 2008-06, | ||
| 4886 | Instantiate a class, but _allways_ as inner class. This due to that we do not want flow equations equal to zero. | ||
| 4887 | Called from Interactive.mo, boschsection. | ||
| 4888 | " | ||
| 4889 | input FCore.Cache inCache; | ||
| 4890 | input InnerOuter.InstHierarchy inIH; | ||
| 4891 | input SCode.Program inProgram; | ||
| 4892 | input SCode.Path inPath; | ||
| 4893 | output FCore.Cache outCache; | ||
| 4894 | output FCore.Graph outEnv; | ||
| 4895 | output InnerOuter.InstHierarchy outIH; | ||
| 4896 | output DAE.DAElist outDAElist; | ||
| 4897 | algorithm | ||
| 4898 | (outCache,outEnv,outIH,outDAElist) := | ||
| 4899 | matchcontinue (inCache,inIH,inProgram,inPath) | ||
| 4900 | local | ||
| 4901 | Absyn.Path path; | ||
| 4902 | FCore.Graph env,env_1,env_2; | ||
| 4903 | DAE.DAElist dae; | ||
| 4904 | list<SCode.Element> cdecls; | ||
| 4905 | String cname_str; | ||
| 4906 | SCode.Element cdef; | ||
| 4907 | FCore.Cache cache; | ||
| 4908 | InstanceHierarchy ih; | ||
| 4909 | |||
| 4910 | case (_,_,{},_) | ||
| 4911 | algorithm | ||
| 4912 | ✗ | Error.addMessage(Error.NO_CLASSES_LOADED, {}); | |
| 4913 | ✗ | then | |
| 4914 | fail(); | ||
| 4915 | |||
| 4916 | case (cache,ih,(cdecls as (_ :: _)),(path as Absyn.IDENT())) /* top level class */ | ||
| 4917 | algorithm | ||
| 4918 | ✗ | (cache,env) := Builtin.initialGraph(cache); | |
| 4919 | ✗ | env_1 := FGraphBuildEnv.mkProgramGraph(cdecls, FCore.USERDEFINED(), env); | |
| 4920 | ✗ | (cache,env_2,ih,dae) := instBoschClassInProgram(cache,env_1,ih, cdecls, path); | |
| 4921 | then | ||
| 4922 | (cache,env_2,ih,dae); | ||
| 4923 | |||
| 4924 | case (cache,ih,(cdecls as (_ :: _)),(path as Absyn.QUALIFIED())) /* class in package */ | ||
| 4925 | algorithm | ||
| 4926 | ✗ | (cache,env) := Builtin.initialGraph(cache); | |
| 4927 | ✗ | env_1 := FGraphBuildEnv.mkProgramGraph(cdecls, FCore.USERDEFINED(), env); | |
| 4928 | ✗ | (cache,(cdef as SCode.CLASS()),env_2) := Lookup.lookupClass(cache,env_1, path, SOME(Absyn.dummyInfo)); | |
| 4929 | |||
| 4930 | ✗ | (cache,env_2,ih,_,dae,_,_,_,_,_) := | |
| 4931 | instClass(cache,env_2,ih,UnitAbsyn.noStore, DAE.NOMOD(), DAE.NOPRE(), | ||
| 4932 | cdef, {}, false, InstTypes.INNER_CALL(), ConnectionGraph.EMPTY, Connect.emptySet) "impl" ; | ||
| 4933 | ✗ | then | |
| 4934 | (cache,env_2,ih,dae); | ||
| 4935 | |||
| 4936 | case (_,_,_,path) /* error instantiating */ | ||
| 4937 | algorithm | ||
| 4938 | ✗ | cname_str := AbsynUtil.pathString(path); | |
| 4939 | ✗ | Error.addMessage(Error.ERROR_FLATTENING, {cname_str}); | |
| 4940 | ✗ | then | |
| 4941 | fail(); | ||
| 4942 | end matchcontinue; | ||
| 4943 | end instantiateBoschClass; | ||
| 4944 | |||
| 4945 | protected function instBoschClassInProgram | ||
| 4946 | "Helper function for instantiateBoschClass" | ||
| 4947 | input FCore.Cache inCache; | ||
| 4948 | input FCore.Graph inEnv; | ||
| 4949 | input InnerOuter.InstHierarchy inIH; | ||
| 4950 | input SCode.Program inProgram; | ||
| 4951 | input SCode.Path inPath; | ||
| 4952 | output FCore.Cache outCache; | ||
| 4953 | output FCore.Graph outEnv; | ||
| 4954 | output InnerOuter.InstHierarchy outIH; | ||
| 4955 | output DAE.DAElist outDae; | ||
| 4956 | algorithm | ||
| 4957 | (outCache,outEnv,outIH,outDae):= | ||
| 4958 | matchcontinue (inCache,inEnv,inIH,inProgram,inPath) | ||
| 4959 | local | ||
| 4960 | DAE.DAElist dae; | ||
| 4961 | FCore.Graph env_1,env; | ||
| 4962 | SCode.Element c; | ||
| 4963 | String name1,name2; | ||
| 4964 | list<SCode.Element> cs; | ||
| 4965 | Absyn.Path path; | ||
| 4966 | FCore.Cache cache; | ||
| 4967 | InstanceHierarchy ih; | ||
| 4968 | |||
| 4969 | case (cache,env,ih,((c as SCode.CLASS(name = name1)) :: _),Absyn.IDENT(name = name2)) | ||
| 4970 | algorithm | ||
| 4971 | ✗ | true := stringEq(name1, name2); | |
| 4972 | ✗ | (cache,env_1,ih,_,dae,_,_,_,_,_) := | |
| 4973 | instClass(cache,env,ih, UnitAbsyn.noStore, DAE.NOMOD(), DAE.NOPRE(), c, | ||
| 4974 | {}, false, InstTypes.INNER_CALL(), ConnectionGraph.EMPTY, Connect.emptySet) "impl" ; | ||
| 4975 | ✗ | then | |
| 4976 | (cache,env_1,ih,dae); | ||
| 4977 | |||
| 4978 | case (cache,env,ih,((SCode.CLASS(name = name1)) :: cs),(path as Absyn.IDENT(name = name2))) | ||
| 4979 | algorithm | ||
| 4980 | ✗ | false := stringEq(name1, name2); | |
| 4981 | ✗ | (cache,env,ih,dae) := instBoschClassInProgram(cache,env,ih, cs, path); | |
| 4982 | then | ||
| 4983 | (cache,env,ih,dae); | ||
| 4984 | |||
| 4985 | ✗ | case (cache,env,ih,{},_) then (cache,env,ih,DAE.emptyDae); | |
| 4986 | |||
| 4987 | end matchcontinue; | ||
| 4988 | end instBoschClassInProgram; | ||
| 4989 | |||
| 4990 | protected function modifyInstantiateClass | ||
| 4991 | " Here we check a modifier and a path, | ||
| 4992 | if we have a redeclaration of the class | ||
| 4993 | pointed by the path, we add this to a | ||
| 4994 | special reclaration modifier. | ||
| 4995 | Function returning 2 modifiers: | ||
| 4996 | - one (first output) to represent the redeclaration of | ||
| 4997 | 'current' class (class-name equal to path) | ||
| 4998 | - two (second output) to represent any other modifier." | ||
| 4999 | input DAE.Mod inMod; | ||
| 5000 | input Absyn.Path path; | ||
| 5001 | output DAE.Mod omod1; | ||
| 5002 | output DAE.Mod omod2; | ||
| 5003 | algorithm | ||
| 5004 | (omod1, omod2) := match inMod | ||
| 5005 | local | ||
| 5006 | String id; | ||
| 5007 | |||
| 5008 | case DAE.REDECL(element = SCode.CLASS(name = id)) | ||
| 5009 |
3/4✓ Branch 1 taken 13 times.
✓ Branch 2 taken 1 time.
✓ Branch 5 taken 13 times.
✗ Branch 6 not taken.
|
14 | then if id == AbsynUtil.pathString(path) then |
| 5010 | (inMod, DAE.NOMOD()) else (DAE.NOMOD(), inMod); | ||
| 5011 | |||
| 5012 | 529995 | else (DAE.NOMOD(), inMod); | |
| 5013 | |||
| 5014 | end match; | ||
| 5015 | end modifyInstantiateClass; | ||
| 5016 | |||
| 5017 | protected function removeSelfReferenceAndUpdate | ||
| 5018 | " BZ 2007-07-03 | ||
| 5019 | This function checks if there is a reference to itself. | ||
| 5020 | If it is, it removes the reference. | ||
| 5021 | But also instantiate the declared type, if any. | ||
| 5022 | If it fails (declarations of array dimensions using | ||
| 5023 | the size of itself) it will just remove the element." | ||
| 5024 | input FCore.Cache inCache; | ||
| 5025 | input FCore.Graph inEnv; | ||
| 5026 | input InnerOuter.InstHierarchy inIH; | ||
| 5027 | input UnitAbsyn.InstStore inStore; | ||
| 5028 | input list<Absyn.ComponentRef> inRefs; | ||
| 5029 | input Absyn.ComponentRef inRef; | ||
| 5030 | input Absyn.Path inPath; | ||
| 5031 | input ClassInf.State inState; | ||
| 5032 | input SCode.Attributes iattr; | ||
| 5033 | input SCode.Prefixes inPrefixes; | ||
| 5034 | input Boolean impl; | ||
| 5035 | input list<list<DAE.Dimension>> inInstDims; | ||
| 5036 | input DAE.Prefix pre; | ||
| 5037 | input DAE.Mod mods; | ||
| 5038 | input SCode.Mod scodeMod; | ||
| 5039 | input SourceInfo info; | ||
| 5040 | output FCore.Cache outCache; | ||
| 5041 | output FCore.Graph outEnv; | ||
| 5042 | output InnerOuter.InstHierarchy outIH; | ||
| 5043 | output UnitAbsyn.InstStore outStore; | ||
| 5044 | output list<Absyn.ComponentRef> o1; | ||
| 5045 | algorithm | ||
| 5046 | (outCache,outEnv,outIH,outStore,o1) := | ||
| 5047 | matchcontinue(inCache, inEnv, inIH, inStore, inRefs, inRef, inPath, inState, iattr, inInstDims) | ||
| 5048 | local | ||
| 5049 | Absyn.Path sty; | ||
| 5050 | Absyn.ComponentRef c1; | ||
| 5051 | list<Absyn.ComponentRef> cl1,cl2; | ||
| 5052 | FCore.Cache cache; | ||
| 5053 | FCore.Graph env,compenv,cenv; | ||
| 5054 | Integer i1,i2; | ||
| 5055 | list<Absyn.Subscript> ad; | ||
| 5056 | SCode.Parallelism prl1; | ||
| 5057 | SCode.Variability var1; | ||
| 5058 | Absyn.Direction dir; | ||
| 5059 | Ident n; | ||
| 5060 | SCode.Element c; | ||
| 5061 | DAE.Type ty; | ||
| 5062 | ClassInf.State state; | ||
| 5063 | SCode.Visibility vis; | ||
| 5064 | SCode.ConnectorType ct; | ||
| 5065 | SCode.Attributes attr; | ||
| 5066 | DAE.Dimensions dims; | ||
| 5067 | InstDims inst_dims; | ||
| 5068 | DAE.Var new_var; | ||
| 5069 | InstanceHierarchy ih; | ||
| 5070 | Absyn.InnerOuter io; | ||
| 5071 | UnitAbsyn.InstStore store; | ||
| 5072 | DAE.Mod m; | ||
| 5073 | SCode.Mod smod; | ||
| 5074 | |||
| 5075 | case(cache, env, ih, store, cl1, c1, _, _, _, _) | ||
| 5076 | algorithm | ||
| 5077 | 530009 | cl2 := InstUtil.removeCrefFromCrefs(cl1, c1); | |
| 5078 | 530009 | i1 := listLength(cl2); | |
| 5079 | 530009 | i2 := listLength(cl1); | |
| 5080 |
2/2✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 527489 times.
|
530009 | true := (i1 == i2); |
| 5081 | 527489 | then | |
| 5082 | (cache,env,ih,store,cl2); | ||
| 5083 | |||
| 5084 | // we have reference to ourself, try to instantiate type with all but the self reference removed! | ||
| 5085 | case(cache, env, ih, store, cl1, c1 as Absyn.CREF_IDENT(name = n), sty, state, (attr as SCode.ATTR(arrayDims = ad, connectorType = ct, | ||
| 5086 | parallelism= prl1, variability = var1, direction = dir)), inst_dims) | ||
| 5087 | algorithm | ||
| 5088 | 2520 | ErrorExt.setCheckpoint("Inst.removeSelfReferenceAndUpdate"); | |
| 5089 | 2520 | cl2 := InstUtil.removeCrefFromCrefs(cl1, c1); | |
| 5090 | 2520 | (cache,c,cenv) := Lookup.lookupClass(cache,env, sty, SOME(info)); | |
| 5091 | 2520 | (cache,dims) := InstUtil.elabArraydim(cache,cenv, c1, sty, ad, NONE(), impl, true, false, pre, info, inst_dims); | |
| 5092 | |||
| 5093 | // we really need to keep at least the redeclare modifications here!! | ||
| 5094 | 2496 | smod := SCodeInstUtil.removeSelfReferenceFromMod(scodeMod, c1); | |
| 5095 | 2496 | (cache,m) := Mod.elabMod(cache, env, ih, pre, smod, impl, Mod.COMPONENT(n), info); // m = Mod.elabUntypedMod(smod, env, pre); | |
| 5096 | |||
| 5097 | 2496 | (cenv, c, ih) := FGraph.createVersionScope(env, n, pre, m, cenv, c, ih); | |
| 5098 | 2496 | (cache,compenv,ih,store,_,_,ty,_) := | |
| 5099 | InstVar.instVar(cache, cenv, ih, store, state, m, pre, n, c, attr, | ||
| 5100 | inPrefixes, dims, {}, inst_dims, true, SCode.noComment, info, ConnectionGraph.EMPTY, Connect.emptySet, env); | ||
| 5101 | |||
| 5102 | // print("component: " + n + " ty: " + TypesDump.printTypeStr(ty) + "\n"); | ||
| 5103 | |||
| 5104 | 2491 | io := SCodeUtil.prefixesInnerOuter(inPrefixes); | |
| 5105 | 2491 | vis := SCodeUtil.prefixesVisibility(inPrefixes); | |
| 5106 | |||
| 5107 | 2491 | new_var := DAE.TYPES_VAR(n,DAE.ATTR(DAEUtil.toConnectorTypeNoState(ct),prl1,var1,dir,io,vis),ty,DAE.UNBOUND(),false,NONE()); | |
| 5108 | 2491 | env := FGraph.updateComp(env, new_var, FCore.VAR_TYPED(), compenv); | |
| 5109 | 2491 | ErrorExt.rollBack("Inst.removeSelfReferenceAndUpdate"); | |
| 5110 | 2491 | then | |
| 5111 | (cache,env,ih,store,cl2); | ||
| 5112 | |||
| 5113 | // not working, try again :) | ||
| 5114 | case(_, _, _, _, _, _, _, _, _, _) | ||
| 5115 | algorithm | ||
| 5116 | 29 | ErrorExt.rollBack("Inst.removeSelfReferenceAndUpdate"); | |
| 5117 | 29 | then | |
| 5118 | fail(); | ||
| 5119 | |||
| 5120 | // we have reference to ourself, try to instantiate type with redeclares and constants applied | ||
| 5121 | case(cache, env, ih, store, cl1, c1 as Absyn.CREF_IDENT(name = n), sty, state, (attr as SCode.ATTR(arrayDims = ad, connectorType = ct, | ||
| 5122 | parallelism= prl1, variability = var1, direction = dir)), inst_dims) | ||
| 5123 | algorithm | ||
| 5124 | 29 | ErrorExt.setCheckpoint("Inst.removeSelfReferenceAndUpdate"); | |
| 5125 | 29 | cl2 := InstUtil.removeCrefFromCrefs(cl1, c1); | |
| 5126 | 29 | (cache,c,cenv) := Lookup.lookupClass(cache,env, sty, SOME(info)); | |
| 5127 | 29 | (cache,dims) := InstUtil.elabArraydim(cache, cenv, c1, sty, ad, NONE(), impl, true, false, pre, info, inst_dims); | |
| 5128 | |||
| 5129 | // we really need to keep at least the redeclare modifications here!! | ||
| 5130 | 5 | smod := SCodeInstUtil.removeNonConstantBindingsKeepRedeclares(scodeMod, false); | |
| 5131 | 5 | (cache,m) := Mod.elabMod(cache, env, ih, pre, smod, impl, Mod.COMPONENT(n), info); // m = Mod.elabUntypedMod(smod, env, pre); | |
| 5132 | |||
| 5133 | 5 | (cenv, c, ih) := FGraph.createVersionScope(env, n, pre, m, cenv, c, ih); | |
| 5134 | 5 | (cache,compenv,ih,store,_,_,ty,_) := | |
| 5135 | InstVar.instVar(cache, cenv, ih, store, state, m, pre, n, c, attr, | ||
| 5136 | inPrefixes, dims, {}, inst_dims, true, SCode.noComment, info, ConnectionGraph.EMPTY, Connect.emptySet, env); | ||
| 5137 | |||
| 5138 | // print("component: " + n + " ty: " + TypesDump.printTypeStr(ty) + "\n"); | ||
| 5139 | |||
| 5140 | ✗ | io := SCodeUtil.prefixesInnerOuter(inPrefixes); | |
| 5141 | ✗ | vis := SCodeUtil.prefixesVisibility(inPrefixes); | |
| 5142 | |||
| 5143 | ✗ | new_var := DAE.TYPES_VAR(n,DAE.ATTR(DAEUtil.toConnectorTypeNoState(ct),prl1,var1,dir,io,vis),ty,DAE.UNBOUND(),false,NONE()); | |
| 5144 | ✗ | env := FGraph.updateComp(env, new_var, FCore.VAR_TYPED(), compenv); | |
| 5145 | ✗ | ErrorExt.rollBack("Inst.removeSelfReferenceAndUpdate"); | |
| 5146 | ✗ | then | |
| 5147 | (cache,env,ih,store,cl2); | ||
| 5148 | |||
| 5149 | // not working, try again :) | ||
| 5150 | case(_, _, _, _, _, _, _, _, _, _) | ||
| 5151 | algorithm | ||
| 5152 | 29 | ErrorExt.rollBack("Inst.removeSelfReferenceAndUpdate"); | |
| 5153 | 29 | then | |
| 5154 | fail(); | ||
| 5155 | |||
| 5156 | // we have reference to ourself, try to instantiate type with redeclares only applied | ||
| 5157 | case(cache, env, ih, store, cl1, c1 as Absyn.CREF_IDENT(name = n), sty, state, (attr as SCode.ATTR(arrayDims = ad, connectorType = ct, | ||
| 5158 | parallelism= prl1, variability = var1, direction = dir)), inst_dims) | ||
| 5159 | algorithm | ||
| 5160 | 29 | ErrorExt.setCheckpoint("Inst.removeSelfReferenceAndUpdate"); | |
| 5161 | 29 | cl2 := InstUtil.removeCrefFromCrefs(cl1, c1); | |
| 5162 | 29 | (cache,c,cenv) := Lookup.lookupClass(cache,env, sty, SOME(info)); | |
| 5163 | 29 | (cache,dims) := InstUtil.elabArraydim(cache,cenv, c1, sty, ad, NONE(), impl, true, false, pre, info, inst_dims); | |
| 5164 | |||
| 5165 | // we really need to keep at least the redeclare modifications here!! | ||
| 5166 | 5 | smod := SCodeInstUtil.removeNonConstantBindingsKeepRedeclares(scodeMod, true); | |
| 5167 | 5 | (cache,m) := Mod.elabMod(cache, env, ih, pre, smod, impl, Mod.COMPONENT(n), info); // m = Mod.elabUntypedMod(smod, env, pre); | |
| 5168 | |||
| 5169 | 5 | (cenv, c, ih) := FGraph.createVersionScope(env, n, pre, m, cenv, c, ih); | |
| 5170 | 5 | (cache,compenv,ih,store,_,_,ty,_) := | |
| 5171 | InstVar.instVar(cache, cenv, ih, store, state, m, pre, n, c, attr, | ||
| 5172 | inPrefixes, dims, {}, inst_dims, true, SCode.noComment, info, ConnectionGraph.EMPTY, Connect.emptySet, env); | ||
| 5173 | |||
| 5174 | // print("component: " + n + " ty: " + TypesDump.printTypeStr(ty) + "\n"); | ||
| 5175 | |||
| 5176 | ✗ | io := SCodeUtil.prefixesInnerOuter(inPrefixes); | |
| 5177 | ✗ | vis := SCodeUtil.prefixesVisibility(inPrefixes); | |
| 5178 | |||
| 5179 | ✗ | new_var := DAE.TYPES_VAR(n,DAE.ATTR(DAEUtil.toConnectorTypeNoState(ct),prl1,var1,dir,io,vis),ty,DAE.UNBOUND(),false,NONE()); | |
| 5180 | ✗ | env := FGraph.updateComp(env, new_var, FCore.VAR_TYPED(), compenv); | |
| 5181 | ✗ | ErrorExt.rollBack("Inst.removeSelfReferenceAndUpdate"); | |
| 5182 | ✗ | then | |
| 5183 | (cache,env,ih,store,cl2); | ||
| 5184 | |||
| 5185 | // not working, try again :) | ||
| 5186 | case(_, _, _, _, _, _, _, _, _, _) | ||
| 5187 | algorithm | ||
| 5188 | 29 | ErrorExt.rollBack("Inst.removeSelfReferenceAndUpdate"); | |
| 5189 | 29 | then | |
| 5190 | fail(); | ||
| 5191 | |||
| 5192 | // we have reference to ourself, GEE, nothing worked previously try with NOMOD! | ||
| 5193 | case(cache, env, ih, store, cl1, c1 as Absyn.CREF_IDENT(name = n), sty, state, (attr as SCode.ATTR(arrayDims = ad, connectorType = ct, | ||
| 5194 | parallelism= prl1, variability = var1, direction = dir)), inst_dims) | ||
| 5195 | algorithm | ||
| 5196 | 29 | ErrorExt.setCheckpoint("Inst.removeSelfReferenceAndUpdate"); | |
| 5197 | 29 | cl2 := InstUtil.removeCrefFromCrefs(cl1, c1); | |
| 5198 | 29 | (cache,c,cenv) := Lookup.lookupClass(cache,env, sty, SOME(info)); | |
| 5199 | 29 | (cache,dims) := InstUtil.elabArraydim(cache,cenv, c1, sty, ad, NONE(), impl, true, false, pre, info, inst_dims); | |
| 5200 | |||
| 5201 | // we really need to keep at least the redeclare modifications here!! | ||
| 5202 | // smod = SCodeInstUtil.removeNonConstantBindingsKeepRedeclares(scodeMod, true); | ||
| 5203 | // (cache,m) = Mod.elabMod(cache, env, ih, pre, smod, impl, info); // m = Mod.elabUntypedMod(smod, env, pre); | ||
| 5204 | 5 | m := DAE.NOMOD(); | |
| 5205 | |||
| 5206 | 5 | (cenv, c, ih) := FGraph.createVersionScope(env, n, pre, m, cenv, c, ih); | |
| 5207 | 5 | (cache,compenv,ih,store,_,_,ty,_) := | |
| 5208 | InstVar.instVar(cache, cenv, ih, store, state, m, pre, n, c, attr, | ||
| 5209 | inPrefixes, dims, {}, inst_dims, true, SCode.noComment, info, ConnectionGraph.EMPTY, Connect.emptySet, env); | ||
| 5210 | |||
| 5211 | // print("component: " + n + " ty: " + TypesDump.printTypeStr(ty) + "\n"); | ||
| 5212 | |||
| 5213 | 5 | io := SCodeUtil.prefixesInnerOuter(inPrefixes); | |
| 5214 | 5 | vis := SCodeUtil.prefixesVisibility(inPrefixes); | |
| 5215 | |||
| 5216 | 5 | new_var := DAE.TYPES_VAR(n,DAE.ATTR(DAEUtil.toConnectorTypeNoState(ct),prl1,var1,dir,io,vis),ty,DAE.UNBOUND(),false,NONE()); | |
| 5217 | 5 | env := FGraph.updateComp(env, new_var, FCore.VAR_TYPED(), compenv); | |
| 5218 | 5 | ErrorExt.rollBack("Inst.removeSelfReferenceAndUpdate"); | |
| 5219 | 5 | then | |
| 5220 | (cache,env,ih,store,cl2); | ||
| 5221 | |||
| 5222 | // not working .... really not working, don't bother! | ||
| 5223 | case(_, _, _, _, _, _, _, _, _, _) | ||
| 5224 | algorithm | ||
| 5225 | 24 | ErrorExt.rollBack("Inst.removeSelfReferenceAndUpdate"); | |
| 5226 | 24 | then | |
| 5227 | fail(); | ||
| 5228 | |||
| 5229 | /* | ||
| 5230 | // adrpo, try to remove the modifier containing the self expression and use that to instantiate the type! | ||
| 5231 | case(cache,env,ih,store,cl1,c1 as Absyn.CREF_IDENT(name = n), sty, state, | ||
| 5232 | (attr as SCode.ATTR(arrayDims = ad, connectorType = ct, | ||
| 5233 | parallelism= prl1, variability = var1, direction = dir)), | ||
| 5234 | _,_,_,_,_,_,_) | ||
| 5235 | algorithm | ||
| 5236 | ErrorExt.setCheckpoint("Inst.removeSelfReferenceAndUpdate"); | ||
| 5237 | cl2 = InstUtil.removeCrefFromCrefs(cl1, c1); | ||
| 5238 | (cache,c,cenv) = Lookup.lookupClass(cache,env, sty, SOME(info)); | ||
| 5239 | (cache,dims) = InstUtil.elabArraydim(cache,cenv, c1, sty, ad, NONE(), impl, NONE(), true, false, pre, info, inst_dims); | ||
| 5240 | |||
| 5241 | sM = NFSCodeMod.removeCrefPrefixFromModExp(scodeMod, inRef); | ||
| 5242 | |||
| 5243 | //(cache, dM) = elabMod(cache, env, ih, pre, sM, impl, info); | ||
| 5244 | dM = Mod.elabUntypedMod(sM, env, pre); | ||
| 5245 | |||
| 5246 | (cenv, c, ih) = FGraph.createVersionScope(env, n, pre, dM, cenv, c, ih); | ||
| 5247 | (cache,compenv,ih,store,_,_,ty,_) = | ||
| 5248 | InstVar.instVar(cache, cenv, ih, store, state, dM, pre, n, c, attr, | ||
| 5249 | inPrefixes, dims, {}, inst_dims, true, NONE(), info, ConnectionGraph.EMPTY, Connect.emptySet, env); | ||
| 5250 | |||
| 5251 | // print("component: " + n + " ty: " + TypesDump.printTypeStr(ty) + "\n"); | ||
| 5252 | |||
| 5253 | io = SCodeUtil.prefixesInnerOuter(inPrefixes); | ||
| 5254 | vis = SCodeUtil.prefixesVisibility(inPrefixes); | ||
| 5255 | new_var = DAE.TYPES_VAR(n,DAE.ATTR(ct,prl1,var1,dir,io,vis),ty,DAE.UNBOUND(),false,NONE()); | ||
| 5256 | env = FGraph.updateComp(env, new_var, FCore.VAR_TYPED(), compenv); | ||
| 5257 | ErrorExt.delCheckpoint("Inst.removeSelfReferenceAndUpdate"); | ||
| 5258 | then | ||
| 5259 | (cache,env,ih,store,cl2); | ||
| 5260 | |||
| 5261 | case(_, _, _, _, _, Absyn.CREF_IDENT(name = n), _, _, _, _, _, _, _, _, _, _) | ||
| 5262 | algorithm | ||
| 5263 | ErrorExt.rollBack("Inst.removeSelfReferenceAndUpdate"); | ||
| 5264 | then | ||
| 5265 | fail(); | ||
| 5266 | */ | ||
| 5267 | |||
| 5268 | case(cache, env, ih, store, cl1, c1, _, _, _, _) | ||
| 5269 | algorithm | ||
| 5270 | 24 | cl2 := InstUtil.removeCrefFromCrefs(cl1, c1); | |
| 5271 | 24 | then | |
| 5272 | (cache,env,ih,store,cl2); | ||
| 5273 | |||
| 5274 | end matchcontinue; | ||
| 5275 | end removeSelfReferenceAndUpdate; | ||
| 5276 | |||
| 5277 | protected function updateComponentsInEnv2 | ||
| 5278 | "author: PA | ||
| 5279 | Help function to updateComponentsInEnv." | ||
| 5280 | input FCore.Cache inCache; | ||
| 5281 | input FCore.Graph inEnv; | ||
| 5282 | input InnerOuter.InstHierarchy inIH; | ||
| 5283 | input DAE.Prefix pre; | ||
| 5284 | input DAE.Mod mod; | ||
| 5285 | input list<Absyn.ComponentRef> crefs; | ||
| 5286 | input ClassInf.State ci_state; | ||
| 5287 | input Boolean impl; | ||
| 5288 | input Option<HashTable5.HashTable> inUpdatedComps = NONE(); | ||
| 5289 | input Option<Absyn.ComponentRef> currentCref = NONE(); | ||
| 5290 | output FCore.Cache outCache = inCache; | ||
| 5291 | output FCore.Graph outEnv = inEnv; | ||
| 5292 | output InnerOuter.InstHierarchy outIH = inIH; | ||
| 5293 | output Option<HashTable5.HashTable> outUpdatedComps = inUpdatedComps; | ||
| 5294 | protected | ||
| 5295 | String name; | ||
| 5296 | DAE.Binding binding; | ||
| 5297 | algorithm | ||
| 5298 |
2/2✓ Branch 0 taken 130683 times.
✓ Branch 1 taken 612407 times.
|
743090 | for cr in crefs loop |
| 5299 | try | ||
| 5300 |
4/4✓ Branch 0 taken 30993 times.
✓ Branch 1 taken 99690 times.
✓ Branch 2 taken 2485 times.
✓ Branch 3 taken 97205 times.
|
162098 | Absyn.CREF_IDENT(name = name, subscripts = {}) := cr; |
| 5301 | 97205 | (_, DAE.TYPES_VAR(binding = binding), _, _, _, _) := | |
| 5302 | Lookup.lookupIdentLocal(outCache, outEnv, name); | ||
| 5303 |
2/2✓ Branch 1 taken 31415 times.
✓ Branch 2 taken 41099 times.
|
72514 | true := DAEUtil.isBound(binding); |
| 5304 | else | ||
| 5305 | 89584 | (outCache, outEnv, outIH, outUpdatedComps) := | |
| 5306 | updateComponentInEnv(outCache, outEnv, outIH, pre, mod, cr, ci_state, | ||
| 5307 | impl, outUpdatedComps, currentCref); | ||
| 5308 | end try; | ||
| 5309 | end for; | ||
| 5310 | end updateComponentsInEnv2; | ||
| 5311 | |||
| 5312 | protected function makeFullyQualified2 | ||
| 5313 | "help function to makeFullyQualified" | ||
| 5314 | input FCore.Graph env; | ||
| 5315 | input String name; | ||
| 5316 | input Absyn.Path cachedPath=Absyn.IDENT(""); | ||
| 5317 | output Absyn.Path path; | ||
| 5318 | protected | ||
| 5319 | Absyn.Path scope; | ||
| 5320 | Option<Absyn.Path> oscope; | ||
| 5321 | algorithm | ||
| 5322 | 529153 | oscope := FGraph.getScopePath(env); | |
| 5323 |
3/4✗ Branch 0 not taken.
✓ Branch 1 taken 529153 times.
✓ Branch 2 taken 41869 times.
✓ Branch 3 taken 487284 times.
|
529153 | if isNone(oscope) then |
| 5324 | 41869 | path := makeFullyQualified2Builtin(name, cachedPath); | |
| 5325 | else | ||
| 5326 | 487284 | SOME(scope) := oscope; | |
| 5327 | 487284 | path := AbsynUtil.joinPaths(scope, match cachedPath case Absyn.IDENT("") then Absyn.IDENT(name); else cachedPath; end match); | |
| 5328 | end if; | ||
| 5329 | end makeFullyQualified2; | ||
| 5330 | |||
| 5331 | protected function makeFullyQualified2Builtin "Lookup table to avoid memory allocation of common built-in function calls" | ||
| 5332 | input String ident; | ||
| 5333 | input Absyn.Path cachedPath; | ||
| 5334 | output Absyn.Path path; | ||
| 5335 | algorithm | ||
| 5336 | // TODO: Have annotation asserting that this is a switch-statement | ||
| 5337 | path := match ident | ||
| 5338 | case "abs" then Absyn.FULLYQUALIFIED(Absyn.IDENT("abs")); | ||
| 5339 | case "acos" then Absyn.FULLYQUALIFIED(Absyn.IDENT("acos")); | ||
| 5340 | case "activeState" then Absyn.FULLYQUALIFIED(Absyn.IDENT("activeState")); | ||
| 5341 | case "actualStream" then Absyn.FULLYQUALIFIED(Absyn.IDENT("actualStream")); | ||
| 5342 | case "asin" then Absyn.FULLYQUALIFIED(Absyn.IDENT("asin")); | ||
| 5343 | case "atan" then Absyn.FULLYQUALIFIED(Absyn.IDENT("atan")); | ||
| 5344 | case "atan2" then Absyn.FULLYQUALIFIED(Absyn.IDENT("atan2")); | ||
| 5345 | case "backSample" then Absyn.FULLYQUALIFIED(Absyn.IDENT("backSample")); | ||
| 5346 | case "cardinality" then Absyn.FULLYQUALIFIED(Absyn.IDENT("cardinality")); | ||
| 5347 | case "cat" then Absyn.FULLYQUALIFIED(Absyn.IDENT("cat")); | ||
| 5348 | case "ceil" then Absyn.FULLYQUALIFIED(Absyn.IDENT("ceil")); | ||
| 5349 | case "change" then Absyn.FULLYQUALIFIED(Absyn.IDENT("change")); | ||
| 5350 | case "classDirectory" then Absyn.FULLYQUALIFIED(Absyn.IDENT("classDirectory")); | ||
| 5351 | case "cos" then Absyn.FULLYQUALIFIED(Absyn.IDENT("cos")); | ||
| 5352 | case "cosh" then Absyn.FULLYQUALIFIED(Absyn.IDENT("cosh")); | ||
| 5353 | case "cross" then Absyn.FULLYQUALIFIED(Absyn.IDENT("cross")); | ||
| 5354 | case "delay" then Absyn.FULLYQUALIFIED(Absyn.IDENT("delay")); | ||
| 5355 | case "der" then Absyn.FULLYQUALIFIED(Absyn.IDENT("der")); | ||
| 5356 | case "diagonal" then Absyn.FULLYQUALIFIED(Absyn.IDENT("diagonal")); | ||
| 5357 | case "div" then Absyn.FULLYQUALIFIED(Absyn.IDENT("div")); | ||
| 5358 | case "edge" then Absyn.FULLYQUALIFIED(Absyn.IDENT("edge")); | ||
| 5359 | case "exp" then Absyn.FULLYQUALIFIED(Absyn.IDENT("exp")); | ||
| 5360 | case "fill" then Absyn.FULLYQUALIFIED(Absyn.IDENT("fill")); | ||
| 5361 | case "firstTick" then Absyn.FULLYQUALIFIED(Absyn.IDENT("firstTick")); | ||
| 5362 | case "floor" then Absyn.FULLYQUALIFIED(Absyn.IDENT("floor")); | ||
| 5363 | case "getInstanceName" then Absyn.FULLYQUALIFIED(Absyn.IDENT("getInstanceName")); | ||
| 5364 | case "hold" then Absyn.FULLYQUALIFIED(Absyn.IDENT("hold")); | ||
| 5365 | case "homotopy" then Absyn.FULLYQUALIFIED(Absyn.IDENT("homotopy")); | ||
| 5366 | case "identity" then Absyn.FULLYQUALIFIED(Absyn.IDENT("identity")); | ||
| 5367 | case "inStream" then Absyn.FULLYQUALIFIED(Absyn.IDENT("inStream")); | ||
| 5368 | case "initial" then Absyn.FULLYQUALIFIED(Absyn.IDENT("initial")); | ||
| 5369 | case "initialState" then Absyn.FULLYQUALIFIED(Absyn.IDENT("initialState")); | ||
| 5370 | case "integer" then Absyn.FULLYQUALIFIED(Absyn.IDENT("integer")); | ||
| 5371 | case "interval" then Absyn.FULLYQUALIFIED(Absyn.IDENT("interval")); | ||
| 5372 | case "intAbs" then Absyn.FULLYQUALIFIED(Absyn.IDENT("intAbs")); | ||
| 5373 | case "linspace" then Absyn.FULLYQUALIFIED(Absyn.IDENT("linspace")); | ||
| 5374 | case "log" then Absyn.FULLYQUALIFIED(Absyn.IDENT("log")); | ||
| 5375 | case "log10" then Absyn.FULLYQUALIFIED(Absyn.IDENT("log10")); | ||
| 5376 | case "matrix" then Absyn.FULLYQUALIFIED(Absyn.IDENT("matrix")); | ||
| 5377 | case "max" then Absyn.FULLYQUALIFIED(Absyn.IDENT("max")); | ||
| 5378 | case "min" then Absyn.FULLYQUALIFIED(Absyn.IDENT("min")); | ||
| 5379 | case "mod" then Absyn.FULLYQUALIFIED(Absyn.IDENT("mod")); | ||
| 5380 | case "ndims" then Absyn.FULLYQUALIFIED(Absyn.IDENT("ndims")); | ||
| 5381 | case "noClock" then Absyn.FULLYQUALIFIED(Absyn.IDENT("noClock")); | ||
| 5382 | case "noEvent" then Absyn.FULLYQUALIFIED(Absyn.IDENT("noEvent")); | ||
| 5383 | case "ones" then Absyn.FULLYQUALIFIED(Absyn.IDENT("ones")); | ||
| 5384 | case "outerProduct" then Absyn.FULLYQUALIFIED(Absyn.IDENT("outerProduct")); | ||
| 5385 | case "pre" then Absyn.FULLYQUALIFIED(Absyn.IDENT("pre")); | ||
| 5386 | case "previous" then Absyn.FULLYQUALIFIED(Absyn.IDENT("previous")); | ||
| 5387 | case "print" then Absyn.FULLYQUALIFIED(Absyn.IDENT("print")); | ||
| 5388 | case "product" then Absyn.FULLYQUALIFIED(Absyn.IDENT("product")); | ||
| 5389 | case "realAbs" then Absyn.FULLYQUALIFIED(Absyn.IDENT("realAbs")); | ||
| 5390 | case "rem" then Absyn.FULLYQUALIFIED(Absyn.IDENT("rem")); | ||
| 5391 | case "rooted" then Absyn.FULLYQUALIFIED(Absyn.IDENT("rooted")); | ||
| 5392 | case "sample" then Absyn.FULLYQUALIFIED(Absyn.IDENT("sample")); | ||
| 5393 | case "scalar" then Absyn.FULLYQUALIFIED(Absyn.IDENT("scalar")); | ||
| 5394 | case "semilinear" then Absyn.FULLYQUALIFIED(Absyn.IDENT("semilinear")); | ||
| 5395 | case "shiftSample" then Absyn.FULLYQUALIFIED(Absyn.IDENT("shiftSample")); | ||
| 5396 | case "sign" then Absyn.FULLYQUALIFIED(Absyn.IDENT("sign")); | ||
| 5397 | case "sin" then Absyn.FULLYQUALIFIED(Absyn.IDENT("sin")); | ||
| 5398 | case "sinh" then Absyn.FULLYQUALIFIED(Absyn.IDENT("sinh")); | ||
| 5399 | case "size" then Absyn.FULLYQUALIFIED(Absyn.IDENT("size")); | ||
| 5400 | case "skew" then Absyn.FULLYQUALIFIED(Absyn.IDENT("skew")); | ||
| 5401 | case "smooth" then Absyn.FULLYQUALIFIED(Absyn.IDENT("smooth")); | ||
| 5402 | case "spatialDistribution" then Absyn.FULLYQUALIFIED(Absyn.IDENT("spatialDistribution")); | ||
| 5403 | case "sqrt" then Absyn.FULLYQUALIFIED(Absyn.IDENT("sqrt")); | ||
| 5404 | case "subSample" then Absyn.FULLYQUALIFIED(Absyn.IDENT("subSample")); | ||
| 5405 | case "symmetric" then Absyn.FULLYQUALIFIED(Absyn.IDENT("symmetric")); | ||
| 5406 | case "tan" then Absyn.FULLYQUALIFIED(Absyn.IDENT("tan")); | ||
| 5407 | case "tanh" then Absyn.FULLYQUALIFIED(Absyn.IDENT("tanh")); | ||
| 5408 | case "terminal" then Absyn.FULLYQUALIFIED(Absyn.IDENT("terminal")); | ||
| 5409 | case "ticksInState" then Absyn.FULLYQUALIFIED(Absyn.IDENT("ticksInState")); | ||
| 5410 | case "timeInState" then Absyn.FULLYQUALIFIED(Absyn.IDENT("timeInState")); | ||
| 5411 | case "transition" then Absyn.FULLYQUALIFIED(Absyn.IDENT("transition")); | ||
| 5412 | case "transpose" then Absyn.FULLYQUALIFIED(Absyn.IDENT("transpose")); | ||
| 5413 | case "vector" then Absyn.FULLYQUALIFIED(Absyn.IDENT("vector")); | ||
| 5414 | case "zeros" then Absyn.FULLYQUALIFIED(Absyn.IDENT("zeros")); | ||
| 5415 | 14022 | else match cachedPath case Absyn.IDENT("") then Absyn.IDENT(ident); else cachedPath; end match; | |
| 5416 | end match; | ||
| 5417 | end makeFullyQualified2Builtin; | ||
| 5418 | |||
| 5419 | public function getCachedInstance | ||
| 5420 | input output FCore.Cache cache; | ||
| 5421 | input output FCore.Graph env; | ||
| 5422 | input String name; | ||
| 5423 | input FCore.Ref ref; | ||
| 5424 | protected | ||
| 5425 | Absyn.Path cache_path; | ||
| 5426 | SCode.Element cls; | ||
| 5427 | DAE.Prefix prefix, prefix2; | ||
| 5428 | FCore.Graph env2; | ||
| 5429 | SCode.Encapsulated enc; | ||
| 5430 | SCode.Restriction res; | ||
| 5431 | InstHashTable.CachedInstItemInputs inputs; | ||
| 5432 | algorithm | ||
| 5433 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 186 times.
|
186 | true := Flags.isSet(Flags.CACHE); |
| 5434 | |||
| 5435 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 186 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 186 times.
|
186 | FCore.CL(cls as SCode.CLASS(encapsulatedPrefix = enc, restriction = res), prefix) := |
| 5436 | FNode.refData(ref); | ||
| 5437 | 186 | env2 := FGraph.openScope(env, enc, name, FGraph.restrictionToScopeType(res)); | |
| 5438 | |||
| 5439 | try | ||
| 5440 | 186 | cache_path := generateCachePath(env2, cls, prefix, InstTypes.INNER_CALL()); | |
| 5441 |
6/12✗ Branch 1 not taken.
✓ Branch 2 taken 102 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 102 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 102 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 102 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 102 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 102 times.
|
186 | {SOME(InstHashTable.FUNC_instClassIn(inputs, (env, _, _, _, _, _, _, _, _))), _} := InstHashTable.get(cache_path); |
| 5442 | 102 | (_, prefix2, _, _, _, _, _, _, _) := inputs; | |
| 5443 |
2/4✓ Branch 1 taken 102 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 102 times.
✗ Branch 5 not taken.
|
102 | true := PrefixUtil.isPrefix(prefix) and PrefixUtil.isPrefix(prefix2); |
| 5444 | else | ||
| 5445 | 84 | env := FGraph.pushScopeRef(env, ref); | |
| 5446 | end try; | ||
| 5447 | end getCachedInstance; | ||
| 5448 | |||
| 5449 | protected function generateCachePath | ||
| 5450 | input FCore.Graph env; | ||
| 5451 | input SCode.Element cls; | ||
| 5452 | input DAE.Prefix prefix; | ||
| 5453 | input InstTypes.CallingScope callScope; | ||
| 5454 | output Absyn.Path cachePath; | ||
| 5455 | protected | ||
| 5456 | String name; | ||
| 5457 | algorithm | ||
| 5458 | 2299644 | name := InstTypes.callingScopeStr(callScope) + "$" + SCodeDump.restrString(SCodeUtil.getClassRestriction(cls)) + "$" + generatePrefixStr(prefix) + "$"; | |
| 5459 | 2299644 | cachePath := AbsynUtil.joinPaths(Absyn.IDENT(name), FGraph.getGraphName(env)); | |
| 5460 | end generateCachePath; | ||
| 5461 | |||
| 5462 | public function generatePrefixStr | ||
| 5463 | input DAE.Prefix inPrefix; | ||
| 5464 | output String str; | ||
| 5465 | algorithm | ||
| 5466 | try | ||
| 5467 | 2299644 | str := AbsynUtil.pathString(PrefixUtil.prefixToPath(inPrefix), "$", usefq=false, reverse=true); | |
| 5468 | else | ||
| 5469 | str := ""; | ||
| 5470 | end try; | ||
| 5471 | end generatePrefixStr; | ||
| 5472 | |||
| 5473 | protected function showCacheInfo | ||
| 5474 | input String inMsg; | ||
| 5475 | input Absyn.Path inPath; | ||
| 5476 | algorithm | ||
| 5477 |
1/2✓ Branch 1 taken 2274415 times.
✗ Branch 2 not taken.
|
2274415 | if Flags.isSet(Flags.SHOW_INST_CACHE_INFO) then |
| 5478 | ✗ | print(inMsg + AbsynUtil.pathString(inPath) + "\n"); | |
| 5479 | end if; | ||
| 5480 | end showCacheInfo; | ||
| 5481 | |||
| 5482 | function instFunctionAnnotations "Merges the function's comments from inherited classes" | ||
| 5483 | input list<SCode.Comment> comments; | ||
| 5484 | input ClassInf.State state; | ||
| 5485 | output DAE.DAElist dae=DAE.emptyDae; | ||
| 5486 | protected | ||
| 5487 | Option<String> comment=NONE(); | ||
| 5488 | SCode.Mod mod=SCode.NOMOD(), mod2; | ||
| 5489 | algorithm | ||
| 5490 |
2/2✓ Branch 1 taken 76168 times.
✓ Branch 2 taken 83714 times.
|
159882 | if not ClassInfUtil.isFunction(state) then |
| 5491 | 83714 | return; | |
| 5492 | end if; | ||
| 5493 | |||
| 5494 |
2/2✓ Branch 0 taken 90892 times.
✓ Branch 1 taken 76168 times.
|
167060 | for cmt in comments loop |
| 5495 | |||
| 5496 |
3/4✗ Branch 0 not taken.
✓ Branch 1 taken 90892 times.
✓ Branch 2 taken 76944 times.
✓ Branch 3 taken 13948 times.
|
90892 | if isNone(comment) then |
| 5497 | 76944 | comment := cmt.comment; | |
| 5498 | end if; | ||
| 5499 | |||
| 5500 | mod := match cmt | ||
| 5501 | case SCode.COMMENT(annotation_=SOME(SCode.ANNOTATION(modification=mod2))) | ||
| 5502 | 77677 | then SCodeUtil.mergeModifiers(mod2, mod); | |
| 5503 | else mod; | ||
| 5504 | end match; | ||
| 5505 | |||
| 5506 | end for; | ||
| 5507 | dae := match mod | ||
| 5508 |
3/4✗ Branch 0 not taken.
✓ Branch 1 taken 9850 times.
✓ Branch 2 taken 4054 times.
✓ Branch 3 taken 5796 times.
|
13904 | case SCode.NOMOD() then if isNone(comment) then dae else DAE.DAE({DAE.COMMENT(SCode.COMMENT(NONE(),comment))}); |
| 5509 | 198954 | else DAE.DAE({DAE.COMMENT(SCode.COMMENT(SOME(SCode.ANNOTATION(mod)), comment))}); | |
| 5510 | end match; | ||
| 5511 | end instFunctionAnnotations; | ||
| 5512 | |||
| 5513 | public function instClassType | ||
| 5514 | input output FCore.Cache cache; | ||
| 5515 | input output FCore.Graph env; | ||
| 5516 | input SCode.Element classElem; | ||
| 5517 | output DAE.Type ty; | ||
| 5518 | algorithm | ||
| 5519 | 4 | (cache, env, _, _, _, _, ty) := instClass(cache, env, InnerOuter.emptyInstHierarchy, | |
| 5520 | UnitAbsyn.noStore, DAE.NOMOD(), DAE.NOPRE(), classElem, {}, true, | ||
| 5521 | InstTypes.TOP_CALL(), ConnectionGraph.EMPTY, Connect.emptySet); | ||
| 5522 | end instClassType; | ||
| 5523 | |||
| 5524 | |||
| 5525 | protected function checkInstanceRestriction | ||
| 5526 | input SCode.Element cdef; | ||
| 5527 | input Absyn.Path path; | ||
| 5528 | input Boolean relaxedFrontEnd; | ||
| 5529 | algorithm | ||
| 5530 | // Do not allow instantiation of functions and packages. | ||
| 5531 |
5/6✓ Branch 0 taken 212 times.
✓ Branch 1 taken 14 times.
✓ Branch 3 taken 211 times.
✓ Branch 4 taken 1 time.
✓ Branch 6 taken 211 times.
✗ Branch 7 not taken.
|
226 | if not relaxedFrontEnd and (SCodeUtil.isFunction(cdef) or |
| 5532 | SCodeUtil.isPackage(cdef)) then | ||
| 5533 | 3 | Error.addSourceMessage(Error.INST_INVALID_RESTRICTION, | |
| 5534 | {AbsynUtil.pathString(path), SCodeDump.restrString(SCodeUtil.getClassRestriction(cdef))}, | ||
| 5535 | SCodeUtil.elementInfo(cdef)); | ||
| 5536 | 1 | fail(); | |
| 5537 | end if; | ||
| 5538 | end checkInstanceRestriction; | ||
| 5539 | |||
| 5540 | annotation(__OpenModelica_Interface="frontend"); | ||
| 5541 | end Inst; | ||
| 5542 |