[llvm] r201629 - MCAsmParser: change representation of MCAsmMacroParameter

Saleem Abdulrasool compnerd at compnerd.org
Tue Feb 18 19:00:23 PST 2014


Author: compnerd
Date: Tue Feb 18 21:00:23 2014
New Revision: 201629

URL: http://llvm.org/viewvc/llvm-project?rev=201629&view=rev
Log:
MCAsmParser: change representation of MCAsmMacroParameter

Rather than using std::pair, create a structure to represent the type.  This is
a preliminary refactoring to enable required parameter handling.  Additional
state is needed to indicate required parameters.  This has a minor side effect
of improving readability by providing more accurate names compared to first and
second.

Modified:
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp

Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=201629&r1=201628&r2=201629&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Tue Feb 18 21:00:23 2014
@@ -51,11 +51,15 @@ FatalAssemblerWarnings("fatal-assembler-
 MCAsmParserSemaCallback::~MCAsmParserSemaCallback() {}
 
 namespace {
-
 /// \brief Helper types for tracking macro definitions.
 typedef std::vector<AsmToken> MCAsmMacroArgument;
 typedef std::vector<MCAsmMacroArgument> MCAsmMacroArguments;
-typedef std::pair<StringRef, MCAsmMacroArgument> MCAsmMacroParameter;
+
+struct MCAsmMacroParameter {
+  StringRef Name;
+  MCAsmMacroArgument Value;
+};
+
 typedef std::vector<MCAsmMacroParameter> MCAsmMacroParameters;
 
 struct MCAsmMacro {
@@ -1793,7 +1797,7 @@ bool AsmParser::expandMacro(raw_svector_
       StringRef Argument(Begin, I - (Pos + 1));
       unsigned Index = 0;
       for (; Index < NParameters; ++Index)
-        if (Parameters[Index].first == Argument)
+        if (Parameters[Index].Name == Argument)
           break;
 
       if (Index == NParameters) {
@@ -1939,8 +1943,8 @@ bool AsmParser::parseMacroArguments(cons
 
   A.resize(NParameters);
   for (unsigned PI = 0; PI < NParameters; ++PI)
-    if (!M->Parameters[PI].second.empty())
-      A[PI] = M->Parameters[PI].second;
+    if (!M->Parameters[PI].Value.empty())
+      A[PI] = M->Parameters[PI].Value;
 
   bool NamedParametersFound = false;
 
@@ -1954,7 +1958,7 @@ bool AsmParser::parseMacroArguments(cons
 
     if (Lexer.is(AsmToken::Identifier) && Lexer.peekTok().is(AsmToken::Equal)) {
       L = Lexer.getLoc();
-      if (parseIdentifier(FA.first)) {
+      if (parseIdentifier(FA.Name)) {
         Error(L, "invalid argument identifier for formal argument");
         eatToEndOfStatement();
         return true;
@@ -1970,34 +1974,34 @@ bool AsmParser::parseMacroArguments(cons
       NamedParametersFound = true;
     }
 
-    if (NamedParametersFound && FA.first.empty()) {
+    if (NamedParametersFound && FA.Name.empty()) {
       Error(Lexer.getLoc(), "cannot mix positional and keyword arguments");
       eatToEndOfStatement();
       return true;
     }
 
-    if (parseMacroArgument(FA.second))
+    if (parseMacroArgument(FA.Value))
       return true;
 
     unsigned PI = Parameter;
-    if (!FA.first.empty()) {
+    if (!FA.Name.empty()) {
       unsigned FAI = 0;
       for (FAI = 0; FAI < NParameters; ++FAI)
-        if (M->Parameters[FAI].first == FA.first)
+        if (M->Parameters[FAI].Name == FA.Name)
           break;
       if (FAI >= NParameters) {
         Error(L,
-              "parameter named '" + FA.first + "' does not exist for macro '" +
+              "parameter named '" + FA.Name + "' does not exist for macro '" +
               M->Name + "'");
         return true;
       }
       PI = FAI;
     }
 
-    if (!FA.second.empty()) {
+    if (!FA.Value.empty()) {
       if (A.size() <= PI)
         A.resize(PI + 1);
-      A[PI] = FA.second;
+      A[PI] = FA.Value;
     }
 
     // At the end of the statement, fill in remaining arguments that have
@@ -3203,12 +3207,12 @@ bool AsmParser::parseDirectiveMacro(SMLo
   MCAsmMacroParameters Parameters;
   while (getLexer().isNot(AsmToken::EndOfStatement)) {
     MCAsmMacroParameter Parameter;
-    if (parseIdentifier(Parameter.first))
+    if (parseIdentifier(Parameter.Name))
       return TokError("expected identifier in '.macro' directive");
 
     if (getLexer().is(AsmToken::Equal)) {
       Lex();
-      if (parseMacroArgument(Parameter.second))
+      if (parseMacroArgument(Parameter.Value))
         return true;
     }
 
@@ -3346,7 +3350,7 @@ void AsmParser::checkForBadMacro(SMLoc D
       StringRef Argument(Begin, I - (Pos + 1));
       unsigned Index = 0;
       for (; Index < NParameters; ++Index)
-        if (Parameters[Index].first == Argument)
+        if (Parameters[Index].Name == Argument)
           break;
 
       if (Index == NParameters) {
@@ -4114,7 +4118,7 @@ bool AsmParser::parseDirectiveRept(SMLoc
 bool AsmParser::parseDirectiveIrp(SMLoc DirectiveLoc) {
   MCAsmMacroParameter Parameter;
 
-  if (parseIdentifier(Parameter.first))
+  if (parseIdentifier(Parameter.Name))
     return TokError("expected identifier in '.irp' directive");
 
   if (Lexer.isNot(AsmToken::Comma))
@@ -4154,7 +4158,7 @@ bool AsmParser::parseDirectiveIrp(SMLoc
 bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {
   MCAsmMacroParameter Parameter;
 
-  if (parseIdentifier(Parameter.first))
+  if (parseIdentifier(Parameter.Name))
     return TokError("expected identifier in '.irpc' directive");
 
   if (Lexer.isNot(AsmToken::Comma))





More information about the llvm-commits mailing list