Chromium Code Reviews| 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; |
| } |