18 #include "clang/Lex/MacroArgs.h"
19 #include "llvm/Support/raw_ostream.h"
25 clang::SourceLocation
Loc) {
27 return std::string(
"(none)");
30 clang::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();
46 std::replace(Result.begin(), Result.end(),
'\\',
'/');
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,
94 clang::Preprocessor &
PP)
95 : CallbackCalls(CallbackCalls), Ignore(Ignore), PP(PP) {}
103 clang::SourceLocation
Loc, clang::PPCallbacks::FileChangeReason Reason,
104 clang::SrcMgr::CharacteristicKind FileType, clang::FileID PrevFID) {
116 const clang::Token &FilenameTok,
117 clang::SrcMgr::CharacteristicKind FileType) {
128 llvm::SmallVectorImpl<char> &RecoveryPath) {
138 clang::SourceLocation HashLoc,
const clang::Token &IncludeTok,
139 llvm::StringRef FileName,
bool IsAngled,
140 clang::CharSourceRange FilenameRange,
const clang::FileEntry *
File,
141 llvm::StringRef SearchPath, llvm::StringRef RelativePath,
142 const clang::Module *Imported) {
157 clang::ModuleIdPath
Path,
158 const clang::Module *Imported) {
179 clang::PragmaIntroducerKind Introducer) {
187 const clang::IdentifierInfo *
Kind,
188 llvm::StringRef Str) {
198 llvm::StringRef
Name,
199 llvm::StringRef Value) {
208 llvm::StringRef DebugType) {
216 clang::SourceLocation
Loc, llvm::StringRef Namespace,
217 clang::PPCallbacks::PragmaMessageKind
Kind, llvm::StringRef Str) {
228 llvm::StringRef Namespace) {
237 llvm::StringRef Namespace) {
245 llvm::StringRef Namespace,
246 clang::diag::Severity Mapping,
247 llvm::StringRef Str) {
258 clang::SourceLocation NameLoc,
const clang::IdentifierInfo *
Name,
259 clang::SourceLocation StateLoc,
unsigned State) {
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) {
305 const clang::MacroDefinition &MacroDefinition,
306 clang::SourceRange
Range,
307 const clang::MacroArgs *Args) {
318 const clang::MacroDirective *MacroDirective) {
326 const clang::Token &MacroNameTok,
327 const clang::MacroDefinition &MacroDefinition) {
335 const clang::MacroDefinition &MacroDefinition,
336 clang::SourceRange
Range) {
351 clang::SourceRange ConditionRange,
361 clang::SourceRange ConditionRange,
363 clang::SourceLocation IfLoc) {
373 const clang::Token &MacroNameTok,
374 const clang::MacroDefinition &MacroDefinition) {
383 const clang::Token &MacroNameTok,
384 const clang::MacroDefinition &MacroDefinition) {
393 clang::SourceLocation IfLoc) {
401 clang::SourceLocation IfLoc) {
425 llvm::raw_string_ostream SS(Str);
439 llvm::StringRef Value) {
445 const std::string &Value) {
451 const clang::Token &Value) {
463 if (Value.isInvalid()) {
467 const clang::FileEntry *FileEntry =
468 PP.getSourceManager().getFileEntryForID(Value);
478 const clang::FileEntry *Value) {
488 clang::SourceLocation Value) {
489 if (Value.isInvalid()) {
498 clang::SourceRange Value) {
501 if (Value.isInvalid()) {
506 llvm::raw_string_ostream SS(Str);
514 clang::CharSourceRange Value) {
515 if (Value.isInvalid()) {
524 clang::ModuleIdPath Value) {
528 llvm::raw_string_ostream SS(Str);
530 for (
int I = 0, E = Value.size(); I != E; ++I) {
534 <<
"Name: " << Value[I].first->getName() <<
", "
543 const clang::IdentifierInfo *Value) {
553 const clang::MacroDirective *Value) {
563 const clang::MacroDefinition &Value) {
565 llvm::raw_string_ostream SS(Str);
568 if (Value.getLocalDirective()) {
572 for (
auto *MM : Value.getModuleMacros()) {
574 SS << MM->getOwningModule()->getFullModuleName();
582 const clang::MacroArgs *Value) {
588 llvm::raw_string_ostream SS(Str);
592 for (
int I = 0, E = Value->getNumArguments(); I < E; ++I) {
593 const clang::Token *Current = Value->getUnexpArgument(I);
594 int TokenCount = Value->getArgLength(Current) + 1;
601 for (
int TokenIndex = 0; TokenIndex < TokenCount; ++TokenIndex, ++Current) {
607 if (Current->isAnyIdentifier() ||
608 Current->is(clang::tok::numeric_constant)) {
609 SS <<
PP.getSpelling(*Current);
611 SS <<
"<" << Current->getName() <<
">";
621 const clang::Module *Value) {
631 const std::string &Value) {
633 llvm::raw_string_ostream SS(Str);
634 SS <<
"\"" << Value <<
"\"";
640 llvm::StringRef Value) {
641 std::string
Path(Value);
643 std::replace(Path.begin(), Path.end(),
'\\',
'/');
650 const char *B =
PP.getSourceManager().getCharacterData(Range.getBegin());
651 const char *E =
PP.getSourceManager().getCharacterData(Range.getEnd());
652 return llvm::StringRef(B, E - B);
SourceLocation Loc
'#' location in the include directive
llvm::StringRef getSourceString(clang::CharSourceRange Range)
Get the raw source string of the range.
This class represents one callback function argument by name and value.
void beginCallback(const char *Name)
Start a new callback.
void PragmaDebug(clang::SourceLocation Loc, llvm::StringRef DebugType) override
void EndOfMainFile() override
void Ifndef(clang::SourceLocation Loc, const clang::Token &MacroNameTok, const clang::MacroDefinition &MD) override
void appendFilePathArgument(const char *Name, llvm::StringRef Value)
Append a double-quoted file path argument to the top trace item.
std::vector< CallbackCall > & CallbackCalls
Callback trace information.
void PragmaDiagnosticPop(clang::SourceLocation Loc, llvm::StringRef Namespace) override
void PragmaOpenCLExtension(clang::SourceLocation NameLoc, const clang::IdentifierInfo *Name, clang::SourceLocation StateLoc, unsigned State) override
void PragmaDetectMismatch(clang::SourceLocation Loc, llvm::StringRef Name, llvm::StringRef Value) override
void FileChanged(clang::SourceLocation Loc, clang::PPCallbacks::FileChangeReason Reason, clang::SrcMgr::CharacteristicKind FileType, clang::FileID PrevFID=clang::FileID()) override
static const char *const PragmaMessageKindStrings[]
void Else(clang::SourceLocation Loc, clang::SourceLocation IfLoc) override
void MacroExpands(const clang::Token &MacroNameTok, const clang::MacroDefinition &MD, clang::SourceRange Range, const clang::MacroArgs *Args) override
std::vector< HeaderHandle > Path
void appendQuotedArgument(const char *Name, const std::string &Value)
Append a double-quoted argument to the top trace item.
static const char *const FileChangeReasonStrings[]
void FileSkipped(const clang::FileEntry &SkippedFile, const clang::Token &FilenameTok, clang::SrcMgr::CharacteristicKind FileType) override
void SourceRangeSkipped(clang::SourceRange Range) override
llvm::SmallSet< std::string, 4 > & Ignore
Names of callbacks to ignore.
static const char *const MacroDirectiveKindStrings[]
~PPCallbacksTracker() override
PPCallbacksTracker(llvm::SmallSet< std::string, 4 > &Ignore, std::vector< CallbackCall > &CallbackCalls, clang::Preprocessor &PP)
Note that all of the arguments are references, and owned by the caller.
void PragmaMessage(clang::SourceLocation Loc, llvm::StringRef Namespace, clang::PPCallbacks::PragmaMessageKind Kind, llvm::StringRef Str) override
void MacroDefined(const clang::Token &MacroNameTok, const clang::MacroDirective *MD) override
void InclusionDirective(clang::SourceLocation HashLoc, const clang::Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, clang::CharSourceRange FilenameRange, const clang::FileEntry *File, llvm::StringRef SearchPath, llvm::StringRef RelativePath, const clang::Module *Imported) override
void PragmaWarningPush(clang::SourceLocation Loc, int Level) override
void moduleImport(clang::SourceLocation ImportLoc, clang::ModuleIdPath Path, const clang::Module *Imported) override
bool IsAngled
true if this was an include with angle brackets
static const char *const PragmaIntroducerKindStrings[]
void Defined(const clang::Token &MacroNameTok, const clang::MacroDefinition &MD, clang::SourceRange Range) override
Classes and definitions for preprocessor tracking.
This class represents one callback call by name and an array of arguments.
void PragmaComment(clang::SourceLocation Loc, const clang::IdentifierInfo *Kind, llvm::StringRef Str) override
void If(clang::SourceLocation Loc, clang::SourceRange ConditionRange, ConditionValueKind ConditionValue) override
bool FileNotFound(llvm::StringRef FileName, llvm::SmallVectorImpl< char > &RecoveryPath) override
clang::PPCallbacks::ConditionValueKind ConditionValue
void PragmaWarningPop(clang::SourceLocation Loc) override
void PragmaDiagnostic(clang::SourceLocation Loc, llvm::StringRef Namespace, clang::diag::Severity mapping, llvm::StringRef Str) override
static const char *const ConditionValueKindStrings[]
void Elif(clang::SourceLocation Loc, clang::SourceRange ConditionRange, ConditionValueKind ConditionValue, clang::SourceLocation IfLoc) override
CharSourceRange Range
SourceRange for the file name.
void Endif(clang::SourceLocation Loc, clang::SourceLocation IfLoc) override
void PragmaDirective(clang::SourceLocation Loc, clang::PragmaIntroducerKind Introducer) override
void Ifdef(clang::SourceLocation Loc, const clang::Token &MacroNameTok, const clang::MacroDefinition &MD) override
void appendArgument(const char *Name, bool Value)
Append a bool argument to the top trace item.
bool DisableTrace
Inhibit trace while this is set.
static const char *const MappingStrings[]
void PragmaDiagnosticPush(clang::SourceLocation Loc, llvm::StringRef Namespace) override
void PragmaWarning(clang::SourceLocation Loc, llvm::StringRef WarningSpec, llvm::ArrayRef< int > Ids) override
void Ident(clang::SourceLocation Loc, llvm::StringRef str) override
void MacroUndefined(const clang::Token &MacroNameTok, const clang::MacroDefinition &MD) override
static const char *const CharacteristicKindStrings[]
static std::string getSourceLocationString(clang::Preprocessor &PP, clang::SourceLocation Loc)