[cfe-dev] Constructor Initializers

Jordan Rose jordan_rose at apple.com
Tue Jan 29 09:12:27 PST 2013


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 Jan 29, 2013, at 1:20 , Miguel Aguilar <miguel.aguilar at ice.rwth-aachen.de> wrote:

> Hi,
> 
> Any ideas on this issue???
> 
> Thanks
> 
> On 01/25/2013 05:07 PM, Miguel Aguilar wrote:
>> 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
>> 
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
> 
> _______________________________________________
> 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