* Makefile.in (LIBCPP_DEPS): New macro.
[official-gcc.git] / gcc / cpplib.h
bloba7dc4f7f2340a86c91113becc93b978debe6b64e
1 /* Definitions for CPP library.
2 Copyright (C) 1995, 96-99, 2000 Free Software Foundation, Inc.
3 Written by Per Bothner, 1994-95.
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.
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.
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.
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__
25 #include <sys/types.h>
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
31 typedef struct cpp_reader cpp_reader;
32 typedef struct cpp_buffer cpp_buffer;
33 typedef struct cpp_options cpp_options;
35 enum cpp_token
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. */
62 typedef int (*parse_cleanup_t) PARAMS((cpp_buffer *, cpp_reader *));
64 struct cpp_buffer
66 unsigned char *cur; /* current position */
67 unsigned char *rlimit; /* end of valid data */
68 unsigned char *buf; /* entire buffer */
69 unsigned char *alimit; /* end of allocated buffer */
70 unsigned char *line_base; /* start of current line */
72 struct cpp_buffer *prev;
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;
81 /* Pointer into the include hash table. Used for include_next and
82 to record control macros. */
83 struct ihash *ihash;
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;
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;
95 /* True if this is a header file included using <FILENAME>. */
96 char system_header_p;
97 char seen_eof;
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.
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;
113 /* Used by the C++ frontend to implement redirected input (such as for
114 default argument and/or template parsing). */
115 char manual_pop;
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;
123 struct file_name_map_list;
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
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. */
133 struct cpp_reader
135 cpp_buffer *buffer;
136 cpp_options *opts;
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;
145 /* Error counter for exit code */
146 int errors;
148 /* Line where a newline was first seen in a string constant. */
149 int multiline_string_line;
151 /* Current depth in #include directives that use <...>. */
152 int system_include_depth;
154 /* Current depth of buffer stack. */
155 int buffer_stack_depth;
157 /* Hash table of macros and assertions. See cpphash.c */
158 #define HASHSIZE 1403
159 struct hashnode **hashtab;
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];
165 /* Chain of `actual directory' file_name_list entries,
166 for "" inclusion. */
167 struct file_name_list *actual_dirs;
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;
173 struct if_stack *if_stack;
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;
179 /* If non-zero, macros are not expanded. */
180 char no_macro_expand;
182 /* If non-zero, directives cause a hard error. Used when parsing
183 macro arguments. */
184 char no_directives;
186 /* Print column number in error messages. */
187 char show_column;
189 /* We're printed a warning recommending against using #import. */
190 char import_warning;
192 /* If true, character between '<' and '>' are a single (string) token. */
193 char parsing_include_directive;
195 /* If true, # introduces an assertion (see do_assert) */
196 char parsing_if_directive;
198 /* If true, # and ## are the STRINGIZE and TOKPASTE operators */
199 char parsing_define_directive;
201 /* True if escape sequences (as described for has_escapes in
202 parse_buffer) should be emitted. */
203 char output_escapes;
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;
210 long lineno;
212 struct tm *timebuf;
214 /* Buffer of -M output. */
215 struct deps *deps;
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;
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)
229 /* Macros for manipulating the token_buffer. */
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))
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))
242 #define CPP_OPTIONS(PFILE) ((PFILE)->opts)
243 #define CPP_BUFFER(PFILE) ((PFILE)->buffer)
245 /* Pointed to by cpp_reader.opts. */
246 struct cpp_options
248 char *in_fname;
250 /* Name of output file, for error messages. */
251 const char *out_fname;
253 struct file_name_map_list *map_list;
255 /* Non-0 means -v, so print the full set of include dirs. */
256 char verbose;
258 /* Nonzero means use extra default include directories for C++. */
260 char cplusplus;
262 /* Nonzero means handle cplusplus style comments */
264 char cplusplus_comments;
266 /* Nonzero means handle #import, for objective C. */
268 char objc;
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). */
275 char lang_asm;
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. */
281 char lang_fortran;
283 /* Nonzero means handle CHILL comment syntax
284 and output CHILL string delimiter for __DATE___ etc. */
286 char chill;
288 /* Nonzero means don't copy comments into the output file. */
290 char discard_comments;
292 /* Nonzero means process the ANSI trigraph sequences. */
294 char trigraphs;
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. */
300 char print_deps;
302 /* Nonzero if missing .h files in -M output are assumed to be generated
303 files and not errors. */
305 char print_deps_missing_files;
307 /* If true, fopen (deps_file, "a") else fopen (deps_file, "w"). */
308 char print_deps_append;
310 /* Nonzero means print names of header files (-H). */
312 char print_include_names;
314 /* Nonzero means try to make failure to fit ANSI C an error. */
316 char pedantic_errors;
318 /* Nonzero means don't print warning messages. */
320 char inhibit_warnings;
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). */
325 char inhibit_errors;
327 /* Nonzero means warn if slash-star appears in a comment. */
329 char warn_comments;
331 /* Nonzero means warn if there are any trigraphs. */
333 char warn_trigraphs;
335 /* Nonzero means warn if #import is used. */
337 char warn_import;
339 /* Nonzero means warn if a macro argument is (or would be)
340 stringified with -traditional. */
342 char warn_stringify;
344 /* Nonzero means turn warnings into errors. */
346 char warnings_are_errors;
348 /* Nonzero causes output not to be done,
349 but directives such as #define that have side effects
350 are still obeyed. */
352 char no_output;
354 /* Nonzero means we should look for header.gcc files that remap file
355 names. */
356 char remap;
358 /* Nonzero means don't output line number information. */
359 char no_line_commands;
361 /* Nonzero means -I- has been seen,
362 so don't look for #include "foo" the source-file directory. */
363 char ignore_srcdir;
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;
370 /* Nonzero means try to imitate old fashioned non-ANSI preprocessor. */
371 char traditional;
373 /* Nonzero means warn if undefined identifiers are evaluated in an #if. */
374 char warn_undef;
376 /* Nonzero for the 1989 C Standard, including corrigenda and amendments. */
377 char c89;
379 /* Nonzero for the 1999 C Standard, including corrigenda and amendments. */
380 char c99;
382 /* Nonzero means give all the error messages the ANSI standard requires. */
383 char pedantic;
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;
389 char done_initializing;
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> */
395 /* Directory prefix that should replace `/usr/lib/gcc-lib/TARGET/VERSION'
396 in the standard include file directories. */
397 char *include_prefix;
398 int include_prefix_len;
400 char no_standard_includes;
401 char no_standard_cplusplus_includes;
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
410 enum {dump_none = 0, dump_only, dump_names, dump_definitions}
411 dump_macros;
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;
421 /* Nonzero means pass #include lines through to the output,
422 even if they are ifdefed out. */
423 int dump_includes;
425 /* Pending options - -D, -U, -A, -I, -ixxx. */
426 struct cpp_pending *pending;
428 /* File name which deps are being written to.
429 This is 0 if deps are being written to stdout. */
430 char *deps_file;
432 /* Target-name to write with the dependency information. */
433 char *deps_target;
436 /* Name under which this program was invoked. */
437 extern const char *progname;
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 *));
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 *, char *));
447 extern void cpp_finish PARAMS ((cpp_reader *));
448 extern void cpp_cleanup PARAMS ((cpp_reader *PFILE));
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 *, unsigned char *));
453 extern void cpp_assert PARAMS ((cpp_reader *, unsigned char *));
454 extern void cpp_undef PARAMS ((cpp_reader *, unsigned char *));
455 extern void cpp_unassert PARAMS ((cpp_reader *, unsigned char *));
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. */
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 *));
486 extern void cpp_grow_buffer PARAMS ((cpp_reader *, long));
487 extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
488 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));
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 *));
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));
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 *));
507 #ifdef __cplusplus
509 #endif
510 #endif /* __GCC_CPPLIB__ */