2012-10-29 14:02:59 +08:00
|
|
|
//===- IndexingContext.h - Higher level API functions -----------*- C++ -*-===//
|
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 "CXCursor.h"
|
2012-12-04 17:25:21 +08:00
|
|
|
#include "Index_Internal.h"
|
2011-10-18 03:48:19 +08:00
|
|
|
#include "clang/AST/DeclGroup.h"
|
2012-12-04 17:25:21 +08:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2011-11-16 10:34:59 +08:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2012-03-24 07:24:18 +08:00
|
|
|
#include <deque>
|
2011-10-18 03:48:19 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
class FileEntry;
|
|
|
|
class ObjCPropertyDecl;
|
2011-11-22 15:24:51 +08:00
|
|
|
class ClassTemplateDecl;
|
|
|
|
class FunctionTemplateDecl;
|
|
|
|
class TypeAliasTemplateDecl;
|
2012-02-11 04:10:44 +08:00
|
|
|
class ClassTemplateSpecializationDecl;
|
2011-10-18 03:48:19 +08:00
|
|
|
|
|
|
|
namespace cxindex {
|
|
|
|
class IndexingContext;
|
2011-12-15 08:05:00 +08:00
|
|
|
class AttrListInfo;
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2012-03-31 09:14:06 +08:00
|
|
|
class ScratchAlloc {
|
|
|
|
IndexingContext &IdxCtx;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ScratchAlloc(IndexingContext &indexCtx);
|
|
|
|
ScratchAlloc(const ScratchAlloc &SA);
|
|
|
|
|
|
|
|
~ScratchAlloc();
|
|
|
|
|
|
|
|
const char *toCStr(StringRef Str);
|
|
|
|
const char *copyCStr(StringRef Str);
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T *allocate();
|
|
|
|
};
|
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
struct EntityInfo : public CXIdxEntityInfo {
|
|
|
|
const NamedDecl *Dcl;
|
|
|
|
IndexingContext *IndexCtx;
|
2012-02-20 22:00:23 +08:00
|
|
|
IntrusiveRefCntPtr<AttrListInfo> AttrList;
|
2011-11-24 04:27:26 +08:00
|
|
|
|
|
|
|
EntityInfo() {
|
|
|
|
name = USR = 0;
|
2011-12-15 08:05:00 +08:00
|
|
|
attributes = 0;
|
|
|
|
numAttributes = 0;
|
2011-11-24 04:27:26 +08:00
|
|
|
}
|
2011-11-22 15:24:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ContainerInfo : public CXIdxContainerInfo {
|
|
|
|
const DeclContext *DC;
|
|
|
|
IndexingContext *IndexCtx;
|
|
|
|
};
|
|
|
|
|
2011-11-11 08:23:36 +08:00
|
|
|
struct DeclInfo : public CXIdxDeclInfo {
|
2011-11-15 06:39:19 +08:00
|
|
|
enum DInfoKind {
|
|
|
|
Info_Decl,
|
|
|
|
|
|
|
|
Info_ObjCContainer,
|
|
|
|
Info_ObjCInterface,
|
|
|
|
Info_ObjCProtocol,
|
2011-11-22 15:24:51 +08:00
|
|
|
Info_ObjCCategory,
|
|
|
|
|
2012-02-29 01:50:33 +08:00
|
|
|
Info_ObjCProperty,
|
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
Info_CXXClass
|
2011-11-15 06:39:19 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
DInfoKind Kind;
|
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
EntityInfo EntInfo;
|
2011-12-08 04:44:19 +08:00
|
|
|
ContainerInfo SemanticContainer;
|
|
|
|
ContainerInfo LexicalContainer;
|
2011-11-22 15:24:51 +08:00
|
|
|
ContainerInfo DeclAsContainer;
|
|
|
|
|
2011-11-15 06:39:19 +08:00
|
|
|
DeclInfo(bool isRedeclaration, bool isDefinition, bool isContainer)
|
|
|
|
: Kind(Info_Decl) {
|
|
|
|
this->isRedeclaration = isRedeclaration;
|
|
|
|
this->isDefinition = isDefinition;
|
|
|
|
this->isContainer = isContainer;
|
2011-11-18 08:26:51 +08:00
|
|
|
attributes = 0;
|
|
|
|
numAttributes = 0;
|
2011-12-08 04:44:19 +08:00
|
|
|
declAsContainer = semanticContainer = lexicalContainer = 0;
|
2012-12-07 03:41:16 +08:00
|
|
|
flags = 0;
|
2011-11-15 06:39:19 +08:00
|
|
|
}
|
|
|
|
DeclInfo(DInfoKind K,
|
|
|
|
bool isRedeclaration, bool isDefinition, bool isContainer)
|
|
|
|
: Kind(K) {
|
|
|
|
this->isRedeclaration = isRedeclaration;
|
|
|
|
this->isDefinition = isDefinition;
|
|
|
|
this->isContainer = isContainer;
|
2011-11-18 08:26:51 +08:00
|
|
|
attributes = 0;
|
|
|
|
numAttributes = 0;
|
2011-12-08 04:44:19 +08:00
|
|
|
declAsContainer = semanticContainer = lexicalContainer = 0;
|
2012-12-07 03:41:16 +08:00
|
|
|
flags = 0;
|
2011-11-15 06:39:19 +08:00
|
|
|
}
|
2011-11-11 08:23:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ObjCContainerDeclInfo : public DeclInfo {
|
2011-11-12 10:16:30 +08:00
|
|
|
CXIdxObjCContainerDeclInfo ObjCContDeclInfo;
|
2011-11-11 08:23:36 +08:00
|
|
|
|
2011-11-15 06:39:19 +08:00
|
|
|
ObjCContainerDeclInfo(bool isForwardRef,
|
|
|
|
bool isRedeclaration,
|
|
|
|
bool isImplementation)
|
|
|
|
: DeclInfo(Info_ObjCContainer, isRedeclaration,
|
|
|
|
/*isDefinition=*/!isForwardRef, /*isContainer=*/!isForwardRef) {
|
|
|
|
init(isForwardRef, isImplementation);
|
|
|
|
}
|
|
|
|
ObjCContainerDeclInfo(DInfoKind K,
|
|
|
|
bool isForwardRef,
|
|
|
|
bool isRedeclaration,
|
|
|
|
bool isImplementation)
|
|
|
|
: DeclInfo(K, isRedeclaration, /*isDefinition=*/!isForwardRef,
|
|
|
|
/*isContainer=*/!isForwardRef) {
|
|
|
|
init(isForwardRef, isImplementation);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool classof(const DeclInfo *D) {
|
|
|
|
return Info_ObjCContainer <= D->Kind && D->Kind <= Info_ObjCCategory;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void init(bool isForwardRef, bool isImplementation) {
|
|
|
|
if (isForwardRef)
|
|
|
|
ObjCContDeclInfo.kind = CXIdxObjCContainer_ForwardRef;
|
|
|
|
else if (isImplementation)
|
|
|
|
ObjCContDeclInfo.kind = CXIdxObjCContainer_Implementation;
|
|
|
|
else
|
|
|
|
ObjCContDeclInfo.kind = CXIdxObjCContainer_Interface;
|
|
|
|
}
|
2011-11-12 10:16:30 +08:00
|
|
|
};
|
|
|
|
|
2011-11-15 06:39:19 +08:00
|
|
|
struct ObjCInterfaceDeclInfo : public ObjCContainerDeclInfo {
|
2011-11-12 10:16:30 +08:00
|
|
|
CXIdxObjCInterfaceDeclInfo ObjCInterDeclInfo;
|
2011-11-15 06:39:19 +08:00
|
|
|
CXIdxObjCProtocolRefListInfo ObjCProtoListInfo;
|
|
|
|
|
|
|
|
ObjCInterfaceDeclInfo(const ObjCInterfaceDecl *D)
|
|
|
|
: ObjCContainerDeclInfo(Info_ObjCInterface,
|
|
|
|
/*isForwardRef=*/false,
|
2012-01-15 00:38:05 +08:00
|
|
|
/*isRedeclaration=*/D->getPreviousDecl() != 0,
|
2011-11-15 06:39:19 +08:00
|
|
|
/*isImplementation=*/false) { }
|
|
|
|
|
|
|
|
static bool classof(const DeclInfo *D) {
|
|
|
|
return D->Kind == Info_ObjCInterface;
|
|
|
|
}
|
2011-11-12 10:16:30 +08:00
|
|
|
};
|
|
|
|
|
2011-11-15 06:39:19 +08:00
|
|
|
struct ObjCProtocolDeclInfo : public ObjCContainerDeclInfo {
|
|
|
|
CXIdxObjCProtocolRefListInfo ObjCProtoRefListInfo;
|
|
|
|
|
|
|
|
ObjCProtocolDeclInfo(const ObjCProtocolDecl *D)
|
|
|
|
: ObjCContainerDeclInfo(Info_ObjCProtocol,
|
|
|
|
/*isForwardRef=*/false,
|
2012-01-15 00:38:05 +08:00
|
|
|
/*isRedeclaration=*/D->getPreviousDecl(),
|
2011-11-15 06:39:19 +08:00
|
|
|
/*isImplementation=*/false) { }
|
|
|
|
|
|
|
|
static bool classof(const DeclInfo *D) {
|
|
|
|
return D->Kind == Info_ObjCProtocol;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ObjCCategoryDeclInfo : public ObjCContainerDeclInfo {
|
|
|
|
CXIdxObjCCategoryDeclInfo ObjCCatDeclInfo;
|
2011-12-14 02:47:45 +08:00
|
|
|
CXIdxObjCProtocolRefListInfo ObjCProtoListInfo;
|
2011-11-15 06:39:19 +08:00
|
|
|
|
|
|
|
explicit ObjCCategoryDeclInfo(bool isImplementation)
|
|
|
|
: ObjCContainerDeclInfo(Info_ObjCCategory,
|
|
|
|
/*isForwardRef=*/false,
|
|
|
|
/*isRedeclaration=*/isImplementation,
|
|
|
|
/*isImplementation=*/isImplementation) { }
|
|
|
|
|
|
|
|
static bool classof(const DeclInfo *D) {
|
|
|
|
return D->Kind == Info_ObjCCategory;
|
|
|
|
}
|
2011-11-11 08:23:36 +08:00
|
|
|
};
|
|
|
|
|
2012-02-29 01:50:33 +08:00
|
|
|
struct ObjCPropertyDeclInfo : public DeclInfo {
|
|
|
|
CXIdxObjCPropertyDeclInfo ObjCPropDeclInfo;
|
|
|
|
|
|
|
|
ObjCPropertyDeclInfo()
|
|
|
|
: DeclInfo(Info_ObjCProperty,
|
|
|
|
/*isRedeclaration=*/false, /*isDefinition=*/false,
|
|
|
|
/*isContainer=*/false) { }
|
|
|
|
|
|
|
|
static bool classof(const DeclInfo *D) {
|
|
|
|
return D->Kind == Info_ObjCProperty;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
struct CXXClassDeclInfo : public DeclInfo {
|
|
|
|
CXIdxCXXClassDeclInfo CXXClassInfo;
|
|
|
|
|
|
|
|
CXXClassDeclInfo(bool isRedeclaration, bool isDefinition)
|
|
|
|
: DeclInfo(Info_CXXClass, isRedeclaration, isDefinition, isDefinition) { }
|
|
|
|
|
|
|
|
static bool classof(const DeclInfo *D) {
|
|
|
|
return D->Kind == Info_CXXClass;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
struct AttrInfo : public CXIdxAttrInfo {
|
|
|
|
const Attr *A;
|
|
|
|
|
|
|
|
AttrInfo(CXIdxAttrKind Kind, CXCursor C, CXIdxLoc Loc, const Attr *A) {
|
|
|
|
kind = Kind;
|
|
|
|
cursor = C;
|
|
|
|
loc = Loc;
|
|
|
|
this->A = A;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct IBOutletCollectionInfo : public AttrInfo {
|
2011-11-22 15:24:51 +08:00
|
|
|
EntityInfo ClassInfo;
|
2011-11-18 08:26:51 +08:00
|
|
|
CXIdxIBOutletCollectionAttrInfo IBCollInfo;
|
|
|
|
|
|
|
|
IBOutletCollectionInfo(CXCursor C, CXIdxLoc Loc, const Attr *A) :
|
|
|
|
AttrInfo(CXIdxAttr_IBOutletCollection, C, Loc, A) {
|
|
|
|
assert(C.kind == CXCursor_IBOutletCollectionAttr);
|
2011-12-15 08:05:00 +08:00
|
|
|
IBCollInfo.objcClass = 0;
|
2011-11-18 08:26:51 +08:00
|
|
|
}
|
|
|
|
|
2011-12-15 08:05:00 +08:00
|
|
|
IBOutletCollectionInfo(const IBOutletCollectionInfo &other);
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
static bool classof(const AttrInfo *A) {
|
|
|
|
return A->kind == CXIdxAttr_IBOutletCollection;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-12-15 08:05:00 +08:00
|
|
|
class AttrListInfo {
|
2012-03-31 09:14:06 +08:00
|
|
|
ScratchAlloc SA;
|
|
|
|
|
2011-12-15 08:05:00 +08:00
|
|
|
SmallVector<AttrInfo, 2> Attrs;
|
|
|
|
SmallVector<IBOutletCollectionInfo, 2> IBCollAttrs;
|
|
|
|
SmallVector<CXIdxAttrInfo *, 2> CXAttrs;
|
|
|
|
unsigned ref_cnt;
|
|
|
|
|
2012-09-16 04:20:27 +08:00
|
|
|
AttrListInfo(const AttrListInfo &) LLVM_DELETED_FUNCTION;
|
|
|
|
void operator=(const AttrListInfo &) LLVM_DELETED_FUNCTION;
|
2011-12-15 08:05:00 +08:00
|
|
|
public:
|
2012-03-31 09:14:06 +08:00
|
|
|
AttrListInfo(const Decl *D, IndexingContext &IdxCtx);
|
|
|
|
|
|
|
|
static IntrusiveRefCntPtr<AttrListInfo> create(const Decl *D,
|
|
|
|
IndexingContext &IdxCtx);
|
2011-12-15 08:05:00 +08:00
|
|
|
|
|
|
|
const CXIdxAttrInfo *const *getAttrs() const {
|
|
|
|
if (CXAttrs.empty())
|
|
|
|
return 0;
|
|
|
|
return CXAttrs.data();
|
|
|
|
}
|
|
|
|
unsigned getNumAttrs() const { return (unsigned)CXAttrs.size(); }
|
|
|
|
|
|
|
|
/// \brief Retain/Release only useful when we allocate a AttrListInfo from the
|
|
|
|
/// BumpPtrAllocator, and not from the stack; so that we keep a pointer
|
|
|
|
// in the EntityInfo
|
|
|
|
void Retain() { ++ref_cnt; }
|
|
|
|
void Release() {
|
|
|
|
assert (ref_cnt > 0 && "Reference count is already zero.");
|
|
|
|
if (--ref_cnt == 0) {
|
|
|
|
// Memory is allocated from a BumpPtrAllocator, no need to delete it.
|
|
|
|
this->~AttrListInfo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-11-16 10:34:59 +08:00
|
|
|
struct RefFileOccurence {
|
|
|
|
const FileEntry *File;
|
|
|
|
const Decl *Dcl;
|
|
|
|
|
|
|
|
RefFileOccurence(const FileEntry *File, const Decl *Dcl)
|
|
|
|
: File(File), Dcl(Dcl) { }
|
|
|
|
};
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
class IndexingContext {
|
|
|
|
ASTContext *Ctx;
|
|
|
|
CXClientData ClientData;
|
|
|
|
IndexerCallbacks &CB;
|
|
|
|
unsigned IndexOptions;
|
|
|
|
CXTranslationUnit CXTU;
|
|
|
|
|
2011-11-11 08:23:36 +08:00
|
|
|
typedef llvm::DenseMap<const FileEntry *, CXIdxClientFile> FileMapTy;
|
2011-11-22 15:24:51 +08:00
|
|
|
typedef llvm::DenseMap<const DeclContext *, CXIdxClientContainer>
|
|
|
|
ContainerMapTy;
|
|
|
|
typedef llvm::DenseMap<const Decl *, CXIdxClientEntity> EntityMapTy;
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
FileMapTy FileMap;
|
|
|
|
ContainerMapTy ContainerMap;
|
2011-11-22 15:24:51 +08:00
|
|
|
EntityMapTy EntityMap;
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-16 10:34:59 +08:00
|
|
|
llvm::DenseSet<RefFileOccurence> RefFileOccurences;
|
|
|
|
|
2012-03-24 07:24:18 +08:00
|
|
|
std::deque<DeclGroupRef> TUDeclsInObjCContainer;
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-24 04:27:26 +08:00
|
|
|
llvm::BumpPtrAllocator StrScratch;
|
2011-11-11 08:23:36 +08:00
|
|
|
unsigned StrAdapterCount;
|
2011-12-15 08:05:00 +08:00
|
|
|
friend class ScratchAlloc;
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-12 10:16:30 +08:00
|
|
|
struct ObjCProtocolListInfo {
|
|
|
|
SmallVector<CXIdxObjCProtocolRefInfo, 4> ProtInfos;
|
2011-11-22 15:24:51 +08:00
|
|
|
SmallVector<EntityInfo, 4> ProtEntities;
|
2011-11-12 10:16:30 +08:00
|
|
|
SmallVector<CXIdxObjCProtocolRefInfo *, 4> Prots;
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
CXIdxObjCProtocolRefListInfo getListInfo() const {
|
2011-11-15 06:39:19 +08:00
|
|
|
CXIdxObjCProtocolRefListInfo Info = { Prots.data(),
|
|
|
|
(unsigned)Prots.size() };
|
|
|
|
return Info;
|
|
|
|
}
|
2011-11-12 10:16:30 +08:00
|
|
|
|
|
|
|
ObjCProtocolListInfo(const ObjCProtocolList &ProtList,
|
|
|
|
IndexingContext &IdxCtx,
|
2011-12-15 08:05:00 +08:00
|
|
|
ScratchAlloc &SA);
|
2011-11-22 15:24:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CXXBasesListInfo {
|
|
|
|
SmallVector<CXIdxBaseClassInfo, 4> BaseInfos;
|
|
|
|
SmallVector<EntityInfo, 4> BaseEntities;
|
|
|
|
SmallVector<CXIdxBaseClassInfo *, 4> CXBases;
|
|
|
|
|
|
|
|
const CXIdxBaseClassInfo *const *getBases() const {
|
|
|
|
return CXBases.data();
|
|
|
|
}
|
|
|
|
unsigned getNumBases() const { return (unsigned)CXBases.size(); }
|
|
|
|
|
|
|
|
CXXBasesListInfo(const CXXRecordDecl *D,
|
2011-12-15 08:05:00 +08:00
|
|
|
IndexingContext &IdxCtx, ScratchAlloc &SA);
|
2011-12-08 04:44:15 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
SourceLocation getBaseLoc(const CXXBaseSpecifier &Base) const;
|
2011-11-22 15:24:51 +08:00
|
|
|
};
|
2011-11-18 08:26:51 +08:00
|
|
|
|
2011-12-15 08:05:00 +08:00
|
|
|
friend class AttrListInfo;
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
public:
|
|
|
|
IndexingContext(CXClientData clientData, IndexerCallbacks &indexCallbacks,
|
|
|
|
unsigned indexOptions, CXTranslationUnit cxTU)
|
|
|
|
: Ctx(0), ClientData(clientData), CB(indexCallbacks),
|
2011-11-24 04:27:26 +08:00
|
|
|
IndexOptions(indexOptions), CXTU(cxTU),
|
|
|
|
StrScratch(/*size=*/1024), StrAdapterCount(0) { }
|
2011-10-18 03:48:19 +08:00
|
|
|
|
|
|
|
ASTContext &getASTContext() const { return *Ctx; }
|
|
|
|
|
|
|
|
void setASTContext(ASTContext &ctx);
|
2012-01-18 02:48:07 +08:00
|
|
|
void setPreprocessor(Preprocessor &PP);
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2012-02-15 06:23:11 +08:00
|
|
|
bool shouldSuppressRefs() const {
|
2011-11-18 08:26:51 +08:00
|
|
|
return IndexOptions & CXIndexOpt_SuppressRedundantRefs;
|
2011-11-16 10:34:59 +08:00
|
|
|
}
|
|
|
|
|
2012-02-15 06:23:11 +08:00
|
|
|
bool shouldIndexFunctionLocalSymbols() const {
|
2012-01-14 08:11:49 +08:00
|
|
|
return IndexOptions & CXIndexOpt_IndexFunctionLocalSymbols;
|
|
|
|
}
|
|
|
|
|
2012-02-15 06:23:11 +08:00
|
|
|
bool shouldIndexImplicitTemplateInsts() const {
|
|
|
|
return IndexOptions & CXIndexOpt_IndexImplicitTemplateInstantiations;
|
|
|
|
}
|
|
|
|
|
2012-09-11 06:58:04 +08:00
|
|
|
static bool isFunctionLocalDecl(const Decl *D);
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool shouldAbort();
|
|
|
|
|
2011-12-01 10:42:50 +08:00
|
|
|
bool hasDiagnosticCallback() const { return CB.diagnostic; }
|
|
|
|
|
2011-11-11 08:23:36 +08:00
|
|
|
void enteredMainFile(const FileEntry *File);
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
void 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
|
|
|
|
2012-10-04 05:05:44 +08:00
|
|
|
void importedModule(const ImportDecl *ImportD);
|
2012-10-04 05:05:51 +08:00
|
|
|
void importedPCH(const FileEntry *File);
|
2012-10-03 00:10:38 +08:00
|
|
|
|
2011-11-12 10:16:30 +08:00
|
|
|
void startedTranslationUnit();
|
2011-10-18 03:48:19 +08:00
|
|
|
|
|
|
|
void indexDecl(const Decl *D);
|
|
|
|
|
|
|
|
void indexTagDecl(const TagDecl *D);
|
|
|
|
|
|
|
|
void indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent,
|
|
|
|
const DeclContext *DC = 0);
|
|
|
|
|
|
|
|
void indexTypeLoc(TypeLoc TL, const NamedDecl *Parent,
|
2011-12-14 02:47:41 +08:00
|
|
|
const DeclContext *DC = 0);
|
|
|
|
|
|
|
|
void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
|
|
|
|
const NamedDecl *Parent,
|
|
|
|
const DeclContext *DC = 0);
|
2011-10-18 03:48:19 +08:00
|
|
|
|
|
|
|
void indexDeclContext(const DeclContext *DC);
|
|
|
|
|
2011-12-14 02:47:41 +08:00
|
|
|
void indexBody(const Stmt *S, const NamedDecl *Parent,
|
|
|
|
const DeclContext *DC = 0);
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
void handleDiagnosticSet(CXDiagnosticSet CXDiagSet);
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool handleFunction(const FunctionDecl *FD);
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool handleVar(const VarDecl *D);
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool handleField(const FieldDecl *D);
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool handleEnumerator(const EnumConstantDecl *D);
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool handleTagDecl(const TagDecl *D);
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
bool handleTypedefName(const TypedefNameDecl *D);
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool handleObjCInterface(const ObjCInterfaceDecl *D);
|
|
|
|
bool handleObjCImplementation(const ObjCImplementationDecl *D);
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool handleObjCProtocol(const ObjCProtocolDecl *D);
|
|
|
|
|
|
|
|
bool handleObjCCategory(const ObjCCategoryDecl *D);
|
|
|
|
bool handleObjCCategoryImpl(const ObjCCategoryImplDecl *D);
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool handleObjCMethod(const ObjCMethodDecl *D);
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool handleSynthesizedObjCProperty(const ObjCPropertyImplDecl *D);
|
2012-02-29 01:50:39 +08:00
|
|
|
bool handleSynthesizedObjCMethod(const ObjCMethodDecl *D, SourceLocation Loc,
|
|
|
|
const DeclContext *LexicalDC);
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool handleObjCProperty(const ObjCPropertyDecl *D);
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-12-07 13:52:06 +08:00
|
|
|
bool handleNamespace(const NamespaceDecl *D);
|
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
bool handleClassTemplate(const ClassTemplateDecl *D);
|
|
|
|
bool handleFunctionTemplate(const FunctionTemplateDecl *D);
|
|
|
|
bool handleTypeAliasTemplate(const TypeAliasTemplateDecl *D);
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool handleReference(const NamedDecl *D, SourceLocation Loc, CXCursor Cursor,
|
|
|
|
const NamedDecl *Parent,
|
|
|
|
const DeclContext *DC,
|
|
|
|
const Expr *E = 0,
|
|
|
|
CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
|
|
|
|
|
|
|
|
bool 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 = 0,
|
|
|
|
CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
|
2011-10-18 03:48:19 +08:00
|
|
|
|
|
|
|
bool isNotFromSourceFile(SourceLocation Loc) const;
|
|
|
|
|
2012-09-11 06:58:04 +08:00
|
|
|
void indexTopLevelDecl(const Decl *D);
|
2011-10-18 03:48:19 +08:00
|
|
|
void indexTUDeclsInObjCContainer();
|
|
|
|
void indexDeclGroupRef(DeclGroupRef DG);
|
|
|
|
|
|
|
|
void addTUDeclInObjCContainer(DeclGroupRef DG) {
|
|
|
|
TUDeclsInObjCContainer.push_back(DG);
|
|
|
|
}
|
|
|
|
|
2011-11-11 08:23:36 +08:00
|
|
|
void translateLoc(SourceLocation Loc, CXIdxClientFile *indexFile, CXFile *file,
|
2011-10-18 03:48:19 +08:00
|
|
|
unsigned *line, unsigned *column, unsigned *offset);
|
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
CXIdxClientContainer getClientContainerForDC(const DeclContext *DC) const;
|
|
|
|
void addContainerInMap(const DeclContext *DC, CXIdxClientContainer container);
|
|
|
|
|
|
|
|
CXIdxClientEntity getClientEntity(const Decl *D) const;
|
|
|
|
void setClientEntity(const Decl *D, CXIdxClientEntity client);
|
|
|
|
|
2012-02-11 04:10:44 +08:00
|
|
|
static bool isTemplateImplicitInstantiation(const Decl *D);
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
private:
|
2011-11-18 08:26:51 +08:00
|
|
|
bool 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 = 0);
|
2011-11-11 08:23:36 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool handleObjCContainer(const ObjCContainerDecl *D,
|
2011-11-11 08:23:36 +08:00
|
|
|
SourceLocation Loc, CXCursor Cursor,
|
|
|
|
ObjCContainerDeclInfo &ContDInfo);
|
2011-10-18 03:48:19 +08:00
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
bool handleCXXRecordDecl(const CXXRecordDecl *RD, const NamedDecl *OrigD);
|
2011-11-11 08:23:36 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
bool markEntityOccurrenceInFile(const NamedDecl *D, SourceLocation Loc);
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
const NamedDecl *getEntityDecl(const NamedDecl *D) const;
|
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
const DeclContext *getEntityContainer(const Decl *D) const;
|
|
|
|
|
2011-11-11 08:23:36 +08:00
|
|
|
CXIdxClientFile getIndexFile(const FileEntry *File);
|
2011-10-18 03:48:19 +08:00
|
|
|
|
|
|
|
CXIdxLoc getIndexLoc(SourceLocation Loc) const;
|
|
|
|
|
|
|
|
void 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-10-18 03:48:19 +08:00
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
void getContainerInfo(const DeclContext *DC, ContainerInfo &ContInfo);
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
CXCursor getCursor(const Decl *D) {
|
2013-02-03 21:19:54 +08:00
|
|
|
return cxcursor::MakeCXCursor(D, CXTU);
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CXCursor getRefCursor(const NamedDecl *D, SourceLocation Loc);
|
2011-11-22 15:24:51 +08:00
|
|
|
|
2012-02-08 06:46:16 +08:00
|
|
|
static bool shouldIgnoreIfImplicit(const Decl *D);
|
2011-10-18 03:48:19 +08:00
|
|
|
};
|
|
|
|
|
2012-03-31 09:14:06 +08:00
|
|
|
inline ScratchAlloc::ScratchAlloc(IndexingContext &idxCtx) : IdxCtx(idxCtx) {
|
|
|
|
++IdxCtx.StrAdapterCount;
|
|
|
|
}
|
|
|
|
inline ScratchAlloc::ScratchAlloc(const ScratchAlloc &SA) : IdxCtx(SA.IdxCtx) {
|
|
|
|
++IdxCtx.StrAdapterCount;
|
|
|
|
}
|
2011-12-15 08:05:00 +08:00
|
|
|
|
2012-03-31 09:14:06 +08:00
|
|
|
inline ScratchAlloc::~ScratchAlloc() {
|
|
|
|
--IdxCtx.StrAdapterCount;
|
|
|
|
if (IdxCtx.StrAdapterCount == 0)
|
|
|
|
IdxCtx.StrScratch.Reset();
|
|
|
|
}
|
2011-12-15 08:05:00 +08:00
|
|
|
|
2012-03-31 09:14:06 +08:00
|
|
|
template <typename T>
|
|
|
|
inline T *ScratchAlloc::allocate() {
|
|
|
|
return IdxCtx.StrScratch.Allocate<T>();
|
|
|
|
}
|
2011-12-15 08:05:00 +08:00
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
}} // end clang::cxindex
|
2011-11-16 10:34:59 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
/// Define DenseMapInfo so that FileID's can be used as keys in DenseMap and
|
|
|
|
/// DenseSets.
|
|
|
|
template <>
|
|
|
|
struct DenseMapInfo<clang::cxindex::RefFileOccurence> {
|
|
|
|
static inline clang::cxindex::RefFileOccurence getEmptyKey() {
|
|
|
|
return clang::cxindex::RefFileOccurence(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline clang::cxindex::RefFileOccurence getTombstoneKey() {
|
|
|
|
return clang::cxindex::RefFileOccurence((const clang::FileEntry *)~0,
|
|
|
|
(const clang::Decl *)~0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned getHashValue(clang::cxindex::RefFileOccurence S) {
|
2012-05-27 21:28:44 +08:00
|
|
|
typedef std::pair<const clang::FileEntry *, const clang::Decl *> PairTy;
|
|
|
|
return DenseMapInfo<PairTy>::getHashValue(PairTy(S.File, S.Dcl));
|
2011-11-16 10:34:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool isEqual(clang::cxindex::RefFileOccurence LHS,
|
|
|
|
clang::cxindex::RefFileOccurence RHS) {
|
|
|
|
return LHS.File == RHS.File && LHS.Dcl == RHS.Dcl;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|