1 /* Part of CPP library.
2 Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 2, or (at your option) any
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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. */
22 #ifndef __GCC_CPPHASH__
23 #define __GCC_CPPHASH__
25 typedef unsigned char U_CHAR;
26 #define U (const U_CHAR *) /* Intended use: U"string" */
28 /* The structure of a node in the hash table. The hash table
29 has entries for all tokens defined by #define commands (type T_MACRO),
30 plus some special tokens like __LINE__ (these each have their own
31 type, and the appropriate code is run when that type of node is seen.
32 It does not contain control words like "#define", which are recognized
33 by a separate piece of code. */
35 /* different flavors of hash nodes */
38 T_VOID = 0, /* no definition yet */
39 T_SPECLINE, /* `__LINE__' */
40 T_DATE, /* `__DATE__' */
41 T_FILE, /* `__FILE__' */
42 T_BASE_FILE, /* `__BASE_FILE__' */
43 T_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */
44 T_TIME, /* `__TIME__' */
45 T_STDC, /* `__STDC__' */
46 T_CONST, /* Constant string, used by `__SIZE_TYPE__' etc */
47 T_XCONST, /* Ditto, but the string is malloced memory */
48 T_POISON, /* poisoned identifier */
49 T_MACRO, /* object-like macro */
50 T_FMACRO, /* function-like macro */
51 T_IDENTITY, /* macro defined to itself */
52 T_EMPTY, /* macro defined to nothing */
53 T_ASSERTION /* predicate for #assert */
56 typedef struct hashnode HASHNODE;
59 unsigned int hash; /* cached hash value */
60 unsigned short length; /* length of name */
61 ENUM_BITFIELD(node_type) type : 8; /* node type */
62 char disabled; /* macro turned off for rescan? */
65 const U_CHAR *cpval; /* some predefined macros */
66 const struct object_defn *odefn; /* #define foo bar */
67 const struct funct_defn *fdefn; /* #define foo(x) bar(x) */
68 struct predicate *pred; /* #assert */
71 const U_CHAR name[1]; /* name[length] */
74 /* Structure used for assertion predicates. */
77 struct predicate *next;
78 struct cpp_toklist answer;
81 /* List of directories to look for include files in. */
84 struct file_name_list *next;
85 struct file_name_list *alloc; /* for the cache of
86 current directory entries */
89 /* We use these to tell if the directory mentioned here is a duplicate
90 of an earlier directory on the search path. */
93 /* If the following is nonzero, it is a C-language system include
96 /* Mapping of file names for this directory.
97 Only used on MS-DOS and related platforms. */
98 struct file_name_map *name_map;
100 #define ABSOLUTE_PATH ((struct file_name_list *)-1)
102 /* This structure is used for the table of all includes. It is
103 indexed by the `short name' (the name as it appeared in the
104 #include statement) which is stored in *nshort. */
107 /* Next file with the same short name but a
108 different (partial) pathname). */
109 struct ihash *next_this_file;
111 /* Location of the file in the include search path.
112 Used for include_next */
113 struct file_name_list *foundhere;
115 unsigned int hash; /* save hash value for future reference */
116 const char *nshort; /* name of file as referenced in #include;
117 points into name[] */
118 const U_CHAR *control_macro; /* macro, if any, preventing reinclusion -
119 see redundant_include_p */
120 const char name[1]; /* (partial) pathname of file */
122 typedef struct ihash IHASH;
124 /* Character classes.
125 If the definition of `numchar' looks odd to you, please look up the
126 definition of a pp-number in the C standard [section 6.4.8 of C99] */
127 #define ISidnum 0x01 /* a-zA-Z0-9_ */
128 #define ISidstart 0x02 /* _a-zA-Z */
129 #define ISnumstart 0x04 /* 0-9 */
130 #define IShspace 0x08 /* ' ' \t \f \v */
131 #define ISspace 0x10 /* ' ' \t \f \v \n */
133 #define _dollar_ok(x) ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident))
135 #define is_idchar(x) ((_cpp_IStable[x] & ISidnum) || _dollar_ok(x))
136 #define is_idstart(x) ((_cpp_IStable[x] & ISidstart) || _dollar_ok(x))
137 #define is_numchar(x) (_cpp_IStable[x] & ISidnum)
138 #define is_numstart(x) (_cpp_IStable[x] & ISnumstart)
139 #define is_hspace(x) (_cpp_IStable[x] & IShspace)
140 #define is_space(x) (_cpp_IStable[x] & ISspace)
142 /* This table is constant if it can be initialized at compile time,
143 which is the case if cpp was compiled with GCC >=2.7, or another
144 compiler that supports C99. */
145 #if (GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L)
146 extern const unsigned char _cpp_IStable[256];
148 extern unsigned char _cpp_IStable[256];
153 /* One character lookahead in the input buffer. Note that if this
154 returns EOF, it does *not* necessarily mean the file's end has been
156 #define CPP_BUF_PEEK(BUFFER) \
157 ((BUFFER)->cur < (BUFFER)->rlimit ? *(BUFFER)->cur : EOF)
159 /* Make sure PFILE->token_buffer has space for at least N more characters. */
160 #define CPP_RESERVE(PFILE, N) \
161 (CPP_WRITTEN (PFILE) + (size_t)(N) > (PFILE)->token_buffer_size \
162 && (_cpp_grow_token_buffer (PFILE, N), 0))
164 /* Append string STR (of length N) to PFILE's output buffer.
165 Assume there is enough space. */
166 #define CPP_PUTS_Q(PFILE, STR, N) \
167 (memcpy ((PFILE)->limit, STR, (N)), (PFILE)->limit += (N))
168 /* Append string STR (of length N) to PFILE's output buffer. Make space. */
169 #define CPP_PUTS(PFILE, STR, N) CPP_RESERVE(PFILE, N), CPP_PUTS_Q(PFILE, STR,N)
170 /* Append character CH to PFILE's output buffer. Assume sufficient space. */
171 #define CPP_PUTC_Q(PFILE, CH) (*(PFILE)->limit++ = (CH))
172 /* Append character CH to PFILE's output buffer. Make space if need be. */
173 #define CPP_PUTC(PFILE, CH) (CPP_RESERVE (PFILE, 1), CPP_PUTC_Q (PFILE, CH))
175 /* Advance the current line by one. */
176 #define CPP_BUMP_BUFFER_LINE(PBUF) ((PBUF)->lineno++,\
177 (PBUF)->line_base = (PBUF)->cur)
178 #define CPP_BUMP_LINE(PFILE) CPP_BUMP_BUFFER_LINE(CPP_BUFFER(PFILE))
179 #define CPP_BUMP_BUFFER_LINE_CUR(PBUF, CUR) ((PBUF)->lineno++,\
180 (PBUF)->line_base = CUR)
181 #define CPP_BUMP_LINE_CUR(PFILE, CUR) \
182 CPP_BUMP_BUFFER_LINE_CUR(CPP_BUFFER(PFILE), CUR)
183 #define CPP_PREV_BUFFER(BUFFER) ((BUFFER)->prev)
185 /* Are we in column 1 right now? Used mainly for -traditional handling
187 #define CPP_IN_COLUMN_1(PFILE) \
188 (CPP_BUFFER (PFILE)->cur - CPP_BUFFER (PFILE)->line_base == 1)
190 #define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps)
191 #define CPP_TRADITIONAL(PFILE) CPP_OPTION (PFILE, traditional)
192 #define CPP_PEDANTIC(PFILE) \
193 (CPP_OPTION (PFILE, pedantic) && !CPP_BUFFER (PFILE)->system_header_p)
194 #define CPP_WTRADITIONAL(PF) \
195 (CPP_OPTION (PF, warn_traditional) && !CPP_BUFFER (PF)->system_header_p)
197 /* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion.
198 (Note that it is false while we're expanding macro *arguments*.) */
199 #define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->macro != NULL)
201 /* Remember the current position of PFILE so it may be returned to
202 after looking ahead a bit.
204 Note that when you set a mark, you _must_ return to that mark. You
205 may not forget about it and continue parsing. You may not pop a
206 buffer with an active mark. You may not call CPP_BUMP_LINE while a
208 #define CPP_SET_BUF_MARK(IP) ((IP)->mark = (IP)->cur)
209 #define CPP_GOTO_BUF_MARK(IP) ((IP)->cur = (IP)->mark, (IP)->mark = 0)
210 #define CPP_SET_MARK(PFILE) CPP_SET_BUF_MARK(CPP_BUFFER(PFILE))
211 #define CPP_GOTO_MARK(PFILE) CPP_GOTO_BUF_MARK(CPP_BUFFER(PFILE))
213 /* ACTIVE_MARK_P is true if there's a live mark in the buffer. */
214 #define ACTIVE_MARK_P(PFILE) (CPP_BUFFER (PFILE)->mark != 0)
216 /* Are mark and point adjacent characters? Used mostly to deal with
217 the somewhat annoying semantic of #define. */
218 #define ADJACENT_TO_MARK(PFILE) \
219 (CPP_BUFFER(PFILE)->cur - CPP_BUFFER(PFILE)->mark == 1)
222 extern unsigned int _cpp_calc_hash PARAMS ((const U_CHAR *, size_t));
223 extern HASHNODE *_cpp_lookup PARAMS ((cpp_reader *,
224 const U_CHAR *, int));
225 extern void _cpp_free_definition PARAMS ((HASHNODE *));
226 extern int _cpp_create_definition PARAMS ((cpp_reader *,
227 cpp_toklist *, HASHNODE *));
228 extern void _cpp_dump_definition PARAMS ((cpp_reader *, HASHNODE *));
229 extern void _cpp_quote_string PARAMS ((cpp_reader *, const U_CHAR *));
230 extern void _cpp_macroexpand PARAMS ((cpp_reader *, HASHNODE *));
231 extern void _cpp_init_macro_hash PARAMS ((cpp_reader *));
232 extern void _cpp_dump_macro_hash PARAMS ((cpp_reader *));
235 extern void _cpp_simplify_pathname PARAMS ((char *));
236 extern void _cpp_execute_include PARAMS ((cpp_reader *, U_CHAR *,
238 struct file_name_list *));
239 extern void _cpp_init_include_hash PARAMS ((cpp_reader *));
240 extern const char *_cpp_fake_ihash PARAMS ((cpp_reader *, const char *));
243 extern int _cpp_parse_expr PARAMS ((cpp_reader *));
246 extern void _cpp_parse_name PARAMS ((cpp_reader *, int));
247 extern void _cpp_skip_rest_of_line PARAMS ((cpp_reader *));
248 extern void _cpp_skip_hspace PARAMS ((cpp_reader *));
249 extern void _cpp_expand_to_buffer PARAMS ((cpp_reader *,
250 const unsigned char *, int));
251 extern int _cpp_parse_assertion PARAMS ((cpp_reader *));
252 extern enum cpp_ttype _cpp_lex_token PARAMS ((cpp_reader *));
253 extern long _cpp_read_and_prescan PARAMS ((cpp_reader *, cpp_buffer *,
255 extern void _cpp_init_input_buffer PARAMS ((cpp_reader *));
256 extern void _cpp_grow_token_buffer PARAMS ((cpp_reader *, long));
257 extern enum cpp_ttype _cpp_get_directive_token
258 PARAMS ((cpp_reader *));
259 extern enum cpp_ttype _cpp_get_define_token
260 PARAMS ((cpp_reader *));
261 extern enum cpp_ttype _cpp_scan_until PARAMS ((cpp_reader *, cpp_toklist *,
263 extern void _cpp_init_toklist PARAMS ((cpp_toklist *));
264 extern void _cpp_clear_toklist PARAMS ((cpp_toklist *));
265 extern void _cpp_free_toklist PARAMS ((cpp_toklist *));
266 extern void _cpp_slice_toklist PARAMS ((cpp_toklist *,
269 extern void _cpp_squeeze_toklist PARAMS ((cpp_toklist *));
270 extern int _cpp_equiv_tokens PARAMS ((const cpp_token *,
272 extern int _cpp_equiv_toklists PARAMS ((const cpp_toklist *,
273 const cpp_toklist *));
277 extern int _cpp_handle_directive PARAMS ((cpp_reader *));
278 extern void _cpp_unwind_if_stack PARAMS ((cpp_reader *, cpp_buffer *));
279 extern void _cpp_check_directive PARAMS ((cpp_toklist *, cpp_token *));
281 /* These are inline functions instead of macros so we can get type
284 static inline int ustrcmp PARAMS ((const U_CHAR *, const U_CHAR *));
285 static inline int ustrncmp PARAMS ((const U_CHAR *, const U_CHAR *,
287 static inline size_t ustrlen PARAMS ((const U_CHAR *));
288 static inline U_CHAR *uxstrdup PARAMS ((const U_CHAR *));
289 static inline U_CHAR *ustrchr PARAMS ((const U_CHAR *, int));
293 const U_CHAR *s1, *s2;
295 return strcmp ((const char *)s1, (const char *)s2);
300 const U_CHAR *s1, *s2;
303 return strncmp ((const char *)s1, (const char *)s2, n);
310 return strlen ((const char *)s1);
313 static inline U_CHAR *
317 return (U_CHAR *) xstrdup ((const char *)s1);
320 static inline U_CHAR *
325 return (U_CHAR *) strchr ((const char *)s1, c);