13#include "clang/Basic/FileManager.h"
14#include "clang/Basic/IdentifierTable.h"
15#include "clang/Basic/SourceManager.h"
16#include "clang/Lex/MacroInfo.h"
17#include "clang/Lex/Token.h"
18#include "llvm/Support/Path.h"
22namespace find_all_symbols {
24std::optional<SymbolInfo>
25FindAllMacros::CreateMacroSymbol(
const Token &MacroNameTok,
26 const MacroInfo *info) {
27 std::string FilePath =
31 return SymbolInfo(MacroNameTok.getIdentifierInfo()->getName(),
36 const MacroDirective *MD) {
37 if (
auto Symbol = CreateMacroSymbol(MacroNameTok, MD->getMacroInfo()))
38 ++FileSymbols[*Symbol].Seen;
41void FindAllMacros::MacroUsed(
const Token &
Name,
const MacroDefinition &MD) {
42 if (!MD || !SM->isInMainFile(SM->getExpansionLoc(
Name.getLocation())))
44 if (
auto Symbol = CreateMacroSymbol(
Name, MD.getMacroInfo()))
45 ++FileSymbols[*Symbol].Used;
49 const MacroDefinition &MD, SourceRange
Range,
50 const MacroArgs *
Args) {
51 MacroUsed(MacroNameTok, MD);
55 const MacroDefinition &MD) {
56 MacroUsed(MacroNameTok, MD);
60 const MacroDefinition &MD) {
61 MacroUsed(MacroNameTok, MD);
66 SM->getFileEntryRefForID(SM->getMainFileID())->getName(), FileSymbols);
llvm::SmallString< 256U > Name
CharSourceRange Range
SourceRange for the file name.
void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD) override
void Ifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range, const MacroArgs *Args) override
void Ifndef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
void EndOfMainFile() override
Describes a named symbol from a header.
virtual void reportSymbols(llvm::StringRef FileName, const SymbolInfo::SignalMap &Symbols)=0
std::string getIncludePath(const SourceManager &SM, SourceLocation Loc, const HeaderMapCollector *Collector)
This calculates the include path for Loc.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//