[cfe-commits] r145107 - in /cfe/trunk: lib/Sema/SemaDeclObjC.cpp tools/libclang/IndexDecl.cpp tools/libclang/IndexingContext.cpp tools/libclang/IndexingContext.h

Argyrios Kyrtzidis akyrtzi at gmail.com
Wed Nov 23 12:27:26 PST 2011


Author: akirtzidis
Date: Wed Nov 23 14:27:26 2011
New Revision: 145107

URL: http://llvm.org/viewvc/llvm-project?rev=145107&view=rev
Log:
[libclang] Indexing API: Fix issues, mostly C++ related.

Modified:
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/tools/libclang/IndexDecl.cpp
    cfe/trunk/tools/libclang/IndexingContext.cpp
    cfe/trunk/tools/libclang/IndexingContext.h

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=145107&r1=145106&r2=145107&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed Nov 23 14:27:26 2011
@@ -817,9 +817,10 @@
     if (!CatIDecl) {
       // Category @implementation with no corresponding @interface.
       // Create and install one.
-      CatIDecl = ObjCCategoryDecl::Create(Context, CurContext, SourceLocation(),
-                                          SourceLocation(), SourceLocation(),
+      CatIDecl = ObjCCategoryDecl::Create(Context, CurContext, AtCatImplLoc,
+                                          ClassLoc, CatLoc,
                                           CatName, IDecl);
+      CatIDecl->setImplicit();
     }
   }
 

Modified: cfe/trunk/tools/libclang/IndexDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexDecl.cpp?rev=145107&r1=145106&r2=145107&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexDecl.cpp (original)
+++ cfe/trunk/tools/libclang/IndexDecl.cpp Wed Nov 23 14:27:26 2011
@@ -109,6 +109,9 @@
 
   bool VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
     const ObjCInterfaceDecl *Class = D->getClassInterface();
+    if (!Class)
+      return true;
+
     if (Class->isImplicitInterfaceDecl())
       IndexCtx.handleObjCInterface(Class);
 
@@ -128,7 +131,8 @@
   }
 
   bool VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
-    if (D->getCategoryDecl()->getLocation().isInvalid())
+    const ObjCCategoryDecl *Cat = D->getCategoryDecl();
+    if (!Cat)
       return true;
 
     IndexCtx.handleObjCCategoryImpl(D);

Modified: cfe/trunk/tools/libclang/IndexingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexingContext.cpp?rev=145107&r1=145106&r2=145107&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexingContext.cpp (original)
+++ cfe/trunk/tools/libclang/IndexingContext.cpp Wed Nov 23 14:27:26 2011
@@ -99,10 +99,13 @@
          I = D->bases_begin(), E = D->bases_end(); I != E; ++I) {
     const CXXBaseSpecifier &Base = *I;
     BaseEntities.push_back(EntityInfo());
-    const CXXRecordDecl *BaseRD = 0;
+    const NamedDecl *BaseD = 0;
     if (const RecordType *RT = Base.getType()->getAs<RecordType>())
-      BaseRD = dyn_cast_or_null<CXXRecordDecl>(RT->getDecl());
-    IdxCtx.getEntityInfo(BaseRD, BaseEntities.back(), SA);
+      BaseD = RT->getDecl();
+    else if (const TypedefType *TDT = Base.getType()->getAs<TypedefType>())
+      BaseD = TDT->getDecl();
+    if (BaseD)
+      IdxCtx.getEntityInfo(BaseD, BaseEntities.back(), SA);
     CXIdxBaseClassInfo BaseInfo = { 0,
                          MakeCursorCXXBaseSpecifier(&Base, IdxCtx.CXTU),
                          IdxCtx.getIndexLoc(Base.getSourceRange().getBegin()) };
@@ -110,7 +113,7 @@
   }
 
   for (unsigned i = 0, e = BaseInfos.size(); i != e; ++i) {
-    if (BaseEntities[i].USR)
+    if (BaseEntities[i].name && BaseEntities[i].USR)
       BaseInfos[i].base = &BaseEntities[i];
   }
 
@@ -123,9 +126,14 @@
     return "";
   if (Str.data()[Str.size()] == '\0')
     return Str.data();
-  Scratch += Str;
-  Scratch.push_back('\0');
-  return Scratch.data() + (Scratch.size() - Str.size() - 1);
+  return copyCStr(Str);
+}
+
+const char *IndexingContext::StrAdapter::copyCStr(StringRef Str) {
+  char *buf = IdxCtx.StrScratch.Allocate<char>(Str.size() + 1);
+  std::uninitialized_copy(Str.begin(), Str.end(), buf);
+  buf[Str.size()] = '\0';
+  return buf;
 }
 
 void IndexingContext::setASTContext(ASTContext &ctx) {
@@ -516,14 +524,21 @@
 
 bool IndexingContext::handleCXXRecordDecl(const CXXRecordDecl *RD,
                                           const NamedDecl *OrigD) {
-  StrAdapter SA(*this);
-  CXXClassDeclInfo DInfo(/*isRedeclaration=*/!OrigD->isCanonicalDecl(),
-                         /*isDefinition=*/RD->isThisDeclarationADefinition());
-  CXXBasesListInfo BaseList(RD, *this, SA);
-  DInfo.CXXClassInfo.declInfo = &DInfo;
-  DInfo.CXXClassInfo.bases = BaseList.getBases();
-  DInfo.CXXClassInfo.numBases = BaseList.getNumBases();
+  if (RD->isThisDeclarationADefinition()) {
+    StrAdapter SA(*this);
+    CXXClassDeclInfo CXXDInfo(/*isRedeclaration=*/!OrigD->isCanonicalDecl(),
+                           /*isDefinition=*/RD->isThisDeclarationADefinition());
+    CXXBasesListInfo BaseList(RD, *this, SA);
+    CXXDInfo.CXXClassInfo.declInfo = &CXXDInfo;
+    CXXDInfo.CXXClassInfo.bases = BaseList.getBases();
+    CXXDInfo.CXXClassInfo.numBases = BaseList.getNumBases();
+
+    return handleDecl(OrigD, OrigD->getLocation(), getCursor(OrigD), CXXDInfo);
+  }
 
+  DeclInfo DInfo(/*isRedeclaration=*/!OrigD->isCanonicalDecl(),
+                 /*isDefinition=*/RD->isThisDeclarationADefinition(),
+                 /*isContainer=*/RD->isThisDeclarationADefinition());
   return handleDecl(OrigD, OrigD->getLocation(), getCursor(OrigD), DInfo);
 }
 
@@ -675,7 +690,6 @@
 void IndexingContext::getEntityInfo(const NamedDecl *D,
                                     EntityInfo &EntityInfo,
                                     StrAdapter &SA) {
-  EntityInfo.name = EntityInfo.USR = 0;
   if (!D)
     return;
 
@@ -699,7 +713,8 @@
     }
 
     if (const CXXRecordDecl *CXXRec = dyn_cast<CXXRecordDecl>(D)) {
-      if (TD->getTagKind() == TTK_Struct && !CXXRec->isPOD())
+      if (TD->getTagKind() == TTK_Struct &&
+          CXXRec->hasDefinition() && !CXXRec->isPOD())
         EntityInfo.kind = CXIdxEntity_CXXClass;
     }
 
@@ -805,25 +820,25 @@
   if (IdentifierInfo *II = D->getIdentifier()) {
     EntityInfo.name = SA.toCStr(II->getName());
 
-  } else if (isa<RecordDecl>(D) || isa<NamespaceDecl>(D)) {
-    EntityInfo.name = 0; // anonymous record/namespace.
+  } else if (isa<TagDecl>(D) || isa<FieldDecl>(D) || isa<NamespaceDecl>(D)) {
+    EntityInfo.name = 0; // anonymous tag/field/namespace.
 
   } else {
-    unsigned Begin = SA.getCurSize();
+    llvm::SmallString<256> StrBuf;
     {
-      llvm::raw_svector_ostream OS(SA.getBuffer());
+      llvm::raw_svector_ostream OS(StrBuf);
       D->printName(OS);
     }
-    EntityInfo.name = SA.getCStr(Begin);
+    EntityInfo.name = SA.copyCStr(StrBuf.str());
   }
 
   {
-    unsigned Begin = SA.getCurSize();
-    bool Ignore = getDeclCursorUSR(D, SA.getBuffer());
+    llvm::SmallString<512> StrBuf;
+    bool Ignore = getDeclCursorUSR(D, StrBuf);
     if (Ignore) {
       EntityInfo.USR = 0;
     } else {
-      EntityInfo.USR = SA.getCStr(Begin);
+      EntityInfo.USR = SA.copyCStr(StrBuf.str());
     }
   }
 }
@@ -855,6 +870,10 @@
 }
 
 bool IndexingContext::shouldIgnoreIfImplicit(const NamedDecl *D) {
+  if (isa<ObjCInterfaceDecl>(D))
+    return false;
+  if (isa<ObjCCategoryDecl>(D))
+    return false;
   if (isa<ObjCIvarDecl>(D))
     return false;
   if (isa<ObjCMethodDecl>(D))

Modified: cfe/trunk/tools/libclang/IndexingContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexingContext.h?rev=145107&r1=145106&r2=145107&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexingContext.h (original)
+++ cfe/trunk/tools/libclang/IndexingContext.h Wed Nov 23 14:27:26 2011
@@ -28,6 +28,10 @@
 struct EntityInfo : public CXIdxEntityInfo {
   const NamedDecl *Dcl;
   IndexingContext *IndexCtx;
+
+  EntityInfo() {
+    name = USR = 0;
+  }
 };
 
 struct ContainerInfo : public CXIdxContainerInfo {
@@ -225,35 +229,25 @@
 
   SmallVector<DeclGroupRef, 8> TUDeclsInObjCContainer;
   
-  llvm::SmallString<256> StrScratch;
+  llvm::BumpPtrAllocator StrScratch;
   unsigned StrAdapterCount;
 
   class StrAdapter {
-    llvm::SmallString<256> &Scratch;
     IndexingContext &IdxCtx;
 
   public:
-    StrAdapter(IndexingContext &indexCtx)
-      : Scratch(indexCtx.StrScratch), IdxCtx(indexCtx) {
+    StrAdapter(IndexingContext &indexCtx) : IdxCtx(indexCtx) {
       ++IdxCtx.StrAdapterCount;
     }
 
     ~StrAdapter() {
       --IdxCtx.StrAdapterCount;
       if (IdxCtx.StrAdapterCount == 0)
-        Scratch.clear();
+        IdxCtx.StrScratch.Reset();
     }
 
     const char *toCStr(StringRef Str);
-
-    unsigned getCurSize() const { return Scratch.size(); }
-
-    const char *getCStr(unsigned CharIndex) {
-      Scratch.push_back('\0');
-      return Scratch.data() + CharIndex;
-    }
-
-    SmallVectorImpl<char> &getBuffer() { return Scratch; }
+    const char *copyCStr(StringRef Str);
   };
 
   struct ObjCProtocolListInfo {
@@ -305,7 +299,8 @@
   IndexingContext(CXClientData clientData, IndexerCallbacks &indexCallbacks,
                   unsigned indexOptions, CXTranslationUnit cxTU)
     : Ctx(0), ClientData(clientData), CB(indexCallbacks),
-      IndexOptions(indexOptions), CXTU(cxTU), StrAdapterCount(0) { }
+      IndexOptions(indexOptions), CXTU(cxTU),
+      StrScratch(/*size=*/1024), StrAdapterCount(0) { }
 
   ASTContext &getASTContext() const { return *Ctx; }
 





More information about the cfe-commits mailing list