17a7e6055SDimitry Andric //===- BinaryStreamError.cpp - Error extensions for streams -----*- C++ -*-===// 27a7e6055SDimitry Andric // 37a7e6055SDimitry Andric // The LLVM Compiler Infrastructure 47a7e6055SDimitry Andric // 57a7e6055SDimitry Andric // This file is distributed under the University of Illinois Open Source 67a7e6055SDimitry Andric // License. See LICENSE.TXT for details. 77a7e6055SDimitry Andric // 87a7e6055SDimitry Andric //===----------------------------------------------------------------------===// 97a7e6055SDimitry Andric 107a7e6055SDimitry Andric #include "llvm/Support/BinaryStreamError.h" 117a7e6055SDimitry Andric #include "llvm/Support/ErrorHandling.h" 127a7e6055SDimitry Andric 137a7e6055SDimitry Andric using namespace llvm; 147a7e6055SDimitry Andric 157a7e6055SDimitry Andric char BinaryStreamError::ID = 0; 167a7e6055SDimitry Andric BinaryStreamError(stream_error_code C)177a7e6055SDimitry AndricBinaryStreamError::BinaryStreamError(stream_error_code C) 187a7e6055SDimitry Andric : BinaryStreamError(C, "") {} 197a7e6055SDimitry Andric BinaryStreamError(StringRef Context)207a7e6055SDimitry AndricBinaryStreamError::BinaryStreamError(StringRef Context) 217a7e6055SDimitry Andric : BinaryStreamError(stream_error_code::unspecified, Context) {} 227a7e6055SDimitry Andric BinaryStreamError(stream_error_code C,StringRef Context)237a7e6055SDimitry AndricBinaryStreamError::BinaryStreamError(stream_error_code C, StringRef Context) 247a7e6055SDimitry Andric : Code(C) { 257a7e6055SDimitry Andric ErrMsg = "Stream Error: "; 267a7e6055SDimitry Andric switch (C) { 277a7e6055SDimitry Andric case stream_error_code::unspecified: 287a7e6055SDimitry Andric ErrMsg += "An unspecified error has occurred."; 297a7e6055SDimitry Andric break; 307a7e6055SDimitry Andric case stream_error_code::stream_too_short: 317a7e6055SDimitry Andric ErrMsg += "The stream is too short to perform the requested operation."; 327a7e6055SDimitry Andric break; 337a7e6055SDimitry Andric case stream_error_code::invalid_array_size: 347a7e6055SDimitry Andric ErrMsg += "The buffer size is not a multiple of the array element size."; 357a7e6055SDimitry Andric break; 367a7e6055SDimitry Andric case stream_error_code::invalid_offset: 377a7e6055SDimitry Andric ErrMsg += "The specified offset is invalid for the current stream."; 387a7e6055SDimitry Andric break; 397a7e6055SDimitry Andric case stream_error_code::filesystem_error: 407a7e6055SDimitry Andric ErrMsg += "An I/O error occurred on the file system."; 417a7e6055SDimitry Andric break; 427a7e6055SDimitry Andric } 437a7e6055SDimitry Andric 447a7e6055SDimitry Andric if (!Context.empty()) { 457a7e6055SDimitry Andric ErrMsg += " "; 467a7e6055SDimitry Andric ErrMsg += Context; 477a7e6055SDimitry Andric } 487a7e6055SDimitry Andric } 497a7e6055SDimitry Andric log(raw_ostream & OS) const50*b5893f02SDimitry Andricvoid BinaryStreamError::log(raw_ostream &OS) const { OS << ErrMsg; } 517a7e6055SDimitry Andric getErrorMessage() const527a7e6055SDimitry AndricStringRef BinaryStreamError::getErrorMessage() const { return ErrMsg; } 537a7e6055SDimitry Andric convertToErrorCode() const547a7e6055SDimitry Andricstd::error_code BinaryStreamError::convertToErrorCode() const { 557a7e6055SDimitry Andric return inconvertibleErrorCode(); 567a7e6055SDimitry Andric } 57