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

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

Issue 1783923003: rewrite_to_chrome_style: Blacklisted methods are not blink methods! (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 AST_MATCHER(clang::FunctionDecl, isDefaulted) { 57 AST_MATCHER(clang::FunctionDecl, isDefaulted) {
58 return Node.isDefaulted(); 58 return Node.isDefaulted();
59 } 59 }
60 60
61 } // namespace internal_hack 61 } // namespace internal_hack
62 62
63 const char kBlinkFieldPrefix[] = "m_"; 63 const char kBlinkFieldPrefix[] = "m_";
64 const char kBlinkStaticMemberPrefix[] = "s_"; 64 const char kBlinkStaticMemberPrefix[] = "s_";
65 const char kGeneratedFileRegex[] = "^gen/|/gen/"; 65 const char kGeneratedFileRegex[] = "^gen/|/gen/";
66 66
67 // These methods should never be renamed, we do not consider them
68 // to be blink (or wtf) methods at all.
69 const char* const kBlacklistMethods[] = {"trace", "lock", "unlock", "try_lock"};
70
67 AST_MATCHER(clang::FunctionDecl, isOverloadedOperator) { 71 AST_MATCHER(clang::FunctionDecl, isOverloadedOperator) {
68 return Node.isOverloadedOperator(); 72 return Node.isOverloadedOperator();
69 } 73 }
70 74
71 AST_MATCHER_P(clang::FunctionTemplateDecl, 75 AST_MATCHER_P(clang::FunctionTemplateDecl,
72 templatedDecl, 76 templatedDecl,
73 clang::ast_matchers::internal::Matcher<clang::FunctionDecl>, 77 clang::ast_matchers::internal::Matcher<clang::FunctionDecl>,
74 InnerMatcher) { 78 InnerMatcher) {
75 return InnerMatcher.matches(*Node.getTemplatedDecl(), Finder, Builder); 79 return InnerMatcher.matches(*Node.getTemplatedDecl(), Finder, Builder);
76 } 80 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 return false; 128 return false;
125 } 129 }
126 130
127 // A method is from Blink if it is from the Blink namespace or overrides a 131 // A method is from Blink if it is from the Blink namespace or overrides a
128 // method from the Blink namespace. 132 // method from the Blink namespace.
129 bool IsBlinkOrWTFMethod(const clang::CXXMethodDecl& decl, 133 bool IsBlinkOrWTFMethod(const clang::CXXMethodDecl& decl,
130 clang::SourceManager& source_manager) { 134 clang::SourceManager& source_manager) {
131 bool overrides_blink = false; 135 bool overrides_blink = false;
132 bool overrides_non_blink = false; 136 bool overrides_non_blink = false;
133 137
138 // Blacklisted methods are not considered to be in blink so that they will
dcheng 2016/03/10 22:52:46 1) Would it make sense to just combine the iterato
danakj 2016/03/10 22:55:14 We made the iterator blacklist only kick in based
dcheng 2016/03/10 22:57:53 Hmm... that makes it more complicated. I'd sugges
139 // never be rewritten.
140 if (!decl.isStatic()) {
141 for (const auto& b : kBlacklistMethods) {
142 if (decl.getNameAsString() == b)
143 return false;
144 }
145 }
146
134 for (auto it = decl.begin_overridden_methods(); 147 for (auto it = decl.begin_overridden_methods();
135 it != decl.end_overridden_methods(); ++it) { 148 it != decl.end_overridden_methods(); ++it) {
136 if (IsBlinkOrWTFMethod(**it, source_manager)) 149 if (IsBlinkOrWTFMethod(**it, source_manager))
137 overrides_blink = true; 150 overrides_blink = true;
138 else 151 else
139 overrides_non_blink = true; 152 overrides_non_blink = true;
140 } 153 }
141 154
142 // If this fires we have a class overriding a method from a class in blink, 155 // If this fires we have a class overriding a method from a class in blink,
143 // and also overriding a method of the same name from a class not in blink, 156 // and also overriding a method of the same name from a class not in blink,
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 ret_type.find("Iterator") != std::string::npos) { 311 ret_type.find("Iterator") != std::string::npos) {
299 // Iterator methods shouldn't be renamed to work with stl and range-for 312 // Iterator methods shouldn't be renamed to work with stl and range-for
300 // loops. 313 // loops.
301 static const char* kIteratorBlacklist[] = {"begin", "end", "rbegin", 314 static const char* kIteratorBlacklist[] = {"begin", "end", "rbegin",
302 "rend"}; 315 "rend"};
303 for (const auto& b : kIteratorBlacklist) { 316 for (const auto& b : kIteratorBlacklist) {
304 if (original_name == b) 317 if (original_name == b)
305 return false; 318 return false;
306 } 319 }
307 } 320 }
308
309 // Some methods shouldn't be renamed because reasons.
310 static const char* kBlacklist[] = {"trace", "lock", "unlock", "try_lock"};
311 for (const auto& b : kBlacklist) {
312 if (original_name == b)
313 return false;
314 }
315 } 321 }
316 322
317 name = decl.getName().str(); 323 name = decl.getName().str();
318 name[0] = clang::toUppercase(name[0]); 324 name[0] = clang::toUppercase(name[0]);
319 return true; 325 return true;
320 } 326 }
321 327
322 bool GetNameForDecl(const clang::FieldDecl& decl, 328 bool GetNameForDecl(const clang::FieldDecl& decl,
323 const clang::ASTContext& context, 329 const clang::ASTContext& context,
324 clang::SourceManager& source_manager, 330 clang::SourceManager& source_manager,
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 for (const auto& r : replacements) { 797 for (const auto& r : replacements) {
792 std::string replacement_text = r.getReplacementText().str(); 798 std::string replacement_text = r.getReplacementText().str();
793 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); 799 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0');
794 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() 800 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset()
795 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; 801 << ":::" << r.getLength() << ":::" << replacement_text << "\n";
796 } 802 }
797 llvm::outs() << "==== END EDITS ====\n"; 803 llvm::outs() << "==== END EDITS ====\n";
798 804
799 return 0; 805 return 0;
800 } 806 }
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