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> createIndexingASTConsumer(
37     std::shared_ptr<IndexDataConsumer> DataConsumer,
38     const IndexingOptions &Opts, std::shared_ptr<Preprocessor> PP,
39     std::function<bool(const Decl *)> ShouldSkipFunctionBody);
40 
41 inline std::unique_ptr<ASTConsumer> createIndexingASTConsumer(
42     std::shared_ptr<IndexDataConsumer> DataConsumer,
43     const IndexingOptions &Opts, std::shared_ptr<Preprocessor> PP) {
44   return createIndexingASTConsumer(
45       std::move(DataConsumer), Opts, std::move(PP),
46       /*ShouldSkipFunctionBody=*/[](const Decl *) { return false; });
47 }
48 
49 /// Creates a frontend action that indexes all symbols (macros and AST decls).
50 std::unique_ptr<FrontendAction>
51 createIndexingAction(std::shared_ptr<IndexDataConsumer> DataConsumer,
52                      const IndexingOptions &Opts);
53 
54 /// Recursively indexes all decls in the AST.
55 void indexASTUnit(ASTUnit &Unit, IndexDataConsumer &DataConsumer,
56                   IndexingOptions Opts);
57 
58 /// Recursively indexes \p Decls.
59 void indexTopLevelDecls(ASTContext &Ctx, Preprocessor &PP,
60                         ArrayRef<const Decl *> Decls,
61                         IndexDataConsumer &DataConsumer, IndexingOptions Opts);
62 
63 /// Creates a PPCallbacks that indexes macros and feeds macros to \p Consumer.
64 /// The caller is responsible for calling `Consumer.setPreprocessor()`.
65 std::unique_ptr<PPCallbacks> indexMacrosCallback(IndexDataConsumer &Consumer,
66                                                  IndexingOptions Opts);
67 
68 /// Recursively indexes all top-level decls in the module.
69 void indexModuleFile(serialization::ModuleFile &Mod, ASTReader &Reader,
70                      IndexDataConsumer &DataConsumer, IndexingOptions Opts);
71 
72 } // namespace index
73 } // namespace clang
74 
75 #endif
76