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

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

Issue 2601063002: Blacklisting of method names coming from std library. (Closed)
Patch Set: Also blacklisting "insert". 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/function-templates-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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 IsBlacklistedFunctionName(llvm::StringRef name) { 210 bool IsBlacklistedFunctionName(llvm::StringRef name) {
211 // https://crbug.com/672902: Method names with an underscore are typically
212 // mimicked after std library / are typically not originating from Blink.
213 // Do not rewrite such names (like push_back, emplace_back, etc.).
214 if (name.find('_') != llvm::StringRef::npos)
215 return true;
216
211 // https://crbug.com/677166: Have to avoid renaming |hash| -> |Hash| to avoid 217 // https://crbug.com/677166: Have to avoid renaming |hash| -> |Hash| to avoid
212 // colliding with a struct already named |Hash|. 218 // colliding with a struct already named |Hash|.
213 return name == "hash"; 219 return name == "hash";
214 } 220 }
215 221
216 bool IsBlacklistedFreeFunctionName(llvm::StringRef name) { 222 bool IsBlacklistedFreeFunctionName(llvm::StringRef name) {
217 // swap() functions should match the signature of std::swap for ADL tricks. 223 // swap() functions should match the signature of std::swap for ADL tricks.
218 return name == "swap"; 224 return name == "swap";
219 } 225 }
220 226
221 bool IsBlacklistedInstanceMethodName(llvm::StringRef name) { 227 bool IsBlacklistedInstanceMethodName(llvm::StringRef name) {
222 static const char* kBlacklistedNames[] = { 228 static const char* kBlacklistedNames[] = {
223 // We should avoid renaming the method names listed below, because 229 // We should avoid renaming the method names listed below, because
224 // 1. They are used in templated code (e.g. in <algorithms>) 230 // 1. They are used in templated code (e.g. in <algorithms>)
225 // 2. They (begin+end) are used in range-based for syntax sugar 231 // 2. They (begin+end) are used in range-based for syntax sugar
226 // - for (auto x : foo) { ... } // <- foo.begin() will be called. 232 // - for (auto x : foo) { ... } // <- foo.begin() will be called.
227 "begin", "end", "rbegin", "rend", "lock", "unlock", "try_lock", 233 "begin", "end", "rbegin", "rend", "lock", "unlock", "try_lock",
234
235 // https://crbug.com/672902: Should not rewrite names that mimick methods
236 // from std library.
237 "back", "empty", "erase", "front", "insert",
228 }; 238 };
229 for (const auto& b : kBlacklistedNames) { 239 for (const auto& b : kBlacklistedNames) {
230 if (name == b) 240 if (name == b)
231 return true; 241 return true;
232 } 242 }
233 return false; 243 return false;
234 } 244 }
235 245
236 bool IsBlacklistedFunction(const clang::FunctionDecl& decl) { 246 bool IsBlacklistedFunction(const clang::FunctionDecl& decl) {
237 clang::StringRef name = decl.getName(); 247 clang::StringRef name = decl.getName();
(...skipping 1140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 for (const auto& r : replacements) { 1388 for (const auto& r : replacements) {
1379 std::string replacement_text = r.getReplacementText().str(); 1389 std::string replacement_text = r.getReplacementText().str();
1380 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); 1390 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0');
1381 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() 1391 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset()
1382 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; 1392 << ":::" << r.getLength() << ":::" << replacement_text << "\n";
1383 } 1393 }
1384 llvm::outs() << "==== END EDITS ====\n"; 1394 llvm::outs() << "==== END EDITS ====\n";
1385 1395
1386 return 0; 1396 return 0;
1387 } 1397 }
OLDNEW
« no previous file with comments | « no previous file | tools/clang/rewrite_to_chrome_style/tests/function-templates-expected.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698