1 //===- IndexingContext.h - Indexing context data ----------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_LIB_INDEX_INDEXINGCONTEXT_H
10 #define LLVM_CLANG_LIB_INDEX_INDEXINGCONTEXT_H
12 #include "clang/Basic/IdentifierTable.h"
13 #include "clang/Basic/LLVM.h"
14 #include "clang/Index/IndexSymbol.h"
15 #include "clang/Index/IndexingAction.h"
16 #include "clang/Lex/MacroInfo.h"
17 #include "llvm/ADT/ArrayRef.h"
29 class NestedNameSpecifierLoc
;
36 class IndexDataConsumer
;
38 class IndexingContext
{
39 IndexingOptions IndexOpts
;
40 IndexDataConsumer
&DataConsumer
;
41 ASTContext
*Ctx
= nullptr;
44 IndexingContext(IndexingOptions IndexOpts
, IndexDataConsumer
&DataConsumer
)
45 : IndexOpts(IndexOpts
), DataConsumer(DataConsumer
) {}
47 const IndexingOptions
&getIndexOpts() const { return IndexOpts
; }
48 IndexDataConsumer
&getDataConsumer() { return DataConsumer
; }
50 void setASTContext(ASTContext
&ctx
) { Ctx
= &ctx
; }
52 bool shouldIndex(const Decl
*D
);
54 const LangOptions
&getLangOpts() const;
56 bool shouldSuppressRefs() const {
60 bool shouldIndexFunctionLocalSymbols() const;
62 bool shouldIndexImplicitInstantiation() const;
64 bool shouldIndexParametersInDeclarations() const;
66 bool shouldIndexTemplateParameters() const;
68 static bool isTemplateImplicitInstantiation(const Decl
*D
);
70 bool handleDecl(const Decl
*D
, SymbolRoleSet Roles
= SymbolRoleSet(),
71 ArrayRef
<SymbolRelation
> Relations
= std::nullopt
);
73 bool handleDecl(const Decl
*D
, SourceLocation Loc
,
74 SymbolRoleSet Roles
= SymbolRoleSet(),
75 ArrayRef
<SymbolRelation
> Relations
= std::nullopt
,
76 const DeclContext
*DC
= nullptr);
78 bool handleReference(const NamedDecl
*D
, SourceLocation Loc
,
79 const NamedDecl
*Parent
, const DeclContext
*DC
,
80 SymbolRoleSet Roles
= SymbolRoleSet(),
81 ArrayRef
<SymbolRelation
> Relations
= std::nullopt
,
82 const Expr
*RefE
= nullptr);
84 void handleMacroDefined(const IdentifierInfo
&Name
, SourceLocation Loc
,
87 void handleMacroUndefined(const IdentifierInfo
&Name
, SourceLocation Loc
,
90 void handleMacroReference(const IdentifierInfo
&Name
, SourceLocation Loc
,
93 bool importedModule(const ImportDecl
*ImportD
);
95 bool indexDecl(const Decl
*D
);
97 void indexTagDecl(const TagDecl
*D
,
98 ArrayRef
<SymbolRelation
> Relations
= std::nullopt
);
100 void indexTypeSourceInfo(TypeSourceInfo
*TInfo
, const NamedDecl
*Parent
,
101 const DeclContext
*DC
= nullptr,
103 bool isIBType
= false);
105 void indexTypeLoc(TypeLoc TL
, const NamedDecl
*Parent
,
106 const DeclContext
*DC
= nullptr,
108 bool isIBType
= false);
110 void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS
,
111 const NamedDecl
*Parent
,
112 const DeclContext
*DC
= nullptr);
114 bool indexDeclContext(const DeclContext
*DC
);
116 void indexBody(const Stmt
*S
, const NamedDecl
*Parent
,
117 const DeclContext
*DC
= nullptr);
119 bool indexTopLevelDecl(const Decl
*D
);
120 bool indexDeclGroupRef(DeclGroupRef DG
);
123 bool shouldIgnoreIfImplicit(const Decl
*D
);
125 bool shouldIndexMacroOccurrence(bool IsRef
, SourceLocation Loc
);
127 bool handleDeclOccurrence(const Decl
*D
, SourceLocation Loc
,
128 bool IsRef
, const Decl
*Parent
,
130 ArrayRef
<SymbolRelation
> Relations
,
133 const DeclContext
*ContainerDC
);
136 } // end namespace index
137 } // end namespace clang