1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
//===- CIndexHigh.cpp - Higher level API functions ------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "IndexingContext.h"
#include "clang/AST/RecursiveASTVisitor.h"
using namespace clang;
using namespace cxindex;
namespace {
class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
IndexingContext &IndexCtx;
const DeclContext *ParentDC;
public:
BodyIndexer(IndexingContext &indexCtx, const DeclContext *DC)
: IndexCtx(indexCtx), ParentDC(DC) { }
bool shouldWalkTypesOfTypeLocs() const { return false; }
bool TraverseTypeLoc(TypeLoc TL) {
IndexCtx.indexTypeLoc(TL, 0, ParentDC);
return true;
}
bool VisitDeclRefExpr(DeclRefExpr *E) {
const NamedDecl *D = E->getDecl();
if (!D)
return true;
if (D->getParentFunctionOrMethod())
return true;
IndexCtx.handleReference(D, E->getLocation(), 0, ParentDC, E);
return true;
}
bool VisitMemberExpr(MemberExpr *E) {
const NamedDecl *D = E->getMemberDecl();
if (!D)
return true;
if (D->getParentFunctionOrMethod())
return true;
IndexCtx.handleReference(D, E->getMemberLoc(), 0, ParentDC, E);
return true;
}
bool VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
const NamedDecl *D = E->getDecl();
if (!D)
return true;
if (D->getParentFunctionOrMethod())
return true;
IndexCtx.handleReference(D, E->getLocation(), 0, ParentDC, E);
return true;
}
bool VisitObjCMessageExpr(ObjCMessageExpr *E) {
if (ObjCMethodDecl *MD = E->getMethodDecl())
IndexCtx.handleReference(MD, E->getSelectorStartLoc(), 0, ParentDC, E);
return true;
}
bool VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
if (E->isImplicitProperty()) {
if (ObjCMethodDecl *MD = E->getImplicitPropertyGetter())
IndexCtx.handleReference(MD, E->getLocation(), 0, ParentDC, E,
CXIdxEntityRef_ImplicitProperty);
if (ObjCMethodDecl *MD = E->getImplicitPropertySetter())
IndexCtx.handleReference(MD, E->getLocation(), 0, ParentDC, E,
CXIdxEntityRef_ImplicitProperty);
} else {
IndexCtx.handleReference(E->getExplicitProperty(), E->getLocation(), 0,
ParentDC, E);
}
return true;
}
};
} // anonymous namespace
void IndexingContext::indexBody(const Stmt *S, const DeclContext *DC) {
BodyIndexer(*this, DC).TraverseStmt(const_cast<Stmt*>(S));
}
|