OSDN Git Service

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