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

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: 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 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,
Łukasz Anforowicz 2016/08/24 19:20:21 Ideally I would name this |hasQualifier|, but if I
194 clang::ast_matchers::internal::Matcher<clang::NestedNameSpecifier>,
195 InnerMatcher) {
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 auto blink_namespace_decl_matcher =
816 decl(hasAncestor(namespaceDecl(anyOf(hasName("blink"), hasName("WTF")), 826 namespaceDecl(anyOf(hasName("blink"), hasName("WTF")),
817 hasParent(translationUnitDecl()))), 827 hasParent(translationUnitDecl()));
818 unless(isExpansionInFileMatching(kGeneratedFileRegex))); 828 auto in_blink_namespace = decl(
829 anyOf(decl(hasAncestor(blink_namespace_decl_matcher)),
830 declaratorDecl(declaratorDeclHasQualifier(anyOf(
831 specifiesNamespace(blink_namespace_decl_matcher),
832 hasPrefix(specifiesNamespace(blink_namespace_decl_matcher)))))),
833 unless(isExpansionInFileMatching(kGeneratedFileRegex)));
819 834
820 // Field, variable, and enum declarations ======== 835 // Field, variable, and enum declarations ========
821 // Given 836 // Given
822 // int x; 837 // int x;
823 // struct S { 838 // struct S {
824 // int y; 839 // int y;
825 // enum { VALUE }; 840 // enum { VALUE };
826 // }; 841 // };
827 // matches |x|, |y|, and |VALUE|. 842 // matches |x|, |y|, and |VALUE|.
828 auto field_decl_matcher = id("decl", fieldDecl(in_blink_namespace)); 843 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) { 1196 for (const auto& r : replacements) {
1182 std::string replacement_text = r.getReplacementText().str(); 1197 std::string replacement_text = r.getReplacementText().str();
1183 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); 1198 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0');
1184 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() 1199 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset()
1185 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; 1200 << ":::" << r.getLength() << ":::" << replacement_text << "\n";
1186 } 1201 }
1187 llvm::outs() << "==== END EDITS ====\n"; 1202 llvm::outs() << "==== END EDITS ====\n";
1188 1203
1189 return 0; 1204 return 0;
1190 } 1205 }
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