aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-11-23 20:27:26 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-11-23 20:27:26 +0000
commit37f40572c4c78a8c57a7b45266f8b86db172a7c1 (patch)
tree453704e8a6b69639f39b4eeeff13cec1df9d9657
parenta6d81f9a2d236ae21491455f649ea765123f6fc7 (diff)
[libclang] Indexing API: Fix issues, mostly C++ related.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145107 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaDeclObjC.cpp5
-rw-r--r--tools/libclang/IndexDecl.cpp6
-rw-r--r--tools/libclang/IndexingContext.cpp67
-rw-r--r--tools/libclang/IndexingContext.h25
4 files changed, 61 insertions, 42 deletions
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index f4e2fb3205..ebb0cb5463 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -817,9 +817,10 @@ Decl *Sema::ActOnStartCategoryImplementation(
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();
}
}
diff --git a/tools/libclang/IndexDecl.cpp b/tools/libclang/IndexDecl.cpp
index 777dea1d15..0970054575 100644
--- a/tools/libclang/IndexDecl.cpp
+++ b/tools/libclang/IndexDecl.cpp
@@ -109,6 +109,9 @@ public:
bool VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
const ObjCInterfaceDecl *Class = D->getClassInterface();
+ if (!Class)
+ return true;
+
if (Class->isImplicitInterfaceDecl())
IndexCtx.handleObjCInterface(Class);
@@ -128,7 +131,8 @@ public:
}
bool VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
- if (D->getCategoryDecl()->getLocation().isInvalid())
+ const ObjCCategoryDecl *Cat = D->getCategoryDecl();
+ if (!Cat)
return true;
IndexCtx.handleObjCCategoryImpl(D);
diff --git a/tools/libclang/IndexingContext.cpp b/tools/libclang/IndexingContext.cpp
index 77d4801113..07c3b4dfb2 100644
--- a/tools/libclang/IndexingContext.cpp
+++ b/tools/libclang/IndexingContext.cpp
@@ -99,10 +99,13 @@ IndexingContext::CXXBasesListInfo::CXXBasesListInfo(const CXXRecordDecl *D,
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 @@ IndexingContext::CXXBasesListInfo::CXXBasesListInfo(const CXXRecordDecl *D,
}
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 @@ const char *IndexingContext::StrAdapter::toCStr(StringRef Str) {
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 @@ void IndexingContext::setClientEntity(const Decl *D, CXIdxClientEntity client) {
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::translateLoc(SourceLocation Loc,
void IndexingContext::getEntityInfo(const NamedDecl *D,
EntityInfo &EntityInfo,
StrAdapter &SA) {
- EntityInfo.name = EntityInfo.USR = 0;
if (!D)
return;
@@ -699,7 +713,8 @@ void IndexingContext::getEntityInfo(const NamedDecl *D,
}
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 @@ void IndexingContext::getEntityInfo(const NamedDecl *D,
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 @@ CXCursor IndexingContext::getRefCursor(const NamedDecl *D, SourceLocation Loc) {
}
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))
diff --git a/tools/libclang/IndexingContext.h b/tools/libclang/IndexingContext.h
index cbf96d8dbb..9a9fb3f4f0 100644
--- a/tools/libclang/IndexingContext.h
+++ b/tools/libclang/IndexingContext.h
@@ -28,6 +28,10 @@ namespace cxindex {
struct EntityInfo : public CXIdxEntityInfo {
const NamedDecl *Dcl;
IndexingContext *IndexCtx;
+
+ EntityInfo() {
+ name = USR = 0;
+ }
};
struct ContainerInfo : public CXIdxContainerInfo {
@@ -225,35 +229,25 @@ class IndexingContext {
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 @@ public:
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; }