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

Side by Side Diff: tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp

Issue 2604023002: ABANDONED CL: Rewrite also identifiers declared in generated files. (Closed)
Patch Set: Created 3 years, 11 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/generated-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 25 matching lines...) Expand all
36 36
37 using namespace clang::ast_matchers; 37 using namespace clang::ast_matchers;
38 using clang::tooling::CommonOptionsParser; 38 using clang::tooling::CommonOptionsParser;
39 using clang::tooling::Replacement; 39 using clang::tooling::Replacement;
40 using llvm::StringRef; 40 using llvm::StringRef;
41 41
42 namespace { 42 namespace {
43 43
44 const char kBlinkFieldPrefix[] = "m_"; 44 const char kBlinkFieldPrefix[] = "m_";
45 const char kBlinkStaticMemberPrefix[] = "s_"; 45 const char kBlinkStaticMemberPrefix[] = "s_";
46 const char kGeneratedFileRegex[] = "^gen/|/gen/";
47 46
48 template <typename MatcherType, typename NodeType> 47 template <typename MatcherType, typename NodeType>
49 bool IsMatching(const MatcherType& matcher, 48 bool IsMatching(const MatcherType& matcher,
50 const NodeType& node, 49 const NodeType& node,
51 clang::ASTContext& context) { 50 clang::ASTContext& context) {
52 return !match(matcher, node, context).empty(); 51 return !match(matcher, node, context).empty();
53 } 52 }
54 53
55 const clang::ast_matchers::internal:: 54 const clang::ast_matchers::internal::
56 VariadicDynCastAllOfMatcher<clang::Expr, clang::UnresolvedMemberExpr> 55 VariadicDynCastAllOfMatcher<clang::Expr, clang::UnresolvedMemberExpr>
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 options.getSourcePathList()); 986 options.getSourcePathList());
988 987
989 MatchFinder match_finder; 988 MatchFinder match_finder;
990 std::set<Replacement> replacements; 989 std::set<Replacement> replacements;
991 990
992 // Blink namespace matchers ======== 991 // Blink namespace matchers ========
993 auto blink_namespace_decl = 992 auto blink_namespace_decl =
994 namespaceDecl(anyOf(hasName("blink"), hasName("WTF")), 993 namespaceDecl(anyOf(hasName("blink"), hasName("WTF")),
995 hasParent(translationUnitDecl())); 994 hasParent(translationUnitDecl()));
996 995
996 auto protocol_namespace_decl =
997 namespaceDecl(hasName("protocol"),
998 hasParent(namespaceDecl(hasName("blink"),
999 hasParent(translationUnitDecl()))));
1000
997 // Given top-level compilation unit: 1001 // Given top-level compilation unit:
998 // namespace WTF { 1002 // namespace WTF {
999 // void foo() {} 1003 // void foo() {}
1000 // } 1004 // }
1001 // matches |foo|. 1005 // matches |foo|.
1002 auto decl_under_blink_namespace = decl(hasAncestor(blink_namespace_decl)); 1006 auto decl_under_blink_namespace =
1007 decl(hasAncestor(blink_namespace_decl),
1008 unless(hasAncestor(protocol_namespace_decl)));
1003 1009
1004 // Given top-level compilation unit: 1010 // Given top-level compilation unit:
1005 // void WTF::function() {} 1011 // void WTF::function() {}
1006 // void WTF::Class::method() {} 1012 // void WTF::Class::method() {}
1007 // matches |WTF::function| and |WTF::Class::method| decls. 1013 // matches |WTF::function| and |WTF::Class::method| decls.
1008 auto decl_has_qualifier_to_blink_namespace = 1014 auto decl_has_qualifier_to_blink_namespace =
1009 declaratorDecl(has(nestedNameSpecifier( 1015 declaratorDecl(has(nestedNameSpecifier(
1010 hasTopLevelPrefix(specifiesNamespace(blink_namespace_decl))))); 1016 hasTopLevelPrefix(specifiesNamespace(blink_namespace_decl)))));
1011 1017
1012 auto in_blink_namespace = decl( 1018 auto in_blink_namespace = decl(
1013 anyOf(decl_under_blink_namespace, decl_has_qualifier_to_blink_namespace, 1019 anyOf(decl_under_blink_namespace, decl_has_qualifier_to_blink_namespace,
1014 hasAncestor(decl_has_qualifier_to_blink_namespace)), 1020 hasAncestor(decl_has_qualifier_to_blink_namespace)));
1015 unless(isExpansionInFileMatching(kGeneratedFileRegex)));
1016 1021
1017 // Field, variable, and enum declarations ======== 1022 // Field, variable, and enum declarations ========
1018 // Given 1023 // Given
1019 // int x; 1024 // int x;
1020 // struct S { 1025 // struct S {
1021 // int y; 1026 // int y;
1022 // enum { VALUE }; 1027 // enum { VALUE };
1023 // }; 1028 // };
1024 // matches |x|, |y|, and |VALUE|. 1029 // matches |x|, |y|, and |VALUE|.
1025 auto field_decl_matcher = id("decl", fieldDecl(in_blink_namespace)); 1030 auto field_decl_matcher = id("decl", fieldDecl(in_blink_namespace));
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 for (const auto& r : replacements) { 1365 for (const auto& r : replacements) {
1361 std::string replacement_text = r.getReplacementText().str(); 1366 std::string replacement_text = r.getReplacementText().str();
1362 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); 1367 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0');
1363 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() 1368 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset()
1364 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; 1369 << ":::" << r.getLength() << ":::" << replacement_text << "\n";
1365 } 1370 }
1366 llvm::outs() << "==== END EDITS ====\n"; 1371 llvm::outs() << "==== END EDITS ====\n";
1367 1372
1368 return 0; 1373 return 0;
1369 } 1374 }
OLDNEW
« no previous file with comments | « no previous file | tools/clang/rewrite_to_chrome_style/tests/generated-expected.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698