blob: 40f97d48a1dc0dfe340726c182f40d59d9d6ef82 [file] [log] [blame]
Michael J. Spencerd2a02f42011-06-25 17:42:56 +00001//===- Error.cpp - 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 defines a new error_category for the Object library.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Object/Error.h"
15#include "llvm/Support/ErrorHandling.h"
16
17using namespace llvm;
18using namespace object;
19
20namespace {
21class _object_error_category : public _do_message {
22public:
23 virtual const char* name() const;
24 virtual std::string message(int ev) const;
25 virtual error_condition default_error_condition(int ev) const;
26};
27}
28
29const char *_object_error_category::name() const {
30 return "llvm.object";
31}
32
33std::string _object_error_category::message(int ev) const {
34 switch (ev) {
35 case object_error::success: return "Success";
36 case object_error::invalid_file_type:
37 return "The file was not recognized as a valid object file";
38 case object_error::parse_failed:
39 return "Invalid data was encountered while parsing the file";
40 default:
41 llvm_unreachable("An enumerator of object_error does not have a message "
42 "defined.");
43 }
44}
45
46error_condition _object_error_category::default_error_condition(int ev) const {
47 if (ev == object_error::success)
48 return errc::success;
49 return errc::invalid_argument;
50}
51
52const error_category &object::object_category() {
53 static _object_error_category o;
54 return o;
55}