1169695Skan/* Part of CPP library.
2169695Skan   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3169695Skan   Free Software Foundation, Inc.
4169695Skan
5169695SkanThis program is free software; you can redistribute it and/or modify it
6169695Skanunder the terms of the GNU General Public License as published by the
7169695SkanFree Software Foundation; either version 2, or (at your option) any
8169695Skanlater version.
9169695Skan
10169695SkanThis program is distributed in the hope that it will be useful,
11169695Skanbut WITHOUT ANY WARRANTY; without even the implied warranty of
12169695SkanMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13169695SkanGNU General Public License for more details.
14169695Skan
15169695SkanYou should have received a copy of the GNU General Public License
16169695Skanalong with this program; if not, write to the Free Software
17169695SkanFoundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
18169695Skan
19169695Skan/* This header defines all the internal data structures and functions
20169695Skan   that need to be visible across files.  It should not be used outside
21169695Skan   cpplib.  */
22169695Skan
23169695Skan#ifndef LIBCPP_INTERNAL_H
24169695Skan#define LIBCPP_INTERNAL_H
25169695Skan
26169695Skan#include "symtab.h"
27169695Skan#include "cpp-id-data.h"
28169695Skan
29169695Skan#ifndef HAVE_ICONV_H
30169695Skan#undef HAVE_ICONV
31169695Skan#endif
32169695Skan
33169695Skan#if HAVE_ICONV
34169695Skan#include <iconv.h>
35169695Skan#else
36169695Skan#define HAVE_ICONV 0
37169695Skantypedef int iconv_t;  /* dummy */
38169695Skan#endif
39169695Skan
40169695Skanstruct directive;		/* Deliberately incomplete.  */
41169695Skanstruct pending_option;
42169695Skanstruct op;
43169695Skanstruct _cpp_strbuf;
44169695Skan
45169695Skantypedef bool (*convert_f) (iconv_t, const unsigned char *, size_t,
46169695Skan			   struct _cpp_strbuf *);
47169695Skanstruct cset_converter
48169695Skan{
49169695Skan  convert_f func;
50169695Skan  iconv_t cd;
51169695Skan};
52169695Skan
53169695Skan#define BITS_PER_CPPCHAR_T (CHAR_BIT * sizeof (cppchar_t))
54169695Skan
55169695Skan/* Test if a sign is valid within a preprocessing number.  */
56169695Skan#define VALID_SIGN(c, prevc) \
57169695Skan  (((c) == '+' || (c) == '-') && \
58169695Skan   ((prevc) == 'e' || (prevc) == 'E' \
59169695Skan    || (((prevc) == 'p' || (prevc) == 'P') \
60169695Skan        && CPP_OPTION (pfile, extended_numbers))))
61169695Skan
62169695Skan#define CPP_OPTION(PFILE, OPTION) ((PFILE)->opts.OPTION)
63169695Skan#define CPP_BUFFER(PFILE) ((PFILE)->buffer)
64169695Skan#define CPP_BUF_COLUMN(BUF, CUR) ((CUR) - (BUF)->line_base)
65169695Skan#define CPP_BUF_COL(BUF) CPP_BUF_COLUMN(BUF, (BUF)->cur)
66169695Skan
67169695Skan#define CPP_INCREMENT_LINE(PFILE, COLS_HINT) do { \
68169695Skan    const struct line_maps *line_table = PFILE->line_table; \
69169695Skan    const struct line_map *map = &line_table->maps[line_table->used-1]; \
70169695Skan    unsigned int line = SOURCE_LINE (map, line_table->highest_line); \
71169695Skan    linemap_line_start (PFILE->line_table, line + 1, COLS_HINT); \
72169695Skan  } while (0)
73169695Skan
74169695Skan/* Maximum nesting of cpp_buffers.  We use a static limit, partly for
75169695Skan   efficiency, and partly to limit runaway recursion.  */
76169695Skan#define CPP_STACK_MAX 200
77169695Skan
78169695Skan/* Host alignment handling.  */
79169695Skanstruct dummy
80169695Skan{
81169695Skan  char c;
82169695Skan  union
83169695Skan  {
84169695Skan    double d;
85169695Skan    int *p;
86169695Skan  } u;
87169695Skan};
88169695Skan
89169695Skan#define DEFAULT_ALIGNMENT offsetof (struct dummy, u)
90169695Skan#define CPP_ALIGN2(size, align) (((size) + ((align) - 1)) & ~((align) - 1))
91169695Skan#define CPP_ALIGN(size) CPP_ALIGN2 (size, DEFAULT_ALIGNMENT)
92169695Skan
93169695Skan#define _cpp_mark_macro_used(NODE) do {					\
94169695Skan  if ((NODE)->type == NT_MACRO && !((NODE)->flags & NODE_BUILTIN))	\
95169695Skan    (NODE)->value.macro->used = 1; } while (0)
96169695Skan
97169695Skan/* A generic memory buffer, and operations on it.  */
98169695Skantypedef struct _cpp_buff _cpp_buff;
99169695Skanstruct _cpp_buff
100169695Skan{
101169695Skan  struct _cpp_buff *next;
102169695Skan  unsigned char *base, *cur, *limit;
103169695Skan};
104169695Skan
105169695Skanextern _cpp_buff *_cpp_get_buff (cpp_reader *, size_t);
106169695Skanextern void _cpp_release_buff (cpp_reader *, _cpp_buff *);
107169695Skanextern void _cpp_extend_buff (cpp_reader *, _cpp_buff **, size_t);
108169695Skanextern _cpp_buff *_cpp_append_extend_buff (cpp_reader *, _cpp_buff *, size_t);
109169695Skanextern void _cpp_free_buff (_cpp_buff *);
110169695Skanextern unsigned char *_cpp_aligned_alloc (cpp_reader *, size_t);
111169695Skanextern unsigned char *_cpp_unaligned_alloc (cpp_reader *, size_t);
112169695Skan
113169695Skan#define BUFF_ROOM(BUFF) (size_t) ((BUFF)->limit - (BUFF)->cur)
114169695Skan#define BUFF_FRONT(BUFF) ((BUFF)->cur)
115169695Skan#define BUFF_LIMIT(BUFF) ((BUFF)->limit)
116169695Skan
117169695Skan/* #include types.  */
118169695Skanenum include_type {IT_INCLUDE, IT_INCLUDE_NEXT, IT_IMPORT, IT_CMDLINE};
119169695Skan
120169695Skanunion utoken
121169695Skan{
122169695Skan  const cpp_token *token;
123169695Skan  const cpp_token **ptoken;
124169695Skan};
125169695Skan
126169695Skan/* A "run" of tokens; part of a chain of runs.  */
127169695Skantypedef struct tokenrun tokenrun;
128169695Skanstruct tokenrun
129169695Skan{
130169695Skan  tokenrun *next, *prev;
131169695Skan  cpp_token *base, *limit;
132169695Skan};
133169695Skan
134169695Skan/* Accessor macros for struct cpp_context.  */
135169695Skan#define FIRST(c) ((c)->u.iso.first)
136169695Skan#define LAST(c) ((c)->u.iso.last)
137169695Skan#define CUR(c) ((c)->u.trad.cur)
138169695Skan#define RLIMIT(c) ((c)->u.trad.rlimit)
139169695Skan
140169695Skantypedef struct cpp_context cpp_context;
141169695Skanstruct cpp_context
142169695Skan{
143169695Skan  /* Doubly-linked list.  */
144169695Skan  cpp_context *next, *prev;
145169695Skan
146169695Skan  union
147169695Skan  {
148169695Skan    /* For ISO macro expansion.  Contexts other than the base context
149169695Skan       are contiguous tokens.  e.g. macro expansions, expanded
150169695Skan       argument tokens.  */
151169695Skan    struct
152169695Skan    {
153169695Skan      union utoken first;
154169695Skan      union utoken last;
155169695Skan    } iso;
156169695Skan
157169695Skan    /* For traditional macro expansion.  */
158169695Skan    struct
159169695Skan    {
160169695Skan      const unsigned char *cur;
161169695Skan      const unsigned char *rlimit;
162169695Skan    } trad;
163169695Skan  } u;
164169695Skan
165169695Skan  /* If non-NULL, a buffer used for storage related to this context.
166169695Skan     When the context is popped, the buffer is released.  */
167169695Skan  _cpp_buff *buff;
168169695Skan
169169695Skan  /* For a macro context, the macro node, otherwise NULL.  */
170169695Skan  cpp_hashnode *macro;
171169695Skan
172169695Skan  /* True if utoken element is token, else ptoken.  */
173169695Skan  bool direct_p;
174169695Skan};
175169695Skan
176169695Skanstruct lexer_state
177169695Skan{
178169695Skan  /* Nonzero if first token on line is CPP_HASH.  */
179169695Skan  unsigned char in_directive;
180169695Skan
181169695Skan  /* Nonzero if in a directive that will handle padding tokens itself.
182169695Skan     #include needs this to avoid problems with computed include and
183169695Skan     spacing between tokens.  */
184169695Skan  unsigned char directive_wants_padding;
185169695Skan
186169695Skan  /* True if we are skipping a failed conditional group.  */
187169695Skan  unsigned char skipping;
188169695Skan
189169695Skan  /* Nonzero if in a directive that takes angle-bracketed headers.  */
190169695Skan  unsigned char angled_headers;
191169695Skan
192169695Skan  /* Nonzero if in a #if or #elif directive.  */
193169695Skan  unsigned char in_expression;
194169695Skan
195169695Skan  /* Nonzero to save comments.  Turned off if discard_comments, and in
196169695Skan     all directives apart from #define.  */
197169695Skan  unsigned char save_comments;
198169695Skan
199169695Skan  /* Nonzero if lexing __VA_ARGS__ is valid.  */
200169695Skan  unsigned char va_args_ok;
201169695Skan
202169695Skan  /* Nonzero if lexing poisoned identifiers is valid.  */
203169695Skan  unsigned char poisoned_ok;
204169695Skan
205169695Skan  /* Nonzero to prevent macro expansion.  */
206169695Skan  unsigned char prevent_expansion;
207169695Skan
208169695Skan  /* Nonzero when parsing arguments to a function-like macro.  */
209169695Skan  unsigned char parsing_args;
210169695Skan
211169695Skan  /* Nonzero if prevent_expansion is true only because output is
212169695Skan     being discarded.  */
213169695Skan  unsigned char discarding_output;
214169695Skan
215169695Skan  /* Nonzero to skip evaluating part of an expression.  */
216169695Skan  unsigned int skip_eval;
217169695Skan
218169695Skan  /* Nonzero when handling a deferred pragma.  */
219169695Skan  unsigned char in_deferred_pragma;
220169695Skan
221169695Skan  /* Nonzero if the deferred pragma being handled allows macro expansion.  */
222169695Skan  unsigned char pragma_allow_expansion;
223260573Spfg
224260573Spfg  /* APPLE LOCAL begin #error with unmatched quotes 5607574 */
225260573Spfg  /* Nonzero when handling #error and #warning to allow unmatched quotes.  */
226260573Spfg  unsigned char in_diagnostic;
227260573Spfg  /* APPLE LOCAL end #error with unmatched quotes 5607574 */
228169695Skan};
229169695Skan
230169695Skan/* Special nodes - identifiers with predefined significance.  */
231169695Skanstruct spec_nodes
232169695Skan{
233169695Skan  cpp_hashnode *n_defined;		/* defined operator */
234169695Skan  cpp_hashnode *n_true;			/* C++ keyword true */
235169695Skan  cpp_hashnode *n_false;		/* C++ keyword false */
236169695Skan  cpp_hashnode *n__VA_ARGS__;		/* C99 vararg macros */
237169695Skan};
238169695Skan
239169695Skantypedef struct _cpp_line_note _cpp_line_note;
240169695Skanstruct _cpp_line_note
241169695Skan{
242169695Skan  /* Location in the clean line the note refers to.  */
243169695Skan  const unsigned char *pos;
244169695Skan
245169695Skan  /* Type of note.  The 9 'from' trigraph characters represent those
246169695Skan     trigraphs, '\\' an escaped newline, ' ' an escaped newline with
247169695Skan     intervening space, and anything else is invalid.  */
248169695Skan  unsigned int type;
249169695Skan};
250169695Skan
251169695Skan/* Represents the contents of a file cpplib has read in.  */
252169695Skanstruct cpp_buffer
253169695Skan{
254169695Skan  const unsigned char *cur;        /* Current location.  */
255169695Skan  const unsigned char *line_base;  /* Start of current physical line.  */
256169695Skan  const unsigned char *next_line;  /* Start of to-be-cleaned logical line.  */
257169695Skan
258169695Skan  const unsigned char *buf;        /* Entire character buffer.  */
259169695Skan  const unsigned char *rlimit;     /* Writable byte at end of file.  */
260169695Skan
261169695Skan  _cpp_line_note *notes;           /* Array of notes.  */
262169695Skan  unsigned int cur_note;           /* Next note to process.  */
263169695Skan  unsigned int notes_used;         /* Number of notes.  */
264169695Skan  unsigned int notes_cap;          /* Size of allocated array.  */
265169695Skan
266169695Skan  struct cpp_buffer *prev;
267169695Skan
268169695Skan  /* Pointer into the file table; non-NULL if this is a file buffer.
269169695Skan     Used for include_next and to record control macros.  */
270169695Skan  struct _cpp_file *file;
271169695Skan
272169695Skan  /* Saved value of __TIMESTAMP__ macro - date and time of last modification
273169695Skan     of the assotiated file.  */
274169695Skan  const unsigned char *timestamp;
275169695Skan
276169695Skan  /* Value of if_stack at start of this file.
277169695Skan     Used to prohibit unmatched #endif (etc) in an include file.  */
278169695Skan  struct if_stack *if_stack;
279169695Skan
280169695Skan  /* True if we need to get the next clean line.  */
281169695Skan  bool need_line;
282169695Skan
283169695Skan  /* True if we have already warned about C++ comments in this file.
284169695Skan     The warning happens only for C89 extended mode with -pedantic on,
285169695Skan     or for -Wtraditional, and only once per file (otherwise it would
286169695Skan     be far too noisy).  */
287169695Skan  unsigned int warned_cplusplus_comments : 1;
288169695Skan
289169695Skan  /* True if we don't process trigraphs and escaped newlines.  True
290169695Skan     for preprocessed input, command line directives, and _Pragma
291169695Skan     buffers.  */
292169695Skan  unsigned int from_stage3 : 1;
293169695Skan
294169695Skan  /* At EOF, a buffer is automatically popped.  If RETURN_AT_EOF is
295169695Skan     true, a CPP_EOF token is then returned.  Otherwise, the next
296169695Skan     token from the enclosing buffer is returned.  */
297169695Skan  unsigned int return_at_eof : 1;
298169695Skan
299169695Skan  /* One for a system header, two for a C system header file that therefore
300169695Skan     needs to be extern "C" protected in C++, and zero otherwise.  */
301169695Skan  unsigned char sysp;
302169695Skan
303169695Skan  /* The directory of the this buffer's file.  Its NAME member is not
304169695Skan     allocated, so we don't need to worry about freeing it.  */
305169695Skan  struct cpp_dir dir;
306169695Skan
307169695Skan  /* Descriptor for converting from the input character set to the
308169695Skan     source character set.  */
309169695Skan  struct cset_converter input_cset_desc;
310169695Skan};
311169695Skan
312169695Skan/* A cpp_reader encapsulates the "state" of a pre-processor run.
313169695Skan   Applying cpp_get_token repeatedly yields a stream of pre-processor
314169695Skan   tokens.  Usually, there is only one cpp_reader object active.  */
315169695Skanstruct cpp_reader
316169695Skan{
317169695Skan  /* Top of buffer stack.  */
318169695Skan  cpp_buffer *buffer;
319169695Skan
320169695Skan  /* Overlaid buffer (can be different after processing #include).  */
321169695Skan  cpp_buffer *overlaid_buffer;
322169695Skan
323169695Skan  /* Lexer state.  */
324169695Skan  struct lexer_state state;
325169695Skan
326169695Skan  /* Source line tracking.  */
327169695Skan  struct line_maps *line_table;
328169695Skan
329169695Skan  /* The line of the '#' of the current directive.  */
330169695Skan  source_location directive_line;
331169695Skan
332169695Skan  /* Memory buffers.  */
333169695Skan  _cpp_buff *a_buff;		/* Aligned permanent storage.  */
334169695Skan  _cpp_buff *u_buff;		/* Unaligned permanent storage.  */
335169695Skan  _cpp_buff *free_buffs;	/* Free buffer chain.  */
336169695Skan
337169695Skan  /* Context stack.  */
338169695Skan  struct cpp_context base_context;
339169695Skan  struct cpp_context *context;
340169695Skan
341169695Skan  /* If in_directive, the directive if known.  */
342169695Skan  const struct directive *directive;
343169695Skan
344169695Skan  /* Token generated while handling a directive, if any. */
345169695Skan  cpp_token directive_result;
346169695Skan
347169695Skan  /* Search paths for include files.  */
348169695Skan  struct cpp_dir *quote_include;	/* "" */
349169695Skan  struct cpp_dir *bracket_include;	/* <> */
350169695Skan  struct cpp_dir no_search_path;	/* No path.  */
351169695Skan
352169695Skan  /* Chain of all hashed _cpp_file instances.  */
353169695Skan  struct _cpp_file *all_files;
354169695Skan
355169695Skan  struct _cpp_file *main_file;
356169695Skan
357169695Skan  /* File and directory hash table.  */
358169695Skan  struct htab *file_hash;
359169695Skan  struct htab *dir_hash;
360169695Skan  struct file_hash_entry *file_hash_entries;
361169695Skan  unsigned int file_hash_entries_allocated, file_hash_entries_used;
362169695Skan
363259268Spfg  /* Negative path lookup hash table.  */
364259268Spfg  struct htab *nonexistent_file_hash;
365259268Spfg  struct obstack nonexistent_file_ob;
366259268Spfg
367169695Skan  /* Nonzero means don't look for #include "foo" the source-file
368169695Skan     directory.  */
369169695Skan  bool quote_ignores_source_dir;
370169695Skan
371169695Skan  /* Nonzero if any file has contained #pragma once or #import has
372169695Skan     been used.  */
373169695Skan  bool seen_once_only;
374169695Skan
375169695Skan  /* Multiple include optimization.  */
376169695Skan  const cpp_hashnode *mi_cmacro;
377169695Skan  const cpp_hashnode *mi_ind_cmacro;
378169695Skan  bool mi_valid;
379169695Skan
380169695Skan  /* Lexing.  */
381169695Skan  cpp_token *cur_token;
382169695Skan  tokenrun base_run, *cur_run;
383169695Skan  unsigned int lookaheads;
384169695Skan
385169695Skan  /* Nonzero prevents the lexer from re-using the token runs.  */
386169695Skan  unsigned int keep_tokens;
387169695Skan
388169695Skan  /* Error counter for exit code.  */
389169695Skan  unsigned int errors;
390169695Skan
391169695Skan  /* Buffer to hold macro definition string.  */
392169695Skan  unsigned char *macro_buffer;
393169695Skan  unsigned int macro_buffer_len;
394169695Skan
395169695Skan  /* Descriptor for converting from the source character set to the
396169695Skan     execution character set.  */
397169695Skan  struct cset_converter narrow_cset_desc;
398169695Skan
399169695Skan  /* Descriptor for converting from the source character set to the
400169695Skan     wide execution character set.  */
401169695Skan  struct cset_converter wide_cset_desc;
402169695Skan
403169695Skan  /* Date and time text.  Calculated together if either is requested.  */
404169695Skan  const unsigned char *date;
405169695Skan  const unsigned char *time;
406169695Skan
407169695Skan  /* EOF token, and a token forcing paste avoidance.  */
408169695Skan  cpp_token avoid_paste;
409169695Skan  cpp_token eof;
410169695Skan
411169695Skan  /* Opaque handle to the dependencies of mkdeps.c.  */
412169695Skan  struct deps *deps;
413169695Skan
414169695Skan  /* Obstack holding all macro hash nodes.  This never shrinks.
415169695Skan     See identifiers.c */
416169695Skan  struct obstack hash_ob;
417169695Skan
418169695Skan  /* Obstack holding buffer and conditional structures.  This is a
419169695Skan     real stack.  See directives.c.  */
420169695Skan  struct obstack buffer_ob;
421169695Skan
422169695Skan  /* Pragma table - dynamic, because a library user can add to the
423169695Skan     list of recognized pragmas.  */
424169695Skan  struct pragma_entry *pragmas;
425169695Skan
426169695Skan  /* Call backs to cpplib client.  */
427169695Skan  struct cpp_callbacks cb;
428169695Skan
429169695Skan  /* Identifier hash table.  */
430169695Skan  struct ht *hash_table;
431169695Skan
432169695Skan  /* Expression parser stack.  */
433169695Skan  struct op *op_stack, *op_limit;
434169695Skan
435169695Skan  /* User visible options.  */
436169695Skan  struct cpp_options opts;
437169695Skan
438169695Skan  /* Special nodes - identifiers with predefined significance to the
439169695Skan     preprocessor.  */
440169695Skan  struct spec_nodes spec_nodes;
441169695Skan
442169695Skan  /* Whether cpplib owns the hashtable.  */
443169695Skan  bool our_hashtable;
444169695Skan
445169695Skan  /* Traditional preprocessing output buffer (a logical line).  */
446169695Skan  struct
447169695Skan  {
448169695Skan    unsigned char *base;
449169695Skan    unsigned char *limit;
450169695Skan    unsigned char *cur;
451169695Skan    source_location first_line;
452169695Skan  } out;
453169695Skan
454169695Skan  /* Used for buffer overlays by traditional.c.  */
455169695Skan  const unsigned char *saved_cur, *saved_rlimit, *saved_line_base;
456169695Skan
457169695Skan  /* A saved list of the defined macros, for dependency checking
458169695Skan     of precompiled headers.  */
459169695Skan  struct cpp_savedstate *savedstate;
460228474Sed
461228474Sed  unsigned int nextcounter;
462169695Skan};
463169695Skan
464169695Skan/* Character classes.  Based on the more primitive macros in safe-ctype.h.
465169695Skan   If the definition of `numchar' looks odd to you, please look up the
466169695Skan   definition of a pp-number in the C standard [section 6.4.8 of C99].
467169695Skan
468169695Skan   In the unlikely event that characters other than \r and \n enter
469169695Skan   the set is_vspace, the macro handle_newline() in lex.c must be
470169695Skan   updated.  */
471169695Skan#define _dollar_ok(x)	((x) == '$' && CPP_OPTION (pfile, dollars_in_ident))
472169695Skan
473169695Skan#define is_idchar(x)	(ISIDNUM(x) || _dollar_ok(x))
474169695Skan#define is_numchar(x)	ISIDNUM(x)
475169695Skan#define is_idstart(x)	(ISIDST(x) || _dollar_ok(x))
476169695Skan#define is_numstart(x)	ISDIGIT(x)
477169695Skan#define is_hspace(x)	ISBLANK(x)
478169695Skan#define is_vspace(x)	IS_VSPACE(x)
479169695Skan#define is_nvspace(x)	IS_NVSPACE(x)
480169695Skan#define is_space(x)	IS_SPACE_OR_NUL(x)
481169695Skan
482169695Skan/* This table is constant if it can be initialized at compile time,
483169695Skan   which is the case if cpp was compiled with GCC >=2.7, or another
484169695Skan   compiler that supports C99.  */
485169695Skan#if HAVE_DESIGNATED_INITIALIZERS
486169695Skanextern const unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
487169695Skan#else
488169695Skanextern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
489169695Skan#endif
490169695Skan
491169695Skan/* Macros.  */
492169695Skan
493169695Skanstatic inline int cpp_in_system_header (cpp_reader *);
494169695Skanstatic inline int
495169695Skancpp_in_system_header (cpp_reader *pfile)
496169695Skan{
497169695Skan  return pfile->buffer ? pfile->buffer->sysp : 0;
498169695Skan}
499169695Skan#define CPP_PEDANTIC(PF) CPP_OPTION (PF, pedantic)
500169695Skan#define CPP_WTRADITIONAL(PF) CPP_OPTION (PF, warn_traditional)
501169695Skan
502169695Skan/* In errors.c  */
503169695Skanextern int _cpp_begin_message (cpp_reader *, int,
504169695Skan			       source_location, unsigned int);
505169695Skan
506169695Skan/* In macro.c */
507169695Skanextern void _cpp_free_definition (cpp_hashnode *);
508169695Skanextern bool _cpp_create_definition (cpp_reader *, cpp_hashnode *);
509169695Skanextern void _cpp_pop_context (cpp_reader *);
510169695Skanextern void _cpp_push_text_context (cpp_reader *, cpp_hashnode *,
511169695Skan				    const unsigned char *, size_t);
512169695Skanextern bool _cpp_save_parameter (cpp_reader *, cpp_macro *, cpp_hashnode *);
513169695Skanextern bool _cpp_arguments_ok (cpp_reader *, cpp_macro *, const cpp_hashnode *,
514169695Skan			       unsigned int);
515169695Skanextern const unsigned char *_cpp_builtin_macro_text (cpp_reader *,
516169695Skan						     cpp_hashnode *);
517169695Skanextern int _cpp_warn_if_unused_macro (cpp_reader *, cpp_hashnode *, void *);
518169695Skanextern void _cpp_push_token_context (cpp_reader *, cpp_hashnode *,
519169695Skan				     const cpp_token *, unsigned int);
520169695Skan
521169695Skan/* In identifiers.c */
522169695Skanextern void _cpp_init_hashtable (cpp_reader *, hash_table *);
523169695Skanextern void _cpp_destroy_hashtable (cpp_reader *);
524169695Skan
525169695Skan/* In files.c */
526169695Skantypedef struct _cpp_file _cpp_file;
527169695Skanextern _cpp_file *_cpp_find_file (cpp_reader *, const char *, cpp_dir *,
528169695Skan				  bool, int);
529169695Skanextern bool _cpp_find_failed (_cpp_file *);
530169695Skanextern void _cpp_mark_file_once_only (cpp_reader *, struct _cpp_file *);
531169695Skanextern void _cpp_fake_include (cpp_reader *, const char *);
532169695Skanextern bool _cpp_stack_file (cpp_reader *, _cpp_file*, bool);
533169695Skanextern bool _cpp_stack_include (cpp_reader *, const char *, int,
534169695Skan				enum include_type);
535169695Skanextern int _cpp_compare_file_date (cpp_reader *, const char *, int);
536169695Skanextern void _cpp_report_missing_guards (cpp_reader *);
537169695Skanextern void _cpp_init_files (cpp_reader *);
538169695Skanextern void _cpp_cleanup_files (cpp_reader *);
539169695Skanextern void _cpp_pop_file_buffer (cpp_reader *, struct _cpp_file *);
540169695Skanextern bool _cpp_save_file_entries (cpp_reader *pfile, FILE *f);
541169695Skanextern bool _cpp_read_file_entries (cpp_reader *, FILE *);
542169695Skanextern struct stat *_cpp_get_file_stat (_cpp_file *);
543169695Skan
544169695Skan/* In expr.c */
545169695Skanextern bool _cpp_parse_expr (cpp_reader *);
546169695Skanextern struct op *_cpp_expand_op_stack (cpp_reader *);
547169695Skan
548169695Skan/* In lex.c */
549169695Skanextern void _cpp_process_line_notes (cpp_reader *, int);
550169695Skanextern void _cpp_clean_line (cpp_reader *);
551169695Skanextern bool _cpp_get_fresh_line (cpp_reader *);
552169695Skanextern bool _cpp_skip_block_comment (cpp_reader *);
553169695Skanextern cpp_token *_cpp_temp_token (cpp_reader *);
554169695Skanextern const cpp_token *_cpp_lex_token (cpp_reader *);
555169695Skanextern cpp_token *_cpp_lex_direct (cpp_reader *);
556169695Skanextern int _cpp_equiv_tokens (const cpp_token *, const cpp_token *);
557169695Skanextern void _cpp_init_tokenrun (tokenrun *, unsigned int);
558169695Skan
559169695Skan/* In init.c.  */
560169695Skanextern void _cpp_maybe_push_include_file (cpp_reader *);
561169695Skan
562169695Skan/* In directives.c */
563169695Skanextern int _cpp_test_assertion (cpp_reader *, unsigned int *);
564169695Skanextern int _cpp_handle_directive (cpp_reader *, int);
565169695Skanextern void _cpp_define_builtin (cpp_reader *, const char *);
566169695Skanextern char ** _cpp_save_pragma_names (cpp_reader *);
567169695Skanextern void _cpp_restore_pragma_names (cpp_reader *, char **);
568169695Skanextern void _cpp_do__Pragma (cpp_reader *);
569169695Skanextern void _cpp_init_directives (cpp_reader *);
570169695Skanextern void _cpp_init_internal_pragmas (cpp_reader *);
571169695Skanextern void _cpp_do_file_change (cpp_reader *, enum lc_reason, const char *,
572169695Skan				 unsigned int, unsigned int);
573169695Skanextern void _cpp_pop_buffer (cpp_reader *);
574169695Skan
575259405Spfg/* In directives.c */
576259405Spfgstruct _cpp_dir_only_callbacks
577259405Spfg{
578259405Spfg  /* Called to print a block of lines. */
579259405Spfg  void (*print_lines) (int, const void *, size_t);
580259405Spfg  void (*maybe_print_line) (source_location);
581259405Spfg};
582259405Spfg
583259405Spfgextern void _cpp_preprocess_dir_only (cpp_reader *,
584259405Spfg				      const struct _cpp_dir_only_callbacks *);
585259405Spfg
586169695Skan/* In traditional.c.  */
587169695Skanextern bool _cpp_scan_out_logical_line (cpp_reader *, cpp_macro *);
588169695Skanextern bool _cpp_read_logical_line_trad (cpp_reader *);
589169695Skanextern void _cpp_overlay_buffer (cpp_reader *pfile, const unsigned char *,
590169695Skan				 size_t);
591169695Skanextern void _cpp_remove_overlay (cpp_reader *);
592169695Skanextern bool _cpp_create_trad_definition (cpp_reader *, cpp_macro *);
593169695Skanextern bool _cpp_expansions_different_trad (const cpp_macro *,
594169695Skan					    const cpp_macro *);
595169695Skanextern unsigned char *_cpp_copy_replacement_text (const cpp_macro *,
596169695Skan						  unsigned char *);
597169695Skanextern size_t _cpp_replacement_text_len (const cpp_macro *);
598169695Skan
599169695Skan/* In charset.c.  */
600169695Skan
601169695Skan/* The normalization state at this point in the sequence.
602169695Skan   It starts initialized to all zeros, and at the end
603169695Skan   'level' is the normalization level of the sequence.  */
604169695Skan
605169695Skanstruct normalize_state
606169695Skan{
607169695Skan  /* The previous character.  */
608169695Skan  cppchar_t previous;
609169695Skan  /* The combining class of the previous character.  */
610169695Skan  unsigned char prev_class;
611169695Skan  /* The lowest normalization level so far.  */
612169695Skan  enum cpp_normalize_level level;
613169695Skan};
614169695Skan#define INITIAL_NORMALIZE_STATE { 0, 0, normalized_KC }
615169695Skan#define NORMALIZE_STATE_RESULT(st) ((st)->level)
616169695Skan
617169695Skan/* We saw a character that matches ISIDNUM(), update a
618169695Skan   normalize_state appropriately.  */
619169695Skan#define NORMALIZE_STATE_UPDATE_IDNUM(st) \
620169695Skan  ((st)->previous = 0, (st)->prev_class = 0)
621169695Skan
622169695Skanextern cppchar_t _cpp_valid_ucn (cpp_reader *, const unsigned char **,
623169695Skan				 const unsigned char *, int,
624169695Skan				 struct normalize_state *state);
625169695Skanextern void _cpp_destroy_iconv (cpp_reader *);
626169695Skanextern unsigned char *_cpp_convert_input (cpp_reader *, const char *,
627169695Skan					  unsigned char *, size_t, size_t,
628169695Skan					  off_t *);
629169695Skanextern const char *_cpp_default_encoding (void);
630169695Skanextern cpp_hashnode * _cpp_interpret_identifier (cpp_reader *pfile,
631169695Skan						 const unsigned char *id,
632169695Skan						 size_t len);
633169695Skan
634169695Skan/* Utility routines and macros.  */
635169695Skan#define DSC(str) (const unsigned char *)str, sizeof str - 1
636169695Skan
637169695Skan/* These are inline functions instead of macros so we can get type
638169695Skan   checking.  */
639169695Skanstatic inline int ustrcmp (const unsigned char *, const unsigned char *);
640169695Skanstatic inline int ustrncmp (const unsigned char *, const unsigned char *,
641169695Skan			    size_t);
642169695Skanstatic inline size_t ustrlen (const unsigned char *);
643169695Skanstatic inline unsigned char *uxstrdup (const unsigned char *);
644169695Skanstatic inline unsigned char *ustrchr (const unsigned char *, int);
645169695Skanstatic inline int ufputs (const unsigned char *, FILE *);
646169695Skan
647169695Skan/* Use a const char for the second parameter since it is usually a literal.  */
648169695Skanstatic inline int ustrcspn (const unsigned char *, const char *);
649169695Skan
650169695Skanstatic inline int
651169695Skanustrcmp (const unsigned char *s1, const unsigned char *s2)
652169695Skan{
653169695Skan  return strcmp ((const char *)s1, (const char *)s2);
654169695Skan}
655169695Skan
656169695Skanstatic inline int
657169695Skanustrncmp (const unsigned char *s1, const unsigned char *s2, size_t n)
658169695Skan{
659169695Skan  return strncmp ((const char *)s1, (const char *)s2, n);
660169695Skan}
661169695Skan
662169695Skanstatic inline int
663169695Skanustrcspn (const unsigned char *s1, const char *s2)
664169695Skan{
665169695Skan  return strcspn ((const char *)s1, s2);
666169695Skan}
667169695Skan
668169695Skanstatic inline size_t
669169695Skanustrlen (const unsigned char *s1)
670169695Skan{
671169695Skan  return strlen ((const char *)s1);
672169695Skan}
673169695Skan
674169695Skanstatic inline unsigned char *
675169695Skanuxstrdup (const unsigned char *s1)
676169695Skan{
677169695Skan  return (unsigned char *) xstrdup ((const char *)s1);
678169695Skan}
679169695Skan
680169695Skanstatic inline unsigned char *
681169695Skanustrchr (const unsigned char *s1, int c)
682169695Skan{
683169695Skan  return (unsigned char *) strchr ((const char *)s1, c);
684169695Skan}
685169695Skan
686169695Skanstatic inline int
687169695Skanufputs (const unsigned char *s, FILE *f)
688169695Skan{
689169695Skan  return fputs ((const char *)s, f);
690169695Skan}
691169695Skan
692169695Skan#endif /* ! LIBCPP_INTERNAL_H */
693