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,
328 const clang::MacroDirective *Undef) {
336 const clang::MacroDefinition &MacroDefinition,
337 clang::SourceRange
Range) {
352 clang::SourceRange ConditionRange,
362 clang::SourceRange ConditionRange,
364 clang::SourceLocation IfLoc) {
374 const clang::Token &MacroNameTok,
375 const clang::MacroDefinition &MacroDefinition) {
384 const clang::Token &MacroNameTok,
385 const clang::MacroDefinition &MacroDefinition) {
394 clang::SourceLocation IfLoc) {
402 clang::SourceLocation IfLoc) {
426 llvm::raw_string_ostream SS(Str);
440 llvm::StringRef Value) {
446 const std::string &Value) {
452 const clang::Token &Value) {
464 if (Value.isInvalid()) {
468 const clang::FileEntry *FileEntry =
469 PP.getSourceManager().getFileEntryForID(Value);
479 const clang::FileEntry *Value) {
489 clang::SourceLocation Value) {
490 if (Value.isInvalid()) {
499 clang::SourceRange Value) {
502 if (Value.isInvalid()) {
507 llvm::raw_string_ostream SS(Str);
515 clang::CharSourceRange Value) {
516 if (Value.isInvalid()) {
525 clang::ModuleIdPath Value) {
529 llvm::raw_string_ostream SS(Str);
531 for (
int I = 0, E = Value.size(); I != E; ++I) {
535 <<
"Name: " << Value[I].first->getName() <<
", "
544 const clang::IdentifierInfo *Value) {
554 const clang::MacroDirective *Value) {
564 const clang::MacroDefinition &Value) {
566 llvm::raw_string_ostream SS(Str);
569 if (Value.getLocalDirective()) {
573 for (
auto *MM : Value.getModuleMacros()) {
575 SS << MM->getOwningModule()->getFullModuleName();
583 const clang::MacroArgs *Value) {
589 llvm::raw_string_ostream SS(Str);
594 for (
unsigned I = 0; I < Value->getNumMacroArguments(); ++I) {
595 const clang::Token *Current = Value->getUnexpArgument(I);
599 while (Current->isNot(clang::tok::eof)) {
605 if (Current->isAnyIdentifier() ||
606 Current->is(clang::tok::numeric_constant)) {
607 SS <<
PP.getSpelling(*Current);
609 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 MacroUndefined(const clang::Token &MacroNameTok, const clang::MacroDefinition &MD, const clang::MacroDirective *Undef) 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
static const char *const CharacteristicKindStrings[]
static std::string getSourceLocationString(clang::Preprocessor &PP, clang::SourceLocation Loc)