OMCompiler/Compiler/FrontEnd/DAEDumpTypes.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 DAEDumpTypes | ||
| 37 | " file: DAEDumpTypes.mo | ||
| 38 | package: DAEDumpTypes | ||
| 39 | description: DAEDumpTypes output | ||
| 40 | |||
| 41 | |||
| 42 | This module implements functions to print the DAE AST." | ||
| 43 | |||
| 44 | import DAE; | ||
| 45 | import SCode; | ||
| 46 | |||
| 47 | protected | ||
| 48 | import SCodeDump; | ||
| 49 | import SCodeUtil; | ||
| 50 | |||
| 51 | public uniontype splitElements | ||
| 52 | record SPLIT_ELEMENTS | ||
| 53 | list<DAE.Element> v; | ||
| 54 | list<DAE.Element> ie; | ||
| 55 | list<DAE.Element> ia; | ||
| 56 | list<DAE.Element> e; | ||
| 57 | list<DAE.Element> a; | ||
| 58 | list<DAE.Element> co; | ||
| 59 | list<DAE.Element> o; | ||
| 60 | list<DAE.Element> ca; | ||
| 61 | list<compWithSplitElements> sm; | ||
| 62 | end SPLIT_ELEMENTS; | ||
| 63 | end splitElements; | ||
| 64 | |||
| 65 | public uniontype compWithSplitElements | ||
| 66 | record COMP_WITH_SPLIT | ||
| 67 | String name; | ||
| 68 | splitElements spltElems; | ||
| 69 | Option<SCode.Comment> comment; | ||
| 70 | end COMP_WITH_SPLIT; | ||
| 71 | end compWithSplitElements; | ||
| 72 | |||
| 73 | public uniontype functionList | ||
| 74 | record FUNCTION_LIST | ||
| 75 | list<DAE.Function> funcs; | ||
| 76 | end FUNCTION_LIST; | ||
| 77 | end functionList; | ||
| 78 | |||
| 79 | protected | ||
| 80 | import Config; | ||
| 81 | import System; | ||
| 82 | |||
| 83 | public | ||
| 84 | |||
| 85 | function dumpCommentStr | ||
| 86 | "Dumps a comment to a string." | ||
| 87 | input Option<SCode.Comment> inComment; | ||
| 88 | output String outString; | ||
| 89 | algorithm | ||
| 90 | outString := match inComment | ||
| 91 | local | ||
| 92 | String cmt; | ||
| 93 | |||
| 94 | case SOME(SCode.COMMENT(comment = SOME(cmt))) | ||
| 95 | algorithm | ||
| 96 | 16749 | cmt := System.escapedString(cmt,false); | |
| 97 | 16749 | then stringAppendList({" \"", cmt, "\""}); | |
| 98 | |||
| 99 | else ""; | ||
| 100 | |||
| 101 | end match; | ||
| 102 | end dumpCommentStr; | ||
| 103 | |||
| 104 | function dumpClassAnnotationStr | ||
| 105 | input Option<SCode.Comment> inComment; | ||
| 106 | output String outString; | ||
| 107 | algorithm | ||
| 108 | 18 | outString := dumpAnnotationStr(inComment, " ", ";\n"); | |
| 109 | end dumpClassAnnotationStr; | ||
| 110 | |||
| 111 | function dumpCommentAnnotationStr | ||
| 112 | input Option<SCode.Comment> inComment; | ||
| 113 | output String outString; | ||
| 114 | algorithm | ||
| 115 | outString := match inComment | ||
| 116 | case NONE() then ""; | ||
| 117 | 20151 | else dumpCommentStr(inComment) + dumpCompAnnotationStr(inComment); | |
| 118 | end match; | ||
| 119 | end dumpCommentAnnotationStr; | ||
| 120 | |||
| 121 | function dumpCompAnnotationStr | ||
| 122 | input Option<SCode.Comment> inComment; | ||
| 123 | output String outString; | ||
| 124 | algorithm | ||
| 125 | 20151 | outString := dumpAnnotationStr(inComment, " ", ""); | |
| 126 | end dumpCompAnnotationStr; | ||
| 127 | |||
| 128 | protected function dumpAnnotationStr | ||
| 129 | input Option<SCode.Comment> inComment; | ||
| 130 | input String inPrefix; | ||
| 131 | input String inSuffix; | ||
| 132 | output String outString; | ||
| 133 | algorithm | ||
| 134 | outString := matchcontinue inComment | ||
| 135 | local | ||
| 136 | String ann; | ||
| 137 | SCode.Mod ann_mod; | ||
| 138 | |||
| 139 | case SOME(SCode.COMMENT(annotation_ = SOME(SCode.ANNOTATION(ann_mod)))) | ||
| 140 | algorithm | ||
| 141 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3885 times.
|
3885 | if Config.showAnnotations() then |
| 142 | ✗ | ann := inPrefix + "annotation" + SCodeDump.printModStr(ann_mod, SCodeDump.defaultOptions) + inSuffix; | |
| 143 | elseif Config.showStructuralAnnotations() then | ||
| 144 | ✗ | ann_mod := filterStructuralMods(ann_mod); | |
| 145 | |||
| 146 | ✗ | if not SCodeUtil.isEmptyMod(ann_mod) then | |
| 147 | ✗ | ann := inPrefix + "annotation" + SCodeDump.printModStr(ann_mod, SCodeDump.defaultOptions) + inSuffix; | |
| 148 | else | ||
| 149 | ann := ""; | ||
| 150 | end if; | ||
| 151 | else | ||
| 152 | ann := ""; | ||
| 153 | end if; | ||
| 154 | then | ||
| 155 | ann; | ||
| 156 | |||
| 157 | else ""; | ||
| 158 | |||
| 159 | end matchcontinue; | ||
| 160 | end dumpAnnotationStr; | ||
| 161 | |||
| 162 | public function filterStructuralMods | ||
| 163 | input output SCode.Mod mod; | ||
| 164 | algorithm | ||
| 165 | 10 | mod := SCodeUtil.filterSubMods(mod, filterStructuralMod); | |
| 166 | end filterStructuralMods; | ||
| 167 | |||
| 168 | protected function filterStructuralMod | ||
| 169 | input SCode.SubMod mod; | ||
| 170 | output Boolean keep; | ||
| 171 | algorithm | ||
| 172 | keep := match mod.ident | ||
| 173 | case "Evaluate" then true; | ||
| 174 | case "Inline" then true; | ||
| 175 | case "LateInline" then true; | ||
| 176 | case "derivative" then true; | ||
| 177 | case "inverse" then true; | ||
| 178 | case "smoothOrder" then true; | ||
| 179 | case "InlineAfterIndexReduction" then true; | ||
| 180 | case "GenerateEvents" then true; | ||
| 181 | else false; | ||
| 182 | end match; | ||
| 183 | end filterStructuralMod; | ||
| 184 | |||
| 185 | annotation(__OpenModelica_Interface="frontend_dump"); | ||
| 186 | end DAEDumpTypes; | ||
| 187 |