OMCompiler/Compiler/Template/DAEDumpTpl.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 DAEDumpTpl | ||
| 37 | |||
| 38 | import interface DAEDumpTV; | ||
| 39 | import AbsynDumpTpl; | ||
| 40 | import SCodeDumpTpl; | ||
| 41 | |||
| 42 | /***************************************************************************** | ||
| 43 | * SECTION: MAIN TEMPLATE FUNCTION * | ||
| 44 | *****************************************************************************/ | ||
| 45 | 1026 | template dumpDAE(list<DAEDumpTypes.compWithSplitElements> fixedDaeList, DAEDumpTypes.functionList funLists) | |
| 46 | ::= | ||
| 47 | let comp_str =(fixedDaeList |> dae => dumpComp(dae) ;separator="\n") | ||
| 48 | let fun_str = match funLists case FUNCTION_LIST(__) then dumpFunctions(funcs) | ||
| 49 | if fun_str then | ||
| 50 | << | ||
| 51 | <%fun_str%><%\n\n%> | ||
| 52 | <%comp_str%> | ||
| 53 | >> | ||
| 54 | else | ||
| 55 | << | ||
| 56 | <%comp_str%> | ||
| 57 | >> | ||
| 58 | end dumpDAE; | ||
| 59 | |||
| 60 | 1026 | template dumpComp(DAEDumpTypes.compWithSplitElements fixedDae) | |
| 61 | ::= | ||
| 62 | match fixedDae case COMP_WITH_SPLIT(__) then | ||
| 63 | let cmt_str = dumpCommentOpt(comment) | ||
| 64 | let ann_str = dumpClassAnnotation(comment) | ||
| 65 | let name_rep = if (Flags.getConfigBool(Flags.MODELICA_OUTPUT)) then System.stringReplace(name, ".","__") else name | ||
| 66 | << | ||
| 67 | class <%name_rep%><%cmt_str%> | ||
| 68 | <%dumpCompStream(spltElems)%> | ||
| 69 | <%if ann_str then " "%><%ann_str%> | ||
| 70 | end <%name_rep%>;<%\n%> | ||
| 71 | >> | ||
| 72 | end dumpComp; | ||
| 73 | |||
| 74 | 1029 | template dumpCompStream(DAEDumpTypes.splitElements elems) | |
| 75 | ::= | ||
| 76 | match elems | ||
| 77 | case SPLIT_ELEMENTS(__) then | ||
| 78 | let var_str = dumpVars(v) | ||
| 79 | let ieq_str = dumpInitialEquationSection(ie) | ||
| 80 | let ial_str = dumpInitialAlgorithmSection(ia) | ||
| 81 | let eq_str = dumpEquationSection(e) | ||
| 82 | let al_str = dumpAlgorithmSection(a) | ||
| 83 | let sm_str = (sm |> flatSM => dumpStateMachineSection(flatSM) ;separator="\n") | ||
| 84 | << | ||
| 85 | <%var_str%> | ||
| 86 | <%sm_str%> | ||
| 87 | <%ieq_str%> | ||
| 88 | <%ial_str%> | ||
| 89 | <%eq_str%> | ||
| 90 | <%al_str%> | ||
| 91 | >> | ||
| 92 | end dumpCompStream; | ||
| 93 | |||
| 94 | /***************************************************************************** | ||
| 95 | * SECTION: FUNCTION SECTION * | ||
| 96 | *****************************************************************************/ | ||
| 97 | 1026 | template dumpFunctions(list<DAE.Function> funcs) | |
| 98 | ::= | ||
| 99 | (funcs |> func => dumpFunction(func) ;separator="\n\n") | ||
| 100 | end dumpFunctions; | ||
| 101 | |||
| 102 | 492 | template dumpFunction(DAE.Function function) | |
| 103 | ::= | ||
| 104 | match function | ||
| 105 | case FUNCTION(functions = {FUNCTION_PARTIAL_DERIVATIVE(__)}) then | ||
| 106 | let fn_name = AbsynDumpTpl.dumpPathNoQual(path) | ||
| 107 | let cmt_str = dumpCommentOpt(comment) | ||
| 108 | let ann_str = dumpClassAnnotation(comment) | ||
| 109 | let impure_str = if isImpure then 'impure ' | ||
| 110 | << | ||
| 111 | <%impure_str%>function <%fn_name%> = <%dumpFunctionDefinitions(functions)%><%cmt_str%><%if ann_str then " "%><%ann_str%>; | ||
| 112 | >> | ||
| 113 | case FUNCTION(__) then | ||
| 114 | let cmt_str = dumpCommentOpt(comment) | ||
| 115 | let ann_str = dumpClassAnnotation(comment) | ||
| 116 | let impure_str = if isImpure then 'impure ' | ||
| 117 | << | ||
| 118 | <%impure_str%>function <%AbsynDumpTpl.dumpPathNoQual(path)%><%cmt_str%> | ||
| 119 | <%dumpFunctionDefinitions(functions)%> | ||
| 120 | <%if ann_str then " "%><%ann_str%> | ||
| 121 | end <%AbsynDumpTpl.dumpPathNoQual(path)%>; | ||
| 122 | >> | ||
| 123 | case RECORD_CONSTRUCTOR(__) then | ||
| 124 | if (Flags.isSet(Flags.PRINT_RECORD_TYPES)) then | ||
| 125 | << | ||
| 126 | <%dumpRecordType(type_)%> | ||
| 127 | >> | ||
| 128 | else | ||
| 129 | << | ||
| 130 | function <%AbsynDumpTpl.dumpPathNoQual(path)%> "Automatically generated record constructor for <%AbsynDumpTpl.dumpPathNoQual(path)%>" | ||
| 131 | <%dumpRecordInputVarStr(type_)%> | ||
| 132 | output <%dumpPathLastIndent(path)%> res; | ||
| 133 | end <%AbsynDumpTpl.dumpPathNoQual(path)%>; | ||
| 134 | >> | ||
| 135 | end dumpFunction; | ||
| 136 | |||
| 137 | 493 | template dumpFunctionDefinitions(list<FunctionDefinition> functions) | |
| 138 | ::= | ||
| 139 | (functions |> func => dumpFunctionDefinition(func) ;separator="\n") | ||
| 140 | |||
| 141 | end dumpFunctionDefinitions; | ||
| 142 | |||
| 143 | 444 | template dumpFunctionDefinition(DAE.FunctionDefinition functions) | |
| 144 | ::= | ||
| 145 | match functions | ||
| 146 | case FUNCTION_DEF(__) then | ||
| 147 | << | ||
| 148 | <%dumpFunctionBody(body)%> | ||
| 149 | >> | ||
| 150 | case FUNCTION_EXT(__) then | ||
| 151 | << | ||
| 152 | <%dumpFunctionBody(body)%><%\n%><%\n%> | ||
| 153 | <%dumpExternalDecl(externalDecl)%> | ||
| 154 | >> | ||
| 155 | case FUNCTION_DER_MAPPER(__) then '' | ||
| 156 | case FUNCTION_INVERSE(__) then '' | ||
| 157 | case FUNCTION_PARTIAL_DERIVATIVE(__) then | ||
| 158 | let vars = (derivedVars |> var => var ;separator=", ") | ||
| 159 | << | ||
| 160 | der(<%AbsynDumpTpl.dumpPathNoQual(derivedFunction)%>, <%vars%>) | ||
| 161 | >> | ||
| 162 | end dumpFunctionDefinition; | ||
| 163 | |||
| 164 | 48 | template dumpExternalDecl(DAE.ExternalDecl externalDecl) | |
| 165 | ::= | ||
| 166 | match externalDecl | ||
| 167 | case EXTERNALDECL(__) then | ||
| 168 | let func_name_str = name | ||
| 169 | let func_args_str = dumpExtArgs(args) | ||
| 170 | let func_str = if func_name_str then ' <%func_name_str%>(<%func_args_str%>)' | ||
| 171 | let ext_output_str = '<%dumpExtArg(returnArg)%>' | ||
| 172 | let output_str = if ext_output_str then ' <%ext_output_str%> =' | ||
| 173 | let lang_str = language | ||
| 174 | let ann_str = match ann case SOME(annotation) then ' <%dumpAnnotation(annotation)%>' | ||
| 175 | ' external "<%lang_str%>"<%output_str%><%func_str%><%ann_str%>;' | ||
| 176 | end dumpExternalDecl; | ||
| 177 | |||
| 178 | 48 | template dumpExtArgs(list<ExtArg> args) | |
| 179 | ::= | ||
| 180 | (args |> arg => dumpExtArg(arg) ;separator=", ") | ||
| 181 | end dumpExtArgs; | ||
| 182 | |||
| 183 | 99 | template dumpExtArg(DAE.ExtArg arg) | |
| 184 | ::= | ||
| 185 | match arg | ||
| 186 | case EXTARG(__) then dumpCref(componentRef) | ||
| 187 | case EXTARGEXP(__) then dumpExp(exp) | ||
| 188 | case EXTARGSIZE(__) then 'size(<%dumpCref(componentRef)%>, <%dumpExp(exp)%>)' | ||
| 189 | end dumpExtArg; | ||
| 190 | |||
| 191 | 141 | template dumpRecordInputVarStr(Type type_) | |
| 192 | ::= | ||
| 193 | match type_ | ||
| 194 | case T_COMPLEX(__) then '<%dumpRecordVars(varLst)%>' | ||
| 195 | case T_FUNCTION(__) then '<%dumpRecordInputVarStr(funcResultType)%>' | ||
| 196 | end dumpRecordInputVarStr; | ||
| 197 | |||
| 198 | 143 | template dumpRecordVars(list<DAE.Var> varLst) | |
| 199 | ::= | ||
| 200 | (varLst |> v => dumpRecordVar(v) ;separator="\n") | ||
| 201 | end dumpRecordVars; | ||
| 202 | |||
| 203 | 759 | template dumpRecordVar(DAE.Var v) | |
| 204 | ::= | ||
| 205 | match v | ||
| 206 | case TYPES_VAR(__) then | ||
| 207 | let attr_str = dumpRecordConstructorInputAttr(attributes) | ||
| 208 | let binding_str = dumpRecordConstructorBinding(binding) | ||
| 209 | let &attr = buffer "" | ||
| 210 | let ty_str = dumpType(ty, &attr) | ||
| 211 | '<%attr_str%><%ty_str%> <%name%><%attr%><%binding_str%>;' | ||
| 212 | end dumpRecordVar; | ||
| 213 | |||
| 214 | 715 | template dumpRecordConstructorInputAttr(DAE.Attributes attr) | |
| 215 | ::= | ||
| 216 | match attr | ||
| 217 | case DAE.ATTR(direction = Absyn.INPUT()) then 'input ' | ||
| 218 | case DAE.ATTR(visibility = SCode.PROTECTED()) then 'protected ' | ||
| 219 | case DAE.ATTR(variability = SCode.CONST()) then 'constant ' | ||
| 220 | else 'input ' | ||
| 221 | end dumpRecordConstructorInputAttr; | ||
| 222 | |||
| 223 | 110 | template dumpRecordConstructorBinding(DAE.Binding binding) | |
| 224 | ::= | ||
| 225 | match binding | ||
| 226 | case DAE.UNBOUND() then '' | ||
| 227 | case DAE.EQBOUND(__) then ' = <%dumpExp(exp)%>' | ||
| 228 | end dumpRecordConstructorBinding; | ||
| 229 | |||
| 230 | ✗ | template dumpRecordVarBinding(Binding binding) | |
| 231 | ::= | ||
| 232 | match binding | ||
| 233 | case UNBOUND(__) then '' | ||
| 234 | case EQBOUND(__) then ' = <%dumpExp(exp)%>' | ||
| 235 | case VALBOUND(__) then 'value bound***** check what to display' | ||
| 236 | end dumpRecordVarBinding; | ||
| 237 | |||
| 238 | 492 | template dumpFunctionBody(list<Element> dAElist) | |
| 239 | ::= | ||
| 240 | (dAElist |> lst => dumpFunctionElement(lst) ;separator="\n")+ | ||
| 241 | (dAElist |> lst => dumpFunctionAnnotation(lst)) | ||
| 242 | end dumpFunctionBody; | ||
| 243 | |||
| 244 | 2096 | template dumpFunctionElement(DAE.Element lst) | |
| 245 | ::= | ||
| 246 | match lst | ||
| 247 | case VAR(__) then dumpVar(lst,true) | ||
| 248 | case INITIALALGORITHM(__) then dumpFunctionAlgorithm(algorithm_ ,"initial algorithm") | ||
| 249 | case ALGORITHM(__) then dumpFunctionAlgorithm(algorithm_ ,"algorithm") | ||
| 250 | case COMMENT(__) then "" | ||
| 251 | else 'Element not found' | ||
| 252 | |||
| 253 | end dumpFunctionElement; | ||
| 254 | |||
| 255 | 13 | template dumpFunctionAnnotation(DAE.Element lst) | |
| 256 | ::= | ||
| 257 | match lst | ||
| 258 | case COMMENT(__) then | ||
| 259 | let x=dumpCommentAnnotationNoOpt(cmt) | ||
| 260 | if x then \n+x | ||
| 261 | else "" | ||
| 262 | |||
| 263 | end dumpFunctionAnnotation; | ||
| 264 | |||
| 265 | 407 | template dumpFunctionAlgorithm(Algorithm algorithm_, String label) | |
| 266 | ::= | ||
| 267 | match algorithm_ | ||
| 268 | case ALGORITHM_STMTS(__) then | ||
| 269 | << | ||
| 270 | <%label%> | ||
| 271 | <%dumpStatements(statementLst)%> | ||
| 272 | >> | ||
| 273 | end dumpFunctionAlgorithm; | ||
| 274 | |||
| 275 | /***************************************************************************** | ||
| 276 | * SECTION: VARIABLE SECTION * | ||
| 277 | *****************************************************************************/ | ||
| 278 | 1029 | template dumpVars(list<DAE.Element> v) | |
| 279 | ::= (v |> var => dumpVar(var,false) ;separator="\n") | ||
| 280 | end dumpVars; | ||
| 281 | |||
| 282 | 17531 | template dumpVar(DAE.Element lst, Boolean printTypeDimension) | |
| 283 | ::= | ||
| 284 | match lst | ||
| 285 | case VAR(__) then | ||
| 286 | let final = match variableAttributesOption case SOME(VariableAttributes) then dumpFinalPrefix(VariableAttributes) | ||
| 287 | let varVisibility = dumpVarVisibility(protection) | ||
| 288 | let varParallelism = dumpVarParallelism(parallelism) | ||
| 289 | let varKind = dumpVarKind(kind) | ||
| 290 | let varDirection = dumpVarDirection(direction) | ||
| 291 | let &attr = buffer "" | ||
| 292 | let varType = dumpType(ty, &attr) | ||
| 293 | let dim_str = if printTypeDimension then dumpTypeDimensions(dims) | ||
| 294 | let varName = dumpCref(componentRef) | ||
| 295 | let bindingExp = match binding case SOME(exp) then dumpExp(exp) | ||
| 296 | let varAttr = match variableAttributesOption case SOME(VariableAttributes) then dumpVariableAttributes(VariableAttributes) | ||
| 297 | let cmt_str = dumpCommentOpt(comment) | ||
| 298 | let ann_str = dumpCompAnnotation(comment) | ||
| 299 | let binding_str = if bindingExp then ' = <%bindingExp%>' | ||
| 300 | /* uncomment this and use the source_str if you want to print the typeLst inside the source (we should maybe put it on a flag or something) | ||
| 301 | let source_str = match source case SOURCE(__) then (typeLst |> tp => AbsynDumpTpl.dumpPath(tp) ;separator=", ") else '' | ||
| 302 | */ | ||
| 303 | << | ||
| 304 | <%varVisibility%><%final%><%varParallelism%><%varKind%><%varDirection%> <%varType%><%dim_str%> <%varName%><%attr%><%varAttr%><%binding_str%><%cmt_str%><%ann_str%>; | ||
| 305 | >> | ||
| 306 | end dumpVar; | ||
| 307 | |||
| 308 | 806 | template dumpFinalPrefix(DAE.VariableAttributes varAttr) | |
| 309 | ::= | ||
| 310 | match varAttr | ||
| 311 | case VAR_ATTR_REAL(finalPrefix=SOME(true)) then ' final' | ||
| 312 | case VAR_ATTR_INT(finalPrefix=SOME(true)) then ' final' | ||
| 313 | case VAR_ATTR_BOOL(finalPrefix=SOME(true)) then ' final' | ||
| 314 | case VAR_ATTR_STRING(finalPrefix=SOME(true)) then ' final' | ||
| 315 | case VAR_ATTR_ENUMERATION(finalPrefix=SOME(true)) then ' final' | ||
| 316 | end dumpFinalPrefix; | ||
| 317 | |||
| 318 | 1974 | template dumpVarVisibility(VarVisibility protection) | |
| 319 | ::= | ||
| 320 | match protection | ||
| 321 | case PROTECTED(__) then ' protected' | ||
| 322 | end dumpVarVisibility; | ||
| 323 | |||
| 324 | ✗ | template dumpVarParallelism(VarParallelism parallelism) | |
| 325 | ::= | ||
| 326 | match parallelism | ||
| 327 | case PARGLOBAL(__) then ' parglobal' | ||
| 328 | case PARLOCAL(__) then ' parlocal' | ||
| 329 | end dumpVarParallelism; | ||
| 330 | |||
| 331 | 3299 | template dumpVarKind(DAE.VarKind kind) | |
| 332 | ::= | ||
| 333 | match kind | ||
| 334 | case CONST(__) then ' constant' | ||
| 335 | case PARAM(__) then ' parameter' | ||
| 336 | case DISCRETE(__) then ' discrete' | ||
| 337 | end dumpVarKind; | ||
| 338 | |||
| 339 | 1052 | template dumpVarDirection(VarDirection direction) | |
| 340 | ::= | ||
| 341 | match direction | ||
| 342 | case INPUT(__) then ' input' | ||
| 343 | case OUTPUT(__) then ' output' | ||
| 344 | end dumpVarDirection; | ||
| 345 | |||
| 346 | 15710 | template dumpType(Type ty, Text &attributes) | |
| 347 | ::= | ||
| 348 | match ty | ||
| 349 | case T_INTEGER(__) then | ||
| 350 | let &attributes += dumpVarAttributes(varLst) | ||
| 351 | "Integer" | ||
| 352 | case T_REAL(__) then | ||
| 353 | let &attributes += dumpVarAttributes(varLst) | ||
| 354 | "Real" | ||
| 355 | case T_STRING(__) then | ||
| 356 | let &attributes += dumpVarAttributes(varLst) | ||
| 357 | "String" | ||
| 358 | case T_BOOL(__) then | ||
| 359 | let &attributes += dumpVarAttributes(varLst) | ||
| 360 | "Boolean" | ||
| 361 | case T_CLOCK(__) then | ||
| 362 | let &attributes += dumpVarAttributes(varLst) | ||
| 363 | "Clock" | ||
| 364 | case T_ENUMERATION(__) then | ||
| 365 | let lit_str = names ;separator=", " | ||
| 366 | 'enumeration(<%lit_str%>)' | ||
| 367 | case T_ARRAY(__) then dumpArrayType(ty, dumpDimensions(dims), &attributes) | ||
| 368 | case T_COMPLEX(complexClassType=RECORD(path=rname)) then AbsynDumpTpl.dumpPathNoQual(rname) | ||
| 369 | case T_COMPLEX(__) then AbsynDumpTpl.dumpPath(ClassInfUtil.getStateName(complexClassType)) | ||
| 370 | case T_SUBTYPE_BASIC(__) then dumpType(complexType, &attributes) | ||
| 371 | case T_FUNCTION(__) then dumpFunctionType(ty) | ||
| 372 | case T_TUPLE(__) then dumpTupleType(types, "(", ")") | ||
| 373 | case T_METATUPLE(__) then dumpTupleType(types, "tuple<", ">") | ||
| 374 | case T_METALIST(__) then 'list<<%dumpType(ty, attributes)%>>' | ||
| 375 | case T_METAARRAY(__) then 'array<<%dumpType(ty, attributes)%>>' | ||
| 376 | case T_METAPOLYMORPHIC(__) then 'polymorphic<<%name%>>' | ||
| 377 | case T_METAUNIONTYPE(__) then AbsynDumpTpl.dumpPathNoQual(path) | ||
| 378 | case T_METARECORD(__) then AbsynDumpTpl.dumpPathNoQual(path) | ||
| 379 | case T_METABOXED(__) then '#<%dumpType(ty, attributes)%>' | ||
| 380 | case T_METAOPTION(ty = DAE.T_UNKNOWN(__)) then 'Option<Any>' | ||
| 381 | case T_METAOPTION(__) then 'Option<<%dumpType(ty, &attributes)%>>' | ||
| 382 | case T_METATYPE(__) then dumpType(ty, &attributes) | ||
| 383 | case T_NORETCALL(__) then '#T_NORETCALL#' | ||
| 384 | case T_UNKNOWN(__) then '#T_UNKNOWN#' | ||
| 385 | case T_ANYTYPE(__) then '#T_ANYTYPE#' | ||
| 386 | else 'DAEDumpTpl.dumpType: Not yet implemented' | ||
| 387 | end dumpType; | ||
| 388 | |||
| 389 | 94 | template dumpArrayType(Type ty, String dims_accum, Text &attributes) | |
| 390 | ::= | ||
| 391 | match ty | ||
| 392 | case T_ARRAY(__) then | ||
| 393 | let dims_str = dumpDimensions(dims) | ||
| 394 | let dims_accum_str = if dims_accum then '<%dims_accum%>, <%dims_str%>' else dims_str | ||
| 395 | dumpArrayType(ty, dims_accum_str, &attributes) | ||
| 396 | else | ||
| 397 | let ty_str = dumpType(ty, &attributes) | ||
| 398 | let dims_str = if dims_accum then '[<%dims_accum%>]' | ||
| 399 | '<%ty_str%><%dims_str%>' | ||
| 400 | end dumpArrayType; | ||
| 401 | |||
| 402 | ✗ | template dumpTupleType(list<Type> tys, String ty_begin, String ty_end) | |
| 403 | ::= | ||
| 404 | let &attr = buffer "" | ||
| 405 | '<%ty_begin%><%(tys |> ty => dumpType(ty, &attr) ;separator=", ")%><%ty_end%>' | ||
| 406 | end dumpTupleType; | ||
| 407 | |||
| 408 | 6 | template dumpFunctionType(Type ty) | |
| 409 | ::= | ||
| 410 | match ty | ||
| 411 | case T_FUNCTION(__) then | ||
| 412 | let args_str = (funcArg |> arg => dumpFuncArg(arg) ;separator=", ") | ||
| 413 | let src_str = AbsynDumpTpl.dumpPath(path) | ||
| 414 | let &attr = buffer "" | ||
| 415 | let res_str = dumpType(funcResultType, &attr) | ||
| 416 | '<%src_str%><function>(<%args_str%>) => <%res_str%>' | ||
| 417 | end dumpFunctionType; | ||
| 418 | |||
| 419 | 7 | template dumpFuncArg(FuncArg arg) | |
| 420 | ::= | ||
| 421 | match arg | ||
| 422 | case FUNCARG(__) then | ||
| 423 | let &attr = buffer "" | ||
| 424 | let ty_str = dumpType(ty, &attr) | ||
| 425 | let c_str = dumpConst(const) | ||
| 426 | let p_str = dumpParallelism(par) | ||
| 427 | let binding_str = match defaultBinding case SOME(bexp) then ' := <%dumpExp(bexp)%>' | ||
| 428 | '<%ty_str%> <%c_str%><%p_str%><%name%><%binding_str%>' | ||
| 429 | end dumpFuncArg; | ||
| 430 | |||
| 431 | 2 | template dumpRecordType(Type ty) | |
| 432 | ::= | ||
| 433 | match ty | ||
| 434 | case T_COMPLEX(__) then | ||
| 435 | let name = AbsynDumpTpl.dumpPath(ClassInfUtil.getStateName(complexClassType)) | ||
| 436 | let vars = dumpRecordVars(varLst) | ||
| 437 | << | ||
| 438 | record <%name%> | ||
| 439 | <%vars%> | ||
| 440 | end <%name%>; | ||
| 441 | >> | ||
| 442 | case T_FUNCTION(__) then dumpRecordType(funcResultType) | ||
| 443 | end dumpRecordType; | ||
| 444 | |||
| 445 | ✗ | template dumpConst(Const c) | |
| 446 | ::= | ||
| 447 | match c | ||
| 448 | case C_PARAM() then "parameter " | ||
| 449 | case C_CONST() then "constant " | ||
| 450 | end dumpConst; | ||
| 451 | |||
| 452 | ✗ | template dumpParallelism(DAE.VarParallelism p) | |
| 453 | ::= | ||
| 454 | match p | ||
| 455 | case PARGLOBAL() then "parglobal " | ||
| 456 | case PARLOCAL() then "parlocal " | ||
| 457 | end dumpParallelism; | ||
| 458 | |||
| 459 | 338 | template dumpVarAttributes(list<DAE.Var> literalVarLst) | |
| 460 | ::= if literalVarLst then '(<%(literalVarLst |> var => dumpVarAttribute(var) ;separator=", ")%>)' | ||
| 461 | end dumpVarAttributes; | ||
| 462 | |||
| 463 | 1067 | template dumpVarAttribute(DAE.Var var) | |
| 464 | ::= | ||
| 465 | match var | ||
| 466 | case TYPES_VAR(binding = DAE.EQBOUND(exp = e)) then '<%name%> = <%dumpExp(e)%>' | ||
| 467 | end dumpVarAttribute; | ||
| 468 | |||
| 469 | 96 | template dumpDimensions(list<Dimension> dims) | |
| 470 | ::= if dims then (dims |> dim => dumpDimension(dim) ;separator=", ") | ||
| 471 | end dumpDimensions; | ||
| 472 | |||
| 473 | 275 | template dumpDimension(Dimension dim) | |
| 474 | ::= | ||
| 475 | match dim | ||
| 476 | case DIM_INTEGER(__) then integer | ||
| 477 | case DIM_ENUM(__) then AbsynDumpTpl.dumpPath(enumTypeName) | ||
| 478 | case DIM_EXP(__) then dumpExp(exp) | ||
| 479 | case DIM_UNKNOWN(__) then ':' | ||
| 480 | end dumpDimension; | ||
| 481 | |||
| 482 | 12856 | template dumpVariableAttributes(DAE.VariableAttributes variableAttributesOption) | |
| 483 | ::= | ||
| 484 | match variableAttributesOption | ||
| 485 | case VAR_ATTR_REAL(__) then | ||
| 486 | let quantity_str = dumpExpAttrOpt(quantity, "quantity") | ||
| 487 | let unit_str = dumpExpAttrOpt(unit, "unit") | ||
| 488 | let displayunit_str = dumpExpAttrOpt(displayUnit, "displayUnit") | ||
| 489 | let min_str = dumpExpAttrOpt(min, "min") | ||
| 490 | let max_str = dumpExpAttrOpt(max, "max") | ||
| 491 | let start_str = dumpExpAttrOpt(start, "start") | ||
| 492 | let fixed_str = dumpExpAttrOpt(fixed, "fixed") | ||
| 493 | let nominal_str = dumpExpAttrOpt(nominal, "nominal") | ||
| 494 | let statesel_str = dumpStateSelectAttrOpt(stateSelectOption) | ||
| 495 | let uncert_str = dumpUncertaintyAttrOpt(uncertainOption) | ||
| 496 | let dist_str = dumpDistributionAttrOpt(distributionOption) | ||
| 497 | let so_str = dumpStartOriginAttrOpt(startOrigin) | ||
| 498 | let attrs_str = {quantity_str, unit_str, displayunit_str, min_str, max_str, | ||
| 499 | start_str, fixed_str, nominal_str, statesel_str, uncert_str, dist_str, | ||
| 500 | so_str} ;separator=", " | ||
| 501 | if attrs_str then '(<%attrs_str%>)' | ||
| 502 | case VAR_ATTR_INT(__) then | ||
| 503 | let quantity_str = dumpExpAttrOpt(quantity, "quantity") | ||
| 504 | let min_str = dumpExpAttrOpt(min, "min") | ||
| 505 | let max_str = dumpExpAttrOpt(max, "max") | ||
| 506 | let start_str = dumpExpAttrOpt(start, "start") | ||
| 507 | let fixed_str = dumpExpAttrOpt(fixed, "fixed") | ||
| 508 | let uncert_str = dumpUncertaintyAttrOpt(uncertainOption) | ||
| 509 | let dist_str = dumpDistributionAttrOpt(distributionOption) | ||
| 510 | let so_str = dumpStartOriginAttrOpt(startOrigin) | ||
| 511 | let attrs_str = {quantity_str, min_str, max_str, start_str, fixed_str, | ||
| 512 | uncert_str, dist_str, so_str} ;separator=", " | ||
| 513 | if attrs_str then '(<%attrs_str%>)' | ||
| 514 | case VAR_ATTR_BOOL(__) then | ||
| 515 | let quantity_str = dumpExpAttrOpt(quantity, "quantity") | ||
| 516 | let start_str = dumpExpAttrOpt(start, "start") | ||
| 517 | let fixed_str = dumpExpAttrOpt(fixed, "fixed") | ||
| 518 | let so_str = dumpStartOriginAttrOpt(startOrigin) | ||
| 519 | let attrs_str = {quantity_str, start_str, fixed_str, so_str} ;separator=", " | ||
| 520 | if attrs_str then '(<%attrs_str%>)' | ||
| 521 | case VAR_ATTR_STRING(__) then | ||
| 522 | let quantity_str = dumpExpAttrOpt(quantity, "quantity") | ||
| 523 | let start_str = dumpExpAttrOpt(start, "start") | ||
| 524 | let so_str = dumpStartOriginAttrOpt(startOrigin) | ||
| 525 | let attrs_str = {quantity_str, start_str, so_str} ;separator=", " | ||
| 526 | if attrs_str then '(<%attrs_str%>)' | ||
| 527 | case VAR_ATTR_ENUMERATION(__) then | ||
| 528 | let quantity_str = dumpExpAttrOpt(quantity, "quantity") | ||
| 529 | let min_str = dumpExpAttrOpt(min, "min") | ||
| 530 | let max_str = dumpExpAttrOpt(max, "max") | ||
| 531 | let start_str = dumpExpAttrOpt(start, "start") | ||
| 532 | let fixed_str = dumpExpAttrOpt(fixed, "fixed") | ||
| 533 | let so_str = dumpStartOriginAttrOpt(startOrigin) | ||
| 534 | let attrs_str = {quantity_str, min_str, max_str, start_str, fixed_str, so_str} ;separator=", " | ||
| 535 | if attrs_str then '(<%attrs_str%>)' | ||
| 536 | end dumpVariableAttributes; | ||
| 537 | |||
| 538 | 21106 | template dumpExpAttrOpt(Option<Exp> exp, String attr) | |
| 539 | ::= | ||
| 540 | match exp | ||
| 541 | case SOME(e) then '<%attr%> = <%dumpExp(e)%>' | ||
| 542 | end dumpExpAttrOpt; | ||
| 543 | |||
| 544 | 121 | template dumpStateSelectAttrOpt(Option<StateSelect> stateSelect) | |
| 545 | ::= match stateSelect case SOME(ss) then dumpStateSelectAttr(ss) | ||
| 546 | end dumpStateSelectAttrOpt; | ||
| 547 | |||
| 548 | 121 | template dumpStateSelectAttr(DAE.StateSelect stateSelect) | |
| 549 | ::= 'stateSelect = <%dumpStateSelect(stateSelect)%>' | ||
| 550 | end dumpStateSelectAttr; | ||
| 551 | |||
| 552 | 88 | template dumpStateSelect(DAE.StateSelect stateSelect) | |
| 553 | ::= | ||
| 554 | match stateSelect | ||
| 555 | case NEVER(__) then 'StateSelect.never' | ||
| 556 | case AVOID(__) then 'StateSelect.avoid' | ||
| 557 | case DEFAULT(__) then 'StateSelect.default' | ||
| 558 | case PREFER(__) then 'StateSelect.prefer' | ||
| 559 | case ALWAYS(__) then 'StateSelect.always' | ||
| 560 | end dumpStateSelect; | ||
| 561 | |||
| 562 | ✗ | template dumpUncertaintyAttrOpt(Option<Uncertainty> uncertainty) | |
| 563 | ::= match uncertainty case SOME(u) then dumpUncertaintyAttr(u) | ||
| 564 | end dumpUncertaintyAttrOpt; | ||
| 565 | |||
| 566 | ✗ | template dumpUncertaintyAttr(DAE.Uncertainty uncertainty) | |
| 567 | ::= 'uncertainty = <%dumpUncertainty(uncertainty)%>' | ||
| 568 | end dumpUncertaintyAttr; | ||
| 569 | |||
| 570 | ✗ | template dumpUncertainty(DAE.Uncertainty uncertainty) | |
| 571 | ::= | ||
| 572 | match uncertainty | ||
| 573 | case GIVEN(__) then 'Uncertainty.given' | ||
| 574 | case SOUGHT(__) then 'Uncertainty.sought' | ||
| 575 | case REFINE(__) then 'Uncertainty.refine' | ||
| 576 | case PROPAGATE(__) then 'Uncertainty.propagate' | ||
| 577 | end dumpUncertainty; | ||
| 578 | |||
| 579 | ✗ | template dumpDistributionAttrOpt(Option<Distribution> distribution) | |
| 580 | ::= match distribution case SOME(d) then dumpDistributionAttr(d) | ||
| 581 | end dumpDistributionAttrOpt; | ||
| 582 | |||
| 583 | ✗ | template dumpDistributionAttr(Distribution distribution) | |
| 584 | ::= 'distribution = <%dumpDistribution(distribution)%>' | ||
| 585 | end dumpDistributionAttr; | ||
| 586 | |||
| 587 | ✗ | template dumpDistribution(Distribution distribution) | |
| 588 | ::= | ||
| 589 | match distribution | ||
| 590 | case DISTRIBUTION(__) then | ||
| 591 | let name_str = dumpExp(name) | ||
| 592 | let params_str = dumpExp(params) | ||
| 593 | let paramnames_str = dumpExp(paramNames) | ||
| 594 | 'Distribution(name = <%name_str%>, params = <%params_str%>, paramNames = <%paramnames_str%>)' | ||
| 595 | end dumpDistribution; | ||
| 596 | |||
| 597 | 14547 | template dumpStartOriginAttrOpt(Option<DAE.StartOrigin> startOrigin) | |
| 598 | ::= if Config.showStartOrigin() then | ||
| 599 | match startOrigin | ||
| 600 | case SOME(UNDEFINED_ORIGIN(__)) then 'startOrigin = undefined' | ||
| 601 | case SOME(TYPE_ORIGIN(__)) then 'startOrigin = type' | ||
| 602 | case SOME(BINDING_ORIGIN(__)) then 'startOrigin = binding' | ||
| 603 | case SOME(CONFIDENCE(actual = actual, raw = raw)) then 'startOrigin = confidence(<%actual%>, <%raw%>)' | ||
| 604 | case SOME(TYPE_CONFIDENCE(level = level)) then 'startOrigin = typeConfidence(<%level%>)' | ||
| 605 | end dumpStartOriginAttrOpt; | ||
| 606 | |||
| 607 | 35951 | template dumpCref(ComponentRef c) | |
| 608 | ::= | ||
| 609 | match c | ||
| 610 | case CREF_QUAL(__) then | ||
| 611 | if (Flags.getConfigBool(Flags.MODELICA_OUTPUT)) then | ||
| 612 | << | ||
| 613 | <%ident%><%dumpSubscripts(subscriptLst)%>__<%dumpCref(componentRef)%> | ||
| 614 | >> | ||
| 615 | else | ||
| 616 | << | ||
| 617 | <%ident%><%dumpSubscripts(subscriptLst)%>.<%dumpCref(componentRef)%> | ||
| 618 | >> | ||
| 619 | case CREF_IDENT(ident = "$DER") then | ||
| 620 | << | ||
| 621 | der(<%ident%><%dumpSubscripts(subscriptLst)%>) | ||
| 622 | >> | ||
| 623 | case CREF_IDENT(__) then | ||
| 624 | << | ||
| 625 | <%ident%><%dumpSubscripts(subscriptLst)%> | ||
| 626 | >> | ||
| 627 | end dumpCref; | ||
| 628 | |||
| 629 | 292 | template dumpTypeDimensions(list<Dimension> dimensionLst) | |
| 630 | ::= | ||
| 631 | if dimensionLst then | ||
| 632 | let sub_str = (dimensionLst |> s => dumpDimension(s) ;separator=", ") | ||
| 633 | '[<%sub_str%>]' | ||
| 634 | end dumpTypeDimensions; | ||
| 635 | |||
| 636 | |||
| 637 | 11974 | template dumpSubscripts(list<Subscript> subscriptLst) | |
| 638 | ::= | ||
| 639 | if subscriptLst then | ||
| 640 | if (Flags.getConfigBool(Flags.MODELICA_OUTPUT)) then | ||
| 641 | let sub_str = (subscriptLst |> s => dumpSubscript(s) ;separator="_") | ||
| 642 | '_<%sub_str%>' | ||
| 643 | else | ||
| 644 | let sub_str = (subscriptLst |> s => dumpSubscript(s) ;separator=",") | ||
| 645 | '[<%sub_str%>]' | ||
| 646 | end dumpSubscripts; | ||
| 647 | |||
| 648 | 16710 | template dumpSubscript(DAE.Subscript subscript) | |
| 649 | ::= | ||
| 650 | match subscript | ||
| 651 | case WHOLEDIM(__) then ':' | ||
| 652 | case SLICE(__) then dumpExp(exp) | ||
| 653 | case INDEX(__) then dumpExp(exp) | ||
| 654 | case WHOLE_NONEXP(__) then '1:<%dumpExp(exp)%>' | ||
| 655 | end dumpSubscript; | ||
| 656 | |||
| 657 | /***************************************************************************** | ||
| 658 | * SECTION: INITIAL EQUATION SECTION * | ||
| 659 | *****************************************************************************/ | ||
| 660 | 13 | template dumpInitialEquationSection(list<DAE.Element> ie) | |
| 661 | ::= | ||
| 662 | if ie then | ||
| 663 | << | ||
| 664 | initial equation | ||
| 665 | <%ie |> ineq => dumpEquationElement(ineq) ;separator="\n"%> | ||
| 666 | >> | ||
| 667 | end dumpInitialEquationSection; | ||
| 668 | |||
| 669 | /***************************************************************************** | ||
| 670 | * SECTION: EQUATION SECTION * | ||
| 671 | *****************************************************************************/ | ||
| 672 | |||
| 673 | 527 | template dumpEquationSection(list<DAE.Element> e) | |
| 674 | ::= | ||
| 675 | if e then | ||
| 676 | << | ||
| 677 | equation | ||
| 678 | <%e |> eq => dumpEquationElement(eq) ;separator="\n"%> | ||
| 679 | >> | ||
| 680 | end dumpEquationSection; | ||
| 681 | |||
| 682 | 3949 | template dumpEquationElement(DAE.Element lst) | |
| 683 | ::= | ||
| 684 | match lst | ||
| 685 | case EQUATION(__) then dumpEquation(exp, scalar, source) | ||
| 686 | case EQUEQUATION(__) then dumpEquEquation(cr1, cr2, source) | ||
| 687 | case ARRAY_EQUATION(__) then dumpEquation(exp, array, source) | ||
| 688 | case COMPLEX_EQUATION(__) then dumpEquation(lhs, rhs, source) | ||
| 689 | case DEFINE(__) then dumpDefine(componentRef, exp, source) | ||
| 690 | case WHEN_EQUATION(__) then dumpWhenEquation(lst) | ||
| 691 | case FOR_EQUATION(__) then dumpForEquation(lst) | ||
| 692 | case IF_EQUATION(__) then dumpIfEquation(condition1, equations2, equations3, source) | ||
| 693 | case ASSERT(__) then dumpAssert(condition, message, level, source) | ||
| 694 | case INITIAL_ASSERT(__) then dumpAssert(condition, message, level, source) | ||
| 695 | case TERMINATE(__) then dumpTerminate(message, source) | ||
| 696 | case INITIAL_TERMINATE(__) then dumpTerminate(message, source) | ||
| 697 | case REINIT(__) then dumpReinit(componentRef, exp, source) | ||
| 698 | case NORETCALL(__) then dumpNoRetCall(exp, source) | ||
| 699 | case INITIAL_NORETCALL(__) then dumpNoRetCall(exp, source) | ||
| 700 | case INITIALDEFINE(__) then dumpDefine(componentRef, exp, source) | ||
| 701 | case INITIAL_ARRAY_EQUATION(__) then dumpEquation(exp, array, source) | ||
| 702 | case INITIAL_COMPLEX_EQUATION(__) then dumpEquation(lhs, rhs, source) | ||
| 703 | case INITIAL_FOR_EQUATION(__) then dumpForEquation(lst) | ||
| 704 | case INITIAL_IF_EQUATION(__) then dumpIfEquation(condition1, equations2, equations3, source) | ||
| 705 | case INITIALEQUATION(__) then dumpEquation(exp1, exp2, source) | ||
| 706 | else 'UNKNOWN EQUATION TYPE' | ||
| 707 | end dumpEquationElement; | ||
| 708 | |||
| 709 | 4726 | template dumpEquation(DAE.Exp lhs, DAE.Exp rhs, DAE.ElementSource src) | |
| 710 | ::= | ||
| 711 | let lhs_str = match lhs case IFEXP(__) then '(<%dumpExp(lhs)%>)' else dumpExp(lhs) | ||
| 712 | let rhs_str = dumpExp(rhs) | ||
| 713 | let src_str = dumpSource(src) | ||
| 714 | << | ||
| 715 | <%lhs_str%> = <%rhs_str%><%src_str%>; | ||
| 716 | >> | ||
| 717 | end dumpEquation; | ||
| 718 | |||
| 719 | 2363 | template dumpEquEquation(DAE.ComponentRef lhs, DAE.ComponentRef rhs, DAE.ElementSource src) | |
| 720 | ::= | ||
| 721 | let lhs_str = dumpCref(lhs) | ||
| 722 | let rhs_str = dumpCref(rhs) | ||
| 723 | let src_str = dumpSource(src) | ||
| 724 | << | ||
| 725 | <%lhs_str%> = <%rhs_str%><%src_str%>; | ||
| 726 | >> | ||
| 727 | end dumpEquEquation; | ||
| 728 | |||
| 729 | 7 | template dumpDefine(DAE.ComponentRef lhs, DAE.Exp rhs, DAE.ElementSource src) | |
| 730 | ::= | ||
| 731 | let lhs_str = dumpCref(lhs) | ||
| 732 | let rhs_str = dumpExp(rhs) | ||
| 733 | let src_str = dumpSource(src) | ||
| 734 | << | ||
| 735 | <%lhs_str%> = <%rhs_str%><%src_str%>; | ||
| 736 | >> | ||
| 737 | end dumpDefine; | ||
| 738 | |||
| 739 | 241 | template dumpAssert(DAE.Exp cond, DAE.Exp msg, DAE.Exp lvl, DAE.ElementSource src) | |
| 740 | ::= | ||
| 741 | let cond_str = dumpExp(cond) | ||
| 742 | let msg_str = dumpExp(msg) | ||
| 743 | let lvl_str = match lvl case DAE.ENUM_LITERAL(index = 1) then ', AssertionLevel.warning' | ||
| 744 | let src_str = dumpSource(src) | ||
| 745 | << | ||
| 746 | assert(<%cond_str%>, <%msg_str%><%lvl_str%>)<%src_str%>; | ||
| 747 | >> | ||
| 748 | end dumpAssert; | ||
| 749 | |||
| 750 | 1 | template dumpTerminate(DAE.Exp msg, DAE.ElementSource src) | |
| 751 | ::= | ||
| 752 | let msg_str = dumpExp(msg) | ||
| 753 | let src_str = dumpSource(src) | ||
| 754 | << | ||
| 755 | terminate(<%msg_str%>)<%src_str%>; | ||
| 756 | >> | ||
| 757 | end dumpTerminate; | ||
| 758 | |||
| 759 | 6 | template dumpReinit(DAE.ComponentRef cref, DAE.Exp exp, DAE.ElementSource src) | |
| 760 | ::= | ||
| 761 | let cref_str = dumpCref(cref) | ||
| 762 | let exp_str = dumpExp(exp) | ||
| 763 | let src_str = dumpSource(src) | ||
| 764 | << | ||
| 765 | reinit(<%cref_str%>, <%exp_str%>)<%src_str%>; | ||
| 766 | >> | ||
| 767 | end dumpReinit; | ||
| 768 | |||
| 769 | 26 | template dumpNoRetCall(DAE.Exp call_exp, DAE.ElementSource src) | |
| 770 | ::= | ||
| 771 | let call_str = dumpExp(call_exp) | ||
| 772 | let src_str = dumpSource(src) | ||
| 773 | let tail_str = match call_exp | ||
| 774 | case CALL(attr=CALL_ATTR(tailCall=TAIL(__))) then "return " | ||
| 775 | else "" | ||
| 776 | << | ||
| 777 | <%tail_str%><%call_str%><%src_str%>; | ||
| 778 | >> | ||
| 779 | end dumpNoRetCall; | ||
| 780 | |||
| 781 | 38 | template dumpWhenEquation(DAE.Element lst) | |
| 782 | ::= | ||
| 783 | match lst | ||
| 784 | case WHEN_EQUATION(__) then | ||
| 785 | let when_cond_str = dumpExp(condition) | ||
| 786 | let body_str = (equations |> e => dumpEquationElement(e) ;separator="\n") | ||
| 787 | let elsewhen_str = match elsewhen_ case SOME(el) then dumpWhenEquation(el) | ||
| 788 | let src_str = dumpSource(source) | ||
| 789 | if not elsewhen_str then | ||
| 790 | << | ||
| 791 | when <%when_cond_str%> then | ||
| 792 | <%body_str%> | ||
| 793 | end when<%src_str%>; | ||
| 794 | >> | ||
| 795 | else | ||
| 796 | << | ||
| 797 | when <%when_cond_str%> then | ||
| 798 | <%body_str%> | ||
| 799 | else<%elsewhen_str%> | ||
| 800 | >> | ||
| 801 | end dumpWhenEquation; | ||
| 802 | |||
| 803 | 17 | template dumpForEquation(DAE.Element lst) | |
| 804 | ::= | ||
| 805 | match lst | ||
| 806 | case FOR_EQUATION(__) then | ||
| 807 | let range_str = dumpExp(range) | ||
| 808 | let body_str = (equations |> e => dumpEquationElement(e) ;separator="\n") | ||
| 809 | let src_str = dumpSource(source) | ||
| 810 | << | ||
| 811 | for <%iter%> in <%range_str%> loop | ||
| 812 | <%body_str%> | ||
| 813 | end for<%src_str%>; | ||
| 814 | >> | ||
| 815 | case INITIAL_FOR_EQUATION(__) then | ||
| 816 | let range_str = dumpExp(range) | ||
| 817 | let body_str = (equations |> e => dumpEquationElement(e) ;separator="\n") | ||
| 818 | let src_str = dumpSource(source) | ||
| 819 | << | ||
| 820 | for <%iter%> in <%range_str%> loop | ||
| 821 | <%body_str%> | ||
| 822 | end for<%src_str%>; | ||
| 823 | >> | ||
| 824 | end dumpForEquation; | ||
| 825 | |||
| 826 | 16 | template dumpIfEquation(list<DAE.Exp> conds, list<list<DAE.Element>> branches, | |
| 827 | list<DAE.Element> else_branch, DAE.ElementSource src) | ||
| 828 | ::= | ||
| 829 | match conds | ||
| 830 | case if_cond :: elseif_conds then | ||
| 831 | match branches | ||
| 832 | case if_branch :: elseif_branches then | ||
| 833 | let if_cond_str = dumpExp(if_cond) | ||
| 834 | let if_branch_str = (if_branch |> e => dumpEquationElement(e) ;separator="\n") | ||
| 835 | let elseif_str = dumpElseIfEquation(elseif_conds, elseif_branches) | ||
| 836 | let else_str = if else_branch then | ||
| 837 | << | ||
| 838 | else | ||
| 839 | <%else_branch |> e => dumpEquationElement(e) ;separator="\n"%> | ||
| 840 | >> | ||
| 841 | let src_str = dumpSource(src) | ||
| 842 | << | ||
| 843 | if <%if_cond_str%> then | ||
| 844 | <%if_branch_str%> | ||
| 845 | <%elseif_str%> | ||
| 846 | <%else_str%> | ||
| 847 | end if<%src_str%>; | ||
| 848 | >> | ||
| 849 | end dumpIfEquation; | ||
| 850 | |||
| 851 | 5 | template dumpElseIfEquation(list<Exp> condition1, | |
| 852 | list<list<DAE.Element>> equations) | ||
| 853 | ::= | ||
| 854 | match condition1 | ||
| 855 | case cond :: rest_conds then | ||
| 856 | match equations | ||
| 857 | case branch :: rest_branches then | ||
| 858 | let cond_str = dumpExp(cond) | ||
| 859 | let branch_str = (branch |> e => dumpEquationElement(e) ;separator="\n") | ||
| 860 | let rest_str = dumpElseIfEquation(rest_conds, rest_branches) | ||
| 861 | << | ||
| 862 | elseif <%cond_str%> then | ||
| 863 | <%branch_str%> | ||
| 864 | <%rest_str%> | ||
| 865 | >> | ||
| 866 | end dumpElseIfEquation; | ||
| 867 | |||
| 868 | /***************************************************************************** | ||
| 869 | * SECTION: INITIAL ALGORITHM SECTION * | ||
| 870 | *****************************************************************************/ | ||
| 871 | 1029 | template dumpInitialAlgorithmSection(list<DAE.Element> ia) | |
| 872 | ::= (ia |> alg => dumpInitialAlgorithm(alg) ;separator="\n") | ||
| 873 | end dumpInitialAlgorithmSection; | ||
| 874 | |||
| 875 | 4 | template dumpInitialAlgorithm(DAE.Element alg) | |
| 876 | ::= | ||
| 877 | match alg | ||
| 878 | case INITIALALGORITHM(__) then | ||
| 879 | << | ||
| 880 | <%dumpAlgorithm(algorithm_, "initial algorithm")%> | ||
| 881 | >> | ||
| 882 | end dumpInitialAlgorithm; | ||
| 883 | |||
| 884 | |||
| 885 | /***************************************************************************** | ||
| 886 | * SECTION: ALGORITHM SECTION * | ||
| 887 | *****************************************************************************/ | ||
| 888 | |||
| 889 | 1029 | template dumpAlgorithmSection(list<DAE.Element> a) | |
| 890 | ::= (a |> alg => dumpAlgorithmElement(alg) ;separator="\n") | ||
| 891 | end dumpAlgorithmSection; | ||
| 892 | |||
| 893 | 63 | template dumpAlgorithmElement(DAE.Element alg) | |
| 894 | ::= | ||
| 895 | match alg | ||
| 896 | case ALGORITHM(__) then | ||
| 897 | << | ||
| 898 | <%dumpAlgorithm(algorithm_, "algorithm")%> | ||
| 899 | >> | ||
| 900 | end dumpAlgorithmElement; | ||
| 901 | |||
| 902 | 67 | template dumpAlgorithm(Algorithm algorithm_, String header) | |
| 903 | ::= | ||
| 904 | match algorithm_ | ||
| 905 | case ALGORITHM_STMTS(__) then | ||
| 906 | << | ||
| 907 | <%header%> | ||
| 908 | <%dumpStatements(statementLst)%> | ||
| 909 | >> | ||
| 910 | end dumpAlgorithm; | ||
| 911 | |||
| 912 | 476 | template dumpStatements(list<DAE.Statement> stmts) | |
| 913 | ::= (stmts |> stmt => dumpStatement(stmt) ;separator="\n") | ||
| 914 | end dumpStatements; | ||
| 915 | |||
| 916 | 2014 | template dumpStatement(DAE.Statement stmt) | |
| 917 | ::= | ||
| 918 | match stmt | ||
| 919 | case STMT_ASSIGN(__) then dumpAssignment(exp1, exp, source) | ||
| 920 | case STMT_TUPLE_ASSIGN(__) then dumpTupleAssignStatement(stmt) | ||
| 921 | case STMT_ASSIGN_ARR(__) then dumpArrayAssignStatement(stmt) | ||
| 922 | case STMT_IF(__) then dumpIfStatement(stmt) | ||
| 923 | case STMT_FOR(__) then dumpForStatement(stmt) | ||
| 924 | case STMT_PARFOR(__) then dumpParForStatement(stmt) | ||
| 925 | case STMT_WHILE(__) then dumpWhileStatement(stmt) | ||
| 926 | case STMT_WHEN(__) then dumpWhenStatement(stmt) | ||
| 927 | case STMT_ASSERT(__) then dumpAssert(cond, msg, level, source) | ||
| 928 | case STMT_TERMINATE(__) then dumpTerminate(msg, source) | ||
| 929 | case STMT_REINIT(__) then dumpReinitStatement(stmt) | ||
| 930 | case STMT_NORETCALL(__) then dumpNoRetCall(exp, source) | ||
| 931 | case STMT_RETURN(__) then 'return;' | ||
| 932 | case STMT_BREAK(__) then 'break;' | ||
| 933 | case STMT_CONTINUE(__) then 'continue;' | ||
| 934 | case STMT_FAILURE(__) then 'fail();' | ||
| 935 | else errorMsg("DAEDumpTypes.dumpStatement: Unknown statement.") | ||
| 936 | |||
| 937 | end dumpStatement; | ||
| 938 | |||
| 939 | 2014 | template dumpAssignment(DAE.Exp lhs, DAE.Exp rhs, DAE.ElementSource src) | |
| 940 | ::= | ||
| 941 | let lhs_str = match lhs case IFEXP(__) then '(<%dumpExp(lhs)%>)' else dumpExp(lhs) | ||
| 942 | let rhs_str = dumpExp(rhs) | ||
| 943 | let src_str = dumpSource(src) | ||
| 944 | << | ||
| 945 | <%lhs_str%> := <%rhs_str%><%src_str%>; | ||
| 946 | >> | ||
| 947 | end dumpAssignment; | ||
| 948 | |||
| 949 | 41 | template dumpTupleAssignStatement(DAE.Statement stmt) | |
| 950 | ::= | ||
| 951 | match stmt | ||
| 952 | case STMT_TUPLE_ASSIGN(__) then | ||
| 953 | let lhs_str = (expExpLst |> e => dumpExp(e);separator=", ") | ||
| 954 | let rhs_str = dumpExp(exp) | ||
| 955 | let src_str = dumpSource(source) | ||
| 956 | << | ||
| 957 | (<%lhs_str%>) := <%rhs_str%><%src_str%>; | ||
| 958 | >> | ||
| 959 | end dumpTupleAssignStatement; | ||
| 960 | |||
| 961 | 81 | template dumpArrayAssignStatement(DAE.Statement stmt) | |
| 962 | ::= | ||
| 963 | match stmt | ||
| 964 | case STMT_ASSIGN_ARR(__) then | ||
| 965 | let lhs_str = dumpExp(lhs) | ||
| 966 | let rhs_str = dumpExp(exp) | ||
| 967 | let src_str = dumpSource(source) | ||
| 968 | << | ||
| 969 | <%lhs_str%> := <%rhs_str%><%src_str%>; | ||
| 970 | >> | ||
| 971 | end dumpArrayAssignStatement; | ||
| 972 | |||
| 973 | 166 | template dumpIfStatement(DAE.Statement stmt) | |
| 974 | ::= | ||
| 975 | match stmt | ||
| 976 | case STMT_IF(__) then | ||
| 977 | let if_cond_str = dumpExp(exp) | ||
| 978 | let true_branch_str = (statementLst |> e => dumpStatement(e) ;separator="\n") | ||
| 979 | let else_if_str = dumpElseIfStatements(else_) | ||
| 980 | let src_str = dumpSource(source) | ||
| 981 | << | ||
| 982 | if <%if_cond_str%> then | ||
| 983 | <%true_branch_str%> | ||
| 984 | <%else_if_str%> | ||
| 985 | end if<%src_str%>; | ||
| 986 | >> | ||
| 987 | end dumpIfStatement; | ||
| 988 | |||
| 989 | 99 | template dumpElseIfStatements(Else else_) | |
| 990 | ::= | ||
| 991 | match else_ | ||
| 992 | case ELSEIF(__) then | ||
| 993 | let elseif_cond_str = dumpExp(exp) | ||
| 994 | let elseif_body_str = (statementLst |> e => dumpStatement(e) ;separator="\n") | ||
| 995 | let else_str = dumpElseIfStatements(else_) | ||
| 996 | << | ||
| 997 | elseif <%elseif_cond_str%> then | ||
| 998 | <%elseif_body_str%> | ||
| 999 | <%else_str%> | ||
| 1000 | >> | ||
| 1001 | case ELSE(__) then | ||
| 1002 | let else_body_str = (statementLst |> e => dumpStatement(e) ;separator="\n") | ||
| 1003 | << | ||
| 1004 | else | ||
| 1005 | <%else_body_str%> | ||
| 1006 | >> | ||
| 1007 | end dumpElseIfStatements; | ||
| 1008 | |||
| 1009 | 44 | template dumpForStatement(DAE.Statement stmt) | |
| 1010 | ::= | ||
| 1011 | match stmt | ||
| 1012 | case STMT_FOR(__) then | ||
| 1013 | let range_str = dumpExp(range) | ||
| 1014 | let alg_str = (statementLst |> e => dumpStatement(e) ;separator="\n") | ||
| 1015 | let src_str = dumpSource(source) | ||
| 1016 | << | ||
| 1017 | for <%iter%> in <%range_str%> loop | ||
| 1018 | <%alg_str%> | ||
| 1019 | end for<%src_str%>; | ||
| 1020 | >> | ||
| 1021 | end dumpForStatement; | ||
| 1022 | |||
| 1023 | ✗ | template dumpParForStatement(DAE.Statement stmt) | |
| 1024 | ::= | ||
| 1025 | match stmt | ||
| 1026 | case STMT_PARFOR(__) then | ||
| 1027 | let range_str = dumpExp(range) | ||
| 1028 | let alg_str = (statementLst |> e => dumpStatement(e) ;separator="\n") | ||
| 1029 | let src_str = dumpSource(source) | ||
| 1030 | << | ||
| 1031 | parfor <%iter%> in <%range_str%> loop | ||
| 1032 | <%alg_str%> | ||
| 1033 | end for<%src_str%>; | ||
| 1034 | >> | ||
| 1035 | end dumpParForStatement; | ||
| 1036 | |||
| 1037 | 18 | template dumpWhileStatement(DAE.Statement stmt) | |
| 1038 | ::= | ||
| 1039 | match stmt | ||
| 1040 | case STMT_WHILE(__) then | ||
| 1041 | let while_cond = dumpExp(exp) | ||
| 1042 | let body_str = (statementLst |> e => dumpStatement(e) ;separator="\n") | ||
| 1043 | let src_str = dumpSource(source) | ||
| 1044 | << | ||
| 1045 | while <%while_cond%> loop | ||
| 1046 | <%body_str%> | ||
| 1047 | end while<%src_str%>; | ||
| 1048 | >> | ||
| 1049 | end dumpWhileStatement; | ||
| 1050 | |||
| 1051 | 56 | template dumpWhenStatement(DAE.Statement stmt) | |
| 1052 | ::= | ||
| 1053 | match stmt | ||
| 1054 | case STMT_WHEN(__) then | ||
| 1055 | let when_cond_str = dumpExp(exp) | ||
| 1056 | let body_str = (statementLst |> e => dumpStatement(e) ;separator="\n") | ||
| 1057 | let elsewhen_str = match elseWhen case SOME(ew) then dumpWhenStatement(ew) | ||
| 1058 | let src_str = dumpSource(source) | ||
| 1059 | if not elsewhen_str then | ||
| 1060 | << | ||
| 1061 | when <%when_cond_str%> then | ||
| 1062 | <%body_str%> | ||
| 1063 | end when<%src_str%>; | ||
| 1064 | >> | ||
| 1065 | else | ||
| 1066 | << | ||
| 1067 | when <%when_cond_str%> then | ||
| 1068 | <%body_str%> | ||
| 1069 | else<%elsewhen_str%> | ||
| 1070 | >> | ||
| 1071 | end dumpWhenStatement; | ||
| 1072 | |||
| 1073 | 2 | template dumpReinitStatement(DAE.Statement stmt) | |
| 1074 | ::= | ||
| 1075 | match stmt | ||
| 1076 | case STMT_REINIT(__) then | ||
| 1077 | let exp_str = dumpExp(var) | ||
| 1078 | let new_exp_str = dumpExp(value) | ||
| 1079 | let src_str = dumpSource(source) | ||
| 1080 | << | ||
| 1081 | reinit(<%exp_str%>, <%new_exp_str%>)<%src_str%>; | ||
| 1082 | >> | ||
| 1083 | end dumpReinitStatement; | ||
| 1084 | |||
| 1085 | /***************************************************************************** | ||
| 1086 | * SECTION: STATE MACHINES * | ||
| 1087 | *****************************************************************************/ | ||
| 1088 | 3 | template dumpStateMachineSection(DAEDumpTypes.compWithSplitElements fixedDae) | |
| 1089 | ::= | ||
| 1090 | match fixedDae case COMP_WITH_SPLIT(__) then | ||
| 1091 | /* Whether we have a DAE.FLAT_SM (stateMachine) or DAE.STATE_SM (state) is encoded in the comment. | ||
| 1092 | That is a bit hackish */ | ||
| 1093 | let kind = match comment case SOME(co) then dumpStateMachineComment(co) | ||
| 1094 | << | ||
| 1095 | <%kind%> <%name%> | ||
| 1096 | <%dumpCompStream(spltElems)%> | ||
| 1097 | end <%name%>;<%\n%> | ||
| 1098 | >> | ||
| 1099 | end dumpStateMachineSection; | ||
| 1100 | |||
| 1101 | 3 | template dumpStateMachineComment(SCode.Comment cmt) | |
| 1102 | ::= | ||
| 1103 | match cmt case COMMENT(__) then | ||
| 1104 | let kind_str = match comment case SOME(co) then co | ||
| 1105 | '<%kind_str%>' | ||
| 1106 | end dumpStateMachineComment; | ||
| 1107 | |||
| 1108 | |||
| 1109 | /***************************************************************************** | ||
| 1110 | * SECTION: EXPRESSIONS * | ||
| 1111 | *****************************************************************************/ | ||
| 1112 | 59138 | template dumpExp(DAE.Exp exp) | |
| 1113 | ::= ExpressionDumpTpl.dumpExp(exp, "\"") | ||
| 1114 | end dumpExp; | ||
| 1115 | |||
| 1116 | 1519 | template dumpClassAnnotation(Option<SCode.Comment> comment) | |
| 1117 | ::= | ||
| 1118 | let cmt_str = dumpCommentAnnotation(comment) | ||
| 1119 | if cmt_str then '<%cmt_str%>;' | ||
| 1120 | end dumpClassAnnotation; | ||
| 1121 | |||
| 1122 | 17531 | template dumpCompAnnotation(Option<SCode.Comment> comment) | |
| 1123 | ::= | ||
| 1124 | let cmt_str = dumpCommentAnnotation(comment) | ||
| 1125 | if cmt_str then '<%\ %><%cmt_str%>' | ||
| 1126 | end dumpCompAnnotation; | ||
| 1127 | |||
| 1128 | 19050 | template dumpCommentAnnotation(Option<SCode.Comment> comment) | |
| 1129 | ::= match comment case SOME(cmt) then dumpCommentAnnotationNoOpt(cmt) | ||
| 1130 | end dumpCommentAnnotation; | ||
| 1131 | |||
| 1132 | 1932 | template dumpCommentAnnotationNoOpt(SCode.Comment comment) | |
| 1133 | ::= match comment case SCode.COMMENT(annotation_ = SOME(ann)) then dumpAnnotation(ann) | ||
| 1134 | end dumpCommentAnnotationNoOpt; | ||
| 1135 | |||
| 1136 | 19050 | template dumpCommentOpt(Option<SCode.Comment> comment) | |
| 1137 | ::= match comment case SOME(cmt) then dumpComment(cmt) | ||
| 1138 | end dumpCommentOpt; | ||
| 1139 | |||
| 1140 | 24613 | template dumpComment(SCode.Comment comment) | |
| 1141 | ::= match comment case COMMENT(__) then dumpCommentStr(comment) | ||
| 1142 | end dumpComment; | ||
| 1143 | |||
| 1144 | 7433 | template dumpCommentStr(Option<String> comment) | |
| 1145 | ::= match comment case SOME(cmt) then '<%\ %>"<%System.escapedString(cmt,false)%>"' | ||
| 1146 | end dumpCommentStr; | ||
| 1147 | |||
| 1148 | ✗ | template dumpAnnotationOpt(Option<SCode.Annotation> annotation) | |
| 1149 | ::= match annotation case SOME(ann) then dumpAnnotation(ann) | ||
| 1150 | end dumpAnnotationOpt; | ||
| 1151 | |||
| 1152 | 1948 | template dumpAnnotation(SCode.Annotation annotation) | |
| 1153 | ::= | ||
| 1154 | match annotation | ||
| 1155 | case SCode.ANNOTATION(modification = ann_mod) then | ||
| 1156 | if Config.showAnnotations() then | ||
| 1157 | 'annotation<%SCodeDumpTpl.dumpModifier(ann_mod, SCodeDump.defaultOptions)%>' | ||
| 1158 | else if Config.showStructuralAnnotations() then | ||
| 1159 | let ann_str = SCodeDumpTpl.dumpModifier(DAEDumpTypes.filterStructuralMods(ann_mod), SCodeDump.defaultOptions) | ||
| 1160 | if ann_str then | ||
| 1161 | 'annotation<%ann_str%>' | ||
| 1162 | end dumpAnnotation; | ||
| 1163 | |||
| 1164 | 402 | template dumpPathLastIndent(Absyn.Path path) | |
| 1165 | ::= | ||
| 1166 | match path | ||
| 1167 | case FULLYQUALIFIED(__) then dumpPathLastIndent(path) | ||
| 1168 | case QUALIFIED(__) then dumpPathLastIndent(path) | ||
| 1169 | case IDENT(__) then '<%name%>' | ||
| 1170 | else errorMsg("dumpPathLastIndent: Unknown path.") | ||
| 1171 | end dumpPathLastIndent; | ||
| 1172 | |||
| 1173 | 9865 | template dumpSource(DAE.ElementSource source) | |
| 1174 | ::= | ||
| 1175 | match source | ||
| 1176 | case SOURCE(__) then (comment |> c => dumpComment(c) ;separator=" + ") | ||
| 1177 | end dumpSource; | ||
| 1178 | |||
| 1179 | ✗ | template errorMsg(String errMessage) | |
| 1180 | ::= | ||
| 1181 | let() = Tpl.addTemplateError(errMessage) | ||
| 1182 | << | ||
| 1183 | <%errMessage%> | ||
| 1184 | >> | ||
| 1185 | end errorMsg; | ||
| 1186 | |||
| 1187 | annotation(__OpenModelica_Interface="frontend_dump"); | ||
| 1188 | end DAEDumpTpl; | ||
| 1189 |