clang-tools  15.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 
21 namespace clang {
22 namespace pp_trace {
23 
24 // Get a "file:line:column" source location string.
25 static 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.
58 static const char *const FileChangeReasonStrings[] = {
59  "EnterFile", "ExitFile", "SystemHeaderPragma", "RenameFile"
60 };
61 
62 // CharacteristicKind strings.
63 static const char *const CharacteristicKindStrings[] = { "C_User", "C_System",
64  "C_ExternCSystem" };
65 
66 // MacroDirective::Kind strings.
67 static const char *const MacroDirectiveKindStrings[] = {
68  "MD_Define","MD_Undefine", "MD_Visibility"
69 };
70 
71 // PragmaIntroducerKind strings.
72 static const char *const PragmaIntroducerKindStrings[] = { "PIK_HashPragma",
73  "PIK__Pragma",
74  "PIK___pragma" };
75 
76 // PragmaMessageKind strings.
77 static const char *const PragmaMessageKindStrings[] = {
78  "PMK_Message", "PMK_Warning", "PMK_Error"
79 };
80 
81 // PragmaWarningSpecifier strings.
82 static 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.
88 static const char *const ConditionValueKindStrings[] = {
89  "CVK_NotEvaluated", "CVK_False", "CVK_True"
90 };
91 
92 // Mapping strings.
93 static 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.
122 void 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, Optional<FileEntryRef> File,
137  llvm::StringRef SearchPath, llvm::StringRef RelativePath,
138  const Module *Imported, SrcMgr::CharacteristicKind FileType) {
139  beginCallback("InclusionDirective");
140  appendArgument("IncludeTok", IncludeTok);
141  appendFilePathArgument("FileName", FileName);
142  appendArgument("IsAngled", IsAngled);
143  appendArgument("FilenameRange", FilenameRange);
144  appendArgument("File", File);
145  appendFilePathArgument("SearchPath", SearchPath);
146  appendFilePathArgument("RelativePath", RelativePath);
147  appendArgument("Imported", Imported);
148 }
149 
150 // Callback invoked whenever there was an explicit module-import
151 // syntax.
152 void PPCallbacksTracker::moduleImport(SourceLocation ImportLoc,
153  ModuleIdPath Path,
154  const Module *Imported) {
155  beginCallback("moduleImport");
156  appendArgument("ImportLoc", ImportLoc);
157  appendArgument("Path", Path);
158  appendArgument("Imported", Imported);
159 }
160 
161 // Callback invoked when the end of the main file is reached.
162 // No subsequent callbacks will be made.
164 
165 // Callback invoked when a #ident or #sccs directive is read.
166 void PPCallbacksTracker::Ident(SourceLocation Loc, llvm::StringRef Str) {
167  beginCallback("Ident");
168  appendArgument("Loc", Loc);
169  appendArgument("Str", Str);
170 }
171 
172 // Callback invoked when start reading any pragma directive.
174  PragmaIntroducerKind Introducer) {
175  beginCallback("PragmaDirective");
176  appendArgument("Loc", Loc);
177  appendArgument("Introducer", Introducer, PragmaIntroducerKindStrings);
178 }
179 
180 // Callback invoked when a #pragma comment directive is read.
182  const IdentifierInfo *Kind,
183  llvm::StringRef Str) {
184  beginCallback("PragmaComment");
185  appendArgument("Loc", Loc);
186  appendArgument("Kind", Kind);
187  appendArgument("Str", Str);
188 }
189 
190 // Callback invoked when a #pragma detect_mismatch directive is
191 // read.
193  llvm::StringRef Name,
194  llvm::StringRef Value) {
195  beginCallback("PragmaDetectMismatch");
196  appendArgument("Loc", Loc);
197  appendArgument("Name", Name);
198  appendArgument("Value", Value);
199 }
200 
201 // Callback invoked when a #pragma clang __debug directive is read.
203  llvm::StringRef DebugType) {
204  beginCallback("PragmaDebug");
205  appendArgument("Loc", Loc);
206  appendArgument("DebugType", DebugType);
207 }
208 
209 // Callback invoked when a #pragma message directive is read.
211  llvm::StringRef Namespace,
212  PPCallbacks::PragmaMessageKind Kind,
213  llvm::StringRef Str) {
214  beginCallback("PragmaMessage");
215  appendArgument("Loc", Loc);
216  appendArgument("Namespace", Namespace);
218  appendArgument("Str", Str);
219 }
220 
221 // Callback invoked when a #pragma gcc diagnostic push directive
222 // is read.
224  llvm::StringRef Namespace) {
225  beginCallback("PragmaDiagnosticPush");
226  appendArgument("Loc", Loc);
227  appendArgument("Namespace", Namespace);
228 }
229 
230 // Callback invoked when a #pragma gcc diagnostic pop directive
231 // is read.
233  llvm::StringRef Namespace) {
234  beginCallback("PragmaDiagnosticPop");
235  appendArgument("Loc", Loc);
236  appendArgument("Namespace", Namespace);
237 }
238 
239 // Callback invoked when a #pragma gcc diagnostic directive is read.
241  llvm::StringRef Namespace,
242  diag::Severity Mapping,
243  llvm::StringRef Str) {
244  beginCallback("PragmaDiagnostic");
245  appendArgument("Loc", Loc);
246  appendArgument("Namespace", Namespace);
247  appendArgument("Mapping", (unsigned)Mapping, MappingStrings);
248  appendArgument("Str", Str);
249 }
250 
251 // Called when an OpenCL extension is either disabled or
252 // enabled with a pragma.
253 void PPCallbacksTracker::PragmaOpenCLExtension(SourceLocation NameLoc,
254  const IdentifierInfo *Name,
255  SourceLocation StateLoc,
256  unsigned State) {
257  beginCallback("PragmaOpenCLExtension");
258  appendArgument("NameLoc", NameLoc);
259  appendArgument("Name", Name);
260  appendArgument("StateLoc", StateLoc);
261  appendArgument("State", (int)State);
262 }
263 
264 // Callback invoked when a #pragma warning directive is read.
266  PragmaWarningSpecifier WarningSpec,
267  llvm::ArrayRef<int> Ids) {
268  beginCallback("PragmaWarning");
269  appendArgument("Loc", Loc);
270  appendArgument("WarningSpec", WarningSpec, PragmaWarningSpecifierStrings);
271 
272  std::string Str;
273  llvm::raw_string_ostream SS(Str);
274  SS << "[";
275  for (int i = 0, e = Ids.size(); i != e; ++i) {
276  if (i)
277  SS << ", ";
278  SS << Ids[i];
279  }
280  SS << "]";
281  appendArgument("Ids", SS.str());
282 }
283 
284 // Callback invoked when a #pragma warning(push) directive is read.
285 void PPCallbacksTracker::PragmaWarningPush(SourceLocation Loc, int Level) {
286  beginCallback("PragmaWarningPush");
287  appendArgument("Loc", Loc);
288  appendArgument("Level", Level);
289 }
290 
291 // Callback invoked when a #pragma warning(pop) directive is read.
293  beginCallback("PragmaWarningPop");
294  appendArgument("Loc", Loc);
295 }
296 
297 // Callback invoked when a #pragma execution_character_set(push) directive
298 // is read.
300  StringRef Str) {
301  beginCallback("PragmaExecCharsetPush");
302  appendArgument("Loc", Loc);
303  appendArgument("Charset", Str);
304 }
305 
306 // Callback invoked when a #pragma execution_character_set(pop) directive
307 // is read.
309  beginCallback("PragmaExecCharsetPop");
310  appendArgument("Loc", Loc);
311 }
312 
313 // Called by Preprocessor::HandleMacroExpandedIdentifier when a
314 // macro invocation is found.
315 void PPCallbacksTracker::MacroExpands(const Token &MacroNameTok,
316  const MacroDefinition &MacroDefinition,
317  SourceRange Range,
318  const MacroArgs *Args) {
319  beginCallback("MacroExpands");
320  appendArgument("MacroNameTok", MacroNameTok);
321  appendArgument("MacroDefinition", MacroDefinition);
322  appendArgument("Range", Range);
323  appendArgument("Args", Args);
324 }
325 
326 // Hook called whenever a macro definition is seen.
327 void PPCallbacksTracker::MacroDefined(const Token &MacroNameTok,
328  const MacroDirective *MacroDirective) {
329  beginCallback("MacroDefined");
330  appendArgument("MacroNameTok", MacroNameTok);
331  appendArgument("MacroDirective", MacroDirective);
332 }
333 
334 // Hook called whenever a macro #undef is seen.
335 void PPCallbacksTracker::MacroUndefined(const Token &MacroNameTok,
336  const MacroDefinition &MacroDefinition,
337  const MacroDirective *Undef) {
338  beginCallback("MacroUndefined");
339  appendArgument("MacroNameTok", MacroNameTok);
340  appendArgument("MacroDefinition", MacroDefinition);
341 }
342 
343 // Hook called whenever the 'defined' operator is seen.
344 void PPCallbacksTracker::Defined(const Token &MacroNameTok,
345  const MacroDefinition &MacroDefinition,
346  SourceRange Range) {
347  beginCallback("Defined");
348  appendArgument("MacroNameTok", MacroNameTok);
349  appendArgument("MacroDefinition", MacroDefinition);
350  appendArgument("Range", Range);
351 }
352 
353 // Hook called when a source range is skipped.
355  SourceLocation EndifLoc) {
356  beginCallback("SourceRangeSkipped");
357  appendArgument("Range", SourceRange(Range.getBegin(), EndifLoc));
358 }
359 
360 // Hook called whenever an #if is seen.
361 void PPCallbacksTracker::If(SourceLocation Loc, SourceRange ConditionRange,
362  ConditionValueKind ConditionValue) {
363  beginCallback("If");
364  appendArgument("Loc", Loc);
365  appendArgument("ConditionRange", ConditionRange);
367 }
368 
369 // Hook called whenever an #elif is seen.
370 void PPCallbacksTracker::Elif(SourceLocation Loc, SourceRange ConditionRange,
371  ConditionValueKind ConditionValue,
372  SourceLocation IfLoc) {
373  beginCallback("Elif");
374  appendArgument("Loc", Loc);
375  appendArgument("ConditionRange", ConditionRange);
377  appendArgument("IfLoc", IfLoc);
378 }
379 
380 // Hook called whenever an #ifdef is seen.
381 void PPCallbacksTracker::Ifdef(SourceLocation Loc, const Token &MacroNameTok,
382  const MacroDefinition &MacroDefinition) {
383  beginCallback("Ifdef");
384  appendArgument("Loc", Loc);
385  appendArgument("MacroNameTok", MacroNameTok);
386  appendArgument("MacroDefinition", MacroDefinition);
387 }
388 
389 // Hook called whenever an #ifndef is seen.
390 void PPCallbacksTracker::Ifndef(SourceLocation Loc, const Token &MacroNameTok,
391  const MacroDefinition &MacroDefinition) {
392  beginCallback("Ifndef");
393  appendArgument("Loc", Loc);
394  appendArgument("MacroNameTok", MacroNameTok);
395  appendArgument("MacroDefinition", MacroDefinition);
396 }
397 
398 // Hook called whenever an #else is seen.
399 void PPCallbacksTracker::Else(SourceLocation Loc, SourceLocation IfLoc) {
400  beginCallback("Else");
401  appendArgument("Loc", Loc);
402  appendArgument("IfLoc", IfLoc);
403 }
404 
405 // Hook called whenever an #endif is seen.
406 void PPCallbacksTracker::Endif(SourceLocation Loc, SourceLocation IfLoc) {
407  beginCallback("Endif");
408  appendArgument("Loc", Loc);
409  appendArgument("IfLoc", IfLoc);
410 }
411 
412 // Helper functions.
413 
414 // Start a new callback.
416  auto R = CallbackIsEnabled.try_emplace(Name, false);
417  if (R.second) {
418  llvm::StringRef N(Name);
419  for (const std::pair<llvm::GlobPattern, bool> &Filter : Filters)
420  if (Filter.first.match(N))
421  R.first->second = Filter.second;
422  }
423  DisableTrace = !R.first->second;
424  if (DisableTrace)
425  return;
426  CallbackCalls.push_back(CallbackCall(Name));
427 }
428 
429 // Append a bool argument to the top trace item.
430 void PPCallbacksTracker::appendArgument(const char *Name, bool Value) {
431  appendArgument(Name, (Value ? "true" : "false"));
432 }
433 
434 // Append an int argument to the top trace item.
435 void PPCallbacksTracker::appendArgument(const char *Name, int Value) {
436  std::string Str;
437  llvm::raw_string_ostream SS(Str);
438  SS << Value;
439  appendArgument(Name, SS.str());
440 }
441 
442 // Append a string argument to the top trace item.
443 void PPCallbacksTracker::appendArgument(const char *Name, const char *Value) {
444  if (DisableTrace)
445  return;
446  CallbackCalls.back().Arguments.push_back(Argument{Name, Value});
447 }
448 
449 // Append a string object argument to the top trace item.
451  llvm::StringRef Value) {
452  appendArgument(Name, Value.str());
453 }
454 
455 // Append a string object argument to the top trace item.
457  const std::string &Value) {
458  appendArgument(Name, Value.c_str());
459 }
460 
461 // Append a token argument to the top trace item.
462 void PPCallbacksTracker::appendArgument(const char *Name, const Token &Value) {
463  appendArgument(Name, PP.getSpelling(Value));
464 }
465 
466 // Append an enum argument to the top trace item.
467 void PPCallbacksTracker::appendArgument(const char *Name, int Value,
468  const char *const Strings[]) {
469  appendArgument(Name, Strings[Value]);
470 }
471 
472 // Append a FileID argument to the top trace item.
473 void PPCallbacksTracker::appendArgument(const char *Name, FileID Value) {
474  if (Value.isInvalid()) {
475  appendArgument(Name, "(invalid)");
476  return;
477  }
478  const FileEntry *FileEntry = PP.getSourceManager().getFileEntryForID(Value);
479  if (!FileEntry) {
480  appendArgument(Name, "(getFileEntryForID failed)");
481  return;
482  }
483  appendFilePathArgument(Name, FileEntry->getName());
484 }
485 
486 // Append a FileEntry argument to the top trace item.
488  Optional<FileEntryRef> Value) {
489  if (!Value) {
490  appendArgument(Name, "(null)");
491  return;
492  }
493  appendArgument(Name, *Value);
494 }
495 
496 void PPCallbacksTracker::appendArgument(const char *Name, FileEntryRef Value) {
497  appendFilePathArgument(Name, Value.getName());
498 }
499 
500 // Append a SourceLocation argument to the top trace item.
502  SourceLocation Value) {
503  if (Value.isInvalid()) {
504  appendArgument(Name, "(invalid)");
505  return;
506  }
507  appendArgument(Name, getSourceLocationString(PP, Value).c_str());
508 }
509 
510 // Append a SourceRange argument to the top trace item.
511 void PPCallbacksTracker::appendArgument(const char *Name, SourceRange Value) {
512  if (DisableTrace)
513  return;
514  if (Value.isInvalid()) {
515  appendArgument(Name, "(invalid)");
516  return;
517  }
518  std::string Str;
519  llvm::raw_string_ostream SS(Str);
520  SS << "[" << getSourceLocationString(PP, Value.getBegin()) << ", "
521  << getSourceLocationString(PP, Value.getEnd()) << "]";
522  appendArgument(Name, SS.str());
523 }
524 
525 // Append a CharSourceRange argument to the top trace item.
527  CharSourceRange Value) {
528  if (Value.isInvalid()) {
529  appendArgument(Name, "(invalid)");
530  return;
531  }
532  appendArgument(Name, getSourceString(Value).str().c_str());
533 }
534 
535 // Append a SourceLocation argument to the top trace item.
536 void PPCallbacksTracker::appendArgument(const char *Name, ModuleIdPath Value) {
537  if (DisableTrace)
538  return;
539  std::string Str;
540  llvm::raw_string_ostream SS(Str);
541  SS << "[";
542  for (int I = 0, E = Value.size(); I != E; ++I) {
543  if (I)
544  SS << ", ";
545  SS << "{"
546  << "Name: " << Value[I].first->getName() << ", "
547  << "Loc: " << getSourceLocationString(PP, Value[I].second) << "}";
548  }
549  SS << "]";
550  appendArgument(Name, SS.str());
551 }
552 
553 // Append an IdentifierInfo argument to the top trace item.
555  const IdentifierInfo *Value) {
556  if (!Value) {
557  appendArgument(Name, "(null)");
558  return;
559  }
560  appendArgument(Name, Value->getName().str().c_str());
561 }
562 
563 // Append a MacroDirective argument to the top trace item.
565  const MacroDirective *Value) {
566  if (!Value) {
567  appendArgument(Name, "(null)");
568  return;
569  }
570  appendArgument(Name, MacroDirectiveKindStrings[Value->getKind()]);
571 }
572 
573 // Append a MacroDefinition argument to the top trace item.
575  const MacroDefinition &Value) {
576  std::string Str;
577  llvm::raw_string_ostream SS(Str);
578  SS << "[";
579  bool Any = false;
580  if (Value.getLocalDirective()) {
581  SS << "(local)";
582  Any = true;
583  }
584  for (auto *MM : Value.getModuleMacros()) {
585  if (Any) SS << ", ";
586  SS << MM->getOwningModule()->getFullModuleName();
587  }
588  SS << "]";
589  appendArgument(Name, SS.str());
590 }
591 
592 // Append a MacroArgs argument to the top trace item.
594  const MacroArgs *Value) {
595  if (!Value) {
596  appendArgument(Name, "(null)");
597  return;
598  }
599  std::string Str;
600  llvm::raw_string_ostream SS(Str);
601  SS << "[";
602 
603  // Each argument is is a series of contiguous Tokens, terminated by a eof.
604  // Go through each argument printing tokens until we reach eof.
605  for (unsigned I = 0; I < Value->getNumMacroArguments(); ++I) {
606  const Token *Current = Value->getUnexpArgument(I);
607  if (I)
608  SS << ", ";
609  bool First = true;
610  while (Current->isNot(tok::eof)) {
611  if (!First)
612  SS << " ";
613  // We need to be careful here because the arguments might not be legal in
614  // YAML, so we use the token name for anything but identifiers and
615  // numeric literals.
616  if (Current->isAnyIdentifier() || Current->is(tok::numeric_constant)) {
617  SS << PP.getSpelling(*Current);
618  } else {
619  SS << "<" << Current->getName() << ">";
620  }
621  ++Current;
622  First = false;
623  }
624  }
625  SS << "]";
626  appendArgument(Name, SS.str());
627 }
628 
629 // Append a Module argument to the top trace item.
630 void PPCallbacksTracker::appendArgument(const char *Name, const Module *Value) {
631  if (!Value) {
632  appendArgument(Name, "(null)");
633  return;
634  }
635  appendArgument(Name, Value->Name.c_str());
636 }
637 
638 // Append a double-quoted argument to the top trace item.
640  const std::string &Value) {
641  std::string Str;
642  llvm::raw_string_ostream SS(Str);
643  SS << "\"" << Value << "\"";
644  appendArgument(Name, SS.str());
645 }
646 
647 // Append a double-quoted file path argument to the top trace item.
649  llvm::StringRef Value) {
650  std::string Path(Value);
651  // YAML treats backslash as escape, so use forward slashes.
652  std::replace(Path.begin(), Path.end(), '\\', '/');
654 }
655 
656 // Get the raw source string of the range.
657 llvm::StringRef PPCallbacksTracker::getSourceString(CharSourceRange Range) {
658  const char *B = PP.getSourceManager().getCharacterData(Range.getBegin());
659  const char *E = PP.getSourceManager().getCharacterData(Range.getEnd());
660  return llvm::StringRef(B, E - B);
661 }
662 
663 } // namespace pp_trace
664 } // namespace clang
Range
CharSourceRange Range
SourceRange for the file name.
Definition: IncludeOrderCheck.cpp:38
Loc
SourceLocation Loc
Definition: KernelNameRestrictionCheck.cpp:45
clang::pp_trace::PragmaIntroducerKindStrings
static const char *const PragmaIntroducerKindStrings[]
Definition: PPCallbacksTracker.cpp:72
clang::pp_trace::PPCallbacksTracker::PragmaExecCharsetPop
void PragmaExecCharsetPop(SourceLocation Loc) override
Definition: PPCallbacksTracker.cpp:308
E
const Expr * E
Definition: AvoidBindCheck.cpp:88
clang::pp_trace::PPCallbacksTracker::PragmaComment
void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, llvm::StringRef Str) override
Definition: PPCallbacksTracker.cpp:181
clang::pp_trace::PPCallbacksTracker::PragmaOpenCLExtension
void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *Name, SourceLocation StateLoc, unsigned State) override
Definition: PPCallbacksTracker.cpp:253
clang::pp_trace::Argument
Definition: PPCallbacksTracker.h:39
clang::pp_trace::PPCallbacksTracker::PPCallbacksTracker
PPCallbacksTracker(const FilterType &Filters, std::vector< CallbackCall > &CallbackCalls, Preprocessor &PP)
Note that all of the arguments are references, and owned by the caller.
Definition: PPCallbacksTracker.cpp:99
clang::pp_trace::PPCallbacksTracker::If
void If(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue) override
Definition: PPCallbacksTracker.cpp:361
clang::pp_trace::FilterType
std::vector< std::pair< llvm::GlobPattern, bool > > FilterType
Definition: PPCallbacksTracker.h:55
clang::pp_trace::PPCallbacksTracker::Endif
void Endif(SourceLocation Loc, SourceLocation IfLoc) override
Definition: PPCallbacksTracker.cpp:406
clang::pp_trace::PPCallbacksTracker::DisableTrace
bool DisableTrace
Inhibit trace while this is set.
Definition: PPCallbacksTracker.h:233
clang::pp_trace::PPCallbacksTracker::InclusionDirective
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, Optional< FileEntryRef > File, llvm::StringRef SearchPath, llvm::StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override
Definition: PPCallbacksTracker.cpp:134
ConditionValue
clang::PPCallbacks::ConditionValueKind ConditionValue
Definition: PreprocessorTracker.cpp:660
clang::pp_trace::PPCallbacksTracker::PragmaWarning
void PragmaWarning(SourceLocation Loc, PragmaWarningSpecifier WarningSpec, llvm::ArrayRef< int > Ids) override
Definition: PPCallbacksTracker.cpp:265
Kind
BindArgumentKind Kind
Definition: AvoidBindCheck.cpp:59
clang::pp_trace::PPCallbacksTracker::PragmaWarningPop
void PragmaWarningPop(SourceLocation Loc) override
Definition: PPCallbacksTracker.cpp:292
clang::pp_trace::PPCallbacksTracker::Defined
void Defined(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range) override
Definition: PPCallbacksTracker.cpp:344
clang::pp_trace::PPCallbacksTracker::~PPCallbacksTracker
~PPCallbacksTracker() override
Definition: PPCallbacksTracker.cpp:104
clang::pp_trace::PPCallbacksTracker::FileChanged
void FileChanged(SourceLocation Loc, PPCallbacks::FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID=FileID()) override
Definition: PPCallbacksTracker.cpp:109
clang::pp_trace::PPCallbacksTracker::beginCallback
void beginCallback(const char *Name)
Start a new callback.
Definition: PPCallbacksTracker.cpp:415
clang::pp_trace::FileChangeReasonStrings
static const char *const FileChangeReasonStrings[]
Definition: PPCallbacksTracker.cpp:58
clang::pp_trace::CharacteristicKindStrings
static const char *const CharacteristicKindStrings[]
Definition: PPCallbacksTracker.cpp:63
clang::pp_trace::PPCallbacksTracker::moduleImport
void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path, const Module *Imported) override
Definition: PPCallbacksTracker.cpp:152
clang::pp_trace::PPCallbacksTracker::PragmaDirective
void PragmaDirective(SourceLocation Loc, PragmaIntroducerKind Introducer) override
Definition: PPCallbacksTracker.cpp:173
clang::pp_trace::PPCallbacksTracker::PragmaWarningPush
void PragmaWarningPush(SourceLocation Loc, int Level) override
Definition: PPCallbacksTracker.cpp:285
clang::pp_trace::PPCallbacksTracker::PP
Preprocessor & PP
Definition: PPCallbacksTracker.h:235
clang::pp_trace::PPCallbacksTracker::CallbackIsEnabled
llvm::StringMap< bool > CallbackIsEnabled
Definition: PPCallbacksTracker.h:230
clang::pp_trace::PPCallbacksTracker::Ifdef
void Ifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
Definition: PPCallbacksTracker.cpp:381
clang::pp_trace::PragmaMessageKindStrings
static const char *const PragmaMessageKindStrings[]
Definition: PPCallbacksTracker.cpp:77
clang::pp_trace::PPCallbacksTracker::CallbackCalls
std::vector< CallbackCall > & CallbackCalls
Callback trace information.
Definition: PPCallbacksTracker.h:224
clang::pp_trace::ConditionValueKindStrings
static const char *const ConditionValueKindStrings[]
Definition: PPCallbacksTracker.cpp:88
clang::pp_trace::PPCallbacksTracker::appendArgument
void appendArgument(const char *Name, bool Value)
Append a bool argument to the top trace item.
Definition: PPCallbacksTracker.cpp:430
clang::pp_trace::PPCallbacksTracker::Ident
void Ident(SourceLocation Loc, llvm::StringRef str) override
Definition: PPCallbacksTracker.cpp:166
clang::pp_trace::MacroDirectiveKindStrings
static const char *const MacroDirectiveKindStrings[]
Definition: PPCallbacksTracker.cpp:67
clang::pp_trace::PPCallbacksTracker::FileSkipped
void FileSkipped(const FileEntryRef &SkippedFile, const Token &FilenameTok, SrcMgr::CharacteristicKind FileType) override
Definition: PPCallbacksTracker.cpp:122
Args
llvm::json::Object Args
Definition: Trace.cpp:138
clang::pp_trace::CallbackCall
This class represents one callback call by name and an array of arguments.
Definition: PPCallbacksTracker.h:46
clang::pp_trace::PPCallbacksTracker::EndOfMainFile
void EndOfMainFile() override
Definition: PPCallbacksTracker.cpp:163
clang::pp_trace::PPCallbacksTracker::SourceRangeSkipped
void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override
Definition: PPCallbacksTracker.cpp:354
clang::clangd::replace
static std::string replace(llvm::StringRef Haystack, llvm::StringRef Needle, llvm::StringRef Repl)
Definition: TestIndex.cpp:30
clang::pp_trace::PPCallbacksTracker::appendFilePathArgument
void appendFilePathArgument(const char *Name, llvm::StringRef Value)
Append a double-quoted file path argument to the top trace item.
Definition: PPCallbacksTracker.cpp:648
clang::pp_trace::PPCallbacksTracker::PragmaDetectMismatch
void PragmaDetectMismatch(SourceLocation Loc, llvm::StringRef Name, llvm::StringRef Value) override
Definition: PPCallbacksTracker.cpp:192
Name
Token Name
Definition: MacroToEnumCheck.cpp:89
FileName
StringRef FileName
Definition: KernelNameRestrictionCheck.cpp:46
clang::pp_trace::PPCallbacksTracker::Ifndef
void Ifndef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override
Definition: PPCallbacksTracker.cpp:390
clang::tidy::bugprone::PP
static Preprocessor * PP
Definition: BadSignalToKillThreadCheck.cpp:29
clang::pp_trace::PPCallbacksTracker::getSourceString
llvm::StringRef getSourceString(CharSourceRange Range)
Get the raw source string of the range.
Definition: PPCallbacksTracker.cpp:657
clang::pp_trace::PPCallbacksTracker::PragmaDiagnosticPush
void PragmaDiagnosticPush(SourceLocation Loc, llvm::StringRef Namespace) override
Definition: PPCallbacksTracker.cpp:223
IsAngled
bool IsAngled
true if this was an include with angle brackets
Definition: IncludeOrderCheck.cpp:40
clang::pp_trace::PPCallbacksTracker::Filters
const FilterType & Filters
Definition: PPCallbacksTracker.h:227
clang::pp_trace::PPCallbacksTracker::PragmaDiagnosticPop
void PragmaDiagnosticPop(SourceLocation Loc, llvm::StringRef Namespace) override
Definition: PPCallbacksTracker.cpp:232
Strings
std::vector< llvm::StringRef > Strings
Definition: Serialization.cpp:213
clang::pp_trace::PPCallbacksTracker::PragmaMessage
void PragmaMessage(SourceLocation Loc, llvm::StringRef Namespace, PPCallbacks::PragmaMessageKind Kind, llvm::StringRef Str) override
Definition: PPCallbacksTracker.cpp:210
clang::pp_trace::PPCallbacksTracker::MacroExpands
void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, SourceRange Range, const MacroArgs *Args) override
Definition: PPCallbacksTracker.cpp:315
clang::pp_trace::PPCallbacksTracker::MacroDefined
void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD) override
Definition: PPCallbacksTracker.cpp:327
clang::pp_trace::MappingStrings
static const char *const MappingStrings[]
Definition: PPCallbacksTracker.cpp:93
clang::pp_trace::PPCallbacksTracker::Elif
void Elif(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue, SourceLocation IfLoc) override
Definition: PPCallbacksTracker.cpp:370
clang::pp_trace::PragmaWarningSpecifierStrings
static const char *const PragmaWarningSpecifierStrings[]
Definition: PPCallbacksTracker.cpp:82
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::pp_trace::PPCallbacksTracker::Else
void Else(SourceLocation Loc, SourceLocation IfLoc) override
Definition: PPCallbacksTracker.cpp:399
clang::pp_trace::PPCallbacksTracker::appendQuotedArgument
void appendQuotedArgument(const char *Name, const std::string &Value)
Append a double-quoted argument to the top trace item.
Definition: PPCallbacksTracker.cpp:639
clang::pp_trace::getSourceLocationString
static std::string getSourceLocationString(Preprocessor &PP, SourceLocation Loc)
Definition: PPCallbacksTracker.cpp:25
clang::pp_trace::PPCallbacksTracker::MacroUndefined
void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *Undef) override
Definition: PPCallbacksTracker.cpp:335
ns1::ns2::B
@ B
Definition: CategoricalFeature.h:3
PPCallbacksTracker.h
clang::pp_trace::PPCallbacksTracker::PragmaExecCharsetPush
void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str) override
Definition: PPCallbacksTracker.cpp:299
clang::pp_trace::PPCallbacksTracker::PragmaDebug
void PragmaDebug(SourceLocation Loc, llvm::StringRef DebugType) override
Definition: PPCallbacksTracker.cpp:202
clang::pp_trace::PPCallbacksTracker::PragmaDiagnostic
void PragmaDiagnostic(SourceLocation Loc, llvm::StringRef Namespace, diag::Severity mapping, llvm::StringRef Str) override
Definition: PPCallbacksTracker.cpp:240
Path
std::vector< HeaderHandle > Path
Definition: PreprocessorTracker.cpp:525