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 4942d50dac7ba089567723315df77f6b64bcfd87..6c62041bb0d680313a8b1223e6b3abf773f8b6a8 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(); |
+} |
+ |
const char kBlinkFieldPrefix[] = "m_"; |
const char kBlinkStaticMemberPrefix[] = "s_"; |
@@ -229,6 +235,7 @@ struct TargetNodeTraits<clang::CXXCtorInitializer> { |
static const char kName[]; |
static clang::CharSourceRange GetRange( |
const clang::CXXCtorInitializer& init) { |
+ assert(init.isWritten()); |
return clang::CharSourceRange::getTokenRange(init.getSourceLocation()); |
} |
}; |
@@ -410,7 +417,16 @@ 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", |
+ memberExpr( |
+ member(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(isDefaulted()))))); |
auto decl_ref_matcher = id("expr", declRefExpr(to(var_decl_matcher))); |
MemberRewriter member_rewriter(&replacements); |
@@ -526,7 +542,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); |