[lld] [lld][ELF] remove `consumeLabel` in ScriptLexer (PR #99567)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 18 14:03:50 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lld-elf

Author: Hongyu Chen (yugier)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/99567.diff


3 Files Affected:

- (modified) lld/ELF/ScriptLexer.cpp (-12) 
- (modified) lld/ELF/ScriptLexer.h (-1) 
- (modified) lld/ELF/ScriptParser.cpp (+2-2) 


``````````diff
diff --git a/lld/ELF/ScriptLexer.cpp b/lld/ELF/ScriptLexer.cpp
index 14f39ed10e17c..5ac1c15043ce6 100644
--- a/lld/ELF/ScriptLexer.cpp
+++ b/lld/ELF/ScriptLexer.cpp
@@ -289,18 +289,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 7919e493fa28b..b4d2ab8627a91 100644
--- a/lld/ELF/ScriptLexer.h
+++ b/lld/ELF/ScriptLexer.h
@@ -30,7 +30,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 db46263115242..830c4f315a5a8 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -1692,11 +1692,11 @@ ScriptParser::readSymbols() {
   while (!errorCount()) {
     if (consume("}"))
       break;
-    if (consumeLabel("local")) {
+    if (consume("local:") || (consume("local") && consume(":"))) {
       v = &locals;
       continue;
     }
-    if (consumeLabel("global")) {
+    if (consume("global:") || (consume("global") && consume(":"))) {
       v = &globals;
       continue;
     }

``````````

</details>


https://github.com/llvm/llvm-project/pull/99567


More information about the llvm-commits mailing list