OSDN Git Service

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