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

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


Author: Fangrui Song
Date: 2024-07-26T17:25:23-07:00
New Revision: b32c38ab5b4cf5c66469180ba3594e98eff2c124

URL: https://github.com/llvm/llvm-project/commit/b32c38ab5b4cf5c66469180ba3594e98eff2c124
DIFF: https://github.com/llvm/llvm-project/commit/b32c38ab5b4cf5c66469180ba3594e98eff2c124.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 2bea5da9ec798..a79a0b34892fc 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -313,9 +313,8 @@ void ScriptParser::readDefsym(StringRef name) {
 void ScriptParser::readNoCrossRefs(bool to) {
   expect("(");
   NoCrossRefCommand cmd{{}, to};
-  while (peek() != ")" && !atEOF())
-    cmd.outputSections.push_back(unquote(next()));
-  expect(")");
+  while (auto tok = till(")"))
+    cmd.outputSections.push_back(unquote(tok));
   if (cmd.outputSections.size() < 2)
     warn(getCurrentLocation() + ": ignored with fewer than 2 output sections");
   else
@@ -1769,16 +1768,13 @@ SmallVector<SymbolVersion, 0> ScriptParser::readVersionExtern() {
   expect("{");
 
   SmallVector<SymbolVersion, 0> ret;
-  while (!errorCount() && peek() != "}") {
-    StringRef tok = next();
+  while (auto tok = till("}")) {
     ret.push_back(
-        {unquote(tok), isCXX, !tok.starts_with("\"") && hasWildcard(tok)});
+        {unquote(tok), isCXX, !tok.str.starts_with("\"") && hasWildcard(tok)});
     if (consume("}"))
       return ret;
     expect(";");
   }
-
-  expect("}");
   return ret;
 }
 


        


More information about the llvm-commits mailing list