2011-10-18 03:48:19 +08:00
|
|
|
//===- CIndexHigh.cpp - Higher level API functions ------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "IndexingContext.h"
|
2013-12-20 10:02:54 +08:00
|
|
|
#include "clang/AST/DataRecursiveASTVisitor.h"
|
2011-10-18 03:48:19 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
using namespace cxindex;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2013-12-20 10:02:54 +08:00
|
|
|
class BodyIndexer : public DataRecursiveASTVisitor<BodyIndexer> {
|
2011-10-18 03:48:19 +08:00
|
|
|
IndexingContext &IndexCtx;
|
2011-12-14 02:47:41 +08:00
|
|
|
const NamedDecl *Parent;
|
2011-10-18 03:48:19 +08:00
|
|
|
const DeclContext *ParentDC;
|
|
|
|
|
2013-12-20 10:02:54 +08:00
|
|
|
typedef DataRecursiveASTVisitor<BodyIndexer> base;
|
2011-10-18 03:48:19 +08:00
|
|
|
public:
|
2011-12-14 02:47:41 +08:00
|
|
|
BodyIndexer(IndexingContext &indexCtx,
|
|
|
|
const NamedDecl *Parent, const DeclContext *DC)
|
2012-01-12 10:34:39 +08:00
|
|
|
: IndexCtx(indexCtx), Parent(Parent), ParentDC(DC) { }
|
2011-10-18 03:48:19 +08:00
|
|
|
|
|
|
|
bool shouldWalkTypesOfTypeLocs() const { return false; }
|
|
|
|
|
|
|
|
bool TraverseTypeLoc(TypeLoc TL) {
|
2011-12-14 02:47:41 +08:00
|
|
|
IndexCtx.indexTypeLoc(TL, Parent, ParentDC);
|
2011-10-18 03:48:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-24 00:58:38 +08:00
|
|
|
bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) {
|
|
|
|
IndexCtx.indexNestedNameSpecifierLoc(NNS, Parent, ParentDC);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
bool VisitDeclRefExpr(DeclRefExpr *E) {
|
2011-12-14 02:47:41 +08:00
|
|
|
IndexCtx.handleReference(E->getDecl(), E->getLocation(),
|
|
|
|
Parent, ParentDC, E);
|
2011-10-18 03:48:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitMemberExpr(MemberExpr *E) {
|
2011-12-14 02:47:41 +08:00
|
|
|
IndexCtx.handleReference(E->getMemberDecl(), E->getMemberLoc(),
|
|
|
|
Parent, ParentDC, E);
|
2011-10-18 03:48:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-02-22 10:10:41 +08:00
|
|
|
bool VisitDesignatedInitExpr(DesignatedInitExpr *E) {
|
|
|
|
for (DesignatedInitExpr::reverse_designators_iterator
|
|
|
|
D = E->designators_rbegin(), DEnd = E->designators_rend();
|
|
|
|
D != DEnd; ++D) {
|
|
|
|
if (D->isFieldDesignator())
|
|
|
|
IndexCtx.handleReference(D->getField(), D->getFieldLoc(),
|
|
|
|
Parent, ParentDC, E);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
bool VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
|
2011-12-14 02:47:41 +08:00
|
|
|
IndexCtx.handleReference(E->getDecl(), E->getLocation(),
|
|
|
|
Parent, ParentDC, E);
|
2011-10-18 03:48:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
2011-10-18 23:13:11 +08:00
|
|
|
|
|
|
|
bool VisitObjCMessageExpr(ObjCMessageExpr *E) {
|
|
|
|
if (ObjCMethodDecl *MD = E->getMethodDecl())
|
2011-12-14 02:47:41 +08:00
|
|
|
IndexCtx.handleReference(MD, E->getSelectorStartLoc(),
|
|
|
|
Parent, ParentDC, E,
|
2012-01-12 10:34:39 +08:00
|
|
|
E->isImplicit() ? CXIdxEntityRef_Implicit
|
|
|
|
: CXIdxEntityRef_Direct);
|
2011-10-18 23:13:11 +08:00
|
|
|
return true;
|
|
|
|
}
|
2011-10-18 23:50:50 +08:00
|
|
|
|
|
|
|
bool VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
|
2012-03-07 04:06:06 +08:00
|
|
|
if (E->isExplicitProperty())
|
2011-12-14 02:47:41 +08:00
|
|
|
IndexCtx.handleReference(E->getExplicitProperty(), E->getLocation(),
|
|
|
|
Parent, ParentDC, E);
|
2012-03-07 04:06:06 +08:00
|
|
|
|
|
|
|
// No need to do a handleReference for the objc method, because there will
|
|
|
|
// be a message expr as part of PseudoObjectExpr.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-16 15:28:30 +08:00
|
|
|
bool VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
|
|
|
|
IndexCtx.handleReference(E->getPropertyDecl(), E->getMemberLoc(), Parent,
|
|
|
|
ParentDC, E, CXIdxEntityRef_Direct);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-16 08:50:02 +08:00
|
|
|
bool VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
|
|
|
|
IndexCtx.handleReference(E->getProtocol(), E->getProtocolIdLoc(),
|
|
|
|
Parent, ParentDC, E, CXIdxEntityRef_Direct);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-19 08:25:12 +08:00
|
|
|
bool VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
|
|
|
|
if (ObjCMethodDecl *MD = E->getBoxingMethod())
|
2012-03-07 04:06:06 +08:00
|
|
|
IndexCtx.handleReference(MD, E->getLocStart(),
|
|
|
|
Parent, ParentDC, E, CXIdxEntityRef_Implicit);
|
|
|
|
return true;
|
|
|
|
}
|
2012-04-19 08:25:12 +08:00
|
|
|
|
2012-03-07 04:06:06 +08:00
|
|
|
bool VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
|
|
|
|
if (ObjCMethodDecl *MD = E->getDictWithObjectsMethod())
|
|
|
|
IndexCtx.handleReference(MD, E->getLocStart(),
|
|
|
|
Parent, ParentDC, E, CXIdxEntityRef_Implicit);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
|
|
|
|
if (ObjCMethodDecl *MD = E->getArrayWithObjectsMethod())
|
|
|
|
IndexCtx.handleReference(MD, E->getLocStart(),
|
|
|
|
Parent, ParentDC, E, CXIdxEntityRef_Implicit);
|
2011-10-18 23:50:50 +08:00
|
|
|
return true;
|
|
|
|
}
|
2011-11-18 08:26:51 +08:00
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
bool VisitCXXConstructExpr(CXXConstructExpr *E) {
|
2011-12-14 02:47:41 +08:00
|
|
|
IndexCtx.handleReference(E->getConstructor(), E->getLocation(),
|
|
|
|
Parent, ParentDC, E);
|
2011-11-22 15:24:51 +08:00
|
|
|
return true;
|
|
|
|
}
|
2012-01-14 08:11:49 +08:00
|
|
|
|
2012-05-08 06:16:49 +08:00
|
|
|
bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
|
|
|
|
if (E->getOperatorLoc().isInvalid())
|
|
|
|
return true; // implicit.
|
|
|
|
return base::TraverseCXXOperatorCallExpr(E);
|
|
|
|
}
|
|
|
|
|
2012-01-14 08:11:49 +08:00
|
|
|
bool VisitDeclStmt(DeclStmt *S) {
|
2012-09-11 06:58:04 +08:00
|
|
|
if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
|
2012-01-14 08:11:49 +08:00
|
|
|
IndexCtx.indexDeclGroupRef(S->getDeclGroup());
|
2012-09-11 06:58:04 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeclGroupRef DG = S->getDeclGroup();
|
|
|
|
for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I) {
|
|
|
|
const Decl *D = *I;
|
|
|
|
if (!D)
|
|
|
|
continue;
|
|
|
|
if (!IndexCtx.isFunctionLocalDecl(D))
|
|
|
|
IndexCtx.indexTopLevelDecl(D);
|
|
|
|
}
|
|
|
|
|
2012-01-14 08:11:49 +08:00
|
|
|
return true;
|
|
|
|
}
|
2012-02-15 10:07:05 +08:00
|
|
|
|
2014-05-21 06:03:39 +08:00
|
|
|
bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C) {
|
|
|
|
if (C->capturesThis())
|
2012-02-15 08:54:55 +08:00
|
|
|
return true;
|
2012-02-15 10:07:05 +08:00
|
|
|
|
2014-05-21 06:03:39 +08:00
|
|
|
if (C->capturesVariable() && IndexCtx.shouldIndexFunctionLocalSymbols())
|
|
|
|
IndexCtx.handleReference(C->getCapturedVar(), C->getLocation(), Parent,
|
|
|
|
ParentDC);
|
2013-05-16 14:20:58 +08:00
|
|
|
|
|
|
|
// FIXME: Lambda init-captures.
|
2012-02-15 08:54:55 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2011-12-14 02:47:41 +08:00
|
|
|
void IndexingContext::indexBody(const Stmt *S, const NamedDecl *Parent,
|
|
|
|
const DeclContext *DC) {
|
|
|
|
if (!S)
|
|
|
|
return;
|
|
|
|
|
2014-06-08 16:38:04 +08:00
|
|
|
if (!DC)
|
2011-12-14 02:47:41 +08:00
|
|
|
DC = Parent->getLexicalDeclContext();
|
|
|
|
BodyIndexer(*this, Parent, DC).TraverseStmt(const_cast<Stmt*>(S));
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|