c590de68636ec453a17435765cc132703d76e791
[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 /* Structure used for assertion predicates. */
29 struct predicate
30 {
31 struct predicate *next;
32 struct cpp_toklist answer;
33 };
34
35 /* List of directories to look for include files in. */
36 struct file_name_list
37 {
38 struct file_name_list *next;
39 struct file_name_list *alloc; /* for the cache of
40 current directory entries */
41 char *name;
42 unsigned int nlen;
43 /* We use these to tell if the directory mentioned here is a duplicate
44 of an earlier directory on the search path. */
45 ino_t ino;
46 dev_t dev;
47 /* If the following is nonzero, it is a C-language system include
48 directory. */
49 int sysp;
50 /* Mapping of file names for this directory.
51 Only used on MS-DOS and related platforms. */
52 struct file_name_map *name_map;
53 };
54 #define ABSOLUTE_PATH ((struct file_name_list *)-1)
55
56 /* This structure is used for the table of all includes. It is
57 indexed by the `short name' (the name as it appeared in the
58 #include statement) which is stored in *nshort. */
59 struct ihash
60 {
61 /* Next file with the same short name but a
62 different (partial) pathname). */
63 struct ihash *next_this_file;
64
65 /* Location of the file in the include search path.
66 Used for include_next and to detect redundant includes. */
67 struct file_name_list *foundhere;
68
69 unsigned int hash; /* save hash value for future reference */
70 const char *nshort; /* name of file as referenced in #include;
71 points into name[] */
72 const U_CHAR *control_macro; /* macro, if any, preventing reinclusion. */
73 const char name[1]; /* (partial) pathname of file */
74 };
75 typedef struct ihash IHASH;
76
77 /* Character classes.
78 If the definition of `numchar' looks odd to you, please look up the
79 definition of a pp-number in the C standard [section 6.4.8 of C99] */
80 #define ISidnum 0x01 /* a-zA-Z0-9_ */
81 #define ISidstart 0x02 /* _a-zA-Z */
82 #define ISnumstart 0x04 /* 0-9 */
83 #define IShspace 0x08 /* ' ' \t \f \v */
84 #define ISspace 0x10 /* ' ' \t \f \v \n */
85
86 #define _dollar_ok(x) ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident))
87
88 #define is_idchar(x) ((_cpp_IStable[x] & ISidnum) || _dollar_ok(x))
89 #define is_idstart(x) ((_cpp_IStable[x] & ISidstart) || _dollar_ok(x))
90 #define is_numchar(x) (_cpp_IStable[x] & ISidnum)
91 #define is_numstart(x) (_cpp_IStable[x] & ISnumstart)
92 #define is_hspace(x) (_cpp_IStable[x] & IShspace)
93 #define is_space(x) (_cpp_IStable[x] & ISspace)
94
95 /* This table is constant if it can be initialized at compile time,
96 which is the case if cpp was compiled with GCC >=2.7, or another
97 compiler that supports C99. */
98 #if (GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L)
99 extern const unsigned char _cpp_IStable[256];
100 #else
101 extern unsigned char _cpp_IStable[256];
102 #endif
103
104 /* Macros. */
105
106 /* One character lookahead in the input buffer. Note that if this
107 returns EOF, it does *not* necessarily mean the file's end has been
108 reached. */
109 #define CPP_BUF_PEEK(BUFFER) \
110 ((BUFFER)->cur < (BUFFER)->rlimit ? *(BUFFER)->cur : EOF)
111
112 /* Make sure PFILE->token_buffer has space for at least N more characters. */
113 #define CPP_RESERVE(PFILE, N) \
114 (CPP_WRITTEN (PFILE) + (size_t)(N) > (PFILE)->token_buffer_size \
115 && (_cpp_grow_token_buffer (PFILE, N), 0))
116
117 /* Append string STR (of length N) to PFILE's output buffer.
118 Assume there is enough space. */
119 #define CPP_PUTS_Q(PFILE, STR, N) \
120 (memcpy ((PFILE)->limit, STR, (N)), (PFILE)->limit += (N))
121 /* Append string STR (of length N) to PFILE's output buffer. Make space. */
122 #define CPP_PUTS(PFILE, STR, N) CPP_RESERVE(PFILE, N), CPP_PUTS_Q(PFILE, STR,N)
123 /* Append character CH to PFILE's output buffer. Assume sufficient space. */
124 #define CPP_PUTC_Q(PFILE, CH) (*(PFILE)->limit++ = (CH))
125 /* Append character CH to PFILE's output buffer. Make space if need be. */
126 #define CPP_PUTC(PFILE, CH) (CPP_RESERVE (PFILE, 1), CPP_PUTC_Q (PFILE, CH))
127
128 /* Advance the current line by one. */
129 #define CPP_BUMP_BUFFER_LINE(PBUF) ((PBUF)->lineno++,\
130 (PBUF)->line_base = (PBUF)->cur)
131 #define CPP_BUMP_LINE(PFILE) CPP_BUMP_BUFFER_LINE(CPP_BUFFER(PFILE))
132 #define CPP_BUMP_BUFFER_LINE_CUR(PBUF, CUR) ((PBUF)->lineno++,\
133 (PBUF)->line_base = CUR)
134 #define CPP_BUMP_LINE_CUR(PFILE, CUR) \
135 CPP_BUMP_BUFFER_LINE_CUR(CPP_BUFFER(PFILE), CUR)
136 #define CPP_PREV_BUFFER(BUFFER) ((BUFFER)->prev)
137
138 /* Are we in column 1 right now? Used mainly for -traditional handling
139 of directives. */
140 #define CPP_IN_COLUMN_1(PFILE) \
141 (CPP_BUFFER (PFILE)->cur - CPP_BUFFER (PFILE)->line_base == 1)
142
143 #define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps)
144 #define CPP_TRADITIONAL(PFILE) CPP_OPTION (PFILE, traditional)
145 #define CPP_PEDANTIC(PFILE) \
146 (CPP_OPTION (PFILE, pedantic) && !CPP_BUFFER (PFILE)->system_header_p)
147 #define CPP_WTRADITIONAL(PF) \
148 (CPP_OPTION (PF, warn_traditional) && !CPP_BUFFER (PF)->system_header_p)
149
150 /* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion.
151 (Note that it is false while we're expanding macro *arguments*.) */
152 #define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->macro != NULL)
153
154 /* Remember the current position of PFILE so it may be returned to
155 after looking ahead a bit.
156
157 Note that when you set a mark, you _must_ return to that mark. You
158 may not forget about it and continue parsing. You may not pop a
159 buffer with an active mark. You may not call CPP_BUMP_LINE while a
160 mark is active. */
161 #define CPP_SET_BUF_MARK(IP) ((IP)->mark = (IP)->cur)
162 #define CPP_GOTO_BUF_MARK(IP) ((IP)->cur = (IP)->mark, (IP)->mark = 0)
163 #define CPP_SET_MARK(PFILE) CPP_SET_BUF_MARK(CPP_BUFFER(PFILE))
164 #define CPP_GOTO_MARK(PFILE) CPP_GOTO_BUF_MARK(CPP_BUFFER(PFILE))
165
166 /* ACTIVE_MARK_P is true if there's a live mark in the buffer. */
167 #define ACTIVE_MARK_P(PFILE) (CPP_BUFFER (PFILE)->mark != 0)
168
169 /* Are mark and point adjacent characters? Used mostly to deal with
170 the somewhat annoying semantic of #define. */
171 #define ADJACENT_TO_MARK(PFILE) \
172 (CPP_BUFFER(PFILE)->cur - CPP_BUFFER(PFILE)->mark == 1)
173
174 /* Flags for _cpp_init_toklist. */
175 #define DUMMY_TOKEN 0
176 #define NO_DUMMY_TOKEN 1
177
178 /* In cpphash.c */
179 extern unsigned int _cpp_calc_hash PARAMS ((const U_CHAR *, size_t));
180 extern void _cpp_free_definition PARAMS ((cpp_hashnode *));
181 extern int _cpp_create_definition PARAMS ((cpp_reader *, cpp_toklist *,
182 cpp_hashnode *));
183 extern void _cpp_dump_definition PARAMS ((cpp_reader *, cpp_hashnode *));
184 extern void _cpp_quote_string PARAMS ((cpp_reader *, const U_CHAR *));
185 extern void _cpp_macroexpand PARAMS ((cpp_reader *, cpp_hashnode *));
186 extern void _cpp_init_macro_hash PARAMS ((cpp_reader *));
187 extern void _cpp_dump_macro_hash PARAMS ((cpp_reader *));
188
189 /* In cppfiles.c */
190 extern void _cpp_simplify_pathname PARAMS ((char *));
191 extern void _cpp_execute_include PARAMS ((cpp_reader *, U_CHAR *,
192 unsigned int, int,
193 struct file_name_list *));
194 extern void _cpp_init_include_hash PARAMS ((cpp_reader *));
195 extern const char *_cpp_fake_ihash PARAMS ((cpp_reader *, const char *));
196
197 /* In cppexp.c */
198 extern int _cpp_parse_expr PARAMS ((cpp_reader *));
199
200 /* In cpplex.c */
201 extern void _cpp_parse_name PARAMS ((cpp_reader *, int));
202 extern void _cpp_skip_rest_of_line PARAMS ((cpp_reader *));
203 extern void _cpp_skip_hspace PARAMS ((cpp_reader *));
204 extern void _cpp_expand_to_buffer PARAMS ((cpp_reader *,
205 const unsigned char *, int));
206 extern int _cpp_parse_assertion PARAMS ((cpp_reader *));
207 extern enum cpp_ttype _cpp_lex_token PARAMS ((cpp_reader *));
208 extern ssize_t _cpp_prescan PARAMS ((cpp_reader *, cpp_buffer *,
209 ssize_t));
210 extern void _cpp_init_input_buffer PARAMS ((cpp_reader *));
211 extern void _cpp_grow_token_buffer PARAMS ((cpp_reader *, long));
212 extern enum cpp_ttype _cpp_get_directive_token
213 PARAMS ((cpp_reader *));
214 extern enum cpp_ttype _cpp_get_define_token
215 PARAMS ((cpp_reader *));
216 extern enum cpp_ttype _cpp_scan_until PARAMS ((cpp_reader *, cpp_toklist *,
217 enum cpp_ttype));
218 extern void _cpp_init_toklist PARAMS ((cpp_toklist *, int));
219 extern void _cpp_clear_toklist PARAMS ((cpp_toklist *));
220 extern void _cpp_free_toklist PARAMS ((cpp_toklist *));
221 extern void _cpp_slice_toklist PARAMS ((cpp_toklist *,
222 const cpp_token *,
223 const cpp_token *));
224 extern void _cpp_squeeze_toklist PARAMS ((cpp_toklist *));
225 extern int _cpp_equiv_tokens PARAMS ((const cpp_token *,
226 const cpp_token *));
227 extern int _cpp_equiv_toklists PARAMS ((const cpp_toklist *,
228 const cpp_toklist *));
229 extern void _cpp_expand_token_space PARAMS ((cpp_toklist *, unsigned int));
230
231 /* In cpplib.c */
232 extern int _cpp_handle_directive PARAMS ((cpp_reader *));
233 extern void _cpp_unwind_if_stack PARAMS ((cpp_reader *, cpp_buffer *));
234 extern void _cpp_check_directive PARAMS ((cpp_toklist *, cpp_token *));
235
236 /* These are inline functions instead of macros so we can get type
237 checking. */
238
239 static inline int ustrcmp PARAMS ((const U_CHAR *, const U_CHAR *));
240 static inline int ustrncmp PARAMS ((const U_CHAR *, const U_CHAR *,
241 size_t));
242 static inline size_t ustrlen PARAMS ((const U_CHAR *));
243 static inline U_CHAR *uxstrdup PARAMS ((const U_CHAR *));
244 static inline U_CHAR *ustrchr PARAMS ((const U_CHAR *, int));
245
246 static inline int
247 ustrcmp (s1, s2)
248 const U_CHAR *s1, *s2;
249 {
250 return strcmp ((const char *)s1, (const char *)s2);
251 }
252
253 static inline int
254 ustrncmp (s1, s2, n)
255 const U_CHAR *s1, *s2;
256 size_t n;
257 {
258 return strncmp ((const char *)s1, (const char *)s2, n);
259 }
260
261 static inline size_t
262 ustrlen (s1)
263 const U_CHAR *s1;
264 {
265 return strlen ((const char *)s1);
266 }
267
268 static inline U_CHAR *
269 uxstrdup (s1)
270 const U_CHAR *s1;
271 {
272 return (U_CHAR *) xstrdup ((const char *)s1);
273 }
274
275 static inline U_CHAR *
276 ustrchr (s1, c)
277 const U_CHAR *s1;
278 int c;
279 {
280 return (U_CHAR *) strchr ((const char *)s1, c);
281 }
282
283 #endif