13#include "clang/ASTMatchers/ASTMatchFinder.h"
14#include "clang/ASTMatchers/ASTMatchers.h"
15#include "clang/Frontend/CompilerInstance.h"
16#include "clang/Frontend/FrontendActions.h"
17#include "clang/Lex/Preprocessor.h"
18#include "clang/Tooling/CommonOptionsParser.h"
19#include "clang/Tooling/Tooling.h"
20#include "llvm/ADT/ArrayRef.h"
21#include "llvm/ADT/SmallString.h"
22#include "llvm/ADT/StringRef.h"
23#include "llvm/Support/CommandLine.h"
24#include "llvm/Support/FileSystem.h"
25#include "llvm/Support/MemoryBuffer.h"
26#include "llvm/Support/Path.h"
27#include "llvm/Support/ThreadPool.h"
28#include "llvm/Support/raw_ostream.h"
33#include <system_error>
47static cl::extrahelp
CommonHelp(CommonOptionsParser::HelpMessage);
50static cl::extrahelp
MoreHelp(
"\nMore help text...");
52static cl::opt<std::string>
OutputDir(
"output-dir", cl::desc(R
"(
53The output directory for saving the results.)"),
57static cl::opt<std::string>
MergeDir(
"merge-dir", cl::desc(R
"(
58The directory for merging symbols.)"),
62namespace find_all_symbols {
69 SmallString<128> ResultPath;
70 llvm::sys::fs::createUniqueFile(
73 llvm::raw_fd_ostream
OS(FD,
true);
78bool Merge(llvm::StringRef
MergeDir, llvm::StringRef OutputFile) {
81 std::mutex SymbolMutex;
82 auto AddSymbols = [&](ArrayRef<SymbolAndSignals> NewSymbols) {
84 std::unique_lock<std::mutex> LockGuard(SymbolMutex);
85 for (
const auto &Symbol : NewSymbols) {
86 Symbols[Symbol.Symbol] += Symbol.Signals;
92 llvm::DefaultThreadPool Pool;
93 for (llvm::sys::fs::directory_iterator Dir(
MergeDir, EC), DirEnd;
94 Dir != DirEnd && !EC; Dir.increment(EC)) {
97 [&AddSymbols](std::string
Path) {
98 auto Buffer = llvm::MemoryBuffer::getFile(
Path);
100 llvm::errs() <<
"Can't open " <<
Path <<
"\n";
103 std::vector<SymbolAndSignals> Symbols =
105 for (
auto &Symbol : Symbols) {
107 Symbol.Signals.Seen = std::min(Symbol.Signals.Seen, 1u);
108 Symbol.Signals.Used = std::min(Symbol.Signals.Used, 1u);
117 llvm::raw_fd_ostream
OS(OutputFile, EC, llvm::sys::fs::OF_None);
119 llvm::errs() <<
"Can't open '" << OutputFile <<
"': " << EC.message()
130int main(
int argc,
const char **argv) {
131 auto ExpectedParser =
133 if (!ExpectedParser) {
134 llvm::errs() << ExpectedParser.takeError();
138 CommonOptionsParser &OptionsParser = ExpectedParser.get();
139 ClangTool Tool(OptionsParser.getCompilations(),
140 OptionsParser.getSourcePathList());
142 std::vector<std::string> sources = OptionsParser.getSourcePathList();
143 if (sources.empty()) {
144 llvm::errs() <<
"Must specify at least one one source file.\n";
155 std::make_unique<clang::find_all_symbols::FindAllSymbolsActionFactory>(
157 return Tool.run(Factory.get());
int main(int argc, const char **argv)
static cl::OptionCategory FindAllSymbolsCategory("find_all_symbols options")
static cl::opt< std::string > MergeDir("merge-dir", cl::desc(R"(
The directory for merging symbols.)"), cl::init(""), cl::cat(FindAllSymbolsCategory))
static cl::extrahelp MoreHelp("\nMore help text...")
static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage)
static cl::opt< std::string > OutputDir("output-dir", cl::desc(R"(
The output directory for saving the results.)"), cl::init("."), cl::cat(FindAllSymbolsCategory))
std::vector< HeaderHandle > Path
llvm::raw_string_ostream OS
Describes a named symbol from a header.
std::map< SymbolInfo, Signals > SignalMap
An interface for classes that collect symbols.
void reportSymbols(StringRef FileName, const SymbolInfo::SignalMap &Symbols) override
bool Merge(llvm::StringRef MergeDir, llvm::StringRef OutputFile)
const HeaderMapCollector::RegexHeaderMap * getSTLPostfixHeaderMap()
bool WriteSymbolInfosToStream(llvm::raw_ostream &OS, const SymbolInfo::SignalMap &Symbols)
Write SymbolInfos to a stream (YAML format).
std::vector< SymbolAndSignals > ReadSymbolInfosFromYAML(llvm::StringRef Yaml)
Read SymbolInfos from a YAML document.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Some operations such as code completion produce a set of candidates.