| 1 |
//===-- FindAllSymbols.h - find all symbols----------------------*- 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_TOOLS_EXTRA_FIND_ALL_SYMBOLS_SYMBOL_MATCHER_H |
| 10 |
#define LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_SYMBOL_MATCHER_H |
| 11 |
|
| 12 |
#include "SymbolInfo.h" |
| 13 |
#include "SymbolReporter.h" |
| 14 |
#include "clang/ASTMatchers/ASTMatchFinder.h" |
| 15 |
#include <string> |
| 16 |
|
| 17 |
namespace clang { |
| 18 |
namespace find_all_symbols { |
| 19 |
|
| 20 |
class HeaderMapCollector; |
| 21 |
|
| 22 |
/// FindAllSymbols collects all classes, free standing functions and |
| 23 |
/// global variables with some extra information such as the path of the header |
| 24 |
/// file, the namespaces they are contained in, the type of variables and the |
| 25 |
/// parameter types of functions. |
| 26 |
/// |
| 27 |
/// NOTE: |
| 28 |
/// - Symbols declared in main files are not collected since they can not be |
| 29 |
/// included. |
| 30 |
/// - Member functions are not collected because accessing them must go |
| 31 |
/// through the class. #include fixer only needs the class name to find |
| 32 |
/// headers. |
| 33 |
/// |
| 34 |
class FindAllSymbols : public ast_matchers::MatchFinder::MatchCallback { |
| 35 |
public: |
| 36 |
explicit FindAllSymbols(SymbolReporter *Reporter, |
| 37 |
HeaderMapCollector *Collector = nullptr) |
| 38 |
: Reporter(Reporter), Collector(Collector) {} |
| 39 |
|
| 40 |
void registerMatchers(ast_matchers::MatchFinder *MatchFinder); |
| 41 |
|
| 42 |
void run(const ast_matchers::MatchFinder::MatchResult &result) override; |
| 43 |
|
| 44 |
protected: |
| 45 |
void onEndOfTranslationUnit() override; |
| 46 |
|
| 47 |
private: |
| 48 |
// Current source file being processed, filled by first symbol found. |
| 49 |
std::string Filename; |
| 50 |
// Findings for the current source file, flushed on onEndOfTranslationUnit. |
| 51 |
SymbolInfo::SignalMap FileSymbols; |
| 52 |
// Reporter for SymbolInfo. |
| 53 |
SymbolReporter *const Reporter; |
| 54 |
// A remapping header file collector allowing clients include a different |
| 55 |
// header. |
| 56 |
HeaderMapCollector *const Collector; |
| 57 |
}; |
| 58 |
|
| 59 |
} // namespace find_all_symbols |
| 60 |
} // namespace clang |
| 61 |
|
| 62 |
#endif // LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_SYMBOL_MATCHER_H |