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

Unified 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: rewrite-blacklist-namespace: blacklistfunction 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
diff --git a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
index 13b36000a1e2bbe359079ecb4d05560b0db1343b..97090ca23207547fdaf4949d1d958388e340d129 100644
--- a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
+++ b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
@@ -87,6 +87,35 @@ AST_MATCHER_P(clang::CXXCtorInitializer,
InnerMatcher.matches(*NodeAsDecl, Finder, Builder));
}
+bool IsBlacklistedMethod(const clang::CXXMethodDecl& decl) {
+ if (decl.isStatic())
+ return false;
+
+ clang::StringRef name = decl.getName();
+
+ // These methods should never be renamed.
+ static const char* kBlacklistMethods[] = {"trace", "lock", "unlock",
+ "try_lock"};
+ for (const auto& b : kBlacklistMethods) {
+ if (name == b)
+ return true;
+ }
+
+ // Iterator methods shouldn't be renamed to work with stl and range-for
+ // loops.
+ std::string ret_type = decl.getReturnType().getAsString();
+ if (ret_type.find("iterator") == std::string::npos &&
+ ret_type.find("Iterator") == std::string::npos)
+ return false;
+ static const char* kIteratorBlacklist[] = {"begin", "end", "rbegin", "rend"};
+ for (const auto& b : kIteratorBlacklist) {
+ if (name == b)
+ return true;
+ }
+
+ return false;
+}
+
bool IsDeclContextInBlinkOrWTF(const clang::DeclContext* decl_context,
const clang::SourceLocation& location,
clang::SourceManager& source_manager,
@@ -131,6 +160,11 @@ bool IsBlinkOrWTFMethod(const clang::CXXMethodDecl& decl,
bool overrides_blink = false;
bool overrides_non_blink = false;
+ // Blacklisted methods are not considered to be in blink so that they will
+ // never be rewritten.
+ if (IsBlacklistedMethod(decl))
+ return false;
+
for (auto it = decl.begin_overridden_methods();
it != decl.end_overridden_methods(); ++it) {
if (IsBlinkOrWTFMethod(**it, source_manager))
@@ -291,30 +325,7 @@ bool GetNameForDecl(const clang::CXXMethodDecl& decl,
clang::SourceManager& source_manager,
std::string& name) {
StringRef original_name = decl.getName();
-
- if (!decl.isStatic()) {
- std::string ret_type = decl.getReturnType().getAsString();
- if (ret_type.find("iterator") != std::string::npos ||
- ret_type.find("Iterator") != std::string::npos) {
- // Iterator methods shouldn't be renamed to work with stl and range-for
- // loops.
- static const char* kIteratorBlacklist[] = {"begin", "end", "rbegin",
- "rend"};
- for (const auto& b : kIteratorBlacklist) {
- if (original_name == b)
- return false;
- }
- }
-
- // Some methods shouldn't be renamed because reasons.
- static const char* kBlacklist[] = {"trace", "lock", "unlock", "try_lock"};
- for (const auto& b : kBlacklist) {
- if (original_name == b)
- return false;
- }
- }
-
- name = decl.getName().str();
+ name = original_name.str();
dcheng 2016/03/10 23:57:42 Nit: get rid of |original_name| local here.
danakj 2016/03/11 01:49:33 Done.
name[0] = clang::toUppercase(name[0]);
return true;
}
« 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