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 @@
//
// { 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;
- }
- }
- expect(";");
-}
-
void DynamicListParser::run() {
- while (!atEOF())
- readGroup();
+ while (!atEOF()) {
+ expect("{");
+ while (!Error) {
+ Config->DynamicList.push_back(next());
+ expect(";");
+ if (skip("}"))
+ break;
+ }
+ expect(";");
+ }
}
void elf::parseDynamicList(MemoryBufferRef MB) {
@@ -80,8 +70,8 @@
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 @@
}
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::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::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 @@
}
while (!atEOF() && !Error) {
- if (peek() == "{") {
+ StringRef Version = next();
+ if (Version == "{") {
setError(Msg);
return;
}
- parseVersion(next());
+ expect("{");
+ parseVersion(Version);
}
}