]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/cpphash.h
New macro expander.
[thirdparty/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 /* 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
44 {
45 cpp_chunk *next;
46 unsigned char *front;
47 unsigned char *limit;
48 unsigned char *base;
49 };
50
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
72 /* This structure is used for the table of all includes. */
73 struct include_file
74 {
75 const char *name; /* actual path name of file */
76 const cpp_hashnode *cmacro; /* macro, if any, preventing reinclusion. */
77 const struct file_name_list *foundhere;
78 /* location in search path where file was
79 found, for #include_next */
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) */
83 unsigned short include_count; /* number of times file has been read */
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 */
87 unsigned char defined; /* cmacro prevents inclusion in this state */
88 };
89
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
93 to be included again if the macro is defined or not as specified by
94 DEFINED. */
95 #define NEVER_REREAD ((const cpp_hashnode *)-1)
96 #define DO_NOT_REREAD(inc) \
97 ((inc)->cmacro && ((inc)->cmacro == NEVER_REREAD \
98 || ((inc)->cmacro->type == NT_MACRO) == (inc)->defined))
99
100 /* Character classes.
101 If the definition of `numchar' looks odd to you, please look up the
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. */
107 #define ISidnum 0x01 /* a-zA-Z0-9_ */
108 #define ISidstart 0x02 /* _a-zA-Z */
109 #define ISnumstart 0x04 /* 0-9 */
110 #define IShspace 0x08 /* ' ' \t */
111 #define ISvspace 0x10 /* \r \n */
112 #define ISspace 0x20 /* ' ' \t \r \n \f \v \0 */
113
114 #define _dollar_ok(x) ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident))
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)
121 #define is_vspace(x) (_cpp_IStable[x] & ISvspace)
122 #define is_nvspace(x) ((_cpp_IStable[x] & (ISspace | ISvspace)) == ISspace)
123 #define is_space(x) (_cpp_IStable[x] & ISspace)
124
125 /* These tables are constant if they can be initialized at compile time,
126 which is the case if cpp was compiled with GCC >=2.7, or another
127 compiler that supports C99. */
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];
131 #else
132 extern unsigned char _cpp_IStable[UCHAR_MAX + 1];
133 extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
134 #endif
135
136 /* Macros. */
137
138 #define CPP_PREV_BUFFER(BUFFER) ((BUFFER)->prev)
139 #define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps)
140 #define CPP_IN_SYSTEM_HEADER(PFILE) \
141 (CPP_BUFFER (PFILE) && CPP_BUFFER (PFILE)->inc \
142 && CPP_BUFFER (PFILE)->inc->sysp)
143 #define CPP_PEDANTIC(PF) \
144 CPP_OPTION (PF, pedantic)
145 #define CPP_WTRADITIONAL(PF) \
146 CPP_OPTION (PF, warn_traditional)
147
148 /* Hash step. The hash calculation is duplicated in cpp_lookup and
149 parse_name. */
150 #define HASHSTEP(r, c) ((r) * 67 + (c - 113));
151
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,
155 const char *, const cpp_lexer_pos *));
156
157 /* In cppmacro.c */
158 extern void _cpp_free_definition PARAMS ((cpp_hashnode *));
159 extern int _cpp_create_definition PARAMS ((cpp_reader *, cpp_hashnode *));
160 extern void _cpp_pop_context PARAMS ((cpp_reader *));
161 extern void _cpp_get_token PARAMS ((cpp_reader *, cpp_token *));
162 extern void _cpp_free_lookaheads PARAMS ((cpp_reader *));
163 extern void _cpp_push_token PARAMS ((cpp_reader *, const cpp_token *,
164 const cpp_lexer_pos *));
165
166 /* In cpphash.c */
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));
171
172 /* In cppfiles.c */
173 extern void _cpp_simplify_pathname PARAMS ((char *));
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 *));
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 *));
182 extern const char *_cpp_fake_include PARAMS ((cpp_reader *, const char *));
183 extern void _cpp_pop_file_buffer PARAMS ((cpp_reader *, cpp_buffer *));
184
185 /* In cppexp.c */
186 extern int _cpp_parse_expr PARAMS ((cpp_reader *));
187
188 /* In cpplex.c */
189 extern void _cpp_lex_token PARAMS ((cpp_reader *, cpp_token *));
190 extern int _cpp_equiv_tokens PARAMS ((const cpp_token *,
191 const cpp_token *));
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 *));
201
202 /* In cpplib.c */
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 *));
206 extern void _cpp_init_stacks PARAMS ((cpp_reader *));
207 extern void _cpp_cleanup_stacks PARAMS ((cpp_reader *));
208 extern void _cpp_init_internal_pragmas PARAMS ((cpp_reader *));
209
210 /* Utility routines and macros. */
211 #define DSC(str) (const U_CHAR *)str, sizeof str - 1
212 #define xnew(T) (T *) xmalloc (sizeof(T))
213 #define xcnew(T) (T *) xcalloc (1, sizeof(T))
214 #define xnewvec(T, N) (T *) xmalloc (sizeof(T) * (N))
215 #define xcnewvec(T, N) (T *) xcalloc (N, sizeof(T))
216 #define xobnew(O, T) (T *) obstack_alloc (O, sizeof(T))
217
218 #endif