OMCompiler/Compiler/Script/GlobalScriptDump.mo
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of OpenModelica. | ||
| 3 | * | ||
| 4 | * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), | ||
| 5 | * c/o Linköpings universitet, Department of Computer and Information Science, | ||
| 6 | * SE-58183 Linköping, Sweden. | ||
| 7 | * | ||
| 8 | * All rights reserved. | ||
| 9 | * | ||
| 10 | * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR | ||
| 11 | * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. | ||
| 12 | * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES | ||
| 13 | * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL | ||
| 14 | * VERSION 3, ACCORDING TO RECIPIENTS CHOICE. | ||
| 15 | * | ||
| 16 | * The OpenModelica software and the OSMC (Open Source Modelica Consortium) | ||
| 17 | * Public License (OSMC-PL) are obtained from OSMC, either from the above | ||
| 18 | * address, from the URLs: | ||
| 19 | * http://www.openmodelica.org or | ||
| 20 | * https://github.com/OpenModelica/ or | ||
| 21 | * http://www.ida.liu.se/projects/OpenModelica, | ||
| 22 | * and in the OpenModelica distribution. | ||
| 23 | * | ||
| 24 | * GNU AGPL version 3 is obtained from: | ||
| 25 | * https://www.gnu.org/licenses/licenses.html#GPL | ||
| 26 | * | ||
| 27 | * This program is distributed WITHOUT ANY WARRANTY; without | ||
| 28 | * even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 29 | * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH | ||
| 30 | * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. | ||
| 31 | * | ||
| 32 | * See the full OSMC Public License conditions for more details. | ||
| 33 | * | ||
| 34 | */ | ||
| 35 | |||
| 36 | encapsulated package GlobalScriptDump | ||
| 37 | " file: GlobalScriptDump.mo | ||
| 38 | package: GlobalScriptDump | ||
| 39 | description: Dump functions for scripting types. | ||
| 40 | |||
| 41 | " | ||
| 42 | |||
| 43 | import Absyn; | ||
| 44 | import GlobalScript; | ||
| 45 | import SymbolTable; | ||
| 46 | |||
| 47 | protected | ||
| 48 | |||
| 49 | import Dump; | ||
| 50 | import List; | ||
| 51 | |||
| 52 | public | ||
| 53 | |||
| 54 | function printIstmtsStr | ||
| 55 | "Prints a group of interactive statements to a string." | ||
| 56 | input GlobalScript.Statements inStatements; | ||
| 57 | output String outString; | ||
| 58 | algorithm | ||
| 59 | outString := match inStatements | ||
| 60 | local | ||
| 61 | list<GlobalScript.Statement> stmts; | ||
| 62 | |||
| 63 | case GlobalScript.ISTMTS(interactiveStmtLst = stmts) | ||
| 64 | 383 | then stringDelimitList(List.map(stmts, printIstmtStr), "; "); | |
| 65 | |||
| 66 | else "printIstmtsStr: unknown"; | ||
| 67 | end match; | ||
| 68 | end printIstmtsStr; | ||
| 69 | |||
| 70 | function printIstmtStr | ||
| 71 | input GlobalScript.Statement inStatement; | ||
| 72 | output String outString; | ||
| 73 | algorithm | ||
| 74 | outString := match inStatement | ||
| 75 | local | ||
| 76 | Absyn.AlgorithmItem alg; | ||
| 77 | Absyn.Exp expr; | ||
| 78 | |||
| 79 | case GlobalScript.IALG(algItem = alg) | ||
| 80 | ✗ | then Dump.unparseAlgorithmStr(alg); | |
| 81 | |||
| 82 | case GlobalScript.IEXP(exp = expr) | ||
| 83 | 384 | then Dump.printExpStr(expr); | |
| 84 | |||
| 85 | else "printIstmtStr: unknown"; | ||
| 86 | end match; | ||
| 87 | end printIstmtStr; | ||
| 88 | |||
| 89 | function printAST | ||
| 90 | "author: vwaurich TUD 10-2016" | ||
| 91 | input Absyn.Program pr; | ||
| 92 | protected | ||
| 93 | String s=""; | ||
| 94 | Absyn.Class class_; | ||
| 95 | list<Absyn.Class> classes; | ||
| 96 | Absyn.Within within_ ; | ||
| 97 | algorithm | ||
| 98 | ✗ | Absyn.PROGRAM(classes, within_) := pr; | |
| 99 | ✗ | for class_ in classes loop | |
| 100 | ✗ | s := s+classString(class_)+"\n"; | |
| 101 | end for; | ||
| 102 | ✗ | print(s); | |
| 103 | end printAST; | ||
| 104 | |||
| 105 | function printGlobalScript | ||
| 106 | "author: vwaurich TUD 10-2016" | ||
| 107 | input SymbolTable st; | ||
| 108 | algorithm | ||
| 109 | ✗ | print("AST\n"); | |
| 110 | ✗ | printAST(st.ast); | |
| 111 | end printGlobalScript; | ||
| 112 | |||
| 113 | protected | ||
| 114 | |||
| 115 | function classString | ||
| 116 | "author: vwaurich TUD 10-2016" | ||
| 117 | input Absyn.Class cl; | ||
| 118 | output String s; | ||
| 119 | protected | ||
| 120 | Absyn.Ident id; | ||
| 121 | algorithm | ||
| 122 | ✗ | Absyn.CLASS(name = id) := cl; | |
| 123 | ✗ | s := id +": "+ AbsynUtil.classFilename(cl); | |
| 124 | end classString; | ||
| 125 | |||
| 126 | annotation(__OpenModelica_Interface="backend"); | ||
| 127 | end GlobalScriptDump; | ||
| 128 |