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

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

Issue 1782293003: rewrite_to_chrome_style: Blacklist InspectorAgent::disable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rewrite-blacklist-inspector: rebase 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 return inner_matcher.matches(decl, finder, builder); 137 return inner_matcher.matches(decl, finder, builder);
138 } 138 }
139 139
140 AST_MATCHER_P(clang::CXXMethodDecl, 140 AST_MATCHER_P(clang::CXXMethodDecl,
141 includeAllOverriddenMethods, 141 includeAllOverriddenMethods,
142 clang::ast_matchers::internal::Matcher<clang::CXXMethodDecl>, 142 clang::ast_matchers::internal::Matcher<clang::CXXMethodDecl>,
143 InnerMatcher) { 143 InnerMatcher) {
144 return MatchAllOverriddenMethods(Node, InnerMatcher, Finder, Builder); 144 return MatchAllOverriddenMethods(Node, InnerMatcher, Finder, Builder);
145 } 145 }
146 146
147 bool IsMethodOverrideOf(const clang::CXXMethodDecl& decl,
148 const char* class_name) {
149 if (decl.getParent()->getQualifiedNameAsString() == class_name)
150 return true;
151 for (auto it = decl.begin_overridden_methods();
152 it != decl.end_overridden_methods(); ++it) {
153 if (IsMethodOverrideOf(**it, class_name))
154 return true;
155 }
156 return false;
157 }
158
147 bool IsBlacklistedMethod(const clang::CXXMethodDecl& decl) { 159 bool IsBlacklistedMethod(const clang::CXXMethodDecl& decl) {
148 if (decl.isStatic()) 160 if (decl.isStatic())
149 return false; 161 return false;
150 162
151 clang::StringRef name = decl.getName(); 163 clang::StringRef name = decl.getName();
152 164
153 // These methods should never be renamed. 165 // These methods should never be renamed.
154 static const char* kBlacklistMethods[] = {"trace", "lock", "unlock", 166 static const char* kBlacklistMethods[] = {"trace", "lock", "unlock",
155 "try_lock"}; 167 "try_lock"};
156 for (const auto& b : kBlacklistMethods) { 168 for (const auto& b : kBlacklistMethods) {
157 if (name == b) 169 if (name == b)
158 return true; 170 return true;
159 } 171 }
160 172
161 // Iterator methods shouldn't be renamed to work with stl and range-for 173 // Iterator methods shouldn't be renamed to work with stl and range-for
162 // loops. 174 // loops.
163 std::string ret_type = decl.getReturnType().getAsString(); 175 std::string ret_type = decl.getReturnType().getAsString();
164 if (ret_type.find("iterator") == std::string::npos && 176 if (ret_type.find("iterator") != std::string::npos ||
165 ret_type.find("Iterator") == std::string::npos) 177 ret_type.find("Iterator") != std::string::npos) {
166 return false; 178 static const char* kIteratorBlacklist[] = {"begin", "end", "rbegin",
167 static const char* kIteratorBlacklist[] = {"begin", "end", "rbegin", "rend"}; 179 "rend"};
168 for (const auto& b : kIteratorBlacklist) { 180 for (const auto& b : kIteratorBlacklist) {
169 if (name == b) 181 if (name == b)
170 return true; 182 return true;
183 }
171 } 184 }
172 185
186 // Subclasses of InspectorAgent will subclass "disable()" from both blink and
187 // from gen/, which is problematic, but DevTools folks don't want to rename
188 // it or split this up. So don't rename it at all.
189 if (name.equals("disable") &&
190 IsMethodOverrideOf(decl, "blink::InspectorAgent"))
191 return true;
192
173 return false; 193 return false;
174 } 194 }
175 195
176 AST_MATCHER(clang::CXXMethodDecl, isBlacklistedMethod) { 196 AST_MATCHER(clang::CXXMethodDecl, isBlacklistedMethod) {
177 return IsBlacklistedMethod(Node); 197 return IsBlacklistedMethod(Node);
178 } 198 }
179 199
180 // Helper to convert from a camelCaseName to camel_case_name. It uses some 200 // Helper to convert from a camelCaseName to camel_case_name. It uses some
181 // heuristics to try to handle acronyms in camel case names correctly. 201 // heuristics to try to handle acronyms in camel case names correctly.
182 std::string CamelCaseToUnderscoreCase(StringRef input) { 202 std::string CamelCaseToUnderscoreCase(StringRef input) {
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 for (const auto& r : replacements) { 796 for (const auto& r : replacements) {
777 std::string replacement_text = r.getReplacementText().str(); 797 std::string replacement_text = r.getReplacementText().str();
778 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); 798 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0');
779 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() 799 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset()
780 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; 800 << ":::" << r.getLength() << ":::" << replacement_text << "\n";
781 } 801 }
782 llvm::outs() << "==== END EDITS ====\n"; 802 llvm::outs() << "==== END EDITS ====\n";
783 803
784 return 0; 804 return 0;
785 } 805 }
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