LLVM 22.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
22const 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 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().
73class OutputConfigError : public ErrorInfo<OutputConfigError, OutputError> {
74 void anchor() override;
75
76public:
77 OutputConfig getConfig() const { return Config; }
78 void log(raw_ostream &OS) const override;
79
80 // Used by ErrorInfo::classID.
81 static char ID;
82
83 OutputConfigError(OutputConfig Config, const Twine &OutputPath)
85 OutputPath, OutputErrorCode::invalid_config),
86 Config(Config) {}
87
88private:
89 OutputConfig Config;
90};
91
92/// Error related to a temporary file for an \a OutputFile. Derives from \a
93/// OutputError and adds \a getTempPath().
94class TempFileOutputError : public ErrorInfo<TempFileOutputError, OutputError> {
95 void anchor() override;
96
97public:
98 StringRef getTempPath() const { return TempPath; }
99 void log(raw_ostream &OS) const override;
100
101 // Used by ErrorInfo::classID.
102 static char ID;
103
104 TempFileOutputError(const Twine &TempPath, const Twine &OutputPath,
105 std::error_code EC)
106 : ErrorInfo<TempFileOutputError, OutputError>(OutputPath, EC),
107 TempPath(TempPath.str()) {}
108
109 TempFileOutputError(const Twine &TempPath, const Twine &OutputPath,
111 : ErrorInfo<TempFileOutputError, OutputError>(OutputPath, EV),
112 TempPath(TempPath.str()) {}
113
114private:
115 std::string TempPath;
116};
117
118/// Return \a Error::success() or use \p TempPath and \p OutputPath to create a
119/// \a TempFileOutputError, depending on \p EC.
121 const Twine &OutputPath,
122 std::error_code EC) {
123 if (EC)
124 return make_error<TempFileOutputError>(TempPath, OutputPath, EC);
125 return Error::success();
126}
127
128} // namespace llvm::vfs
129
130#endif // LLVM_SUPPORT_VIRTUALOUTPUTERROR_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the declarations of the OutputConfig class.
ECError()=default
std::error_code EC
Definition Error.h:1210
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
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
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
void log(raw_ostream &OS) const override
OutputConfigError(OutputConfig Config, const Twine &OutputPath)
Error related to an OutputFile.
StringRef getOutputPath() const
void log(raw_ostream &OS) const override
Print an error message to an output stream.
OutputError(const Twine &OutputPath, std::error_code EC)
OutputError(const Twine &OutputPath, OutputErrorCode EV)
void log(raw_ostream &OS) const override
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)
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.