]> gcc.gnu.org Git - gcc.git/blame - gcc/cpphash.h
Daily bump.
[gcc.git] / gcc / cpphash.h
CommitLineData
88ae23e7
ZW
1/* Part of CPP library.
2 Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4283012f
JL
3
4This program is free software; you can redistribute it and/or modify it
5under the terms of the GNU General Public License as published by the
6Free Software Foundation; either version 2, or (at your option) any
7later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
42b17236 16Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
4283012f 17
88ae23e7
ZW
18/* This header defines all the internal data structures and functions
19 that need to be visible across files. It's called cpphash.h for
20 historical reasons. */
21
bb52fa7f
ZW
22#ifndef __GCC_CPPHASH__
23#define __GCC_CPPHASH__
24
88ae23e7
ZW
25typedef unsigned char U_CHAR;
26
bb52fa7f
ZW
27/* Structure allocated for every #define. For a simple replacement
28 such as
29 #define foo bar ,
30 nargs = -1, the `pattern' list is null, and the expansion is just
31 the replacement text. Nargs = 0 means a functionlike macro with no args,
32 e.g.,
33 #define getchar() getc (stdin) .
34 When there are args, the expansion is the replacement text with the
35 args squashed out, and the reflist is a list describing how to
36 build the output from the input: e.g., "3 chars, then the 1st arg,
37 then 9 chars, then the 3rd arg, then 0 chars, then the 2nd arg".
38 The chars here come from the expansion. Whatever is left of the
39 expansion after the last arg-occurrence is copied after that arg.
40 Note that the reflist can be arbitrarily long---
41 its length depends on the number of times the arguments appear in
42 the replacement text, not how many args there are. Example:
43 #define f(x) x+x+x+x+x+x+x would have replacement text "++++++" and
44 pattern list
45 { (0, 1), (1, 1), (1, 1), ..., (1, 1), NULL }
46 where (x, y) means (nchars, argno). */
47
ba412f14
ZW
48struct reflist
49{
50 struct reflist *next;
51 char stringify; /* nonzero if this arg was preceded by a
52 # operator. */
53 char raw_before; /* Nonzero if a ## operator before arg. */
54 char raw_after; /* Nonzero if a ## operator after arg. */
55 char rest_args; /* Nonzero if this arg. absorbs the rest */
56 int nchars; /* Number of literal chars to copy before
57 this arg occurrence. */
58 int argno; /* Number of arg to substitute (origin-0) */
59};
60
bb52fa7f 61typedef struct definition DEFINITION;
ba412f14
ZW
62struct definition
63{
bb52fa7f
ZW
64 int nargs;
65 int length; /* length of expansion string */
ba412f14 66 U_CHAR *expansion;
bb52fa7f 67 int line; /* Line number of definition */
ba412f14 68 int col;
bb52fa7f
ZW
69 const char *file; /* File of definition */
70 char rest_args; /* Nonzero if last arg. absorbs the rest */
ba412f14
ZW
71 struct reflist *pattern;
72
38b24ee2 73 /* Names of macro args, concatenated in order with \0 between
ba412f14
ZW
74 them. The only use of this is that we warn on redefinition if
75 this differs between the old and new definitions. */
76 U_CHAR *argnames;
bb52fa7f
ZW
77};
78
88ae23e7
ZW
79/* The structure of a node in the hash table. The hash table
80 has entries for all tokens defined by #define commands (type T_MACRO),
81 plus some special tokens like __LINE__ (these each have their own
82 type, and the appropriate code is run when that type of node is seen.
83 It does not contain control words like "#define", which are recognized
84 by a separate piece of code. */
85
168d3732 86/* different flavors of hash nodes */
88ae23e7
ZW
87enum node_type
88{
88ae23e7
ZW
89 T_SPECLINE, /* `__LINE__' */
90 T_DATE, /* `__DATE__' */
91 T_FILE, /* `__FILE__' */
92 T_BASE_FILE, /* `__BASE_FILE__' */
93 T_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */
94 T_VERSION, /* `__VERSION__' */
95 T_TIME, /* `__TIME__' */
96 T_STDC, /* `__STDC__' */
97 T_CONST, /* Constant string, used by `__SIZE_TYPE__' etc */
98 T_MACRO, /* macro defined by `#define' */
99 T_DISABLED, /* macro temporarily turned off for rescan */
100 T_POISON, /* macro defined with `#pragma poison' */
101 T_UNUSED /* Used for something not defined. */
102};
103
7f2935c7 104/* different kinds of things that can appear in the value field
5dfa4da1
ZW
105 of a hash node. */
106union hashval
107{
108 const char *cpval; /* some predefined macros */
109 DEFINITION *defn; /* #define */
110 struct hashnode *aschain; /* #assert */
7f2935c7
PB
111};
112
cf4ed945 113typedef struct hashnode HASHNODE;
88ae23e7
ZW
114struct hashnode
115{
d35364d1
ZW
116 const U_CHAR *name; /* the actual name */
117 size_t length; /* length of token, for quick comparison */
118 unsigned long hash; /* cached hash value */
7f2935c7 119 union hashval value; /* pointer to expansion, or whatever */
d35364d1 120 enum node_type type; /* type of special token */
7f2935c7
PB
121};
122
88ae23e7
ZW
123/* List of directories to look for include files in. */
124struct file_name_list
125{
126 struct file_name_list *next;
127 struct file_name_list *alloc; /* for the cache of
128 current directory entries */
129 char *name;
130 unsigned int nlen;
131 /* We use these to tell if the directory mentioned here is a duplicate
132 of an earlier directory on the search path. */
133 ino_t ino;
134 dev_t dev;
135 /* If the following is nonzero, it is a C-language system include
136 directory. */
137 int sysp;
138 /* Mapping of file names for this directory.
139 Only used on MS-DOS and related platforms. */
140 struct file_name_map *name_map;
141};
142#define ABSOLUTE_PATH ((struct file_name_list *)-1)
143
144/* This structure is used for the table of all includes. It is
145 indexed by the `short name' (the name as it appeared in the
146 #include statement) which is stored in *nshort. */
147struct ihash
148{
88ae23e7
ZW
149 /* Next file with the same short name but a
150 different (partial) pathname). */
151 struct ihash *next_this_file;
152
153 /* Location of the file in the include search path.
154 Used for include_next */
155 struct file_name_list *foundhere;
d35364d1
ZW
156
157 unsigned long hash; /* save hash value for future reference */
158 const char *nshort; /* name of file as referenced in #include;
159 points into name[] */
88ae23e7
ZW
160 const U_CHAR *control_macro; /* macro, if any, preventing reinclusion -
161 see redundant_include_p */
d35364d1 162 const char name[1]; /* (partial) pathname of file */
88ae23e7
ZW
163};
164typedef struct ihash IHASH;
165
166/* Character classes.
167 If the definition of `numchar' looks odd to you, please look up the
168 definition of a pp-number in the C standard [section 6.4.8 of C99] */
169#define ISidnum 0x01 /* a-zA-Z0-9_ */
170#define ISidstart 0x02 /* _a-zA-Z */
171#define ISnumstart 0x04 /* 0-9 */
172#define IShspace 0x08 /* ' ' \t \f \v */
173#define ISspace 0x10 /* ' ' \t \f \v \n */
174
ae79697b 175#define _dollar_ok(x) ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident))
88ae23e7
ZW
176
177#define is_idchar(x) ((_cpp_IStable[x] & ISidnum) || _dollar_ok(x))
178#define is_idstart(x) ((_cpp_IStable[x] & ISidstart) || _dollar_ok(x))
179#define is_numchar(x) (_cpp_IStable[x] & ISidnum)
180#define is_numstart(x) (_cpp_IStable[x] & ISnumstart)
181#define is_hspace(x) (_cpp_IStable[x] & IShspace)
182#define is_space(x) (_cpp_IStable[x] & ISspace)
183
184/* This table is constant if it can be initialized at compile time,
185 which is the case if cpp was compiled with GCC >=2.7, or another
186 compiler that supports C99. */
187#if (GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L)
188extern const unsigned char _cpp_IStable[256];
189#else
190extern unsigned char _cpp_IStable[256];
191#endif
192
193/* Macros. */
194
195#define CPP_BUF_PEEK(BUFFER) \
196 ((BUFFER)->cur < (BUFFER)->rlimit ? *(BUFFER)->cur : EOF)
197#define CPP_BUF_GET(BUFFER) \
198 ((BUFFER)->cur < (BUFFER)->rlimit ? *(BUFFER)->cur++ : EOF)
199#define CPP_FORWARD(BUFFER, N) ((BUFFER)->cur += (N))
200
45b966db
ZW
201/* Make sure PFILE->token_buffer has space for at least N more characters. */
202#define CPP_RESERVE(PFILE, N) \
203 (CPP_WRITTEN (PFILE) + (size_t)(N) > (PFILE)->token_buffer_size \
204 && (_cpp_grow_token_buffer (PFILE, N), 0))
205
88ae23e7
ZW
206/* Append string STR (of length N) to PFILE's output buffer.
207 Assume there is enough space. */
208#define CPP_PUTS_Q(PFILE, STR, N) \
209 (memcpy ((PFILE)->limit, STR, (N)), (PFILE)->limit += (N))
210/* Append string STR (of length N) to PFILE's output buffer. Make space. */
211#define CPP_PUTS(PFILE, STR, N) CPP_RESERVE(PFILE, N), CPP_PUTS_Q(PFILE, STR,N)
212/* Append character CH to PFILE's output buffer. Assume sufficient space. */
213#define CPP_PUTC_Q(PFILE, CH) (*(PFILE)->limit++ = (CH))
214/* Append character CH to PFILE's output buffer. Make space if need be. */
215#define CPP_PUTC(PFILE, CH) (CPP_RESERVE (PFILE, 1), CPP_PUTC_Q (PFILE, CH))
216/* Make sure PFILE->limit is followed by '\0'. */
217#define CPP_NUL_TERMINATE_Q(PFILE) (*(PFILE)->limit = 0)
218#define CPP_NUL_TERMINATE(PFILE) (CPP_RESERVE(PFILE, 1), *(PFILE)->limit = 0)
219
220/* Advance the current line by one. */
221#define CPP_BUMP_BUFFER_LINE(PBUF) ((PBUF)->lineno++,\
222 (PBUF)->line_base = (PBUF)->cur)
223#define CPP_BUMP_LINE(PFILE) CPP_BUMP_BUFFER_LINE(CPP_BUFFER(PFILE))
224#define CPP_PREV_BUFFER(BUFFER) ((BUFFER)->prev)
225
ae79697b
ZW
226#define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps)
227#define CPP_TRADITIONAL(PFILE) CPP_OPTION (PFILE, traditional)
88ae23e7 228#define CPP_PEDANTIC(PFILE) \
07aa0b04
ZW
229 (CPP_OPTION (PFILE, pedantic) && !CPP_BUFFER (PFILE)->system_header_p)
230#define CPP_WTRADITIONAL(PF) \
231 (CPP_OPTION (PF, warn_traditional) && !CPP_BUFFER (PF)->system_header_p)
88ae23e7 232
45b966db
ZW
233/* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion.
234 (Note that it is false while we're expanding macro *arguments*.) */
235#define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->data != NULL)
236
237/* Remember the current position of PFILE so it may be returned to
238 after looking ahead a bit.
239
240 Note that when you set a mark, you _must_ return to that mark. You
241 may not forget about it and continue parsing. You may not pop a
242 buffer with an active mark. You may not call CPP_BUMP_LINE while a
243 mark is active. */
244#define CPP_SET_BUF_MARK(IP) ((IP)->mark = (IP)->cur - (IP)->buf)
245#define CPP_GOTO_BUF_MARK(IP) ((IP)->cur = (IP)->buf + (IP)->mark, \
246 (IP)->mark = -1)
247#define CPP_SET_MARK(PFILE) CPP_SET_BUF_MARK(CPP_BUFFER(PFILE))
248#define CPP_GOTO_MARK(PFILE) CPP_GOTO_BUF_MARK(CPP_BUFFER(PFILE))
249
250/* ACTIVE_MARK_P is true if there's a live mark in the buffer. */
251#define ACTIVE_MARK_P(PFILE) (CPP_BUFFER (PFILE)->mark != -1)
252
253/* Last arg to output_line_command. */
254enum file_change_code {same_file, rename_file, enter_file, leave_file};
255
88ae23e7 256/* In cpphash.c */
d35364d1
ZW
257extern HASHNODE *_cpp_make_hashnode PARAMS ((const U_CHAR *, size_t,
258 enum node_type,
259 unsigned long));
29a72a4f 260extern unsigned int _cpp_calc_hash PARAMS ((const U_CHAR *, size_t));
d35364d1
ZW
261extern HASHNODE *_cpp_lookup PARAMS ((cpp_reader *,
262 const U_CHAR *, int));
263extern HASHNODE **_cpp_lookup_slot PARAMS ((cpp_reader *,
264 const U_CHAR *, int, int,
265 unsigned long *));
266extern void _cpp_free_definition PARAMS ((DEFINITION *));
267extern DEFINITION *_cpp_create_definition PARAMS ((cpp_reader *, int));
268extern void _cpp_dump_definition PARAMS ((cpp_reader *, const U_CHAR *,
269 long, DEFINITION *));
270extern int _cpp_compare_defs PARAMS ((cpp_reader *, DEFINITION *,
271 DEFINITION *));
45b966db 272extern void _cpp_quote_string PARAMS ((cpp_reader *, const char *));
d35364d1
ZW
273extern void _cpp_macroexpand PARAMS ((cpp_reader *, HASHNODE *));
274extern void _cpp_init_macro_hash PARAMS ((cpp_reader *));
275extern void _cpp_dump_macro_hash PARAMS ((cpp_reader *));
bb52fa7f 276
88ae23e7
ZW
277/* In cppfiles.c */
278extern void _cpp_simplify_pathname PARAMS ((char *));
168d3732
ZW
279extern void _cpp_execute_include PARAMS ((cpp_reader *, char *,
280 unsigned int, int,
281 struct file_name_list *));
d35364d1 282extern void _cpp_init_include_hash PARAMS ((cpp_reader *));
88ae23e7
ZW
283
284/* In cppexp.c */
285extern int _cpp_parse_expr PARAMS ((cpp_reader *));
286
45b966db
ZW
287/* In cpplex.c */
288extern void _cpp_parse_name PARAMS ((cpp_reader *, int));
289extern void _cpp_skip_rest_of_line PARAMS ((cpp_reader *));
290extern void _cpp_skip_hspace PARAMS ((cpp_reader *));
291extern int _cpp_parse_assertion PARAMS ((cpp_reader *));
292extern enum cpp_token _cpp_lex_token PARAMS ((cpp_reader *));
293extern long _cpp_read_and_prescan PARAMS ((cpp_reader *, cpp_buffer *,
294 int, size_t));
295extern void _cpp_init_input_buffer PARAMS ((cpp_reader *));
296extern void _cpp_grow_token_buffer PARAMS ((cpp_reader *, long));
297extern enum cpp_token _cpp_get_directive_token
298 PARAMS ((cpp_reader *));
299
300/* In cpplib.c */
301extern int _cpp_handle_directive PARAMS ((cpp_reader *));
302extern void _cpp_handle_eof PARAMS ((cpp_reader *));
303extern void _cpp_output_line_command PARAMS ((cpp_reader *,
304 enum file_change_code));
305
306
bb52fa7f 307#endif
This page took 0.565199 seconds and 5 git commands to generate.