146 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_CLANG_LIB_INDEX_INDEXINGCONTEXT_H10#define LLVM_CLANG_LIB_INDEX_INDEXINGCONTEXT_H11 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"18 19namespace clang {20 class ASTContext;21 class Decl;22 class DeclGroupRef;23 class ImportDecl;24 class HeuristicResolver;25 class TagDecl;26 class TypeSourceInfo;27 class NamedDecl;28 class ObjCMethodDecl;29 class DeclContext;30 class NestedNameSpecifierLoc;31 class Stmt;32 class Expr;33 class TypeLoc;34 class SourceLocation;35 36namespace index {37 class IndexDataConsumer;38 39class IndexingContext {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 on48 // HeuristicResolver.h (unique_ptr requires a complete type at49 // the point where its destructor is called).50 ~IndexingContext();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 67 bool shouldIndexFunctionLocalSymbols() const;68 69 bool shouldIndexImplicitInstantiation() const;70 71 bool shouldIndexParametersInDeclarations() const;72 73 bool shouldIndexTemplateParameters() const;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,81 SymbolRoleSet Roles = SymbolRoleSet(),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,87 SymbolRoleSet Roles = SymbolRoleSet(),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 index143} // end namespace clang144 145#endif146