xref: /llvm-project/clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbols.h (revision 282dc72c8b84759dda4fe12420228158962351e8)
143356f56SNico Weber //===-- FindAllSymbols.h - find all symbols----------------------*- C++ -*-===//
243356f56SNico Weber //
343356f56SNico Weber // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
443356f56SNico Weber // See https://llvm.org/LICENSE.txt for license information.
543356f56SNico Weber // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
643356f56SNico Weber //
743356f56SNico Weber //===----------------------------------------------------------------------===//
843356f56SNico Weber 
943356f56SNico Weber #ifndef LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_SYMBOL_MATCHER_H
1043356f56SNico Weber #define LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_SYMBOL_MATCHER_H
1143356f56SNico Weber 
1243356f56SNico Weber #include "SymbolInfo.h"
1343356f56SNico Weber #include "SymbolReporter.h"
1443356f56SNico Weber #include "clang/ASTMatchers/ASTMatchFinder.h"
1543356f56SNico Weber #include <string>
1643356f56SNico Weber 
1743356f56SNico Weber namespace clang {
1843356f56SNico Weber namespace find_all_symbols {
1943356f56SNico Weber 
2043356f56SNico Weber class HeaderMapCollector;
2143356f56SNico Weber 
22*282dc72cSDmitri Gribenko /// FindAllSymbols collects all classes, free standing functions and
2343356f56SNico Weber /// global variables with some extra information such as the path of the header
2443356f56SNico Weber /// file, the namespaces they are contained in, the type of variables and the
2543356f56SNico Weber /// parameter types of functions.
2643356f56SNico Weber ///
2743356f56SNico Weber /// NOTE:
2843356f56SNico Weber ///   - Symbols declared in main files are not collected since they can not be
2943356f56SNico Weber ///   included.
3043356f56SNico Weber ///   - Member functions are not collected because accessing them must go
3143356f56SNico Weber ///   through the class. #include fixer only needs the class name to find
3243356f56SNico Weber ///   headers.
3343356f56SNico Weber ///
3443356f56SNico Weber class FindAllSymbols : public ast_matchers::MatchFinder::MatchCallback {
3543356f56SNico Weber public:
3643356f56SNico Weber   explicit FindAllSymbols(SymbolReporter *Reporter,
3743356f56SNico Weber                           HeaderMapCollector *Collector = nullptr)
Reporter(Reporter)3843356f56SNico Weber       : Reporter(Reporter), Collector(Collector) {}
3943356f56SNico Weber 
4043356f56SNico Weber   void registerMatchers(ast_matchers::MatchFinder *MatchFinder);
4143356f56SNico Weber 
4243356f56SNico Weber   void run(const ast_matchers::MatchFinder::MatchResult &result) override;
4343356f56SNico Weber 
4443356f56SNico Weber protected:
4543356f56SNico Weber   void onEndOfTranslationUnit() override;
4643356f56SNico Weber 
4743356f56SNico Weber private:
4843356f56SNico Weber   // Current source file being processed, filled by first symbol found.
4943356f56SNico Weber   std::string Filename;
5043356f56SNico Weber   // Findings for the current source file, flushed on onEndOfTranslationUnit.
5143356f56SNico Weber   SymbolInfo::SignalMap FileSymbols;
5243356f56SNico Weber   // Reporter for SymbolInfo.
5343356f56SNico Weber   SymbolReporter *const Reporter;
5443356f56SNico Weber   // A remapping header file collector allowing clients include a different
5543356f56SNico Weber   // header.
5643356f56SNico Weber   HeaderMapCollector *const Collector;
5743356f56SNico Weber };
5843356f56SNico Weber 
5943356f56SNico Weber } // namespace find_all_symbols
6043356f56SNico Weber } // namespace clang
6143356f56SNico Weber 
6243356f56SNico Weber #endif // LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_SYMBOL_MATCHER_H
63