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

Unified Diff: tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp

Issue 2608443002: Blacklisting renaming of "hash" in case of static methods and functions. (Closed)
Patch Set: Making IsBlacklistedMethodName a free function again. Created 4 years 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 | tools/clang/rewrite_to_chrome_style/tests/methods-expected.cc » ('j') | 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 a268739ccd31eddba1b9f780e521fc96fd8e74d4..144a1889d51c766b98141ff2ab05e5a84fe36340 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,13 +233,27 @@ bool IsBlacklistedMethodName(llvm::StringRef name) {
return false;
}
+bool IsBlacklistedMethodName(llvm::StringRef name) {
+ return IsBlacklistedFunctionName(name) ||
+ IsBlacklistedInstanceMethodName(name);
+}
+
+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 (IsBlacklistedFunctionName(name))
+ return true;
+
+ // Remaining cases are only applicable to instance methods.
if (decl.isStatic())
return false;
- clang::StringRef name = decl.getName();
- if (IsBlacklistedMethodName(name))
- return true;
+ if (IsBlacklistedInstanceMethodName(name))
+ return true;
// Subclasses of InspectorAgent will subclass "disable()" from both blink and
// from gen/, which is problematic, but DevTools folks don't want to rename
« no previous file with comments | « no previous file | tools/clang/rewrite_to_chrome_style/tests/methods-expected.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698