63 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_SYMBOL_MATCHER_H10#define LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_SYMBOL_MATCHER_H11 12#include "SymbolInfo.h"13#include "SymbolReporter.h"14#include "clang/ASTMatchers/ASTMatchFinder.h"15#include <string>16 17namespace clang {18namespace find_all_symbols {19 20class HeaderMapCollector;21 22/// FindAllSymbols collects all classes, free standing functions and23/// global variables with some extra information such as the path of the header24/// file, the namespaces they are contained in, the type of variables and the25/// parameter types of functions.26///27/// NOTE:28/// - Symbols declared in main files are not collected since they can not be29/// included.30/// - Member functions are not collected because accessing them must go31/// through the class. #include fixer only needs the class name to find32/// headers.33///34class FindAllSymbols : public ast_matchers::MatchFinder::MatchCallback {35public: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 44protected:45 void onEndOfTranslationUnit() override;46 47private: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 different55 // header.56 HeaderMapCollector *const Collector;57};58 59} // namespace find_all_symbols60} // namespace clang61 62#endif // LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_SYMBOL_MATCHER_H63