diff options
author | Rui Ueyama <ruiu@google.com> | 2016-04-20 20:54:13 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2016-04-20 20:54:13 +0000 |
commit | 6011811beb50d8df9216b9932ab375f7576860de (patch) | |
tree | 870bfa66ce3952c442bc3e48d61c87488da5a85f | |
parent | 62f3726365375131f5116b72ae3a279bfcec8352 (diff) | |
download | bcm5719-llvm-6011811beb50d8df9216b9932ab375f7576860de.tar.gz bcm5719-llvm-6011811beb50d8df9216b9932ab375f7576860de.zip |
Define and use a utility function. NFC.
llvm-svn: 266914
-rw-r--r-- | lld/ELF/LinkerScript.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 0db250c4cca..dd67fdb38ab 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -64,6 +64,20 @@ static StringRef next(ArrayRef<StringRef> &Tokens) { return Tok; } +static bool expect(ArrayRef<StringRef> &Tokens, StringRef S) { + if (Tokens.empty()) { + error(S + " expected"); + return false; + } + StringRef Tok = Tokens.front(); + if (Tok != S) { + error(S + " expected, but got " + Tok); + return false; + } + Tokens = Tokens.slice(1); + return true; +} + static uint64_t parseExpr(ArrayRef<StringRef> &Tokens, uint64_t Dot); // This is a part of the operator-precedence parser to evaluate @@ -75,13 +89,8 @@ static uint64_t parsePrimary(ArrayRef<StringRef> &Tokens, uint64_t Dot) { return Dot; if (Tok == "(") { uint64_t V = parseExpr(Tokens, Dot); - if (Tokens.empty()) { - error(") expected"); - } else { - Tok = next(Tokens); - if (Tok != ")") - error(") expected, but got " + Tok); - } + if (!expect(Tokens, ")")) + return 0; return V; } return getInteger(Tok); |