clang 17.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
19namespace 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
35namespace index {
36 class IndexDataConsumer;
37
39 IndexingOptions IndexOpts;
40 IndexDataConsumer &DataConsumer;
41 ASTContext *Ctx = nullptr;
42
43public:
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
67
68 static bool isTemplateImplicitInstantiation(const Decl *D);
69
70 bool handleDecl(const Decl *D, SymbolRoleSet Roles = SymbolRoleSet(),
71 ArrayRef<SymbolRelation> Relations = std::nullopt);
72
73 bool handleDecl(const Decl *D, SourceLocation Loc,
75 ArrayRef<SymbolRelation> Relations = std::nullopt,
76 const DeclContext *DC = nullptr);
77
78 bool handleReference(const NamedDecl *D, SourceLocation Loc,
79 const NamedDecl *Parent, const DeclContext *DC,
81 ArrayRef<SymbolRelation> Relations = std::nullopt,
82 const Expr *RefE = nullptr, const Decl *RefD = nullptr);
83
85 const MacroInfo &MI);
86
88 const MacroInfo &MI);
89
91 const MacroInfo &MD);
92
93 bool importedModule(const ImportDecl *ImportD);
94
95 bool indexDecl(const Decl *D);
96
97 void indexTagDecl(const TagDecl *D,
98 ArrayRef<SymbolRelation> Relations = std::nullopt);
99
101 const DeclContext *DC = nullptr,
102 bool isBase = false,
103 bool isIBType = false);
104
105 void indexTypeLoc(TypeLoc TL, const NamedDecl *Parent,
106 const DeclContext *DC = nullptr,
107 bool isBase = false,
108 bool isIBType = false);
109
111 const NamedDecl *Parent,
112 const DeclContext *DC = nullptr);
113
114 bool indexDeclContext(const DeclContext *DC);
115
116 void indexBody(const Stmt *S, const NamedDecl *Parent,
117 const DeclContext *DC = nullptr);
118
119 bool indexTopLevelDecl(const Decl *D);
121
122private:
123 bool shouldIgnoreIfImplicit(const Decl *D);
124
125 bool shouldIndexMacroOccurrence(bool IsRef, SourceLocation Loc);
126
127 bool handleDeclOccurrence(const Decl *D, SourceLocation Loc,
128 bool IsRef, const Decl *Parent,
129 SymbolRoleSet Roles,
130 ArrayRef<SymbolRelation> Relations,
131 const Expr *RefE,
132 const Decl *RefD,
133 const DeclContext *ContainerDC);
134};
135
136} // end namespace index
137} // end namespace clang
138
139#endif
NodeId Parent
Definition: ASTDiff.cpp:191
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::MacroInfo and clang::MacroDirective classes.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1389
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
This represents one expression.
Definition: Expr.h:110
One of these records is kept for each identifier that is lexed.
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4637
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:82
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
This represents a decl that may have a name.
Definition: Decl.h:247
A C++ nested-name-specifier augmented with source location information.
Encodes a location in the source.
Stmt - This represents one statement.
Definition: Stmt.h:72
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3438
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:58
A container of type source information.
Definition: Type.h:6604
bool shouldIndexImplicitInstantiation() const
IndexDataConsumer & getDataConsumer()
bool importedModule(const ImportDecl *ImportD)
bool shouldIndex(const Decl *D)
bool indexDeclContext(const DeclContext *DC)
Definition: IndexDecl.cpp:792
bool shouldIndexFunctionLocalSymbols() const
const IndexingOptions & getIndexOpts() const
void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, const NamedDecl *Parent, const DeclContext *DC=nullptr)
void handleMacroReference(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MD)
bool indexTopLevelDecl(const Decl *D)
Definition: IndexDecl.cpp:799
void indexTypeLoc(TypeLoc TL, const NamedDecl *Parent, const DeclContext *DC=nullptr, bool isBase=false, bool isIBType=false)
void indexBody(const Stmt *S, const NamedDecl *Parent, const DeclContext *DC=nullptr)
Definition: IndexBody.cpp:495
bool shouldIndexParametersInDeclarations() const
bool indexDeclGroupRef(DeclGroupRef DG)
Definition: IndexDecl.cpp:812
void handleMacroUndefined(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MI)
static bool isTemplateImplicitInstantiation(const Decl *D)
void indexTagDecl(const TagDecl *D, ArrayRef< SymbolRelation > Relations=std::nullopt)
const LangOptions & getLangOpts() const
bool indexDecl(const Decl *D)
Definition: IndexDecl.cpp:774
IndexingContext(IndexingOptions IndexOpts, IndexDataConsumer &DataConsumer)
void handleMacroDefined(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MI)
bool handleReference(const NamedDecl *D, SourceLocation Loc, const NamedDecl *Parent, const DeclContext *DC, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations=std::nullopt, const Expr *RefE=nullptr, const Decl *RefD=nullptr)
void setASTContext(ASTContext &ctx)
void indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent, const DeclContext *DC=nullptr, bool isBase=false, bool isIBType=false)
bool handleDecl(const Decl *D, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations=std::nullopt)
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
unsigned SymbolRoleSet
Definition: IndexSymbol.h:133