blob: 6dd45af814a9f898a9ed39421e255be98cb3afb3 [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;
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +000021 const NamedDecl *Parent;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000022 const DeclContext *ParentDC;
23
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +000024 typedef RecursiveASTVisitor<BodyIndexer> base;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000025public:
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +000026 BodyIndexer(IndexingContext &indexCtx,
27 const NamedDecl *Parent, const DeclContext *DC)
Argyrios Kyrtzidis746f5bc2012-01-12 02:34:39 +000028 : IndexCtx(indexCtx), Parent(Parent), ParentDC(DC) { }
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000029
30 bool shouldWalkTypesOfTypeLocs() const { return false; }
31
32 bool TraverseTypeLoc(TypeLoc TL) {
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +000033 IndexCtx.indexTypeLoc(TL, Parent, ParentDC);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000034 return true;
35 }
36
37 bool VisitDeclRefExpr(DeclRefExpr *E) {
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +000038 IndexCtx.handleReference(E->getDecl(), E->getLocation(),
39 Parent, ParentDC, E);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000040 return true;
41 }
42
43 bool VisitMemberExpr(MemberExpr *E) {
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +000044 IndexCtx.handleReference(E->getMemberDecl(), E->getMemberLoc(),
45 Parent, ParentDC, E);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000046 return true;
47 }
48
49 bool VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +000050 IndexCtx.handleReference(E->getDecl(), E->getLocation(),
51 Parent, ParentDC, E);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000052 return true;
53 }
Argyrios Kyrtzidis9fbbf142011-10-18 15:13:11 +000054
55 bool VisitObjCMessageExpr(ObjCMessageExpr *E) {
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +000056 if (TypeSourceInfo *Cls = E->getClassReceiverTypeInfo())
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +000057 IndexCtx.indexTypeSourceInfo(Cls, Parent, ParentDC);
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +000058
Argyrios Kyrtzidis9fbbf142011-10-18 15:13:11 +000059 if (ObjCMethodDecl *MD = E->getMethodDecl())
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +000060 IndexCtx.handleReference(MD, E->getSelectorStartLoc(),
61 Parent, ParentDC, E,
Argyrios Kyrtzidis746f5bc2012-01-12 02:34:39 +000062 E->isImplicit() ? CXIdxEntityRef_Implicit
63 : CXIdxEntityRef_Direct);
Argyrios Kyrtzidis9fbbf142011-10-18 15:13:11 +000064 return true;
65 }
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +000066
67 bool VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
68 if (E->isImplicitProperty()) {
69 if (ObjCMethodDecl *MD = E->getImplicitPropertyGetter())
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +000070 IndexCtx.handleReference(MD, E->getLocation(), Parent, ParentDC, E,
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +000071 CXIdxEntityRef_Implicit);
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +000072 if (ObjCMethodDecl *MD = E->getImplicitPropertySetter())
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +000073 IndexCtx.handleReference(MD, E->getLocation(), Parent, ParentDC, E,
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +000074 CXIdxEntityRef_Implicit);
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +000075 } else {
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +000076 IndexCtx.handleReference(E->getExplicitProperty(), E->getLocation(),
77 Parent, ParentDC, E);
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +000078 }
79 return true;
80 }
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +000081
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +000082 bool VisitCXXConstructExpr(CXXConstructExpr *E) {
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +000083 IndexCtx.handleReference(E->getConstructor(), E->getLocation(),
84 Parent, ParentDC, E);
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +000085 return true;
86 }
Argyrios Kyrtzidis22490742012-01-14 00:11:49 +000087
88 bool VisitDeclStmt(DeclStmt *S) {
89 if (IndexCtx.indexFunctionLocalSymbols())
90 IndexCtx.indexDeclGroupRef(S->getDeclGroup());
91 return true;
92 }
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000093};
94
95} // anonymous namespace
96
Argyrios Kyrtzidise422e452011-12-13 18:47:41 +000097void IndexingContext::indexBody(const Stmt *S, const NamedDecl *Parent,
98 const DeclContext *DC) {
99 if (!S)
100 return;
101
102 if (DC == 0)
103 DC = Parent->getLexicalDeclContext();
104 BodyIndexer(*this, Parent, DC).TraverseStmt(const_cast<Stmt*>(S));
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +0000105}