clang-tools 6.0.0

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