[pkg-d-commits] [ldc] 46/74: Simplify two overly long if conditions [nfc]

Matthias Klumpp mak at moszumanska.debian.org
Thu Jul 13 20:54:17 UTC 2017


This is an automated email from the git hooks/post-receive script.

mak pushed a commit to annotated tag v1.3.0-beta2
in repository ldc.

commit dbe9196aabe173bf1c2255897a0c0c85b7da3f20
Author: David Nadlinger <code at klickverbot.at>
Date:   Wed May 24 21:32:21 2017 +0100

    Simplify two overly long if conditions [nfc]
---
 gen/toir.cpp | 46 +++++++++++++++++++++++++---------------------
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/gen/toir.cpp b/gen/toir.cpp
index 1dc45ee..e23b731 100644
--- a/gen/toir.cpp
+++ b/gen/toir.cpp
@@ -1680,31 +1680,35 @@ public:
     // passed:
     p->scope() = IRScope(passedbb);
 
-    FuncDeclaration *invdecl;
-    // class invariants
-    if (global.params.useInvariants && condty->ty == Tclass &&
-        !(static_cast<TypeClass *>(condty)->sym->isInterfaceDeclaration()) &&
-        !(static_cast<TypeClass *>(condty)->sym->isCPPclass())) {
+    // class/struct invariants
+    if (!global.params.useInvariants)
+      return;
+    if (condty->ty == Tclass) {
+      const auto sym = static_cast<TypeClass *>(condty)->sym;
+      if (sym->isInterfaceDeclaration() || sym->isCPPclass())
+        return;
+
       Logger::println("calling class invariant");
-      llvm::Function *fn = getRuntimeFunction(
-          e->loc, gIR->module,
-          gABI->mangleFunctionForLLVM("_D9invariant12_d_invariantFC6ObjectZv",
-                                      LINKd)
-              .c_str());
-      LLValue *arg =
+
+      const auto fnMangle = gABI->mangleFunctionForLLVM(
+          "_D9invariant12_d_invariantFC6ObjectZv", LINKd);
+      const auto fn = getRuntimeFunction(e->loc, gIR->module, fnMangle.c_str());
+
+      const auto arg =
           DtoBitCast(DtoRVal(cond), fn->getFunctionType()->getParamType(0));
+
       gIR->CreateCallOrInvoke(fn, arg);
-    }
-    // struct invariants
-    else if (global.params.useInvariants && condty->ty == Tpointer &&
-             condty->nextOf()->ty == Tstruct &&
-             (invdecl =
-                  static_cast<TypeStruct *>(condty->nextOf())->sym->inv) !=
-                 nullptr) {
+    } else if (condty->ty == Tpointer && condty->nextOf()->ty == Tstruct) {
+      const auto invDecl =
+          static_cast<TypeStruct *>(condty->nextOf())->sym->inv;
+      if (!invDecl)
+        return;
+
       Logger::print("calling struct invariant");
-      DtoResolveFunction(invdecl);
-      DFuncValue invfunc(invdecl, DtoCallee(invdecl), DtoRVal(cond));
-      DtoCallFunction(e->loc, nullptr, &invfunc, nullptr);
+
+      DtoResolveFunction(invDecl);
+      DFuncValue invFunc(invDecl, DtoCallee(invDecl), DtoRVal(cond));
+      DtoCallFunction(e->loc, nullptr, &invFunc, nullptr);
     }
   }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git



More information about the pkg-d-commits mailing list