LLVM  6.0.0svn
Error.h
Go to the documentation of this file.
1 //===- Error.h - system_error extensions for Object -------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This declares a new error_category for the Object library.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_OBJECT_ERROR_H
15 #define LLVM_OBJECT_ERROR_H
16 
17 #include "llvm/ADT/Twine.h"
18 #include "llvm/Support/Error.h"
19 #include <system_error>
20 
21 namespace llvm {
22 namespace object {
23 
24 class Binary;
25 
27 
28 enum class object_error {
29  // Error code 0 is absent. Use std::error_code() instead.
30  arch_not_found = 1,
38 };
39 
40 inline std::error_code make_error_code(object_error e) {
41  return std::error_code(static_cast<int>(e), object_category());
42 }
43 
44 /// Base class for all errors indicating malformed binary files.
45 ///
46 /// Having a subclass for all malformed binary files allows archive-walking
47 /// code to skip malformed files without having to understand every possible
48 /// way that a binary file might be malformed.
49 ///
50 /// Currently inherits from ECError for easy interoperability with
51 /// std::error_code, but this will be removed in the future.
52 class BinaryError : public ErrorInfo<BinaryError, ECError> {
53 public:
54  static char ID;
56  // Default to parse_failed, can be overridden with setErrorCode.
58  }
59 };
60 
61 /// Generic binary error.
62 ///
63 /// For errors that don't require their own specific sub-error (most errors)
64 /// this class can be used to describe the error via a string message.
65 class GenericBinaryError : public ErrorInfo<GenericBinaryError, BinaryError> {
66 public:
67  static char ID;
69  GenericBinaryError(Twine Msg, object_error ECOverride);
70  const std::string &getMessage() const { return Msg; }
71  void log(raw_ostream &OS) const override;
72 private:
73  std::string Msg;
74 };
75 
76 /// isNotObjectErrorInvalidFileType() is used when looping through the children
77 /// of an archive after calling getAsBinary() on the child and it returns an
78 /// llvm::Error. In the cases we want to loop through the children and ignore the
79 /// non-objects in the archive this is used to test the error to see if an
80 /// error() function needs to called on the llvm::Error.
82 
83 } // end namespace object.
84 
85 } // end namespace llvm.
86 
87 namespace std {
88 template <>
89 struct is_error_code_enum<llvm::object::object_error> : std::true_type {};
90 }
91 
92 #endif
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
std::error_code make_error_code(object_error e)
Definition: Error.h:40
const std::error_category & object_category()
Definition: Error.cpp:76
Definition: BitVector.h:920
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
Error isNotObjectErrorInvalidFileType(llvm::Error Err)
isNotObjectErrorInvalidFileType() is used when looping through the children of an archive after calli...
Definition: Error.cpp:80
static char ID
Definition: Error.h:54
object_error
Definition: Error.h:28
static ManagedStatic< _object_error_category > error_category
Definition: Error.cpp:74
Base class for user error types.
Definition: Error.h:331
Base class for all errors indicating malformed binary files.
Definition: Error.h:52
Generic binary error.
Definition: Error.h:65
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
const std::string & getMessage() const
Definition: Error.h:70