Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -741,8 +741,7 @@ } void ScriptParser::readLocationCounterValue() { - expect("."); - expect("="); + expect({".", "="}); std::vector Expr = readSectionsCommandExpr(); if (Expr.empty()) error("error in location counter expression"); @@ -753,8 +752,7 @@ void ScriptParser::readOutputSectionDescription(StringRef OutSec) { OutputSectionCommand *Cmd = new OutputSectionCommand(OutSec); Opt.Commands.emplace_back(Cmd); - expect(":"); - expect("{"); + expect({":", "{"}); while (!Error && !skip("}")) { StringRef Tok = next(); @@ -765,9 +763,7 @@ while (!Error && !skip(")")) InCmd->Patterns.push_back(next()); } else if (Tok == "KEEP") { - expect("("); - expect("*"); - expect("("); + expect({"(", "*", "("}); auto *InCmd = new InputSectionDescription(); Cmd->Commands.emplace_back(InCmd); while (!Error && !skip(")")) { Index: ELF/ScriptParser.h =================================================================== --- ELF/ScriptParser.h +++ ELF/ScriptParser.h @@ -33,6 +33,7 @@ StringRef peek(); bool skip(StringRef Tok); void expect(StringRef Expect); + void expect(ArrayRef Expect); size_t getPos(); void printErrorPos(); Index: ELF/ScriptParser.cpp =================================================================== --- ELF/ScriptParser.cpp +++ ELF/ScriptParser.cpp @@ -14,6 +14,7 @@ #include "ScriptParser.h" #include "Error.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/Twine.h" using namespace llvm; @@ -153,6 +154,11 @@ setError(Expect + " expected, but got " + Tok); } +void ScriptParserBase::expect(ArrayRef Expect) { + for (StringRef Tok : Expect) + expect(Tok); +} + // Returns the current line number. size_t ScriptParserBase::getPos() { if (Pos == 0) Index: ELF/SymbolListFile.cpp =================================================================== --- ELF/SymbolListFile.cpp +++ ELF/SymbolListFile.cpp @@ -103,23 +103,20 @@ void VersionScriptParser::parseLocal() { Config->DefaultSymbolVersion = VER_NDX_LOCAL; - expect("*"); - expect(";"); + expect({"*", ";"}); } void VersionScriptParser::parseExtern(std::vector *Globals) { - expect("C++"); - expect("{"); + expect({ "C++", "{" }); for (;;) { if (peek() == "}" || Error) break; - Globals->push_back({next(), true}); + Globals->push_back({ next(), true }); expect(";"); } - expect("}"); - expect(";"); + expect({"}", ";"}); } void VersionScriptParser::parseGlobal(StringRef VerStr) {