[Demangler] Tidy up a bit, and add line numbers to ManglingErrors.

Because DEMANGLER_ASSERT() might cause the remanglers to return a ManglingError
with the code ManglingError::AssertionFailed, it's useful to have a line number
in the ManglingError as well as the other information.  This is also potentially
helpful for other cases where the code is used multiple times in the remanglers.

rdar://79725187
This commit is contained in:
Alastair Houghton
2021-09-06 16:42:20 +01:00
parent 227b438963
commit b8a879954a
7 changed files with 206 additions and 180 deletions

View File

@@ -542,14 +542,17 @@ struct SWIFT_NODISCARD ManglingError {
Code code;
NodePointer node;
unsigned line;
ManglingError() : code(Uninitialized), node(nullptr) {}
ManglingError(Code c) : code(c), node(nullptr) {}
ManglingError(Code c, NodePointer n) : code(c), node(n) {}
ManglingError(Code c) : code(c), node(nullptr), line(0) {}
ManglingError(Code c, NodePointer n, unsigned l) : code(c), node(n), line(l) {}
bool isSuccess() const { return code == Success; }
};
#define MANGLING_ERROR(c,n) ManglingError((c), (n), __LINE__)
/// Used as a return type for mangling functions that may fail
template <typename T>
class SWIFT_NODISCARD ManglingErrorOr {
@@ -559,8 +562,10 @@ private:
public:
ManglingErrorOr() : err_() {}
ManglingErrorOr(ManglingError::Code code, NodePointer node = nullptr)
: err_(code, node) {}
ManglingErrorOr(ManglingError::Code code,
NodePointer node = nullptr,
unsigned line = 0)
: err_(code, node, line) {}
ManglingErrorOr(const ManglingError &err) : err_(err) {}
ManglingErrorOr(const T &t) : err_(ManglingError::Success), value_(t) {}
ManglingErrorOr(T &&t) : err_(ManglingError::Success), value_(std::move(t)) {}
@@ -568,8 +573,6 @@ public:
bool isSuccess() const { return err_.code == ManglingError::Success; }
const ManglingError &error() const { return err_; }
ManglingError::Code errorCode() const { return err_.code; }
NodePointer errorNode() const { return err_.node; }
const T &result() const {
assert(isSuccess());