Fix typos in comment
[official-gcc.git] / gcc / cpphash.h
blob5f4f86bedb656b70322604fa19f90627321bbf92
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
7 later version.
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. */
30 enum spell_type
32 SPELL_OPERATOR = 0,
33 SPELL_CHAR,
34 SPELL_IDENT,
35 SPELL_STRING,
36 SPELL_NONE
39 struct token_spelling
41 ENUM_BITFIELD(spell_type) type : CHAR_BIT;
42 const U_CHAR *spelling;
45 extern const struct token_spelling token_spellings[];
46 #define TOKEN_SPELL(token) (token_spellings[(token)->type].type)
48 /* Chained list of answers to an assertion. */
49 struct answer
51 struct answer *next;
52 cpp_toklist list;
54 #define FREE_ANSWER(answer) do {_cpp_free_toklist (&answer->list); \
55 free (answer); } while (0)
57 /* Values for the origin field of struct directive. KANDR directives
58 come from traditional (K&R) C. STDC89 directives come from the
59 1989 C standard. EXTENSION directives are extensions. */
60 #define KANDR 0
61 #define STDC89 1
62 #define EXTENSION 2
64 /* Values for the flags field of struct directive. COND indicates a
65 conditional. EXPAND means that macros are to be expanded on the
66 directive line. INCL means to treat "..." and <...> as
67 q-char-sequence and h-char-sequence respectively. COMMENTS means
68 preserve comments in the directive if -C. */
69 #define COND (1 << 0)
70 #define EXPAND (1 << 1)
71 #define INCL (1 << 2)
72 #define COMMENTS (1 << 3)
74 /* Defines one #-directive, including how to handle it. */
75 typedef int (*directive_handler) PARAMS ((cpp_reader *));
76 struct directive
78 directive_handler handler; /* Function to handle directive. */
79 const U_CHAR *name; /* Name of directive. */
80 unsigned short length; /* Length of name. */
81 unsigned char origin; /* Origin of directive. */
82 unsigned char flags; /* Flags describing this directive. */
85 /* List of directories to look for include files in. */
86 struct file_name_list
88 struct file_name_list *next;
89 struct file_name_list *alloc; /* for the cache of
90 current directory entries */
91 char *name;
92 unsigned int nlen;
93 /* We use these to tell if the directory mentioned here is a duplicate
94 of an earlier directory on the search path. */
95 ino_t ino;
96 dev_t dev;
97 /* If the following is nonzero, it is a C-language system include
98 directory. */
99 int sysp;
100 /* Mapping of file names for this directory.
101 Only used on MS-DOS and related platforms. */
102 struct file_name_map *name_map;
104 #define ABSOLUTE_PATH ((struct file_name_list *)-1)
106 /* This structure is used for the table of all includes. */
107 struct include_file
109 const char *name; /* actual path name of file */
110 const cpp_hashnode *cmacro; /* macro, if any, preventing reinclusion. */
111 const struct file_name_list *foundhere;
112 /* location in search path where file was
113 found, for #include_next */
114 int fd; /* file descriptor possibly open on file */
115 unsigned short include_count; /* number of times file has been read */
116 unsigned short sysp; /* file is a system header */
117 time_t date; /* modification date of file, if known */
120 /* Special nodes - identifiers with predefined significance.
121 Note that the array length of dirs[] must be kept in sync with
122 cpplib.c's dtable[]. */
123 struct spec_nodes
125 cpp_hashnode *n_L; /* L"str" */
126 cpp_hashnode *n_defined; /* #if defined */
127 cpp_hashnode *n__STRICT_ANSI__; /* STDC_0_IN_SYSTEM_HEADERS */
128 cpp_hashnode *n__CHAR_UNSIGNED__; /* plain char is unsigned */
129 cpp_hashnode *n__VA_ARGS__; /* C99 vararg macros */
130 cpp_hashnode *dirs[19]; /* 19 directives counting #sccs */
134 /* The cmacro works like this: If it's NULL, the file is to be
135 included again. If it's NEVER_REREAD, the file is never to be
136 included again. Otherwise it is a macro hashnode, and the file is
137 to be included again if the macro is not defined. */
138 #define NEVER_REREAD ((const cpp_hashnode *)-1)
139 #define DO_NOT_REREAD(inc) \
140 ((inc)->cmacro && \
141 ((inc)->cmacro == NEVER_REREAD || (inc)->cmacro->type != T_VOID))
143 /* Character classes.
144 If the definition of `numchar' looks odd to you, please look up the
145 definition of a pp-number in the C standard [section 6.4.8 of C99].
147 In the unlikely event that characters other than \r and \n enter
148 the set is_vspace, the macro handle_newline() in cpplex.c must be
149 updated. */
150 #define ISidnum 0x01 /* a-zA-Z0-9_ */
151 #define ISidstart 0x02 /* _a-zA-Z */
152 #define ISnumstart 0x04 /* 0-9 */
153 #define IShspace 0x08 /* ' ' \t */
154 #define ISvspace 0x10 /* \r \n */
155 #define ISspace 0x20 /* ' ' \t \r \n \f \v \0 */
157 #define _dollar_ok(x) ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident))
159 #define is_idchar(x) ((_cpp_IStable[x] & ISidnum) || _dollar_ok(x))
160 #define is_idstart(x) ((_cpp_IStable[x] & ISidstart) || _dollar_ok(x))
161 #define is_numchar(x) (_cpp_IStable[x] & ISidnum)
162 #define is_numstart(x) (_cpp_IStable[x] & ISnumstart)
163 #define is_hspace(x) (_cpp_IStable[x] & IShspace)
164 #define is_vspace(x) (_cpp_IStable[x] & ISvspace)
165 #define is_nvspace(x) ((_cpp_IStable[x] & (ISspace | ISvspace)) == ISspace)
166 #define is_space(x) (_cpp_IStable[x] & ISspace)
168 /* This table is constant if it can be initialized at compile time,
169 which is the case if cpp was compiled with GCC >=2.7, or another
170 compiler that supports C99. */
171 #if (GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L)
172 extern const unsigned char _cpp_IStable[256];
173 #else
174 extern unsigned char _cpp_IStable[256];
175 #endif
177 /* Macros. */
179 /* Make sure PFILE->token_buffer has space for at least N more characters. */
180 #define CPP_RESERVE(PFILE, N) \
181 (CPP_WRITTEN (PFILE) + (size_t)(N) > (PFILE)->token_buffer_size \
182 && (_cpp_grow_token_buffer (PFILE, N), 0))
184 /* Append string STR (of length N) to PFILE's output buffer.
185 Assume there is enough space. */
186 #define CPP_PUTS_Q(PFILE, STR, N) \
187 (memcpy ((PFILE)->limit, STR, (N)), (PFILE)->limit += (N))
188 /* Append string STR (of length N) to PFILE's output buffer. Make space. */
189 #define CPP_PUTS(PFILE, STR, N) CPP_RESERVE(PFILE, N), CPP_PUTS_Q(PFILE, STR,N)
190 /* Append character CH to PFILE's output buffer. Assume sufficient space. */
191 #define CPP_PUTC_Q(PFILE, CH) (*(PFILE)->limit++ = (CH))
192 /* Append character CH to PFILE's output buffer. Make space if need be. */
193 #define CPP_PUTC(PFILE, CH) (CPP_RESERVE (PFILE, 1), CPP_PUTC_Q (PFILE, CH))
195 #define CPP_PREV_BUFFER(BUFFER) ((BUFFER)->prev)
196 #define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps)
197 #define CPP_IN_SYSTEM_HEADER(PFILE) \
198 (CPP_BUFFER (PFILE) && CPP_BUFFER (PFILE)->inc \
199 && CPP_BUFFER (PFILE)->inc->sysp)
200 #define CPP_PEDANTIC(PF) \
201 (CPP_OPTION (PF, pedantic) && !CPP_IN_SYSTEM_HEADER (PF))
202 #define CPP_WTRADITIONAL(PF) \
203 (CPP_OPTION (PF, warn_traditional) && !CPP_IN_SYSTEM_HEADER (PF))
205 /* Flags for _cpp_init_toklist. */
206 #define DUMMY_TOKEN 0
207 #define NO_DUMMY_TOKEN 1
209 /* In cpphash.c */
210 extern unsigned int _cpp_calc_hash PARAMS ((const U_CHAR *, size_t));
211 extern void _cpp_free_definition PARAMS ((cpp_hashnode *));
212 extern int _cpp_create_definition PARAMS ((cpp_reader *, cpp_hashnode *));
213 extern void _cpp_dump_definition PARAMS ((cpp_reader *, cpp_hashnode *));
214 extern void _cpp_init_macros PARAMS ((cpp_reader *));
215 extern void _cpp_cleanup_macros PARAMS ((cpp_reader *));
216 extern void _cpp_dump_macro_hash PARAMS ((cpp_reader *));
218 /* In cppfiles.c */
219 extern void _cpp_simplify_pathname PARAMS ((char *));
220 extern void _cpp_execute_include PARAMS ((cpp_reader *, const U_CHAR *,
221 unsigned int, int,
222 struct file_name_list *,
223 int));
224 extern int _cpp_compare_file_date PARAMS ((cpp_reader *, const U_CHAR *,
225 unsigned int, int));
226 extern void _cpp_report_missing_guards PARAMS ((cpp_reader *));
227 extern void _cpp_init_includes PARAMS ((cpp_reader *));
228 extern void _cpp_cleanup_includes PARAMS ((cpp_reader *));
229 extern const char *_cpp_fake_include PARAMS ((cpp_reader *, const char *));
230 extern void _cpp_pop_file_buffer PARAMS ((cpp_reader *, cpp_buffer *));
232 /* In cppexp.c */
233 extern int _cpp_parse_expr PARAMS ((cpp_reader *));
235 /* In cpplex.c */
236 extern void _cpp_skip_rest_of_line PARAMS ((cpp_reader *));
237 extern void _cpp_free_temp_tokens PARAMS ((cpp_reader *));
238 extern void _cpp_init_input_buffer PARAMS ((cpp_reader *));
239 extern void _cpp_grow_token_buffer PARAMS ((cpp_reader *, long));
240 extern void _cpp_init_toklist PARAMS ((cpp_toklist *, int));
241 extern void _cpp_clear_toklist PARAMS ((cpp_toklist *));
242 extern void _cpp_free_toklist PARAMS ((const cpp_toklist *));
243 extern int _cpp_equiv_tokens PARAMS ((const cpp_token *,
244 const cpp_token *));
245 extern int _cpp_equiv_toklists PARAMS ((const cpp_toklist *,
246 const cpp_toklist *));
247 extern void _cpp_expand_token_space PARAMS ((cpp_toklist *, unsigned int));
248 extern void _cpp_reserve_name_space PARAMS ((cpp_toklist *, unsigned int));
249 extern void _cpp_expand_name_space PARAMS ((cpp_toklist *, unsigned int));
250 extern void _cpp_dump_list PARAMS ((cpp_reader *,
251 const cpp_toklist *,
252 const cpp_token *, int));
253 extern int _cpp_equiv_tokens PARAMS ((const cpp_token *,
254 const cpp_token *));
255 extern void _cpp_run_directive PARAMS ((cpp_reader *,
256 const struct directive *,
257 const char *, size_t));
258 extern unsigned int _cpp_get_line PARAMS ((cpp_reader *,
259 unsigned int *));
260 extern const cpp_token *_cpp_get_token PARAMS ((cpp_reader *));
261 extern const cpp_token *_cpp_get_raw_token PARAMS ((cpp_reader *));
262 extern void _cpp_push_token PARAMS ((cpp_reader *, const cpp_token*));
263 extern const cpp_token *_cpp_glue_header_name PARAMS ((cpp_reader *));
264 extern const U_CHAR *_cpp_spell_operator PARAMS ((enum cpp_ttype));
266 /* In cpplib.c */
267 extern const struct directive *_cpp_check_directive
268 PARAMS ((cpp_reader *, const cpp_token *, int));
269 extern const struct directive *_cpp_check_linemarker
270 PARAMS ((cpp_reader *, const cpp_token *, int));
271 extern cpp_hashnode *_cpp_parse_assertion PARAMS ((cpp_reader *,
272 struct answer **));
273 extern struct answer **_cpp_find_answer PARAMS ((cpp_hashnode *,
274 const cpp_toklist *));
275 extern void _cpp_init_stacks PARAMS ((cpp_reader *));
276 extern void _cpp_cleanup_stacks PARAMS ((cpp_reader *));
278 /* Utility routines and macros. */
279 #define xnew(T) (T *) xmalloc (sizeof(T))
280 #define xnewvec(T, N) (T *) xmalloc (sizeof(T) * (N))
281 #define xobnew(O, T) (T *) obstack_alloc (O, sizeof(T))
283 /* These are inline functions instead of macros so we can get type
284 checking. */
286 static inline int ustrcmp PARAMS ((const U_CHAR *, const U_CHAR *));
287 static inline int ustrncmp PARAMS ((const U_CHAR *, const U_CHAR *,
288 size_t));
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));
293 static inline int
294 ustrcmp (s1, s2)
295 const U_CHAR *s1, *s2;
297 return strcmp ((const char *)s1, (const char *)s2);
300 static inline int
301 ustrncmp (s1, s2, n)
302 const U_CHAR *s1, *s2;
303 size_t n;
305 return strncmp ((const char *)s1, (const char *)s2, n);
308 static inline size_t
309 ustrlen (s1)
310 const U_CHAR *s1;
312 return strlen ((const char *)s1);
315 static inline U_CHAR *
316 uxstrdup (s1)
317 const U_CHAR *s1;
319 return (U_CHAR *) xstrdup ((const char *)s1);
322 static inline U_CHAR *
323 ustrchr (s1, c)
324 const U_CHAR *s1;
325 int c;
327 return (U_CHAR *) strchr ((const char *)s1, c);
330 #endif