OMCompiler/Compiler/FrontEnd/TypesDump.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 TypesDump | ||
| 37 | " file: TypesDump.mo | ||
| 38 | package: TypesDump | ||
| 39 | description: Dumping of DAE Types | ||
| 40 | " | ||
| 41 | |||
| 42 | public import DAE; | ||
| 43 | protected | ||
| 44 | import AbsynUtil; | ||
| 45 | import ClassInfUtil; | ||
| 46 | import Config; | ||
| 47 | import Dump; | ||
| 48 | import Error; | ||
| 49 | import ExpressionBasics; | ||
| 50 | import List; | ||
| 51 | import Print; | ||
| 52 | import SCodeDump; | ||
| 53 | import ValuesDump; | ||
| 54 | |||
| 55 | protected type Binding = DAE.Binding; | ||
| 56 | protected type Const = DAE.Const; | ||
| 57 | protected type EqualityConstraint = DAE.EqualityConstraint; | ||
| 58 | protected type FuncArg = DAE.FuncArg; | ||
| 59 | protected type Properties = DAE.Properties; | ||
| 60 | protected type TupleConst = DAE.TupleConst; | ||
| 61 | protected type Type = DAE.Type; | ||
| 62 | protected type Var = DAE.Var; | ||
| 63 | protected type EqMod = DAE.EqMod; | ||
| 64 | |||
| 65 | public function unparseEqMod | ||
| 66 | "prints eqmod to a string" | ||
| 67 | input DAE.EqMod eq; | ||
| 68 | output String str; | ||
| 69 | algorithm | ||
| 70 | str := match eq | ||
| 71 | local DAE.Exp e; Absyn.Exp e2; | ||
| 72 | |||
| 73 | case DAE.TYPED(modifierAsExp = e) | ||
| 74 | algorithm | ||
| 75 | 4 | str := ExpressionBasics.printExpStr(e); | |
| 76 | then | ||
| 77 | str; | ||
| 78 | |||
| 79 | case DAE.UNTYPED(exp=e2) | ||
| 80 | algorithm | ||
| 81 | ✗ | str := Dump.printExpStr(e2); | |
| 82 | then str; | ||
| 83 | end match; | ||
| 84 | end unparseEqMod; | ||
| 85 | |||
| 86 | public function unparseOptionEqMod | ||
| 87 | "prints eqmod to a string" | ||
| 88 | input Option<DAE.EqMod> eq; | ||
| 89 | output String str; | ||
| 90 | algorithm | ||
| 91 | str := match eq | ||
| 92 | local | ||
| 93 | DAE.EqMod e; | ||
| 94 | case NONE() then "NONE()"; | ||
| 95 | ✗ | case SOME(e) then unparseEqMod(e); | |
| 96 | end match; | ||
| 97 | end unparseOptionEqMod; | ||
| 98 | |||
| 99 | public function unparseType | ||
| 100 | "This function prints a Modelica type as a piece of Modelica code." | ||
| 101 | input DAE.Type inType; | ||
| 102 | output String outString; | ||
| 103 | algorithm | ||
| 104 | outString := match inType | ||
| 105 | local | ||
| 106 | String s1,s2,str,dims,res,vstr,name,st_str,bc_tp_str,paramstr,restypestr,tystr,funcstr; | ||
| 107 | list<String> l,vars,paramstrs,tystrs; | ||
| 108 | Type ty,bc_tp,restype; | ||
| 109 | DAE.Dimensions dimlst; | ||
| 110 | list<DAE.Var> vs; | ||
| 111 | ClassInf.State ci_state; | ||
| 112 | list<DAE.FuncArg> params; | ||
| 113 | Absyn.Path path; | ||
| 114 | list<DAE.Type> tys; | ||
| 115 | DAE.CodeType codeType; | ||
| 116 | Boolean b; | ||
| 117 | |||
| 118 | case DAE.T_INTEGER(varLst = {}) then "Integer"; | ||
| 119 | case DAE.T_REAL(varLst = {}) then "Real"; | ||
| 120 | case DAE.T_STRING(varLst = {}) then "String"; | ||
| 121 | case DAE.T_BOOL(varLst = {}) then "Boolean"; | ||
| 122 | // BTH | ||
| 123 | case DAE.T_CLOCK() then "Clock"; | ||
| 124 | |||
| 125 | case DAE.T_INTEGER(varLst = vs) | ||
| 126 | algorithm | ||
| 127 | ✗ | s1 := stringDelimitList(List.map(vs, unparseVarAttr),", "); | |
| 128 | ✗ | s2 := "Integer(" + s1 + ")"; | |
| 129 | then s2; | ||
| 130 | case DAE.T_REAL(varLst = vs) | ||
| 131 | algorithm | ||
| 132 | 139 | s1 := stringDelimitList(List.map(vs, unparseVarAttr),", "); | |
| 133 | 139 | s2 := "Real(" + s1 + ")"; | |
| 134 | then s2; | ||
| 135 | case DAE.T_STRING(varLst = vs) | ||
| 136 | algorithm | ||
| 137 | ✗ | s1 := stringDelimitList(List.map(vs, unparseVarAttr),", "); | |
| 138 | ✗ | s2 := "String(" + s1 + ")"; | |
| 139 | then s2; | ||
| 140 | case DAE.T_BOOL(varLst = vs) | ||
| 141 | algorithm | ||
| 142 | ✗ | s1 := stringDelimitList(List.map(vs, unparseVarAttr),", "); | |
| 143 | ✗ | s2 := "Boolean(" + s1 + ")"; | |
| 144 | then s2; | ||
| 145 | case DAE.T_ENUMERATION(path = path, names = l) | ||
| 146 | algorithm | ||
| 147 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
|
28 | s1 := if Config.typeinfo() then " /*" + AbsynUtil.pathString(path) + "*/ (" else "("; |
| 148 | 28 | s2 := stringDelimitList(l, ", "); | |
| 149 | /* s2 = stringAppendList(List.map(vs, unparseVar)); | ||
| 150 | s2 = if_(s2 == "", "", "(" + s2 + ")"); */ | ||
| 151 | 28 | str := stringAppendList({"enumeration",s1,s2,")"}); | |
| 152 | then | ||
| 153 | str; | ||
| 154 | |||
| 155 | case ty as DAE.T_ARRAY() | ||
| 156 | algorithm | ||
| 157 | 406 | (ty,dimlst) := flattenArrayType(ty); | |
| 158 | 406 | tystr := unparseType(ty); | |
| 159 | 406 | dims := printDimensionsStr(dimlst); | |
| 160 | 406 | res := stringAppendList({tystr,"[",dims,"]"}); | |
| 161 | then | ||
| 162 | res; | ||
| 163 | |||
| 164 | case DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(path),varLst = vs) | ||
| 165 | algorithm | ||
| 166 | 23 | name := AbsynUtil.pathStringNoQual(path); | |
| 167 | 23 | vars := List.map(vs, unparseVar); | |
| 168 | 23 | vstr := stringAppendList(vars); | |
| 169 | 23 | res := stringAppendList({"record ",name,"\n",vstr,"end ", name, ";"}); | |
| 170 | then | ||
| 171 | res; | ||
| 172 | |||
| 173 | case DAE.T_COMPLEX(complexClassType = ClassInf.CONNECTOR(path, b),varLst = vs) | ||
| 174 | algorithm | ||
| 175 | 4 | name := AbsynUtil.pathStringNoQual(path); | |
| 176 | 4 | vars := List.map(vs, unparseVar); | |
| 177 | 4 | vstr := stringAppendList(vars); | |
| 178 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | str := if b then "expandable " else ""; |
| 179 | 4 | res := stringAppendList({str, "connector ",name,"\n",vstr,"end ", name, ";"}); | |
| 180 | then | ||
| 181 | res; | ||
| 182 | |||
| 183 | case DAE.T_SUBTYPE_BASIC(complexClassType = ci_state, complexType = bc_tp) | ||
| 184 | algorithm | ||
| 185 | 1 | st_str := AbsynUtil.pathString(ClassInfUtil.getStateName(ci_state)); | |
| 186 | 1 | res := ClassInfUtil.printStateStr(ci_state); | |
| 187 | 1 | bc_tp_str := unparseType(bc_tp); | |
| 188 | 1 | res := stringAppendList({"(",res," ",st_str," bc:",bc_tp_str,")"}); | |
| 189 | then | ||
| 190 | res; | ||
| 191 | |||
| 192 | case DAE.T_COMPLEX(complexClassType = ci_state) | ||
| 193 | algorithm | ||
| 194 | 85 | st_str := AbsynUtil.pathString(ClassInfUtil.getStateName(ci_state)); | |
| 195 | 85 | res := ClassInfUtil.printStateStr(ci_state); | |
| 196 | 85 | res := stringAppendList({res," ",st_str}); | |
| 197 | then | ||
| 198 | res; | ||
| 199 | |||
| 200 | case DAE.T_FUNCTION(funcArg = params, funcResultType = restype, path=path) | ||
| 201 | algorithm | ||
| 202 | 96 | funcstr := AbsynUtil.pathString(path); | |
| 203 | 96 | paramstrs := List.map(params, unparseParam); | |
| 204 | 96 | paramstr := stringDelimitList(paramstrs, ", "); | |
| 205 | 96 | restypestr := unparseType(restype); | |
| 206 | 96 | res := stringAppendList({funcstr,"<function>(",paramstr,") => ",restypestr}); | |
| 207 | then | ||
| 208 | res; | ||
| 209 | |||
| 210 | case DAE.T_TUPLE(types = tys) | ||
| 211 | algorithm | ||
| 212 | tystrs := match inType.names | ||
| 213 | local | ||
| 214 | list<String> names; | ||
| 215 | ✗ | case SOME(names) then list(unparseType(t) + " " + n threaded for t in tys, n in names); | |
| 216 | ✗ | else list(unparseType(t) for t in tys); | |
| 217 | end match; | ||
| 218 | ✗ | tystr := stringDelimitList(tystrs, ", "); | |
| 219 | ✗ | res := stringAppendList({"(",tystr,")"}); | |
| 220 | then | ||
| 221 | res; | ||
| 222 | |||
| 223 | // MetaModelica tuple | ||
| 224 | case DAE.T_METATUPLE(types = tys) | ||
| 225 | algorithm | ||
| 226 | 64 | tystrs := List.map(tys, unparseType); | |
| 227 | 64 | tystr := stringDelimitList(tystrs, ", "); | |
| 228 | 64 | res := stringAppendList({"tuple<",tystr,">"}); | |
| 229 | then | ||
| 230 | res; | ||
| 231 | |||
| 232 | // MetaModelica list | ||
| 233 | case DAE.T_METALIST(ty = ty) | ||
| 234 | algorithm | ||
| 235 | 139 | tystr := unparseType(ty); | |
| 236 | 139 | res := stringAppendList({"list<",tystr,">"}); | |
| 237 | then | ||
| 238 | res; | ||
| 239 | |||
| 240 | case DAE.T_METAARRAY(ty = ty) | ||
| 241 | algorithm | ||
| 242 | 14 | tystr := unparseType(ty); | |
| 243 | 14 | res := stringAppendList({"array<",tystr,">"}); | |
| 244 | then | ||
| 245 | res; | ||
| 246 | |||
| 247 | // MetaModelica list | ||
| 248 | case DAE.T_METAPOLYMORPHIC(name = tystr) | ||
| 249 | algorithm | ||
| 250 | 127 | res := stringAppendList({"polymorphic<",tystr,">"}); | |
| 251 | then | ||
| 252 | res; | ||
| 253 | |||
| 254 | // MetaModelica uniontype | ||
| 255 | case DAE.T_METAUNIONTYPE() | ||
| 256 | algorithm | ||
| 257 | 268 | res := AbsynUtil.pathStringNoQual(inType.path); | |
| 258 |
6/6✓ Branch 0 taken 31 times.
✓ Branch 1 taken 237 times.
✓ Branch 3 taken 32 times.
✓ Branch 4 taken 31 times.
✓ Branch 5 taken 32 times.
✓ Branch 6 taken 31 times.
|
300 | then if listEmpty(inType.typeVars) then res else (res+"<"+stringDelimitList(list(unparseType(tv) for tv in inType.typeVars), ",")+">"); |
| 259 | |||
| 260 | // MetaModelica uniontype (but we know which record in the UT it is) | ||
| 261 | /* | ||
| 262 | case (DAE.T_METARECORD(utPath=_, fields = vs, source = {p})) | ||
| 263 | algorithm | ||
| 264 | str = AbsynUtil.pathStringNoQual(p); | ||
| 265 | vars = List.map(vs, unparseVar); | ||
| 266 | vstr = stringAppendList(vars); | ||
| 267 | res = stringAppendList({"metarecord ",str,"\n",vstr,"end ", str, ";"}); | ||
| 268 | then res; | ||
| 269 | */ | ||
| 270 | case DAE.T_METARECORD() | ||
| 271 | algorithm | ||
| 272 | 10 | res := AbsynUtil.pathStringNoQual(inType.path); | |
| 273 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
10 | then if listEmpty(inType.typeVars) then res else (res+"<"+stringDelimitList(list(unparseType(tv) for tv in inType.typeVars), ",")+">"); |
| 274 | |||
| 275 | // MetaModelica boxed type | ||
| 276 | case DAE.T_METABOXED(ty = ty) | ||
| 277 | algorithm | ||
| 278 | 111 | res := unparseType(ty); | |
| 279 | 111 | res := "#" /* this is a box */ + res; | |
| 280 | then res; | ||
| 281 | |||
| 282 | // MetaModelica Option type | ||
| 283 | case DAE.T_METAOPTION(ty = DAE.T_UNKNOWN()) then "Option<Any>"; | ||
| 284 | case DAE.T_METAOPTION(ty = ty) | ||
| 285 | algorithm | ||
| 286 | 6 | tystr := unparseType(ty); | |
| 287 | 6 | res := stringAppendList({"Option<",tystr,">"}); | |
| 288 | then | ||
| 289 | res; | ||
| 290 | |||
| 291 | 497 | case DAE.T_METATYPE(ty = ty) then unparseType(ty); | |
| 292 | |||
| 293 | case DAE.T_NORETCALL() then "#NORETCALL#"; | ||
| 294 | case DAE.T_UNKNOWN() then "#T_UNKNOWN#"; | ||
| 295 | case DAE.T_ANYTYPE() then "#ANYTYPE#"; | ||
| 296 | ✗ | case DAE.T_CODE(ty = codeType) then printCodeTypeStr(codeType); | |
| 297 | ✗ | case DAE.T_FUNCTION_REFERENCE_VAR(functionType=ty) then "#FUNCTION_REFERENCE_VAR#" + unparseType(ty); | |
| 298 | ✗ | case DAE.T_FUNCTION_REFERENCE_FUNC(functionType=ty) then "#FUNCTION_REFERENCE_FUNC#" + unparseType(ty); | |
| 299 | else "Internal error TypesDump.unparseType: not implemented yet\n"; | ||
| 300 | end match; | ||
| 301 | end unparseType; | ||
| 302 | |||
| 303 | public function unparseTypeNoAttr | ||
| 304 | "Like unparseType, but doesn't print out builtin attributes." | ||
| 305 | input DAE.Type inType; | ||
| 306 | output String outString; | ||
| 307 | protected | ||
| 308 | DAE.Type ty; | ||
| 309 | algorithm | ||
| 310 | 36451 | (ty, _) := stripTypeVars(inType); | |
| 311 | 36451 | outString := unparseType(ty); | |
| 312 | end unparseTypeNoAttr; | ||
| 313 | |||
| 314 | public function unparsePropTypeNoAttr | ||
| 315 | input DAE.Properties inProps; | ||
| 316 | output String outString; | ||
| 317 | algorithm | ||
| 318 | outString := match inProps | ||
| 319 | local | ||
| 320 | DAE.Type ty; | ||
| 321 | |||
| 322 | ✗ | case DAE.PROP(type_ = ty) then unparseTypeNoAttr(ty); | |
| 323 | ✗ | case DAE.PROP_TUPLE(type_ = ty) then unparseTypeNoAttr(ty); | |
| 324 | end match; | ||
| 325 | end unparsePropTypeNoAttr; | ||
| 326 | |||
| 327 | public function unparseConst | ||
| 328 | input DAE.Const inConst; | ||
| 329 | output String outString; | ||
| 330 | algorithm | ||
| 331 | outString := match inConst | ||
| 332 | case DAE.C_CONST() then "constant"; | ||
| 333 | case DAE.C_PARAM() then "parameter"; | ||
| 334 | case DAE.C_VAR() then "continuous"; | ||
| 335 | case DAE.C_UNKNOWN() then "unknown"; | ||
| 336 | end match; | ||
| 337 | end unparseConst; | ||
| 338 | |||
| 339 | public function printConstStr | ||
| 340 | "This function prints a Const as a string." | ||
| 341 | input DAE.Const inConst; | ||
| 342 | output String outString; | ||
| 343 | algorithm | ||
| 344 | outString := match inConst | ||
| 345 | case DAE.C_CONST() then "C_CONST"; | ||
| 346 | case DAE.C_PARAM() then "C_PARAM"; | ||
| 347 | case DAE.C_VAR() then "C_VAR"; | ||
| 348 | else algorithm | ||
| 349 | ✗ | Error.addInternalError(getInstanceName() + " failed.", sourceInfo()); | |
| 350 | ✗ | then fail(); | |
| 351 | end match; | ||
| 352 | end printConstStr; | ||
| 353 | |||
| 354 | public function printTupleConstStr | ||
| 355 | "This function prints a Modelica TupleConst as a string." | ||
| 356 | input DAE.TupleConst inTupleConst; | ||
| 357 | output String outString; | ||
| 358 | algorithm | ||
| 359 | outString := match inTupleConst | ||
| 360 | local | ||
| 361 | String cstr,res,res_1; | ||
| 362 | DAE.Const c; | ||
| 363 | list<String> strlist; | ||
| 364 | list<DAE.TupleConst> constlist; | ||
| 365 | case DAE.SINGLE_CONST(const = c) | ||
| 366 | algorithm | ||
| 367 | ✗ | cstr := printConstStr(c); | |
| 368 | then | ||
| 369 | cstr; | ||
| 370 | case DAE.TUPLE_CONST(tupleConstLst = constlist) | ||
| 371 | algorithm | ||
| 372 | ✗ | strlist := List.map(constlist, printTupleConstStr); | |
| 373 | ✗ | res := stringDelimitList(strlist, ", "); | |
| 374 | ✗ | res_1 := stringAppendList({"(",res,")"}); | |
| 375 | then | ||
| 376 | res_1; | ||
| 377 | end match; | ||
| 378 | end printTupleConstStr; | ||
| 379 | |||
| 380 | public function printTypeStr "This function prints a textual description of a Modelica type to a string. | ||
| 381 | If the type is not one of the primitive types, it simply prints composite." | ||
| 382 | input DAE.Type inType; | ||
| 383 | output String str; | ||
| 384 | algorithm | ||
| 385 | str := matchcontinue inType | ||
| 386 | local | ||
| 387 | list<DAE.Var> vars; | ||
| 388 | ClassInf.State st; | ||
| 389 | list<DAE.Dimension> dims; | ||
| 390 | Type t,ty,restype; | ||
| 391 | list<DAE.FuncArg> params; | ||
| 392 | list<DAE.Type> tys; | ||
| 393 | String s1,s2,compType; | ||
| 394 | Absyn.Path path; | ||
| 395 | |||
| 396 | case DAE.T_INTEGER(varLst = vars) | ||
| 397 | 29 | then List.toStringCustom(vars, printVarStr, "Integer", "(", ", ", ")", false); | |
| 398 | |||
| 399 | case DAE.T_REAL(varLst = vars) | ||
| 400 | 7256 | then List.toStringCustom(vars, printVarStr, "Real", "(", ", ", ")", false); | |
| 401 | |||
| 402 | case DAE.T_STRING(varLst = vars) | ||
| 403 | 10642 | then List.toStringCustom(vars, printVarStr, "String", "(", ", ", ")", false); | |
| 404 | |||
| 405 | case DAE.T_BOOL(varLst = vars) | ||
| 406 | 7 | then List.toStringCustom(vars, printVarStr, "Boolean", "(", ", ", ")", false); | |
| 407 | |||
| 408 | case DAE.T_CLOCK(varLst = vars) | ||
| 409 | ✗ | then List.toStringCustom(vars, printVarStr, "Clock", "(", ", ", ")", false); | |
| 410 | |||
| 411 | case DAE.T_ENUMERATION(literalVarLst = vars) | ||
| 412 | 1 | then List.toStringCustom(vars, printVarStr, "Enumeration", "(", ", ", ")", false); | |
| 413 | |||
| 414 | case DAE.T_SUBTYPE_BASIC(complexClassType = st, complexType = t, varLst = vars) | ||
| 415 | algorithm | ||
| 416 | ✗ | compType := printTypeStr(t); | |
| 417 | ✗ | s1 := ClassInfUtil.printStateStr(st); | |
| 418 | ✗ | s2 := stringDelimitList(List.map(vars, printVarStr),", "); | |
| 419 | ✗ | str := stringAppendList({"composite(",s1,"{",s2,"}, derived from ", compType, ")"}); | |
| 420 | then | ||
| 421 | str; | ||
| 422 | |||
| 423 | case DAE.T_COMPLEX(complexClassType = st,varLst = vars) | ||
| 424 | algorithm | ||
| 425 | 2634 | s1 := ClassInfUtil.printStateStr(st); | |
| 426 | 2634 | s2 := stringDelimitList(List.map(vars, printVarStr),", "); | |
| 427 | 2634 | str := stringAppendList({"composite(",s1,"{",s2,"})"}); | |
| 428 | then | ||
| 429 | str; | ||
| 430 | |||
| 431 | case DAE.T_ARRAY(dims = dims,ty = t) | ||
| 432 | algorithm | ||
| 433 | 7840 | s1 := stringDelimitList(List.map(dims, ExpressionBasics.dimensionString), ", "); | |
| 434 | 7840 | s2 := printTypeStr(t); | |
| 435 | 7840 | str := stringAppendList({"array(",s2,")[",s1,"]"}); | |
| 436 | then | ||
| 437 | str; | ||
| 438 | |||
| 439 | case DAE.T_FUNCTION(funcArg = params,funcResultType = restype) | ||
| 440 | algorithm | ||
| 441 | 18 | s1 := printParamsStr(params); | |
| 442 | 18 | s2 := printTypeStr(restype); | |
| 443 | 18 | str := stringAppendList({"function(", s1,") => ",s2}); | |
| 444 | 18 | str := str + AbsynUtil.pathString(inType.path); | |
| 445 | then | ||
| 446 | str; | ||
| 447 | |||
| 448 | case DAE.T_TUPLE(types = tys) | ||
| 449 | algorithm | ||
| 450 | ✗ | s1 := stringDelimitList(List.map(tys, printTypeStr),", "); | |
| 451 | ✗ | str := stringAppendList({"(",s1,")"}); | |
| 452 | then | ||
| 453 | str; | ||
| 454 | |||
| 455 | // MetaModelica tuple | ||
| 456 | case DAE.T_METATUPLE(types = tys) | ||
| 457 | algorithm | ||
| 458 | ✗ | str := printTypeStr(DAE.T_TUPLE(tys,NONE())); | |
| 459 | then | ||
| 460 | str; | ||
| 461 | |||
| 462 | // MetaModelica list | ||
| 463 | case DAE.T_METALIST(ty = ty) | ||
| 464 | algorithm | ||
| 465 | ✗ | s1 := printTypeStr(ty); | |
| 466 | ✗ | str := stringAppendList({"list<",s1,">"}); | |
| 467 | then | ||
| 468 | str; | ||
| 469 | |||
| 470 | // MetaModelica Option | ||
| 471 | case DAE.T_METAOPTION(ty = ty) | ||
| 472 | algorithm | ||
| 473 | ✗ | s1 := printTypeStr(ty); | |
| 474 | ✗ | str := stringAppendList({"Option<",s1,">"}); | |
| 475 | then | ||
| 476 | str; | ||
| 477 | |||
| 478 | // MetaModelica Array | ||
| 479 | case DAE.T_METAARRAY(ty = ty) | ||
| 480 | algorithm | ||
| 481 | ✗ | s1 := printTypeStr(ty); | |
| 482 | ✗ | str := stringAppendList({"array<",s1,">"}); | |
| 483 | then | ||
| 484 | str; | ||
| 485 | |||
| 486 | // MetaModelica Boxed | ||
| 487 | case DAE.T_METABOXED(ty = ty) | ||
| 488 | algorithm | ||
| 489 | ✗ | s1 := printTypeStr(ty); | |
| 490 | ✗ | str := stringAppendList({"boxed<",s1,">"}); | |
| 491 | then | ||
| 492 | str; | ||
| 493 | |||
| 494 | // MetaModelica polymorphic | ||
| 495 | case DAE.T_METAPOLYMORPHIC(name = s1) | ||
| 496 | algorithm | ||
| 497 | ✗ | str := stringAppendList({"polymorphic<",s1,">"}); | |
| 498 | then | ||
| 499 | str; | ||
| 500 | |||
| 501 | // NoType | ||
| 502 | case DAE.T_UNKNOWN() | ||
| 503 | algorithm | ||
| 504 | str := "T_UNKNOWN"; | ||
| 505 | then | ||
| 506 | str; | ||
| 507 | |||
| 508 | // AnyType of none | ||
| 509 | case DAE.T_ANYTYPE(anyClassType = NONE()) | ||
| 510 | algorithm | ||
| 511 | str := "ANYTYPE()"; | ||
| 512 | then | ||
| 513 | str; | ||
| 514 | // AnyType of some | ||
| 515 | case DAE.T_ANYTYPE(anyClassType = SOME(st)) | ||
| 516 | algorithm | ||
| 517 | ✗ | s1 := ClassInfUtil.printStateStr(st); | |
| 518 | ✗ | str := "ANYTYPE(" + s1 + ")"; | |
| 519 | then | ||
| 520 | str; | ||
| 521 | |||
| 522 | case DAE.T_NORETCALL() | ||
| 523 | then "()"; | ||
| 524 | |||
| 525 | // MetaType | ||
| 526 | case DAE.T_METATYPE(ty = t) | ||
| 527 | algorithm | ||
| 528 | ✗ | s1 := printTypeStr(t); | |
| 529 | ✗ | str := stringAppendList({"METATYPE(", s1, ")"}); | |
| 530 | then | ||
| 531 | str; | ||
| 532 | |||
| 533 | // Uniontype, Metarecord | ||
| 534 | case t as DAE.T_METARECORD() | ||
| 535 | algorithm | ||
| 536 | ✗ | s1 := AbsynUtil.pathStringNoQual(t.path); | |
| 537 | ✗ | str := "#" + s1 + "#"; | |
| 538 | then | ||
| 539 | str; | ||
| 540 | case t as DAE.T_METAUNIONTYPE() | ||
| 541 | algorithm | ||
| 542 | ✗ | s1 := AbsynUtil.pathStringNoQual(t.path); | |
| 543 | ✗ | str := "#" + s1 + "#"; | |
| 544 | then | ||
| 545 | str; | ||
| 546 | |||
| 547 | // Code | ||
| 548 | case DAE.T_CODE(DAE.C_EXPRESSION()) then "$Code(Expression)"; | ||
| 549 | case DAE.T_CODE(DAE.C_EXPRESSION_OR_MODIFICATION()) then "$Code(ExpressionOrModification)"; | ||
| 550 | case DAE.T_CODE(DAE.C_TYPENAME()) then "$Code(TypeName)"; | ||
| 551 | case DAE.T_CODE(DAE.C_VARIABLENAME()) then "$Code(VariableName)"; | ||
| 552 | case DAE.T_CODE(DAE.C_VARIABLENAMES()) then "$Code(VariableName[:])"; | ||
| 553 | |||
| 554 | // All the other ones we don't handle | ||
| 555 | else | ||
| 556 | algorithm | ||
| 557 | str := "TypesDump.printTypeStr failed"; | ||
| 558 | then | ||
| 559 | str; | ||
| 560 | |||
| 561 | end matchcontinue; | ||
| 562 | end printTypeStr; | ||
| 563 | |||
| 564 | public function printConnectorTypeStr | ||
| 565 | "Author BZ, 2009-09 | ||
| 566 | Print the connector-type-name" | ||
| 567 | input DAE.Type it; | ||
| 568 | output String s "Connector type"; | ||
| 569 | output String s2 "Components of connector"; | ||
| 570 | algorithm | ||
| 571 | (s,s2) := matchcontinue it | ||
| 572 | local | ||
| 573 | Absyn.Path connectorName; | ||
| 574 | list<DAE.Var> vars; | ||
| 575 | list<String> varNames; | ||
| 576 | Boolean isExpandable; | ||
| 577 | String isExpandableStr; | ||
| 578 | Type t; | ||
| 579 | |||
| 580 | case DAE.T_COMPLEX(complexClassType = (ClassInf.CONNECTOR(connectorName,isExpandable)),varLst = vars) | ||
| 581 | algorithm | ||
| 582 | ✗ | varNames := List.map(vars,getVarName); | |
| 583 | ✗ | isExpandableStr := if isExpandable then "/* expandable */ " else ""; | |
| 584 | ✗ | s := isExpandableStr + AbsynUtil.pathString(connectorName); | |
| 585 | ✗ | s2 := "{" + stringDelimitList(varNames,", ") + "}"; | |
| 586 | then | ||
| 587 | (s,s2); | ||
| 588 | |||
| 589 | // TODO! check if we can get T_SUBTYPE_BASIC here??!! | ||
| 590 | case DAE.T_SUBTYPE_BASIC(complexClassType = (ClassInf.CONNECTOR(connectorName,isExpandable)), varLst = vars, complexType = t) | ||
| 591 | algorithm | ||
| 592 | ✗ | varNames := List.map(vars,getVarName); | |
| 593 | ✗ | isExpandableStr := if isExpandable then "/* expandable */ " else ""; | |
| 594 | ✗ | s := isExpandableStr + AbsynUtil.pathString(connectorName); | |
| 595 | ✗ | s2 := "{" + stringDelimitList(varNames,", ") + "}" + " subtype of: " + printTypeStr(t); | |
| 596 | then | ||
| 597 | (s,s2); | ||
| 598 | |||
| 599 | ✗ | else ("", unparseType(it)); | |
| 600 | end matchcontinue; | ||
| 601 | end printConnectorTypeStr; | ||
| 602 | |||
| 603 | public function printParamsStr "Prints function arguments to a string." | ||
| 604 | input list<DAE.FuncArg> inFuncArgLst; | ||
| 605 | output String str; | ||
| 606 | algorithm | ||
| 607 | str := match inFuncArgLst | ||
| 608 | local | ||
| 609 | String n; | ||
| 610 | DAE.Type t; | ||
| 611 | list<DAE.FuncArg> params; | ||
| 612 | String s1,s2; | ||
| 613 | case {} then ""; | ||
| 614 | case {DAE.FUNCARG(name=n,ty=t)} | ||
| 615 | algorithm | ||
| 616 | 18 | s1 := printTypeStr(t); | |
| 617 | 18 | str := stringAppendList({n," :: ",s1}); | |
| 618 | then | ||
| 619 | str; | ||
| 620 | case DAE.FUNCARG(name=n,ty=t)::params | ||
| 621 | algorithm | ||
| 622 | 18 | s1 := printTypeStr(t); | |
| 623 | 18 | s2 := printParamsStr(params); | |
| 624 | 18 | str := stringAppendList({n," :: ",s1, " * ",s2}); | |
| 625 | then | ||
| 626 | str; | ||
| 627 | end match; | ||
| 628 | end printParamsStr; | ||
| 629 | |||
| 630 | public function unparseVarAttr " | ||
| 631 | Prints a variable which is attribute of builtin type to a string, e.g. on the form 'max = 10.0'" | ||
| 632 | input DAE.Var inVar; | ||
| 633 | output String outString; | ||
| 634 | algorithm | ||
| 635 | outString := matchcontinue inVar | ||
| 636 | local | ||
| 637 | String res,n,bindStr,valStr; | ||
| 638 | Values.Value value; | ||
| 639 | DAE.Exp e; | ||
| 640 | |||
| 641 | case DAE.TYPES_VAR(name = n, binding = DAE.EQBOUND(exp=e)) | ||
| 642 | algorithm | ||
| 643 | 510 | bindStr := ExpressionBasics.printExpStr(e); | |
| 644 | 510 | res := stringAppendList({n," = ",bindStr}); | |
| 645 | then | ||
| 646 | res; | ||
| 647 | case DAE.TYPES_VAR(name = n, binding = DAE.VALBOUND(valBound=value)) | ||
| 648 | algorithm | ||
| 649 | ✗ | valStr := ValuesDump.valString(value); | |
| 650 | ✗ | res := stringAppendList({n," = ",valStr}); | |
| 651 | then | ||
| 652 | res; | ||
| 653 | else ""; | ||
| 654 | end matchcontinue; | ||
| 655 | end unparseVarAttr; | ||
| 656 | |||
| 657 | public function unparseVar | ||
| 658 | "Prints a variable to a string." | ||
| 659 | input DAE.Var inVar; | ||
| 660 | output String outString; | ||
| 661 | algorithm | ||
| 662 | outString := match inVar | ||
| 663 | local | ||
| 664 | String t,res,n, s; | ||
| 665 | DAE.Type typ; | ||
| 666 | DAE.ConnectorType ct; | ||
| 667 | |||
| 668 | case DAE.TYPES_VAR(name = n,ty = typ,attributes = DAE.ATTR(connectorType = ct)) | ||
| 669 | algorithm | ||
| 670 | 71 | s := connectorTypeStr(ct); | |
| 671 | 71 | t := unparseType(typ); | |
| 672 | 71 | res := stringAppendList({" ", s, t," ", n, ";\n"}); | |
| 673 | then | ||
| 674 | res; | ||
| 675 | |||
| 676 | end match; | ||
| 677 | end unparseVar; | ||
| 678 | |||
| 679 | public function connectorTypeStr | ||
| 680 | input DAE.ConnectorType ct; | ||
| 681 | output String str; | ||
| 682 | algorithm | ||
| 683 | str := match ct | ||
| 684 | local case DAE.POTENTIAL() then ""; | ||
| 685 | case DAE.FLOW() then "flow "; | ||
| 686 | case DAE.STREAM(_) then "stream "; | ||
| 687 | else ""; | ||
| 688 | end match; | ||
| 689 | end connectorTypeStr; | ||
| 690 | |||
| 691 | protected function unparseParam "Prints a function argument to a string." | ||
| 692 | input DAE.FuncArg inFuncArg; | ||
| 693 | output String outString; | ||
| 694 | algorithm | ||
| 695 | outString := match inFuncArg | ||
| 696 | local | ||
| 697 | String tstr,res,id,cstr,estr,pstr; | ||
| 698 | DAE.Type ty; | ||
| 699 | DAE.Const c; | ||
| 700 | DAE.VarParallelism p; | ||
| 701 | DAE.Exp exp; | ||
| 702 | case DAE.FUNCARG(id,ty,c,p,NONE()) | ||
| 703 | algorithm | ||
| 704 | 114 | tstr := unparseType(ty); | |
| 705 | 114 | cstr := constStrFriendly(c); | |
| 706 | 114 | pstr := dumpVarParallelismStr(p); | |
| 707 | 114 | res := stringAppendList({tstr," ",cstr,pstr,id}); | |
| 708 | then | ||
| 709 | res; | ||
| 710 | case DAE.FUNCARG(id,ty,c,p,SOME(exp)) | ||
| 711 | algorithm | ||
| 712 | 6 | tstr := unparseType(ty); | |
| 713 | 6 | cstr := constStrFriendly(c); | |
| 714 | 6 | estr := ExpressionBasics.printExpStr(exp); | |
| 715 | 6 | pstr := dumpVarParallelismStr(p); | |
| 716 | 6 | res := stringAppendList({tstr," ",cstr,pstr,id," := ",estr}); | |
| 717 | then | ||
| 718 | res; | ||
| 719 | end match; | ||
| 720 | end unparseParam; | ||
| 721 | |||
| 722 | public function printVarStr "author: LS | ||
| 723 | Prints a Var to the a string." | ||
| 724 | input DAE.Var inVar; | ||
| 725 | output String str; | ||
| 726 | algorithm | ||
| 727 | str := matchcontinue inVar | ||
| 728 | local | ||
| 729 | String vs,n; | ||
| 730 | SCode.Variability var; | ||
| 731 | DAE.Type typ; | ||
| 732 | DAE.Binding bind; | ||
| 733 | String s1,s2; | ||
| 734 | |||
| 735 | case DAE.TYPES_VAR(name = n,attributes = DAE.ATTR(variability = var),ty = typ,binding = bind) | ||
| 736 | algorithm | ||
| 737 | 19133 | s1 := printTypeStr(typ); | |
| 738 | 19133 | vs := SCodeDump.variabilityString(var); | |
| 739 | 19133 | s2 := printBindingStr(bind); | |
| 740 | 19133 | str := stringAppendList({s1," ",n," ",vs," ",s2}); | |
| 741 | then | ||
| 742 | str; | ||
| 743 | case DAE.TYPES_VAR(name = n) | ||
| 744 | algorithm | ||
| 745 | str := stringAppendList({n}); | ||
| 746 | then | ||
| 747 | str; | ||
| 748 | end matchcontinue; | ||
| 749 | end printVarStr; | ||
| 750 | |||
| 751 | public function printBindingStr "Print a variable binding to a string." | ||
| 752 | input DAE.Binding inBinding; | ||
| 753 | output String outString; | ||
| 754 | algorithm | ||
| 755 | outString := match inBinding | ||
| 756 | local | ||
| 757 | String str,str2,res,v_str,s,str3; | ||
| 758 | Values.Value v; | ||
| 759 | |||
| 760 | case DAE.UNBOUND() then "UNBOUND"; | ||
| 761 | case DAE.EQBOUND(evaluatedExp = NONE()) | ||
| 762 | algorithm | ||
| 763 | ✗ | str := ExpressionBasics.printExpStr(inBinding.exp); | |
| 764 | ✗ | str2 := printConstStr(inBinding.constant_); | |
| 765 | ✗ | str3 := printBindingSourceStr(inBinding.source); | |
| 766 | ✗ | res := stringAppendList({"DAE.EQBOUND(",str,", NONE(), ",str2,", ",str3,")"}); | |
| 767 | then | ||
| 768 | res; | ||
| 769 | case DAE.EQBOUND(evaluatedExp = SOME(v)) | ||
| 770 | algorithm | ||
| 771 | 11185 | str := ExpressionBasics.printExpStr(inBinding.exp); | |
| 772 | 11185 | str2 := printConstStr(inBinding.constant_); | |
| 773 | 11185 | v_str := ValuesDump.valString(v); | |
| 774 | 11185 | str3 := printBindingSourceStr(inBinding.source); | |
| 775 | 11185 | res := stringAppendList({"DAE.EQBOUND(",str,", SOME(",v_str,"), ",str2,", ",str3,")"}); | |
| 776 | then | ||
| 777 | res; | ||
| 778 | case DAE.VALBOUND(valBound = v) | ||
| 779 | algorithm | ||
| 780 | ✗ | s := ValuesDump.unparseValues({v}); | |
| 781 | ✗ | str3 := printBindingSourceStr(inBinding.source); | |
| 782 | ✗ | res := stringAppendList({"DAE.VALBOUND(",s,", ",str3,")"}); | |
| 783 | then | ||
| 784 | res; | ||
| 785 | else | ||
| 786 | algorithm | ||
| 787 | ✗ | Error.addInternalError(getInstanceName() + " failed.", sourceInfo()); | |
| 788 | ✗ | then | |
| 789 | fail(); | ||
| 790 | end match; | ||
| 791 | end printBindingStr; | ||
| 792 | |||
| 793 | public function printFarg "Prints a function argument to the Print buffer." | ||
| 794 | input DAE.FuncArg inFuncArg; | ||
| 795 | algorithm | ||
| 796 | () := match inFuncArg | ||
| 797 | local | ||
| 798 | String n; | ||
| 799 | DAE.Type ty; | ||
| 800 | case DAE.FUNCARG(name=n,ty=ty) | ||
| 801 | algorithm | ||
| 802 | ✗ | Print.printErrorBuf(printTypeStr(ty)); | |
| 803 | ✗ | Print.printErrorBuf(" "); | |
| 804 | ✗ | Print.printErrorBuf(n); | |
| 805 | then | ||
| 806 | (); | ||
| 807 | end match; | ||
| 808 | end printFarg; | ||
| 809 | |||
| 810 | public function printFargStr "Prints a function argument to a string" | ||
| 811 | input DAE.FuncArg inFuncArg; | ||
| 812 | output String outString; | ||
| 813 | algorithm | ||
| 814 | outString := match inFuncArg | ||
| 815 | local | ||
| 816 | String s,res,n,cs; | ||
| 817 | DAE.Type ty; | ||
| 818 | DAE.Const c; | ||
| 819 | |||
| 820 | case DAE.FUNCARG(n,ty,c,_,_) | ||
| 821 | algorithm | ||
| 822 | ✗ | s := unparseType(ty); | |
| 823 | ✗ | cs := constStrFriendly(c); | |
| 824 | // res = stringAppendList({ps,cs,s," ",n}); | ||
| 825 | ✗ | res := stringAppendList({cs,s," ",n}); | |
| 826 | then | ||
| 827 | res; | ||
| 828 | end match; | ||
| 829 | end printFargStr; | ||
| 830 | |||
| 831 | public function getTypeName "Return the type name of a Type." | ||
| 832 | input DAE.Type inType; | ||
| 833 | output String outString; | ||
| 834 | algorithm | ||
| 835 | outString := matchcontinue inType | ||
| 836 | local | ||
| 837 | String n,dimstr,tystr,str; | ||
| 838 | ClassInf.State st; | ||
| 839 | DAE.Type ty,arrayty; | ||
| 840 | list<DAE.Dimension> dims; | ||
| 841 | |||
| 842 | case DAE.T_INTEGER() then "Integer"; | ||
| 843 | case DAE.T_REAL() then "Real"; | ||
| 844 | case DAE.T_STRING() then "String"; | ||
| 845 | case DAE.T_BOOL() then "Boolean"; | ||
| 846 | // BTH | ||
| 847 | case DAE.T_CLOCK() then "Clock"; | ||
| 848 | case DAE.T_COMPLEX(complexClassType = st) | ||
| 849 | algorithm | ||
| 850 | 10 | n := AbsynUtil.pathString(ClassInfUtil.getStateName(st)); | |
| 851 | then | ||
| 852 | n; | ||
| 853 | case DAE.T_SUBTYPE_BASIC(complexClassType = st) | ||
| 854 | algorithm | ||
| 855 | ✗ | n := AbsynUtil.pathString(ClassInfUtil.getStateName(st)); | |
| 856 | then | ||
| 857 | n; | ||
| 858 | case arrayty as DAE.T_ARRAY() | ||
| 859 | algorithm | ||
| 860 | ✗ | (ty,dims) := flattenArrayType(arrayty); | |
| 861 | ✗ | dimstr := ExpressionBasics.dimensionsString(dims); | |
| 862 | ✗ | tystr := getTypeName(ty); | |
| 863 | ✗ | str := stringAppendList({tystr,"[",dimstr,"]"}); | |
| 864 | then | ||
| 865 | str; | ||
| 866 | |||
| 867 | // MetaModelica type | ||
| 868 | case DAE.T_METALIST(ty = ty) | ||
| 869 | algorithm | ||
| 870 | ✗ | n := getTypeName(ty); | |
| 871 | then | ||
| 872 | n; | ||
| 873 | |||
| 874 | else "Not nameable type or no type"; | ||
| 875 | end matchcontinue; | ||
| 876 | end getTypeName; | ||
| 877 | |||
| 878 | function constStrFriendly "return the DAE.Const as a friendly string. Used for debugging." | ||
| 879 | input DAE.Const const; | ||
| 880 | output String str; | ||
| 881 | algorithm | ||
| 882 | str := match const | ||
| 883 | case DAE.C_VAR() then ""; | ||
| 884 | case DAE.C_PARAM() then "parameter "; | ||
| 885 | case DAE.C_CONST() then "constant "; | ||
| 886 | |||
| 887 | end match; | ||
| 888 | end constStrFriendly; | ||
| 889 | |||
| 890 | function dumpVarParallelismStr "Dump VarParallelism to a string" | ||
| 891 | input DAE.VarParallelism inVarParallelism; | ||
| 892 | output String outString; | ||
| 893 | algorithm | ||
| 894 | outString := match inVarParallelism | ||
| 895 | case DAE.NON_PARALLEL() then ""; | ||
| 896 | case DAE.PARGLOBAL() then "parglobal "; | ||
| 897 | case DAE.PARLOCAL() then "parlocal "; | ||
| 898 | end match; | ||
| 899 | end dumpVarParallelismStr; | ||
| 900 | |||
| 901 | function printBindingSourceStr "prints a binding source as a string" | ||
| 902 | input DAE.BindingSource bindingSource; | ||
| 903 | output String str; | ||
| 904 | algorithm | ||
| 905 | str := match bindingSource | ||
| 906 | case DAE.BINDING_FROM_DEFAULT_VALUE() then "[DEFAULT VALUE]"; | ||
| 907 | case DAE.BINDING_FROM_START_VALUE() then "[START VALUE]"; | ||
| 908 | case DAE.BINDING_FROM_RECORD_SUBMODS() then "[RECORD SUBMODS]"; | ||
| 909 | case DAE.BINDING_FROM_DERIVED_RECORD_DECL() then "[DERIVED RECORD]"; | ||
| 910 | end match; | ||
| 911 | end printBindingSourceStr; | ||
| 912 | |||
| 913 | public function flattenArrayType | ||
| 914 | "Returns the element type of a Type and the dimensions of the type." | ||
| 915 | input DAE.Type inType; | ||
| 916 | output DAE.Type outType; | ||
| 917 | output DAE.Dimensions outDimensions; | ||
| 918 | algorithm | ||
| 919 | (outType, outDimensions) := match inType | ||
| 920 | local | ||
| 921 | Type ty; | ||
| 922 | DAE.Dimensions dims; | ||
| 923 | |||
| 924 | // Array type | ||
| 925 | case DAE.T_ARRAY() | ||
| 926 | algorithm | ||
| 927 | 4381682 | (ty, dims) := flattenArrayType(inType.ty); | |
| 928 | 4381682 | dims := listAppend(inType.dims, dims); | |
| 929 | then | ||
| 930 | (ty, dims); | ||
| 931 | |||
| 932 | // Complex type extending basetype with equality constraint | ||
| 933 | case DAE.T_SUBTYPE_BASIC(equalityConstraint = SOME(_)) | ||
| 934 | then (inType, {}); | ||
| 935 | |||
| 936 | // Complex type extending basetype. | ||
| 937 | case DAE.T_SUBTYPE_BASIC() | ||
| 938 | 23 | then flattenArrayType(inType.complexType); | |
| 939 | |||
| 940 | // Element type | ||
| 941 | else (inType, {}); | ||
| 942 | end match; | ||
| 943 | end flattenArrayType; | ||
| 944 | |||
| 945 | public function getVarName "Return the name of a Var" | ||
| 946 | input DAE.Var v; | ||
| 947 | output String name; | ||
| 948 | algorithm | ||
| 949 | name := match v | ||
| 950 | case DAE.TYPES_VAR(name = name) then name; | ||
| 951 | end match; | ||
| 952 | end getVarName; | ||
| 953 | |||
| 954 | public function stripTypeVars | ||
| 955 | "Strips the attribute variables from a type, and returns both the stripped | ||
| 956 | type and the attribute variables." | ||
| 957 | input DAE.Type inType; | ||
| 958 | output DAE.Type outType; | ||
| 959 | output list<DAE.Var> outVars; | ||
| 960 | algorithm | ||
| 961 | (outType, outVars) := match inType | ||
| 962 | local | ||
| 963 | list<DAE.Var> vars, sub_vars; | ||
| 964 | DAE.Type ty; | ||
| 965 | DAE.Dimensions dims; | ||
| 966 | ClassInf.State state; | ||
| 967 | EqualityConstraint ec; | ||
| 968 | list<DAE.Type> tys; | ||
| 969 | |||
| 970 | case DAE.T_INTEGER(varLst=vars) then (DAE.T_INTEGER_DEFAULT, vars); | ||
| 971 | case DAE.T_REAL(varLst=vars) then (DAE.T_REAL_DEFAULT, vars); | ||
| 972 | case DAE.T_STRING(varLst=vars) then (DAE.T_STRING_DEFAULT, vars); | ||
| 973 | case DAE.T_BOOL(varLst=vars) then (DAE.T_BOOL_DEFAULT, vars); | ||
| 974 | ✗ | case DAE.T_TUPLE(tys, _) then (DAE.T_TUPLE(tys, NONE()), {}); | |
| 975 | |||
| 976 | case DAE.T_ARRAY(ty, dims) | ||
| 977 | algorithm | ||
| 978 | 49 | (ty, vars) := stripTypeVars(ty); | |
| 979 | 49 | then | |
| 980 | (DAE.T_ARRAY(ty, dims), vars); | ||
| 981 | |||
| 982 | case DAE.T_SUBTYPE_BASIC(state, sub_vars, ty, ec) | ||
| 983 | algorithm | ||
| 984 | ✗ | (ty, vars) := stripTypeVars(ty); | |
| 985 | ✗ | then | |
| 986 | (DAE.T_SUBTYPE_BASIC(state, sub_vars, ty, ec), vars); | ||
| 987 | |||
| 988 | else (inType, {}); | ||
| 989 | |||
| 990 | end match; | ||
| 991 | end stripTypeVars; | ||
| 992 | |||
| 993 | public function printDimensionsStr "Prints dimensions to a string" | ||
| 994 | input DAE.Dimensions dims; | ||
| 995 | output String res; | ||
| 996 | algorithm | ||
| 997 | 406 | res:=stringDelimitList(List.map(dims,ExpressionBasics.dimensionString),", "); | |
| 998 | end printDimensionsStr; | ||
| 999 | |||
| 1000 | public function printCodeTypeStr | ||
| 1001 | input DAE.CodeType ct; | ||
| 1002 | output String str; | ||
| 1003 | algorithm | ||
| 1004 | str := match ct | ||
| 1005 | case DAE.C_EXPRESSION() then "OpenModelica.Code.Expression"; | ||
| 1006 | case DAE.C_EXPRESSION_OR_MODIFICATION() then "OpenModelica.Code.ExpressionOrModification"; | ||
| 1007 | case DAE.C_MODIFICATION() then "OpenModelica.Code.Modification"; | ||
| 1008 | case DAE.C_TYPENAME() then "OpenModelica.Code.TypeName"; | ||
| 1009 | case DAE.C_VARIABLENAME() then "OpenModelica.Code.VariableName"; | ||
| 1010 | case DAE.C_VARIABLENAMES() then "OpenModelica.Code.VariableNames"; | ||
| 1011 | else "TypesDump.printCodeTypeStr failed"; | ||
| 1012 | end match; | ||
| 1013 | end printCodeTypeStr; | ||
| 1014 | |||
| 1015 | public function getDimensions | ||
| 1016 | "Returns the dimensions of a Type." | ||
| 1017 | input DAE.Type inType; | ||
| 1018 | output DAE.Dimensions outDimensions; | ||
| 1019 | algorithm | ||
| 1020 | outDimensions := match inType | ||
| 1021 | 3910759 | case DAE.T_ARRAY() then listAppend(inType.dims, getDimensions(inType.ty)); | |
| 1022 | 864 | case DAE.T_METAARRAY() then DAE.DIM_UNKNOWN() :: getDimensions(inType.ty); | |
| 1023 | 195 | case DAE.T_SUBTYPE_BASIC() then getDimensions(inType.complexType); | |
| 1024 | 118785 | case DAE.T_METATYPE() then getDimensions(inType.ty); | |
| 1025 | else {}; | ||
| 1026 | end match; | ||
| 1027 | end getDimensions; | ||
| 1028 | |||
| 1029 | annotation(__OpenModelica_Interface="frontend_dump"); | ||
| 1030 | end TypesDump; | ||
| 1031 |