[cfe-dev] Iterating over the constructors of a class

Jordan Rose jordan_rose at apple.com
Mon Feb 4 09:11:23 PST 2013


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


On Feb 4, 2013, at 5:35 , Miguel Aguilar <miguel.aguilar at ice.rwth-aachen.de> wrote:

> 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
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list