Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 1 | //===- 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 | |
| 14 | using namespace clang; |
| 15 | using namespace cxindex; |
| 16 | |
| 17 | namespace { |
| 18 | |
| 19 | class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> { |
| 20 | IndexingContext &IndexCtx; |
| 21 | const DeclContext *ParentDC; |
| 22 | |
| 23 | public: |
| 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 Kyrtzidis | d6c8209 | 2011-11-16 02:35:01 +0000 | [diff] [blame] | 35 | IndexCtx.handleReference(E->getDecl(), E->getLocation(), 0, ParentDC, E); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 36 | return true; |
| 37 | } |
| 38 | |
| 39 | bool VisitMemberExpr(MemberExpr *E) { |
Argyrios Kyrtzidis | d6c8209 | 2011-11-16 02:35:01 +0000 | [diff] [blame] | 40 | IndexCtx.handleReference(E->getMemberDecl(), E->getMemberLoc(), 0, ParentDC, |
| 41 | E); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 42 | return true; |
| 43 | } |
| 44 | |
| 45 | bool VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Argyrios Kyrtzidis | d6c8209 | 2011-11-16 02:35:01 +0000 | [diff] [blame] | 46 | IndexCtx.handleReference(E->getDecl(), E->getLocation(), 0, ParentDC, E); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 47 | return true; |
| 48 | } |
Argyrios Kyrtzidis | 9fbbf14 | 2011-10-18 15:13:11 +0000 | [diff] [blame] | 49 | |
| 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 Kyrtzidis | aca19be | 2011-10-18 15:50:50 +0000 | [diff] [blame] | 55 | |
| 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 Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | } // anonymous namespace |
| 73 | |
| 74 | void IndexingContext::indexBody(const Stmt *S, const DeclContext *DC) { |
| 75 | BodyIndexer(*this, DC).TraverseStmt(const_cast<Stmt*>(S)); |
| 76 | } |