2011-10-18 03:48:19 +08:00
|
|
|
//===- CIndexHigh.cpp - Higher level API functions ------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "IndexingContext.h"
|
|
|
|
|
|
|
|
#include "clang/AST/RecursiveASTVisitor.h"
|
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
using namespace cxindex;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
|
|
|
|
IndexingContext &IndexCtx;
|
2011-12-14 02:47:41 +08:00
|
|
|
const NamedDecl *Parent;
|
2011-10-18 03:48:19 +08:00
|
|
|
const DeclContext *ParentDC;
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
typedef RecursiveASTVisitor<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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2011-11-18 08:26:51 +08:00
|
|
|
if (TypeSourceInfo *Cls = E->getClassReceiverTypeInfo())
|
2011-12-14 02:47:41 +08:00
|
|
|
IndexCtx.indexTypeSourceInfo(Cls, Parent, ParentDC);
|
2011-11-18 08:26:51 +08:00
|
|
|
|
2011-10-18 23:13:11 +08:00
|
|
|
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) {
|
|
|
|
if (E->isImplicitProperty()) {
|
|
|
|
if (ObjCMethodDecl *MD = E->getImplicitPropertyGetter())
|
2011-12-14 02:47:41 +08:00
|
|
|
IndexCtx.handleReference(MD, E->getLocation(), Parent, ParentDC, E,
|
2011-11-18 08:26:51 +08:00
|
|
|
CXIdxEntityRef_Implicit);
|
2011-10-18 23:50:50 +08:00
|
|
|
if (ObjCMethodDecl *MD = E->getImplicitPropertySetter())
|
2011-12-14 02:47:41 +08:00
|
|
|
IndexCtx.handleReference(MD, E->getLocation(), Parent, ParentDC, E,
|
2011-11-18 08:26:51 +08:00
|
|
|
CXIdxEntityRef_Implicit);
|
2011-10-18 23:50:50 +08:00
|
|
|
} else {
|
2011-12-14 02:47:41 +08:00
|
|
|
IndexCtx.handleReference(E->getExplicitProperty(), E->getLocation(),
|
|
|
|
Parent, ParentDC, E);
|
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
|
|
|
|
|
|
|
bool VisitDeclStmt(DeclStmt *S) {
|
|
|
|
if (IndexCtx.indexFunctionLocalSymbols())
|
|
|
|
IndexCtx.indexDeclGroupRef(S->getDeclGroup());
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (DC == 0)
|
|
|
|
DC = Parent->getLexicalDeclContext();
|
|
|
|
BodyIndexer(*this, Parent, DC).TraverseStmt(const_cast<Stmt*>(S));
|
2011-10-18 03:48:19 +08:00
|
|
|
}
|