OSDN Git Service

new
[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 /* Structure used for assertion predicates.  */
29 struct predicate
30 {
31   struct predicate *next;
32   struct cpp_toklist answer;
33 };
34
35 /* List of directories to look for include files in. */
36 struct file_name_list
37 {
38   struct file_name_list *next;
39   struct file_name_list *alloc; /* for the cache of
40                                    current directory entries */
41   char *name;
42   unsigned int nlen;
43   /* We use these to tell if the directory mentioned here is a duplicate
44      of an earlier directory on the search path. */
45   ino_t ino;
46   dev_t dev;
47   /* If the following is nonzero, it is a C-language system include
48      directory.  */
49   int sysp;
50   /* Mapping of file names for this directory.
51      Only used on MS-DOS and related platforms. */
52   struct file_name_map *name_map;
53 };
54 #define ABSOLUTE_PATH ((struct file_name_list *)-1)
55
56 /* This structure is used for the table of all includes.  It is
57    indexed by the `short name' (the name as it appeared in the
58    #include statement) which is stored in *nshort.  */
59 struct ihash
60 {
61   /* Next file with the same short name but a
62      different (partial) pathname). */
63   struct ihash *next_this_file;
64
65   /* Location of the file in the include search path.
66      Used for include_next and to detect redundant includes. */
67   struct file_name_list *foundhere;
68
69   unsigned int hash;            /* save hash value for future reference */
70   const char *nshort;           /* name of file as referenced in #include;
71                                    points into name[]  */
72   const cpp_hashnode *cmacro;   /* macro, if any, preventing reinclusion.  */
73   const char name[1];           /* (partial) pathname of file */
74 };
75 typedef struct ihash IHASH;
76 #define NEVER_REINCLUDE ((const cpp_hashnode *)-1)
77
78 /* Character classes.
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 */
86
87 #define _dollar_ok(x)   ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident))
88
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)
95
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];
101 #else
102 extern unsigned char _cpp_IStable[256];
103 #endif
104
105 /* Macros.  */
106
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
109    reached.  */
110 #define CPP_BUF_PEEK(BUFFER) \
111   ((BUFFER)->cur < (BUFFER)->rlimit ? *(BUFFER)->cur : EOF)
112
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))
117
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))
128
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)
138
139 /* Are we in column 1 right now?  Used mainly for -traditional handling
140    of directives.  */
141 #define CPP_IN_COLUMN_1(PFILE) \
142 (CPP_BUFFER (PFILE)->cur - CPP_BUFFER (PFILE)->line_base == 1)
143
144 #define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps)
145 #define CPP_TRADITIONAL(PFILE) CPP_OPTION (PFILE, traditional)
146 #define CPP_PEDANTIC(PFILE) \
147   (CPP_OPTION (PFILE, pedantic) && !CPP_BUFFER (PFILE)->system_header_p)
148 #define CPP_WTRADITIONAL(PF) \
149   (CPP_OPTION (PF, warn_traditional) && !CPP_BUFFER (PF)->system_header_p)
150
151 /* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion.
152    (Note that it is false while we're expanding macro *arguments*.) */
153 #define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->macro != NULL)
154
155 /* Remember the current position of PFILE so it may be returned to
156    after looking ahead a bit.
157
158    Note that when you set a mark, you _must_ return to that mark.  You
159    may not forget about it and continue parsing.  You may not pop a
160    buffer with an active mark.  You may not call CPP_BUMP_LINE while a
161    mark is active.  */
162 #define CPP_SET_BUF_MARK(IP)   ((IP)->mark = (IP)->cur)
163 #define CPP_GOTO_BUF_MARK(IP)  ((IP)->cur = (IP)->mark, (IP)->mark = 0)
164 #define CPP_SET_MARK(PFILE)  CPP_SET_BUF_MARK(CPP_BUFFER(PFILE))
165 #define CPP_GOTO_MARK(PFILE) CPP_GOTO_BUF_MARK(CPP_BUFFER(PFILE))
166
167 /* ACTIVE_MARK_P is true if there's a live mark in the buffer.  */
168 #define ACTIVE_MARK_P(PFILE) (CPP_BUFFER (PFILE)->mark != 0)
169
170 /* Are mark and point adjacent characters?  Used mostly to deal with
171    the somewhat annoying semantic of #define.  */
172 #define ADJACENT_TO_MARK(PFILE) \
173  (CPP_BUFFER(PFILE)->cur - CPP_BUFFER(PFILE)->mark == 1)
174
175 /* Flags for _cpp_init_toklist.  */
176 #define DUMMY_TOKEN     0
177 #define NO_DUMMY_TOKEN  1
178
179 /* In cpphash.c */
180 extern unsigned int _cpp_calc_hash      PARAMS ((const U_CHAR *, size_t));
181 extern void _cpp_free_definition        PARAMS ((cpp_hashnode *));
182 extern int _cpp_create_definition       PARAMS ((cpp_reader *, cpp_toklist *,
183                                                  cpp_hashnode *));
184 extern void _cpp_dump_definition        PARAMS ((cpp_reader *, cpp_hashnode *));
185 extern void _cpp_quote_string           PARAMS ((cpp_reader *, const U_CHAR *));
186 extern void _cpp_macroexpand            PARAMS ((cpp_reader *, cpp_hashnode *));
187 extern void _cpp_init_macro_hash        PARAMS ((cpp_reader *));
188 extern void _cpp_dump_macro_hash        PARAMS ((cpp_reader *));
189
190 /* In cppfiles.c */
191 extern void _cpp_simplify_pathname      PARAMS ((char *));
192 extern void _cpp_execute_include        PARAMS ((cpp_reader *, U_CHAR *,
193                                                  unsigned int, int,
194                                                  struct file_name_list *));
195 extern void _cpp_init_include_hash      PARAMS ((cpp_reader *));
196 extern const char *_cpp_fake_ihash      PARAMS ((cpp_reader *, const char *));
197
198 /* In cppexp.c */
199 extern int _cpp_parse_expr              PARAMS ((cpp_reader *));
200
201 /* In cpplex.c */
202 extern void _cpp_parse_name             PARAMS ((cpp_reader *, int));
203 extern void _cpp_skip_rest_of_line      PARAMS ((cpp_reader *));
204 extern void _cpp_skip_hspace            PARAMS ((cpp_reader *));
205 extern void _cpp_expand_to_buffer       PARAMS ((cpp_reader *,
206                                                  const unsigned char *, int));
207 extern int _cpp_parse_assertion         PARAMS ((cpp_reader *));
208 extern enum cpp_ttype _cpp_lex_token    PARAMS ((cpp_reader *));
209 extern ssize_t _cpp_prescan             PARAMS ((cpp_reader *, cpp_buffer *,
210                                                  ssize_t));
211 extern void _cpp_init_input_buffer      PARAMS ((cpp_reader *));
212 extern void _cpp_grow_token_buffer      PARAMS ((cpp_reader *, long));
213 extern enum cpp_ttype _cpp_get_directive_token
214                                         PARAMS ((cpp_reader *));
215 extern enum cpp_ttype _cpp_get_define_token
216                                         PARAMS ((cpp_reader *));
217 extern enum cpp_ttype _cpp_scan_until   PARAMS ((cpp_reader *, cpp_toklist *,
218                                                  enum cpp_ttype));
219 extern void _cpp_init_toklist           PARAMS ((cpp_toklist *, int));
220 extern void _cpp_clear_toklist          PARAMS ((cpp_toklist *));
221 extern void _cpp_free_toklist           PARAMS ((cpp_toklist *));
222 extern void _cpp_slice_toklist          PARAMS ((cpp_toklist *,
223                                                  const cpp_token *,
224                                                  const cpp_token *));
225 extern void _cpp_squeeze_toklist        PARAMS ((cpp_toklist *));
226 extern int _cpp_equiv_tokens            PARAMS ((const cpp_token *,
227                                                  const cpp_token *));
228 extern int _cpp_equiv_toklists          PARAMS ((const cpp_toklist *,
229                                                  const cpp_toklist *));
230 extern void _cpp_expand_token_space     PARAMS ((cpp_toklist *, unsigned int));
231
232 /* In cpplib.c */
233 extern int _cpp_handle_directive        PARAMS ((cpp_reader *));
234 extern void _cpp_unwind_if_stack        PARAMS ((cpp_reader *, cpp_buffer *));
235 extern void _cpp_check_directive        PARAMS ((cpp_toklist *, cpp_token *));
236
237 /* These are inline functions instead of macros so we can get type
238    checking.  */
239
240 static inline int ustrcmp       PARAMS ((const U_CHAR *, const U_CHAR *));
241 static inline int ustrncmp      PARAMS ((const U_CHAR *, const U_CHAR *,
242                                          size_t));
243 static inline size_t ustrlen    PARAMS ((const U_CHAR *));
244 static inline U_CHAR *uxstrdup  PARAMS ((const U_CHAR *));
245 static inline U_CHAR *ustrchr   PARAMS ((const U_CHAR *, int));
246
247 static inline int
248 ustrcmp (s1, s2)
249      const U_CHAR *s1, *s2;
250 {
251   return strcmp ((const char *)s1, (const char *)s2);
252 }
253
254 static inline int
255 ustrncmp (s1, s2, n)
256      const U_CHAR *s1, *s2;
257      size_t n;
258 {
259   return strncmp ((const char *)s1, (const char *)s2, n);
260 }
261
262 static inline size_t
263 ustrlen (s1)
264      const U_CHAR *s1;
265 {
266   return strlen ((const char *)s1);
267 }
268
269 static inline U_CHAR *
270 uxstrdup (s1)
271      const U_CHAR *s1;
272 {
273   return (U_CHAR *) xstrdup ((const char *)s1);
274 }
275
276 static inline U_CHAR *
277 ustrchr (s1, c)
278      const U_CHAR *s1;
279      int c;
280 {
281   return (U_CHAR *) strchr ((const char *)s1, c);
282 }
283
284 #endif