OMCompiler/Compiler/Template/ExpressionDumpTpl.tpl
| 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 | package ExpressionDumpTpl | ||
| 37 | |||
| 38 | import interface ExpressionDumpTV; | ||
| 39 | import AbsynDumpTpl; | ||
| 40 | import DAEDumpTpl; | ||
| 41 | |||
| 42 | 1828640 | template dumpExp(DAE.Exp exp, String stringDelimiter) | |
| 43 | ::= | ||
| 44 | match exp | ||
| 45 | case ICONST(__) then integer | ||
| 46 | case RCONST(__) then real | ||
| 47 | case SCONST(__) then | ||
| 48 | let str = escapedString(string,false) | ||
| 49 | '<%stringDelimiter%><%str%><%stringDelimiter%>' | ||
| 50 | case BCONST(__) then bool | ||
| 51 | case CLKCONST(__) then dumpClockKind(clk, stringDelimiter) | ||
| 52 | case ENUM_LITERAL(__) then | ||
| 53 | (if typeinfo() then '/* <%index%> */') + AbsynDumpTpl.dumpPath(name) | ||
| 54 | case CREF(__) then (if typeinfo() then '/*<%unparseType(ty)%>*/ ') + dumpCref(componentRef) | ||
| 55 | case e as BINARY(__) then | ||
| 56 | let lhs_str = dumpOperand(exp1, e, true) | ||
| 57 | let rhs_str = dumpOperand(exp2, e, false) | ||
| 58 | let op_str = dumpBinOp(operator) | ||
| 59 | '<%lhs_str%> <%op_str%> <%rhs_str%>' | ||
| 60 | case e as UNARY(__) then | ||
| 61 | let exp_str = dumpOperand(exp, e, false) | ||
| 62 | let op_str = dumpUnaryOp(operator) | ||
| 63 | '<%op_str%><%exp_str%>' | ||
| 64 | case e as LBINARY(__) then | ||
| 65 | let lhs_str = dumpOperand(exp1, e, true) | ||
| 66 | let rhs_str = dumpOperand(exp2, e, false) | ||
| 67 | let op_str = dumpLogicalBinOp(operator) | ||
| 68 | '<%lhs_str%> <%op_str%> <%rhs_str%>' | ||
| 69 | case e as LUNARY(__) then | ||
| 70 | let exp_str = dumpOperand(exp, e, false) | ||
| 71 | let op_str = dumpLogicalUnaryOp(operator) | ||
| 72 | '<%op_str%> <%exp_str%>' | ||
| 73 | case e as RELATION(__) then | ||
| 74 | let lhs_str = dumpOperand(exp1, e, true) | ||
| 75 | let rhs_str = dumpOperand(exp2, e, false) | ||
| 76 | let op_str = dumpRelationOp(operator) | ||
| 77 | '<%lhs_str%> <%op_str%> <%rhs_str%>' | ||
| 78 | case IFEXP(__) then | ||
| 79 | let cond_str = dumpExp(expCond, stringDelimiter) | ||
| 80 | let then_str = dumpExp(expThen, stringDelimiter) | ||
| 81 | let else_str = dumpExp(expElse, stringDelimiter) | ||
| 82 | 'if <%cond_str%> then <%then_str%> else <%else_str%>' | ||
| 83 | case CALL(attr=attr as CALL_ATTR(builtin=true)) then | ||
| 84 | let func_str = AbsynDumpTpl.dumpPathNoQual(path) | ||
| 85 | let argl = dumpExpList(expLst, stringDelimiter, ", ") | ||
| 86 | '<%if typeinfo() then '/*<%unparseType(attr.ty)%>*/ ' %><%func_str%>(<%argl%>)' | ||
| 87 | case CALL(__) then | ||
| 88 | let func_str = AbsynDumpTpl.dumpPathNoQual(path) | ||
| 89 | let argl = dumpExpList(expLst, stringDelimiter, ", ") | ||
| 90 | '<%func_str%>(<%argl%>)' | ||
| 91 | case RECORD(__) then | ||
| 92 | let func_str = AbsynDumpTpl.dumpPathNoQual(path) | ||
| 93 | let argl = dumpExpList(exps, stringDelimiter, ", ") | ||
| 94 | '<%func_str%>(<%argl%>)' | ||
| 95 | case PARTEVALFUNCTION(__) then | ||
| 96 | let func_str = AbsynDumpTpl.dumpPathNoQual(path) | ||
| 97 | let argl = dumpExpList(expList, stringDelimiter, ", ") | ||
| 98 | 'function <%func_str%>(<%argl%>)' | ||
| 99 | case ARRAY(array={}) then | ||
| 100 | if (Flags.getConfigBool(Flags.MODELICA_OUTPUT)) then | ||
| 101 | 'fill(0,0)' | ||
| 102 | else | ||
| 103 | let expl = dumpExpList(array, stringDelimiter, ", ") | ||
| 104 | '<%if typeinfo() then (if scalar then '/* scalar <%unparseType(ty)%>*/' else '/* non-scalar <%unparseType(ty)%> */ ')%>{<%expl%>}' | ||
| 105 | case ARRAY(__) then | ||
| 106 | let expl = dumpExpList(array, stringDelimiter, ", ") | ||
| 107 | '<%if typeinfo() then (if scalar then '/* scalar <%unparseType(ty)%>*/' else '/* non-scalar <%unparseType(ty)%> */ ')%>{<%expl%>}' | ||
| 108 | |||
| 109 | case MATRIX(__) then | ||
| 110 | let mat_str = (matrix |> row => dumpExpList(row, stringDelimiter, ", ") ;separator="}, {") | ||
| 111 | '<%if typeinfo() then '/* matrix <%unparseType(ty) %> */ '%>{{<%mat_str%>}}' | ||
| 112 | case e as RANGE(__) then | ||
| 113 | let start_str = dumpOperand(start, e, false) | ||
| 114 | let step_str = match step case SOME(step) then '<%dumpOperand(step, e, false)%>:' | ||
| 115 | let stop_str = dumpOperand(stop, e, false) | ||
| 116 | '<%start_str%>:<%step_str%><%stop_str%>' | ||
| 117 | case TUPLE(__) then | ||
| 118 | let tuple_str = dumpExpList(PR, stringDelimiter, ", ") | ||
| 119 | '(<%tuple_str%>)' | ||
| 120 | case CAST(__) then | ||
| 121 | let exp_str = dumpExp(exp, stringDelimiter) | ||
| 122 | let ty_str = dumpType(ty) | ||
| 123 | '/*<%ty_str%>*/(<%exp_str%>)' | ||
| 124 | case ASUB(__) then | ||
| 125 | let needs_paren = parenthesizeSubExp(exp) | ||
| 126 | let lparen = if needs_paren then "(" | ||
| 127 | let rparen = if needs_paren then ")" | ||
| 128 | let exp_str = dumpExp(exp, stringDelimiter) | ||
| 129 | let sub_str = dumpSubscripts(sub) | ||
| 130 | '<%lparen%><%exp_str%><%rparen%><%if typeinfo() then "/*ASUB*/"%><%sub_str%>' | ||
| 131 | case TSUB(__) then | ||
| 132 | let needs_paren = parenthesizeSubExp(exp) | ||
| 133 | let lparen = if needs_paren then "(" | ||
| 134 | let rparen = if needs_paren then ")" | ||
| 135 | let exp_str = dumpExp(exp, stringDelimiter) | ||
| 136 | '<%lparen%><%exp_str%><%rparen%>[<%ix%>]' | ||
| 137 | case RSUB(__) then | ||
| 138 | let needs_paren = parenthesizeSubExp(exp) | ||
| 139 | let lparen = if needs_paren then "(" | ||
| 140 | let rparen = if needs_paren then ")" | ||
| 141 | let exp_str = dumpExp(exp, stringDelimiter) | ||
| 142 | '<%if typeinfo() then '/*RSUB: <%unparseType(ty)%>*/'%><%lparen%><%exp_str%><%rparen%>.<%fieldName%>' | ||
| 143 | case SIZE(__) then | ||
| 144 | let exp_str = dumpExp(exp, stringDelimiter) | ||
| 145 | let dim_str = match sz case SOME(dim) then ', <%dumpExp(dim, stringDelimiter)%>' | ||
| 146 | 'size(<%exp_str%><%dim_str%>)' | ||
| 147 | case CODE(__) then | ||
| 148 | let code_str = Dump.printCodeStr(code) | ||
| 149 | '$Code(<%code_str%>)' | ||
| 150 | case EMPTY(__) then | ||
| 151 | let name_str = dumpCref(name) | ||
| 152 | '<EMPTY(scope: <%scope%>, name: <%name_str%>, ty: <%tyStr%>)>' | ||
| 153 | case REDUCTION(reductionInfo = ri as REDUCTIONINFO(__)) then | ||
| 154 | let name_str = AbsynDumpTpl.dumpPathNoQual(ri.path) | ||
| 155 | let exp_str = dumpExp(expr, stringDelimiter) | ||
| 156 | let iter_str = (iterators |> it => dumpReductionIterator(it, stringDelimiter) ;separator=", ") | ||
| 157 | '<%name_str%>(<%exp_str%> for <% match ri.iterType case THREAD() then "threaded " %><%iter_str%>)' | ||
| 158 | case LIST(__) then | ||
| 159 | let expl_str = dumpExpList(valList, stringDelimiter, ", ") | ||
| 160 | 'List(<%expl_str%>)' | ||
| 161 | case CONS(__) then | ||
| 162 | let car_str = dumpExp(car, stringDelimiter) | ||
| 163 | let cdr_str = dumpExp(cdr, stringDelimiter) | ||
| 164 | 'listCons(<%car_str%>, <%cdr_str%>)' | ||
| 165 | case META_TUPLE(__) then | ||
| 166 | let tuple_str = dumpExpList(listExp, stringDelimiter, ", ") | ||
| 167 | 'Tuple(<%tuple_str%>)' | ||
| 168 | case META_OPTION(exp = SOME(exp)) then 'SOME(<%dumpExp(exp, stringDelimiter)%>)' | ||
| 169 | case META_OPTION(__) then 'NONE()' | ||
| 170 | case METARECORDCALL(__) then | ||
| 171 | let name_str = AbsynDumpTpl.dumpPath(path) | ||
| 172 | let args_str = dumpExpList(args, stringDelimiter, ", ") | ||
| 173 | '<%name_str%>(<%args_str%>)' | ||
| 174 | case MATCHEXPRESSION(__) then | ||
| 175 | let match_ty = dumpMatchType(matchType) | ||
| 176 | let inputs_str = dumpExpList(inputs, stringDelimiter, ", ") | ||
| 177 | let case_str = (cases |> c => dumpMatchCase(c) ;separator="\n") | ||
| 178 | << | ||
| 179 | <%match_ty%> (<%inputs_str%>) | ||
| 180 | <%case_str%> | ||
| 181 | end <%match_ty%> | ||
| 182 | >> | ||
| 183 | case BOX(__) then | ||
| 184 | '#(<%dumpExp(exp, stringDelimiter)%>)' | ||
| 185 | case UNBOX(__) then | ||
| 186 | 'unbox(<%dumpExp(exp, stringDelimiter)%>)' | ||
| 187 | case SHARED_LITERAL(__) then | ||
| 188 | if typeinfo() then '/* Shared literal <%index%> */ <%dumpExp(exp, stringDelimiter)%>' else dumpExp(exp, stringDelimiter) | ||
| 189 | case PATTERN(__) then (if typeinfo() then '/*pattern*/') + dumpPattern(pattern) | ||
| 190 | |||
| 191 | else errorMsg("ExpressionDumpTpl.dumpExp: Unknown expression.") | ||
| 192 | end dumpExp; | ||
| 193 | |||
| 194 | 700 | template parenthesizeSubExp(DAE.Exp exp) | |
| 195 | ::= | ||
| 196 | match exp | ||
| 197 | case ICONST(__) then "" | ||
| 198 | case RCONST(__) then "" | ||
| 199 | case SCONST(__) then "" | ||
| 200 | case BCONST(__) then "" | ||
| 201 | case ENUM_LITERAL(__) then "" | ||
| 202 | case CREF(__) then "" | ||
| 203 | case CALL(__) then "" | ||
| 204 | case ARRAY(__) then "" | ||
| 205 | case MATRIX(__) then "" | ||
| 206 | case TUPLE(__) then "" | ||
| 207 | case CAST(__) then "" | ||
| 208 | case SIZE(__) then "" | ||
| 209 | case REDUCTION(__) then "" | ||
| 210 | else "y" | ||
| 211 | end parenthesizeSubExp; | ||
| 212 | |||
| 213 | 526924 | template dumpExpList(list<DAE.Exp> expl, String stringDelimiter, String expDelimiter) | |
| 214 | ::= (expl |> exp => dumpExp(exp, stringDelimiter) ;separator=expDelimiter) | ||
| 215 | end dumpExpList; | ||
| 216 | |||
| 217 | ✗ | template dumpExpListCrefs(list<DAE.Exp> expl, String stringDelimiter, String expDelimiter) | |
| 218 | ::= (expl |> exp => dumpExpCrefs(exp, stringDelimiter) ;separator=expDelimiter) | ||
| 219 | end dumpExpListCrefs; | ||
| 220 | |||
| 221 | 16 | template dumpClockKind(DAE.ClockKind clk, String stringDelimiter) | |
| 222 | ::= | ||
| 223 | match clk | ||
| 224 | case INFERRED_CLOCK(__) then "Clock()" | ||
| 225 | case RATIONAL_CLOCK(__) then | ||
| 226 | let ic_str = dumpExp(intervalCounter, stringDelimiter) | ||
| 227 | let re_str = dumpExp(resolution, stringDelimiter) | ||
| 228 | 'Clock(<%ic_str%>, <%re_str%>)' | ||
| 229 | case REAL_CLOCK(__) then | ||
| 230 | let interval_str = dumpExp(interval, stringDelimiter) | ||
| 231 | 'Clock(<%interval_str%>)' | ||
| 232 | case EVENT_CLOCK(__) then | ||
| 233 | let condition_str = dumpExp(condition, stringDelimiter) | ||
| 234 | let si_str = dumpExp(startInterval, stringDelimiter) | ||
| 235 | 'Clock(<%condition_str%>, <%si_str%>)' | ||
| 236 | case SOLVER_CLOCK(__) then | ||
| 237 | let clk_str = dumpExp(c, stringDelimiter) | ||
| 238 | let sm_str = dumpExp(solverMethod, stringDelimiter) | ||
| 239 | 'Clock(<%clk_str%>, <%sm_str%>)' | ||
| 240 | end dumpClockKind; | ||
| 241 | |||
| 242 | |||
| 243 | 3167961 | template dumpCref(DAE.ComponentRef cref) | |
| 244 | ::= | ||
| 245 | match cref | ||
| 246 | case CREF_IDENT(__) then | ||
| 247 | let sub_str = dumpSubscripts(subscriptLst) | ||
| 248 | '<%ident%><%sub_str%>' | ||
| 249 | case CREF_QUAL(__) then | ||
| 250 | let sub_str = dumpSubscripts(subscriptLst) | ||
| 251 | let cref_str = dumpCref(componentRef) | ||
| 252 | if (Flags.getConfigBool(Flags.MODELICA_OUTPUT)) then | ||
| 253 | '<%ident%><%sub_str%>__<%cref_str%>' | ||
| 254 | else | ||
| 255 | '<%ident%><%sub_str%>.<%cref_str%>' | ||
| 256 | case WILD() then '_' | ||
| 257 | case OPTIMICA_ATTR_INST_CREF(__) then | ||
| 258 | '<%dumpCref(componentRef)%>(<%instant%>)' | ||
| 259 | else errorMsg("ExpressionDumpTpl.dumpCref: unknown cref") | ||
| 260 | end dumpCref; | ||
| 261 | |||
| 262 | 946951 | template dumpSubscripts(list<DAE.Subscript> subscripts) | |
| 263 | ::= | ||
| 264 | if subscripts then | ||
| 265 | if (Flags.getConfigBool(Flags.MODELICA_OUTPUT)) then | ||
| 266 | let sub_str = (subscripts |> sub => dumpSubscript(sub) ;separator="_") | ||
| 267 | '_<%sub_str%>' | ||
| 268 | else | ||
| 269 | let sub_str = (subscripts |> sub => dumpSubscript(sub) ;separator=",") | ||
| 270 | '[<%sub_str%>]' | ||
| 271 | end dumpSubscripts; | ||
| 272 | |||
| 273 | 1067854 | template dumpSubscript(DAE.Subscript subscript) | |
| 274 | ::= | ||
| 275 | match subscript | ||
| 276 | case WHOLEDIM(__) then ':' | ||
| 277 | case SLICE(__) then dumpExp(exp, "\"") | ||
| 278 | case INDEX(__) then dumpExp(exp, "\"") | ||
| 279 | case WHOLE_NONEXP(__) then dumpExp(exp, "\"") | ||
| 280 | end dumpSubscript; | ||
| 281 | |||
| 282 | 167 | template dumpReductionIterator(DAE.ReductionIterator iterator, String stringDelimiter) | |
| 283 | ::= | ||
| 284 | match iterator | ||
| 285 | case REDUCTIONITER(guardExp = NONE()) then | ||
| 286 | let exp_str = dumpExp(exp, stringDelimiter) | ||
| 287 | '<%id%> in <%exp_str%>' | ||
| 288 | case REDUCTIONITER(guardExp = SOME(gexp)) then | ||
| 289 | let exp_str = dumpExp(exp, stringDelimiter) | ||
| 290 | let guard_str = dumpExp(gexp, stringDelimiter) | ||
| 291 | '<%id%> guard <%guard_str%> in <%exp_str%>' | ||
| 292 | end dumpReductionIterator; | ||
| 293 | |||
| 294 | 2665662 | template dumpOperand(DAE.Exp operand, DAE.Exp operation, Boolean lhs) | |
| 295 | ::= | ||
| 296 | let op_str = dumpExp(operand, "\"") | ||
| 297 | if shouldParenthesize(operand, operation, lhs) then | ||
| 298 | '(<%op_str%>)' | ||
| 299 | else | ||
| 300 | op_str | ||
| 301 | end dumpOperand; | ||
| 302 | |||
| 303 | 1068749 | template dumpBinOp(DAE.Operator op) | |
| 304 | ::= | ||
| 305 | if typeinfo() then | ||
| 306 | match op | ||
| 307 | case ADD(__) then '+' | ||
| 308 | case SUB(__) then '-' | ||
| 309 | case MUL(__) then '*' | ||
| 310 | case DIV(__) then '/' | ||
| 311 | case POW(__) then '^' | ||
| 312 | case ADD_ARR(__) then '+ /* ADD_ARR */' | ||
| 313 | case SUB_ARR(__) then '- /* SUB_ARR */' | ||
| 314 | case MUL_ARR(__) then '.* /* MUL_ARR */' | ||
| 315 | case DIV_ARR(__) then './ /* DIV_ARR */' | ||
| 316 | case POW_ARR(__) then '^ /* POW_ARR */' | ||
| 317 | case POW_ARR2(__) then '.^ /* POW_ARR2 */' | ||
| 318 | case MUL_ARRAY_SCALAR(__) then '* /* MUL_ARR_SCA */' | ||
| 319 | case ADD_ARRAY_SCALAR(__) then '.+ /* ADD_ARR_SCA */' | ||
| 320 | case SUB_SCALAR_ARRAY(__) then '.- /* SUB_SCA_ARR */' | ||
| 321 | case POW_SCALAR_ARRAY(__) then '.^ /* POW_SCA_ARR */' | ||
| 322 | case POW_ARRAY_SCALAR(__) then '.^ /* POW_ARR_SCA */' | ||
| 323 | case MUL_SCALAR_PRODUCT(__) then '* /* MUL_SCA_PRO */' | ||
| 324 | case MUL_MATRIX_PRODUCT(__) then '* /* MUL_MAT_PRO */' | ||
| 325 | case DIV_SCALAR_ARRAY(__) then '/ /* DIV_SCA_ARR */' | ||
| 326 | case DIV_ARRAY_SCALAR(__) then '/ /* DIV_ARR_SCA */' | ||
| 327 | else errorMsg("ExpressionDumpTpl.dumpBinOp: Unknown operator.") | ||
| 328 | else | ||
| 329 | match op | ||
| 330 | case ADD(__) then '+' | ||
| 331 | case SUB(__) then '-' | ||
| 332 | case MUL(__) then '*' | ||
| 333 | case DIV(__) then '/' | ||
| 334 | case POW(__) then '^' | ||
| 335 | case ADD_ARR(__) then '+' | ||
| 336 | case SUB_ARR(__) then '-' | ||
| 337 | case MUL_ARR(__) then '.*' | ||
| 338 | case DIV_ARR(__) then './' | ||
| 339 | case POW_ARR(__) then '^' | ||
| 340 | case POW_ARR2(__) then '.^' | ||
| 341 | case MUL_ARRAY_SCALAR(__) then '*' | ||
| 342 | case ADD_ARRAY_SCALAR(__) then '.+' | ||
| 343 | case SUB_SCALAR_ARRAY(__) then '.-' | ||
| 344 | case POW_SCALAR_ARRAY(__) then '.^' | ||
| 345 | case POW_ARRAY_SCALAR(__) then '.^' | ||
| 346 | case MUL_SCALAR_PRODUCT(__) then '*' | ||
| 347 | case MUL_MATRIX_PRODUCT(__) then '*' | ||
| 348 | case DIV_SCALAR_ARRAY(__) then './' | ||
| 349 | case DIV_ARRAY_SCALAR(__) then '/' | ||
| 350 | else errorMsg("ExpressionDumpTpl.dumpBinOp: Unknown operator.") | ||
| 351 | end dumpBinOp; | ||
| 352 | |||
| 353 | 54437 | template dumpUnaryOp(DAE.Operator op) | |
| 354 | ::= | ||
| 355 | match op | ||
| 356 | case UMINUS(__) then '-' | ||
| 357 | case UMINUS_ARR(__) then '-' | ||
| 358 | case ADD(__) then '+' | ||
| 359 | else errorMsg("ExpressionDumpTpl.dumpUnaryOp: Unknown operator.") | ||
| 360 | end dumpUnaryOp; | ||
| 361 | |||
| 362 | 50618 | template dumpLogicalBinOp(DAE.Operator op) | |
| 363 | ::= | ||
| 364 | match op | ||
| 365 | case DAE.AND(__) then 'and' | ||
| 366 | case DAE.OR(__) then 'or' | ||
| 367 | else errorMsg("ExpressionDumpTpl.dumpLogicalBinOp: Unknown operator.") | ||
| 368 | end dumpLogicalBinOp; | ||
| 369 | |||
| 370 | 2749 | template dumpLogicalUnaryOp(DAE.Operator op) | |
| 371 | ::= | ||
| 372 | match op | ||
| 373 | case DAE.NOT(__) then 'not' | ||
| 374 | else errorMsg("ExpressionDumpTpl.dumpLogicalUnaryOp: Unknown operator.") | ||
| 375 | end dumpLogicalUnaryOp; | ||
| 376 | |||
| 377 | 100933 | template dumpRelationOp(DAE.Operator op) | |
| 378 | ::= | ||
| 379 | match op | ||
| 380 | case LESS(__) then "<" | ||
| 381 | case LESSEQ(__) then "<=" | ||
| 382 | case GREATER(__) then ">" | ||
| 383 | case GREATEREQ(__) then ">=" | ||
| 384 | case EQUAL(__) then "==" | ||
| 385 | case NEQUAL(__) then "<>" | ||
| 386 | case USERDEFINED(__) then "USERDEFINED" | ||
| 387 | else errorMsg("ExpressionDumpTpl.dumpRelationOp: Unknown operator.") | ||
| 388 | end dumpRelationOp; | ||
| 389 | |||
| 390 | 6222 | template dumpType(DAE.Type ty) | |
| 391 | ::= | ||
| 392 | match ty | ||
| 393 | case T_INTEGER(__) then 'Integer' | ||
| 394 | case T_REAL(__) then 'Real' | ||
| 395 | case T_BOOL(__) then 'Bool' | ||
| 396 | case T_STRING(__) then 'String' | ||
| 397 | case T_ENUMERATION(__) then AbsynDumpTpl.dumpPath(path) | ||
| 398 | case T_ARRAY(__) then | ||
| 399 | let dim_str = dumpDimensions(dims) | ||
| 400 | let ty_str = dumpType(ty) | ||
| 401 | '<%ty_str%>[<%dim_str%>]' | ||
| 402 | case T_COMPLEX(__) then dumpClassState(complexClassType) | ||
| 403 | case T_SUBTYPE_BASIC(__) then dumpClassState(complexClassType) | ||
| 404 | case T_FUNCTION(__) then | ||
| 405 | let arg_str = (funcArg |> arg => dumpFuncArg(arg) ;separator=", ") | ||
| 406 | let ret_str = dumpType(funcResultType) | ||
| 407 | '<function>(<%arg_str%>) => <%ret_str%>' | ||
| 408 | case T_FUNCTION_REFERENCE_VAR(__) then dumpType(functionType) | ||
| 409 | case T_FUNCTION_REFERENCE_FUNC(__) then dumpType(functionType) | ||
| 410 | case T_TUPLE(__) then | ||
| 411 | let ty_str = (types |> ty => dumpType(ty) ;separator=", ") | ||
| 412 | '(<%ty_str%>' | ||
| 413 | case T_CODE(__) then '#T_CODE#' | ||
| 414 | case T_METALIST(__) then | ||
| 415 | let ty_str = dumpType(ty) | ||
| 416 | 'list<<%ty_str%>>' | ||
| 417 | case T_METATUPLE(__) then | ||
| 418 | let ty_str = (types |> ty => dumpType(ty) ;separator=", ") | ||
| 419 | 'tuple<<%ty_str%>>' | ||
| 420 | case T_METAOPTION(__) then | ||
| 421 | let ty_str = dumpType(ty) | ||
| 422 | 'Option<<%ty_str%>>' | ||
| 423 | case T_METAUNIONTYPE(__) then AbsynDumpTpl.dumpPath(path) | ||
| 424 | case T_METARECORD(__) then AbsynDumpTpl.dumpPath(path) | ||
| 425 | case T_METAARRAY(__) then | ||
| 426 | let ty_str = dumpType(ty) | ||
| 427 | 'array<<%ty_str%>>' | ||
| 428 | case T_METABOXED(__) then dumpType(ty) | ||
| 429 | case T_METAPOLYMORPHIC(__) then 'polymorphic<<%name%>>' | ||
| 430 | case T_METATYPE(__) then dumpType(ty) | ||
| 431 | case T_UNKNOWN(__) then '#T_UNKNOWN#' | ||
| 432 | case T_ANYTYPE(__) then 'Any' | ||
| 433 | case T_NORETCALL(__) then '#T_NORETCALL#' | ||
| 434 | end dumpType; | ||
| 435 | |||
| 436 | ✗ | template dumpFuncArg(DAE.FuncArg arg) | |
| 437 | ::= match arg case arg as FUNCARG() then arg.name | ||
| 438 | end dumpFuncArg; | ||
| 439 | |||
| 440 | 22 | template dumpDimensions(DAE.Dimensions dims) | |
| 441 | ::= (dims |> dim => dumpDimension(dim) ;separator=", ") | ||
| 442 | end dumpDimensions; | ||
| 443 | |||
| 444 | 20 | template dumpDimension(DAE.Dimension dim) | |
| 445 | ::= | ||
| 446 | match dim | ||
| 447 | case DIM_INTEGER(__) then integer | ||
| 448 | case DIM_ENUM(__) then AbsynDumpTpl.dumpPath(enumTypeName) | ||
| 449 | case DIM_EXP(__) then dumpExp(exp, "\"") | ||
| 450 | case DIM_UNKNOWN(__) then ':' | ||
| 451 | end dumpDimension; | ||
| 452 | |||
| 453 | 8 | template dumpClassState(ClassInf.State state) | |
| 454 | ::= AbsynDumpTpl.dumpPath(ClassInfUtil.getStateName(state)) | ||
| 455 | end dumpClassState; | ||
| 456 | |||
| 457 | 1 | template dumpMatchType(DAE.MatchType ty) | |
| 458 | ::= | ||
| 459 | match ty | ||
| 460 | case MATCHCONTINUE() then "matchcontinue" | ||
| 461 | case MATCH(switch = NONE()) then "match" | ||
| 462 | case MATCH(switch = SOME(_)) then "match /* switch */" | ||
| 463 | end dumpMatchType; | ||
| 464 | |||
| 465 | 2 | template dumpMatchCase(DAE.MatchCase mcase) | |
| 466 | ::= | ||
| 467 | match mcase | ||
| 468 | case CASE(body = {}, result = SOME(result)) then | ||
| 469 | let pat_str = dumpPatterns(patterns) | ||
| 470 | let res_str = dumpExp(result, "\"") | ||
| 471 | 'case (<%pat_str%>) then <%res_str%>;' | ||
| 472 | case CASE(body = {}, result = NONE()) then | ||
| 473 | let pat_str = dumpPatterns(patterns) | ||
| 474 | 'case (<%pat_str%>) then fail();' | ||
| 475 | case CASE(result = SOME(result)) then | ||
| 476 | let pat_str = dumpPatterns(patterns) | ||
| 477 | let res_str = dumpExp(result, "\"") | ||
| 478 | let body_str = DAEDumpTpl.dumpStatements(body) | ||
| 479 | << | ||
| 480 | case (<%pat_str%>) | ||
| 481 | algorithm | ||
| 482 | <%body_str%> | ||
| 483 | then | ||
| 484 | <%res_str%>; | ||
| 485 | >> | ||
| 486 | case CASE(__) then | ||
| 487 | let pat_str = dumpPatterns(patterns) | ||
| 488 | let body_str = DAEDumpTpl.dumpStatements(body) | ||
| 489 | << | ||
| 490 | case (<%pat_str%>) | ||
| 491 | algorithm | ||
| 492 | <%body_str%> | ||
| 493 | then | ||
| 494 | fail(); | ||
| 495 | >> | ||
| 496 | end dumpMatchCase; | ||
| 497 | |||
| 498 | 3 | template dumpPatterns(list<DAE.Pattern> patterns) | |
| 499 | ::= (patterns |> pat => dumpPattern(pat) ;separator=", ") | ||
| 500 | end dumpPatterns; | ||
| 501 | |||
| 502 | 2 | template dumpPattern(DAE.Pattern pattern) | |
| 503 | ::= | ||
| 504 | match pattern | ||
| 505 | case PAT_WILD() then "_" | ||
| 506 | case PAT_AS(pat = PAT_WILD()) then id | ||
| 507 | case PAT_AS_FUNC_PTR(pat = PAT_WILD()) then id | ||
| 508 | case PAT_SOME(__) then 'SOME(<%dumpPattern(pat)%>)' | ||
| 509 | case PAT_META_TUPLE(__) then '(<%dumpPatterns(patterns)%>)' | ||
| 510 | case PAT_CALL_TUPLE(__) then '(<%dumpPatterns(patterns)%>)' | ||
| 511 | case PAT_CALL(__) then | ||
| 512 | let name_str = AbsynDumpTpl.dumpPath(name) | ||
| 513 | let pat_str = dumpPatterns(patterns) | ||
| 514 | '<%name_str%>(<%pat_str%>)' | ||
| 515 | case PAT_CALL_NAMED(__) then | ||
| 516 | let name_str = AbsynDumpTpl.dumpPath(name) | ||
| 517 | let pat_str = (patterns |> pat => dumpNamedPattern(pat) ;separator=", ") | ||
| 518 | '<%name_str%>(<%pat_str%>)' | ||
| 519 | case PAT_CONS(__) then '<%dumpPattern(head)%>::<%dumpPattern(tail)%>' | ||
| 520 | case PAT_CONSTANT(__) then dumpExp(exp, "\"") | ||
| 521 | case PAT_AS(__) then '<%id%> as <%dumpPattern(pat)%>' | ||
| 522 | case PAT_AS_FUNC_PTR(__) then '<%id%> as <%dumpPattern(pat)%>' | ||
| 523 | else "*PATTERN*" | ||
| 524 | end dumpPattern; | ||
| 525 | |||
| 526 | ✗ | template dumpNamedPattern(tuple<Pattern, String, Type> pattern) | |
| 527 | ::= match pattern case (pat, id, _) then '<%id%> = <%dumpPattern(pat)%>' | ||
| 528 | end dumpNamedPattern; | ||
| 529 | |||
| 530 | |||
| 531 | |||
| 532 | ✗ | template dumpExpCrefs(DAE.Exp exp, String stringDelimiter) | |
| 533 | ::= | ||
| 534 | match exp | ||
| 535 | case ICONST(__) then '' | ||
| 536 | case RCONST(__) then '' | ||
| 537 | case SCONST(__) then '' | ||
| 538 | case BCONST(__) then '' | ||
| 539 | case ENUM_LITERAL(__) then AbsynDumpTpl.dumpPath(name) | ||
| 540 | case CREF(__) then dumpCref(componentRef) | ||
| 541 | case e as BINARY(__) then | ||
| 542 | let lhs_str = dumpExpCrefs(exp1, stringDelimiter) | ||
| 543 | let rhs_str = dumpExpCrefs(exp2, stringDelimiter) | ||
| 544 | '<%lhs_str%> <%rhs_str%>' | ||
| 545 | case e as UNARY(__) then | ||
| 546 | let exp_str = dumpOperand(exp, e, false) | ||
| 547 | let op_str = dumpUnaryOp(operator) | ||
| 548 | '<%op_str%><%exp_str%>' | ||
| 549 | case e as LBINARY(__) then | ||
| 550 | let lhs_str = dumpExpCrefs(exp1, stringDelimiter) | ||
| 551 | let rhs_str = dumpExpCrefs(exp2, stringDelimiter) | ||
| 552 | '<%lhs_str%> <%rhs_str%>' | ||
| 553 | case e as LUNARY(__) then | ||
| 554 | let lhs_str = dumpExpCrefs(exp, stringDelimiter) | ||
| 555 | '<%lhs_str%>' | ||
| 556 | case e as RELATION(__) then | ||
| 557 | let lhs_str = dumpExpCrefs(exp1, stringDelimiter) | ||
| 558 | let rhs_str = dumpExpCrefs(exp2, stringDelimiter) | ||
| 559 | '<%lhs_str%> <%rhs_str%>' | ||
| 560 | case IFEXP(__) then | ||
| 561 | let cond_str = dumpExpCrefs(expCond, stringDelimiter) | ||
| 562 | let then_str = dumpExpCrefs(expThen, stringDelimiter) | ||
| 563 | let else_str = dumpExpCrefs(expElse, stringDelimiter) | ||
| 564 | '<%cond_str%> <%then_str%> <%else_str%>' | ||
| 565 | case CALL(attr=attr as CALL_ATTR(builtin=true)) then | ||
| 566 | let argl = dumpExpListCrefs(expLst, stringDelimiter, " ") | ||
| 567 | '<%argl%>' | ||
| 568 | case CALL(__) then | ||
| 569 | let argl = dumpExpListCrefs(expLst, stringDelimiter, " ") | ||
| 570 | '<%argl%>' | ||
| 571 | case PARTEVALFUNCTION(__) then | ||
| 572 | let func_str = AbsynDumpTpl.dumpPathNoQual(path) | ||
| 573 | let argl = dumpExpList(expList, stringDelimiter, ", ") | ||
| 574 | 'function <%func_str%>(<%argl%>)' | ||
| 575 | case ARRAY(__) then | ||
| 576 | let expl = dumpExpList(array, stringDelimiter, ", ") | ||
| 577 | '<%if typeinfo() then (if scalar then "/* scalar */ " else "/* non-scalar */ ")%>{<%expl%>}' | ||
| 578 | case MATRIX(__) then | ||
| 579 | let mat_str = (matrix |> row => dumpExpList(row, stringDelimiter, ", ") ;separator="}, {") | ||
| 580 | '<%if typeinfo() then '/* matrix <%unparseType(ty) %> */ '%>{{<%mat_str%>}}' | ||
| 581 | case e as RANGE(__) then | ||
| 582 | let start_str = dumpOperand(start, e, false) | ||
| 583 | let step_str = match step case SOME(step) then '<%dumpOperand(step, e, false)%>:' | ||
| 584 | let stop_str = dumpOperand(stop, e, false) | ||
| 585 | '<%start_str%>:<%step_str%><%stop_str%>' | ||
| 586 | case TUPLE(PR={}) then "" | ||
| 587 | case TUPLE(__) then | ||
| 588 | let tuple_str = dumpExpList(PR, stringDelimiter, ", ") | ||
| 589 | '(<%tuple_str%>)' | ||
| 590 | case CAST(__) then | ||
| 591 | let exp_str = dumpExpCrefs(exp, stringDelimiter) | ||
| 592 | '(<%exp_str%>)' | ||
| 593 | case ASUB(__) then | ||
| 594 | let needs_paren = parenthesizeSubExp(exp) | ||
| 595 | let lparen = if needs_paren then "(" | ||
| 596 | let rparen = if needs_paren then ")" | ||
| 597 | let exp_str = dumpExp(exp, stringDelimiter) | ||
| 598 | let sub_str = dumpSubscripts(sub) | ||
| 599 | '<%lparen%><%exp_str%><%rparen%><%sub_str%>' | ||
| 600 | case TSUB(__) then | ||
| 601 | let needs_paren = parenthesizeSubExp(exp) | ||
| 602 | let lparen = if needs_paren then "(" | ||
| 603 | let rparen = if needs_paren then ")" | ||
| 604 | let exp_str = dumpExp(exp, stringDelimiter) | ||
| 605 | '<%lparen%><%exp_str%><%rparen%>[<%ix%>]' | ||
| 606 | case SIZE(__) then | ||
| 607 | let exp_str = dumpExp(exp, stringDelimiter) | ||
| 608 | let dim_str = match sz case SOME(dim) then ', <%dumpExp(dim, stringDelimiter)%>' | ||
| 609 | 'size(<%exp_str%><%dim_str%>)' | ||
| 610 | case CODE(__) then | ||
| 611 | let code_str = Dump.printCodeStr(code) | ||
| 612 | '$Code(<%code_str%>)' | ||
| 613 | case EMPTY(__) then | ||
| 614 | let name_str = dumpCref(name) | ||
| 615 | '<EMPTY(scope: <%scope%>, name: <%name_str%>, ty: <%tyStr%>)>' | ||
| 616 | case REDUCTION(reductionInfo = ri as REDUCTIONINFO(path = name)) then | ||
| 617 | let name_str = AbsynDumpTpl.dumpPathNoQual(name) | ||
| 618 | let exp_str = dumpExp(expr, stringDelimiter) | ||
| 619 | let iter_str = (iterators |> it => dumpReductionIterator(it, stringDelimiter) ;separator=", ") | ||
| 620 | '<%name_str%>(<%exp_str%> for <% match ri.iterType case THREAD() then "threaded " %><%iter_str%>)' | ||
| 621 | case LIST(__) then | ||
| 622 | let expl_str = dumpExpList(valList, stringDelimiter, ", ") | ||
| 623 | 'List(<%expl_str%>)' | ||
| 624 | case CONS(__) then | ||
| 625 | let car_str = dumpExp(car, stringDelimiter) | ||
| 626 | let cdr_str = dumpExp(cdr, stringDelimiter) | ||
| 627 | 'listCons(<%car_str%>, <%cdr_str%>)' | ||
| 628 | case META_TUPLE(__) then | ||
| 629 | let tuple_str = dumpExpList(listExp, stringDelimiter, ", ") | ||
| 630 | 'Tuple(<%tuple_str%>)' | ||
| 631 | case META_OPTION(exp = SOME(exp)) then 'SOME(<%dumpExp(exp, stringDelimiter)%>)' | ||
| 632 | case META_OPTION(__) then 'NONE()' | ||
| 633 | case METARECORDCALL(__) then | ||
| 634 | let name_str = AbsynDumpTpl.dumpPath(path) | ||
| 635 | let args_str = dumpExpList(args, stringDelimiter, ", ") | ||
| 636 | '<%name_str%>(<%args_str%>)' | ||
| 637 | case MATCHEXPRESSION(__) then | ||
| 638 | let match_ty = dumpMatchType(matchType) | ||
| 639 | let inputs_str = dumpExpList(inputs, stringDelimiter, ", ") | ||
| 640 | let case_str = (cases |> c => dumpMatchCase(c) ;separator="\n") | ||
| 641 | << | ||
| 642 | <%match_ty%> (<%inputs_str%>) | ||
| 643 | <%case_str%> | ||
| 644 | end <%match_ty%> | ||
| 645 | >> | ||
| 646 | case BOX(__) then | ||
| 647 | '#(<%dumpExp(exp, stringDelimiter)%>)' | ||
| 648 | case UNBOX(__) then | ||
| 649 | 'unbox(<%dumpExp(exp, stringDelimiter)%>)' | ||
| 650 | case SHARED_LITERAL(__) then | ||
| 651 | dumpExpCrefs(exp, stringDelimiter) | ||
| 652 | case PATTERN(__) then dumpPattern(pattern) | ||
| 653 | else errorMsg("ExpressionDumpTpl.dumpExp: Unknown expression.") | ||
| 654 | end dumpExpCrefs; | ||
| 655 | |||
| 656 | |||
| 657 | ✗ | template errorMsg(String errMessage) | |
| 658 | ::= | ||
| 659 | let() = Tpl.addTemplateError(errMessage) | ||
| 660 | << | ||
| 661 | <%errMessage%> | ||
| 662 | >> | ||
| 663 | end errorMsg; | ||
| 664 | |||
| 665 | |||
| 666 | 4 | template dumpConstraints(list<DAE.Constraint> cons) | |
| 667 | ::= | ||
| 668 | (cons |> con => (match con | ||
| 669 | case con as DAE.CONSTRAINT_DT(constraint = c, localCon=true) then | ||
| 670 | '<%dumpExp(c,"\"")%> (local)' | ||
| 671 | case con as DAE.CONSTRAINT_DT(constraint = c, localCon=false) then | ||
| 672 | '<%dumpExp(c,"\"")%> (global)' | ||
| 673 | ) | ||
| 674 | ;separator=", ") | ||
| 675 | end dumpConstraints; | ||
| 676 | |||
| 677 | annotation(__OpenModelica_Interface="frontend_dump"); | ||
| 678 | end ExpressionDumpTpl; | ||
| 679 |