1d88c1a5aSDimitry Andric //===- MSFError.cpp - Error extensions for MSF files ------------*- C++ -*-===//
2d88c1a5aSDimitry Andric //
3d88c1a5aSDimitry Andric //                     The LLVM Compiler Infrastructure
4d88c1a5aSDimitry Andric //
5d88c1a5aSDimitry Andric // This file is distributed under the University of Illinois Open Source
6d88c1a5aSDimitry Andric // License. See LICENSE.TXT for details.
7d88c1a5aSDimitry Andric //
8d88c1a5aSDimitry Andric //===----------------------------------------------------------------------===//
9d88c1a5aSDimitry Andric 
10d88c1a5aSDimitry Andric #include "llvm/DebugInfo/MSF/MSFError.h"
11d88c1a5aSDimitry Andric #include "llvm/Support/ErrorHandling.h"
12d88c1a5aSDimitry Andric #include "llvm/Support/ManagedStatic.h"
13d88c1a5aSDimitry Andric 
14d88c1a5aSDimitry Andric using namespace llvm;
15d88c1a5aSDimitry Andric using namespace llvm::msf;
16d88c1a5aSDimitry Andric 
17d88c1a5aSDimitry Andric // FIXME: This class is only here to support the transition to llvm::Error. It
18d88c1a5aSDimitry Andric // will be removed once this transition is complete. Clients should prefer to
19d88c1a5aSDimitry Andric // deal with the Error value directly, rather than converting to error_code.
20d88c1a5aSDimitry Andric class MSFErrorCategory : public std::error_category {
21d88c1a5aSDimitry Andric public:
name() const22d88c1a5aSDimitry Andric   const char *name() const noexcept override { return "llvm.msf"; }
message(int Condition) const23d88c1a5aSDimitry Andric   std::string message(int Condition) const override {
24d88c1a5aSDimitry Andric     switch (static_cast<msf_error_code>(Condition)) {
25d88c1a5aSDimitry Andric     case msf_error_code::unspecified:
26d88c1a5aSDimitry Andric       return "An unknown error has occurred.";
27d88c1a5aSDimitry Andric     case msf_error_code::insufficient_buffer:
28d88c1a5aSDimitry Andric       return "The buffer is not large enough to read the requested number of "
29d88c1a5aSDimitry Andric              "bytes.";
30d88c1a5aSDimitry Andric     case msf_error_code::not_writable:
31d88c1a5aSDimitry Andric       return "The specified stream is not writable.";
32d88c1a5aSDimitry Andric     case msf_error_code::no_stream:
33d88c1a5aSDimitry Andric       return "The specified stream does not exist.";
34d88c1a5aSDimitry Andric     case msf_error_code::invalid_format:
35d88c1a5aSDimitry Andric       return "The data is in an unexpected format.";
36d88c1a5aSDimitry Andric     case msf_error_code::block_in_use:
37d88c1a5aSDimitry Andric       return "The block is already in use.";
38d88c1a5aSDimitry Andric     }
39d88c1a5aSDimitry Andric     llvm_unreachable("Unrecognized msf_error_code");
40d88c1a5aSDimitry Andric   }
41d88c1a5aSDimitry Andric };
42d88c1a5aSDimitry Andric 
43*b5893f02SDimitry Andric static llvm::ManagedStatic<MSFErrorCategory> MSFCategory;
MSFErrCategory()44*b5893f02SDimitry Andric const std::error_category &llvm::msf::MSFErrCategory() { return *MSFCategory; }
45d88c1a5aSDimitry Andric 
46*b5893f02SDimitry Andric char MSFError::ID;
47