OMCompiler/Compiler/NFFrontEnd/NFPrefixes.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 NFPrefixes | ||
| 37 | |||
| 38 | import Absyn; | ||
| 39 | import DAE; | ||
| 40 | import NFInstNode.InstNode; | ||
| 41 | import SCode; | ||
| 42 | import Type = NFType; | ||
| 43 | |||
| 44 | package ConnectorType | ||
| 45 | type Type = Integer; | ||
| 46 | |||
| 47 | constant Type NON_CONNECTOR = 0; | ||
| 48 | constant Type POTENTIAL = intBitLShift(1, 0) "A connector element without a prefix."; | ||
| 49 | constant Type FLOW = intBitLShift(1, 1) "A connector element with flow prefix."; | ||
| 50 | constant Type STREAM = intBitLShift(1, 2) "A connector element with stream prefix."; | ||
| 51 | constant Type POTENTIALLY_PRESENT = intBitLShift(1, 3) "An element declared inside an expandable connector."; | ||
| 52 | constant Type UNDECLARED = intBitLShift(1, 4) "An undeclared connector used in a connection."; | ||
| 53 | constant Type CONNECTOR = intBitLShift(1, 5) "A non-expandable connector that contains elements."; | ||
| 54 | constant Type EXPANDABLE = intBitLShift(1, 6) "An expandable connector."; | ||
| 55 | constant Type AUGMENTED = intBitLShift(1, 7) "A variable added during augmentation of an expandable connector."; | ||
| 56 | |||
| 57 | // flow/stream | ||
| 58 | constant Type FLOW_STREAM_MASK = intBitOr(FLOW, STREAM); | ||
| 59 | // potential/flow/stream | ||
| 60 | constant Type PREFIX_MASK = intBitOr(POTENTIAL, FLOW_STREAM_MASK); | ||
| 61 | // Some kind of connector, where anything inside an expandable connector also counts. | ||
| 62 | constant Type CONNECTOR_MASK = intBitOr(CONNECTOR, intBitOr(EXPANDABLE, POTENTIALLY_PRESENT)); | ||
| 63 | |||
| 64 | function fromSCode | ||
| 65 | input SCode.ConnectorType scodeCty; | ||
| 66 | output Type cty; | ||
| 67 | algorithm | ||
| 68 | cty := match scodeCty | ||
| 69 | case SCode.ConnectorType.POTENTIAL() then 0; | ||
| 70 | case SCode.ConnectorType.FLOW() then FLOW; | ||
| 71 | case SCode.ConnectorType.STREAM() then STREAM; | ||
| 72 | end match; | ||
| 73 | end fromSCode; | ||
| 74 | |||
| 75 | function toDAE | ||
| 76 | input Type cty; | ||
| 77 | output DAE.ConnectorType dcty; | ||
| 78 | algorithm | ||
| 79 |
2/2✓ Branch 0 taken 456077 times.
✓ Branch 1 taken 70126 times.
|
526203 | if intBitAnd(cty, POTENTIAL) > 0 then |
| 80 | dcty := DAE.ConnectorType.POTENTIAL(); | ||
| 81 | elseif intBitAnd(cty, FLOW) > 0 then | ||
| 82 | dcty := DAE.ConnectorType.FLOW(); | ||
| 83 | elseif intBitAnd(cty, STREAM) > 0 then | ||
| 84 | dcty := DAE.ConnectorType.STREAM(NONE()); | ||
| 85 | else | ||
| 86 | dcty := DAE.ConnectorType.NON_CONNECTOR(); | ||
| 87 | end if; | ||
| 88 | end toDAE; | ||
| 89 | |||
| 90 | function merge | ||
| 91 | input Type outerCty; | ||
| 92 | input Type innerCty; | ||
| 93 | input InstNode node; | ||
| 94 | input Boolean isClass = false; | ||
| 95 | output Type cty; | ||
| 96 | algorithm | ||
| 97 | // If both the outer and the inner has flow or stream, give an error. | ||
| 98 |
3/4✓ Branch 0 taken 989 times.
✓ Branch 1 taken 1026018 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 989 times.
|
1027007 | if intBitAnd(outerCty, FLOW_STREAM_MASK) > 0 and intBitAnd(innerCty, FLOW_STREAM_MASK) > 0 then |
| 99 | ✗ | printPrefixError(toString(outerCty), toString(innerCty), node); | |
| 100 | end if; | ||
| 101 | |||
| 102 | 1027007 | cty := intBitOr(outerCty, innerCty); | |
| 103 | end merge; | ||
| 104 | |||
| 105 | function isPotential | ||
| 106 | input Type cty; | ||
| 107 | output Boolean isPotential; | ||
| 108 | algorithm | ||
| 109 | 51409 | isPotential := intBitAnd(cty, POTENTIAL) > 0; | |
| 110 | annotation(__OpenModelica_EarlyInline = true); | ||
| 111 | end isPotential; | ||
| 112 | |||
| 113 | function setPotential | ||
| 114 | input output Type cty; | ||
| 115 | algorithm | ||
| 116 | 56994 | cty := intBitOr(cty, POTENTIAL); | |
| 117 | annotation(__OpenModelica_EarlyInline = true); | ||
| 118 | end setPotential; | ||
| 119 | |||
| 120 | function isFlow | ||
| 121 | input Type cty; | ||
| 122 | output Boolean isFlow; | ||
| 123 | algorithm | ||
| 124 | 323786 | isFlow := intBitAnd(cty, FLOW) > 0; | |
| 125 | annotation(__OpenModelica_EarlyInline = true); | ||
| 126 | end isFlow; | ||
| 127 | |||
| 128 | function isStream | ||
| 129 | input Type cty; | ||
| 130 | output Boolean isStream; | ||
| 131 | algorithm | ||
| 132 | 29394 | isStream := intBitAnd(cty, STREAM) > 0; | |
| 133 | annotation(__OpenModelica_EarlyInline = true); | ||
| 134 | end isStream; | ||
| 135 | |||
| 136 | function isFlowOrStream | ||
| 137 | input Type cty; | ||
| 138 | output Boolean isFlowOrStream; | ||
| 139 | algorithm | ||
| 140 | 2082434 | isFlowOrStream := intBitAnd(cty, FLOW_STREAM_MASK) > 0; | |
| 141 | annotation(__OpenModelica_EarlyInline = true); | ||
| 142 | end isFlowOrStream; | ||
| 143 | |||
| 144 | function unsetFlowStream | ||
| 145 | input output Type cty; | ||
| 146 | algorithm | ||
| 147 | ✗ | cty := intBitAnd(cty, intBitNot(FLOW_STREAM_MASK)); | |
| 148 | annotation(__OpenModelica_EarlyInline = true); | ||
| 149 | end unsetFlowStream; | ||
| 150 | |||
| 151 | function isConnector | ||
| 152 | "Returns true if the connector type has the connector bit set, otherwise false." | ||
| 153 | input Type cty; | ||
| 154 | output Boolean isConnector; | ||
| 155 | algorithm | ||
| 156 | 475129 | isConnector := intBitAnd(cty, CONNECTOR) > 0; | |
| 157 | annotation(__OpenModelica_EarlyInline = true); | ||
| 158 | end isConnector; | ||
| 159 | |||
| 160 | function setConnector | ||
| 161 | input output Type cty; | ||
| 162 | algorithm | ||
| 163 | 24926 | cty := intBitOr(cty, CONNECTOR); | |
| 164 | annotation(__OpenModelica_EarlyInline = true); | ||
| 165 | end setConnector; | ||
| 166 | |||
| 167 | function isConnectorType | ||
| 168 | "Returns true if the connector type has the connector, expandable, or | ||
| 169 | potentially present bits set, otherwise false." | ||
| 170 | input Type cty; | ||
| 171 | output Boolean isConnector; | ||
| 172 | algorithm | ||
| 173 | 1194124 | isConnector := intBitAnd(cty, CONNECTOR_MASK) > 0; | |
| 174 | annotation(__OpenModelica_EarlyInline = true); | ||
| 175 | end isConnectorType; | ||
| 176 | |||
| 177 | function isExpandable | ||
| 178 | input Type cty; | ||
| 179 | output Boolean isExpandable; | ||
| 180 | algorithm | ||
| 181 | 28016 | isExpandable := intBitAnd(cty, EXPANDABLE) > 0; | |
| 182 | annotation(__OpenModelica_EarlyInline = true); | ||
| 183 | end isExpandable; | ||
| 184 | |||
| 185 | function setExpandable | ||
| 186 | input output Type cty; | ||
| 187 | algorithm | ||
| 188 | 42 | cty := intBitOr(cty, EXPANDABLE); | |
| 189 | annotation(__OpenModelica_EarlyInline = true); | ||
| 190 | end setExpandable; | ||
| 191 | |||
| 192 | function isUndeclared | ||
| 193 | "Returns true if the connector type represents an undeclared connector, otherwise false." | ||
| 194 | input Type cty; | ||
| 195 | output Boolean undeclared; | ||
| 196 | algorithm | ||
| 197 | 28132 | undeclared := intBitAnd(cty, UNDECLARED) > 0; | |
| 198 | annotation(__OpenModelica_EarlyInline = true); | ||
| 199 | end isUndeclared; | ||
| 200 | |||
| 201 | function isPotentiallyPresent | ||
| 202 | input Type cty; | ||
| 203 | output Boolean isPotentiallyPresent; | ||
| 204 | algorithm | ||
| 205 | 364767 | isPotentiallyPresent := intBitAnd(cty, POTENTIALLY_PRESENT) > 0; | |
| 206 | annotation(__OpenModelica_EarlyInline = true); | ||
| 207 | end isPotentiallyPresent; | ||
| 208 | |||
| 209 | function setPresent | ||
| 210 | input output Type cty; | ||
| 211 | algorithm | ||
| 212 | 113 | cty := intBitAnd(cty, intBitNot(POTENTIALLY_PRESENT)); | |
| 213 | annotation(__OpenModelica_EarlyInline = true); | ||
| 214 | end setPresent; | ||
| 215 | |||
| 216 | function isAugmented | ||
| 217 | input Type cty; | ||
| 218 | output Boolean augmented; | ||
| 219 | algorithm | ||
| 220 | 19032 | augmented := intBitAnd(cty, AUGMENTED) > 0; | |
| 221 | annotation(__OpenModelica_EarlyInline = true); | ||
| 222 | end isAugmented; | ||
| 223 | |||
| 224 | function toString | ||
| 225 | input Type cty; | ||
| 226 | output String str; | ||
| 227 | algorithm | ||
| 228 | ✗ | if intBitAnd(cty, FLOW) > 0 then | |
| 229 | str := "flow"; | ||
| 230 | elseif intBitAnd(cty, STREAM) > 0 then | ||
| 231 | str := "stream"; | ||
| 232 | elseif intBitAnd(cty, EXPANDABLE) > 0 then | ||
| 233 | str := "expandable"; | ||
| 234 | else | ||
| 235 | str := ""; | ||
| 236 | end if; | ||
| 237 | end toString; | ||
| 238 | |||
| 239 | function unparse | ||
| 240 | input Type cty; | ||
| 241 | output String str; | ||
| 242 | algorithm | ||
| 243 |
2/2✓ Branch 0 taken 810 times.
✓ Branch 1 taken 308 times.
|
1118 | if intBitAnd(cty, FLOW) > 0 then |
| 244 | str := "flow "; | ||
| 245 | elseif intBitAnd(cty, STREAM) > 0 then | ||
| 246 | str := "stream "; | ||
| 247 | else | ||
| 248 | str := ""; | ||
| 249 | end if; | ||
| 250 | end unparse; | ||
| 251 | |||
| 252 | function toDebugString | ||
| 253 | input Type cty; | ||
| 254 | output String str; | ||
| 255 | protected | ||
| 256 | list<String> strl = {}; | ||
| 257 | algorithm | ||
| 258 | ✗ | if intBitAnd(cty, POTENTIAL) > 0 then strl := "potential" :: strl; end if; | |
| 259 | ✗ | if intBitAnd(cty, FLOW) > 0 then strl := "flow" :: strl; end if; | |
| 260 | ✗ | if intBitAnd(cty, STREAM) > 0 then strl := "stream" :: strl; end if; | |
| 261 | ✗ | if intBitAnd(cty, POTENTIALLY_PRESENT) > 0 then strl := "potentially present" :: strl; end if; | |
| 262 | ✗ | if intBitAnd(cty, UNDECLARED) > 0 then strl := "undeclared" :: strl; end if; | |
| 263 | ✗ | if intBitAnd(cty, CONNECTOR) > 0 then strl := "connector" :: strl; end if; | |
| 264 | ✗ | if intBitAnd(cty, EXPANDABLE) > 0 then strl := "expandable" :: strl; end if; | |
| 265 | |||
| 266 | ✗ | str := stringDelimitList(strl, " "); | |
| 267 | end toDebugString; | ||
| 268 | end ConnectorType; | ||
| 269 | |||
| 270 | type Parallelism = enumeration( | ||
| 271 | NON_PARALLEL, | ||
| 272 | GLOBAL, | ||
| 273 | LOCAL | ||
| 274 | ); | ||
| 275 | |||
| 276 | type Variability = enumeration( | ||
| 277 | CONSTANT, | ||
| 278 | STRUCTURAL_PARAMETER, | ||
| 279 | PARAMETER, | ||
| 280 | NON_STRUCTURAL_PARAMETER, | ||
| 281 | DISCRETE, | ||
| 282 | IMPLICITLY_DISCRETE, | ||
| 283 | CONTINUOUS | ||
| 284 | ); | ||
| 285 | |||
| 286 | type Purity = enumeration( | ||
| 287 | PURE, | ||
| 288 | IMPURE | ||
| 289 | ); | ||
| 290 | |||
| 291 | type Direction = enumeration( | ||
| 292 | NONE, | ||
| 293 | INPUT, | ||
| 294 | OUTPUT | ||
| 295 | ); | ||
| 296 | |||
| 297 | type InnerOuter = enumeration( | ||
| 298 | NOT_INNER_OUTER, | ||
| 299 | INNER, | ||
| 300 | OUTER, | ||
| 301 | INNER_OUTER | ||
| 302 | ); | ||
| 303 | |||
| 304 | type Visibility = enumeration( | ||
| 305 | PUBLIC, | ||
| 306 | PROTECTED | ||
| 307 | ); | ||
| 308 | |||
| 309 | type AccessLevel = enumeration( | ||
| 310 | HIDE, | ||
| 311 | ICON, | ||
| 312 | DOCUMENTATION, | ||
| 313 | DIAGRAM, | ||
| 314 | NON_PACKAGE_TEXT, | ||
| 315 | NON_PACKAGE_DUPLICATE, | ||
| 316 | PACKAGE_TEXT, | ||
| 317 | PACKAGE_DUPLICATE | ||
| 318 | ); | ||
| 319 | |||
| 320 | uniontype Replaceable | ||
| 321 | record REPLACEABLE | ||
| 322 | Option<InstNode> constrainingClass; | ||
| 323 | end REPLACEABLE; | ||
| 324 | |||
| 325 | record NOT_REPLACEABLE end NOT_REPLACEABLE; | ||
| 326 | end Replaceable; | ||
| 327 | |||
| 328 | function parallelismFromSCode | ||
| 329 | input SCode.Parallelism scodePar; | ||
| 330 | output Parallelism par; | ||
| 331 | algorithm | ||
| 332 | par := match scodePar | ||
| 333 | case SCode.Parallelism.PARGLOBAL() then Parallelism.GLOBAL; | ||
| 334 | case SCode.Parallelism.PARLOCAL() then Parallelism.LOCAL; | ||
| 335 | case SCode.Parallelism.NON_PARALLEL() then Parallelism.NON_PARALLEL; | ||
| 336 | end match; | ||
| 337 | end parallelismFromSCode; | ||
| 338 | |||
| 339 | function parallelismToSCode | ||
| 340 | input Parallelism par; | ||
| 341 | output SCode.Parallelism scodePar; | ||
| 342 | algorithm | ||
| 343 | scodePar := match par | ||
| 344 | case Parallelism.GLOBAL then SCode.Parallelism.PARGLOBAL(); | ||
| 345 | case Parallelism.LOCAL then SCode.Parallelism.PARLOCAL() ; | ||
| 346 | case Parallelism.NON_PARALLEL then SCode.Parallelism.NON_PARALLEL() ; | ||
| 347 | end match; | ||
| 348 | end parallelismToSCode; | ||
| 349 | |||
| 350 | function parallelismToDAE | ||
| 351 | input Parallelism par; | ||
| 352 | output DAE.VarParallelism dpar; | ||
| 353 | algorithm | ||
| 354 | dpar := match par | ||
| 355 | case Parallelism.GLOBAL then DAE.VarParallelism.PARGLOBAL(); | ||
| 356 | case Parallelism.LOCAL then DAE.VarParallelism.PARLOCAL(); | ||
| 357 | case Parallelism.NON_PARALLEL then DAE.VarParallelism.NON_PARALLEL(); | ||
| 358 | end match; | ||
| 359 | end parallelismToDAE; | ||
| 360 | |||
| 361 | function parallelismString | ||
| 362 | input Parallelism par; | ||
| 363 | output String str; | ||
| 364 | algorithm | ||
| 365 | str := match par | ||
| 366 | case Parallelism.GLOBAL then "parglobal"; | ||
| 367 | case Parallelism.LOCAL then "parlocal"; | ||
| 368 | else ""; | ||
| 369 | end match; | ||
| 370 | end parallelismString; | ||
| 371 | |||
| 372 | function unparseParallelism | ||
| 373 | input Parallelism par; | ||
| 374 | output String str; | ||
| 375 | algorithm | ||
| 376 | str := match par | ||
| 377 | case Parallelism.GLOBAL then "parglobal "; | ||
| 378 | case Parallelism.LOCAL then "parlocal "; | ||
| 379 | else ""; | ||
| 380 | end match; | ||
| 381 | end unparseParallelism; | ||
| 382 | |||
| 383 | function mergeParallelism | ||
| 384 | input Parallelism outerPar; | ||
| 385 | input Parallelism innerPar; | ||
| 386 | input InstNode node; | ||
| 387 | output Parallelism par; | ||
| 388 | algorithm | ||
| 389 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 347554 times.
|
347554 | if outerPar == Parallelism.NON_PARALLEL then |
| 390 | par := innerPar; | ||
| 391 | elseif innerPar == Parallelism.NON_PARALLEL then | ||
| 392 | par := outerPar; | ||
| 393 | elseif innerPar == outerPar then | ||
| 394 | par := innerPar; | ||
| 395 | else | ||
| 396 | ✗ | printPrefixError(parallelismString(outerPar), parallelismString(innerPar), node); | |
| 397 | end if; | ||
| 398 | end mergeParallelism; | ||
| 399 | |||
| 400 | function variabilityFromSCode | ||
| 401 | input SCode.Variability scodeVar; | ||
| 402 | output Variability var; | ||
| 403 | algorithm | ||
| 404 | var := match scodeVar | ||
| 405 | case SCode.Variability.CONST() then Variability.CONSTANT; | ||
| 406 | case SCode.Variability.PARAM() then Variability.PARAMETER; | ||
| 407 | case SCode.Variability.DISCRETE() then Variability.DISCRETE; | ||
| 408 | case SCode.Variability.VAR() then Variability.CONTINUOUS; | ||
| 409 | end match; | ||
| 410 | end variabilityFromSCode; | ||
| 411 | |||
| 412 | function variabilityToSCode | ||
| 413 | input Variability var; | ||
| 414 | output SCode.Variability scodeVar; | ||
| 415 | algorithm | ||
| 416 | scodeVar := match var | ||
| 417 | case Variability.CONSTANT then SCode.Variability.CONST(); | ||
| 418 | case Variability.STRUCTURAL_PARAMETER then SCode.Variability.PARAM(); | ||
| 419 | case Variability.PARAMETER then SCode.Variability.PARAM(); | ||
| 420 | case Variability.NON_STRUCTURAL_PARAMETER then SCode.Variability.PARAM(); | ||
| 421 | case Variability.DISCRETE then SCode.Variability.DISCRETE(); | ||
| 422 | else SCode.Variability.VAR(); | ||
| 423 | end match; | ||
| 424 | end variabilityToSCode; | ||
| 425 | |||
| 426 | function variabilityToDAE | ||
| 427 | input Variability var; | ||
| 428 | output DAE.VarKind varKind; | ||
| 429 | algorithm | ||
| 430 | varKind := match var | ||
| 431 | case Variability.CONSTANT then DAE.VarKind.CONST(); | ||
| 432 | case Variability.STRUCTURAL_PARAMETER then DAE.VarKind.PARAM(); | ||
| 433 | case Variability.PARAMETER then DAE.VarKind.PARAM(); | ||
| 434 | case Variability.NON_STRUCTURAL_PARAMETER then DAE.VarKind.PARAM(); | ||
| 435 | case Variability.DISCRETE then DAE.VarKind.DISCRETE(); | ||
| 436 | else DAE.VarKind.VARIABLE(); | ||
| 437 | end match; | ||
| 438 | end variabilityToDAE; | ||
| 439 | |||
| 440 | function variabilityToDAEConst | ||
| 441 | input Variability var; | ||
| 442 | output DAE.Const const; | ||
| 443 | algorithm | ||
| 444 | const := match var | ||
| 445 | case Variability.CONSTANT then DAE.Const.C_CONST(); | ||
| 446 | case Variability.STRUCTURAL_PARAMETER then DAE.Const.C_PARAM(); | ||
| 447 | case Variability.PARAMETER then DAE.Const.C_PARAM(); | ||
| 448 | case Variability.NON_STRUCTURAL_PARAMETER then DAE.Const.C_PARAM(); | ||
| 449 | else DAE.Const.C_VAR(); | ||
| 450 | end match; | ||
| 451 | end variabilityToDAEConst; | ||
| 452 | |||
| 453 | function variabilityString | ||
| 454 | input Variability var; | ||
| 455 | output String str; | ||
| 456 | algorithm | ||
| 457 | str := match var | ||
| 458 | case Variability.CONSTANT then "constant"; | ||
| 459 | case Variability.STRUCTURAL_PARAMETER then "parameter"; | ||
| 460 | case Variability.PARAMETER then "parameter"; | ||
| 461 | case Variability.NON_STRUCTURAL_PARAMETER then "parameter"; | ||
| 462 | case Variability.DISCRETE then "discrete"; | ||
| 463 | case Variability.IMPLICITLY_DISCRETE then "discrete"; | ||
| 464 | case Variability.CONTINUOUS then "continuous"; | ||
| 465 | end match; | ||
| 466 | end variabilityString; | ||
| 467 | |||
| 468 | function unparseVariability | ||
| 469 | input Variability var; | ||
| 470 | input Type ty; | ||
| 471 | output String str; | ||
| 472 | algorithm | ||
| 473 | str := match var | ||
| 474 | case Variability.CONSTANT then "constant "; | ||
| 475 | case Variability.STRUCTURAL_PARAMETER then "parameter "; | ||
| 476 | case Variability.PARAMETER then "parameter "; | ||
| 477 | case Variability.NON_STRUCTURAL_PARAMETER then "parameter "; | ||
| 478 | ✗ | case Variability.DISCRETE then if Type.isDiscrete(ty) then "" else "discrete "; | |
| 479 | else ""; | ||
| 480 | end match; | ||
| 481 | end unparseVariability; | ||
| 482 | |||
| 483 | function variabilityMax | ||
| 484 | input Variability var1; | ||
| 485 | input Variability var2; | ||
| 486 | output Variability var = if var1 > var2 then var1 else var2; | ||
| 487 | end variabilityMax; | ||
| 488 | |||
| 489 | function variabilityMin | ||
| 490 | input Variability var1; | ||
| 491 | input Variability var2; | ||
| 492 | output Variability var = if var1 > var2 then var2 else var1; | ||
| 493 | end variabilityMin; | ||
| 494 | |||
| 495 | function effectiveVariability | ||
| 496 | input Variability inVar; | ||
| 497 | output Variability outVar; | ||
| 498 | algorithm | ||
| 499 | outVar := match inVar | ||
| 500 | case Variability.STRUCTURAL_PARAMETER then Variability.PARAMETER; | ||
| 501 | case Variability.NON_STRUCTURAL_PARAMETER then Variability.PARAMETER; | ||
| 502 | case Variability.IMPLICITLY_DISCRETE then Variability.DISCRETE; | ||
| 503 | else inVar; | ||
| 504 | end match; | ||
| 505 | end effectiveVariability; | ||
| 506 | |||
| 507 | function purityString | ||
| 508 | input Purity purity; | ||
| 509 | output String str; | ||
| 510 | algorithm | ||
| 511 | str := match purity | ||
| 512 | case Purity.PURE then "pure"; | ||
| 513 | case Purity.IMPURE then "impure"; | ||
| 514 | end match; | ||
| 515 | end purityString; | ||
| 516 | |||
| 517 | function purityMin | ||
| 518 | "Returns the least pure of the arguments." | ||
| 519 | input Purity p1; | ||
| 520 | input Purity p2; | ||
| 521 | output Purity p = if p1 == Purity.IMPURE then p1 else p2; | ||
| 522 | end purityMin; | ||
| 523 | |||
| 524 | function directionFromSCode | ||
| 525 | input Absyn.Direction scodeDir; | ||
| 526 | output Direction dir; | ||
| 527 | algorithm | ||
| 528 | dir := match scodeDir | ||
| 529 | case Absyn.Direction.INPUT() then Direction.INPUT; | ||
| 530 | case Absyn.Direction.OUTPUT() then Direction.OUTPUT; | ||
| 531 | else Direction.NONE; | ||
| 532 | end match; | ||
| 533 | end directionFromSCode; | ||
| 534 | |||
| 535 | function directionToDAE | ||
| 536 | input Direction dir; | ||
| 537 | output DAE.VarDirection ddir; | ||
| 538 | algorithm | ||
| 539 | ddir := match dir | ||
| 540 | case Direction.INPUT then DAE.VarDirection.INPUT(); | ||
| 541 | case Direction.OUTPUT then DAE.VarDirection.OUTPUT(); | ||
| 542 | else DAE.VarDirection.BIDIR(); | ||
| 543 | end match; | ||
| 544 | end directionToDAE; | ||
| 545 | |||
| 546 | function directionToAbsyn | ||
| 547 | input Direction dir; | ||
| 548 | output Absyn.Direction adir; | ||
| 549 | algorithm | ||
| 550 | adir := match dir | ||
| 551 | case Direction.INPUT then Absyn.INPUT(); | ||
| 552 | case Direction.OUTPUT then Absyn.OUTPUT(); | ||
| 553 | else Absyn.BIDIR(); | ||
| 554 | end match; | ||
| 555 | end directionToAbsyn; | ||
| 556 | |||
| 557 | function directionString | ||
| 558 | input Direction dir; | ||
| 559 | output String str; | ||
| 560 | algorithm | ||
| 561 | str := match dir | ||
| 562 | case Direction.INPUT then "input"; | ||
| 563 | case Direction.OUTPUT then "output"; | ||
| 564 | else ""; | ||
| 565 | end match; | ||
| 566 | end directionString; | ||
| 567 | |||
| 568 | function unparseDirection | ||
| 569 | input Direction dir; | ||
| 570 | output String str; | ||
| 571 | algorithm | ||
| 572 | str := match dir | ||
| 573 | case Direction.INPUT then "input "; | ||
| 574 | case Direction.OUTPUT then "output "; | ||
| 575 | else ""; | ||
| 576 | end match; | ||
| 577 | end unparseDirection; | ||
| 578 | |||
| 579 | function mergeDirection | ||
| 580 | input Direction outerDir; | ||
| 581 | input Direction innerDir; | ||
| 582 | input InstNode node; | ||
| 583 | input Boolean allowSame = false; | ||
| 584 | output Direction dir; | ||
| 585 | algorithm | ||
| 586 |
2/2✓ Branch 0 taken 16412 times.
✓ Branch 1 taken 331359 times.
|
347771 | if outerDir == Direction.NONE then |
| 587 | dir := innerDir; | ||
| 588 | elseif innerDir == Direction.NONE then | ||
| 589 | dir := outerDir; | ||
| 590 | elseif allowSame and outerDir == innerDir then | ||
| 591 | dir := innerDir; | ||
| 592 | else | ||
| 593 | 2 | printPrefixError(directionString(outerDir), directionString(innerDir), node); | |
| 594 | end if; | ||
| 595 | end mergeDirection; | ||
| 596 | |||
| 597 | function innerOuterFromSCode | ||
| 598 | input Absyn.InnerOuter scodeIO; | ||
| 599 | output InnerOuter io; | ||
| 600 | algorithm | ||
| 601 | io := match scodeIO | ||
| 602 | case Absyn.NOT_INNER_OUTER() then InnerOuter.NOT_INNER_OUTER; | ||
| 603 | case Absyn.INNER() then InnerOuter.INNER; | ||
| 604 | case Absyn.OUTER() then InnerOuter.OUTER; | ||
| 605 | case Absyn.INNER_OUTER() then InnerOuter.INNER_OUTER; | ||
| 606 | end match; | ||
| 607 | end innerOuterFromSCode; | ||
| 608 | |||
| 609 | function innerOuterToAbsyn | ||
| 610 | input InnerOuter inIO; | ||
| 611 | output Absyn.InnerOuter outIO; | ||
| 612 | algorithm | ||
| 613 | outIO := match inIO | ||
| 614 | case InnerOuter.NOT_INNER_OUTER then Absyn.NOT_INNER_OUTER(); | ||
| 615 | case InnerOuter.INNER then Absyn.INNER(); | ||
| 616 | case InnerOuter.OUTER then Absyn.OUTER(); | ||
| 617 | case InnerOuter.INNER_OUTER then Absyn.INNER_OUTER(); | ||
| 618 | end match; | ||
| 619 | end innerOuterToAbsyn; | ||
| 620 | |||
| 621 | function innerOuterString | ||
| 622 | input InnerOuter io; | ||
| 623 | output String str; | ||
| 624 | algorithm | ||
| 625 | str := match io | ||
| 626 | case InnerOuter.INNER then "inner"; | ||
| 627 | case InnerOuter.OUTER then "outer"; | ||
| 628 | case InnerOuter.INNER_OUTER then "inner outer"; | ||
| 629 | else ""; | ||
| 630 | end match; | ||
| 631 | end innerOuterString; | ||
| 632 | |||
| 633 | function unparseInnerOuter | ||
| 634 | input InnerOuter io; | ||
| 635 | output String str; | ||
| 636 | algorithm | ||
| 637 | str := match io | ||
| 638 | case InnerOuter.INNER then "inner "; | ||
| 639 | case InnerOuter.OUTER then "outer "; | ||
| 640 | case InnerOuter.INNER_OUTER then "inner outer "; | ||
| 641 | else ""; | ||
| 642 | end match; | ||
| 643 | end unparseInnerOuter; | ||
| 644 | |||
| 645 | function visibilityFromSCode | ||
| 646 | input SCode.Visibility scodeVis; | ||
| 647 | output Visibility vis; | ||
| 648 | algorithm | ||
| 649 | vis := match scodeVis | ||
| 650 | case SCode.Visibility.PUBLIC() then Visibility.PUBLIC; | ||
| 651 | else Visibility.PROTECTED; | ||
| 652 | end match; | ||
| 653 | end visibilityFromSCode; | ||
| 654 | |||
| 655 | function visibilityToDAE | ||
| 656 | input Visibility vis; | ||
| 657 | output DAE.VarVisibility dvis = if vis == Visibility.PUBLIC then | ||
| 658 | DAE.VarVisibility.PUBLIC() else DAE.VarVisibility.PROTECTED(); | ||
| 659 | end visibilityToDAE; | ||
| 660 | |||
| 661 | function visibilityToSCode | ||
| 662 | input Visibility vis; | ||
| 663 | output SCode.Visibility scodeVis = if vis == Visibility.PUBLIC then | ||
| 664 | SCode.Visibility.PUBLIC() else SCode.Visibility.PROTECTED(); | ||
| 665 | end visibilityToSCode; | ||
| 666 | |||
| 667 | function visibilityString | ||
| 668 | input Visibility vis; | ||
| 669 | output String str = if vis == Visibility.PUBLIC then "public" else "protected"; | ||
| 670 | end visibilityString; | ||
| 671 | |||
| 672 | function unparseVisibility | ||
| 673 | input Visibility vis; | ||
| 674 | output String str = if vis == Visibility.PROTECTED then "protected " else ""; | ||
| 675 | end unparseVisibility; | ||
| 676 | |||
| 677 | function mergeVisibility | ||
| 678 | input Visibility outerVis; | ||
| 679 | input Visibility innerVis; | ||
| 680 | output Visibility vis = if outerVis == Visibility.PROTECTED then outerVis else innerVis; | ||
| 681 | end mergeVisibility; | ||
| 682 | |||
| 683 | function isReplaceable | ||
| 684 | input Replaceable repl; | ||
| 685 | output Boolean res; | ||
| 686 | algorithm | ||
| 687 | res := match repl | ||
| 688 | case Replaceable.REPLACEABLE() then true; | ||
| 689 | else false; | ||
| 690 | end match; | ||
| 691 | end isReplaceable; | ||
| 692 | |||
| 693 | function replaceableString | ||
| 694 | input Replaceable repl; | ||
| 695 | output String str; | ||
| 696 | algorithm | ||
| 697 | str := match repl | ||
| 698 | case Replaceable.REPLACEABLE() then "replaceable"; | ||
| 699 | else ""; | ||
| 700 | end match; | ||
| 701 | end replaceableString; | ||
| 702 | |||
| 703 | function unparseReplaceable | ||
| 704 | input Replaceable repl; | ||
| 705 | output String str; | ||
| 706 | algorithm | ||
| 707 | str := match repl | ||
| 708 | case Replaceable.REPLACEABLE() then "replaceable "; | ||
| 709 | else ""; | ||
| 710 | end match; | ||
| 711 | end unparseReplaceable; | ||
| 712 | |||
| 713 | function printPrefixError | ||
| 714 | input String outerPrefix; | ||
| 715 | input String innerPrefix; | ||
| 716 | input InstNode node; | ||
| 717 | algorithm | ||
| 718 | 6 | Error.addSourceMessage(Error.INVALID_TYPE_PREFIX, | |
| 719 | {outerPrefix, InstNode.typeName(node), InstNode.name(node), innerPrefix}, | ||
| 720 | InstNode.info(node)); | ||
| 721 | 2 | fail(); | |
| 722 | end printPrefixError; | ||
| 723 | |||
| 724 | function accessLevelFromAbsyn | ||
| 725 | input Absyn.Exp exp; | ||
| 726 | output Option<AccessLevel> access; | ||
| 727 | protected | ||
| 728 | String name; | ||
| 729 | algorithm | ||
| 730 | access := match exp | ||
| 731 | case Absyn.Exp.CREF(componentRef = Absyn.ComponentRef.CREF_QUAL(name = "Access", | ||
| 732 | componentRef = Absyn.ComponentRef.CREF_IDENT(name = name))) | ||
| 733 | then match name | ||
| 734 | case "hide" then SOME(AccessLevel.HIDE); | ||
| 735 | case "icon" then SOME(AccessLevel.ICON); | ||
| 736 | case "documentation" then SOME(AccessLevel.DOCUMENTATION); | ||
| 737 | case "diagram" then SOME(AccessLevel.DIAGRAM); | ||
| 738 | case "nonPackageText" then SOME(AccessLevel.NON_PACKAGE_TEXT); | ||
| 739 | case "nonPackageDuplicate" then SOME(AccessLevel.NON_PACKAGE_DUPLICATE); | ||
| 740 | case "packageText" then SOME(AccessLevel.PACKAGE_TEXT); | ||
| 741 | case "packageDuplicate" then SOME(AccessLevel.PACKAGE_DUPLICATE); | ||
| 742 | else NONE(); | ||
| 743 | end match; | ||
| 744 | |||
| 745 | else NONE(); | ||
| 746 | end match; | ||
| 747 | end accessLevelFromAbsyn; | ||
| 748 | |||
| 749 | annotation(__OpenModelica_Interface="nf_frontend"); | ||
| 750 | end NFPrefixes; | ||
| 751 |