OMCompiler/Compiler/FrontEnd/InstMeta.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 InstMeta | ||
| 37 | " file: InstMeta.mo | ||
| 38 | package: InstMeta | ||
| 39 | description: Different MetaModelica extension functions, for instantiation and later parts of the compiler. | ||
| 40 | " | ||
| 41 | |||
| 42 | import ClassInf; | ||
| 43 | import DAE; | ||
| 44 | import FCore; | ||
| 45 | import SCode; | ||
| 46 | |||
| 47 | protected | ||
| 48 | import Absyn; | ||
| 49 | |||
| 50 | import Flags; | ||
| 51 | import Lookup; | ||
| 52 | import SCodeUtil; | ||
| 53 | import Types; | ||
| 54 | |||
| 55 | public function fixUniontype | ||
| 56 | input FCore.Cache inCache; | ||
| 57 | input FCore.Graph inEnv; | ||
| 58 | input ClassInf.State inState; | ||
| 59 | input SCode.ClassDef inClassDef; | ||
| 60 | output FCore.Cache cache = inCache; | ||
| 61 | output Option<DAE.Type> outType; | ||
| 62 | algorithm | ||
| 63 | outType := match (inState, inClassDef) | ||
| 64 | local | ||
| 65 | Absyn.Path p, p2, utPathOfRestriction, utPath; | ||
| 66 | Boolean isSingleton; | ||
| 67 | DAE.EvaluateSingletonType singletonType; | ||
| 68 | String name; | ||
| 69 | list<Absyn.Path> paths; | ||
| 70 | list<DAE.Type> typeVarsTypes; | ||
| 71 | list<String> names, typeVars; | ||
| 72 | case (ClassInf.META_UNIONTYPE(typeVars=typeVars), SCode.PARTS()) | ||
| 73 | algorithm | ||
| 74 | 39619 | utPath := inState.path; | |
| 75 | 39619 | p := AbsynUtil.makeFullyQualified(inState.path); | |
| 76 |
2/2✓ Branch 0 taken 536444 times.
✓ Branch 1 taken 39619 times.
|
576063 | names := SCodeUtil.elementNames(list( |
| 77 | e for e | ||
| 78 | guard match e | ||
| 79 | case SCode.CLASS(restriction=SCode.R_METARECORD(name = utPathOfRestriction)) | ||
| 80 | 534500 | then AbsynUtil.pathSuffixOf(utPathOfRestriction, utPath); | |
| 81 | else false; | ||
| 82 | end match | ||
| 83 | in inClassDef.elementLst)); | ||
| 84 |
4/4✓ Branch 0 taken 534497 times.
✓ Branch 1 taken 39619 times.
✓ Branch 2 taken 534497 times.
✓ Branch 3 taken 39619 times.
|
574116 | paths := list(AbsynUtil.suffixPath(p, n) for n in names); |
| 85 | 39619 | isSingleton := listLength(paths) == 1; | |
| 86 |
2/2✓ Branch 0 taken 13006 times.
✓ Branch 1 taken 26613 times.
|
39619 | if isSingleton then |
| 87 | 13006 | p2 := listGet(paths, 1); | |
| 88 | 13006 | singletonType := DAE.EVAL_SINGLETON_TYPE_FUNCTION(function fixUniontype2(arr=arrayCreate(1, (cache, inEnv, p2, NONE())))); | |
| 89 | else | ||
| 90 | singletonType := DAE.NOT_SINGLETON(); | ||
| 91 | end if; | ||
| 92 |
4/4✓ Branch 0 taken 108 times.
✓ Branch 1 taken 39619 times.
✓ Branch 2 taken 108 times.
✓ Branch 3 taken 39619 times.
|
39727 | typeVarsTypes := list(DAE.T_METAPOLYMORPHIC(tv) for tv in typeVars); |
| 93 |
2/2✓ Branch 0 taken 26613 times.
✓ Branch 1 taken 13006 times.
|
66232 | then |
| 94 | SOME(DAE.T_METAUNIONTYPE(paths, typeVarsTypes, isSingleton, singletonType, p)); | ||
| 95 | else NONE(); | ||
| 96 | end match; | ||
| 97 | end fixUniontype; | ||
| 98 | |||
| 99 | protected function fixUniontype2 | ||
| 100 | input array<tuple<FCore.Cache, FCore.Graph, Absyn.Path, Option<DAE.Type>>> arr; | ||
| 101 | output DAE.Type singletonType; | ||
| 102 | protected | ||
| 103 | FCore.Cache cache; | ||
| 104 | FCore.Graph env; | ||
| 105 | Absyn.Path p; | ||
| 106 | Option<DAE.Type> ot; | ||
| 107 | algorithm | ||
| 108 | 466 | (cache,env,p,ot) := arrayGet(arr, 1); | |
| 109 |
3/4✗ Branch 0 not taken.
✓ Branch 1 taken 466 times.
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 426 times.
|
466 | if isNone(ot) then |
| 110 | 40 | (_, singletonType) := Lookup.lookupType(cache, env, p, SOME(sourceInfo())); | |
| 111 | 40 | arrayUpdate(arr, 1, (cache,env,p,SOME(singletonType))); | |
| 112 | else | ||
| 113 | 426 | SOME(singletonType) := ot; | |
| 114 | end if; | ||
| 115 | end fixUniontype2; | ||
| 116 | |||
| 117 | public function checkArrayType | ||
| 118 | "Checks that an array type is valid." | ||
| 119 | input DAE.Type inType; | ||
| 120 | protected | ||
| 121 | DAE.Type el_ty; | ||
| 122 | algorithm | ||
| 123 | 51407 | el_ty := Types.arrayElementType(inType); | |
| 124 |
6/6✓ Branch 1 taken 48478 times.
✓ Branch 2 taken 2929 times.
✓ Branch 4 taken 47946 times.
✓ Branch 5 taken 532 times.
✓ Branch 7 taken 209 times.
✓ Branch 8 taken 50666 times.
|
51407 | false := (not Types.isString(el_ty) and Types.isBoxedType(el_ty)) or |
| 125 | Flags.isSet(Flags.RML); | ||
| 126 | end checkArrayType; | ||
| 127 | |||
| 128 | annotation(__OpenModelica_Interface="frontend"); | ||
| 129 | end InstMeta; | ||
| 130 |