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 267f617258d5e23e1edd491c175af87160939f15..3a19515c190ac61352db73b703e20e33987e67ac 100644 |
--- a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp |
+++ b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp |
@@ -187,6 +187,16 @@ AST_MATCHER_P( |
return qual && InnerMatcher.matches(*qual, Finder, Builder); |
} |
+// Matches |T::f| DependentScopeDeclRefExpr if InnerMatcher matches |T|. |
+AST_MATCHER_P( |
+ clang::DeclaratorDecl, |
+ declaratorDeclHasQualifier, |
+ clang::ast_matchers::internal::Matcher<clang::NestedNameSpecifier>, |
+ InnerMatcher) { |
dcheng
2016/08/25 00:33:12
Is there any chance we can use the nestedNameSpeci
Łukasz Anforowicz
2016/08/25 21:08:09
Interesting.
FWIW, the AST for ...
template
|
+ clang::NestedNameSpecifier* qual = Node.getQualifier(); |
+ return qual && InnerMatcher.matches(*qual, Finder, Builder); |
+} |
+ |
// Matches |const Class<T>&| QualType if InnerMatcher matches |Class<T>|. |
AST_MATCHER_P(clang::QualType, |
hasUnderlyingType, |
@@ -812,10 +822,29 @@ int main(int argc, const char* argv[]) { |
MatchFinder match_finder; |
std::set<Replacement> replacements; |
- auto in_blink_namespace = |
- decl(hasAncestor(namespaceDecl(anyOf(hasName("blink"), hasName("WTF")), |
- hasParent(translationUnitDecl()))), |
- unless(isExpansionInFileMatching(kGeneratedFileRegex))); |
+ // Blink namespace matchers ======== |
+ auto blink_namespace_decl = |
+ namespaceDecl(anyOf(hasName("blink"), hasName("WTF")), |
+ hasParent(translationUnitDecl())); |
+ |
+ // Given top-level compilation unit: |
+ // namespace WTF { |
+ // void foo() {} |
+ // } |
+ // matches |foo|. |
+ auto decl_under_blink_namespace = decl(hasAncestor(blink_namespace_decl)); |
+ |
+ // Given top-level compilation unit: |
+ // void WTF::foo() {} |
+ // matches |WTF::foo|. |
+ auto decl_has_qualifier_to_blink_namespace = |
+ declaratorDecl(declaratorDeclHasQualifier( |
+ anyOf(specifiesNamespace(blink_namespace_decl), |
+ hasPrefix(specifiesNamespace(blink_namespace_decl))))); |
dcheng
2016/08/25 00:33:12
How come we need both? It would be good to expand
Łukasz Anforowicz
2016/08/25 21:08:09
I've added a test in methods-original.cc + verifie
|
+ |
+ auto in_blink_namespace = decl( |
+ anyOf(decl_under_blink_namespace, decl_has_qualifier_to_blink_namespace), |
+ unless(isExpansionInFileMatching(kGeneratedFileRegex))); |
// Field, variable, and enum declarations ======== |
// Given |