[llvm] e5f746e - [MC] Replace a switch with two 'if's (NFC)

Sergei Barannikov via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 22 16:14:43 PST 2023


Author: Sergei Barannikov
Date: 2023-01-23T03:14:20+03:00
New Revision: e5f746e9bb61f06d273c629a06eb598abfbcedc3

URL: https://github.com/llvm/llvm-project/commit/e5f746e9bb61f06d273c629a06eb598abfbcedc3
DIFF: https://github.com/llvm/llvm-project/commit/e5f746e9bb61f06d273c629a06eb598abfbcedc3.diff

LOG: [MC] Replace a switch with two 'if's (NFC)

This simplifies logic a bit and helps to reduce the future diff.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index f16e109ac739e..6e9aa1bf52163 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -1901,16 +1901,14 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,
 
   // FIXME: Recurse on local labels?
 
-  // See what kind of statement we have.
-  switch (Lexer.getKind()) {
-  case AsmToken::Colon: {
-    if (!getTargetParser().isLabel(ID))
-      break;
+  // Check for a label.
+  //   ::= identifier ':'
+  //   ::= number ':'
+  if (Lexer.is(AsmToken::Colon) && getTargetParser().isLabel(ID)) {
     if (checkForValidSection())
       return true;
 
-    // identifier ':'   -> Label.
-    Lex();
+    Lex(); // Consume the ':'.
 
     // Diagnose attempt to use '.' as a label.
     if (IDVal == ".")
@@ -1971,16 +1969,11 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,
     return false;
   }
 
-  case AsmToken::Equal:
-    if (!getTargetParser().equalIsAsmAssignment())
-      break;
-    // identifier '=' ... -> assignment statement
+  // Check for an assignment statement.
+  //   ::= identifier '='
+  if (Lexer.is(AsmToken::Equal) && getTargetParser().equalIsAsmAssignment()) {
     Lex();
-
     return parseAssignment(IDVal, AssignmentKind::Equal);
-
-  default: // Normal instruction or directive.
-    break;
   }
 
   // If macros are enabled, check to see if this is a macro instantiation.


        


More information about the llvm-commits mailing list