17#include "clang/Basic/FileManager.h"
18#include "clang/Lex/MacroArgs.h"
19#include "llvm/Support/raw_ostream.h"
28 return std::string(
"(none)");
31 PresumedLoc PLoc = PP.getSourceManager().getPresumedLoc(
Loc);
33 if (PLoc.isInvalid()) {
34 return std::string(
"(invalid)");
38 llvm::raw_string_ostream SS(Str);
41 SS <<
"\"" << PLoc.getFilename() <<
':' << PLoc.getLine() <<
':'
42 << PLoc.getColumn() <<
"\"";
44 std::string Result = SS.str();
47 std::replace(Result.begin(), Result.end(),
'\\',
'/');
52 return std::string(
"(nonfile)");
59 "EnterFile",
"ExitFile",
"SystemHeaderPragma",
"RenameFile"
68 "MD_Define",
"MD_Undefine",
"MD_Visibility"
78 "PMK_Message",
"PMK_Warning",
"PMK_Error"
83 "PWS_Default",
"PWS_Disable",
"PWS_Error",
"PWS_Once",
"PWS_Suppress",
84 "PWS_Level1",
"PWS_Level2",
"PWS_Level3",
"PWS_Level4",
89 "CVK_NotEvaluated",
"CVK_False",
"CVK_True"
94 "MAP_REMARK",
"MAP_WARNING",
95 "MAP_ERROR",
"MAP_FATAL" };
100 std::vector<CallbackCall> &CallbackCalls,
102 : CallbackCalls(CallbackCalls), Filters(Filters), PP(PP) {}
110 PPCallbacks::FileChangeReason Reason,
111 SrcMgr::CharacteristicKind FileType,
123 const Token &FilenameTok,
124 SrcMgr::CharacteristicKind FileType) {
135 SourceLocation HashLoc,
const Token &IncludeTok, llvm::StringRef
FileName,
136 bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
137 llvm::StringRef SearchPath, llvm::StringRef RelativePath,
138 const Module *SuggestedModule,
bool ModuleImported,
139 SrcMgr::CharacteristicKind FileType) {
157 const Module *Imported) {
177 PragmaIntroducerKind Introducer) {
185 const IdentifierInfo *
Kind,
186 llvm::StringRef Str) {
196 llvm::StringRef
Name,
197 llvm::StringRef Value) {
206 llvm::StringRef DebugType) {
214 llvm::StringRef Namespace,
215 PPCallbacks::PragmaMessageKind
Kind,
216 llvm::StringRef Str) {
227 llvm::StringRef Namespace) {
236 llvm::StringRef Namespace) {
244 llvm::StringRef Namespace,
245 diag::Severity Mapping,
246 llvm::StringRef Str) {
257 const IdentifierInfo *
Name,
258 SourceLocation StateLoc,
269 PragmaWarningSpecifier WarningSpec,
270 llvm::ArrayRef<int> Ids) {
276 llvm::raw_string_ostream SS(Str);
278 for (
int i = 0, e = Ids.size(); i != e; ++i) {
319 const MacroDefinition &MacroDefinition,
321 const MacroArgs *
Args) {
331 const MacroDirective *MacroDirective) {
339 const MacroDefinition &MacroDefinition,
340 const MacroDirective *Undef) {
348 const MacroDefinition &MacroDefinition,
358 SourceLocation EndifLoc) {
375 SourceLocation IfLoc) {
385 const MacroDefinition &MacroDefinition) {
394 const MacroDefinition &MacroDefinition) {
421 llvm::StringRef N(
Name);
422 for (
const std::pair<llvm::GlobPattern, bool> &Filter :
Filters)
423 if (Filter.first.match(N))
424 R.first->second = Filter.second;
440 llvm::raw_string_ostream SS(Str);
454 llvm::StringRef Value) {
460 const std::string &Value) {
477 if (Value.isInvalid()) {
481 OptionalFileEntryRef FileEntry =
482 PP.getSourceManager().getFileEntryRefForID(Value);
492 OptionalFileEntryRef Value) {
506 SourceLocation Value) {
507 if (Value.isInvalid()) {
518 if (Value.isInvalid()) {
523 llvm::raw_string_ostream SS(Str);
531 CharSourceRange Value) {
532 if (Value.isInvalid()) {
544 llvm::raw_string_ostream SS(Str);
546 for (
int I = 0,
E = Value.size(); I !=
E; ++I) {
550 <<
"Name: " << Value[I].first->getName() <<
", "
559 const IdentifierInfo *Value) {
569 const MacroDirective *Value) {
579 const MacroDefinition &Value) {
581 llvm::raw_string_ostream SS(Str);
584 if (Value.getLocalDirective()) {
588 for (
auto *MM : Value.getModuleMacros()) {
590 SS << MM->getOwningModule()->getFullModuleName();
598 const MacroArgs *Value) {
604 llvm::raw_string_ostream SS(Str);
609 for (
unsigned I = 0; I < Value->getNumMacroArguments(); ++I) {
610 const Token *Current = Value->getUnexpArgument(I);
614 while (Current->isNot(tok::eof)) {
620 if (Current->isAnyIdentifier() || Current->is(tok::numeric_constant)) {
621 SS <<
PP.getSpelling(*Current);
623 SS <<
"<" << Current->getName() <<
">";
644 const std::string &Value) {
646 llvm::raw_string_ostream SS(Str);
647 SS <<
"\"" << Value <<
"\"";
653 llvm::StringRef Value) {
654 std::string
Path(Value);
656 std::replace(
Path.begin(),
Path.end(),
'\\',
'/');
662 const char *B =
PP.getSourceManager().getCharacterData(
Range.getBegin());
663 const char *
E =
PP.getSourceManager().getCharacterData(
Range.getEnd());
664 return llvm::StringRef(B,
E - B);
llvm::SmallString< 256U > Name
CharSourceRange Range
SourceRange for the file name.
bool IsAngled
true if this was an include with angle brackets
Classes and definitions for preprocessor tracking.
std::vector< HeaderHandle > Path
clang::PPCallbacks::ConditionValueKind ConditionValue
std::vector< llvm::StringRef > Strings
This class represents one callback call by name and an array of arguments.
void beginCallback(const char *Name)
Start a new callback.
void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override
void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, llvm::StringRef Str) override
void FileSkipped(const FileEntryRef &SkippedFile, const Token &FilenameTok, SrcMgr::CharacteristicKind FileType) override
void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *Undef) override
void Ifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
void Elif(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue, SourceLocation IfLoc) override
void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD) override
void If(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue) override
void PragmaDiagnostic(SourceLocation Loc, llvm::StringRef Namespace, diag::Severity mapping, llvm::StringRef Str) override
void Ident(SourceLocation Loc, llvm::StringRef str) override
llvm::StringMap< bool > CallbackIsEnabled
void appendQuotedArgument(const char *Name, const std::string &Value)
Append a double-quoted argument to the top trace item.
void PragmaDirective(SourceLocation Loc, PragmaIntroducerKind Introducer) override
void PragmaDiagnosticPop(SourceLocation Loc, llvm::StringRef Namespace) override
void PragmaDetectMismatch(SourceLocation Loc, llvm::StringRef Name, llvm::StringRef Value) override
void PragmaWarningPop(SourceLocation Loc) override
void Ifndef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, llvm::StringRef SearchPath, llvm::StringRef RelativePath, const Module *SuggestedModule, bool ModuleImported, SrcMgr::CharacteristicKind FileType) override
void PragmaMessage(SourceLocation Loc, llvm::StringRef Namespace, PPCallbacks::PragmaMessageKind Kind, llvm::StringRef Str) override
void Endif(SourceLocation Loc, SourceLocation IfLoc) override
void PragmaDebug(SourceLocation Loc, llvm::StringRef DebugType) override
std::vector< CallbackCall > & CallbackCalls
Callback trace information.
void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range, const MacroArgs *Args) override
void PragmaWarning(SourceLocation Loc, PragmaWarningSpecifier WarningSpec, llvm::ArrayRef< int > Ids) override
llvm::StringRef getSourceString(CharSourceRange Range)
Get the raw source string of the range.
bool DisableTrace
Inhibit trace while this is set.
~PPCallbacksTracker() override
PPCallbacksTracker(const FilterType &Filters, std::vector< CallbackCall > &CallbackCalls, Preprocessor &PP)
Note that all of the arguments are references, and owned by the caller.
void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str) override
void Defined(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range) override
void PragmaWarningPush(SourceLocation Loc, int Level) override
void EndOfMainFile() override
void Else(SourceLocation Loc, SourceLocation IfLoc) override
void PragmaExecCharsetPop(SourceLocation Loc) override
void FileChanged(SourceLocation Loc, PPCallbacks::FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID=FileID()) override
void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path, const Module *Imported) override
void PragmaDiagnosticPush(SourceLocation Loc, llvm::StringRef Namespace) override
void appendArgument(const char *Name, bool Value)
Append a bool argument to the top trace item.
void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *Name, SourceLocation StateLoc, unsigned State) override
void appendFilePathArgument(const char *Name, llvm::StringRef Value)
Append a double-quoted file path argument to the top trace item.
const FilterType & Filters
static const char *const PragmaIntroducerKindStrings[]
std::vector< std::pair< llvm::GlobPattern, bool > > FilterType
static const char *const PragmaMessageKindStrings[]
static const char *const CharacteristicKindStrings[]
static const char *const ConditionValueKindStrings[]
static const char *const PragmaWarningSpecifierStrings[]
static const char *const FileChangeReasonStrings[]
static const char *const MacroDirectiveKindStrings[]
static const char *const MappingStrings[]
static std::string getSourceLocationString(Preprocessor &PP, SourceLocation Loc)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//