Repository navigation
Expand file tree
/
Copy patherror.c
More file actions
8832 lines (8017 loc) · 321 KB
/
Copy patherror.c
File metadata and controls
8832 lines (8017 loc) · 321 KB
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
/*
Part of the EDG Compiler Project, under the Apache License v2.0 with LLVM
Exceptions.
See https://edgcpp.org/LICENSE.txt for license information.
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
/*
error.c -- Error reporting routines.
*/
/* Header files common to all files. */
#include "fe_common.h"
#ifdef PCH_PRAGMA_GUARD
/* Mark the end of the sequence of headers subject to precompiled header
processing. */
#pragma hdrstop
#endif /* ifdef PCH_PRAGMA_GUARD */
#include "err_data.h"
#include "decls.h"
#include "templates.h"
#if !STANDALONE_UTILITY_PROGRAM
#if IL_SHOULD_BE_WRITTEN_TO_FILE
#include "il_write.h"
#endif /* IL_SHOULD_BE_WRITTEN_TO_FILE */
#include "pch.h"
#if RECORD_MACRO_INVOCATIONS
#include "macro.h"
#endif /* RECORD_MACRO_INVOCATIONS */
#endif /* !STANDALONE_UTILITY_PROGRAM */
/* Conditionally open the "edg" namespace. */
BEGIN_EDG_NAMESPACE
/*
Static variable set when a catastrophe occurs, to catch catastrophe loops.
*/
STATIC_THREAD a_boolean
catastrophe_has_occurred;
/*
Constants, structures and static variables used to format diagnostic
messages.
*/
#define NORMAL_DIAG_INDENT 0 /* The number of spaces to be indented prior
to conventional single message
diagnostics. */
#define SOURCE_INDENT 2 /* The number of spaces by which source lines
are indented. */
#define INDENT_AMOUNT 10 /* Number of additional spaces at the start of
continuation lines. */
#define LIST_DIAG_INDENT 12 /* The number of spaces to be indented prior
to each additional message that is part of
a multiple message diagnostic, i.e. an
error diagnostic followed by a list of
entities. For appearances, this value
should be greater than INDENT_AMOUNT. */
#define MACRO_CONTEXT_INDENT 1 /* The number of spaces to indent macro
context lines. For best appearances, this
value should be greater than
NORMAL_DIAG_INDENT and less than
SOURCE_INDENT. */
STATIC_THREAD int
diagnostic_indent;
/* Typically all diagnostic messages will
begin in the first column of a line and
subsequent continuation lines would be
indented. With diagnostics involving
multiple messages or entity names, this
static variable will be adjusted for the
start of each additional message. See
NORMAL_DIAG_INDENT and LIST_DIAG_INDENT
above. */
STATIC_THREAD a_memory_region_number
diag_memory_region;
/* The memory region to be used for allocating
diagnostics. Normally this is front end
memory, but for command-line errors and
catastrophic errors, which can occur before
IL memory can be allocated, general memory is
used. This is indicated by setting this to
NO_MEMORY_REGION_NUMBER. */
/*
Kinds of diagnostic fill-ins that can be represented by a_diag_fill_in.
*/
enum a_diag_fill_in_kind {
dfk_number,
/* An integer value. */
dfk_unsigned_number,
/* An unsigned integer value. */
dfk_position,
/* A source position. */
dfk_string,
/* A null-terminated ASCII string. */
dfk_symbol,
/* A symbol name (and possibly type). */
dfk_type,
/* A type name. */
dfk_template_args,
/* A template argument list. */
dfk_reflection,
/* A reflection. */
dfk_module,
/* A module. */
/*lint -esym(749,*a_diag_fill_in_kind::dfk_last)*/
dfk_last /* Must be last. */
};
/*
Structure used to represent an entity to be used as a fill-in
in a diagnostic message.
*/
typedef struct a_diag_fill_in *a_diag_fill_in_ptr;
typedef struct a_diag_fill_in {
a_diag_fill_in_kind
kind;
/* The kind of entity to be included in the
diagnostic. */
#if CHECKING
a_byte_boolean
fill_in_used;
/* Set to TRUE when the fill-in is inserted into
the message text. Used to detect unused
fill-ins. */
#endif /* CHECKING */
a_diag_fill_in_ptr
next;
/* Pointer to the next fill-in entry for this
message, or NULL if there are no more fill-ins. */
union {
/* When kind == dfk_number. */
a_signed_diag_number
number;
/* The numeric value to be inserted. */
/* When kind == dfk_unsigned_number. */
an_unsigned_diag_number
unsigned_number;
/* The numeric value to be inserted. */
/* When kind == dfk_position. */
a_source_position
position;
/* The source position to be inserted. */
/* When kind == dfk_string. */
struct {
a_const_char
*start; /* The start of the string to be inserted. */
size_t len; /* The length of the string to be inserted. */
} string;
/* When kind == dfk_symbol. */
struct {
a_symbol_ptr
ptr;
/* Pointer to the symbol to be included in the
diagnostic. */
a_scope_depth
scope_depth;
/* A scope depth associated with the symbol,
or NO_SCOPE_DEPTH. This is only used
for certain context fill-ins. */
a_byte_boolean
full_type; /* True if the symbol should be expanded
into an object (type and name). */
a_byte_boolean
name_only; /* True if only the symbol name is needed. */
a_byte_boolean
force_function_params;
/* True if parameters of a function should be
listed even if it is not overloaded. */
a_byte_boolean
force_template_name_output;
/* True if the "A<T> [with T=int]" style
of output should be used for classes
when distinct template signatures are
being used. */
a_byte_boolean
decl_pos; /* True if the declaration position is
to be generated. */
a_byte_boolean
template_args; /* True if the template arguments are to be
displayed; the scope is specified by the
scope_depth field. Used for
sk_function_template only. */
a_byte_boolean
trans_unit; /* True if the translation unit should be
displayed under certain circumstances.
In the primary translation unit, it is
displayed for secondary translation units.
In secondary translation units, it is
displayed for all translation units. */
} symbol;
/* When kind == dfk_type. */
a_type_ptr
type;
/* A pointer to the type entry to be included
in the diagnostic. */
/* When kind == dfk_template_args. */
a_template_arg_ptr
template_args;
/* A pointer to the template argument list to be
included in the diagnostic. */
/* When kind == dfk_reflection. */
a_reflection_value
reflection;
/* The reflection value to be included in the
diagnostic. */
/* When kind == dfk_module. */
a_module_ptr
mod; /* The module to be included in the diagnostic. */
} variant;
} a_diag_fill_in;
/*
Category codes for the various parts of the processing for multi-line
diagnostics:
*/
enum a_diagnostic_kind {
dck_primary, /* A top-level normal diagnostic, also used
for "more information" messages, which
are treated mostly like primary
messages. */
dck_sub_message, /* Additional message in a multi-message
diagnostic. This message will typically
be indented relative to its associated
primary message. Source file information
is not displayed. */
dck_context, /* A diagnostic message that specifies
error context information. */
dck_macro_context /* Similar to dck_context, but for macro
context stack trace information. */
};
/*
Structure to hold information resulting from conversion of a source
position to file/line information.
*/
typedef struct a_source_info_for_pos *a_source_info_for_pos_ptr;
typedef struct a_source_info_for_pos {
a_boolean at_end_of_source;
/* TRUE if the location is after the end of the
source file. */
a_source_file_ptr
source_file;
/* The source file, or NULL if none is available. */
a_const_char *file_name;
/* The name of the source file, or NULL if
none is available. */
a_line_number line_number;
/* The line number within the compilation unit. */
a_unicode_source_kind
unicode_source_kind;
/* The Unicode source kind of the file from which
the source line originated. */
} a_source_info_for_pos;
/*
Structure used to build a diagnostic to be issued. A diagnostic consists of
a primary entry and an optional list of sub-messages used for lists of
information associated with the primary entry. Primary entries and sub-
messages may have associated fill-in entries.
*/
typedef struct a_diagnostic {
a_diagnostic_kind
kind;
/* Indicates whether this is a primary diagnostic,
sub-message, context, etc. */
a_diagnostic_ptr
next;
/* Pointer to the next sub-message if the current
entry is for a sub-message. NULL for primary
entries and for the last diagnostic of a
sub-message. */
a_diagnostic_ptr
primary_diag;
/* For a subordinate diagnostic or context, this
points back to the primary diagnostic. NULL
otherwise. */
a_diag_list
sub_msgs;
/* A list of subordinate diagnostics used for
multi-message diagnostics (e.g., for a list
of candidate functions on an ambiguous call).
The list may be empty. */
a_diag_list
context;
/* A list of context diagnostics. The list may be
empty. */
a_diag_list
macro_context;
/* A list of macro context diagnostics. The list
may be empty. */
a_diag_list
more_info;
/* Pointer to a list of additional information
diagnostics to be issued to provide more detail
about the cause of the primary message. The list
may be empty. */
a_translation_unit_ptr
translation_unit;
/* Pointer to the translation unit with which this
error is associated, or NULL if the diagnostic
is not associated with a translation unit
(e.g., for a command-line error). */
a_source_position
position;
/* Source location associated with this diagnostic.
This is the position passed in on the call of the
diagnostic routine. */
a_source_info_for_pos
source_info;
/* File, line, etc. for position. */
a_source_position
diag_header_pos;
/* The position to be displayed in the diagnostic
header. This can be different than "position"
when macro positions are being reported. */
a_source_info_for_pos
diag_header_source_info;
/* File, line, etc. for diag_header_pos. */
an_error_code error_code;
/* The error code associated with the diagnostic that
being issued. */
an_error_severity
severity;
/* The severity of the diagnostic being issued, or
es_none for sub-messages. */
a_diag_fill_in_ptr
fill_in_head;
/* Pointer to a list of diagnostic fill-ins to be
inserted into the diagnostic message. NULL if
there are no fill-ins. */
a_diag_fill_in_ptr
fill_in_tail;
/* Pointer to the last element of a list of fill-ins.
NULL if there are no fill-ins. */
} a_diagnostic;
void a_diag_list::append(a_diagnostic_ptr dp)
/*
Append the given diagnostic entry to *this.
*/
{
if (this->head == NULL) {
this->head = dp;
} else {
this->tail->next = dp;
} /* if */
this->tail = dp;
} /* a_diag_list::append */
/*
Describe a label fill-in entry. Label fill-in entries are used to specify
at run time which of two different strings (as specified by error codes)
should be filled in based upon the value of a variable. Useful in cases
where an error message should differ depending on a particular mode.
*/
typedef struct a_label_fill_in_entry {
a_const_char *label; /* The name of the "label" that is used in
error message text (i.e., %[label]). This
string is used only for matching purposes
and doesn't necessarily have to appear
in the substituted string. */
a_boolean *test; /* A pointer to a boolean variable whose
value at run time is used to decide which
error code below is substituted. */
an_error_code true_value,
false_value; /* Error codes representing strings to be used
in the "TRUE" and "FALSE" cases. Note that
these error codes should not themselves
contain any fill-ins. */
} a_label_fill_in_entry;
/* Define the label fill-ins: */
STATIC_THREAD a_label_fill_in_entry label_fill_ins[] = {
{ "managed", &use_cppcli_fill_ins, ec_managed, ec_cppcx },
{ "C++/CLI", &use_cppcli_fill_ins, ec_cppcli, ec_cppcx_mapping },
{ "default", &use_cppcli_fill_ins, ec_default, ec_cli_mapping },
{ "cli::array", &use_cppcli_fill_ins, ec_cli_array, ec_platform_array},
{ "C++/CLI array", &use_cppcli_fill_ins, ec_cppcli_array, ec_cppcx_array },
{ "System", &use_cppcli_fill_ins, ec_system, ec_platform },
{ "gcnew", &use_cppcli_fill_ins, ec_gcnew, ec_ref_new },
{ NULL, (a_boolean*)NULL, ec_no_error, ec_no_error },
};
static a_label_fill_in_entry *get_label_fill_in_entry(a_const_char *label,
sizeof_t length)
/*
Return a pointer to the label fill-in entry that matches the specified
label, with the specified length. An assertion failure occurs if the
label fill-in entry is not found.
*/
{
a_label_fill_in_entry *lfie;
for (lfie = label_fill_ins; lfie->label != NULL; lfie++) {
if (strncmp(lfie->label, label, length) == 0) break;
} /* for */
#if CHECKING
if (lfie->label == NULL) {
#if DEBUG
char *label_copy = alloc_general((sizeof_t)length+1);
strncpy(label_copy, label, length);
label_copy[length] = '\0';
fprintf(f_debug, "missing fill-in label: %s\n", label_copy);
#endif /* DEBUG */
unexpected_condition_str(
"get_label_fill_in_entry: no label fill-in found");
} /* if */
#endif /* CHECKING */
return lfie;
} /* get_label_fill_in_entry */
#if EXPENSIVE_CHECKING && !STANDALONE_UTILITY_PROGRAM
static void verify_label_fill_in_entries(void)
/*
Check the label fill-ins of each error message to ensure that the label
fill-in entries are valid.
*/
{
int error_code;
a_const_char *ptr, *end_label;
for (error_code = 0; error_code < (int)ec_last; error_code++) {
ptr = error_text((an_error_code)error_code);
while (ptr != NULL) {
ptr = mbc_strchr(ptr, '%');
if (ptr == NULL || *ptr == '\0') {
break;
} else {
ptr++;
if (*ptr == '\0') {
break;
} else if (*ptr == '[') {
end_label = mbc_strchr(ptr+1, ']');
check_assertion(end_label != NULL);
(void)get_label_fill_in_entry(ptr + 1,
(sizeof_t)(end_label - ptr - 1));
ptr = end_label+1;
} /* if */
} /* if */
} /* while */
} /* for */
} /* verify_label_fill_in_entries */
#endif /* EXPENSIVE_CHECKING && !STANDALONE_UTILITY_PROGRAM */
#if DEBUG
/*
Counts of tables allocated, to track total use of memory.
*/
STATIC_THREAD uint32_t num_diagnostics_allocated,
num_diag_fill_ins_allocated;
#endif /* DEBUG */
STATIC_THREAD a_diagnostic_ptr
avail_diagnostics;
/* List of diagnostic entries freed and available
for reuse. */
STATIC_THREAD a_diag_fill_in_ptr
avail_diag_fill_ins;
/* List of diagnostic fill-in entries freed and
available for reuse. */
STATIC_THREAD a_text_buffer_ptr
msg_buffer;
/* Buffer used to construct an error message. */
STATIC_THREAD a_text_buffer_ptr
prefix_buffer;
/* Buffer used to construct the diagnostic prefix
information (file, severity, etc). */
STATIC_THREAD a_text_buffer_ptr
write_diagnostic_buffer;
/* A text buffer used by write_diagnostic to
accumulate the entire contents of a
diagnostic message (so it can be written
in one atomic operation). The text buffer
is not null-terminated during the
construction of the diagnostic. */
STATIC_THREAD int
diagnostic_line_length;
/* The maximum length of an error output line.
Use to wrap diagnostics. */
/*
Information related to issuing diagnostics (e.g., severity, etc.) for each
error code.
*/
struct an_error_code_entry {
an_error_severity
default_severity;
/* Default severity for this error code.
Contains values set from the
command-line. */
/* The members below are re-initialized for each compilation. (Note: when
adding a new field, code in error_init must be updated to make that so).
*/
an_error_severity
current_severity;
/* The current severity associated with an
error code. Contains values set from the
command-line or by pragmas. */
a_bit_field once:1; /* TRUE if a non-error diagnostic should be
issued only once. */
a_bit_field diagnostic_issued:1;
/* TRUE if a diagnostic has ever been issued
for this error code. */
a_bit_field severity_changed_by_pragma:1;
/* TRUE if the severity of this error code has
ever been modified by a pragma during the
current compilation. */
};
STATIC_THREAD an_error_code_entry
error_codes[(int)ec_last + 1];
/* An array of consisting of information
related to how each error code is handled.
*/
STATIC_THREAD a_boolean
error_codes_initialized;
/* A flag used to avoid re-initialization of
error_codes when compiling the first
translation unit. */
STATIC_THREAD an_il_to_str_output_control_block
octl; /* Output control block for interface to il_to_str
routines. */
#if !STANDALONE_UTILITY_PROGRAM
/*
Variables pertaining to a line of source that must be reread for output in
a diagnostic. Most diagnostics are issued for the current logical source
line. Occasionally a diagnostic will refer to a source line that is not in
the current logical source line (a line read earlier). The buffer pointed
to by error_source_line will hold such a source line that has been reread.
*/
STATIC_THREAD char
*error_source_line;
/* Characters of the source line being reread for
diagnostic generation, ended by both a newline and
a null. Space is dynamically allocated, and its
upper bound is given by
after_end_of_error_source_line. */
#define ERROR_SOURCE_LINE_INITIAL_ALLOCATION 200
#define ERROR_SOURCE_LINE_INCREMENTAL_ALLOCATION 1000
/* Initial and incremental allocation sizes for
error_source_line. The initial allocation should be
such that almost all cases can be accepted (so that
the realloc is hardly ever needed). */
STATIC_THREAD char
*after_end_of_error_source_line;
/* Address past the last element of error_source_line,
as an aid to checking for overflow, etc. A variable
because error_source_line line can be reallocated
larger if needed. */
/*
Data structures and variables used to index into source files to locate
a needed source line for a diagnostic. For each source file, an index
table is created and updated as the file is read.
*/
#define INITIAL_PHYSICAL_LINE_COUNT_INCREMENT 100
/* Constant value specifying the starting
interval at which physical line positions
will be recorded in the error_file_index
entry. */
#define NUMBER_OF_ERROR_FILE_INDEX_TABLE_ENTRIES 10
/* Number of physical line indexes maintained
for each source file. */
typedef struct an_error_file_index *an_error_file_index_ptr;
typedef struct an_error_file_index {
a_source_file_ptr
source_file; /* Pointer to the IL source file entry
associated with this physical line index
table. */
an_error_file_index_ptr
previous; /* Pointer to the previous an_error_file_index
entry in the doubly linked list. */
an_error_file_index_ptr
next; /* Pointer to the next an_error_file_index
entry in the doubly linked list. */
unsigned short
next_index_entry;
/* Index of the next available entry in the
line_number and file_position arrays. */
a_line_number line_number[NUMBER_OF_ERROR_FILE_INDEX_TABLE_ENTRIES];
/* Physical line number of the file that
begins at the associated file position. */
long file_position[NUMBER_OF_ERROR_FILE_INDEX_TABLE_ENTRIES];
/* File position that is the beginning of
the associated physical line and used
to fseek() into the file. */
long physical_line_count_increment;
/* Value specifying the interval at which
physical line positions will be recorded
in the error_file_index entry. Initially
set to INITIAL_PHYSICAL_LINE_COUNT_INCREMENT
but may be updated later if the file is
large. */
} an_error_file_index;
STATIC_THREAD an_error_file_index_ptr
head_of_file_index_list;
/* Pointer to the beginning of the list of
an_error_file_index entries. Initialized
to NULL by error_init(). */
STATIC_THREAD an_error_file_index_ptr
tail_of_file_index_list;
/* Pointer to the tail of the list of
an_error_file_index entries. Initialized
to NULL by error_init(). */
/*
Type used to track diagnostic (e.g., pk_diag*) pragmas. Such pragmas are
"immediate" and for each one that is encountered (except pk_diag_once),
an element of this type is entered into the pragma_diag_list linked list.
Elements in that list are kept sorted by source location (i.e.,
src/column). Note that a_source_location is not used here because it
potentially contains additional fields and there is a desire to keep this
structure small.
*/
struct a_pragma_diag_elem {
inline a_pragma_diag_elem(a_pragma_kind kind,
a_source_position *pos);
inline a_pragma_diag_elem(a_pragma_kind kind,
a_source_position *pos,
int error_number);
struct a_pragma_diag_elem
*next; /* Next entry on the list. */
struct a_pragma_diag_elem
*prev; /* Previous entry on the list. */
a_simple_source_position
spos; /* Source position of the pragma. */
a_pragma_kind kind; /* The pk_diag* pragma kind. */
a_bit_field is_pop:1;
/* TRUE if this corresponds to a "diagnostic pop". */
union {
/* When kind == pk_diagnostic: */
a_pragma_diag_elem
*corresponding_push;
/* When is_pop is TRUE, this entry is a pointer to
the corresponding "push". For "pop" entries that
have no corresponding "push" entry, NULL is used. */
/* When kind != pk_diagnostic: */
int error_number;
/* The error number specified by the pragma. */
} variant;
};
namespace detail {
template<>
struct Is_trivially_copyable_edg_impl<a_pragma_diag_elem> :
Integral_constant<bool, true> {
}; /* Is_trivially_copyable_edg_impl */
template<>
struct Is_trivially_destructible_edg_impl<a_pragma_diag_elem> :
Integral_constant<bool, true> {
}; /* Is_trivially_destructible_edg_impl */
} /* namespace detail */
inline a_pragma_diag_elem::a_pragma_diag_elem(a_pragma_kind _kind,
a_source_position *pos)
/*
Constructor for pk_diagnostic entries.
*/
: kind(_kind)
, is_pop(FALSE)
{
check_assertion(kind == pk_diagnostic);
this->next = NULL;
this->prev = NULL;
this->spos.seq = pos->seq;
this->spos.column = pos->column;
this->variant.corresponding_push = NULL;
} /* a_pragma_diag_elem::a_pragma_diag_elem */
inline a_pragma_diag_elem::a_pragma_diag_elem(a_pragma_kind _kind,
a_source_position *pos,
int error_number)
/*
Constructor for pk_diag_* (and pk_none) entries.
*/
: kind(_kind)
, is_pop(FALSE)
{
check_assertion(kind != pk_diagnostic);
this->next = NULL;
this->prev = NULL;
this->spos.seq = pos->seq;
this->spos.column = pos->column;
this->variant.error_number = error_number;
} /* a_pragma_diag_elem::a_pragma_diag_elem */
static inline a_boolean operator==(const a_pragma_diag_elem &e1,
const a_pragma_diag_elem &e2)
/*
Return TRUE if e1 and e2 have the same values for all applicable non-static
data members.
*/
{
return (e1.kind == e2.kind &&
e1.spos.seq == e2.spos.seq &&
e1.spos.column == e2.spos.column &&
(e1.kind == pk_diagnostic ?
(!e1.is_pop ||
e1.variant.corresponding_push == e2.variant.corresponding_push) :
e1.variant.error_number == e2.variant.error_number));
} /* operator== */
STATIC_THREAD a_pragma_diag_elem
*pragma_diag_list, *pragma_diag_tail;
/* Head and tail pointers to a linked list of
a_pragma_diag_elem entries that represent all of the
"diagnostic" pragmas in the compilation. The list
is ordered by source location (which generally
occurs naturally except for the case of _Pragmas in
instantiations which must be inserted at the proper
location). */
STATIC_THREAD Dyn_array<a_pragma_diag_elem*>
*pragma_push_stack;
/* A stack that keeps track of "diagnostic push"
pragmas so that they can later be matched with their
corresponding "diagnostic pop". */
#endif /* !STANDALONE_UTILITY_PROGRAM */
/*
Structure used to maintain a record of diagnostic messages that have been
issued during prototype instantiations. This is used to suppress
diagnostics during actual instantiations if the diagnostic was issued
during the prototype instantiation.
*/
typedef struct a_recorded_diagnostic *a_recorded_diagnostic_ptr;
typedef struct a_recorded_diagnostic {
a_recorded_diagnostic_ptr
next;
/* Pointer to the next entry in the current bucket.
NULL for the last entry in the bucket. */
an_error_code error_code;
/* The error code of the diagnostic. */
an_error_severity
severity;
/* The severity of the message. */
a_source_position
error_pos;
/* The position associated with the message. */
a_scope_number
scope_of_prev_check;
/* The scope number at the point of the last
suppressed diagnostic. */
unsigned int number_of_times_suppressed;
/* Number of times the message was suppressed in
scope_of_prev_check. */
} a_recorded_diagnostic;
#define RECORDED_DIAG_TABLE_SIZE 983
/* The number of buckets in the recorded diagnostic
table. This number should be prime. */
STATIC_THREAD a_recorded_diagnostic_ptr
recorded_diagnostic_table[RECORDED_DIAG_TABLE_SIZE];
/* The top level array used for the hash table used
to find previously issued diagnostics. */
static inline void annotate_diagnostic(a_text_buffer_ptr buffer,
a_diagnostic_annotation_kind kind)
/*
Emit, in buffer, the "escape" sequence (DIAG_ANNOTATION_INDICATOR) followed
by the kind of annotation, but only if annotations are enabled.
*/
{
if (annotate_diagnostics) {
add_char_to_text_buffer(buffer, DIAG_ANNOTATION_INDICATOR);
add_char_to_text_buffer(buffer, (char)kind);
} /* if */
} /* annotate_diagnostic */
static void set_sgr_string(a_diagnostic_annotation_kind kind,
a_const_char *string)
/*
Find (in sgr_string_for_colored_diagnostics) the string if it exists and save a
pointer to it (and its length) in sgr_map[kind]. If the string doesn't exist,
set the pointer to NULL and the length to 0.
*/
{
a_const_char *ptr = strstr(sgr_string_for_colored_diagnostics, string);
sgr_map[(int)kind].ptr = NULL;
sgr_map[(int)kind].length = 0;
if (ptr != NULL) {
size_t len = strlen(string);
if (ptr[len] == '=') {
ptr += len+1;
a_const_char *end_ptr = strchr(ptr, ':');
len = (end_ptr == NULL) ? strlen(ptr) : (size_t)(end_ptr - ptr);
sgr_map[(int)kind].ptr = ptr;
sgr_map[(int)kind].length = len;
/* Make sure only valid characters are in the SGR string. */
for (a_const_char *p = ptr; p < ptr+len ; p++) {
if (*p != ';' && !isdigit((unsigned char)*p)) {
sgr_map[(int)kind].ptr = NULL;
break;
} /* if */
} /* for */
} /* if */
} /* if */
} /* set_sgr_string */
void init_colorization(void)
/*
Perform initialization to enable colorization of diagnostics.
*/
{
check_assertion(colorize_diagnostics);
if (getenv("NOCOLOR") != NULL) {
/* Do not colorize if the NOCOLOR environment variable is set. */
colorize_diagnostics = FALSE;
} else if (!terminal_is_color_capable()) {
/* Only colorize if errors are being sent to a terminal. */
colorize_diagnostics = FALSE;
} /* if */
if (colorize_diagnostics) {
if ((sgr_string_for_colored_diagnostics = getenv("EDG_COLORS")) != NULL) {
/* Use EDG_COLORS environment variable if set. */
} else if ((sgr_string_for_colored_diagnostics = getenv("GCC_COLORS")) !=
NULL) {
/* Use select portions of GCC_COLORS environment variable if set. */
} else {
/* Use default settings. */
sgr_string_for_colored_diagnostics = DEFAULT_EDG_COLORS;
} /* if */
/* Find relevant substrings in the sgr_string, if any. */
set_sgr_string(da_error, "error");
set_sgr_string(da_warning, "warning");
set_sgr_string(da_note, "note");
set_sgr_string(da_locus, "locus");
set_sgr_string(da_quote, "quote");
set_sgr_string(da_range1, "range1");
} /* if */
annotate_diagnostics = colorize_diagnostics;
} /* init_colorization */
static void add_colorization_characters(a_diagnostic_annotation_kind kind)
/*
The diagnostic currently being written (in write_diagnostic_buffer) has
the specified annotation kind at this point in the buffer. Add the appropriate
SGR code (if there is one) to the buffer.
*/
{
check_assertion(kind < da_last);
an_sgr_string *sgrp = &sgr_map[(int)kind];
if (kind == da_reset || sgrp->ptr != NULL) {
add_char_to_text_buffer(write_diagnostic_buffer, '\033');
add_char_to_text_buffer(write_diagnostic_buffer, '[');
if (kind == da_reset) {
add_char_to_text_buffer(write_diagnostic_buffer, '0');
} else {
add_string_with_length_to_text_buffer(write_diagnostic_buffer,
sgrp->ptr, sgrp->length);
} /* if */
add_char_to_text_buffer(write_diagnostic_buffer, 'm');
} /* if */
} /* add_colorization_characters */
static char *diag_copy_string(a_const_char *string)
/*
Make a copy of the specified string to diag_memory_region and return
a pointer to the copy. When STANDALONE_UTILITY_PROGRAM is TRUE, general
memory is always used.
*/
{
#if STANDALONE_UTILITY_PROGRAM
sizeof_t length;
char *new_string;
length = strlen(string);
new_string = alloc_general(length+1);
(void)strcpy(new_string, string);
return new_string;
#else /* !STANDALONE_UTILITY_PROGRAM */
return copy_string_to_region(diag_memory_region, string);
#endif /* STANDALONE_UTILITY_PROGRAM */
} /* diag_copy_string */
a_const_char *error_text(an_error_code error_code)
/*
Return a pointer to the error text for the message identified by the given
error code. Note that if this routine is modified to get the text from
some other source (e.g., a file) it should be copied into memory in such
a way that it will not be invalidated by subsequent calls of this routine.
This routine is called numerous times for each diagnostic, so it is important
that it be fast. If a file is used, all of the messages should probably
be read into memory so that an array of strings can still be used here.
*/
{
check_assertion_str2((int)error_code < (int)ec_last,
"error_text: ", "invalid error code");
return ((a_const_char *)message_text[(int)error_code]);
} /* error_text */
static void clear_source_info_for_pos(a_source_info_for_pos_ptr sifpp)
/*
Initialize the fields of the source-info-for-pos entry sifpp.
*/
{
sifpp->at_end_of_source = FALSE;
sifpp->source_file = NULL;
sifpp->file_name = NULL;
sifpp->line_number = 0;
sifpp->unicode_source_kind = usk_none;
} /* clear_source_info_for_pos */
static a_diagnostic_ptr alloc_diagnostic(void)
/*
Allocate and initialize a diagnostic entry. Reuse an entry from a list
of freed entries if possible.
*/
{
a_diagnostic_ptr dp;
/* Don't attempt reuse if the allocation is from general memory. */
if (avail_diagnostics != NULL &&
diag_memory_region != NO_MEMORY_REGION_NUMBER) {
/* Reuse an existing entry. */
dp = avail_diagnostics;
avail_diagnostics = avail_diagnostics->next;
} else {
/* Allocate a new entry. */
dp = alloc_general_or_in_region_of_type(diag_memory_region, a_diagnostic);
#if DEBUG
num_diagnostics_allocated++;
#endif /* DEBUG */
} /* if */
dp->kind = dck_primary;
dp->next = NULL;
dp->primary_diag = NULL;
clear_diag_list(&dp->sub_msgs);
clear_diag_list(&dp->context);
clear_diag_list(&dp->macro_context);
clear_diag_list(&dp->more_info);
dp->translation_unit = NULL;
dp->position = null_source_position;
clear_source_info_for_pos(&dp->source_info);
dp->diag_header_pos = null_source_position;
clear_source_info_for_pos(&dp->diag_header_source_info);
dp->error_code = ec_no_error;
dp->severity = es_none;
dp->fill_in_head = NULL;
dp->fill_in_tail = NULL;
return dp;
} /* alloc_diagnostic */
/* Forward declaration. */
static void free_diagnostic(a_diagnostic_ptr dp);
static void free_diag_list_elements(a_diag_list_ptr dlp)
/*
Free the list of diagnostics pointed to by the diagnostic list entry dip.
*/
{
a_diagnostic_ptr dp;
a_diagnostic_ptr next_dp;
for (dp = dlp->head; dp != NULL; dp = next_dp) {