]>
Commit | Line | Data |
---|---|---|
88ae23e7 ZW |
1 | /* Part of CPP library. |
2 | Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. | |
4283012f JL |
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 | |
42b17236 | 16 | Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
4283012f | 17 | |
88ae23e7 ZW |
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 | ||
bb52fa7f ZW |
22 | #ifndef __GCC_CPPHASH__ |
23 | #define __GCC_CPPHASH__ | |
24 | ||
93c80368 NB |
25 | /* Test if a sign is valid within a preprocessing number. */ |
26 | #define VALID_SIGN(c, prevc) \ | |
27 | (((c) == '+' || (c) == '-') && \ | |
28 | ((prevc) == 'e' || (prevc) == 'E' \ | |
29 | || (((prevc) == 'p' || (prevc) == 'P') && !CPP_OPTION (pfile, c89)))) | |
30 | ||
31 | /* Memory pools. */ | |
32 | #define ALIGN(size, align) (((size) + ((align) - 1)) & ~((align) - 1)) | |
33 | #define POOL_FRONT(p) ((p)->cur->front) | |
34 | #define POOL_LIMIT(p) ((p)->cur->limit) | |
35 | #define POOL_BASE(p) ((p)->cur->base) | |
36 | #define POOL_SIZE(p) ((p)->cur->limit - (p)->cur->base) | |
37 | #define POOL_ROOM(p) ((p)->cur->limit - (p)->cur->front) | |
38 | #define POOL_USED(p) ((p)->cur->front - (p)->cur->base) | |
39 | #define POOL_COMMIT(p, len) do {((p)->cur->front += ALIGN (len, (p)->align));\ | |
40 | if ((p)->cur->front > (p)->cur->limit) abort ();} while (0) | |
41 | ||
42 | typedef struct cpp_chunk cpp_chunk; | |
43 | struct cpp_chunk | |
15dad1d9 | 44 | { |
93c80368 NB |
45 | cpp_chunk *next; |
46 | unsigned char *front; | |
47 | unsigned char *limit; | |
48 | unsigned char *base; | |
15dad1d9 ZW |
49 | }; |
50 | ||
88ae23e7 ZW |
51 | /* List of directories to look for include files in. */ |
52 | struct file_name_list | |
53 | { | |
54 | struct file_name_list *next; | |
55 | struct file_name_list *alloc; /* for the cache of | |
56 | current directory entries */ | |
57 | char *name; | |
58 | unsigned int nlen; | |
59 | /* We use these to tell if the directory mentioned here is a duplicate | |
60 | of an earlier directory on the search path. */ | |
61 | ino_t ino; | |
62 | dev_t dev; | |
63 | /* If the following is nonzero, it is a C-language system include | |
64 | directory. */ | |
65 | int sysp; | |
66 | /* Mapping of file names for this directory. | |
67 | Only used on MS-DOS and related platforms. */ | |
68 | struct file_name_map *name_map; | |
69 | }; | |
70 | #define ABSOLUTE_PATH ((struct file_name_list *)-1) | |
71 | ||
c31a6508 ZW |
72 | /* This structure is used for the table of all includes. */ |
73 | struct include_file | |
88ae23e7 | 74 | { |
c31a6508 | 75 | const char *name; /* actual path name of file */ |
ea4a453b | 76 | const cpp_hashnode *cmacro; /* macro, if any, preventing reinclusion. */ |
c31a6508 ZW |
77 | const struct file_name_list *foundhere; |
78 | /* location in search path where file was | |
79 | found, for #include_next */ | |
a58d32c2 ZW |
80 | const unsigned char *buffer; /* pointer to cached file contents */ |
81 | struct stat st; /* copy of stat(2) data for file */ | |
82 | int fd; /* fd open on file (short term storage only) */ | |
d4506961 | 83 | unsigned short include_count; /* number of times file has been read */ |
a58d32c2 ZW |
84 | unsigned short refcnt; /* number of stacked buffers using this file */ |
85 | unsigned char sysp; /* file is a system header */ | |
86 | unsigned char mapped; /* file buffer is mmapped */ | |
93c80368 | 87 | unsigned char defined; /* cmacro prevents inclusion in this state */ |
88ae23e7 | 88 | }; |
c31a6508 | 89 | |
a58d32c2 ZW |
90 | /* The cmacro works like this: If it's NULL, the file is to be |
91 | included again. If it's NEVER_REREAD, the file is never to be | |
92 | included again. Otherwise it is a macro hashnode, and the file is | |
93c80368 NB |
93 | to be included again if the macro is defined or not as specified by |
94 | DEFINED. */ | |
a58d32c2 ZW |
95 | #define NEVER_REREAD ((const cpp_hashnode *)-1) |
96 | #define DO_NOT_REREAD(inc) \ | |
93c80368 NB |
97 | ((inc)->cmacro && ((inc)->cmacro == NEVER_REREAD \ |
98 | || ((inc)->cmacro->type == NT_MACRO) == (inc)->defined)) | |
bfb9dc7f | 99 | |
88ae23e7 ZW |
100 | /* Character classes. |
101 | If the definition of `numchar' looks odd to you, please look up the | |
91fcd158 NB |
102 | definition of a pp-number in the C standard [section 6.4.8 of C99]. |
103 | ||
104 | In the unlikely event that characters other than \r and \n enter | |
105 | the set is_vspace, the macro handle_newline() in cpplex.c must be | |
106 | updated. */ | |
88ae23e7 ZW |
107 | #define ISidnum 0x01 /* a-zA-Z0-9_ */ |
108 | #define ISidstart 0x02 /* _a-zA-Z */ | |
109 | #define ISnumstart 0x04 /* 0-9 */ | |
91fcd158 NB |
110 | #define IShspace 0x08 /* ' ' \t */ |
111 | #define ISvspace 0x10 /* \r \n */ | |
112 | #define ISspace 0x20 /* ' ' \t \r \n \f \v \0 */ | |
88ae23e7 | 113 | |
ae79697b | 114 | #define _dollar_ok(x) ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident)) |
88ae23e7 ZW |
115 | |
116 | #define is_idchar(x) ((_cpp_IStable[x] & ISidnum) || _dollar_ok(x)) | |
117 | #define is_idstart(x) ((_cpp_IStable[x] & ISidstart) || _dollar_ok(x)) | |
118 | #define is_numchar(x) (_cpp_IStable[x] & ISidnum) | |
119 | #define is_numstart(x) (_cpp_IStable[x] & ISnumstart) | |
120 | #define is_hspace(x) (_cpp_IStable[x] & IShspace) | |
91fcd158 NB |
121 | #define is_vspace(x) (_cpp_IStable[x] & ISvspace) |
122 | #define is_nvspace(x) ((_cpp_IStable[x] & (ISspace | ISvspace)) == ISspace) | |
88ae23e7 ZW |
123 | #define is_space(x) (_cpp_IStable[x] & ISspace) |
124 | ||
61d0346d | 125 | /* These tables are constant if they can be initialized at compile time, |
88ae23e7 ZW |
126 | which is the case if cpp was compiled with GCC >=2.7, or another |
127 | compiler that supports C99. */ | |
61d0346d NB |
128 | #if HAVE_DESIGNATED_INITIALIZERS |
129 | extern const unsigned char _cpp_IStable[UCHAR_MAX + 1]; | |
130 | extern const unsigned char _cpp_trigraph_map[UCHAR_MAX + 1]; | |
88ae23e7 | 131 | #else |
61d0346d NB |
132 | extern unsigned char _cpp_IStable[UCHAR_MAX + 1]; |
133 | extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1]; | |
88ae23e7 ZW |
134 | #endif |
135 | ||
136 | /* Macros. */ | |
137 | ||
88ae23e7 | 138 | #define CPP_PREV_BUFFER(BUFFER) ((BUFFER)->prev) |
ae79697b | 139 | #define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps) |
bfb9dc7f ZW |
140 | #define CPP_IN_SYSTEM_HEADER(PFILE) \ |
141 | (CPP_BUFFER (PFILE) && CPP_BUFFER (PFILE)->inc \ | |
142 | && CPP_BUFFER (PFILE)->inc->sysp) | |
c31a6508 | 143 | #define CPP_PEDANTIC(PF) \ |
317639a8 | 144 | CPP_OPTION (PF, pedantic) |
07aa0b04 | 145 | #define CPP_WTRADITIONAL(PF) \ |
317639a8 | 146 | CPP_OPTION (PF, warn_traditional) |
88ae23e7 | 147 | |
711b8824 ZW |
148 | /* Hash step. The hash calculation is duplicated in cpp_lookup and |
149 | parse_name. */ | |
0d9f234d | 150 | #define HASHSTEP(r, c) ((r) * 67 + (c - 113)); |
711b8824 | 151 | |
58fea6af ZW |
152 | /* In cpperror.c */ |
153 | enum error_type { WARNING = 0, PEDWARN, ERROR, FATAL, ICE }; | |
154 | extern int _cpp_begin_message PARAMS ((cpp_reader *, enum error_type, | |
93c80368 | 155 | const char *, const cpp_lexer_pos *)); |
58fea6af | 156 | |
711b8824 | 157 | /* In cppmacro.c */ |
f8f769ea | 158 | extern void _cpp_free_definition PARAMS ((cpp_hashnode *)); |
041c3194 | 159 | extern int _cpp_create_definition PARAMS ((cpp_reader *, cpp_hashnode *)); |
93c80368 | 160 | extern void _cpp_pop_context PARAMS ((cpp_reader *)); |
93c80368 | 161 | extern void _cpp_free_lookaheads PARAMS ((cpp_reader *)); |
b528a07e | 162 | extern void _cpp_release_lookahead PARAMS ((cpp_reader *)); |
93c80368 NB |
163 | extern void _cpp_push_token PARAMS ((cpp_reader *, const cpp_token *, |
164 | const cpp_lexer_pos *)); | |
711b8824 ZW |
165 | |
166 | /* In cpphash.c */ | |
93c80368 NB |
167 | extern void _cpp_init_hashtable PARAMS ((cpp_reader *)); |
168 | extern void _cpp_cleanup_hashtable PARAMS ((cpp_reader *)); | |
169 | extern cpp_hashnode *_cpp_lookup_with_hash PARAMS ((cpp_reader*, size_t, | |
170 | unsigned int)); | |
bb52fa7f | 171 | |
88ae23e7 ZW |
172 | /* In cppfiles.c */ |
173 | extern void _cpp_simplify_pathname PARAMS ((char *)); | |
93c80368 NB |
174 | extern void _cpp_execute_include PARAMS ((cpp_reader *, |
175 | const cpp_token *, int, | |
176 | struct file_name_list *)); | |
177 | extern int _cpp_compare_file_date PARAMS ((cpp_reader *, | |
178 | const cpp_token *)); | |
c71f835b ZW |
179 | extern void _cpp_report_missing_guards PARAMS ((cpp_reader *)); |
180 | extern void _cpp_init_includes PARAMS ((cpp_reader *)); | |
181 | extern void _cpp_cleanup_includes PARAMS ((cpp_reader *)); | |
c31a6508 | 182 | extern const char *_cpp_fake_include PARAMS ((cpp_reader *, const char *)); |
f9a0e96c | 183 | extern void _cpp_pop_file_buffer PARAMS ((cpp_reader *, cpp_buffer *)); |
88ae23e7 ZW |
184 | |
185 | /* In cppexp.c */ | |
186 | extern int _cpp_parse_expr PARAMS ((cpp_reader *)); | |
187 | ||
45b966db | 188 | /* In cpplex.c */ |
93c80368 | 189 | extern void _cpp_lex_token PARAMS ((cpp_reader *, cpp_token *)); |
15dad1d9 ZW |
190 | extern int _cpp_equiv_tokens PARAMS ((const cpp_token *, |
191 | const cpp_token *)); | |
93c80368 NB |
192 | extern void _cpp_init_pool PARAMS ((cpp_pool *, unsigned int, |
193 | unsigned int, unsigned int)); | |
194 | extern void _cpp_free_pool PARAMS ((cpp_pool *)); | |
195 | extern unsigned char *_cpp_pool_reserve PARAMS ((cpp_pool *, unsigned int)); | |
196 | extern unsigned char *_cpp_pool_alloc PARAMS ((cpp_pool *, unsigned int)); | |
197 | extern unsigned char *_cpp_next_chunk PARAMS ((cpp_pool *, unsigned int, | |
198 | unsigned char **)); | |
199 | extern void _cpp_lock_pool PARAMS ((cpp_pool *)); | |
200 | extern void _cpp_unlock_pool PARAMS ((cpp_pool *)); | |
45b966db ZW |
201 | |
202 | /* In cpplib.c */ | |
93c80368 NB |
203 | extern int _cpp_test_assertion PARAMS ((cpp_reader *, int *)); |
204 | extern int _cpp_handle_directive PARAMS ((cpp_reader *, int)); | |
205 | extern void _cpp_define_builtin PARAMS ((cpp_reader *, const char *)); | |
a5c3cccd | 206 | extern void _cpp_do__Pragma PARAMS ((cpp_reader *)); |
c71f835b ZW |
207 | extern void _cpp_init_stacks PARAMS ((cpp_reader *)); |
208 | extern void _cpp_cleanup_stacks PARAMS ((cpp_reader *)); | |
58fea6af | 209 | extern void _cpp_init_internal_pragmas PARAMS ((cpp_reader *)); |
12cf91fe | 210 | |
c31a6508 | 211 | /* Utility routines and macros. */ |
93c80368 | 212 | #define DSC(str) (const U_CHAR *)str, sizeof str - 1 |
c31a6508 | 213 | #define xnew(T) (T *) xmalloc (sizeof(T)) |
a58d32c2 | 214 | #define xcnew(T) (T *) xcalloc (1, sizeof(T)) |
c31a6508 | 215 | #define xnewvec(T, N) (T *) xmalloc (sizeof(T) * (N)) |
711b8824 | 216 | #define xcnewvec(T, N) (T *) xcalloc (N, sizeof(T)) |
c71f835b | 217 | #define xobnew(O, T) (T *) obstack_alloc (O, sizeof(T)) |
c31a6508 | 218 | |
bb52fa7f | 219 | #endif |