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

Side by Side 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, 3 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Changes Blink-style names to Chrome-style names. Currently transforms: 5 // Changes Blink-style names to Chrome-style names. Currently transforms:
6 // fields: 6 // fields:
7 // int m_operationCount => int operation_count_ 7 // int m_operationCount => int operation_count_
8 // variables (including parameters): 8 // variables (including parameters):
9 // int mySuperVariable => int my_super_variable 9 // int mySuperVariable => int my_super_variable
10 // constants: 10 // constants:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 return Node.isOverloadedOperator(); 59 return Node.isOverloadedOperator();
60 } 60 }
61 61
62 AST_MATCHER_P(clang::FunctionTemplateDecl, 62 AST_MATCHER_P(clang::FunctionTemplateDecl,
63 templatedDecl, 63 templatedDecl,
64 clang::ast_matchers::internal::Matcher<clang::FunctionDecl>, 64 clang::ast_matchers::internal::Matcher<clang::FunctionDecl>,
65 InnerMatcher) { 65 InnerMatcher) {
66 return InnerMatcher.matches(*Node.getTemplatedDecl(), Finder, Builder); 66 return InnerMatcher.matches(*Node.getTemplatedDecl(), Finder, Builder);
67 } 67 }
68 68
69 // If |InnerMatcher| matches |top|, then the returned matcher will match:
70 // - |top::function|
71 // - |top::Class::method|
72 // - |top::internal::Class::method|
73 AST_MATCHER_P(
74 clang::NestedNameSpecifier,
75 hasTopLevelPrefix,
76 clang::ast_matchers::internal::Matcher<clang::NestedNameSpecifier>,
77 InnerMatcher) {
78 const clang::NestedNameSpecifier* NodeToMatch = &Node;
79 while (NodeToMatch->getPrefix())
80 NodeToMatch = NodeToMatch->getPrefix();
81 return InnerMatcher.matches(*NodeToMatch, Finder, Builder);
82 }
83
69 // This will narrow CXXCtorInitializers down for both FieldDecls and 84 // This will narrow CXXCtorInitializers down for both FieldDecls and
70 // IndirectFieldDecls (ie. anonymous unions and such). In both cases 85 // IndirectFieldDecls (ie. anonymous unions and such). In both cases
71 // getAnyMember() will return a FieldDecl which we can match against. 86 // getAnyMember() will return a FieldDecl which we can match against.
72 AST_MATCHER_P(clang::CXXCtorInitializer, 87 AST_MATCHER_P(clang::CXXCtorInitializer,
73 forAnyField, 88 forAnyField,
74 clang::ast_matchers::internal::Matcher<clang::FieldDecl>, 89 clang::ast_matchers::internal::Matcher<clang::FieldDecl>,
75 InnerMatcher) { 90 InnerMatcher) {
76 const clang::FieldDecl* NodeAsDecl = Node.getAnyMember(); 91 const clang::FieldDecl* NodeAsDecl = Node.getAnyMember();
77 return (NodeAsDecl != nullptr && 92 return (NodeAsDecl != nullptr &&
78 InnerMatcher.matches(*NodeAsDecl, Finder, Builder)); 93 InnerMatcher.matches(*NodeAsDecl, Finder, Builder));
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 llvm::InitializeNativeTargetAsmParser(); 599 llvm::InitializeNativeTargetAsmParser();
585 llvm::cl::OptionCategory category( 600 llvm::cl::OptionCategory category(
586 "rewrite_to_chrome_style: convert Blink style to Chrome style."); 601 "rewrite_to_chrome_style: convert Blink style to Chrome style.");
587 CommonOptionsParser options(argc, argv, category); 602 CommonOptionsParser options(argc, argv, category);
588 clang::tooling::ClangTool tool(options.getCompilations(), 603 clang::tooling::ClangTool tool(options.getCompilations(),
589 options.getSourcePathList()); 604 options.getSourcePathList());
590 605
591 MatchFinder match_finder; 606 MatchFinder match_finder;
592 std::set<Replacement> replacements; 607 std::set<Replacement> replacements;
593 608
594 auto in_blink_namespace = 609 // Blink namespace matchers ========
595 decl(hasAncestor(namespaceDecl(anyOf(hasName("blink"), hasName("WTF")), 610 auto blink_namespace_decl =
596 hasParent(translationUnitDecl()))), 611 namespaceDecl(anyOf(hasName("blink"), hasName("WTF")),
597 unless(isExpansionInFileMatching(kGeneratedFileRegex))); 612 hasParent(translationUnitDecl()));
613
614 // Given top-level compilation unit:
615 // namespace WTF {
616 // void foo() {}
617 // }
618 // matches |foo|.
619 auto decl_under_blink_namespace = decl(hasAncestor(blink_namespace_decl));
620
621 // Given top-level compilation unit:
622 // void WTF::function() {}
623 // void WTF::Class::method() {}
624 // matches |WTF::function| and |WTF::Class::method| decls.
625 auto decl_has_qualifier_to_blink_namespace =
626 declaratorDecl(has(nestedNameSpecifier(
627 hasTopLevelPrefix(specifiesNamespace(blink_namespace_decl)))));
628
629 auto in_blink_namespace = decl(
630 anyOf(decl_under_blink_namespace, decl_has_qualifier_to_blink_namespace,
631 hasAncestor(decl_has_qualifier_to_blink_namespace)),
632 unless(isExpansionInFileMatching(kGeneratedFileRegex)));
598 633
599 // Field, variable, and enum declarations ======== 634 // Field, variable, and enum declarations ========
600 // Given 635 // Given
601 // int x; 636 // int x;
602 // struct S { 637 // struct S {
603 // int y; 638 // int y;
604 // enum { VALUE }; 639 // enum { VALUE };
605 // }; 640 // };
606 // matches |x|, |y|, and |VALUE|. 641 // matches |x|, |y|, and |VALUE|.
607 auto field_decl_matcher = id("decl", fieldDecl(in_blink_namespace)); 642 auto field_decl_matcher = id("decl", fieldDecl(in_blink_namespace));
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 for (const auto& r : replacements) { 926 for (const auto& r : replacements) {
892 std::string replacement_text = r.getReplacementText().str(); 927 std::string replacement_text = r.getReplacementText().str();
893 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); 928 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0');
894 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() 929 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset()
895 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; 930 << ":::" << r.getLength() << ":::" << replacement_text << "\n";
896 } 931 }
897 llvm::outs() << "==== END EDITS ====\n"; 932 llvm::outs() << "==== END EDITS ====\n";
898 933
899 return 0; 934 return 0;
900 } 935 }
OLDNEW
« 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