From 601ba8c58362dc09c3ff36d88478a2fa098b88fe Mon Sep 17 00:00:00 2001 From: Tim Shen Date: Fri, 27 Jan 2017 02:11:07 +0000 Subject: [APFloat] Reduce some dispatch boilerplates. NFC. Summary: This is an attempt to reduce the verbose manual dispatching code in APFloat. This doesn't handle multiple dispatch on single discriminator (e.g. APFloat::add(const APFloat&)), nor handles multiple dispatch on multiple discriminators (e.g. APFloat::convert()). Reviewers: hfinkel, echristo, jlebar Subscribers: mehdi_amini, llvm-commits Differential Revision: https://reviews.llvm.org/D29161 llvm-svn: 293255 --- llvm/lib/Support/APFloat.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Support/APFloat.cpp') diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp index 1349eb6ac0b..2fe3b070023 100644 --- a/llvm/lib/Support/APFloat.cpp +++ b/llvm/lib/Support/APFloat.cpp @@ -26,6 +26,15 @@ #include #include +#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL) \ + do { \ + if (usesLayout(getSemantics())) \ + return U.IEEE.METHOD_CALL; \ + if (usesLayout(getSemantics())) \ + return U.Double.METHOD_CALL; \ + llvm_unreachable("Unexpected semantics"); \ + } while (false) + using namespace llvm; /// A macro used to combine two fcCategory enums into one key which can be used @@ -4418,11 +4427,7 @@ APFloat::Storage::Storage(IEEEFloat F, const fltSemantics &Semantics) { } APFloat::opStatus APFloat::convertFromString(StringRef Str, roundingMode RM) { - if (usesLayout(getSemantics())) - return U.IEEE.convertFromString(Str, RM); - if (usesLayout(getSemantics())) - return U.Double.convertFromString(Str, RM); - llvm_unreachable("Unexpected semantics"); + APFLOAT_DISPATCH_ON_SEMANTICS(convertFromString(Str, RM)); } hash_code hash_value(const APFloat &Arg) { @@ -4512,3 +4517,5 @@ APFloat::opStatus APFloat::convertToInteger(APSInt &result, } } // End llvm namespace + +#undef APFLOAT_DISPATCH_ON_SEMANTICS -- cgit v1.2.3