[lld] b828c13 - [ELF] Delete peek2 in Lexer (#99790)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 20 16:35:42 PDT 2024
Author: Hongyu Chen
Date: 2024-07-20T16:35:38-07:00
New Revision: b828c13f3ceb336bf517fab0223b966ccace100e
URL: https://github.com/llvm/llvm-project/commit/b828c13f3ceb336bf517fab0223b966ccace100e
DIFF: https://github.com/llvm/llvm-project/commit/b828c13f3ceb336bf517fab0223b966ccace100e.diff
LOG: [ELF] Delete peek2 in Lexer (#99790)
Thanks to Fangrui's change
https://github.com/llvm/llvm-project/commit/28045ceab08d41a8a42d93ebc445e8fe906f884c
so peek2 can be removed.
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 d5ffe8c4dfd8c..c8c02ab0f3e09 100644
--- a/lld/ELF/ScriptLexer.cpp
+++ b/lld/ELF/ScriptLexer.cpp
@@ -272,15 +272,6 @@ StringRef ScriptLexer::peek() {
return tok;
}
-StringRef ScriptLexer::peek2() {
- skip();
- StringRef tok = next();
- if (errorCount())
- return "";
- pos = pos - 2;
- return tok;
-}
-
bool ScriptLexer::consume(StringRef tok) {
if (next() == tok)
return true;
diff --git a/lld/ELF/ScriptLexer.h b/lld/ELF/ScriptLexer.h
index 7919e493fa28b..d5393818ed553 100644
--- a/lld/ELF/ScriptLexer.h
+++ b/lld/ELF/ScriptLexer.h
@@ -26,7 +26,6 @@ class ScriptLexer {
bool atEOF();
StringRef next();
StringRef peek();
- StringRef peek2();
void skip();
bool consume(StringRef tok);
void expect(StringRef expect);
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index f20de5e2fb4fb..49aa7e6374905 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -92,7 +92,7 @@ class ScriptParser final : ScriptLexer {
SymbolAssignment *readSymbolAssignment(StringRef name);
ByteCommand *readByteCommand(StringRef tok);
std::array<uint8_t, 4> readFill();
- bool readSectionDirective(OutputSection *cmd, StringRef tok2);
+ bool readSectionDirective(OutputSection *cmd, StringRef tok);
void readSectionAddressType(OutputSection *cmd);
OutputDesc *readOverlaySectionDescription();
OutputDesc *readOutputSectionDescription(StringRef outSec);
@@ -873,14 +873,11 @@ constexpr std::pair<const char *, unsigned> typeMap[] = {
// Tries to read the special directive for an output section definition which
// can be one of following: "(NOLOAD)", "(COPY)", "(INFO)", "(OVERLAY)", and
// "(TYPE=<value>)".
-// Tok1 and Tok2 are next 2 tokens peeked. See comment for
-// readSectionAddressType below.
-bool ScriptParser::readSectionDirective(OutputSection *cmd, StringRef tok2) {
- if (tok2 != "NOLOAD" && tok2 != "COPY" && tok2 != "INFO" &&
- tok2 != "OVERLAY" && tok2 != "TYPE")
+bool ScriptParser::readSectionDirective(OutputSection *cmd, StringRef tok) {
+ if (tok != "NOLOAD" && tok != "COPY" && tok != "INFO" && tok != "OVERLAY" &&
+ tok != "TYPE")
return false;
- expect("(");
if (consume("NOLOAD")) {
cmd->type = SHT_NOBITS;
cmd->typeIsSet = true;
@@ -919,19 +916,22 @@ bool ScriptParser::readSectionDirective(OutputSection *cmd, StringRef tok2) {
// https://sourceware.org/binutils/docs/ld/Output-Section-Address.html
// https://sourceware.org/binutils/docs/ld/Output-Section-Type.html
void ScriptParser::readSectionAddressType(OutputSection *cmd) {
- if (peek() == "(") {
+ if (consume("(")) {
// Temporarily set inExpr to support TYPE=<value> without spaces.
SaveAndRestore saved(inExpr, true);
- if (readSectionDirective(cmd, peek2()))
+ if (readSectionDirective(cmd, peek()))
return;
+ cmd->addrExpr = readExpr();
+ expect(")");
+ } else {
+ cmd->addrExpr = readExpr();
}
- cmd->addrExpr = readExpr();
- if (peek() == "(") {
+ if (consume("(")) {
SaveAndRestore saved(inExpr, true);
- StringRef tok2 = peek2();
- if (!readSectionDirective(cmd, tok2))
- setError("unknown section directive: " + tok2);
+ StringRef tok = peek();
+ if (!readSectionDirective(cmd, tok))
+ setError("unknown section directive: " + tok);
}
}
More information about the llvm-commits
mailing list