[lld] r266914 - Define and use a utility function. NFC.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 20 13:54:13 PDT 2016


Author: ruiu
Date: Wed Apr 20 15:54:13 2016
New Revision: 266914

URL: http://llvm.org/viewvc/llvm-project?rev=266914&view=rev
Log:
Define and use a utility function. NFC.

Modified:
    lld/trunk/ELF/LinkerScript.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=266914&r1=266913&r2=266914&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed Apr 20 15:54:13 2016
@@ -64,6 +64,20 @@ static StringRef next(ArrayRef<StringRef
   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<St
     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);




More information about the llvm-commits mailing list