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

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

Issue 2276983002: Prepend "Get" to method name if method name conflicts with return type name. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blink-style-partition-allocator-new-array-delete-array
Patch Set: Rebasing on ToT (more or less). Created 4 years, 3 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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 // If the expression can be evaluated at compile time, then it should have a 280 // If the expression can be evaluated at compile time, then it should have a
281 // kFoo style name. Otherwise, not. 281 // kFoo style name. Otherwise, not.
282 return initializer->isEvaluatable(context); 282 return initializer->isEvaluatable(context);
283 } 283 }
284 284
285 bool GetNameForDecl(const clang::FunctionDecl& decl, 285 bool GetNameForDecl(const clang::FunctionDecl& decl,
286 const clang::ASTContext& context, 286 const clang::ASTContext& context,
287 std::string& name) { 287 std::string& name) {
288 name = decl.getName().str(); 288 name = decl.getName().str();
289 name[0] = clang::toUppercase(name[0]); 289 name[0] = clang::toUppercase(name[0]);
290
291 // https://crbug.com/582312: Prepend "Get" if method name conflicts with type.
292 const clang::IdentifierInfo* return_type =
293 decl.getReturnType().getBaseTypeIdentifier();
294 if (return_type && return_type->getName() == name)
295 name = "Get" + name;
296
290 return true; 297 return true;
291 } 298 }
292 299
293 bool GetNameForDecl(const clang::EnumConstantDecl& decl, 300 bool GetNameForDecl(const clang::EnumConstantDecl& decl,
294 const clang::ASTContext& context, 301 const clang::ASTContext& context,
295 std::string& name) { 302 std::string& name) {
296 StringRef original_name = decl.getName(); 303 StringRef original_name = decl.getName();
297 304
298 // If it's already correct leave it alone. 305 // If it's already correct leave it alone.
299 if (original_name.size() >= 2 && original_name[0] == 'k' && 306 if (original_name.size() >= 2 && original_name[0] == 'k' &&
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 for (const auto& r : replacements) { 886 for (const auto& r : replacements) {
880 std::string replacement_text = r.getReplacementText().str(); 887 std::string replacement_text = r.getReplacementText().str();
881 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); 888 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0');
882 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() 889 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset()
883 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; 890 << ":::" << r.getLength() << ":::" << replacement_text << "\n";
884 } 891 }
885 llvm::outs() << "==== END EDITS ====\n"; 892 llvm::outs() << "==== END EDITS ====\n";
886 893
887 return 0; 894 return 0;
888 } 895 }
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