AsmParser: Refactor duplicate code, NFC
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 20 Jan 2015 02:39:21 +0000 (02:39 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 20 Jan 2015 02:39:21 +0000 (02:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226538 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AsmParser/LLParser.cpp

index 78818b288fa6057a773c4b3fd3b14d78239833e5..442a49c43ac7e7e4cb3fbeb6793a14a51f031726 100644 (file)
@@ -2923,10 +2923,6 @@ bool LLParser::ParseMDNodeTail(MDNode *&N) {
 
 bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
                             MDUnsignedField<uint32_t> &Result) {
-  if (Result.Seen)
-    return Error(Loc,
-                 "field '" + Name + "' cannot be specified more than once");
-
   if (Lex.getKind() != lltok::APSInt || Lex.getAPSIntVal().isSigned())
     return TokError("expected unsigned integer");
   uint64_t Val64 = Lex.getAPSIntVal().getLimitedValue(Result.Max + 1ull);
@@ -2940,10 +2936,6 @@ bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
 }
 
 bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDField &Result) {
-  if (Result.Seen)
-    return Error(Loc,
-                 "field '" + Name + "' cannot be specified more than once");
-
   Metadata *MD;
   if (ParseMetadata(MD, nullptr))
     return true;
@@ -3000,6 +2992,10 @@ bool LLParser::ParseSpecializedMDNode(MDNode *&N, bool IsDistinct) {
 #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))                                      \