Skip to content

Commit 15ef9b2

Browse files
committed
[MC] Allow conversion between ParseStatus and MatchOperandResultTy
This allows a smooth transition to ParseStatus.
1 parent 5106b22 commit 15ef9b2

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ struct ParseInstructionInfo {
122122
: AsmRewrites(rewrites) {}
123123
};
124124

125+
enum OperandMatchResultTy {
126+
MatchOperand_Success, // operand matched successfully
127+
MatchOperand_NoMatch, // operand did not match
128+
MatchOperand_ParseFail // operand matched but had errors
129+
};
130+
125131
/// Ternary parse status returned by various parse* methods.
126132
class ParseStatus {
127133
enum class StatusTy { Success, Failure, NoMatch } Status;
@@ -146,12 +152,17 @@ class ParseStatus {
146152
constexpr bool isSuccess() const { return Status == StatusTy::Success; }
147153
constexpr bool isFailure() const { return Status == StatusTy::Failure; }
148154
constexpr bool isNoMatch() const { return Status == StatusTy::NoMatch; }
149-
};
150155

151-
enum OperandMatchResultTy {
152-
MatchOperand_Success, // operand matched successfully
153-
MatchOperand_NoMatch, // operand did not match
154-
MatchOperand_ParseFail // operand matched but had errors
156+
// Allow implicit conversions to / from OperandMatchResultTy.
157+
constexpr ParseStatus(OperandMatchResultTy R)
158+
: Status(R == MatchOperand_Success ? Success
159+
: R == MatchOperand_ParseFail ? Failure
160+
: NoMatch) {}
161+
constexpr operator OperandMatchResultTy() const {
162+
return isSuccess() ? MatchOperand_Success
163+
: isFailure() ? MatchOperand_ParseFail
164+
: MatchOperand_NoMatch;
165+
}
155166
};
156167

157168
enum class DiagnosticPredicateTy {

0 commit comments

Comments
 (0)