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 db208abc2f762e0a7848ddb5f3700cb21743c46f..442df030fd2a498ee77b637e64bbb95c63cf2ee5 100644 |
--- a/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp |
+++ b/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp |
@@ -53,6 +53,12 @@ AST_MATCHER(clang::FunctionDecl, isOverloadedOperator) { |
return Node.isOverloadedOperator(); |
} |
+// This is available in newer clang revisions... but alas, Chrome has not rolled |
+// that far yet. |
+AST_MATCHER(clang::FunctionDecl, isDefaulted) { |
+ return Node.isDefaulted(); |
+} |
+ |
constexpr char kBlinkFieldPrefix[] = "m_"; |
constexpr char kBlinkStaticMemberPrefix[] = "s_"; |
@@ -210,6 +216,7 @@ struct TargetNodeTraits<clang::CXXCtorInitializer> { |
static constexpr char kName[] = "initializer"; |
static clang::CharSourceRange GetRange( |
const clang::CXXCtorInitializer& init) { |
+ assert(init.isWritten()); |
return clang::CharSourceRange::getTokenRange(init.getSourceLocation()); |
} |
}; |
@@ -390,7 +397,14 @@ int main(int argc, const char* argv[]) { |
// ... |
// } |
// matches |x| in if (x). |
- auto member_matcher = id("expr", memberExpr(member(field_decl_matcher))); |
+ auto member_matcher = |
+ id("expr", |
+ // Needed to avoid matching member references in functions synthesized |
danakj
2016/01/28 23:08:20
can you put this comment on the unless part?
dcheng
2016/01/28 23:15:43
Done.
|
+ // 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. |
+ memberExpr(member(field_decl_matcher), |
+ unless(hasAncestor(functionDecl(isDefaulted()))))); |
danakj
2016/01/28 23:08:20
why the ancestor part of this? (maybe add to comme
dcheng
2016/01/28 23:15:43
Hm... that's kind of implicit in "member reference
danakj
2016/01/29 00:16:55
oh the ancestor is the function, this is the membe
dcheng
2016/01/29 01:17:30
Done.
|
auto decl_ref_matcher = id("expr", declRefExpr(to(var_decl_matcher))); |
MemberRewriter member_rewriter(&replacements); |
@@ -506,7 +520,8 @@ int main(int argc, const char* argv[]) { |
// matches each initializer in the constructor for S. |
auto constructor_initializer_matcher = |
cxxConstructorDecl(forEachConstructorInitializer( |
- id("initializer", cxxCtorInitializer(forField(field_decl_matcher))))); |
+ id("initializer", |
+ cxxCtorInitializer(forField(field_decl_matcher), isWritten())))); |
ConstructorInitializerRewriter constructor_initializer_rewriter( |
&replacements); |