[clang] [APINotes] Upstream APINotes YAML compiler (PR #71413)
Egor Zhdan via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 13 07:47:53 PST 2023
================
@@ -635,3 +638,478 @@ bool clang::api_notes::parseAndDumpAPINotes(StringRef YI,
return false;
}
+
+namespace {
+using namespace api_notes;
+
+class YAMLConverter {
+ const Module &M;
+ 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)
+ : M(TheModule), Writer(TheModule.Name, SourceFile), OS(OS),
+ DiagHandler(DiagHandler), DiagHandlerCtxt(DiagHandlerCtxt),
+ ErrorOccured(false) {}
+
+ void convertAvailability(const AvailabilityItem &Availability,
+ CommonEntityInfo &CEI, llvm::StringRef APIName) {
+ // Populate the unavailability information.
+ CEI.Unavailable = (Availability.Mode == APIAvailability::None);
+ CEI.UnavailableInSwift = (Availability.Mode == APIAvailability::NonSwift);
+ if (CEI.Unavailable || CEI.UnavailableInSwift) {
+ CEI.UnavailableMsg = std::string(Availability.Msg);
+ } else {
+ if (!Availability.Msg.empty()) {
+ emitError(llvm::Twine("availability message for available API '") +
+ APIName + "' will not be used");
+ }
----------------
egorzhdan wrote:
Done
https://github.com/llvm/llvm-project/pull/71413
More information about the cfe-commits
mailing list