blob: 9418ed7bb19ffea226d54819da4f13da44fe6000 [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"
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +000013#include "clang/Analysis/Support/SaveAndRestore.h"
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000014
15using namespace clang;
16using namespace cxindex;
17
18namespace {
19
20class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
21 IndexingContext &IndexCtx;
22 const DeclContext *ParentDC;
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +000023 bool InPseudoObject;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000024
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +000025 typedef RecursiveASTVisitor<BodyIndexer> base;
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000026public:
27 BodyIndexer(IndexingContext &indexCtx, const DeclContext *DC)
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +000028 : IndexCtx(indexCtx), ParentDC(DC), InPseudoObject(false) { }
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000029
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 Kyrtzidisd6c82092011-11-16 02:35:01 +000038 IndexCtx.handleReference(E->getDecl(), E->getLocation(), 0, ParentDC, E);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000039 return true;
40 }
41
42 bool VisitMemberExpr(MemberExpr *E) {
Argyrios Kyrtzidisd6c82092011-11-16 02:35:01 +000043 IndexCtx.handleReference(E->getMemberDecl(), E->getMemberLoc(), 0, ParentDC,
44 E);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000045 return true;
46 }
47
48 bool VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Argyrios Kyrtzidisd6c82092011-11-16 02:35:01 +000049 IndexCtx.handleReference(E->getDecl(), E->getLocation(), 0, ParentDC, E);
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000050 return true;
51 }
Argyrios Kyrtzidis9fbbf142011-10-18 15:13:11 +000052
53 bool VisitObjCMessageExpr(ObjCMessageExpr *E) {
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +000054 if (TypeSourceInfo *Cls = E->getClassReceiverTypeInfo())
55 IndexCtx.indexTypeSourceInfo(Cls, 0, ParentDC);
56
Argyrios Kyrtzidis9fbbf142011-10-18 15:13:11 +000057 if (ObjCMethodDecl *MD = E->getMethodDecl())
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +000058 IndexCtx.handleReference(MD, E->getSelectorStartLoc(), 0, ParentDC, E,
59 InPseudoObject ? CXIdxEntityRef_Implicit
60 : CXIdxEntityRef_Direct);
Argyrios Kyrtzidis9fbbf142011-10-18 15:13:11 +000061 return true;
62 }
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +000063
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 Kyrtzidisb395c632011-11-18 00:26:51 +000068 CXIdxEntityRef_Implicit);
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +000069 if (ObjCMethodDecl *MD = E->getImplicitPropertySetter())
70 IndexCtx.handleReference(MD, E->getLocation(), 0, ParentDC, E,
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +000071 CXIdxEntityRef_Implicit);
Argyrios Kyrtzidisaca19be2011-10-18 15:50:50 +000072 } else {
73 IndexCtx.handleReference(E->getExplicitProperty(), E->getLocation(), 0,
74 ParentDC, E);
75 }
76 return true;
77 }
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +000078
79 bool TraversePseudoObjectExpr(PseudoObjectExpr *E) {
80 SaveAndRestore<bool> InPseudo(InPseudoObject, true);
81 return base::TraversePseudoObjectExpr(E);
82 }
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +000083
84 bool VisitCXXConstructExpr(CXXConstructExpr *E) {
85 IndexCtx.handleReference(E->getConstructor(), E->getLocation(), 0,
86 ParentDC, E);
87 return true;
88 }
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +000089};
90
91} // anonymous namespace
92
93void IndexingContext::indexBody(const Stmt *S, const DeclContext *DC) {
94 BodyIndexer(*this, DC).TraverseStmt(const_cast<Stmt*>(S));
95}