1 //===--- IndexingAction.h - Frontend index action ---------------*- 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_INDEX_INDEXINGACTION_H
10 #define LLVM_CLANG_INDEX_INDEXINGACTION_H
11 
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"
18 #include <memory>
19 
20 namespace clang {
21   class ASTContext;
22   class ASTConsumer;
23   class ASTReader;
24   class ASTUnit;
25   class Decl;
26   class FrontendAction;
27 
28 namespace serialization {
29   class ModuleFile;
30 }
31 
32 namespace index {
33 class IndexDataConsumer;
34 
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);
40 
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);
47 
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);
52 
53 /// Recursively indexes all decls in the AST.
54 void indexASTUnit(ASTUnit &Unit, IndexDataConsumer &DataConsumer,
55                   IndexingOptions Opts);
56 
57 /// Recursively indexes \p Decls.
58 void indexTopLevelDecls(ASTContext &Ctx, Preprocessor &PP,
59                         ArrayRef<const Decl *> Decls,
60                         IndexDataConsumer &DataConsumer, IndexingOptions Opts);
61 
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);
66 
67 /// Recursively indexes all top-level decls in the module.
68 void indexModuleFile(serialization::ModuleFile &Mod, ASTReader &Reader,
69                      IndexDataConsumer &DataConsumer, IndexingOptions Opts);
70 
71 } // namespace index
72 } // namespace clang
73 
74 #endif
75