blob: e02a4fa81a77f170bd48502311250925898c2a9d [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) {
35 const NamedDecl *D = E->getDecl();
36 if (!D)
37 return true;
38 if (D->getParentFunctionOrMethod())
39 return true;
40
41 IndexCtx.handleReference(D, E->getLocation(), 0, ParentDC, E);
42 return true;
43 }
44
45 bool VisitMemberExpr(MemberExpr *E) {
46 const NamedDecl *D = E->getMemberDecl();
47 if (!D)
48 return true;
49 if (D->getParentFunctionOrMethod())
50 return true;
51
52 IndexCtx.handleReference(D, E->getMemberLoc(), 0, ParentDC, E);
53 return true;
54 }
55
56 bool VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
57 const NamedDecl *D = E->getDecl();
58 if (!D)
59 return true;
60 if (D->getParentFunctionOrMethod())
61 return true;
62
63 IndexCtx.handleReference(D, E->getLocation(), 0, ParentDC, E);
64 return true;
65 }
66};
67
68} // anonymous namespace
69
70void IndexingContext::indexBody(const Stmt *S, const DeclContext *DC) {
71 BodyIndexer(*this, DC).TraverseStmt(const_cast<Stmt*>(S));
72}