LLVM 23.0.0git
VirtualOutputError.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file contains the declarations of the OutputError class.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_SUPPORT_VIRTUALOUTPUTERROR_H
15#define LLVM_SUPPORT_VIRTUALOUTPUTERROR_H
16
17#include "llvm/Support/Error.h"
19
20namespace llvm::vfs {
21
22LLVM_ABI const std::error_category &output_category();
23
24enum class OutputErrorCode {
25 // Error code 0 is absent. Use std::error_code() instead.
30};
31
32inline std::error_code make_error_code(OutputErrorCode EV) {
33 return std::error_code(static_cast<int>(EV), output_category());
34}
35
36/// Error related to an \a OutputFile. Derives from \a ECError and adds \a
37/// getOutputPath().
38class LLVM_ABI OutputError : public ErrorInfo<OutputError, ECError> {
39 void anchor() override;
40
41public:
42 StringRef getOutputPath() const { return OutputPath; }
43 void log(raw_ostream &OS) const override;
44
45 // Used by ErrorInfo::classID.
46 static char ID;
47
48 OutputError(const Twine &OutputPath, std::error_code EC)
49 : ErrorInfo<OutputError, ECError>(EC), OutputPath(OutputPath.str()) {
50 assert(EC && "Cannot create OutputError from success EC");
51 }
52
53 OutputError(const Twine &OutputPath, OutputErrorCode EV)
55 OutputPath(OutputPath.str()) {
56 assert(EC && "Cannot create OutputError from success EC");
57 }
58
59private:
60 std::string OutputPath;
61};
62
63/// Return \a Error::success() or use \p OutputPath to create an \a
64/// OutputError, depending on \p EC.
65inline Error convertToOutputError(const Twine &OutputPath, std::error_code EC) {
66 if (EC)
67 return make_error<OutputError>(OutputPath, EC);
68 return Error::success();
69}
70
71/// Error related to an OutputConfig for an \a OutputFile. Derives from \a
72/// OutputError and adds \a getConfig().
74 : public ErrorInfo<OutputConfigError, OutputError> {
75 void anchor() override;
76
77public:
78 OutputConfig getConfig() const { return Config; }
79 void log(raw_ostream &OS) const override;
80
81 // Used by ErrorInfo::classID.
82 static char ID;
83
84 OutputConfigError(OutputConfig Config, const Twine &OutputPath)
86 OutputPath, OutputErrorCode::invalid_config),
87 Config(Config) {}
88
89private:
90 OutputConfig Config;
91};
92
93/// Error related to a temporary file for an \a OutputFile. Derives from \a
94/// OutputError and adds \a getTempPath().
96 : public ErrorInfo<TempFileOutputError, OutputError> {
97 void anchor() override;
98
99public:
100 StringRef getTempPath() const { return TempPath; }
101 void log(raw_ostream &OS) const override;
102
103 // Used by ErrorInfo::classID.
104 static char ID;
105
106 TempFileOutputError(const Twine &TempPath, const Twine &OutputPath,
107 std::error_code EC)
108 : ErrorInfo<TempFileOutputError, OutputError>(OutputPath, EC),
109 TempPath(TempPath.str()) {}
110
111 TempFileOutputError(const Twine &TempPath, const Twine &OutputPath,
113 : ErrorInfo<TempFileOutputError, OutputError>(OutputPath, EV),
114 TempPath(TempPath.str()) {}
115
116private:
117 std::string TempPath;
118};
119
120/// Return \a Error::success() or use \p TempPath and \p OutputPath to create a
121/// \a TempFileOutputError, depending on \p EC.
123 const Twine &OutputPath,
124 std::error_code EC) {
125 if (EC)
126 return make_error<TempFileOutputError>(TempPath, OutputPath, EC);
127 return Error::success();
128}
129
130} // namespace llvm::vfs
131
132#endif // LLVM_SUPPORT_VIRTUALOUTPUTERROR_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition Compiler.h:213
This file contains the declarations of the OutputConfig class.
ECError()=default
std::error_code EC
Definition Error.h:1226
Base class for user error types.
Definition Error.h:354
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
OutputConfigError(OutputConfig Config, const Twine &OutputPath)
Error related to an OutputFile.
StringRef getOutputPath() const
OutputError(const Twine &OutputPath, std::error_code EC)
OutputError(const Twine &OutputPath, OutputErrorCode EV)
TempFileOutputError(const Twine &TempPath, const Twine &OutputPath, std::error_code EC)
TempFileOutputError(const Twine &TempPath, const Twine &OutputPath, OutputErrorCode EV)
Error convertToOutputError(const Twine &OutputPath, std::error_code EC)
Return Error::success() or use OutputPath to create an OutputError, depending on EC.
std::error_code make_error_code(OutputErrorCode EV)
LLVM_ABI const std::error_category & output_category()
Error convertToTempFileOutputError(const Twine &TempPath, const Twine &OutputPath, std::error_code EC)
Return Error::success() or use TempPath and OutputPath to create a TempFileOutputError,...
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
Full configuration for an output for use by the OutputBackend.