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; |
Argyrios Kyrtzidis | e422e45 | 2011-12-13 18:47:41 +0000 | [diff] [blame] | 21 | const NamedDecl *Parent; |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 22 | const DeclContext *ParentDC; |
| 23 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 24 | typedef RecursiveASTVisitor<BodyIndexer> base; |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 25 | public: |
Argyrios Kyrtzidis | e422e45 | 2011-12-13 18:47:41 +0000 | [diff] [blame] | 26 | BodyIndexer(IndexingContext &indexCtx, |
| 27 | const NamedDecl *Parent, const DeclContext *DC) |
Argyrios Kyrtzidis | 746f5bc | 2012-01-12 02:34:39 +0000 | [diff] [blame] | 28 | : IndexCtx(indexCtx), Parent(Parent), ParentDC(DC) { } |
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) { |
Argyrios Kyrtzidis | e422e45 | 2011-12-13 18:47:41 +0000 | [diff] [blame] | 33 | IndexCtx.indexTypeLoc(TL, Parent, ParentDC); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 34 | return true; |
| 35 | } |
| 36 | |
| 37 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
Argyrios Kyrtzidis | e422e45 | 2011-12-13 18:47:41 +0000 | [diff] [blame] | 38 | IndexCtx.handleReference(E->getDecl(), E->getLocation(), |
| 39 | Parent, ParentDC, E); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 40 | return true; |
| 41 | } |
| 42 | |
| 43 | bool VisitMemberExpr(MemberExpr *E) { |
Argyrios Kyrtzidis | e422e45 | 2011-12-13 18:47:41 +0000 | [diff] [blame] | 44 | IndexCtx.handleReference(E->getMemberDecl(), E->getMemberLoc(), |
| 45 | Parent, ParentDC, E); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 46 | return true; |
| 47 | } |
| 48 | |
| 49 | bool VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Argyrios Kyrtzidis | e422e45 | 2011-12-13 18:47:41 +0000 | [diff] [blame] | 50 | IndexCtx.handleReference(E->getDecl(), E->getLocation(), |
| 51 | Parent, ParentDC, E); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 52 | return true; |
| 53 | } |
Argyrios Kyrtzidis | 9fbbf14 | 2011-10-18 15:13:11 +0000 | [diff] [blame] | 54 | |
| 55 | bool VisitObjCMessageExpr(ObjCMessageExpr *E) { |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 56 | if (TypeSourceInfo *Cls = E->getClassReceiverTypeInfo()) |
Argyrios Kyrtzidis | e422e45 | 2011-12-13 18:47:41 +0000 | [diff] [blame] | 57 | IndexCtx.indexTypeSourceInfo(Cls, Parent, ParentDC); |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 58 | |
Argyrios Kyrtzidis | 9fbbf14 | 2011-10-18 15:13:11 +0000 | [diff] [blame] | 59 | if (ObjCMethodDecl *MD = E->getMethodDecl()) |
Argyrios Kyrtzidis | e422e45 | 2011-12-13 18:47:41 +0000 | [diff] [blame] | 60 | IndexCtx.handleReference(MD, E->getSelectorStartLoc(), |
| 61 | Parent, ParentDC, E, |
Argyrios Kyrtzidis | 746f5bc | 2012-01-12 02:34:39 +0000 | [diff] [blame] | 62 | E->isImplicit() ? CXIdxEntityRef_Implicit |
| 63 | : CXIdxEntityRef_Direct); |
Argyrios Kyrtzidis | 9fbbf14 | 2011-10-18 15:13:11 +0000 | [diff] [blame] | 64 | return true; |
| 65 | } |
Argyrios Kyrtzidis | aca19be | 2011-10-18 15:50:50 +0000 | [diff] [blame] | 66 | |
| 67 | bool VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
| 68 | if (E->isImplicitProperty()) { |
| 69 | if (ObjCMethodDecl *MD = E->getImplicitPropertyGetter()) |
Argyrios Kyrtzidis | e422e45 | 2011-12-13 18:47:41 +0000 | [diff] [blame] | 70 | IndexCtx.handleReference(MD, E->getLocation(), Parent, 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 | if (ObjCMethodDecl *MD = E->getImplicitPropertySetter()) |
Argyrios Kyrtzidis | e422e45 | 2011-12-13 18:47:41 +0000 | [diff] [blame] | 73 | IndexCtx.handleReference(MD, E->getLocation(), Parent, ParentDC, E, |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 74 | CXIdxEntityRef_Implicit); |
Argyrios Kyrtzidis | aca19be | 2011-10-18 15:50:50 +0000 | [diff] [blame] | 75 | } else { |
Argyrios Kyrtzidis | e422e45 | 2011-12-13 18:47:41 +0000 | [diff] [blame] | 76 | IndexCtx.handleReference(E->getExplicitProperty(), E->getLocation(), |
| 77 | Parent, ParentDC, E); |
Argyrios Kyrtzidis | aca19be | 2011-10-18 15:50:50 +0000 | [diff] [blame] | 78 | } |
| 79 | return true; |
| 80 | } |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 81 | |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 82 | bool VisitCXXConstructExpr(CXXConstructExpr *E) { |
Argyrios Kyrtzidis | e422e45 | 2011-12-13 18:47:41 +0000 | [diff] [blame] | 83 | IndexCtx.handleReference(E->getConstructor(), E->getLocation(), |
| 84 | Parent, ParentDC, E); |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 85 | return true; |
| 86 | } |
Argyrios Kyrtzidis | 2249074 | 2012-01-14 00:11:49 +0000 | [diff] [blame] | 87 | |
| 88 | bool VisitDeclStmt(DeclStmt *S) { |
| 89 | if (IndexCtx.indexFunctionLocalSymbols()) |
| 90 | IndexCtx.indexDeclGroupRef(S->getDeclGroup()); |
| 91 | return true; |
| 92 | } |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | } // anonymous namespace |
| 96 | |
Argyrios Kyrtzidis | e422e45 | 2011-12-13 18:47:41 +0000 | [diff] [blame] | 97 | void 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 Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 105 | } |