]> gcc.gnu.org Git - gcc.git/blob - gcc/cpphash.h
top level:
[gcc.git] / gcc / cpphash.h
1 /* Part of CPP library.
2 Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
3
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.
8
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.
13
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. */
17
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
22 #ifndef __GCC_CPPHASH__
23 #define __GCC_CPPHASH__
24
25 typedef unsigned char U_CHAR;
26 #define U (const U_CHAR *) /* Intended use: U"string" */
27
28 /* Order here matters. Those beyond SPELL_NONE store their spelling
29 in the token list, and it's length in the token->val.name.len. */
30 enum spell_type
31 {
32 SPELL_OPERATOR = 0,
33 SPELL_CHAR,
34 SPELL_NONE,
35 SPELL_IDENT,
36 SPELL_STRING
37 };
38
39 struct token_spelling
40 {
41 ENUM_BITFIELD(spell_type) type : CHAR_BIT;
42 const U_CHAR *spelling;
43 };
44
45 extern const struct token_spelling token_spellings[];
46
47 /* Chained list of answers to an assertion. */
48 struct answer
49 {
50 struct answer *next;
51 cpp_toklist list;
52 };
53 #define FREE_ANSWER(answer) do {_cpp_free_toklist (&answer->list); \
54 free (answer); } while (0)
55
56 /* Values for the origin field of struct directive. KANDR directives
57 come from traditional (K&R) C. STDC89 directives come from the
58 1989 C standard. EXTENSION directives are extensions. */
59 #define KANDR 0
60 #define STDC89 1
61 #define EXTENSION 2
62
63 /* Values for the flags field of struct directive. COND indicates a
64 conditional. EXPAND means that macros are to be expanded on the
65 directive line. INCL means to treat "..." and <...> as
66 q-char-sequence and h-char-sequence respectively. COMMENTS means
67 preserve comments in the directive if -C. */
68 #define COND (1 << 0)
69 #define EXPAND (1 << 1)
70 #define INCL (1 << 2)
71 #define COMMENTS (1 << 3)
72
73 /* Defines one #-directive, including how to handle it. */
74 typedef int (*directive_handler) PARAMS ((cpp_reader *));
75 struct directive
76 {
77 directive_handler handler; /* Function to handle directive. */
78 const U_CHAR *name; /* Name of directive. */
79 unsigned short length; /* Length of name. */
80 unsigned char origin; /* Origin of directive. */
81 unsigned char flags; /* Flags describing this directive. */
82 };
83
84 /* List of directories to look for include files in. */
85 struct file_name_list
86 {
87 struct file_name_list *next;
88 struct file_name_list *alloc; /* for the cache of
89 current directory entries */
90 char *name;
91 unsigned int nlen;
92 /* We use these to tell if the directory mentioned here is a duplicate
93 of an earlier directory on the search path. */
94 ino_t ino;
95 dev_t dev;
96 /* If the following is nonzero, it is a C-language system include
97 directory. */
98 int sysp;
99 /* Mapping of file names for this directory.
100 Only used on MS-DOS and related platforms. */
101 struct file_name_map *name_map;
102 };
103 #define ABSOLUTE_PATH ((struct file_name_list *)-1)
104
105 /* This structure is used for the table of all includes. */
106 struct include_file
107 {
108 const char *name; /* actual path name of file */
109 const cpp_hashnode *cmacro; /* macro, if any, preventing reinclusion. */
110 const struct file_name_list *foundhere;
111 /* location in search path where file was
112 found, for #include_next */
113 int fd; /* file descriptor possibly open on file */
114 unsigned short include_count; /* number of times file has been read */
115 unsigned short sysp; /* file is a system header */
116 time_t date; /* modification date of file, if known */
117 };
118
119 /* The cmacro works like this: If it's NULL, the file is to be
120 included again. If it's NEVER_REREAD, the file is never to be
121 included again. Otherwise it is a macro hashnode, and the file is
122 to be included again if the macro is not defined. */
123 #define NEVER_REREAD ((const cpp_hashnode *)-1)
124 #define DO_NOT_REREAD(inc) \
125 ((inc)->cmacro && \
126 ((inc)->cmacro == NEVER_REREAD || (inc)->cmacro->type != T_VOID))
127
128 /* Character classes.
129 If the definition of `numchar' looks odd to you, please look up the
130 definition of a pp-number in the C standard [section 6.4.8 of C99] */
131 #define ISidnum 0x01 /* a-zA-Z0-9_ */
132 #define ISidstart 0x02 /* _a-zA-Z */
133 #define ISnumstart 0x04 /* 0-9 */
134 #define IShspace 0x08 /* ' ' \t \f \v */
135 #define ISspace 0x10 /* ' ' \t \f \v \n */
136
137 #define _dollar_ok(x) ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident))
138
139 #define is_idchar(x) ((_cpp_IStable[x] & ISidnum) || _dollar_ok(x))
140 #define is_idstart(x) ((_cpp_IStable[x] & ISidstart) || _dollar_ok(x))
141 #define is_numchar(x) (_cpp_IStable[x] & ISidnum)
142 #define is_numstart(x) (_cpp_IStable[x] & ISnumstart)
143 #define is_hspace(x) (_cpp_IStable[x] & IShspace)
144 #define is_space(x) (_cpp_IStable[x] & ISspace)
145
146 /* This table is constant if it can be initialized at compile time,
147 which is the case if cpp was compiled with GCC >=2.7, or another
148 compiler that supports C99. */
149 #if (GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L)
150 extern const unsigned char _cpp_IStable[256];
151 #else
152 extern unsigned char _cpp_IStable[256];
153 #endif
154
155 /* Macros. */
156
157 /* Make sure PFILE->token_buffer has space for at least N more characters. */
158 #define CPP_RESERVE(PFILE, N) \
159 (CPP_WRITTEN (PFILE) + (size_t)(N) > (PFILE)->token_buffer_size \
160 && (_cpp_grow_token_buffer (PFILE, N), 0))
161
162 /* Append string STR (of length N) to PFILE's output buffer.
163 Assume there is enough space. */
164 #define CPP_PUTS_Q(PFILE, STR, N) \
165 (memcpy ((PFILE)->limit, STR, (N)), (PFILE)->limit += (N))
166 /* Append string STR (of length N) to PFILE's output buffer. Make space. */
167 #define CPP_PUTS(PFILE, STR, N) CPP_RESERVE(PFILE, N), CPP_PUTS_Q(PFILE, STR,N)
168 /* Append character CH to PFILE's output buffer. Assume sufficient space. */
169 #define CPP_PUTC_Q(PFILE, CH) (*(PFILE)->limit++ = (CH))
170 /* Append character CH to PFILE's output buffer. Make space if need be. */
171 #define CPP_PUTC(PFILE, CH) (CPP_RESERVE (PFILE, 1), CPP_PUTC_Q (PFILE, CH))
172
173 #define CPP_PREV_BUFFER(BUFFER) ((BUFFER)->prev)
174 #define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps)
175 #define CPP_TRADITIONAL(PFILE) CPP_OPTION (PFILE, traditional)
176 #define CPP_IN_SYSTEM_HEADER(PFILE) (CPP_BUFFER (PFILE)->inc->sysp)
177 #define CPP_PEDANTIC(PF) \
178 (CPP_OPTION (PF, pedantic) && !CPP_IN_SYSTEM_HEADER (PF))
179 #define CPP_WTRADITIONAL(PF) \
180 (CPP_OPTION (PF, warn_traditional) && !CPP_IN_SYSTEM_HEADER (PF))
181
182 /* Flags for _cpp_init_toklist. */
183 #define DUMMY_TOKEN 0
184 #define NO_DUMMY_TOKEN 1
185
186 /* In cpphash.c */
187 extern unsigned int _cpp_calc_hash PARAMS ((const U_CHAR *, size_t));
188 extern void _cpp_free_definition PARAMS ((cpp_hashnode *));
189 extern int _cpp_create_definition PARAMS ((cpp_reader *, cpp_hashnode *));
190 extern void _cpp_dump_definition PARAMS ((cpp_reader *, cpp_hashnode *));
191 extern void _cpp_init_macro_hash PARAMS ((cpp_reader *));
192 extern void _cpp_dump_macro_hash PARAMS ((cpp_reader *));
193
194 /* In cppfiles.c */
195 extern void _cpp_simplify_pathname PARAMS ((char *));
196 extern void _cpp_execute_include PARAMS ((cpp_reader *, const U_CHAR *,
197 unsigned int, int,
198 struct file_name_list *,
199 int));
200 extern int _cpp_compare_file_date PARAMS ((cpp_reader *, const U_CHAR *,
201 unsigned int, int));
202 extern void _cpp_init_include_table PARAMS ((cpp_reader *));
203 extern const char *_cpp_fake_include PARAMS ((cpp_reader *, const char *));
204
205 /* In cppexp.c */
206 extern int _cpp_parse_expr PARAMS ((cpp_reader *));
207
208 /* In cpplex.c */
209 extern void _cpp_skip_rest_of_line PARAMS ((cpp_reader *));
210 extern void _cpp_free_temp_tokens PARAMS ((cpp_reader *));
211 extern void _cpp_init_input_buffer PARAMS ((cpp_reader *));
212 extern void _cpp_grow_token_buffer PARAMS ((cpp_reader *, long));
213 extern enum cpp_ttype _cpp_get_directive_token
214 PARAMS ((cpp_reader *));
215 extern void _cpp_init_toklist PARAMS ((cpp_toklist *, int));
216 extern void _cpp_clear_toklist PARAMS ((cpp_toklist *));
217 extern void _cpp_free_toklist PARAMS ((const cpp_toklist *));
218 extern int _cpp_equiv_tokens PARAMS ((const cpp_token *,
219 const cpp_token *));
220 extern int _cpp_equiv_toklists PARAMS ((const cpp_toklist *,
221 const cpp_toklist *));
222 extern void _cpp_expand_token_space PARAMS ((cpp_toklist *, unsigned int));
223 extern void _cpp_reserve_name_space PARAMS ((cpp_toklist *, unsigned int));
224 extern void _cpp_expand_name_space PARAMS ((cpp_toklist *, unsigned int));
225 extern void _cpp_dump_list PARAMS ((cpp_reader *,
226 const cpp_toklist *,
227 const cpp_token *, int));
228 extern int _cpp_equiv_tokens PARAMS ((const cpp_token *,
229 const cpp_token *));
230 extern void _cpp_run_directive PARAMS ((cpp_reader *,
231 const struct directive *,
232 const char *, size_t));
233 extern unsigned int _cpp_get_line PARAMS ((cpp_reader *,
234 unsigned int *));
235 extern const cpp_token *_cpp_get_raw_token PARAMS ((cpp_reader *));
236 extern void _cpp_push_token PARAMS ((cpp_reader *, const cpp_token*));
237 extern const cpp_token *_cpp_glue_header_name PARAMS ((cpp_reader *));
238
239 /* In cpplib.c */
240 extern const struct directive *_cpp_check_directive
241 PARAMS ((cpp_reader *, const cpp_token *, int));
242 extern const struct directive *_cpp_check_linemarker
243 PARAMS ((cpp_reader *, const cpp_token *, int));
244 extern void _cpp_unwind_if_stack PARAMS ((cpp_reader *, cpp_buffer *));
245 extern cpp_hashnode * _cpp_parse_assertion PARAMS ((cpp_reader *,
246 struct answer **));
247 extern struct answer** find_answer PARAMS ((cpp_hashnode *,
248 const cpp_toklist *));
249
250 /* Utility routines and macros. */
251 #define xnew(T) (T *) xmalloc (sizeof(T))
252 #define xnewvec(T, N) (T *) xmalloc (sizeof(T) * (N))
253
254 /* These are inline functions instead of macros so we can get type
255 checking. */
256
257 static inline int ustrcmp PARAMS ((const U_CHAR *, const U_CHAR *));
258 static inline int ustrncmp PARAMS ((const U_CHAR *, const U_CHAR *,
259 size_t));
260 static inline size_t ustrlen PARAMS ((const U_CHAR *));
261 static inline U_CHAR *uxstrdup PARAMS ((const U_CHAR *));
262 static inline U_CHAR *ustrchr PARAMS ((const U_CHAR *, int));
263
264 static inline int
265 ustrcmp (s1, s2)
266 const U_CHAR *s1, *s2;
267 {
268 return strcmp ((const char *)s1, (const char *)s2);
269 }
270
271 static inline int
272 ustrncmp (s1, s2, n)
273 const U_CHAR *s1, *s2;
274 size_t n;
275 {
276 return strncmp ((const char *)s1, (const char *)s2, n);
277 }
278
279 static inline size_t
280 ustrlen (s1)
281 const U_CHAR *s1;
282 {
283 return strlen ((const char *)s1);
284 }
285
286 static inline U_CHAR *
287 uxstrdup (s1)
288 const U_CHAR *s1;
289 {
290 return (U_CHAR *) xstrdup ((const char *)s1);
291 }
292
293 static inline U_CHAR *
294 ustrchr (s1, c)
295 const U_CHAR *s1;
296 int c;
297 {
298 return (U_CHAR *) strchr ((const char *)s1, c);
299 }
300
301 #endif
This page took 0.054933 seconds and 6 git commands to generate.