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
This commit is contained in:
parent
8093437f2e
commit
52654ebb12
|
@ -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;
|
||||
}
|
||||
}
|
||||
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 @@ 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<StringRef> *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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue