/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/include/llvm/Support/FormatVariadicDetails.h
Line | Count | Source |
1 | | //===- FormatVariadicDetails.h - Helpers for FormatVariadic.h ----*- C++-*-===// |
2 | | // |
3 | | // The LLVM Compiler Infrastructure |
4 | | // |
5 | | // This file is distributed under the University of Illinois Open Source |
6 | | // License. See LICENSE.TXT for details. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | |
10 | | #ifndef LLVM_SUPPORT_FORMATVARIADIC_DETAILS_H |
11 | | #define LLVM_SUPPORT_FORMATVARIADIC_DETAILS_H |
12 | | |
13 | | #include "llvm/ADT/StringRef.h" |
14 | | #include "llvm/Support/raw_ostream.h" |
15 | | |
16 | | #include <type_traits> |
17 | | |
18 | | namespace llvm { |
19 | | template <typename T, typename Enable = void> struct format_provider {}; |
20 | | |
21 | | namespace detail { |
22 | | class format_adapter { |
23 | | protected: |
24 | 52.9k | virtual ~format_adapter() {} |
25 | | |
26 | | public: |
27 | | virtual void format(raw_ostream &S, StringRef Options) = 0; |
28 | | }; |
29 | | |
30 | | template <typename T> class provider_format_adapter : public format_adapter { |
31 | | T Item; |
32 | | |
33 | | public: |
34 | 5.45k | explicit provider_format_adapter(T &&Item) : Item(Item) {} llvm::detail::provider_format_adapter<unsigned int>::provider_format_adapter(unsigned int&&) Line | Count | Source | 34 | 3.08k | explicit provider_format_adapter(T &&Item) : Item(Item) {} |
llvm::detail::provider_format_adapter<llvm::codeview::GUID const&>::provider_format_adapter(llvm::codeview::GUID const&) Line | Count | Source | 34 | 2 | explicit provider_format_adapter(T &&Item) : Item(Item) {} |
llvm::detail::provider_format_adapter<llvm::StringRef&>::provider_format_adapter(llvm::StringRef&) Line | Count | Source | 34 | 2.36k | explicit provider_format_adapter(T &&Item) : Item(Item) {} |
|
35 | | |
36 | 5.45k | void format(llvm::raw_ostream &S, StringRef Options) override { |
37 | 5.45k | format_provider<typename std::decay<T>::type>::format(Item, S, Options); |
38 | 5.45k | } llvm::detail::provider_format_adapter<llvm::codeview::GUID const&>::format(llvm::raw_ostream&, llvm::StringRef) Line | Count | Source | 36 | 2 | void format(llvm::raw_ostream &S, StringRef Options) override { | 37 | 2 | format_provider<typename std::decay<T>::type>::format(Item, S, Options); | 38 | 2 | } |
llvm::detail::provider_format_adapter<unsigned int>::format(llvm::raw_ostream&, llvm::StringRef) Line | Count | Source | 36 | 3.08k | void format(llvm::raw_ostream &S, StringRef Options) override { | 37 | 3.08k | format_provider<typename std::decay<T>::type>::format(Item, S, Options); | 38 | 3.08k | } |
llvm::detail::provider_format_adapter<llvm::StringRef&>::format(llvm::raw_ostream&, llvm::StringRef) Line | Count | Source | 36 | 2.36k | void format(llvm::raw_ostream &S, StringRef Options) override { | 37 | 2.36k | format_provider<typename std::decay<T>::type>::format(Item, S, Options); | 38 | 2.36k | } |
|
39 | | }; |
40 | | |
41 | | template <typename T> class missing_format_adapter; |
42 | | |
43 | | // Test if format_provider<T> is defined on T and contains a member function |
44 | | // with the signature: |
45 | | // static void format(const T&, raw_stream &, StringRef); |
46 | | // |
47 | | template <class T> class has_FormatProvider { |
48 | | public: |
49 | | using Decayed = typename std::decay<T>::type; |
50 | | typedef void (*Signature_format)(const Decayed &, llvm::raw_ostream &, |
51 | | StringRef); |
52 | | |
53 | | template <typename U> |
54 | | static char test(SameType<Signature_format, &U::format> *); |
55 | | |
56 | | template <typename U> static double test(...); |
57 | | |
58 | | static bool const value = |
59 | | (sizeof(test<llvm::format_provider<Decayed>>(nullptr)) == 1); |
60 | | }; |
61 | | |
62 | | // Simple template that decides whether a type T should use the member-function |
63 | | // based format() invocation. |
64 | | template <typename T> |
65 | | struct uses_format_member |
66 | | : public std::integral_constant< |
67 | | bool, |
68 | | std::is_base_of<format_adapter, |
69 | | typename std::remove_reference<T>::type>::value> {}; |
70 | | |
71 | | // Simple template that decides whether a type T should use the format_provider |
72 | | // based format() invocation. The member function takes priority, so this test |
73 | | // will only be true if there is not ALSO a format member. |
74 | | template <typename T> |
75 | | struct uses_format_provider |
76 | | : public std::integral_constant< |
77 | | bool, !uses_format_member<T>::value && has_FormatProvider<T>::value> { |
78 | | }; |
79 | | |
80 | | // Simple template that decides whether a type T has neither a member-function |
81 | | // nor format_provider based implementation that it can use. Mostly used so |
82 | | // that the compiler spits out a nice diagnostic when a type with no format |
83 | | // implementation can be located. |
84 | | template <typename T> |
85 | | struct uses_missing_provider |
86 | | : public std::integral_constant<bool, |
87 | | !uses_format_member<T>::value && |
88 | | !uses_format_provider<T>::value> {}; |
89 | | |
90 | | template <typename T> |
91 | | typename std::enable_if<uses_format_member<T>::value, T>::type |
92 | | build_format_adapter(T &&Item) { |
93 | | return std::forward<T>(Item); |
94 | | } |
95 | | |
96 | | template <typename T> |
97 | | typename std::enable_if<uses_format_provider<T>::value, |
98 | | provider_format_adapter<T>>::type |
99 | 5.45k | build_format_adapter(T &&Item) { |
100 | 5.45k | return provider_format_adapter<T>(std::forward<T>(Item)); |
101 | 5.45k | } std::__1::enable_if<uses_format_provider<unsigned int>::value, llvm::detail::provider_format_adapter<unsigned int> >::type llvm::detail::build_format_adapter<unsigned int>(unsigned int&&) Line | Count | Source | 99 | 3.08k | build_format_adapter(T &&Item) { | 100 | 3.08k | return provider_format_adapter<T>(std::forward<T>(Item)); | 101 | 3.08k | } |
std::__1::enable_if<uses_format_provider<llvm::StringRef&>::value, llvm::detail::provider_format_adapter<llvm::StringRef&> >::type llvm::detail::build_format_adapter<llvm::StringRef&>(llvm::StringRef&&&) Line | Count | Source | 99 | 2.36k | build_format_adapter(T &&Item) { | 100 | 2.36k | return provider_format_adapter<T>(std::forward<T>(Item)); | 101 | 2.36k | } |
std::__1::enable_if<uses_format_provider<llvm::codeview::GUID const&>::value, llvm::detail::provider_format_adapter<llvm::codeview::GUID const&> >::type llvm::detail::build_format_adapter<llvm::codeview::GUID const&>(llvm::codeview::GUID const&&&) Line | Count | Source | 99 | 2 | build_format_adapter(T &&Item) { | 100 | 2 | return provider_format_adapter<T>(std::forward<T>(Item)); | 101 | 2 | } |
|
102 | | |
103 | | template <typename T> |
104 | | typename std::enable_if<uses_missing_provider<T>::value, |
105 | | missing_format_adapter<T>>::type |
106 | | build_format_adapter(T &&Item) { |
107 | | return missing_format_adapter<T>(); |
108 | | } |
109 | | } |
110 | | } |
111 | | |
112 | | #endif |