[YAMLIO] Add support for numeric values in enums.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226942 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Michael J. Spencer 2015-01-23 21:57:50 +00:00
parent 89eab6e7bd
commit 96c609287d
2 changed files with 26 additions and 0 deletions

View File

@ -447,6 +447,7 @@ public:
virtual void beginEnumScalar() = 0;
virtual bool matchEnumScalar(const char*, bool) = 0;
virtual bool matchEnumFallback() = 0;
virtual void endEnumScalar() = 0;
virtual bool beginBitSetScalar(bool &) = 0;
@ -472,6 +473,15 @@ public:
}
}
template <typename FBT, typename T>
void enumFallback(T &Val) {
if ( matchEnumFallback() ) {
FBT Res = Val;
yamlize(*this, Res, true);
Val = Res;
}
}
template <typename T>
void bitSetCase(T &Val, const char* Str, const T ConstVal) {
if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) {
@ -899,6 +909,7 @@ private:
void endFlowSequence() override;
void beginEnumScalar() override;
bool matchEnumScalar(const char*, bool) override;
bool matchEnumFallback() override;
void endEnumScalar() override;
bool beginBitSetScalar(bool &) override;
bool bitSetMatch(const char *, bool ) override;
@ -1026,6 +1037,7 @@ public:
void endFlowSequence() override;
void beginEnumScalar() override;
bool matchEnumScalar(const char*, bool) override;
bool matchEnumFallback() override;
void endEnumScalar() override;
bool beginBitSetScalar(bool &) override;
bool bitSetMatch(const char *, bool ) override;

View File

@ -233,6 +233,13 @@ bool Input::matchEnumScalar(const char *Str, bool) {
return false;
}
bool Input::matchEnumFallback() {
if (ScalarMatchFound)
return false;
ScalarMatchFound = true;
return true;
}
void Input::endEnumScalar() {
if (!ScalarMatchFound) {
setError(CurrentNode, "unknown enumerated scalar");
@ -508,6 +515,13 @@ bool Output::matchEnumScalar(const char *Str, bool Match) {
return false;
}
bool Output::matchEnumFallback() {
if (EnumerationMatchFound)
return false;
EnumerationMatchFound = true;
return true;
}
void Output::endEnumScalar() {
if (!EnumerationMatchFound)
llvm_unreachable("bad runtime enum value");