OSDN Git Service

* c-common.c (parse_in): Make a cpp_reader *.
[pf3gnuchains/gcc-fork.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') \
30         && CPP_OPTION (pfile, extended_numbers))))
31
32 /* Memory pools.  */
33 #define ALIGN(size, align) (((size) + ((align) - 1)) & ~((align) - 1))
34 #define POOL_FRONT(p) ((p)->cur->front)
35 #define POOL_LIMIT(p) ((p)->cur->limit)
36 #define POOL_BASE(p)  ((p)->cur->base)
37 #define POOL_SIZE(p)  ((p)->cur->limit - (p)->cur->base)
38 #define POOL_ROOM(p)  ((p)->cur->limit - (p)->cur->front)
39 #define POOL_USED(p)  ((p)->cur->front - (p)->cur->base)
40 #define POOL_COMMIT(p, len) do {((p)->cur->front += ALIGN (len, (p)->align));\
41   if ((p)->cur->front > (p)->cur->limit) abort ();} while (0)
42
43 typedef struct cpp_chunk cpp_chunk;
44 struct cpp_chunk
45 {
46   cpp_chunk *next;
47   unsigned char *front;
48   unsigned char *limit;
49   unsigned char *base;
50 };
51
52 /* List of directories to look for include files in. */
53 struct file_name_list
54 {
55   struct file_name_list *next;
56   struct file_name_list *alloc; /* for the cache of
57                                    current directory entries */
58   char *name;
59   unsigned int nlen;
60   /* We use these to tell if the directory mentioned here is a duplicate
61      of an earlier directory on the search path. */
62   ino_t ino;
63   dev_t dev;
64   /* If the following is nonzero, it is a C-language system include
65      directory.  */
66   int sysp;
67   /* Mapping of file names for this directory.
68      Only used on MS-DOS and related platforms. */
69   struct file_name_map *name_map;
70 };
71 #define ABSOLUTE_PATH ((struct file_name_list *)-1)
72
73 /* This structure is used for the table of all includes.  */
74 struct include_file
75 {
76   const char *name;             /* actual path name of file */
77   const cpp_hashnode *cmacro;   /* macro, if any, preventing reinclusion.  */
78   const struct file_name_list *foundhere;
79                                 /* location in search path where file was
80                                    found, for #include_next */
81   const unsigned char *buffer;  /* pointer to cached file contents */
82   struct stat st;               /* copy of stat(2) data for file */
83   int fd;                       /* fd open on file (short term storage only) */
84   unsigned short include_count; /* number of times file has been read */
85   unsigned short refcnt;        /* number of stacked buffers using this file */
86   unsigned char sysp;           /* file is a system header */
87   unsigned char mapped;         /* file buffer is mmapped */
88   unsigned char defined;        /* cmacro prevents inclusion in this state */
89 };
90
91 /* The cmacro works like this: If it's NULL, the file is to be
92    included again.  If it's NEVER_REREAD, the file is never to be
93    included again.  Otherwise it is a macro hashnode, and the file is
94    to be included again if the macro is defined or not as specified by
95    DEFINED.  */
96 #define NEVER_REREAD ((const cpp_hashnode *)-1)
97 #define DO_NOT_REREAD(inc) \
98 ((inc)->cmacro && ((inc)->cmacro == NEVER_REREAD \
99                    || ((inc)->cmacro->type == NT_MACRO) == (inc)->defined))
100
101 struct cpp_buffer
102 {
103   const unsigned char *cur;      /* current position */
104   const unsigned char *rlimit; /* end of valid data */
105   const unsigned char *line_base; /* start of current line */
106   cppchar_t read_ahead;         /* read ahead character */
107   cppchar_t extra_char;         /* extra read-ahead for long tokens.  */
108
109   struct cpp_reader *pfile;     /* Owns this buffer.  */
110   struct cpp_buffer *prev;
111
112   const unsigned char *buf;      /* entire buffer */
113
114   /* Filename specified with #line command.  */
115   const char *nominal_fname;
116
117   /* Actual directory of this file, used only for "" includes */
118   struct file_name_list *actual_dir;
119
120   /* Pointer into the include table.  Used for include_next and
121      to record control macros. */
122   struct include_file *inc;
123
124   /* Value of if_stack at start of this file.
125      Used to prohibit unmatched #endif (etc) in an include file.  */
126   struct if_stack *if_stack;
127
128   /* Token column position adjustment owing to tabs in whitespace.  */
129   unsigned int col_adjust;
130
131   /* Line number at line_base (above). */
132   unsigned int lineno;
133
134   /* Because of the way the lexer works, -Wtrigraphs can sometimes
135      warn twice for the same trigraph.  This helps prevent that.  */
136   const unsigned char *last_Wtrigraphs;
137
138   /* True if we have already warned about C++ comments in this file.
139      The warning happens only for C89 extended mode with -pedantic on,
140      or for -Wtraditional, and only once per file (otherwise it would
141      be far too noisy).  */
142   unsigned char warned_cplusplus_comments;
143
144   /* True if we don't process trigraphs and escaped newlines.  True
145      for preprocessed input, command line directives, and _Pragma
146      buffers.  */
147   unsigned char from_stage3;
148
149   /* Temporary storage for pfile->skipping whilst in a directive.  */
150   unsigned char was_skipping;
151 };
152
153 /* Character classes.
154    If the definition of `numchar' looks odd to you, please look up the
155    definition of a pp-number in the C standard [section 6.4.8 of C99].
156
157    In the unlikely event that characters other than \r and \n enter
158    the set is_vspace, the macro handle_newline() in cpplex.c must be
159    updated.  */
160 #define ISidnum         0x01    /* a-zA-Z0-9_ */
161 #define ISidstart       0x02    /* _a-zA-Z */
162 #define ISnumstart      0x04    /* 0-9 */
163 #define IShspace        0x08    /* ' ' \t */
164 #define ISvspace        0x10    /* \r \n */
165 #define ISspace         0x20    /* ' ' \t \r \n \f \v \0 */
166
167 #define _dollar_ok(x)   ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident))
168
169 #define is_idchar(x)    ((_cpp_IStable[x] & ISidnum) || _dollar_ok(x))
170 #define is_idstart(x)   ((_cpp_IStable[x] & ISidstart) || _dollar_ok(x))
171 #define is_numchar(x)   (_cpp_IStable[x] & ISidnum)
172 #define is_numstart(x)  (_cpp_IStable[x] & ISnumstart)
173 #define is_hspace(x)    (_cpp_IStable[x] & IShspace)
174 #define is_vspace(x)    (_cpp_IStable[x] & ISvspace)
175 #define is_nvspace(x)   ((_cpp_IStable[x] & (ISspace | ISvspace)) == ISspace)
176 #define is_space(x)     (_cpp_IStable[x] & ISspace)
177
178 /* These tables are constant if they can be initialized at compile time,
179    which is the case if cpp was compiled with GCC >=2.7, or another
180    compiler that supports C99.  */
181 #if HAVE_DESIGNATED_INITIALIZERS
182 extern const unsigned char _cpp_IStable[UCHAR_MAX + 1];
183 extern const unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
184 #else
185 extern unsigned char _cpp_IStable[UCHAR_MAX + 1];
186 extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
187 #endif
188
189 /* Macros.  */
190
191 #define CPP_PREV_BUFFER(BUFFER) ((BUFFER)->prev)
192 #define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps)
193 #define CPP_IN_SYSTEM_HEADER(PFILE) \
194   (CPP_BUFFER (PFILE) && CPP_BUFFER (PFILE)->inc \
195    && CPP_BUFFER (PFILE)->inc->sysp)
196 #define CPP_PEDANTIC(PF) \
197   CPP_OPTION (PF, pedantic)
198 #define CPP_WTRADITIONAL(PF) \
199   CPP_OPTION (PF, warn_traditional)
200
201 /* Hash step.  The hash calculation is duplicated in cpp_lookup and
202    parse_name.  */
203 #define HASHSTEP(r, c) ((r) * 67 + (c - 113));
204
205 /* In cpperror.c  */
206 enum error_type { WARNING = 0, PEDWARN, ERROR, FATAL, ICE };
207 extern int _cpp_begin_message PARAMS ((cpp_reader *, enum error_type,
208                                        const char *, const cpp_lexer_pos *));
209
210 /* In cppmacro.c */
211 extern void _cpp_free_definition        PARAMS ((cpp_hashnode *));
212 extern int _cpp_create_definition       PARAMS ((cpp_reader *, cpp_hashnode *));
213 extern void _cpp_pop_context            PARAMS ((cpp_reader *));
214 extern void _cpp_free_lookaheads        PARAMS ((cpp_reader *));
215 extern void _cpp_release_lookahead      PARAMS ((cpp_reader *));
216 extern void _cpp_push_token             PARAMS ((cpp_reader *, const cpp_token *,
217                                                  const cpp_lexer_pos *));
218
219 /* In cpphash.c */
220 extern void _cpp_init_hashtable         PARAMS ((cpp_reader *));
221 extern void _cpp_cleanup_hashtable      PARAMS ((cpp_reader *));
222 extern cpp_hashnode *_cpp_lookup_with_hash PARAMS ((cpp_reader*, size_t,
223                                                     unsigned int));
224
225 /* In cppfiles.c */
226 extern void _cpp_simplify_pathname      PARAMS ((char *));
227 extern int _cpp_read_file               PARAMS ((cpp_reader *, const char *));
228 extern void _cpp_execute_include        PARAMS ((cpp_reader *,
229                                                  const cpp_token *, int,
230                                                  struct file_name_list *));
231 extern int _cpp_compare_file_date       PARAMS ((cpp_reader *,
232                                                  const cpp_token *));
233 extern void _cpp_report_missing_guards  PARAMS ((cpp_reader *));
234 extern void _cpp_init_includes          PARAMS ((cpp_reader *));
235 extern void _cpp_cleanup_includes       PARAMS ((cpp_reader *));
236 extern void _cpp_pop_file_buffer        PARAMS ((cpp_reader *, cpp_buffer *));
237
238 /* In cppexp.c */
239 extern int _cpp_parse_expr              PARAMS ((cpp_reader *));
240
241 /* In cpplex.c */
242 extern void _cpp_lex_token              PARAMS ((cpp_reader *, cpp_token *));
243 extern int _cpp_equiv_tokens            PARAMS ((const cpp_token *,
244                                                  const cpp_token *));
245 extern void _cpp_init_pool              PARAMS ((cpp_pool *, unsigned int,
246                                                   unsigned int, unsigned int));
247 extern void _cpp_free_pool              PARAMS ((cpp_pool *));
248 extern unsigned char *_cpp_pool_reserve PARAMS ((cpp_pool *, unsigned int));
249 extern unsigned char *_cpp_pool_alloc   PARAMS ((cpp_pool *, unsigned int));
250 extern unsigned char *_cpp_next_chunk   PARAMS ((cpp_pool *, unsigned int,
251                                                  unsigned char **));
252 extern void _cpp_lock_pool              PARAMS ((cpp_pool *));
253 extern void _cpp_unlock_pool            PARAMS ((cpp_pool *));
254
255 /* In cpplib.c */
256 extern int _cpp_test_assertion PARAMS ((cpp_reader *, int *));
257 extern int _cpp_handle_directive PARAMS ((cpp_reader *, int));
258 extern void _cpp_define_builtin PARAMS ((cpp_reader *, const char *));
259 extern void _cpp_do__Pragma     PARAMS ((cpp_reader *));
260 extern void _cpp_init_stacks    PARAMS ((cpp_reader *));
261 extern void _cpp_cleanup_stacks PARAMS ((cpp_reader *));
262 extern void _cpp_init_internal_pragmas PARAMS ((cpp_reader *));
263 extern void _cpp_do_file_change PARAMS ((cpp_reader *, enum cpp_fc_reason,
264                                          const char *, unsigned int));
265
266 /* Utility routines and macros.  */
267 #define DSC(str) (const U_CHAR *)str, sizeof str - 1
268 #define xnew(T)         (T *) xmalloc (sizeof(T))
269 #define xcnew(T)        (T *) xcalloc (1, sizeof(T))
270 #define xnewvec(T, N)   (T *) xmalloc (sizeof(T) * (N))
271 #define xcnewvec(T, N)  (T *) xcalloc (N, sizeof(T))
272 #define xobnew(O, T)    (T *) obstack_alloc (O, sizeof(T))
273
274 #endif