18 #include "clang/Lex/MacroArgs.h"
19 #include "llvm/Support/raw_ostream.h"
27 clang::SourceLocation
Loc) {
29 return std::string(
"(none)");
32 clang::PresumedLoc PLoc = PP.getSourceManager().getPresumedLoc(Loc);
34 if (PLoc.isInvalid()) {
35 return std::string(
"(invalid)");
39 llvm::raw_string_ostream SS(Str);
42 SS <<
"\"" << PLoc.getFilename() <<
':' << PLoc.getLine() <<
':'
43 << PLoc.getColumn() <<
"\"";
45 std::string
Result = SS.str();
48 std::replace(Result.begin(), Result.end(),
'\\',
'/');
53 return std::string(
"(nonfile)");
60 "EnterFile",
"ExitFile",
"SystemHeaderPragma",
"RenameFile"
69 "MD_Define",
"MD_Undefine",
"MD_Visibility"
79 "PMK_Message",
"PMK_Warning",
"PMK_Error"
84 "CVK_NotEvaluated",
"CVK_False",
"CVK_True"
89 "MAP_REMARK",
"MAP_WARNING",
90 "MAP_ERROR",
"MAP_FATAL" };
95 std::vector<CallbackCall> &CallbackCalls,
96 clang::Preprocessor &
PP)
97 : CallbackCalls(CallbackCalls), Ignore(Ignore), PP(PP) {}
105 clang::SourceLocation
Loc, clang::PPCallbacks::FileChangeReason Reason,
106 clang::SrcMgr::CharacteristicKind FileType, clang::FileID PrevFID) {
118 const clang::Token &FilenameTok,
119 clang::SrcMgr::CharacteristicKind FileType) {
130 llvm::SmallVectorImpl<char> &RecoveryPath) {
140 clang::SourceLocation HashLoc,
const clang::Token &IncludeTok,
141 llvm::StringRef FileName,
bool IsAngled,
142 clang::CharSourceRange FilenameRange,
const clang::FileEntry *
File,
143 llvm::StringRef SearchPath, llvm::StringRef RelativePath,
144 const clang::Module *Imported) {
159 clang::ModuleIdPath
Path,
160 const clang::Module *Imported) {
181 clang::PragmaIntroducerKind Introducer) {
189 const clang::IdentifierInfo *Kind,
190 llvm::StringRef Str) {
200 llvm::StringRef
Name,
201 llvm::StringRef Value) {
210 llvm::StringRef DebugType) {
218 clang::SourceLocation
Loc, llvm::StringRef Namespace,
219 clang::PPCallbacks::PragmaMessageKind Kind, llvm::StringRef Str) {
230 llvm::StringRef Namespace) {
239 llvm::StringRef Namespace) {
247 llvm::StringRef Namespace,
248 clang::diag::Severity Mapping,
249 llvm::StringRef Str) {
260 clang::SourceLocation NameLoc,
const clang::IdentifierInfo *
Name,
261 clang::SourceLocation StateLoc,
unsigned State) {
271 llvm::StringRef WarningSpec,
272 llvm::ArrayRef<int> Ids) {
278 llvm::raw_string_ostream SS(Str);
280 for (
int i = 0, e = Ids.size(); i != e; ++i) {
307 const clang::MacroDefinition &MacroDefinition,
308 clang::SourceRange
Range,
309 const clang::MacroArgs *Args) {
320 const clang::MacroDirective *MacroDirective) {
328 const clang::Token &MacroNameTok,
329 const clang::MacroDefinition &MacroDefinition) {
337 const clang::MacroDefinition &MacroDefinition,
338 clang::SourceRange
Range) {
353 clang::SourceRange ConditionRange,
363 clang::SourceRange ConditionRange,
365 clang::SourceLocation IfLoc) {
375 const clang::Token &MacroNameTok,
376 const clang::MacroDefinition &MacroDefinition) {
385 const clang::Token &MacroNameTok,
386 const clang::MacroDefinition &MacroDefinition) {
395 clang::SourceLocation IfLoc) {
403 clang::SourceLocation IfLoc) {
427 llvm::raw_string_ostream SS(Str);
441 llvm::StringRef Value) {
447 const std::string &Value) {
453 const clang::Token &Value) {
465 if (Value.isInvalid()) {
469 const clang::FileEntry *FileEntry =
470 PP.getSourceManager().getFileEntryForID(Value);
480 const clang::FileEntry *Value) {
490 clang::SourceLocation Value) {
491 if (Value.isInvalid()) {
500 clang::SourceRange Value) {
503 if (Value.isInvalid()) {
508 llvm::raw_string_ostream SS(Str);
516 clang::CharSourceRange Value) {
517 if (Value.isInvalid()) {
526 clang::ModuleIdPath Value) {
530 llvm::raw_string_ostream SS(Str);
532 for (
int I = 0, E = Value.size(); I != E; ++I) {
536 <<
"Name: " << Value[I].first->getName() <<
", "
545 const clang::IdentifierInfo *Value) {
555 const clang::MacroDirective *Value) {
565 const clang::MacroDefinition &Value) {
567 llvm::raw_string_ostream SS(Str);
570 if (Value.getLocalDirective()) {
574 for (
auto *MM : Value.getModuleMacros()) {
576 SS << MM->getOwningModule()->getFullModuleName();
584 const clang::MacroArgs *Value) {
590 llvm::raw_string_ostream SS(Str);
594 for (
int I = 0, E = Value->getNumArguments(); I < E; ++I) {
595 const clang::Token *Current = Value->getUnexpArgument(I);
596 int TokenCount = Value->getArgLength(Current) + 1;
603 for (
int TokenIndex = 0; TokenIndex < TokenCount; ++TokenIndex, ++Current) {
609 if (Current->isAnyIdentifier() ||
610 Current->is(clang::tok::numeric_constant)) {
611 SS <<
PP.getSpelling(*Current);
613 SS <<
"<" << Current->getName() <<
">";
623 const clang::Module *Value) {
633 const std::string &Value) {
635 llvm::raw_string_ostream SS(Str);
636 SS <<
"\"" << Value <<
"\"";
642 llvm::StringRef Value) {
643 std::string
Path(Value);
645 std::replace(Path.begin(), Path.end(),
'\\',
'/');
652 const char *B =
PP.getSourceManager().getCharacterData(Range.getBegin());
653 const char *E =
PP.getSourceManager().getCharacterData(Range.getEnd());
654 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)