Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
Show First 20 Lines • Show All 161 Lines • ▼ Show 20 Lines | |||||
// Callback invoked when the end of the main file is reached. | // Callback invoked when the end of the main file is reached. | ||||
// No subsequent callbacks will be made. | // No subsequent callbacks will be made. | ||||
void PPCallbacksTracker::EndOfMainFile() { beginCallback("EndOfMainFile"); } | void PPCallbacksTracker::EndOfMainFile() { beginCallback("EndOfMainFile"); } | ||||
// Callback invoked when a #ident or #sccs directive is read. | // Callback invoked when a #ident or #sccs directive is read. | ||||
void PPCallbacksTracker::Ident(SourceLocation HashLoc, SourceLocation Loc, | void PPCallbacksTracker::Ident(SourceLocation HashLoc, SourceLocation Loc, | ||||
llvm::StringRef Str) { | llvm::StringRef Str) { | ||||
beginCallback("Ident"); | beginCallback("Ident"); | ||||
appendArgument("HashLoc", HashLoc); | |||||
appendArgument("Loc", Loc); | appendArgument("Loc", Loc); | ||||
appendArgument("Str", Str); | appendArgument("Str", Str); | ||||
} | } | ||||
// Callback invoked when start reading any pragma directive. | // Callback invoked when start reading any pragma directive. | ||||
void PPCallbacksTracker::PragmaDirective(PragmaIntroducer Introducer) { | void PPCallbacksTracker::PragmaDirective(PragmaIntroducer Introducer) { | ||||
beginCallback("PragmaDirective"); | beginCallback("PragmaDirective"); | ||||
appendArgument("Introducer", Introducer); | appendArgument("Introducer", Introducer); | ||||
} | } | ||||
// Callback invoked when a #pragma comment directive is read. | // Callback invoked when a #pragma comment directive is read. | ||||
void PPCallbacksTracker::PragmaComment(PragmaIntroducer Introducer, | void PPCallbacksTracker::PragmaComment(PragmaIntroducer Introducer, | ||||
SourceLocation Loc, | SourceLocation Loc, | ||||
const IdentifierInfo *Kind, | const IdentifierInfo *Kind, | ||||
llvm::StringRef Str) { | llvm::StringRef Str) { | ||||
beginCallback("PragmaComment"); | beginCallback("PragmaComment"); | ||||
appendArgument("Introducer", Introducer); | |||||
appendArgument("Loc", Loc); | appendArgument("Loc", Loc); | ||||
appendArgument("Kind", Kind); | appendArgument("Kind", Kind); | ||||
appendArgument("Str", Str); | appendArgument("Str", Str); | ||||
} | } | ||||
// Callback invoked when a #pragma detect_mismatch directive is | // Callback invoked when a #pragma detect_mismatch directive is | ||||
// read. | // read. | ||||
void PPCallbacksTracker::PragmaDetectMismatch(PragmaIntroducer Introducer, | void PPCallbacksTracker::PragmaDetectMismatch(PragmaIntroducer Introducer, | ||||
SourceLocation Loc, | SourceLocation Loc, | ||||
llvm::StringRef Name, | llvm::StringRef Name, | ||||
llvm::StringRef Value) { | llvm::StringRef Value) { | ||||
beginCallback("PragmaDetectMismatch"); | beginCallback("PragmaDetectMismatch"); | ||||
appendArgument("Introducer", Introducer); | |||||
appendArgument("Loc", Loc); | appendArgument("Loc", Loc); | ||||
appendArgument("Name", Name); | appendArgument("Name", Name); | ||||
appendArgument("Value", Value); | appendArgument("Value", Value); | ||||
} | } | ||||
// Callback invoked when a #pragma clang __debug directive is read. | // Callback invoked when a #pragma clang __debug directive is read. | ||||
void PPCallbacksTracker::PragmaDebug(PragmaIntroducer Introducer, | void PPCallbacksTracker::PragmaDebug(PragmaIntroducer Introducer, | ||||
SourceLocation Loc, | SourceLocation Loc, | ||||
llvm::StringRef DebugType) { | llvm::StringRef DebugType) { | ||||
beginCallback("PragmaDebug"); | beginCallback("PragmaDebug"); | ||||
appendArgument("Introducer", Introducer); | |||||
appendArgument("Loc", Loc); | appendArgument("Loc", Loc); | ||||
appendArgument("DebugType", DebugType); | appendArgument("DebugType", DebugType); | ||||
} | } | ||||
// Callback invoked when a #pragma message directive is read. | // Callback invoked when a #pragma message directive is read. | ||||
void PPCallbacksTracker::PragmaMessage(PragmaIntroducer Introducer, | void PPCallbacksTracker::PragmaMessage(PragmaIntroducer Introducer, | ||||
SourceLocation Loc, | SourceLocation Loc, | ||||
llvm::StringRef Namespace, | llvm::StringRef Namespace, | ||||
PPCallbacks::PragmaMessageKind Kind, | PPCallbacks::PragmaMessageKind Kind, | ||||
llvm::StringRef Str) { | llvm::StringRef Str) { | ||||
beginCallback("PragmaMessage"); | beginCallback("PragmaMessage"); | ||||
appendArgument("Introducer", Introducer); | |||||
appendArgument("Loc", Loc); | appendArgument("Loc", Loc); | ||||
appendArgument("Namespace", Namespace); | appendArgument("Namespace", Namespace); | ||||
appendArgument("Kind", Kind, PragmaMessageKindStrings); | appendArgument("Kind", Kind, PragmaMessageKindStrings); | ||||
appendArgument("Str", Str); | appendArgument("Str", Str); | ||||
} | } | ||||
// Callback invoked when a #pragma gcc diagnostic push directive | // Callback invoked when a #pragma gcc diagnostic push directive | ||||
// is read. | // is read. | ||||
void PPCallbacksTracker::PragmaDiagnosticPush(PragmaIntroducer Introducer, | void PPCallbacksTracker::PragmaDiagnosticPush(PragmaIntroducer Introducer, | ||||
SourceLocation Loc, | SourceLocation Loc, | ||||
llvm::StringRef Namespace) { | llvm::StringRef Namespace) { | ||||
beginCallback("PragmaDiagnosticPush"); | beginCallback("PragmaDiagnosticPush"); | ||||
appendArgument("Introducer", Introducer); | |||||
appendArgument("Loc", Loc); | appendArgument("Loc", Loc); | ||||
appendArgument("Namespace", Namespace); | appendArgument("Namespace", Namespace); | ||||
} | } | ||||
// Callback invoked when a #pragma gcc diagnostic pop directive | // Callback invoked when a #pragma gcc diagnostic pop directive | ||||
// is read. | // is read. | ||||
void PPCallbacksTracker::PragmaDiagnosticPop(PragmaIntroducer Introducer, | void PPCallbacksTracker::PragmaDiagnosticPop(PragmaIntroducer Introducer, | ||||
SourceLocation Loc, | SourceLocation Loc, | ||||
llvm::StringRef Namespace) { | llvm::StringRef Namespace) { | ||||
beginCallback("PragmaDiagnosticPop"); | beginCallback("PragmaDiagnosticPop"); | ||||
appendArgument("Introducer", Introducer); | |||||
appendArgument("Loc", Loc); | appendArgument("Loc", Loc); | ||||
appendArgument("Namespace", Namespace); | appendArgument("Namespace", Namespace); | ||||
} | } | ||||
// Callback invoked when a #pragma gcc diagnostic directive is read. | // Callback invoked when a #pragma gcc diagnostic directive is read. | ||||
void PPCallbacksTracker::PragmaDiagnostic(PragmaIntroducer Introducer, | void PPCallbacksTracker::PragmaDiagnostic(PragmaIntroducer Introducer, | ||||
SourceLocation Loc, | SourceLocation Loc, | ||||
llvm::StringRef Namespace, | llvm::StringRef Namespace, | ||||
diag::Severity Mapping, | diag::Severity Mapping, | ||||
llvm::StringRef Str) { | llvm::StringRef Str) { | ||||
beginCallback("PragmaDiagnostic"); | beginCallback("PragmaDiagnostic"); | ||||
appendArgument("Introducer", Introducer); | |||||
appendArgument("Loc", Loc); | appendArgument("Loc", Loc); | ||||
appendArgument("Namespace", Namespace); | appendArgument("Namespace", Namespace); | ||||
appendArgument("Mapping", (unsigned)Mapping, MappingStrings); | appendArgument("Mapping", (unsigned)Mapping, MappingStrings); | ||||
appendArgument("Str", Str); | appendArgument("Str", Str); | ||||
} | } | ||||
// Called when an OpenCL extension is either disabled or | // Called when an OpenCL extension is either disabled or | ||||
// enabled with a pragma. | // enabled with a pragma. | ||||
void PPCallbacksTracker::PragmaOpenCLExtension(PragmaIntroducer Introducer, | void PPCallbacksTracker::PragmaOpenCLExtension(PragmaIntroducer Introducer, | ||||
SourceLocation NameLoc, | SourceLocation NameLoc, | ||||
const IdentifierInfo *Name, | const IdentifierInfo *Name, | ||||
SourceLocation StateLoc, | SourceLocation StateLoc, | ||||
unsigned State) { | unsigned State) { | ||||
beginCallback("PragmaOpenCLExtension"); | beginCallback("PragmaOpenCLExtension"); | ||||
appendArgument("Introducer", Introducer); | |||||
appendArgument("NameLoc", NameLoc); | appendArgument("NameLoc", NameLoc); | ||||
appendArgument("Name", Name); | appendArgument("Name", Name); | ||||
appendArgument("StateLoc", StateLoc); | appendArgument("StateLoc", StateLoc); | ||||
appendArgument("State", (int)State); | appendArgument("State", (int)State); | ||||
} | } | ||||
// Callback invoked when a #pragma warning directive is read. | // Callback invoked when a #pragma warning directive is read. | ||||
void PPCallbacksTracker::PragmaWarning(PragmaIntroducer Introducer, | void PPCallbacksTracker::PragmaWarning(PragmaIntroducer Introducer, | ||||
SourceLocation Loc, | SourceLocation Loc, | ||||
PragmaWarningSpecifier WarningSpec, | PragmaWarningSpecifier WarningSpec, | ||||
llvm::ArrayRef<int> Ids) { | llvm::ArrayRef<int> Ids) { | ||||
beginCallback("PragmaWarning"); | beginCallback("PragmaWarning"); | ||||
appendArgument("Introducer", Introducer); | |||||
appendArgument("Loc", Loc); | appendArgument("Loc", Loc); | ||||
appendArgument("WarningSpec", WarningSpec, PragmaWarningSpecifierStrings); | appendArgument("WarningSpec", WarningSpec, PragmaWarningSpecifierStrings); | ||||
std::string Str; | std::string Str; | ||||
llvm::raw_string_ostream SS(Str); | llvm::raw_string_ostream SS(Str); | ||||
SS << "["; | SS << "["; | ||||
for (int i = 0, e = Ids.size(); i != e; ++i) { | for (int i = 0, e = Ids.size(); i != e; ++i) { | ||||
if (i) | if (i) | ||||
SS << ", "; | SS << ", "; | ||||
SS << Ids[i]; | SS << Ids[i]; | ||||
} | } | ||||
SS << "]"; | SS << "]"; | ||||
appendArgument("Ids", SS.str()); | appendArgument("Ids", SS.str()); | ||||
} | } | ||||
// Callback invoked when a #pragma warning(push) directive is read. | // Callback invoked when a #pragma warning(push) directive is read. | ||||
void PPCallbacksTracker::PragmaWarningPush(PragmaIntroducer Introducer, | void PPCallbacksTracker::PragmaWarningPush(PragmaIntroducer Introducer, | ||||
SourceLocation Loc, int Level) { | SourceLocation Loc, int Level) { | ||||
beginCallback("PragmaWarningPush"); | beginCallback("PragmaWarningPush"); | ||||
appendArgument("Introducer", Introducer); | |||||
appendArgument("Loc", Loc); | appendArgument("Loc", Loc); | ||||
appendArgument("Level", Level); | appendArgument("Level", Level); | ||||
} | } | ||||
// Callback invoked when a #pragma warning(pop) directive is read. | // Callback invoked when a #pragma warning(pop) directive is read. | ||||
void PPCallbacksTracker::PragmaWarningPop(PragmaIntroducer Introducer, | void PPCallbacksTracker::PragmaWarningPop(PragmaIntroducer Introducer, | ||||
SourceLocation Loc) { | SourceLocation Loc) { | ||||
beginCallback("PragmaWarningPop"); | beginCallback("PragmaWarningPop"); | ||||
appendArgument("Introducer", Introducer); | |||||
appendArgument("Loc", Loc); | appendArgument("Loc", Loc); | ||||
} | } | ||||
// Callback invoked when a #pragma execution_character_set(push) directive | // Callback invoked when a #pragma execution_character_set(push) directive | ||||
// is read. | // is read. | ||||
void PPCallbacksTracker::PragmaExecCharsetPush(PragmaIntroducer Introducer, | void PPCallbacksTracker::PragmaExecCharsetPush(PragmaIntroducer Introducer, | ||||
SourceLocation Loc, | SourceLocation Loc, | ||||
StringRef Str) { | StringRef Str) { | ||||
beginCallback("PragmaExecCharsetPush"); | beginCallback("PragmaExecCharsetPush"); | ||||
appendArgument("Introducer", Introducer); | |||||
appendArgument("Loc", Loc); | appendArgument("Loc", Loc); | ||||
appendArgument("Charset", Str); | appendArgument("Charset", Str); | ||||
} | } | ||||
// Callback invoked when a #pragma execution_character_set(pop) directive | // Callback invoked when a #pragma execution_character_set(pop) directive | ||||
// is read. | // is read. | ||||
void PPCallbacksTracker::PragmaExecCharsetPop(PragmaIntroducer Introducer, | void PPCallbacksTracker::PragmaExecCharsetPop(PragmaIntroducer Introducer, | ||||
SourceLocation Loc) { | SourceLocation Loc) { | ||||
beginCallback("PragmaExecCharsetPop"); | beginCallback("PragmaExecCharsetPop"); | ||||
appendArgument("Introducer", Introducer); | |||||
appendArgument("Loc", Loc); | appendArgument("Loc", Loc); | ||||
} | } | ||||
// Called by Preprocessor::HandleMacroExpandedIdentifier when a | // Called by Preprocessor::HandleMacroExpandedIdentifier when a | ||||
// macro invocation is found. | // macro invocation is found. | ||||
void PPCallbacksTracker::MacroExpands(const Token &MacroNameTok, | void PPCallbacksTracker::MacroExpands(const Token &MacroNameTok, | ||||
const MacroDefinition &MacroDefinition, | const MacroDefinition &MacroDefinition, | ||||
SourceRange Range, | SourceRange Range, | ||||
const MacroArgs *Args) { | const MacroArgs *Args) { | ||||
beginCallback("MacroExpands"); | beginCallback("MacroExpands"); | ||||
appendArgument("MacroNameTok", MacroNameTok); | appendArgument("MacroNameTok", MacroNameTok); | ||||
appendArgument("MacroDefinition", MacroDefinition); | appendArgument("MacroDefinition", MacroDefinition); | ||||
appendArgument("Range", Range); | appendArgument("Range", Range); | ||||
appendArgument("Args", Args); | appendArgument("Args", Args); | ||||
} | } | ||||
// Hook called whenever a macro definition is seen. | // Hook called whenever a macro definition is seen. | ||||
void PPCallbacksTracker::MacroDefined(SourceLocation HashLoc, | void PPCallbacksTracker::MacroDefined(SourceLocation HashLoc, | ||||
const Token &MacroNameTok, | const Token &MacroNameTok, | ||||
const MacroDirective *MacroDirective) { | const MacroDirective *MacroDirective) { | ||||
beginCallback("MacroDefined"); | beginCallback("MacroDefined"); | ||||
appendArgument("HashLoc", HashLoc); | |||||
appendArgument("MacroNameTok", MacroNameTok); | appendArgument("MacroNameTok", MacroNameTok); | ||||
appendArgument("MacroDirective", MacroDirective); | appendArgument("MacroDirective", MacroDirective); | ||||
} | } | ||||
// Hook called whenever a macro #undef is seen. | // Hook called whenever a macro #undef is seen. | ||||
void PPCallbacksTracker::MacroUndefined(SourceLocation HashLoc, | void PPCallbacksTracker::MacroUndefined(SourceLocation HashLoc, | ||||
const Token &MacroNameTok, | const Token &MacroNameTok, | ||||
const MacroDefinition &MacroDefinition, | const MacroDefinition &MacroDefinition, | ||||
const MacroDirective *Undef) { | const MacroDirective *Undef) { | ||||
beginCallback("MacroUndefined"); | beginCallback("MacroUndefined"); | ||||
appendArgument("HashLoc", HashLoc); | |||||
appendArgument("MacroNameTok", MacroNameTok); | appendArgument("MacroNameTok", MacroNameTok); | ||||
appendArgument("MacroDefinition", MacroDefinition); | appendArgument("MacroDefinition", MacroDefinition); | ||||
} | } | ||||
// Hook called whenever the 'defined' operator is seen. | // Hook called whenever the 'defined' operator is seen. | ||||
void PPCallbacksTracker::Defined(const Token &MacroNameTok, | void PPCallbacksTracker::Defined(const Token &MacroNameTok, | ||||
const MacroDefinition &MacroDefinition, | const MacroDefinition &MacroDefinition, | ||||
SourceRange Range) { | SourceRange Range) { | ||||
Show All 10 Lines | void PPCallbacksTracker::SourceRangeSkipped(SourceRange Range, | ||||
appendArgument("Range", SourceRange(Range.getBegin(), EndifLoc)); | appendArgument("Range", SourceRange(Range.getBegin(), EndifLoc)); | ||||
} | } | ||||
// Hook called whenever an #if is seen. | // Hook called whenever an #if is seen. | ||||
void PPCallbacksTracker::If(SourceLocation HashLoc, SourceLocation Loc, | void PPCallbacksTracker::If(SourceLocation HashLoc, SourceLocation Loc, | ||||
SourceRange ConditionRange, | SourceRange ConditionRange, | ||||
ConditionValueKind ConditionValue) { | ConditionValueKind ConditionValue) { | ||||
beginCallback("If"); | beginCallback("If"); | ||||
appendArgument("HashLoc", HashLoc); | |||||
appendArgument("Loc", Loc); | appendArgument("Loc", Loc); | ||||
appendArgument("ConditionRange", ConditionRange); | appendArgument("ConditionRange", ConditionRange); | ||||
appendArgument("ConditionValue", ConditionValue, ConditionValueKindStrings); | appendArgument("ConditionValue", ConditionValue, ConditionValueKindStrings); | ||||
} | } | ||||
// Hook called whenever an #elif is seen. | // Hook called whenever an #elif is seen. | ||||
void PPCallbacksTracker::Elif(SourceLocation HashLoc, SourceLocation Loc, | void PPCallbacksTracker::Elif(SourceLocation HashLoc, SourceLocation Loc, | ||||
SourceRange ConditionRange, | SourceRange ConditionRange, | ||||
ConditionValueKind ConditionValue, | ConditionValueKind ConditionValue, | ||||
SourceLocation IfLoc) { | SourceLocation IfLoc) { | ||||
beginCallback("Elif"); | beginCallback("Elif"); | ||||
appendArgument("HashLoc", HashLoc); | |||||
appendArgument("Loc", Loc); | appendArgument("Loc", Loc); | ||||
appendArgument("ConditionRange", ConditionRange); | appendArgument("ConditionRange", ConditionRange); | ||||
appendArgument("ConditionValue", ConditionValue, ConditionValueKindStrings); | appendArgument("ConditionValue", ConditionValue, ConditionValueKindStrings); | ||||
appendArgument("IfLoc", IfLoc); | appendArgument("IfLoc", IfLoc); | ||||
} | } | ||||
// Hook called whenever an #ifdef is seen. | // Hook called whenever an #ifdef is seen. | ||||
void PPCallbacksTracker::Ifdef(SourceLocation HashLoc, SourceLocation Loc, | void PPCallbacksTracker::Ifdef(SourceLocation HashLoc, SourceLocation Loc, | ||||
const Token &MacroNameTok, | const Token &MacroNameTok, | ||||
const MacroDefinition &MacroDefinition) { | const MacroDefinition &MacroDefinition) { | ||||
beginCallback("Ifdef"); | beginCallback("Ifdef"); | ||||
appendArgument("HashLoc", HashLoc); | |||||
appendArgument("Loc", Loc); | appendArgument("Loc", Loc); | ||||
appendArgument("MacroNameTok", MacroNameTok); | appendArgument("MacroNameTok", MacroNameTok); | ||||
appendArgument("MacroDefinition", MacroDefinition); | appendArgument("MacroDefinition", MacroDefinition); | ||||
} | } | ||||
// Hook called whenever an #ifndef is seen. | // Hook called whenever an #ifndef is seen. | ||||
void PPCallbacksTracker::Ifndef(SourceLocation HashLoc, SourceLocation Loc, | void PPCallbacksTracker::Ifndef(SourceLocation HashLoc, SourceLocation Loc, | ||||
const Token &MacroNameTok, | const Token &MacroNameTok, | ||||
const MacroDefinition &MacroDefinition) { | const MacroDefinition &MacroDefinition) { | ||||
beginCallback("Ifndef"); | beginCallback("Ifndef"); | ||||
appendArgument("HashLoc", HashLoc); | |||||
appendArgument("Loc", Loc); | appendArgument("Loc", Loc); | ||||
appendArgument("MacroNameTok", MacroNameTok); | appendArgument("MacroNameTok", MacroNameTok); | ||||
appendArgument("MacroDefinition", MacroDefinition); | appendArgument("MacroDefinition", MacroDefinition); | ||||
} | } | ||||
// Hook called whenever an #else is seen. | // Hook called whenever an #else is seen. | ||||
void PPCallbacksTracker::Else(SourceLocation HashLoc, SourceLocation Loc, | void PPCallbacksTracker::Else(SourceLocation HashLoc, SourceLocation Loc, | ||||
SourceLocation IfLoc) { | SourceLocation IfLoc) { | ||||
beginCallback("Else"); | beginCallback("Else"); | ||||
appendArgument("HashLoc", HashLoc); | |||||
appendArgument("Loc", Loc); | appendArgument("Loc", Loc); | ||||
appendArgument("IfLoc", IfLoc); | appendArgument("IfLoc", IfLoc); | ||||
} | } | ||||
// Hook called whenever an #endif is seen. | // Hook called whenever an #endif is seen. | ||||
void PPCallbacksTracker::Endif(SourceLocation HashLoc, SourceLocation Loc, | void PPCallbacksTracker::Endif(SourceLocation HashLoc, SourceLocation Loc, | ||||
SourceLocation IfLoc) { | SourceLocation IfLoc) { | ||||
beginCallback("Endif"); | beginCallback("Endif"); | ||||
appendArgument("HashLoc", HashLoc); | |||||
appendArgument("Loc", Loc); | appendArgument("Loc", Loc); | ||||
appendArgument("IfLoc", IfLoc); | appendArgument("IfLoc", IfLoc); | ||||
} | } | ||||
// Helper functions. | // Helper functions. | ||||
// Start a new callback. | // Start a new callback. | ||||
void PPCallbacksTracker::beginCallback(const char *Name) { | void PPCallbacksTracker::beginCallback(const char *Name) { | ||||
▲ Show 20 Lines • Show All 264 Lines • Show Last 20 Lines |