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

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

Issue 2271203004: Tweak |in_blink_namespace|, to look at ancestors *and also* at qualifiers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blink-style-same-type-and-method-name
Patch Set: Self-review. 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/functions-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 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
« no previous file with comments | « no previous file | tools/clang/rewrite_to_chrome_style/tests/functions-expected.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698