2016-07-29 20:56:36 +00:00
|
|
|
//===- MSFError.cpp - Error extensions for MSF files ------------*- C++ -*-===//
|
2016-07-22 19:56:05 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-07-29 20:56:36 +00:00
|
|
|
#include "llvm/DebugInfo/MSF/MSFError.h"
|
2016-07-22 19:56:05 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::msf;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
// FIXME: This class is only here to support the transition to llvm::Error. It
|
|
|
|
// will be removed once this transition is complete. Clients should prefer to
|
|
|
|
// deal with the Error value directly, rather than converting to error_code.
|
2016-07-29 20:56:36 +00:00
|
|
|
class MSFErrorCategory : public std::error_category {
|
2016-07-22 19:56:05 +00:00
|
|
|
public:
|
2016-10-19 23:52:38 +00:00
|
|
|
const char *name() const noexcept override { return "llvm.msf"; }
|
2016-07-22 19:56:05 +00:00
|
|
|
|
|
|
|
std::string message(int Condition) const override {
|
|
|
|
switch (static_cast<msf_error_code>(Condition)) {
|
|
|
|
case msf_error_code::unspecified:
|
|
|
|
return "An unknown error has occurred.";
|
|
|
|
case msf_error_code::insufficient_buffer:
|
|
|
|
return "The buffer is not large enough to read the requested number of "
|
|
|
|
"bytes.";
|
|
|
|
case msf_error_code::not_writable:
|
|
|
|
return "The specified stream is not writable.";
|
|
|
|
case msf_error_code::no_stream:
|
|
|
|
return "The specified stream does not exist.";
|
|
|
|
case msf_error_code::invalid_format:
|
|
|
|
return "The data is in an unexpected format.";
|
|
|
|
case msf_error_code::block_in_use:
|
|
|
|
return "The block is already in use.";
|
|
|
|
}
|
|
|
|
llvm_unreachable("Unrecognized msf_error_code");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2016-07-29 20:56:36 +00:00
|
|
|
static ManagedStatic<MSFErrorCategory> Category;
|
2016-07-22 19:56:05 +00:00
|
|
|
|
2016-07-29 20:56:36 +00:00
|
|
|
char MSFError::ID = 0;
|
2016-07-22 19:56:05 +00:00
|
|
|
|
2016-07-29 20:56:36 +00:00
|
|
|
MSFError::MSFError(msf_error_code C) : MSFError(C, "") {}
|
2016-07-22 19:56:05 +00:00
|
|
|
|
2016-07-29 20:56:36 +00:00
|
|
|
MSFError::MSFError(const std::string &Context)
|
|
|
|
: MSFError(msf_error_code::unspecified, Context) {}
|
2016-07-22 19:56:05 +00:00
|
|
|
|
2016-07-29 20:56:36 +00:00
|
|
|
MSFError::MSFError(msf_error_code C, const std::string &Context) : Code(C) {
|
|
|
|
ErrMsg = "MSF Error: ";
|
2016-07-22 19:56:05 +00:00
|
|
|
std::error_code EC = convertToErrorCode();
|
|
|
|
if (Code != msf_error_code::unspecified)
|
|
|
|
ErrMsg += EC.message() + " ";
|
|
|
|
if (!Context.empty())
|
|
|
|
ErrMsg += Context;
|
|
|
|
}
|
|
|
|
|
2016-07-29 20:56:36 +00:00
|
|
|
void MSFError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
|
2016-07-22 19:56:05 +00:00
|
|
|
|
2016-07-29 20:56:36 +00:00
|
|
|
const std::string &MSFError::getErrorMessage() const { return ErrMsg; }
|
2016-07-22 19:56:05 +00:00
|
|
|
|
2016-07-29 20:56:36 +00:00
|
|
|
std::error_code MSFError::convertToErrorCode() const {
|
2016-07-22 19:56:05 +00:00
|
|
|
return std::error_code(static_cast<int>(Code), *Category);
|
|
|
|
}
|