[cfe-dev] Constructor Initializers

Miguel Aguilar miguel.aguilar at ice.rwth-aachen.de
Fri Jan 25 08:07:20 PST 2013


Hi,

I am trying to get the constructor initializers of the following class:

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

If I run the -ast-printer I get this:

PC(const Id &n) : ProcessNetwork(n), fifo(this->id("fifo")) {
}

which is clearly incomplete compared to the original code.

Now my main interested is to analyze the constructor initializers, so 
for that I have this code:

bool VisitCXXRecordDecl(CXXRecordDecl *Declaration) {

             for (CXXRecordDecl::ctor_iterator ctor = 
Declaration->ctor_begin(),
                         ctorEnd = Declaration->ctor_end(); ctor != 
ctorEnd; ++ctor) {
                 llvm::outs() << "Ctor name: " << 
ctor->getNameAsString() << "\n";
                 llvm::outs() << "Initializers: " << 
ctor->getNumCtorInitializers() << "\n";
             }

}

However, the getNumCtorInitializers() is always returning 0. Any ideas 
what is wrong here?

Thanks in advanced,

Miguel




More information about the cfe-dev mailing list