OMCompiler/Compiler/FrontEnd/ValuesMake.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 ValuesMake | ||
| 37 | " file: ValuesMake.mo | ||
| 38 | package: ValuesMake | ||
| 39 | description: Evaluated expression values | ||
| 40 | |||
| 41 | |||
| 42 | The package Values contains utility functions for handling evaluated | ||
| 43 | expression values." | ||
| 44 | |||
| 45 | public import Absyn; | ||
| 46 | public import DAE; | ||
| 47 | public import Values; | ||
| 48 | |||
| 49 | protected | ||
| 50 | import List; | ||
| 51 | |||
| 52 | public function makeZero "Returns a zero value based on a DAE.Type" | ||
| 53 | input DAE.Type ty; | ||
| 54 | output Values.Value zero; | ||
| 55 | algorithm | ||
| 56 | zero := match ty | ||
| 57 | case DAE.T_REAL() then Values.REAL(0.0); | ||
| 58 | case DAE.T_INTEGER() then Values.INTEGER(0); | ||
| 59 | end match; | ||
| 60 | end makeZero; | ||
| 61 | |||
| 62 | public function makeBoolean | ||
| 63 | input Boolean b; | ||
| 64 | output Values.Value v; | ||
| 65 | algorithm | ||
| 66 |
2/2✓ Branch 0 taken 65 times.
✓ Branch 1 taken 104 times.
|
234 | v := Values.BOOL(b); |
| 67 | end makeBoolean; | ||
| 68 | |||
| 69 | public function makeReal "Creates a real value " | ||
| 70 | input Real r; | ||
| 71 | output Values.Value v; | ||
| 72 | algorithm | ||
| 73 | 15121 | v := Values.REAL(r); | |
| 74 | end makeReal; | ||
| 75 | |||
| 76 | public function makeInteger "Creates an integer value " | ||
| 77 | input Integer i; | ||
| 78 | output Values.Value v; | ||
| 79 | algorithm | ||
| 80 | 15650 | v := Values.INTEGER(i); | |
| 81 | end makeInteger; | ||
| 82 | |||
| 83 | public function makeString "Creates a string value " | ||
| 84 | input String s; | ||
| 85 | output Values.Value v; | ||
| 86 | algorithm | ||
| 87 | 2050 | v := Values.STRING(s); | |
| 88 | end makeString; | ||
| 89 | |||
| 90 | public function makeTuple "Construct a tuple of a list of Values." | ||
| 91 | input list<Values.Value> inValueLst; | ||
| 92 | output Values.Value outValue; | ||
| 93 | algorithm | ||
| 94 | 2 | outValue := Values.TUPLE(inValueLst); | |
| 95 | end makeTuple; | ||
| 96 | |||
| 97 | public function makeList "Construct a list from a list of Values." | ||
| 98 | input list<Values.Value> inValueLst; | ||
| 99 | output Values.Value outValue; | ||
| 100 | algorithm | ||
| 101 | ✗ | outValue := Values.LIST(inValueLst); | |
| 102 | end makeList; | ||
| 103 | |||
| 104 | public function makeArray " | ||
| 105 | Construct an array of a list of Values. | ||
| 106 | " | ||
| 107 | input list<Values.Value> inValueLst; | ||
| 108 | output Values.Value outValue; | ||
| 109 | algorithm | ||
| 110 | outValue:= | ||
| 111 | match inValueLst | ||
| 112 | local | ||
| 113 | Integer i1; | ||
| 114 | list<Integer> il; | ||
| 115 | list<Values.Value> vlst; | ||
| 116 | case vlst as (Values.ARRAY(dimLst = il)::_) | ||
| 117 | algorithm | ||
| 118 | 865 | i1 := listLength(vlst); | |
| 119 | 865 | then Values.ARRAY(vlst,i1::il); | |
| 120 | case vlst | ||
| 121 | algorithm | ||
| 122 | 46444 | i1 := listLength(vlst); | |
| 123 | 46444 | then Values.ARRAY(vlst,{i1}); | |
| 124 | end match; | ||
| 125 | end makeArray; | ||
| 126 | |||
| 127 | function makeEmptyArray | ||
| 128 | output Values.Value outValue = Values.Value.ARRAY({}, {0}); | ||
| 129 | end makeEmptyArray; | ||
| 130 | |||
| 131 | public function makeStringArray | ||
| 132 | "Creates a Values.ARRAY from a list of Strings." | ||
| 133 | input list<String> inReals; | ||
| 134 | output Values.Value outArray; | ||
| 135 | algorithm | ||
| 136 | 17 | outArray := makeArray(List.map(inReals, makeString)); | |
| 137 | end makeStringArray; | ||
| 138 | |||
| 139 | public function makeIntArray | ||
| 140 | "Creates a Value.ARRAY from a list of integers." | ||
| 141 | input list<Integer> inInts; | ||
| 142 | output Values.Value outArray; | ||
| 143 | algorithm | ||
| 144 | 4 | outArray := makeArray(List.map(inInts, makeInteger)); | |
| 145 | end makeIntArray; | ||
| 146 | |||
| 147 | public function makeRealArray | ||
| 148 | "Creates a Values.ARRAY from a list of reals." | ||
| 149 | input list<Real> inReals; | ||
| 150 | output Values.Value outArray; | ||
| 151 | algorithm | ||
| 152 | 24 | outArray := makeArray(List.map(inReals, makeReal)); | |
| 153 | end makeRealArray; | ||
| 154 | |||
| 155 | public function makeRealMatrix | ||
| 156 | "Creates a matrix (ARRAY of ARRAY) from a list of list of reals." | ||
| 157 | input list<list<Real>> inReals; | ||
| 158 | output Values.Value outArray; | ||
| 159 | algorithm | ||
| 160 | 8 | outArray := makeArray(List.map(inReals, makeRealArray)); | |
| 161 | end makeRealMatrix; | ||
| 162 | |||
| 163 | public function makeCodeTypeName | ||
| 164 | input Absyn.Path path; | ||
| 165 | output Values.Value val; | ||
| 166 | algorithm | ||
| 167 | 186 | val := Values.CODE(Absyn.C_TYPENAME(path)); | |
| 168 | end makeCodeTypeName; | ||
| 169 | |||
| 170 | public function makeCodeTypeNameStr | ||
| 171 | input String str; | ||
| 172 | output Values.Value val; | ||
| 173 | algorithm | ||
| 174 | 273 | val := Values.CODE(Absyn.C_TYPENAME(Absyn.IDENT(str))); | |
| 175 | end makeCodeTypeNameStr; | ||
| 176 | |||
| 177 | public function makeCodeTypeNameArray | ||
| 178 | input list<Absyn.Path> paths; | ||
| 179 | output Values.Value val; | ||
| 180 | algorithm | ||
| 181 |
4/4✓ Branch 0 taken 142 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 142 times.
✓ Branch 3 taken 32 times.
|
174 | val := makeArray(list(makeCodeTypeName(p) for p in paths)); |
| 182 | end makeCodeTypeNameArray; | ||
| 183 | |||
| 184 | annotation(__OpenModelica_Interface="frontend_dump"); | ||
| 185 | end ValuesMake; | ||
| 186 |