Iterating over the constructors of a class

Hi,

I want to check the initializers of the constructor of a class. For that purpose I tried two aproaches: 1) Using the method VisitCXXConstructorDecl and 2) VisitCXXRecordDecl and then use the CXXRecordDecl::ctor_iterator. However, only when I use the approach 1) I can see that the constructor actually has initializers.

The original code of the ctor is:

PC::PC(const Id& n) :
   ProcessNetwork(n),
    prod( id("prod"), fifo),
    cons( id("cons"), fifo),
    fifo( id("fifo"))
{ }

I am printing the name of the ctors, the number of initializers and the body of the ctor.

The output using 1) is:

Ctor name: PC
Initializers: 0
{
}

Ctor name: PC
Initializers: 0
<NULL>

The output using 2) is:

Ctor name: PC
Initializers: 0
{
}

Ctor name: PC
Initializers: 4
{
}

Any idea why I am not getting the right output when I use the CXXRecordDecl::ctor_iterator.

Thanks,

Miguel

Did you miss this e-mail from me last week?

I don't know for sure, but my guess is that the constructors declared within the CXXRecordDecl are just declarations, and the out-of-line definitions aren't showing up. You'll need to use hasBody() (on FunctionDecl) to get the particular CXXConstructorDecl that has the initializers.

(Yes, there's no getDefinition(). The predicate hasBody() has to do a search for the definition anyway, so it just returns the FunctionDecl representing the definition in an optional out parameter.)

Hope that helps,
Jordan