7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " FileIndex.h"
10
+ #include " CollectMacros.h"
10
11
#include " Logger.h"
11
12
#include " ParsedAST.h"
12
13
#include " SymbolCollector.h"
@@ -32,6 +33,7 @@ namespace clangd {
32
33
33
34
static SlabTuple indexSymbols (ASTContext &AST, std::shared_ptr<Preprocessor> PP,
34
35
llvm::ArrayRef<Decl *> DeclsToIndex,
36
+ const MainFileMacros *MacroRefsToIndex,
35
37
const CanonicalIncludes &Includes,
36
38
bool IsIndexMainAST) {
37
39
SymbolCollector::Options CollectorOpts;
@@ -59,6 +61,8 @@ static SlabTuple indexSymbols(ASTContext &AST, std::shared_ptr<Preprocessor> PP,
59
61
60
62
SymbolCollector Collector (std::move (CollectorOpts));
61
63
Collector.setPreprocessor (PP);
64
+ if (MacroRefsToIndex)
65
+ Collector.handleMacros (*MacroRefsToIndex);
62
66
index ::indexTopLevelDecls (AST, *PP, DeclsToIndex, Collector, IndexOpts);
63
67
64
68
const auto &SM = AST.getSourceManager ();
@@ -68,6 +72,7 @@ static SlabTuple indexSymbols(ASTContext &AST, std::shared_ptr<Preprocessor> PP,
68
72
auto Syms = Collector.takeSymbols ();
69
73
auto Refs = Collector.takeRefs ();
70
74
auto Relations = Collector.takeRelations ();
75
+
71
76
vlog (" index AST for {0} (main={1}): \n "
72
77
" symbol slab: {2} symbols, {3} bytes\n "
73
78
" ref slab: {4} symbols, {5} refs, {6} bytes\n "
@@ -80,7 +85,8 @@ static SlabTuple indexSymbols(ASTContext &AST, std::shared_ptr<Preprocessor> PP,
80
85
81
86
SlabTuple indexMainDecls (ParsedAST &AST) {
82
87
return indexSymbols (AST.getASTContext (), AST.getPreprocessorPtr (),
83
- AST.getLocalTopLevelDecls (), AST.getCanonicalIncludes (),
88
+ AST.getLocalTopLevelDecls (), &AST.getMacros (),
89
+ AST.getCanonicalIncludes (),
84
90
/* IsIndexMainAST=*/ true );
85
91
}
86
92
@@ -89,7 +95,8 @@ SlabTuple indexHeaderSymbols(ASTContext &AST, std::shared_ptr<Preprocessor> PP,
89
95
std::vector<Decl *> DeclsToIndex (
90
96
AST.getTranslationUnitDecl ()->decls ().begin (),
91
97
AST.getTranslationUnitDecl ()->decls ().end ());
92
- return indexSymbols (AST, std::move (PP), DeclsToIndex, Includes,
98
+ return indexSymbols (AST, std::move (PP), DeclsToIndex,
99
+ /* MainFileMacros=*/ nullptr , Includes,
93
100
/* IsIndexMainAST=*/ false );
94
101
}
95
102
0 commit comments