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 /* Tokens with SPELL_STRING store their spelling in the token list,
29 and it's length in the token->val.name.len. */
41 enum spell_type category;
45 extern const struct token_spelling _cpp_token_spellings[];
46 #define TOKEN_SPELL(token) (_cpp_token_spellings[(token)->type].category)
47 #define TOKEN_NAME(token) (_cpp_token_spellings[(token)->type].name)
49 /* Chained list of answers to an assertion. */
55 #define FREE_ANSWER(answer) do {_cpp_free_toklist (&answer->list); \
56 free (answer); } while (0)
58 /* Values for the origin field of struct directive. KANDR directives
59 come from traditional (K&R) C. STDC89 directives come from the
60 1989 C standard. EXTENSION directives are extensions. */
65 /* Values for the flags field of struct directive. COND indicates a
66 conditional. EXPAND means that macros are to be expanded on the
67 directive line. INCL means to treat "..." and <...> as
68 q-char-sequence and h-char-sequence respectively. COMMENTS means
69 preserve comments in the directive if -C. IN_I means this directive
70 should be handled even if -fpreprocessed is in effect (these are the
71 directives with callback hooks). */
73 #define EXPAND (1 << 1)
75 #define COMMENTS (1 << 3)
78 /* Defines one #-directive, including how to handle it. */
79 typedef void (*directive_handler) PARAMS ((cpp_reader *));
82 directive_handler handler; /* Function to handle directive. */
83 const U_CHAR *name; /* Name of directive. */
84 unsigned short length; /* Length of name. */
85 unsigned char origin; /* Origin of directive. */
86 unsigned char flags; /* Flags describing this directive. */
89 /* List of directories to look for include files in. */
92 struct file_name_list *next;
93 struct file_name_list *alloc; /* for the cache of
94 current directory entries */
97 /* We use these to tell if the directory mentioned here is a duplicate
98 of an earlier directory on the search path. */
101 /* If the following is nonzero, it is a C-language system include
104 /* Mapping of file names for this directory.
105 Only used on MS-DOS and related platforms. */
106 struct file_name_map *name_map;
108 #define ABSOLUTE_PATH ((struct file_name_list *)-1)
110 /* This structure is used for the table of all includes. */
113 const char *name; /* actual path name of file */
114 const cpp_hashnode *cmacro; /* macro, if any, preventing reinclusion. */
115 const struct file_name_list *foundhere;
116 /* location in search path where file was
117 found, for #include_next */
118 const unsigned char *buffer; /* pointer to cached file contents */
119 struct stat st; /* copy of stat(2) data for file */
120 int fd; /* fd open on file (short term storage only) */
121 unsigned short include_count; /* number of times file has been read */
122 unsigned short refcnt; /* number of stacked buffers using this file */
123 unsigned char sysp; /* file is a system header */
124 unsigned char mapped; /* file buffer is mmapped */
127 /* The cmacro works like this: If it's NULL, the file is to be
128 included again. If it's NEVER_REREAD, the file is never to be
129 included again. Otherwise it is a macro hashnode, and the file is
130 to be included again if the macro is not defined. */
131 #define NEVER_REREAD ((const cpp_hashnode *)-1)
132 #define DO_NOT_REREAD(inc) \
134 ((inc)->cmacro == NEVER_REREAD || (inc)->cmacro->type != T_VOID))
136 /* Special nodes - identifiers with predefined significance.
137 Note that the array length of dirs[] must be kept in sync with
138 cpplib.c's dtable[]. */
141 cpp_hashnode *n_L; /* L"str" */
142 cpp_hashnode *n__STRICT_ANSI__; /* STDC_0_IN_SYSTEM_HEADERS */
143 cpp_hashnode *n__CHAR_UNSIGNED__; /* plain char is unsigned */
144 cpp_hashnode *n__VA_ARGS__; /* C99 vararg macros */
145 cpp_hashnode *dirs[19]; /* 19 directives counting #sccs */
148 /* Character classes.
149 If the definition of `numchar' looks odd to you, please look up the
150 definition of a pp-number in the C standard [section 6.4.8 of C99].
152 In the unlikely event that characters other than \r and \n enter
153 the set is_vspace, the macro handle_newline() in cpplex.c must be
155 #define ISidnum 0x01 /* a-zA-Z0-9_ */
156 #define ISidstart 0x02 /* _a-zA-Z */
157 #define ISnumstart 0x04 /* 0-9 */
158 #define IShspace 0x08 /* ' ' \t */
159 #define ISvspace 0x10 /* \r \n */
160 #define ISspace 0x20 /* ' ' \t \r \n \f \v \0 */
162 #define _dollar_ok(x) ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident))
164 #define is_idchar(x) ((_cpp_IStable[x] & ISidnum) || _dollar_ok(x))
165 #define is_idstart(x) ((_cpp_IStable[x] & ISidstart) || _dollar_ok(x))
166 #define is_numchar(x) (_cpp_IStable[x] & ISidnum)
167 #define is_numstart(x) (_cpp_IStable[x] & ISnumstart)
168 #define is_hspace(x) (_cpp_IStable[x] & IShspace)
169 #define is_vspace(x) (_cpp_IStable[x] & ISvspace)
170 #define is_nvspace(x) ((_cpp_IStable[x] & (ISspace | ISvspace)) == ISspace)
171 #define is_space(x) (_cpp_IStable[x] & ISspace)
173 /* These tables are constant if they can be initialized at compile time,
174 which is the case if cpp was compiled with GCC >=2.7, or another
175 compiler that supports C99. */
176 #if HAVE_DESIGNATED_INITIALIZERS
177 extern const unsigned char _cpp_IStable[UCHAR_MAX + 1];
178 extern const unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
180 extern unsigned char _cpp_IStable[UCHAR_MAX + 1];
181 extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
186 #define CPP_PREV_BUFFER(BUFFER) ((BUFFER)->prev)
187 #define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps)
188 #define CPP_IN_SYSTEM_HEADER(PFILE) \
189 (CPP_BUFFER (PFILE) && CPP_BUFFER (PFILE)->inc \
190 && CPP_BUFFER (PFILE)->inc->sysp)
191 #define CPP_PEDANTIC(PF) \
192 (CPP_OPTION (PF, pedantic) && !CPP_IN_SYSTEM_HEADER (PF))
193 #define CPP_WTRADITIONAL(PF) \
194 (CPP_OPTION (PF, warn_traditional) && !CPP_IN_SYSTEM_HEADER (PF))
196 /* Hash step. The hash calculation is duplicated in cpp_lookup and
198 #define HASHSTEP(r, c) ((r) * 67 + (c - 113));
201 enum error_type { WARNING = 0, PEDWARN, ERROR, FATAL, ICE };
202 extern int _cpp_begin_message PARAMS ((cpp_reader *, enum error_type,
203 const char *, unsigned int,
207 extern void _cpp_free_definition PARAMS ((cpp_hashnode *));
208 extern int _cpp_create_definition PARAMS ((cpp_reader *, cpp_hashnode *));
211 extern void _cpp_init_macros PARAMS ((cpp_reader *));
212 extern void _cpp_cleanup_macros PARAMS ((cpp_reader *));
213 extern cpp_hashnode *_cpp_lookup_with_hash PARAMS ((cpp_reader*, const U_CHAR *,
214 size_t, unsigned int));
217 extern void _cpp_simplify_pathname PARAMS ((char *));
218 extern void _cpp_execute_include PARAMS ((cpp_reader *, const U_CHAR *,
220 struct file_name_list *,
222 extern int _cpp_compare_file_date PARAMS ((cpp_reader *, const U_CHAR *,
224 extern void _cpp_report_missing_guards PARAMS ((cpp_reader *));
225 extern void _cpp_init_includes PARAMS ((cpp_reader *));
226 extern void _cpp_cleanup_includes PARAMS ((cpp_reader *));
227 extern const char *_cpp_fake_include PARAMS ((cpp_reader *, const char *));
228 extern void _cpp_pop_file_buffer PARAMS ((cpp_reader *, cpp_buffer *));
231 extern int _cpp_parse_expr PARAMS ((cpp_reader *));
234 extern void _cpp_skip_rest_of_line PARAMS ((cpp_reader *));
235 extern void _cpp_free_temp_tokens PARAMS ((cpp_reader *));
236 extern void _cpp_init_input_buffer PARAMS ((cpp_reader *));
237 extern void _cpp_grow_token_buffer PARAMS ((cpp_reader *, long));
238 extern void _cpp_init_toklist PARAMS ((cpp_toklist *, int));
239 extern void _cpp_clear_toklist PARAMS ((cpp_toklist *));
240 extern void _cpp_free_toklist PARAMS ((const cpp_toklist *));
241 extern int _cpp_equiv_tokens PARAMS ((const cpp_token *,
243 extern int _cpp_equiv_toklists PARAMS ((const cpp_toklist *,
244 const cpp_toklist *));
245 extern void _cpp_expand_token_space PARAMS ((cpp_toklist *, unsigned int));
246 extern void _cpp_reserve_name_space PARAMS ((cpp_toklist *, unsigned int));
247 extern void _cpp_expand_name_space PARAMS ((cpp_toklist *, unsigned int));
248 extern int _cpp_equiv_tokens PARAMS ((const cpp_token *,
250 extern void _cpp_run_directive PARAMS ((cpp_reader *,
251 const struct directive *,
252 const char *, size_t,
254 extern unsigned int _cpp_get_line PARAMS ((cpp_reader *,
256 extern const cpp_token *_cpp_get_token PARAMS ((cpp_reader *));
257 extern const cpp_token *_cpp_get_raw_token PARAMS ((cpp_reader *));
258 extern void _cpp_push_token PARAMS ((cpp_reader *, const cpp_token*));
259 extern const cpp_token *_cpp_glue_header_name PARAMS ((cpp_reader *));
262 extern const struct directive *_cpp_check_directive
263 PARAMS ((cpp_reader *, const cpp_token *));
264 extern const struct directive *_cpp_check_linemarker
265 PARAMS ((cpp_reader *, const cpp_token *));
266 extern cpp_hashnode *_cpp_parse_assertion PARAMS ((cpp_reader *,
268 extern struct answer **_cpp_find_answer PARAMS ((cpp_hashnode *,
269 const cpp_toklist *));
270 extern void _cpp_define_builtin PARAMS ((cpp_reader *, const char *));
272 extern void _cpp_init_stacks PARAMS ((cpp_reader *));
273 extern void _cpp_cleanup_stacks PARAMS ((cpp_reader *));
274 extern void _cpp_init_internal_pragmas PARAMS ((cpp_reader *));
276 /* Utility routines and macros. */
277 #define xnew(T) (T *) xmalloc (sizeof(T))
278 #define xcnew(T) (T *) xcalloc (1, sizeof(T))
279 #define xnewvec(T, N) (T *) xmalloc (sizeof(T) * (N))
280 #define xcnewvec(T, N) (T *) xcalloc (N, sizeof(T))
281 #define xobnew(O, T) (T *) obstack_alloc (O, sizeof(T))
283 /* These are inline functions instead of macros so we can get type
286 static inline int ustrcmp PARAMS ((const U_CHAR *, const U_CHAR *));
287 static inline int ustrncmp PARAMS ((const U_CHAR *, const U_CHAR *,
289 static inline size_t ustrlen PARAMS ((const U_CHAR *));
290 static inline U_CHAR *uxstrdup PARAMS ((const U_CHAR *));
291 static inline U_CHAR *ustrchr PARAMS ((const U_CHAR *, int));
292 static inline int ufputs PARAMS ((const U_CHAR *, FILE *));
296 const U_CHAR *s1, *s2;
298 return strcmp ((const char *)s1, (const char *)s2);
303 const U_CHAR *s1, *s2;
306 return strncmp ((const char *)s1, (const char *)s2, n);
313 return strlen ((const char *)s1);
316 static inline U_CHAR *
320 return (U_CHAR *) xstrdup ((const char *)s1);
323 static inline U_CHAR *
328 return (U_CHAR *) strchr ((const char *)s1, c);
336 return fputs ((const char *)s, f);