17 #include "clang/Lex/MacroArgs.h" 18 #include "llvm/Support/raw_ostream.h" 27 return std::string(
"(none)");
30 PresumedLoc PLoc = PP.getSourceManager().getPresumedLoc(Loc);
32 if (PLoc.isInvalid()) {
33 return std::string(
"(invalid)");
37 llvm::raw_string_ostream SS(Str);
40 SS <<
"\"" << PLoc.getFilename() <<
':' << PLoc.getLine() <<
':' 41 << PLoc.getColumn() <<
"\"";
43 std::string Result = SS.str();
51 return std::string(
"(nonfile)");
58 "EnterFile",
"ExitFile",
"SystemHeaderPragma",
"RenameFile" 67 "MD_Define",
"MD_Undefine",
"MD_Visibility" 77 "PMK_Message",
"PMK_Warning",
"PMK_Error" 82 "CVK_NotEvaluated",
"CVK_False",
"CVK_True" 87 "MAP_REMARK",
"MAP_WARNING",
88 "MAP_ERROR",
"MAP_FATAL" };
93 std::vector<CallbackCall> &CallbackCalls,
95 : CallbackCalls(CallbackCalls), Filters(Filters), PP(PP) {}
103 PPCallbacks::FileChangeReason Reason,
104 SrcMgr::CharacteristicKind FileType,
116 const Token &FilenameTok,
117 SrcMgr::CharacteristicKind FileType) {
128 llvm::SmallVectorImpl<char> &RecoveryPath) {
138 SourceLocation HashLoc,
const Token &IncludeTok, llvm::StringRef
FileName,
139 bool IsAngled, CharSourceRange FilenameRange,
const FileEntry *File,
140 llvm::StringRef SearchPath, llvm::StringRef RelativePath,
141 const Module *Imported, SrcMgr::CharacteristicKind FileType) {
157 const Module *Imported) {
177 PragmaIntroducerKind Introducer) {
180 appendArgument(
"Introducer", Introducer, PragmaIntroducerKindStrings);
185 const IdentifierInfo *
Kind,
186 llvm::StringRef Str) {
196 llvm::StringRef
Name,
197 llvm::StringRef Value) {
206 llvm::StringRef DebugType) {
214 llvm::StringRef Namespace,
215 PPCallbacks::PragmaMessageKind
Kind,
216 llvm::StringRef Str) {
227 llvm::StringRef Namespace) {
236 llvm::StringRef Namespace) {
244 llvm::StringRef Namespace,
245 diag::Severity Mapping,
246 llvm::StringRef Str) {
257 const IdentifierInfo *
Name,
258 SourceLocation StateLoc,
269 llvm::StringRef WarningSpec,
270 llvm::ArrayRef<int> Ids) {
276 llvm::raw_string_ostream SS(Str);
278 for (
int i = 0, e = Ids.size(); i != e; ++i) {
319 const MacroDefinition &MacroDefinition,
321 const MacroArgs *Args) {
331 const MacroDirective *MacroDirective) {
339 const MacroDefinition &MacroDefinition,
340 const MacroDirective *Undef) {
348 const MacroDefinition &MacroDefinition,
358 SourceLocation EndifLoc) {
369 appendArgument(
"ConditionValue", ConditionValue, ConditionValueKindStrings);
375 SourceLocation IfLoc) {
379 appendArgument(
"ConditionValue", ConditionValue, ConditionValueKindStrings);
385 const MacroDefinition &MacroDefinition) {
394 const MacroDefinition &MacroDefinition) {
421 llvm::StringRef N(Name);
422 for (
const std::pair<llvm::GlobPattern, bool> &Filter :
Filters)
423 if (Filter.first.match(N))
424 R.first->second = Filter.second;
440 llvm::raw_string_ostream SS(Str);
454 llvm::StringRef Value) {
460 const std::string &Value) {
477 if (Value.isInvalid()) {
481 const FileEntry *FileEntry =
PP.getSourceManager().getFileEntryForID(Value);
491 const FileEntry *Value) {
501 SourceLocation Value) {
502 if (Value.isInvalid()) {
513 if (Value.isInvalid()) {
518 llvm::raw_string_ostream SS(Str);
526 CharSourceRange Value) {
527 if (Value.isInvalid()) {
539 llvm::raw_string_ostream SS(Str);
541 for (
int I = 0,
E = Value.size(); I !=
E; ++I) {
545 <<
"Name: " << Value[I].first->getName() <<
", " 554 const IdentifierInfo *Value) {
564 const MacroDirective *Value) {
569 appendArgument(Name, MacroDirectiveKindStrings[Value->getKind()]);
574 const MacroDefinition &Value) {
576 llvm::raw_string_ostream SS(Str);
579 if (Value.getLocalDirective()) {
583 for (
auto *MM : Value.getModuleMacros()) {
585 SS << MM->getOwningModule()->getFullModuleName();
593 const MacroArgs *Value) {
599 llvm::raw_string_ostream SS(Str);
604 for (
unsigned I = 0; I < Value->getNumMacroArguments(); ++I) {
605 const Token *Current = Value->getUnexpArgument(I);
609 while (Current->isNot(tok::eof)) {
615 if (Current->isAnyIdentifier() || Current->is(tok::numeric_constant)) {
616 SS <<
PP.getSpelling(*Current);
618 SS <<
"<" << Current->getName() <<
">";
639 const std::string &Value) {
641 llvm::raw_string_ostream SS(Str);
642 SS <<
"\"" << Value <<
"\"";
648 llvm::StringRef Value) {
649 std::string
Path(Value);
657 const char *B =
PP.getSourceManager().getCharacterData(Range.getBegin());
658 const char *
E =
PP.getSourceManager().getCharacterData(Range.getEnd());
659 return llvm::StringRef(B, E - B);
SourceLocation Loc
'#' location in the include directive
void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path, const Module *Imported) override
std::vector< CallbackCall > & CallbackCalls
Callback trace information.
void appendQuotedArgument(const char *Name, const std::string &Value)
Append a double-quoted argument to the top trace item.
void FileSkipped(const FileEntryRef &SkippedFile, const Token &FilenameTok, SrcMgr::CharacteristicKind FileType) override
void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD) override
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, llvm::StringRef SearchPath, llvm::StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override
static const char *const CharacteristicKindStrings[]
static const char *const FileChangeReasonStrings[]
void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override
const FilterType & Filters
std::vector< HeaderHandle > Path
void PragmaDetectMismatch(SourceLocation Loc, llvm::StringRef Name, llvm::StringRef Value) override
static std::string replace(llvm::StringRef Haystack, llvm::StringRef Needle, llvm::StringRef Repl)
void PragmaExecCharsetPop(SourceLocation Loc) override
llvm::StringRef getSourceString(CharSourceRange Range)
Get the raw source string of the range.
void Elif(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue, SourceLocation IfLoc) override
void If(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue) override
static const char *const PragmaIntroducerKindStrings[]
void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, llvm::StringRef Str) override
bool DisableTrace
Inhibit trace while this is set.
void Defined(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range) override
void Else(SourceLocation Loc, SourceLocation IfLoc) override
void PragmaMessage(SourceLocation Loc, llvm::StringRef Namespace, PPCallbacks::PragmaMessageKind Kind, llvm::StringRef Str) override
This class represents one callback call by name and an array of arguments.
void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *Name, SourceLocation StateLoc, unsigned State) override
void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range, const MacroArgs *Args) override
PPCallbacksTracker(const FilterType &Filters, std::vector< CallbackCall > &CallbackCalls, Preprocessor &PP)
Note that all of the arguments are references, and owned by the caller.
void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *Undef) override
bool IsAngled
true if this was an include with angle brackets
Classes and definitions for preprocessor tracking.
void PragmaWarning(SourceLocation Loc, llvm::StringRef WarningSpec, llvm::ArrayRef< int > Ids) override
static constexpr llvm::StringLiteral Name
void beginCallback(const char *Name)
Start a new callback.
void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str) override
void PragmaDebug(SourceLocation Loc, llvm::StringRef DebugType) override
static const char *const MacroDirectiveKindStrings[]
static const char *const ConditionValueKindStrings[]
void appendArgument(const char *Name, bool Value)
Append a bool argument to the top trace item.
clang::PPCallbacks::ConditionValueKind ConditionValue
void PragmaWarningPush(SourceLocation Loc, int Level) override
std::vector< llvm::StringRef > Strings
llvm::StringMap< bool > CallbackIsEnabled
static const char *const PragmaMessageKindStrings[]
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
void PragmaDiagnostic(SourceLocation Loc, llvm::StringRef Namespace, diag::Severity mapping, llvm::StringRef Str) override
void Ifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
static std::string getSourceLocationString(Preprocessor &PP, SourceLocation Loc)
CharSourceRange Range
SourceRange for the file name.
bool FileNotFound(llvm::StringRef FileName, llvm::SmallVectorImpl< char > &RecoveryPath) override
static const char *const MappingStrings[]
std::vector< std::pair< llvm::GlobPattern, bool > > FilterType
void Endif(SourceLocation Loc, SourceLocation IfLoc) override
void Ident(SourceLocation Loc, llvm::StringRef str) override
void appendFilePathArgument(const char *Name, llvm::StringRef Value)
Append a double-quoted file path argument to the top trace item.
void FileChanged(SourceLocation Loc, PPCallbacks::FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID=FileID()) override
void EndOfMainFile() override
void PragmaDiagnosticPush(SourceLocation Loc, llvm::StringRef Namespace) override
~PPCallbacksTracker() override
void PragmaDiagnosticPop(SourceLocation Loc, llvm::StringRef Namespace) override
void PragmaWarningPop(SourceLocation Loc) override
void PragmaDirective(SourceLocation Loc, PragmaIntroducerKind Introducer) override
void Ifndef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override