[lld] 10bb296 - [ELF] Replace some while (peek() != ")" && !atEOF()) with till

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 26 17:19:09 PDT 2024


Author: Fangrui Song
Date: 2024-07-26T17:19:04-07:00
New Revision: 10bb296dfcefcb13fdead32e35822767e59c70da

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

LOG: [ELF] Replace some while (peek() != ")" && !atEOF()) with till

Added: 
    

Modified: 
    lld/ELF/ScriptParser.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index bdfa106090ca5..2bea5da9ec798 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -375,10 +375,9 @@ void ScriptParser::readAsNeeded() {
   expect("(");
   bool orig = config->asNeeded;
   config->asNeeded = true;
-  while (peek() != ")" && !atEOF())
-    addFile(unquote(next()));
+  while (auto tok = till(")"))
+    addFile(unquote(tok));
   config->asNeeded = orig;
-  expect(")");
 }
 
 void ScriptParser::readEntry() {
@@ -392,9 +391,8 @@ void ScriptParser::readEntry() {
 
 void ScriptParser::readExtern() {
   expect("(");
-  while (peek() != ")" && !atEOF())
-    config->undefined.push_back(unquote(next()));
-  expect(")");
+  while (auto tok = till(")"))
+    config->undefined.push_back(unquote(tok));
 }
 
 void ScriptParser::readGroup() {
@@ -427,13 +425,12 @@ void ScriptParser::readInclude() {
 
 void ScriptParser::readInput() {
   expect("(");
-  while (peek() != ")" && !atEOF()) {
-    if (consume("AS_NEEDED"))
+  while (auto tok = till(")")) {
+    if (tok == "AS_NEEDED")
       readAsNeeded();
     else
-      addFile(unquote(next()));
+      addFile(unquote(tok));
   }
-  expect(")");
 }
 
 void ScriptParser::readOutput() {
@@ -712,10 +709,8 @@ static int precedence(StringRef op) {
 
 StringMatcher ScriptParser::readFilePatterns() {
   StringMatcher Matcher;
-
-  while (peek() != ")" && !atEOF())
-    Matcher.addPattern(SingleStringMatcher(next()));
-  expect(")");
+  while (auto tok = till(")"))
+    Matcher.addPattern(SingleStringMatcher(tok));
   return Matcher;
 }
 


        


More information about the llvm-commits mailing list