Open fabianschuiki opened 10 years ago
Clang uses a nice system for diagnostics. The DiagnosticsEngine
collects all diagnostics, which can be notes, remarks, warnings, errors, and fatal errors. Notes and warnings may be mapped to any of the diagnostic types mentioned before. The DiagnosticBuilder
helper class is used to assemble one message from source ranges, AST nodes, code snippets, types, and other pieces of information.
See LLHD's implementation of diagnostics! That works fairly well, to say the least!
Commit 027501cb5f49acd60093eb2ca4d4bbdd407ee853 adds location tracking using the SourceId
, SourceLocation
, and SourceRange
classes. Upon compile, the source files now need to be fed into a source repository in order to assign them a unique ID. This will then allow to resolve locations and ranges to the exact wording in the source file upon compilation.
At the moment, errors are reported by throwing an exception somewhere in the compiler. The resulting message in the output is really not helpful, as it usually refers to entries in the AST rather than the original source file.