OMCompiler/Compiler/FrontEnd/ValuesUtil.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 ValuesUtil | ||
| 37 | " file: ValuesUtil.mo | ||
| 38 | package: ValuesUtil | ||
| 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 AbsynUtil; | ||
| 47 | public import DAE; | ||
| 48 | public import Values; | ||
| 49 | public import ValuesDump; | ||
| 50 | public import ValuesMake; | ||
| 51 | |||
| 52 | protected import Debug; | ||
| 53 | protected import Dump; | ||
| 54 | protected import Error; | ||
| 55 | protected import Expression; | ||
| 56 | protected import ExpressionSimplify; | ||
| 57 | protected import ExpressionSimplifyTypes; | ||
| 58 | protected import Flags; | ||
| 59 | protected import List; | ||
| 60 | protected import Print; | ||
| 61 | protected import System; | ||
| 62 | protected import ClassInf; | ||
| 63 | protected import Types; | ||
| 64 | |||
| 65 | public function typeConvert "Apply type conversion on a list of Values" | ||
| 66 | input DAE.Type inType1; | ||
| 67 | input DAE.Type inType2; | ||
| 68 | input list<Values.Value> inValueLst3; | ||
| 69 | output list<Values.Value> outValueLst; | ||
| 70 | algorithm | ||
| 71 | outValueLst := match (inType1,inType2,inValueLst3) | ||
| 72 | local | ||
| 73 | list<Values.Value> vallst,vrest,vallst2,vals; | ||
| 74 | Real rval,r; | ||
| 75 | DAE.Type from,to; | ||
| 76 | Integer i,ival; | ||
| 77 | list<Integer> dims; | ||
| 78 | |||
| 79 | case (_,_,{}) then {}; | ||
| 80 | |||
| 81 | case (from as DAE.T_INTEGER(),to as DAE.T_REAL(),(Values.INTEGER(integer = i) :: vrest)) | ||
| 82 | algorithm | ||
| 83 | 68 | vallst := typeConvert(from, to, vrest); | |
| 84 | 68 | rval := intReal(i); | |
| 85 | 68 | then | |
| 86 | (Values.REAL(rval) :: vallst); | ||
| 87 | |||
| 88 | case (from as DAE.T_REAL(),to as DAE.T_INTEGER(),(Values.REAL(real = r) :: vrest)) | ||
| 89 | algorithm | ||
| 90 | ✗ | vallst := typeConvert(from, to, vrest); | |
| 91 | ✗ | ival := realInt(r); | |
| 92 | ✗ | then | |
| 93 | (Values.INTEGER(ival) :: vallst); | ||
| 94 | |||
| 95 | case (from,to,(Values.ARRAY(valueLst = vals, dimLst = dims) :: vrest)) | ||
| 96 | algorithm | ||
| 97 | ✗ | vallst := typeConvert(from, to, vals); | |
| 98 | ✗ | vallst2 := typeConvert(from, to, vrest); | |
| 99 | ✗ | then | |
| 100 | (Values.ARRAY(vallst,dims) :: vallst2); | ||
| 101 | end match; | ||
| 102 | end typeConvert; | ||
| 103 | |||
| 104 | public function valueExpType "creates a DAE.Type from a Value" | ||
| 105 | input Values.Value inValue; | ||
| 106 | output DAE.Type tp; | ||
| 107 | algorithm | ||
| 108 | tp := matchcontinue inValue | ||
| 109 | local | ||
| 110 | Absyn.Path path; | ||
| 111 | list<String> nameLst; | ||
| 112 | DAE.Type eltTp; | ||
| 113 | list<Values.Value> valLst; | ||
| 114 | list<DAE.Type> eltTps; | ||
| 115 | list<DAE.Var> varLst; | ||
| 116 | list<Integer> int_dims; | ||
| 117 | DAE.Dimensions dims; | ||
| 118 | |||
| 119 | case Values.INTEGER(_) then DAE.T_INTEGER_DEFAULT; | ||
| 120 | case Values.REAL(_) then DAE.T_REAL_DEFAULT; | ||
| 121 | case Values.BOOL(_) then DAE.T_BOOL_DEFAULT; | ||
| 122 | case Values.STRING(_) then DAE.T_STRING_DEFAULT; | ||
| 123 | case Values.ENUM_LITERAL(name = path) | ||
| 124 | algorithm | ||
| 125 | ✗ | path := AbsynUtil.pathPrefix(path); | |
| 126 | ✗ | then DAE.T_ENUMERATION(NONE(),path,{},{},{}); | |
| 127 | case Values.ARRAY(valLst,int_dims) algorithm | ||
| 128 | ✗ | eltTp:=valueExpType(listHead(valLst)); | |
| 129 | ✗ | dims := List.map(int_dims, Expression.intDimension); | |
| 130 | ✗ | then DAE.T_ARRAY(eltTp,dims); | |
| 131 | |||
| 132 | case Values.RECORD(path,valLst,nameLst,_) algorithm | ||
| 133 | ✗ | eltTps := List.map(valLst,valueExpType); | |
| 134 | ✗ | varLst := List.threadMap(eltTps,nameLst,valueExpTypeExpVar); | |
| 135 | ✗ | then DAE.T_COMPLEX(ClassInf.RECORD(path),varLst,NONE(), false); | |
| 136 | |||
| 137 | case _ | ||
| 138 | algorithm | ||
| 139 | ✗ | print("valueExpType on "+ValuesDump.valString(inValue) + " not implemented yet\n"); | |
| 140 | ✗ | then fail(); | |
| 141 | end matchcontinue; | ||
| 142 | end valueExpType; | ||
| 143 | |||
| 144 | protected function valueExpTypeExpVar "help function to valueExpType" | ||
| 145 | input DAE.Type etp; | ||
| 146 | input String name; | ||
| 147 | output DAE.Var expVar; | ||
| 148 | annotation(__OpenModelica_EarlyInline = true); | ||
| 149 | algorithm | ||
| 150 | ✗ | expVar := DAE.TYPES_VAR(name, DAE.dummyAttrVar, etp, DAE.UNBOUND(), false, NONE()); | |
| 151 | end valueExpTypeExpVar; | ||
| 152 | |||
| 153 | public function isZero "Returns true if value is zero" | ||
| 154 | input Values.Value inValue; | ||
| 155 | output Boolean isZero; | ||
| 156 | algorithm | ||
| 157 | isZero := match inValue | ||
| 158 | local | ||
| 159 | Real rval; | ||
| 160 | Integer ival; | ||
| 161 | |||
| 162 | ✗ | case Values.REAL(rval) then realEq(rval, 0.0); | |
| 163 | ✗ | case Values.INTEGER(ival) then intEq(ival, 0); | |
| 164 | else false; | ||
| 165 | end match; | ||
| 166 | end isZero; | ||
| 167 | |||
| 168 | public function isArray "Return true if Value is an array." | ||
| 169 | input Values.Value inValue; | ||
| 170 | output Boolean outBoolean; | ||
| 171 | algorithm | ||
| 172 | outBoolean := match inValue | ||
| 173 | case Values.ARRAY() then true; | ||
| 174 | else false; | ||
| 175 | end match; | ||
| 176 | end isArray; | ||
| 177 | |||
| 178 | public function isRecord "Return true if Value is an array." | ||
| 179 | input Values.Value inValue; | ||
| 180 | output Boolean outBoolean; | ||
| 181 | algorithm | ||
| 182 | outBoolean := match inValue | ||
| 183 | case Values.RECORD() then true; | ||
| 184 | else false; | ||
| 185 | end match; | ||
| 186 | end isRecord; | ||
| 187 | |||
| 188 | public function nthArrayelt "author: PA | ||
| 189 | Return the nth value of an array, indexed from 1..n" | ||
| 190 | input Values.Value inValue; | ||
| 191 | input Integer inInteger; | ||
| 192 | output Values.Value outValue; | ||
| 193 | protected | ||
| 194 | list<Values.Value> vlst; | ||
| 195 | algorithm | ||
| 196 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 211776 times.
|
211776 | Values.ARRAY(valueLst=vlst) := inValue; |
| 197 | 211776 | outValue := listGet(vlst, inInteger); | |
| 198 | end nthArrayelt; | ||
| 199 | |||
| 200 | public function safeIntRealOp | ||
| 201 | "Performs mul, div, sub, add and pow on integers and reals. | ||
| 202 | If for example an integer multiplication does not fit in a | ||
| 203 | integer, a real is returned instead. The is not the ideal way of | ||
| 204 | handling this, since the types are decided in run-time. Currently, | ||
| 205 | this is the simplest and best alternative for the moment though. | ||
| 206 | |||
| 207 | In the future, we should introduce BIG-INTS, or maybe throw exceptions | ||
| 208 | (when exceptions are available in the language). | ||
| 209 | " | ||
| 210 | input Values.Value val1; | ||
| 211 | input Values.Value val2; | ||
| 212 | input Values.IntRealOp op; | ||
| 213 | output Values.Value outv; | ||
| 214 | algorithm | ||
| 215 | outv := matchcontinue(val1, val2, op) | ||
| 216 | local | ||
| 217 | Real rv1,rv2,rv3; | ||
| 218 | Integer iv1, iv2; | ||
| 219 | DAE.Exp e; | ||
| 220 | //MUL | ||
| 221 | case (Values.INTEGER(iv1),Values.INTEGER(iv2), Values.MULOP()) | ||
| 222 | algorithm | ||
| 223 | 14965 | e := ExpressionSimplify.safeIntOp(iv1,iv2,ExpressionSimplifyTypes.MULOP()); | |
| 224 | 14965 | outv := expValue(e); | |
| 225 | then | ||
| 226 | outv; | ||
| 227 | case (Values.REAL(rv1),Values.INTEGER(iv2), Values.MULOP()) | ||
| 228 | algorithm | ||
| 229 | ✗ | rv2 := intReal(iv2); | |
| 230 | ✗ | rv3 := rv1 * rv2; | |
| 231 | ✗ | then | |
| 232 | Values.REAL(rv3); | ||
| 233 | case (Values.INTEGER(iv1), Values.REAL(rv2), Values.MULOP()) | ||
| 234 | algorithm | ||
| 235 | ✗ | rv1 := intReal(iv1); | |
| 236 | ✗ | rv3 := rv1 * rv2; | |
| 237 | ✗ | then | |
| 238 | Values.REAL(rv3); | ||
| 239 | case (Values.REAL(rv1), Values.REAL(rv2), Values.MULOP()) | ||
| 240 | algorithm | ||
| 241 | 157093 | rv3 := rv1 * rv2; | |
| 242 | 157093 | then | |
| 243 | Values.REAL(rv3); | ||
| 244 | //DIV | ||
| 245 | case (Values.INTEGER(iv1),Values.INTEGER(iv2), Values.DIVOP()) | ||
| 246 | algorithm | ||
| 247 | ✗ | e := ExpressionSimplify.safeIntOp(iv1,iv2,ExpressionSimplifyTypes.DIVOP()); | |
| 248 | ✗ | outv := expValue(e); | |
| 249 | then | ||
| 250 | outv; | ||
| 251 | case (Values.REAL(rv1),Values.INTEGER(iv2), Values.DIVOP()) | ||
| 252 | algorithm | ||
| 253 | ✗ | rv2 := intReal(iv2); | |
| 254 | ✗ | rv3 := rv1 / rv2; | |
| 255 | ✗ | then | |
| 256 | Values.REAL(rv3); | ||
| 257 | case (Values.INTEGER(iv1), Values.REAL(rv2), Values.DIVOP()) | ||
| 258 | algorithm | ||
| 259 | ✗ | rv1 := intReal(iv1); | |
| 260 | ✗ | rv3 := rv1 / rv2; | |
| 261 | ✗ | then | |
| 262 | Values.REAL(rv3); | ||
| 263 | case (Values.REAL(rv1), Values.REAL(rv2), Values.DIVOP()) | ||
| 264 | algorithm | ||
| 265 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16740 times.
|
16740 | rv3 := rv1 / rv2; |
| 266 | 16740 | then | |
| 267 | Values.REAL(rv3); | ||
| 268 | //POW | ||
| 269 | case (Values.INTEGER(iv1),Values.INTEGER(iv2), Values.POWOP()) // this means indirect that we are dealing with decimal numbers (a^(-b)) = 1/a^b | ||
| 270 | algorithm | ||
| 271 | ✗ | true := (iv2 < 0); | |
| 272 | ✗ | rv1 := intReal(iv1); | |
| 273 | ✗ | rv2 := intReal(iv2); | |
| 274 | ✗ | rv3 := realPow(rv1, rv2); | |
| 275 | ✗ | then | |
| 276 | Values.REAL(rv3); | ||
| 277 | case (Values.INTEGER(iv1),Values.INTEGER(iv2), Values.POWOP()) | ||
| 278 | algorithm | ||
| 279 | ✗ | e := ExpressionSimplify.safeIntOp(iv1,iv2,ExpressionSimplifyTypes.POWOP()); | |
| 280 | ✗ | outv := expValue(e); | |
| 281 | then | ||
| 282 | outv; | ||
| 283 | case (Values.REAL(rv1),Values.INTEGER(iv2), Values.POWOP()) | ||
| 284 | algorithm | ||
| 285 | ✗ | rv2 := intReal(iv2); | |
| 286 | ✗ | rv3 := realPow(rv1, rv2); | |
| 287 | ✗ | then | |
| 288 | Values.REAL(rv3); | ||
| 289 | case (Values.INTEGER(iv1), Values.REAL(rv2), Values.POWOP()) | ||
| 290 | algorithm | ||
| 291 | ✗ | iv2 := realInt(rv2); | |
| 292 | ✗ | e := ExpressionSimplify.safeIntOp(iv1,iv2,ExpressionSimplifyTypes.POWOP()); | |
| 293 | ✗ | outv := expValue(e); | |
| 294 | then | ||
| 295 | outv; | ||
| 296 | case (Values.INTEGER(iv1), Values.REAL(rv2), Values.POWOP()) | ||
| 297 | algorithm | ||
| 298 | ✗ | rv1 := intReal(iv1); | |
| 299 | ✗ | rv3 := realPow(rv1, rv2); | |
| 300 | ✗ | then | |
| 301 | Values.REAL(rv3); | ||
| 302 | case (Values.REAL(rv1), Values.REAL(rv2), Values.POWOP()) | ||
| 303 | algorithm | ||
| 304 |
8/22✓ Branch 0 taken 517 times.
✓ Branch 1 taken 11209 times.
✓ Branch 2 taken 517 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 517 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 517 times.
✓ Branch 8 taken 517 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 11726 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 11726 times.
|
11726 | rv3 := realPow(rv1, rv2); |
| 305 | 11726 | then | |
| 306 | Values.REAL(rv3); | ||
| 307 | //ADD | ||
| 308 | case (Values.INTEGER(iv1),Values.INTEGER(iv2), Values.ADDOP()) | ||
| 309 | algorithm | ||
| 310 | 11485 | e := ExpressionSimplify.safeIntOp(iv1,iv2,ExpressionSimplifyTypes.ADDOP()); | |
| 311 | 11485 | outv := expValue(e); | |
| 312 | then | ||
| 313 | outv; | ||
| 314 | case (Values.REAL(rv1),Values.INTEGER(iv2), Values.ADDOP()) | ||
| 315 | algorithm | ||
| 316 | 17 | rv2 := intReal(iv2); | |
| 317 | 17 | rv3 := rv1 + rv2; | |
| 318 | 17 | then | |
| 319 | Values.REAL(rv3); | ||
| 320 | case (Values.INTEGER(iv1), Values.REAL(rv2), Values.ADDOP()) | ||
| 321 | algorithm | ||
| 322 | 127 | rv1 := intReal(iv1); | |
| 323 | 127 | rv3 := rv1 + rv2; | |
| 324 | 127 | then | |
| 325 | Values.REAL(rv3); | ||
| 326 | case (Values.REAL(rv1), Values.REAL(rv2), Values.ADDOP()) | ||
| 327 | algorithm | ||
| 328 | 16 | rv3 := rv1 + rv2; | |
| 329 | 16 | then | |
| 330 | Values.REAL(rv3); | ||
| 331 | //SUB | ||
| 332 | case (Values.INTEGER(iv1),Values.INTEGER(iv2), Values.SUBOP()) | ||
| 333 | algorithm | ||
| 334 | 5 | e := ExpressionSimplify.safeIntOp(iv1,iv2,ExpressionSimplifyTypes.SUBOP()); | |
| 335 | 5 | outv := expValue(e); | |
| 336 | then | ||
| 337 | outv; | ||
| 338 | case (Values.REAL(rv1),Values.INTEGER(iv2), Values.SUBOP()) | ||
| 339 | algorithm | ||
| 340 | ✗ | rv2 := intReal(iv2); | |
| 341 | ✗ | rv3 := rv1 - rv2; | |
| 342 | ✗ | then | |
| 343 | Values.REAL(rv3); | ||
| 344 | case (Values.INTEGER(iv1), Values.REAL(rv2), Values.SUBOP()) | ||
| 345 | algorithm | ||
| 346 | ✗ | rv1 := intReal(iv1); | |
| 347 | ✗ | rv3 := rv1 - rv2; | |
| 348 | ✗ | then | |
| 349 | Values.REAL(rv3); | ||
| 350 | case (Values.REAL(rv1), Values.REAL(rv2), Values.SUBOP()) | ||
| 351 | algorithm | ||
| 352 | 14948 | rv3 := rv1 - rv2; | |
| 353 | 14948 | then | |
| 354 | Values.REAL(rv3); | ||
| 355 | end matchcontinue; | ||
| 356 | end safeIntRealOp; | ||
| 357 | |||
| 358 | public function safeLessEq | ||
| 359 | "Checks if val1 is less or equal to val2. Val1 or val2 can be integers (or | ||
| 360 | something that can be converted to integer) or reals." | ||
| 361 | input Values.Value val1; | ||
| 362 | input Values.Value val2; | ||
| 363 | output Boolean outv; | ||
| 364 | algorithm | ||
| 365 | outv := match(val1, val2) | ||
| 366 | local | ||
| 367 | Real r1, r2; | ||
| 368 | Integer i1, i2; | ||
| 369 | |||
| 370 | case (Values.REAL(r1), Values.REAL(r2)) | ||
| 371 | 30 | then (r1 <= r2); | |
| 372 | |||
| 373 | case (Values.REAL(r1), _) | ||
| 374 | algorithm | ||
| 375 | 8 | r2 := intReal(valueInteger(val2)); | |
| 376 | 8 | then (r1 <= r2); | |
| 377 | |||
| 378 | case (_, Values.REAL(r2)) | ||
| 379 | algorithm | ||
| 380 | ✗ | r1 := intReal(valueInteger(val1)); | |
| 381 | ✗ | then (r1 <= r2); | |
| 382 | |||
| 383 | case (_, _) | ||
| 384 | algorithm | ||
| 385 | 2741 | i1 := valueInteger(val1); | |
| 386 | 2741 | i2 := valueInteger(val2); | |
| 387 | 2741 | then | |
| 388 | (i1 <= i2); | ||
| 389 | end match; | ||
| 390 | end safeLessEq; | ||
| 391 | |||
| 392 | public function writeToFileAsArgs " | ||
| 393 | Write a list of Values to a file. This function is used when | ||
| 394 | writing the formal input arguments of a function call to a file before | ||
| 395 | executing the function. | ||
| 396 | " | ||
| 397 | input list<Values.Value> vallst; | ||
| 398 | input String filename; | ||
| 399 | protected | ||
| 400 | String str; | ||
| 401 | algorithm | ||
| 402 | ✗ | str := ValuesDump.unparseValues(vallst); | |
| 403 | ✗ | System.writeFile(filename, str); | |
| 404 | end writeToFileAsArgs; | ||
| 405 | |||
| 406 | public function addElementwiseArrayelt " | ||
| 407 | Perform elementwise addition of two arrays. | ||
| 408 | " | ||
| 409 | input list<Values.Value> inValueLst1; | ||
| 410 | input list<Values.Value> inValueLst2; | ||
| 411 | output list<Values.Value> outValueLst; | ||
| 412 | algorithm | ||
| 413 | outValueLst:= | ||
| 414 | match (inValueLst1,inValueLst2) | ||
| 415 | local | ||
| 416 | list<Values.Value> reslst,res2,v1lst,rest1,v2lst,rest2; | ||
| 417 | Integer res,v1,v2; | ||
| 418 | Real r1,r2,rres; | ||
| 419 | String s1,s2,sres; | ||
| 420 | list<Integer> dims; | ||
| 421 | case ((Values.ARRAY(valueLst = v1lst, dimLst = dims) :: rest1),(Values.ARRAY(valueLst = v2lst) :: rest2)) | ||
| 422 | algorithm | ||
| 423 | ✗ | reslst := addElementwiseArrayelt(v1lst, v2lst); | |
| 424 | ✗ | res2 := addElementwiseArrayelt(rest1, rest2); | |
| 425 | ✗ | then | |
| 426 | (Values.ARRAY(reslst,dims) :: res2); | ||
| 427 | case ((Values.INTEGER(integer = v1) :: rest1),(Values.INTEGER(integer = v2) :: rest2)) | ||
| 428 | algorithm | ||
| 429 | ✗ | res := v1 + v2; | |
| 430 | ✗ | res2 := addElementwiseArrayelt(rest1, rest2); | |
| 431 | ✗ | then | |
| 432 | (Values.INTEGER(res) :: res2); | ||
| 433 | case ((Values.REAL(real = r1) :: rest1),(Values.REAL(real = r2) :: rest2)) | ||
| 434 | algorithm | ||
| 435 | 930 | rres := r1 + r2; | |
| 436 | 930 | res2 := addElementwiseArrayelt(rest1, rest2); | |
| 437 | 930 | then | |
| 438 | (Values.REAL(rres) :: res2); | ||
| 439 | case ((Values.STRING(string = s1) :: rest1),(Values.STRING(string = s2) :: rest2)) | ||
| 440 | algorithm | ||
| 441 | ✗ | sres := stringAppend(s1, s2); | |
| 442 | ✗ | res2 := addElementwiseArrayelt(rest1, rest2) "Addition of strings is string concatenation" ; | |
| 443 | ✗ | then | |
| 444 | (Values.STRING(sres) :: res2); | ||
| 445 | case ({},{}) then {}; | ||
| 446 | end match; | ||
| 447 | end addElementwiseArrayelt; | ||
| 448 | |||
| 449 | public function subElementwiseArrayelt " | ||
| 450 | Perform element subtraction of two arrays of values | ||
| 451 | " | ||
| 452 | input list<Values.Value> inValueLst1; | ||
| 453 | input list<Values.Value> inValueLst2; | ||
| 454 | output list<Values.Value> outValueLst; | ||
| 455 | algorithm | ||
| 456 | outValueLst:= | ||
| 457 | match (inValueLst1,inValueLst2) | ||
| 458 | local | ||
| 459 | list<Values.Value> reslst,res2,v1lst,rest1,v2lst,rest2; | ||
| 460 | Integer res,v1,v2; | ||
| 461 | list<Integer> dims; | ||
| 462 | Real r1,r2,rres; | ||
| 463 | case ((Values.ARRAY(valueLst = v1lst, dimLst = dims) :: rest1),(Values.ARRAY(valueLst = v2lst) :: rest2)) | ||
| 464 | algorithm | ||
| 465 | ✗ | reslst := subElementwiseArrayelt(v1lst, v2lst); | |
| 466 | ✗ | res2 := subElementwiseArrayelt(rest1, rest2); | |
| 467 | ✗ | then | |
| 468 | (Values.ARRAY(reslst,dims) :: res2); | ||
| 469 | case ((Values.INTEGER(integer = v1) :: rest1),(Values.INTEGER(integer = v2) :: rest2)) | ||
| 470 | algorithm | ||
| 471 | ✗ | res := v1 - v2; | |
| 472 | ✗ | res2 := subElementwiseArrayelt(rest1, rest2); | |
| 473 | ✗ | then | |
| 474 | (Values.INTEGER(res) :: res2); | ||
| 475 | case ((Values.REAL(real = r1) :: rest1),(Values.REAL(real = r2) :: rest2)) | ||
| 476 | algorithm | ||
| 477 | ✗ | rres := r1 - r2; | |
| 478 | ✗ | res2 := subElementwiseArrayelt(rest1, rest2); | |
| 479 | ✗ | then | |
| 480 | (Values.REAL(rres) :: res2); | ||
| 481 | case ({},{}) then {}; | ||
| 482 | end match; | ||
| 483 | end subElementwiseArrayelt; | ||
| 484 | |||
| 485 | public function mulElementwiseArrayelt " | ||
| 486 | Perform elementwise multiplication of two arrays of values | ||
| 487 | " | ||
| 488 | input list<Values.Value> inValueLst1; | ||
| 489 | input list<Values.Value> inValueLst2; | ||
| 490 | output list<Values.Value> outValueLst; | ||
| 491 | algorithm | ||
| 492 | outValueLst:= | ||
| 493 | match (inValueLst1,inValueLst2) | ||
| 494 | local | ||
| 495 | list<Values.Value> reslst,res2,v1lst,rest1,v2lst,rest2; | ||
| 496 | Integer res,v1,v2; | ||
| 497 | list<Integer> dims; | ||
| 498 | Real rres,r1,r2; | ||
| 499 | case ((Values.ARRAY(valueLst = v1lst, dimLst = dims) :: rest1),(Values.ARRAY(valueLst = v2lst) :: rest2)) | ||
| 500 | algorithm | ||
| 501 | ✗ | reslst := mulElementwiseArrayelt(v1lst, v2lst); | |
| 502 | ✗ | res2 := mulElementwiseArrayelt(rest1, rest2); | |
| 503 | ✗ | then | |
| 504 | (Values.ARRAY(reslst,dims) :: res2); | ||
| 505 | case ((Values.INTEGER(integer = v1) :: rest1),(Values.INTEGER(integer = v2) :: rest2)) | ||
| 506 | algorithm | ||
| 507 | ✗ | res := v1 * v2; | |
| 508 | ✗ | res2 := mulElementwiseArrayelt(rest1, rest2); | |
| 509 | ✗ | then | |
| 510 | (Values.INTEGER(res) :: res2); | ||
| 511 | case ((Values.REAL(real = r1) :: rest1),(Values.REAL(real = r2) :: rest2)) | ||
| 512 | algorithm | ||
| 513 | ✗ | rres := r1 * r2; | |
| 514 | ✗ | res2 := mulElementwiseArrayelt(rest1, rest2); | |
| 515 | ✗ | then | |
| 516 | (Values.REAL(rres) :: res2); | ||
| 517 | case ({},{}) then {}; | ||
| 518 | end match; | ||
| 519 | end mulElementwiseArrayelt; | ||
| 520 | |||
| 521 | public function divElementwiseArrayelt " | ||
| 522 | Perform elementwise division of two arrays of values | ||
| 523 | " | ||
| 524 | input list<Values.Value> inValueLst1; | ||
| 525 | input list<Values.Value> inValueLst2; | ||
| 526 | output list<Values.Value> outValueLst; | ||
| 527 | algorithm | ||
| 528 | outValueLst:= | ||
| 529 | match (inValueLst1,inValueLst2) | ||
| 530 | local | ||
| 531 | list<Values.Value> reslst,res2,v1lst,rest1,v2lst,rest2; | ||
| 532 | Real res,r1,r2; | ||
| 533 | Integer i1,i2; | ||
| 534 | list<Integer> dims; | ||
| 535 | case ((Values.ARRAY(valueLst = v1lst, dimLst = dims) :: rest1),(Values.ARRAY(valueLst = v2lst) :: rest2)) | ||
| 536 | algorithm | ||
| 537 | ✗ | reslst := divElementwiseArrayelt(v1lst, v2lst); | |
| 538 | ✗ | res2 := divElementwiseArrayelt(rest1, rest2); | |
| 539 | ✗ | then | |
| 540 | (Values.ARRAY(reslst,dims) :: res2); | ||
| 541 | case ((Values.INTEGER(integer = i1) :: rest1),(Values.INTEGER(integer = i2) :: rest2)) | ||
| 542 | algorithm | ||
| 543 | ✗ | r1:=intReal(i1); | |
| 544 | ✗ | r2:=intReal(i2); | |
| 545 | ✗ | res := r1 / r2; | |
| 546 | ✗ | res2 := divElementwiseArrayelt(rest1, rest2); | |
| 547 | ✗ | then | |
| 548 | (Values.REAL(res) :: res2); | ||
| 549 | case ((Values.REAL(real = r1) :: rest1),(Values.REAL(real = r2) :: rest2)) | ||
| 550 | algorithm | ||
| 551 | ✗ | res := r1 / r2; | |
| 552 | ✗ | res2 := divElementwiseArrayelt(rest1, rest2); | |
| 553 | ✗ | then | |
| 554 | (Values.REAL(res) :: res2); | ||
| 555 | case ({},{}) then {}; | ||
| 556 | end match; | ||
| 557 | end divElementwiseArrayelt; | ||
| 558 | |||
| 559 | public function powElementwiseArrayelt " | ||
| 560 | Computes elementwise powers of two arrays of values | ||
| 561 | " | ||
| 562 | input list<Values.Value> inValueLst1; | ||
| 563 | input list<Values.Value> inValueLst2; | ||
| 564 | output list<Values.Value> outValueLst; | ||
| 565 | algorithm | ||
| 566 | outValueLst:= | ||
| 567 | match (inValueLst1,inValueLst2) | ||
| 568 | local | ||
| 569 | list<Values.Value> reslst,res2,v1lst,rest1,v2lst,rest2; | ||
| 570 | Integer i1,i2; | ||
| 571 | Real res,r1,r2; | ||
| 572 | list<Integer> dims; | ||
| 573 | case ((Values.ARRAY(valueLst = v1lst, dimLst = dims) :: rest1),(Values.ARRAY(valueLst = v2lst) :: rest2)) | ||
| 574 | algorithm | ||
| 575 | ✗ | reslst := powElementwiseArrayelt(v1lst, v2lst); | |
| 576 | ✗ | res2 := powElementwiseArrayelt(rest1, rest2); | |
| 577 | ✗ | then | |
| 578 | (Values.ARRAY(reslst,dims) :: res2); | ||
| 579 | case ((Values.INTEGER(integer = i1) :: rest1),(Values.INTEGER(integer = i2) :: rest2)) | ||
| 580 | algorithm | ||
| 581 | ✗ | r1:=intReal(i1); | |
| 582 | ✗ | r2:=intReal(i2); | |
| 583 | ✗ | res := r1 ^ r2; | |
| 584 | ✗ | res2 := powElementwiseArrayelt(rest1, rest2); | |
| 585 | ✗ | then | |
| 586 | (Values.REAL(res) :: res2); | ||
| 587 | case ((Values.REAL(real = r1) :: rest1),(Values.REAL(real = r2) :: rest2)) | ||
| 588 | algorithm | ||
| 589 | ✗ | res := r1 ^ r2; | |
| 590 | ✗ | res2 := powElementwiseArrayelt(rest1, rest2); | |
| 591 | ✗ | then | |
| 592 | (Values.REAL(res) :: res2); | ||
| 593 | case ({},{}) then {}; | ||
| 594 | end match; | ||
| 595 | end powElementwiseArrayelt; | ||
| 596 | |||
| 597 | public function absynExpValue | ||
| 598 | input Absyn.Exp exp; | ||
| 599 | output Values.Value value; | ||
| 600 | algorithm | ||
| 601 | value := match exp | ||
| 602 | 2 | case Absyn.Exp.INTEGER() then Values.Value.INTEGER(exp.value); | |
| 603 | ✗ | case Absyn.Exp.REAL() then Values.Value.REAL(stringReal(exp.value)); | |
| 604 | ✗ | case Absyn.Exp.CREF() then Values.Value.CODE(Absyn.CodeNode.C_VARIABLENAME(exp.componentRef)); | |
| 605 | 2 | case Absyn.Exp.STRING() then Values.Value.STRING(exp.value); | |
| 606 | ✗ | case Absyn.Exp.BOOL() then Values.Value.BOOL(exp.value); | |
| 607 | ✗ | case Absyn.Exp.ARRAY() then ValuesMake.makeArray(list(absynExpValue(e) for e in exp.arrayExp)); | |
| 608 | ✗ | case Absyn.Exp.TUPLE() then ValuesMake.makeTuple(list(absynExpValue(e) for e in exp.expressions)); | |
| 609 | ✗ | case Absyn.Exp.CODE() then Values.Value.CODE(exp.code); | |
| 610 | ✗ | else Values.Value.CODE(Absyn.CodeNode.C_EXPRESSION(exp)); | |
| 611 | end match; | ||
| 612 | end absynExpValue; | ||
| 613 | |||
| 614 | public function expValue "Returns the value of constant expressions in DAE.Exp" | ||
| 615 | input DAE.Exp inExp; | ||
| 616 | output Values.Value outValue; | ||
| 617 | algorithm | ||
| 618 | outValue := match inExp | ||
| 619 | local | ||
| 620 | Integer i; | ||
| 621 | Real r; | ||
| 622 | Boolean b; | ||
| 623 | String s; | ||
| 624 | 37791 | case DAE.ICONST(integer = i) then Values.INTEGER(i); | |
| 625 | 122019 | case DAE.RCONST(real = r) then Values.REAL(r); | |
| 626 | 276456 | case DAE.SCONST(string = s) then Values.STRING(s); | |
| 627 |
2/2✓ Branch 0 taken 1164 times.
✓ Branch 1 taken 774 times.
|
3102 | case DAE.BCONST(bool = b) then Values.BOOL(b); |
| 628 | end match; | ||
| 629 | end expValue; | ||
| 630 | |||
| 631 | public function valueExp "Transforms a Value into an Exp" | ||
| 632 | input Values.Value inValue; | ||
| 633 | input Option<DAE.Exp> originalExp = NONE(); | ||
| 634 | output DAE.Exp outExp; | ||
| 635 | algorithm | ||
| 636 | outExp := match inValue | ||
| 637 | local | ||
| 638 | list<DAE.Exp> explist; | ||
| 639 | DAE.Type vt; | ||
| 640 | DAE.Type t; | ||
| 641 | DAE.Exp e; | ||
| 642 | Values.Value v; | ||
| 643 | list<Values.Value> vallist; | ||
| 644 | list<DAE.Type> typelist; | ||
| 645 | list<Integer> int_dims; | ||
| 646 | Integer i; | ||
| 647 | Real r; | ||
| 648 | String s, scope, name, tyStr; | ||
| 649 | Boolean b; | ||
| 650 | list<DAE.Exp> expl; | ||
| 651 | list<DAE.Type> tpl; | ||
| 652 | list<String> namelst; | ||
| 653 | list<DAE.Var> varlst; | ||
| 654 | Integer ix; | ||
| 655 | Absyn.Path path; | ||
| 656 | Absyn.CodeNode code; | ||
| 657 | Values.Value valType; | ||
| 658 | DAE.Type ety; | ||
| 659 | |||
| 660 | 316013 | case Values.INTEGER(integer = i) then DAE.ICONST(i); | |
| 661 | 1512061 | case Values.REAL(real = r) then DAE.RCONST(r); | |
| 662 | 706700 | case Values.STRING(string = s) then DAE.SCONST(s); | |
| 663 |
2/2✓ Branch 0 taken 57126 times.
✓ Branch 1 taken 25790 times.
|
140042 | case Values.BOOL(boolean = b) then DAE.BCONST(b); |
| 664 | 16033 | case Values.ENUM_LITERAL(name = path, index = i) then DAE.ENUM_LITERAL(path, i); | |
| 665 | |||
| 666 | 317215 | case Values.ARRAY(valueLst = vallist, dimLst = int_dims) then valueExpArray(vallist,int_dims, originalExp); | |
| 667 | |||
| 668 | case Values.TUPLE(valueLst = vallist) | ||
| 669 | algorithm | ||
| 670 | 141 | explist := List.map(vallist, function valueExp(originalExp=NONE())); | |
| 671 | 141 | then | |
| 672 | DAE.TUPLE(explist); | ||
| 673 | |||
| 674 | case Values.RECORD(path,vallist,namelst,-1) | ||
| 675 | algorithm | ||
| 676 | 7132 | expl := List.map(vallist,function valueExp(originalExp=NONE())); | |
| 677 | 7132 | tpl := List.map(expl,Expression.typeof); | |
| 678 | 7132 | varlst := List.threadMap(namelst,tpl,Expression.makeVar); | |
| 679 | 7132 | t := DAE.T_COMPLEX(ClassInf.RECORD(path),varlst,NONE(), false); | |
| 680 | 7132 | then DAE.RECORD(path,expl,namelst,t); | |
| 681 | |||
| 682 | case Values.ENUM_LITERAL(name = path, index = ix) | ||
| 683 | ✗ | then DAE.ENUM_LITERAL(path, ix); | |
| 684 | |||
| 685 | case Values.TUPLE(vallist) | ||
| 686 | algorithm | ||
| 687 | ✗ | explist := List.map(vallist, function valueExp(originalExp=NONE())); | |
| 688 | ✗ | then DAE.TUPLE(explist); | |
| 689 | |||
| 690 | /* MetaModelica types */ | ||
| 691 | case Values.OPTION(SOME(v)) | ||
| 692 | algorithm | ||
| 693 | 870 | e := valueExp(v); | |
| 694 | 870 | (e,_) := Types.matchType(e, Types.typeOfValue(v), DAE.T_METABOXED_DEFAULT, true); | |
| 695 | 870 | then DAE.META_OPTION(SOME(e)); | |
| 696 | |||
| 697 | case Values.OPTION(NONE()) then DAE.META_OPTION(NONE()); | ||
| 698 | |||
| 699 | case Values.META_TUPLE(vallist) | ||
| 700 | algorithm | ||
| 701 | 19031 | explist := List.map(vallist, function valueExp(originalExp=NONE())); | |
| 702 | 19031 | typelist := List.map(vallist, Types.typeOfValue); | |
| 703 | 19031 | (explist,_) := Types.matchTypeTuple(explist, typelist, List.map(typelist, Types.boxIfUnboxedType), true); | |
| 704 | 19031 | then DAE.META_TUPLE(explist); | |
| 705 | |||
| 706 | case Values.LIST({}) then DAE.LIST({}); | ||
| 707 | |||
| 708 | case Values.LIST(vallist) | ||
| 709 | algorithm | ||
| 710 | 1465 | explist := List.map(vallist, function valueExp(originalExp=NONE())); | |
| 711 | 1465 | typelist := List.map(vallist, Types.typeOfValue); | |
| 712 | 1465 | vt := Types.boxIfUnboxedType(List.reduce(typelist,Types.superType)); | |
| 713 | 1465 | (explist,_) := Types.matchTypes(explist, typelist, vt, true); | |
| 714 | 1465 | then DAE.LIST(explist); | |
| 715 | |||
| 716 | case Values.META_ARRAY(vallist) | ||
| 717 | algorithm | ||
| 718 | ✗ | explist := List.map(vallist, function valueExp(originalExp=NONE())); | |
| 719 | ✗ | typelist := List.map(vallist, Types.typeOfValue); | |
| 720 | ✗ | vt := Types.boxIfUnboxedType(List.reduce(typelist,Types.superType)); | |
| 721 | ✗ | (explist,_) := Types.matchTypes(explist, typelist, vt, true); | |
| 722 | ✗ | then Expression.makeBuiltinCall("listArrayLiteral", {DAE.LIST(explist)}, DAE.T_METAARRAY(vt), false); | |
| 723 | |||
| 724 | /* MetaRecord */ | ||
| 725 | case Values.RECORD(path,vallist,namelst,ix) | ||
| 726 | algorithm | ||
| 727 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 60845 times.
|
60845 | true := ix >= 0; |
| 728 | 60845 | explist := List.map(vallist, function valueExp(originalExp=NONE())); | |
| 729 | 60845 | typelist := List.map(vallist, Types.typeOfValue); | |
| 730 | 60845 | (explist,_) := Types.matchTypeTuple(explist, typelist, List.map(typelist, Types.boxIfUnboxedType), true); | |
| 731 | 60845 | then DAE.METARECORDCALL(path,explist,namelst,ix,{}); | |
| 732 | |||
| 733 | case Values.META_FAIL() | ||
| 734 | then DAE.CALL(Absyn.IDENT("fail"),{},DAE.callAttrBuiltinOther); | ||
| 735 | |||
| 736 | case Values.META_BOX(v) | ||
| 737 | algorithm | ||
| 738 | ✗ | e := valueExp(v); | |
| 739 | ✗ | then DAE.BOX(e); | |
| 740 | |||
| 741 | case Values.CODE(A=code) | ||
| 742 | 950 | then DAE.CODE(code,DAE.T_UNKNOWN_DEFAULT); | |
| 743 | |||
| 744 | case Values.EMPTY(scope = scope, name = name, tyStr = tyStr, ty = valType) | ||
| 745 | algorithm | ||
| 746 |
3/4✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 3 times.
|
12 | if isSome(originalExp) then |
| 747 | 3 | SOME(e) := originalExp; | |
| 748 | else | ||
| 749 | 9 | ety := Types.simplifyType(Types.typeOfValue(valType)); | |
| 750 | 9 | e := DAE.EMPTY(scope, DAE.CREF_IDENT(name, ety, {}), ety, tyStr); | |
| 751 | end if; | ||
| 752 | then | ||
| 753 | e; | ||
| 754 | |||
| 755 | case Values.NORETCALL() | ||
| 756 | then DAE.TUPLE({}); | ||
| 757 | |||
| 758 | case v | ||
| 759 | algorithm | ||
| 760 | ✗ | s := "ValuesUtil.valueExp failed for " + ValuesDump.valString(v); | |
| 761 | ✗ | Error.addMessage(Error.INTERNAL_ERROR, {s}); | |
| 762 | ✗ | then | |
| 763 | fail(); | ||
| 764 | end match; | ||
| 765 | end valueExp; | ||
| 766 | |||
| 767 | public function valueExpNoOriginal "valueExp without an original expression; Susan cannot pass NONE()." | ||
| 768 | input Values.Value inValue; | ||
| 769 | output DAE.Exp outExp = valueExp(inValue); | ||
| 770 | end valueExpNoOriginal; | ||
| 771 | |||
| 772 | protected function valueExpArray | ||
| 773 | input list<Values.Value> values; | ||
| 774 | input list<Integer> inDims; | ||
| 775 | input Option<DAE.Exp> originalExp; | ||
| 776 | output DAE.Exp outExp; | ||
| 777 | algorithm | ||
| 778 | outExp := matchcontinue (values,inDims, originalExp) | ||
| 779 | local | ||
| 780 | Values.Value v; | ||
| 781 | list<Values.Value> xs,xs2; | ||
| 782 | list<DAE.Exp> explist, exps1; | ||
| 783 | DAE.Dimensions dims; | ||
| 784 | list<Integer> int_dims; | ||
| 785 | DAE.Type t,vt; | ||
| 786 | Integer dim; | ||
| 787 | Boolean b; | ||
| 788 | list<list<DAE.Exp>> mexpl; | ||
| 789 | case ({},{},_) then DAE.ARRAY(DAE.T_UNKNOWN_DEFAULT,false,{}); | ||
| 790 | case ({},_,_) | ||
| 791 | algorithm | ||
| 792 | 4300 | dims := List.map(inDims, Expression.intDimension); | |
| 793 | 4300 | then DAE.ARRAY(DAE.T_ARRAY(DAE.T_UNKNOWN_DEFAULT, dims),false,{}); | |
| 794 | |||
| 795 | // Matrix | ||
| 796 | case(Values.ARRAY(valueLst=v::xs)::xs2,dim::int_dims,_) | ||
| 797 | algorithm | ||
| 798 |
3/4✓ Branch 0 taken 26947 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26924 times.
✓ Branch 3 taken 23 times.
|
26947 | failure(Values.ARRAY() := v); |
| 799 | 26924 | explist := List.map((v :: xs), function valueExp(originalExp=NONE())); | |
| 800 |
2/2✓ Branch 2 taken 779 times.
✓ Branch 3 taken 26145 times.
|
26924 | DAE.MATRIX(t,_,mexpl) := valueExp(Values.ARRAY(xs2,int_dims)); |
| 801 | 26145 | t := Expression.arrayDimensionSetFirst(t, DAE.DIM_INTEGER(dim)); | |
| 802 | 26145 | then | |
| 803 | DAE.MATRIX(t,dim,explist::mexpl); | ||
| 804 | |||
| 805 | // Matrix last row | ||
| 806 | case({Values.ARRAY(valueLst=v::xs)},_,_) | ||
| 807 | algorithm | ||
| 808 |
3/4✓ Branch 0 taken 13185 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13176 times.
✓ Branch 3 taken 9 times.
|
13185 | failure(Values.ARRAY() := v); |
| 809 | 13176 | dim := listLength(v::xs); | |
| 810 | 13176 | explist := List.map((v :: xs), function valueExp(originalExp=NONE())); | |
| 811 | 13176 | vt := Types.typeOfValue(v); | |
| 812 | 13176 | t := Types.simplifyType(vt); | |
| 813 | 13176 | dim := listLength(v::xs); | |
| 814 | 13176 | t := Expression.liftArrayR(t,DAE.DIM_INTEGER(dim)); | |
| 815 | 13176 | t := Expression.liftArrayR(t,DAE.DIM_INTEGER(1)); | |
| 816 | 13176 | then | |
| 817 | DAE.MATRIX(t,dim,{explist}); | ||
| 818 | |||
| 819 | // Generic array and we have original exp | ||
| 820 | case (v :: xs,_, SOME(DAE.ARRAY(array=exps1))) | ||
| 821 | algorithm | ||
| 822 |
7/8✓ Branch 0 taken 313726 times.
✓ Branch 1 taken 70338 times.
✓ Branch 2 taken 313726 times.
✓ Branch 3 taken 70338 times.
✓ Branch 4 taken 313726 times.
✓ Branch 5 taken 70338 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 70338 times.
|
697790 | explist := list(valueExp(e1, SOME(e2)) threaded for e1 in values, e2 in exps1); |
| 823 | 70338 | vt := Types.typeOfValue(v); | |
| 824 | 70338 | t := Types.simplifyType(vt); | |
| 825 | 70338 | dim := listLength(v::xs); | |
| 826 | 70338 | t := Expression.liftArrayR(t,DAE.DIM_INTEGER(dim)); | |
| 827 | 70338 | b := Types.isArray(vt); | |
| 828 | b := boolNot(b); | ||
| 829 |
2/2✓ Branch 0 taken 130 times.
✓ Branch 1 taken 70208 times.
|
70468 | then DAE.ARRAY(t,b,explist); |
| 830 | |||
| 831 | case (v :: xs,_,_) | ||
| 832 | algorithm | ||
| 833 | 203149 | explist := List.map((v :: xs), function valueExp(originalExp=NONE())); | |
| 834 | 203149 | vt := Types.typeOfValue(v); | |
| 835 | 203149 | t := Types.simplifyType(vt); | |
| 836 | 203149 | dim := listLength(v::xs); | |
| 837 | 203149 | t := Expression.liftArrayR(t,DAE.DIM_INTEGER(dim)); | |
| 838 | 203149 | b := Types.isArray(vt); | |
| 839 | b := boolNot(b); | ||
| 840 |
2/2✓ Branch 0 taken 856 times.
✓ Branch 1 taken 202293 times.
|
204005 | then DAE.ARRAY(t,b,explist); |
| 841 | end matchcontinue; | ||
| 842 | end valueExpArray; | ||
| 843 | |||
| 844 | public function valueReal " | ||
| 845 | Return the real value of a Value. If the value is an integer, | ||
| 846 | it is cast to a real. | ||
| 847 | " | ||
| 848 | input Values.Value inValue; | ||
| 849 | output Real outReal; | ||
| 850 | algorithm | ||
| 851 | outReal:= match inValue | ||
| 852 | 17336 | case Values.REAL() then inValue.real; | |
| 853 | ✗ | case Values.INTEGER() then intReal(inValue.integer); | |
| 854 | end match; | ||
| 855 | end valueReal; | ||
| 856 | |||
| 857 | public function valueBool "Author: BZ, 2008-09 | ||
| 858 | Return the bool value of a Value. | ||
| 859 | " | ||
| 860 | input Values.Value inValue; | ||
| 861 | output Boolean outBool; | ||
| 862 | algorithm | ||
| 863 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1461 times.
|
1461 | Values.BOOL(boolean = outBool) := inValue; |
| 864 | end valueBool; | ||
| 865 | |||
| 866 | public function valueReals " | ||
| 867 | Return the real value of a Value. If the value is an integer, | ||
| 868 | it is cast to a real. | ||
| 869 | " | ||
| 870 | input list<Values.Value> inValue; | ||
| 871 | output list<Real> outReal; | ||
| 872 | algorithm | ||
| 873 | outReal:= | ||
| 874 | match inValue | ||
| 875 | local | ||
| 876 | Real r; | ||
| 877 | list<Values.Value> rest; | ||
| 878 | list<Real> res; | ||
| 879 | Integer i; | ||
| 880 | case {} then {}; | ||
| 881 | case Values.REAL(real = r)::rest | ||
| 882 | algorithm | ||
| 883 | 65 | res := valueReals(rest); | |
| 884 | 65 | then | |
| 885 | r::res; | ||
| 886 | case Values.INTEGER(integer = i)::rest | ||
| 887 | algorithm | ||
| 888 | ✗ | r := intReal(i); | |
| 889 | ✗ | res := valueReals(rest); | |
| 890 | ✗ | then | |
| 891 | r::res; | ||
| 892 | case _::rest | ||
| 893 | algorithm | ||
| 894 | ✗ | res := valueReals(rest); | |
| 895 | then | ||
| 896 | res; | ||
| 897 | end match; | ||
| 898 | end valueReals; | ||
| 899 | |||
| 900 | public function valueString | ||
| 901 | input Values.Value value; | ||
| 902 | output String str; | ||
| 903 | algorithm | ||
| 904 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | Values.Value.STRING(string = str) := value; |
| 905 | end valueString; | ||
| 906 | |||
| 907 | public function arrayValueInts | ||
| 908 | "Returns the integer values of a Values array." | ||
| 909 | input Values.Value inValue; | ||
| 910 | output list<Integer> outReal; | ||
| 911 | protected | ||
| 912 | list<Values.Value> vals; | ||
| 913 | algorithm | ||
| 914 | ✗ | Values.ARRAY(valueLst=vals) := inValue; | |
| 915 | ✗ | outReal := List.map(vals, valueInteger); | |
| 916 | end arrayValueInts; | ||
| 917 | |||
| 918 | public function arrayValueReals " | ||
| 919 | Return the real value of a Value. If the value is an integer, | ||
| 920 | it is cast to a real. | ||
| 921 | " | ||
| 922 | input Values.Value inValue; | ||
| 923 | output list<Real> outReal; | ||
| 924 | protected | ||
| 925 | list<Values.Value> vals; | ||
| 926 | algorithm | ||
| 927 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 12 times.
|
16 | Values.ARRAY(valueLst=vals) := inValue; |
| 928 | 12 | outReal := valueReals(vals); | |
| 929 | end arrayValueReals; | ||
| 930 | |||
| 931 | public function matrixValueReals | ||
| 932 | "Returns the real values of a Values matrix." | ||
| 933 | input Values.Value inValue; | ||
| 934 | output list<list<Real>> outReals; | ||
| 935 | algorithm | ||
| 936 | outReals := matchcontinue inValue | ||
| 937 | local | ||
| 938 | list<Values.Value> vals; | ||
| 939 | list<Real> reals; | ||
| 940 | |||
| 941 | // A matrix. | ||
| 942 | case Values.ARRAY(valueLst = vals) | ||
| 943 | 8 | then List.map(vals, arrayValueReals); | |
| 944 | |||
| 945 | // A 1-dimensional array. | ||
| 946 | case Values.ARRAY(valueLst = vals) | ||
| 947 | algorithm | ||
| 948 | 4 | reals := valueReals(vals); | |
| 949 | 4 | then | |
| 950 | List.map(reals, List.create); | ||
| 951 | |||
| 952 | end matchcontinue; | ||
| 953 | end matrixValueReals; | ||
| 954 | |||
| 955 | public function arrayValueStrings | ||
| 956 | input Values.Value value; | ||
| 957 | output list<String> strings; | ||
| 958 | algorithm | ||
| 959 |
4/4✓ Branch 1 taken 9 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 10 times.
|
19 | strings := list(valueString(v) for v in arrayValues(value)); |
| 960 | end arrayValueStrings; | ||
| 961 | |||
| 962 | public function valueNeg "author: PA | ||
| 963 | |||
| 964 | Negates a Value | ||
| 965 | " | ||
| 966 | input Values.Value inValue; | ||
| 967 | output Values.Value outValue; | ||
| 968 | algorithm | ||
| 969 | outValue:= | ||
| 970 | match inValue | ||
| 971 | local | ||
| 972 | Real r_1,r; | ||
| 973 | Integer i_1,i; | ||
| 974 | list<Values.Value> vlst_1,vlst; | ||
| 975 | list<Integer> dims; | ||
| 976 | case Values.REAL(real = r) | ||
| 977 | algorithm | ||
| 978 | 85688 | r_1 := - r; | |
| 979 | 85688 | then | |
| 980 | Values.REAL(r_1); | ||
| 981 | case Values.INTEGER(integer = i) | ||
| 982 | algorithm | ||
| 983 | 2862 | i_1 := -i; | |
| 984 | 2862 | then | |
| 985 | Values.INTEGER(i_1); | ||
| 986 | case Values.ARRAY(valueLst = vlst, dimLst = dims) | ||
| 987 | algorithm | ||
| 988 | ✗ | vlst_1 := List.map(vlst, valueNeg); | |
| 989 | ✗ | then | |
| 990 | Values.ARRAY(vlst_1,dims); | ||
| 991 | end match; | ||
| 992 | end valueNeg; | ||
| 993 | |||
| 994 | public function valueSum | ||
| 995 | "Calculates the sum of two scalar values." | ||
| 996 | input Values.Value value1; | ||
| 997 | input Values.Value value2; | ||
| 998 | output Values.Value result; | ||
| 999 | algorithm | ||
| 1000 | result := match (value1, value2) | ||
| 1001 | case (Values.INTEGER(), Values.INTEGER()) | ||
| 1002 | 16 | then Values.INTEGER(value1.integer + value2.integer); | |
| 1003 | case (Values.STRING(), Values.STRING()) | ||
| 1004 | ✗ | then Values.STRING(value1.string + value2.string); | |
| 1005 | 4 | else Values.REAL(valueReal(value1) + valueReal(value2)); | |
| 1006 | end match; | ||
| 1007 | end valueSum; | ||
| 1008 | |||
| 1009 | public function valueSubtract | ||
| 1010 | "Calculates the difference of two scalar values." | ||
| 1011 | input Values.Value value1; | ||
| 1012 | input Values.Value value2; | ||
| 1013 | output Values.Value result; | ||
| 1014 | algorithm | ||
| 1015 | result := match (value1, value2) | ||
| 1016 | case (Values.INTEGER(), Values.INTEGER()) | ||
| 1017 | ✗ | then Values.INTEGER(value1.integer - value2.integer); | |
| 1018 | 3 | else Values.REAL(valueReal(value1) - valueReal(value2)); | |
| 1019 | end match; | ||
| 1020 | end valueSubtract; | ||
| 1021 | |||
| 1022 | public function valueMultiply | ||
| 1023 | "Calculates the product of two scalar values." | ||
| 1024 | input Values.Value value1; | ||
| 1025 | input Values.Value value2; | ||
| 1026 | output Values.Value result; | ||
| 1027 | algorithm | ||
| 1028 | result := match (value1, value2) | ||
| 1029 | case (Values.INTEGER(), Values.INTEGER()) | ||
| 1030 | ✗ | then Values.INTEGER(value1.integer * value2.integer); | |
| 1031 | 1359 | else Values.REAL(valueReal(value1) * valueReal(value2)); | |
| 1032 | end match; | ||
| 1033 | end valueMultiply; | ||
| 1034 | |||
| 1035 | public function valueDivide | ||
| 1036 | "Calculates the quotient of two scalar values." | ||
| 1037 | input Values.Value value1; | ||
| 1038 | input Values.Value value2; | ||
| 1039 | output Values.Value result; | ||
| 1040 | algorithm | ||
| 1041 | result := match value2 | ||
| 1042 | case Values.INTEGER(integer = 0) | ||
| 1043 | algorithm | ||
| 1044 | ✗ | Error.addMessage(Error.DIVISION_BY_ZERO, {"0", intString(value2.integer)}); | |
| 1045 | ✗ | then | |
| 1046 | fail(); | ||
| 1047 | |||
| 1048 | case Values.REAL(real = 0.0) | ||
| 1049 | algorithm | ||
| 1050 | ✗ | Error.addMessage(Error.DIVISION_BY_ZERO, {"0", realString(value2.real)}); | |
| 1051 | ✗ | then | |
| 1052 | fail(); | ||
| 1053 | |||
| 1054 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3750 times.
|
3750 | else Values.REAL(valueReal(value1) / valueReal(value2)); |
| 1055 | end match; | ||
| 1056 | end valueDivide; | ||
| 1057 | |||
| 1058 | public function valuePow | ||
| 1059 | "Calculates the power of two scalar values." | ||
| 1060 | input Values.Value value1; | ||
| 1061 | input Values.Value value2; | ||
| 1062 | output Values.Value result; | ||
| 1063 | algorithm | ||
| 1064 | ✗ | result := Values.REAL(valueReal(value1) ^ valueReal(value2)); | |
| 1065 | end valuePow; | ||
| 1066 | |||
| 1067 | public function sumArray | ||
| 1068 | input Values.Value value; | ||
| 1069 | output Values.Value result; | ||
| 1070 | algorithm | ||
| 1071 | result := match value | ||
| 1072 | 4 | case Values.ARRAY() then sumArrayelt(value.valueLst); | |
| 1073 | else value; | ||
| 1074 | end match; | ||
| 1075 | end sumArray; | ||
| 1076 | |||
| 1077 | public function sumArrayelt | ||
| 1078 | "Calculate the sum of a list of Values." | ||
| 1079 | input list<Values.Value> values; | ||
| 1080 | output Values.Value result; | ||
| 1081 | algorithm | ||
| 1082 | 10 | result := sumArray(listHead(values)); | |
| 1083 | |||
| 1084 |
2/2✓ Branch 1 taken 20 times.
✓ Branch 2 taken 10 times.
|
30 | for v in listRest(values) loop |
| 1085 | 20 | result := valueSum(sumArray(v), result); | |
| 1086 | end for; | ||
| 1087 | end sumArrayelt; | ||
| 1088 | |||
| 1089 | public function multScalarArrayelt | ||
| 1090 | "Multiply a scalar with an list of Values, i.e. array." | ||
| 1091 | input Values.Value scalarValue; | ||
| 1092 | input list<Values.Value> arrayValues; | ||
| 1093 | output list<Values.Value> result; | ||
| 1094 | algorithm | ||
| 1095 |
4/4✓ Branch 0 taken 1359 times.
✓ Branch 1 taken 453 times.
✓ Branch 2 taken 1359 times.
✓ Branch 3 taken 453 times.
|
1812 | result := list( |
| 1096 | match v | ||
| 1097 | case Values.ARRAY() | ||
| 1098 | ✗ | then Values.ARRAY(multScalarArrayelt(scalarValue, v.valueLst), v.dimLst); | |
| 1099 | 1359 | else valueMultiply(scalarValue, v); | |
| 1100 | end match | ||
| 1101 | for v in arrayValues); | ||
| 1102 | end multScalarArrayelt; | ||
| 1103 | |||
| 1104 | public function addScalarArrayelt | ||
| 1105 | "Adds a scalar to an list of Values, i.e. array." | ||
| 1106 | input Values.Value scalarValue; | ||
| 1107 | input list<Values.Value> arrayValues; | ||
| 1108 | output list<Values.Value> result; | ||
| 1109 | algorithm | ||
| 1110 | ✗ | result := list( | |
| 1111 | match v | ||
| 1112 | case Values.ARRAY() | ||
| 1113 | ✗ | then Values.ARRAY(addScalarArrayelt(scalarValue, v.valueLst), v.dimLst); | |
| 1114 | ✗ | else valueSum(scalarValue, v); | |
| 1115 | end match | ||
| 1116 | for v in arrayValues); | ||
| 1117 | end addScalarArrayelt; | ||
| 1118 | |||
| 1119 | public function subScalarArrayelt | ||
| 1120 | "Subtracts a list of Values, i.e. array, from a scalar." | ||
| 1121 | input Values.Value scalarValue; | ||
| 1122 | input list<Values.Value> arrayValues; | ||
| 1123 | output list<Values.Value> result; | ||
| 1124 | algorithm | ||
| 1125 |
4/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 time.
|
4 | result := list( |
| 1126 | match v | ||
| 1127 | case Values.ARRAY() | ||
| 1128 | ✗ | then Values.ARRAY(subScalarArrayelt(scalarValue, v.valueLst), v.dimLst); | |
| 1129 | 3 | else valueSubtract(scalarValue, v); | |
| 1130 | end match | ||
| 1131 | for v in arrayValues); | ||
| 1132 | end subScalarArrayelt; | ||
| 1133 | |||
| 1134 | public function subArrayeltScalar | ||
| 1135 | "Subtracts a scalar from a list of Values, i.e. array." | ||
| 1136 | input Values.Value scalarValue; | ||
| 1137 | input list<Values.Value> arrayValues; | ||
| 1138 | output list<Values.Value> result; | ||
| 1139 | algorithm | ||
| 1140 | ✗ | result := list( | |
| 1141 | match v | ||
| 1142 | case Values.ARRAY() | ||
| 1143 | ✗ | then Values.ARRAY(subArrayeltScalar(scalarValue, v.valueLst), v.dimLst); | |
| 1144 | ✗ | else valueSubtract(v, scalarValue); | |
| 1145 | end match | ||
| 1146 | for v in arrayValues); | ||
| 1147 | end subArrayeltScalar; | ||
| 1148 | |||
| 1149 | public function divScalarArrayelt | ||
| 1150 | "Divides a scalar with a list of Values, i.e. array." | ||
| 1151 | input Values.Value scalarValue; | ||
| 1152 | input list<Values.Value> arrayValues; | ||
| 1153 | output list<Values.Value> result; | ||
| 1154 | algorithm | ||
| 1155 | ✗ | result := list( | |
| 1156 | match v | ||
| 1157 | case Values.ARRAY() | ||
| 1158 | ✗ | then Values.ARRAY(divScalarArrayelt(scalarValue, v.valueLst), v.dimLst); | |
| 1159 | ✗ | else valueDivide(scalarValue, v); | |
| 1160 | end match | ||
| 1161 | for v in arrayValues); | ||
| 1162 | end divScalarArrayelt; | ||
| 1163 | |||
| 1164 | public function divArrayeltScalar | ||
| 1165 | "Divides each array element with a scalar." | ||
| 1166 | input Values.Value scalarValue; | ||
| 1167 | input list<Values.Value> arrayValues; | ||
| 1168 | output list<Values.Value> result; | ||
| 1169 | algorithm | ||
| 1170 |
4/4✓ Branch 0 taken 3750 times.
✓ Branch 1 taken 1250 times.
✓ Branch 2 taken 3750 times.
✓ Branch 3 taken 1250 times.
|
5000 | result := list( |
| 1171 | match v | ||
| 1172 | case Values.ARRAY() | ||
| 1173 | ✗ | then Values.ARRAY(divArrayeltScalar(scalarValue, v.valueLst), v.dimLst); | |
| 1174 | 3750 | else valueDivide(v, scalarValue); | |
| 1175 | end match | ||
| 1176 | for v in arrayValues); | ||
| 1177 | end divArrayeltScalar; | ||
| 1178 | |||
| 1179 | public function powScalarArrayelt | ||
| 1180 | "Takes a power of a scalar with a list of Values, i.e. array." | ||
| 1181 | input Values.Value scalarValue; | ||
| 1182 | input list<Values.Value> arrayValues; | ||
| 1183 | output list<Values.Value> result; | ||
| 1184 | algorithm | ||
| 1185 | ✗ | result := list( | |
| 1186 | match v | ||
| 1187 | case Values.ARRAY() | ||
| 1188 | ✗ | then Values.ARRAY(powScalarArrayelt(scalarValue, v.valueLst), v.dimLst); | |
| 1189 | ✗ | else valuePow(scalarValue, v); | |
| 1190 | end match | ||
| 1191 | for v in arrayValues); | ||
| 1192 | end powScalarArrayelt; | ||
| 1193 | |||
| 1194 | public function powArrayeltScalar | ||
| 1195 | "Takes a power of a scalar with a list of Values, i.e. array." | ||
| 1196 | input Values.Value scalarValue; | ||
| 1197 | input list<Values.Value> arrayValues; | ||
| 1198 | output list<Values.Value> result; | ||
| 1199 | algorithm | ||
| 1200 | ✗ | result := list( | |
| 1201 | match v | ||
| 1202 | case Values.ARRAY() | ||
| 1203 | ✗ | then Values.ARRAY(powArrayeltScalar(scalarValue, v.valueLst), v.dimLst); | |
| 1204 | ✗ | else valuePow(scalarValue, v); | |
| 1205 | end match | ||
| 1206 | for v in arrayValues); | ||
| 1207 | end powArrayeltScalar; | ||
| 1208 | |||
| 1209 | public function multScalarProduct " | ||
| 1210 | Calculate the scalar product of two vectors / arrays. | ||
| 1211 | " | ||
| 1212 | input list<Values.Value> inValueLst1; | ||
| 1213 | input list<Values.Value> inValueLst2; | ||
| 1214 | output Values.Value outValue; | ||
| 1215 | algorithm | ||
| 1216 | outValue:= | ||
| 1217 | matchcontinue (inValueLst1,inValueLst2) | ||
| 1218 | local | ||
| 1219 | Integer i1,i2,res,v1,v2,dim; | ||
| 1220 | list<Values.Value> v1lst,v2lst,vres,rest,vlst,col,mat_1,vals,mat; | ||
| 1221 | Values.Value sres,v; | ||
| 1222 | list<Integer> dims; | ||
| 1223 | Real r1,r2,rres; | ||
| 1224 | case ((Values.INTEGER(integer = i1) :: (v1lst as (_ :: _))),(Values.INTEGER(integer = i2) :: (v2lst as (_ :: _)))) | ||
| 1225 | algorithm | ||
| 1226 | ✗ | i1 := i1*i2; | |
| 1227 | ✗ | Values.INTEGER(i2) := multScalarProduct(v1lst, v2lst); | |
| 1228 | ✗ | res := i1 + i2; | |
| 1229 | ✗ | then | |
| 1230 | Values.INTEGER(res); | ||
| 1231 | case ({Values.INTEGER(integer = v1)},{Values.INTEGER(integer = v2)}) | ||
| 1232 | algorithm | ||
| 1233 | ✗ | res := v1*v2; | |
| 1234 | ✗ | then | |
| 1235 | Values.INTEGER(res); | ||
| 1236 | case ((Values.REAL(real = r1) :: (v1lst as (_ :: _))),(Values.REAL(real = r2) :: (v2lst as (_ :: _)))) | ||
| 1237 | algorithm | ||
| 1238 | 19795 | r1 := r1 * r2; | |
| 1239 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 19795 times.
|
19795 | Values.REAL(r2) := multScalarProduct(v1lst, v2lst); |
| 1240 | 19795 | rres := r1 + r2; | |
| 1241 | 19795 | then | |
| 1242 | Values.REAL(rres); | ||
| 1243 | case ({Values.REAL(real = r1)},{Values.REAL(real = r2)}) | ||
| 1244 | algorithm | ||
| 1245 | 9896 | rres := r1 * r2; | |
| 1246 | 9896 | then | |
| 1247 | Values.REAL(rres); | ||
| 1248 | case ((Values.ARRAY(valueLst = v2lst) :: rest),(vlst as (Values.INTEGER() :: _))) | ||
| 1249 | algorithm | ||
| 1250 | ✗ | sres := multScalarProduct(v2lst, vlst); | |
| 1251 | ✗ | Values.ARRAY(vres,dim::dims) := multScalarProduct(rest, vlst); | |
| 1252 | ✗ | dim := dim+1; | |
| 1253 | ✗ | then | |
| 1254 | Values.ARRAY(sres :: vres, dim::dims); | ||
| 1255 | ✗ | case ({},(Values.INTEGER() :: _)) then ValuesMake.makeArray({}); | |
| 1256 | case ((Values.ARRAY(valueLst = v2lst) :: rest),(vlst as (Values.REAL() :: _))) | ||
| 1257 | algorithm | ||
| 1258 | ✗ | sres := multScalarProduct(v2lst, vlst); | |
| 1259 | ✗ | Values.ARRAY(vres,dim::dims) := multScalarProduct(rest, vlst); | |
| 1260 | ✗ | dim := dim+1; | |
| 1261 | ✗ | then | |
| 1262 | Values.ARRAY(sres :: vres,dim::dims); | ||
| 1263 | ✗ | case ({},(Values.REAL() :: _)) then ValuesMake.makeArray({}); | |
| 1264 | case ((vlst as (Values.INTEGER() :: _)),(mat as (Values.ARRAY(valueLst = (_ :: (_ :: _))) :: _))) | ||
| 1265 | algorithm | ||
| 1266 | ✗ | (Values.ARRAY(valueLst = col),mat_1) := matrixStripFirstColumn(mat); | |
| 1267 | ✗ | v := multScalarProduct(vlst, col); | |
| 1268 | ✗ | Values.ARRAY(vals,dim::dims) := multScalarProduct(vlst, mat_1); | |
| 1269 | ✗ | then | |
| 1270 | Values.ARRAY(v :: vals, dim::dims); | ||
| 1271 | case ((vlst as (Values.INTEGER() :: _)),(mat as (Values.ARRAY(valueLst = {_}) :: _))) | ||
| 1272 | algorithm | ||
| 1273 | ✗ | (Values.ARRAY(valueLst = col),_) := matrixStripFirstColumn(mat); | |
| 1274 | ✗ | Values.INTEGER(i1) := multScalarProduct(vlst, col); | |
| 1275 | ✗ | then | |
| 1276 | ValuesMake.makeArray({Values.INTEGER(i1)}); | ||
| 1277 | case ((vlst as (Values.REAL() :: _)),(mat as (Values.ARRAY(valueLst = (_ :: (_ :: _))) :: _))) | ||
| 1278 | algorithm | ||
| 1279 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4500 times.
|
4500 | (Values.ARRAY(valueLst = col),mat_1) := matrixStripFirstColumn(mat); |
| 1280 | 4500 | v := multScalarProduct(vlst, col); | |
| 1281 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 4500 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4500 times.
|
4500 | Values.ARRAY(valueLst = vals, dimLst = dim::dims) := multScalarProduct(vlst, mat_1); |
| 1282 | 4500 | dim := dim+1; | |
| 1283 | 4500 | then | |
| 1284 | Values.ARRAY(v :: vals, dim::dims); | ||
| 1285 | case ((vlst as (Values.REAL() :: _)),(mat as (Values.ARRAY(valueLst = {_}) :: _))) | ||
| 1286 | algorithm | ||
| 1287 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2250 times.
|
2250 | (Values.ARRAY(valueLst = col),_) := matrixStripFirstColumn(mat); |
| 1288 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2250 times.
|
2250 | Values.REAL(r1) := multScalarProduct(vlst, col); |
| 1289 | 4500 | then | |
| 1290 | ValuesMake.makeArray({Values.REAL(r1)}); | ||
| 1291 | else | ||
| 1292 | algorithm | ||
| 1293 | ✗ | true := Flags.isSet(Flags.FAILTRACE); | |
| 1294 | ✗ | Debug.trace("Values.multScalarProduct failed\n"); | |
| 1295 | ✗ | then | |
| 1296 | fail(); | ||
| 1297 | end matchcontinue; | ||
| 1298 | end multScalarProduct; | ||
| 1299 | |||
| 1300 | public function crossProduct " | ||
| 1301 | Calculate the cross product of two vectors. | ||
| 1302 | x,y => {x[2]*y[3]-x[3]*y[2],x[3]*y[1]-x[1]*y[3],x[1]*y[2]-x[2]*y[1]} | ||
| 1303 | " | ||
| 1304 | input list<Values.Value> inValueLst1; | ||
| 1305 | input list<Values.Value> inValueLst2; | ||
| 1306 | output Values.Value outValue; | ||
| 1307 | algorithm | ||
| 1308 | outValue := match(inValueLst1,inValueLst2) | ||
| 1309 | local | ||
| 1310 | Integer ix1,ix2,ix3,iy1,iy2,iy3,iz1,iz2,iz3; | ||
| 1311 | Real x1,x2,x3,y1,y2,y3,z1,z2,z3; | ||
| 1312 | case ({Values.REAL(x1),Values.REAL(x2),Values.REAL(x3)}, | ||
| 1313 | {Values.REAL(y1),Values.REAL(y2),Values.REAL(y3)}) | ||
| 1314 | algorithm | ||
| 1315 | 4 | z1 := realSub(realMul(x2,y3),realMul(x3,y2)); | |
| 1316 | 4 | z2 := realSub(realMul(x3,y1),realMul(x1,y3)); | |
| 1317 | 4 | z3 := realSub(realMul(x1,y2),realMul(x2,y1)); | |
| 1318 | 8 | then | |
| 1319 | ValuesMake.makeArray({Values.REAL(z1),Values.REAL(z2),Values.REAL(z3)}); | ||
| 1320 | case ({Values.INTEGER(ix1),Values.INTEGER(ix2),Values.INTEGER(ix3)}, | ||
| 1321 | {Values.INTEGER(iy1),Values.INTEGER(iy2),Values.INTEGER(iy3)}) | ||
| 1322 | algorithm | ||
| 1323 | ✗ | iz1 := intSub(intMul(ix2,iy3),intMul(ix3,iy2)); | |
| 1324 | ✗ | iz2 := intSub(intMul(ix3,iy1),intMul(ix1,iy3)); | |
| 1325 | ✗ | iz3 := intSub(intMul(ix1,iy2),intMul(ix2,iy1)); | |
| 1326 | ✗ | then | |
| 1327 | ValuesMake.makeArray({Values.INTEGER(iz1),Values.INTEGER(iz2),Values.INTEGER(iz3)}); | ||
| 1328 | else | ||
| 1329 | algorithm | ||
| 1330 | ✗ | Error.addMessage(Error.INTERNAL_ERROR, {"ValuesUtil.crossProduct failed"}); | |
| 1331 | ✗ | then | |
| 1332 | fail(); | ||
| 1333 | end match; | ||
| 1334 | end crossProduct; | ||
| 1335 | |||
| 1336 | public function multMatrix " | ||
| 1337 | Calculate a matrix multiplication of two matrices, i.e. two dimensional | ||
| 1338 | arrays. | ||
| 1339 | " | ||
| 1340 | input list<Values.Value> inValueLst1; | ||
| 1341 | input list<Values.Value> inValueLst2; | ||
| 1342 | output list<Values.Value> outValueLst; | ||
| 1343 | algorithm | ||
| 1344 | outValueLst:= | ||
| 1345 | match (inValueLst1,inValueLst2) | ||
| 1346 | local | ||
| 1347 | Values.Value res1; | ||
| 1348 | list<Values.Value> res2,v1lst,rest1,m2; | ||
| 1349 | case (((Values.ARRAY(valueLst = v1lst) :: rest1)),(m2 as (Values.ARRAY() :: _))) | ||
| 1350 | algorithm | ||
| 1351 | 2250 | res1 := multScalarProduct(v1lst, m2); | |
| 1352 | 2250 | res2 := multMatrix(rest1, m2); | |
| 1353 | then | ||
| 1354 | (res1 :: res2); | ||
| 1355 | case ({},_) then {}; | ||
| 1356 | end match; | ||
| 1357 | end multMatrix; | ||
| 1358 | |||
| 1359 | protected function matrixStripFirstColumn "This function takes a Value list representing a matrix and strips the | ||
| 1360 | first column of the matrix, i.e. for each sub list it removes the first | ||
| 1361 | element. Returning both the stripped column and the resulting matrix." | ||
| 1362 | input list<Values.Value> inValueLst; | ||
| 1363 | output Values.Value outValue; | ||
| 1364 | output list<Values.Value> outValueLst; | ||
| 1365 | algorithm | ||
| 1366 | (outValue,outValueLst) := match inValueLst | ||
| 1367 | local | ||
| 1368 | list<Values.Value> resl,resl2,vrest,rest; | ||
| 1369 | Values.Value v1; | ||
| 1370 | Integer i; | ||
| 1371 | Integer dim; | ||
| 1372 | case Values.ARRAY(valueLst = (v1 :: vrest), dimLst = {dim}) :: rest | ||
| 1373 | algorithm | ||
| 1374 |
3/6✗ Branch 1 not taken.
✓ Branch 2 taken 20250 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 20250 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 20250 times.
|
20250 | (Values.ARRAY(resl,{i}),resl2) := matrixStripFirstColumn(rest); |
| 1375 | 20250 | i := i+1; | |
| 1376 | 20250 | dim := dim - 1; | |
| 1377 | 40500 | then | |
| 1378 | (Values.ARRAY((v1 :: resl),{i}),(Values.ARRAY(vrest,{dim}) :: resl2)); | ||
| 1379 | |||
| 1380 | case {} then (Values.ARRAY({},{0}),{}); | ||
| 1381 | end match; | ||
| 1382 | end matrixStripFirstColumn; | ||
| 1383 | |||
| 1384 | public function intlistToValue " | ||
| 1385 | Takes a list of integers and builds a Value from it, i.e. an | ||
| 1386 | array of integers. | ||
| 1387 | " | ||
| 1388 | input list<Integer> inIntegerLst; | ||
| 1389 | output Values.Value outValue; | ||
| 1390 | algorithm | ||
| 1391 | outValue:= | ||
| 1392 | match inIntegerLst | ||
| 1393 | local | ||
| 1394 | list<Values.Value> res; | ||
| 1395 | Integer i,len; | ||
| 1396 | list<Integer> lst; | ||
| 1397 | case {} then Values.ARRAY({},{0}); | ||
| 1398 | case i :: lst | ||
| 1399 | algorithm | ||
| 1400 | ✗ | Values.ARRAY(res,{len}) := intlistToValue(lst); | |
| 1401 | ✗ | len := len+1; | |
| 1402 | ✗ | then | |
| 1403 | Values.ARRAY((Values.INTEGER(i) :: res),{len}); | ||
| 1404 | end match; | ||
| 1405 | end intlistToValue; | ||
| 1406 | |||
| 1407 | public function arrayValues " | ||
| 1408 | Return the values of an array. | ||
| 1409 | " | ||
| 1410 | input Values.Value inValue; | ||
| 1411 | output list<Values.Value> outValueLst; | ||
| 1412 | algorithm | ||
| 1413 | outValueLst:= | ||
| 1414 | match inValue | ||
| 1415 | local list<Values.Value> v_lst; | ||
| 1416 | case Values.ARRAY(valueLst = v_lst) then v_lst; | ||
| 1417 | end match; | ||
| 1418 | end arrayValues; | ||
| 1419 | |||
| 1420 | public function arrayScalar | ||
| 1421 | "If an array contains only one value, returns that value. Otherwise fails." | ||
| 1422 | input Values.Value inValue; | ||
| 1423 | output Values.Value outValue; | ||
| 1424 | algorithm | ||
| 1425 |
3/6✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 14 times.
|
14 | Values.ARRAY(valueLst = {outValue}) := inValue; |
| 1426 | end arrayScalar; | ||
| 1427 | |||
| 1428 | public function writePtolemyplotDataset " | ||
| 1429 | This function writes a data set in the pltolemy plot format to a file. | ||
| 1430 | The first column of the dataset matrix should be the time variable. | ||
| 1431 | The message string will be displayed in the plot window of ptplot. | ||
| 1432 | " | ||
| 1433 | input String inString1; | ||
| 1434 | input Values.Value inValue2; | ||
| 1435 | input list<String> inStringLst3; | ||
| 1436 | input String inString4; | ||
| 1437 | output Integer outInteger; | ||
| 1438 | algorithm | ||
| 1439 | outInteger:= | ||
| 1440 | match (inString1,inValue2,inStringLst3,inString4) | ||
| 1441 | local | ||
| 1442 | String str,filename,message; | ||
| 1443 | Values.Value t; | ||
| 1444 | list<Values.Value> rest; | ||
| 1445 | list<String> varnames; | ||
| 1446 | Integer handle; | ||
| 1447 | |||
| 1448 | case (filename,Values.ARRAY(valueLst = (t :: rest)),(_ :: varnames),message) /* filename values Variable names message string */ | ||
| 1449 | algorithm | ||
| 1450 | ✗ | handle := Print.saveAndClearBuf(); | |
| 1451 | |||
| 1452 | ✗ | Print.printBuf("#Ptolemy Plot generated by OpenModelica\nTitleText: "); | |
| 1453 | ✗ | Print.printBuf(message); | |
| 1454 | ✗ | Print.printBuf("\n"); | |
| 1455 | ✗ | unparsePtolemyValues(t, rest, varnames); | |
| 1456 | |||
| 1457 | ✗ | str := Print.getString(); | |
| 1458 | ✗ | Print.restoreBuf(handle); | |
| 1459 | |||
| 1460 | ✗ | System.writeFile(filename, str); | |
| 1461 | then | ||
| 1462 | 0; | ||
| 1463 | end match; | ||
| 1464 | end writePtolemyplotDataset; | ||
| 1465 | |||
| 1466 | protected function unparsePtolemyValues "Helper function to writePtolemyplotDataset." | ||
| 1467 | input Values.Value inValue; | ||
| 1468 | input list<Values.Value> inValueLst; | ||
| 1469 | input list<String> inStringLst; | ||
| 1470 | algorithm | ||
| 1471 | () := match (inValue,inValueLst,inStringLst) | ||
| 1472 | local | ||
| 1473 | String v1; | ||
| 1474 | Values.Value t,s1; | ||
| 1475 | list<Values.Value> xs; | ||
| 1476 | list<String> vs; | ||
| 1477 | |||
| 1478 | case (_,{},_) then (); | ||
| 1479 | case (t,(s1 :: xs),(v1 :: vs)) | ||
| 1480 | algorithm | ||
| 1481 | ✗ | unparsePtolemySet(t, s1, v1); | |
| 1482 | ✗ | unparsePtolemyValues(t, xs, vs); | |
| 1483 | then | ||
| 1484 | (); | ||
| 1485 | end match; | ||
| 1486 | end unparsePtolemyValues; | ||
| 1487 | |||
| 1488 | protected function unparsePtolemySet "Helper function to unparsePtolemyValues." | ||
| 1489 | input Values.Value v1; | ||
| 1490 | input Values.Value v2; | ||
| 1491 | input String varname; | ||
| 1492 | algorithm | ||
| 1493 | ✗ | Print.printBuf(stringAppendList({"DataSet: ",varname,"\n"})); | |
| 1494 | ✗ | unparsePtolemySet2(v1, v2); | |
| 1495 | end unparsePtolemySet; | ||
| 1496 | |||
| 1497 | protected function unparsePtolemySet2 "Helper function to unparsePtolemySet" | ||
| 1498 | input Values.Value inValue1; | ||
| 1499 | input Values.Value inValue2; | ||
| 1500 | algorithm | ||
| 1501 | () := matchcontinue (inValue1,inValue2) | ||
| 1502 | local | ||
| 1503 | Values.Value v1,v2; | ||
| 1504 | list<Values.Value> v1s,v2s; | ||
| 1505 | |||
| 1506 | case (Values.ARRAY(valueLst = {}),Values.ARRAY(valueLst = {})) then (); | ||
| 1507 | // adrpo: ignore dimenstions here as we're just printing! otherwise it fails. | ||
| 1508 | // TODO! FIXME! see why the dimension list is wrong! | ||
| 1509 | case (Values.ARRAY(valueLst = (v1 :: v1s)),Values.ARRAY(valueLst = (v2 :: v2s))) | ||
| 1510 | algorithm | ||
| 1511 | ✗ | ValuesDump.valString2(v1); | |
| 1512 | ✗ | Print.printBuf(","); | |
| 1513 | ✗ | ValuesDump.valString2(v2); | |
| 1514 | ✗ | Print.printBuf("\n"); | |
| 1515 | ✗ | unparsePtolemySet2(Values.ARRAY(v1s,{}), Values.ARRAY(v2s,{})); | |
| 1516 | then | ||
| 1517 | (); | ||
| 1518 | case (v1, _) | ||
| 1519 | algorithm | ||
| 1520 | ✗ | true := Flags.isSet(Flags.FAILTRACE); | |
| 1521 | ✗ | Debug.traceln("- ValuesUtil.unparsePtolemySet2 failed on v1: " + | |
| 1522 | ValuesDump.printValStr(v1) + " and v2: " + ValuesDump.printValStr(v1)); | ||
| 1523 | ✗ | then | |
| 1524 | fail(); | ||
| 1525 | end matchcontinue; | ||
| 1526 | end unparsePtolemySet2; | ||
| 1527 | |||
| 1528 | public function reverseMatrix "Reverses each line and each row of a matrix. | ||
| 1529 | Implementation reverses all dimensions..." | ||
| 1530 | input Values.Value inValue; | ||
| 1531 | output Values.Value outValue; | ||
| 1532 | algorithm | ||
| 1533 | outValue := matchcontinue inValue | ||
| 1534 | local | ||
| 1535 | list<Values.Value> lst_1,lst_2,lst; | ||
| 1536 | Values.Value value; | ||
| 1537 | list<Integer> dims; | ||
| 1538 | case Values.ARRAY(valueLst = lst, dimLst = dims) | ||
| 1539 | algorithm | ||
| 1540 | ✗ | lst_1 := List.map(lst, reverseMatrix); | |
| 1541 | ✗ | lst_2 := listReverse(lst_1); | |
| 1542 | ✗ | then | |
| 1543 | Values.ARRAY(lst_2,dims); | ||
| 1544 | case value then value; | ||
| 1545 | end matchcontinue; | ||
| 1546 | end reverseMatrix; | ||
| 1547 | |||
| 1548 | public function nthnthArrayelt "author: BZ | ||
| 1549 | |||
| 1550 | Return the nth nth....nth value of an array, indexed from 1..n | ||
| 1551 | " | ||
| 1552 | input list<Values.Value> inLst; | ||
| 1553 | input Values.Value inValue; | ||
| 1554 | input Values.Value lastValue; | ||
| 1555 | output Values.Value outValue; | ||
| 1556 | algorithm | ||
| 1557 | outValue:= | ||
| 1558 | match (inLst, inValue,lastValue) | ||
| 1559 | local | ||
| 1560 | Boolean b; | ||
| 1561 | Integer n; | ||
| 1562 | Values.Value res,preRes; | ||
| 1563 | list<Values.Value> vlst,vlst2; | ||
| 1564 | |||
| 1565 | case({},_, preRes) then preRes; | ||
| 1566 | case (((Values.INTEGER(integer=n))::vlst2),Values.ARRAY(valueLst = vlst),_) | ||
| 1567 | algorithm | ||
| 1568 | 390 | res := listGet(vlst, n); | |
| 1569 | 390 | res := nthnthArrayelt(vlst2,res,res); | |
| 1570 | then res; | ||
| 1571 | case (((Values.ENUM_LITERAL(index=n))::vlst2),Values.ARRAY(valueLst = vlst),_) | ||
| 1572 | algorithm | ||
| 1573 | ✗ | res := listGet(vlst, n); | |
| 1574 | ✗ | res := nthnthArrayelt(vlst2,res,res); | |
| 1575 | then res; | ||
| 1576 | case (((Values.BOOL(boolean=b))::vlst2),Values.ARRAY(valueLst = vlst),_) | ||
| 1577 | algorithm | ||
| 1578 | ✗ | res := listGet(vlst, if b then 2 else 1); | |
| 1579 | ✗ | res := nthnthArrayelt(vlst2,res,res); | |
| 1580 | then res; | ||
| 1581 | end match; | ||
| 1582 | end nthnthArrayelt; | ||
| 1583 | |||
| 1584 | public function valueInteger | ||
| 1585 | "Converts a value to an Integer, or fails if that is not possible." | ||
| 1586 | input Values.Value inValue; | ||
| 1587 | output Integer outInteger; | ||
| 1588 | algorithm | ||
| 1589 | outInteger := match inValue | ||
| 1590 | local | ||
| 1591 | Integer i; | ||
| 1592 | case Values.INTEGER(integer = i) then i; | ||
| 1593 | case Values.ENUM_LITERAL(index = i) then i; | ||
| 1594 | case Values.BOOL(boolean = true) then 1; | ||
| 1595 | case Values.BOOL(boolean = false) then 0; | ||
| 1596 | end match; | ||
| 1597 | end valueInteger; | ||
| 1598 | |||
| 1599 | public function valueDimensions | ||
| 1600 | "Returns the dimensions of a value." | ||
| 1601 | input Values.Value inValue; | ||
| 1602 | output list<Integer> outDimensions; | ||
| 1603 | algorithm | ||
| 1604 | outDimensions := match inValue | ||
| 1605 | local | ||
| 1606 | list<Integer> dims; | ||
| 1607 | case Values.ARRAY(dimLst = dims) then dims; | ||
| 1608 | else {}; | ||
| 1609 | end match; | ||
| 1610 | end valueDimensions; | ||
| 1611 | |||
| 1612 | public function extractValueString | ||
| 1613 | input Values.Value val; | ||
| 1614 | output String str; | ||
| 1615 | algorithm | ||
| 1616 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3583 times.
|
3583 | Values.STRING(str) := val; |
| 1617 | end extractValueString; | ||
| 1618 | |||
| 1619 | public function getCode | ||
| 1620 | input Values.Value val; | ||
| 1621 | output Absyn.CodeNode code; | ||
| 1622 | algorithm | ||
| 1623 | ✗ | Values.CODE(code) := val; | |
| 1624 | end getCode; | ||
| 1625 | |||
| 1626 | public function getPath | ||
| 1627 | input Values.Value val; | ||
| 1628 | output Absyn.Path path; | ||
| 1629 | protected | ||
| 1630 | Absyn.CodeNode code; | ||
| 1631 | algorithm | ||
| 1632 | ✗ | Values.CODE(code) := val; | |
| 1633 | ✗ | Absyn.C_TYPENAME(path) := code; | |
| 1634 | end getPath; | ||
| 1635 | |||
| 1636 | public function printCodeVariableName | ||
| 1637 | input Values.Value val; | ||
| 1638 | output String str; | ||
| 1639 | algorithm | ||
| 1640 | str := match val | ||
| 1641 | local | ||
| 1642 | Absyn.ComponentRef cr; | ||
| 1643 | Absyn.Exp exp; | ||
| 1644 | // der(x) | ||
| 1645 | 22 | case Values.CODE(Absyn.C_EXPRESSION(exp)) then Dump.printExpStr(exp); | |
| 1646 | // x | ||
| 1647 | case Values.CODE(Absyn.C_VARIABLENAME(cr)) | ||
| 1648 | 2668 | then Dump.printComponentRefStr(cr); | |
| 1649 | end match; | ||
| 1650 | end printCodeVariableName; | ||
| 1651 | |||
| 1652 | public function boxIfUnboxedVal | ||
| 1653 | input Values.Value v; | ||
| 1654 | output Values.Value ov; | ||
| 1655 | algorithm | ||
| 1656 | ov := match v | ||
| 1657 | ✗ | case Values.INTEGER(_) then Values.META_BOX(v); | |
| 1658 | 48 | case Values.REAL(_) then Values.META_BOX(v); | |
| 1659 | ✗ | case Values.BOOL(_) then Values.META_BOX(v); | |
| 1660 | else v; | ||
| 1661 | end match; | ||
| 1662 | end boxIfUnboxedVal; | ||
| 1663 | |||
| 1664 | public function unboxIfBoxedVal | ||
| 1665 | input Values.Value iv; | ||
| 1666 | output Values.Value ov; | ||
| 1667 | algorithm | ||
| 1668 | ov := match iv local Values.Value v; | ||
| 1669 | case Values.META_BOX(v) then v; | ||
| 1670 | else iv; | ||
| 1671 | end match; | ||
| 1672 | end unboxIfBoxedVal; | ||
| 1673 | |||
| 1674 | public function arrayOrListVals | ||
| 1675 | input Values.Value v; | ||
| 1676 | input Boolean boxIfUnboxed; | ||
| 1677 | output list<Values.Value> vals; | ||
| 1678 | algorithm | ||
| 1679 | vals := match (v,boxIfUnboxed) | ||
| 1680 | case (Values.ARRAY(valueLst = vals),_) then vals; | ||
| 1681 | 22 | case (Values.LIST(vals),true) then List.map(vals,boxIfUnboxedVal); | |
| 1682 | case (Values.LIST(vals),_) then vals; | ||
| 1683 | end match; | ||
| 1684 | end arrayOrListVals; | ||
| 1685 | |||
| 1686 | public function containsEmpty | ||
| 1687 | input Values.Value inValue; | ||
| 1688 | output Option<Values.Value> outEmptyVal; | ||
| 1689 | algorithm | ||
| 1690 | outEmptyVal := match inValue | ||
| 1691 | case Values.EMPTY() then SOME(inValue); | ||
| 1692 | ✗ | case Values.ARRAY() then arrayContainsEmpty(inValue.valueLst); | |
| 1693 | ✗ | case Values.RECORD() then arrayContainsEmpty(inValue.orderd); | |
| 1694 | ✗ | case Values.TUPLE() then arrayContainsEmpty(inValue.valueLst); | |
| 1695 | else NONE(); | ||
| 1696 | end match; | ||
| 1697 | end containsEmpty; | ||
| 1698 | |||
| 1699 | public function arrayContainsEmpty | ||
| 1700 | "Searches for an EMPTY value in a list, and returns SOME(value) if found, | ||
| 1701 | otherwise NONE()." | ||
| 1702 | input list<Values.Value> inValues; | ||
| 1703 | output Option<Values.Value> outOptValue = NONE(); | ||
| 1704 | algorithm | ||
| 1705 | ✗ | for val in inValues loop | |
| 1706 | ✗ | outOptValue := containsEmpty(val); | |
| 1707 | |||
| 1708 | ✗ | if isSome(outOptValue) then | |
| 1709 | break; | ||
| 1710 | end if; | ||
| 1711 | end for; | ||
| 1712 | end arrayContainsEmpty; | ||
| 1713 | |||
| 1714 | public function liftValueList | ||
| 1715 | input Values.Value inValue; | ||
| 1716 | input list<DAE.Dimension> inDimensions; | ||
| 1717 | output Values.Value outValue = inValue; | ||
| 1718 | algorithm | ||
| 1719 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 time.
|
3 | for dim in listReverse(inDimensions) loop |
| 1720 | 2 | outValue := ValuesMake.makeArray(List.fill(outValue, Expression.dimensionSize(dim))); | |
| 1721 | end for; | ||
| 1722 | end liftValueList; | ||
| 1723 | |||
| 1724 | public function isEmpty | ||
| 1725 | input Values.Value inValue; | ||
| 1726 | output Boolean outIsEmpty; | ||
| 1727 | algorithm | ||
| 1728 | outIsEmpty := match inValue | ||
| 1729 | case Values.EMPTY() then true; | ||
| 1730 | else false; | ||
| 1731 | end match; | ||
| 1732 | end isEmpty; | ||
| 1733 | |||
| 1734 | public function typeConvertRecord | ||
| 1735 | "Converts the component values of a record to the correct types." | ||
| 1736 | input Values.Value inValue; | ||
| 1737 | input DAE.Type inType; | ||
| 1738 | output Values.Value outValue = inValue; | ||
| 1739 | algorithm | ||
| 1740 | outValue := match (outValue, inType) | ||
| 1741 | local | ||
| 1742 | DAE.Type ty; | ||
| 1743 | |||
| 1744 | case (Values.RECORD(), DAE.T_COMPLEX()) | ||
| 1745 | algorithm | ||
| 1746 |
7/8✓ Branch 0 taken 5229 times.
✓ Branch 1 taken 1916 times.
✓ Branch 2 taken 5229 times.
✓ Branch 3 taken 1916 times.
✓ Branch 4 taken 5229 times.
✓ Branch 5 taken 1916 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1916 times.
|
9061 | outValue.orderd := list(typeConvertRecord(val, Types.getVarType(var)) |
| 1747 | threaded for val in outValue.orderd, var in inType.varLst); | ||
| 1748 | then | ||
| 1749 | outValue; | ||
| 1750 | |||
| 1751 | case (Values.INTEGER(), DAE.T_REAL()) | ||
| 1752 | 5 | then Values.REAL(intReal(outValue.integer)); | |
| 1753 | |||
| 1754 | case (Values.ARRAY(), DAE.T_ARRAY()) | ||
| 1755 | algorithm | ||
| 1756 | 9112 | ty := Expression.unliftArray(inType); | |
| 1757 |
4/4✓ Branch 0 taken 27870 times.
✓ Branch 1 taken 9112 times.
✓ Branch 2 taken 27870 times.
✓ Branch 3 taken 9112 times.
|
46094 | outValue.valueLst := list(typeConvertRecord(v, ty) for v in outValue.valueLst); |
| 1758 | then | ||
| 1759 | outValue; | ||
| 1760 | |||
| 1761 | else outValue; | ||
| 1762 | end match; | ||
| 1763 | end typeConvertRecord; | ||
| 1764 | |||
| 1765 | public function fixZeroSizeArray "Work-around for Values.ARRAY({}) becoming T_UNKNOWN in ValuesUtil.valueExp" | ||
| 1766 | input output DAE.Exp e; | ||
| 1767 | input DAE.Type ty; | ||
| 1768 | algorithm | ||
| 1769 | e := match e | ||
| 1770 | case DAE.ARRAY(ty=DAE.T_ARRAY(ty=DAE.T_UNKNOWN()), scalar=false, array={}) | ||
| 1771 |
2/2✓ Branch 2 taken 55 times.
✓ Branch 3 taken 2868 times.
|
2978 | then DAE.ARRAY(ty, not Types.isArray(Types.unliftArray(ty)), {}); |
| 1772 | else e; | ||
| 1773 | end match; | ||
| 1774 | end fixZeroSizeArray; | ||
| 1775 | |||
| 1776 | public function arraySize | ||
| 1777 | input Values.Value value; | ||
| 1778 | output Integer size; | ||
| 1779 | algorithm | ||
| 1780 | size := match value | ||
| 1781 | 3 | case Values.Value.ARRAY() then listHead(value.dimLst); | |
| 1782 | ✗ | case Values.Value.META_ARRAY() then listLength(value.valueLst); | |
| 1783 | else 0; | ||
| 1784 | end match; | ||
| 1785 | end arraySize; | ||
| 1786 | |||
| 1787 | annotation(__OpenModelica_Interface="frontend_base"); | ||
| 1788 | end ValuesUtil; | ||
| 1789 |