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 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); |