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

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: 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 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // Matches |T::m| DependentScopeDeclRefExpr if InnerMatcher matches |T|. 180 // Matches |T::m| DependentScopeDeclRefExpr if InnerMatcher matches |T|.
181 AST_MATCHER_P( 181 AST_MATCHER_P(
182 clang::DependentScopeDeclRefExpr, 182 clang::DependentScopeDeclRefExpr,
183 dependentScopeIfQualifier, 183 dependentScopeIfQualifier,
184 clang::ast_matchers::internal::Matcher<clang::NestedNameSpecifier>, 184 clang::ast_matchers::internal::Matcher<clang::NestedNameSpecifier>,
185 InnerMatcher) { 185 InnerMatcher) {
186 clang::NestedNameSpecifier* qual = Node.getQualifier(); 186 clang::NestedNameSpecifier* qual = Node.getQualifier();
187 return qual && InnerMatcher.matches(*qual, Finder, Builder); 187 return qual && InnerMatcher.matches(*qual, Finder, Builder);
188 } 188 }
189 189
190 // Matches |T::f| DependentScopeDeclRefExpr if InnerMatcher matches |T|.
191 AST_MATCHER_P(
192 clang::DeclaratorDecl,
193 declaratorDeclHasQualifier,
194 clang::ast_matchers::internal::Matcher<clang::NestedNameSpecifier>,
195 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
196 clang::NestedNameSpecifier* qual = Node.getQualifier();
197 return qual && InnerMatcher.matches(*qual, Finder, Builder);
198 }
199
190 // Matches |const Class<T>&| QualType if InnerMatcher matches |Class<T>|. 200 // Matches |const Class<T>&| QualType if InnerMatcher matches |Class<T>|.
191 AST_MATCHER_P(clang::QualType, 201 AST_MATCHER_P(clang::QualType,
192 hasUnderlyingType, 202 hasUnderlyingType,
193 clang::ast_matchers::internal::Matcher<clang::Type>, 203 clang::ast_matchers::internal::Matcher<clang::Type>,
194 InnerMatcher) { 204 InnerMatcher) {
195 const clang::Type* type = Node.getTypePtrOrNull(); 205 const clang::Type* type = Node.getTypePtrOrNull();
196 return type && InnerMatcher.matches(*type, Finder, Builder); 206 return type && InnerMatcher.matches(*type, Finder, Builder);
197 } 207 }
198 208
199 bool IsMethodOverrideOf(const clang::CXXMethodDecl& decl, 209 bool IsMethodOverrideOf(const clang::CXXMethodDecl& decl,
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 llvm::InitializeNativeTargetAsmParser(); 815 llvm::InitializeNativeTargetAsmParser();
806 llvm::cl::OptionCategory category( 816 llvm::cl::OptionCategory category(
807 "rewrite_to_chrome_style: convert Blink style to Chrome style."); 817 "rewrite_to_chrome_style: convert Blink style to Chrome style.");
808 CommonOptionsParser options(argc, argv, category); 818 CommonOptionsParser options(argc, argv, category);
809 clang::tooling::ClangTool tool(options.getCompilations(), 819 clang::tooling::ClangTool tool(options.getCompilations(),
810 options.getSourcePathList()); 820 options.getSourcePathList());
811 821
812 MatchFinder match_finder; 822 MatchFinder match_finder;
813 std::set<Replacement> replacements; 823 std::set<Replacement> replacements;
814 824
815 auto in_blink_namespace = 825 // Blink namespace matchers ========
816 decl(hasAncestor(namespaceDecl(anyOf(hasName("blink"), hasName("WTF")), 826 auto blink_namespace_decl =
817 hasParent(translationUnitDecl()))), 827 namespaceDecl(anyOf(hasName("blink"), hasName("WTF")),
818 unless(isExpansionInFileMatching(kGeneratedFileRegex))); 828 hasParent(translationUnitDecl()));
829
830 // Given top-level compilation unit:
831 // namespace WTF {
832 // void foo() {}
833 // }
834 // matches |foo|.
835 auto decl_under_blink_namespace = decl(hasAncestor(blink_namespace_decl));
836
837 // Given top-level compilation unit:
838 // void WTF::foo() {}
839 // matches |WTF::foo|.
840 auto decl_has_qualifier_to_blink_namespace =
841 declaratorDecl(declaratorDeclHasQualifier(
842 anyOf(specifiesNamespace(blink_namespace_decl),
843 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
844
845 auto in_blink_namespace = decl(
846 anyOf(decl_under_blink_namespace, decl_has_qualifier_to_blink_namespace),
847 unless(isExpansionInFileMatching(kGeneratedFileRegex)));
819 848
820 // Field, variable, and enum declarations ======== 849 // Field, variable, and enum declarations ========
821 // Given 850 // Given
822 // int x; 851 // int x;
823 // struct S { 852 // struct S {
824 // int y; 853 // int y;
825 // enum { VALUE }; 854 // enum { VALUE };
826 // }; 855 // };
827 // matches |x|, |y|, and |VALUE|. 856 // matches |x|, |y|, and |VALUE|.
828 auto field_decl_matcher = id("decl", fieldDecl(in_blink_namespace)); 857 auto field_decl_matcher = id("decl", fieldDecl(in_blink_namespace));
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 for (const auto& r : replacements) { 1210 for (const auto& r : replacements) {
1182 std::string replacement_text = r.getReplacementText().str(); 1211 std::string replacement_text = r.getReplacementText().str();
1183 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); 1212 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0');
1184 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() 1213 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset()
1185 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; 1214 << ":::" << r.getLength() << ":::" << replacement_text << "\n";
1186 } 1215 }
1187 llvm::outs() << "==== END EDITS ====\n"; 1216 llvm::outs() << "==== END EDITS ====\n";
1188 1217
1189 return 0; 1218 return 0;
1190 } 1219 }
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