[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang-tools-extra / clang-include-fixer / find-all-symbols / FindAllSymbols.h
blob4893cda501097f343c406627912aaa06ae6df739
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_SYMBOL_MATCHER_H
10 #define LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_SYMBOL_MATCHER_H
12 #include "SymbolInfo.h"
13 #include "SymbolReporter.h"
14 #include "clang/ASTMatchers/ASTMatchFinder.h"
15 #include <string>
17 namespace clang {
18 namespace find_all_symbols {
20 class HeaderMapCollector;
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) {}
40 void registerMatchers(ast_matchers::MatchFinder *MatchFinder);
42 void run(const ast_matchers::MatchFinder::MatchResult &result) override;
44 protected:
45 void onEndOfTranslationUnit() override;
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;
59 } // namespace find_all_symbols
60 } // namespace clang
62 #endif // LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_SYMBOL_MATCHER_H