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
This commit is contained in:
Luboš Luňák
2013-07-15 19:55:41 +02:00
parent 67db35da5d
commit 9d65113efe

View File

@@ -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;
}