2016-02-13 07:10:59 +08:00
|
|
|
//===- CXIndexDataConsumer.cpp - Index data consumer for libclang----------===//
|
2011-10-18 03:48:19 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-10-18 03:48:19 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
#include "CXIndexDataConsumer.h"
|
2011-10-18 03:48:19 +08:00
|
|
|
#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"
|
2016-02-13 07:10:59 +08:00
|
|
|
#include "clang/AST/DeclVisitor.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;
|
2016-02-13 07:10:59 +08:00
|
|
|
using namespace clang::index;
|
2011-10-18 03:48:19 +08:00
|
|
|
using namespace cxindex;
|
|
|
|
using namespace cxcursor;
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
namespace {
|
|
|
|
class IndexingDeclVisitor : public ConstDeclVisitor<IndexingDeclVisitor, bool> {
|
|
|
|
CXIndexDataConsumer &DataConsumer;
|
|
|
|
SourceLocation DeclLoc;
|
|
|
|
const DeclContext *LexicalDC;
|
|
|
|
|
|
|
|
public:
|
|
|
|
IndexingDeclVisitor(CXIndexDataConsumer &dataConsumer, SourceLocation Loc,
|
|
|
|
const DeclContext *lexicalDC)
|
|
|
|
: DataConsumer(dataConsumer), DeclLoc(Loc), LexicalDC(lexicalDC) { }
|
|
|
|
|
|
|
|
bool VisitFunctionDecl(const FunctionDecl *D) {
|
|
|
|
DataConsumer.handleFunction(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitVarDecl(const VarDecl *D) {
|
|
|
|
DataConsumer.handleVar(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitFieldDecl(const FieldDecl *D) {
|
|
|
|
DataConsumer.handleField(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitMSPropertyDecl(const MSPropertyDecl *D) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitEnumConstantDecl(const EnumConstantDecl *D) {
|
|
|
|
DataConsumer.handleEnumerator(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitTypedefNameDecl(const TypedefNameDecl *D) {
|
|
|
|
DataConsumer.handleTypedefName(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitTagDecl(const TagDecl *D) {
|
|
|
|
DataConsumer.handleTagDecl(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
|
|
|
|
DataConsumer.handleObjCInterface(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
|
|
|
|
DataConsumer.handleObjCProtocol(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
|
|
|
|
DataConsumer.handleObjCImplementation(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
|
|
|
|
DataConsumer.handleObjCCategory(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
|
|
|
|
DataConsumer.handleObjCCategoryImpl(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitObjCMethodDecl(const ObjCMethodDecl *D) {
|
2016-04-01 04:18:22 +08:00
|
|
|
if (isa<ObjCImplDecl>(LexicalDC) && !D->isThisDeclarationADefinition())
|
2016-02-13 07:10:59 +08:00
|
|
|
DataConsumer.handleSynthesizedObjCMethod(D, DeclLoc, LexicalDC);
|
|
|
|
else
|
2017-01-26 10:11:50 +08:00
|
|
|
DataConsumer.handleObjCMethod(D, DeclLoc);
|
2016-02-13 07:10:59 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
|
|
|
|
DataConsumer.handleObjCProperty(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
|
|
|
|
DataConsumer.handleSynthesizedObjCProperty(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitNamespaceDecl(const NamespaceDecl *D) {
|
|
|
|
DataConsumer.handleNamespace(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitUsingDecl(const UsingDecl *D) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitClassTemplateDecl(const ClassTemplateDecl *D) {
|
|
|
|
DataConsumer.handleClassTemplate(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitClassTemplateSpecializationDecl(const
|
|
|
|
ClassTemplateSpecializationDecl *D) {
|
|
|
|
DataConsumer.handleTagDecl(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
|
|
|
|
DataConsumer.handleFunctionTemplate(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
|
|
|
|
DataConsumer.handleTypeAliasTemplate(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitImportDecl(const ImportDecl *D) {
|
|
|
|
DataConsumer.importedModule(D);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2018-02-13 01:42:09 +08:00
|
|
|
|
|
|
|
CXSymbolRole getSymbolRole(SymbolRoleSet Role) {
|
|
|
|
// CXSymbolRole mirrors low 9 bits of clang::index::SymbolRole.
|
|
|
|
return CXSymbolRole(static_cast<uint32_t>(Role) & ((1 << 9) - 1));
|
|
|
|
}
|
2016-02-13 07:10:59 +08:00
|
|
|
}
|
|
|
|
|
2019-12-16 17:33:56 +08:00
|
|
|
bool CXIndexDataConsumer::handleDeclOccurrence(
|
2018-04-09 22:12:51 +08:00
|
|
|
const Decl *D, SymbolRoleSet Roles, ArrayRef<SymbolRelation> Relations,
|
|
|
|
SourceLocation Loc, ASTNodeInfo ASTNode) {
|
|
|
|
Loc = getASTContext().getSourceManager().getFileLoc(Loc);
|
2016-02-13 07:10:59 +08:00
|
|
|
|
|
|
|
if (Roles & (unsigned)SymbolRole::Reference) {
|
|
|
|
const NamedDecl *ND = dyn_cast<NamedDecl>(D);
|
|
|
|
if (!ND)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (auto *ObjCID = dyn_cast_or_null<ObjCInterfaceDecl>(ASTNode.OrigD)) {
|
|
|
|
if (!ObjCID->isThisDeclarationADefinition() &&
|
|
|
|
ObjCID->getLocation() == Loc) {
|
|
|
|
// The libclang API treats this as ObjCClassRef declaration.
|
|
|
|
IndexingDeclVisitor(*this, Loc, nullptr).Visit(ObjCID);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-03-09 10:12:46 +08:00
|
|
|
if (auto *ObjCPD = dyn_cast_or_null<ObjCProtocolDecl>(ASTNode.OrigD)) {
|
|
|
|
if (!ObjCPD->isThisDeclarationADefinition() &&
|
|
|
|
ObjCPD->getLocation() == Loc) {
|
|
|
|
// The libclang API treats this as ObjCProtocolRef declaration.
|
|
|
|
IndexingDeclVisitor(*this, Loc, nullptr).Visit(ObjCPD);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-02-13 07:10:59 +08:00
|
|
|
|
|
|
|
CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct;
|
|
|
|
if (Roles & (unsigned)SymbolRole::Implicit) {
|
|
|
|
Kind = CXIdxEntityRef_Implicit;
|
|
|
|
}
|
2018-02-13 01:42:09 +08:00
|
|
|
CXSymbolRole CXRole = getSymbolRole(Roles);
|
2016-02-13 07:10:59 +08:00
|
|
|
|
|
|
|
CXCursor Cursor;
|
|
|
|
if (ASTNode.OrigE) {
|
|
|
|
Cursor = cxcursor::MakeCXCursor(ASTNode.OrigE,
|
|
|
|
cast<Decl>(ASTNode.ContainerDC),
|
|
|
|
getCXTU());
|
|
|
|
} else {
|
2016-04-01 04:18:22 +08:00
|
|
|
if (ASTNode.OrigD) {
|
|
|
|
if (auto *OrigND = dyn_cast<NamedDecl>(ASTNode.OrigD))
|
|
|
|
Cursor = getRefCursor(OrigND, Loc);
|
|
|
|
else
|
|
|
|
Cursor = MakeCXCursor(ASTNode.OrigD, CXTU);
|
|
|
|
} else {
|
|
|
|
Cursor = getRefCursor(ND, Loc);
|
|
|
|
}
|
2016-02-13 07:10:59 +08:00
|
|
|
}
|
|
|
|
handleReference(ND, Loc, Cursor,
|
|
|
|
dyn_cast_or_null<NamedDecl>(ASTNode.Parent),
|
2018-02-13 01:42:09 +08:00
|
|
|
ASTNode.ContainerDC, ASTNode.OrigE, Kind, CXRole);
|
2016-02-13 07:10:59 +08:00
|
|
|
|
|
|
|
} else {
|
2016-04-01 04:18:22 +08:00
|
|
|
const DeclContext *LexicalDC = ASTNode.ContainerDC;
|
|
|
|
if (!LexicalDC) {
|
|
|
|
for (const auto &SymRel : Relations) {
|
|
|
|
if (SymRel.Roles & (unsigned)SymbolRole::RelationChildOf)
|
|
|
|
LexicalDC = dyn_cast<DeclContext>(SymRel.RelatedSymbol);
|
|
|
|
}
|
2016-02-13 07:10:59 +08:00
|
|
|
}
|
2016-04-01 04:18:22 +08:00
|
|
|
IndexingDeclVisitor(*this, Loc, LexicalDC).Visit(ASTNode.OrigD);
|
2016-02-13 07:10:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return !shouldAbort();
|
|
|
|
}
|
|
|
|
|
2019-12-16 17:33:56 +08:00
|
|
|
bool CXIndexDataConsumer::handleModuleOccurrence(const ImportDecl *ImportD,
|
|
|
|
const Module *Mod,
|
|
|
|
SymbolRoleSet Roles,
|
|
|
|
SourceLocation Loc) {
|
2018-09-18 23:02:56 +08:00
|
|
|
if (Roles & (SymbolRoleSet)SymbolRole::Declaration)
|
|
|
|
IndexingDeclVisitor(*this, SourceLocation(), nullptr).Visit(ImportD);
|
2016-02-13 07:10:59 +08:00
|
|
|
return !shouldAbort();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXIndexDataConsumer::finish() {
|
|
|
|
indexDiagnostics();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CXIndexDataConsumer::ObjCProtocolListInfo::ObjCProtocolListInfo(
|
2011-11-12 10:16:30 +08:00
|
|
|
const ObjCProtocolList &ProtList,
|
2016-02-13 07:10:59 +08:00
|
|
|
CXIndexDataConsumer &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);
|
2014-06-08 16:38:04 +08:00
|
|
|
CXIdxObjCProtocolRefInfo ProtInfo = { nullptr,
|
2011-11-12 10:16:30 +08:00
|
|
|
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
|
2014-06-08 16:38:04 +08:00
|
|
|
IBCollInfo.objcClass = nullptr;
|
2011-12-15 08:05:00 +08:00
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
AttrListInfo::AttrListInfo(const Decl *D, CXIndexDataConsumer &IdxCtx)
|
2012-03-31 09:14:06 +08:00
|
|
|
: 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 =
|
2018-08-10 05:08:08 +08:00
|
|
|
IBAttr->getInterfaceLoc()->getTypeLoc().getBeginLoc();
|
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);
|
2014-06-08 16:38:04 +08:00
|
|
|
IBInfo.IBCollInfo.objcClass = nullptr;
|
2011-11-18 08:26:51 +08:00
|
|
|
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>
|
2016-02-13 07:10:59 +08:00
|
|
|
AttrListInfo::create(const Decl *D, CXIndexDataConsumer &IdxCtx) {
|
2012-03-31 09:14:06 +08:00
|
|
|
ScratchAlloc SA(IdxCtx);
|
|
|
|
AttrListInfo *attrs = SA.allocate<AttrListInfo>();
|
|
|
|
return new (attrs) AttrListInfo(D, IdxCtx);
|
2011-12-15 08:05:00 +08:00
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
CXIndexDataConsumer::CXXBasesListInfo::CXXBasesListInfo(const CXXRecordDecl *D,
|
|
|
|
CXIndexDataConsumer &IdxCtx,
|
2011-12-15 08:05:00 +08:00
|
|
|
ScratchAlloc &SA) {
|
2014-03-13 23:41:46 +08:00
|
|
|
for (const auto &Base : D->bases()) {
|
2011-11-22 15:24:51 +08:00
|
|
|
BaseEntities.push_back(EntityInfo());
|
2014-06-08 16:38:04 +08:00
|
|
|
const NamedDecl *BaseD = nullptr;
|
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);
|
2014-06-08 16:38:04 +08:00
|
|
|
CXIdxBaseClassInfo BaseInfo = { nullptr,
|
2011-11-22 15:24:51 +08:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
SourceLocation CXIndexDataConsumer::CXXBasesListInfo::getBaseLoc(
|
2011-12-08 04:44:15 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
void CXIndexDataConsumer::setASTContext(ASTContext &ctx) {
|
2011-10-18 03:48:19 +08:00
|
|
|
Ctx = &ctx;
|
2013-01-27 02:53:38 +08:00
|
|
|
cxtu::getASTUnit(CXTU)->setASTContext(&ctx);
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2017-01-06 03:48:07 +08:00
|
|
|
void CXIndexDataConsumer::setPreprocessor(std::shared_ptr<Preprocessor> PP) {
|
|
|
|
cxtu::getASTUnit(CXTU)->setPreprocessor(std::move(PP));
|
2012-01-18 02:48:07 +08:00
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::isFunctionLocalDecl(const Decl *D) {
|
2012-09-11 06:58:04 +08:00
|
|
|
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:
|
|
|
|
case InternalLinkage:
|
|
|
|
return true;
|
2017-07-08 08:37:59 +08:00
|
|
|
case VisibleNoLinkage:
|
|
|
|
case ModuleInternalLinkage:
|
2012-09-11 06:58:04 +08:00
|
|
|
case UniqueExternalLinkage:
|
2013-05-13 08:12:11 +08:00
|
|
|
llvm_unreachable("Not a sema linkage");
|
2017-07-08 08:37:59 +08:00
|
|
|
case ModuleLinkage:
|
2012-09-11 06:58:04 +08:00
|
|
|
case ExternalLinkage:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::shouldAbort() {
|
2011-11-18 08:26:51 +08:00
|
|
|
if (!CB.abortQuery)
|
|
|
|
return false;
|
2014-06-08 16:38:04 +08:00
|
|
|
return CB.abortQuery(ClientData, nullptr);
|
2011-11-18 08:26:51 +08:00
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
void CXIndexDataConsumer::enteredMainFile(const FileEntry *File) {
|
2011-11-11 08:23:36 +08:00
|
|
|
if (File && CB.enteredMainFile) {
|
2013-01-16 06:09:51 +08:00
|
|
|
CXIdxClientFile idxFile =
|
|
|
|
CB.enteredMainFile(ClientData,
|
2014-06-08 16:38:04 +08:00
|
|
|
static_cast<CXFile>(const_cast<FileEntry *>(File)),
|
|
|
|
nullptr);
|
2011-11-11 08:23:36 +08:00
|
|
|
FileMap[File] = idxFile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
void CXIndexDataConsumer::ppIncludedFile(SourceLocation hashLoc,
|
2011-10-18 03:48:19 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
void CXIndexDataConsumer::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
|
|
|
|
2016-09-02 04:15:25 +08:00
|
|
|
// If the imported module is part of the top-level module that we're
|
|
|
|
// indexing, it doesn't correspond to an imported AST file.
|
|
|
|
// FIXME: This assumes that AST files and top-level modules directly
|
|
|
|
// correspond, which is unlikely to remain true forever.
|
|
|
|
if (Module *SrcMod = ImportD->getImportedOwningModule())
|
|
|
|
if (SrcMod->getTopLevelModule() == Mod->getTopLevelModule())
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
void CXIndexDataConsumer::importedPCH(const FileEntry *File) {
|
2012-10-04 05:05:51 +08:00
|
|
|
if (!CB.importedASTFile)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CXIdxImportedASTFileInfo Info = {
|
2013-01-16 06:09:51 +08:00
|
|
|
static_cast<CXFile>(
|
|
|
|
const_cast<FileEntry *>(File)),
|
2014-06-08 16:38:04 +08:00
|
|
|
/*module=*/nullptr,
|
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;
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
void CXIndexDataConsumer::startedTranslationUnit() {
|
2014-06-08 16:38:04 +08:00
|
|
|
CXIdxClientContainer idxCont = nullptr;
|
2011-10-18 03:48:19 +08:00
|
|
|
if (CB.startedTranslationUnit)
|
2014-06-08 16:38:04 +08:00
|
|
|
idxCont = CB.startedTranslationUnit(ClientData, nullptr);
|
2011-10-18 03:48:19 +08:00
|
|
|
addContainerInMap(Ctx->getTranslationUnitDecl(), idxCont);
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
void CXIndexDataConsumer::indexDiagnostics() {
|
|
|
|
if (!hasDiagnosticCallback())
|
|
|
|
return;
|
|
|
|
|
|
|
|
CXDiagnosticSetImpl *DiagSet = cxdiag::lazyCreateDiags(getCXTU());
|
|
|
|
handleDiagnosticSet(DiagSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXIndexDataConsumer::handleDiagnosticSet(CXDiagnostic CXDiagSet) {
|
2011-10-18 03:48:19 +08:00
|
|
|
if (!CB.diagnostic)
|
|
|
|
return;
|
|
|
|
|
2014-06-08 16:38:04 +08:00
|
|
|
CB.diagnostic(ClientData, CXDiagSet, nullptr);
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::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,
|
2016-02-10 03:07:07 +08:00
|
|
|
const DeclContext *LexicalDC,
|
|
|
|
const DeclContext *SemaDC) {
|
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
|
|
|
|
2016-02-10 03:07:07 +08:00
|
|
|
if (!SemaDC)
|
|
|
|
SemaDC = D->getDeclContext();
|
|
|
|
getContainerInfo(SemaDC, DInfo.SemanticContainer);
|
2011-12-08 04:44:19 +08:00
|
|
|
DInfo.semanticContainer = &DInfo.SemanticContainer;
|
2012-02-11 04:10:44 +08:00
|
|
|
|
2016-02-10 03:07:07 +08:00
|
|
|
if (LexicalDC == SemaDC) {
|
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
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::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
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::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
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::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
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::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
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::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
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::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
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::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
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::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;
|
2014-06-08 16:38:04 +08:00
|
|
|
InterInfo.ObjCInterDeclInfo.superInfo = D->getSuperClass() ? &BaseClass
|
|
|
|
: nullptr;
|
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
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::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
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::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
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::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 {
|
2014-06-08 16:38:04 +08:00
|
|
|
CatDInfo.ObjCCatDeclInfo.objcClass = nullptr;
|
2011-11-16 10:34:59 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::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 {
|
2014-06-08 16:38:04 +08:00
|
|
|
CatDInfo.ObjCCatDeclInfo.objcClass = nullptr;
|
2011-11-16 10:35:05 +08:00
|
|
|
CatDInfo.ObjCCatDeclInfo.classCursor = clang_getNullCursor();
|
|
|
|
}
|
|
|
|
CatDInfo.ObjCCatDeclInfo.classLoc = getIndexLoc(ClassLoc);
|
2014-06-08 16:38:04 +08:00
|
|
|
CatDInfo.ObjCCatDeclInfo.protocols = nullptr;
|
2011-12-14 02:47:45 +08:00
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
return handleObjCContainer(D, CategoryLoc, getCursor(D), CatDInfo);
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2017-01-26 10:11:50 +08:00
|
|
|
bool CXIndexDataConsumer::handleObjCMethod(const ObjCMethodDecl *D,
|
|
|
|
SourceLocation Loc) {
|
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;
|
2017-01-26 10:11:50 +08:00
|
|
|
return handleDecl(D, Loc, getCursor(D), DInfo);
|
2011-11-18 08:26:51 +08:00
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::handleSynthesizedObjCProperty(
|
2011-11-18 08:26:51 +08:00
|
|
|
const ObjCPropertyImplDecl *D) {
|
|
|
|
ObjCPropertyDecl *PD = D->getPropertyDecl();
|
2016-02-10 03:07:19 +08:00
|
|
|
auto *DC = D->getDeclContext();
|
|
|
|
return handleReference(PD, D->getLocation(), getCursor(D),
|
|
|
|
dyn_cast<NamedDecl>(DC), DC);
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::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);
|
2016-04-01 04:18:22 +08:00
|
|
|
return handleDecl(D, Loc, getCursor(D), DInfo, LexicalDC, D->getDeclContext());
|
2011-11-18 08:26:51 +08:00
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::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 {
|
2014-06-08 16:38:04 +08:00
|
|
|
DInfo.ObjCPropDeclInfo.getter = nullptr;
|
2012-02-29 01:50:33 +08:00
|
|
|
}
|
|
|
|
if (ObjCMethodDecl *Setter = D->getSetterMethodDecl()) {
|
|
|
|
getEntityInfo(Setter, SetterEntity, SA);
|
|
|
|
DInfo.ObjCPropDeclInfo.setter = &SetterEntity;
|
|
|
|
} else {
|
2014-06-08 16:38:04 +08:00
|
|
|
DInfo.ObjCPropDeclInfo.setter = nullptr;
|
2012-02-29 01:50:33 +08:00
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::handleNamespace(const NamespaceDecl *D) {
|
2011-12-07 13:52:06 +08:00
|
|
|
DeclInfo DInfo(/*isRedeclaration=*/!D->isOriginalNamespace(),
|
|
|
|
/*isDefinition=*/true,
|
|
|
|
/*isContainer=*/true);
|
|
|
|
return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::handleClassTemplate(const ClassTemplateDecl *D) {
|
2011-11-22 15:24:51 +08:00
|
|
|
return handleCXXRecordDecl(D->getTemplatedDecl(), D);
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::handleFunctionTemplate(const FunctionTemplateDecl *D) {
|
2011-11-22 15:24:51 +08:00
|
|
|
DeclInfo DInfo(/*isRedeclaration=*/!D->isCanonicalDecl(),
|
|
|
|
/*isDefinition=*/D->isThisDeclarationADefinition(),
|
|
|
|
/*isContainer=*/D->isThisDeclarationADefinition());
|
|
|
|
return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::handleTypeAliasTemplate(const TypeAliasTemplateDecl *D) {
|
2011-11-22 15:24:51 +08:00
|
|
|
DeclInfo DInfo(/*isRedeclaration=*/!D->isCanonicalDecl(),
|
|
|
|
/*isDefinition=*/true, /*isContainer=*/false);
|
|
|
|
return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation Loc,
|
2011-11-18 08:26:51 +08:00
|
|
|
CXCursor Cursor,
|
|
|
|
const NamedDecl *Parent,
|
|
|
|
const DeclContext *DC,
|
|
|
|
const Expr *E,
|
2018-02-13 01:42:09 +08:00
|
|
|
CXIdxEntityRefKind Kind,
|
|
|
|
CXSymbolRole Role) {
|
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
|
|
|
|
[index] Return when DC is null in handleReference
Summary:
DC may sometimes be NULL and getContainerInfo(DC, Container) will dereference a null pointer.
Default template arguments (the following example and many test files in https://github.com/nlohmann/json)
may cause null pointer dereference.
```c++
template <typename>
struct actor;
template <template <typename> class Actor = actor>
struct terminal;
```
In tools/libclang/CXIndexDataConsumer.cpp#L203
handleReference(ND, Loc, Cursor,
dyn_cast_or_null<NamedDecl>(ASTNode.Parent),
ASTNode.ContainerDC, ASTNode.OrigE, Kind);
`dyn_cast_or_null<NamedDecl>(ASTNode.Parent)` is somehow a null pointer and in tools/libclang/CXIndexDataConsumer.cpp:935
ContainerInfo Container;
getContainerInfo(DC, Container);
The null DC is casted `ContInfo.cursor = getCursor(cast<Decl>(DC));` and SIGSEGV.
```
See discussions in https://github.com/jacobdufault/cquery/issues/219 https://github.com/jacobdufault/cquery/issues/192
Reviewers: akyrtzi, sammccall, yvvan
Reviewed By: sammccall
Subscribers: mehdi_amini, cfe-commits
Differential Revision: https://reviews.llvm.org/D41575
llvm-svn: 322017
2018-01-09 02:57:38 +08:00
|
|
|
if (!D || !DC)
|
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,
|
2014-06-08 16:38:04 +08:00
|
|
|
Parent ? &ParentEntity : nullptr,
|
2018-02-13 01:42:09 +08:00
|
|
|
&Container,
|
|
|
|
Role };
|
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
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::isNotFromSourceFile(SourceLocation Loc) const {
|
2011-10-18 03:48:19 +08:00
|
|
|
if (Loc.isInvalid())
|
|
|
|
return true;
|
|
|
|
SourceManager &SM = Ctx->getSourceManager();
|
|
|
|
SourceLocation FileLoc = SM.getFileLoc(Loc);
|
|
|
|
FileID FID = SM.getFileID(FileLoc);
|
2014-06-08 16:38:04 +08:00
|
|
|
return SM.getFileEntryForID(FID) == nullptr;
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
void CXIndexDataConsumer::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);
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
CXIdxClientEntity CXIndexDataConsumer::getClientEntity(const Decl *D) const {
|
2011-11-22 15:24:51 +08:00
|
|
|
if (!D)
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2011-11-22 15:24:51 +08:00
|
|
|
EntityMapTy::const_iterator I = EntityMap.find(D);
|
|
|
|
if (I == EntityMap.end())
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2011-11-22 15:24:51 +08:00
|
|
|
return I->second;
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
void CXIndexDataConsumer::setClientEntity(const Decl *D, CXIdxClientEntity client) {
|
2011-11-22 15:24:51 +08:00
|
|
|
if (!D)
|
|
|
|
return;
|
|
|
|
EntityMap[D] = client;
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::handleCXXRecordDecl(const CXXRecordDecl *RD,
|
2011-11-22 15:24:51 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::markEntityOccurrenceInFile(const NamedDecl *D,
|
2011-11-18 08:26:51 +08:00
|
|
|
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);
|
2015-12-28 23:24:08 +08:00
|
|
|
return !res.second; // already in map
|
2011-11-18 08:26:51 +08:00
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
const NamedDecl *CXIndexDataConsumer::getEntityDecl(const NamedDecl *D) const {
|
2011-10-18 03:48:19 +08:00
|
|
|
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 *
|
2016-02-13 07:10:59 +08:00
|
|
|
CXIndexDataConsumer::getEntityContainer(const Decl *D) const {
|
2011-11-22 15:24:51 +08:00
|
|
|
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
|
2016-02-13 07:10:59 +08:00
|
|
|
CXIndexDataConsumer::getClientContainerForDC(const DeclContext *DC) const {
|
2011-11-22 15:24:51 +08:00
|
|
|
if (!DC)
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2011-11-22 15:24:51 +08:00
|
|
|
|
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())
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2011-11-22 15:24:51 +08:00
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
return I->second;
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
CXIdxClientFile CXIndexDataConsumer::getIndexFile(const FileEntry *File) {
|
2011-10-18 03:48:19 +08:00
|
|
|
if (!File)
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2011-10-18 03:48:19 +08:00
|
|
|
|
|
|
|
FileMapTy::iterator FI = FileMap.find(File);
|
|
|
|
if (FI != FileMap.end())
|
|
|
|
return FI->second;
|
|
|
|
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
CXIdxLoc CXIndexDataConsumer::getIndexLoc(SourceLocation Loc) const {
|
2014-06-08 16:38:04 +08:00
|
|
|
CXIdxLoc idxLoc = { {nullptr, nullptr}, 0 };
|
2011-10-18 03:48:19 +08:00
|
|
|
if (Loc.isInvalid())
|
|
|
|
return idxLoc;
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
idxLoc.ptr_data[0] = const_cast<CXIndexDataConsumer *>(this);
|
2011-10-18 03:48:19 +08:00
|
|
|
idxLoc.int_data = Loc.getRawEncoding();
|
|
|
|
return idxLoc;
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
void CXIndexDataConsumer::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;
|
|
|
|
}
|
|
|
|
|
2016-03-26 01:01:59 +08:00
|
|
|
static CXIdxEntityKind getEntityKindFromSymbolKind(SymbolKind K, SymbolLanguage L);
|
2016-02-13 07:10:59 +08:00
|
|
|
static CXIdxEntityCXXTemplateKind
|
2016-11-12 07:49:55 +08:00
|
|
|
getEntityKindFromSymbolProperties(SymbolPropertySet K);
|
2016-02-13 07:10:59 +08:00
|
|
|
static CXIdxEntityLanguage getEntityLangFromSymbolLang(SymbolLanguage L);
|
|
|
|
|
|
|
|
void CXIndexDataConsumer::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;
|
2016-02-13 07:10:59 +08:00
|
|
|
|
|
|
|
SymbolInfo SymInfo = getSymbolInfo(D);
|
2016-03-26 01:01:59 +08:00
|
|
|
EntityInfo.kind = getEntityKindFromSymbolKind(SymInfo.Kind, SymInfo.Lang);
|
2016-11-12 07:49:55 +08:00
|
|
|
EntityInfo.templateKind = getEntityKindFromSymbolProperties(SymInfo.Properties);
|
2016-02-13 07:10:59 +08:00
|
|
|
EntityInfo.lang = getEntityLangFromSymbolLang(SymInfo.Lang);
|
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-22 15:24:51 +08:00
|
|
|
if (EntityInfo.kind == CXIdxEntity_Unexposed)
|
|
|
|
return;
|
|
|
|
|
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)) {
|
2014-06-08 16:38:04 +08:00
|
|
|
EntityInfo.name = nullptr; // 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) {
|
2014-06-08 16:38:04 +08:00
|
|
|
EntityInfo.USR = nullptr;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
void CXIndexDataConsumer::getContainerInfo(const DeclContext *DC,
|
2011-11-22 15:24:51 +08:00
|
|
|
ContainerInfo &ContInfo) {
|
|
|
|
ContInfo.cursor = getCursor(cast<Decl>(DC));
|
|
|
|
ContInfo.DC = DC;
|
|
|
|
ContInfo.IndexCtx = this;
|
|
|
|
}
|
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
CXCursor CXIndexDataConsumer::getRefCursor(const NamedDecl *D, SourceLocation Loc) {
|
2011-10-18 03:48:19 +08:00
|
|
|
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
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::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
|
|
|
|
2016-02-13 07:10:59 +08:00
|
|
|
bool CXIndexDataConsumer::isTemplateImplicitInstantiation(const Decl *D) {
|
2012-02-11 04:10:44 +08:00
|
|
|
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;
|
|
|
|
}
|
2016-02-13 07:10:59 +08:00
|
|
|
|
2016-03-26 01:01:59 +08:00
|
|
|
static CXIdxEntityKind getEntityKindFromSymbolKind(SymbolKind K, SymbolLanguage Lang) {
|
2016-02-13 07:10:59 +08:00
|
|
|
switch (K) {
|
|
|
|
case SymbolKind::Unknown:
|
|
|
|
case SymbolKind::Module:
|
|
|
|
case SymbolKind::Macro:
|
2016-03-26 01:01:59 +08:00
|
|
|
case SymbolKind::ClassProperty:
|
2017-08-17 07:12:21 +08:00
|
|
|
case SymbolKind::Using:
|
2020-01-30 21:07:42 +08:00
|
|
|
case SymbolKind::TemplateTypeParm:
|
|
|
|
case SymbolKind::TemplateTemplateParm:
|
|
|
|
case SymbolKind::NonTypeTemplateParm:
|
2016-02-13 07:10:59 +08:00
|
|
|
return CXIdxEntity_Unexposed;
|
|
|
|
|
|
|
|
case SymbolKind::Enum: return CXIdxEntity_Enum;
|
|
|
|
case SymbolKind::Struct: return CXIdxEntity_Struct;
|
|
|
|
case SymbolKind::Union: return CXIdxEntity_Union;
|
2016-03-26 01:01:59 +08:00
|
|
|
case SymbolKind::TypeAlias:
|
|
|
|
if (Lang == SymbolLanguage::CXX)
|
|
|
|
return CXIdxEntity_CXXTypeAlias;
|
|
|
|
return CXIdxEntity_Typedef;
|
2016-02-13 07:10:59 +08:00
|
|
|
case SymbolKind::Function: return CXIdxEntity_Function;
|
|
|
|
case SymbolKind::Variable: return CXIdxEntity_Variable;
|
2016-03-26 01:01:59 +08:00
|
|
|
case SymbolKind::Field:
|
|
|
|
if (Lang == SymbolLanguage::ObjC)
|
|
|
|
return CXIdxEntity_ObjCIvar;
|
|
|
|
return CXIdxEntity_Field;
|
2016-02-13 07:10:59 +08:00
|
|
|
case SymbolKind::EnumConstant: return CXIdxEntity_EnumConstant;
|
2016-03-26 01:01:59 +08:00
|
|
|
case SymbolKind::Class:
|
|
|
|
if (Lang == SymbolLanguage::ObjC)
|
|
|
|
return CXIdxEntity_ObjCClass;
|
|
|
|
return CXIdxEntity_CXXClass;
|
|
|
|
case SymbolKind::Protocol:
|
|
|
|
if (Lang == SymbolLanguage::ObjC)
|
|
|
|
return CXIdxEntity_ObjCProtocol;
|
|
|
|
return CXIdxEntity_CXXInterface;
|
|
|
|
case SymbolKind::Extension: return CXIdxEntity_ObjCCategory;
|
|
|
|
case SymbolKind::InstanceMethod:
|
|
|
|
if (Lang == SymbolLanguage::ObjC)
|
|
|
|
return CXIdxEntity_ObjCInstanceMethod;
|
|
|
|
return CXIdxEntity_CXXInstanceMethod;
|
|
|
|
case SymbolKind::ClassMethod: return CXIdxEntity_ObjCClassMethod;
|
|
|
|
case SymbolKind::StaticMethod: return CXIdxEntity_CXXStaticMethod;
|
|
|
|
case SymbolKind::InstanceProperty: return CXIdxEntity_ObjCProperty;
|
|
|
|
case SymbolKind::StaticProperty: return CXIdxEntity_CXXStaticVariable;
|
|
|
|
case SymbolKind::Namespace: return CXIdxEntity_CXXNamespace;
|
|
|
|
case SymbolKind::NamespaceAlias: return CXIdxEntity_CXXNamespaceAlias;
|
|
|
|
case SymbolKind::Constructor: return CXIdxEntity_CXXConstructor;
|
|
|
|
case SymbolKind::Destructor: return CXIdxEntity_CXXDestructor;
|
|
|
|
case SymbolKind::ConversionFunction: return CXIdxEntity_CXXConversionFunction;
|
2017-02-26 13:37:56 +08:00
|
|
|
case SymbolKind::Parameter: return CXIdxEntity_Variable;
|
2016-02-13 07:10:59 +08:00
|
|
|
}
|
2016-02-15 08:36:52 +08:00
|
|
|
llvm_unreachable("invalid symbol kind");
|
2016-02-13 07:10:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static CXIdxEntityCXXTemplateKind
|
2016-11-12 07:49:55 +08:00
|
|
|
getEntityKindFromSymbolProperties(SymbolPropertySet K) {
|
2017-12-24 03:31:24 +08:00
|
|
|
if (K & (SymbolPropertySet)SymbolProperty::TemplatePartialSpecialization)
|
2016-02-13 07:10:59 +08:00
|
|
|
return CXIdxEntity_TemplatePartialSpecialization;
|
2017-12-24 03:31:24 +08:00
|
|
|
if (K & (SymbolPropertySet)SymbolProperty::TemplateSpecialization)
|
2016-02-13 07:10:59 +08:00
|
|
|
return CXIdxEntity_TemplateSpecialization;
|
2017-12-24 03:31:24 +08:00
|
|
|
if (K & (SymbolPropertySet)SymbolProperty::Generic)
|
2016-04-22 15:21:04 +08:00
|
|
|
return CXIdxEntity_Template;
|
|
|
|
return CXIdxEntity_NonTemplate;
|
2016-02-13 07:10:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static CXIdxEntityLanguage getEntityLangFromSymbolLang(SymbolLanguage L) {
|
|
|
|
switch (L) {
|
|
|
|
case SymbolLanguage::C: return CXIdxEntityLang_C;
|
|
|
|
case SymbolLanguage::ObjC: return CXIdxEntityLang_ObjC;
|
|
|
|
case SymbolLanguage::CXX: return CXIdxEntityLang_CXX;
|
2017-04-24 22:52:00 +08:00
|
|
|
case SymbolLanguage::Swift: return CXIdxEntityLang_Swift;
|
2016-02-13 07:10:59 +08:00
|
|
|
}
|
2016-02-15 08:36:52 +08:00
|
|
|
llvm_unreachable("invalid symbol language");
|
2016-02-13 07:10:59 +08:00
|
|
|
}
|