OSDN Git Service

ch:
[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 /* For complex reasons, cpp_reader is also typedefed in c-pragma.h.  */
32 #ifndef _C_PRAGMA_H
33 typedef struct cpp_reader cpp_reader;
34 #endif
35 typedef struct cpp_buffer cpp_buffer;
36 typedef struct cpp_options cpp_options;
37 typedef struct cpp_printer cpp_printer;
38 typedef struct cpp_token cpp_token;
39 typedef struct cpp_toklist cpp_toklist;
40 typedef struct cpp_string cpp_string;
41 typedef struct cpp_hashnode cpp_hashnode;
42
43 /* The first two groups, apart from '=', can appear in preprocessor
44    expressions.  This allows a lookup table to be implemented in
45    _cpp_parse_expr.
46
47    The first group, to CPP_LAST_EQ, can be immediately followed by an
48    '='.  The lexer needs operators ending in '=', like ">>=", to be in
49    the same order as their counterparts without the '=', like ">>".  */
50
51 /* Positions in the table.  */
52 #define CPP_LAST_EQ CPP_MAX
53 #define CPP_FIRST_DIGRAPH CPP_HASH
54 #define CPP_LAST_PUNCTUATOR CPP_DOT_STAR
55
56 #define TTYPE_TABLE                             \
57   OP(CPP_EQ = 0,        "=")                    \
58   OP(CPP_NOT,           "!")                    \
59   OP(CPP_GREATER,       ">")    /* compare */   \
60   OP(CPP_LESS,          "<")                    \
61   OP(CPP_PLUS,          "+")    /* math */      \
62   OP(CPP_MINUS,         "-")                    \
63   OP(CPP_MULT,          "*")                    \
64   OP(CPP_DIV,           "/")                    \
65   OP(CPP_MOD,           "%")                    \
66   OP(CPP_AND,           "&")    /* bit ops */   \
67   OP(CPP_OR,            "|")                    \
68   OP(CPP_XOR,           "^")                    \
69   OP(CPP_RSHIFT,        ">>")                   \
70   OP(CPP_LSHIFT,        "<<")                   \
71   OP(CPP_MIN,           "<?")   /* extension */ \
72   OP(CPP_MAX,           ">?")                   \
73 \
74   OP(CPP_COMPL,         "~")                    \
75   OP(CPP_AND_AND,       "&&")   /* logical */   \
76   OP(CPP_OR_OR,         "||")                   \
77   OP(CPP_QUERY,         "?")                    \
78   OP(CPP_COLON,         ":")                    \
79   OP(CPP_COMMA,         ",")    /* grouping */  \
80   OP(CPP_OPEN_PAREN,    "(")                    \
81   OP(CPP_CLOSE_PAREN,   ")")                    \
82   OP(CPP_EQ_EQ,         "==")   /* compare */   \
83   OP(CPP_NOT_EQ,        "!=")                   \
84   OP(CPP_GREATER_EQ,    ">=")                   \
85   OP(CPP_LESS_EQ,       "<=")                   \
86 \
87   OP(CPP_PLUS_EQ,       "+=")   /* math */      \
88   OP(CPP_MINUS_EQ,      "-=")                   \
89   OP(CPP_MULT_EQ,       "*=")                   \
90   OP(CPP_DIV_EQ,        "/=")                   \
91   OP(CPP_MOD_EQ,        "%=")                   \
92   OP(CPP_AND_EQ,        "&=")   /* bit ops */   \
93   OP(CPP_OR_EQ,         "|=")                   \
94   OP(CPP_XOR_EQ,        "^=")                   \
95   OP(CPP_RSHIFT_EQ,     ">>=")                  \
96   OP(CPP_LSHIFT_EQ,     "<<=")                  \
97   OP(CPP_MIN_EQ,        "<?=")  /* extension */ \
98   OP(CPP_MAX_EQ,        ">?=")                  \
99   /* Digraphs together, beginning with CPP_FIRST_DIGRAPH.  */   \
100   OP(CPP_HASH,          "#")    /* digraphs */  \
101   OP(CPP_PASTE,         "##")                   \
102   OP(CPP_OPEN_SQUARE,   "[")                    \
103   OP(CPP_CLOSE_SQUARE,  "]")                    \
104   OP(CPP_OPEN_BRACE,    "{")                    \
105   OP(CPP_CLOSE_BRACE,   "}")                    \
106   /* The remainder of the punctuation.  Order is not significant.  */   \
107   OP(CPP_SEMICOLON,     ";")    /* structure */ \
108   OP(CPP_ELLIPSIS,      "...")                  \
109   OP(CPP_BACKSLASH,     "\\")                   \
110   OP(CPP_PLUS_PLUS,     "++")   /* increment */ \
111   OP(CPP_MINUS_MINUS,   "--")                   \
112   OP(CPP_DEREF,         "->")   /* accessors */ \
113   OP(CPP_DOT,           ".")                    \
114   OP(CPP_SCOPE,         "::")                   \
115   OP(CPP_DEREF_STAR,    "->*")                  \
116   OP(CPP_DOT_STAR,      ".*")                   \
117   OP(CPP_DEFINED,       "defined") /* #if */    \
118 \
119   TK(CPP_NAME,          SPELL_IDENT)    /* word */                      \
120   TK(CPP_INT,           SPELL_STRING)   /* 23 */                        \
121   TK(CPP_FLOAT,         SPELL_STRING)   /* 3.14159 */                   \
122   TK(CPP_NUMBER,        SPELL_STRING)   /* 34_be+ta  */                 \
123 \
124   TK(CPP_CHAR,          SPELL_STRING)   /* 'char' */                    \
125   TK(CPP_WCHAR,         SPELL_STRING)   /* L'char' */                   \
126   TK(CPP_OTHER,         SPELL_CHAR)     /* stray punctuation */         \
127 \
128   TK(CPP_STRING,        SPELL_STRING)   /* "string" */                  \
129   TK(CPP_WSTRING,       SPELL_STRING)   /* L"string" */                 \
130   TK(CPP_OSTRING,       SPELL_STRING)   /* @"string" - Objective C */   \
131   TK(CPP_HEADER_NAME,   SPELL_STRING)   /* <stdio.h> in #include */     \
132 \
133   TK(CPP_COMMENT,       SPELL_STRING)   /* Only if output comments.  */ \
134   TK(CPP_MACRO_ARG,     SPELL_NONE)     /* Macro argument.  */          \
135   TK(CPP_PLACEMARKER,   SPELL_NONE)     /* Placemarker token.  */       \
136   TK(CPP_EOF,           SPELL_NONE)     /* End of file.  */
137
138 #define OP(e, s) e,
139 #define TK(e, s) e,
140 enum cpp_ttype
141 {
142   TTYPE_TABLE
143   N_TTYPES
144 };
145 #undef OP
146 #undef TK
147
148 /* Payload of a NUMBER, FLOAT, STRING, or COMMENT token.  */
149 struct cpp_string
150 {
151   unsigned int len;
152   const unsigned char *text;
153 };
154
155 /* Flags for the cpp_token structure.  */
156 #define PREV_WHITE      (1 << 0) /* If whitespace before this token.  */
157 #define BOL             (1 << 1) /* Beginning of logical line.  */
158 #define DIGRAPH         (1 << 2) /* If it was a digraph.  */
159 #define STRINGIFY_ARG   (1 << 3) /* If macro argument to be stringified.  */
160 #define PASTE_LEFT      (1 << 4) /* If on LHS of a ## operator.  */
161 #define PASTED          (1 << 5) /* The result of a ## operator.  */
162 #define NAMED_OP        (1 << 6) /* C++ named operators, also "defined".  */
163
164 /* A preprocessing token.  This has been carefully packed and should
165    occupy 16 bytes on 32-bit hosts and 24 bytes on 64-bit hosts.  */
166 struct cpp_token
167 {
168   unsigned int line;            /* starting line number of this token */
169   unsigned short col;           /* starting column of this token */
170   ENUM_BITFIELD(cpp_ttype) type : CHAR_BIT;  /* token type */
171   unsigned char flags;          /* flags - see above */
172
173   union
174   {
175     HOST_WIDEST_INT integer;    /* an integer */
176     struct cpp_hashnode *node;  /* an identifier */
177     struct cpp_string str;      /* a string, or number */
178     unsigned int aux;           /* argument no. for a CPP_MACRO_ARG, or
179                                    character represented by CPP_OTHER.  */
180   } val;
181 };
182
183 /* cpp_toklist flags.  */
184 #define VAR_ARGS        (1 << 0)
185 #define BEG_OF_FILE     (1 << 1)
186
187 struct directive;               /* These are deliberately incomplete.  */
188 struct answer;
189 struct macro_args;
190 struct cpp_context;
191
192 struct cpp_toklist
193 {
194   cpp_token *tokens;            /* actual tokens as an array */
195   unsigned int tokens_used;     /* tokens used */
196   unsigned int tokens_cap;      /* tokens allocated */
197
198   unsigned char *namebuf;       /* names buffer */
199   unsigned int name_used;       /* _bytes_ used */
200   unsigned int name_cap;        /* _bytes_ allocated */
201
202   /* If the list represents a directive, this points to it.  */
203   const struct directive *directive;
204
205   const char *file;             /* in file name */
206   unsigned int line;            /* starting line number */
207
208   unsigned short params_len;    /* length of macro parameter names.  */
209
210   short int paramc;             /* no. of macro params (-1 = obj-like).  */
211
212   /* Per-list flags, see above */
213   unsigned short flags;
214 };
215
216 /* A standalone character.  We may want to make it unsigned for the
217    same reason we use unsigned char - to avoid signedness issues.  */
218 typedef int cppchar_t;
219
220 struct cpp_buffer
221 {
222   const unsigned char *cur;      /* current position */
223   const unsigned char *rlimit; /* end of valid data */
224   const unsigned char *line_base; /* start of current line */
225   cppchar_t read_ahead;         /* read ahead character */
226   cppchar_t extra_char;         /* extra read-ahead for long tokens.  */
227
228   struct cpp_reader *pfile;     /* Owns this buffer.  */
229   struct cpp_buffer *prev;
230
231   const unsigned char *buf;      /* entire buffer */
232
233   /* Filename specified with #line command.  */
234   const char *nominal_fname;
235
236   /* Actual directory of this file, used only for "" includes */
237   struct file_name_list *actual_dir;
238
239   /* Pointer into the include table.  Used for include_next and
240      to record control macros. */
241   struct include_file *inc;
242
243   /* Value of if_stack at start of this file.
244      Used to prohibit unmatched #endif (etc) in an include file.  */
245   struct if_stack *if_stack;
246
247   /* Token column position adjustment owing to tabs in whitespace.  */
248   unsigned int col_adjust;
249
250   /* Line number at line_base (above). */
251   unsigned int lineno;
252
253   /* True if we have already warned about C++ comments in this file.
254      The warning happens only for C89 extended mode with -pedantic on,
255      or for -Wtraditional, and only once per file (otherwise it would
256      be far too noisy).  */
257   char warned_cplusplus_comments;
258 };
259
260 struct file_name_map_list;
261 struct htab;
262
263 /* Maximum nesting of cpp_buffers.  We use a static limit, partly for
264    efficiency, and partly to limit runaway recursion.  */
265 #define CPP_STACK_MAX 200
266
267 /* Values for opts.dump_macros.
268   dump_only means inhibit output of the preprocessed text
269              and instead output the definitions of all user-defined
270              macros in a form suitable for use as input to cpp.
271    dump_names means pass #define and the macro name through to output.
272    dump_definitions means pass the whole definition (plus #define) through
273 */
274 enum { dump_none = 0, dump_only, dump_names, dump_definitions };
275
276 /* This structure is nested inside struct cpp_reader, and
277    carries all the options visible to the command line.  */
278 struct cpp_options
279 {
280   /* Name of input and output files.  */
281   const char *in_fname;
282   const char *out_fname;
283
284   /* Characters between tab stops.  */
285   unsigned int tabstop;
286
287   /* Pending options - -D, -U, -A, -I, -ixxx. */
288   struct cpp_pending *pending;
289
290   /* File name which deps are being written to.  This is 0 if deps are
291      being written to stdout.  */
292   const char *deps_file;
293
294   /* Target-name to write with the dependency information.  */
295   char *deps_target;
296
297   /* Search paths for include files.  */
298   struct file_name_list *quote_include;  /* First dir to search for "file" */
299   struct file_name_list *bracket_include;/* First dir to search for <file> */
300
301   /* Map between header names and file names, used only on DOS where
302      file names are limited in length.  */
303   struct file_name_map_list *map_list;
304
305   /* Directory prefix that should replace `/usr/lib/gcc-lib/TARGET/VERSION'
306      in the standard include file directories.  */
307   const char *include_prefix;
308   unsigned int include_prefix_len;
309
310   /* -fleading_underscore sets this to "_".  */
311   const char *user_label_prefix;
312
313   /* Non-0 means -v, so print the full set of include dirs.  */
314   unsigned char verbose;
315
316   /* Nonzero means use extra default include directories for C++.  */
317   unsigned char cplusplus;
318
319   /* Nonzero means handle cplusplus style comments */
320   unsigned char cplusplus_comments;
321
322   /* Nonzero means handle #import, for objective C.  */
323   unsigned char objc;
324
325   /* Nonzero means this is an assembly file, so ignore unrecognized
326      directives and the "# 33" form of #line, both of which are
327      probably comments.  Also, permit unbalanced ' strings (again,
328      likely to be in comments).  */
329   unsigned char lang_asm;
330
331   /* Nonzero means don't copy comments into the output file.  */
332   unsigned char discard_comments;
333
334   /* Nonzero means process the ISO trigraph sequences.  */
335   unsigned char trigraphs;
336
337   /* Nonzero means process the ISO digraph sequences.  */
338   unsigned char digraphs;
339
340   /* Nonzero means print the names of included files rather than the
341      preprocessed output.  1 means just the #include "...", 2 means
342      #include <...> as well.  */
343   unsigned char print_deps;
344
345   /* Nonzero if missing .h files in -M output are assumed to be
346      generated files and not errors.  */
347   unsigned char print_deps_missing_files;
348
349   /* If true, fopen (deps_file, "a") else fopen (deps_file, "w"). */
350   unsigned char print_deps_append;
351
352   /* Nonzero means print names of header files (-H).  */
353   unsigned char print_include_names;
354
355   /* Nonzero means cpp_pedwarn causes a hard error.  */
356   unsigned char pedantic_errors;
357
358   /* Nonzero means don't print warning messages.  */
359   unsigned char inhibit_warnings;
360
361   /* Nonzero means don't suppress warnings from system headers.  */
362   unsigned char warn_system_headers;
363
364   /* Nonzero means don't print error messages.  Has no option to
365      select it, but can be set by a user of cpplib (e.g. fix-header).  */
366   unsigned char inhibit_errors;
367
368   /* Nonzero means warn if slash-star appears in a comment.  */
369   unsigned char warn_comments;
370
371   /* Nonzero means warn if there are any trigraphs.  */
372   unsigned char warn_trigraphs;
373
374   /* Nonzero means warn if #import is used.  */
375   unsigned char warn_import;
376
377   /* Nonzero means warn about various incompatibilities with
378      traditional C.  */
379   unsigned char warn_traditional;
380
381   /* Nonzero means warn if ## is applied to two tokens that cannot be
382      pasted together.  */
383   unsigned char warn_paste;
384
385   /* Nonzero means turn warnings into errors.  */
386   unsigned char warnings_are_errors;
387
388   /* Nonzero causes output not to be done, but directives such as
389      #define that have side effects are still obeyed.  */
390   unsigned char no_output;
391
392   /* Nonzero means we should look for header.gcc files that remap file
393      names.  */
394   unsigned char remap;
395
396   /* Nonzero means don't output line number information.  */
397   unsigned char no_line_commands;
398
399   /* Nonzero means -I- has been seen, so don't look for #include "foo"
400      the source-file directory.  */
401   unsigned char ignore_srcdir;
402
403   /* Zero means dollar signs are punctuation. */
404   unsigned char dollars_in_ident;
405
406   /* Nonzero means warn if undefined identifiers are evaluated in an #if.  */
407   unsigned char warn_undef;
408
409   /* Nonzero for the 1989 C Standard, including corrigenda and amendments.  */
410   unsigned char c89;
411
412   /* Nonzero for the 1999 C Standard, including corrigenda and amendments.  */
413   unsigned char c99;
414
415   /* Nonzero means give all the error messages the ANSI standard requires.  */
416   unsigned char pedantic;
417
418   /* Nonzero means we're looking at already preprocessed code, so don't
419      bother trying to do macro expansion and whatnot.  */
420   unsigned char preprocessed;
421
422   /* Nonzero disables all the standard directories for headers.  */
423   unsigned char no_standard_includes;
424
425   /* Nonzero disables the C++-specific standard directories for headers.  */
426   unsigned char no_standard_cplusplus_includes;
427
428   /* Nonzero means dump macros in some fashion - see above.  */
429   unsigned char dump_macros;
430
431   /* Nonzero means pass all #define and #undef directives which we
432      actually process through to the output stream.  This feature is
433      used primarily to allow cc1 to record the #defines and #undefs
434      for the sake of debuggers which understand about preprocessor
435      macros, but it may also be useful with -E to figure out how
436      symbols are defined, and where they are defined.  */
437   unsigned char debug_output;
438
439   /* Nonzero means pass #include lines through to the output.  */
440   unsigned char dump_includes;
441
442   /* Print column number in error messages.  */
443   unsigned char show_column;
444 };
445
446 struct lexer_state
447 {
448   /* Nonzero if first token on line is CPP_HASH.  */
449   unsigned char in_directive;
450
451   /* Nonzero if the directive's # was not in the first column.  Used
452      by -Wtraditional.  */
453   unsigned char indented;
454
455   /* Nonzero if in a directive that takes angle-bracketed headers.  */
456   unsigned char angled_headers;
457
458   /* Nonzero to save comments.  Turned off if discard_comments, and in
459      all directives apart from #define.  */
460   unsigned char save_comments;
461
462   /* Nonzero to force the lexer to skip newlines.  */
463   unsigned char skip_newlines;
464
465   /* Nonzero if we're in the subroutine lex_line.  */
466   unsigned char in_lex_line;
467
468   /* Nonzero if we're mid-comment.  */
469   unsigned char lexing_comment;
470
471   /* Tells parse_number we saw a leading period.  */
472   unsigned char seen_dot;
473 };
474 #define IN_DIRECTIVE(pfile) (pfile->state.in_directive)
475 #define KNOWN_DIRECTIVE(list) (list->directive != 0)
476
477 /* A cpp_reader encapsulates the "state" of a pre-processor run.
478    Applying cpp_get_token repeatedly yields a stream of pre-processor
479    tokens.  Usually, there is only one cpp_reader object active. */
480
481 struct cpp_reader
482 {
483   /* Top of buffer stack.  */
484   cpp_buffer *buffer;
485
486   /* Lexer state.  */
487   struct lexer_state state;
488
489   /* Error counter for exit code */
490   unsigned int errors;
491
492   /* Line and column where a newline was first seen in a string
493      constant (multi-line strings).  */
494   unsigned int mls_line;
495   unsigned int mls_column;
496
497   /* Current depth in #include directives that use <...>.  */
498   unsigned int system_include_depth;
499
500   /* Current depth of buffer stack. */
501   unsigned int buffer_stack_depth;
502
503   /* Current depth in #include directives.  */
504   unsigned int include_depth;
505
506   /* Hash table of macros and assertions.  See cpphash.c */
507   struct htab *hashtab;
508
509   /* Tree of other included files.  See cppfiles.c */
510   struct splay_tree_s *all_include_files;
511
512   /* Chain of `actual directory' file_name_list entries,
513      for "" inclusion. */
514   struct file_name_list *actual_dirs;
515
516   /* Current maximum length of directory names in the search path
517      for include files.  (Altered as we get more of them.)  */
518   unsigned int max_include_len;
519
520   /* Potential controlling macro for the current buffer.  This is only
521      live between the #endif and the end of file, and there can only
522      be one at a time, so it is per-reader not per-buffer.  */
523   const cpp_hashnode *potential_control_macro;
524
525   /* Token list used to store logical lines with new lexer.  */
526   cpp_toklist token_list;
527
528   /* Temporary token store.  */
529   cpp_token **temp_tokens;
530   unsigned int temp_cap;
531   unsigned int temp_alloced;
532   unsigned int temp_used;
533
534   /* Date and time tokens.  Calculated together if either is requested.  */
535   cpp_token *date;
536   cpp_token *time;
537
538   /* The # of a the current directive. It may not be first in line if
539      we append, and finding it is tedious.  */
540   const cpp_token *first_directive_token;
541
542   /* Context stack.  Used for macro expansion and for determining
543      which macros are disabled.  */
544   unsigned int context_cap;
545   unsigned int cur_context;
546   unsigned int no_expand_level;
547   unsigned int paste_level;
548   struct cpp_context *contexts;
549
550   /* Current arguments when scanning arguments. Used for pointer
551      fix-up.  */
552   struct macro_args *args;
553
554   /* Buffer of -M output.  */
555   struct deps *deps;
556
557   /* Obstack holding all macro hash nodes.  This never shrinks.
558      See cpphash.c */
559   struct obstack *hash_ob;
560
561   /* Obstack holding buffer and conditional structures.  This is a
562      real stack.  See cpplib.c */
563   struct obstack *buffer_ob;
564
565   /* Pragma table - dynamic, because a library user can add to the
566      list of recognized pragmas.  */
567   struct pragma_entry *pragmas;
568
569   /* Call backs.  */
570   struct {
571     void (*enter_file) PARAMS ((cpp_reader *));
572     void (*leave_file) PARAMS ((cpp_reader *));
573     void (*rename_file) PARAMS ((cpp_reader *));
574     void (*include) PARAMS ((cpp_reader *, const unsigned char *,
575                              const unsigned char *, unsigned int, int));
576     void (*define) PARAMS ((cpp_reader *, cpp_hashnode *));
577     void (*undef) PARAMS ((cpp_reader *, cpp_hashnode *));
578     void (*poison) PARAMS ((cpp_reader *));
579     void (*ident) PARAMS ((cpp_reader *, const unsigned char *, unsigned int));
580     void (*def_pragma) PARAMS ((cpp_reader *));
581   } cb;
582
583   /* User visible options.  */
584   struct cpp_options opts;
585
586   /* Nonzero means we have printed (while error reporting) a list of
587      containing files that matches the current status.  */
588   unsigned char input_stack_listing_current;
589
590   /* We're printed a warning recommending against using #import.  */
591   unsigned char import_warning;
592
593   /* True after cpp_start_read completes.  Used to inhibit some
594      warnings while parsing the command line.  */
595   unsigned char done_initializing;
596
597   /* True if we are skipping a failed conditional group.  */
598   unsigned char skipping;
599
600   /* True if we need to save parameter spellings - only if -pedantic,
601      or we might need to write out definitions.  */
602   unsigned char save_parameter_spellings;
603
604   /* True if output_line_command needs to output a newline.  */
605   unsigned char need_newline;
606
607   /* Special nodes - identifiers with predefined significance to the
608      preprocessor.  */
609   struct spec_nodes *spec_nodes;
610 };
611
612 /* struct cpp_printer encapsulates state used to convert the stream of
613    tokens coming from cpp_get_token back into a text file.  Not
614    everyone wants to do that, hence we separate the function.  */
615
616 struct cpp_printer
617 {
618   FILE *outf;                   /* stream to write to */
619   const char *last_fname;       /* previous file name */
620   unsigned int lineno;          /* line currently being written */
621 };
622
623 #define CPP_FATAL_LIMIT 1000
624 /* True if we have seen a "fatal" error. */
625 #define CPP_FATAL_ERRORS(READER) ((READER)->errors >= CPP_FATAL_LIMIT)
626
627 #define CPP_OPTION(PFILE, OPTION) ((PFILE)->opts.OPTION)
628 #define CPP_BUFFER(PFILE) ((PFILE)->buffer)
629 #define CPP_BUF_LINE(BUF) ((BUF)->lineno)
630 #define CPP_BUF_COLUMN(BUF, CUR) ((CUR) - (BUF)->line_base + (BUF)->col_adjust)
631 #define CPP_BUF_COL(BUF) CPP_BUF_COLUMN(BUF, (BUF)->cur)
632
633 /* Name under which this program was invoked.  */
634 extern const char *progname;
635
636 /* The structure of a node in the hash table.  The hash table
637    has entries for all tokens defined by #define commands (type T_MACRO),
638    plus some special tokens like __LINE__ (these each have their own
639    type, and the appropriate code is run when that type of node is seen.
640    It does not contain control words like "#define", which are recognized
641    by a separate piece of code. */
642
643 /* different flavors of hash nodes */
644 enum node_type
645 {
646   T_VOID = 0,      /* no definition yet */
647   T_SPECLINE,      /* `__LINE__' */
648   T_DATE,          /* `__DATE__' */
649   T_FILE,          /* `__FILE__' */
650   T_BASE_FILE,     /* `__BASE_FILE__' */
651   T_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */
652   T_TIME,          /* `__TIME__' */
653   T_STDC,          /* `__STDC__' */
654   T_OPERATOR,      /* operator with a name; val.code is token type */
655   T_POISON,        /* poisoned identifier */
656   T_MACRO,         /* a macro, either object-like or function-like */
657   T_ASSERTION      /* predicate for #assert */
658 };
659
660 /* There is a slot in the hashnode for use by front ends when integrated
661    with cpplib.  It holds a tree (see tree.h) but we mustn't drag that
662    header into every user of cpplib.h.  cpplib does not do anything with
663    this slot except clear it when a new node is created.  */
664 union tree_node;
665
666 struct cpp_hashnode
667 {
668   unsigned int hash;                    /* cached hash value */
669   unsigned short length;                /* length of name */
670   ENUM_BITFIELD(node_type) type : 8;    /* node type */
671
672   union
673   {
674     const cpp_toklist *expansion;       /* a macro's replacement list.  */
675     struct answer *answers;             /* answers to an assertion.  */
676     enum cpp_ttype code;                /* code for a named operator.  */
677   } value;
678
679   union tree_node *fe_value;            /* front end value */
680
681   const unsigned char name[1];          /* name[length] */
682 };
683
684 extern void cpp_init PARAMS ((void));
685 extern int cpp_handle_options PARAMS ((cpp_reader *, int, char **));
686 extern int cpp_handle_option PARAMS ((cpp_reader *, int, char **));
687 extern void cpp_reader_init PARAMS ((cpp_reader *));
688 extern cpp_printer *cpp_printer_init PARAMS ((cpp_reader *, cpp_printer *));
689
690 extern void cpp_register_pragma PARAMS ((cpp_reader *,
691                                          const char *, const char *,
692                                          void (*) PARAMS ((cpp_reader *))));
693 extern void cpp_register_pragma_space PARAMS ((cpp_reader *, const char *));
694
695 extern int cpp_start_read PARAMS ((cpp_reader *, cpp_printer *, const char *));
696 extern void cpp_output_tokens PARAMS ((cpp_reader *, cpp_printer *,
697                                        unsigned int));
698 extern void cpp_finish PARAMS ((cpp_reader *, cpp_printer *));
699 extern void cpp_cleanup PARAMS ((cpp_reader *));
700
701 extern const cpp_token *cpp_get_token PARAMS ((cpp_reader *));
702
703 extern void cpp_define PARAMS ((cpp_reader *, const char *));
704 extern void cpp_assert PARAMS ((cpp_reader *, const char *));
705 extern void cpp_undef  PARAMS ((cpp_reader *, const char *));
706 extern void cpp_unassert PARAMS ((cpp_reader *, const char *));
707
708 extern void cpp_free_token_list PARAMS ((cpp_toklist *));
709 extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
710                                             const unsigned char *, long));
711 extern cpp_buffer *cpp_pop_buffer PARAMS ((cpp_reader *));
712 extern int cpp_defined PARAMS ((cpp_reader *, const unsigned char *, int));
713
714 /* N.B. The error-message-printer prototypes have not been nicely
715    formatted because exgettext needs to see 'msgid' on the same line
716    as the name of the function in order to work properly.  Only the
717    string argument gets a name in an effort to keep the lines from
718    getting ridiculously oversized.  */
719
720 extern void cpp_ice PARAMS ((cpp_reader *, const char *msgid, ...))
721   ATTRIBUTE_PRINTF_2;
722 extern void cpp_fatal PARAMS ((cpp_reader *, const char *msgid, ...))
723   ATTRIBUTE_PRINTF_2;
724 extern void cpp_error PARAMS ((cpp_reader *, const char *msgid, ...))
725   ATTRIBUTE_PRINTF_2;
726 extern void cpp_warning PARAMS ((cpp_reader *, const char *msgid, ...))
727   ATTRIBUTE_PRINTF_2;
728 extern void cpp_pedwarn PARAMS ((cpp_reader *, const char *msgid, ...))
729   ATTRIBUTE_PRINTF_2;
730 extern void cpp_notice PARAMS ((cpp_reader *, const char *msgid, ...))
731   ATTRIBUTE_PRINTF_2;
732 extern void cpp_error_with_line PARAMS ((cpp_reader *, int, int, const char *msgid, ...))
733   ATTRIBUTE_PRINTF_4;
734 extern void cpp_warning_with_line PARAMS ((cpp_reader *, int, int, const char *msgid, ...))
735   ATTRIBUTE_PRINTF_4;
736 extern void cpp_pedwarn_with_line PARAMS ((cpp_reader *, int, int, const char *msgid, ...))
737   ATTRIBUTE_PRINTF_4;
738 extern void cpp_pedwarn_with_file_and_line PARAMS ((cpp_reader *, const char *, int, int, const char *msgid, ...))
739   ATTRIBUTE_PRINTF_5;
740 extern void cpp_error_from_errno PARAMS ((cpp_reader *, const char *));
741 extern void cpp_notice_from_errno PARAMS ((cpp_reader *, const char *));
742
743 extern const char *cpp_type2name PARAMS ((enum cpp_ttype));
744
745 /* In cpplex.c */
746 extern cpp_buffer *cpp_push_buffer      PARAMS ((cpp_reader *,
747                                                  const unsigned char *, long));
748 extern cpp_buffer *cpp_pop_buffer       PARAMS ((cpp_reader *));
749 extern void cpp_scan_buffer             PARAMS ((cpp_reader *, cpp_printer *));
750 extern void cpp_scan_buffer_nooutput    PARAMS ((cpp_reader *));
751 extern int cpp_ideq                     PARAMS ((const cpp_token *,
752                                                  const char *));
753 extern void cpp_printf                  PARAMS ((cpp_reader *, cpp_printer *,
754                                                  const char *, ...));
755
756 extern void cpp_output_list             PARAMS ((cpp_reader *, FILE *,
757                                                  const cpp_toklist *,
758                                                  const cpp_token *));
759
760 /* In cpphash.c */
761 extern cpp_hashnode *cpp_lookup PARAMS ((cpp_reader *,
762                                          const unsigned char *, size_t));
763 extern void cpp_forall_identifiers PARAMS ((cpp_reader *,
764                                             int (*) PARAMS ((cpp_reader *,
765                                                              cpp_hashnode *))));
766 /* In cppmacro.c */
767 extern void cpp_dump_definition PARAMS ((cpp_reader *, FILE *,
768                                          const cpp_hashnode *));
769
770 /* In cppfiles.c */
771 extern int cpp_included PARAMS ((cpp_reader *, const char *));
772 extern int cpp_read_file PARAMS ((cpp_reader *, const char *));
773 extern void cpp_make_system_header PARAMS ((cpp_reader *, cpp_buffer *, int));
774 extern const char *cpp_syshdr_flags PARAMS ((cpp_reader *, cpp_buffer *));
775
776 #ifdef __cplusplus
777 }
778 #endif
779 #endif /* __GCC_CPPLIB__ */