Skip to content

Commit fc3322f

Browse files
committed
[Demangling] More remangler error handling.
First pass at adding error handling to the actual Remangler. There are still some assert() calls at this point that I'm thinking about. rdar://79725187
1 parent 3f01f85 commit fc3322f

File tree

2 files changed

+1339
-868
lines changed

2 files changed

+1339
-868
lines changed

include/swift/Demangling/Demangle.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ enum class OperatorKind {
513513
};
514514

515515
/// A mangling error, which consists of an error code and a Node pointer
516-
struct ManglingError {
516+
struct SWIFT_NODISCARD ManglingError {
517517
enum Code {
518518
Success = 0,
519519
Uninitialized,
@@ -524,20 +524,32 @@ struct ManglingError {
524524
UnsupportedNodeKind,
525525
UnexpectedBuiltinVectorType,
526526
UnexpectedBuiltinType,
527+
MultipleChildNodes,
528+
WrongNodeType,
529+
WrongDependentMemberType,
530+
BadDirectness,
531+
UnknownEncoding,
532+
InvalidImplCalleeConvention,
533+
InvalidImplDifferentiability,
534+
InvalidImplFunctionAttribute,
535+
InvalidImplParameterConvention,
536+
InvalidMetatypeRepresentation,
537+
MultiByteRelatedEntity,
527538
};
528539

529540
Code code;
530541
NodePointer node;
531542

532543
ManglingError() : code(Uninitialized), node(nullptr) {}
533-
ManglingError(Code c, NodePointer n = nullptr) : code(c), node(n) {}
544+
ManglingError(Code c) : code(c), node(nullptr) {}
545+
ManglingError(Code c, NodePointer n) : code(c), node(n) {}
534546

535547
bool isSuccess() const { return code == Success; }
536548
};
537549

538550
/// Used as a return type for mangling functions that may fail
539551
template <typename T>
540-
class ManglingErrorOr {
552+
class SWIFT_NODISCARD ManglingErrorOr {
541553
private:
542554
ManglingError err_;
543555
T value_;
@@ -552,6 +564,7 @@ class ManglingErrorOr {
552564

553565
bool isSuccess() const { return err_.code == ManglingError::Success; }
554566

567+
const ManglingError &error() const { return err_; }
555568
ManglingError::Code errorCode() const { return err_.code; }
556569
NodePointer errorNode() const { return err_.node; }
557570

0 commit comments

Comments
 (0)