1 | //===-- FindAllMacros.h - find all macros -----------------------*- C++ -*-===// |
2 | // |
3 | // |
4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
5 | // See https://llvm.org/LICENSE.txt for license information. |
6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
7 | // |
8 | //===----------------------------------------------------------------------===// |
9 | |
10 | #ifndef LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_FIND_ALL_MACROS_H |
11 | #define |
12 | |
13 | #include "SymbolInfo.h" |
14 | #include "SymbolReporter.h" |
15 | #include "clang/Lex/PPCallbacks.h" |
16 | #include <optional> |
17 | |
18 | namespace clang { |
19 | class MacroInfo; |
20 | namespace find_all_symbols { |
21 | |
22 | class ; |
23 | |
24 | /// A preprocessor that collects all macro symbols. |
25 | /// The contexts of a macro will be ignored since they are not available during |
26 | /// preprocessing period. |
27 | class FindAllMacros : public clang::PPCallbacks { |
28 | public: |
29 | explicit (SymbolReporter *Reporter, SourceManager *SM, |
30 | HeaderMapCollector *Collector = nullptr) |
31 | : Reporter(Reporter), SM(SM), Collector(Collector) {} |
32 | |
33 | void MacroDefined(const Token &MacroNameTok, |
34 | const MacroDirective *MD) override; |
35 | |
36 | void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, |
37 | SourceRange Range, const MacroArgs *Args) override; |
38 | |
39 | void Ifdef(SourceLocation Loc, const Token &MacroNameTok, |
40 | const MacroDefinition &MD) override; |
41 | |
42 | void Ifndef(SourceLocation Loc, const Token &MacroNameTok, |
43 | const MacroDefinition &MD) override; |
44 | |
45 | void EndOfMainFile() override; |
46 | |
47 | private: |
48 | std::optional<SymbolInfo> CreateMacroSymbol(const Token &MacroNameTok, |
49 | const MacroInfo *MD); |
50 | // Not a callback, just a common path for all usage types. |
51 | void MacroUsed(const Token &Name, const MacroDefinition &MD); |
52 | |
53 | SymbolInfo::SignalMap FileSymbols; |
54 | // Reporter for SymbolInfo. |
55 | SymbolReporter *const Reporter; |
56 | SourceManager *const SM; |
57 | // A remapping header file collector allowing clients to include a different |
58 | // header. |
59 | HeaderMapCollector *const Collector; |
60 | }; |
61 | |
62 | } // namespace find_all_symbols |
63 | } // namespace clang |
64 | |
65 | #endif // LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_FIND_ALL_MACROS_H |
66 | |