[clang] [APINotes] Upstream APINotes YAML compiler (PR #71413)

Saleem Abdulrasool via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 6 20:31:31 PST 2023


================
@@ -635,3 +638,496 @@ bool clang::api_notes::parseAndDumpAPINotes(StringRef YI,
 
   return false;
 }
+
+namespace {
+using namespace api_notes;
+
+class YAMLConverter {
+  const Module &TheModule;
+  APINotesWriter Writer;
+  llvm::raw_ostream &OS;
+  llvm::SourceMgr::DiagHandlerTy DiagHandler;
+  void *DiagHandlerCtxt;
+  bool ErrorOccured;
+
+  /// Emit a diagnostic
+  bool emitError(llvm::Twine Message) {
+    DiagHandler(
+        llvm::SMDiagnostic("", llvm::SourceMgr::DK_Error, Message.str()),
+        DiagHandlerCtxt);
+    ErrorOccured = true;
+    return true;
+  }
+
+public:
+  YAMLConverter(const Module &TheModule, const FileEntry *SourceFile,
+                llvm::raw_ostream &OS,
+                llvm::SourceMgr::DiagHandlerTy DiagHandler,
+                void *DiagHandlerCtxt)
+      : TheModule(TheModule), Writer(TheModule.Name, SourceFile), OS(OS),
+        DiagHandler(DiagHandler), DiagHandlerCtxt(DiagHandlerCtxt),
+        ErrorOccured(false) {}
+
+  bool convertAvailability(const AvailabilityItem &In,
+                           CommonEntityInfo &OutInfo, llvm::StringRef APIName) {
----------------
compnerd wrote:

```suggestion
  bool convertAvailability(const AvailabilityItem &Availablity,
                           CommonEntityInfo &CEI, llvm::StringRef APIName) {
```

The availability is what s being converted, and the CEI is what the output is already referred to as elsewhere. It makes sense to follow the existing patterns IMO.

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


More information about the cfe-commits mailing list