* arm-protos.h (arm_dllexport_name_p, arm_dllimport_name_p): Constify.
[official-gcc.git] / gcc / cpphash.h
blob16de5bb1259fef56dced8202fe5ed60a4411318e
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 /* gcc 2.7.2 can't handle __extension__ const char array[] = { ... }.
29 I don't know when this was added - be conservative, assume it only
30 works in 2.95. */
31 #if GCC_VERSION < 2095
32 #define __extension__
33 #endif
35 /* The structure of a node in the hash table. The hash table
36 has entries for all tokens defined by #define commands (type T_MACRO),
37 plus some special tokens like __LINE__ (these each have their own
38 type, and the appropriate code is run when that type of node is seen.
39 It does not contain control words like "#define", which are recognized
40 by a separate piece of code. */
42 /* different flavors of hash nodes */
43 enum node_type
45 T_VOID = 0, /* no definition yet */
46 T_SPECLINE, /* `__LINE__' */
47 T_DATE, /* `__DATE__' */
48 T_FILE, /* `__FILE__' */
49 T_BASE_FILE, /* `__BASE_FILE__' */
50 T_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */
51 T_TIME, /* `__TIME__' */
52 T_STDC, /* `__STDC__' */
53 T_CONST, /* Constant string, used by `__SIZE_TYPE__' etc */
54 T_XCONST, /* Ditto, but the string is malloced memory */
55 T_POISON, /* poisoned identifier */
56 T_MACRO, /* object-like macro */
57 T_FMACRO, /* function-like macro */
58 T_IDENTITY, /* macro defined to itself */
59 T_EMPTY /* macro defined to nothing */
62 typedef struct hashnode HASHNODE;
63 struct hashnode
65 unsigned int hash; /* cached hash value */
66 unsigned short length; /* length of name */
67 ENUM_BITFIELD(node_type) type : 8; /* node type */
68 char disabled; /* macro turned off for rescan? */
70 union {
71 const U_CHAR *cpval; /* some predefined macros */
72 const struct object_defn *odefn; /* #define foo bar */
73 const struct funct_defn *fdefn; /* #define foo(x) bar(x) */
74 struct hashnode *aschain; /* #assert */
75 } value;
77 const U_CHAR *name;
80 /* List of directories to look for include files in. */
81 struct file_name_list
83 struct file_name_list *next;
84 struct file_name_list *alloc; /* for the cache of
85 current directory entries */
86 char *name;
87 unsigned int nlen;
88 /* We use these to tell if the directory mentioned here is a duplicate
89 of an earlier directory on the search path. */
90 ino_t ino;
91 dev_t dev;
92 /* If the following is nonzero, it is a C-language system include
93 directory. */
94 int sysp;
95 /* Mapping of file names for this directory.
96 Only used on MS-DOS and related platforms. */
97 struct file_name_map *name_map;
99 #define ABSOLUTE_PATH ((struct file_name_list *)-1)
101 /* This structure is used for the table of all includes. It is
102 indexed by the `short name' (the name as it appeared in the
103 #include statement) which is stored in *nshort. */
104 struct ihash
106 /* Next file with the same short name but a
107 different (partial) pathname). */
108 struct ihash *next_this_file;
110 /* Location of the file in the include search path.
111 Used for include_next */
112 struct file_name_list *foundhere;
114 unsigned int hash; /* save hash value for future reference */
115 const char *nshort; /* name of file as referenced in #include;
116 points into name[] */
117 const U_CHAR *control_macro; /* macro, if any, preventing reinclusion -
118 see redundant_include_p */
119 const char name[1]; /* (partial) pathname of file */
121 typedef struct ihash IHASH;
123 /* Character classes.
124 If the definition of `numchar' looks odd to you, please look up the
125 definition of a pp-number in the C standard [section 6.4.8 of C99] */
126 #define ISidnum 0x01 /* a-zA-Z0-9_ */
127 #define ISidstart 0x02 /* _a-zA-Z */
128 #define ISnumstart 0x04 /* 0-9 */
129 #define IShspace 0x08 /* ' ' \t \f \v */
130 #define ISspace 0x10 /* ' ' \t \f \v \n */
132 #define _dollar_ok(x) ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident))
134 #define is_idchar(x) ((_cpp_IStable[x] & ISidnum) || _dollar_ok(x))
135 #define is_idstart(x) ((_cpp_IStable[x] & ISidstart) || _dollar_ok(x))
136 #define is_numchar(x) (_cpp_IStable[x] & ISidnum)
137 #define is_numstart(x) (_cpp_IStable[x] & ISnumstart)
138 #define is_hspace(x) (_cpp_IStable[x] & IShspace)
139 #define is_space(x) (_cpp_IStable[x] & ISspace)
141 /* This table is constant if it can be initialized at compile time,
142 which is the case if cpp was compiled with GCC >=2.7, or another
143 compiler that supports C99. */
144 #if (GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L)
145 extern const unsigned char _cpp_IStable[256];
146 #else
147 extern unsigned char _cpp_IStable[256];
148 #endif
150 /* Macros. */
152 /* One character lookahead in the input buffer. Note that if this
153 returns EOF, it does *not* necessarily mean the file's end has been
154 reached. */
155 #define CPP_BUF_PEEK(BUFFER) \
156 ((BUFFER)->cur < (BUFFER)->rlimit ? *(BUFFER)->cur : EOF)
158 /* Make sure PFILE->token_buffer has space for at least N more characters. */
159 #define CPP_RESERVE(PFILE, N) \
160 (CPP_WRITTEN (PFILE) + (size_t)(N) > (PFILE)->token_buffer_size \
161 && (_cpp_grow_token_buffer (PFILE, N), 0))
163 /* Append string STR (of length N) to PFILE's output buffer.
164 Assume there is enough space. */
165 #define CPP_PUTS_Q(PFILE, STR, N) \
166 (memcpy ((PFILE)->limit, STR, (N)), (PFILE)->limit += (N))
167 /* Append string STR (of length N) to PFILE's output buffer. Make space. */
168 #define CPP_PUTS(PFILE, STR, N) CPP_RESERVE(PFILE, N), CPP_PUTS_Q(PFILE, STR,N)
169 /* Append character CH to PFILE's output buffer. Assume sufficient space. */
170 #define CPP_PUTC_Q(PFILE, CH) (*(PFILE)->limit++ = (CH))
171 /* Append character CH to PFILE's output buffer. Make space if need be. */
172 #define CPP_PUTC(PFILE, CH) (CPP_RESERVE (PFILE, 1), CPP_PUTC_Q (PFILE, CH))
174 /* Advance the current line by one. */
175 #define CPP_BUMP_BUFFER_LINE(PBUF) ((PBUF)->lineno++,\
176 (PBUF)->line_base = (PBUF)->cur)
177 #define CPP_BUMP_LINE(PFILE) CPP_BUMP_BUFFER_LINE(CPP_BUFFER(PFILE))
178 #define CPP_BUMP_BUFFER_LINE_CUR(PBUF, CUR) ((PBUF)->lineno++,\
179 (PBUF)->line_base = CUR)
180 #define CPP_BUMP_LINE_CUR(PFILE, CUR) \
181 CPP_BUMP_BUFFER_LINE_CUR(CPP_BUFFER(PFILE), CUR)
182 #define CPP_PREV_BUFFER(BUFFER) ((BUFFER)->prev)
184 /* Are we in column 1 right now? Used mainly for -traditional handling
185 of directives. */
186 #define CPP_IN_COLUMN_1(PFILE) \
187 (CPP_BUFFER (PFILE)->cur - CPP_BUFFER (PFILE)->line_base == 1)
189 #define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps)
190 #define CPP_TRADITIONAL(PFILE) CPP_OPTION (PFILE, traditional)
191 #define CPP_PEDANTIC(PFILE) \
192 (CPP_OPTION (PFILE, pedantic) && !CPP_BUFFER (PFILE)->system_header_p)
193 #define CPP_WTRADITIONAL(PF) \
194 (CPP_OPTION (PF, warn_traditional) && !CPP_BUFFER (PF)->system_header_p)
196 /* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion.
197 (Note that it is false while we're expanding macro *arguments*.) */
198 #define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->macro != NULL)
200 /* Remember the current position of PFILE so it may be returned to
201 after looking ahead a bit.
203 Note that when you set a mark, you _must_ return to that mark. You
204 may not forget about it and continue parsing. You may not pop a
205 buffer with an active mark. You may not call CPP_BUMP_LINE while a
206 mark is active. */
207 #define CPP_SET_BUF_MARK(IP) ((IP)->mark = (IP)->cur)
208 #define CPP_GOTO_BUF_MARK(IP) ((IP)->cur = (IP)->mark, (IP)->mark = 0)
209 #define CPP_SET_MARK(PFILE) CPP_SET_BUF_MARK(CPP_BUFFER(PFILE))
210 #define CPP_GOTO_MARK(PFILE) CPP_GOTO_BUF_MARK(CPP_BUFFER(PFILE))
212 /* ACTIVE_MARK_P is true if there's a live mark in the buffer. */
213 #define ACTIVE_MARK_P(PFILE) (CPP_BUFFER (PFILE)->mark != 0)
215 /* Are mark and point adjacent characters? Used mostly to deal with
216 the somewhat annoying semantic of #define. */
217 #define ADJACENT_TO_MARK(PFILE) \
218 (CPP_BUFFER(PFILE)->cur - CPP_BUFFER(PFILE)->mark == 1)
220 /* In cpphash.c */
221 extern unsigned int _cpp_calc_hash PARAMS ((const U_CHAR *, size_t));
222 extern HASHNODE *_cpp_lookup PARAMS ((cpp_reader *,
223 const U_CHAR *, int));
224 extern void _cpp_free_definition PARAMS ((HASHNODE *));
225 extern int _cpp_create_definition PARAMS ((cpp_reader *,
226 cpp_toklist *, HASHNODE *));
227 extern void _cpp_dump_definition PARAMS ((cpp_reader *, HASHNODE *));
228 extern void _cpp_quote_string PARAMS ((cpp_reader *, const U_CHAR *));
229 extern void _cpp_macroexpand PARAMS ((cpp_reader *, HASHNODE *));
230 extern void _cpp_init_macro_hash PARAMS ((cpp_reader *));
231 extern void _cpp_dump_macro_hash PARAMS ((cpp_reader *));
233 /* In cppfiles.c */
234 extern void _cpp_simplify_pathname PARAMS ((char *));
235 extern void _cpp_execute_include PARAMS ((cpp_reader *, U_CHAR *,
236 unsigned int, int,
237 struct file_name_list *));
238 extern void _cpp_init_include_hash PARAMS ((cpp_reader *));
239 extern const char *_cpp_fake_ihash PARAMS ((cpp_reader *, const char *));
241 /* In cppexp.c */
242 extern int _cpp_parse_expr PARAMS ((cpp_reader *));
244 /* In cpplex.c */
245 extern void _cpp_parse_name PARAMS ((cpp_reader *, int));
246 extern void _cpp_skip_rest_of_line PARAMS ((cpp_reader *));
247 extern void _cpp_skip_hspace PARAMS ((cpp_reader *));
248 extern void _cpp_expand_to_buffer PARAMS ((cpp_reader *,
249 const unsigned char *, int));
250 extern int _cpp_parse_assertion PARAMS ((cpp_reader *));
251 extern enum cpp_ttype _cpp_lex_token PARAMS ((cpp_reader *));
252 extern long _cpp_read_and_prescan PARAMS ((cpp_reader *, cpp_buffer *,
253 int, size_t));
254 extern void _cpp_init_input_buffer PARAMS ((cpp_reader *));
255 extern void _cpp_grow_token_buffer PARAMS ((cpp_reader *, long));
256 extern enum cpp_ttype _cpp_get_directive_token
257 PARAMS ((cpp_reader *));
258 extern enum cpp_ttype _cpp_get_define_token
259 PARAMS ((cpp_reader *));
260 extern void _cpp_scan_line PARAMS ((cpp_reader *, cpp_toklist *));
262 /* In cpplib.c */
263 extern int _cpp_handle_directive PARAMS ((cpp_reader *));
264 extern void _cpp_unwind_if_stack PARAMS ((cpp_reader *, cpp_buffer *));
265 extern void _cpp_check_directive PARAMS ((cpp_toklist *, cpp_token *));
267 /* These are inline functions instead of macros so we can get type
268 checking. */
270 static inline int ustrcmp PARAMS ((const U_CHAR *, const U_CHAR *));
271 static inline int ustrncmp PARAMS ((const U_CHAR *, const U_CHAR *,
272 size_t));
273 static inline size_t ustrlen PARAMS ((const U_CHAR *));
274 static inline U_CHAR *uxstrdup PARAMS ((const U_CHAR *));
275 static inline U_CHAR *ustrchr PARAMS ((const U_CHAR *, int));
277 static inline int
278 ustrcmp (s1, s2)
279 const U_CHAR *s1, *s2;
281 return strcmp ((const char *)s1, (const char *)s2);
284 static inline int
285 ustrncmp (s1, s2, n)
286 const U_CHAR *s1, *s2;
287 size_t n;
289 return strncmp ((const char *)s1, (const char *)s2, n);
292 static inline size_t
293 ustrlen (s1)
294 const U_CHAR *s1;
296 return strlen ((const char *)s1);
299 static inline U_CHAR *
300 uxstrdup (s1)
301 const U_CHAR *s1;
303 return (U_CHAR *) xstrdup ((const char *)s1);
306 static inline U_CHAR *
307 ustrchr (s1, c)
308 const U_CHAR *s1;
309 int c;
311 return (U_CHAR *) strchr ((const char *)s1, c);
314 #endif