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" |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame^] | 13 | #include "clang/Analysis/Support/SaveAndRestore.h" |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 14 | |
| 15 | using namespace clang; |
| 16 | using namespace cxindex; |
| 17 | |
| 18 | namespace { |
| 19 | |
| 20 | class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> { |
| 21 | IndexingContext &IndexCtx; |
| 22 | const DeclContext *ParentDC; |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame^] | 23 | bool InPseudoObject; |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 24 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame^] | 25 | typedef RecursiveASTVisitor<BodyIndexer> base; |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 26 | public: |
| 27 | BodyIndexer(IndexingContext &indexCtx, const DeclContext *DC) |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame^] | 28 | : IndexCtx(indexCtx), ParentDC(DC), InPseudoObject(false) { } |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 29 | |
| 30 | bool shouldWalkTypesOfTypeLocs() const { return false; } |
| 31 | |
| 32 | bool TraverseTypeLoc(TypeLoc TL) { |
| 33 | IndexCtx.indexTypeLoc(TL, 0, ParentDC); |
| 34 | return true; |
| 35 | } |
| 36 | |
| 37 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
Argyrios Kyrtzidis | d6c8209 | 2011-11-16 02:35:01 +0000 | [diff] [blame] | 38 | IndexCtx.handleReference(E->getDecl(), E->getLocation(), 0, ParentDC, E); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 39 | return true; |
| 40 | } |
| 41 | |
| 42 | bool VisitMemberExpr(MemberExpr *E) { |
Argyrios Kyrtzidis | d6c8209 | 2011-11-16 02:35:01 +0000 | [diff] [blame] | 43 | IndexCtx.handleReference(E->getMemberDecl(), E->getMemberLoc(), 0, ParentDC, |
| 44 | E); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 45 | return true; |
| 46 | } |
| 47 | |
| 48 | bool VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Argyrios Kyrtzidis | d6c8209 | 2011-11-16 02:35:01 +0000 | [diff] [blame] | 49 | IndexCtx.handleReference(E->getDecl(), E->getLocation(), 0, ParentDC, E); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 50 | return true; |
| 51 | } |
Argyrios Kyrtzidis | 9fbbf14 | 2011-10-18 15:13:11 +0000 | [diff] [blame] | 52 | |
| 53 | bool VisitObjCMessageExpr(ObjCMessageExpr *E) { |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame^] | 54 | if (TypeSourceInfo *Cls = E->getClassReceiverTypeInfo()) |
| 55 | IndexCtx.indexTypeSourceInfo(Cls, 0, ParentDC); |
| 56 | |
Argyrios Kyrtzidis | 9fbbf14 | 2011-10-18 15:13:11 +0000 | [diff] [blame] | 57 | if (ObjCMethodDecl *MD = E->getMethodDecl()) |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame^] | 58 | IndexCtx.handleReference(MD, E->getSelectorStartLoc(), 0, ParentDC, E, |
| 59 | InPseudoObject ? CXIdxEntityRef_Implicit |
| 60 | : CXIdxEntityRef_Direct); |
Argyrios Kyrtzidis | 9fbbf14 | 2011-10-18 15:13:11 +0000 | [diff] [blame] | 61 | return true; |
| 62 | } |
Argyrios Kyrtzidis | aca19be | 2011-10-18 15:50:50 +0000 | [diff] [blame] | 63 | |
| 64 | bool VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
| 65 | if (E->isImplicitProperty()) { |
| 66 | if (ObjCMethodDecl *MD = E->getImplicitPropertyGetter()) |
| 67 | IndexCtx.handleReference(MD, E->getLocation(), 0, ParentDC, E, |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame^] | 68 | CXIdxEntityRef_Implicit); |
Argyrios Kyrtzidis | aca19be | 2011-10-18 15:50:50 +0000 | [diff] [blame] | 69 | if (ObjCMethodDecl *MD = E->getImplicitPropertySetter()) |
| 70 | IndexCtx.handleReference(MD, E->getLocation(), 0, ParentDC, E, |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame^] | 71 | CXIdxEntityRef_Implicit); |
Argyrios Kyrtzidis | aca19be | 2011-10-18 15:50:50 +0000 | [diff] [blame] | 72 | } else { |
| 73 | IndexCtx.handleReference(E->getExplicitProperty(), E->getLocation(), 0, |
| 74 | ParentDC, E); |
| 75 | } |
| 76 | return true; |
| 77 | } |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame^] | 78 | |
| 79 | bool TraversePseudoObjectExpr(PseudoObjectExpr *E) { |
| 80 | SaveAndRestore<bool> InPseudo(InPseudoObject, true); |
| 81 | return base::TraversePseudoObjectExpr(E); |
| 82 | } |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | } // anonymous namespace |
| 86 | |
| 87 | void IndexingContext::indexBody(const Stmt *S, const DeclContext *DC) { |
| 88 | BodyIndexer(*this, DC).TraverseStmt(const_cast<Stmt*>(S)); |
| 89 | } |