OMCompiler/Compiler/Util/ErrorExt.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 ErrorExt | ||
| 37 | " | ||
| 38 | file: ErrorExt.mo | ||
| 39 | package: ErrorExt | ||
| 40 | description: Error handling External interface | ||
| 41 | |||
| 42 | |||
| 43 | This file contains the external interface to the error handling. | ||
| 44 | Error messages are stored externally, impl. in C++." | ||
| 45 | |||
| 46 | |||
| 47 | import ErrorTypes; | ||
| 48 | |||
| 49 | 5354 | function registerModelicaFormatError | |
| 50 | external "C" Error_registerModelicaFormatError() annotation(Documentation(info="<html> | ||
| 51 | <p>Registers the ModelicaFormatError function to output messages in the Error buffer instead of the default standard output.</p> | ||
| 52 | <p>Note: Only works in the bootstrapped compiler!</p> | ||
| 53 | </html>"),Library = "omcruntime"); | ||
| 54 | end registerModelicaFormatError; | ||
| 55 | |||
| 56 | 2677 | function addSourceMessage | |
| 57 | input ErrorTypes.ErrorID id; | ||
| 58 | input ErrorTypes.MessageType msg_type; | ||
| 59 | input ErrorTypes.Severity msg_severity; | ||
| 60 | input Integer sline; | ||
| 61 | input Integer scol; | ||
| 62 | input Integer eline; | ||
| 63 | input Integer ecol; | ||
| 64 | input Boolean read_only; | ||
| 65 | input String filename; | ||
| 66 | input String msg; | ||
| 67 | input list<String> tokens; | ||
| 68 | |||
| 69 | external "C" Error_addSourceMessage(OpenModelica.threadData(),id,msg_type,msg_severity,sline,scol,eline,ecol,read_only,filename,msg,tokens) annotation(Library = "omcruntime"); | ||
| 70 | end addSourceMessage; | ||
| 71 | |||
| 72 | 57780 | function printMessagesStr | |
| 73 | "Prints all error messages as a string and pops them from the message queue." | ||
| 74 | input Boolean warningsAsErrors = false; | ||
| 75 | output String outString; | ||
| 76 | |||
| 77 | external "C" outString=Error_printMessagesStr(OpenModelica.threadData(),warningsAsErrors) annotation(Library = "omcruntime"); | ||
| 78 | end printMessagesStr; | ||
| 79 | |||
| 80 | 8384 | function printCheckpointMessagesStr | |
| 81 | "Prints the error messages since the last checkpoint as a string and pops them | ||
| 82 | from the message queue." | ||
| 83 | input Boolean warningsAsErrors = false; | ||
| 84 | output String outString; | ||
| 85 | |||
| 86 | external "C" outString=Error_printCheckpointMessagesStr(OpenModelica.threadData(),warningsAsErrors) annotation(Library = "omcruntime"); | ||
| 87 | end printCheckpointMessagesStr; | ||
| 88 | |||
| 89 | 1 | function getNumMessages | |
| 90 | output Integer num; | ||
| 91 | |||
| 92 | external "C" num=Error_getNumMessages(OpenModelica.threadData()) annotation(Library = "omcruntime"); | ||
| 93 | end getNumMessages; | ||
| 94 | |||
| 95 | 774985 | function getNumErrorMessages | |
| 96 | output Integer num; | ||
| 97 | |||
| 98 | external "C" num=ErrorImpl__getNumErrorMessages(OpenModelica.threadData()) annotation(Library = "omcruntime"); | ||
| 99 | end getNumErrorMessages; | ||
| 100 | |||
| 101 | 10528006 | function getNumWarningMessages | |
| 102 | output Integer num; | ||
| 103 | |||
| 104 | external "C" num=ErrorImpl__getNumWarningMessages(OpenModelica.threadData()) annotation(Library = "omcruntime"); | ||
| 105 | end getNumWarningMessages; | ||
| 106 | |||
| 107 | ✗ | function getMessages | |
| 108 | "Returns all error messages and pops them from the message queue." | ||
| 109 | output list<ErrorTypes.TotalMessage> res; | ||
| 110 | |||
| 111 | external "C" res=Error_getMessages(OpenModelica.threadData()) annotation(Library = "omcruntime"); | ||
| 112 | end getMessages; | ||
| 113 | |||
| 114 | ✗ | function getCheckpointMessages | |
| 115 | "Returns all error messages since the last checkpoint and pops them from the message queue." | ||
| 116 | output list<ErrorTypes.TotalMessage> res; | ||
| 117 | |||
| 118 | external "C" res=ErrorImpl__getCheckpointMessages(OpenModelica.threadData()) annotation(Library = "omcruntime"); | ||
| 119 | end getCheckpointMessages; | ||
| 120 | |||
| 121 | 56 | function clearMessages | |
| 122 | external "C" ErrorImpl__clearMessages(OpenModelica.threadData()) annotation(Library = "omcruntime"); | ||
| 123 | end clearMessages; | ||
| 124 | |||
| 125 | 1520 | function getNumCheckpoints "Used to rollback/delete checkpoints without considering the identifier. Used to reset the error messages after a stack overflow exception." | |
| 126 | output Integer n; | ||
| 127 | external "C" n=ErrorImpl__getNumCheckpoints(OpenModelica.threadData()) annotation(Library = "omcruntime"); | ||
| 128 | end getNumCheckpoints; | ||
| 129 | |||
| 130 | 10278 | function rollbackNumCheckpoints "Used to rollback/delete checkpoints without considering the identifier. Used to reset the error messages after a stack overflow exception." | |
| 131 | input Integer n; | ||
| 132 | external "C" ErrorImpl__rollbackNumCheckpoints(OpenModelica.threadData(), n) annotation(Library = "omcruntime"); | ||
| 133 | end rollbackNumCheckpoints; | ||
| 134 | |||
| 135 | ✗ | function deleteNumCheckpoints "Used to rollback/delete checkpoints without considering the identifier. Used to reset the error messages after a stack overflow exception." | |
| 136 | input Integer n; | ||
| 137 | external "C" ErrorImpl__deleteNumCheckpoints(OpenModelica.threadData(), n) annotation(Library = "omcruntime"); | ||
| 138 | end deleteNumCheckpoints; | ||
| 139 | |||
| 140 | ✗ | function setCheckpoint "sets a checkpoint for the error messages, so error messages can be rolled back (i.e. deleted) up to this point | |
| 141 | A unique identifier for this checkpoint must be provided. It is checked when doing rollback or deletion" | ||
| 142 | input String id "uniqe identifier for the checkpoint (up to the programmer to guarantee uniqueness)"; | ||
| 143 | external "C" ErrorImpl__setCheckpoint(OpenModelica.threadData(),id) annotation(Library = "omcruntime"); | ||
| 144 | end setCheckpoint; | ||
| 145 | |||
| 146 | 23343713 | function delCheckpoint "deletes the checkpoint at the top of the stack without | |
| 147 | removing the error messages issued since that checkpoint. | ||
| 148 | If the checkpoint id doesn't match, the application exits with -1. | ||
| 149 | " | ||
| 150 | |||
| 151 | input String id "unique identifier"; | ||
| 152 | external "C" ErrorImpl__delCheckpoint(OpenModelica.threadData(),id) annotation(Library = "omcruntime"); | ||
| 153 | end delCheckpoint; | ||
| 154 | |||
| 155 | 18205632 | function printErrorsNoWarning | |
| 156 | output String outString; | ||
| 157 | external "C" outString=Error_printErrorsNoWarning(OpenModelica.threadData()) annotation(Library = "omcruntime"); | ||
| 158 | end printErrorsNoWarning; | ||
| 159 | |||
| 160 | ✗ | function rollBack "rolls back error messages until the latest checkpoint, | |
| 161 | deleting all error messages added since that point in time. A unique identifier for the checkpoint must be provided | ||
| 162 | The application will exit with return code -1 if this identifier does not match." | ||
| 163 | input String id "unique identifier"; | ||
| 164 | external "C" ErrorImpl__rollBack(OpenModelica.threadData(),id) annotation(Library = "omcruntime"); | ||
| 165 | end rollBack; | ||
| 166 | |||
| 167 | 5135431 | function popCheckPoint "rolls back error messages until the latest checkpoint, | |
| 168 | returning all error messages added since that point in time. A unique identifier for the checkpoint must be provided | ||
| 169 | The application will exit with return code -1 if this identifier does not match." | ||
| 170 | input String id "unique identifier"; | ||
| 171 | output list<Integer> handles "opaque pointers; you MUST pass them back or memory is leaked"; | ||
| 172 | external "C" handles=ErrorImpl__pop(OpenModelica.threadData(),id) annotation(Library = "omcruntime"); | ||
| 173 | end popCheckPoint; | ||
| 174 | |||
| 175 | 2650 | function pushMessages "Pushes stored pointers back to the error stack." | |
| 176 | input list<Integer> handles "opaque pointers from popCheckPoint"; | ||
| 177 | external "C" ErrorImpl__pushMessages(OpenModelica.threadData(),handles) annotation(Library = "omcruntime"); | ||
| 178 | end pushMessages; | ||
| 179 | |||
| 180 | 1646 | function freeMessages "Pushes stored pointers back to the error stack." | |
| 181 | input list<Integer> handles "opaque pointers from popCheckPoint"; | ||
| 182 | external "C" ErrorImpl__freeMessages(OpenModelica.threadData(),handles) annotation(Library = "omcruntime"); | ||
| 183 | end freeMessages; | ||
| 184 | |||
| 185 | 1004 | function isTopCheckpoint | |
| 186 | "@author: adrpo | ||
| 187 | This function checks if the specified checkpoint exists AT THE TOP OF THE STACK!. | ||
| 188 | You can use it to rollBack/delete a checkpoint, but you're | ||
| 189 | not sure that it exists (due to MetaModelica backtracking)." | ||
| 190 | input String id "unique identifier"; | ||
| 191 | output Boolean isThere "tells us if the checkpoint exists (true) or doesn't (false)"; | ||
| 192 | external "C" isThere=ErrorImpl__isTopCheckpoint(OpenModelica.threadData(),id) annotation(Library = "omcruntime"); | ||
| 193 | end isTopCheckpoint; | ||
| 194 | |||
| 195 | 126 | function setShowErrorMessages | |
| 196 | input Boolean inShow; | ||
| 197 | external "C" Error_setShowErrorMessages(OpenModelica.threadData(),inShow) annotation(Library = "omcruntime"); | ||
| 198 | end setShowErrorMessages; | ||
| 199 | |||
| 200 | ✗ | function moveMessagesToParentThread | |
| 201 | external "C" Error_moveMessagesToParentThread(OpenModelica.threadData()) annotation(Library = "omcruntime"); | ||
| 202 | end moveMessagesToParentThread; | ||
| 203 | |||
| 204 | 2677 | function initAssertionFunctions "Makes assert() and other runtime assertions print to the error buffer" | |
| 205 | external "C" Error_initAssertionFunctions() annotation(Library = "omcruntime"); | ||
| 206 | end initAssertionFunctions; | ||
| 207 | |||
| 208 | annotation(__OpenModelica_Interface="error"); | ||
| 209 | end ErrorExt; | ||
| 210 |