Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: tools/clang/rewrite_to_chrome_style/tests/template-original.cc

Issue 1838713002: rewrite_to_chrome_style: improve template rewrite handling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert global cherry-pick Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/clang/rewrite_to_chrome_style/tests/template-expected.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 namespace not_blink { 5 namespace not_blink {
6 6
7 void notBlinkFunction(int x) {} 7 void function(int x) {}
8 8
9 class NotBlinkClass { 9 class Class {
10 public: 10 public:
11 void notBlinkMethod() {} 11 void method() {}
12 template <typename T>
13 void methodTemplate(T) {}
14 template <typename T>
15 static void staticMethodTemplate(T) {}
12 }; 16 };
13 17
14 template <typename T> 18 template <typename T>
15 void notBlinkFunctionTemplate(T x) {} 19 void functionTemplate(T x) {}
16 20
17 } // not_blink 21 } // not_blink
18 22
19 namespace blink { 23 namespace blink {
20 24
21 template <typename T, int number> 25 template <typename T, int number>
22 void F() { 26 void F() {
23 // We don't assert on this, and we don't end up considering it a const for 27 // We don't assert on this, and we don't end up considering it a const for
24 // now. 28 // now.
25 const int maybe_a_const = sizeof(T); 29 const int maybe_a_const = sizeof(T);
(...skipping 13 matching lines...) Expand all
39 void f(int x) {} 43 void f(int x) {}
40 44
41 template <typename T, void g(T)> 45 template <typename T, void g(T)>
42 void h(T x) { 46 void h(T x) {
43 g(x); 47 g(x);
44 } 48 }
45 49
46 void test() { 50 void test() {
47 // f should be rewritten. 51 // f should be rewritten.
48 h<int, f>(0); 52 h<int, f>(0);
49 // notBlinkFunction should stay the same. 53 // Non-Blink should stay the same.
50 h<int, not_blink::notBlinkFunction>(1); 54 h<int, not_blink::function>(1);
51 } 55 }
52 56
53 } // namespace test_template_arg_is_function 57 } // namespace test_template_arg_is_function
54 58
55 namespace test_template_arg_is_method { 59 namespace test_template_arg_is_method {
56 60
57 class BlinkClass { 61 class Class {
58 public: 62 public:
59 void method() {} 63 void method() {}
60 }; 64 };
61 65
62 template <typename T, void (T::*g)()> 66 template <typename T, void (T::*g)()>
63 void h(T&& x) { 67 void h(T&& x) {
64 (x.*g)(); 68 (x.*g)();
65 } 69 }
66 70
67 void test() { 71 void test() {
68 // method should be rewritten. 72 // method should be rewritten.
69 h<BlinkClass, &BlinkClass::method>(BlinkClass()); 73 h<Class, &Class::method>(Class());
70 h<not_blink::NotBlinkClass, &not_blink::NotBlinkClass::notBlinkMethod>( 74 // Non-Blink should stay the same.
71 not_blink::NotBlinkClass()); 75 h<not_blink::Class, &not_blink::Class::method>(not_blink::Class());
72 } 76 }
73 77
74 } // namespace test_template_arg_is_method 78 } // namespace test_template_arg_is_method
75 79
76 // Test template arguments that are function templates. 80 namespace test_template_arg_is_function_template {
77 template <typename T, char converter(T)> 81
78 unsigned reallyBadHash(const T* data, unsigned length) { 82 namespace nested {
79 unsigned hash = 1; 83 template <typename T>
80 for (unsigned i = 0; i < length; ++i) { 84 void f(T) {}
81 hash *= converter(data[i]);
82 }
83 return hash;
84 } 85 }
85 86
86 struct StringHasher { 87 template <typename T, void g(T)>
87 static unsigned Hash(const char* data, unsigned length) { 88 void h(T x) {
88 return reallyBadHash<char, brokenFoldCase<char>>(data, length); 89 g(x);
89 } 90 }
90 91
91 private: 92 void test() {
93 // f should be rewritten.
94 h<int, nested::f>(0);
95 // Non-Blink should stay the same.
96 h<int, not_blink::functionTemplate>(1);
97 }
98
99 } // namespace test_template_arg_is_function_template
100
101 namespace test_template_arg_is_method_template_in_non_member_context {
102
103 struct Class {
92 template <typename T> 104 template <typename T>
93 static char brokenFoldCase(T input) { 105 static void f(T) {}
94 return input - ('a' - 'A'); 106 };
107
108 template <typename T, void g(T)>
109 void h(T x) {
110 g(x);
111 }
112
113 void test() {
114 // f should be rewritten.
115 h<int, Class::f>(0);
116 // Non-Blink should stay the same.
117 h<int, not_blink::Class::staticMethodTemplate>(1);
118 }
119
120 } // test_template_arg_is_method_template_in_non_member_context
121
122 namespace test_template_arg_is_method_template_in_member_context {
123
124 struct Class {
125 template <typename T>
126 static void f(T) {}
127 };
128
129 struct Class2 {
130 template <typename T>
131 void f(T x) {
132 // f should be rewritten.
133 Class c;
134 c.f(x);
135 // Non-Blink should stay the same.
136 not_blink::Class c2;
137 c2.method(x);
95 } 138 }
96 }; 139 };
97 140
141 } // namespace test_template_arg_is_method_template_in_member_context
142
98 } // namespace blink 143 } // namespace blink
OLDNEW
« no previous file with comments | « tools/clang/rewrite_to_chrome_style/tests/template-expected.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698