diff options
author | Justin Bogner <mail@justinbogner.com> | 2016-10-17 06:21:13 +0000 |
---|---|---|
committer | Justin Bogner <mail@justinbogner.com> | 2016-10-17 06:21:13 +0000 |
commit | 5424e7c7dc504a5cb12cb71a8b6330471f4e0da6 (patch) | |
tree | a641246830f2440f6db9b7dea37e183944a1084e | |
parent | 812101d86204a5fa8a2499cc541d1a1185100996 (diff) | |
download | bcm5719-llvm-5424e7c7dc504a5cb12cb71a8b6330471f4e0da6.tar.gz bcm5719-llvm-5424e7c7dc504a5cb12cb71a8b6330471f4e0da6.zip |
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.
llvm-svn: 284363
-rw-r--r-- | lld/ELF/LinkerScript.cpp | 18 | ||||
-rw-r--r-- | lld/ELF/ScriptParser.cpp | 10 | ||||
-rw-r--r-- | lld/ELF/ScriptParser.h | 1 |
3 files changed, 20 insertions, 9 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 54d5a9b13e2..061f7f83a40 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -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, int MinPrec) { 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::readVersionDeclaration(StringRef VerStr) { // 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 VerStr) { StringRef Cur = peek(); if (Cur == "}" || Cur == "local:" || Error) return; - next(); + skip(); Globals->push_back({unquote(Cur), false, hasWildcard(Cur)}); expect(";"); } diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp index 97d68d92318..63c8d5a4ffc 100644 --- a/lld/ELF/ScriptParser.cpp +++ b/lld/ELF/ScriptParser.cpp @@ -150,6 +150,16 @@ bool ScriptParserBase::skip(StringRef Tok) { return true; } +void ScriptParserBase::skip() { + if (Error) + return; + if (atEOF()) { + setError("unexpected EOF"); + return; + } + ++Pos; +} + void ScriptParserBase::expect(StringRef Expect) { if (Error) return; diff --git a/lld/ELF/ScriptParser.h b/lld/ELF/ScriptParser.h index 1acd19dc453..64a91d42e23 100644 --- a/lld/ELF/ScriptParser.h +++ b/lld/ELF/ScriptParser.h @@ -29,6 +29,7 @@ protected: bool atEOF(); StringRef next(); StringRef peek(); + void skip(); bool skip(StringRef Tok); void expect(StringRef Expect); |