clang 22.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;
25 class TagDecl;
26 class TypeSourceInfo;
27 class NamedDecl;
28 class ObjCMethodDecl;
29 class DeclContext;
31 class Stmt;
32 class Expr;
33 class TypeLoc;
34 class SourceLocation;
35
36namespace index {
38
40 IndexingOptions IndexOpts;
41 IndexDataConsumer &DataConsumer;
42 ASTContext *Ctx = nullptr;
43 std::unique_ptr<HeuristicResolver> Resolver;
44
45public:
46 IndexingContext(IndexingOptions IndexOpts, IndexDataConsumer &DataConsumer);
47 // Defaulted, but defined out of line to avoid a dependency on
48 // HeuristicResolver.h (unique_ptr requires a complete type at
49 // the point where its destructor is called).
51
52 const IndexingOptions &getIndexOpts() const { return IndexOpts; }
53 IndexDataConsumer &getDataConsumer() { return DataConsumer; }
54
55 void setASTContext(ASTContext &ctx);
56
57 HeuristicResolver *getResolver() const { return Resolver.get(); }
58
59 bool shouldIndex(const Decl *D);
60
61 const LangOptions &getLangOpts() const;
62
63 bool shouldSuppressRefs() const {
64 return false;
65 }
66
68
70
72
74
75 static bool isTemplateImplicitInstantiation(const Decl *D);
76
77 bool handleDecl(const Decl *D, SymbolRoleSet Roles = SymbolRoleSet(),
78 ArrayRef<SymbolRelation> Relations = {});
79
80 bool handleDecl(const Decl *D, SourceLocation Loc,
82 ArrayRef<SymbolRelation> Relations = {},
83 const DeclContext *DC = nullptr);
84
85 bool handleReference(const NamedDecl *D, SourceLocation Loc,
86 const NamedDecl *Parent, const DeclContext *DC,
88 ArrayRef<SymbolRelation> Relations = {},
89 const Expr *RefE = nullptr);
90
91 void handleMacroDefined(const IdentifierInfo &Name, SourceLocation Loc,
92 const MacroInfo &MI);
93
94 void handleMacroUndefined(const IdentifierInfo &Name, SourceLocation Loc,
95 const MacroInfo &MI);
96
97 void handleMacroReference(const IdentifierInfo &Name, SourceLocation Loc,
98 const MacroInfo &MD);
99
100 bool importedModule(const ImportDecl *ImportD);
101
102 bool indexDecl(const Decl *D);
103
104 void indexTagDecl(const TagDecl *D, ArrayRef<SymbolRelation> Relations = {});
105
106 void indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent,
107 const DeclContext *DC = nullptr,
108 bool isBase = false,
109 bool isIBType = false);
110
111 void indexTypeLoc(TypeLoc TL, const NamedDecl *Parent,
112 const DeclContext *DC = nullptr,
113 bool isBase = false,
114 bool isIBType = false);
115
116 void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
117 const NamedDecl *Parent,
118 const DeclContext *DC = nullptr);
119
120 bool indexDeclContext(const DeclContext *DC);
121
122 void indexBody(const Stmt *S, const NamedDecl *Parent,
123 const DeclContext *DC = nullptr);
124
125 bool indexTopLevelDecl(const Decl *D);
126 bool indexDeclGroupRef(DeclGroupRef DG);
127
128private:
129 bool shouldIgnoreIfImplicit(const Decl *D);
130
131 bool shouldIndexMacroOccurrence(bool IsRef, SourceLocation Loc);
132
133 bool handleDeclOccurrence(const Decl *D, SourceLocation Loc,
134 bool IsRef, const Decl *Parent,
135 SymbolRoleSet Roles,
136 ArrayRef<SymbolRelation> Relations,
137 const Expr *RefE,
138 const Decl *RefD,
139 const DeclContext *ContainerDC);
140};
141
142} // end namespace index
143} // end namespace clang
144
145#endif
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:188
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1449
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
This represents one expression.
Definition Expr.h:112
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition Decl.h:5015
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
This represents a decl that may have a name.
Definition Decl.h:273
A C++ nested-name-specifier augmented with source location information.
ObjCMethodDecl - Represents an instance or class method declaration.
Definition DeclObjC.h:140
Encodes a location in the source.
Stmt - This represents one statement.
Definition Stmt.h:85
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3714
Base wrapper for a particular "section" of type source info.
Definition TypeLoc.h:59
A container of type source information.
Definition TypeBase.h:8256
void setASTContext(ASTContext &ctx)
IndexDataConsumer & getDataConsumer()
bool importedModule(const ImportDecl *ImportD)
bool handleDecl(const Decl *D, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations={})
HeuristicResolver * getResolver() const
bool indexDeclContext(const DeclContext *DC)
bool handleReference(const NamedDecl *D, SourceLocation Loc, const NamedDecl *Parent, const DeclContext *DC, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations={}, const Expr *RefE=nullptr)
void indexTagDecl(const TagDecl *D, ArrayRef< SymbolRelation > Relations={})
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)
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)
IndexingContext(IndexingOptions IndexOpts, IndexDataConsumer &DataConsumer)
bool shouldIndexParametersInDeclarations() const
bool indexDeclGroupRef(DeclGroupRef DG)
void handleMacroUndefined(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MI)
static bool isTemplateImplicitInstantiation(const Decl *D)
const LangOptions & getLangOpts() const
bool indexDecl(const Decl *D)
void handleMacroDefined(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MI)
void indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent, const DeclContext *DC=nullptr, bool isBase=false, bool isIBType=false)
unsigned SymbolRoleSet
The JSON file list parser is used to communicate input to InstallAPI.