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
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 /* Structure used for assertion predicates. */
31 struct predicate
*next
;
32 struct cpp_toklist answer
;
35 /* List of directories to look for include files in. */
38 struct file_name_list
*next
;
39 struct file_name_list
*alloc
; /* for the cache of
40 current directory entries */
43 /* We use these to tell if the directory mentioned here is a duplicate
44 of an earlier directory on the search path. */
47 /* If the following is nonzero, it is a C-language system include
50 /* Mapping of file names for this directory.
51 Only used on MS-DOS and related platforms. */
52 struct file_name_map
*name_map
;
54 #define ABSOLUTE_PATH ((struct file_name_list *)-1)
56 /* This structure is used for the table of all includes. */
59 const char *name
; /* actual path name of file */
60 const cpp_hashnode
*cmacro
; /* macro, if any, preventing reinclusion. */
61 const struct file_name_list
*foundhere
;
62 /* location in search path where file was
63 found, for #include_next */
64 int fd
; /* file descriptor possibly open on file */
65 unsigned short include_count
; /* number of times file has been read */
66 unsigned short sysp
; /* file is a system header */
69 /* The cmacro works like this: If it's NULL, the file is to be
70 included again. If it's NEVER_REREAD, the file is never to be
71 included again. Otherwise it is a macro hashnode, and the file is
72 to be included again if the macro is not defined. */
73 #define NEVER_REREAD ((const cpp_hashnode *)-1)
74 #define DO_NOT_REREAD(inc) \
76 ((inc)->cmacro == NEVER_REREAD || (inc)->cmacro->type != T_VOID))
79 If the definition of `numchar' looks odd to you, please look up the
80 definition of a pp-number in the C standard [section 6.4.8 of C99] */
81 #define ISidnum 0x01 /* a-zA-Z0-9_ */
82 #define ISidstart 0x02 /* _a-zA-Z */
83 #define ISnumstart 0x04 /* 0-9 */
84 #define IShspace 0x08 /* ' ' \t \f \v */
85 #define ISspace 0x10 /* ' ' \t \f \v \n */
87 #define _dollar_ok(x) ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident))
89 #define is_idchar(x) ((_cpp_IStable[x] & ISidnum) || _dollar_ok(x))
90 #define is_idstart(x) ((_cpp_IStable[x] & ISidstart) || _dollar_ok(x))
91 #define is_numchar(x) (_cpp_IStable[x] & ISidnum)
92 #define is_numstart(x) (_cpp_IStable[x] & ISnumstart)
93 #define is_hspace(x) (_cpp_IStable[x] & IShspace)
94 #define is_space(x) (_cpp_IStable[x] & ISspace)
96 /* This table is constant if it can be initialized at compile time,
97 which is the case if cpp was compiled with GCC >=2.7, or another
98 compiler that supports C99. */
99 #if (GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L)
100 extern const unsigned char _cpp_IStable
[256];
102 extern unsigned char _cpp_IStable
[256];
107 /* One character lookahead in the input buffer. Note that if this
108 returns EOF, it does *not* necessarily mean the file's end has been
110 #define CPP_BUF_PEEK(BUFFER) \
111 ((BUFFER)->cur < (BUFFER)->rlimit ? *(BUFFER)->cur : EOF)
113 /* Make sure PFILE->token_buffer has space for at least N more characters. */
114 #define CPP_RESERVE(PFILE, N) \
115 (CPP_WRITTEN (PFILE) + (size_t)(N) > (PFILE)->token_buffer_size \
116 && (_cpp_grow_token_buffer (PFILE, N), 0))
118 /* Append string STR (of length N) to PFILE's output buffer.
119 Assume there is enough space. */
120 #define CPP_PUTS_Q(PFILE, STR, N) \
121 (memcpy ((PFILE)->limit, STR, (N)), (PFILE)->limit += (N))
122 /* Append string STR (of length N) to PFILE's output buffer. Make space. */
123 #define CPP_PUTS(PFILE, STR, N) CPP_RESERVE(PFILE, N), CPP_PUTS_Q(PFILE, STR,N)
124 /* Append character CH to PFILE's output buffer. Assume sufficient space. */
125 #define CPP_PUTC_Q(PFILE, CH) (*(PFILE)->limit++ = (CH))
126 /* Append character CH to PFILE's output buffer. Make space if need be. */
127 #define CPP_PUTC(PFILE, CH) (CPP_RESERVE (PFILE, 1), CPP_PUTC_Q (PFILE, CH))
129 /* Advance the current line by one. */
130 #define CPP_BUMP_BUFFER_LINE(PBUF) ((PBUF)->lineno++,\
131 (PBUF)->line_base = (PBUF)->cur)
132 #define CPP_BUMP_LINE(PFILE) CPP_BUMP_BUFFER_LINE(CPP_BUFFER(PFILE))
133 #define CPP_BUMP_BUFFER_LINE_CUR(PBUF, CUR) ((PBUF)->lineno++,\
134 (PBUF)->line_base = CUR)
135 #define CPP_BUMP_LINE_CUR(PFILE, CUR) \
136 CPP_BUMP_BUFFER_LINE_CUR(CPP_BUFFER(PFILE), CUR)
137 #define CPP_PREV_BUFFER(BUFFER) ((BUFFER)->prev)
139 /* Are we in column 1 right now? Used mainly for -traditional handling
141 #define CPP_IN_COLUMN_1(PFILE) \
142 (CPP_BUFFER (PFILE)->cur - CPP_BUFFER (PFILE)->line_base == 1)
144 #define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps)
145 #define CPP_TRADITIONAL(PFILE) CPP_OPTION (PFILE, traditional)
146 #define CPP_IN_SYSTEM_HEADER(PFILE) (cpp_file_buffer (PFILE)->inc->sysp)
147 #define CPP_PEDANTIC(PF) \
148 (CPP_OPTION (PF, pedantic) && !CPP_IN_SYSTEM_HEADER (PF))
149 #define CPP_WTRADITIONAL(PF) \
150 (CPP_OPTION (PF, warn_traditional) && !CPP_IN_SYSTEM_HEADER (PF))
152 /* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion.
153 (Note that it is false while we're expanding macro *arguments*.) */
154 #define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->macro != NULL)
156 /* Remember the current position of PFILE so it may be returned to
157 after looking ahead a bit.
159 Note that when you set a mark, you _must_ return to that mark. You
160 may not forget about it and continue parsing. You may not pop a
161 buffer with an active mark. You may not call CPP_BUMP_LINE while a
163 #define CPP_SET_BUF_MARK(IP) ((IP)->mark = (IP)->cur)
164 #define CPP_GOTO_BUF_MARK(IP) ((IP)->cur = (IP)->mark, (IP)->mark = 0)
165 #define CPP_SET_MARK(PFILE) CPP_SET_BUF_MARK(CPP_BUFFER(PFILE))
166 #define CPP_GOTO_MARK(PFILE) CPP_GOTO_BUF_MARK(CPP_BUFFER(PFILE))
168 /* ACTIVE_MARK_P is true if there's a live mark in the buffer. */
169 #define ACTIVE_MARK_P(PFILE) (CPP_BUFFER (PFILE)->mark != 0)
171 /* Are mark and point adjacent characters? Used mostly to deal with
172 the somewhat annoying semantic of #define. */
173 #define ADJACENT_TO_MARK(PFILE) \
174 (CPP_BUFFER(PFILE)->cur - CPP_BUFFER(PFILE)->mark == 1)
176 /* Flags for _cpp_init_toklist. */
177 #define DUMMY_TOKEN 0
178 #define NO_DUMMY_TOKEN 1
181 extern unsigned int _cpp_calc_hash
PARAMS ((const U_CHAR
*, size_t));
182 extern void _cpp_free_definition
PARAMS ((cpp_hashnode
*));
183 extern int _cpp_create_definition
PARAMS ((cpp_reader
*, cpp_toklist
*,
185 extern void _cpp_dump_definition
PARAMS ((cpp_reader
*, cpp_hashnode
*));
186 extern void _cpp_quote_string
PARAMS ((cpp_reader
*, const U_CHAR
*));
187 extern void _cpp_macroexpand
PARAMS ((cpp_reader
*, cpp_hashnode
*));
188 extern void _cpp_init_macro_hash
PARAMS ((cpp_reader
*));
189 extern void _cpp_dump_macro_hash
PARAMS ((cpp_reader
*));
192 extern void _cpp_simplify_pathname
PARAMS ((char *));
193 extern void _cpp_execute_include
PARAMS ((cpp_reader
*, U_CHAR
*,
195 struct file_name_list
*));
196 extern void _cpp_init_include_table
PARAMS ((cpp_reader
*));
197 extern const char *_cpp_fake_include
PARAMS ((cpp_reader
*, const char *));
200 extern int _cpp_parse_expr
PARAMS ((cpp_reader
*));
203 extern void _cpp_parse_name
PARAMS ((cpp_reader
*, int));
204 extern void _cpp_skip_rest_of_line
PARAMS ((cpp_reader
*));
205 extern void _cpp_skip_hspace
PARAMS ((cpp_reader
*));
206 extern void _cpp_expand_to_buffer
PARAMS ((cpp_reader
*,
207 const unsigned char *, int));
208 extern int _cpp_parse_assertion
PARAMS ((cpp_reader
*));
209 extern enum cpp_ttype _cpp_lex_token
PARAMS ((cpp_reader
*));
210 extern ssize_t _cpp_prescan
PARAMS ((cpp_reader
*, cpp_buffer
*,
212 extern void _cpp_init_input_buffer
PARAMS ((cpp_reader
*));
213 extern void _cpp_grow_token_buffer
PARAMS ((cpp_reader
*, long));
214 extern enum cpp_ttype _cpp_get_directive_token
215 PARAMS ((cpp_reader
*));
216 extern enum cpp_ttype _cpp_get_define_token
217 PARAMS ((cpp_reader
*));
218 extern enum cpp_ttype _cpp_scan_until
PARAMS ((cpp_reader
*, cpp_toklist
*,
220 extern void _cpp_init_toklist
PARAMS ((cpp_toklist
*, int));
221 extern void _cpp_clear_toklist
PARAMS ((cpp_toklist
*));
222 extern void _cpp_free_toklist
PARAMS ((cpp_toklist
*));
223 extern void _cpp_slice_toklist
PARAMS ((cpp_toklist
*,
226 extern void _cpp_squeeze_toklist
PARAMS ((cpp_toklist
*));
227 extern int _cpp_equiv_tokens
PARAMS ((const cpp_token
*,
229 extern int _cpp_equiv_toklists
PARAMS ((const cpp_toklist
*,
230 const cpp_toklist
*));
231 extern void _cpp_expand_token_space
PARAMS ((cpp_toklist
*, unsigned int));
234 extern int _cpp_handle_directive
PARAMS ((cpp_reader
*));
235 extern void _cpp_unwind_if_stack
PARAMS ((cpp_reader
*, cpp_buffer
*));
236 extern void _cpp_check_directive
PARAMS ((cpp_toklist
*, cpp_token
*));
238 /* Utility routines and macros. */
239 #define xnew(T) (T *) xmalloc (sizeof(T))
240 #define xnewvec(T, N) (T *) xmalloc (sizeof(T) * (N))
242 /* These are inline functions instead of macros so we can get type
245 static inline int ustrcmp
PARAMS ((const U_CHAR
*, const U_CHAR
*));
246 static inline int ustrncmp
PARAMS ((const U_CHAR
*, const U_CHAR
*,
248 static inline size_t ustrlen
PARAMS ((const U_CHAR
*));
249 static inline U_CHAR
*uxstrdup
PARAMS ((const U_CHAR
*));
250 static inline U_CHAR
*ustrchr
PARAMS ((const U_CHAR
*, int));
254 const U_CHAR
*s1
, *s2
;
256 return strcmp ((const char *)s1
, (const char *)s2
);
261 const U_CHAR
*s1
, *s2
;
264 return strncmp ((const char *)s1
, (const char *)s2
, n
);
271 return strlen ((const char *)s1
);
274 static inline U_CHAR
*
278 return (U_CHAR
*) xstrdup ((const char *)s1
);
281 static inline U_CHAR
*
286 return (U_CHAR
*) strchr ((const char *)s1
, c
);