From 18703d41f027e89cc0554e5395cae9a0f27e4b5b Mon Sep 17 00:00:00 2001
From: Chris Lattner
Diagnostics are created by adding an entry to one of the -clang/Basic/Diagnostic*Kinds.def files, depending on what library will -be using it. This file encodes the unique ID of the -diagnostic (as an enum, the first argument), the severity of the diagnostic -(second argument) and the English translation + format string.
+clang/Basic/Diagnostic*Kinds.td files, depending on what library will +be using it. From this file, tblgen generates the unique ID of the diagnostic, +the severity of the diagnostic and the English translation + format string.There is little sanity with the naming of the unique ID's right now. Some start with err_, warn_, ext_ to encode the severity into the name. Since the @@ -243,7 +242,7 @@ are some simple format strings:
Diagnostics should never take random English strings as arguments: you shouldn't use "you have a problem with %0" and pass in things like "your argument" or "your return value" as arguments. Doing -this prevents translating the Clang diagnostics to +this prevents translating the Clang diagnostics to other languages (because they'll get random English words in their otherwise localized diagnostic). The exceptions to this are C/C++ language keywords (e.g. auto, const, mutable, etc) and C/C++ operators (/=). Note @@ -373,10 +372,10 @@ of repetitive diagnostics and/or have an idea for a useful formatter, please bring it up on the cfe-dev mailing list.
-Now that you've created the diagnostic in the DiagnosticKinds.def file, you +
Now that you've created the diagnostic in the DiagnosticKinds.td file, you need to write the code that detects the condition in question and emits the new diagnostic. Various components of Clang (e.g. the preprocessor, Sema, etc) provide a helper function named "Diag". It creates a diagnostic and @@ -394,7 +393,7 @@ it.
This shows that use of the Diag method: they take a location (a SourceLocation object) and a diagnostic enum value -(which matches the name from DiagnosticKinds.def). If the diagnostic takes +(which matches the name from DiagnosticKinds.td). If the diagnostic takes arguments, they are specified with the << operator: the first argument becomes %0, the second becomes %1, etc. The diagnostic interface allows you to specify arguments of many different types, including int and -- GitLab