Constructor Initializers

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

Hi,

Any ideas on this issue???

Thanks

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