[lld] r284363 - ELF: Add a skip() overload to ignore any token
Justin Bogner via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 16 23:21:14 PDT 2016
Author: bogner
Date: Mon Oct 17 01:21:13 2016
New Revision: 284363
URL: http://llvm.org/viewvc/llvm-project?rev=284363&view=rev
Log:
ELF: Add a skip() overload to ignore any token
Most functions that return StringRef should check their return values,
so I'm planning on marking StringRef [[nodiscard]]. This requires
splitting up functions like next() that are sometimes just used for
side effects.
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/ScriptParser.cpp
lld/trunk/ELF/ScriptParser.h
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=284363&r1=284362&r2=284363&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Mon Oct 17 01:21:13 2016
@@ -1106,14 +1106,14 @@ void ScriptParser::readOutput() {
void ScriptParser::readOutputArch() {
// Error checking only for now.
expect("(");
- next();
+ skip();
expect(")");
}
void ScriptParser::readOutputFormat() {
// Error checking only for now.
expect("(");
- next();
+ skip();
StringRef Tok = next();
if (Tok == ")")
return;
@@ -1121,9 +1121,9 @@ void ScriptParser::readOutputFormat() {
setError("unexpected token: " + Tok);
return;
}
- next();
+ skip();
expect(",");
- next();
+ skip();
expect(")");
}
@@ -1495,7 +1495,7 @@ Expr ScriptParser::readExpr1(Expr Lhs, i
return readTernary(Lhs);
if (precedence(Op1) < MinPrec)
break;
- next();
+ skip();
Expr Rhs = readPrimary();
// Evaluate the remaining part of the expression first if the
@@ -1623,7 +1623,7 @@ Expr ScriptParser::readPrimary() {
}
if (Tok == "SEGMENT_START") {
expect("(");
- next();
+ skip();
expect(",");
Expr E = readExpr();
expect(")");
@@ -1678,7 +1678,7 @@ Expr ScriptParser::readPrimary() {
}
Expr ScriptParser::readTernary(Expr Cond) {
- next();
+ skip();
Expr L = readExpr();
expect(":");
Expr R = readExpr();
@@ -1748,7 +1748,7 @@ void ScriptParser::readVersionDeclaratio
// version hierarchy is, probably against your instinct, purely for human; the
// runtime doesn't care about them at all. In LLD, we simply skip the token.
if (!VerStr.empty() && peek() != ";")
- next();
+ skip();
expect(";");
}
@@ -1788,7 +1788,7 @@ void ScriptParser::readGlobal(StringRef
StringRef Cur = peek();
if (Cur == "}" || Cur == "local:" || Error)
return;
- next();
+ skip();
Globals->push_back({unquote(Cur), false, hasWildcard(Cur)});
expect(";");
}
Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=284363&r1=284362&r2=284363&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Mon Oct 17 01:21:13 2016
@@ -150,6 +150,16 @@ bool ScriptParserBase::skip(StringRef To
return true;
}
+void ScriptParserBase::skip() {
+ if (Error)
+ return;
+ if (atEOF()) {
+ setError("unexpected EOF");
+ return;
+ }
+ ++Pos;
+}
+
void ScriptParserBase::expect(StringRef Expect) {
if (Error)
return;
Modified: lld/trunk/ELF/ScriptParser.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.h?rev=284363&r1=284362&r2=284363&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.h (original)
+++ lld/trunk/ELF/ScriptParser.h Mon Oct 17 01:21:13 2016
@@ -29,6 +29,7 @@ protected:
bool atEOF();
StringRef next();
StringRef peek();
+ void skip();
bool skip(StringRef Tok);
void expect(StringRef Expect);
More information about the llvm-commits
mailing list