2011-10-18 03:48:19 +08:00
|
|
|
//===- CIndexHigh.cpp - Higher level API functions ------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "IndexingContext.h"
|
|
|
|
#include "CXTranslationUnit.h"
|
|
|
|
#include "CIndexDiagnostic.h"
|
|
|
|
|
|
|
|
#include "clang/Frontend/ASTUnit.h"
|
2011-11-22 15:24:51 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2011-11-18 08:26:51 +08:00
|
|
|
#include "clang/AST/DeclTemplate.h"
|
2011-10-18 03:48:19 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
using namespace cxindex;
|
|
|
|
using namespace cxcursor;
|
|
|
|
|
2011-11-12 10:16:30 +08:00
|
|
|
IndexingContext::ObjCProtocolListInfo::ObjCProtocolListInfo(
|
|
|
|
const ObjCProtocolList &ProtList,
|
|
|
|
IndexingContext &IdxCtx,
|
|
|
|
StrAdapter &SA) {
|
|
|
|
ObjCInterfaceDecl::protocol_loc_iterator LI = ProtList.loc_begin();
|
|
|
|
for (ObjCInterfaceDecl::protocol_iterator
|
|
|
|
I = ProtList.begin(), E = ProtList.end(); I != E; ++I, ++LI) {
|
|
|
|
SourceLocation Loc = *LI;
|
|
|
|
ObjCProtocolDecl *PD = *I;
|
2011-11-22 15:24:51 +08:00
|
|
|
ProtEntities.push_back(EntityInfo());
|
2011-11-12 10:16:30 +08:00
|
|
|
IdxCtx.getEntityInfo(PD, ProtEntities.back(), SA);
|
|
|
|
CXIdxObjCProtocolRefInfo ProtInfo = { 0,
|
|
|
|
MakeCursorObjCProtocolRef(PD, Loc, IdxCtx.CXTU),
|
|
|
|
IdxCtx.getIndexLoc(Loc) };
|
|
|
|
ProtInfos.push_back(ProtInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = ProtInfos.size(); i != e; ++i)
|
|
|
|
ProtInfos[i].protocol = &ProtEntities[i];
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = ProtInfos.size(); i != e; ++i)
|
|
|
|
Prots.push_back(&ProtInfos[i]);
|
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
IndexingContext::AttrListInfo::AttrListInfo(const Decl *D,
|
|
|
|
IndexingContext &IdxCtx,
|
|
|
|
StrAdapter &SA) {
|
|
|
|
for (AttrVec::const_iterator AttrI = D->attr_begin(), AttrE = D->attr_end();
|
|
|
|
AttrI != AttrE; ++AttrI) {
|
|
|
|
const Attr *A = *AttrI;
|
|
|
|
CXCursor C = MakeCXCursor(A, const_cast<Decl *>(D), IdxCtx.CXTU);
|
|
|
|
CXIdxLoc Loc = IdxCtx.getIndexLoc(A->getLocation());
|
|
|
|
switch (C.kind) {
|
|
|
|
default:
|
|
|
|
Attrs.push_back(AttrInfo(CXIdxAttr_Unexposed, C, Loc, A));
|
|
|
|
break;
|
|
|
|
case CXCursor_IBActionAttr:
|
|
|
|
Attrs.push_back(AttrInfo(CXIdxAttr_IBAction, C, Loc, A));
|
|
|
|
break;
|
|
|
|
case CXCursor_IBOutletAttr:
|
|
|
|
Attrs.push_back(AttrInfo(CXIdxAttr_IBOutlet, C, Loc, A));
|
|
|
|
break;
|
|
|
|
case CXCursor_IBOutletCollectionAttr:
|
|
|
|
IBCollAttrs.push_back(IBOutletCollectionInfo(C, Loc, A));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = IBCollAttrs.size(); i != e; ++i) {
|
|
|
|
IBOutletCollectionInfo &IBInfo = IBCollAttrs[i];
|
|
|
|
CXAttrs.push_back(&IBInfo);
|
|
|
|
|
|
|
|
const IBOutletCollectionAttr *
|
|
|
|
IBAttr = cast<IBOutletCollectionAttr>(IBInfo.A);
|
|
|
|
IBInfo.IBCollInfo.attrInfo = &IBInfo;
|
|
|
|
IBInfo.IBCollInfo.classLoc = IdxCtx.getIndexLoc(IBAttr->getInterfaceLoc());
|
|
|
|
IBInfo.IBCollInfo.objcClass = 0;
|
|
|
|
IBInfo.IBCollInfo.classCursor = clang_getNullCursor();
|
|
|
|
QualType Ty = IBAttr->getInterface();
|
|
|
|
if (const ObjCInterfaceType *InterTy = Ty->getAs<ObjCInterfaceType>()) {
|
|
|
|
if (const ObjCInterfaceDecl *InterD = InterTy->getInterface()) {
|
2011-11-22 15:24:51 +08:00
|
|
|
IdxCtx.getEntityInfo(InterD, IBInfo.ClassInfo, SA);
|
|
|
|
IBInfo.IBCollInfo.objcClass = &IBInfo.ClassInfo;
|
2011-11-18 08:26:51 +08:00
|
|
|
IBInfo.IBCollInfo.classCursor = MakeCursorObjCClassRef(InterD,
|
|
|
|
IBAttr->getInterfaceLoc(), IdxCtx.CXTU);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = Attrs.size(); i != e; ++i)
|
|
|
|
CXAttrs.push_back(&Attrs[i]);
|
|
|
|
}
|
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
IndexingContext::CXXBasesListInfo::CXXBasesListInfo(const CXXRecordDecl *D,
|
|
|
|
IndexingContext &IdxCtx,
|
|
|
|
IndexingContext::StrAdapter &SA) {
|
|
|
|
for (CXXRecordDecl::base_class_const_iterator
|
|
|
|
I = D->bases_begin(), E = D->bases_end(); I != E; ++I) {
|
|
|
|
const CXXBaseSpecifier &Base = *I;
|
|
|
|
BaseEntities.push_back(EntityInfo());
|
2011-11-24 04:27:26 +08:00
|
|
|
const NamedDecl *BaseD = 0;
|
2011-11-22 15:24:51 +08:00
|
|
|
if (const RecordType *RT = Base.getType()->getAs<RecordType>())
|
2011-11-24 04:27:26 +08:00
|
|
|
BaseD = RT->getDecl();
|
|
|
|
else if (const TypedefType *TDT = Base.getType()->getAs<TypedefType>())
|
|
|
|
BaseD = TDT->getDecl();
|
|
|
|
if (BaseD)
|
|
|
|
IdxCtx.getEntityInfo(BaseD, BaseEntities.back(), SA);
|
2011-11-22 15:24:51 +08:00
|
|
|
CXIdxBaseClassInfo BaseInfo = { 0,
|
|
|
|
MakeCursorCXXBaseSpecifier(&Base, IdxCtx.CXTU),
|
|
|
|
IdxCtx.getIndexLoc(Base.getSourceRange().getBegin()) };
|
|
|
|
BaseInfos.push_back(BaseInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = BaseInfos.size(); i != e; ++i) {
|
2011-11-24 04:27:26 +08:00
|
|
|
if (BaseEntities[i].name && BaseEntities[i].USR)
|
2011-11-22 15:24:51 +08:00
|
|
|
BaseInfos[i].base = &BaseEntities[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = BaseInfos.size(); i != e; ++i)
|
|
|
|
CXBases.push_back(&BaseInfos[i]);
|
|
|
|
}
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
const char *IndexingContext::StrAdapter::toCStr(StringRef Str) {
|
|
|
|
if (Str.empty())
|
|
|
|
return "";
|
|
|
|
if (Str.data()[Str.size()] == '\0')
|
|
|
|
return Str.data();
|
2011-11-24 04:27:26 +08:00
|
|
|
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;
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void IndexingContext::setASTContext(ASTContext &ctx) {
|
|
|
|
Ctx = &ctx;
|
|
|
|
static_cast<ASTUnit*>(CXTU->TUData)->setASTContext(&ctx);
|
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool IndexingContext::shouldAbort() {
|
|
|
|
if (!CB.abortQuery)
|
|
|
|
return false;
|
|
|
|
return CB.abortQuery(ClientData, 0);
|
|
|
|
}
|
|
|
|
|
2011-11-11 08:23:36 +08:00
|
|
|
void IndexingContext::enteredMainFile(const FileEntry *File) {
|
|
|
|
if (File && CB.enteredMainFile) {
|
|
|
|
CXIdxClientFile idxFile = CB.enteredMainFile(ClientData, (CXFile)File, 0);
|
|
|
|
FileMap[File] = idxFile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
void IndexingContext::ppIncludedFile(SourceLocation hashLoc,
|
|
|
|
StringRef filename,
|
|
|
|
const FileEntry *File,
|
|
|
|
bool isImport, bool isAngled) {
|
|
|
|
if (!CB.ppIncludedFile)
|
|
|
|
return;
|
|
|
|
|
2011-11-11 08:23:36 +08:00
|
|
|
StrAdapter SA(*this);
|
2011-10-18 03:48:19 +08:00
|
|
|
CXIdxIncludedFileInfo Info = { getIndexLoc(hashLoc),
|
|
|
|
SA.toCStr(filename),
|
2011-11-11 08:23:36 +08:00
|
|
|
(CXFile)File,
|
2011-10-18 03:48:19 +08:00
|
|
|
isImport, isAngled };
|
2011-11-11 08:23:36 +08:00
|
|
|
CXIdxClientFile idxFile = CB.ppIncludedFile(ClientData, &Info);
|
|
|
|
FileMap[File] = idxFile;
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2011-11-12 10:16:30 +08:00
|
|
|
void IndexingContext::startedTranslationUnit() {
|
2011-11-11 08:23:36 +08:00
|
|
|
CXIdxClientContainer idxCont = 0;
|
2011-10-18 03:48:19 +08:00
|
|
|
if (CB.startedTranslationUnit)
|
|
|
|
idxCont = CB.startedTranslationUnit(ClientData, 0);
|
|
|
|
addContainerInMap(Ctx->getTranslationUnitDecl(), idxCont);
|
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
void IndexingContext::handleDiagnosticSet(CXDiagnostic CXDiagSet) {
|
2011-10-18 03:48:19 +08:00
|
|
|
if (!CB.diagnostic)
|
|
|
|
return;
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
CB.diagnostic(ClientData, CXDiagSet, 0);
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool IndexingContext::handleDecl(const NamedDecl *D,
|
2011-11-11 08:23:36 +08:00
|
|
|
SourceLocation Loc, CXCursor Cursor,
|
|
|
|
DeclInfo &DInfo) {
|
2011-11-18 08:26:46 +08:00
|
|
|
if (!CB.indexDeclaration || !D)
|
2011-11-18 08:26:51 +08:00
|
|
|
return false;
|
2011-11-22 15:24:51 +08:00
|
|
|
if (D->isImplicit() && shouldIgnoreIfImplicit(D))
|
|
|
|
return false;
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-11 08:23:36 +08:00
|
|
|
StrAdapter SA(*this);
|
2011-11-22 15:24:51 +08:00
|
|
|
getEntityInfo(D, DInfo.EntInfo, SA);
|
|
|
|
if (!DInfo.EntInfo.USR || Loc.isInvalid())
|
2011-11-18 08:26:51 +08:00
|
|
|
return false;
|
2011-11-18 08:26:46 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
markEntityOccurrenceInFile(D, Loc);
|
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
DInfo.entityInfo = &DInfo.EntInfo;
|
2011-11-11 08:23:36 +08:00
|
|
|
DInfo.cursor = Cursor;
|
|
|
|
DInfo.loc = getIndexLoc(Loc);
|
2011-11-15 06:39:19 +08:00
|
|
|
DInfo.isImplicit = D->isImplicit();
|
2011-11-11 08:23:36 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
AttrListInfo AttrList(D, *this, SA);
|
|
|
|
DInfo.attributes = AttrList.getAttrs();
|
|
|
|
DInfo.numAttributes = AttrList.getNumAttrs();
|
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
getContainerInfo(D->getDeclContext(), DInfo.Container);
|
|
|
|
DInfo.container = &DInfo.Container;
|
|
|
|
if (DInfo.isContainer) {
|
|
|
|
getContainerInfo(getEntityContainer(D), DInfo.DeclAsContainer);
|
|
|
|
DInfo.declAsContainer = &DInfo.DeclAsContainer;
|
|
|
|
}
|
2011-11-18 08:26:51 +08:00
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
CB.indexDeclaration(ClientData, &DInfo);
|
2011-11-18 08:26:51 +08:00
|
|
|
return true;
|
2011-11-11 08:23:36 +08:00
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool IndexingContext::handleObjCContainer(const ObjCContainerDecl *D,
|
2011-11-11 08:23:36 +08:00
|
|
|
SourceLocation Loc, CXCursor Cursor,
|
|
|
|
ObjCContainerDeclInfo &ContDInfo) {
|
2011-11-12 10:16:30 +08:00
|
|
|
ContDInfo.ObjCContDeclInfo.declInfo = &ContDInfo;
|
2011-11-18 08:26:51 +08:00
|
|
|
return handleDecl(D, Loc, Cursor, ContDInfo);
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool IndexingContext::handleFunction(const FunctionDecl *D) {
|
2011-11-15 06:39:19 +08:00
|
|
|
DeclInfo DInfo(!D->isFirstDeclaration(), D->isThisDeclarationADefinition(),
|
|
|
|
D->isThisDeclarationADefinition());
|
2011-11-18 08:26:51 +08:00
|
|
|
return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
2011-11-11 08:23:36 +08:00
|
|
|
}
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool IndexingContext::handleVar(const VarDecl *D) {
|
2011-11-15 06:39:19 +08:00
|
|
|
DeclInfo DInfo(!D->isFirstDeclaration(), D->isThisDeclarationADefinition(),
|
|
|
|
/*isContainer=*/false);
|
2011-11-18 08:26:51 +08:00
|
|
|
return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool IndexingContext::handleField(const FieldDecl *D) {
|
2011-11-15 06:39:19 +08:00
|
|
|
DeclInfo DInfo(/*isRedeclaration=*/false, /*isDefinition=*/true,
|
|
|
|
/*isContainer=*/false);
|
2011-11-18 08:26:51 +08:00
|
|
|
return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool IndexingContext::handleEnumerator(const EnumConstantDecl *D) {
|
2011-11-15 06:39:19 +08:00
|
|
|
DeclInfo DInfo(/*isRedeclaration=*/false, /*isDefinition=*/true,
|
|
|
|
/*isContainer=*/false);
|
2011-11-18 08:26:51 +08:00
|
|
|
return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool IndexingContext::handleTagDecl(const TagDecl *D) {
|
2011-11-22 15:24:51 +08:00
|
|
|
if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(D))
|
|
|
|
return handleCXXRecordDecl(CXXRD, D);
|
|
|
|
|
2011-11-15 06:39:19 +08:00
|
|
|
DeclInfo DInfo(!D->isFirstDeclaration(), D->isThisDeclarationADefinition(),
|
|
|
|
D->isThisDeclarationADefinition());
|
2011-11-18 08:26:51 +08:00
|
|
|
return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
bool IndexingContext::handleTypedefName(const TypedefNameDecl *D) {
|
2011-11-15 06:39:19 +08:00
|
|
|
DeclInfo DInfo(!D->isFirstDeclaration(), /*isDefinition=*/true,
|
|
|
|
/*isContainer=*/false);
|
2011-11-18 08:26:51 +08:00
|
|
|
return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
2011-11-11 08:23:36 +08:00
|
|
|
}
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool IndexingContext::handleObjCClass(const ObjCClassDecl *D) {
|
2011-11-11 08:23:36 +08:00
|
|
|
const ObjCClassDecl::ObjCClassRef *Ref = D->getForwardDecl();
|
|
|
|
ObjCInterfaceDecl *IFaceD = Ref->getInterface();
|
|
|
|
SourceLocation Loc = Ref->getLocation();
|
|
|
|
bool isRedeclaration = IFaceD->getLocation() != Loc;
|
2011-11-15 06:39:19 +08:00
|
|
|
|
|
|
|
ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/true, isRedeclaration,
|
|
|
|
/*isImplementation=*/false);
|
2011-11-18 08:26:51 +08:00
|
|
|
return handleObjCContainer(IFaceD, Loc,
|
|
|
|
MakeCursorObjCClassRef(IFaceD, Loc, CXTU), ContDInfo);
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool IndexingContext::handleObjCInterface(const ObjCInterfaceDecl *D) {
|
2011-11-12 10:16:30 +08:00
|
|
|
StrAdapter SA(*this);
|
|
|
|
|
|
|
|
CXIdxBaseClassInfo BaseClass;
|
2011-11-22 15:24:51 +08:00
|
|
|
EntityInfo BaseEntity;
|
2011-11-12 10:16:30 +08:00
|
|
|
BaseClass.cursor = clang_getNullCursor();
|
|
|
|
if (ObjCInterfaceDecl *SuperD = D->getSuperClass()) {
|
|
|
|
getEntityInfo(SuperD, BaseEntity, SA);
|
|
|
|
SourceLocation SuperLoc = D->getSuperClassLoc();
|
|
|
|
BaseClass.base = &BaseEntity;
|
|
|
|
BaseClass.cursor = MakeCursorObjCSuperClassRef(SuperD, SuperLoc, CXTU);
|
|
|
|
BaseClass.loc = getIndexLoc(SuperLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjCProtocolListInfo ProtInfo(D->getReferencedProtocols(), *this, SA);
|
|
|
|
|
2011-11-15 06:39:19 +08:00
|
|
|
ObjCInterfaceDeclInfo InterInfo(D);
|
|
|
|
InterInfo.ObjCProtoListInfo = ProtInfo.getListInfo();
|
|
|
|
InterInfo.ObjCInterDeclInfo.containerInfo = &InterInfo.ObjCContDeclInfo;
|
2011-11-12 10:16:30 +08:00
|
|
|
InterInfo.ObjCInterDeclInfo.superInfo = D->getSuperClass() ? &BaseClass : 0;
|
2011-11-15 06:39:19 +08:00
|
|
|
InterInfo.ObjCInterDeclInfo.protocols = &InterInfo.ObjCProtoListInfo;
|
2011-11-12 10:16:30 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
return handleObjCContainer(D, D->getLocation(), getCursor(D), InterInfo);
|
2011-11-11 08:23:36 +08:00
|
|
|
}
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool IndexingContext::handleObjCImplementation(
|
2011-11-11 08:23:36 +08:00
|
|
|
const ObjCImplementationDecl *D) {
|
2011-11-15 06:39:19 +08:00
|
|
|
ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/false,
|
2011-11-15 14:20:24 +08:00
|
|
|
/*isRedeclaration=*/true,
|
2011-11-15 06:39:19 +08:00
|
|
|
/*isImplementation=*/true);
|
2011-11-18 08:26:51 +08:00
|
|
|
return handleObjCContainer(D, D->getLocation(), getCursor(D), ContDInfo);
|
2011-11-11 08:23:36 +08:00
|
|
|
}
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool IndexingContext::handleObjCForwardProtocol(const ObjCProtocolDecl *D,
|
2011-11-11 08:23:36 +08:00
|
|
|
SourceLocation Loc,
|
|
|
|
bool isRedeclaration) {
|
2011-11-15 06:39:19 +08:00
|
|
|
ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/true,
|
|
|
|
isRedeclaration,
|
|
|
|
/*isImplementation=*/false);
|
2011-11-18 08:26:51 +08:00
|
|
|
return handleObjCContainer(D, Loc, MakeCursorObjCProtocolRef(D, Loc, CXTU),
|
|
|
|
ContDInfo);
|
2011-11-11 08:23:36 +08:00
|
|
|
}
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool IndexingContext::handleObjCProtocol(const ObjCProtocolDecl *D) {
|
2011-11-11 08:23:36 +08:00
|
|
|
StrAdapter SA(*this);
|
2011-11-12 10:16:30 +08:00
|
|
|
ObjCProtocolListInfo ProtListInfo(D->getReferencedProtocols(), *this, SA);
|
2011-11-11 08:23:36 +08:00
|
|
|
|
2011-11-15 06:39:19 +08:00
|
|
|
ObjCProtocolDeclInfo ProtInfo(D);
|
|
|
|
ProtInfo.ObjCProtoRefListInfo = ProtListInfo.getListInfo();
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
return handleObjCContainer(D, D->getLocation(), getCursor(D), ProtInfo);
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool IndexingContext::handleObjCCategory(const ObjCCategoryDecl *D) {
|
2011-11-15 06:39:19 +08:00
|
|
|
ObjCCategoryDeclInfo CatDInfo(/*isImplementation=*/false);
|
2011-11-22 15:24:51 +08:00
|
|
|
EntityInfo ClassEntity;
|
2011-11-11 08:23:36 +08:00
|
|
|
StrAdapter SA(*this);
|
2011-11-15 14:20:16 +08:00
|
|
|
const ObjCInterfaceDecl *IFaceD = D->getClassInterface();
|
|
|
|
SourceLocation ClassLoc = D->getLocation();
|
2011-11-18 08:26:51 +08:00
|
|
|
SourceLocation CategoryLoc = D->IsClassExtension() ? ClassLoc
|
|
|
|
: D->getCategoryNameLoc();
|
2011-11-16 10:34:59 +08:00
|
|
|
getEntityInfo(IFaceD, ClassEntity, SA);
|
2011-11-11 08:23:36 +08:00
|
|
|
|
2011-11-12 10:16:30 +08:00
|
|
|
CatDInfo.ObjCCatDeclInfo.containerInfo = &CatDInfo.ObjCContDeclInfo;
|
2011-11-16 10:34:59 +08:00
|
|
|
if (IFaceD) {
|
|
|
|
CatDInfo.ObjCCatDeclInfo.objcClass = &ClassEntity;
|
|
|
|
CatDInfo.ObjCCatDeclInfo.classCursor =
|
|
|
|
MakeCursorObjCClassRef(IFaceD, ClassLoc, CXTU);
|
|
|
|
} else {
|
|
|
|
CatDInfo.ObjCCatDeclInfo.objcClass = 0;
|
|
|
|
CatDInfo.ObjCCatDeclInfo.classCursor = clang_getNullCursor();
|
|
|
|
}
|
2011-11-15 14:20:16 +08:00
|
|
|
CatDInfo.ObjCCatDeclInfo.classLoc = getIndexLoc(ClassLoc);
|
2011-11-18 08:26:51 +08:00
|
|
|
return handleObjCContainer(D, CategoryLoc, getCursor(D), CatDInfo);
|
2011-11-11 08:23:36 +08:00
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool IndexingContext::handleObjCCategoryImpl(const ObjCCategoryImplDecl *D) {
|
2011-11-11 08:23:36 +08:00
|
|
|
const ObjCCategoryDecl *CatD = D->getCategoryDecl();
|
2011-11-15 06:39:19 +08:00
|
|
|
ObjCCategoryDeclInfo CatDInfo(/*isImplementation=*/true);
|
2011-11-22 15:24:51 +08:00
|
|
|
EntityInfo ClassEntity;
|
2011-11-11 08:23:36 +08:00
|
|
|
StrAdapter SA(*this);
|
2011-11-16 10:35:05 +08:00
|
|
|
const ObjCInterfaceDecl *IFaceD = CatD->getClassInterface();
|
|
|
|
SourceLocation ClassLoc = D->getLocation();
|
|
|
|
SourceLocation CategoryLoc = ClassLoc; //FIXME: D->getCategoryNameLoc();
|
|
|
|
getEntityInfo(IFaceD, ClassEntity, SA);
|
2011-11-11 08:23:36 +08:00
|
|
|
|
2011-11-12 10:16:30 +08:00
|
|
|
CatDInfo.ObjCCatDeclInfo.containerInfo = &CatDInfo.ObjCContDeclInfo;
|
2011-11-16 10:35:05 +08:00
|
|
|
if (IFaceD) {
|
|
|
|
CatDInfo.ObjCCatDeclInfo.objcClass = &ClassEntity;
|
|
|
|
CatDInfo.ObjCCatDeclInfo.classCursor =
|
|
|
|
MakeCursorObjCClassRef(IFaceD, ClassLoc, CXTU);
|
|
|
|
} else {
|
|
|
|
CatDInfo.ObjCCatDeclInfo.objcClass = 0;
|
|
|
|
CatDInfo.ObjCCatDeclInfo.classCursor = clang_getNullCursor();
|
|
|
|
}
|
|
|
|
CatDInfo.ObjCCatDeclInfo.classLoc = getIndexLoc(ClassLoc);
|
2011-11-18 08:26:51 +08:00
|
|
|
return handleObjCContainer(D, CategoryLoc, getCursor(D), CatDInfo);
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool IndexingContext::handleObjCMethod(const ObjCMethodDecl *D) {
|
2011-11-15 06:39:19 +08:00
|
|
|
DeclInfo DInfo(!D->isCanonicalDecl(), D->isThisDeclarationADefinition(),
|
|
|
|
D->isThisDeclarationADefinition());
|
2011-11-18 08:26:51 +08:00
|
|
|
return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IndexingContext::handleSynthesizedObjCProperty(
|
|
|
|
const ObjCPropertyImplDecl *D) {
|
|
|
|
ObjCPropertyDecl *PD = D->getPropertyDecl();
|
|
|
|
return handleReference(PD, D->getLocation(), getCursor(D), 0, D->getDeclContext());
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool IndexingContext::handleSynthesizedObjCMethod(const ObjCMethodDecl *D,
|
|
|
|
SourceLocation Loc) {
|
|
|
|
DeclInfo DInfo(/*isRedeclaration=*/true, /*isDefinition=*/true,
|
|
|
|
/*isContainer=*/false);
|
|
|
|
return handleDecl(D, Loc, getCursor(D), DInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IndexingContext::handleObjCProperty(const ObjCPropertyDecl *D) {
|
2011-11-15 06:39:19 +08:00
|
|
|
DeclInfo DInfo(/*isRedeclaration=*/false, /*isDefinition=*/false,
|
|
|
|
/*isContainer=*/false);
|
2011-11-18 08:26:51 +08:00
|
|
|
return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2011-12-07 13:52:06 +08:00
|
|
|
bool IndexingContext::handleNamespace(const NamespaceDecl *D) {
|
|
|
|
DeclInfo DInfo(/*isRedeclaration=*/!D->isOriginalNamespace(),
|
|
|
|
/*isDefinition=*/true,
|
|
|
|
/*isContainer=*/true);
|
|
|
|
return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
|
|
|
}
|
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
bool IndexingContext::handleClassTemplate(const ClassTemplateDecl *D) {
|
|
|
|
return handleCXXRecordDecl(D->getTemplatedDecl(), D);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IndexingContext::handleFunctionTemplate(const FunctionTemplateDecl *D) {
|
|
|
|
DeclInfo DInfo(/*isRedeclaration=*/!D->isCanonicalDecl(),
|
|
|
|
/*isDefinition=*/D->isThisDeclarationADefinition(),
|
|
|
|
/*isContainer=*/D->isThisDeclarationADefinition());
|
|
|
|
return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IndexingContext::handleTypeAliasTemplate(const TypeAliasTemplateDecl *D) {
|
|
|
|
DeclInfo DInfo(/*isRedeclaration=*/!D->isCanonicalDecl(),
|
|
|
|
/*isDefinition=*/true, /*isContainer=*/false);
|
|
|
|
return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc,
|
2011-10-18 03:48:19 +08:00
|
|
|
const NamedDecl *Parent,
|
|
|
|
const DeclContext *DC,
|
2011-10-18 23:50:50 +08:00
|
|
|
const Expr *E,
|
|
|
|
CXIdxEntityRefKind Kind) {
|
2011-11-16 10:35:01 +08:00
|
|
|
if (!D)
|
2011-11-18 08:26:51 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
CXCursor Cursor = E ? MakeCXCursor(const_cast<Expr*>(E),
|
|
|
|
const_cast<Decl*>(cast<Decl>(DC)), CXTU)
|
|
|
|
: getRefCursor(D, Loc);
|
|
|
|
return handleReference(D, Loc, Cursor, Parent, DC, E, Kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc,
|
|
|
|
CXCursor Cursor,
|
|
|
|
const NamedDecl *Parent,
|
|
|
|
const DeclContext *DC,
|
|
|
|
const Expr *E,
|
|
|
|
CXIdxEntityRefKind Kind) {
|
2011-11-22 15:24:51 +08:00
|
|
|
if (!CB.indexEntityReference)
|
2011-11-18 08:26:51 +08:00
|
|
|
return false;
|
2011-11-22 15:24:51 +08:00
|
|
|
|
|
|
|
if (!D)
|
2011-11-18 08:26:51 +08:00
|
|
|
return false;
|
2011-10-18 03:48:19 +08:00
|
|
|
if (Loc.isInvalid())
|
2011-11-18 08:26:51 +08:00
|
|
|
return false;
|
2011-11-22 15:24:51 +08:00
|
|
|
if (D->getParentFunctionOrMethod())
|
2011-11-18 08:26:51 +08:00
|
|
|
return false;
|
2011-10-18 03:48:19 +08:00
|
|
|
if (isNotFromSourceFile(D->getLocation()))
|
2011-11-18 08:26:51 +08:00
|
|
|
return false;
|
2011-11-22 15:24:51 +08:00
|
|
|
if (D->isImplicit() && shouldIgnoreIfImplicit(D))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (suppressRefs()) {
|
|
|
|
if (markEntityOccurrenceInFile(D, Loc))
|
|
|
|
return false; // already occurred.
|
|
|
|
}
|
2011-11-16 10:34:59 +08:00
|
|
|
|
2011-11-18 08:26:46 +08:00
|
|
|
StrAdapter SA(*this);
|
2011-11-22 15:24:51 +08:00
|
|
|
EntityInfo RefEntity, ParentEntity;
|
2011-11-18 08:26:46 +08:00
|
|
|
getEntityInfo(D, RefEntity, SA);
|
|
|
|
if (!RefEntity.USR)
|
2011-11-18 08:26:51 +08:00
|
|
|
return false;
|
2011-11-18 08:26:46 +08:00
|
|
|
|
|
|
|
getEntityInfo(Parent, ParentEntity, SA);
|
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
ContainerInfo Container;
|
|
|
|
getContainerInfo(DC, Container);
|
2011-11-16 10:34:59 +08:00
|
|
|
|
2011-10-28 21:37:11 +08:00
|
|
|
CXIdxEntityRefInfo Info = { Cursor,
|
2011-10-18 03:48:19 +08:00
|
|
|
getIndexLoc(Loc),
|
2011-11-11 08:23:36 +08:00
|
|
|
&RefEntity,
|
2011-11-16 10:34:59 +08:00
|
|
|
Parent ? &ParentEntity : 0,
|
2011-11-22 15:24:51 +08:00
|
|
|
&Container,
|
2011-10-18 23:50:50 +08:00
|
|
|
Kind };
|
2011-10-18 03:48:19 +08:00
|
|
|
CB.indexEntityReference(ClientData, &Info);
|
2011-11-18 08:26:51 +08:00
|
|
|
return true;
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IndexingContext::isNotFromSourceFile(SourceLocation Loc) const {
|
|
|
|
if (Loc.isInvalid())
|
|
|
|
return true;
|
|
|
|
SourceManager &SM = Ctx->getSourceManager();
|
|
|
|
SourceLocation FileLoc = SM.getFileLoc(Loc);
|
|
|
|
FileID FID = SM.getFileID(FileLoc);
|
|
|
|
return SM.getFileEntryForID(FID) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexingContext::addContainerInMap(const DeclContext *DC,
|
2011-11-11 08:23:36 +08:00
|
|
|
CXIdxClientContainer container) {
|
2011-11-22 15:24:51 +08:00
|
|
|
if (!DC)
|
|
|
|
return;
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
assert(getScopedContext(DC) == DC);
|
|
|
|
ContainerMapTy::iterator I = ContainerMap.find(DC);
|
|
|
|
if (I == ContainerMap.end()) {
|
|
|
|
if (container)
|
|
|
|
ContainerMap[DC] = container;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Allow changing the container of a previously seen DeclContext so we
|
|
|
|
// can handle invalid user code, like a function re-definition.
|
|
|
|
if (container)
|
|
|
|
I->second = container;
|
|
|
|
else
|
|
|
|
ContainerMap.erase(I);
|
|
|
|
}
|
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
CXIdxClientEntity IndexingContext::getClientEntity(const Decl *D) const {
|
|
|
|
if (!D)
|
|
|
|
return 0;
|
|
|
|
EntityMapTy::const_iterator I = EntityMap.find(D);
|
|
|
|
if (I == EntityMap.end())
|
|
|
|
return 0;
|
|
|
|
return I->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexingContext::setClientEntity(const Decl *D, CXIdxClientEntity client) {
|
|
|
|
if (!D)
|
|
|
|
return;
|
|
|
|
EntityMap[D] = client;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IndexingContext::handleCXXRecordDecl(const CXXRecordDecl *RD,
|
|
|
|
const NamedDecl *OrigD) {
|
2011-11-24 04:27:26 +08:00
|
|
|
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);
|
|
|
|
}
|
2011-11-22 15:24:51 +08:00
|
|
|
|
2011-11-24 04:27:26 +08:00
|
|
|
DeclInfo DInfo(/*isRedeclaration=*/!OrigD->isCanonicalDecl(),
|
|
|
|
/*isDefinition=*/RD->isThisDeclarationADefinition(),
|
|
|
|
/*isContainer=*/RD->isThisDeclarationADefinition());
|
2011-11-22 15:24:51 +08:00
|
|
|
return handleDecl(OrigD, OrigD->getLocation(), getCursor(OrigD), DInfo);
|
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool IndexingContext::markEntityOccurrenceInFile(const NamedDecl *D,
|
|
|
|
SourceLocation Loc) {
|
|
|
|
SourceManager &SM = Ctx->getSourceManager();
|
|
|
|
D = getEntityDecl(D);
|
|
|
|
|
|
|
|
std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
|
|
|
|
FileID FID = LocInfo.first;
|
|
|
|
if (FID.isInvalid())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
const FileEntry *FE = SM.getFileEntryForID(FID);
|
|
|
|
if (!FE)
|
|
|
|
return true;
|
|
|
|
RefFileOccurence RefOccur(FE, D);
|
|
|
|
std::pair<llvm::DenseSet<RefFileOccurence>::iterator, bool>
|
|
|
|
res = RefFileOccurences.insert(RefOccur);
|
|
|
|
if (!res.second)
|
|
|
|
return true; // already in map.
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
const NamedDecl *IndexingContext::getEntityDecl(const NamedDecl *D) const {
|
|
|
|
assert(D);
|
|
|
|
D = cast<NamedDecl>(D->getCanonicalDecl());
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
if (const ObjCImplementationDecl *
|
2011-10-18 03:48:19 +08:00
|
|
|
ImplD = dyn_cast<ObjCImplementationDecl>(D)) {
|
|
|
|
return getEntityDecl(ImplD->getClassInterface());
|
|
|
|
|
|
|
|
} else if (const ObjCCategoryImplDecl *
|
|
|
|
CatImplD = dyn_cast<ObjCCategoryImplDecl>(D)) {
|
|
|
|
return getEntityDecl(CatImplD->getCategoryDecl());
|
2011-11-22 15:24:51 +08:00
|
|
|
} else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
|
|
|
if (FunctionTemplateDecl *TemplD = FD->getDescribedFunctionTemplate())
|
|
|
|
return getEntityDecl(TemplD);
|
|
|
|
} else if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) {
|
|
|
|
if (ClassTemplateDecl *TemplD = RD->getDescribedClassTemplate())
|
|
|
|
return getEntityDecl(TemplD);
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return D;
|
|
|
|
}
|
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
const DeclContext *
|
|
|
|
IndexingContext::getEntityContainer(const Decl *D) const {
|
|
|
|
const DeclContext *DC = dyn_cast<DeclContext>(D);
|
|
|
|
if (DC)
|
|
|
|
return DC;
|
|
|
|
|
|
|
|
if (const ClassTemplateDecl *ClassTempl = dyn_cast<ClassTemplateDecl>(D)) {
|
|
|
|
DC = ClassTempl->getTemplatedDecl();
|
|
|
|
} if (const FunctionTemplateDecl *
|
|
|
|
FuncTempl = dyn_cast<FunctionTemplateDecl>(D)) {
|
|
|
|
DC = FuncTempl->getTemplatedDecl();
|
|
|
|
}
|
|
|
|
|
|
|
|
return DC;
|
|
|
|
}
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
const DeclContext *
|
|
|
|
IndexingContext::getScopedContext(const DeclContext *DC) const {
|
|
|
|
// Local contexts are ignored for indexing.
|
|
|
|
const DeclContext *FuncCtx = cast<Decl>(DC)->getParentFunctionOrMethod();
|
|
|
|
if (FuncCtx)
|
|
|
|
return FuncCtx;
|
|
|
|
|
|
|
|
// We consider enums always scoped for indexing.
|
|
|
|
if (isa<TagDecl>(DC))
|
|
|
|
return DC;
|
|
|
|
|
|
|
|
if (const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(DC)) {
|
|
|
|
if (NS->isAnonymousNamespace())
|
|
|
|
return getScopedContext(NS->getParent());
|
|
|
|
return NS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DC->getRedeclContext();
|
|
|
|
}
|
|
|
|
|
2011-11-11 08:23:36 +08:00
|
|
|
CXIdxClientContainer
|
2011-11-22 15:24:51 +08:00
|
|
|
IndexingContext::getClientContainerForDC(const DeclContext *DC) const {
|
|
|
|
if (!DC)
|
|
|
|
return 0;
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
DC = getScopedContext(DC);
|
|
|
|
ContainerMapTy::const_iterator I = ContainerMap.find(DC);
|
2011-11-16 10:35:05 +08:00
|
|
|
if (I == ContainerMap.end())
|
|
|
|
return 0;
|
2011-11-22 15:24:51 +08:00
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
return I->second;
|
|
|
|
}
|
|
|
|
|
2011-11-11 08:23:36 +08:00
|
|
|
CXIdxClientFile IndexingContext::getIndexFile(const FileEntry *File) {
|
2011-10-18 03:48:19 +08:00
|
|
|
if (!File)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
FileMapTy::iterator FI = FileMap.find(File);
|
|
|
|
if (FI != FileMap.end())
|
|
|
|
return FI->second;
|
|
|
|
|
2011-11-11 08:23:36 +08:00
|
|
|
return 0;
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CXIdxLoc IndexingContext::getIndexLoc(SourceLocation Loc) const {
|
|
|
|
CXIdxLoc idxLoc = { {0, 0}, 0 };
|
|
|
|
if (Loc.isInvalid())
|
|
|
|
return idxLoc;
|
|
|
|
|
|
|
|
idxLoc.ptr_data[0] = (void*)this;
|
|
|
|
idxLoc.int_data = Loc.getRawEncoding();
|
|
|
|
return idxLoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexingContext::translateLoc(SourceLocation Loc,
|
2011-11-11 08:23:36 +08:00
|
|
|
CXIdxClientFile *indexFile, CXFile *file,
|
2011-10-18 03:48:19 +08:00
|
|
|
unsigned *line, unsigned *column,
|
|
|
|
unsigned *offset) {
|
|
|
|
if (Loc.isInvalid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
SourceManager &SM = Ctx->getSourceManager();
|
|
|
|
Loc = SM.getFileLoc(Loc);
|
|
|
|
|
|
|
|
std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
|
|
|
|
FileID FID = LocInfo.first;
|
|
|
|
unsigned FileOffset = LocInfo.second;
|
|
|
|
|
|
|
|
if (FID.isInvalid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const FileEntry *FE = SM.getFileEntryForID(FID);
|
|
|
|
if (indexFile)
|
|
|
|
*indexFile = getIndexFile(FE);
|
|
|
|
if (file)
|
|
|
|
*file = (void *)FE;
|
|
|
|
if (line)
|
|
|
|
*line = SM.getLineNumber(FID, FileOffset);
|
|
|
|
if (column)
|
|
|
|
*column = SM.getColumnNumber(FID, FileOffset);
|
|
|
|
if (offset)
|
|
|
|
*offset = FileOffset;
|
|
|
|
}
|
|
|
|
|
2011-11-11 08:23:36 +08:00
|
|
|
void IndexingContext::getEntityInfo(const NamedDecl *D,
|
2011-11-22 15:24:51 +08:00
|
|
|
EntityInfo &EntityInfo,
|
|
|
|
StrAdapter &SA) {
|
2011-11-16 10:34:59 +08:00
|
|
|
if (!D)
|
|
|
|
return;
|
2011-11-22 15:24:51 +08:00
|
|
|
|
2011-11-11 08:23:36 +08:00
|
|
|
D = getEntityDecl(D);
|
2011-11-22 15:24:51 +08:00
|
|
|
EntityInfo.cursor = getCursor(D);
|
|
|
|
EntityInfo.Dcl = D;
|
|
|
|
EntityInfo.IndexCtx = this;
|
2011-11-11 08:23:36 +08:00
|
|
|
EntityInfo.kind = CXIdxEntity_Unexposed;
|
2011-11-22 15:24:51 +08:00
|
|
|
EntityInfo.templateKind = CXIdxEntity_NonTemplate;
|
2011-12-08 04:44:12 +08:00
|
|
|
EntityInfo.lang = CXIdxEntityLang_C;
|
2011-11-11 08:23:36 +08:00
|
|
|
|
|
|
|
if (const TagDecl *TD = dyn_cast<TagDecl>(D)) {
|
|
|
|
switch (TD->getTagKind()) {
|
|
|
|
case TTK_Struct:
|
|
|
|
EntityInfo.kind = CXIdxEntity_Struct; break;
|
|
|
|
case TTK_Union:
|
|
|
|
EntityInfo.kind = CXIdxEntity_Union; break;
|
|
|
|
case TTK_Class:
|
2011-12-08 04:44:12 +08:00
|
|
|
EntityInfo.kind = CXIdxEntity_CXXClass;
|
|
|
|
EntityInfo.lang = CXIdxEntityLang_CXX;
|
|
|
|
break;
|
2011-11-11 08:23:36 +08:00
|
|
|
case TTK_Enum:
|
|
|
|
EntityInfo.kind = CXIdxEntity_Enum; break;
|
|
|
|
}
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
if (const CXXRecordDecl *CXXRec = dyn_cast<CXXRecordDecl>(D)) {
|
2011-12-08 04:44:12 +08:00
|
|
|
// FIXME: isPOD check is not sufficient, a POD can contain methods,
|
|
|
|
// we want a isCStructLike check.
|
|
|
|
if (CXXRec->hasDefinition() && !CXXRec->isPOD())
|
|
|
|
EntityInfo.lang = CXIdxEntityLang_CXX;
|
2011-11-22 15:24:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isa<ClassTemplatePartialSpecializationDecl>(D)) {
|
|
|
|
EntityInfo.templateKind = CXIdxEntity_TemplatePartialSpecialization;
|
|
|
|
} else if (isa<ClassTemplateSpecializationDecl>(D)) {
|
|
|
|
EntityInfo.templateKind = CXIdxEntity_TemplateSpecialization;
|
|
|
|
}
|
|
|
|
|
2011-11-11 08:23:36 +08:00
|
|
|
} else {
|
|
|
|
switch (D->getKind()) {
|
|
|
|
case Decl::Typedef:
|
|
|
|
EntityInfo.kind = CXIdxEntity_Typedef; break;
|
|
|
|
case Decl::Function:
|
2011-11-22 15:24:51 +08:00
|
|
|
EntityInfo.kind = CXIdxEntity_Function;
|
|
|
|
break;
|
2011-11-11 08:23:36 +08:00
|
|
|
case Decl::Var:
|
2011-11-22 15:24:51 +08:00
|
|
|
EntityInfo.kind = CXIdxEntity_Variable;
|
2011-12-08 04:44:12 +08:00
|
|
|
if (isa<CXXRecordDecl>(D->getDeclContext())) {
|
2011-11-22 15:24:51 +08:00
|
|
|
EntityInfo.kind = CXIdxEntity_CXXStaticVariable;
|
2011-12-08 04:44:12 +08:00
|
|
|
EntityInfo.lang = CXIdxEntityLang_CXX;
|
|
|
|
}
|
2011-11-22 15:24:51 +08:00
|
|
|
break;
|
2011-11-11 08:23:36 +08:00
|
|
|
case Decl::Field:
|
2011-12-06 06:05:28 +08:00
|
|
|
EntityInfo.kind = CXIdxEntity_Field;
|
|
|
|
if (const CXXRecordDecl *
|
2011-12-08 04:44:12 +08:00
|
|
|
CXXRec = dyn_cast<CXXRecordDecl>(D->getDeclContext())) {
|
|
|
|
// FIXME: isPOD check is not sufficient, a POD can contain methods,
|
|
|
|
// we want a isCStructLike check.
|
2011-12-06 06:05:28 +08:00
|
|
|
if (!CXXRec->isPOD())
|
2011-12-08 04:44:12 +08:00
|
|
|
EntityInfo.lang = CXIdxEntityLang_CXX;
|
|
|
|
}
|
2011-12-06 06:05:28 +08:00
|
|
|
break;
|
2011-11-11 08:23:36 +08:00
|
|
|
case Decl::EnumConstant:
|
|
|
|
EntityInfo.kind = CXIdxEntity_EnumConstant; break;
|
|
|
|
case Decl::ObjCInterface:
|
2011-12-08 04:44:12 +08:00
|
|
|
EntityInfo.kind = CXIdxEntity_ObjCClass;
|
|
|
|
EntityInfo.lang = CXIdxEntityLang_ObjC;
|
|
|
|
break;
|
2011-11-11 08:23:36 +08:00
|
|
|
case Decl::ObjCProtocol:
|
2011-12-08 04:44:12 +08:00
|
|
|
EntityInfo.kind = CXIdxEntity_ObjCProtocol;
|
|
|
|
EntityInfo.lang = CXIdxEntityLang_ObjC;
|
|
|
|
break;
|
2011-11-11 08:23:36 +08:00
|
|
|
case Decl::ObjCCategory:
|
2011-12-08 04:44:12 +08:00
|
|
|
EntityInfo.kind = CXIdxEntity_ObjCCategory;
|
|
|
|
EntityInfo.lang = CXIdxEntityLang_ObjC;
|
|
|
|
break;
|
2011-11-11 08:23:36 +08:00
|
|
|
case Decl::ObjCMethod:
|
2011-11-15 06:39:19 +08:00
|
|
|
if (cast<ObjCMethodDecl>(D)->isInstanceMethod())
|
|
|
|
EntityInfo.kind = CXIdxEntity_ObjCInstanceMethod;
|
|
|
|
else
|
|
|
|
EntityInfo.kind = CXIdxEntity_ObjCClassMethod;
|
2011-12-08 04:44:12 +08:00
|
|
|
EntityInfo.lang = CXIdxEntityLang_ObjC;
|
2011-11-15 06:39:19 +08:00
|
|
|
break;
|
2011-11-11 08:23:36 +08:00
|
|
|
case Decl::ObjCProperty:
|
2011-12-08 04:44:12 +08:00
|
|
|
EntityInfo.kind = CXIdxEntity_ObjCProperty;
|
|
|
|
EntityInfo.lang = CXIdxEntityLang_ObjC;
|
|
|
|
break;
|
2011-11-11 08:23:36 +08:00
|
|
|
case Decl::ObjCIvar:
|
2011-12-08 04:44:12 +08:00
|
|
|
EntityInfo.kind = CXIdxEntity_ObjCIvar;
|
|
|
|
EntityInfo.lang = CXIdxEntityLang_ObjC;
|
|
|
|
break;
|
2011-11-22 15:24:51 +08:00
|
|
|
case Decl::Namespace:
|
2011-12-08 04:44:12 +08:00
|
|
|
EntityInfo.kind = CXIdxEntity_CXXNamespace;
|
|
|
|
EntityInfo.lang = CXIdxEntityLang_CXX;
|
|
|
|
break;
|
2011-11-22 15:24:51 +08:00
|
|
|
case Decl::NamespaceAlias:
|
2011-12-08 04:44:12 +08:00
|
|
|
EntityInfo.kind = CXIdxEntity_CXXNamespaceAlias;
|
|
|
|
EntityInfo.lang = CXIdxEntityLang_CXX;
|
|
|
|
break;
|
2011-11-22 15:24:51 +08:00
|
|
|
case Decl::CXXConstructor:
|
2011-12-08 04:44:12 +08:00
|
|
|
EntityInfo.kind = CXIdxEntity_CXXConstructor;
|
|
|
|
EntityInfo.lang = CXIdxEntityLang_CXX;
|
|
|
|
break;
|
2011-11-22 15:24:51 +08:00
|
|
|
case Decl::CXXDestructor:
|
2011-12-08 04:44:12 +08:00
|
|
|
EntityInfo.kind = CXIdxEntity_CXXDestructor;
|
|
|
|
EntityInfo.lang = CXIdxEntityLang_CXX;
|
|
|
|
break;
|
2011-11-22 15:24:51 +08:00
|
|
|
case Decl::CXXConversion:
|
2011-12-08 04:44:12 +08:00
|
|
|
EntityInfo.kind = CXIdxEntity_CXXConversionFunction;
|
|
|
|
EntityInfo.lang = CXIdxEntityLang_CXX;
|
|
|
|
break;
|
2011-11-22 15:24:51 +08:00
|
|
|
case Decl::CXXMethod: {
|
|
|
|
const CXXMethodDecl *MD = cast<CXXMethodDecl>(D);
|
|
|
|
if (MD->isStatic())
|
|
|
|
EntityInfo.kind = CXIdxEntity_CXXStaticMethod;
|
|
|
|
else
|
|
|
|
EntityInfo.kind = CXIdxEntity_CXXInstanceMethod;
|
2011-12-08 04:44:12 +08:00
|
|
|
EntityInfo.lang = CXIdxEntityLang_CXX;
|
2011-11-22 15:24:51 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::ClassTemplate:
|
|
|
|
EntityInfo.kind = CXIdxEntity_CXXClass;
|
|
|
|
EntityInfo.templateKind = CXIdxEntity_Template;
|
|
|
|
break;
|
|
|
|
case Decl::FunctionTemplate:
|
|
|
|
EntityInfo.kind = CXIdxEntity_Function;
|
|
|
|
EntityInfo.templateKind = CXIdxEntity_Template;
|
|
|
|
if (const CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>(
|
|
|
|
cast<FunctionTemplateDecl>(D)->getTemplatedDecl())) {
|
|
|
|
if (isa<CXXConstructorDecl>(MD))
|
|
|
|
EntityInfo.kind = CXIdxEntity_CXXConstructor;
|
|
|
|
else if (isa<CXXDestructorDecl>(MD))
|
|
|
|
EntityInfo.kind = CXIdxEntity_CXXDestructor;
|
|
|
|
else if (isa<CXXConversionDecl>(MD))
|
|
|
|
EntityInfo.kind = CXIdxEntity_CXXConversionFunction;
|
|
|
|
else {
|
|
|
|
if (MD->isStatic())
|
|
|
|
EntityInfo.kind = CXIdxEntity_CXXStaticMethod;
|
|
|
|
else
|
|
|
|
EntityInfo.kind = CXIdxEntity_CXXInstanceMethod;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Decl::TypeAliasTemplate:
|
|
|
|
EntityInfo.kind = CXIdxEntity_CXXTypeAlias;
|
|
|
|
EntityInfo.templateKind = CXIdxEntity_Template;
|
|
|
|
break;
|
|
|
|
case Decl::TypeAlias:
|
2011-12-08 04:44:12 +08:00
|
|
|
EntityInfo.kind = CXIdxEntity_CXXTypeAlias;
|
|
|
|
EntityInfo.lang = CXIdxEntityLang_CXX;
|
|
|
|
break;
|
2011-11-11 08:23:36 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
if (EntityInfo.kind == CXIdxEntity_Unexposed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
|
|
|
if (FD->getTemplatedKind() ==
|
|
|
|
FunctionDecl::TK_FunctionTemplateSpecialization)
|
|
|
|
EntityInfo.templateKind = CXIdxEntity_TemplateSpecialization;
|
|
|
|
}
|
|
|
|
|
2011-12-08 04:44:12 +08:00
|
|
|
if (EntityInfo.templateKind != CXIdxEntity_NonTemplate)
|
|
|
|
EntityInfo.lang = CXIdxEntityLang_CXX;
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
if (IdentifierInfo *II = D->getIdentifier()) {
|
|
|
|
EntityInfo.name = SA.toCStr(II->getName());
|
|
|
|
|
2011-11-24 04:27:26 +08:00
|
|
|
} else if (isa<TagDecl>(D) || isa<FieldDecl>(D) || isa<NamespaceDecl>(D)) {
|
|
|
|
EntityInfo.name = 0; // anonymous tag/field/namespace.
|
2011-10-18 03:48:19 +08:00
|
|
|
|
|
|
|
} else {
|
2011-11-24 04:27:26 +08:00
|
|
|
llvm::SmallString<256> StrBuf;
|
2011-10-18 03:48:19 +08:00
|
|
|
{
|
2011-11-24 04:27:26 +08:00
|
|
|
llvm::raw_svector_ostream OS(StrBuf);
|
2011-10-18 03:48:19 +08:00
|
|
|
D->printName(OS);
|
|
|
|
}
|
2011-11-24 04:27:26 +08:00
|
|
|
EntityInfo.name = SA.copyCStr(StrBuf.str());
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2011-11-11 08:23:36 +08:00
|
|
|
{
|
2011-11-24 04:27:26 +08:00
|
|
|
llvm::SmallString<512> StrBuf;
|
|
|
|
bool Ignore = getDeclCursorUSR(D, StrBuf);
|
2011-11-11 08:23:36 +08:00
|
|
|
if (Ignore) {
|
2011-11-18 08:26:46 +08:00
|
|
|
EntityInfo.USR = 0;
|
2011-11-11 08:23:36 +08:00
|
|
|
} else {
|
2011-11-24 04:27:26 +08:00
|
|
|
EntityInfo.USR = SA.copyCStr(StrBuf.str());
|
2011-11-11 08:23:36 +08:00
|
|
|
}
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
void IndexingContext::getContainerInfo(const DeclContext *DC,
|
|
|
|
ContainerInfo &ContInfo) {
|
|
|
|
ContInfo.cursor = getCursor(cast<Decl>(DC));
|
|
|
|
ContInfo.DC = DC;
|
|
|
|
ContInfo.IndexCtx = this;
|
|
|
|
}
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
CXCursor IndexingContext::getRefCursor(const NamedDecl *D, SourceLocation Loc) {
|
|
|
|
if (const TypeDecl *TD = dyn_cast<TypeDecl>(D))
|
|
|
|
return MakeCursorTypeRef(TD, Loc, CXTU);
|
|
|
|
if (const ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D))
|
|
|
|
return MakeCursorObjCClassRef(ID, Loc, CXTU);
|
|
|
|
if (const ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D))
|
|
|
|
return MakeCursorObjCProtocolRef(PD, Loc, CXTU);
|
2011-11-18 08:26:51 +08:00
|
|
|
if (const TemplateDecl *Template = dyn_cast<TemplateDecl>(D))
|
|
|
|
return MakeCursorTemplateRef(Template, Loc, CXTU);
|
|
|
|
if (const NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(D))
|
|
|
|
return MakeCursorNamespaceRef(Namespace, Loc, CXTU);
|
|
|
|
if (const NamespaceAliasDecl *Namespace = dyn_cast<NamespaceAliasDecl>(D))
|
|
|
|
return MakeCursorNamespaceRef(Namespace, Loc, CXTU);
|
|
|
|
if (const FieldDecl *Field = dyn_cast<FieldDecl>(D))
|
|
|
|
return MakeCursorMemberRef(Field, Loc, CXTU);
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
2011-11-22 15:24:51 +08:00
|
|
|
|
|
|
|
bool IndexingContext::shouldIgnoreIfImplicit(const NamedDecl *D) {
|
2011-11-24 04:27:26 +08:00
|
|
|
if (isa<ObjCInterfaceDecl>(D))
|
|
|
|
return false;
|
|
|
|
if (isa<ObjCCategoryDecl>(D))
|
|
|
|
return false;
|
2011-11-22 15:24:51 +08:00
|
|
|
if (isa<ObjCIvarDecl>(D))
|
|
|
|
return false;
|
|
|
|
if (isa<ObjCMethodDecl>(D))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|