AsmParser: PARSE_MD_FIELD() => ParseMDField(), NFC
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 20 Jan 2015 02:42:29 +0000 (02:42 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 20 Jan 2015 02:42:29 +0000 (02:42 +0000)
Extract most of `PARSE_MD_FIELD()` into a function.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226539 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AsmParser/LLParser.cpp
lib/AsmParser/LLParser.h

index 442a49c43ac7e7e4cb3fbeb6793a14a51f031726..0ad921ae4befea24c09165ef453a2e35ea0b14f6 100644 (file)
@@ -2972,6 +2972,16 @@ bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
   return ParseToken(lltok::rparen, "expected ')' here");
 }
 
+template <class FieldTy>
+bool LLParser::ParseMDField(StringRef Name, FieldTy &Result) {
+  if (Result.Seen)
+    return TokError("field '" + Name + "' cannot be specified more than once");
+
+  LocTy Loc = Lex.getLoc();
+  Lex.Lex();
+  return ParseMDField(Loc, Name, Result);
+}
+
 bool LLParser::ParseSpecializedMDNode(MDNode *&N, bool IsDistinct) {
   assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
 #define DISPATCH_TO_PARSER(CLASS)                                              \
@@ -2990,19 +3000,8 @@ bool LLParser::ParseSpecializedMDNode(MDNode *&N, bool IsDistinct) {
   if (!NAME.Seen)                                                              \
     return Error(ClosingLoc, "missing required field '" #NAME "'");
 #define PARSE_MD_FIELD(NAME, TYPE, DEFAULT)                                    \
-  do {                                                                         \
-    if (Lex.getStrVal() == #NAME) {                                            \
-      if (NAME.Seen)                                                           \
-        return TokError("field '" #NAME                                        \
-                        "' cannot be specified more than once");               \
-                                                                               \
-      LocTy Loc = Lex.getLoc();                                                \
-      Lex.Lex();                                                               \
-      if (ParseMDField(Loc, #NAME, NAME))                                      \
-        return true;                                                           \
-      return false;                                                            \
-    }                                                                          \
-  } while (0)
+  if (Lex.getStrVal() == #NAME)                                                \
+    return ParseMDField(#NAME, NAME);
 #define PARSE_MD_FIELDS()                                                      \
   VISIT_MD_FIELDS(DECLARE_FIELD, DECLARE_FIELD)                                \
   do {                                                                         \
index ad311910a6fe3ee223233fd72f8f51c1ec5c00fa..235e2642ef26bb276fe0dd87bb15ca42a5954904 100644 (file)
@@ -421,6 +421,7 @@ namespace llvm {
     bool ParseMDField(LocTy Loc, StringRef Name,
                       MDUnsignedField<uint32_t> &Result);
     bool ParseMDField(LocTy Loc, StringRef Name, MDField &Result);
+    template <class FieldTy> bool ParseMDField(StringRef Name, FieldTy &Result);
     template <class ParserTy>
     bool ParseMDFieldsImplBody(ParserTy parseField);
     template <class ParserTy>