[clang] [APINotes] Upstream APINotes YAML compiler (PR #71413)
Saleem Abdulrasool via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 13 07:40:56 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");
+ }
+ }
+ }
+
+ void convertParams(const ParamsSeq &Params, FunctionInfo &OutInfo) {
+ for (const auto &P : Params) {
+ ParamInfo PI;
+ if (P.Nullability)
+ PI.setNullabilityAudited(*P.Nullability);
+ PI.setNoEscape(P.NoEscape);
+ PI.setType(std::string(P.Type));
+ PI.setRetainCountConvention(P.RetainCountConvention);
+ if (OutInfo.Params.size() <= P.Position) {
+ OutInfo.Params.resize(P.Position + 1);
+ }
----------------
compnerd wrote:
Unnecessary braces
```suggestion
if (OutInfo.Params.size() <= P.Position)
OutInfo.Params.resize(P.Position + 1);
```
https://github.com/llvm/llvm-project/pull/71413
More information about the cfe-commits
mailing list