Handling messages for the user
Only a centralized definition of messages is missing. In a large piece of software (such as a compiler), you do not want to sprinkle message strings all over the place. If there is a request to change messages or translate them into another language, then you better have them in a central place!
A simple approach is that each message has an ID (an enum
member), a severity level such as Error
or Warning
, and a string containing the messages. In your code, you only refer to the message ID. The severity level and message string are only used when the message is printed. These three items (the ID, the security level, and the message) must be managed consistently. The LLVM libraries use the preprocessor to solve this. The data is stored in a file with the .def
suffix and is wrapped in a macro name. That file is usually included several times, with different definitions for the macro. The definition is in the include/tinylang/Basic/Diagnostic.def
file path...