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

Unified Diff: tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp

Issue 1765783002: rewrite_to_chrome_style: Rewrite references to members through the class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/clang/rewrite_to_chrome_style/tests/methods-expected.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
diff --git a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
index 93ecb224069515013ae7c434539593cb5368f87a..12794df34c90d794080bedea61aecc84e79954a6 100644
--- a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
+++ b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp
@@ -383,6 +383,7 @@ struct TargetNodeTraits<clang::NamedDecl> {
static clang::SourceLocation GetLoc(const clang::NamedDecl& decl) {
return decl.getLocation();
}
+ static const char* GetType() { return "NamedDecl"; }
};
const char TargetNodeTraits<clang::NamedDecl>::kName[] = "decl";
@@ -392,6 +393,7 @@ struct TargetNodeTraits<clang::MemberExpr> {
static clang::SourceLocation GetLoc(const clang::MemberExpr& expr) {
return expr.getMemberLoc();
}
+ static const char* GetType() { return "MemberExpr"; }
};
const char TargetNodeTraits<clang::MemberExpr>::kName[] = "expr";
@@ -401,6 +403,7 @@ struct TargetNodeTraits<clang::DeclRefExpr> {
static clang::SourceLocation GetLoc(const clang::DeclRefExpr& expr) {
return expr.getLocation();
}
+ static const char* GetType() { return "DeclRefExpr"; }
};
const char TargetNodeTraits<clang::DeclRefExpr>::kName[] = "expr";
@@ -411,6 +414,7 @@ struct TargetNodeTraits<clang::CXXCtorInitializer> {
assert(init.isWritten());
return init.getSourceLocation();
}
+ static const char* GetType() { return "CXXCtorInitializer"; }
};
const char TargetNodeTraits<clang::CXXCtorInitializer>::kName[] = "initializer";
@@ -460,6 +464,7 @@ using FieldDeclRewriter = RewriterBase<clang::FieldDecl, clang::NamedDecl>;
using VarDeclRewriter = RewriterBase<clang::VarDecl, clang::NamedDecl>;
using MemberRewriter = RewriterBase<clang::FieldDecl, clang::MemberExpr>;
using DeclRefRewriter = RewriterBase<clang::VarDecl, clang::DeclRefExpr>;
+using FieldDeclRefRewriter = RewriterBase<clang::FieldDecl, clang::DeclRefExpr>;
using FunctionDeclRewriter =
RewriterBase<clang::FunctionDecl, clang::NamedDecl>;
using FunctionRefRewriter =
@@ -559,6 +564,28 @@ int main(int argc, const char* argv[]) {
EnumConstantDeclRefRewriter enum_member_ref_rewriter(&replacements);
match_finder.addMatcher(enum_member_ref_matcher, &enum_member_ref_rewriter);
+ // Member references in a non-member context ========
+ // Given
+ // struct S {
+ // typedef int U::*UnspecifiedBoolType;
+ // operator UnspecifiedBoolType() { return s_ ? &U::s_ : 0; }
+ // int s_;
+ // };
+ // matches |&U::s_| but not |s_|.
+ auto member_ref_matcher = id(
+ "expr",
+ declRefExpr(
+ to(field_decl_matcher),
+ // Needed to avoid matching member references in functions (which will
+ // be an ancestor of the member reference) synthesized by the
+ // compiler, such as a synthesized copy constructor.
+ // This skips explicitly defaulted functions as well, but that's OK:
+ // there's nothing interesting to rewrite in those either.
+ unless(hasAncestor(functionDecl(internal_hack::isDefaulted())))));
dcheng 2016/03/04 01:41:55 I think we might not need this, cause the things y
danakj 2016/03/04 01:55:51 I couldn't think of it offhand, but then I thought
+
+ FieldDeclRefRewriter member_ref_rewriter(&replacements);
+ match_finder.addMatcher(member_ref_matcher, &member_ref_rewriter);
+
// Non-method function declarations ========
// Given
// void f();
« no previous file with comments | « no previous file | tools/clang/rewrite_to_chrome_style/tests/methods-expected.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698