Handle access note I/O and parse errors

This commit is contained in:
Becca Royal-Gordon
2021-02-04 15:59:47 -08:00
parent d347ffae0e
commit e42294737f
5 changed files with 56 additions and 12 deletions

View File

@@ -215,15 +215,30 @@ template <> struct llvm::yaml::MappingTraits<swift::AccessNote> {
};
namespace swift {
static void
convertToErrorAndJoin(const llvm::SMDiagnostic &diag, void *Context) {
auto newError = llvm::createStringError(std::errc::invalid_argument,
"%s at line %d, column %d",
diag.getMessage().bytes_begin(),
diag.getLineNo(), diag.getColumnNo());
auto &errors = *(llvm::Error*)Context;
errors = llvm::joinErrors(std::move(errors), std::move(newError));
}
llvm::Expected<AccessNotes>
AccessNotes::load(ASTContext &ctx, llvm::MemoryBuffer *buffer) {
llvm::yaml::Input yamlIn(buffer->getBuffer(), (void *)&ctx);
llvm::Error errors = llvm::Error::success();
llvm::yaml::Input yamlIn(buffer->getBuffer(), (void *)&ctx,
convertToErrorAndJoin, &errors);
AccessNotes notes;
yamlIn >> notes;
if (yamlIn.error())
return llvm::errorCodeToError(yamlIn.error());
return llvm::Expected<AccessNotes>(std::move(errors));
return notes;
}