OSDN Git Service

* cppfiles.c (file_cleanup, _cpp_find_include_file,
[pf3gnuchains/gcc-fork.git] / gcc / cpplib.h
1 /* Definitions for CPP library.
2    Copyright (C) 1995, 96-99, 2000 Free Software Foundation, Inc.
3    Written by Per Bothner, 1994-95.
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any
8 later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19  In other words, you are welcome to use, share and improve this program.
20  You are forbidden to forbid anyone else to use, share and improve
21  what you give them.   Help stamp out software-hoarding!  */
22 #ifndef __GCC_CPPLIB__
23 #define __GCC_CPPLIB__
24
25 #include <sys/types.h>
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 typedef struct cpp_reader cpp_reader;
32 typedef struct cpp_buffer cpp_buffer;
33 typedef struct cpp_options cpp_options;
34
35 enum cpp_token
36 {
37   CPP_EOF = -1,
38   CPP_OTHER = 0,
39   CPP_COMMENT = 1,
40   CPP_HSPACE,
41   CPP_VSPACE, /* newlines and #line directives */
42   CPP_NAME,
43   CPP_NUMBER,
44   CPP_CHAR,
45   CPP_WCHAR,
46   CPP_STRING,
47   CPP_WSTRING,
48   CPP_DIRECTIVE,
49   CPP_ASSERTION,        /* #machine(a29k) */
50   CPP_STRINGIZE,        /* stringize macro argument */
51   CPP_TOKPASTE,         /* paste macro arg with next/prev token */
52   CPP_LPAREN,           /* "(" */
53   CPP_RPAREN,           /* ")" */
54   CPP_LBRACE,           /* "{" */
55   CPP_RBRACE,           /* "}" */
56   CPP_COMMA,            /* "," */
57   CPP_SEMICOLON,        /* ";" */
58   CPP_3DOTS,            /* "..." */
59   CPP_POP               /* We're about to pop the buffer stack.  */
60 };
61
62 typedef int (*parse_cleanup_t) PARAMS((cpp_buffer *, cpp_reader *));
63
64 struct cpp_buffer
65 {
66   const unsigned char *cur;      /* current position */
67   const unsigned char *rlimit; /* end of valid data */
68   const unsigned char *buf;      /* entire buffer */
69   const unsigned char *alimit; /* end of allocated buffer */
70   const unsigned char *line_base; /* start of current line */
71
72   struct cpp_buffer *prev;
73
74   /* Filename specified with #line command.  */
75   const char *nominal_fname;
76   /* Last filename specified with #line command.  */
77   const char *last_nominal_fname;
78   /* Actual directory of this file, used only for "" includes */
79   struct file_name_list *actual_dir;
80
81   /* Pointer into the include hash table.  Used for include_next and
82      to record control macros. */
83   struct ihash *ihash;
84
85   long lineno; /* Line number at CPP_LINE_BASE. */
86   long colno; /* Column number at CPP_LINE_BASE. */
87   long mark;  /* Saved position for lengthy backtrack. */
88   parse_cleanup_t cleanup;
89   void *data;
90
91   /* Value of if_stack at start of this file.
92      Used to prohibit unmatched #endif (etc) in an include file.  */
93   struct if_stack *if_stack;
94
95   /* True if this is a header file included using <FILENAME>.  */
96   char system_header_p;
97   char seen_eof;
98
99   /* True if buffer contains escape sequences.
100      Currently there are two kinds:
101      "\r-" means following identifier should not be macro-expanded.
102      "\r " means a token-separator.  This turns into " " in final output
103           if not stringizing and needed to separate tokens; otherwise nothing.
104      Any other two-character sequence beginning with \r is an error.
105
106      If this is NOT set, then \r is a one-character escape meaning backslash
107      newline.  This is guaranteed not to occur in the middle of a token.
108      The two interpretations of \r do not conflict, because the two-character
109      escapes are used only in macro buffers, and backslash-newline is removed
110      from macro expansion text in collect_expansion and/or macarg.  */
111   char has_escapes;
112
113   /* Used by the C++ frontend to implement redirected input (such as for
114      default argument and/or template parsing).  */
115   char manual_pop;
116
117   /* True if we have already warned about C++ comments in this file.
118      The warning happens only for C89 extended mode with -pedantic on,
119      and only once per file (otherwise it would be far too noisy).  */
120   char warned_cplusplus_comments;
121 };
122
123 struct file_name_map_list;
124
125 /* Maximum nesting of cpp_buffers.  We use a static limit, partly for
126    efficiency, and partly to limit runaway recursion.  */
127 #define CPP_STACK_MAX 200
128
129 /* A cpp_reader encapsulates the "state" of a pre-processor run.
130    Applying cpp_get_token repeatedly yields a stream of pre-processor
131    tokens.  Usually, there is only one cpp_reader object active. */
132
133 struct cpp_reader
134 {
135   cpp_buffer *buffer;
136   cpp_options *opts;
137
138   /* A buffer used for both for cpp_get_token's output, and also internally. */
139   unsigned char *token_buffer;
140   /* Allocated size of token_buffer.  CPP_RESERVE allocates space.  */
141   unsigned int token_buffer_size;
142   /* End of the written part of token_buffer. */
143   unsigned char *limit;
144
145   /* Error counter for exit code */
146   int errors;
147
148   /* Line where a newline was first seen in a string constant.  */
149   int multiline_string_line;
150
151   /* Current depth in #include directives that use <...>.  */
152   int system_include_depth;
153
154   /* Current depth of buffer stack. */
155   int buffer_stack_depth;
156
157   /* Hash table of macros and assertions.  See cpphash.c */
158 #define HASHSIZE 1403
159   struct hashnode **hashtab;
160
161   /* Hash table of other included files.  See cppfiles.c */
162 #define ALL_INCLUDE_HASHSIZE 71
163   struct ihash *all_include_files[ALL_INCLUDE_HASHSIZE];
164
165   /* Chain of `actual directory' file_name_list entries,
166      for "" inclusion. */
167   struct file_name_list *actual_dirs;
168
169   /* Current maximum length of directory names in the search path
170      for include files.  (Altered as we get more of them.)  */
171   unsigned int max_include_len;
172
173   struct if_stack *if_stack;
174
175   /* Nonzero means we have printed (while error reporting) a list of
176      containing files that matches the current status.  */
177   char input_stack_listing_current;
178
179   /* If non-zero, macros are not expanded.  */
180   char no_macro_expand;
181
182   /* If non-zero, directives cause a hard error.  Used when parsing
183      macro arguments.  */
184   char no_directives;
185
186   /* Print column number in error messages.  */
187   char show_column;
188
189   /* We're printed a warning recommending against using #import.  */
190   char import_warning;
191
192   /* If true, character between '<' and '>' are a single (string) token.  */
193   char parsing_include_directive;
194
195   /* If true, # introduces an assertion (see do_assert) */
196   char parsing_if_directive;
197
198   /* If true, # and ## are the STRINGIZE and TOKPASTE operators */
199   char parsing_define_directive;
200
201   /* True if escape sequences (as described for has_escapes in
202      parse_buffer) should be emitted.  */
203   char output_escapes;
204
205   /* 0: Have seen non-white-space on this line.
206      1: Only seen white space so far on this line.
207      2: Only seen white space so far in this file.  */
208   char only_seen_white;
209
210   long lineno;
211
212   struct tm *timebuf;
213
214   /* Buffer of -M output.  */
215   struct deps *deps;
216
217   /* A buffer and a table, used only by read_and_prescan (in cppfiles.c)
218      which are allocated once per cpp_reader object to keep them off the
219      stack and avoid setup costs.  */
220   unsigned char *input_buffer;
221   unsigned char *input_speccase;
222   size_t input_buffer_len;
223 };
224
225 #define CPP_FATAL_LIMIT 1000
226 /* True if we have seen a "fatal" error. */
227 #define CPP_FATAL_ERRORS(READER) ((READER)->errors >= CPP_FATAL_LIMIT)
228
229 /* Macros for manipulating the token_buffer. */
230
231 /* Number of characters currently in PFILE's output buffer. */
232 #define CPP_WRITTEN(PFILE) ((size_t)((PFILE)->limit - (PFILE)->token_buffer))
233 #define CPP_PWRITTEN(PFILE) ((PFILE)->limit)
234 #define CPP_ADJUST_WRITTEN(PFILE,DELTA) ((PFILE)->limit += (DELTA))
235 #define CPP_SET_WRITTEN(PFILE,N) ((PFILE)->limit = (PFILE)->token_buffer + (N))
236
237 /* Make sure PFILE->token_buffer has space for at least N more characters. */
238 #define CPP_RESERVE(PFILE, N) \
239   (CPP_WRITTEN (PFILE) + (size_t)(N) > (PFILE)->token_buffer_size \
240    && (cpp_grow_buffer (PFILE, N), 0))
241
242 #define CPP_OPTIONS(PFILE) ((PFILE)->opts)
243 #define CPP_BUFFER(PFILE) ((PFILE)->buffer)
244
245 /* Pointed to by cpp_reader.opts. */
246 struct cpp_options
247 {
248   const char *in_fname;
249
250   /* Name of output file, for error messages.  */
251   const char *out_fname;
252
253   struct file_name_map_list *map_list;
254
255   /* Non-0 means -v, so print the full set of include dirs.  */
256   char verbose;
257
258   /* Nonzero means use extra default include directories for C++.  */
259
260   char cplusplus;
261
262   /* Nonzero means handle cplusplus style comments */
263
264   char cplusplus_comments;
265
266   /* Nonzero means handle #import, for objective C.  */
267
268   char objc;
269
270   /* Nonzero means this is an assembly file, so ignore unrecognized
271      directives and the "# 33" form of #line, both of which are
272      probably comments.  Also, permit unbalanced ' strings (again,
273      likely to be in comments).  */
274
275   char lang_asm;
276
277   /* Nonzero means this is Fortran, and we don't know where the
278      comments are, so permit unbalanced ' strings.  Unlike lang_asm,
279      this does not ignore unrecognized directives.  */
280
281   char lang_fortran;
282
283   /* Nonzero means handle CHILL comment syntax
284      and output CHILL string delimiter for __DATE___ etc. */
285
286   char chill;
287
288   /* Nonzero means don't copy comments into the output file.  */
289
290   char discard_comments;
291
292   /* Nonzero means process the ANSI trigraph sequences.  */
293
294   char trigraphs;
295
296   /* Nonzero means print the names of included files rather than
297      the preprocessed output.  1 means just the #include "...",
298      2 means #include <...> as well.  */
299
300   char print_deps;
301
302   /* Nonzero if missing .h files in -M output are assumed to be generated
303      files and not errors.  */
304
305   char print_deps_missing_files;
306
307   /* If true, fopen (deps_file, "a") else fopen (deps_file, "w"). */
308   char print_deps_append;
309
310   /* Nonzero means print names of header files (-H).  */
311
312   char print_include_names;
313
314   /* Nonzero means try to make failure to fit ANSI C an error.  */
315
316   char pedantic_errors;
317
318   /* Nonzero means don't print warning messages.  */
319
320   char inhibit_warnings;
321
322   /* Nonzero means don't print error messages.  Has no option to select it,
323      but can be set by a user of cpplib (e.g. fix-header).  */
324
325   char inhibit_errors;
326
327   /* Nonzero means warn if slash-star appears in a comment.  */
328
329   char warn_comments;
330
331   /* Nonzero means warn if there are any trigraphs.  */
332
333   char warn_trigraphs;
334
335   /* Nonzero means warn if #import is used.  */
336
337   char warn_import;
338
339   /* Nonzero means warn if a macro argument is (or would be)
340      stringified with -traditional.  */
341
342   char warn_stringify;
343
344   /* Nonzero means turn warnings into errors.  */
345
346   char warnings_are_errors;
347
348   /* Nonzero causes output not to be done,
349      but directives such as #define that have side effects
350      are still obeyed.  */
351
352   char no_output;
353
354   /* Nonzero means we should look for header.gcc files that remap file
355      names.  */
356   char remap;
357
358   /* Nonzero means don't output line number information.  */
359   char no_line_commands;
360
361   /* Nonzero means -I- has been seen,
362      so don't look for #include "foo" the source-file directory.  */
363   char ignore_srcdir;
364
365   /* Zero means dollar signs are punctuation.
366      This used to be needed for conformance to the C Standard,
367      before the C Standard was corrected.  */
368   char dollars_in_ident;
369
370   /* Nonzero means try to imitate old fashioned non-ANSI preprocessor.  */
371   char traditional;
372
373   /* Nonzero means warn if undefined identifiers are evaluated in an #if.  */
374   char warn_undef;
375
376   /* Nonzero for the 1989 C Standard, including corrigenda and amendments.  */
377   char c89;
378
379   /* Nonzero for the 1999 C Standard, including corrigenda and amendments.  */
380   char c99;
381
382   /* Nonzero means give all the error messages the ANSI standard requires.  */
383   char pedantic;
384
385   /* Nonzero means we're looking at already preprocessed code, so don't
386      bother trying to do macro expansion and whatnot.  */
387   char preprocessed;
388
389   char done_initializing;
390
391   /* Search paths for include files.  */
392   struct file_name_list *quote_include;  /* First dir to search for "file" */
393   struct file_name_list *bracket_include;/* First dir to search for <file> */
394
395   /* Directory prefix that should replace `/usr/lib/gcc-lib/TARGET/VERSION'
396      in the standard include file directories.  */
397   const char *include_prefix;
398   int include_prefix_len;
399
400   char no_standard_includes;
401   char no_standard_cplusplus_includes;
402
403 /* dump_only means inhibit output of the preprocessed text
404              and instead output the definitions of all user-defined
405              macros in a form suitable for use as input to cccp.
406    dump_names means pass #define and the macro name through to output.
407    dump_definitions means pass the whole definition (plus #define) through
408 */
409
410   enum {dump_none = 0, dump_only, dump_names, dump_definitions}
411      dump_macros;
412
413 /* Nonzero means pass all #define and #undef directives which we actually
414    process through to the output stream.  This feature is used primarily
415    to allow cc1 to record the #defines and #undefs for the sake of
416    debuggers which understand about preprocessor macros, but it may
417    also be useful with -E to figure out how symbols are defined, and
418    where they are defined.  */
419   int debug_output;
420
421   /* Nonzero means pass #include lines through to the output,
422      even if they are ifdefed out.  */
423   int dump_includes;
424
425   /* Pending options - -D, -U, -A, -I, -ixxx. */
426   struct cpp_pending *pending;
427
428   /* File name which deps are being written to.
429      This is 0 if deps are being written to stdout.  */
430   const char *deps_file;
431
432   /* Target-name to write with the dependency information.  */
433   char *deps_target;
434 };
435
436 /* Name under which this program was invoked.  */
437 extern const char *progname;
438
439 extern int cpp_handle_options PARAMS ((cpp_reader *, int, char **));
440 extern enum cpp_token cpp_get_token PARAMS ((cpp_reader *));
441 extern enum cpp_token cpp_get_non_space_token PARAMS ((cpp_reader *));
442 extern enum cpp_token get_directive_token PARAMS ((cpp_reader *));
443
444 extern void cpp_reader_init PARAMS ((cpp_reader *));
445 extern void cpp_options_init PARAMS ((cpp_options *));
446 extern int cpp_start_read PARAMS ((cpp_reader *, const char *));
447 extern void cpp_finish PARAMS ((cpp_reader *));
448 extern void cpp_cleanup PARAMS ((cpp_reader *PFILE));
449
450 extern void cpp_buf_line_and_col PARAMS((cpp_buffer *, long *, long *));
451 extern cpp_buffer *cpp_file_buffer PARAMS((cpp_reader *));
452 extern void cpp_define PARAMS ((cpp_reader *, const char *));
453 extern void cpp_assert PARAMS ((cpp_reader *, const char *));
454 extern void cpp_undef  PARAMS ((cpp_reader *, const char *));
455 extern void cpp_unassert PARAMS ((cpp_reader *, const char *));
456
457 /* N.B. The error-message-printer prototypes have not been nicely
458    formatted because exgettext needs to see 'msgid' on the same line
459    as the name of the function in order to work properly.  Only the
460    string argument gets a name in an effort to keep the lines from
461    getting ridiculously oversized.  */
462
463 extern void cpp_ice PARAMS ((cpp_reader *, const char *msgid, ...))
464   ATTRIBUTE_PRINTF_2;
465 extern void cpp_fatal PARAMS ((cpp_reader *, const char *msgid, ...))
466   ATTRIBUTE_PRINTF_2;
467 extern void cpp_error PARAMS ((cpp_reader *, const char *msgid, ...))
468   ATTRIBUTE_PRINTF_2;
469 extern void cpp_warning PARAMS ((cpp_reader *, const char *msgid, ...))
470   ATTRIBUTE_PRINTF_2;
471 extern void cpp_pedwarn PARAMS ((cpp_reader *, const char *msgid, ...))
472   ATTRIBUTE_PRINTF_2;
473 extern void cpp_notice PARAMS ((cpp_reader *, const char *msgid, ...))
474   ATTRIBUTE_PRINTF_2;
475 extern void cpp_error_with_line PARAMS ((cpp_reader *, int, int, const char *msgid, ...))
476   ATTRIBUTE_PRINTF_4;
477 extern void cpp_warning_with_line PARAMS ((cpp_reader *, int, int, const char *msgid, ...))
478   ATTRIBUTE_PRINTF_4;
479 extern void cpp_pedwarn_with_line PARAMS ((cpp_reader *, int, int, const char *msgid, ...))
480   ATTRIBUTE_PRINTF_4;
481 extern void cpp_pedwarn_with_file_and_line PARAMS ((cpp_reader *, const char *, int, int, const char *msgid, ...))
482   ATTRIBUTE_PRINTF_5;
483 extern void cpp_error_from_errno PARAMS ((cpp_reader *, const char *));
484 extern void cpp_notice_from_errno PARAMS ((cpp_reader *, const char *));
485
486 extern void cpp_grow_buffer PARAMS ((cpp_reader *, long));
487 extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
488                                             const unsigned char *, long));
489 extern cpp_buffer *cpp_pop_buffer PARAMS ((cpp_reader *));
490 extern int cpp_defined PARAMS ((cpp_reader *, const unsigned char *, int));
491
492 extern void quote_string                PARAMS ((cpp_reader *, const char *));
493 extern void cpp_expand_to_buffer        PARAMS ((cpp_reader *,
494                                                  const unsigned char *, int));
495 extern void cpp_scan_buffer             PARAMS ((cpp_reader *));
496
497 /* Last arg to output_line_command.  */
498 enum file_change_code {same_file, rename_file, enter_file, leave_file};
499 extern void output_line_command         PARAMS ((cpp_reader *,
500                                                  enum file_change_code));
501
502 /* In cppfiles.c */
503 extern int cpp_included                 PARAMS ((cpp_reader *, const char *));
504 extern int cpp_read_file                PARAMS ((cpp_reader *, const char *));
505
506
507 #ifdef __cplusplus
508 }
509 #endif
510 #endif /* __GCC_CPPLIB__ */