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

Side by Side Diff: tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp

Issue 2608443002: Blacklisting renaming of "hash" in case of static methods and functions. (Closed)
Patch Set: Making IsBlacklistedMethodName a free function again. Created 3 years, 11 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 | « no previous file | tools/clang/rewrite_to_chrome_style/tests/methods-expected.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 // Changes Blink-style names to Chrome-style names. Currently transforms: 5 // Changes Blink-style names to Chrome-style names. Currently transforms:
6 // fields: 6 // fields:
7 // int m_operationCount => int operation_count_ 7 // int m_operationCount => int operation_count_
8 // variables (including parameters): 8 // variables (including parameters):
9 // int mySuperVariable => int my_super_variable 9 // int mySuperVariable => int my_super_variable
10 // constants: 10 // constants:
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 if (decl.getParent()->getQualifiedNameAsString() == class_name) 200 if (decl.getParent()->getQualifiedNameAsString() == class_name)
201 return true; 201 return true;
202 for (auto it = decl.begin_overridden_methods(); 202 for (auto it = decl.begin_overridden_methods();
203 it != decl.end_overridden_methods(); ++it) { 203 it != decl.end_overridden_methods(); ++it) {
204 if (IsMethodOverrideOf(**it, class_name)) 204 if (IsMethodOverrideOf(**it, class_name))
205 return true; 205 return true;
206 } 206 }
207 return false; 207 return false;
208 } 208 }
209 209
210 bool IsBlacklistedFunction(const clang::FunctionDecl& decl) { 210 bool IsBlacklistedFunctionName(llvm::StringRef name) {
211 // swap() functions should match the signature of std::swap for ADL tricks. 211 // https://crbug.com/677166: Have to avoid renaming |hash| -> |Hash| to avoid
212 return decl.getName() == "swap"; 212 // colliding with a struct already named |Hash|.
213 return name == "hash";
213 } 214 }
214 215
215 bool IsBlacklistedMethodName(llvm::StringRef name) { 216 bool IsBlacklistedFreeFunctionName(llvm::StringRef name) {
217 // swap() functions should match the signature of std::swap for ADL tricks.
218 return name == "swap";
219 }
220
221 bool IsBlacklistedInstanceMethodName(llvm::StringRef name) {
216 static const char* kBlacklistedNames[] = { 222 static const char* kBlacklistedNames[] = {
217 "hash", 223 // We should avoid renaming the method names listed below, because
218 "lock", "unlock", "try_lock", 224 // 1. They are used in templated code (e.g. in <algorithms>)
219 "begin", "end", "rbegin", "rend", 225 // 2. They (begin+end) are used in range-based for syntax sugar
226 // - for (auto x : foo) { ... } // <- foo.begin() will be called.
227 "begin", "end", "rbegin", "rend", "lock", "unlock", "try_lock",
220 }; 228 };
221 for (const auto& b : kBlacklistedNames) { 229 for (const auto& b : kBlacklistedNames) {
222 if (name == b) 230 if (name == b)
223 return true; 231 return true;
224 } 232 }
225 return false; 233 return false;
226 } 234 }
227 235
236 bool IsBlacklistedMethodName(llvm::StringRef name) {
237 return IsBlacklistedFunctionName(name) ||
238 IsBlacklistedInstanceMethodName(name);
239 }
240
241 bool IsBlacklistedFunction(const clang::FunctionDecl& decl) {
242 clang::StringRef name = decl.getName();
243 return IsBlacklistedFunctionName(name) || IsBlacklistedFreeFunctionName(name);
244 }
245
228 bool IsBlacklistedMethod(const clang::CXXMethodDecl& decl) { 246 bool IsBlacklistedMethod(const clang::CXXMethodDecl& decl) {
247 clang::StringRef name = decl.getName();
248 if (IsBlacklistedFunctionName(name))
249 return true;
250
251 // Remaining cases are only applicable to instance methods.
229 if (decl.isStatic()) 252 if (decl.isStatic())
230 return false; 253 return false;
231 254
232 clang::StringRef name = decl.getName(); 255 if (IsBlacklistedInstanceMethodName(name))
233 if (IsBlacklistedMethodName(name)) 256 return true;
234 return true;
235 257
236 // Subclasses of InspectorAgent will subclass "disable()" from both blink and 258 // Subclasses of InspectorAgent will subclass "disable()" from both blink and
237 // from gen/, which is problematic, but DevTools folks don't want to rename 259 // from gen/, which is problematic, but DevTools folks don't want to rename
238 // it or split this up. So don't rename it at all. 260 // it or split this up. So don't rename it at all.
239 if (name.equals("disable") && 261 if (name.equals("disable") &&
240 IsMethodOverrideOf(decl, "blink::InspectorAgent")) 262 IsMethodOverrideOf(decl, "blink::InspectorAgent"))
241 return true; 263 return true;
242 264
243 return false; 265 return false;
244 } 266 }
(...skipping 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 for (const auto& r : replacements) { 1382 for (const auto& r : replacements) {
1361 std::string replacement_text = r.getReplacementText().str(); 1383 std::string replacement_text = r.getReplacementText().str();
1362 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); 1384 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0');
1363 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() 1385 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset()
1364 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; 1386 << ":::" << r.getLength() << ":::" << replacement_text << "\n";
1365 } 1387 }
1366 llvm::outs() << "==== END EDITS ====\n"; 1388 llvm::outs() << "==== END EDITS ====\n";
1367 1389
1368 return 0; 1390 return 0;
1369 } 1391 }
OLDNEW
« no previous file with comments | « no previous file | tools/clang/rewrite_to_chrome_style/tests/methods-expected.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698