[clang-tools-extra] r348840 - [clang-tidy] NFC Consolidate test absl::Time implementation

Jonas Toth via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 11 04:42:17 PST 2018


Author: jonastoth
Date: Tue Dec 11 04:42:17 2018
New Revision: 348840

URL: http://llvm.org/viewvc/llvm-project?rev=348840&view=rev
Log:
[clang-tidy] NFC Consolidate test absl::Time implementation

Summary: Several tests re-implement these same prototypes (differently), so we can put them in a common location.

Patch by hwright.

Reviewers: JonasToth

Reviewed By: JonasToth

Tags: #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D55540

Added:
    clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/
    clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/time.h
Modified:
    clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp
    clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-float.cpp
    clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-scale.cpp
    clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp

Added: clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/time.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/time.h?rev=348840&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/time.h (added)
+++ clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/time.h Tue Dec 11 04:42:17 2018
@@ -0,0 +1,72 @@
+// Mimic the implementation of absl::Duration
+namespace absl {
+
+using int64_t = long long int;
+
+class Duration {
+public:
+  Duration &operator*=(int64_t r);
+  Duration &operator*=(float r);
+  Duration &operator*=(double r);
+  template <typename T> Duration &operator*=(T r);
+
+  Duration &operator/=(int64_t r);
+  Duration &operator/=(float r);
+  Duration &operator/=(double r);
+  template <typename T> Duration &operator/=(T r);
+};
+
+template <typename T> Duration operator*(Duration lhs, T rhs);
+template <typename T> Duration operator*(T lhs, Duration rhs);
+template <typename T> Duration operator/(Duration lhs, T rhs);
+
+class Time{};
+
+constexpr Duration Nanoseconds(long long);
+constexpr Duration Microseconds(long long);
+constexpr Duration Milliseconds(long long);
+constexpr Duration Seconds(long long);
+constexpr Duration Minutes(long long);
+constexpr Duration Hours(long long);
+
+template <typename T> struct EnableIfFloatImpl {};
+template <> struct EnableIfFloatImpl<float> { typedef int Type; };
+template <> struct EnableIfFloatImpl<double> { typedef int Type; };
+template <> struct EnableIfFloatImpl<long double> { typedef int Type; };
+template <typename T> using EnableIfFloat = typename EnableIfFloatImpl<T>::Type;
+
+template <typename T, EnableIfFloat<T> = 0> Duration Nanoseconds(T n);
+template <typename T, EnableIfFloat<T> = 0> Duration Microseconds(T n);
+template <typename T, EnableIfFloat<T> = 0> Duration Milliseconds(T n);
+template <typename T, EnableIfFloat<T> = 0> Duration Seconds(T n);
+template <typename T, EnableIfFloat<T> = 0> Duration Minutes(T n);
+template <typename T, EnableIfFloat<T> = 0> Duration Hours(T n);
+
+double ToDoubleHours(Duration d);
+double ToDoubleMinutes(Duration d);
+double ToDoubleSeconds(Duration d);
+double ToDoubleMilliseconds(Duration d);
+double ToDoubleMicroseconds(Duration d);
+double ToDoubleNanoseconds(Duration d);
+int64_t ToInt64Hours(Duration d);
+int64_t ToInt64Minutes(Duration d);
+int64_t ToInt64Seconds(Duration d);
+int64_t ToInt64Milliseconds(Duration d);
+int64_t ToInt64Microseconds(Duration d);
+int64_t ToInt64Nanoseconds(Duration d);
+
+// Relational Operators
+constexpr bool operator<(Duration lhs, Duration rhs);
+constexpr bool operator>(Duration lhs, Duration rhs);
+constexpr bool operator>=(Duration lhs, Duration rhs);
+constexpr bool operator<=(Duration lhs, Duration rhs);
+constexpr bool operator==(Duration lhs, Duration rhs);
+constexpr bool operator!=(Duration lhs, Duration rhs);
+
+// Additive Operators
+inline Time operator+(Time lhs, Duration rhs);
+inline Time operator+(Duration lhs, Time rhs);
+inline Time operator-(Time lhs, Duration rhs);
+inline Duration operator-(Time lhs, Time rhs);
+
+}  // namespace absl

Modified: clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp?rev=348840&r1=348839&r2=348840&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp Tue Dec 11 04:42:17 2018
@@ -1,62 +1,6 @@
-// RUN: %check_clang_tidy %s abseil-duration-comparison %t
+// RUN: %check_clang_tidy %s abseil-duration-comparison %t -- -- -I%S/Inputs
 
-// Mimic the implementation of absl::Duration
-namespace absl {
-
-class Duration {};
-class Time{};
-
-Duration Nanoseconds(long long);
-Duration Microseconds(long long);
-Duration Milliseconds(long long);
-Duration Seconds(long long);
-Duration Minutes(long long);
-Duration Hours(long long);
-
-#define GENERATE_DURATION_FACTORY_OVERLOADS(NAME) \
-  Duration NAME(float n);                         \
-  Duration NAME(double n);                        \
-  template <typename T>                           \
-  Duration NAME(T n);
-
-GENERATE_DURATION_FACTORY_OVERLOADS(Nanoseconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Microseconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Milliseconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Seconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Minutes);
-GENERATE_DURATION_FACTORY_OVERLOADS(Hours);
-#undef GENERATE_DURATION_FACTORY_OVERLOADS
-
-using int64_t = long long int;
-
-double ToDoubleHours(Duration d);
-double ToDoubleMinutes(Duration d);
-double ToDoubleSeconds(Duration d);
-double ToDoubleMilliseconds(Duration d);
-double ToDoubleMicroseconds(Duration d);
-double ToDoubleNanoseconds(Duration d);
-int64_t ToInt64Hours(Duration d);
-int64_t ToInt64Minutes(Duration d);
-int64_t ToInt64Seconds(Duration d);
-int64_t ToInt64Milliseconds(Duration d);
-int64_t ToInt64Microseconds(Duration d);
-int64_t ToInt64Nanoseconds(Duration d);
-
-// Relational Operators
-constexpr bool operator<(Duration lhs, Duration rhs);
-constexpr bool operator>(Duration lhs, Duration rhs);
-constexpr bool operator>=(Duration lhs, Duration rhs);
-constexpr bool operator<=(Duration lhs, Duration rhs);
-constexpr bool operator==(Duration lhs, Duration rhs);
-constexpr bool operator!=(Duration lhs, Duration rhs);
-
-// Additive Operators
-inline Time operator+(Time lhs, Duration rhs);
-inline Time operator+(Duration lhs, Time rhs);
-inline Time operator-(Time lhs, Duration rhs);
-inline Duration operator-(Time lhs, Time rhs);
-
-}  // namespace absl
+#include "absl/time/time.h"
 
 void f() {
   double x;

Modified: clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-float.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-float.cpp?rev=348840&r1=348839&r2=348840&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-float.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-float.cpp Tue Dec 11 04:42:17 2018
@@ -1,32 +1,6 @@
-// RUN: %check_clang_tidy %s abseil-duration-factory-float %t
+// RUN: %check_clang_tidy %s abseil-duration-factory-float %t -- -- -I%S/Inputs
 
-// Mimic the implementation of absl::Duration
-namespace absl {
-
-class Duration {};
-
-Duration Nanoseconds(long long);
-Duration Microseconds(long long);
-Duration Milliseconds(long long);
-Duration Seconds(long long);
-Duration Minutes(long long);
-Duration Hours(long long);
-
-#define GENERATE_DURATION_FACTORY_OVERLOADS(NAME) \
-  Duration NAME(float n);                         \
-  Duration NAME(double n);                        \
-  template <typename T>                           \
-  Duration NAME(T n);
-
-GENERATE_DURATION_FACTORY_OVERLOADS(Nanoseconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Microseconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Milliseconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Seconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Minutes);
-GENERATE_DURATION_FACTORY_OVERLOADS(Hours);
-#undef GENERATE_DURATION_FACTORY_OVERLOADS
-
-}  // namespace absl
+#include "absl/time/time.h"
 
 void ConvertFloatTest() {
   absl::Duration d;

Modified: clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-scale.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-scale.cpp?rev=348840&r1=348839&r2=348840&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-scale.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-scale.cpp Tue Dec 11 04:42:17 2018
@@ -1,32 +1,6 @@
-// RUN: %check_clang_tidy %s abseil-duration-factory-scale %t
+// RUN: %check_clang_tidy %s abseil-duration-factory-scale %t -- -- -I%S/Inputs
 
-// Mimic the implementation of absl::Duration
-namespace absl {
-
-class Duration {};
-
-Duration Nanoseconds(long long);
-Duration Microseconds(long long);
-Duration Milliseconds(long long);
-Duration Seconds(long long);
-Duration Minutes(long long);
-Duration Hours(long long);
-
-#define GENERATE_DURATION_FACTORY_OVERLOADS(NAME) \
-  Duration NAME(float n);                         \
-  Duration NAME(double n);                        \
-  template <typename T>                           \
-  Duration NAME(T n);
-
-GENERATE_DURATION_FACTORY_OVERLOADS(Nanoseconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Microseconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Milliseconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Seconds);
-GENERATE_DURATION_FACTORY_OVERLOADS(Minutes);
-GENERATE_DURATION_FACTORY_OVERLOADS(Hours);
-#undef GENERATE_DURATION_FACTORY_OVERLOADS
-
-}  // namespace absl
+#include "absl/time/time.h"
 
 void ScaleTest() {
   absl::Duration d;

Modified: clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp?rev=348840&r1=348839&r2=348840&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp Tue Dec 11 04:42:17 2018
@@ -1,49 +1,8 @@
-// RUN: %check_clang_tidy %s abseil-upgrade-duration-conversions %t
+// RUN: %check_clang_tidy %s abseil-upgrade-duration-conversions %t -- -- -I%S/Inputs
 
 using int64_t = long long;
 
-// Partial implementation of relevant APIs from
-// https://github.com/abseil/abseil-cpp/blob/master/absl/time/time.h
-namespace absl {
-
-class Duration {
-public:
-  Duration &operator*=(int64_t r);
-  Duration &operator*=(float r);
-  Duration &operator*=(double r);
-  template <typename T> Duration &operator*=(T r);
-
-  Duration &operator/=(int64_t r);
-  Duration &operator/=(float r);
-  Duration &operator/=(double r);
-  template <typename T> Duration &operator/=(T r);
-};
-
-template <typename T> Duration operator*(Duration lhs, T rhs);
-template <typename T> Duration operator*(T lhs, Duration rhs);
-template <typename T> Duration operator/(Duration lhs, T rhs);
-
-constexpr Duration Nanoseconds(int64_t n);
-constexpr Duration Microseconds(int64_t n);
-constexpr Duration Milliseconds(int64_t n);
-constexpr Duration Seconds(int64_t n);
-constexpr Duration Minutes(int64_t n);
-constexpr Duration Hours(int64_t n);
-
-template <typename T> struct EnableIfFloatImpl {};
-template <> struct EnableIfFloatImpl<float> { typedef int Type; };
-template <> struct EnableIfFloatImpl<double> { typedef int Type; };
-template <> struct EnableIfFloatImpl<long double> { typedef int Type; };
-template <typename T> using EnableIfFloat = typename EnableIfFloatImpl<T>::Type;
-
-template <typename T, EnableIfFloat<T> = 0> Duration Nanoseconds(T n);
-template <typename T, EnableIfFloat<T> = 0> Duration Microseconds(T n);
-template <typename T, EnableIfFloat<T> = 0> Duration Milliseconds(T n);
-template <typename T, EnableIfFloat<T> = 0> Duration Seconds(T n);
-template <typename T, EnableIfFloat<T> = 0> Duration Minutes(T n);
-template <typename T, EnableIfFloat<T> = 0> Duration Hours(T n);
-
-} // namespace absl
+#include "absl/time/time.h"
 
 template <typename T> struct ConvertibleTo {
   operator T() const;




More information about the cfe-commits mailing list