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 *Imported, SrcMgr::CharacteristicKind FileType) {
155 const Module *Imported) {
175 PragmaIntroducerKind Introducer) {
183 const IdentifierInfo *
Kind,
184 llvm::StringRef Str) {
194 llvm::StringRef
Name,
195 llvm::StringRef Value) {
204 llvm::StringRef DebugType) {
212 llvm::StringRef Namespace,
213 PPCallbacks::PragmaMessageKind
Kind,
214 llvm::StringRef Str) {
225 llvm::StringRef Namespace) {
234 llvm::StringRef Namespace) {
242 llvm::StringRef Namespace,
243 diag::Severity Mapping,
244 llvm::StringRef Str) {
255 const IdentifierInfo *
Name,
256 SourceLocation StateLoc,
267 PragmaWarningSpecifier WarningSpec,
268 llvm::ArrayRef<int> Ids) {
274 llvm::raw_string_ostream SS(Str);
276 for (
int i = 0, e = Ids.size(); i != e; ++i) {
317 const MacroDefinition &MacroDefinition,
319 const MacroArgs *
Args) {
329 const MacroDirective *MacroDirective) {
337 const MacroDefinition &MacroDefinition,
338 const MacroDirective *Undef) {
346 const MacroDefinition &MacroDefinition,
356 SourceLocation EndifLoc) {
373 SourceLocation IfLoc) {
383 const MacroDefinition &MacroDefinition) {
392 const MacroDefinition &MacroDefinition) {
419 llvm::StringRef N(
Name);
420 for (
const std::pair<llvm::GlobPattern, bool> &Filter :
Filters)
421 if (Filter.first.match(N))
422 R.first->second = Filter.second;
438 llvm::raw_string_ostream SS(Str);
452 llvm::StringRef Value) {
458 const std::string &Value) {
475 if (Value.isInvalid()) {
479 OptionalFileEntryRef FileEntry =
480 PP.getSourceManager().getFileEntryRefForID(Value);
490 OptionalFileEntryRef Value) {
504 SourceLocation Value) {
505 if (Value.isInvalid()) {
516 if (Value.isInvalid()) {
521 llvm::raw_string_ostream SS(Str);
529 CharSourceRange Value) {
530 if (Value.isInvalid()) {
542 llvm::raw_string_ostream SS(Str);
544 for (
int I = 0,
E = Value.size(); I !=
E; ++I) {
548 <<
"Name: " << Value[I].first->getName() <<
", "
557 const IdentifierInfo *Value) {
567 const MacroDirective *Value) {
577 const MacroDefinition &Value) {
579 llvm::raw_string_ostream SS(Str);
582 if (Value.getLocalDirective()) {
586 for (
auto *MM : Value.getModuleMacros()) {
588 SS << MM->getOwningModule()->getFullModuleName();
596 const MacroArgs *Value) {
602 llvm::raw_string_ostream SS(Str);
607 for (
unsigned I = 0; I < Value->getNumMacroArguments(); ++I) {
608 const Token *Current = Value->getUnexpArgument(I);
612 while (Current->isNot(tok::eof)) {
618 if (Current->isAnyIdentifier() || Current->is(tok::numeric_constant)) {
619 SS <<
PP.getSpelling(*Current);
621 SS <<
"<" << Current->getName() <<
">";
642 const std::string &Value) {
644 llvm::raw_string_ostream SS(Str);
645 SS <<
"\"" << Value <<
"\"";
651 llvm::StringRef Value) {
652 std::string
Path(Value);
654 std::replace(
Path.begin(),
Path.end(),
'\\',
'/');
660 const char *B =
PP.getSourceManager().getCharacterData(
Range.getBegin());
661 const char *
E =
PP.getSourceManager().getCharacterData(
Range.getEnd());
662 return llvm::StringRef(B,
E - B);
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 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 InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, llvm::StringRef SearchPath, llvm::StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) 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++ -*-===//