[PATCH] D19332: [ELF] - implemented ternary operator for linkerscript expressions

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 20 14:00:30 PDT 2016


ruiu added inline comments.

================
Comment at: ELF/LinkerScript.cpp:94-104
@@ +93,13 @@
+                             uint64_t Dot) {
+  next(Tokens);
+
+  uint64_t V1 = parsePrimary(Tokens, Dot);
+  V1 = parseExpr(V1, 0, Tokens, Dot);
+  if (Tokens.empty() || next(Tokens) != ":")
+    error("incomplete ternary operator expression");
+
+  uint64_t V2 = parsePrimary(Tokens, Dot);
+  V2 = parseExpr(V2, 0, Tokens, Dot);
+
+  return Cond ? V1 : V2;
+}
----------------
Please sync after r266912. I defined `expect` and redefined `readExpr`. Now you can write this as

  next(Tokens);
  uint64_t V = parseExpr(Tokens, Dot);
  if (expect(Tokens, ":")
    return 0;
  uint64_t W = parseExpr(Tokens, Dot);
  return Cond ? V : W;


http://reviews.llvm.org/D19332





More information about the llvm-commits mailing list