xref: /openbsd-src/gnu/llvm/clang/lib/Index/IndexingContext.h (revision 12c855180aad702bbcca06e0398d774beeafb155)
1e5dd7070Spatrick //===- IndexingContext.h - Indexing context data ----------------*- C++ -*-===//
2e5dd7070Spatrick //
3e5dd7070Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e5dd7070Spatrick // See https://llvm.org/LICENSE.txt for license information.
5e5dd7070Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e5dd7070Spatrick //
7e5dd7070Spatrick //===----------------------------------------------------------------------===//
8e5dd7070Spatrick 
9e5dd7070Spatrick #ifndef LLVM_CLANG_LIB_INDEX_INDEXINGCONTEXT_H
10e5dd7070Spatrick #define LLVM_CLANG_LIB_INDEX_INDEXINGCONTEXT_H
11e5dd7070Spatrick 
12e5dd7070Spatrick #include "clang/Basic/IdentifierTable.h"
13e5dd7070Spatrick #include "clang/Basic/LLVM.h"
14e5dd7070Spatrick #include "clang/Index/IndexSymbol.h"
15e5dd7070Spatrick #include "clang/Index/IndexingAction.h"
16e5dd7070Spatrick #include "clang/Lex/MacroInfo.h"
17e5dd7070Spatrick #include "llvm/ADT/ArrayRef.h"
18e5dd7070Spatrick 
19e5dd7070Spatrick namespace clang {
20e5dd7070Spatrick   class ASTContext;
21e5dd7070Spatrick   class Decl;
22e5dd7070Spatrick   class DeclGroupRef;
23e5dd7070Spatrick   class ImportDecl;
24e5dd7070Spatrick   class TagDecl;
25e5dd7070Spatrick   class TypeSourceInfo;
26e5dd7070Spatrick   class NamedDecl;
27e5dd7070Spatrick   class ObjCMethodDecl;
28e5dd7070Spatrick   class DeclContext;
29e5dd7070Spatrick   class NestedNameSpecifierLoc;
30e5dd7070Spatrick   class Stmt;
31e5dd7070Spatrick   class Expr;
32e5dd7070Spatrick   class TypeLoc;
33e5dd7070Spatrick   class SourceLocation;
34e5dd7070Spatrick 
35e5dd7070Spatrick namespace index {
36e5dd7070Spatrick   class IndexDataConsumer;
37e5dd7070Spatrick 
38e5dd7070Spatrick class IndexingContext {
39e5dd7070Spatrick   IndexingOptions IndexOpts;
40e5dd7070Spatrick   IndexDataConsumer &DataConsumer;
41e5dd7070Spatrick   ASTContext *Ctx = nullptr;
42e5dd7070Spatrick 
43e5dd7070Spatrick public:
IndexingContext(IndexingOptions IndexOpts,IndexDataConsumer & DataConsumer)44e5dd7070Spatrick   IndexingContext(IndexingOptions IndexOpts, IndexDataConsumer &DataConsumer)
45e5dd7070Spatrick     : IndexOpts(IndexOpts), DataConsumer(DataConsumer) {}
46e5dd7070Spatrick 
getIndexOpts()47e5dd7070Spatrick   const IndexingOptions &getIndexOpts() const { return IndexOpts; }
getDataConsumer()48e5dd7070Spatrick   IndexDataConsumer &getDataConsumer() { return DataConsumer; }
49e5dd7070Spatrick 
setASTContext(ASTContext & ctx)50e5dd7070Spatrick   void setASTContext(ASTContext &ctx) { Ctx = &ctx; }
51e5dd7070Spatrick 
52e5dd7070Spatrick   bool shouldIndex(const Decl *D);
53e5dd7070Spatrick 
54e5dd7070Spatrick   const LangOptions &getLangOpts() const;
55e5dd7070Spatrick 
shouldSuppressRefs()56e5dd7070Spatrick   bool shouldSuppressRefs() const {
57e5dd7070Spatrick     return false;
58e5dd7070Spatrick   }
59e5dd7070Spatrick 
60e5dd7070Spatrick   bool shouldIndexFunctionLocalSymbols() const;
61e5dd7070Spatrick 
62e5dd7070Spatrick   bool shouldIndexImplicitInstantiation() const;
63e5dd7070Spatrick 
64e5dd7070Spatrick   bool shouldIndexParametersInDeclarations() const;
65e5dd7070Spatrick 
66e5dd7070Spatrick   bool shouldIndexTemplateParameters() const;
67e5dd7070Spatrick 
68e5dd7070Spatrick   static bool isTemplateImplicitInstantiation(const Decl *D);
69e5dd7070Spatrick 
70e5dd7070Spatrick   bool handleDecl(const Decl *D, SymbolRoleSet Roles = SymbolRoleSet(),
71*12c85518Srobert                   ArrayRef<SymbolRelation> Relations = std::nullopt);
72e5dd7070Spatrick 
73e5dd7070Spatrick   bool handleDecl(const Decl *D, SourceLocation Loc,
74e5dd7070Spatrick                   SymbolRoleSet Roles = SymbolRoleSet(),
75*12c85518Srobert                   ArrayRef<SymbolRelation> Relations = std::nullopt,
76e5dd7070Spatrick                   const DeclContext *DC = nullptr);
77e5dd7070Spatrick 
78e5dd7070Spatrick   bool handleReference(const NamedDecl *D, SourceLocation Loc,
79*12c85518Srobert                        const NamedDecl *Parent, const DeclContext *DC,
80e5dd7070Spatrick                        SymbolRoleSet Roles = SymbolRoleSet(),
81*12c85518Srobert                        ArrayRef<SymbolRelation> Relations = std::nullopt,
82*12c85518Srobert                        const Expr *RefE = nullptr, const Decl *RefD = nullptr);
83e5dd7070Spatrick 
84e5dd7070Spatrick   void handleMacroDefined(const IdentifierInfo &Name, SourceLocation Loc,
85e5dd7070Spatrick                           const MacroInfo &MI);
86e5dd7070Spatrick 
87e5dd7070Spatrick   void handleMacroUndefined(const IdentifierInfo &Name, SourceLocation Loc,
88e5dd7070Spatrick                             const MacroInfo &MI);
89e5dd7070Spatrick 
90e5dd7070Spatrick   void handleMacroReference(const IdentifierInfo &Name, SourceLocation Loc,
91e5dd7070Spatrick                             const MacroInfo &MD);
92e5dd7070Spatrick 
93e5dd7070Spatrick   bool importedModule(const ImportDecl *ImportD);
94e5dd7070Spatrick 
95e5dd7070Spatrick   bool indexDecl(const Decl *D);
96e5dd7070Spatrick 
97e5dd7070Spatrick   void indexTagDecl(const TagDecl *D,
98*12c85518Srobert                     ArrayRef<SymbolRelation> Relations = std::nullopt);
99e5dd7070Spatrick 
100e5dd7070Spatrick   void indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent,
101e5dd7070Spatrick                            const DeclContext *DC = nullptr,
102e5dd7070Spatrick                            bool isBase = false,
103e5dd7070Spatrick                            bool isIBType = false);
104e5dd7070Spatrick 
105e5dd7070Spatrick   void indexTypeLoc(TypeLoc TL, const NamedDecl *Parent,
106e5dd7070Spatrick                     const DeclContext *DC = nullptr,
107e5dd7070Spatrick                     bool isBase = false,
108e5dd7070Spatrick                     bool isIBType = false);
109e5dd7070Spatrick 
110e5dd7070Spatrick   void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
111e5dd7070Spatrick                                    const NamedDecl *Parent,
112e5dd7070Spatrick                                    const DeclContext *DC = nullptr);
113e5dd7070Spatrick 
114e5dd7070Spatrick   bool indexDeclContext(const DeclContext *DC);
115e5dd7070Spatrick 
116e5dd7070Spatrick   void indexBody(const Stmt *S, const NamedDecl *Parent,
117e5dd7070Spatrick                  const DeclContext *DC = nullptr);
118e5dd7070Spatrick 
119e5dd7070Spatrick   bool indexTopLevelDecl(const Decl *D);
120e5dd7070Spatrick   bool indexDeclGroupRef(DeclGroupRef DG);
121e5dd7070Spatrick 
122e5dd7070Spatrick private:
123e5dd7070Spatrick   bool shouldIgnoreIfImplicit(const Decl *D);
124e5dd7070Spatrick 
125a9ac8606Spatrick   bool shouldIndexMacroOccurrence(bool IsRef, SourceLocation Loc);
126a9ac8606Spatrick 
127e5dd7070Spatrick   bool handleDeclOccurrence(const Decl *D, SourceLocation Loc,
128e5dd7070Spatrick                             bool IsRef, const Decl *Parent,
129e5dd7070Spatrick                             SymbolRoleSet Roles,
130e5dd7070Spatrick                             ArrayRef<SymbolRelation> Relations,
131e5dd7070Spatrick                             const Expr *RefE,
132e5dd7070Spatrick                             const Decl *RefD,
133e5dd7070Spatrick                             const DeclContext *ContainerDC);
134e5dd7070Spatrick };
135e5dd7070Spatrick 
136e5dd7070Spatrick } // end namespace index
137e5dd7070Spatrick } // end namespace clang
138e5dd7070Spatrick 
139e5dd7070Spatrick #endif
140