From 9d65113efeff9b82acddf531d341ecb0e56447a9 Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Mon, 15 Jul 2013 19:55:41 +0200 Subject: fix finding all parents for AST nodes Ctor bodies can also have code inside of member variables initialization, which is not considered to be inside function body. Change-Id: Id68960093a51396b9486f1364b1a361526c3431d --- compilerplugins/clang/plugin.cxx | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'compilerplugins') diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx index 6611606d793f..7454144f7dfd 100644 --- a/compilerplugins/clang/plugin.cxx +++ b/compilerplugins/clang/plugin.cxx @@ -100,11 +100,23 @@ bool ParentBuilder::VisitFunctionDecl( const FunctionDecl* function ) { // if( ignoreLocation( declaration )) // return true; ??? - if( !function->doesThisDeclarationHaveABody()) - return true; - const Stmt* body = function->getBody(); - (*parents)[ body ] = NULL; // no parent - walk( body ); + if( function->doesThisDeclarationHaveABody()) + { + const Stmt* body = function->getBody(); + (*parents)[ body ] = NULL; // no parent + walk( body ); + } + if( const CXXConstructorDecl* ctor = dyn_cast< CXXConstructorDecl >( function )) + { + for( CXXConstructorDecl::init_const_iterator it = ctor->init_begin(); + it != ctor->init_end(); + ++it ) + { + const Expr* init_expression = (*it)->getInit(); + (*parents)[ init_expression ] = NULL; + walk( init_expression ); + } + } return true; } -- cgit v1.2.3