From: Rui Ueyama Date: Sat, 16 Jul 2016 03:45:59 +0000 (+0000) Subject: Use ScriptParserBase::skip() instead of peek() and next(). X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=52654ebb12e4de5d90b005f876f3718d91571480;p=platform%2Fupstream%2Fllvm.git Use ScriptParserBase::skip() instead of peek() and next(). skip(S) consumes a token if the next token is S, so it can be used instead of peek() & next(). llvm-svn: 275672 --- diff --git a/lld/ELF/SymbolListFile.cpp b/lld/ELF/SymbolListFile.cpp index f07b8ee..7ccb321 100644 --- a/lld/ELF/SymbolListFile.cpp +++ b/lld/ELF/SymbolListFile.cpp @@ -28,36 +28,26 @@ using namespace lld::elf; // // { symbol1; symbol2; [...]; symbolN }; // -// Multiple groups can be defined in the same file and they are merged -// in only one definition. +// Multiple groups can be defined in the same file, and they are merged +// into a single group. class DynamicListParser final : public ScriptParserBase { public: DynamicListParser(StringRef S) : ScriptParserBase(S) {} - void run(); - -private: - void readGroup(); }; -// Parse the default group definition using C language symbol name. -void DynamicListParser::readGroup() { - expect("{"); - while (!Error) { - Config->DynamicList.push_back(next()); - expect(";"); - if (peek() == "}") { - next(); - break; +void DynamicListParser::run() { + while (!atEOF()) { + expect("{"); + while (!Error) { + Config->DynamicList.push_back(next()); + expect(";"); + if (skip("}")) + break; } + expect(";"); } - expect(";"); -} - -void DynamicListParser::run() { - while (!atEOF()) - readGroup(); } void elf::parseDynamicList(MemoryBufferRef MB) { @@ -80,8 +70,8 @@ public: private: void parseVersion(StringRef Version); + void parseGlobal(StringRef Version); void parseLocal(); - void parseVersionSymbols(StringRef Version); }; size_t elf::defineSymbolVersion(StringRef Version) { @@ -93,17 +83,12 @@ size_t elf::defineSymbolVersion(StringRef Version) { } void VersionScriptParser::parseVersion(StringRef Version) { - expect("{"); defineSymbolVersion(Version); - if (peek() == "global:") { - next(); - parseVersionSymbols(Version); - } - if (peek() == "local:") - parseLocal(); - else if (peek() != "}") - parseVersionSymbols(Version); + if (skip("global:") || peek() != "local:") + parseGlobal(Version); + if (skip("local:")) + parseLocal(); expect("}"); // Each version may have a parent version. For example, "Ver2" defined as @@ -116,13 +101,12 @@ void VersionScriptParser::parseVersion(StringRef Version) { } void VersionScriptParser::parseLocal() { - expect("local:"); + Config->DefaultSymbolVersion = VER_NDX_LOCAL; expect("*"); expect(";"); - Config->DefaultSymbolVersion = VER_NDX_LOCAL; } -void VersionScriptParser::parseVersionSymbols(StringRef Version) { +void VersionScriptParser::parseGlobal(StringRef Version) { std::vector *Globals; if (Version.empty()) Globals = &Config->VersionScriptGlobals; @@ -144,7 +128,7 @@ void VersionScriptParser::parseVersionSymbols(StringRef Version) { void VersionScriptParser::run() { StringRef Msg = "anonymous version definition is used in " "combination with other version definitions"; - if (peek() == "{") { + if (skip("{")) { parseVersion(""); if (!atEOF()) setError(Msg); @@ -152,11 +136,13 @@ void VersionScriptParser::run() { } while (!atEOF() && !Error) { - if (peek() == "{") { + StringRef Version = next(); + if (Version == "{") { setError(Msg); return; } - parseVersion(next()); + expect("{"); + parseVersion(Version); } }