forked from decompals/mips-gcc-2.7.2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcccp.c
10453 lines (9114 loc) · 278 KB
/
cccp.c
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
/* C Compatible Compiler Preprocessor (CCCP)
Copyright (C) 1986, 87, 89, 92, 93, 94, 1995 Free Software Foundation, Inc.
Written by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
In other words, you are welcome to use, share and improve this program.
You are forbidden to forbid anyone else to use, share and improve
what you give them. Help stamp out software-hoarding! */
typedef unsigned char U_CHAR;
#ifdef EMACS
#define NO_SHORTNAMES
#include "../src/config.h"
#ifdef open
#undef open
#undef read
#undef write
#endif /* open */
#endif /* EMACS */
/* The macro EMACS is defined when cpp is distributed as part of Emacs,
for the sake of machines with limited C compilers. */
#ifndef EMACS
#include "config.h"
#endif /* not EMACS */
#ifndef STANDARD_INCLUDE_DIR
#define STANDARD_INCLUDE_DIR "/usr/include"
#endif
#ifndef LOCAL_INCLUDE_DIR
#define LOCAL_INCLUDE_DIR "/usr/local/include"
#endif
#if 0 /* We can't get ptrdiff_t, so I arranged not to need PTR_INT_TYPE. */
#ifdef __STDC__
#define PTR_INT_TYPE ptrdiff_t
#else
#define PTR_INT_TYPE long
#endif
#endif /* 0 */
#include "pcp.h"
/* By default, colon separates directories in a path. */
#ifndef PATH_SEPARATOR
#define PATH_SEPARATOR ':'
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#include <stdio.h>
#include <signal.h>
/* The following symbols should be autoconfigured:
HAVE_FCNTL_H
HAVE_STDLIB_H
HAVE_SYS_TIME_H
HAVE_UNISTD_H
STDC_HEADERS
TIME_WITH_SYS_TIME
In the mean time, we'll get by with approximations based
on existing GCC configuration symbols. */
#ifdef POSIX
# ifndef HAVE_STDLIB_H
# define HAVE_STDLIB_H 1
# endif
# ifndef HAVE_UNISTD_H
# define HAVE_UNISTD_H 1
# endif
# ifndef STDC_HEADERS
# define STDC_HEADERS 1
# endif
#endif /* defined (POSIX) */
#if defined (POSIX) || (defined (USG) && !defined (VMS))
# ifndef HAVE_FCNTL_H
# define HAVE_FCNTL_H 1
# endif
#endif
#ifndef RLIMIT_STACK
# include <time.h>
#else
# if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
# else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
# endif
# include <sys/resource.h>
#endif
#if HAVE_FCNTL_H
# include <fcntl.h>
#endif
/* This defines "errno" properly for VMS, and gives us EACCES. */
#include <errno.h>
#if HAVE_STDLIB_H
# include <stdlib.h>
#else
char *getenv ();
#endif
#if STDC_HEADERS
# include <string.h>
# ifndef bcmp
# define bcmp(a, b, n) memcmp (a, b, n)
# endif
# ifndef bcopy
# define bcopy(s, d, n) memcpy (d, s, n)
# endif
# ifndef bzero
# define bzero(d, n) memset (d, 0, n)
# endif
#else /* !STDC_HEADERS */
char *index ();
char *rindex ();
# if !defined (BSTRING) && (defined (USG) || defined (VMS))
# ifndef bcmp
# define bcmp my_bcmp
static int
my_bcmp (a, b, n)
register char *a;
register char *b;
register unsigned n;
{
while (n-- > 0)
if (*a++ != *b++)
return 1;
return 0;
}
# endif /* !defined (bcmp) */
# ifndef bcopy
# define bcopy my_bcopy
static void
my_bcopy (s, d, n)
register char *s;
register char *d;
register unsigned n;
{
while (n-- > 0)
*d++ = *s++;
}
# endif /* !defined (bcopy) */
# ifndef bzero
# define bzero my_bzero
static void
my_bzero (b, length)
register char *b;
register unsigned length;
{
while (length-- > 0)
*b++ = 0;
}
# endif /* !defined (bzero) */
# endif /* !defined (BSTRING) && (defined (USG) || defined (VMS)) */
#endif /* ! STDC_HEADERS */
#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6)
# define __attribute__(x)
#endif
#ifndef PROTO
# if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
# define PROTO(ARGS) ARGS
# else
# define PROTO(ARGS) ()
# endif
#endif
#if 1
# include <stdarg.h>
# define VA_START(va_list, var) va_start (va_list, var)
# define PRINTF_ALIST(msg) char *msg, ...
# define PRINTF_DCL(msg)
# define PRINTF_PROTO(ARGS, m, n) PROTO (ARGS) __attribute__ ((format (printf, m, n)))
#else // 1
#include <varargs.h>
# define VA_START(va_list, var) va_start (va_list)
# define PRINTF_ALIST(msg) msg, va_alist
# define PRINTF_DCL(msg) char *msg; va_dcl
# define PRINTF_PROTO(ARGS, m, n) () __attribute__ ((format (printf, m, n)))
# define vfprintf(file, msg, args) \
{ \
char *a0 = va_arg(args, char *); \
char *a1 = va_arg(args, char *); \
char *a2 = va_arg(args, char *); \
char *a3 = va_arg(args, char *); \
fprintf (file, msg, a0, a1, a2, a3); \
}
#endif // 1
#define PRINTF_PROTO_1(ARGS) PRINTF_PROTO(ARGS, 1, 2)
#define PRINTF_PROTO_2(ARGS) PRINTF_PROTO(ARGS, 2, 3)
#define PRINTF_PROTO_3(ARGS) PRINTF_PROTO(ARGS, 3, 4)
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
/* VMS-specific definitions */
#ifdef VMS
#include <descrip.h>
#define O_RDONLY 0 /* Open arg for Read/Only */
#define O_WRONLY 1 /* Open arg for Write/Only */
#define read(fd,buf,size) VMS_read (fd,buf,size)
#define write(fd,buf,size) VMS_write (fd,buf,size)
#define open(fname,mode,prot) VMS_open (fname,mode,prot)
#define fopen(fname,mode) VMS_fopen (fname,mode)
#define freopen(fname,mode,ofile) VMS_freopen (fname,mode,ofile)
#define strncat(dst,src,cnt) VMS_strncat (dst,src,cnt)
#define fstat(fd,stbuf) VMS_fstat (fd,stbuf)
static int VMS_fstat (), VMS_stat ();
static char * VMS_strncat ();
static int VMS_read ();
static int VMS_write ();
static int VMS_open ();
static FILE * VMS_fopen ();
static FILE * VMS_freopen ();
static void hack_vms_include_specification ();
typedef struct { unsigned :16, :16, :16; } vms_ino_t;
#define ino_t vms_ino_t
#define INCLUDE_LEN_FUDGE 10 /* leave room for VMS syntax conversion */
#ifdef __GNUC__
#define BSTRING /* VMS/GCC supplies the bstring routines */
#endif /* __GNUC__ */
#endif /* VMS */
#ifndef O_RDONLY
#define O_RDONLY 0
#endif
#undef MIN
#undef MAX
#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
/* Find the largest host integer type and set its size and type. */
#ifndef HOST_BITS_PER_WIDE_INT
#if HOST_BITS_PER_LONG > HOST_BITS_PER_INT
#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG
#define HOST_WIDE_INT long
#else
#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_INT
#define HOST_WIDE_INT int
#endif
#endif
#ifndef S_ISREG
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#endif
#ifndef S_ISDIR
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
/* Define a generic NULL if one hasn't already been defined. */
#ifndef NULL
#define NULL 0
#endif
#ifndef GENERIC_PTR
#if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
#define GENERIC_PTR void *
#else
#define GENERIC_PTR char *
#endif
#endif
#ifndef NULL_PTR
#define NULL_PTR ((GENERIC_PTR)0)
#endif
#ifndef INCLUDE_LEN_FUDGE
#define INCLUDE_LEN_FUDGE 0
#endif
/* External declarations. */
extern char *version_string;
#ifndef VMS
#ifndef HAVE_STRERROR
#ifndef DARWIN
extern int sys_nerr;
#else
extern const int sys_nerr;
#endif
#if defined(bsd4_4)
extern const char *const sys_errlist[];
#else
#ifndef DARWIN
extern char *sys_errlist[];
#else
extern const char* const sys_errlist[];
#endif
#endif
#else /* HAVE_STRERROR */
char *strerror ();
#endif
#else /* VMS */
char *strerror (int,...);
#endif
int parse_escape PROTO((char **));
HOST_WIDE_INT parse_c_expression PROTO((char *));
#ifndef errno
extern int errno;
#endif
/* Name under which this program was invoked. */
static char *progname;
/* Nonzero means use extra default include directories for C++. */
static int cplusplus;
/* Nonzero means handle cplusplus style comments */
static int cplusplus_comments;
/* Nonzero means handle #import, for objective C. */
static int objc;
/* Nonzero means this is an assembly file, and allow
unknown directives, which could be comments. */
static int lang_asm;
/* Current maximum length of directory names in the search path
for include files. (Altered as we get more of them.) */
static int max_include_len;
/* Nonzero means turn NOTREACHED into #pragma NOTREACHED etc */
static int for_lint = 0;
/* Nonzero means copy comments into the output file. */
static int put_out_comments = 0;
/* Nonzero means don't process the ANSI trigraph sequences. */
static int no_trigraphs = 0;
/* Nonzero means print the names of included files rather than
the preprocessed output. 1 means just the #include "...",
2 means #include <...> as well. */
static int print_deps = 0;
/* Nonzero if missing .h files in -M output are assumed to be generated
files and not errors. */
static int print_deps_missing_files = 0;
/* Nonzero means print names of header files (-H). */
static int print_include_names = 0;
/* Nonzero means don't output line number information. */
static int no_line_directives;
/* Nonzero means output the text in failing conditionals,
inside #failed ... #endfailed. */
static int output_conditionals;
/* dump_only means inhibit output of the preprocessed text
and instead output the definitions of all user-defined
macros in a form suitable for use as input to cccp.
dump_names means pass #define and the macro name through to output.
dump_definitions means pass the whole definition (plus #define) through
*/
static enum {dump_none, dump_only, dump_names, dump_definitions}
dump_macros = dump_none;
/* Nonzero means pass all #define and #undef directives which we actually
process through to the output stream. This feature is used primarily
to allow cc1 to record the #defines and #undefs for the sake of
debuggers which understand about preprocessor macros, but it may
also be useful with -E to figure out how symbols are defined, and
where they are defined. */
static int debug_output = 0;
/* Nonzero indicates special processing used by the pcp program. The
special effects of this mode are:
Inhibit all macro expansion, except those inside #if directives.
Process #define directives normally, and output their contents
to the output file.
Output preconditions to pcp_outfile indicating all the relevant
preconditions for use of this file in a later cpp run.
*/
static FILE *pcp_outfile;
/* Nonzero means we are inside an IF during a -pcp run. In this mode
macro expansion is done, and preconditions are output for all macro
uses requiring them. */
static int pcp_inside_if;
/* Nonzero means never to include precompiled files.
This is 1 since there's no way now to make precompiled files,
so it's not worth testing for them. */
static int no_precomp = 1;
/* Nonzero means give all the error messages the ANSI standard requires. */
int pedantic;
/* Nonzero means try to make failure to fit ANSI C an error. */
static int pedantic_errors;
/* Nonzero means don't print warning messages. -w. */
static int inhibit_warnings = 0;
/* Nonzero means warn if slash-star appears in a comment. */
static int warn_comments;
/* Nonzero means warn if a macro argument is (or would be)
stringified with -traditional. */
static int warn_stringify;
/* Nonzero means warn if there are any trigraphs. */
static int warn_trigraphs;
/* Nonzero means warn if #import is used. */
static int warn_import = 1;
/* Nonzero means turn warnings into errors. */
static int warnings_are_errors;
/* Nonzero means try to imitate old fashioned non-ANSI preprocessor. */
int traditional;
/* Nonzero causes output not to be done,
but directives such as #define that have side effects
are still obeyed. */
static int no_output;
/* Nonzero means this file was included with a -imacros or -include
command line and should not be recorded as an include file. */
static int no_record_file;
/* Nonzero means that we have finished processing the command line options.
This flag is used to decide whether or not to issue certain errors
and/or warnings. */
static int done_initializing = 0;
/* Line where a newline was first seen in a string constant. */
static int multiline_string_line = 0;
/* I/O buffer structure.
The `fname' field is nonzero for source files and #include files
and for the dummy text used for -D and -U.
It is zero for rescanning results of macro expansion
and for expanding macro arguments. */
#define INPUT_STACK_MAX 400
static struct file_buf {
char *fname;
/* Filename specified with #line directive. */
char *nominal_fname;
/* Record where in the search path this file was found.
For #include_next. */
struct file_name_list *dir;
int lineno;
int length;
U_CHAR *buf;
U_CHAR *bufp;
/* Macro that this level is the expansion of.
Included so that we can reenable the macro
at the end of this level. */
struct hashnode *macro;
/* Value of if_stack at start of this file.
Used to prohibit unmatched #endif (etc) in an include file. */
struct if_stack *if_stack;
/* Object to be freed at end of input at this level. */
U_CHAR *free_ptr;
/* True if this is a header file included using <FILENAME>. */
char system_header_p;
} instack[INPUT_STACK_MAX];
static int last_error_tick; /* Incremented each time we print it. */
static int input_file_stack_tick; /* Incremented when the status changes. */
/* Current nesting level of input sources.
`instack[indepth]' is the level currently being read. */
static int indepth = -1;
#define CHECK_DEPTH(code) \
if (indepth >= (INPUT_STACK_MAX - 1)) \
{ \
error_with_line (line_for_error (instack[indepth].lineno), \
"macro or `#include' recursion too deep"); \
code; \
}
/* Current depth in #include directives that use <...>. */
static int system_include_depth = 0;
typedef struct file_buf FILE_BUF;
/* The output buffer. Its LENGTH field is the amount of room allocated
for the buffer, not the number of chars actually present. To get
that, subtract outbuf.buf from outbuf.bufp. */
#define OUTBUF_SIZE 10 /* initial size of output buffer */
static FILE_BUF outbuf;
/* Grow output buffer OBUF points at
so it can hold at least NEEDED more chars. */
#define check_expand(OBUF, NEEDED) \
(((OBUF)->length - ((OBUF)->bufp - (OBUF)->buf) <= (NEEDED)) \
? grow_outbuf ((OBUF), (NEEDED)) : 0)
struct file_name_list
{
struct file_name_list *next;
char *fname;
/* If the following is nonzero, it is a macro name.
Don't include the file again if that macro is defined. */
U_CHAR *control_macro;
/* If the following is nonzero, it is a C-language system include
directory. */
int c_system_include_path;
/* Mapping of file names for this directory. */
struct file_name_map *name_map;
/* Non-zero if name_map is valid. */
int got_name_map;
};
/* #include "file" looks in source file dir, then stack. */
/* #include <file> just looks in the stack. */
/* -I directories are added to the end, then the defaults are added. */
/* The */
static struct default_include {
char *fname; /* The name of the directory. */
int cplusplus; /* Only look here if we're compiling C++. */
int cxx_aware; /* Includes in this directory don't need to
be wrapped in extern "C" when compiling
C++. */
} include_defaults_array[]
#ifdef INCLUDE_DEFAULTS
= INCLUDE_DEFAULTS;
#else
= {
/* Pick up GNU C++ specific include files. */
{ GPLUSPLUS_INCLUDE_DIR, 1, 1 },
#ifdef CROSS_COMPILE
/* This is the dir for fixincludes. Put it just before
the files that we fix. */
{ GCC_INCLUDE_DIR, 0, 0 },
/* For cross-compilation, this dir name is generated
automatically in Makefile.in. */
{ CROSS_INCLUDE_DIR, 0, 0 },
/* This is another place that the target system's headers might be. */
{ TOOL_INCLUDE_DIR, 0, 0 },
#else /* not CROSS_COMPILE */
/* This should be /usr/local/include and should come before
the fixincludes-fixed header files. */
{ LOCAL_INCLUDE_DIR, 0, 1 },
/* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here.
Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h. */
{ TOOL_INCLUDE_DIR, 0, 0 },
/* This is the dir for fixincludes. Put it just before
the files that we fix. */
{ GCC_INCLUDE_DIR, 0, 0 },
/* Some systems have an extra dir of include files. */
#ifdef SYSTEM_INCLUDE_DIR
{ SYSTEM_INCLUDE_DIR, 0, 0 },
#endif
{ STANDARD_INCLUDE_DIR, 0, 0 },
#endif /* not CROSS_COMPILE */
{ 0, 0, 0 }
};
#endif /* no INCLUDE_DEFAULTS */
/* The code looks at the defaults through this pointer, rather than through
the constant structure above. This pointer gets changed if an environment
variable specifies other defaults. */
static struct default_include *include_defaults = include_defaults_array;
static struct file_name_list *include = 0; /* First dir to search */
/* First dir to search for <file> */
/* This is the first element to use for #include <...>.
If it is 0, use the entire chain for such includes. */
static struct file_name_list *first_bracket_include = 0;
/* This is the first element in the chain that corresponds to
a directory of system header files. */
static struct file_name_list *first_system_include = 0;
static struct file_name_list *last_include = 0; /* Last in chain */
/* Chain of include directories to put at the end of the other chain. */
static struct file_name_list *after_include = 0;
static struct file_name_list *last_after_include = 0; /* Last in chain */
/* Chain to put at the start of the system include files. */
static struct file_name_list *before_system = 0;
static struct file_name_list *last_before_system = 0; /* Last in chain */
/* List of included files that contained #pragma once. */
static struct file_name_list *dont_repeat_files = 0;
/* List of other included files.
If ->control_macro if nonzero, the file had a #ifndef
around the entire contents, and ->control_macro gives the macro name. */
static struct file_name_list *all_include_files = 0;
/* Directory prefix that should replace `/usr' in the standard
include file directories. */
static char *include_prefix;
/* Global list of strings read in from precompiled files. This list
is kept in the order the strings are read in, with new strings being
added at the end through stringlist_tailp. We use this list to output
the strings at the end of the run.
*/
static STRINGDEF *stringlist;
static STRINGDEF **stringlist_tailp = &stringlist;
/* Structure returned by create_definition */
typedef struct macrodef MACRODEF;
struct macrodef
{
struct definition *defn;
U_CHAR *symnam;
int symlen;
};
enum sharp_token_type {
NO_SHARP_TOKEN = 0, /* token not present */
SHARP_TOKEN = '#', /* token spelled with # only */
WHITE_SHARP_TOKEN, /* token spelled with # and white space */
PERCENT_COLON_TOKEN = '%', /* token spelled with %: only */
WHITE_PERCENT_COLON_TOKEN /* token spelled with %: and white space */
};
/* Structure allocated for every #define. For a simple replacement
such as
#define foo bar ,
nargs = -1, the `pattern' list is null, and the expansion is just
the replacement text. Nargs = 0 means a functionlike macro with no args,
e.g.,
#define getchar() getc (stdin) .
When there are args, the expansion is the replacement text with the
args squashed out, and the reflist is a list describing how to
build the output from the input: e.g., "3 chars, then the 1st arg,
then 9 chars, then the 3rd arg, then 0 chars, then the 2nd arg".
The chars here come from the expansion. Whatever is left of the
expansion after the last arg-occurrence is copied after that arg.
Note that the reflist can be arbitrarily long---
its length depends on the number of times the arguments appear in
the replacement text, not how many args there are. Example:
#define f(x) x+x+x+x+x+x+x would have replacement text "++++++" and
pattern list
{ (0, 1), (1, 1), (1, 1), ..., (1, 1), NULL }
where (x, y) means (nchars, argno). */
typedef struct definition DEFINITION;
struct definition {
int nargs;
int length; /* length of expansion string */
int predefined; /* True if the macro was builtin or */
/* came from the command line */
U_CHAR *expansion;
int line; /* Line number of definition */
char *file; /* File of definition */
char rest_args; /* Nonzero if last arg. absorbs the rest */
struct reflist {
struct reflist *next;
enum sharp_token_type stringify; /* set if a # operator before arg */
enum sharp_token_type raw_before; /* set if a ## operator before arg */
enum sharp_token_type raw_after; /* set if a ## operator after arg */
char rest_args; /* Nonzero if this arg. absorbs the rest */
int nchars; /* Number of literal chars to copy before
this arg occurrence. */
int argno; /* Number of arg to substitute (origin-0) */
} *pattern;
union {
/* Names of macro args, concatenated in reverse order
with comma-space between them.
The only use of this is that we warn on redefinition
if this differs between the old and new definitions. */
U_CHAR *argnames;
} args;
};
/* different kinds of things that can appear in the value field
of a hash node. Actually, this may be useless now. */
union hashval {
char *cpval;
DEFINITION *defn;
KEYDEF *keydef;
};
/*
* special extension string that can be added to the last macro argument to
* allow it to absorb the "rest" of the arguments when expanded. Ex:
* #define wow(a, b...) process (b, a, b)
* { wow (1, 2, 3); } -> { process (2, 3, 1, 2, 3); }
* { wow (one, two); } -> { process (two, one, two); }
* if this "rest_arg" is used with the concat token '##' and if it is not
* supplied then the token attached to with ## will not be outputted. Ex:
* #define wow (a, b...) process (b ## , a, ## b)
* { wow (1, 2); } -> { process (2, 1, 2); }
* { wow (one); } -> { process (one); {
*/
static char rest_extension[] = "...";
#define REST_EXTENSION_LENGTH (sizeof (rest_extension) - 1)
/* The structure of a node in the hash table. The hash table
has entries for all tokens defined by #define directives (type T_MACRO),
plus some special tokens like __LINE__ (these each have their own
type, and the appropriate code is run when that type of node is seen.
It does not contain control words like "#define", which are recognized
by a separate piece of code. */
/* different flavors of hash nodes --- also used in keyword table */
enum node_type {
T_DEFINE = 1, /* the `#define' keyword */
T_INCLUDE, /* the `#include' keyword */
T_INCLUDE_NEXT, /* the `#include_next' keyword */
T_IMPORT, /* the `#import' keyword */
T_IFDEF, /* the `#ifdef' keyword */
T_IFNDEF, /* the `#ifndef' keyword */
T_IF, /* the `#if' keyword */
T_ELSE, /* `#else' */
T_PRAGMA, /* `#pragma' */
T_ELIF, /* `#elif' */
T_UNDEF, /* `#undef' */
T_LINE, /* `#line' */
T_ERROR, /* `#error' */
T_WARNING, /* `#warning' */
T_ENDIF, /* `#endif' */
T_SCCS, /* `#sccs', used on system V. */
T_IDENT, /* `#ident', used on system V. */
T_ASSERT, /* `#assert', taken from system V. */
T_UNASSERT, /* `#unassert', taken from system V. */
T_SPECLINE, /* special symbol `__LINE__' */
T_DATE, /* `__DATE__' */
T_FILE, /* `__FILE__' */
T_BASE_FILE, /* `__BASE_FILE__' */
T_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */
T_VERSION, /* `__VERSION__' */
T_SIZE_TYPE, /* `__SIZE_TYPE__' */
T_PTRDIFF_TYPE, /* `__PTRDIFF_TYPE__' */
T_WCHAR_TYPE, /* `__WCHAR_TYPE__' */
T_USER_LABEL_PREFIX_TYPE, /* `__USER_LABEL_PREFIX__' */
T_REGISTER_PREFIX_TYPE, /* `__REGISTER_PREFIX__' */
T_IMMEDIATE_PREFIX_TYPE, /* `__IMMEDIATE_PREFIX__' */
T_TIME, /* `__TIME__' */
T_CONST, /* Constant value, used by `__STDC__' */
T_MACRO, /* macro defined by `#define' */
T_DISABLED, /* macro temporarily turned off for rescan */
T_SPEC_DEFINED, /* special `defined' macro for use in #if statements */
T_PCSTRING, /* precompiled string (hashval is KEYDEF *) */
T_UNUSED /* Used for something not defined. */
};
struct hashnode {
struct hashnode *next; /* double links for easy deletion */
struct hashnode *prev;
struct hashnode **bucket_hdr; /* also, a back pointer to this node's hash
chain is kept, in case the node is the head
of the chain and gets deleted. */
enum node_type type; /* type of special token */
int length; /* length of token, for quick comparison */
U_CHAR *name; /* the actual name */
union hashval value; /* pointer to expansion, or whatever */
};
typedef struct hashnode HASHNODE;
/* Some definitions for the hash table. The hash function MUST be
computed as shown in hashf () below. That is because the rescan
loop computes the hash value `on the fly' for most tokens,
in order to avoid the overhead of a lot of procedure calls to
the hashf () function. Hashf () only exists for the sake of
politeness, for use when speed isn't so important. */
#define HASHSIZE 1403
static HASHNODE *hashtab[HASHSIZE];
#define HASHSTEP(old, c) ((old << 2) + c)
#define MAKE_POS(v) (v & 0x7fffffff) /* make number positive */
/* Symbols to predefine. */
#ifdef CPP_PREDEFINES
static char *predefs = CPP_PREDEFINES;
#else
static char *predefs = "";
#endif
/* We let tm.h override the types used here, to handle trivial differences
such as the choice of unsigned int or long unsigned int for size_t.
When machines start needing nontrivial differences in the size type,
it would be best to do something here to figure out automatically
from other information what type to use. */
/* The string value for __SIZE_TYPE__. */
#ifndef SIZE_TYPE
#define SIZE_TYPE "long unsigned int"
#endif
/* The string value for __PTRDIFF_TYPE__. */
#ifndef PTRDIFF_TYPE
#define PTRDIFF_TYPE "long int"
#endif
/* The string value for __WCHAR_TYPE__. */
#ifndef WCHAR_TYPE
#define WCHAR_TYPE "int"
#endif
char * wchar_type = WCHAR_TYPE;
#undef WCHAR_TYPE
/* The string value for __USER_LABEL_PREFIX__ */
#ifndef USER_LABEL_PREFIX
#define USER_LABEL_PREFIX ""
#endif
/* The string value for __REGISTER_PREFIX__ */
#ifndef REGISTER_PREFIX
#define REGISTER_PREFIX ""
#endif
/* The string value for __IMMEDIATE_PREFIX__ */
#ifndef IMMEDIATE_PREFIX
#define IMMEDIATE_PREFIX ""
#endif
/* In the definition of a #assert name, this structure forms
a list of the individual values asserted.
Each value is itself a list of "tokens".
These are strings that are compared by name. */
struct tokenlist_list {
struct tokenlist_list *next;
struct arglist *tokens;
};
struct assertion_hashnode {
struct assertion_hashnode *next; /* double links for easy deletion */
struct assertion_hashnode *prev;
/* also, a back pointer to this node's hash
chain is kept, in case the node is the head
of the chain and gets deleted. */
struct assertion_hashnode **bucket_hdr;
int length; /* length of token, for quick comparison */
U_CHAR *name; /* the actual name */
/* List of token-sequences. */
struct tokenlist_list *value;
};
typedef struct assertion_hashnode ASSERTION_HASHNODE;
/* Some definitions for the hash table. The hash function MUST be
computed as shown in hashf below. That is because the rescan
loop computes the hash value `on the fly' for most tokens,
in order to avoid the overhead of a lot of procedure calls to
the hashf function. hashf only exists for the sake of
politeness, for use when speed isn't so important. */
#define ASSERTION_HASHSIZE 37
static ASSERTION_HASHNODE *assertion_hashtab[ASSERTION_HASHSIZE];
/* Nonzero means inhibit macroexpansion of what seem to be
assertion tests, in rescan. For #if. */
static int assertions_flag;
/* `struct directive' defines one #-directive, including how to handle it. */
#define DO_PROTO PROTO((U_CHAR *, U_CHAR *, FILE_BUF *, struct directive *))
struct directive {
int length; /* Length of name */
int (*func) DO_PROTO; /* Function to handle directive */
char *name; /* Name of directive */
enum node_type type; /* Code which describes which directive. */
char angle_brackets; /* Nonzero => <...> is special. */
char traditional_comments; /* Nonzero: keep comments if -traditional. */
char pass_thru; /* Copy preprocessed directive to output file. */
};
/* These functions are declared to return int instead of void since they
are going to be placed in the table and some old compilers have trouble with
pointers to functions returning void. */
static int do_assert DO_PROTO;
static int do_define DO_PROTO;
static int do_elif DO_PROTO;
static int do_else DO_PROTO;
static int do_endif DO_PROTO;
static int do_error DO_PROTO;
static int do_ident DO_PROTO;
static int do_if DO_PROTO;
static int do_include DO_PROTO;
static int do_line DO_PROTO;
static int do_pragma DO_PROTO;
#ifdef SCCS_DIRECTIVE
static int do_sccs DO_PROTO;
#endif
static int do_unassert DO_PROTO;
static int do_undef DO_PROTO;
static int do_warning DO_PROTO;
static int do_xifdef DO_PROTO;
/* Here is the actual list of #-directives, most-often-used first. */
static struct directive directive_table[] = {
{ 6, do_define, "define", T_DEFINE, 0, 1},
{ 2, do_if, "if", T_IF},
{ 5, do_xifdef, "ifdef", T_IFDEF},
{ 6, do_xifdef, "ifndef", T_IFNDEF},
{ 5, do_endif, "endif", T_ENDIF},
{ 4, do_else, "else", T_ELSE},
{ 4, do_elif, "elif", T_ELIF},
{ 4, do_line, "line", T_LINE},
{ 7, do_include, "include", T_INCLUDE, 1},
{ 12, do_include, "include_next", T_INCLUDE_NEXT, 1},
{ 6, do_include, "import", T_IMPORT, 1},
{ 5, do_undef, "undef", T_UNDEF},
{ 5, do_error, "error", T_ERROR},
{ 7, do_warning, "warning", T_WARNING},
#ifdef SCCS_DIRECTIVE
{ 4, do_sccs, "sccs", T_SCCS},
#endif
{ 6, do_pragma, "pragma", T_PRAGMA, 0, 0, 1},
{ 5, do_ident, "ident", T_IDENT},
{ 6, do_assert, "assert", T_ASSERT},
{ 8, do_unassert, "unassert", T_UNASSERT},