OMCompiler/Compiler/Template/SCodeDumpTpl.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 SCodeDumpTpl | ||
| 37 | |||
| 38 | import interface SCodeTV; | ||
| 39 | import AbsynDumpTpl; | ||
| 40 | |||
| 41 | 5 | template dumpProgram(list<SCode.Element> program, SCodeDumpOptions options) | |
| 42 | ::= dumpElements(program, false, options) | ||
| 43 | end dumpProgram; | ||
| 44 | |||
| 45 | 254 | template dumpElements(list<SCode.Element> elements, Boolean indent, SCodeDumpOptions options) | |
| 46 | ::= dumpElements2(filterElements(elements,options), indent, options) | ||
| 47 | end dumpElements; | ||
| 48 | |||
| 49 | 254 | template dumpElements2(list<SCode.Element> elements, | |
| 50 | Boolean indent, SCodeDumpOptions options) | ||
| 51 | ::= | ||
| 52 | dumpElements3(elements, listLength(elements), makeStatefulBoolean(false), indent, makeStatefulBoolean(true), options) | ||
| 53 | end dumpElements2; | ||
| 54 | |||
| 55 | 254 | template dumpElements3(list<SCode.Element> elements, Integer numElements, array<Boolean> prevSpacing, | |
| 56 | Boolean indent, array<Boolean> inPublicSection, SCodeDumpOptions options) | ||
| 57 | ::= | ||
| 58 | elements |> el hasindex i1 fromindex 1 => | ||
| 59 | let spacing = dumpElementSpacing(el) | ||
| 60 | let pre_spacing = if boolNot(intEq(1,i1)) then dumpPreElementSpacing(spacing, getStatefulBoolean(prevSpacing)) | ||
| 61 | let el_str = dumpElement(el,'',options) | ||
| 62 | let vis_str = dumpElementVisibility(el, getStatefulBoolean(inPublicSection)) | ||
| 63 | let dummyTxt = if vis_str then setStatefulBoolean(inPublicSection, boolNot(getStatefulBoolean(inPublicSection))) | ||
| 64 | let post_spacing = if boolNot(intEq(i1, numElements)) | ||
| 65 | then | ||
| 66 | (if spacing then | ||
| 67 | let () = setStatefulBoolean(prevSpacing, true) | ||
| 68 | spacing | ||
| 69 | else | ||
| 70 | let () = setStatefulBoolean(prevSpacing, false) | ||
| 71 | "") | ||
| 72 | else | ||
| 73 | let () = setStatefulBoolean(prevSpacing, false) | ||
| 74 | "" | ||
| 75 | if indent then | ||
| 76 | << | ||
| 77 | <%pre_spacing%><%vis_str%> | ||
| 78 | <%el_str%>;<%post_spacing%><%\n%> | ||
| 79 | >> | ||
| 80 | else | ||
| 81 | << | ||
| 82 | <%pre_spacing%><%vis_str%> | ||
| 83 | <%el_str%>;<%post_spacing%><%\n%> | ||
| 84 | >> | ||
| 85 | end dumpElements3; | ||
| 86 | |||
| 87 | 1375 | template dumpPreElementSpacing(String curSpacing, Boolean prevSpacing) | |
| 88 | ::= if not prevSpacing then curSpacing | ||
| 89 | end dumpPreElementSpacing; | ||
| 90 | |||
| 91 | 331 | template dumpElementSpacing(SCode.Element element) | |
| 92 | ::= match element case CLASS(__) then dumpClassDefSpacing(classDef) | ||
| 93 | end dumpElementSpacing; | ||
| 94 | |||
| 95 | 242 | template dumpClassDefSpacing(SCode.ClassDef classDef) | |
| 96 | ::= | ||
| 97 | match classDef | ||
| 98 | case CLASS_EXTENDS(__) then dumpClassDefSpacing(composition) | ||
| 99 | case PARTS(__) then '<%\n%>' | ||
| 100 | end dumpClassDefSpacing; | ||
| 101 | |||
| 102 | 1125 | template dumpElement(SCode.Element element, String each, SCodeDumpOptions options) | |
| 103 | ::= | ||
| 104 | match element | ||
| 105 | case IMPORT(__) then | ||
| 106 | match visibility | ||
| 107 | case PROTECTED(__) then (match options case OPTIONS(stripProtectedImports=true) then "" else dumpImport(element)) else dumpImport(element) | ||
| 108 | case EXTENDS(__) then dumpExtends(element,options) | ||
| 109 | case CLASS(__) then dumpClass(element, each, options) | ||
| 110 | case COMPONENT(__) then dumpComponent(element, each, options) | ||
| 111 | case DEFINEUNIT(__) then dumpDefineUnit(element) | ||
| 112 | else errorMsg("SCodeDump.dumpElement: Unknown element.") | ||
| 113 | end dumpElement; | ||
| 114 | |||
| 115 | 1068 | template dumpElementVisibility(SCode.Element element, Boolean inPublicSection) | |
| 116 | ::= | ||
| 117 | match element | ||
| 118 | case IMPORT(__) then dumpSectionVisibility(visibility, inPublicSection) | ||
| 119 | case EXTENDS(__) then dumpSectionVisibility(visibility, inPublicSection) | ||
| 120 | case CLASS(prefixes = PREFIXES(visibility = vis)) then | ||
| 121 | dumpSectionVisibility(vis, inPublicSection) | ||
| 122 | case COMPONENT(prefixes = PREFIXES(visibility = vis)) then | ||
| 123 | dumpSectionVisibility(vis, inPublicSection) | ||
| 124 | case DEFINEUNIT(__) then dumpSectionVisibility(visibility, inPublicSection) | ||
| 125 | end dumpElementVisibility; | ||
| 126 | |||
| 127 | 1353 | template dumpSectionVisibility(SCode.Visibility visibility, | |
| 128 | Boolean inPublicSection) | ||
| 129 | ::= | ||
| 130 | match visibility | ||
| 131 | case SCode.PUBLIC(__) then | ||
| 132 | if not inPublicSection then 'public<%\n%>' | ||
| 133 | case SCode.PROTECTED(__) then | ||
| 134 | if inPublicSection then 'protected<%\n%>' | ||
| 135 | end dumpSectionVisibility; | ||
| 136 | |||
| 137 | 44 | template dumpImport(SCode.Element import) | |
| 138 | ::= | ||
| 139 | match import | ||
| 140 | case IMPORT(__) then | ||
| 141 | let visibility_str = dumpVisibility(visibility) | ||
| 142 | let import_str = match imp | ||
| 143 | case NAMED_IMPORT(__) then | ||
| 144 | 'import <%name%> = <%AbsynDumpTpl.dumpPath(path)%>' | ||
| 145 | case QUAL_IMPORT(__) then | ||
| 146 | 'import <%AbsynDumpTpl.dumpPath(path)%>' | ||
| 147 | case UNQUAL_IMPORT(__) then | ||
| 148 | 'import <%AbsynDumpTpl.dumpPath(path)%>.*' | ||
| 149 | else errorMsg("SCodeDump.dumpImport: Unknown import.") | ||
| 150 | '<%visibility_str%><%import_str%>' | ||
| 151 | end dumpImport; | ||
| 152 | |||
| 153 | 169 | template dumpExtends(SCode.Element extends, SCodeDumpOptions options) | |
| 154 | ::= | ||
| 155 | match extends | ||
| 156 | case EXTENDS(__) then | ||
| 157 | let bc_str = AbsynDumpTpl.dumpPath(baseClassPath) | ||
| 158 | let visibility_str = dumpVisibility(visibility) | ||
| 159 | let mod_str = dumpModifier(modifications, options) | ||
| 160 | let ann_str = dumpAnnotationOpt(ann, options) | ||
| 161 | '<%visibility_str%>extends <%bc_str%><%mod_str%><%ann_str%>' | ||
| 162 | end dumpExtends; | ||
| 163 | |||
| 164 | 360 | template dumpClass(SCode.Element class, String each, SCodeDumpOptions options) | |
| 165 | ::= | ||
| 166 | match class | ||
| 167 | case CLASS(__) then | ||
| 168 | let prefix_str = dumpPrefixes(prefixes, each) | ||
| 169 | let enc_str = dumpEncapsulated(encapsulatedPrefix) | ||
| 170 | let partial_str = dumpPartial(partialPrefix) | ||
| 171 | let res_str = dumpRestriction(restriction) | ||
| 172 | let prefixes_str = '<%prefix_str%><%enc_str%><%partial_str%><%res_str%>' | ||
| 173 | let cdef_str = dumpClassDef(classDef, options) | ||
| 174 | let cmt_str = dumpClassComment(cmt, options) | ||
| 175 | let ann_str = dumpClassAnnotation(cmt, options) | ||
| 176 | let cc_str = dumpReplaceableConstrainClass(prefixes, options) | ||
| 177 | let header_str = dumpClassHeader(classDef, name, restriction, cmt_str, options) | ||
| 178 | let footer_str = dumpClassFooter(classDef, cdef_str, name, cmt_str, ann_str, cc_str) | ||
| 179 | << | ||
| 180 | <%prefixes_str%> <%header_str%><%footer_str%> | ||
| 181 | >> | ||
| 182 | end dumpClass; | ||
| 183 | |||
| 184 | 232 | template dumpClassHeader(SCode.ClassDef classDef, String name, SCode.Restriction restr, String cmt, SCodeDumpOptions options) | |
| 185 | ::= | ||
| 186 | match classDef | ||
| 187 | case CLASS_EXTENDS(__) | ||
| 188 | then | ||
| 189 | let mod_str = dumpModifier(modifications, options) | ||
| 190 | 'extends <%name%><%mod_str%><%cmt%>' | ||
| 191 | case PARTS(__) then '<%name%><%dumpRestrictionTypeVars(restr)%><%cmt%>' | ||
| 192 | else '<%name%>' | ||
| 193 | end dumpClassHeader; | ||
| 194 | |||
| 195 | 249 | template dumpClassDef(SCode.ClassDef classDef, SCodeDumpOptions options) | |
| 196 | ::= | ||
| 197 | match classDef | ||
| 198 | case p as PARTS(__) then | ||
| 199 | let el_str = dumpElements(elementLst, true, options) | ||
| 200 | let neq_str = dumpEquations(normalEquationLst, "equation", options) | ||
| 201 | let ieq_str = dumpEquations(initialEquationLst, "initial equation", options) | ||
| 202 | let nal_str = match options case OPTIONS(stripAlgorithmSections=false) then dumpAlgorithmSections(p.normalAlgorithmLst, "algorithm", options) | ||
| 203 | let ial_str = match options case OPTIONS(stripAlgorithmSections=false) then dumpAlgorithmSections(p.initialAlgorithmLst, "initial algorithm", options) | ||
| 204 | let extdecl_str = dumpExternalDeclOpt(p.externalDecl, options) | ||
| 205 | let cdef_str = | ||
| 206 | << | ||
| 207 | <%el_str%> | ||
| 208 | <%ieq_str%> | ||
| 209 | <%ial_str%> | ||
| 210 | <%neq_str%> | ||
| 211 | <%nal_str%> | ||
| 212 | <%extdecl_str%> | ||
| 213 | >> | ||
| 214 | cdef_str | ||
| 215 | case CLASS_EXTENDS(__) then | ||
| 216 | let mod_str = dumpModifier(modifications,options) | ||
| 217 | let cdef_str = dumpClassDef(composition,options) | ||
| 218 | << | ||
| 219 | <%cdef_str%> | ||
| 220 | >> | ||
| 221 | case DERIVED(__) then | ||
| 222 | let type_str = AbsynDumpTpl.dumpTypeSpec(typeSpec) | ||
| 223 | let mod_str = dumpModifier(modifications,options) | ||
| 224 | let attr_str = dumpAttributes(attributes) | ||
| 225 | ' = <%attr_str%><%type_str%><%mod_str%>' | ||
| 226 | case ENUMERATION(__) then | ||
| 227 | let enum_str = if enumLst then | ||
| 228 | (enumLst |> enum => dumpEnumLiteral(enum, options) ;separator=", ") | ||
| 229 | else | ||
| 230 | ':' | ||
| 231 | ' = enumeration(<%enum_str%>)' | ||
| 232 | case PDER(__) then | ||
| 233 | let func_str = AbsynDumpTpl.dumpPath(functionPath) | ||
| 234 | ' = der(<%func_str%>, <%derivedVariables ;separator=", "%>)' | ||
| 235 | case OVERLOAD(__) then | ||
| 236 | ' = overload(<%pathLst |> path => AbsynDumpTpl.dumpPath(path); separator=", "%>)' | ||
| 237 | else errorMsg("SCodeDump.dumpClassDef: Unknown class definition.") | ||
| 238 | end dumpClassDef; | ||
| 239 | |||
| 240 | 249 | template dumpClassFooter(SCode.ClassDef classDef, String cdefStr, String name, String cmt, String ann, String cc_str) | |
| 241 | ::= | ||
| 242 | match classDef | ||
| 243 | case DERIVED(__) then '<%cdefStr%><%cmt%><%ann%><%cc_str%>' | ||
| 244 | case ENUMERATION(__) then '<%cdefStr%><%cmt%><%ann%><%cc_str%>' | ||
| 245 | case PDER(__) then cdefStr | ||
| 246 | case _ then | ||
| 247 | let annstr = if ann then '<%ann%>;' else '' | ||
| 248 | if cdefStr then | ||
| 249 | << | ||
| 250 | |||
| 251 | <%cdefStr%> | ||
| 252 | <%if annstr then " "%><%annstr%> | ||
| 253 | end <%name%><%cc_str%> | ||
| 254 | >> | ||
| 255 | else | ||
| 256 | << | ||
| 257 | <%annstr%> end <%name%><%cc_str%> | ||
| 258 | >> | ||
| 259 | end dumpClassFooter; | ||
| 260 | |||
| 261 | 360 | template dumpClassComment(SCode.Comment comment, SCodeDumpOptions options) | |
| 262 | ::= | ||
| 263 | match comment | ||
| 264 | case COMMENT(__) then dumpCommentStr(comment, options) | ||
| 265 | end dumpClassComment; | ||
| 266 | |||
| 267 | 360 | template dumpClassAnnotation(SCode.Comment comment, SCodeDumpOptions options) | |
| 268 | ::= | ||
| 269 | match comment | ||
| 270 | case COMMENT(__) then dumpAnnotationOpt(annotation_, options) | ||
| 271 | end dumpClassAnnotation; | ||
| 272 | |||
| 273 | 1125 | template dumpComponent(SCode.Element component, String each, SCodeDumpOptions options) | |
| 274 | ::= | ||
| 275 | match component | ||
| 276 | case COMPONENT(__) then | ||
| 277 | let prefix_str = dumpPrefixes(prefixes, each) | ||
| 278 | let cc_str = dumpReplaceableConstrainClass(prefixes,options) | ||
| 279 | let attr_pre_str = dumpAttributes(attributes) | ||
| 280 | let attr_dim_str = dumpAttributeDim(attributes) | ||
| 281 | let type_str = AbsynDumpTpl.dumpTypeSpec(typeSpec) | ||
| 282 | let mod_str1 = dumpModifier(modifications,options) | ||
| 283 | let mod_str = // If stripOutputBindings is set, we need to look for the direction | ||
| 284 | match options | ||
| 285 | case OPTIONS(stripOutputBindings=false) then mod_str1 | ||
| 286 | else match attributes | ||
| 287 | case ATTR(direction=OUTPUT(__)) then "" | ||
| 288 | else mod_str1 | ||
| 289 | end match | ||
| 290 | let cond_str = match condition case SOME(cond) then ' if <%AbsynDumpTpl.dumpExp(cond)%>' | ||
| 291 | let cmt_str = dumpComment(comment, options) | ||
| 292 | '<%prefix_str%><%attr_pre_str%><%type_str%> <%name%><%attr_dim_str%><%mod_str%><%cond_str%><%cc_str%><%cmt_str%>' | ||
| 293 | end dumpComponent; | ||
| 294 | |||
| 295 | ✗ | template dumpDefineUnit(SCode.Element defineUnit) | |
| 296 | ::= | ||
| 297 | match defineUnit | ||
| 298 | case DEFINEUNIT(__) then | ||
| 299 | let vis_str = dumpVisibility(visibility) | ||
| 300 | let exp_str = match exp case SOME(e) then 'exp = "<%e%>"' | ||
| 301 | let weight_str = match weight case SOME(w) then 'weight = <%w%>' | ||
| 302 | let args_str = {exp_str, weight_str} ;separator=", " | ||
| 303 | let pb = if args_str then '(' | ||
| 304 | let pe = if args_str then ')' | ||
| 305 | 'defineunit <%name%><%pb%><%args_str%><%pe%>' | ||
| 306 | end dumpDefineUnit; | ||
| 307 | |||
| 308 | 20 | template dumpEnumLiteral(SCode.Enum enum, SCodeDumpOptions options) | |
| 309 | ::= | ||
| 310 | match enum | ||
| 311 | case ENUM(__) then | ||
| 312 | let cmt_str = dumpComment(comment, options) | ||
| 313 | '<%literal%><%cmt_str%>' | ||
| 314 | end dumpEnumLiteral; | ||
| 315 | |||
| 316 | 26 | template dumpEquations(list<SCode.Equation> equations, String label, SCodeDumpOptions options) | |
| 317 | ::= | ||
| 318 | if equations then | ||
| 319 | << | ||
| 320 | <%label%> | ||
| 321 | <%equations |> eq => dumpEquation(eq, options) ;separator="\n"%> | ||
| 322 | >> | ||
| 323 | end dumpEquations; | ||
| 324 | |||
| 325 | 264 | template dumpEquation(SCode.Equation equation, SCodeDumpOptions options) | |
| 326 | ::= | ||
| 327 | match equation | ||
| 328 | case EQ_IF(__) then dumpIfEquation(equation, options) | ||
| 329 | case EQ_EQUALS(__) then | ||
| 330 | let lhs_str = AbsynDumpTpl.dumpLhsExp(expLeft) | ||
| 331 | let rhs_str = AbsynDumpTpl.dumpExp(expRight) | ||
| 332 | let cmt_str = dumpComment(comment, options) | ||
| 333 | '<%lhs_str%> = <%rhs_str%><%cmt_str%>;' | ||
| 334 | case EQ_CONNECT(__) then | ||
| 335 | let lhs_str = AbsynDumpTpl.dumpCref(crefLeft) | ||
| 336 | let rhs_str = AbsynDumpTpl.dumpCref(crefRight) | ||
| 337 | let cmt_str = dumpComment(comment, options) | ||
| 338 | 'connect(<%lhs_str%>, <%rhs_str%>)<%cmt_str%>;' | ||
| 339 | case EQ_FOR(__) then dumpForEquation(equation, options) | ||
| 340 | case EQ_WHEN(__) then dumpWhenEquation(equation, options) | ||
| 341 | case EQ_ASSERT(__) then | ||
| 342 | let cond_str = AbsynDumpTpl.dumpExp(condition) | ||
| 343 | let msg_str = AbsynDumpTpl.dumpExp(message) | ||
| 344 | let lvl_str = dumpAssertionLevel(level) | ||
| 345 | let cmt_str = dumpComment(comment, options) | ||
| 346 | 'assert(<%cond_str%>, <%msg_str%><%lvl_str%>)<%cmt_str%>;' | ||
| 347 | case EQ_TERMINATE(__) then | ||
| 348 | let msg_str = AbsynDumpTpl.dumpExp(message) | ||
| 349 | let cmt_str = dumpComment(comment, options) | ||
| 350 | 'terminate(<%msg_str%>)<%cmt_str%>;' | ||
| 351 | case EQ_REINIT(__) then | ||
| 352 | let cref_str = AbsynDumpTpl.dumpExp(cref) | ||
| 353 | let exp_str = AbsynDumpTpl.dumpExp(expReinit) | ||
| 354 | let cmt_str = dumpComment(comment, options) | ||
| 355 | 'reinit(<%cref_str%>, <%exp_str%>)<%cmt_str%>;' | ||
| 356 | case EQ_NORETCALL(__) then | ||
| 357 | let exp_str = AbsynDumpTpl.dumpExp(exp) | ||
| 358 | let cmt_str = dumpComment(comment, options) | ||
| 359 | '<%exp_str%><%cmt_str%>;' | ||
| 360 | else errorMsg("SCodeDump.dumpEquation: Unknown Equation.") | ||
| 361 | end dumpEquation; | ||
| 362 | |||
| 363 | 43 | template dumpIfEquation(SCode.Equation ifequation, SCodeDumpOptions options) | |
| 364 | ::= | ||
| 365 | match ifequation | ||
| 366 | case EQ_IF(condition = if_cond :: elseif_conds, | ||
| 367 | thenBranch = if_branch :: elseif_branches) then | ||
| 368 | let if_cond_str = AbsynDumpTpl.dumpExp(if_cond) | ||
| 369 | let if_branch_str = (if_branch |> e => dumpEquation(e, options) ;separator="\n") | ||
| 370 | let elseif_str = dumpElseIfEquation(elseif_conds, elseif_branches, options) | ||
| 371 | let else_str = if elseBranch then | ||
| 372 | << | ||
| 373 | else | ||
| 374 | <%elseBranch |> e => dumpEquation(e, options) ;separator="\n"%> | ||
| 375 | >> | ||
| 376 | let cmt_str = dumpComment(comment, options) | ||
| 377 | << | ||
| 378 | if <%if_cond_str%> then | ||
| 379 | <%if_branch_str%> | ||
| 380 | <%elseif_str%> | ||
| 381 | <%else_str%> | ||
| 382 | end if<%cmt_str%>; | ||
| 383 | >> | ||
| 384 | end dumpIfEquation; | ||
| 385 | |||
| 386 | 19 | template dumpElseIfEquation(list<Absyn.Exp> condition, | |
| 387 | list<list<SCode.Equation>> branches, SCodeDumpOptions options) | ||
| 388 | ::= | ||
| 389 | match condition | ||
| 390 | case cond :: rest_conds then | ||
| 391 | match branches | ||
| 392 | case branch :: rest_branches then | ||
| 393 | let cond_str = AbsynDumpTpl.dumpExp(cond) | ||
| 394 | let branch_str = (branch |> e => dumpEquation(e, options) ;separator="\n") | ||
| 395 | let rest_str = dumpElseIfEquation(rest_conds, rest_branches, options) | ||
| 396 | << | ||
| 397 | elseif <%cond_str%> then | ||
| 398 | <%branch_str%> | ||
| 399 | <%rest_str%> | ||
| 400 | >> | ||
| 401 | end dumpElseIfEquation; | ||
| 402 | |||
| 403 | 18 | template dumpForEquation(SCode.Equation for_equation, SCodeDumpOptions options) | |
| 404 | ::= | ||
| 405 | match for_equation | ||
| 406 | case EQ_FOR(range=SOME(range)) then | ||
| 407 | let range_str = AbsynDumpTpl.dumpExp(range) | ||
| 408 | let eq_str = (eEquationLst |> e => dumpEquation(e, options) ;separator="\n") | ||
| 409 | let cmt_str = dumpComment(comment, options) | ||
| 410 | << | ||
| 411 | for <%index%> in <%range_str%> loop | ||
| 412 | <%eq_str%> | ||
| 413 | end for<%cmt_str%>; | ||
| 414 | >> | ||
| 415 | case EQ_FOR(__) then | ||
| 416 | let eq_str = (eEquationLst |> e => dumpEquation(e, options) ;separator="\n") | ||
| 417 | let cmt_str = dumpComment(comment, options) | ||
| 418 | << | ||
| 419 | for <%index%> loop | ||
| 420 | <%eq_str%> | ||
| 421 | end for<%cmt_str%>; | ||
| 422 | >> | ||
| 423 | end dumpForEquation; | ||
| 424 | |||
| 425 | ✗ | template dumpWhenEquation(SCode.Equation when_equation, SCodeDumpOptions options) | |
| 426 | ::= | ||
| 427 | match when_equation | ||
| 428 | case EQ_WHEN(__) then | ||
| 429 | let cond_str = AbsynDumpTpl.dumpExp(condition) | ||
| 430 | let body_str = (eEquationLst |> e => dumpEquation(e, options) ;separator="\n") | ||
| 431 | let else_str = (elseBranches |> (else_cond, else_body) => | ||
| 432 | let else_cond_str = AbsynDumpTpl.dumpExp(else_cond) | ||
| 433 | let else_body_str = (else_body |> e => dumpEquation(e, options) ;separator="\n") | ||
| 434 | << | ||
| 435 | elsewhen <%else_cond_str%> then | ||
| 436 | <%else_body_str%> | ||
| 437 | >> ;separator="\n") | ||
| 438 | let cmt_str = dumpComment(comment, options) | ||
| 439 | << | ||
| 440 | when <%cond_str%> then | ||
| 441 | <%body_str%> | ||
| 442 | <%else_str%> | ||
| 443 | end when<%cmt_str%>; | ||
| 444 | >> | ||
| 445 | end dumpWhenEquation; | ||
| 446 | |||
| 447 | ✗ | template dumpAssertionLevel(Absyn.Exp exp) | |
| 448 | ::= match exp | ||
| 449 | case CREF(componentRef = CREF_FULLYQUALIFIED(componentRef = CREF_QUAL( | ||
| 450 | name = "AssertionLevel", componentRef = CREF_IDENT(name = "error")))) then "" | ||
| 451 | case CREF(componentRef = CREF_QUAL(name = "AssertionLevel", | ||
| 452 | componentRef = CREF_IDENT(name = "error"))) then "" | ||
| 453 | else ', <%AbsynDumpTpl.dumpExp(exp)%>' | ||
| 454 | end dumpAssertionLevel; | ||
| 455 | |||
| 456 | 70 | template dumpAlgorithmSections(list<SCode.AlgorithmSection> algorithms, | |
| 457 | String label, SCodeDumpOptions options) | ||
| 458 | ::= | ||
| 459 | if algorithms then | ||
| 460 | << | ||
| 461 | <%label%> | ||
| 462 | <%algorithms |> al => dumpAlgorithmSection(al, options) ;separator="\n"%> | ||
| 463 | >> | ||
| 464 | end dumpAlgorithmSections; | ||
| 465 | |||
| 466 | 70 | template dumpAlgorithmSection(SCode.AlgorithmSection algorithm, SCodeDumpOptions options) | |
| 467 | ::= match algorithm case ALGORITHM(__) then dumpStatements(statements, options) | ||
| 468 | end dumpAlgorithmSection; | ||
| 469 | |||
| 470 | 155 | template dumpStatements(list<SCode.Statement> statements, SCodeDumpOptions options) | |
| 471 | ::= statements |> s => dumpStatement(s, options) ;separator="\n" | ||
| 472 | end dumpStatements; | ||
| 473 | |||
| 474 | 255 | template dumpStatement(SCode.Statement statement, SCodeDumpOptions options) | |
| 475 | ::= | ||
| 476 | match statement | ||
| 477 | case ALG_ASSIGN(__) then | ||
| 478 | let lhs_str = AbsynDumpTpl.dumpLhsExp(assignComponent) | ||
| 479 | let rhs_str = AbsynDumpTpl.dumpExp(value) | ||
| 480 | let cmt_str = dumpComment(comment, options) | ||
| 481 | '<%lhs_str%> := <%rhs_str%><%cmt_str%>;' | ||
| 482 | case ALG_IF(__) then dumpIfStatement(statement, options) | ||
| 483 | case ALG_FOR(__) then dumpForStatement(statement, options) | ||
| 484 | case ALG_WHILE(__) then dumpWhileStatement(statement, options) | ||
| 485 | case ALG_WHEN_A(__) then dumpWhenStatement(statement, options) | ||
| 486 | case ALG_ASSERT(__) then | ||
| 487 | let cond_str = AbsynDumpTpl.dumpExp(condition) | ||
| 488 | let msg_str = AbsynDumpTpl.dumpExp(message) | ||
| 489 | let lvl_str = dumpAssertionLevel(level) | ||
| 490 | 'assert(<%cond_str%>, <%msg_str%><%lvl_str%>);' | ||
| 491 | case ALG_TERMINATE(__) then | ||
| 492 | let msg_str = AbsynDumpTpl.dumpExp(message) | ||
| 493 | 'terminate(<%msg_str%>);' | ||
| 494 | case ALG_REINIT(__) then | ||
| 495 | let cr_str = AbsynDumpTpl.dumpExp(cref) | ||
| 496 | let exp_str = AbsynDumpTpl.dumpExp(newValue) | ||
| 497 | 'reinit(<%cr_str%>, <%exp_str%>);' | ||
| 498 | case ALG_NORETCALL(__) then | ||
| 499 | let exp_str = AbsynDumpTpl.dumpExp(exp) | ||
| 500 | let cmt_str = dumpComment(comment, options) | ||
| 501 | '<%exp_str%><%cmt_str%>;' | ||
| 502 | case ALG_RETURN(__) then | ||
| 503 | let cmt_str = dumpComment(comment, options) | ||
| 504 | 'return<%cmt_str%>;' | ||
| 505 | case ALG_BREAK(__) then | ||
| 506 | let cmt_str = dumpComment(comment, options) | ||
| 507 | 'break<%cmt_str%>;' | ||
| 508 | case ALG_FAILURE(stmts={stmt}) then | ||
| 509 | let cmt_str = dumpComment(comment, options) | ||
| 510 | 'failure(<%dumpStatement(stmt,options)%>)<%cmt_str%>;' | ||
| 511 | case SCode.ALG_TRY(__) then dumpTryStatement(statement, options) | ||
| 512 | case ALG_CONTINUE(__) then | ||
| 513 | let cmt_str = dumpComment(comment, options) | ||
| 514 | 'continue<%cmt_str%>;' | ||
| 515 | else errorMsg("SCodeDump.dumpStatement: Unknown statement.") | ||
| 516 | end dumpStatement; | ||
| 517 | |||
| 518 | 35 | template dumpIfStatement(SCode.Statement if_statement, SCodeDumpOptions options) | |
| 519 | ::= | ||
| 520 | match if_statement | ||
| 521 | case ALG_IF(__) then | ||
| 522 | let cond_str = AbsynDumpTpl.dumpExp(boolExpr) | ||
| 523 | let true_branch_str = dumpStatements(trueBranch, options) | ||
| 524 | let else_if_str = dumpElseIfStatements(elseIfBranch, options) | ||
| 525 | let else_branch_str = dumpStatements(elseBranch, options) | ||
| 526 | let cmt_str = dumpComment(comment, options) | ||
| 527 | << | ||
| 528 | if <%cond_str%> then | ||
| 529 | <%true_branch_str%> | ||
| 530 | <%else_if_str%> | ||
| 531 | else | ||
| 532 | <%else_branch_str%> | ||
| 533 | end if<%cmt_str%>; | ||
| 534 | >> | ||
| 535 | end dumpIfStatement; | ||
| 536 | |||
| 537 | 35 | template dumpElseIfStatements(list<tuple<Absyn.Exp, list<SCode.Statement>>> else_if, SCodeDumpOptions options) | |
| 538 | ::= | ||
| 539 | else_if |> eib as (cond, body) => | ||
| 540 | let cond_str = AbsynDumpTpl.dumpExp(cond) | ||
| 541 | let body_str = dumpStatements(body, options) | ||
| 542 | << | ||
| 543 | elseif <%cond_str%> then | ||
| 544 | <%body_str%> | ||
| 545 | >> ;separator="\n" | ||
| 546 | end dumpElseIfStatements; | ||
| 547 | |||
| 548 | 4 | template dumpForStatement(SCode.Statement for_statement, SCodeDumpOptions options) | |
| 549 | ::= | ||
| 550 | match for_statement | ||
| 551 | case ALG_FOR(range=SOME(e)) then | ||
| 552 | let range_str = AbsynDumpTpl.dumpExp(e) | ||
| 553 | let body_str = dumpStatements(forBody, options) | ||
| 554 | let cmt_str = dumpComment(comment, options) | ||
| 555 | << | ||
| 556 | for <%index%> in <%range_str%> loop | ||
| 557 | <%body_str%> | ||
| 558 | end for<%cmt_str%>; | ||
| 559 | >> | ||
| 560 | case ALG_FOR(__) then | ||
| 561 | let body_str = dumpStatements(forBody, options) | ||
| 562 | let cmt_str = dumpComment(comment, options) | ||
| 563 | << | ||
| 564 | for <%index%> loop | ||
| 565 | <%body_str%> | ||
| 566 | end for<%cmt_str%>; | ||
| 567 | >> | ||
| 568 | end dumpForStatement; | ||
| 569 | |||
| 570 | 1 | template dumpWhileStatement(SCode.Statement while_statement, SCodeDumpOptions options) | |
| 571 | ::= | ||
| 572 | match while_statement | ||
| 573 | case ALG_WHILE(__) then | ||
| 574 | let cond_str = AbsynDumpTpl.dumpExp(boolExpr) | ||
| 575 | let body_str = dumpStatements(whileBody, options) | ||
| 576 | let cmt_str = dumpComment(comment, options) | ||
| 577 | << | ||
| 578 | while <%cond_str%> loop | ||
| 579 | <%body_str%> | ||
| 580 | end while<%cmt_str%>; | ||
| 581 | >> | ||
| 582 | end dumpWhileStatement; | ||
| 583 | |||
| 584 | ✗ | template dumpWhenStatement(SCode.Statement when_statement, SCodeDumpOptions options) | |
| 585 | ::= | ||
| 586 | match when_statement | ||
| 587 | case ALG_WHEN_A(branches = ((when_cond, when_body) :: elsewhens)) then | ||
| 588 | let when_cond_str = AbsynDumpTpl.dumpExp(when_cond) | ||
| 589 | let when_body_str = dumpStatements(when_body, options) | ||
| 590 | let elsewhen_str = (elsewhens |> ew as (ew_cond, ew_body) => | ||
| 591 | let ew_cond_str = AbsynDumpTpl.dumpExp(ew_cond) | ||
| 592 | let ew_body_str = dumpStatements(ew_body, options) | ||
| 593 | << | ||
| 594 | elsewhen <%ew_cond_str%> then | ||
| 595 | <%ew_body_str%> | ||
| 596 | >> ;separator="\n") | ||
| 597 | let cmt_str = dumpComment(comment, options) | ||
| 598 | << | ||
| 599 | when <%when_cond_str%> then | ||
| 600 | <%when_body_str%> | ||
| 601 | <%elsewhen_str%> | ||
| 602 | end when<%cmt_str%>; | ||
| 603 | >> | ||
| 604 | end dumpWhenStatement; | ||
| 605 | |||
| 606 | ✗ | template dumpTryStatement(SCode.Statement try_statement, SCodeDumpOptions options) | |
| 607 | ::= | ||
| 608 | match try_statement | ||
| 609 | case s as ALG_TRY(__) then | ||
| 610 | let cmt_str = dumpComment(comment, options) | ||
| 611 | let algs1 = dumpStatements(body, options) | ||
| 612 | let algs2 = dumpStatements(elseBody, options) | ||
| 613 | << | ||
| 614 | try | ||
| 615 | <%algs1%> | ||
| 616 | else | ||
| 617 | <%algs2%> | ||
| 618 | end try<%cmt_str%>; | ||
| 619 | >> | ||
| 620 | end dumpTryStatement; | ||
| 621 | |||
| 622 | 1485 | template dumpPrefixes(SCode.Prefixes prefixes, String each) | |
| 623 | ::= | ||
| 624 | match prefixes | ||
| 625 | case PREFIXES(__) then | ||
| 626 | let redeclare_str = dumpRedeclare(redeclarePrefix) | ||
| 627 | let final_str = dumpFinal(finalPrefix) | ||
| 628 | let io_str = dumpInnerOuter(innerOuter) | ||
| 629 | let replaceable_str = dumpReplaceable(replaceablePrefix) | ||
| 630 | '<%redeclare_str%><%each%><%final_str%><%io_str%><%replaceable_str%>' | ||
| 631 | end dumpPrefixes; | ||
| 632 | |||
| 633 | ✗ | template dumpVisibility(SCode.Visibility visibility) | |
| 634 | ::= | ||
| 635 | match visibility | ||
| 636 | case PROTECTED(__) then 'protected ' | ||
| 637 | end dumpVisibility; | ||
| 638 | |||
| 639 | 53 | template dumpRedeclare(SCode.Redeclare redeclare) | |
| 640 | ::= | ||
| 641 | match redeclare | ||
| 642 | case REDECLARE(__) then 'redeclare ' | ||
| 643 | end dumpRedeclare; | ||
| 644 | |||
| 645 | 154 | template dumpFinal(SCode.Final final) | |
| 646 | ::= | ||
| 647 | match final | ||
| 648 | case FINAL(__) then 'final ' | ||
| 649 | end dumpFinal; | ||
| 650 | |||
| 651 | 4 | template dumpInnerOuter(Absyn.InnerOuter innerOuter) | |
| 652 | ::= | ||
| 653 | match innerOuter | ||
| 654 | case INNER(__) then 'inner ' | ||
| 655 | case OUTER(__) then 'outer ' | ||
| 656 | case INNER_OUTER(__) then 'inner outer ' | ||
| 657 | end dumpInnerOuter; | ||
| 658 | |||
| 659 | 44 | template dumpReplaceable(SCode.Replaceable replaceable) | |
| 660 | ::= | ||
| 661 | match replaceable | ||
| 662 | case REPLACEABLE(__) then | ||
| 663 | 'replaceable ' | ||
| 664 | end dumpReplaceable; | ||
| 665 | |||
| 666 | 5 | template dumpReplaceableConstrainClass(SCode.Prefixes replaceable, SCodeDumpOptions options) | |
| 667 | ::= | ||
| 668 | match replaceable | ||
| 669 | case PREFIXES(replaceablePrefix = REPLACEABLE(cc = SOME(CONSTRAINCLASS( | ||
| 670 | constrainingClass = cc_path, modifier = cc_mod)))) then | ||
| 671 | let path_str = AbsynDumpTpl.dumpPath(cc_path) | ||
| 672 | let mod_str = dumpModifier(cc_mod, options) | ||
| 673 | ' constrainedby <%path_str%><%mod_str%>' | ||
| 674 | end dumpReplaceableConstrainClass; | ||
| 675 | |||
| 676 | 21 | template dumpEach(SCode.Each each) | |
| 677 | ::= | ||
| 678 | match each | ||
| 679 | case EACH(__) then 'each ' | ||
| 680 | end dumpEach; | ||
| 681 | |||
| 682 | 3 | template dumpEncapsulated(SCode.Encapsulated encapsulated) | |
| 683 | ::= | ||
| 684 | match encapsulated | ||
| 685 | case ENCAPSULATED(__) then 'encapsulated ' | ||
| 686 | end dumpEncapsulated; | ||
| 687 | |||
| 688 | 56 | template dumpPartial(SCode.Partial partial) | |
| 689 | ::= | ||
| 690 | match partial | ||
| 691 | case PARTIAL(__) then 'partial ' | ||
| 692 | end dumpPartial; | ||
| 693 | |||
| 694 | 219 | template dumpRestriction(SCode.Restriction restriction) | |
| 695 | ::= | ||
| 696 | match restriction | ||
| 697 | case R_CLASS(__) then 'class' | ||
| 698 | case R_OPTIMIZATION(__) then 'optimization' | ||
| 699 | case R_MODEL(__) then 'model' | ||
| 700 | case R_RECORD(__) then | ||
| 701 | if isOperator then 'operator record' else 'record' | ||
| 702 | case R_OPERATOR(__) then 'operator' | ||
| 703 | case R_BLOCK(__) then 'block' | ||
| 704 | case R_CONNECTOR(__) then | ||
| 705 | if isExpandable then 'expandable connector' else 'connector' | ||
| 706 | case R_OPERATOR(__) then 'operator' | ||
| 707 | case R_TYPE(__) then 'type' | ||
| 708 | case R_PACKAGE(__) then 'package' | ||
| 709 | case R_FUNCTION(__) then dumpFunctionRestriction(functionRestriction) | ||
| 710 | case R_ENUMERATION(__) then 'enumeration' | ||
| 711 | case R_PREDEFINED_INTEGER(__) then 'IntegerType' | ||
| 712 | case R_PREDEFINED_REAL(__) then 'RealType' | ||
| 713 | case R_PREDEFINED_STRING(__) then 'StringType' | ||
| 714 | case R_PREDEFINED_BOOLEAN(__) then 'BooleanType' | ||
| 715 | case R_PREDEFINED_ENUMERATION(__) then 'EnumType' | ||
| 716 | case R_METARECORD(__) then 'record' | ||
| 717 | case R_UNIONTYPE(__) then 'uniontype' | ||
| 718 | else errorMsg("SCodeDump.dumpRestriction: Unknown restriction.") | ||
| 719 | end dumpRestriction; | ||
| 720 | |||
| 721 | ✗ | template dumpRestrictionTypeVars(SCode.Restriction restriction) | |
| 722 | ::= | ||
| 723 | match restriction | ||
| 724 | case R_UNIONTYPE(__) then | ||
| 725 | (if typeVars then ("<" + (typeVars |> tv => tv ; separator=",") + ">")) | ||
| 726 | else "" | ||
| 727 | end dumpRestrictionTypeVars; | ||
| 728 | |||
| 729 | 119 | template dumpFunctionRestriction(SCode.FunctionRestriction funcRest) | |
| 730 | ::= | ||
| 731 | match funcRest | ||
| 732 | case FR_NORMAL_FUNCTION(__) then '<%AbsynDumpTpl.dumpPurity(purity)%>function' | ||
| 733 | case FR_EXTERNAL_FUNCTION(__) then '<%AbsynDumpTpl.dumpPurity(purity)%>function' | ||
| 734 | case FR_OPERATOR_FUNCTION(__) then 'operator function' | ||
| 735 | case FR_RECORD_CONSTRUCTOR(__) then 'function' | ||
| 736 | else errorMsg("SCodeDump.dumpFunctionRestriction: Unknown Function restriction.") | ||
| 737 | end dumpFunctionRestriction; | ||
| 738 | |||
| 739 | 1054 | template dumpModifier(SCode.Mod modifier, SCodeDumpOptions options) | |
| 740 | ::= | ||
| 741 | match modifier | ||
| 742 | case MOD(__) then | ||
| 743 | let binding_str = dumpModifierBinding(binding) | ||
| 744 | let submod_str = if subModLst then | ||
| 745 | '(<%(subModLst |> submod => dumpSubModifier(submod, options) ;separator=", ")%>)' | ||
| 746 | '<%submod_str%><%binding_str%>' | ||
| 747 | end dumpModifier; | ||
| 748 | |||
| 749 | 446 | template dumpAnnotationModifier(SCode.Mod modifier, SCodeDumpOptions options) | |
| 750 | ::= | ||
| 751 | match modifier | ||
| 752 | case MOD(__) then | ||
| 753 | let binding_str = dumpModifierBinding(binding) | ||
| 754 | let text = subModLst |> submod => dumpAnnotationSubModifier(submod, options) ;separator=", " | ||
| 755 | let submod_str = if text then '(<%text%>)' | ||
| 756 | '<%submod_str%><%binding_str%>' | ||
| 757 | end dumpAnnotationModifier; | ||
| 758 | |||
| 759 | 609 | template dumpModifierPrefix(SCode.Mod modifier) | |
| 760 | ::= | ||
| 761 | match modifier | ||
| 762 | case MOD(__) then | ||
| 763 | let final_str = dumpFinal(finalPrefix) | ||
| 764 | let each_str = dumpEach(eachPrefix) | ||
| 765 | '<%each_str%><%final_str%>' | ||
| 766 | case REDECL(__) then | ||
| 767 | let final_str = dumpFinal(finalPrefix) | ||
| 768 | let each_str = dumpEach(eachPrefix) | ||
| 769 | '<%each_str%><%final_str%>' | ||
| 770 | end dumpModifierPrefix; | ||
| 771 | |||
| 772 | 18 | template dumpRedeclModifier(SCode.Mod modifier, SCodeDumpOptions options) | |
| 773 | ::= | ||
| 774 | match modifier | ||
| 775 | case REDECL(__) then | ||
| 776 | let each_str = dumpEach(eachPrefix) | ||
| 777 | '<%dumpElement(element, each_str, options)%>' | ||
| 778 | end dumpRedeclModifier; | ||
| 779 | |||
| 780 | 1018 | template dumpModifierBinding(Option<Absyn.Exp> binding) | |
| 781 | ::= match binding case SOME(exp) then '<%\ %>= <%AbsynDumpTpl.dumpExp(exp)%>' | ||
| 782 | end dumpModifierBinding; | ||
| 783 | |||
| 784 | 464 | template dumpSubModifier(SCode.SubMod submod, SCodeDumpOptions options) | |
| 785 | ::= | ||
| 786 | match submod | ||
| 787 | case NAMEMOD(mod = MOD(__)) then | ||
| 788 | '<%dumpModifierPrefix(mod)%><%ident%><%dumpModifier(mod,options)%>' | ||
| 789 | case NAMEMOD(mod = REDECL(__)) then | ||
| 790 | '<%dumpRedeclModifier(mod,options)%>' | ||
| 791 | end dumpSubModifier; | ||
| 792 | |||
| 793 | 512 | template dumpAnnotationSubModifier(SCode.SubMod submod, SCodeDumpOptions options) | |
| 794 | ::= | ||
| 795 | match submod | ||
| 796 | case NAMEMOD(mod = nameMod as MOD(__)) then | ||
| 797 | (if Config.showAnnotations() then | ||
| 798 | '<%dumpModifierPrefix(mod)%><%ident%><%dumpAnnotationModifier(nameMod,options)%>' | ||
| 799 | else | ||
| 800 | match ident | ||
| 801 | case "choices" | ||
| 802 | case "Documentation" | ||
| 803 | case "Dialog" | ||
| 804 | case "Diagram" | ||
| 805 | case "Icon" | ||
| 806 | case "Line" | ||
| 807 | case "Placement" | ||
| 808 | case "preferredView" | ||
| 809 | case "conversion" | ||
| 810 | case "defaultComponentName" | ||
| 811 | case "revisionId" | ||
| 812 | case "uses" | ||
| 813 | then "" | ||
| 814 | else '<%dumpModifierPrefix(nameMod)%><%ident%><%dumpAnnotationModifier(nameMod,options)%>') | ||
| 815 | case NAMEMOD(mod = REDECL(__)) then | ||
| 816 | '<%dumpRedeclModifier(mod,options)%>' | ||
| 817 | end dumpAnnotationSubModifier; | ||
| 818 | |||
| 819 | 1231 | template dumpAttributes(SCode.Attributes attributes) | |
| 820 | ::= | ||
| 821 | match attributes | ||
| 822 | case ATTR(__) then | ||
| 823 | let ct_str = dumpConnectorType(connectorType) | ||
| 824 | let prl_str = dumpParallelism(parallelism) | ||
| 825 | let var_str = dumpVariability(variability) | ||
| 826 | let dir_str = dumpDirection(direction) | ||
| 827 | '<%prl_str%><%var_str%><%dir_str%><%ct_str%>' | ||
| 828 | end dumpAttributes; | ||
| 829 | |||
| 830 | 3 | template dumpConnectorType(SCode.ConnectorType connectorType) | |
| 831 | ::= | ||
| 832 | match connectorType | ||
| 833 | case FLOW() then 'flow ' | ||
| 834 | case STREAM() then 'stream ' | ||
| 835 | end dumpConnectorType; | ||
| 836 | |||
| 837 | ✗ | template dumpParallelism(SCode.Parallelism parallelism) | |
| 838 | ::= | ||
| 839 | match parallelism | ||
| 840 | case PARGLOBAL(__) then 'parglobal ' | ||
| 841 | case PARLOCAL(__) then 'parlocal ' | ||
| 842 | end dumpParallelism; | ||
| 843 | |||
| 844 | 121 | template dumpVariability(SCode.Variability variability) | |
| 845 | ::= | ||
| 846 | match variability | ||
| 847 | case DISCRETE(__) then 'discrete ' | ||
| 848 | case PARAM(__) then 'parameter ' | ||
| 849 | case CONST(__) then 'constant ' | ||
| 850 | end dumpVariability; | ||
| 851 | |||
| 852 | 374 | template dumpDirection(Absyn.Direction direction) | |
| 853 | ::= | ||
| 854 | match direction | ||
| 855 | case INPUT(__) then 'input ' | ||
| 856 | case OUTPUT(__) then 'output ' | ||
| 857 | case INPUT_OUTPUT(__) then 'input output ' | ||
| 858 | end dumpDirection; | ||
| 859 | |||
| 860 | 1125 | template dumpAttributeDim(SCode.Attributes attributes) | |
| 861 | ::= match attributes case ATTR(__) then AbsynDumpTpl.dumpSubscripts(arrayDims) | ||
| 862 | end dumpAttributeDim; | ||
| 863 | |||
| 864 | 301 | template dumpAnnotationOpt(Option<SCode.Annotation> annotation, SCodeDumpOptions options) | |
| 865 | ::= match annotation case SOME(ann) then dumpAnnotation(ann, options) | ||
| 866 | end dumpAnnotationOpt; | ||
| 867 | |||
| 868 | 301 | template dumpAnnotation(SCode.Annotation annotation, SCodeDumpOptions options) | |
| 869 | ::= | ||
| 870 | match annotation | ||
| 871 | case ANNOTATION(__) then | ||
| 872 | let modifStr = dumpAnnotationModifier(modification,options) | ||
| 873 | if modifStr then '<%\ %>annotation<%modifStr%>' | ||
| 874 | end dumpAnnotation; | ||
| 875 | |||
| 876 | ✗ | template dumpAnnotationElement(SCode.Annotation annotation, SCodeDumpOptions options) | |
| 877 | ::= | ||
| 878 | let annstr = '<%dumpAnnotation(annotation, options)%>' | ||
| 879 | if annstr then | ||
| 880 | '<%\ %><%annstr%>;' | ||
| 881 | end dumpAnnotationElement; | ||
| 882 | |||
| 883 | 7 | template dumpExternalDeclOpt(Option<SCode.ExternalDecl> externalDecl, SCodeDumpOptions options) | |
| 884 | ::= match externalDecl case SOME(extdecl) then dumpExternalDecl(extdecl, options) | ||
| 885 | end dumpExternalDeclOpt; | ||
| 886 | |||
| 887 | 7 | template dumpExternalDecl(SCode.ExternalDecl externalDecl, SCodeDumpOptions options) | |
| 888 | ::= | ||
| 889 | let res = match externalDecl | ||
| 890 | case EXTERNALDECL(__) then | ||
| 891 | let func_name_str = match funcName case SOME(name) then name | ||
| 892 | let func_args_str = (args |> arg => AbsynDumpTpl.dumpExp(arg) ;separator=", ") | ||
| 893 | let func_str = if func_name_str then ' <%func_name_str%>(<%func_args_str%>)' | ||
| 894 | let lang_str = match lang case SOME(l) then ' "<%l%>"' | ||
| 895 | let ann_str = dumpAnnotationOpt(annotation_, options) | ||
| 896 | let output_str = match output_ case SOME(name) then ' <%AbsynDumpTpl.dumpCref(name)%> =' | ||
| 897 | 'external<%lang_str%><%output_str%><%func_str%><%ann_str%>;' | ||
| 898 | match externalDecl | ||
| 899 | case EXTERNALDECL(lang=SOME("builtin")) then res | ||
| 900 | else match options case OPTIONS(stripExternalDecl=false) then res | ||
| 901 | end dumpExternalDecl; | ||
| 902 | |||
| 903 | ✗ | template dumpCommentOpt(Option<SCode.Comment> comment, SCodeDumpOptions options) | |
| 904 | ::= match comment case SOME(cmt) then dumpComment(cmt, options) | ||
| 905 | end dumpCommentOpt; | ||
| 906 | |||
| 907 | 1795 | template dumpComment(SCode.Comment comment, SCodeDumpOptions options) | |
| 908 | ::= | ||
| 909 | match comment | ||
| 910 | case COMMENT(__) then | ||
| 911 | let ann_str = dumpAnnotationOpt(annotation_, options) | ||
| 912 | let cmt_str = dumpCommentStr(comment, options) | ||
| 913 | '<%cmt_str%><%ann_str%>' | ||
| 914 | end dumpComment; | ||
| 915 | |||
| 916 | 2160 | template dumpCommentStr(Option<String> comment, SCodeDumpOptions options) | |
| 917 | ::= | ||
| 918 | match options case OPTIONS(stripStringComments=false) then | ||
| 919 | match comment case SOME(cmt) then '<%\ %>"<%System.escapedString(cmt,false)%>"' | ||
| 920 | end dumpCommentStr; | ||
| 921 | |||
| 922 | ✗ | template errorMsg(String errMessage) | |
| 923 | ::= | ||
| 924 | let() = Tpl.addTemplateError(errMessage) | ||
| 925 | << | ||
| 926 | <%errMessage%> | ||
| 927 | >> | ||
| 928 | end errorMsg; | ||
| 929 | |||
| 930 | annotation(__OpenModelica_Interface="frontend_dump"); | ||
| 931 | end SCodeDumpTpl; | ||
| 932 | // vim: filetype=susan sw=2 sts=2 | ||
| 933 |