-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[ELF] Delete peek2 in Lexer #99790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ELF] Delete peek2 in Lexer #99790
Conversation
Thanks to Fangrui's change llvm@28045ce so peek2 can be elimnated easily.
@llvm/pr-subscribers-lld @llvm/pr-subscribers-lld-elf Author: Hongyu Chen (yugier) ChangesThanks to Fangrui's change Full diff: https://github.com/llvm/llvm-project/pull/99790.diff 3 Files Affected:
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);
}
}
|
Capitalize "delete" |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/66/builds/1897 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/139/builds/1529 Here is the relevant piece of the build log for the reference:
|
Summary: Thanks to Fangrui's change 28045ce so peek2 can be removed. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251424
Thanks to Fangrui's change
28045ce
so peek2 can be removed.