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 3374ea29ea6bd6ab8c3f0b796c90c6e5683384c2..feb1d95b4d264d7c4d8ea15606adb2b58b7d5065 100644 |
--- a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp |
+++ b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp |
@@ -207,16 +207,24 @@ bool IsMethodOverrideOf(const clang::CXXMethodDecl& decl, |
return false; |
} |
-bool IsBlacklistedFunction(const clang::FunctionDecl& decl) { |
+bool IsBlacklistedFunctionName(llvm::StringRef name) { |
+ // https://crbug.com/677166: Have to avoid renaming |hash| -> |Hash| to avoid |
+ // colliding with a struct already named |Hash|. |
+ return name == "hash"; |
+} |
+ |
+bool IsBlacklistedFreeFunctionName(llvm::StringRef name) { |
// swap() functions should match the signature of std::swap for ADL tricks. |
- return decl.getName() == "swap"; |
+ return name == "swap"; |
} |
-bool IsBlacklistedMethodName(llvm::StringRef name) { |
+bool IsBlacklistedInstanceMethodName(llvm::StringRef name) { |
static const char* kBlacklistedNames[] = { |
- "hash", |
- "lock", "unlock", "try_lock", |
- "begin", "end", "rbegin", "rend", |
+ // We should avoid renaming the method names listed below, because |
+ // 1. They are used in templated code (e.g. in <algorithms>) |
+ // 2. They (begin+end) are used in range-based for syntax sugar |
+ // - for (auto x : foo) { ... } // <- foo.begin() will be called. |
+ "begin", "end", "rbegin", "rend", "lock", "unlock", "try_lock", |
}; |
for (const auto& b : kBlacklistedNames) { |
if (name == b) |
@@ -225,18 +233,23 @@ bool IsBlacklistedMethodName(llvm::StringRef name) { |
return false; |
} |
-bool IsBlacklistedMethod(const clang::CXXMethodDecl& decl) { |
- if (decl.isStatic()) |
- return false; |
+bool IsBlacklistedFunction(const clang::FunctionDecl& decl) { |
+ clang::StringRef name = decl.getName(); |
+ return IsBlacklistedFunctionName(name) || IsBlacklistedFreeFunctionName(name); |
+} |
+bool IsBlacklistedMethod(const clang::CXXMethodDecl& decl) { |
clang::StringRef name = decl.getName(); |
- if (IsBlacklistedMethodName(name)) |
- return true; |
+ if (IsBlacklistedFunctionName(name)) |
+ return true; |
+ |
+ if (decl.isInstance() && IsBlacklistedInstanceMethodName(name)) |
+ return true; |
dcheng
2016/12/28 18:48:49
I think we can just early return here if it's stat
Łukasz Anforowicz
2016/12/28 18:56:50
Done.
|
// Subclasses of InspectorAgent will subclass "disable()" from both blink and |
// from gen/, which is problematic, but DevTools folks don't want to rename |
// it or split this up. So don't rename it at all. |
- if (name.equals("disable") && |
+ if (decl.isInstance() && name.equals("disable") && |
IsMethodOverrideOf(decl, "blink::InspectorAgent")) |
return true; |
@@ -852,6 +865,11 @@ class UnresolvedRewriterBase : public RewriterBase<TargetNode> { |
} |
private: |
+ static bool IsBlacklistedMethodName(llvm::StringRef name) { |
dcheng
2016/12/28 18:48:49
How come this is a static method now?
Łukasz Anforowicz
2016/12/28 18:56:50
This was a free function, but the only caller was/
dcheng
2016/12/28 19:03:38
I think it's just confusing to not have all the si
Łukasz Anforowicz
2016/12/28 19:08:07
Done.
|
+ return IsBlacklistedFunctionName(name) || |
+ IsBlacklistedInstanceMethodName(name); |
+ } |
+ |
// This method calculates a new name for nodes that depend on template |
// parameters (http://en.cppreference.com/w/cpp/language/dependent_name). The |
// renaming is based on crude heuristics, because such nodes are not bound to |