llvm/lldb/include/lldb/Utility/Status.h

//===-- Status.h ------------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_UTILITY_STATUS_H
#define LLDB_UTILITY_STATUS_H

#include "lldb/lldb-defines.h"
#include "lldb/lldb-enumerations.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
#include <cstdarg>
#include <cstdint>
#include <string>
#include <system_error>
#include <type_traits>

namespace llvm {
class raw_ostream;
}

namespace lldb_private {

const char *ExpressionResultAsCString(lldb::ExpressionResults result);

/// Going a bit against the spirit of llvm::Error,
/// lldb_private::Status need to store errors long-term and sometimes
/// copy them. This base class defines an interface for this
/// operation.
class CloneableError
    : public llvm::ErrorInfo<CloneableError, llvm::ErrorInfoBase> {};

/// Common base class for all error-code errors.
class CloneableECError
    : public llvm::ErrorInfo<CloneableECError, CloneableError> {};
/// FIXME: Move these declarations closer to where they're used.
class MachKernelError
    : public llvm::ErrorInfo<MachKernelError, CloneableECError> {};

class Win32Error : public llvm::ErrorInfo<Win32Error, CloneableECError> {};

class ExpressionErrorBase
    : public llvm::ErrorInfo<ExpressionErrorBase, CloneableECError> {};

/// \class Status Status.h "lldb/Utility/Status.h" An error handling class.
///
/// This class is designed to be able to hold any error code that can be
/// encountered on a given platform. The errors are stored as a value of type
/// Status::ValueType. This value should be large enough to hold any and all
/// errors that the class supports. Each error has an associated type that is
/// of type lldb::ErrorType. New types can be added to support new error
/// types, and architecture specific types can be enabled. In the future we
/// may wish to switch to a registration mechanism where new error types can
/// be registered at runtime instead of a hard coded scheme.
///
/// All errors in this class also know how to generate a string representation
/// of themselves for printing results and error codes. The string value will
/// be fetched on demand and its string value will be cached until the error
/// is cleared of the value of the error changes.
///
/// API design notes:
///
/// Most APIs that currently vend a Status would be better served by
/// returning llvm::Expected<> instead. If possibles APIs should be
/// refactored to avoid Status. The only legitimate long-term uses of
/// Status are objects that need to store an error for a long time
/// (which should be questioned as a design decision, too).
///
/// Implementation notes:
///
/// Internally, Status stores an llvm::Error.
///   eErrorTypeInvalid
///   eErrorTypeGeneric      llvm::StringError
///   eErrorTypePOSIX        llvm::ECError
///   eErrorTypeMachKernel   MachKernelError
///   eErrorTypeExpression   llvm::ErrorList<ExpressionError>
///   eErrorTypeWin32        Win32Error

class Status {};

} // namespace lldb_private

namespace llvm {
template <> struct format_provider<lldb_private::Status> {};
} // namespace llvm

#define LLDB_ERRORF(status, fmt, ...)

#endif // LLDB_UTILITY_STATUS_H