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

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: Handle parameters and variables underneath namespace-less function decl. 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 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 llvm::InitializeNativeTargetAsmParser(); 577 llvm::InitializeNativeTargetAsmParser();
578 llvm::cl::OptionCategory category( 578 llvm::cl::OptionCategory category(
579 "rewrite_to_chrome_style: convert Blink style to Chrome style."); 579 "rewrite_to_chrome_style: convert Blink style to Chrome style.");
580 CommonOptionsParser options(argc, argv, category); 580 CommonOptionsParser options(argc, argv, category);
581 clang::tooling::ClangTool tool(options.getCompilations(), 581 clang::tooling::ClangTool tool(options.getCompilations(),
582 options.getSourcePathList()); 582 options.getSourcePathList());
583 583
584 MatchFinder match_finder; 584 MatchFinder match_finder;
585 std::set<Replacement> replacements; 585 std::set<Replacement> replacements;
586 586
587 auto in_blink_namespace = 587 // Blink namespace matchers ========
588 decl(hasAncestor(namespaceDecl(anyOf(hasName("blink"), hasName("WTF")), 588 auto blink_namespace_decl =
589 hasParent(translationUnitDecl()))), 589 namespaceDecl(anyOf(hasName("blink"), hasName("WTF")),
590 unless(isExpansionInFileMatching(kGeneratedFileRegex))); 590 hasParent(translationUnitDecl()));
591
592 // Given top-level compilation unit:
593 // namespace WTF {
594 // void foo() {}
595 // }
596 // matches |foo|.
597 auto decl_under_blink_namespace = decl(hasAncestor(blink_namespace_decl));
598
599 // Given top-level compilation unit:
600 // void WTF::function() {} // (1)
601 // void WTF::Class::method() {} // (2)
dcheng 2016/08/29 21:12:17 As mentioned offline, this doesn't match something
602 // matches |WTF::function| and |WTF::Class::method| decls.
603 auto decl_has_qualifier_to_blink_namespace =
604 declaratorDecl(has(nestedNameSpecifier(
605 anyOf(specifiesNamespace(blink_namespace_decl), // (1)
606 hasPrefix(specifiesNamespace(blink_namespace_decl)))))); // (2)
607
608 auto in_blink_namespace = decl(
609 anyOf(decl_under_blink_namespace, decl_has_qualifier_to_blink_namespace,
610 hasAncestor(decl_has_qualifier_to_blink_namespace)),
611 unless(isExpansionInFileMatching(kGeneratedFileRegex)));
591 612
592 // Field, variable, and enum declarations ======== 613 // Field, variable, and enum declarations ========
593 // Given 614 // Given
594 // int x; 615 // int x;
595 // struct S { 616 // struct S {
596 // int y; 617 // int y;
597 // enum { VALUE }; 618 // enum { VALUE };
598 // }; 619 // };
599 // matches |x|, |y|, and |VALUE|. 620 // matches |x|, |y|, and |VALUE|.
600 auto field_decl_matcher = id("decl", fieldDecl(in_blink_namespace)); 621 auto field_decl_matcher = id("decl", fieldDecl(in_blink_namespace));
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 for (const auto& r : replacements) { 900 for (const auto& r : replacements) {
880 std::string replacement_text = r.getReplacementText().str(); 901 std::string replacement_text = r.getReplacementText().str();
881 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); 902 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0');
882 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() 903 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset()
883 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; 904 << ":::" << r.getLength() << ":::" << replacement_text << "\n";
884 } 905 }
885 llvm::outs() << "==== END EDITS ====\n"; 906 llvm::outs() << "==== END EDITS ====\n";
886 907
887 return 0; 908 return 0;
888 } 909 }
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