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,
140 clang::CharSourceRange FilenameRange,
const clang::FileEntry *
File,
141 llvm::StringRef SearchPath, llvm::StringRef RelativePath,
142 const clang::Module *Imported, clang::SrcMgr::CharacteristicKind FileType) {
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) {
346 clang::SourceLocation EndifLoc) {
348 appendArgument(
"Range", clang::SourceRange(Range.getBegin(), EndifLoc));
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);
595 for (
unsigned I = 0; I < Value->getNumMacroArguments(); ++I) {
596 const clang::Token *Current = Value->getUnexpArgument(I);
600 while (Current->isNot(clang::tok::eof)) {
606 if (Current->isAnyIdentifier() ||
607 Current->is(clang::tok::numeric_constant)) {
608 SS <<
PP.getSpelling(*Current);
610 SS <<
"<" << Current->getName() <<
">";
622 const clang::Module *Value) {
632 const std::string &Value) {
634 llvm::raw_string_ostream SS(Str);
635 SS <<
"\"" << Value <<
"\"";
641 llvm::StringRef Value) {
642 std::string
Path(Value);
644 std::replace(Path.begin(), Path.end(),
'\\',
'/');
651 const char *B =
PP.getSourceManager().getCharacterData(Range.getBegin());
652 const char *E =
PP.getSourceManager().getCharacterData(Range.getEnd());
653 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
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 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.
static constexpr llvm::StringLiteral Name
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
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
std::vector< llvm::StringRef > Strings
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
void SourceRangeSkipped(clang::SourceRange Range, clang::SourceLocation EndifLoc) override
CharSourceRange Range
SourceRange for the file name.
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, clang::SrcMgr::CharacteristicKind FileType) override
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)