LCOV - code coverage report
Current view: top level - lib/DebugInfo/Msf - MsfError.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 14 26 53.8 %
Date: 2016-07-29 04:53:09 Functions: 4 10 40.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- MsfError.cpp - Error extensions for Msf files ------------*- 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             : #include "llvm/DebugInfo/Msf/MsfError.h"
      11             : #include "llvm/Support/ErrorHandling.h"
      12             : #include "llvm/Support/ManagedStatic.h"
      13             : 
      14             : using namespace llvm;
      15             : using namespace llvm::msf;
      16             : 
      17             : namespace {
      18             : // FIXME: This class is only here to support the transition to llvm::Error. It
      19             : // will be removed once this transition is complete. Clients should prefer to
      20             : // deal with the Error value directly, rather than converting to error_code.
      21           8 : class MsfErrorCategory : public std::error_category {
      22             : public:
      23           0 :   const char *name() const LLVM_NOEXCEPT override { return "llvm.msf"; }
      24             : 
      25           3 :   std::string message(int Condition) const override {
      26           3 :     switch (static_cast<msf_error_code>(Condition)) {
      27             :     case msf_error_code::unspecified:
      28           0 :       return "An unknown error has occurred.";
      29             :     case msf_error_code::insufficient_buffer:
      30             :       return "The buffer is not large enough to read the requested number of "
      31           6 :              "bytes.";
      32             :     case msf_error_code::not_writable:
      33           0 :       return "The specified stream is not writable.";
      34             :     case msf_error_code::no_stream:
      35           0 :       return "The specified stream does not exist.";
      36             :     case msf_error_code::invalid_format:
      37           0 :       return "The data is in an unexpected format.";
      38             :     case msf_error_code::block_in_use:
      39           0 :       return "The block is already in use.";
      40             :     }
      41           0 :     llvm_unreachable("Unrecognized msf_error_code");
      42             :   }
      43             : };
      44             : } // end anonymous namespace
      45             : 
      46             : static ManagedStatic<MsfErrorCategory> Category;
      47             : 
      48             : char MsfError::ID = 0;
      49             : 
      50          12 : MsfError::MsfError(msf_error_code C) : MsfError(C, "") {}
      51             : 
      52           0 : MsfError::MsfError(const std::string &Context)
      53           0 :     : MsfError(msf_error_code::unspecified, Context) {}
      54             : 
      55           9 : MsfError::MsfError(msf_error_code C, const std::string &Context) : Code(C) {
      56           6 :   ErrMsg = "Msf Error: ";
      57           3 :   std::error_code EC = convertToErrorCode();
      58           3 :   if (Code != msf_error_code::unspecified)
      59          12 :     ErrMsg += EC.message() + "  ";
      60           3 :   if (!Context.empty())
      61           0 :     ErrMsg += Context;
      62           3 : }
      63             : 
      64           0 : void MsfError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
      65             : 
      66           0 : const std::string &MsfError::getErrorMessage() const { return ErrMsg; }
      67             : 
      68           3 : std::error_code MsfError::convertToErrorCode() const {
      69           3 :   return std::error_code(static_cast<int>(Code), *Category);
      70             : }

Generated by: LCOV version 1.12