9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_COLLECTEDMACROS_H 10 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_COLLECTEDMACROS_H 16 #include "clang/Basic/IdentifierTable.h" 17 #include "clang/Lex/PPCallbacks.h" 18 #include "llvm/ADT/DenseMap.h" 28 llvm::DenseMap<SymbolID, std::vector<Range>>
MacroRefs;
44 const LangOptions &LangOpts,
46 : SM(SM), LangOpts(LangOpts), Out(Out) {}
49 SrcMgr::CharacteristicKind, FileID)
override {
53 void MacroDefined(
const Token &MacroName,
const MacroDirective *
MD)
override {
54 add(MacroName, MD->getMacroInfo());
58 SourceRange
Range,
const MacroArgs *Args)
override {
59 add(MacroName, MD.getMacroInfo());
63 const clang::MacroDefinition &
MD,
64 const clang::MacroDirective *Undef)
override {
65 add(MacroName, MD.getMacroInfo());
68 void Ifdef(SourceLocation
Loc,
const Token &MacroName,
69 const MacroDefinition &
MD)
override {
70 add(MacroName, MD.getMacroInfo());
73 void Ifndef(SourceLocation
Loc,
const Token &MacroName,
74 const MacroDefinition &
MD)
override {
75 add(MacroName, MD.getMacroInfo());
78 void Defined(
const Token &MacroName,
const MacroDefinition &
MD,
79 SourceRange
Range)
override {
80 add(MacroName, MD.getMacroInfo());
88 Out.SkippedRanges.push_back(
Range{Begin, End});
92 void add(
const Token &MacroNameTok,
const MacroInfo *MI) {
95 auto Loc = MacroNameTok.getLocation();
100 auto Name = MacroNameTok.getIdentifierInfo()->getName();
101 Out.Names.insert(
Name);
103 Out.MacroRefs[*SID].push_back(*
Range);
105 Out.UnknownMacros.push_back(*
Range);
108 const SourceManager &SM;
109 const LangOptions &LangOpts;
110 bool InMainFile =
true;
117 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_COLLECTEDMACROS_H SourceLocation Loc
'#' location in the include directive
std::vector< Range > SkippedRanges
void SourceRangeSkipped(SourceRange R, SourceLocation EndifLoc) override
llvm::Optional< SymbolID > getSymbolID(const Decl *D)
Gets the symbol ID for a declaration, if possible.
Collects macro references (e.g.
bool isInsideMainFile(SourceLocation Loc, const SourceManager &SM)
Returns true iff Loc is inside the main file.
void Ifdef(SourceLocation Loc, const Token &MacroName, const MacroDefinition &MD) override
void Defined(const Token &MacroName, const MacroDefinition &MD, SourceRange Range) override
void Ifndef(SourceLocation Loc, const Token &MacroName, const MacroDefinition &MD) override
std::vector< Range > UnknownMacros
llvm::DenseMap< SymbolID, std::vector< Range > > MacroRefs
void MacroUndefined(const clang::Token &MacroName, const clang::MacroDefinition &MD, const clang::MacroDirective *Undef) override
void FileChanged(SourceLocation Loc, FileChangeReason, SrcMgr::CharacteristicKind, FileID) override
void MacroDefined(const Token &MacroName, const MacroDirective *MD) override
static constexpr llvm::StringLiteral Name
llvm::Optional< Range > getTokenRange(const SourceManager &SM, const LangOptions &LangOpts, SourceLocation TokLoc)
Returns the taken range at TokLoc.
Position sourceLocToPosition(const SourceManager &SM, SourceLocation Loc)
Turn a SourceLocation into a [line, column] pair.
void MacroExpands(const Token &MacroName, const MacroDefinition &MD, SourceRange Range, const MacroArgs *Args) override
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static GeneratorRegistry::Add< MDGenerator > MD(MDGenerator::Format, "Generator for MD output.")
CollectMainFileMacros(const SourceManager &SM, const LangOptions &LangOpts, MainFileMacros &Out)