clang 8.0.0

IndexingContext.h
Go to the documentation of this file.
1 //===- 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
13 #include "clang/Basic/IdentifierTable.h"
14 #include "clang/Basic/LLVM.h"
15 #include "clang/Index/IndexSymbol.h"
16 #include "clang/Index/IndexingAction.h"
17 #include "clang/Lex/MacroInfo.h"
18 #include "llvm/ADT/ArrayRef.h"
19
20 namespace 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
36 namespace index {
37 class IndexDataConsumer;
38
39 class IndexingContext {
40 IndexingOptions IndexOpts;
41 IndexDataConsumer &DataConsumer;
42 ASTContext *Ctx = nullptr;
43
44 public:
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
53 bool shouldIndex(const Decl *D);
54
55 const LangOptions &getLangOpts() const;
56
57 bool shouldSuppressRefs() const {
58 return false;
59 }
60
61 bool shouldIndexFunctionLocalSymbols() const;
62
63 bool shouldIndexImplicitInstantiation() const;
64
65 static bool isTemplateImplicitInstantiation(const Decl *D);
66
67 bool handleDecl(const Decl *D, SymbolRoleSet Roles = SymbolRoleSet(),
68 ArrayRef<SymbolRelation> Relations = None);
69
70 bool handleDecl(const Decl *D, SourceLocation Loc,
71 SymbolRoleSet Roles = SymbolRoleSet(),
72 ArrayRef<SymbolRelation> Relations = None,
73 const DeclContext *DC = nullptr);
74
75 bool handleReference(const NamedDecl *D, SourceLocation Loc,
76 const NamedDecl *Parent,
77 const DeclContext *DC,
78 SymbolRoleSet Roles = SymbolRoleSet(),
79 ArrayRef<SymbolRelation> Relations = None,
80 const Expr *RefE = nullptr,
81 const Decl *RefD = nullptr);
82
83 void handleMacroDefined(const IdentifierInfo &Name, SourceLocation Loc,
84 const MacroInfo &MI);
85
86 void handleMacroUndefined(const IdentifierInfo &Name, SourceLocation Loc,
87 const MacroInfo &MI);
88
89 void handleMacroReference(const IdentifierInfo &Name, SourceLocation Loc,
90 const MacroInfo &MD);
91
92 bool importedModule(const ImportDecl *ImportD);
93
94 bool indexDecl(const Decl *D);
95
96 void indexTagDecl(const TagDecl *D,
97 ArrayRef<SymbolRelation> Relations = None);
98
99 void indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent,
100 const DeclContext *DC = nullptr,
101 bool isBase = false,
102 bool isIBType = false);
103
104 void indexTypeLoc(TypeLoc TL, const NamedDecl *Parent,
105 const DeclContext *DC = nullptr,
106 bool isBase = false,
107 bool isIBType = false);
108
109 void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
110 const NamedDecl *Parent,
111 const DeclContext *DC = nullptr);
112
113 bool indexDeclContext(const DeclContext *DC);
114
115 void indexBody(const Stmt *S, const NamedDecl *Parent,
116 const DeclContext *DC = nullptr);
117
118 bool indexTopLevelDecl(const Decl *D);
119 bool indexDeclGroupRef(DeclGroupRef DG);
120
121 private:
122 bool shouldIgnoreIfImplicit(const Decl *D);
123
124 bool handleDeclOccurrence(const Decl *D, SourceLocation Loc,
125 bool IsRef, const Decl *Parent,
126 SymbolRoleSet Roles,
127 ArrayRef<SymbolRelation> Relations,
128 const Expr *RefE,
129 const Decl *RefD,
130 const DeclContext *ContainerDC);
131 };
132
133 } // end namespace index
134 } // end namespace clang
135
136 #endif
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:66
clang::index::IndexingContext::shouldSuppressRefs
bool shouldSuppressRefs() const
Definition: IndexingContext.h:57
clang::index::IndexingContext::indexTypeLoc
void indexTypeLoc(TypeLoc TL, const NamedDecl *Parent, const DeclContext *DC=nullptr, bool isBase=false, bool isIBType=false)
Definition: IndexTypeSourceInfo.cpp:202
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:87
clang::index::IndexingOptions
Definition: IndexingAction.h:33
MacroInfo.h
Defines the clang::MacroInfo and clang::MacroDirective classes.
clang::index::IndexingContext::indexTopLevelDecl
bool indexTopLevelDecl(const Decl *D)
Definition: IndexDecl.cpp:750
clang::CodeGen::AlignmentSource::Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
clang::TypeSourceInfo
A container of type source information.
Definition: Decl.h:87
clang::index::IndexingContext::handleMacroDefined
void handleMacroDefined(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MI)
Definition: IndexingContext.cpp:438
clang::index::IndexingContext::setASTContext
void setASTContext(ASTContext &ctx)
Definition: IndexingContext.h:51
clang::index::IndexingContext::IndexingContext
IndexingContext(IndexingOptions IndexOpts, IndexDataConsumer &DataConsumer)
Definition: IndexingContext.h:45
clang::TypeLoc
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:57
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:58
clang::index::IndexingContext::getLangOpts
const LangOptions & getLangOpts() const
Definition: IndexingContext.cpp:32
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:155
clang::NestedNameSpecifierLoc
A C++ nested-name-specifier augmented with source location information.
Definition: NestedNameSpecifier.h:237
clang::index::IndexingContext::handleMacroReference
void handleMacroReference(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MD)
Definition: IndexingContext.cpp:452
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
LLVM.h
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
clang::index::IndexingContext::shouldIndexFunctionLocalSymbols
bool shouldIndexFunctionLocalSymbols() const
Definition: IndexingContext.cpp:36
clang::index::IndexDataConsumer
Definition: IndexDataConsumer.h:27
clang::index::IndexingContext::indexDecl
bool indexDecl(const Decl *D)
Definition: IndexDecl.cpp:725
clang::index::SymbolSubKind::None
llvm::ArrayRef
Definition: LLVM.h:32
Parent
NodeId Parent
Definition: ASTDiff.cpp:192
clang::index::SymbolRoleSet
unsigned SymbolRoleSet
Definition: IndexSymbol.h:124
clang::Expr
This represents one expression.
Definition: Expr.h:106
clang::index::IndexingContext
Definition: IndexingContext.h:39
clang::index::IndexingContext::indexDeclContext
bool indexDeclContext(const DeclContext *DC)
Definition: IndexDecl.cpp:743
clang::index::IndexingContext::indexDeclGroupRef
bool indexDeclGroupRef(DeclGroupRef DG)
Definition: IndexDecl.cpp:760
clang::index::IndexingContext::isTemplateImplicitInstantiation
static bool isTemplateImplicitInstantiation(const Decl *D)
Definition: IndexingContext.cpp:140
IdentifierTable.h
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
IndexSymbol.h
clang::index::IndexingContext::handleReference
bool handleReference(const NamedDecl *D, SourceLocation Loc, const NamedDecl *Parent, const DeclContext *DC, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations=None, const Expr *RefE=nullptr, const Decl *RefD=nullptr)
Definition: IndexingContext.cpp:66
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::TagDecl
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3064
clang::index::IndexingContext::shouldIndexImplicitInstantiation
bool shouldIndexImplicitInstantiation() const
Definition: IndexingContext.cpp:40
clang::ImportDecl
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4149
clang::index::IndexingContext::shouldIndex
bool shouldIndex(const Decl *D)
Definition: IndexingContext.cpp:28
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::index::IndexingContext::handleDecl
bool handleDecl(const Decl *D, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations=None)
Definition: IndexingContext.cpp:44
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1262
clang::DeclGroupRef
Definition: DeclGroup.h:52
IndexingAction.h
clang::MacroInfo
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:40
clang::index::IndexingContext::indexTypeSourceInfo
void indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent, const DeclContext *DC=nullptr, bool isBase=false, bool isIBType=false)
Definition: IndexTypeSourceInfo.cpp:191
clang::index::IndexingContext::handleMacroUndefined
void handleMacroUndefined(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MI)
Definition: IndexingContext.cpp:445
clang::index::IndexingContext::indexNestedNameSpecifierLoc
void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, const NamedDecl *Parent, const DeclContext *DC=nullptr)
Definition: IndexTypeSourceInfo.cpp:215
clang::index::IndexingContext::indexTagDecl
void indexTagDecl(const TagDecl *D, ArrayRef< SymbolRelation > Relations=None)
Definition: IndexTypeSourceInfo.cpp:250
clang::index::IndexingContext::importedModule
bool importedModule(const ImportDecl *ImportD)
Definition: IndexingContext.cpp:96
clang::index::IndexingContext::getDataConsumer
IndexDataConsumer & getDataConsumer()
Definition: IndexingContext.h:49
clang::index::IndexingContext::indexBody
void indexBody(const Stmt *S, const NamedDecl *Parent, const DeclContext *DC=nullptr)
Definition: IndexBody.cpp:472
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:249
clang::index::IndexingContext::getIndexOpts
const IndexingOptions & getIndexOpts() const
Definition: IndexingContext.h:48