Path: blob/main/contrib/llvm-project/llvm/lib/Support/BinaryStreamError.cpp
35232 views
//===- BinaryStreamError.cpp - Error extensions for streams -----*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/Support/BinaryStreamError.h"9#include "llvm/Support/raw_ostream.h"1011using namespace llvm;1213char BinaryStreamError::ID = 0;1415BinaryStreamError::BinaryStreamError(stream_error_code C)16: BinaryStreamError(C, "") {}1718BinaryStreamError::BinaryStreamError(StringRef Context)19: BinaryStreamError(stream_error_code::unspecified, Context) {}2021BinaryStreamError::BinaryStreamError(stream_error_code C, StringRef Context)22: Code(C) {23ErrMsg = "Stream Error: ";24switch (C) {25case stream_error_code::unspecified:26ErrMsg += "An unspecified error has occurred.";27break;28case stream_error_code::stream_too_short:29ErrMsg += "The stream is too short to perform the requested operation.";30break;31case stream_error_code::invalid_array_size:32ErrMsg += "The buffer size is not a multiple of the array element size.";33break;34case stream_error_code::invalid_offset:35ErrMsg += "The specified offset is invalid for the current stream.";36break;37case stream_error_code::filesystem_error:38ErrMsg += "An I/O error occurred on the file system.";39break;40}4142if (!Context.empty()) {43ErrMsg += " ";44ErrMsg += Context;45}46}4748void BinaryStreamError::log(raw_ostream &OS) const { OS << ErrMsg; }4950StringRef BinaryStreamError::getErrorMessage() const { return ErrMsg; }5152std::error_code BinaryStreamError::convertToErrorCode() const {53return inconvertibleErrorCode();54}555657