[cfe-dev] C++ Header File Parsing: Update

Raghavendra K raghavendrak at huawei.com
Thu May 30 02:09:14 PDT 2013


Hi,

calling getParent from the FieldDecl class yields container class. So it is always null.
I have changed the program not use getParent but directly cast to CXXRecordDecl.
Class X
{
  A obk;
  std::map<int,int> bobj;
};

As per the above class, i get 2 fieldDecl. 
First fieldDecl,refers to a local class A and am able to get its fields
Now second fieldDecl is a template, when i try to get CTemplateRecordDecl, it is givingNULL
is it bug in clang? Pls help how to proceed.

Code:
CXXRecordDecl* fieldClass = (*classfieldItr)->getType().getTypePtrOrNull()->getUnqualifiedDesugaredType()->getAsCXXRecordDecl();
 CXXRecordDecl* pCXXRecord = (CXXRecordDecl*)fieldClass->getDefinition();
                         if(pCXXRecord)
                         {
                            fprintf(flogs,"****1\n");
                            TemplateSpecializationKind tempKind = pCXXRecord->getTemplateSpecializationKind();
                            fprintf(flogs,"****TemplateKind=%d\n",(int)tempKind);
                            fprintf(flogs,"****Qualfier=%s\n",pCXXRecord->getQualifiedNameAsString().c_str());

                            ClassTemplateDecl* classTemp = pCXXRecord->getDescribedClassTemplate();=============>is NULL.
                            if(classTemp)
                            {
                              fprintf(flogs,"****2\n");
                              TemplateParameterList* tempList = classTemp->getTemplateParameters();
                              if(tempList)
                              fprintf(flogs,"****SOFAR SO GOOD\n");
                            }
                            MemberSpecializationInfo* memSpc = pCXXRecord->getMemberSpecializationInfo();
                            NamedDecl* pNamedDecl =  memSpc->getInstantiatedFrom();

                              fprintf(flogs,"****NamedDecl=%s\n",pNamedDecl->getNameAsString().c_str());







More information about the cfe-dev mailing list