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

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

Issue 2276983002: Prepend "Get" to method name if method name conflicts with return type name. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blink-style-partition-allocator-new-array-delete-array
Patch Set: Created 4 years, 4 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 | 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 4e86a88fc1c474a9a7b3a3be4d8b95e3e5c48a1e..267f617258d5e23e1edd491c175af87160939f15 100644
--- a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
+++ b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
@@ -337,15 +337,24 @@ bool IsProbablyConst(const clang::VarDecl& decl,
}
bool GetNameForDecl(const clang::FunctionDecl& decl,
- const clang::ASTContext& context,
+ clang::ASTContext& context,
Łukasz Anforowicz 2016/08/24 18:09:49 |match| function call below takes a non-const ASTC
std::string& name) {
name = decl.getName().str();
name[0] = clang::toUppercase(name[0]);
+
+ // https://crbug.com/582312: Prepend "Get" if method name conflicts with type.
+ auto base_matcher =
+ hasCanonicalType(hasDeclaration(namedDecl(hasName(name))));
dcheng 2016/08/25 17:36:00 Can we just pull the return type out of the Functi
Łukasz Anforowicz 2016/08/25 18:30:40 Thanks - done. I didn't know about getBaseTypeIde
+ auto conflict_matcher = qualType(
+ anyOf(pointsTo(base_matcher), references(base_matcher), base_matcher));
+ if (!match(conflict_matcher, decl.getReturnType(), context).empty())
+ name = "Get" + name;
+
return true;
}
bool GetNameForDecl(const clang::EnumConstantDecl& decl,
- const clang::ASTContext& context,
+ clang::ASTContext& context,
Łukasz Anforowicz 2016/08/24 18:09:49 Best to be consistent here (i.e. use non-const in
std::string& name) {
StringRef original_name = decl.getName();
@@ -372,7 +381,7 @@ bool GetNameForDecl(const clang::EnumConstantDecl& decl,
}
bool GetNameForDecl(const clang::FieldDecl& decl,
- const clang::ASTContext& context,
+ clang::ASTContext& context,
std::string& name) {
StringRef original_name = decl.getName();
bool member_prefix = original_name.startswith(kBlinkFieldPrefix);
@@ -403,7 +412,7 @@ bool GetNameForConstant(const std::string& original_name, std::string& name) {
}
bool GetNameForDecl(const clang::VarDecl& decl,
- const clang::ASTContext& context,
+ clang::ASTContext& context,
std::string& name) {
StringRef original_name = decl.getName();
@@ -466,14 +475,14 @@ bool GetNameForDecl(const clang::VarDecl& decl,
}
bool GetNameForDecl(const clang::FunctionTemplateDecl& decl,
- const clang::ASTContext& context,
+ clang::ASTContext& context,
std::string& name) {
clang::FunctionDecl* templated_function = decl.getTemplatedDecl();
return GetNameForDecl(*templated_function, context, name);
}
bool GetNameForDecl(const clang::NamedDecl& decl,
- const clang::ASTContext& context,
+ clang::ASTContext& context,
std::string& name) {
if (auto* function = clang::dyn_cast<clang::FunctionDecl>(&decl))
return GetNameForDecl(*function, context, name);
@@ -491,7 +500,7 @@ bool GetNameForDecl(const clang::NamedDecl& decl,
}
bool GetNameForDecl(const clang::UsingDecl& decl,
- const clang::ASTContext& context,
+ clang::ASTContext& context,
std::string& name) {
assert(decl.shadow_size() > 0);
« 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