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

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

Issue 1641703003: rewrite_to_chrome_style: skip nodes expanded from macros (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 | 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 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 }; 215 };
216 constexpr char TargetNodeTraits<clang::CXXCtorInitializer>::kName[]; 216 constexpr char TargetNodeTraits<clang::CXXCtorInitializer>::kName[];
217 217
218 template <typename DeclNode, typename TargetNode> 218 template <typename DeclNode, typename TargetNode>
219 class RewriterBase : public MatchFinder::MatchCallback { 219 class RewriterBase : public MatchFinder::MatchCallback {
220 public: 220 public:
221 explicit RewriterBase(Replacements* replacements) 221 explicit RewriterBase(Replacements* replacements)
222 : replacements_(replacements) {} 222 : replacements_(replacements) {}
223 223
224 void run(const MatchFinder::MatchResult& result) override { 224 void run(const MatchFinder::MatchResult& result) override {
225 std::string name; 225 std::string new_name;
226 const DeclNode* decl = result.Nodes.getNodeAs<DeclNode>("decl"); 226 const DeclNode* decl = result.Nodes.getNodeAs<DeclNode>("decl");
227 clang::ASTContext* context = result.Context; 227 clang::ASTContext* context = result.Context;
228 if (!GetNameForDecl(*decl, *context, name)) 228 if (!GetNameForDecl(*decl, *context, new_name))
229 return; 229 return;
230 auto r = replacements_->emplace( 230 llvm::StringRef old_name = decl->getName();
231 *result.SourceManager, TargetNodeTraits<TargetNode>::GetRange( 231 if (old_name == new_name)
dcheng 2016/01/28 06:47:42 I moved this up to reduce the amount of edits emit
232 *result.Nodes.getNodeAs<TargetNode>( 232 return;
233 TargetNodeTraits<TargetNode>::kName)), 233 clang::CharSourceRange range = TargetNodeTraits<TargetNode>::GetRange(
234 name); 234 *result.Nodes.getNodeAs<TargetNode>(
235 auto from = decl->getNameAsString(); 235 TargetNodeTraits<TargetNode>::kName));
236 auto to = r.first->getReplacementText().str(); 236 if (range.getBegin().isMacroID() || range.getEnd().isMacroID())
237 if (from != to) 237 return;
238 replacement_names_.emplace(std::move(from), std::move(to)); 238 replacements_->emplace(*result.SourceManager, range, new_name);
239 replacement_names_.emplace(old_name.str(), std::move(new_name));
239 } 240 }
240 241
241 const std::unordered_map<std::string, std::string>& replacement_names() 242 const std::unordered_map<std::string, std::string>& replacement_names()
242 const { 243 const {
243 return replacement_names_; 244 return replacement_names_;
244 } 245 }
245 246
246 private: 247 private:
247 Replacements* const replacements_; 248 Replacements* const replacements_;
248 std::unordered_map<std::string, std::string> replacement_names_; 249 std::unordered_map<std::string, std::string> replacement_names_;
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 for (const auto& r : replacements) { 556 for (const auto& r : replacements) {
556 std::string replacement_text = r.getReplacementText().str(); 557 std::string replacement_text = r.getReplacementText().str();
557 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); 558 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0');
558 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() 559 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset()
559 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; 560 << ":::" << r.getLength() << ":::" << replacement_text << "\n";
560 } 561 }
561 llvm::outs() << "==== END EDITS ====\n"; 562 llvm::outs() << "==== END EDITS ====\n";
562 563
563 return 0; 564 return 0;
564 } 565 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698