-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextra.patch
1988 lines (1918 loc) · 71.1 KB
/
extra.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Index: pp-trace/ArgTokens.cpp
===================================================================
--- pp-trace/ArgTokens.cpp (nonexistent)
+++ pp-trace/ArgTokens.cpp (working copy)
@@ -0,0 +1,33 @@
+#include "ArgTokens.h"
+
+void ArgTokens::Init(const MacroDefinition &MD,
+ const clang::MacroArgs *ActArgs, clang::Preprocessor& PP) {
+
+ if (!ActArgs) {
+ return;
+ }
+
+ if (IsInitialized()) {
+ Destroy();
+ }
+
+ const auto DefArgs = MD.getMacroInfo()->args();
+
+ for (auto I = 0u, E = ActArgs->getNumArguments(); I < E; ++I) {
+ auto Current = ActArgs->getUnexpArgument(I);
+ auto TokenCount = ActArgs->getArgLength(Current) + 1;
+ E -= TokenCount;
+ --TokenCount;
+
+ Cache.push_back(std::make_tuple(DefArgs[I]->getName(),
+ std::tuple_element<1, decltype(Cache)::value_type>::type()));
+ for (auto TokenIndex = 0u; TokenIndex < TokenCount; ++TokenIndex, ++Current) {
+ std::get<1>(Cache.back()).push_back(PP.getSpelling(*Current));
+ }
+ }
+}
+
+void ArgTokens::Destroy() {
+ Cache.clear();
+}
+
Index: pp-trace/ArgTokens.h
===================================================================
--- pp-trace/ArgTokens.h (nonexistent)
+++ pp-trace/ArgTokens.h (working copy)
@@ -0,0 +1,37 @@
+#ifndef PPTRACE_ARGTOKENS_H
+#define PPTRACE_ARGTOKENS_H
+
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/MacroArgs.h"
+
+#include <vector>
+
+using namespace clang;
+
+class ArgTokens {
+private:
+
+ // A vector of tuples of strings(parameter) and vectors of (actual args)
+ std::vector<
+ std::tuple<
+ std::string,
+ std::vector<std::string>
+ >
+ > Cache;
+
+public:
+
+ void Init(const MacroDefinition &MacroDefinition, const MacroArgs *ActualArgs,
+ Preprocessor& PP);
+
+ decltype(Cache.cbegin()) begin() const { return Cache.cbegin(); }
+ decltype(Cache.cend()) end() const { return Cache.cend(); }
+ decltype(Cache.size()) size() const { return Cache.size(); }
+
+ bool IsInitialized() const { return !Cache.empty(); }
+
+ void Destroy();
+};
+
+
+#endif // PPTRACE_ARGTOKENS_H
Index: pp-trace/CallbackCall.h
===================================================================
--- pp-trace/CallbackCall.h (nonexistent)
+++ pp-trace/CallbackCall.h (working copy)
@@ -0,0 +1,118 @@
+#ifndef PPTRACE_CALLBACKCALL_H
+#define PPTRACE_CALLBACKCALL_H
+
+#include "ArgTokens.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/SmallSet.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/MacroArgs.h"
+#include <string>
+#include <vector>
+
+
+/// \brief This class represents one callback function argument by name
+/// and value.
+struct Argument {
+ std::string Name;
+ std::string Value;
+};
+
+/// \brief This class represents one callback call by name and an array
+/// of arguments.
+class CallbackCall {
+public:
+ CallbackCall(llvm::StringRef Name) : Name(Name) {}
+ CallbackCall() = default;
+
+ std::string Name;
+ std::vector<Argument> Arguments;
+};
+
+class CallbackCalls {
+private:
+
+ /// \brief Callback trace information.
+ /// We use a reference so the trace will be preserved for the caller
+ /// after this object is destructed.
+ std::vector<CallbackCall> Calls;
+
+public:
+ CallbackCalls(llvm::SmallSet<std::string, 4> &Ignore);
+ virtual ~CallbackCalls() {}
+
+ decltype(Calls.cbegin()) begin() const { return Calls.cbegin(); }
+ decltype(Calls.cend()) end() const { return Calls.cend(); }
+
+ /// \brief Start a new callback.
+ void beginCallback(const char *Name);
+
+ /// \brief Append a bool argument to the top trace item.
+ virtual void appendArgument(const char *Name, bool Value);
+
+ /// \brief Append an int argument to the top trace item.
+ virtual void appendArgument(const char *Name, int Value);
+
+ /// \brief Append a string argument to the top trace item.
+ virtual void appendArgument(const char *Name, const char *Value);
+
+ /// \brief Append a string reference object argument to the top trace item.
+ virtual void appendArgument(const char *Name, llvm::StringRef Value);
+
+ /// \brief Append a string object argument to the top trace item.
+ virtual void appendArgument(const char *Name, const std::string &Value);
+
+ /// \brief Append a token argument to the top trace item.
+ virtual void appendArgument(const char *Name, const clang::Token &Value, clang::Preprocessor& PP);
+
+ /// \brief Append an enum argument to the top trace item.
+ virtual void appendArgument(const char *Name, int Value, const char *const Strings[]);
+
+ /// \brief Append a FileID argument to the top trace item.
+ virtual void appendArgument(const char *Name, clang::FileID Value, clang::Preprocessor& PP);
+
+ /// \brief Append a FileEntry argument to the top trace item.
+ virtual void appendArgument(const char *Name, const clang::FileEntry *Value);
+
+ /// \brief Append a SourceLocation argument to the top trace item.
+ virtual void appendArgument(const char *Name, clang::SourceLocation Value, clang::Preprocessor& PP);
+
+ /// \brief Append a SourceRange argument to the top trace item.
+ virtual void appendArgument(const char *Name, clang::SourceRange Value, clang::Preprocessor& PP);
+
+ /// \brief Append a CharSourceRange argument to the top trace item.
+ virtual void appendArgument(const char *Name, clang::CharSourceRange Value, clang::Preprocessor& PP);
+
+ /// \brief Append a ModuleIdPath argument to the top trace item.
+ virtual void appendArgument(const char *Name, clang::ModuleIdPath Value, clang::Preprocessor& PP);
+
+ /// \brief Append an IdentifierInfo argument to the top trace item.
+ virtual void appendArgument(const char *Name, const clang::IdentifierInfo *Value);
+
+ /// \brief Append a MacroDirective argument to the top trace item.
+ virtual void appendArgument(const char *Name, const clang::MacroDirective *Value);
+
+ /// \brief Append a MacroDefinition argument to the top trace item.
+ virtual void appendArgument(const char *Name, const clang::MacroDefinition &Value);
+
+ /// \brief Append a Module argument to the top trace item.
+ virtual void appendArgument(const char *Name, const clang::Module *Value);
+
+ /// \brief Append an ArgTokens argument to the top trace item.
+ virtual void appendArgument(const char *Name, const ArgTokens *Args);
+
+ /// \brief Append a double-quoted argument to the top trace item.
+ void appendQuotedArgument(const char *Name, const std::string &Value);
+
+ /// \brief Append a double-quoted file path argument to the top trace item.
+ void appendFilePathArgument(const char *Name, llvm::StringRef Value);
+
+private:
+
+ /// \brief Inhibit trace while this is set.
+ bool DisableTrace;
+
+ /// \brief Names of callbacks to ignore.
+ llvm::SmallSet<std::string, 4> &Ignore;
+};
+
+#endif // PPTRACE_CALLBACKCALL_H
Index: pp-trace/CallbackCalls.cpp
===================================================================
--- pp-trace/CallbackCalls.cpp (nonexistent)
+++ pp-trace/CallbackCalls.cpp (working copy)
@@ -0,0 +1,235 @@
+#include "CallbackCall.h"
+#include "Utils.h"
+#include "clang/Lex/Preprocessor.h"
+
+
+// MacroDirective::Kind strings.
+static const char *const MacroDirectiveKindStrings[] = {
+ "MD_Define", "MD_Undefine", "MD_Visibility"
+};
+
+CallbackCalls::CallbackCalls(llvm::SmallSet<std::string, 4> &Ignore)
+ : Ignore(Ignore) { }
+
+// Start a new callback.
+void CallbackCalls::beginCallback(const char *Name) {
+ DisableTrace = Ignore.count(std::string(Name));
+ if (DisableTrace)
+ return;
+ Calls.push_back(CallbackCall(Name));
+}
+
+// Append a bool argument to the top trace item.
+void CallbackCalls::appendArgument(const char *Name, bool Value) {
+ appendArgument(Name, (Value ? "true" : "false"));
+}
+
+// Append an int argument to the top trace item.
+void CallbackCalls::appendArgument(const char *Name, int Value) {
+ std::string Str;
+ llvm::raw_string_ostream SS(Str);
+ SS << Value;
+ appendArgument(Name, SS.str());
+}
+
+// Append a string argument to the top trace item.
+void CallbackCalls::appendArgument(const char *Name, const char *Value) {
+ if (DisableTrace)
+ return;
+ Calls.back().Arguments.push_back(Argument{ Name, Value });
+}
+
+// Append a string object argument to the top trace item.
+void CallbackCalls::appendArgument(const char *Name,
+ llvm::StringRef Value) {
+ appendArgument(Name, Value.str());
+}
+
+// Append a string object argument to the top trace item.
+void CallbackCalls::appendArgument(const char *Name,
+ const std::string &Value) {
+ appendArgument(Name, Value.c_str());
+}
+
+// Append a token argument to the top trace item.
+void CallbackCalls::appendArgument(const char *Name,
+ const clang::Token &Value,
+ clang::Preprocessor& PP) {
+ appendArgument(Name, PP.getSpelling(Value));
+}
+
+// Append an enum argument to the top trace item.
+void CallbackCalls::appendArgument(const char *Name, int Value,
+ const char *const Strings[]) {
+ appendArgument(Name, Strings[Value]);
+}
+
+// Append a FileID argument to the top trace item.
+void CallbackCalls::appendArgument(const char *Name, clang::FileID Value,
+ clang::Preprocessor& PP) {
+ if (Value.isInvalid()) {
+ appendArgument(Name, "(invalid)");
+ return;
+ }
+ const clang::FileEntry *FileEntry =
+ PP.getSourceManager().getFileEntryForID(Value);
+ if (!FileEntry) {
+ appendArgument(Name, "(getFileEntryForID failed)");
+ return;
+ }
+ appendFilePathArgument(Name, FileEntry->getName());
+}
+
+// Append a FileEntry argument to the top trace item.
+void CallbackCalls::appendArgument(const char *Name,
+ const clang::FileEntry *Value) {
+ if (!Value) {
+ appendArgument(Name, "(null)");
+ return;
+ }
+ appendFilePathArgument(Name, Value->getName());
+}
+
+// Append a SourceLocation argument to the top trace item.
+void CallbackCalls::appendArgument(const char *Name,
+ clang::SourceLocation Value,
+ clang::Preprocessor& PP) {
+ if (Value.isInvalid()) {
+ appendArgument(Name, "(invalid)");
+ return;
+ }
+ appendArgument(Name, getSourceLocationString(PP, Value).c_str());
+}
+
+// Append a SourceRange argument to the top trace item.
+void CallbackCalls::appendArgument(const char *Name,
+ clang::SourceRange Value,
+ clang::Preprocessor& PP) {
+ if (DisableTrace)
+ return;
+ if (Value.isInvalid()) {
+ appendArgument(Name, "(invalid)");
+ return;
+ }
+ std::string Str;
+ llvm::raw_string_ostream SS(Str);
+ SS << "[" << getSourceLocationString(PP, Value.getBegin()) << ", "
+ << getSourceLocationString(PP, Value.getEnd()) << "]";
+ appendArgument(Name, SS.str());
+}
+
+// Append a CharSourceRange argument to the top trace item.
+void CallbackCalls::appendArgument(const char *Name,
+ clang::CharSourceRange Value,
+ clang::Preprocessor& PP) {
+ if (Value.isInvalid()) {
+ appendArgument(Name, "(invalid)");
+ return;
+ }
+ appendArgument(Name, getSourceString<clang::CharSourceRange>(PP, Value).str().c_str());
+}
+
+// Append a SourceLocation argument to the top trace item.
+void CallbackCalls::appendArgument(const char *Name,
+ clang::ModuleIdPath Value,
+ clang::Preprocessor& PP) {
+ if (DisableTrace)
+ return;
+ std::string Str;
+ llvm::raw_string_ostream SS(Str);
+ SS << "[";
+ for (int I = 0, E = Value.size(); I != E; ++I) {
+ if (I)
+ SS << ", ";
+ SS << "{"
+ << "Name: " << Value[I].first->getName() << ", "
+ << "Loc: " << getSourceLocationString(PP, Value[I].second) << "}";
+ }
+ SS << "]";
+ appendArgument(Name, SS.str());
+}
+
+// Append an IdentifierInfo argument to the top trace item.
+void CallbackCalls::appendArgument(const char *Name,
+ const clang::IdentifierInfo *Value) {
+ if (!Value) {
+ appendArgument(Name, "(null)");
+ return;
+ }
+ appendArgument(Name, Value->getName().str().c_str());
+}
+
+// Append a MacroDirective argument to the top trace item.
+void CallbackCalls::appendArgument(const char *Name,
+ const clang::MacroDirective *Value) {
+ if (!Value) {
+ appendArgument(Name, "(null)");
+ return;
+ }
+ appendArgument(Name, MacroDirectiveKindStrings[Value->getKind()]);
+}
+
+// Append a MacroDefinition argument to the top trace item.
+void CallbackCalls::appendArgument(const char *Name,
+ const clang::MacroDefinition &Value) {
+ std::string Str;
+ llvm::raw_string_ostream SS(Str);
+ SS << "[";
+ bool Any = false;
+ if (Value.getLocalDirective()) {
+ SS << "(local)";
+ Any = true;
+ }
+ for (auto *MM : Value.getModuleMacros()) {
+ if (Any)
+ SS << ", ";
+ SS << MM->getOwningModule()->getFullModuleName();
+ }
+ SS << "]";
+ appendArgument(Name, SS.str());
+}
+
+// Append a Module argument to the top trace item.
+void CallbackCalls::appendArgument(const char *Name,
+ const clang::Module *Value) {
+ if (!Value) {
+ appendArgument(Name, "(null)");
+ return;
+ }
+ appendArgument(Name, Value->Name.c_str());
+}
+
+// Append an ArgTokens argument to the top trace item.
+void CallbackCalls::appendArgument(const char *Name, const ArgTokens *Args) {
+ std::string s;
+ llvm::raw_string_ostream SS(s);
+ for (const auto& arg : *Args) {
+ SS << "\n - ";
+ SS << std::get<0>(arg) << ": ";
+ const auto& subargs = std::get<1>(arg);
+
+ for (auto subarg = subargs.cbegin(); subarg < subargs.cend(); ++subarg) {
+ SS << *subarg;
+ }
+ }
+
+ appendArgument(Name, SS.str());
+}
+
+// Append a double-quoted argument to the top trace item.
+void CallbackCalls::appendQuotedArgument(const char *Name,
+ const std::string &Value) {
+ std::string Str;
+ llvm::raw_string_ostream SS(Str);
+ SS << "\"" << Value << "\"";
+ appendArgument(Name, SS.str());
+}
+
+// Append a double-quoted file path argument to the top trace item.
+void CallbackCalls::appendFilePathArgument(const char *Name,
+ llvm::StringRef Value) {
+ std::string Path(Value);
+ // YAML treats backslash as escape, so use forward slashes.
+ std::replace(Path.begin(), Path.end(), '\\', '/');
+ appendQuotedArgument(Name, Path);
+}
Index: pp-trace/CMakeLists.txt
===================================================================
--- pp-trace/CMakeLists.txt (revision 302379)
+++ pp-trace/CMakeLists.txt (working copy)
@@ -5,6 +5,9 @@
add_clang_executable(pp-trace
PPTrace.cpp
PPCallbacksTracker.cpp
+ VerboseDecorator.cpp
+ CallbackCalls.cpp
+ ArgTokens.cpp
)
target_link_libraries(pp-trace
Index: pp-trace/PPCallbacksTracker.cpp
===================================================================
--- pp-trace/PPCallbacksTracker.cpp (revision 302379)
+++ pp-trace/PPCallbacksTracker.cpp (working copy)
@@ -15,42 +15,9 @@
//===----------------------------------------------------------------------===//
#include "PPCallbacksTracker.h"
-#include "clang/Lex/MacroArgs.h"
#include "llvm/Support/raw_ostream.h"
-// Utility functions.
-// Get a "file:line:column" source location string.
-static std::string getSourceLocationString(clang::Preprocessor &PP,
- clang::SourceLocation Loc) {
- if (Loc.isInvalid())
- return std::string("(none)");
-
- if (Loc.isFileID()) {
- clang::PresumedLoc PLoc = PP.getSourceManager().getPresumedLoc(Loc);
-
- if (PLoc.isInvalid()) {
- return std::string("(invalid)");
- }
-
- std::string Str;
- llvm::raw_string_ostream SS(Str);
-
- // The macro expansion and spelling pos is identical for file locs.
- SS << "\"" << PLoc.getFilename() << ':' << PLoc.getLine() << ':'
- << PLoc.getColumn() << "\"";
-
- std::string Result = SS.str();
-
- // YAML treats backslash as escape, so use forward slashes.
- std::replace(Result.begin(), Result.end(), '\\', '/');
-
- return Result;
- }
-
- return std::string("(nonfile)");
-}
-
// Enum string tables.
// FileChangeReason strings.
@@ -62,10 +29,6 @@
static const char *const CharacteristicKindStrings[] = { "C_User", "C_System",
"C_ExternCSystem" };
-// MacroDirective::Kind strings.
-static const char *const MacroDirectiveKindStrings[] = {
- "MD_Define","MD_Undefine", "MD_Visibility"
-};
// PragmaIntroducerKind strings.
static const char *const PragmaIntroducerKindStrings[] = { "PIK_HashPragma",
@@ -89,13 +52,25 @@
// PPCallbacksTracker functions.
-PPCallbacksTracker::PPCallbacksTracker(llvm::SmallSet<std::string, 4> &Ignore,
- std::vector<CallbackCall> &CallbackCalls,
+PPCallbacksTracker::PPCallbacksTracker(CallbackCalls &CallbackCalls,
clang::Preprocessor &PP)
- : CallbackCalls(CallbackCalls), Ignore(Ignore), PP(PP) {}
+ : Calls(CallbackCalls), PP(PP) {
+ llvm::outs() << "PPCallbacksTracker CTOR\n";
+}
-PPCallbacksTracker::~PPCallbacksTracker() {}
+PPCallbacksTracker::PPCallbacksTracker(PPCallbacksTracker&& o)
+ : Calls(o.Calls), PP(o.PP) {
+
+ llvm::outs() << "MOVE CTOR\n";
+}
+
+PPCallbacksTracker& PPCallbacksTracker::operator=(PPCallbacksTracker&& o) {
+ llvm::outs() << "MOVE ASSIGN\n";
+
+ return *this;
+}
+
// Callback functions.
// Callback invoked whenever a source file is entered or exited.
@@ -102,11 +77,11 @@
void PPCallbacksTracker::FileChanged(
clang::SourceLocation Loc, clang::PPCallbacks::FileChangeReason Reason,
clang::SrcMgr::CharacteristicKind FileType, clang::FileID PrevFID) {
- beginCallback("FileChanged");
- appendArgument("Loc", Loc);
- appendArgument("Reason", Reason, FileChangeReasonStrings);
- appendArgument("FileType", FileType, CharacteristicKindStrings);
- appendArgument("PrevFID", PrevFID);
+ Calls.beginCallback("FileChanged");
+ Calls.appendArgument("Loc", Loc, PP);
+ Calls.appendArgument("Reason", Reason, FileChangeReasonStrings);
+ Calls.appendArgument("FileType", FileType, CharacteristicKindStrings);
+ Calls.appendArgument("PrevFID", PrevFID, PP);
}
// Callback invoked whenever a source file is skipped as the result
@@ -115,10 +90,10 @@
PPCallbacksTracker::FileSkipped(const clang::FileEntry &SkippedFile,
const clang::Token &FilenameTok,
clang::SrcMgr::CharacteristicKind FileType) {
- beginCallback("FileSkipped");
- appendArgument("ParentFile", &SkippedFile);
- appendArgument("FilenameTok", FilenameTok);
- appendArgument("FileType", FileType, CharacteristicKindStrings);
+ Calls.beginCallback("FileSkipped");
+ Calls.appendArgument("ParentFile", &SkippedFile);
+ Calls.appendArgument("FilenameTok", FilenameTok, PP);
+ Calls.appendArgument("FileType", FileType, CharacteristicKindStrings);
}
// Callback invoked whenever an inclusion directive results in a
@@ -126,8 +101,8 @@
bool
PPCallbacksTracker::FileNotFound(llvm::StringRef FileName,
llvm::SmallVectorImpl<char> &RecoveryPath) {
- beginCallback("FileNotFound");
- appendFilePathArgument("FileName", FileName);
+ Calls.beginCallback("FileNotFound");
+ Calls.appendFilePathArgument("FileName", FileName);
return false;
}
@@ -140,15 +115,15 @@
clang::CharSourceRange FilenameRange, const clang::FileEntry *File,
llvm::StringRef SearchPath, llvm::StringRef RelativePath,
const clang::Module *Imported) {
- beginCallback("InclusionDirective");
- appendArgument("IncludeTok", IncludeTok);
- appendFilePathArgument("FileName", FileName);
- appendArgument("IsAngled", IsAngled);
- appendArgument("FilenameRange", FilenameRange);
- appendArgument("File", File);
- appendFilePathArgument("SearchPath", SearchPath);
- appendFilePathArgument("RelativePath", RelativePath);
- appendArgument("Imported", Imported);
+ Calls.beginCallback("InclusionDirective");
+ Calls.appendArgument("IncludeTok", IncludeTok, PP);
+ Calls.appendFilePathArgument("FileName", FileName);
+ Calls.appendArgument("IsAngled", IsAngled);
+ Calls.appendArgument("FilenameRange", FilenameRange, PP);
+ Calls.appendArgument("File", File);
+ Calls.appendFilePathArgument("SearchPath", SearchPath);
+ Calls.appendFilePathArgument("RelativePath", RelativePath);
+ Calls.appendArgument("Imported", Imported);
}
// Callback invoked whenever there was an explicit module-import
@@ -156,21 +131,21 @@
void PPCallbacksTracker::moduleImport(clang::SourceLocation ImportLoc,
clang::ModuleIdPath Path,
const clang::Module *Imported) {
- beginCallback("moduleImport");
- appendArgument("ImportLoc", ImportLoc);
- appendArgument("Path", Path);
- appendArgument("Imported", Imported);
+ Calls.beginCallback("moduleImport");
+ Calls.appendArgument("ImportLoc", ImportLoc, PP);
+ Calls.appendArgument("Path", Path, PP);
+ Calls.appendArgument("Imported", Imported);
}
// Callback invoked when the end of the main file is reached.
// No subsequent callbacks will be made.
-void PPCallbacksTracker::EndOfMainFile() { beginCallback("EndOfMainFile"); }
+void PPCallbacksTracker::EndOfMainFile() { Calls.beginCallback("EndOfMainFile"); }
// Callback invoked when a #ident or #sccs directive is read.
void PPCallbacksTracker::Ident(clang::SourceLocation Loc, llvm::StringRef Str) {
- beginCallback("Ident");
- appendArgument("Loc", Loc);
- appendArgument("Str", Str);
+ Calls.beginCallback("Ident");
+ Calls.appendArgument("Loc", Loc, PP);
+ Calls.appendArgument("Str", Str);
}
// Callback invoked when start reading any pragma directive.
@@ -177,9 +152,9 @@
void
PPCallbacksTracker::PragmaDirective(clang::SourceLocation Loc,
clang::PragmaIntroducerKind Introducer) {
- beginCallback("PragmaDirective");
- appendArgument("Loc", Loc);
- appendArgument("Introducer", Introducer, PragmaIntroducerKindStrings);
+ Calls.beginCallback("PragmaDirective");
+ Calls.appendArgument("Loc", Loc, PP);
+ Calls.appendArgument("Introducer", Introducer, PragmaIntroducerKindStrings);
}
// Callback invoked when a #pragma comment directive is read.
@@ -186,10 +161,10 @@
void PPCallbacksTracker::PragmaComment(clang::SourceLocation Loc,
const clang::IdentifierInfo *Kind,
llvm::StringRef Str) {
- beginCallback("PragmaComment");
- appendArgument("Loc", Loc);
- appendArgument("Kind", Kind);
- appendArgument("Str", Str);
+ Calls.beginCallback("PragmaComment");
+ Calls.appendArgument("Loc", Loc, PP);
+ Calls.appendArgument("Kind", Kind);
+ Calls.appendArgument("Str", Str);
}
// Callback invoked when a #pragma detect_mismatch directive is
@@ -197,18 +172,18 @@
void PPCallbacksTracker::PragmaDetectMismatch(clang::SourceLocation Loc,
llvm::StringRef Name,
llvm::StringRef Value) {
- beginCallback("PragmaDetectMismatch");
- appendArgument("Loc", Loc);
- appendArgument("Name", Name);
- appendArgument("Value", Value);
+ Calls.beginCallback("PragmaDetectMismatch");
+ Calls.appendArgument("Loc", Loc, PP);
+ Calls.appendArgument("Name", Name);
+ Calls.appendArgument("Value", Value);
}
// Callback invoked when a #pragma clang __debug directive is read.
void PPCallbacksTracker::PragmaDebug(clang::SourceLocation Loc,
llvm::StringRef DebugType) {
- beginCallback("PragmaDebug");
- appendArgument("Loc", Loc);
- appendArgument("DebugType", DebugType);
+ Calls.beginCallback("PragmaDebug");
+ Calls.appendArgument("Loc", Loc, PP);
+ Calls.appendArgument("DebugType", DebugType);
}
// Callback invoked when a #pragma message directive is read.
@@ -215,11 +190,11 @@
void PPCallbacksTracker::PragmaMessage(
clang::SourceLocation Loc, llvm::StringRef Namespace,
clang::PPCallbacks::PragmaMessageKind Kind, llvm::StringRef Str) {
- beginCallback("PragmaMessage");
- appendArgument("Loc", Loc);
- appendArgument("Namespace", Namespace);
- appendArgument("Kind", Kind, PragmaMessageKindStrings);
- appendArgument("Str", Str);
+ Calls.beginCallback("PragmaMessage");
+ Calls.appendArgument("Loc", Loc, PP);
+ Calls.appendArgument("Namespace", Namespace);
+ Calls.appendArgument("Kind", Kind, PragmaMessageKindStrings);
+ Calls.appendArgument("Str", Str);
}
// Callback invoked when a #pragma gcc dianostic push directive
@@ -226,9 +201,9 @@
// is read.
void PPCallbacksTracker::PragmaDiagnosticPush(clang::SourceLocation Loc,
llvm::StringRef Namespace) {
- beginCallback("PragmaDiagnosticPush");
- appendArgument("Loc", Loc);
- appendArgument("Namespace", Namespace);
+ Calls.beginCallback("PragmaDiagnosticPush");
+ Calls.appendArgument("Loc", Loc, PP);
+ Calls.appendArgument("Namespace", Namespace);
}
// Callback invoked when a #pragma gcc dianostic pop directive
@@ -235,9 +210,9 @@
// is read.
void PPCallbacksTracker::PragmaDiagnosticPop(clang::SourceLocation Loc,
llvm::StringRef Namespace) {
- beginCallback("PragmaDiagnosticPop");
- appendArgument("Loc", Loc);
- appendArgument("Namespace", Namespace);
+ Calls.beginCallback("PragmaDiagnosticPop");
+ Calls.appendArgument("Loc", Loc, PP);
+ Calls.appendArgument("Namespace", Namespace);
}
// Callback invoked when a #pragma gcc dianostic directive is read.
@@ -245,11 +220,11 @@
llvm::StringRef Namespace,
clang::diag::Severity Mapping,
llvm::StringRef Str) {
- beginCallback("PragmaDiagnostic");
- appendArgument("Loc", Loc);
- appendArgument("Namespace", Namespace);
- appendArgument("Mapping", (unsigned)Mapping, MappingStrings);
- appendArgument("Str", Str);
+ Calls.beginCallback("PragmaDiagnostic");
+ Calls.appendArgument("Loc", Loc, PP);
+ Calls.appendArgument("Namespace", Namespace);
+ Calls.appendArgument("Mapping", (unsigned)Mapping, MappingStrings);
+ Calls.appendArgument("Str", Str);
}
// Called when an OpenCL extension is either disabled or
@@ -257,11 +232,11 @@
void PPCallbacksTracker::PragmaOpenCLExtension(
clang::SourceLocation NameLoc, const clang::IdentifierInfo *Name,
clang::SourceLocation StateLoc, unsigned State) {
- beginCallback("PragmaOpenCLExtension");
- appendArgument("NameLoc", NameLoc);
- appendArgument("Name", Name);
- appendArgument("StateLoc", StateLoc);
- appendArgument("State", (int)State);
+ Calls.beginCallback("PragmaOpenCLExtension");
+ Calls.appendArgument("NameLoc", NameLoc, PP);
+ Calls.appendArgument("Name", Name);
+ Calls.appendArgument("StateLoc", StateLoc, PP);
+ Calls.appendArgument("State", (int)State);
}
// Callback invoked when a #pragma warning directive is read.
@@ -268,9 +243,9 @@
void PPCallbacksTracker::PragmaWarning(clang::SourceLocation Loc,
llvm::StringRef WarningSpec,
llvm::ArrayRef<int> Ids) {
- beginCallback("PragmaWarning");
- appendArgument("Loc", Loc);
- appendArgument("WarningSpec", WarningSpec);
+ Calls.beginCallback("PragmaWarning");
+ Calls.appendArgument("Loc", Loc, PP);
+ Calls.appendArgument("WarningSpec", WarningSpec);
std::string Str;
llvm::raw_string_ostream SS(Str);
@@ -281,21 +256,21 @@
SS << Ids[i];
}
SS << "]";
- appendArgument("Ids", SS.str());
+ Calls.appendArgument("Ids", SS.str());
}
// Callback invoked when a #pragma warning(push) directive is read.
void PPCallbacksTracker::PragmaWarningPush(clang::SourceLocation Loc,
int Level) {
- beginCallback("PragmaWarningPush");
- appendArgument("Loc", Loc);
- appendArgument("Level", Level);
+ Calls.beginCallback("PragmaWarningPush");
+ Calls.appendArgument("Loc", Loc, PP);
+ Calls.appendArgument("Level", Level);
}
// Callback invoked when a #pragma warning(pop) directive is read.
void PPCallbacksTracker::PragmaWarningPop(clang::SourceLocation Loc) {
- beginCallback("PragmaWarningPop");
- appendArgument("Loc", Loc);
+ Calls.beginCallback("PragmaWarningPop");
+ Calls.appendArgument("Loc", Loc, PP);
}
// Called by Preprocessor::HandleMacroExpandedIdentifier when a
@@ -305,11 +280,15 @@
const clang::MacroDefinition &MacroDefinition,
clang::SourceRange Range,
const clang::MacroArgs *Args) {
- beginCallback("MacroExpands");
- appendArgument("MacroNameTok", MacroNameTok);
- appendArgument("MacroDefinition", MacroDefinition);
- appendArgument("Range", Range);
- appendArgument("Args", Args);
+ Calls.beginCallback("MacroExpands");
+ Calls.appendArgument("MacroNameTok", MacroNameTok, PP);
+ Calls.appendArgument("MacroDefinition", MacroDefinition);
+ Calls.appendArgument("Range", Range, PP);
+
+ if (MacroDefinition.getMacroInfo()->isFunctionLike()) {
+ CurrArgs.Init(MacroDefinition, Args, PP);
+ Calls.appendArgument("Args", &CurrArgs);
+ }
}
// Hook called whenever a macro definition is seen.
@@ -316,9 +295,9 @@
void
PPCallbacksTracker::MacroDefined(const clang::Token &MacroNameTok,
const clang::MacroDirective *MacroDirective) {
- beginCallback("MacroDefined");
- appendArgument("MacroNameTok", MacroNameTok);
- appendArgument("MacroDirective", MacroDirective);
+ Calls.beginCallback("MacroDefined");
+ Calls.appendArgument("MacroNameTok", MacroNameTok, PP);
+ Calls.appendArgument("MacroDirective", MacroDirective);
}
// Hook called whenever a macro #undef is seen.
@@ -326,9 +305,9 @@
const clang::Token &MacroNameTok,
const clang::MacroDefinition &MacroDefinition,
const clang::MacroDirective *Undef) {
- beginCallback("MacroUndefined");
- appendArgument("MacroNameTok", MacroNameTok);
- appendArgument("MacroDefinition", MacroDefinition);
+ Calls.beginCallback("MacroUndefined");
+ Calls.appendArgument("MacroNameTok", MacroNameTok, PP);
+ Calls.appendArgument("MacroDefinition", MacroDefinition);
}
// Hook called whenever the 'defined' operator is seen.
@@ -335,16 +314,16 @@
void PPCallbacksTracker::Defined(const clang::Token &MacroNameTok,
const clang::MacroDefinition &MacroDefinition,
clang::SourceRange Range) {
- beginCallback("Defined");
- appendArgument("MacroNameTok", MacroNameTok);
- appendArgument("MacroDefinition", MacroDefinition);
- appendArgument("Range", Range);
+ Calls.beginCallback("Defined");
+ Calls.appendArgument("MacroNameTok", MacroNameTok, PP);
+ Calls.appendArgument("MacroDefinition", MacroDefinition);
+ Calls.appendArgument("Range", Range, PP);
}
// Hook called when a source range is skipped.
void PPCallbacksTracker::SourceRangeSkipped(clang::SourceRange Range) {
- beginCallback("SourceRangeSkipped");
- appendArgument("Range", Range);
+ Calls.beginCallback("SourceRangeSkipped");
+ Calls.appendArgument("Range", Range, PP);
}
// Hook called whenever an #if is seen.
@@ -351,10 +330,10 @@
void PPCallbacksTracker::If(clang::SourceLocation Loc,
clang::SourceRange ConditionRange,
ConditionValueKind ConditionValue) {
- beginCallback("If");
- appendArgument("Loc", Loc);
- appendArgument("ConditionRange", ConditionRange);
- appendArgument("ConditionValue", ConditionValue, ConditionValueKindStrings);
+ Calls.beginCallback("If");
+ Calls.appendArgument("Loc", Loc, PP);
+ Calls.appendArgument("ConditionRange", ConditionRange, PP);
+ Calls.appendArgument("ConditionValue", ConditionValue, ConditionValueKindStrings);
}
// Hook called whenever an #elif is seen.
@@ -362,11 +341,11 @@
clang::SourceRange ConditionRange,
ConditionValueKind ConditionValue,
clang::SourceLocation IfLoc) {
- beginCallback("Elif");
- appendArgument("Loc", Loc);
- appendArgument("ConditionRange", ConditionRange);
- appendArgument("ConditionValue", ConditionValue, ConditionValueKindStrings);
- appendArgument("IfLoc", IfLoc);
+ Calls.beginCallback("Elif");
+ Calls.appendArgument("Loc", Loc, PP);
+ Calls.appendArgument("ConditionRange", ConditionRange, PP);
+ Calls.appendArgument("ConditionValue", ConditionValue, ConditionValueKindStrings);
+ Calls.appendArgument("IfLoc", IfLoc, PP);
}
// Hook called whenever an #ifdef is seen.
@@ -373,10 +352,10 @@
void PPCallbacksTracker::Ifdef(clang::SourceLocation Loc,
const clang::Token &MacroNameTok,
const clang::MacroDefinition &MacroDefinition) {
- beginCallback("Ifdef");
- appendArgument("Loc", Loc);
- appendArgument("MacroNameTok", MacroNameTok);
- appendArgument("MacroDefinition", MacroDefinition);
+ Calls.beginCallback("Ifdef");
+ Calls.appendArgument("Loc", Loc, PP);
+ Calls.appendArgument("MacroNameTok", MacroNameTok, PP);
+ Calls.appendArgument("MacroDefinition", MacroDefinition);
}
// Hook called whenever an #ifndef is seen.
@@ -383,272 +362,34 @@
void PPCallbacksTracker::Ifndef(clang::SourceLocation Loc,
const clang::Token &MacroNameTok,
const clang::MacroDefinition &MacroDefinition) {
- beginCallback("Ifndef");
- appendArgument("Loc", Loc);
- appendArgument("MacroNameTok", MacroNameTok);
- appendArgument("MacroDefinition", MacroDefinition);
+ Calls.beginCallback("Ifndef");
+ Calls.appendArgument("Loc", Loc, PP);
+ Calls.appendArgument("MacroNameTok", MacroNameTok, PP);
+ Calls.appendArgument("MacroDefinition", MacroDefinition);
}
// Hook called whenever an #else is seen.
void PPCallbacksTracker::Else(clang::SourceLocation Loc,
clang::SourceLocation IfLoc) {
- beginCallback("Else");
- appendArgument("Loc", Loc);
- appendArgument("IfLoc", IfLoc);
+ Calls.beginCallback("Else");
+ Calls.appendArgument("Loc", Loc, PP);
+ Calls.appendArgument("IfLoc", IfLoc, PP);
}
// Hook called whenever an #endif is seen.
void PPCallbacksTracker::Endif(clang::SourceLocation Loc,
clang::SourceLocation IfLoc) {
- beginCallback("Endif");
- appendArgument("Loc", Loc);
- appendArgument("IfLoc", IfLoc);
+ Calls.beginCallback("Endif");
+ Calls.appendArgument("Loc", Loc, PP);
+ Calls.appendArgument("IfLoc", IfLoc, PP);
}
-// Helper functions.
-
-// Start a new callback.
-void PPCallbacksTracker::beginCallback(const char *Name) {
- DisableTrace = Ignore.count(std::string(Name));
- if (DisableTrace)
- return;
- CallbackCalls.push_back(CallbackCall(Name));
+void PPCallbacksTracker::RecursiveExpansion(const clang::Token & Tok)
+{
+ auto B = getCharacterData(PP, Tok.getLocation());
+ auto tok = llvm::StringRef(B, Tok.getLength());
+ Calls.beginCallback("RecursiveExpansion");
+ Calls.appendArgument("MacroNameTok", tok);
}
-// Append a bool argument to the top trace item.
-void PPCallbacksTracker::appendArgument(const char *Name, bool Value) {
- appendArgument(Name, (Value ? "true" : "false"));
-}
-
-// Append an int argument to the top trace item.
-void PPCallbacksTracker::appendArgument(const char *Name, int Value) {
- std::string Str;
- llvm::raw_string_ostream SS(Str);
- SS << Value;
- appendArgument(Name, SS.str());
-}
-
-// Append a string argument to the top trace item.
-void PPCallbacksTracker::appendArgument(const char *Name, const char *Value) {
- if (DisableTrace)