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

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

Issue 2246263002: Skip parameter replacements where old text != old name. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: The fix fixes the new regression test. Created 4 years, 4 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
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 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 std::string new_name; 516 std::string new_name;
517 if (!GetNameForDecl(*decl, *context, new_name)) 517 if (!GetNameForDecl(*decl, *context, new_name))
518 return; // If false, the name was not suitable for renaming. 518 return; // If false, the name was not suitable for renaming.
519 llvm::StringRef old_name = decl->getName(); 519 llvm::StringRef old_name = decl->getName();
520 if (old_name == new_name) 520 if (old_name == new_name)
521 return; 521 return;
522 clang::SourceLocation loc = TargetNodeTraits<TargetNode>::GetLoc( 522 clang::SourceLocation loc = TargetNodeTraits<TargetNode>::GetLoc(
523 *result.Nodes.getNodeAs<TargetNode>( 523 *result.Nodes.getNodeAs<TargetNode>(
524 TargetNodeTraits<TargetNode>::GetName())); 524 TargetNodeTraits<TargetNode>::GetName()));
525 clang::CharSourceRange range = clang::CharSourceRange::getTokenRange(loc); 525 clang::CharSourceRange range = clang::CharSourceRange::getTokenRange(loc);
526
527 // Check if |range| really covers text of |old_name|. This might not be
528 // true when specializing a templatized class that had an unnamed parameter
529 // in one of method declarations.
530 StringRef old_text = clang::Lexer::getSourceText(
531 range, *result.SourceManager, result.Context->getLangOpts());
532 if (!loc.isMacroID() && old_text != old_name)
533 return;
534
Łukasz Anforowicz 2016/08/15 23:05:08 The new code makes the new regression test pass.
dcheng 2016/08/25 04:08:51 How were you printing out this diagnostic info? Re
Łukasz Anforowicz 2016/08/25 23:32:33 Thanks for bringing up "spelling location". I can
526 replacements_->emplace(*result.SourceManager, range, new_name); 535 replacements_->emplace(*result.SourceManager, range, new_name);
527 replacement_names_.emplace(old_name.str(), std::move(new_name)); 536 replacement_names_.emplace(old_name.str(), std::move(new_name));
528 } 537 }
529 538
530 const std::unordered_map<std::string, std::string>& replacement_names() 539 const std::unordered_map<std::string, std::string>& replacement_names()
531 const { 540 const {
532 return replacement_names_; 541 return replacement_names_;
533 } 542 }
534 543
535 private: 544 private:
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 for (const auto& r : replacements) { 889 for (const auto& r : replacements) {
881 std::string replacement_text = r.getReplacementText().str(); 890 std::string replacement_text = r.getReplacementText().str();
882 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); 891 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0');
883 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() 892 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset()
884 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; 893 << ":::" << r.getLength() << ":::" << replacement_text << "\n";
885 } 894 }
886 llvm::outs() << "==== END EDITS ====\n"; 895 llvm::outs() << "==== END EDITS ====\n";
887 896
888 return 0; 897 return 0;
889 } 898 }
OLDNEW
« no previous file with comments | « docs/clang_tool_refactoring.md ('k') | tools/clang/rewrite_to_chrome_style/tests/template-expected.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698