Use Expected<T> instead of ErrorOr<T>in yaml reader. NFC
authorPete Cooper <peter_cooper@apple.com>
Thu, 31 Mar 2016 01:13:04 +0000 (01:13 +0000)
committerPete Cooper <peter_cooper@apple.com>
Thu, 31 Mar 2016 01:13:04 +0000 (01:13 +0000)
llvm-svn: 264981

lld/lib/ReaderWriter/MachO/MachONormalizedFile.h
lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp
lld/unittests/MachOTests/MachONormalizedFileYAMLTests.cpp

index 5f7584a..92a21f7 100644 (file)
@@ -300,7 +300,7 @@ size_t headerAndLoadCommandsSize(const NormalizedFile &file);
 
 
 /// Parses a yaml encoded mach-o file to produce an in-memory normalized view.
-ErrorOr<std::unique_ptr<NormalizedFile>>
+llvm::Expected<std::unique_ptr<NormalizedFile>>
 readYaml(std::unique_ptr<MemoryBuffer> &mb);
 
 /// Writes a yaml encoded mach-o files given an in-memory normalized view.
index 51230cd..0b1e919 100644 (file)
@@ -800,7 +800,7 @@ bool MachOYamlIOTaggedDocumentHandler::handledDocTag(llvm::yaml::IO &io,
 namespace normalized {
 
 /// Parses a yaml encoded mach-o file to produce an in-memory normalized view.
-ErrorOr<std::unique_ptr<NormalizedFile>>
+llvm::Expected<std::unique_ptr<NormalizedFile>>
 readYaml(std::unique_ptr<MemoryBuffer> &mb) {
   // Make empty NormalizedFile.
   std::unique_ptr<NormalizedFile> f(new NormalizedFile());
@@ -814,8 +814,9 @@ readYaml(std::unique_ptr<MemoryBuffer> &mb) {
   yin >> *f;
 
   // Return error if there were parsing problems.
-  if (yin.error())
-    return make_error_code(lld::YamlReaderError::illegal_value);
+  if (auto ec = yin.error())
+    return llvm::make_error<GenericError>(Twine("YAML parsing error: ")
+                                          + ec.message());
 
   // Hand ownership of instantiated NormalizedFile to caller.
   return std::move(f);
index 6b75c34..211c3b1 100644 (file)
@@ -21,7 +21,7 @@ using lld::mach_o::normalized::Relocation;
 
 static std::unique_ptr<NormalizedFile> fromYAML(StringRef str) {
   std::unique_ptr<MemoryBuffer> mb(MemoryBuffer::getMemBuffer(str));
-  ErrorOr<std::unique_ptr<NormalizedFile>> r
+  llvm::Expected<std::unique_ptr<NormalizedFile>> r
                                     = lld::mach_o::normalized::readYaml(mb);
   EXPECT_FALSE(!r);
   return std::move(*r);