1 //===--- IndexingAction.h - Frontend index action ---------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_INDEX_INDEXINGACTION_H
10 #define LLVM_CLANG_INDEX_INDEXINGACTION_H
12 #include "clang/AST/ASTConsumer.h"
13 #include "clang/Basic/LLVM.h"
14 #include "clang/Index/IndexingOptions.h"
15 #include "clang/Lex/PPCallbacks.h"
16 #include "clang/Lex/Preprocessor.h"
17 #include "llvm/ADT/ArrayRef.h"
28 namespace serialization {
33 class IndexDataConsumer;
35 /// Creates an ASTConsumer that indexes all symbols (macros and AST decls).
36 std::unique_ptr<ASTConsumer>
37 createIndexingASTConsumer(std::shared_ptr<IndexDataConsumer> DataConsumer,
38 const IndexingOptions &Opts,
39 std::shared_ptr<Preprocessor> PP);
41 std::unique_ptr<ASTConsumer> createIndexingASTConsumer(
42 std::shared_ptr<IndexDataConsumer> DataConsumer,
43 const IndexingOptions &Opts, std::shared_ptr<Preprocessor> PP,
44 // Prefer to set Opts.ShouldTraverseDecl and use the above overload.
45 // This version is only needed if used to *track* function body parsing.
46 std::function<bool(const Decl *)> ShouldSkipFunctionBody);
48 /// Creates a frontend action that indexes all symbols (macros and AST decls).
49 std::unique_ptr<FrontendAction>
50 createIndexingAction(std::shared_ptr<IndexDataConsumer> DataConsumer,
51 const IndexingOptions &Opts);
53 /// Recursively indexes all decls in the AST.
54 void indexASTUnit(ASTUnit &Unit, IndexDataConsumer &DataConsumer,
55 IndexingOptions Opts);
57 /// Recursively indexes \p Decls.
58 void indexTopLevelDecls(ASTContext &Ctx, Preprocessor &PP,
59 ArrayRef<const Decl *> Decls,
60 IndexDataConsumer &DataConsumer, IndexingOptions Opts);
62 /// Creates a PPCallbacks that indexes macros and feeds macros to \p Consumer.
63 /// The caller is responsible for calling `Consumer.setPreprocessor()`.
64 std::unique_ptr<PPCallbacks> indexMacrosCallback(IndexDataConsumer &Consumer,
65 IndexingOptions Opts);
67 /// Recursively indexes all top-level decls in the module.
68 void indexModuleFile(serialization::ModuleFile &Mod, ASTReader &Reader,
69 IndexDataConsumer &DataConsumer, IndexingOptions Opts);