-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgSTLFilt.pl
2062 lines (1689 loc) · 71.2 KB
/
gSTLFilt.pl
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
################################################################################################################
# gSTLFilt.pl: BD Software STL Error Message Decryptor (a Perl script)
# This version supports the gcc 2/3/4 C++ compiler/library
# It was tested under:
# DJGPP 2.95.2
# MinGW gcc 2.95.2, 3.2.3, 3.4.5, 4.1.1
# TDM gcc 4.2.2
#
$STLFilt_ID = "BD Software STL Message Decryptor v3.10 for gcc 2/3/4";
#
# (c) Copyright Leor Zolman 2002-2008. Permission to copy, use, modify, sell and
# distribute this software is granted provided this copyright notice appears
# in all copies. This software is provided "as is" without express or implied
# warranty, and with no claim as to its suitability for any purpose.
#
#################################################################################################################
# Visit www.bdsoft.com for information about BD Software's on-site training seminars #
# in C, C++, STL, Perl, Unix Fundamentals and Korn Shell Programming #
#################################################################################################################
#
# For quick installation instructions for the STL Error Decryptor, see QUICKSTART.txt.
# For manifest and other general information, see README.txt
#
# (Note: hard tab setting for this source file is: 4)
#
# Purpose: Transform STL template-based typenames from gcc error messages
# into a minimal, *readable* format. We might lose some details...
# but retain our sanity!
#
# This script may be used in several different ways:
# 1) With the "Proxy C++" program, C++.EXE (from the command-line or from within Dev-CPP)
# 2) With a batch/shell script driver for command-line use...
# For Windows: The companion batch file GFILT.BAT is provided as a sample driver for this script
# For Unix/Linux/OS X: The companion shell script "gfilt" is provided as a sample driver for
# this script, allowing arbitrary intermixing of compiler and Decryptor options
# on the command line.
#
# Acknowledgements:
# Scott Meyers taught his "Effective STL" seminar, where the project began.
# Thomas Becker wrote and helps me maintain the Win32 piping code used throughout both C++.CPP and
# the Perl scripts, keeping everyone talking despite all the curves thrown him (so far) by
# ActiveState and Microsoft. THANK YOU, Thomas!
# David Abrahams designed the long-typename-wrapping algorithm and continues to contribute actively
# to its evolution.
# David Smallberg came up with the "Proxy compiler" idea (but blame me for the name).
#
# For the complete list of folks whose feedback and de-bugging help contributed to this
# package, and also for the list of programming courses BD Software offers, see README.txt.
#
#
#################################################################################################################
#
# Script Options
# --------------
#
# Command line options are case insensitive, and may be preceded by either '-' or '/'.
# The Proxy C++, if being used, supplies many of these options as per settings in the
# Proxy-gcc.INI configuration file.
#
# Note that some of the Decryptor's behavior is controlled via command-line options,
# while other behavior may only be configured via hard-wired variable settings. Please
# examine the entire "User-Configurable Settings" section below to become familiar with
# all the customizable features.
#
# General options:
#
# -iter:x Set iterator policy to x, where x is s[short], m[edium] or l[ong]
# (See the assignments of $def_iter_policy and $newiter below for details)
#
# -cand:x Set "candidates" policy to x, where x is L[ong], M[edium] or S[hort]
# (See the assignment of $def_cand_policy below for details)
#
# -hdr:x Set STL header policy to x or nn, where x is L[ong], M[edium], or S[hort],
# -hdr:nn or nn is the # of errors to show in a cluster
# -hdr:LD Dave Abrahams re-ordering mode 1 (see below)
# -hdr:LD1 save as above
# -hdr:LD2 Dave Abrahams re-ordering mode 2
# (See the assignment of $def_hdr_policy below for details)
#
# -with:x Set "with clause" substitution policy to x, where x is L[ong] or S[hort]
# (See the assignment of $def_with_policy below for details)
#
# -path:x Set "show long pathnames" policy to x, where x is l[ong] or s[hort]
# (See the assignment of $def_path_policy below for details)
#
# -showback:x Set backtrace policy: Y (default) or N (suppress all backtrace lines)
#
# -width:nn Set output line width (break message lines at this column, or 0 for NO wrapping)
#
# -lognative Log all native messages to NativeLog.txt (for de-bugging)
#
# -banner:x Show Decryptor banner line: Y (default) or N
#
# -nullarg:xxx Add xxx to the list of "null argument" typenames that get stripped from the
# trailing portion of template argument lists. (See also the initializations of
# variable @nullargs). xxx must be fully qualified (including namespace).
#
# if xxx is 'clear', the null argument list is emptied; subsequent -nullarg
# specification appearing on the command line will work, but not the defaults
# as per the initialization of @nullargs below (unless they're re-specified
# using the -nullarg option later on the commmad line.)
#
# Options supporting long typename wrapping:
#
# (Note: If output width is set to 0, line wrapping is disabled and the
# following options have NO EFFECT)
#
# -break:x Break algorithm: D[ave Abrahams] (default) or P[lain]
# The "Dave" option wraps long complex typenames in a way that
# makes it easier to see parameter lists at various nesting depths.
#
# -cbreak:x Comma break: B = break before commas (default), A = break after
# [applies only in -break:D mode]
#
# -closewrap:x Wrap before unmatched closing delimiters: Y (default) or N
# [applies only in -break:D mode]
#
# -meta:x Configure for metaprogramming [Y] or vanilla wrapping [N] as follows:
#
# -meta:y (or just -meta) forces -break:D, and forces -cbreak and
# -closewrap options according to values specified in the $meta_y_cbreak
# and $meta_y_closewrap variable initializations, respectively.
#
# -meta:n forces -break:P (-cbreak and -closewrap don't apply)
#
# In either case, if the output width hasn't yet been set to a non-zero
# value, it is set to 80 (choosing a wrapping flavor makes no sense
# with wrapping disabled); this may be overridden by a subsequent -width
# option.
#
# Note: If no -meta option is present, the default values for -break,
# -cbreak and -closewrap are determined by the user-configurable
# settings of $break_algorithm, $comma_wrap and $close_wrap below.
#
# Note also that -meta is not configurable from the INI files, because
# it is intended as a command-line "override" mechanism. The individual
# settings of -break, -cbreak and -closewrap, however, *are* (and apply
# only when the /meta option is not used.)
#
#################################################################################################################
# User-configurable settings (use UPPER CASE ONLY for all alphabetics here (except $newiter):
#
####################################################################################
# The following twelve settings may be overridden by options on
# the command line (either explicitly, or when conveyed by the
# Proxy C++ from settings in Proxy-gcc.INI):
# default iterator policy (/iter:x option):
$def_iter_policy = 'L'; # 'L' (Long): NEVER remove iterator type name qualification
# 'M' (Medium): USUALLY remove iterator type name qualification
# leave intact when iter type may be significant
# to the diagnostic
# 'S' (Short): ALWAYS remove iterator type name qualification
$def_cand_policy = 'L'; # default candidate policy (/cand:x option):
# 'L' (long): Retain candidate list (same as: 'Y')
# 'M' (medium): Suppress candidates, but tell how many were suppressed
# 'S' (short): completely ignore candidate list (same as: 'N')
$def_hdr_policy = 'LD2'; # default standard header messages policy (/hdr:x option):
# 'L' (long): Retain all messages referring to standard header files (same as 'Y')
# 'M' (medium): Retain only the first $headers_to_show messages in each cluster
# 'S' (short): Discard all messages referring to standard header files (same as 'N')
# 'LD[1]' (long, Dave Abrahams re-ordering mode 1):
# actual error msg moves to front of instantiation backtrace
# 'LD2' (long, Dave Abrahams re-ordering mode 2):
# as above, with trigger line duplicated before the backtrace
$def_with_policy = 'S'; # default "with clause" substitution policy (/with:x option):
# 'L' (long): Do NOT substitute in template parameters in "with" clauses
# 'S' (short): Do substitute template parameters in "with" clauses
$def_path_policy = 'S'; # default long path policy (/path:x option):
# 'L' (long): Retain entire pathname in all cases (same as 'Y')
# 'S' (short): Discard all except base name from pathnames (same as 'N')
# [NOTE: Use L if you rely upon your IDE to locate errors in source files]
$def_hdrs_to_show = 1; # Default number of header messages to show for 'M' header policy
$banner = 'Y'; # Show banner with Decryptor ID by default (/banner option)
$break_algorithm = 'D'; # P[lain] or D[ave Abrahams] line-breaking algorithm (/break:x option)
# (Note: line-breaking of any kind happens only if $output_width is non-zero)
$comma_wrap = 'B'; # wrap lines B[efore] or A[fter] commas. (/cbreak:x option)
# (Applies in Dave mode only.)
$close_wrap = 'Y'; # Force a break before close delimiters
# whose open is not on the same line (/closewrap:x option)
# (Applies in Dave mode only.)
$output_width = 80; # wrap at 80 columns by default (/width:nn option)
$show_backtraces = 'Y'; # show (Y) or suppress (N) backtrace messages (/showback:x option)
#####################################################################################
# The remaining settings are controlled strictly by their assigned
# value below (no corresponding command-line options offered):
$newiter = 'iter'; # ('iter' or 'IT' or...) shorten the word "iterator" to this
# Note: /iter:L forces $newiter to be 'iterator' (no filtering)
$tabsize = 4; # number of chars to incrementally indent lines
$advise_re_policy_opts = 1; # remind folks they can use /hdr:L and /cand:L to see more message details
$nix_only_once = 1; # suppress "undefined identifiers shown only once..." messages
$reformat_linenumbers = 0; # 1 to reformat lines numbers to LZ's preferred style (may conflict with
# cursor-placement mechanisms in some editors/IDE's)
$smush_amps_and_stars = 0; # 1 leaves asterisks/ampersands adjacent to preceding identifiers;
# 0 inserts a space between
$space_after_commas = 0; # 1 to force spaces after commas, 0 not to
$meta_y_cbreak = 'B'; # /meta:y forces this value for cbreak
$meta_y_closewrap = 'Y'; # /meta:y forces this values for closewrap
$wrap_own_msgs = 0; # wrap STL Decryptor messages to same output width
# as errors (1) or don't (0)
$keep_stdns = 0; # 0 to remove "std::" and related prefixes, 1 to retain them.
# NOTE: if set to 1, STL-related filtering will *not* work (for now). This option
# is designed for use in conjunction with /break:D to retain maximum detail in
# metaprogramming-style messages, rather than for use with STL library messages.
$show_internal_err = 1; # If set to 0, suppresses delimiter mismatch errors. Please leave at 1,
# and contact me as per the emitted instructions in the case of an
# internal error.
# default list of names of trailing type names to be stripped from the end of
# argument lists (the -nullarg:xxx command line option allows additional names to
# be added to the list, or for the these default ones to be cleared out):
@nullargs = qw(boost::tuples::null_type mpl_::void_ mpl_::na boost::detail::variant::void\d+);
# (Designed primarly for use with boost libraries tuple, mpl, etc...)
#@nullargs = qw(); # to totally disable the null args stripping feature by default, uncomment this
# line and comment out the initialization of @nullargs above.
#
# END of user-configurable settings (change anything below here AT YOUR OWN RISK.)
#################################################################################################################
$| = 1; # force output buffer flush after every line
$iter_policy = $def_iter_policy; # default iterator policy
$dave_move = 0; # true for /hdr:LD1
$dave_rep = 0; # true for /hdr:LD2
$in_backtrace = 0; # not processing a backtrace right now
if ("\u$def_hdr_policy" =~ 'LD[12]?')
{
$dave_move = 1;
$dave_rep = 0;
$dave_rep = 1 if "\u$def_hdr_policy" eq 'LD2';
$def_hdr_policy = 'L';
}
$header_policy = $def_hdr_policy; # default std. header message policy
$with_policy = $def_with_policy; # default "with clause" substitution policy
$headers_to_show = $def_hdrs_to_show; # number of headers to show for 'M' header policy
$candidate_policy = $def_cand_policy; # default candidate policy (gcc only)
$pathname_policy = $def_path_policy; # default pathname policy (gcc only)
$lognative = 0; # by default, not logging native messages
$suppressed_headers = 0; # true when we've suppressed at least one stdlib header
$suppressed_candidates = 0; # true when we've suppressed at least one template candidate
$pdbg = 0; # true to show print trace
$wrapdbg = 0; # de-bug wrap loop
$movedbg = 0; # de-bug Dave mode reordering
$delimdbg = 0; # de-bug /wrap:D mode delimiter parsing
$optdbg = 0; # show value of all command-line modfiable options
$choked = 0; # haven't choked yet with an internal error
sub scanback;
sub println;
sub print2;
sub break_and_print;
sub break_and_print_plain;
sub break_and_println_plain;
sub break_and_print_fragment;
sub lognative_header;
sub showkey;
# Little hack to avoid "Exiting subroutine via next" warnings on internal error:
sub NoWarn
{
$msg = shift (@_);
print "$msg" if $msg !~ /Exiting subroutine via next/;
}
$SIG{__WARN__} = "NoWarn";
@save_args = @ARGV; # lognative_header uses this
while (@ARGV) # process command-line options
{
if ($ARGV[0] =~ /^[\/-]iter:([SML])[A-Z]*$/i) # allow command-line iterator policy
{ # specification of form: /iter:x
print "$ARGV[0] " if $optdbg;
$iter_policy = "\u$1";
$newiter = 'iterator' if $iter_policy eq 'L';
shift;
next;
}
if ($ARGV[0] =~ /^[\/-]cand:([YNSML])[A-Z]*$/i) # allow candidate policy
{ # specification of form: /cand:x
print "$ARGV[0] " if $optdbg;
$candidate_policy = "\u$1";
$candidate_policy =~ tr/NY/SL/;
shift;
next;
}
if ($ARGV[0] =~ /^[\/-]with:([YNSL])[A-Z]*$/i) # allow with clause policy
{ # specification of form: /with:x
print "$ARGV[0] " if $optdbg;
$with_policy = "\u$1";
$with_policy =~ tr/NY/LS/;
shift;
next;
}
if ($ARGV[0] =~ /^[\/-]hdr:L(D[12]?)$/i) # detect special "Dave Abrahams" header policy
{ # specifications of form: /hdr:LD /hdr:LD1 /hdr:LD2
print "$ARGV[0] " if $optdbg;
$header_policy = "L";
$dave_move = 1; # moving error line to before the trace
$dave_rep = 0;
$dave_rep = 1 if "\u$1" eq "D2"; # replicating trigger line
shift;
next;
}
if ($ARGV[0] =~ /^[\/-]hdr:([YNSML])[a-ce-z]*$/i) # allow standard header policy
{ # specification of form: /hdr:x
print "$ARGV[0] " if $optdbg;
$header_policy = "\u$1";
$header_policy =~ tr/NY/SL/;
$headers_to_show = 0 if $header_policy eq 'S';
$dave_move = 0;
$dave_rep = 0;
shift;
next;
}
if ($ARGV[0] =~ /^[\/-]hdr:(\d+)/i) # allow standard header policy
{ # specification of form: /hdr:nn
print "$ARGV[0] " if $optdbg;
$header_policy = 'M';
$headers_to_show = $1;
shift;
next;
}
if ($ARGV[0] =~ /^[\/-]path:([SL])[A-Z]*$/i) # allow pathname policy
{ # specification of form: /path:x
print "$ARGV[0] " if $optdbg;
$pathname_policy = "\u$1";
$pathname_policy =~ tr/NY/SL/;
shift;
next;
}
if ($ARGV[0] =~ /^[\/-]banner:?([YN]?)[A-Z]*$/i) # banner:Y or N
{ # (just "/banner" means Y)
print "$ARGV[0] " if $optdbg;
$banner = "\u$1";
$banner = 'Y' if $banner eq "";
shift;
next;
}
if ($ARGV[0] =~ /^[\/-]showback:?([YN]?)[A-Z]*$/i) # showback:Y or N
{ # (just "/showback" means Y)
print "$ARGV[0] " if $optdbg;
$show_backtraces = "\u$1";
$show_backtraces = 'Y' if $show_backtraces eq "";
shift;
next;
}
if ($ARGV[0] =~ /^[\/-]width:(\d+)/i) # allow line output width spec
{ # of form: /width:n
print "$ARGV[0] " if $optdbg;
$output_width = $1;
shift;
next;
}
if ($ARGV[0] =~ /^[\/-]break:([DP])[A-Z]*$/i) # break: D or P
{
print "$ARGV[0] " if $optdbg;
$break_algorithm = "\u$1";
shift;
next;
}
if ($ARGV[0] =~ /^[\/-]cbreak:([AB])[A-Z]*$/i) # comma break: B or A
{
print "$ARGV[0] " if $optdbg;
$comma_wrap = "\u$1";
shift;
next;
}
if ($ARGV[0] =~ /^[\/-]closewrap:?([YN]?)[A-Z]*$/i) # closewrap:Y or N
{ # (just "/closewrap" means Y)
print "$ARGV[0] " if $optdbg;
$close_wrap = "\u$1";
$close_wrap = 'Y' if $close_wrap eq "";
shift;
next;
}
if ($ARGV[0] =~ /^[\/-]nullarg:(.*)/i) # add to list of "null arg" identifiers
{
print "$ARGV[0] " if $optdbg;
if ($1 =~ /^clear$/i)
{
@nullargs = (); # "clear" means clear out null arg list
}
else
{
push @nullargs, $1; # any other name is appened to list
}
shift;
next;
}
if ($ARGV[0] =~ /^[\/-]meta:?([YN]?)[A-Z]*$/i) # meta:Y or N
{ # (just "/meta" means Y)
if ("\u$1" =~ /^N/)
{
$break_algorithm = 'P';
}
else
{
$break_algorithm = 'D';
$comma_wrap = $meta_y_cbreak;
$close_wrap = $meta_y_closewrap;
}
$output_width = 80 if $output_width == 0;
shift;
next;
}
if ($ARGV[0] =~ /^[\/-]lognative/i) # allow log native msgs option
{ # of form: /lognative
print "$ARGV[0] " if $optdbg;
$lognative = 1;
shift;
next;
}
println "Warning: unrecognized gSTLFilt2.pl command line option: $ARGV[0]\n";
shift;
}
# List of "standard" header files names:
@keywords = qw(algo algorithm algobase bitset cassert cctype cerrno cfloat ciso646
climits clocale cmath complex csetjmp csignal cstdarg stdarg cstddef stddef
cstdio stdio cstdlib stdlib cstring ctime time cwchar cwtype cxxabi deque editbuf exception exception_defines
fstream fstream.h functional hashtable hash_map hash_set heap iomanip
ios iosfwd iostream iostream istream iterator limits list locale
map memory new new numeric ostream queue rope set slist
pair sstream stack stdexcept streambuf streambuf_iterator string
strstream strstream stream_iterator typeinfo utility valarray vector
basic_ios basic_string boost_concept_check char_traits codecvt concept_check
cpp_type_traits fpos functexcept generic_shadow gslice gslice_array indirect_array
ios_base localefwd stringfwd locale_facets mask_array pthread_allocimpl slice slice_array
type_traits valarray_array valarray_meta bastring complext fcomplex ldcomplex
std_valarray straits strfile tempbuf alloc floatio math
array random regex type_traits tuple unordered_map unordered_set
cfenv cinttypes cstdbool cstdint ctgmath
);
# Put 'em in a hash for rapid searching:
for (@keywords)
{
$keywords{$_}++;
}
print "\n" if $optdbg;
$tab = " " x $tabsize;
print "\n\n" . ("=" x $output_width) . "\n\n" if $pdbg or $wrapdbg or $movedbg or $delimdbg;
#
# This sections builds the $t ("type") regex from the ground up.
# After it is built, the component variables (except for $id) are not used again.
#
$sid = '\b[a-zA-Z_]\w*'; # pattern for a simple identifier or keyword
$id = "(?:$sid\:\:)*$sid"; # simple id preceded by an optional namespace qualifier
$p = '(?: ?\*)*'; # suffix for "ptr", "ptr to ptr", "ptr to ptr to ptr", ad nauseum.
$idp = "(?:$id )*$id ?$p ?"; # one or more identifiers/keywords with perhaps some *'s after
# simple id or basic template spec
$cid = "(?:$idp(?: ?const ?\\*? ?)?|$id<$idp(?: ?const ?\\*? ?)?(?:, ?$idp(?: ?const ?\\*? ?)?)*>$p) ?";
# a cid or template type with 1+ cid's as parameters
$t = "(?:$cid|$id<$cid(?:, ?$cid)*>$p|$id<$id<$cid>$p(?:, ?$id<$cid>$p)* ?>$p)";
println "$STLFilt_ID" if ($banner eq 'Y');
showkey $output_width if $pdbg;
lognative_header if $lognative;
$doing_candidates = 0;
$doing_stl_headers = 0;
$save_filename = '';
$this_is_gcc3 = 0;
$saw_instantiated = 0;
#
# Data structures supporting the Dave Abrahams mode line break algorithm:
#
@open_delims = ('(', '{', '<');
@close_delims= (')', '}', '>');
for (@open_delims) # list of "open" delimiters
{
$open_delims{$_}++;
}
for (@close_delims) # list of "close" delimiters
{
$close_delims{$_}++;
}
# create "opposites" table, mapping each delimiter to its complement:
for ($i = 0; $i < @open_delims; $i++)
{
$opps{$open_delims[$i]} = $close_delims[$i];
$opps{$close_delims[$i]} = $open_delims[$i];
}
# The following state varaibles are used for Dave-mode line re-ordering:
$pushed_back_line = "";
$displaying_error_msg = 0; # true if displaying actual error message of backtrace in re-order mode
$last_within_context = ""; # save "within this context" lines to detect duplicates and strip them
#
# NOTE: We cannot use a main loop of the form
#
# while( <> )
#
# because of ActivePerl's way of handling input from Win32 pipes
# connected to STDIN. (EOF is treated like an ordinary character.
# In particular, it doesn't get read unless FOLLOWED by a newline.
# Yeah, great, EOF followed by a newline.)
#
MAIN_LOOP:
while ( 1 )
{
if ($pushed_back_line ne "")
{
$_ = $pushed_back_line;
$pushed_back_line = "";
}
else
{
# Read the first char of the next line to see if it equals EOF.
# If we're the ones who write the code that writes to STDIN,
# we can guarantee that EOF is always preceded by a newline.
#
# We must do this in a loop, because if the next line is empty,
# then we have not read the first char of the next line, but
# the entire next line.
#
$newlines = "";
CHECK_FOR_EOF_LOOP:
while( 1 )
{
# Read one char.
$nextchar = "";
$numRead = read STDIN, $nextchar, 1;
# Normally, perl will return an undefined value from read if the next
# character was EOF. ActivePerl will simply read the EOF like any other
# character. Since we know that one of the newlines was ours, we print one
# less newline than we have seen. NOTE: It is possible that we have seen no
# newline at all. This happens if the CL output has no newline at the end.
# In that case, we have appended a newline, and that's good.
if (1 != $numRead or $nextchar eq "\032")
{
if ($newlines ne "")
{
chop $newlines;
print $newlines;
}
last MAIN_LOOP;
}
else # Else, if we have read a newline, we store it for later output and continue reading.
{
if ($nextchar eq "\n")
{
$newlines = $newlines . "\n";
}
# Else, if we have read something that's neither a newline nor EOF, we print
# the accumulated newlines and proceed to read and process the next line.
else
{
print $newlines;
last CHECK_FOR_EOF_LOOP;
}
}
}
# Read the next line, prepend the first char, which has already been read.
$_ = <STDIN>;
# If the read failed, the pipe must have broken.
if (!defined $_)
{
print "\nSTL Decryptor: Input stream terminated abnormally (broken pipe?)\n";
last MAIN_LOOP;
}
$_ = $nextchar . $_;
}
#
# Done with special EOF-processing-enabled input handling.
# Now process the line (in $_):
#
$save_line_for_dbg = $_; # in case of a panic error
print LOGNATIVE $_ if $lognative; # log native message if requested
print "DBG: Next line to be processed:\n$_\n" if $movedbg;
s/{anonymous}/anonymous/g; # massage anonymous namespace specs to qualify as identifiers
s/<unnamed>/unnamed/g;
$obj = 0; # by default, not object file message
$obj = 1 if /\.o(bj)?\b/i or /\.a\b/i; # set $obj if an object or lib file
if ($obj)
{
print "************** PRINT DBG 1 **************\n" if $pdbg;
if (/(.*\):\s*)([\S].*)/) # look for possibly-mangled name followed by additional text...
{
$before = $1;
$after = "$2\n";
break_and_print_plain "$before"; # print the part containing possible mangled-name-from-hell
$_ = $after; # and process the rest normally.
}
else
{
break_and_print_plain "$_"; # print entire line containing possible mangled-name-from-hell
next;
}
}
next if $show_backtraces eq 'N' and (/\binstantiated from\b/ or /^\s*from /);
# get rid of useless messages from gcc
if ($nix_only_once)
{
next if /\(Each undeclared identifier is reported only once/;
next if /for each function it appears in\.\)/;
}
$has_lineno = 0;
$has_lineno = 1 if /^(.*\.(cpp|cxx|cc|h|hpp|tcc)\:(\d+\:) ?)/;
# strip prefix of form:
if (/^(.*\.(cpp|cxx|cc|h|hpp|tcc)\:(\d+\:)? ?)/ or # "pathname.h:n: " or
(/^((?:[a-zA-Z]\:)?[^:]*\b(\w+)(\.\w+)?\:(\d+\:)? ?)/ and exists $keywords{$2})) # std header
{
$prefix = "$1"; # and restore it later
s/^\Q$prefix//; # remove during filtering
}
else
{
$prefix = ""; # null prefix if none detected
}
# test if we're looking at a message referring to a standard header
# (note that the candidate policy trumps the header policy):
$needs_stripping = ($prefix =~ /stl_[a-zA-Z]\w*\.h:/i or
($prefix =~ m#([/\\])include\1(?:.*\1)*(\w+)# and exists $keywords{$2}));
$this_is_an_stl_header = ($needs_stripping and
!$doing_candidates and ($_ !~ /candidates are\:/));
# strip message referring to standard headers if header_policy is S:
if ($this_is_an_stl_header)
{
++$doing_stl_headers;
next if $header_policy eq 'S'; # skip all headers if using 'S' header policy
# skip all but first $headers_to_show if policy is 'M'
next if $doing_stl_headers > $headers_to_show and $header_policy eq 'M';
}
# if 'M' or 'S' header policy, tell how many skipped:
if (!$this_is_an_stl_header and ($doing_stl_headers > ($headers_to_show)) and $header_policy ne 'L')
{
println " [STL Decryptor: Suppressed " .
($doing_stl_headers - $headers_to_show) .
($header_policy eq 'M' ? " more " : " ") .
"STL standard header message" .
(($doing_stl_headers - $headers_to_show) != 1 ? "s" : "") . "]";
$suppressed_headers = 1;
}
$doing_stl_headers = 0 if !$this_is_an_stl_header;
# gcc: strip pathname from deadly-long stdlib file paths as per $pathname_policy:
if ($pathname_policy eq 'S' and $needs_stripping)
{
$preprefix = ""; # special case: preserve leading " from " phrase
if ($prefix =~ /^(.* from )/)
{
$preprefix = $1;
$prefix =~ s/^.* from //;
}
if ($prefix =~ /$sid\.(h|hpp|tcc|cpp|cxx|cc)\:/)
{ # case where there's an extension
$prefix =~ s/.*($sid\.(h|hpp|tcc|cpp|cxx|cc))\:/$preprefix$1:/;
}
else
{ # case where there's (perhaps) no extension
$prefix =~ s/^(?:[a-zA-Z]\:)?[^:]*\b(\w+(\.\w+)?\:(\d+\:)? ?)/$preprefix$1/;
}
}
# save filename, if any
if ($prefix =~ /^($sid\.(h|hpp|tcc))\:/)
{
$filename = $1; # save file basename
}
else
{
$filename = 'No filename';
}
if ($candidate_policy ne 'L' and /candidates are:/)
{
$doing_candidates++;
$save_filename = $filename;
$suppressed_candidates = 1;
next;
}
$this_is_gcc3 = 1 if $doing_candidates and / /;
# skip all messages referring to "candidates" (if req'd):
if ($candidate_policy ne 'L' and $doing_candidates and
($this_is_gcc3 and / /) or (!$this_is_gcc3 and $filename eq $save_filename))
{
$doing_candidates++;
next;
}
if (((!$this_is_gcc3 and $filename ne $save_filename) or $this_is_gcc3) and $doing_candidates)
{
println " [STL Decryptor: Suppressed $doing_candidates 'candidate' line" .
($doing_candidates != 1 ? "s" : "") . "]"
if $candidate_policy eq 'M';
$doing_candidates = 0;
}
s/no matching function for call to/No match for/;
###################################################################################################
# Do 'with' clause processing, transforming into plain-Jane type specifications:
if ($with_policy eq 'S')
{
# temporary eliminate [##] sequences:
@dims = ();
$dim_counter = 1;
while (/(\[(\d*)])/)
{
$old = $1;
$sub = $2;
s/\Q$old/zzz-$dim_counter-$sub-zzz/;
push @dims, $sub;
$dim_counter++;
}
while (/(.*)( \[with ([^]]*)])/)
{
$text = $1; # the original message text with placeholder names
$keyclause = $2; # the "with [...]" clause
$keylist = $3; # just the list of key/value mappings
chop $keylist if substr($keylist, -1, 1) eq ']';
%map = (); # clear the hash of key/value pairs
while($keylist =~ /(\w+) ?=/)
{
$key = $1;
$pos = $start = index($keylist, $key) + length($key) + 1;
if (substr($keylist, $pos, 1) eq '=')
{ $pos++; $start++; }
if (substr($keylist, $pos, 1) eq ' ')
{ $pos++; $start++; }
$depth = 0; # count <'s and >'s
$previous = ' ';
while ($pos <= length($keylist))
{
$next = substr ($keylist, $pos++, 1);
last if $depth == 0 and ($next eq ',' or ($next eq ']' and $previous ne '[')); # ignore "[]"
$previous = $next;
$depth++ if $next =~ /[<\[\(]/;
$depth-- if $next =~ /[>\]\)]/;
}
$value = substr($keylist, $start, $pos - $start - 1);
$map{$key} = $value;
last if $pos > length($keylist);
$keylist = substr($keylist, $pos);
}
# Apply substitutions to the original text fragment:
$newtext = $text;
while(($key, $value) = each(%map))
{
$newtext =~ s/\b$key\b/$value/g;
}
# Replace the original message text with the expanded version:
s/\Q$text/$newtext/;
# Delete the key/value list from the message:
s/\Q$keyclause//;
}
# restore [###] clauses:
$dim_counter = 1;
foreach $dim (@dims)
{
s/zzz-$dim_counter-$dim-zzz/[$dim]/g;
$dim_counter++;
}
}
# End 'with' clause processing
#############################################################################################
# eliminate standard namespace qualifiers (for now, required for STL filtering):
s/\bstd(ext)?\:\://g unless $keep_stdns;
s/\b__gnu_cxx\:\://g unless $keep_stdns;
s/note: //; # WTF? It's just noise.
s/typename //g; # ditto
# The following section strips out the "class" keyword when it is part
# of a type name, but not when it is part of the 'prose' of a message.
# To do this, we only strip the word "class" when it follows an
# odd-numbered single quote (1st, 3rd, 5th,
$out = ""; # accumulate result into $out
$old = $_;
while (1)
{
if (($pos = index ($old, "`")) == -1) # index of next opening quote
{ # if none,
$out .= $old; # we're done
last;
}
$out .= substr($old, 0, $pos + 1, ""); # splice up to & including the "'" to $out
$pos = index($old, "'"); # index of next closing quote in $out
$txt = substr($old, 0, $pos + 1, ""); # splice from $old into $txt
$txt =~ s/\bclass //g if !/\btypedef\b/; # filter out "class" from $txt
$out .= $txt; # concatenate result to cumulative result
} # loop for next fragment
$_ = $out; # done; update entire current line
# s/\bclass //g if !/typedef/; # strip "class" except in typedef errors
s/\bstruct ([^'])/$1/g if !/typedef/; # don't strip "struct" for *anonymous* structs or typedefs
s/\b_STLD?\:\://g unless $keep_stdns; # for STLPort
# simplify the ubiquitous "vanilla" string and i/ostreams (w/optional default allocator):
s/\b(_?basic_(string|if?stream|of?stream|([io]?stringstream)))<(char|wchar_t), ?(string_)?char_traits<\4>(, ?__default_alloc_template<(true|false), ?0>)? ?>\:\:\1/$2::$2/g;
s/\b_?basic_(string|if?stream|of?stream|([io]?stringstream))<(char|wchar_t), ?(string_)?char_traits<\3>(, ?__default_alloc_template<(true|false), ?0>)? ?>/$1/g;
s/\b(_?basic_(string|if?stream|of?stream|([io]?stringstream)))<(char|wchar_t), ?(string_)?char_traits<\4>(, allocator<\4>)? ?>\:\:\1/$2::$2/g;
s/\b_?basic_(string|if?stream|of?stream|([io]?stringstream))<(char|wchar_t), ?(string_)?char_traits<\3>(, allocator<\3>)? ?>/$1/g;
s/\b([io])stream_iterator<($t), ?($t), ?char_traits<\3>, ?($t)>/$1stream_iterator<$2>/g;
s/\b__normal_iterator<const $t, ?($t)>\:\:__normal_iterator\(/string::const_iterator(/g;
s/\b__normal_iterator<$t, ?($t)>\:\:__normal_iterator\(/string::iterator(/g;
# The following loop repeats until no transformations occur in the last complete iteration:
for ($pass = 1; ;$pass++) # pass count (for de-bugging purposes only)
{
my $before = $_; # save the current line; keep looping while changes happen
#
# Handle allocator clauses:
#
# delete allocators from template typenames completely:
$has_double_gt = 0;
$has_double_gt++ if />>/;
s/allocator<($t)>::rebind<\1>::other::($id)/allocator<$1>::$2/g;
s/\b,? ?allocator<$t ?>(,(0|1|true|false)) ?>/$2>/g;
s/, ?allocator<$id<($t), ?allocator<\1> ?> ?>//g;
s/, ?allocator<$t> ?>/>/g;
# remove allocator clauses
# gcc 4.x allocator types
s/, ?allocator<($t) ?>\:\:rebind<\1 ?>\:\:other>/>/g;
# remove allocator clauses if the message doesn't refer to an allocator explicitly:
unless (/' to '.*allocator</ or /allocator<$t>\:\:/)
{
s/, ?allocator<$t ?> ?//g; # the leading comma allows the full spec.
s/, ?const allocator<$t ?> ?&//g; # to appear in the error message details
s/,? ?(const )?$t\:\:allocator_type ?&//g;
}
if (!$has_double_gt)
{
while (/>>/)
{
s/>>/> >/g;
}
}
# gcc deque, deque iterators:
s/\bdeque<($t),0>/deque<$1>/g;
s/\b_Deque_iterator<($t), ?\1 ?&, ?\1 ?[*&](, ?0)?>\:\:_Deque_iterator ?\(/deque<$1>::iterator(/g;
s/\b_Deque_iterator<($t), ?\1 ?&, ?\1 ?[*&](, ?0)?>/deque<$1>::iterator/g;
s/\b_Deque_iterator<($t), ?const \1 ?&, ?const \1 ?[*&](,0)?>\:\:_Deque_iterator ?\(/deque<$1>::const_iterator(/g;
s/\b_Deque_iterator<($t), ?const \1 ?&, ?const \1 ?[*&](,0)?>/deque<$1>::const_iterator/g;
# gcc list iterators:
s/\b_List_iterator<($t), ?(const )?\1 ?&, ?(const )?\1 ?\*>\:\:_List_iterator ?\(/list<$1>::iterator(/g;
s/\b_List_iterator<($t), ?(const )?\1 ?&, ?(const )?\1 ?\*>/list<$1>::iterator/g;
s/\b_List_iterator<($t)>\:\:_List_iterator\(/list<$1>::iterator(/g;