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

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: 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 // getAnyMember() will return a FieldDecl which we can match against. 80 // getAnyMember() will return a FieldDecl which we can match against.
81 AST_MATCHER_P(clang::CXXCtorInitializer, 81 AST_MATCHER_P(clang::CXXCtorInitializer,
82 forAnyField, 82 forAnyField,
83 clang::ast_matchers::internal::Matcher<clang::FieldDecl>, 83 clang::ast_matchers::internal::Matcher<clang::FieldDecl>,
84 InnerMatcher) { 84 InnerMatcher) {
85 const clang::FieldDecl* NodeAsDecl = Node.getAnyMember(); 85 const clang::FieldDecl* NodeAsDecl = Node.getAnyMember();
86 return (NodeAsDecl != nullptr && 86 return (NodeAsDecl != nullptr &&
87 InnerMatcher.matches(*NodeAsDecl, Finder, Builder)); 87 InnerMatcher.matches(*NodeAsDecl, Finder, Builder));
88 } 88 }
89 89
90 bool IsMethodOverrideOf(const clang::CXXMethodDecl& decl,
91 const char* class_name) {
92 if (decl.getParent()->getQualifiedNameAsString() == class_name)
93 return true;
94 for (auto it = decl.begin_overridden_methods();
95 it != decl.end_overridden_methods(); ++it) {
96 if (IsMethodOverrideOf(**it, class_name))
97 return true;
98 }
99 return false;
100 }
101
90 bool IsBlacklistedMethod(const clang::CXXMethodDecl& decl) { 102 bool IsBlacklistedMethod(const clang::CXXMethodDecl& decl) {
91 if (decl.isStatic()) 103 if (decl.isStatic())
92 return false; 104 return false;
93 105
94 clang::StringRef name = decl.getName(); 106 clang::StringRef name = decl.getName();
95 107
96 // These methods should never be renamed. 108 // These methods should never be renamed.
97 static const char* kBlacklistMethods[] = {"trace", "lock", "unlock", 109 static const char* kBlacklistMethods[] = {"trace", "lock", "unlock",
98 "try_lock"}; 110 "try_lock"};
99 for (const auto& b : kBlacklistMethods) { 111 for (const auto& b : kBlacklistMethods) {
100 if (name == b) 112 if (name == b)
101 return true; 113 return true;
102 } 114 }
103 115
104 // Iterator methods shouldn't be renamed to work with stl and range-for 116 // Iterator methods shouldn't be renamed to work with stl and range-for
105 // loops. 117 // loops.
106 std::string ret_type = decl.getReturnType().getAsString(); 118 std::string ret_type = decl.getReturnType().getAsString();
107 if (ret_type.find("iterator") == std::string::npos && 119 if (ret_type.find("iterator") != std::string::npos ||
108 ret_type.find("Iterator") == std::string::npos) 120 ret_type.find("Iterator") != std::string::npos) {
109 return false; 121 static const char* kIteratorBlacklist[] = {"begin", "end", "rbegin",
110 static const char* kIteratorBlacklist[] = {"begin", "end", "rbegin", "rend"}; 122 "rend"};
111 for (const auto& b : kIteratorBlacklist) { 123 for (const auto& b : kIteratorBlacklist) {
112 if (name == b) 124 if (name == b)
125 return true;
126 }
127 }
128
129 // Subclasses of InspectorAgent will subclass "disable()" from both blink and
130 // from gen/, which is problematic, but DevTools folks don't want to rename
131 // it or split this up. So don't rename it at all.
132 if (name.equals("disable")) {
133 if (IsMethodOverrideOf(decl, "blink::InspectorAgent"))
dcheng 2016/03/11 02:01:17 Nit: &&
danakj 2016/03/11 02:08:42 Ohh ya :) Done.
113 return true; 134 return true;
114 } 135 }
115 136
116 return false; 137 return false;
117 } 138 }
118 139
119 bool IsDeclContextInBlinkOrWTF(const clang::DeclContext* decl_context, 140 bool IsDeclContextInBlinkOrWTF(const clang::DeclContext* decl_context,
120 const clang::SourceLocation& location, 141 const clang::SourceLocation& location,
121 clang::SourceManager& source_manager, 142 clang::SourceManager& source_manager,
122 bool blink, 143 bool blink,
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 for (const auto& r : replacements) { 823 for (const auto& r : replacements) {
803 std::string replacement_text = r.getReplacementText().str(); 824 std::string replacement_text = r.getReplacementText().str();
804 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); 825 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0');
805 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() 826 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset()
806 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; 827 << ":::" << r.getLength() << ":::" << replacement_text << "\n";
807 } 828 }
808 llvm::outs() << "==== END EDITS ====\n"; 829 llvm::outs() << "==== END EDITS ====\n";
809 830
810 return 0; 831 return 0;
811 } 832 }
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