2012-10-29 14:03:40 +08:00
|
|
|
//===- IndexingContext.cpp - Higher level API functions -------------------===//
|
2011-10-18 03:48:19 +08:00
|
|
|
//
|
|
|
|
// 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 "CIndexDiagnostic.h"
|
2012-12-04 17:25:21 +08:00
|
|
|
#include "CXTranslationUnit.h"
|
Remove unnecessary inclusion of Sema.h
Let me tell you a tale...
Within some twisted maze of debug info I've ended up implementing an
insane man's Include What You Use device. When the debugger emits debug
info it really shouldn't, I find out why & then realize the code could
be improved too.
In this instance CIndexDiagnostics.cpp had a lot more debug info with
Clang than GCC. Upon inspection a major culprit was all the debug info
describing clang::Sema. This was emitted because clang::Sema is
befriended by DiagnosticEngine which was rightly required, but GCC
doesn't emit debug info for friends so it never emitted anything for
Clang. Clang does emit debug info for friends (will be fixed/changed to
reduce debug info size).
But why didn't Clang just emit a declaration of Sema if this entire TU
didn't require a definition?
1) Diagnostic.h did the right thing, only using a declaration of Sema
and not including Sema.h at all.
2) Some other dependency of CIndexDiagnostics.cpp didn't do the right
thing. ASTUnit.h, only needing a declaration, still included Sema.h
(hence this commit which removes that include and adds the necessary
includes to the cpp files that were relying on this)
3) -flimit-debug-info didn't save us because of
EnterExpressionEvaluationContext, defined inline in Sema.h which fires
the "requiresCompleteType" check/flag (since it uses nested types from
Sema and calls Sema member functions) and thus, if debug info is ever
emitted for the type, the whole type is emitted and not just a
declaration.
Improving -flimit-debug-info to account for this would be... hard.
Modifying the code so that's not 'required to be complete' might be
possible, but probably only by moving EnterExpressionEvaluationContext
either into Sema, or out of Sema.h. That might be a bit too much of a
contortion to be bothered with.
Also, this is only one of the cases where emitting debug info for
friends caused us to emit a lot more debug info (this change reduces
Clang's DWO size by 0.93%, dropping friends entirely reduces debug info
by 3.2%) - I haven't hunted down the other cases, but I assume they
might be similar (Sema or something like it). IWYU or a similar tool
might help us reduce build times a bit, but analyzing debug info to find
these differences isn't worthwhile. I'll take the 3.2% win, provide this
small improvement to the code itself, and move on.
llvm-svn: 190715
2013-09-14 02:32:52 +08:00
|
|
|
#include "clang/AST/Attr.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"
|
2012-12-04 17:25:21 +08:00
|
|
|
#include "clang/Frontend/ASTUnit.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,
|
2011-12-15 08:05:00 +08:00
|
|
|
ScratchAlloc &SA) {
|
2011-11-12 10:16:30 +08:00
|
|
|
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);
|
2011-12-15 08:04:56 +08:00
|
|
|
|
2012-02-15 06:23:11 +08:00
|
|
|
if (IdxCtx.shouldSuppressRefs())
|
2011-12-15 08:04:56 +08:00
|
|
|
IdxCtx.markEntityOccurrenceInFile(PD, Loc);
|
2011-11-12 10:16:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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-12-15 08:05:00 +08:00
|
|
|
|
|
|
|
IBOutletCollectionInfo::IBOutletCollectionInfo(
|
|
|
|
const IBOutletCollectionInfo &other)
|
2012-01-20 09:38:51 +08:00
|
|
|
: AttrInfo(CXIdxAttr_IBOutletCollection, other.cursor, other.loc, other.A) {
|
2011-12-15 08:05:00 +08:00
|
|
|
|
|
|
|
IBCollInfo.attrInfo = this;
|
|
|
|
IBCollInfo.classCursor = other.IBCollInfo.classCursor;
|
|
|
|
IBCollInfo.classLoc = other.IBCollInfo.classLoc;
|
|
|
|
if (other.IBCollInfo.objcClass) {
|
|
|
|
ClassInfo = other.ClassInfo;
|
|
|
|
IBCollInfo.objcClass = &ClassInfo;
|
|
|
|
} else
|
|
|
|
IBCollInfo.objcClass = 0;
|
|
|
|
}
|
|
|
|
|
2012-03-31 09:14:06 +08:00
|
|
|
AttrListInfo::AttrListInfo(const Decl *D, IndexingContext &IdxCtx)
|
|
|
|
: SA(IdxCtx), ref_cnt(0) {
|
|
|
|
|
2011-12-15 08:05:00 +08:00
|
|
|
if (!D->hasAttrs())
|
|
|
|
return;
|
|
|
|
|
2014-03-09 06:19:01 +08:00
|
|
|
for (const auto *A : D->attrs()) {
|
2013-01-14 08:46:27 +08:00
|
|
|
CXCursor C = MakeCXCursor(A, D, IdxCtx.CXTU);
|
2011-11-18 08:26:51 +08:00
|
|
|
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);
|
2013-11-01 05:23:20 +08:00
|
|
|
SourceLocation InterfaceLocStart =
|
|
|
|
IBAttr->getInterfaceLoc()->getTypeLoc().getLocStart();
|
2011-11-18 08:26:51 +08:00
|
|
|
IBInfo.IBCollInfo.attrInfo = &IBInfo;
|
2013-11-01 05:23:20 +08:00
|
|
|
IBInfo.IBCollInfo.classLoc = IdxCtx.getIndexLoc(InterfaceLocStart);
|
2011-11-18 08:26:51 +08:00
|
|
|
IBInfo.IBCollInfo.objcClass = 0;
|
|
|
|
IBInfo.IBCollInfo.classCursor = clang_getNullCursor();
|
|
|
|
QualType Ty = IBAttr->getInterface();
|
2013-10-31 09:56:18 +08:00
|
|
|
if (const ObjCObjectType *ObjectTy = Ty->getAs<ObjCObjectType>()) {
|
|
|
|
if (const ObjCInterfaceDecl *InterD = ObjectTy->getInterface()) {
|
2011-11-22 15:24:51 +08:00
|
|
|
IdxCtx.getEntityInfo(InterD, IBInfo.ClassInfo, SA);
|
|
|
|
IBInfo.IBCollInfo.objcClass = &IBInfo.ClassInfo;
|
2013-11-01 05:23:20 +08:00
|
|
|
IBInfo.IBCollInfo.classCursor =
|
|
|
|
MakeCursorObjCClassRef(InterD, InterfaceLocStart, IdxCtx.CXTU);
|
2011-11-18 08:26:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = Attrs.size(); i != e; ++i)
|
|
|
|
CXAttrs.push_back(&Attrs[i]);
|
|
|
|
}
|
|
|
|
|
2012-03-31 09:14:06 +08:00
|
|
|
IntrusiveRefCntPtr<AttrListInfo>
|
|
|
|
AttrListInfo::create(const Decl *D, IndexingContext &IdxCtx) {
|
|
|
|
ScratchAlloc SA(IdxCtx);
|
|
|
|
AttrListInfo *attrs = SA.allocate<AttrListInfo>();
|
|
|
|
return new (attrs) AttrListInfo(D, IdxCtx);
|
2011-12-15 08:05:00 +08:00
|
|
|
}
|
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
IndexingContext::CXXBasesListInfo::CXXBasesListInfo(const CXXRecordDecl *D,
|
|
|
|
IndexingContext &IdxCtx,
|
2011-12-15 08:05:00 +08:00
|
|
|
ScratchAlloc &SA) {
|
2011-11-22 15:24:51 +08:00
|
|
|
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-12-08 04:44:15 +08:00
|
|
|
QualType T = Base.getType();
|
|
|
|
SourceLocation Loc = getBaseLoc(Base);
|
|
|
|
|
|
|
|
if (const TypedefType *TDT = T->getAs<TypedefType>()) {
|
2011-11-24 04:27:26 +08:00
|
|
|
BaseD = TDT->getDecl();
|
2011-12-08 04:44:15 +08:00
|
|
|
} else if (const TemplateSpecializationType *
|
|
|
|
TST = T->getAs<TemplateSpecializationType>()) {
|
|
|
|
BaseD = TST->getTemplateName().getAsTemplateDecl();
|
|
|
|
} else if (const RecordType *RT = T->getAs<RecordType>()) {
|
|
|
|
BaseD = RT->getDecl();
|
|
|
|
}
|
|
|
|
|
2011-11-24 04:27:26 +08:00
|
|
|
if (BaseD)
|
|
|
|
IdxCtx.getEntityInfo(BaseD, BaseEntities.back(), SA);
|
2011-11-22 15:24:51 +08:00
|
|
|
CXIdxBaseClassInfo BaseInfo = { 0,
|
|
|
|
MakeCursorCXXBaseSpecifier(&Base, IdxCtx.CXTU),
|
2011-12-08 04:44:15 +08:00
|
|
|
IdxCtx.getIndexLoc(Loc) };
|
2011-11-22 15:24:51 +08:00
|
|
|
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-12-08 04:44:15 +08:00
|
|
|
SourceLocation IndexingContext::CXXBasesListInfo::getBaseLoc(
|
|
|
|
const CXXBaseSpecifier &Base) const {
|
|
|
|
SourceLocation Loc = Base.getSourceRange().getBegin();
|
|
|
|
TypeLoc TL;
|
|
|
|
if (Base.getTypeSourceInfo())
|
|
|
|
TL = Base.getTypeSourceInfo()->getTypeLoc();
|
|
|
|
if (TL.isNull())
|
|
|
|
return Loc;
|
|
|
|
|
2013-02-19 06:06:02 +08:00
|
|
|
if (QualifiedTypeLoc QL = TL.getAs<QualifiedTypeLoc>())
|
|
|
|
TL = QL.getUnqualifiedLoc();
|
|
|
|
|
|
|
|
if (ElaboratedTypeLoc EL = TL.getAs<ElaboratedTypeLoc>())
|
|
|
|
return EL.getNamedTypeLoc().getBeginLoc();
|
|
|
|
if (DependentNameTypeLoc DL = TL.getAs<DependentNameTypeLoc>())
|
|
|
|
return DL.getNameLoc();
|
|
|
|
if (DependentTemplateSpecializationTypeLoc DTL =
|
|
|
|
TL.getAs<DependentTemplateSpecializationTypeLoc>())
|
|
|
|
return DTL.getTemplateNameLoc();
|
2011-12-08 04:44:15 +08:00
|
|
|
|
|
|
|
return Loc;
|
|
|
|
}
|
|
|
|
|
2011-12-15 08:05:00 +08:00
|
|
|
const char *ScratchAlloc::toCStr(StringRef Str) {
|
2011-10-18 03:48:19 +08:00
|
|
|
if (Str.empty())
|
|
|
|
return "";
|
|
|
|
if (Str.data()[Str.size()] == '\0')
|
|
|
|
return Str.data();
|
2011-11-24 04:27:26 +08:00
|
|
|
return copyCStr(Str);
|
|
|
|
}
|
|
|
|
|
2011-12-15 08:05:00 +08:00
|
|
|
const char *ScratchAlloc::copyCStr(StringRef Str) {
|
2011-11-24 04:27:26 +08:00
|
|
|
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;
|
2013-01-27 02:53:38 +08:00
|
|
|
cxtu::getASTUnit(CXTU)->setASTContext(&ctx);
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2012-01-18 02:48:07 +08:00
|
|
|
void IndexingContext::setPreprocessor(Preprocessor &PP) {
|
2013-01-27 02:53:38 +08:00
|
|
|
cxtu::getASTUnit(CXTU)->setPreprocessor(&PP);
|
2012-01-18 02:48:07 +08:00
|
|
|
}
|
|
|
|
|
2012-09-11 06:58:04 +08:00
|
|
|
bool IndexingContext::isFunctionLocalDecl(const Decl *D) {
|
|
|
|
assert(D);
|
|
|
|
|
|
|
|
if (!D->getParentFunctionOrMethod())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
|
2013-05-13 08:12:11 +08:00
|
|
|
switch (ND->getFormalLinkage()) {
|
2012-09-11 06:58:04 +08:00
|
|
|
case NoLinkage:
|
2013-05-26 01:16:20 +08:00
|
|
|
case VisibleNoLinkage:
|
2012-09-11 06:58:04 +08:00
|
|
|
case InternalLinkage:
|
|
|
|
return true;
|
|
|
|
case UniqueExternalLinkage:
|
2013-05-13 08:12:11 +08:00
|
|
|
llvm_unreachable("Not a sema linkage");
|
2012-09-11 06:58:04 +08:00
|
|
|
case ExternalLinkage:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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) {
|
2013-01-16 06:09:51 +08:00
|
|
|
CXIdxClientFile idxFile =
|
|
|
|
CB.enteredMainFile(ClientData,
|
|
|
|
static_cast<CXFile>(const_cast<FileEntry *>(File)), 0);
|
2011-11-11 08:23:36 +08:00
|
|
|
FileMap[File] = idxFile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
void IndexingContext::ppIncludedFile(SourceLocation hashLoc,
|
|
|
|
StringRef filename,
|
|
|
|
const FileEntry *File,
|
2012-10-18 08:17:05 +08:00
|
|
|
bool isImport, bool isAngled,
|
|
|
|
bool isModuleImport) {
|
2011-10-18 03:48:19 +08:00
|
|
|
if (!CB.ppIncludedFile)
|
|
|
|
return;
|
|
|
|
|
2011-12-15 08:05:00 +08:00
|
|
|
ScratchAlloc SA(*this);
|
2011-10-18 03:48:19 +08:00
|
|
|
CXIdxIncludedFileInfo Info = { getIndexLoc(hashLoc),
|
|
|
|
SA.toCStr(filename),
|
2013-01-16 06:09:51 +08:00
|
|
|
static_cast<CXFile>(
|
|
|
|
const_cast<FileEntry *>(File)),
|
2012-10-18 08:17:05 +08:00
|
|
|
isImport, isAngled, isModuleImport };
|
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
|
|
|
}
|
|
|
|
|
2012-10-04 05:05:44 +08:00
|
|
|
void IndexingContext::importedModule(const ImportDecl *ImportD) {
|
2012-10-03 00:10:38 +08:00
|
|
|
if (!CB.importedASTFile)
|
|
|
|
return;
|
|
|
|
|
2012-10-04 05:05:44 +08:00
|
|
|
Module *Mod = ImportD->getImportedModule();
|
|
|
|
if (!Mod)
|
|
|
|
return;
|
2012-10-03 00:10:38 +08:00
|
|
|
|
|
|
|
CXIdxImportedASTFileInfo Info = {
|
2013-01-16 06:09:51 +08:00
|
|
|
static_cast<CXFile>(
|
|
|
|
const_cast<FileEntry *>(Mod->getASTFile())),
|
2012-10-05 08:22:40 +08:00
|
|
|
Mod,
|
2012-10-04 05:05:44 +08:00
|
|
|
getIndexLoc(ImportD->getLocation()),
|
2012-10-05 08:22:40 +08:00
|
|
|
ImportD->isImplicit()
|
2012-10-03 00:10:38 +08:00
|
|
|
};
|
|
|
|
CXIdxClientASTFile astFile = CB.importedASTFile(ClientData, &Info);
|
|
|
|
(void)astFile;
|
|
|
|
}
|
|
|
|
|
2012-10-04 05:05:51 +08:00
|
|
|
void IndexingContext::importedPCH(const FileEntry *File) {
|
|
|
|
if (!CB.importedASTFile)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CXIdxImportedASTFileInfo Info = {
|
2013-01-16 06:09:51 +08:00
|
|
|
static_cast<CXFile>(
|
|
|
|
const_cast<FileEntry *>(File)),
|
2012-10-05 08:22:40 +08:00
|
|
|
/*module=*/NULL,
|
2012-10-04 05:05:51 +08:00
|
|
|
getIndexLoc(SourceLocation()),
|
2012-10-05 08:22:40 +08:00
|
|
|
/*isImplicit=*/false
|
2012-10-04 05:05:51 +08:00
|
|
|
};
|
|
|
|
CXIdxClientASTFile astFile = CB.importedASTFile(ClientData, &Info);
|
|
|
|
(void)astFile;
|
|
|
|
}
|
|
|
|
|
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,
|
2012-02-29 01:50:39 +08:00
|
|
|
DeclInfo &DInfo,
|
|
|
|
const DeclContext *LexicalDC) {
|
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-12-15 08:05:00 +08:00
|
|
|
ScratchAlloc SA(*this);
|
2011-11-22 15:24:51 +08:00
|
|
|
getEntityInfo(D, DInfo.EntInfo, SA);
|
2012-02-15 06:23:11 +08:00
|
|
|
if ((!shouldIndexFunctionLocalSymbols() && !DInfo.EntInfo.USR)
|
2012-01-14 10:05:51 +08:00
|
|
|
|| Loc.isInvalid())
|
2011-11-18 08:26:51 +08:00
|
|
|
return false;
|
2011-11-18 08:26:46 +08:00
|
|
|
|
2012-02-29 01:50:39 +08:00
|
|
|
if (!LexicalDC)
|
|
|
|
LexicalDC = D->getLexicalDeclContext();
|
|
|
|
|
2012-02-15 06:23:11 +08:00
|
|
|
if (shouldSuppressRefs())
|
2011-12-14 02:47:35 +08:00
|
|
|
markEntityOccurrenceInFile(D, Loc);
|
2011-11-18 08:26:51 +08:00
|
|
|
|
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
|
|
|
|
2012-03-31 09:14:06 +08:00
|
|
|
DInfo.attributes = DInfo.EntInfo.attributes;
|
|
|
|
DInfo.numAttributes = DInfo.EntInfo.numAttributes;
|
2011-11-18 08:26:51 +08:00
|
|
|
|
2011-12-08 04:44:19 +08:00
|
|
|
getContainerInfo(D->getDeclContext(), DInfo.SemanticContainer);
|
|
|
|
DInfo.semanticContainer = &DInfo.SemanticContainer;
|
2012-02-11 04:10:44 +08:00
|
|
|
|
2012-02-29 01:50:39 +08:00
|
|
|
if (LexicalDC == D->getDeclContext()) {
|
2012-02-11 04:10:44 +08:00
|
|
|
DInfo.lexicalContainer = &DInfo.SemanticContainer;
|
|
|
|
} else if (isTemplateImplicitInstantiation(D)) {
|
|
|
|
// Implicit instantiations have the lexical context of where they were
|
|
|
|
// instantiated first. We choose instead the semantic context because:
|
|
|
|
// 1) at the time that we see the instantiation we have not seen the
|
|
|
|
// function where it occurred yet.
|
|
|
|
// 2) the lexical context of the first instantiation is not useful
|
|
|
|
// information anyway.
|
|
|
|
DInfo.lexicalContainer = &DInfo.SemanticContainer;
|
|
|
|
} else {
|
2012-02-29 01:50:39 +08:00
|
|
|
getContainerInfo(LexicalDC, DInfo.LexicalContainer);
|
2012-02-11 04:10:44 +08:00
|
|
|
DInfo.lexicalContainer = &DInfo.LexicalContainer;
|
|
|
|
}
|
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
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) {
|
2012-12-07 03:41:16 +08:00
|
|
|
bool isDef = D->isThisDeclarationADefinition();
|
|
|
|
bool isContainer = isDef;
|
|
|
|
bool isSkipped = false;
|
|
|
|
if (D->hasSkippedBody()) {
|
|
|
|
isSkipped = true;
|
|
|
|
isDef = true;
|
|
|
|
isContainer = false;
|
|
|
|
}
|
|
|
|
|
2013-10-17 23:37:26 +08:00
|
|
|
DeclInfo DInfo(!D->isFirstDecl(), isDef, isContainer);
|
2012-12-07 03:41:16 +08:00
|
|
|
if (isSkipped)
|
|
|
|
DInfo.flags |= CXIdxDeclFlag_Skipped;
|
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) {
|
2013-10-17 23:37:26 +08:00
|
|
|
DeclInfo DInfo(!D->isFirstDecl(), D->isThisDeclarationADefinition(),
|
2011-11-15 06:39:19 +08:00
|
|
|
/*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
|
|
|
}
|
|
|
|
|
2013-04-16 15:28:30 +08:00
|
|
|
bool IndexingContext::handleMSProperty(const MSPropertyDecl *D) {
|
|
|
|
DeclInfo DInfo(/*isRedeclaration=*/false, /*isDefinition=*/true,
|
|
|
|
/*isContainer=*/false);
|
|
|
|
return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2013-10-17 23:37:26 +08:00
|
|
|
DeclInfo DInfo(!D->isFirstDecl(), D->isThisDeclarationADefinition(),
|
2011-11-15 06:39:19 +08:00
|
|
|
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) {
|
2013-10-17 23:37:26 +08:00
|
|
|
DeclInfo DInfo(!D->isFirstDecl(), /*isDefinition=*/true,
|
2011-11-15 06:39:19 +08:00
|
|
|
/*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-12-28 06:43:10 +08:00
|
|
|
bool IndexingContext::handleObjCInterface(const ObjCInterfaceDecl *D) {
|
2011-12-14 02:47:35 +08:00
|
|
|
// For @class forward declarations, suppress them the same way as references.
|
2011-12-28 06:43:10 +08:00
|
|
|
if (!D->isThisDeclarationADefinition()) {
|
2012-02-15 06:23:11 +08:00
|
|
|
if (shouldSuppressRefs() && markEntityOccurrenceInFile(D, D->getLocation()))
|
2011-12-14 02:47:35 +08:00
|
|
|
return false; // already occurred.
|
|
|
|
|
2011-12-28 06:43:10 +08:00
|
|
|
// FIXME: This seems like the wrong definition for redeclaration.
|
2012-01-15 00:38:05 +08:00
|
|
|
bool isRedeclaration = D->hasDefinition() || D->getPreviousDecl();
|
2011-12-28 06:43:10 +08:00
|
|
|
ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/true, isRedeclaration,
|
|
|
|
/*isImplementation=*/false);
|
|
|
|
return handleObjCContainer(D, D->getLocation(),
|
|
|
|
MakeCursorObjCClassRef(D, D->getLocation(),
|
|
|
|
CXTU),
|
|
|
|
ContDInfo);
|
|
|
|
}
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-12-15 08:05:00 +08:00
|
|
|
ScratchAlloc SA(*this);
|
2011-11-12 10:16:30 +08:00
|
|
|
|
|
|
|
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);
|
2011-12-15 08:04:56 +08:00
|
|
|
|
2012-02-15 06:23:11 +08:00
|
|
|
if (shouldSuppressRefs())
|
2011-12-15 08:04:56 +08:00
|
|
|
markEntityOccurrenceInFile(SuperD, SuperLoc);
|
2011-11-12 10:16:30 +08:00
|
|
|
}
|
|
|
|
|
2011-12-15 13:27:12 +08:00
|
|
|
ObjCProtocolList EmptyProtoList;
|
2012-01-02 03:29:29 +08:00
|
|
|
ObjCProtocolListInfo ProtInfo(D->isThisDeclarationADefinition()
|
|
|
|
? D->getReferencedProtocols()
|
|
|
|
: EmptyProtoList,
|
2011-12-15 13:27:12 +08:00
|
|
|
*this, SA);
|
2011-11-12 10:16:30 +08:00
|
|
|
|
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::handleObjCProtocol(const ObjCProtocolDecl *D) {
|
2012-01-02 05:23:57 +08:00
|
|
|
if (!D->isThisDeclarationADefinition()) {
|
2012-02-15 06:23:11 +08:00
|
|
|
if (shouldSuppressRefs() && markEntityOccurrenceInFile(D, D->getLocation()))
|
2012-01-02 05:23:57 +08:00
|
|
|
return false; // already occurred.
|
|
|
|
|
|
|
|
// FIXME: This seems like the wrong definition for redeclaration.
|
2012-01-15 00:38:05 +08:00
|
|
|
bool isRedeclaration = D->hasDefinition() || D->getPreviousDecl();
|
2012-01-02 05:23:57 +08:00
|
|
|
ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/true,
|
|
|
|
isRedeclaration,
|
|
|
|
/*isImplementation=*/false);
|
|
|
|
return handleObjCContainer(D, D->getLocation(),
|
|
|
|
MakeCursorObjCProtocolRef(D, D->getLocation(),
|
|
|
|
CXTU),
|
|
|
|
ContDInfo);
|
|
|
|
}
|
|
|
|
|
2011-12-15 08:05:00 +08:00
|
|
|
ScratchAlloc SA(*this);
|
2012-01-02 03:29:29 +08:00
|
|
|
ObjCProtocolList EmptyProtoList;
|
|
|
|
ObjCProtocolListInfo ProtListInfo(D->isThisDeclarationADefinition()
|
|
|
|
? D->getReferencedProtocols()
|
|
|
|
: EmptyProtoList,
|
|
|
|
*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) {
|
2012-03-31 09:14:06 +08:00
|
|
|
ScratchAlloc SA(*this);
|
|
|
|
|
2011-11-15 06:39:19 +08:00
|
|
|
ObjCCategoryDeclInfo CatDInfo(/*isImplementation=*/false);
|
2011-11-22 15:24:51 +08:00
|
|
|
EntityInfo ClassEntity;
|
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
|
|
|
|
2012-02-15 06:23:11 +08:00
|
|
|
if (shouldSuppressRefs())
|
2011-12-14 02:47:35 +08:00
|
|
|
markEntityOccurrenceInFile(IFaceD, ClassLoc);
|
|
|
|
|
2011-12-14 02:47:45 +08:00
|
|
|
ObjCProtocolListInfo ProtInfo(D->getReferencedProtocols(), *this, SA);
|
|
|
|
|
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-12-14 02:47:45 +08:00
|
|
|
CatDInfo.ObjCProtoListInfo = ProtInfo.getListInfo();
|
|
|
|
CatDInfo.ObjCCatDeclInfo.protocols = &CatDInfo.ObjCProtoListInfo;
|
|
|
|
|
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) {
|
2012-03-31 09:14:06 +08:00
|
|
|
ScratchAlloc SA(*this);
|
|
|
|
|
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-16 10:35:05 +08:00
|
|
|
const ObjCInterfaceDecl *IFaceD = CatD->getClassInterface();
|
|
|
|
SourceLocation ClassLoc = D->getLocation();
|
2011-12-09 08:31:40 +08:00
|
|
|
SourceLocation CategoryLoc = D->getCategoryNameLoc();
|
2011-11-16 10:35:05 +08:00
|
|
|
getEntityInfo(IFaceD, ClassEntity, SA);
|
2011-11-11 08:23:36 +08:00
|
|
|
|
2012-02-15 06:23:11 +08:00
|
|
|
if (shouldSuppressRefs())
|
2012-01-24 05:28:38 +08:00
|
|
|
markEntityOccurrenceInFile(IFaceD, ClassLoc);
|
|
|
|
|
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-12-14 02:47:45 +08:00
|
|
|
CatDInfo.ObjCCatDeclInfo.protocols = 0;
|
|
|
|
|
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) {
|
2012-12-07 03:41:16 +08:00
|
|
|
bool isDef = D->isThisDeclarationADefinition();
|
|
|
|
bool isContainer = isDef;
|
|
|
|
bool isSkipped = false;
|
|
|
|
if (D->hasSkippedBody()) {
|
|
|
|
isSkipped = true;
|
|
|
|
isDef = true;
|
|
|
|
isContainer = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeclInfo DInfo(!D->isCanonicalDecl(), isDef, isContainer);
|
|
|
|
if (isSkipped)
|
|
|
|
DInfo.flags |= CXIdxDeclFlag_Skipped;
|
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,
|
2012-02-29 01:50:39 +08:00
|
|
|
SourceLocation Loc,
|
|
|
|
const DeclContext *LexicalDC) {
|
2011-11-18 08:26:51 +08:00
|
|
|
DeclInfo DInfo(/*isRedeclaration=*/true, /*isDefinition=*/true,
|
|
|
|
/*isContainer=*/false);
|
2012-02-29 01:50:39 +08:00
|
|
|
return handleDecl(D, Loc, getCursor(D), DInfo, LexicalDC);
|
2011-11-18 08:26:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IndexingContext::handleObjCProperty(const ObjCPropertyDecl *D) {
|
2012-03-31 09:14:06 +08:00
|
|
|
ScratchAlloc SA(*this);
|
|
|
|
|
2012-02-29 01:50:33 +08:00
|
|
|
ObjCPropertyDeclInfo DInfo;
|
|
|
|
EntityInfo GetterEntity;
|
|
|
|
EntityInfo SetterEntity;
|
|
|
|
|
|
|
|
DInfo.ObjCPropDeclInfo.declInfo = &DInfo;
|
|
|
|
|
|
|
|
if (ObjCMethodDecl *Getter = D->getGetterMethodDecl()) {
|
|
|
|
getEntityInfo(Getter, GetterEntity, SA);
|
|
|
|
DInfo.ObjCPropDeclInfo.getter = &GetterEntity;
|
|
|
|
} else {
|
|
|
|
DInfo.ObjCPropDeclInfo.getter = 0;
|
|
|
|
}
|
|
|
|
if (ObjCMethodDecl *Setter = D->getSetterMethodDecl()) {
|
|
|
|
getEntityInfo(Setter, SetterEntity, SA);
|
|
|
|
DInfo.ObjCPropDeclInfo.setter = &SetterEntity;
|
|
|
|
} else {
|
|
|
|
DInfo.ObjCPropDeclInfo.setter = 0;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2013-01-14 08:46:27 +08:00
|
|
|
CXCursor Cursor = E ? MakeCXCursor(E, cast<Decl>(DC), CXTU)
|
2011-11-18 08:26:51 +08:00
|
|
|
: 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;
|
2012-09-11 06:58:04 +08:00
|
|
|
if (!shouldIndexFunctionLocalSymbols() && isFunctionLocalDecl(D))
|
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;
|
|
|
|
|
2012-02-15 06:23:11 +08:00
|
|
|
if (shouldSuppressRefs()) {
|
2011-11-22 15:24:51 +08:00
|
|
|
if (markEntityOccurrenceInFile(D, Loc))
|
|
|
|
return false; // already occurred.
|
|
|
|
}
|
2011-11-16 10:34:59 +08:00
|
|
|
|
2011-12-15 08:05:00 +08:00
|
|
|
ScratchAlloc 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-12-08 04:44:19 +08:00
|
|
|
CXIdxEntityRefInfo Info = { Kind,
|
|
|
|
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-12-08 04:44:19 +08:00
|
|
|
&Container };
|
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
|
|
|
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()) {
|
2011-12-15 08:05:00 +08:00
|
|
|
ScratchAlloc SA(*this);
|
2011-11-24 04:27:26 +08:00
|
|
|
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();
|
|
|
|
|
2012-02-15 06:23:11 +08:00
|
|
|
if (shouldSuppressRefs()) {
|
2012-02-08 11:04:33 +08:00
|
|
|
// Go through bases and mark them as referenced.
|
|
|
|
for (unsigned i = 0, e = BaseList.getNumBases(); i != e; ++i) {
|
|
|
|
const CXIdxBaseClassInfo *baseInfo = BaseList.getBases()[i];
|
|
|
|
if (baseInfo->base) {
|
|
|
|
const NamedDecl *BaseD = BaseList.BaseEntities[i].Dcl;
|
|
|
|
SourceLocation
|
|
|
|
Loc = SourceLocation::getFromRawEncoding(baseInfo->loc.int_data);
|
|
|
|
markEntityOccurrenceInFile(BaseD, Loc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-24 04:27:26 +08:00
|
|
|
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) {
|
2011-12-14 02:47:35 +08:00
|
|
|
if (!D || Loc.isInvalid())
|
|
|
|
return true;
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
SourceManager &SM = Ctx->getSourceManager();
|
|
|
|
D = getEntityDecl(D);
|
|
|
|
|
2011-12-14 02:47:35 +08:00
|
|
|
std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(SM.getFileLoc(Loc));
|
2011-11-18 08:26:51 +08:00
|
|
|
FileID FID = LocInfo.first;
|
|
|
|
if (FID.isInvalid())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
const FileEntry *FE = SM.getFileEntryForID(FID);
|
|
|
|
if (!FE)
|
|
|
|
return true;
|
2013-12-01 07:33:14 +08:00
|
|
|
RefFileOccurrence RefOccur(FE, D);
|
|
|
|
std::pair<llvm::DenseSet<RefFileOccurrence>::iterator, bool>
|
|
|
|
res = RefFileOccurrences.insert(RefOccur);
|
2011-11-18 08:26:51 +08:00
|
|
|
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();
|
2012-12-20 01:29:30 +08:00
|
|
|
} else if (const FunctionTemplateDecl *
|
2011-11-22 15:24:51 +08:00
|
|
|
FuncTempl = dyn_cast<FunctionTemplateDecl>(D)) {
|
|
|
|
DC = FuncTempl->getTemplatedDecl();
|
|
|
|
}
|
|
|
|
|
|
|
|
return DC;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
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;
|
|
|
|
|
2013-01-16 06:09:51 +08:00
|
|
|
idxLoc.ptr_data[0] = const_cast<IndexingContext *>(this);
|
2011-10-18 03:48:19 +08:00
|
|
|
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)
|
2013-01-16 06:09:51 +08:00
|
|
|
*file = const_cast<FileEntry *>(FE);
|
2011-10-18 03:48:19 +08:00
|
|
|
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,
|
2011-12-15 08:05:00 +08:00
|
|
|
ScratchAlloc &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
|
|
|
|
2011-12-15 08:05:00 +08:00
|
|
|
if (D->hasAttrs()) {
|
2012-03-31 09:14:06 +08:00
|
|
|
EntityInfo.AttrList = AttrListInfo::create(D, *this);
|
|
|
|
EntityInfo.attributes = EntityInfo.AttrList->getAttrs();
|
|
|
|
EntityInfo.numAttributes = EntityInfo.AttrList->getNumAttrs();
|
2011-12-15 08:05:00 +08:00
|
|
|
}
|
|
|
|
|
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:
|
2012-09-01 06:18:20 +08:00
|
|
|
EntityInfo.kind = CXIdxEntity_CXXClass;
|
|
|
|
EntityInfo.lang = CXIdxEntityLang_CXX;
|
|
|
|
break;
|
|
|
|
case TTK_Interface:
|
|
|
|
EntityInfo.kind = CXIdxEntity_CXXInterface;
|
|
|
|
EntityInfo.lang = CXIdxEntityLang_CXX;
|
|
|
|
break;
|
|
|
|
case TTK_Enum:
|
|
|
|
EntityInfo.kind = CXIdxEntity_Enum; break;
|
|
|
|
}
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2012-01-24 00:58:45 +08:00
|
|
|
if (const CXXRecordDecl *CXXRec = dyn_cast<CXXRecordDecl>(D))
|
|
|
|
if (!CXXRec->isCLike())
|
2011-12-08 04:44:12 +08:00
|
|
|
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;
|
2012-01-14 10:05:51 +08:00
|
|
|
case Decl::ParmVar:
|
|
|
|
EntityInfo.kind = CXIdxEntity_Variable;
|
|
|
|
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 {
|
2012-02-13 20:32:26 +08:00
|
|
|
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
|
|
|
{
|
2012-02-13 20:32:26 +08:00
|
|
|
SmallString<512> StrBuf;
|
2011-11-24 04:27:26 +08:00
|
|
|
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);
|
2012-02-15 08:54:55 +08:00
|
|
|
if (const VarDecl *Var = dyn_cast<VarDecl>(D))
|
|
|
|
return MakeCursorVariableRef(Var, Loc, CXTU);
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
2011-11-22 15:24:51 +08:00
|
|
|
|
2012-02-08 06:46:16 +08:00
|
|
|
bool IndexingContext::shouldIgnoreIfImplicit(const Decl *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;
|
2012-10-04 05:05:44 +08:00
|
|
|
if (isa<ImportDecl>(D))
|
|
|
|
return false;
|
2011-11-22 15:24:51 +08:00
|
|
|
return true;
|
|
|
|
}
|
2012-02-11 04:10:44 +08:00
|
|
|
|
|
|
|
bool IndexingContext::isTemplateImplicitInstantiation(const Decl *D) {
|
|
|
|
if (const ClassTemplateSpecializationDecl *
|
|
|
|
SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
|
|
|
|
return SD->getSpecializationKind() == TSK_ImplicitInstantiation;
|
|
|
|
}
|
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
|
|
|
return FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|