clang  14.0.0git
IndexingContext.h
Go to the documentation of this file.
1 //===- IndexingContext.h - Indexing context data ----------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_LIB_INDEX_INDEXINGCONTEXT_H
10 #define LLVM_CLANG_LIB_INDEX_INDEXINGCONTEXT_H
11 
13 #include "clang/Basic/LLVM.h"
16 #include "clang/Lex/MacroInfo.h"
17 #include "llvm/ADT/ArrayRef.h"
18 
19 namespace clang {
20  class ASTContext;
21  class Decl;
22  class DeclGroupRef;
23  class ImportDecl;
24  class TagDecl;
25  class TypeSourceInfo;
26  class NamedDecl;
27  class ObjCMethodDecl;
28  class DeclContext;
29  class NestedNameSpecifierLoc;
30  class Stmt;
31  class Expr;
32  class TypeLoc;
33  class SourceLocation;
34 
35 namespace index {
36  class IndexDataConsumer;
37 
39  IndexingOptions IndexOpts;
40  IndexDataConsumer &DataConsumer;
41  ASTContext *Ctx = nullptr;
42 
43 public:
45  : IndexOpts(IndexOpts), DataConsumer(DataConsumer) {}
46 
47  const IndexingOptions &getIndexOpts() const { return IndexOpts; }
48  IndexDataConsumer &getDataConsumer() { return DataConsumer; }
49 
50  void setASTContext(ASTContext &ctx) { Ctx = &ctx; }
51 
52  bool shouldIndex(const Decl *D);
53 
54  const LangOptions &getLangOpts() const;
55 
56  bool shouldSuppressRefs() const {
57  return false;
58  }
59 
61 
63 
65 
66  bool shouldIndexTemplateParameters() const;
67 
68  static bool isTemplateImplicitInstantiation(const Decl *D);
69 
70  bool handleDecl(const Decl *D, SymbolRoleSet Roles = SymbolRoleSet(),
71  ArrayRef<SymbolRelation> Relations = None);
72 
73  bool handleDecl(const Decl *D, SourceLocation Loc,
74  SymbolRoleSet Roles = SymbolRoleSet(),
75  ArrayRef<SymbolRelation> Relations = None,
76  const DeclContext *DC = nullptr);
77 
78  bool handleReference(const NamedDecl *D, SourceLocation Loc,
79  const NamedDecl *Parent,
80  const DeclContext *DC,
81  SymbolRoleSet Roles = SymbolRoleSet(),
82  ArrayRef<SymbolRelation> Relations = None,
83  const Expr *RefE = nullptr,
84  const Decl *RefD = nullptr);
85 
86  void handleMacroDefined(const IdentifierInfo &Name, SourceLocation Loc,
87  const MacroInfo &MI);
88 
90  const MacroInfo &MI);
91 
93  const MacroInfo &MD);
94 
95  bool importedModule(const ImportDecl *ImportD);
96 
97  bool indexDecl(const Decl *D);
98 
99  void indexTagDecl(const TagDecl *D,
100  ArrayRef<SymbolRelation> Relations = None);
101 
103  const DeclContext *DC = nullptr,
104  bool isBase = false,
105  bool isIBType = false);
106 
107  void indexTypeLoc(TypeLoc TL, const NamedDecl *Parent,
108  const DeclContext *DC = nullptr,
109  bool isBase = false,
110  bool isIBType = false);
111 
113  const NamedDecl *Parent,
114  const DeclContext *DC = nullptr);
115 
116  bool indexDeclContext(const DeclContext *DC);
117 
118  void indexBody(const Stmt *S, const NamedDecl *Parent,
119  const DeclContext *DC = nullptr);
120 
121  bool indexTopLevelDecl(const Decl *D);
123 
124 private:
125  bool shouldIgnoreIfImplicit(const Decl *D);
126 
127  bool shouldIndexMacroOccurrence(bool IsRef, SourceLocation Loc);
128 
129  bool handleDeclOccurrence(const Decl *D, SourceLocation Loc,
130  bool IsRef, const Decl *Parent,
131  SymbolRoleSet Roles,
132  ArrayRef<SymbolRelation> Relations,
133  const Expr *RefE,
134  const Decl *RefD,
135  const DeclContext *ContainerDC);
136 };
137 
138 } // end namespace index
139 } // end namespace clang
140 
141 #endif
clang::index::IndexingContext::shouldIndex
bool shouldIndex(const Decl *D)
Definition: IndexingContext.cpp:28
clang::index::IndexingContext::getDataConsumer
IndexDataConsumer & getDataConsumer()
Definition: IndexingContext.h:48
clang::index::IndexingContext::indexTypeSourceInfo
void indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent, const DeclContext *DC=nullptr, bool isBase=false, bool isIBType=false)
Definition: IndexTypeSourceInfo.cpp:235
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1347
clang::index::IndexingContext::IndexingContext
IndexingContext(IndexingOptions IndexOpts, IndexDataConsumer &DataConsumer)
Definition: IndexingContext.h:44
clang::index::IndexingContext::getIndexOpts
const IndexingOptions & getIndexOpts() const
Definition: IndexingContext.h:47
clang::index::IndexingContext::indexTypeLoc
void indexTypeLoc(TypeLoc TL, const NamedDecl *Parent, const DeclContext *DC=nullptr, bool isBase=false, bool isIBType=false)
Definition: IndexTypeSourceInfo.cpp:246
clang::index::IndexingContext::indexTagDecl
void indexTagDecl(const TagDecl *D, ArrayRef< SymbolRelation > Relations=None)
Definition: IndexTypeSourceInfo.cpp:294
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
IndexingAction.h
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:249
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:74
clang::index::IndexDataConsumer
Definition: IndexDataConsumer.h:26
clang::index::IndexingContext::getLangOpts
const LangOptions & getLangOpts() const
Definition: IndexingContext.cpp:32
clang::MacroInfo
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
clang::index::IndexingContext::shouldIndexParametersInDeclarations
bool shouldIndexParametersInDeclarations() const
Definition: IndexingContext.cpp:44
clang::CodeGen::AlignmentSource::Decl
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
clang::index::IndexingContext::indexDeclContext
bool indexDeclContext(const DeclContext *DC)
Definition: IndexDecl.cpp:754
clang::index::IndexingContext::indexDecl
bool indexDecl(const Decl *D)
Definition: IndexDecl.cpp:736
clang::ImportDecl
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4447
clang::index::IndexingContext::handleMacroUndefined
void handleMacroUndefined(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MI)
Definition: IndexingContext.cpp:466
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:211
clang::index::IndexingContext::handleMacroDefined
void handleMacroDefined(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MI)
Definition: IndexingContext.cpp:457
IdentifierTable.h
clang::index::IndexingContext::handleMacroReference
void handleMacroReference(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MD)
Definition: IndexingContext.cpp:475
clang::index::IndexingContext::indexNestedNameSpecifierLoc
void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, const NamedDecl *Parent, const DeclContext *DC=nullptr)
Definition: IndexTypeSourceInfo.cpp:259
clang::TagDecl
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3328
clang::NestedNameSpecifierLoc
A C++ nested-name-specifier augmented with source location information.
Definition: NestedNameSpecifier.h:243
clang::index::IndexingContext
Definition: IndexingContext.h:38
clang::index::IndexingContext::setASTContext
void setASTContext(ASTContext &ctx)
Definition: IndexingContext.h:50
clang::index::IndexingContext::indexDeclGroupRef
bool indexDeclGroupRef(DeclGroupRef DG)
Definition: IndexDecl.cpp:774
clang::index::IndexingContext::shouldIndexImplicitInstantiation
bool shouldIndexImplicitInstantiation() const
Definition: IndexingContext.cpp:40
clang::index::IndexingContext::shouldIndexFunctionLocalSymbols
bool shouldIndexFunctionLocalSymbols() const
Definition: IndexingContext.cpp:36
clang::index::IndexingContext::shouldSuppressRefs
bool shouldSuppressRefs() const
Definition: IndexingContext.h:56
clang::index::IndexingContext::importedModule
bool importedModule(const ImportDecl *ImportD)
Definition: IndexingContext.cpp:106
llvm::ArrayRef
Definition: LLVM.h:34
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
clang::TypeLoc
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:58
clang::DeclGroupRef
Definition: DeclGroup.h:51
LLVM.h
clang::index::IndexingOptions
Definition: IndexingOptions.h:20
IndexSymbol.h
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:67
clang::index::SymbolRoleSet
unsigned SymbolRoleSet
Definition: IndexSymbol.h:131
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:58
clang::index::IndexingContext::indexBody
void indexBody(const Stmt *S, const NamedDecl *Parent, const DeclContext *DC=nullptr)
Definition: IndexBody.cpp:479
clang
Definition: CalledOnceCheck.h:17
MacroInfo.h
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:68
clang::index::IndexingContext::isTemplateImplicitInstantiation
static bool isTemplateImplicitInstantiation(const Decl *D)
Definition: IndexingContext.cpp:150
clang::index::IndexingContext::indexTopLevelDecl
bool indexTopLevelDecl(const Decl *D)
Definition: IndexDecl.cpp:761
clang::TypeSourceInfo
A container of type source information.
Definition: Type.h:6396
unsigned
clang::index::IndexingContext::shouldIndexTemplateParameters
bool shouldIndexTemplateParameters() const
Definition: IndexingContext.cpp:48
Parent
NodeId Parent
Definition: ASTDiff.cpp:192
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::index::IndexingContext::handleDecl
bool handleDecl(const Decl *D, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations=None)
Definition: IndexingContext.cpp:52