OMCompiler/Compiler/NFFrontEnd/NFConnection.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 uniontype NFConnection | ||
| 37 | import Connector = NFConnector; | ||
| 38 | protected | ||
| 39 | import Error; | ||
| 40 | import MetaModelica.Dangerous.listReverseInPlace; | ||
| 41 | import Connection = NFConnection; | ||
| 42 | import List; | ||
| 43 | |||
| 44 | public | ||
| 45 | record CONNECTION | ||
| 46 | // TODO: This should be Connector, but the import above doesn't work due to some compiler bug. | ||
| 47 | NFConnector lhs; | ||
| 48 | NFConnector rhs; | ||
| 49 | end CONNECTION; | ||
| 50 | |||
| 51 | function split | ||
| 52 | input Connection conn; | ||
| 53 | output list<Connection> conns = {}; | ||
| 54 | protected | ||
| 55 | list<Connector> cls, crs; | ||
| 56 | Connector cr; | ||
| 57 | algorithm | ||
| 58 | 13939 | cls := Connector.split(conn.lhs); | |
| 59 | 13939 | crs := Connector.split(conn.rhs); | |
| 60 | 13939 | checkBalance(cls, crs, conn); | |
| 61 | |||
| 62 |
2/2✓ Branch 0 taken 34311 times.
✓ Branch 1 taken 13939 times.
|
48250 | for cl in cls loop |
| 63 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 34311 times.
|
34311 | cr :: crs := crs; |
| 64 | |||
| 65 | // Connections involving deleted conditional connectors are filtered out | ||
| 66 | // when collecting the connections, but if the connectors themselves | ||
| 67 | // contain connectors that have been deleted we need to remove them here. | ||
| 68 |
3/4✓ Branch 1 taken 34306 times.
✓ Branch 2 taken 5 times.
✓ Branch 4 taken 34306 times.
✗ Branch 5 not taken.
|
34311 | if not (Connector.isDeleted(cl) or Connector.isDeleted(cr)) then |
| 69 | 34306 | conns := CONNECTION(cl, cr) :: conns; | |
| 70 | end if; | ||
| 71 | end for; | ||
| 72 | |||
| 73 | 13939 | conns := listReverseInPlace(conns); | |
| 74 | end split; | ||
| 75 | |||
| 76 | function scalarize | ||
| 77 | input Connection conn; | ||
| 78 | output list<Connection> conns = {}; | ||
| 79 | protected | ||
| 80 | list<Connector> cls, crs; | ||
| 81 | Connector cr; | ||
| 82 | algorithm | ||
| 83 |
2/2✓ Branch 1 taken 23084 times.
✓ Branch 2 taken 11146 times.
|
34230 | if not Connector.isArray(conn.lhs) then |
| 84 | conns := {conn}; | ||
| 85 | 23084 | return; | |
| 86 | end if; | ||
| 87 | |||
| 88 | 11146 | cls := Connector.scalarize(conn.lhs); | |
| 89 | 11146 | crs := Connector.scalarize(conn.rhs); | |
| 90 | 11146 | checkBalance(cls, crs, conn); | |
| 91 | |||
| 92 |
2/2✓ Branch 0 taken 43691 times.
✓ Branch 1 taken 11146 times.
|
54837 | for cl in cls loop |
| 93 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 43691 times.
|
43691 | cr :: crs := crs; |
| 94 | 43691 | conns := CONNECTION(cl, cr) :: conns; | |
| 95 | end for; | ||
| 96 | |||
| 97 | 11146 | conns := listReverseInPlace(conns); | |
| 98 | end scalarize; | ||
| 99 | |||
| 100 | function scalarizePrefix | ||
| 101 | input Connection conn; | ||
| 102 | output list<Connection> conns = {}; | ||
| 103 | protected | ||
| 104 | list<Connector> cls, crs; | ||
| 105 | Connector cr; | ||
| 106 | algorithm | ||
| 107 | ✗ | if not Connector.isArray(conn.lhs) then | |
| 108 | conns := {conn}; | ||
| 109 | ✗ | return; | |
| 110 | end if; | ||
| 111 | |||
| 112 | ✗ | cls := Connector.scalarizePrefix(conn.lhs); | |
| 113 | ✗ | crs := Connector.scalarizePrefix(conn.rhs); | |
| 114 | ✗ | checkBalance(cls, crs, conn); | |
| 115 | |||
| 116 | ✗ | for cl in cls loop | |
| 117 | ✗ | cr :: crs := crs; | |
| 118 | ✗ | conns := CONNECTION(cl, cr) :: conns; | |
| 119 | end for; | ||
| 120 | |||
| 121 | ✗ | conns := listReverseInPlace(conns); | |
| 122 | end scalarizePrefix; | ||
| 123 | |||
| 124 | function toString | ||
| 125 | input Connection conn; | ||
| 126 | output String str; | ||
| 127 | algorithm | ||
| 128 | ✗ | str := "connect(" + Connector.toString(conn.lhs) + ", " + Connector.toString(conn.rhs) + ")"; | |
| 129 | end toString; | ||
| 130 | |||
| 131 | protected | ||
| 132 | function checkBalance | ||
| 133 | input list<Connector> leftConnectors; | ||
| 134 | input list<Connector> rightConnectors; | ||
| 135 | input Connection conn; | ||
| 136 | algorithm | ||
| 137 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 25085 times.
|
25085 | if listLength(leftConnectors) <> listLength(rightConnectors) then |
| 138 | ✗ | Error.terminate(getInstanceName() + " got unbalanced connection " + toString(conn) + ":" + | |
| 139 | List.toStringCustom(leftConnectors, Connector.toString, "\n lhs: ", "{", ", ", "}", true) + | ||
| 140 | List.toStringCustom(rightConnectors, Connector.toString, "\n rhs: ", "{", ", ", "}", true), sourceInfo()); | ||
| 141 | ✗ | fail(); | |
| 142 | end if; | ||
| 143 | end checkBalance; | ||
| 144 | |||
| 145 | annotation(__OpenModelica_Interface="nf_frontend"); | ||
| 146 | end NFConnection; | ||
| 147 |