[lld] 2ae862b - [ELF] Remove `consumeLabel` in ScriptLexer (#99567)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 23 22:03:49 PDT 2024


Author: Hongyu Chen
Date: 2024-07-23T22:03:46-07:00
New Revision: 2ae862b74b3b132b6682350d47a095e733c337ce

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

LOG: [ELF] Remove `consumeLabel` in ScriptLexer (#99567)

This commit removes `consumeLabel` since we can just use consume
function to have the same functionalities.

Added: 
    

Modified: 
    lld/ELF/ScriptLexer.cpp
    lld/ELF/ScriptLexer.h
    lld/ELF/ScriptParser.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/ScriptLexer.cpp b/lld/ELF/ScriptLexer.cpp
index c8c02ab0f3e09..65055086d6bc2 100644
--- a/lld/ELF/ScriptLexer.cpp
+++ b/lld/ELF/ScriptLexer.cpp
@@ -279,18 +279,6 @@ bool ScriptLexer::consume(StringRef tok) {
   return false;
 }
 
-// Consumes Tok followed by ":". Space is allowed between Tok and ":".
-bool ScriptLexer::consumeLabel(StringRef tok) {
-  if (consume((tok + ":").str()))
-    return true;
-  if (tokens.size() >= pos + 2 && tokens[pos] == tok &&
-      tokens[pos + 1] == ":") {
-    pos += 2;
-    return true;
-  }
-  return false;
-}
-
 void ScriptLexer::skip() { (void)next(); }
 
 void ScriptLexer::expect(StringRef expect) {

diff  --git a/lld/ELF/ScriptLexer.h b/lld/ELF/ScriptLexer.h
index d5393818ed553..7d945d8f570c3 100644
--- a/lld/ELF/ScriptLexer.h
+++ b/lld/ELF/ScriptLexer.h
@@ -29,7 +29,6 @@ class ScriptLexer {
   void skip();
   bool consume(StringRef tok);
   void expect(StringRef expect);
-  bool consumeLabel(StringRef tok);
   std::string getCurrentLocation();
   MemoryBufferRef getCurrentMB();
 

diff  --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index 49aa7e6374905..8637a8b0b2167 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -1719,20 +1719,20 @@ ScriptParser::readSymbols() {
   while (!errorCount()) {
     if (consume("}"))
       break;
-    if (consumeLabel("local")) {
-      v = &locals;
-      continue;
-    }
-    if (consumeLabel("global")) {
-      v = &globals;
-      continue;
-    }
 
     if (consume("extern")) {
       SmallVector<SymbolVersion, 0> ext = readVersionExtern();
       v->insert(v->end(), ext.begin(), ext.end());
     } else {
       StringRef tok = next();
+      if (tok == "local:" || (tok == "local" && consume(":"))) {
+        v = &locals;
+        continue;
+      }
+      if (tok == "global:" || (tok == "global" && consume(":"))) {
+        v = &globals;
+        continue;
+      }
       v->push_back({unquote(tok), false, hasWildcard(tok)});
     }
     expect(";");


        


More information about the llvm-commits mailing list