xref: /netbsd-src/external/gpl3/gcc.old/dist/libcpp/internal.h (revision 946379e7b37692fc43f68eb0d1c10daa0a7f3b6c)
1 /* Part of CPP library.
2    Copyright (C) 1997-2013 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 3, 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; see the file COPYING3.  If not see
16 <http://www.gnu.org/licenses/>.  */
17 
18 /* This header defines all the internal data structures and functions
19    that need to be visible across files.  It should not be used outside
20    cpplib.  */
21 
22 #ifndef LIBCPP_INTERNAL_H
23 #define LIBCPP_INTERNAL_H
24 
25 #include "symtab.h"
26 #include "cpp-id-data.h"
27 
28 #if HAVE_ICONV
29 #include <iconv.h>
30 #else
31 #define HAVE_ICONV 0
32 typedef int iconv_t;  /* dummy */
33 #endif
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 struct directive;		/* Deliberately incomplete.  */
40 struct pending_option;
41 struct op;
42 struct _cpp_strbuf;
43 
44 typedef bool (*convert_f) (iconv_t, const unsigned char *, size_t,
45 			   struct _cpp_strbuf *);
46 struct cset_converter
47 {
48   convert_f func;
49   iconv_t cd;
50   int width;
51 };
52 
53 #define BITS_PER_CPPCHAR_T (CHAR_BIT * sizeof (cppchar_t))
54 
55 /* Test if a sign is valid within a preprocessing number.  */
56 #define VALID_SIGN(c, prevc) \
57   (((c) == '+' || (c) == '-') && \
58    ((prevc) == 'e' || (prevc) == 'E' \
59     || (((prevc) == 'p' || (prevc) == 'P') \
60         && CPP_OPTION (pfile, extended_numbers))))
61 
62 #define CPP_OPTION(PFILE, OPTION) ((PFILE)->opts.OPTION)
63 #define CPP_BUFFER(PFILE) ((PFILE)->buffer)
64 #define CPP_BUF_COLUMN(BUF, CUR) ((CUR) - (BUF)->line_base)
65 #define CPP_BUF_COL(BUF) CPP_BUF_COLUMN(BUF, (BUF)->cur)
66 
67 #define CPP_INCREMENT_LINE(PFILE, COLS_HINT) do { \
68     const struct line_maps *line_table = PFILE->line_table; \
69     const struct line_map *map = \
70       LINEMAPS_LAST_ORDINARY_MAP (line_table); \
71     linenum_type line = SOURCE_LINE (map, line_table->highest_line); \
72     linemap_line_start (PFILE->line_table, line + 1, COLS_HINT); \
73   } while (0)
74 
75 /* Maximum nesting of cpp_buffers.  We use a static limit, partly for
76    efficiency, and partly to limit runaway recursion.  */
77 #define CPP_STACK_MAX 200
78 
79 /* Host alignment handling.  */
80 struct dummy
81 {
82   char c;
83   union
84   {
85     double d;
86     int *p;
87   } u;
88 };
89 
90 #define DEFAULT_ALIGNMENT offsetof (struct dummy, u)
91 #define CPP_ALIGN2(size, align) (((size) + ((align) - 1)) & ~((align) - 1))
92 #define CPP_ALIGN(size) CPP_ALIGN2 (size, DEFAULT_ALIGNMENT)
93 
94 #define _cpp_mark_macro_used(NODE) do {					\
95   if ((NODE)->type == NT_MACRO && !((NODE)->flags & NODE_BUILTIN))	\
96     (NODE)->value.macro->used = 1; } while (0)
97 
98 /* A generic memory buffer, and operations on it.  */
99 typedef struct _cpp_buff _cpp_buff;
100 struct _cpp_buff
101 {
102   struct _cpp_buff *next;
103   unsigned char *base, *cur, *limit;
104 };
105 
106 extern _cpp_buff *_cpp_get_buff (cpp_reader *, size_t);
107 extern void _cpp_release_buff (cpp_reader *, _cpp_buff *);
108 extern void _cpp_extend_buff (cpp_reader *, _cpp_buff **, size_t);
109 extern _cpp_buff *_cpp_append_extend_buff (cpp_reader *, _cpp_buff *, size_t);
110 extern void _cpp_free_buff (_cpp_buff *);
111 extern unsigned char *_cpp_aligned_alloc (cpp_reader *, size_t);
112 extern unsigned char *_cpp_unaligned_alloc (cpp_reader *, size_t);
113 
114 #define BUFF_ROOM(BUFF) (size_t) ((BUFF)->limit - (BUFF)->cur)
115 #define BUFF_FRONT(BUFF) ((BUFF)->cur)
116 #define BUFF_LIMIT(BUFF) ((BUFF)->limit)
117 
118 /* #include types.  */
119 enum include_type {IT_INCLUDE, IT_INCLUDE_NEXT, IT_IMPORT, IT_CMDLINE, IT_DEFAULT};
120 
121 union utoken
122 {
123   const cpp_token *token;
124   const cpp_token **ptoken;
125 };
126 
127 /* A "run" of tokens; part of a chain of runs.  */
128 typedef struct tokenrun tokenrun;
129 struct tokenrun
130 {
131   tokenrun *next, *prev;
132   cpp_token *base, *limit;
133 };
134 
135 /* Accessor macros for struct cpp_context.  */
136 #define FIRST(c) ((c)->u.iso.first)
137 #define LAST(c) ((c)->u.iso.last)
138 #define CUR(c) ((c)->u.trad.cur)
139 #define RLIMIT(c) ((c)->u.trad.rlimit)
140 
141 /* This describes some additional data that is added to the macro
142    token context of type cpp_context, when -ftrack-macro-expansion is
143    on.  */
144 typedef struct
145 {
146   /* The node of the macro we are referring to.  */
147   cpp_hashnode *macro_node;
148   /* This buffer contains an array of virtual locations.  The virtual
149      location at index 0 is the virtual location of the token at index
150      0 in the current instance of cpp_context; similarly for all the
151      other virtual locations.  */
152   source_location *virt_locs;
153   /* This is a pointer to the current virtual location.  This is used
154      to iterate over the virtual locations while we iterate over the
155      tokens they belong to.  */
156   source_location *cur_virt_loc;
157 } macro_context;
158 
159 /* The kind of tokens carried by a cpp_context.  */
160 enum context_tokens_kind {
161   /* This is the value of cpp_context::tokens_kind if u.iso.first
162      contains an instance of cpp_token **.  */
163   TOKENS_KIND_INDIRECT,
164   /* This is the value of cpp_context::tokens_kind if u.iso.first
165      contains an instance of cpp_token *.  */
166   TOKENS_KIND_DIRECT,
167   /* This is the value of cpp_context::tokens_kind when the token
168      context contains tokens resulting from macro expansion.  In that
169      case struct cpp_context::macro points to an instance of struct
170      macro_context.  This is used only when the
171      -ftrack-macro-expansion flag is on.  */
172   TOKENS_KIND_EXTENDED
173 };
174 
175 typedef struct cpp_context cpp_context;
176 struct cpp_context
177 {
178   /* Doubly-linked list.  */
179   cpp_context *next, *prev;
180 
181   union
182   {
183     /* For ISO macro expansion.  Contexts other than the base context
184        are contiguous tokens.  e.g. macro expansions, expanded
185        argument tokens.  */
186     struct
187     {
188       union utoken first;
189       union utoken last;
190     } iso;
191 
192     /* For traditional macro expansion.  */
193     struct
194     {
195       const unsigned char *cur;
196       const unsigned char *rlimit;
197     } trad;
198   } u;
199 
200   /* If non-NULL, a buffer used for storage related to this context.
201      When the context is popped, the buffer is released.  */
202   _cpp_buff *buff;
203 
204   /* If tokens_kind is TOKEN_KIND_EXTENDED, then (as we thus are in a
205      macro context) this is a pointer to an instance of macro_context.
206      Otherwise if tokens_kind is *not* TOKEN_KIND_EXTENDED, then, if
207      we are in a macro context, this is a pointer to an instance of
208      cpp_hashnode, representing the name of the macro this context is
209      for.  If we are not in a macro context, then this is just NULL.
210      Note that when tokens_kind is TOKEN_KIND_EXTENDED, the memory
211      used by the instance of macro_context pointed to by this member
212      is de-allocated upon de-allocation of the instance of struct
213      cpp_context.  */
214   union
215   {
216     macro_context *mc;
217     cpp_hashnode *macro;
218   } c;
219 
220   /* This determines the type of tokens held by this context.  */
221   enum context_tokens_kind tokens_kind;
222 };
223 
224 struct lexer_state
225 {
226   /* Nonzero if first token on line is CPP_HASH.  */
227   unsigned char in_directive;
228 
229   /* Nonzero if we are collecting macro arguments */
230   unsigned char collecting_args;
231 
232   /* Nonzero if in a directive that will handle padding tokens itself.
233      #include needs this to avoid problems with computed include and
234      spacing between tokens.  */
235   unsigned char directive_wants_padding;
236 
237   /* True if we are skipping a failed conditional group.  */
238   unsigned char skipping;
239 
240   /* Nonzero if in a directive that takes angle-bracketed headers.  */
241   unsigned char angled_headers;
242 
243   /* Nonzero if in a #if or #elif directive.  */
244   unsigned char in_expression;
245 
246   /* Nonzero to save comments.  Turned off if discard_comments, and in
247      all directives apart from #define.  */
248   unsigned char save_comments;
249 
250   /* Nonzero if lexing __VA_ARGS__ is valid.  */
251   unsigned char va_args_ok;
252 
253   /* Nonzero if lexing poisoned identifiers is valid.  */
254   unsigned char poisoned_ok;
255 
256   /* Nonzero to prevent macro expansion.  */
257   unsigned char prevent_expansion;
258 
259   /* Nonzero when parsing arguments to a function-like macro.  */
260   unsigned char parsing_args;
261 
262   /* Nonzero if prevent_expansion is true only because output is
263      being discarded.  */
264   unsigned char discarding_output;
265 
266   /* Nonzero to skip evaluating part of an expression.  */
267   unsigned int skip_eval;
268 
269   /* Nonzero when handling a deferred pragma.  */
270   unsigned char in_deferred_pragma;
271 
272   /* Nonzero if the deferred pragma being handled allows macro expansion.  */
273   unsigned char pragma_allow_expansion;
274 };
275 
276 /* Special nodes - identifiers with predefined significance.  */
277 struct spec_nodes
278 {
279   cpp_hashnode *n_defined;		/* defined operator */
280   cpp_hashnode *n_true;			/* C++ keyword true */
281   cpp_hashnode *n_false;		/* C++ keyword false */
282   cpp_hashnode *n__VA_ARGS__;		/* C99 vararg macros */
283 };
284 
285 typedef struct _cpp_line_note _cpp_line_note;
286 struct _cpp_line_note
287 {
288   /* Location in the clean line the note refers to.  */
289   const unsigned char *pos;
290 
291   /* Type of note.  The 9 'from' trigraph characters represent those
292      trigraphs, '\\' an escaped newline, ' ' an escaped newline with
293      intervening space, 0 represents a note that has already been handled,
294      and anything else is invalid.  */
295   unsigned int type;
296 };
297 
298 /* Represents the contents of a file cpplib has read in.  */
299 struct cpp_buffer
300 {
301   const unsigned char *cur;        /* Current location.  */
302   const unsigned char *line_base;  /* Start of current physical line.  */
303   const unsigned char *next_line;  /* Start of to-be-cleaned logical line.  */
304 
305   const unsigned char *buf;        /* Entire character buffer.  */
306   const unsigned char *rlimit;     /* Writable byte at end of file.  */
307   const unsigned char *to_free;	   /* Pointer that should be freed when
308 				      popping the buffer.  */
309 
310   _cpp_line_note *notes;           /* Array of notes.  */
311   unsigned int cur_note;           /* Next note to process.  */
312   unsigned int notes_used;         /* Number of notes.  */
313   unsigned int notes_cap;          /* Size of allocated array.  */
314 
315   struct cpp_buffer *prev;
316 
317   /* Pointer into the file table; non-NULL if this is a file buffer.
318      Used for include_next and to record control macros.  */
319   struct _cpp_file *file;
320 
321   /* Saved value of __TIMESTAMP__ macro - date and time of last modification
322      of the assotiated file.  */
323   const unsigned char *timestamp;
324 
325   /* Value of if_stack at start of this file.
326      Used to prohibit unmatched #endif (etc) in an include file.  */
327   struct if_stack *if_stack;
328 
329   /* True if we need to get the next clean line.  */
330   bool need_line;
331 
332   /* True if we have already warned about C++ comments in this file.
333      The warning happens only for C89 extended mode with -pedantic on,
334      or for -Wtraditional, and only once per file (otherwise it would
335      be far too noisy).  */
336   unsigned int warned_cplusplus_comments : 1;
337 
338   /* True if we don't process trigraphs and escaped newlines.  True
339      for preprocessed input, command line directives, and _Pragma
340      buffers.  */
341   unsigned int from_stage3 : 1;
342 
343   /* At EOF, a buffer is automatically popped.  If RETURN_AT_EOF is
344      true, a CPP_EOF token is then returned.  Otherwise, the next
345      token from the enclosing buffer is returned.  */
346   unsigned int return_at_eof : 1;
347 
348   /* One for a system header, two for a C system header file that therefore
349      needs to be extern "C" protected in C++, and zero otherwise.  */
350   unsigned char sysp;
351 
352   /* The directory of the this buffer's file.  Its NAME member is not
353      allocated, so we don't need to worry about freeing it.  */
354   struct cpp_dir dir;
355 
356   /* Descriptor for converting from the input character set to the
357      source character set.  */
358   struct cset_converter input_cset_desc;
359 };
360 
361 /* The list of saved macros by push_macro pragma.  */
362 struct def_pragma_macro {
363   /* Chain element to previous saved macro.  */
364   struct def_pragma_macro *next;
365   /* Name of the macro.  */
366   char *name;
367   /* The stored macro content.  */
368   unsigned char *definition;
369 
370   /* Definition line number.  */
371   source_location line;
372   /* If macro defined in system header.  */
373   unsigned int syshdr   : 1;
374   /* Nonzero if it has been expanded or had its existence tested.  */
375   unsigned int used     : 1;
376 
377   /* Mark if we save an undefined macro.  */
378   unsigned int is_undef : 1;
379 };
380 
381 /* A cpp_reader encapsulates the "state" of a pre-processor run.
382    Applying cpp_get_token repeatedly yields a stream of pre-processor
383    tokens.  Usually, there is only one cpp_reader object active.  */
384 struct cpp_reader
385 {
386   /* Top of buffer stack.  */
387   cpp_buffer *buffer;
388 
389   /* Overlaid buffer (can be different after processing #include).  */
390   cpp_buffer *overlaid_buffer;
391 
392   /* Lexer state.  */
393   struct lexer_state state;
394 
395   /* Source line tracking.  */
396   struct line_maps *line_table;
397 
398   /* The line of the '#' of the current directive.  */
399   source_location directive_line;
400 
401   /* Memory buffers.  */
402   _cpp_buff *a_buff;		/* Aligned permanent storage.  */
403   _cpp_buff *u_buff;		/* Unaligned permanent storage.  */
404   _cpp_buff *free_buffs;	/* Free buffer chain.  */
405 
406   /* Context stack.  */
407   struct cpp_context base_context;
408   struct cpp_context *context;
409 
410   /* If in_directive, the directive if known.  */
411   const struct directive *directive;
412 
413   /* Token generated while handling a directive, if any. */
414   cpp_token directive_result;
415 
416   /* When expanding a macro at top-level, this is the location of the
417      macro invocation.  */
418   source_location invocation_location;
419 
420   /* Nonzero if we are about to expand a macro.  Note that if we are
421      really expanding a macro, the function macro_of_context returns
422      the macro being expanded and this flag is set to false.  Client
423      code should use the function in_macro_expansion_p to know if we
424      are either about to expand a macro, or are actually expanding
425      one.  */
426   bool about_to_expand_macro_p;
427 
428   /* Search paths for include files.  */
429   struct cpp_dir *quote_include;	/* "" */
430   struct cpp_dir *bracket_include;	/* <> */
431   struct cpp_dir no_search_path;	/* No path.  */
432 
433   /* Chain of all hashed _cpp_file instances.  */
434   struct _cpp_file *all_files;
435 
436   struct _cpp_file *main_file;
437 
438   /* File and directory hash table.  */
439   struct htab *file_hash;
440   struct htab *dir_hash;
441   struct file_hash_entry_pool *file_hash_entries;
442 
443   /* Negative path lookup hash table.  */
444   struct htab *nonexistent_file_hash;
445   struct obstack nonexistent_file_ob;
446 
447   /* Nonzero means don't look for #include "foo" the source-file
448      directory.  */
449   bool quote_ignores_source_dir;
450 
451   /* Nonzero if any file has contained #pragma once or #import has
452      been used.  */
453   bool seen_once_only;
454 
455   /* Multiple include optimization.  */
456   const cpp_hashnode *mi_cmacro;
457   const cpp_hashnode *mi_ind_cmacro;
458   bool mi_valid;
459 
460   /* Lexing.  */
461   cpp_token *cur_token;
462   tokenrun base_run, *cur_run;
463   unsigned int lookaheads;
464 
465   /* Nonzero prevents the lexer from re-using the token runs.  */
466   unsigned int keep_tokens;
467 
468   /* Buffer to hold macro definition string.  */
469   unsigned char *macro_buffer;
470   unsigned int macro_buffer_len;
471 
472   /* Descriptor for converting from the source character set to the
473      execution character set.  */
474   struct cset_converter narrow_cset_desc;
475 
476   /* Descriptor for converting from the source character set to the
477      UTF-8 execution character set.  */
478   struct cset_converter utf8_cset_desc;
479 
480   /* Descriptor for converting from the source character set to the
481      UTF-16 execution character set.  */
482   struct cset_converter char16_cset_desc;
483 
484   /* Descriptor for converting from the source character set to the
485      UTF-32 execution character set.  */
486   struct cset_converter char32_cset_desc;
487 
488   /* Descriptor for converting from the source character set to the
489      wide execution character set.  */
490   struct cset_converter wide_cset_desc;
491 
492   /* Date and time text.  Calculated together if either is requested.  */
493   const unsigned char *date;
494   const unsigned char *time;
495 
496   /* EOF token, and a token forcing paste avoidance.  */
497   cpp_token avoid_paste;
498   cpp_token eof;
499 
500   /* Opaque handle to the dependencies of mkdeps.c.  */
501   struct deps *deps;
502 
503   /* Obstack holding all macro hash nodes.  This never shrinks.
504      See identifiers.c */
505   struct obstack hash_ob;
506 
507   /* Obstack holding buffer and conditional structures.  This is a
508      real stack.  See directives.c.  */
509   struct obstack buffer_ob;
510 
511   /* Pragma table - dynamic, because a library user can add to the
512      list of recognized pragmas.  */
513   struct pragma_entry *pragmas;
514 
515   /* Call backs to cpplib client.  */
516   struct cpp_callbacks cb;
517 
518   /* Identifier hash table.  */
519   struct ht *hash_table;
520 
521   /* Expression parser stack.  */
522   struct op *op_stack, *op_limit;
523 
524   /* User visible options.  */
525   struct cpp_options opts;
526 
527   /* Special nodes - identifiers with predefined significance to the
528      preprocessor.  */
529   struct spec_nodes spec_nodes;
530 
531   /* Whether cpplib owns the hashtable.  */
532   bool our_hashtable;
533 
534   /* Traditional preprocessing output buffer (a logical line).  */
535   struct
536   {
537     unsigned char *base;
538     unsigned char *limit;
539     unsigned char *cur;
540     source_location first_line;
541   } out;
542 
543   /* Used for buffer overlays by traditional.c.  */
544   const unsigned char *saved_cur, *saved_rlimit, *saved_line_base;
545 
546   /* A saved list of the defined macros, for dependency checking
547      of precompiled headers.  */
548   struct cpp_savedstate *savedstate;
549 
550   /* Next value of __COUNTER__ macro. */
551   unsigned int counter;
552 
553   /* Table of comments, when state.save_comments is true.  */
554   cpp_comment_table comments;
555 
556   /* List of saved macros by push_macro.  */
557   struct def_pragma_macro *pushed_macros;
558 
559   /* If non-null, the lexer will use this location for the next token
560      instead of getting a location from the linemap.  */
561   source_location *forced_token_location_p;
562 };
563 
564 /* Character classes.  Based on the more primitive macros in safe-ctype.h.
565    If the definition of `numchar' looks odd to you, please look up the
566    definition of a pp-number in the C standard [section 6.4.8 of C99].
567 
568    In the unlikely event that characters other than \r and \n enter
569    the set is_vspace, the macro handle_newline() in lex.c must be
570    updated.  */
571 #define _dollar_ok(x)	((x) == '$' && CPP_OPTION (pfile, dollars_in_ident))
572 
573 #define is_idchar(x)	(ISIDNUM(x) || _dollar_ok(x))
574 #define is_numchar(x)	ISIDNUM(x)
575 #define is_idstart(x)	(ISIDST(x) || _dollar_ok(x))
576 #define is_numstart(x)	ISDIGIT(x)
577 #define is_hspace(x)	ISBLANK(x)
578 #define is_vspace(x)	IS_VSPACE(x)
579 #define is_nvspace(x)	IS_NVSPACE(x)
580 #define is_space(x)	IS_SPACE_OR_NUL(x)
581 
582 /* This table is constant if it can be initialized at compile time,
583    which is the case if cpp was compiled with GCC >=2.7, or another
584    compiler that supports C99.  */
585 #if HAVE_DESIGNATED_INITIALIZERS
586 extern const unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
587 #else
588 extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
589 #endif
590 
591 /* Macros.  */
592 
593 static inline int cpp_in_system_header (cpp_reader *);
594 static inline int
595 cpp_in_system_header (cpp_reader *pfile)
596 {
597   return pfile->buffer ? pfile->buffer->sysp : 0;
598 }
599 #define CPP_PEDANTIC(PF) CPP_OPTION (PF, cpp_pedantic)
600 #define CPP_WTRADITIONAL(PF) CPP_OPTION (PF, cpp_warn_traditional)
601 
602 static inline int cpp_in_primary_file (cpp_reader *);
603 static inline int
604 cpp_in_primary_file (cpp_reader *pfile)
605 {
606   return pfile->line_table->depth == 1;
607 }
608 
609 /* In macro.c */
610 extern void _cpp_free_definition (cpp_hashnode *);
611 extern bool _cpp_create_definition (cpp_reader *, cpp_hashnode *);
612 extern void _cpp_pop_context (cpp_reader *);
613 extern void _cpp_push_text_context (cpp_reader *, cpp_hashnode *,
614 				    const unsigned char *, size_t);
615 extern bool _cpp_save_parameter (cpp_reader *, cpp_macro *, cpp_hashnode *);
616 extern bool _cpp_arguments_ok (cpp_reader *, cpp_macro *, const cpp_hashnode *,
617 			       unsigned int);
618 extern const unsigned char *_cpp_builtin_macro_text (cpp_reader *,
619 						     cpp_hashnode *);
620 extern int _cpp_warn_if_unused_macro (cpp_reader *, cpp_hashnode *, void *);
621 extern void _cpp_push_token_context (cpp_reader *, cpp_hashnode *,
622 				     const cpp_token *, unsigned int);
623 extern void _cpp_backup_tokens_direct (cpp_reader *, unsigned int);
624 
625 /* In identifiers.c */
626 extern void _cpp_init_hashtable (cpp_reader *, cpp_hash_table *);
627 extern void _cpp_destroy_hashtable (cpp_reader *);
628 
629 /* In files.c */
630 typedef struct _cpp_file _cpp_file;
631 extern _cpp_file *_cpp_find_file (cpp_reader *, const char *, cpp_dir *,
632 				  bool, int, bool);
633 extern bool _cpp_find_failed (_cpp_file *);
634 extern void _cpp_mark_file_once_only (cpp_reader *, struct _cpp_file *);
635 extern void _cpp_fake_include (cpp_reader *, const char *);
636 extern bool _cpp_stack_file (cpp_reader *, _cpp_file*, bool);
637 extern bool _cpp_stack_include (cpp_reader *, const char *, int,
638 				enum include_type);
639 extern int _cpp_compare_file_date (cpp_reader *, const char *, int);
640 extern void _cpp_report_missing_guards (cpp_reader *);
641 extern void _cpp_init_files (cpp_reader *);
642 extern void _cpp_cleanup_files (cpp_reader *);
643 extern void _cpp_pop_file_buffer (cpp_reader *, struct _cpp_file *,
644 				  const unsigned char *);
645 extern bool _cpp_save_file_entries (cpp_reader *pfile, FILE *f);
646 extern bool _cpp_read_file_entries (cpp_reader *, FILE *);
647 extern const char *_cpp_get_file_name (_cpp_file *);
648 extern struct stat *_cpp_get_file_stat (_cpp_file *);
649 
650 /* In expr.c */
651 extern bool _cpp_parse_expr (cpp_reader *, bool);
652 extern struct op *_cpp_expand_op_stack (cpp_reader *);
653 
654 /* In lex.c */
655 extern void _cpp_process_line_notes (cpp_reader *, int);
656 extern void _cpp_clean_line (cpp_reader *);
657 extern bool _cpp_get_fresh_line (cpp_reader *);
658 extern bool _cpp_skip_block_comment (cpp_reader *);
659 extern cpp_token *_cpp_temp_token (cpp_reader *);
660 extern const cpp_token *_cpp_lex_token (cpp_reader *);
661 extern cpp_token *_cpp_lex_direct (cpp_reader *);
662 extern int _cpp_equiv_tokens (const cpp_token *, const cpp_token *);
663 extern void _cpp_init_tokenrun (tokenrun *, unsigned int);
664 extern cpp_hashnode *_cpp_lex_identifier (cpp_reader *, const char *);
665 extern int _cpp_remaining_tokens_num_in_context (cpp_context *);
666 extern void _cpp_init_lexer (void);
667 
668 /* In init.c.  */
669 extern void _cpp_maybe_push_include_file (cpp_reader *);
670 extern const char *cpp_named_operator2name (enum cpp_ttype type);
671 
672 /* In directives.c */
673 extern int _cpp_test_assertion (cpp_reader *, unsigned int *);
674 extern int _cpp_handle_directive (cpp_reader *, int);
675 extern void _cpp_define_builtin (cpp_reader *, const char *);
676 extern char ** _cpp_save_pragma_names (cpp_reader *);
677 extern void _cpp_restore_pragma_names (cpp_reader *, char **);
678 extern int _cpp_do__Pragma (cpp_reader *);
679 extern void _cpp_init_directives (cpp_reader *);
680 extern void _cpp_init_internal_pragmas (cpp_reader *);
681 extern void _cpp_do_file_change (cpp_reader *, enum lc_reason, const char *,
682 				 linenum_type, unsigned int);
683 extern void _cpp_pop_buffer (cpp_reader *);
684 
685 /* In directives.c */
686 struct _cpp_dir_only_callbacks
687 {
688   /* Called to print a block of lines. */
689   void (*print_lines) (int, const void *, size_t);
690   void (*maybe_print_line) (source_location);
691 };
692 
693 extern void _cpp_preprocess_dir_only (cpp_reader *,
694 				      const struct _cpp_dir_only_callbacks *);
695 
696 /* In traditional.c.  */
697 extern bool _cpp_scan_out_logical_line (cpp_reader *, cpp_macro *);
698 extern bool _cpp_read_logical_line_trad (cpp_reader *);
699 extern void _cpp_overlay_buffer (cpp_reader *pfile, const unsigned char *,
700 				 size_t);
701 extern void _cpp_remove_overlay (cpp_reader *);
702 extern bool _cpp_create_trad_definition (cpp_reader *, cpp_macro *);
703 extern bool _cpp_expansions_different_trad (const cpp_macro *,
704 					    const cpp_macro *);
705 extern unsigned char *_cpp_copy_replacement_text (const cpp_macro *,
706 						  unsigned char *);
707 extern size_t _cpp_replacement_text_len (const cpp_macro *);
708 
709 /* In charset.c.  */
710 
711 /* The normalization state at this point in the sequence.
712    It starts initialized to all zeros, and at the end
713    'level' is the normalization level of the sequence.  */
714 
715 struct normalize_state
716 {
717   /* The previous character.  */
718   cppchar_t previous;
719   /* The combining class of the previous character.  */
720   unsigned char prev_class;
721   /* The lowest normalization level so far.  */
722   enum cpp_normalize_level level;
723 };
724 #define INITIAL_NORMALIZE_STATE { 0, 0, normalized_KC }
725 #define NORMALIZE_STATE_RESULT(st) ((st)->level)
726 
727 /* We saw a character that matches ISIDNUM(), update a
728    normalize_state appropriately.  */
729 #define NORMALIZE_STATE_UPDATE_IDNUM(st) \
730   ((st)->previous = 0, (st)->prev_class = 0)
731 
732 extern cppchar_t _cpp_valid_ucn (cpp_reader *, const unsigned char **,
733 				 const unsigned char *, int,
734 				 struct normalize_state *state);
735 extern void _cpp_destroy_iconv (cpp_reader *);
736 extern unsigned char *_cpp_convert_input (cpp_reader *, const char *,
737 					  unsigned char *, size_t, size_t,
738 					  const unsigned char **, off_t *);
739 extern const char *_cpp_default_encoding (void);
740 extern cpp_hashnode * _cpp_interpret_identifier (cpp_reader *pfile,
741 						 const unsigned char *id,
742 						 size_t len);
743 
744 /* Utility routines and macros.  */
745 #define DSC(str) (const unsigned char *)str, sizeof str - 1
746 
747 /* These are inline functions instead of macros so we can get type
748    checking.  */
749 static inline int ustrcmp (const unsigned char *, const unsigned char *);
750 static inline int ustrncmp (const unsigned char *, const unsigned char *,
751 			    size_t);
752 static inline size_t ustrlen (const unsigned char *);
753 static inline const unsigned char *uxstrdup (const unsigned char *);
754 static inline const unsigned char *ustrchr (const unsigned char *, int);
755 static inline int ufputs (const unsigned char *, FILE *);
756 
757 /* Use a const char for the second parameter since it is usually a literal.  */
758 static inline int ustrcspn (const unsigned char *, const char *);
759 
760 static inline int
761 ustrcmp (const unsigned char *s1, const unsigned char *s2)
762 {
763   return strcmp ((const char *)s1, (const char *)s2);
764 }
765 
766 static inline int
767 ustrncmp (const unsigned char *s1, const unsigned char *s2, size_t n)
768 {
769   return strncmp ((const char *)s1, (const char *)s2, n);
770 }
771 
772 static inline int
773 ustrcspn (const unsigned char *s1, const char *s2)
774 {
775   return strcspn ((const char *)s1, s2);
776 }
777 
778 static inline size_t
779 ustrlen (const unsigned char *s1)
780 {
781   return strlen ((const char *)s1);
782 }
783 
784 static inline const unsigned char *
785 uxstrdup (const unsigned char *s1)
786 {
787   return (const unsigned char *) xstrdup ((const char *)s1);
788 }
789 
790 static inline const unsigned char *
791 ustrchr (const unsigned char *s1, int c)
792 {
793   return (const unsigned char *) strchr ((const char *)s1, c);
794 }
795 
796 static inline int
797 ufputs (const unsigned char *s, FILE *f)
798 {
799   return fputs ((const char *)s, f);
800 }
801 
802   /* In line-map.c.  */
803 
804 /* Create a macro map.  A macro map encodes source locations of tokens
805    that are part of a macro replacement-list, at a macro expansion
806    point. See the extensive comments of struct line_map and struct
807    line_map_macro, in line-map.h.
808 
809    This map shall be created when the macro is expanded. The map
810    encodes the source location of the expansion point of the macro as
811    well as the "original" source location of each token that is part
812    of the macro replacement-list. If a macro is defined but never
813    expanded, it has no macro map.  SET is the set of maps the macro
814    map should be part of.  MACRO_NODE is the macro which the new macro
815    map should encode source locations for.  EXPANSION is the location
816    of the expansion point of MACRO. For function-like macros
817    invocations, it's best to make it point to the closing parenthesis
818    of the macro, rather than the the location of the first character
819    of the macro.  NUM_TOKENS is the number of tokens that are part of
820    the replacement-list of MACRO.  */
821 const struct line_map *linemap_enter_macro (struct line_maps *,
822 					    struct cpp_hashnode*,
823 					    source_location,
824 					    unsigned int);
825 
826 /* Create and return a virtual location for a token that is part of a
827    macro expansion-list at a macro expansion point.  See the comment
828    inside struct line_map_macro to see what an expansion-list exactly
829    is.
830 
831    A call to this function must come after a call to
832    linemap_enter_macro.
833 
834    MAP is the map into which the source location is created.  TOKEN_NO
835    is the index of the token in the macro replacement-list, starting
836    at number 0.
837 
838    ORIG_LOC is the location of the token outside of this macro
839    expansion.  If the token comes originally from the macro
840    definition, it is the locus in the macro definition; otherwise it
841    is a location in the context of the caller of this macro expansion
842    (which is a virtual location or a source location if the caller is
843    itself a macro expansion or not).
844 
845    MACRO_DEFINITION_LOC is the location in the macro definition,
846    either of the token itself or of a macro parameter that it
847    replaces.  */
848 source_location linemap_add_macro_token (const struct line_map *,
849 					 unsigned int,
850 					 source_location,
851 					 source_location);
852 
853 /* Return the source line number corresponding to source location
854    LOCATION.  SET is the line map set LOCATION comes from.  If
855    LOCATION is the location of token that is part of the
856    expansion-list of a macro expansion return the line number of the
857    macro expansion point.  */
858 int linemap_get_expansion_line (struct line_maps *,
859 				source_location);
860 
861 /* Return the path of the file corresponding to source code location
862    LOCATION.
863 
864    If LOCATION is the location of a token that is part of the
865    replacement-list of a macro expansion return the file path of the
866    macro expansion point.
867 
868    SET is the line map set LOCATION comes from.  */
869 const char* linemap_get_expansion_filename (struct line_maps *,
870 					    source_location);
871 
872 #ifdef __cplusplus
873 }
874 #endif
875 
876 #endif /* ! LIBCPP_INTERNAL_H */
877