13#include "clang/Basic/SourceLocation.h"
14#include "clang/Tooling/Syntax/Tokens.h"
15#include "llvm/ADT/STLExtras.h"
27void CollectMainFileMacros::add(
const Token &MacroNameTok,
const MacroInfo *MI,
28 bool IsDefinition,
bool InIfCondition) {
31 auto Loc = MacroNameTok.getLocation();
32 if (
Loc.isInvalid() ||
Loc.isMacroID())
35 auto Name = MacroNameTok.getIdentifierInfo()->getName();
37 size_t Start = SM.getFileOffset(
Loc);
38 size_t End = SM.getFileOffset(MacroNameTok.getEndLoc());
40 Out.
MacroRefs[SID].push_back({Start, End, IsDefinition, InIfCondition});
42 Out.
UnknownMacros.push_back({Start, End, IsDefinition, InIfCondition});
46 SrcMgr::CharacteristicKind, FileID) {
51 const MacroDefinition &MD,
53 const MacroArgs *
Args) {
58 const clang::MacroDefinition &MD,
59 const clang::MacroDirective *Undef) {
64 const MacroDefinition &MD) {
70 const MacroDefinition &MD) {
76 const MacroDefinition &MD) {
82 const MacroDefinition &MD) {
88 const MacroDefinition &MD,
95 SourceLocation EndifLoc) {
106 std::vector<clangd::PragmaMark> &Out)
120 const SourceManager &SM;
121 std::vector<clangd::PragmaMark> &Out;
124std::unique_ptr<PPCallbacks>
126 std::vector<PragmaMark> &
Out) {
127 return std::make_unique<CollectPragmaMarks>(SM,
Out);
131 const MacroDirective *MD) {
135 const auto *MI = MD->getMacroInfo();
136 add(
MacroName, MD->getMacroInfo(),
true);
138 for (
const auto &Tok : MI->tokens()) {
139 auto *II = Tok.getIdentifierInfo();
141 if (!II || !II->hadMacroDefinition() ||
142 llvm::is_contained(MI->params(), II))
144 if (
const MacroInfo *MI = PP.getMacroInfo(II))
llvm::SmallString< 256U > Name
CompiledFragmentImpl & Out
void MacroDefined(const Token &MacroName, const MacroDirective *MD) override
void FileChanged(SourceLocation Loc, FileChangeReason, SrcMgr::CharacteristicKind, FileID) override
void MacroExpands(const Token &MacroName, const MacroDefinition &MD, SourceRange Range, const MacroArgs *Args) override
void Elifndef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
void Defined(const Token &MacroName, const MacroDefinition &MD, SourceRange Range) override
void MacroUndefined(const clang::Token &MacroName, const clang::MacroDefinition &MD, const clang::MacroDirective *Undef) override
void Ifndef(SourceLocation Loc, const Token &MacroName, const MacroDefinition &MD) override
void SourceRangeSkipped(SourceRange R, SourceLocation EndifLoc) override
void Ifdef(SourceLocation Loc, const Token &MacroName, const MacroDefinition &MD) override
void Elifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
CollectPragmaMarks(const SourceManager &SM, std::vector< clangd::PragmaMark > &Out)
void PragmaMark(SourceLocation Loc, StringRef Trivia) override
SymbolID getSymbolID(const Decl *D)
Gets the symbol ID for a declaration. Returned SymbolID might be null.
Range halfOpenToRange(const SourceManager &SM, CharSourceRange R)
bool isInsideMainFile(SourceLocation Loc, const SourceManager &SM)
Returns true iff Loc is inside the main file.
std::unique_ptr< PPCallbacks > collectPragmaMarksCallback(const SourceManager &SM, std::vector< PragmaMark > &Out)
Collect all pragma marks from the main file.
Position sourceLocToPosition(const SourceManager &SM, SourceLocation Loc)
Turn a SourceLocation into a [line, column] pair.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Range toRange(const SourceManager &SM) const
std::vector< MacroOccurrence > UnknownMacros
llvm::DenseMap< SymbolID, std::vector< MacroOccurrence > > MacroRefs
std::vector< Range > SkippedRanges
Represents a #pragma mark in the main file.