OSDN Git Service

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