[lld] r275672 - Use ScriptParserBase::skip() instead of peek() and next().
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 15 20:45:59 PDT 2016
Author: ruiu
Date: Fri Jul 15 22:45:59 2016
New Revision: 275672
URL: http://llvm.org/viewvc/llvm-project?rev=275672&view=rev
Log:
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().
Modified:
lld/trunk/ELF/SymbolListFile.cpp
Modified: lld/trunk/ELF/SymbolListFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolListFile.cpp?rev=275672&r1=275671&r2=275672&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolListFile.cpp (original)
+++ lld/trunk/ELF/SymbolListFile.cpp Fri Jul 15 22:45:59 2016
@@ -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(StringRe
}
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(S
}
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<StringRef> *Globals;
if (Version.empty())
Globals = &Config->VersionScriptGlobals;
@@ -144,7 +128,7 @@ void VersionScriptParser::parseVersionSy
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);
}
}
More information about the llvm-commits
mailing list