clang-tools 18.0.0git
PPCallbacksTracker.cpp
Go to the documentation of this file.
1//===--- PPCallbacksTracker.cpp - Preprocessor tracker -*--*---------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// Implementations for preprocessor tracking.
11///
12/// See the header for details.
13///
14//===----------------------------------------------------------------------===//
15
16#include "PPCallbacksTracker.h"
17#include "clang/Basic/FileManager.h"
18#include "clang/Lex/MacroArgs.h"
19#include "llvm/Support/raw_ostream.h"
20
21namespace clang {
22namespace pp_trace {
23
24// Get a "file:line:column" source location string.
25static std::string getSourceLocationString(Preprocessor &PP,
26 SourceLocation Loc) {
27 if (Loc.isInvalid())
28 return std::string("(none)");
29
30 if (Loc.isFileID()) {
31 PresumedLoc PLoc = PP.getSourceManager().getPresumedLoc(Loc);
32
33 if (PLoc.isInvalid()) {
34 return std::string("(invalid)");
35 }
36
37 std::string Str;
38 llvm::raw_string_ostream SS(Str);
39
40 // The macro expansion and spelling pos is identical for file locs.
41 SS << "\"" << PLoc.getFilename() << ':' << PLoc.getLine() << ':'
42 << PLoc.getColumn() << "\"";
43
44 std::string Result = SS.str();
45
46 // YAML treats backslash as escape, so use forward slashes.
47 std::replace(Result.begin(), Result.end(), '\\', '/');
48
49 return Result;
50 }
51
52 return std::string("(nonfile)");
53}
54
55// Enum string tables.
56
57// FileChangeReason strings.
58static const char *const FileChangeReasonStrings[] = {
59 "EnterFile", "ExitFile", "SystemHeaderPragma", "RenameFile"
60};
61
62// CharacteristicKind strings.
63static const char *const CharacteristicKindStrings[] = { "C_User", "C_System",
64 "C_ExternCSystem" };
65
66// MacroDirective::Kind strings.
67static const char *const MacroDirectiveKindStrings[] = {
68 "MD_Define","MD_Undefine", "MD_Visibility"
69};
70
71// PragmaIntroducerKind strings.
72static const char *const PragmaIntroducerKindStrings[] = { "PIK_HashPragma",
73 "PIK__Pragma",
74 "PIK___pragma" };
75
76// PragmaMessageKind strings.
77static const char *const PragmaMessageKindStrings[] = {
78 "PMK_Message", "PMK_Warning", "PMK_Error"
79};
80
81// PragmaWarningSpecifier strings.
82static const char *const PragmaWarningSpecifierStrings[] = {
83 "PWS_Default", "PWS_Disable", "PWS_Error", "PWS_Once", "PWS_Suppress",
84 "PWS_Level1", "PWS_Level2", "PWS_Level3", "PWS_Level4",
85};
86
87// ConditionValueKind strings.
88static const char *const ConditionValueKindStrings[] = {
89 "CVK_NotEvaluated", "CVK_False", "CVK_True"
90};
91
92// Mapping strings.
93static const char *const MappingStrings[] = { "0", "MAP_IGNORE",
94 "MAP_REMARK", "MAP_WARNING",
95 "MAP_ERROR", "MAP_FATAL" };
96
97// PPCallbacksTracker functions.
98
100 std::vector<CallbackCall> &CallbackCalls,
101 Preprocessor &PP)
102 : CallbackCalls(CallbackCalls), Filters(Filters), PP(PP) {}
103
105
106// Callback functions.
107
108// Callback invoked whenever a source file is entered or exited.
110 PPCallbacks::FileChangeReason Reason,
111 SrcMgr::CharacteristicKind FileType,
112 FileID PrevFID) {
113 beginCallback("FileChanged");
114 appendArgument("Loc", Loc);
115 appendArgument("Reason", Reason, FileChangeReasonStrings);
116 appendArgument("FileType", FileType, CharacteristicKindStrings);
117 appendArgument("PrevFID", PrevFID);
118}
119
120// Callback invoked whenever a source file is skipped as the result
121// of header guard optimization.
122void PPCallbacksTracker::FileSkipped(const FileEntryRef &SkippedFile,
123 const Token &FilenameTok,
124 SrcMgr::CharacteristicKind FileType) {
125 beginCallback("FileSkipped");
126 appendArgument("ParentFile", SkippedFile);
127 appendArgument("FilenameTok", FilenameTok);
128 appendArgument("FileType", FileType, CharacteristicKindStrings);
129}
130
131// Callback invoked whenever an inclusion directive of
132// any kind (#include, #import, etc.) has been processed, regardless
133// of whether the inclusion will actually result in an inclusion.
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) {
139 beginCallback("InclusionDirective");
140 appendArgument("HashLoc", HashLoc);
141 appendArgument("IncludeTok", IncludeTok);
142 appendFilePathArgument("FileName", FileName);
143 appendArgument("IsAngled", IsAngled);
144 appendArgument("FilenameRange", FilenameRange);
145 appendArgument("File", File);
146 appendFilePathArgument("SearchPath", SearchPath);
147 appendFilePathArgument("RelativePath", RelativePath);
148 appendArgument("Imported", Imported);
149}
150
151// Callback invoked whenever there was an explicit module-import
152// syntax.
153void PPCallbacksTracker::moduleImport(SourceLocation ImportLoc,
154 ModuleIdPath Path,
155 const Module *Imported) {
156 beginCallback("moduleImport");
157 appendArgument("ImportLoc", ImportLoc);
158 appendArgument("Path", Path);
159 appendArgument("Imported", Imported);
160}
161
162// Callback invoked when the end of the main file is reached.
163// No subsequent callbacks will be made.
165
166// Callback invoked when a #ident or #sccs directive is read.
167void PPCallbacksTracker::Ident(SourceLocation Loc, llvm::StringRef Str) {
168 beginCallback("Ident");
169 appendArgument("Loc", Loc);
170 appendArgument("Str", Str);
171}
172
173// Callback invoked when start reading any pragma directive.
175 PragmaIntroducerKind Introducer) {
176 beginCallback("PragmaDirective");
177 appendArgument("Loc", Loc);
178 appendArgument("Introducer", Introducer, PragmaIntroducerKindStrings);
179}
180
181// Callback invoked when a #pragma comment directive is read.
183 const IdentifierInfo *Kind,
184 llvm::StringRef Str) {
185 beginCallback("PragmaComment");
186 appendArgument("Loc", Loc);
187 appendArgument("Kind", Kind);
188 appendArgument("Str", Str);
189}
190
191// Callback invoked when a #pragma detect_mismatch directive is
192// read.
194 llvm::StringRef Name,
195 llvm::StringRef Value) {
196 beginCallback("PragmaDetectMismatch");
197 appendArgument("Loc", Loc);
198 appendArgument("Name", Name);
199 appendArgument("Value", Value);
200}
201
202// Callback invoked when a #pragma clang __debug directive is read.
204 llvm::StringRef DebugType) {
205 beginCallback("PragmaDebug");
206 appendArgument("Loc", Loc);
207 appendArgument("DebugType", DebugType);
208}
209
210// Callback invoked when a #pragma message directive is read.
212 llvm::StringRef Namespace,
213 PPCallbacks::PragmaMessageKind Kind,
214 llvm::StringRef Str) {
215 beginCallback("PragmaMessage");
216 appendArgument("Loc", Loc);
217 appendArgument("Namespace", Namespace);
219 appendArgument("Str", Str);
220}
221
222// Callback invoked when a #pragma gcc diagnostic push directive
223// is read.
225 llvm::StringRef Namespace) {
226 beginCallback("PragmaDiagnosticPush");
227 appendArgument("Loc", Loc);
228 appendArgument("Namespace", Namespace);
229}
230
231// Callback invoked when a #pragma gcc diagnostic pop directive
232// is read.
234 llvm::StringRef Namespace) {
235 beginCallback("PragmaDiagnosticPop");
236 appendArgument("Loc", Loc);
237 appendArgument("Namespace", Namespace);
238}
239
240// Callback invoked when a #pragma gcc diagnostic directive is read.
242 llvm::StringRef Namespace,
243 diag::Severity Mapping,
244 llvm::StringRef Str) {
245 beginCallback("PragmaDiagnostic");
246 appendArgument("Loc", Loc);
247 appendArgument("Namespace", Namespace);
248 appendArgument("Mapping", (unsigned)Mapping, MappingStrings);
249 appendArgument("Str", Str);
250}
251
252// Called when an OpenCL extension is either disabled or
253// enabled with a pragma.
255 const IdentifierInfo *Name,
256 SourceLocation StateLoc,
257 unsigned State) {
258 beginCallback("PragmaOpenCLExtension");
259 appendArgument("NameLoc", NameLoc);
260 appendArgument("Name", Name);
261 appendArgument("StateLoc", StateLoc);
262 appendArgument("State", (int)State);
263}
264
265// Callback invoked when a #pragma warning directive is read.
267 PragmaWarningSpecifier WarningSpec,
268 llvm::ArrayRef<int> Ids) {
269 beginCallback("PragmaWarning");
270 appendArgument("Loc", Loc);
271 appendArgument("WarningSpec", WarningSpec, PragmaWarningSpecifierStrings);
272
273 std::string Str;
274 llvm::raw_string_ostream SS(Str);
275 SS << "[";
276 for (int i = 0, e = Ids.size(); i != e; ++i) {
277 if (i)
278 SS << ", ";
279 SS << Ids[i];
280 }
281 SS << "]";
282 appendArgument("Ids", SS.str());
283}
284
285// Callback invoked when a #pragma warning(push) directive is read.
286void PPCallbacksTracker::PragmaWarningPush(SourceLocation Loc, int Level) {
287 beginCallback("PragmaWarningPush");
288 appendArgument("Loc", Loc);
289 appendArgument("Level", Level);
290}
291
292// Callback invoked when a #pragma warning(pop) directive is read.
294 beginCallback("PragmaWarningPop");
295 appendArgument("Loc", Loc);
296}
297
298// Callback invoked when a #pragma execution_character_set(push) directive
299// is read.
301 StringRef Str) {
302 beginCallback("PragmaExecCharsetPush");
303 appendArgument("Loc", Loc);
304 appendArgument("Charset", Str);
305}
306
307// Callback invoked when a #pragma execution_character_set(pop) directive
308// is read.
310 beginCallback("PragmaExecCharsetPop");
311 appendArgument("Loc", Loc);
312}
313
314// Called by Preprocessor::HandleMacroExpandedIdentifier when a
315// macro invocation is found.
316void PPCallbacksTracker::MacroExpands(const Token &MacroNameTok,
317 const MacroDefinition &MacroDefinition,
318 SourceRange Range,
319 const MacroArgs *Args) {
320 beginCallback("MacroExpands");
321 appendArgument("MacroNameTok", MacroNameTok);
322 appendArgument("MacroDefinition", MacroDefinition);
323 appendArgument("Range", Range);
324 appendArgument("Args", Args);
325}
326
327// Hook called whenever a macro definition is seen.
328void PPCallbacksTracker::MacroDefined(const Token &MacroNameTok,
329 const MacroDirective *MacroDirective) {
330 beginCallback("MacroDefined");
331 appendArgument("MacroNameTok", MacroNameTok);
332 appendArgument("MacroDirective", MacroDirective);
333}
334
335// Hook called whenever a macro #undef is seen.
336void PPCallbacksTracker::MacroUndefined(const Token &MacroNameTok,
337 const MacroDefinition &MacroDefinition,
338 const MacroDirective *Undef) {
339 beginCallback("MacroUndefined");
340 appendArgument("MacroNameTok", MacroNameTok);
341 appendArgument("MacroDefinition", MacroDefinition);
342}
343
344// Hook called whenever the 'defined' operator is seen.
345void PPCallbacksTracker::Defined(const Token &MacroNameTok,
346 const MacroDefinition &MacroDefinition,
347 SourceRange Range) {
348 beginCallback("Defined");
349 appendArgument("MacroNameTok", MacroNameTok);
350 appendArgument("MacroDefinition", MacroDefinition);
351 appendArgument("Range", Range);
352}
353
354// Hook called when a source range is skipped.
356 SourceLocation EndifLoc) {
357 beginCallback("SourceRangeSkipped");
358 appendArgument("Range", SourceRange(Range.getBegin(), EndifLoc));
359}
360
361// Hook called whenever an #if is seen.
362void PPCallbacksTracker::If(SourceLocation Loc, SourceRange ConditionRange,
363 ConditionValueKind ConditionValue) {
364 beginCallback("If");
365 appendArgument("Loc", Loc);
366 appendArgument("ConditionRange", ConditionRange);
368}
369
370// Hook called whenever an #elif is seen.
371void PPCallbacksTracker::Elif(SourceLocation Loc, SourceRange ConditionRange,
372 ConditionValueKind ConditionValue,
373 SourceLocation IfLoc) {
374 beginCallback("Elif");
375 appendArgument("Loc", Loc);
376 appendArgument("ConditionRange", ConditionRange);
378 appendArgument("IfLoc", IfLoc);
379}
380
381// Hook called whenever an #ifdef is seen.
382void PPCallbacksTracker::Ifdef(SourceLocation Loc, const Token &MacroNameTok,
383 const MacroDefinition &MacroDefinition) {
384 beginCallback("Ifdef");
385 appendArgument("Loc", Loc);
386 appendArgument("MacroNameTok", MacroNameTok);
387 appendArgument("MacroDefinition", MacroDefinition);
388}
389
390// Hook called whenever an #ifndef is seen.
391void PPCallbacksTracker::Ifndef(SourceLocation Loc, const Token &MacroNameTok,
392 const MacroDefinition &MacroDefinition) {
393 beginCallback("Ifndef");
394 appendArgument("Loc", Loc);
395 appendArgument("MacroNameTok", MacroNameTok);
396 appendArgument("MacroDefinition", MacroDefinition);
397}
398
399// Hook called whenever an #else is seen.
400void PPCallbacksTracker::Else(SourceLocation Loc, SourceLocation IfLoc) {
401 beginCallback("Else");
402 appendArgument("Loc", Loc);
403 appendArgument("IfLoc", IfLoc);
404}
405
406// Hook called whenever an #endif is seen.
407void PPCallbacksTracker::Endif(SourceLocation Loc, SourceLocation IfLoc) {
408 beginCallback("Endif");
409 appendArgument("Loc", Loc);
410 appendArgument("IfLoc", IfLoc);
411}
412
413// Helper functions.
414
415// Start a new callback.
417 auto R = CallbackIsEnabled.try_emplace(Name, false);
418 if (R.second) {
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;
423 }
424 DisableTrace = !R.first->second;
425 if (DisableTrace)
426 return;
427 CallbackCalls.push_back(CallbackCall(Name));
428}
429
430// Append a bool argument to the top trace item.
431void PPCallbacksTracker::appendArgument(const char *Name, bool Value) {
432 appendArgument(Name, (Value ? "true" : "false"));
433}
434
435// Append an int argument to the top trace item.
436void PPCallbacksTracker::appendArgument(const char *Name, int Value) {
437 std::string Str;
438 llvm::raw_string_ostream SS(Str);
439 SS << Value;
440 appendArgument(Name, SS.str());
441}
442
443// Append a string argument to the top trace item.
444void PPCallbacksTracker::appendArgument(const char *Name, const char *Value) {
445 if (DisableTrace)
446 return;
447 CallbackCalls.back().Arguments.push_back(Argument{Name, Value});
448}
449
450// Append a string object argument to the top trace item.
452 llvm::StringRef Value) {
453 appendArgument(Name, Value.str());
454}
455
456// Append a string object argument to the top trace item.
458 const std::string &Value) {
459 appendArgument(Name, Value.c_str());
460}
461
462// Append a token argument to the top trace item.
463void PPCallbacksTracker::appendArgument(const char *Name, const Token &Value) {
464 appendArgument(Name, PP.getSpelling(Value));
465}
466
467// Append an enum argument to the top trace item.
468void PPCallbacksTracker::appendArgument(const char *Name, int Value,
469 const char *const Strings[]) {
470 appendArgument(Name, Strings[Value]);
471}
472
473// Append a FileID argument to the top trace item.
474void PPCallbacksTracker::appendArgument(const char *Name, FileID Value) {
475 if (Value.isInvalid()) {
476 appendArgument(Name, "(invalid)");
477 return;
478 }
479 OptionalFileEntryRef FileEntry =
480 PP.getSourceManager().getFileEntryRefForID(Value);
481 if (!FileEntry) {
482 appendArgument(Name, "(getFileEntryForID failed)");
483 return;
484 }
485 appendFilePathArgument(Name, FileEntry->getName());
486}
487
488// Append a FileEntry argument to the top trace item.
490 OptionalFileEntryRef Value) {
491 if (!Value) {
492 appendArgument(Name, "(null)");
493 return;
494 }
495 appendArgument(Name, *Value);
496}
497
498void PPCallbacksTracker::appendArgument(const char *Name, FileEntryRef Value) {
499 appendFilePathArgument(Name, Value.getName());
500}
501
502// Append a SourceLocation argument to the top trace item.
504 SourceLocation Value) {
505 if (Value.isInvalid()) {
506 appendArgument(Name, "(invalid)");
507 return;
508 }
510}
511
512// Append a SourceRange argument to the top trace item.
513void PPCallbacksTracker::appendArgument(const char *Name, SourceRange Value) {
514 if (DisableTrace)
515 return;
516 if (Value.isInvalid()) {
517 appendArgument(Name, "(invalid)");
518 return;
519 }
520 std::string Str;
521 llvm::raw_string_ostream SS(Str);
522 SS << "[" << getSourceLocationString(PP, Value.getBegin()) << ", "
523 << getSourceLocationString(PP, Value.getEnd()) << "]";
524 appendArgument(Name, SS.str());
525}
526
527// Append a CharSourceRange argument to the top trace item.
529 CharSourceRange Value) {
530 if (Value.isInvalid()) {
531 appendArgument(Name, "(invalid)");
532 return;
533 }
534 appendArgument(Name, getSourceString(Value).str().c_str());
535}
536
537// Append a SourceLocation argument to the top trace item.
538void PPCallbacksTracker::appendArgument(const char *Name, ModuleIdPath Value) {
539 if (DisableTrace)
540 return;
541 std::string Str;
542 llvm::raw_string_ostream SS(Str);
543 SS << "[";
544 for (int I = 0, E = Value.size(); I != E; ++I) {
545 if (I)
546 SS << ", ";
547 SS << "{"
548 << "Name: " << Value[I].first->getName() << ", "
549 << "Loc: " << getSourceLocationString(PP, Value[I].second) << "}";
550 }
551 SS << "]";
552 appendArgument(Name, SS.str());
553}
554
555// Append an IdentifierInfo argument to the top trace item.
557 const IdentifierInfo *Value) {
558 if (!Value) {
559 appendArgument(Name, "(null)");
560 return;
561 }
562 appendArgument(Name, Value->getName().str().c_str());
563}
564
565// Append a MacroDirective argument to the top trace item.
567 const MacroDirective *Value) {
568 if (!Value) {
569 appendArgument(Name, "(null)");
570 return;
571 }
573}
574
575// Append a MacroDefinition argument to the top trace item.
577 const MacroDefinition &Value) {
578 std::string Str;
579 llvm::raw_string_ostream SS(Str);
580 SS << "[";
581 bool Any = false;
582 if (Value.getLocalDirective()) {
583 SS << "(local)";
584 Any = true;
585 }
586 for (auto *MM : Value.getModuleMacros()) {
587 if (Any) SS << ", ";
588 SS << MM->getOwningModule()->getFullModuleName();
589 }
590 SS << "]";
591 appendArgument(Name, SS.str());
592}
593
594// Append a MacroArgs argument to the top trace item.
596 const MacroArgs *Value) {
597 if (!Value) {
598 appendArgument(Name, "(null)");
599 return;
600 }
601 std::string Str;
602 llvm::raw_string_ostream SS(Str);
603 SS << "[";
604
605 // Each argument is a series of contiguous Tokens, terminated by a eof.
606 // Go through each argument printing tokens until we reach eof.
607 for (unsigned I = 0; I < Value->getNumMacroArguments(); ++I) {
608 const Token *Current = Value->getUnexpArgument(I);
609 if (I)
610 SS << ", ";
611 bool First = true;
612 while (Current->isNot(tok::eof)) {
613 if (!First)
614 SS << " ";
615 // We need to be careful here because the arguments might not be legal in
616 // YAML, so we use the token name for anything but identifiers and
617 // numeric literals.
618 if (Current->isAnyIdentifier() || Current->is(tok::numeric_constant)) {
619 SS << PP.getSpelling(*Current);
620 } else {
621 SS << "<" << Current->getName() << ">";
622 }
623 ++Current;
624 First = false;
625 }
626 }
627 SS << "]";
628 appendArgument(Name, SS.str());
629}
630
631// Append a Module argument to the top trace item.
632void PPCallbacksTracker::appendArgument(const char *Name, const Module *Value) {
633 if (!Value) {
634 appendArgument(Name, "(null)");
635 return;
636 }
637 appendArgument(Name, Value->Name.c_str());
638}
639
640// Append a double-quoted argument to the top trace item.
642 const std::string &Value) {
643 std::string Str;
644 llvm::raw_string_ostream SS(Str);
645 SS << "\"" << Value << "\"";
646 appendArgument(Name, SS.str());
647}
648
649// Append a double-quoted file path argument to the top trace item.
651 llvm::StringRef Value) {
652 std::string Path(Value);
653 // YAML treats backslash as escape, so use forward slashes.
654 std::replace(Path.begin(), Path.end(), '\\', '/');
656}
657
658// Get the raw source string of the range.
659llvm::StringRef PPCallbacksTracker::getSourceString(CharSourceRange Range) {
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);
663}
664
665} // namespace pp_trace
666} // namespace clang
const Expr * E
BindArgumentKind Kind
llvm::StringRef Name
CharSourceRange Range
SourceRange for the file name.
bool IsAngled
true if this was an include with angle brackets
StringRef FileName
SourceLocation Loc
Classes and definitions for preprocessor tracking.
std::vector< HeaderHandle > Path
clang::PPCallbacks::ConditionValueKind ConditionValue
std::vector< llvm::StringRef > Strings
llvm::json::Object Args
Definition: Trace.cpp:138
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(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 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.
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++ -*-===//