[clang] [Clang] [NFC] Tablegen component diags headers (PR #134777)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 8 06:21:55 PDT 2025


================
@@ -1562,6 +1563,60 @@ void clang::EmitClangDiagsCompatIDs(const llvm::RecordKeeper &Records,
     OS << "DIAG_COMPAT_IDS_END()\n";
 }
 
+/// ClangDiagsIntefaceEmitter - Emit the diagnostics interface header for
+/// a Clang component.
+void clang::EmitClangDiagsInterface(llvm::raw_ostream &OS,
+                                    const std::string &Component) {
+  if (Component.empty())
+    PrintFatalError("'-gen-clang-diags-iface' requires a component name");
+
+  std::string ComponentUpper = StringRef(Component).upper();
+  const char *Comp = Component.c_str();
+  const char *Upper = ComponentUpper.c_str();
+
+  OS << llvm::format(R"c++(
+namespace clang {
----------------
erichkeane wrote:

These are all so common (differing only by the one name change) that I wonder if tablegen is the right place for this, instead of just a predefined file.  BUT I can't htink of a way to do that which doesn't require preprocessor string-replacement inside of a `#include` or `define` identifier, which, IIRC is UB?

SO I guess this is ok and the only way we can reasonably do this?

https://github.com/llvm/llvm-project/pull/134777


More information about the cfe-commits mailing list