blob: f05eaae69651fbba3c14910f9861b5686c561364 [file] [log] [blame]
Argyrios Kyrtzidisf4fb85b2016-02-12 23:10:59 +00001//===- IndexingContext.h - Indexing context data ----------------*- C++ -*-===//
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#ifndef LLVM_CLANG_LIB_INDEX_INDEXINGCONTEXT_H
11#define LLVM_CLANG_LIB_INDEX_INDEXINGCONTEXT_H
12
Eric Liu8c971952018-07-09 08:44:05 +000013#include "clang/Basic/IdentifierTable.h"
Argyrios Kyrtzidisf4fb85b2016-02-12 23:10:59 +000014#include "clang/Basic/LLVM.h"
15#include "clang/Index/IndexSymbol.h"
16#include "clang/Index/IndexingAction.h"
Eric Liu8c971952018-07-09 08:44:05 +000017#include "clang/Lex/MacroInfo.h"
Argyrios Kyrtzidisf4fb85b2016-02-12 23:10:59 +000018#include "llvm/ADT/ArrayRef.h"
19
20namespace clang {
21 class ASTContext;
22 class Decl;
23 class DeclGroupRef;
24 class ImportDecl;
25 class TagDecl;
26 class TypeSourceInfo;
27 class NamedDecl;
28 class ObjCMethodDecl;
29 class DeclContext;
30 class NestedNameSpecifierLoc;
31 class Stmt;
32 class Expr;
33 class TypeLoc;
34 class SourceLocation;
35
36namespace index {
37 class IndexDataConsumer;
38
39class IndexingContext {
40 IndexingOptions IndexOpts;
41 IndexDataConsumer &DataConsumer;
42 ASTContext *Ctx = nullptr;
43
44public:
45 IndexingContext(IndexingOptions IndexOpts, IndexDataConsumer &DataConsumer)
46 : IndexOpts(IndexOpts), DataConsumer(DataConsumer) {}
47
48 const IndexingOptions &getIndexOpts() const { return IndexOpts; }
49 IndexDataConsumer &getDataConsumer() { return DataConsumer; }
50
51 void setASTContext(ASTContext &ctx) { Ctx = &ctx; }
52
Argyrios Kyrtzidis6e5ca5b2017-04-21 05:42:46 +000053 bool shouldIndex(const Decl *D);
54
Alex Lorenza352ba02017-04-24 14:04:58 +000055 const LangOptions &getLangOpts() const;
56
Argyrios Kyrtzidisf4fb85b2016-02-12 23:10:59 +000057 bool shouldSuppressRefs() const {
58 return false;
59 }
60
61 bool shouldIndexFunctionLocalSymbols() const;
62
63 bool shouldIndexImplicitTemplateInsts() const {
64 return false;
65 }
66
Argyrios Kyrtzidisf4fb85b2016-02-12 23:10:59 +000067 static bool isTemplateImplicitInstantiation(const Decl *D);
68
69 bool handleDecl(const Decl *D, SymbolRoleSet Roles = SymbolRoleSet(),
Argyrios Kyrtzidis29cd1a42016-02-13 05:17:15 +000070 ArrayRef<SymbolRelation> Relations = None);
Argyrios Kyrtzidisf4fb85b2016-02-12 23:10:59 +000071
72 bool handleDecl(const Decl *D, SourceLocation Loc,
73 SymbolRoleSet Roles = SymbolRoleSet(),
Argyrios Kyrtzidis29cd1a42016-02-13 05:17:15 +000074 ArrayRef<SymbolRelation> Relations = None,
Argyrios Kyrtzidisf4fb85b2016-02-12 23:10:59 +000075 const DeclContext *DC = nullptr);
76
77 bool handleReference(const NamedDecl *D, SourceLocation Loc,
78 const NamedDecl *Parent,
79 const DeclContext *DC,
Argyrios Kyrtzidis573624a2017-03-17 23:41:59 +000080 SymbolRoleSet Roles = SymbolRoleSet(),
Argyrios Kyrtzidis29cd1a42016-02-13 05:17:15 +000081 ArrayRef<SymbolRelation> Relations = None,
Argyrios Kyrtzidisf4fb85b2016-02-12 23:10:59 +000082 const Expr *RefE = nullptr,
83 const Decl *RefD = nullptr);
84
Eric Liu8c971952018-07-09 08:44:05 +000085 void handleMacroDefined(const IdentifierInfo &Name, SourceLocation Loc,
86 const MacroInfo &MI);
87
88 void handleMacroUndefined(const IdentifierInfo &Name, SourceLocation Loc,
89 const MacroInfo &MI);
90
91 void handleMacroReference(const IdentifierInfo &Name, SourceLocation Loc,
92 const MacroInfo &MD);
93
Argyrios Kyrtzidisf4fb85b2016-02-12 23:10:59 +000094 bool importedModule(const ImportDecl *ImportD);
95
96 bool indexDecl(const Decl *D);
97
Alex Lorenzf6071c32017-04-20 10:43:22 +000098 void indexTagDecl(const TagDecl *D,
99 ArrayRef<SymbolRelation> Relations = None);
Argyrios Kyrtzidisf4fb85b2016-02-12 23:10:59 +0000100
101 void indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent,
102 const DeclContext *DC = nullptr,
Argyrios Kyrtzidisde0f5082017-01-11 21:01:07 +0000103 bool isBase = false,
104 bool isIBType = false);
Argyrios Kyrtzidisf4fb85b2016-02-12 23:10:59 +0000105
106 void indexTypeLoc(TypeLoc TL, const NamedDecl *Parent,
107 const DeclContext *DC = nullptr,
Argyrios Kyrtzidisde0f5082017-01-11 21:01:07 +0000108 bool isBase = false,
109 bool isIBType = false);
Argyrios Kyrtzidisf4fb85b2016-02-12 23:10:59 +0000110
111 void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
112 const NamedDecl *Parent,
113 const DeclContext *DC = nullptr);
114
115 bool indexDeclContext(const DeclContext *DC);
116
117 void indexBody(const Stmt *S, const NamedDecl *Parent,
118 const DeclContext *DC = nullptr);
119
120 bool indexTopLevelDecl(const Decl *D);
121 bool indexDeclGroupRef(DeclGroupRef DG);
122
123private:
124 bool shouldIgnoreIfImplicit(const Decl *D);
125
126 bool handleDeclOccurrence(const Decl *D, SourceLocation Loc,
127 bool IsRef, const Decl *Parent,
128 SymbolRoleSet Roles,
129 ArrayRef<SymbolRelation> Relations,
130 const Expr *RefE,
131 const Decl *RefD,
132 const DeclContext *ContainerDC);
133};
134
135} // end namespace index
136} // end namespace clang
137
138#endif