blob: ece1ed429ca99e50e37868fbd9ab371f2070e67a [file] [log] [blame]
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +00001//===- CIndexHigh.cpp - Higher level API functions ------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "IndexingContext.h"
11
12#include "clang/AST/RecursiveASTVisitor.h"
13
14using namespace clang;
15using namespace cxindex;
16
17namespace {
18
19class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
20 IndexingContext &IndexCtx;
21 const DeclContext *ParentDC;
22
23public:
24 BodyIndexer(IndexingContext &indexCtx, const DeclContext *DC)
25 : IndexCtx(indexCtx), ParentDC(DC) { }
26
27 bool shouldWalkTypesOfTypeLocs() const { return false; }
28
29 bool TraverseTypeLoc(TypeLoc TL) {
30 IndexCtx.indexTypeLoc(TL, 0, ParentDC);
31 return true;
32 }
33
34 bool VisitDeclRefExpr(DeclRefExpr *E) {
Argyrios Kyrtzidisd6c82092011-11-16 02:35:01 +000035 IndexCtx.handleReference(E->getDecl(), E->getLocation(), 0, ParentDC, E);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000036 return true;
37 }
38
39 bool VisitMemberExpr(MemberExpr *E) {
Argyrios Kyrtzidisd6c82092011-11-16 02:35:01 +000040 IndexCtx.handleReference(E->getMemberDecl(), E->getMemberLoc(), 0, ParentDC,
41 E);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000042 return true;
43 }
44
45 bool VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Argyrios Kyrtzidisd6c82092011-11-16 02:35:01 +000046 IndexCtx.handleReference(E->getDecl(), E->getLocation(), 0, ParentDC, E);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000047 return true;
48 }
Argyrios Kyrtzidis9fbbf142011-10-18 15:13:11 +000049
50 bool VisitObjCMessageExpr(ObjCMessageExpr *E) {
51 if (ObjCMethodDecl *MD = E->getMethodDecl())
52 IndexCtx.handleReference(MD, E->getSelectorStartLoc(), 0, ParentDC, E);
53 return true;
54 }
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +000055
56 bool VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
57 if (E->isImplicitProperty()) {
58 if (ObjCMethodDecl *MD = E->getImplicitPropertyGetter())
59 IndexCtx.handleReference(MD, E->getLocation(), 0, ParentDC, E,
60 CXIdxEntityRef_ImplicitProperty);
61 if (ObjCMethodDecl *MD = E->getImplicitPropertySetter())
62 IndexCtx.handleReference(MD, E->getLocation(), 0, ParentDC, E,
63 CXIdxEntityRef_ImplicitProperty);
64 } else {
65 IndexCtx.handleReference(E->getExplicitProperty(), E->getLocation(), 0,
66 ParentDC, E);
67 }
68 return true;
69 }
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000070};
71
72} // anonymous namespace
73
74void IndexingContext::indexBody(const Stmt *S, const DeclContext *DC) {
75 BodyIndexer(*this, DC).TraverseStmt(const_cast<Stmt*>(S));
76}