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

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: Using hasTopLevelPrefix instead of hasPrefix. 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 283dc448b35532297c86ef9089a55f4c6995c2ca..5d6d0b964b28fdfb6090b6b41928cc3875d52810 100644
--- a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
+++ b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
@@ -66,6 +66,21 @@ AST_MATCHER_P(clang::FunctionTemplateDecl,
return InnerMatcher.matches(*Node.getTemplatedDecl(), Finder, Builder);
}
+// If |InnerMatcher| matches |top|, then the returned matcher will match:
+// - |top::function|
+// - |top::Class::method|
+// - |top::internal::Class::method|
+AST_MATCHER_P(
+ clang::NestedNameSpecifier,
+ hasTopLevelPrefix,
+ clang::ast_matchers::internal::Matcher<clang::NestedNameSpecifier>,
+ InnerMatcher) {
+ const clang::NestedNameSpecifier* NodeToMatch = &Node;
+ while (NodeToMatch->getPrefix())
+ NodeToMatch = NodeToMatch->getPrefix();
+ return InnerMatcher.matches(*NodeToMatch, Finder, Builder);
+}
+
// This will narrow CXXCtorInitializers down for both FieldDecls and
// IndirectFieldDecls (ie. anonymous unions and such). In both cases
// getAnyMember() will return a FieldDecl which we can match against.
@@ -591,10 +606,30 @@ 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::function() {}
+ // void WTF::Class::method() {}
+ // matches |WTF::function| and |WTF::Class::method| decls.
+ auto decl_has_qualifier_to_blink_namespace =
+ declaratorDecl(has(nestedNameSpecifier(
+ hasTopLevelPrefix(specifiesNamespace(blink_namespace_decl)))));
+
+ auto in_blink_namespace = decl(
+ anyOf(decl_under_blink_namespace, decl_has_qualifier_to_blink_namespace,
+ hasAncestor(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