Go to the documentation of this file.
17 #include "clang/Basic/FileManager.h"
18 #include "clang/Lex/MacroArgs.h"
19 #include "llvm/Support/raw_ostream.h"
28 return std::string(
"(none)");
31 PresumedLoc PLoc =
PP.getSourceManager().getPresumedLoc(
Loc);
33 if (PLoc.isInvalid()) {
34 return std::string(
"(invalid)");
38 llvm::raw_string_ostream SS(Str);
41 SS <<
"\"" << PLoc.getFilename() <<
':' << PLoc.getLine() <<
':'
42 << PLoc.getColumn() <<
"\"";
44 std::string Result = SS.str();
52 return std::string(
"(nonfile)");
59 "EnterFile",
"ExitFile",
"SystemHeaderPragma",
"RenameFile"
68 "MD_Define",
"MD_Undefine",
"MD_Visibility"
78 "PMK_Message",
"PMK_Warning",
"PMK_Error"
83 "CVK_NotEvaluated",
"CVK_False",
"CVK_True"
88 "MAP_REMARK",
"MAP_WARNING",
89 "MAP_ERROR",
"MAP_FATAL" };
94 std::vector<CallbackCall> &CallbackCalls,
96 : CallbackCalls(CallbackCalls), Filters(Filters),
PP(
PP) {}
104 PPCallbacks::FileChangeReason Reason,
105 SrcMgr::CharacteristicKind FileType,
117 const Token &FilenameTok,
118 SrcMgr::CharacteristicKind FileType) {
129 llvm::SmallVectorImpl<char> &RecoveryPath) {
139 SourceLocation HashLoc,
const Token &IncludeTok, llvm::StringRef
FileName,
140 bool IsAngled, CharSourceRange FilenameRange,
const FileEntry *File,
141 llvm::StringRef SearchPath, llvm::StringRef RelativePath,
142 const Module *Imported, SrcMgr::CharacteristicKind FileType) {
158 const Module *Imported) {
178 PragmaIntroducerKind Introducer) {
186 const IdentifierInfo *
Kind,
187 llvm::StringRef Str) {
197 llvm::StringRef
Name,
198 llvm::StringRef Value) {
207 llvm::StringRef DebugType) {
215 llvm::StringRef Namespace,
216 PPCallbacks::PragmaMessageKind
Kind,
217 llvm::StringRef Str) {
228 llvm::StringRef Namespace) {
237 llvm::StringRef Namespace) {
245 llvm::StringRef Namespace,
246 diag::Severity Mapping,
247 llvm::StringRef Str) {
258 const IdentifierInfo *
Name,
259 SourceLocation StateLoc,
270 llvm::StringRef WarningSpec,
271 llvm::ArrayRef<int> Ids) {
277 llvm::raw_string_ostream SS(Str);
279 for (
int i = 0, e = Ids.size(); i != e; ++i) {
320 const MacroDefinition &MacroDefinition,
322 const MacroArgs *Args) {
332 const MacroDirective *MacroDirective) {
340 const MacroDefinition &MacroDefinition,
341 const MacroDirective *Undef) {
349 const MacroDefinition &MacroDefinition,
359 SourceLocation EndifLoc) {
376 SourceLocation IfLoc) {
386 const MacroDefinition &MacroDefinition) {
395 const MacroDefinition &MacroDefinition) {
422 llvm::StringRef N(
Name);
423 for (
const std::pair<llvm::GlobPattern, bool> &Filter :
Filters)
424 if (Filter.first.match(N))
425 R.first->second = Filter.second;
441 llvm::raw_string_ostream SS(Str);
455 llvm::StringRef Value) {
461 const std::string &Value) {
478 if (Value.isInvalid()) {
482 const FileEntry *FileEntry =
PP.getSourceManager().getFileEntryForID(Value);
492 const FileEntry *Value) {
502 SourceLocation Value) {
503 if (Value.isInvalid()) {
514 if (Value.isInvalid()) {
519 llvm::raw_string_ostream SS(Str);
527 CharSourceRange Value) {
528 if (Value.isInvalid()) {
540 llvm::raw_string_ostream SS(Str);
542 for (
int I = 0,
E = Value.size(); I !=
E; ++I) {
546 <<
"Name: " << Value[I].first->getName() <<
", "
555 const IdentifierInfo *Value) {
565 const MacroDirective *Value) {
575 const MacroDefinition &Value) {
577 llvm::raw_string_ostream SS(Str);
580 if (Value.getLocalDirective()) {
584 for (
auto *MM : Value.getModuleMacros()) {
586 SS << MM->getOwningModule()->getFullModuleName();
594 const MacroArgs *Value) {
600 llvm::raw_string_ostream SS(Str);
605 for (
unsigned I = 0; I < Value->getNumMacroArguments(); ++I) {
606 const Token *Current = Value->getUnexpArgument(I);
610 while (Current->isNot(tok::eof)) {
616 if (Current->isAnyIdentifier() || Current->is(tok::numeric_constant)) {
617 SS <<
PP.getSpelling(*Current);
619 SS <<
"<" << Current->getName() <<
">";
640 const std::string &Value) {
642 llvm::raw_string_ostream SS(Str);
643 SS <<
"\"" << Value <<
"\"";
649 llvm::StringRef Value) {
650 std::string
Path(Value);
658 const char *B =
PP.getSourceManager().getCharacterData(
Range.getBegin());
659 const char *
E =
PP.getSourceManager().getCharacterData(
Range.getEnd());
660 return llvm::StringRef(B,
E - B);
CharSourceRange Range
SourceRange for the file name.
static const char *const PragmaIntroducerKindStrings[]
void PragmaExecCharsetPop(SourceLocation Loc) override
void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, llvm::StringRef Str) override
void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *Name, SourceLocation StateLoc, unsigned State) 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 If(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue) override
std::vector< std::pair< llvm::GlobPattern, bool > > FilterType
void Endif(SourceLocation Loc, SourceLocation IfLoc) override
bool DisableTrace
Inhibit trace while this is set.
clang::PPCallbacks::ConditionValueKind ConditionValue
void PragmaWarningPop(SourceLocation Loc) override
void Defined(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range) override
~PPCallbacksTracker() override
void FileChanged(SourceLocation Loc, PPCallbacks::FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID=FileID()) override
void beginCallback(const char *Name)
Start a new callback.
static const char *const FileChangeReasonStrings[]
static const char *const CharacteristicKindStrings[]
void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path, const Module *Imported) override
void PragmaDirective(SourceLocation Loc, PragmaIntroducerKind Introducer) override
void PragmaWarningPush(SourceLocation Loc, int Level) override
llvm::StringMap< bool > CallbackIsEnabled
void Ifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
static const char *const PragmaMessageKindStrings[]
std::vector< CallbackCall > & CallbackCalls
Callback trace information.
static const char *const ConditionValueKindStrings[]
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
void appendArgument(const char *Name, bool Value)
Append a bool argument to the top trace item.
bool FileNotFound(llvm::StringRef FileName, llvm::SmallVectorImpl< char > &RecoveryPath) override
void Ident(SourceLocation Loc, llvm::StringRef str) override
static const char *const MacroDirectiveKindStrings[]
void FileSkipped(const FileEntryRef &SkippedFile, const Token &FilenameTok, SrcMgr::CharacteristicKind FileType) override
This class represents one callback call by name and an array of arguments.
static constexpr llvm::StringLiteral Name
void EndOfMainFile() override
void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override
static std::string replace(llvm::StringRef Haystack, llvm::StringRef Needle, llvm::StringRef Repl)
void appendFilePathArgument(const char *Name, llvm::StringRef Value)
Append a double-quoted file path argument to the top trace item.
void PragmaDetectMismatch(SourceLocation Loc, llvm::StringRef Name, llvm::StringRef Value) override
void Ifndef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
llvm::StringRef getSourceString(CharSourceRange Range)
Get the raw source string of the range.
void PragmaDiagnosticPush(SourceLocation Loc, llvm::StringRef Namespace) override
bool IsAngled
true if this was an include with angle brackets
const FilterType & Filters
void PragmaDiagnosticPop(SourceLocation Loc, llvm::StringRef Namespace) override
std::vector< llvm::StringRef > Strings
void PragmaMessage(SourceLocation Loc, llvm::StringRef Namespace, PPCallbacks::PragmaMessageKind Kind, llvm::StringRef Str) override
void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range, const MacroArgs *Args) override
void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD) override
static const char *const MappingStrings[]
void Elif(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue, SourceLocation IfLoc) override
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
void Else(SourceLocation Loc, SourceLocation IfLoc) override
void appendQuotedArgument(const char *Name, const std::string &Value)
Append a double-quoted argument to the top trace item.
static std::string getSourceLocationString(Preprocessor &PP, SourceLocation Loc)
SourceLocation Loc
'#' location in the include directive
void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *Undef) override
void PragmaWarning(SourceLocation Loc, llvm::StringRef WarningSpec, llvm::ArrayRef< int > Ids) override
void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str) override
void PragmaDebug(SourceLocation Loc, llvm::StringRef DebugType) override
void PragmaDiagnostic(SourceLocation Loc, llvm::StringRef Namespace, diag::Severity mapping, llvm::StringRef Str) override
std::vector< HeaderHandle > Path