xref: /openbsd-src/gnu/gcc/libcpp/internal.h (revision 404b540a9034ac75a6199ad1a32d1bbc7a0d4210)
1*404b540aSrobert /* Part of CPP library.
2*404b540aSrobert    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3*404b540aSrobert    Free Software Foundation, Inc.
4*404b540aSrobert 
5*404b540aSrobert This program is free software; you can redistribute it and/or modify it
6*404b540aSrobert under the terms of the GNU General Public License as published by the
7*404b540aSrobert Free Software Foundation; either version 2, or (at your option) any
8*404b540aSrobert later version.
9*404b540aSrobert 
10*404b540aSrobert This program is distributed in the hope that it will be useful,
11*404b540aSrobert but WITHOUT ANY WARRANTY; without even the implied warranty of
12*404b540aSrobert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*404b540aSrobert GNU General Public License for more details.
14*404b540aSrobert 
15*404b540aSrobert You should have received a copy of the GNU General Public License
16*404b540aSrobert along with this program; if not, write to the Free Software
17*404b540aSrobert Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
18*404b540aSrobert 
19*404b540aSrobert /* This header defines all the internal data structures and functions
20*404b540aSrobert    that need to be visible across files.  It should not be used outside
21*404b540aSrobert    cpplib.  */
22*404b540aSrobert 
23*404b540aSrobert #ifndef LIBCPP_INTERNAL_H
24*404b540aSrobert #define LIBCPP_INTERNAL_H
25*404b540aSrobert 
26*404b540aSrobert #include "symtab.h"
27*404b540aSrobert #include "cpp-id-data.h"
28*404b540aSrobert 
29*404b540aSrobert #ifndef HAVE_ICONV_H
30*404b540aSrobert #undef HAVE_ICONV
31*404b540aSrobert #endif
32*404b540aSrobert 
33*404b540aSrobert #if HAVE_ICONV
34*404b540aSrobert #include <iconv.h>
35*404b540aSrobert #else
36*404b540aSrobert #define HAVE_ICONV 0
37*404b540aSrobert typedef int iconv_t;  /* dummy */
38*404b540aSrobert #endif
39*404b540aSrobert 
40*404b540aSrobert struct directive;		/* Deliberately incomplete.  */
41*404b540aSrobert struct pending_option;
42*404b540aSrobert struct op;
43*404b540aSrobert struct _cpp_strbuf;
44*404b540aSrobert 
45*404b540aSrobert typedef bool (*convert_f) (iconv_t, const unsigned char *, size_t,
46*404b540aSrobert 			   struct _cpp_strbuf *);
47*404b540aSrobert struct cset_converter
48*404b540aSrobert {
49*404b540aSrobert   convert_f func;
50*404b540aSrobert   iconv_t cd;
51*404b540aSrobert };
52*404b540aSrobert 
53*404b540aSrobert #define BITS_PER_CPPCHAR_T (CHAR_BIT * sizeof (cppchar_t))
54*404b540aSrobert 
55*404b540aSrobert /* Test if a sign is valid within a preprocessing number.  */
56*404b540aSrobert #define VALID_SIGN(c, prevc) \
57*404b540aSrobert   (((c) == '+' || (c) == '-') && \
58*404b540aSrobert    ((prevc) == 'e' || (prevc) == 'E' \
59*404b540aSrobert     || (((prevc) == 'p' || (prevc) == 'P') \
60*404b540aSrobert         && CPP_OPTION (pfile, extended_numbers))))
61*404b540aSrobert 
62*404b540aSrobert #define CPP_OPTION(PFILE, OPTION) ((PFILE)->opts.OPTION)
63*404b540aSrobert #define CPP_BUFFER(PFILE) ((PFILE)->buffer)
64*404b540aSrobert #define CPP_BUF_COLUMN(BUF, CUR) ((CUR) - (BUF)->line_base)
65*404b540aSrobert #define CPP_BUF_COL(BUF) CPP_BUF_COLUMN(BUF, (BUF)->cur)
66*404b540aSrobert 
67*404b540aSrobert #define CPP_INCREMENT_LINE(PFILE, COLS_HINT) do { \
68*404b540aSrobert     const struct line_maps *line_table = PFILE->line_table; \
69*404b540aSrobert     const struct line_map *map = &line_table->maps[line_table->used-1]; \
70*404b540aSrobert     unsigned int line = SOURCE_LINE (map, line_table->highest_line); \
71*404b540aSrobert     linemap_line_start (PFILE->line_table, line + 1, COLS_HINT); \
72*404b540aSrobert   } while (0)
73*404b540aSrobert 
74*404b540aSrobert /* Maximum nesting of cpp_buffers.  We use a static limit, partly for
75*404b540aSrobert    efficiency, and partly to limit runaway recursion.  */
76*404b540aSrobert #define CPP_STACK_MAX 200
77*404b540aSrobert 
78*404b540aSrobert /* Host alignment handling.  */
79*404b540aSrobert struct dummy
80*404b540aSrobert {
81*404b540aSrobert   char c;
82*404b540aSrobert   union
83*404b540aSrobert   {
84*404b540aSrobert     double d;
85*404b540aSrobert     int *p;
86*404b540aSrobert   } u;
87*404b540aSrobert };
88*404b540aSrobert 
89*404b540aSrobert #define DEFAULT_ALIGNMENT offsetof (struct dummy, u)
90*404b540aSrobert #define CPP_ALIGN2(size, align) (((size) + ((align) - 1)) & ~((align) - 1))
91*404b540aSrobert #define CPP_ALIGN(size) CPP_ALIGN2 (size, DEFAULT_ALIGNMENT)
92*404b540aSrobert 
93*404b540aSrobert #define _cpp_mark_macro_used(NODE) do {					\
94*404b540aSrobert   if ((NODE)->type == NT_MACRO && !((NODE)->flags & NODE_BUILTIN))	\
95*404b540aSrobert     (NODE)->value.macro->used = 1; } while (0)
96*404b540aSrobert 
97*404b540aSrobert /* A generic memory buffer, and operations on it.  */
98*404b540aSrobert typedef struct _cpp_buff _cpp_buff;
99*404b540aSrobert struct _cpp_buff
100*404b540aSrobert {
101*404b540aSrobert   struct _cpp_buff *next;
102*404b540aSrobert   unsigned char *base, *cur, *limit;
103*404b540aSrobert };
104*404b540aSrobert 
105*404b540aSrobert extern _cpp_buff *_cpp_get_buff (cpp_reader *, size_t);
106*404b540aSrobert extern void _cpp_release_buff (cpp_reader *, _cpp_buff *);
107*404b540aSrobert extern void _cpp_extend_buff (cpp_reader *, _cpp_buff **, size_t);
108*404b540aSrobert extern _cpp_buff *_cpp_append_extend_buff (cpp_reader *, _cpp_buff *, size_t);
109*404b540aSrobert extern void _cpp_free_buff (_cpp_buff *);
110*404b540aSrobert extern unsigned char *_cpp_aligned_alloc (cpp_reader *, size_t);
111*404b540aSrobert extern unsigned char *_cpp_unaligned_alloc (cpp_reader *, size_t);
112*404b540aSrobert 
113*404b540aSrobert #define BUFF_ROOM(BUFF) (size_t) ((BUFF)->limit - (BUFF)->cur)
114*404b540aSrobert #define BUFF_FRONT(BUFF) ((BUFF)->cur)
115*404b540aSrobert #define BUFF_LIMIT(BUFF) ((BUFF)->limit)
116*404b540aSrobert 
117*404b540aSrobert /* #include types.  */
118*404b540aSrobert enum include_type {IT_INCLUDE, IT_INCLUDE_NEXT, IT_IMPORT, IT_CMDLINE};
119*404b540aSrobert 
120*404b540aSrobert union utoken
121*404b540aSrobert {
122*404b540aSrobert   const cpp_token *token;
123*404b540aSrobert   const cpp_token **ptoken;
124*404b540aSrobert };
125*404b540aSrobert 
126*404b540aSrobert /* A "run" of tokens; part of a chain of runs.  */
127*404b540aSrobert typedef struct tokenrun tokenrun;
128*404b540aSrobert struct tokenrun
129*404b540aSrobert {
130*404b540aSrobert   tokenrun *next, *prev;
131*404b540aSrobert   cpp_token *base, *limit;
132*404b540aSrobert };
133*404b540aSrobert 
134*404b540aSrobert /* Accessor macros for struct cpp_context.  */
135*404b540aSrobert #define FIRST(c) ((c)->u.iso.first)
136*404b540aSrobert #define LAST(c) ((c)->u.iso.last)
137*404b540aSrobert #define CUR(c) ((c)->u.trad.cur)
138*404b540aSrobert #define RLIMIT(c) ((c)->u.trad.rlimit)
139*404b540aSrobert 
140*404b540aSrobert typedef struct cpp_context cpp_context;
141*404b540aSrobert struct cpp_context
142*404b540aSrobert {
143*404b540aSrobert   /* Doubly-linked list.  */
144*404b540aSrobert   cpp_context *next, *prev;
145*404b540aSrobert 
146*404b540aSrobert   union
147*404b540aSrobert   {
148*404b540aSrobert     /* For ISO macro expansion.  Contexts other than the base context
149*404b540aSrobert        are contiguous tokens.  e.g. macro expansions, expanded
150*404b540aSrobert        argument tokens.  */
151*404b540aSrobert     struct
152*404b540aSrobert     {
153*404b540aSrobert       union utoken first;
154*404b540aSrobert       union utoken last;
155*404b540aSrobert     } iso;
156*404b540aSrobert 
157*404b540aSrobert     /* For traditional macro expansion.  */
158*404b540aSrobert     struct
159*404b540aSrobert     {
160*404b540aSrobert       const unsigned char *cur;
161*404b540aSrobert       const unsigned char *rlimit;
162*404b540aSrobert     } trad;
163*404b540aSrobert   } u;
164*404b540aSrobert 
165*404b540aSrobert   /* If non-NULL, a buffer used for storage related to this context.
166*404b540aSrobert      When the context is popped, the buffer is released.  */
167*404b540aSrobert   _cpp_buff *buff;
168*404b540aSrobert 
169*404b540aSrobert   /* For a macro context, the macro node, otherwise NULL.  */
170*404b540aSrobert   cpp_hashnode *macro;
171*404b540aSrobert 
172*404b540aSrobert   /* True if utoken element is token, else ptoken.  */
173*404b540aSrobert   bool direct_p;
174*404b540aSrobert };
175*404b540aSrobert 
176*404b540aSrobert struct lexer_state
177*404b540aSrobert {
178*404b540aSrobert   /* Nonzero if first token on line is CPP_HASH.  */
179*404b540aSrobert   unsigned char in_directive;
180*404b540aSrobert 
181*404b540aSrobert   /* Nonzero if in a directive that will handle padding tokens itself.
182*404b540aSrobert      #include needs this to avoid problems with computed include and
183*404b540aSrobert      spacing between tokens.  */
184*404b540aSrobert   unsigned char directive_wants_padding;
185*404b540aSrobert 
186*404b540aSrobert   /* True if we are skipping a failed conditional group.  */
187*404b540aSrobert   unsigned char skipping;
188*404b540aSrobert 
189*404b540aSrobert   /* Nonzero if in a directive that takes angle-bracketed headers.  */
190*404b540aSrobert   unsigned char angled_headers;
191*404b540aSrobert 
192*404b540aSrobert   /* Nonzero if in a #if or #elif directive.  */
193*404b540aSrobert   unsigned char in_expression;
194*404b540aSrobert 
195*404b540aSrobert   /* Nonzero to save comments.  Turned off if discard_comments, and in
196*404b540aSrobert      all directives apart from #define.  */
197*404b540aSrobert   unsigned char save_comments;
198*404b540aSrobert 
199*404b540aSrobert   /* Nonzero if lexing __VA_ARGS__ is valid.  */
200*404b540aSrobert   unsigned char va_args_ok;
201*404b540aSrobert 
202*404b540aSrobert   /* Nonzero if lexing poisoned identifiers is valid.  */
203*404b540aSrobert   unsigned char poisoned_ok;
204*404b540aSrobert 
205*404b540aSrobert   /* Nonzero to prevent macro expansion.  */
206*404b540aSrobert   unsigned char prevent_expansion;
207*404b540aSrobert 
208*404b540aSrobert   /* Nonzero when parsing arguments to a function-like macro.  */
209*404b540aSrobert   unsigned char parsing_args;
210*404b540aSrobert 
211*404b540aSrobert   /* Nonzero if prevent_expansion is true only because output is
212*404b540aSrobert      being discarded.  */
213*404b540aSrobert   unsigned char discarding_output;
214*404b540aSrobert 
215*404b540aSrobert   /* Nonzero to skip evaluating part of an expression.  */
216*404b540aSrobert   unsigned int skip_eval;
217*404b540aSrobert 
218*404b540aSrobert   /* Nonzero when handling a deferred pragma.  */
219*404b540aSrobert   unsigned char in_deferred_pragma;
220*404b540aSrobert 
221*404b540aSrobert   /* Nonzero if the deferred pragma being handled allows macro expansion.  */
222*404b540aSrobert   unsigned char pragma_allow_expansion;
223*404b540aSrobert };
224*404b540aSrobert 
225*404b540aSrobert /* Special nodes - identifiers with predefined significance.  */
226*404b540aSrobert struct spec_nodes
227*404b540aSrobert {
228*404b540aSrobert   cpp_hashnode *n_defined;		/* defined operator */
229*404b540aSrobert   cpp_hashnode *n_true;			/* C++ keyword true */
230*404b540aSrobert   cpp_hashnode *n_false;		/* C++ keyword false */
231*404b540aSrobert   cpp_hashnode *n__VA_ARGS__;		/* C99 vararg macros */
232*404b540aSrobert };
233*404b540aSrobert 
234*404b540aSrobert typedef struct _cpp_line_note _cpp_line_note;
235*404b540aSrobert struct _cpp_line_note
236*404b540aSrobert {
237*404b540aSrobert   /* Location in the clean line the note refers to.  */
238*404b540aSrobert   const unsigned char *pos;
239*404b540aSrobert 
240*404b540aSrobert   /* Type of note.  The 9 'from' trigraph characters represent those
241*404b540aSrobert      trigraphs, '\\' an escaped newline, ' ' an escaped newline with
242*404b540aSrobert      intervening space, and anything else is invalid.  */
243*404b540aSrobert   unsigned int type;
244*404b540aSrobert };
245*404b540aSrobert 
246*404b540aSrobert /* Represents the contents of a file cpplib has read in.  */
247*404b540aSrobert struct cpp_buffer
248*404b540aSrobert {
249*404b540aSrobert   const unsigned char *cur;        /* Current location.  */
250*404b540aSrobert   const unsigned char *line_base;  /* Start of current physical line.  */
251*404b540aSrobert   const unsigned char *next_line;  /* Start of to-be-cleaned logical line.  */
252*404b540aSrobert 
253*404b540aSrobert   const unsigned char *buf;        /* Entire character buffer.  */
254*404b540aSrobert   const unsigned char *rlimit;     /* Writable byte at end of file.  */
255*404b540aSrobert 
256*404b540aSrobert   _cpp_line_note *notes;           /* Array of notes.  */
257*404b540aSrobert   unsigned int cur_note;           /* Next note to process.  */
258*404b540aSrobert   unsigned int notes_used;         /* Number of notes.  */
259*404b540aSrobert   unsigned int notes_cap;          /* Size of allocated array.  */
260*404b540aSrobert 
261*404b540aSrobert   struct cpp_buffer *prev;
262*404b540aSrobert 
263*404b540aSrobert   /* Pointer into the file table; non-NULL if this is a file buffer.
264*404b540aSrobert      Used for include_next and to record control macros.  */
265*404b540aSrobert   struct _cpp_file *file;
266*404b540aSrobert 
267*404b540aSrobert   /* Saved value of __TIMESTAMP__ macro - date and time of last modification
268*404b540aSrobert      of the assotiated file.  */
269*404b540aSrobert   const unsigned char *timestamp;
270*404b540aSrobert 
271*404b540aSrobert   /* Value of if_stack at start of this file.
272*404b540aSrobert      Used to prohibit unmatched #endif (etc) in an include file.  */
273*404b540aSrobert   struct if_stack *if_stack;
274*404b540aSrobert 
275*404b540aSrobert   /* True if we need to get the next clean line.  */
276*404b540aSrobert   bool need_line;
277*404b540aSrobert 
278*404b540aSrobert   /* True if we have already warned about C++ comments in this file.
279*404b540aSrobert      The warning happens only for C89 extended mode with -pedantic on,
280*404b540aSrobert      or for -Wtraditional, and only once per file (otherwise it would
281*404b540aSrobert      be far too noisy).  */
282*404b540aSrobert   unsigned int warned_cplusplus_comments : 1;
283*404b540aSrobert 
284*404b540aSrobert   /* True if we don't process trigraphs and escaped newlines.  True
285*404b540aSrobert      for preprocessed input, command line directives, and _Pragma
286*404b540aSrobert      buffers.  */
287*404b540aSrobert   unsigned int from_stage3 : 1;
288*404b540aSrobert 
289*404b540aSrobert   /* At EOF, a buffer is automatically popped.  If RETURN_AT_EOF is
290*404b540aSrobert      true, a CPP_EOF token is then returned.  Otherwise, the next
291*404b540aSrobert      token from the enclosing buffer is returned.  */
292*404b540aSrobert   unsigned int return_at_eof : 1;
293*404b540aSrobert 
294*404b540aSrobert   /* One for a system header, two for a C system header file that therefore
295*404b540aSrobert      needs to be extern "C" protected in C++, and zero otherwise.  */
296*404b540aSrobert   unsigned char sysp;
297*404b540aSrobert 
298*404b540aSrobert   /* The directory of the this buffer's file.  Its NAME member is not
299*404b540aSrobert      allocated, so we don't need to worry about freeing it.  */
300*404b540aSrobert   struct cpp_dir dir;
301*404b540aSrobert 
302*404b540aSrobert   /* Descriptor for converting from the input character set to the
303*404b540aSrobert      source character set.  */
304*404b540aSrobert   struct cset_converter input_cset_desc;
305*404b540aSrobert };
306*404b540aSrobert 
307*404b540aSrobert /* A cpp_reader encapsulates the "state" of a pre-processor run.
308*404b540aSrobert    Applying cpp_get_token repeatedly yields a stream of pre-processor
309*404b540aSrobert    tokens.  Usually, there is only one cpp_reader object active.  */
310*404b540aSrobert struct cpp_reader
311*404b540aSrobert {
312*404b540aSrobert   /* Top of buffer stack.  */
313*404b540aSrobert   cpp_buffer *buffer;
314*404b540aSrobert 
315*404b540aSrobert   /* Overlaid buffer (can be different after processing #include).  */
316*404b540aSrobert   cpp_buffer *overlaid_buffer;
317*404b540aSrobert 
318*404b540aSrobert   /* Lexer state.  */
319*404b540aSrobert   struct lexer_state state;
320*404b540aSrobert 
321*404b540aSrobert   /* Source line tracking.  */
322*404b540aSrobert   struct line_maps *line_table;
323*404b540aSrobert 
324*404b540aSrobert   /* The line of the '#' of the current directive.  */
325*404b540aSrobert   source_location directive_line;
326*404b540aSrobert 
327*404b540aSrobert   /* Memory buffers.  */
328*404b540aSrobert   _cpp_buff *a_buff;		/* Aligned permanent storage.  */
329*404b540aSrobert   _cpp_buff *u_buff;		/* Unaligned permanent storage.  */
330*404b540aSrobert   _cpp_buff *free_buffs;	/* Free buffer chain.  */
331*404b540aSrobert 
332*404b540aSrobert   /* Context stack.  */
333*404b540aSrobert   struct cpp_context base_context;
334*404b540aSrobert   struct cpp_context *context;
335*404b540aSrobert 
336*404b540aSrobert   /* If in_directive, the directive if known.  */
337*404b540aSrobert   const struct directive *directive;
338*404b540aSrobert 
339*404b540aSrobert   /* Token generated while handling a directive, if any. */
340*404b540aSrobert   cpp_token directive_result;
341*404b540aSrobert 
342*404b540aSrobert   /* Search paths for include files.  */
343*404b540aSrobert   struct cpp_dir *quote_include;	/* "" */
344*404b540aSrobert   struct cpp_dir *bracket_include;	/* <> */
345*404b540aSrobert   struct cpp_dir no_search_path;	/* No path.  */
346*404b540aSrobert 
347*404b540aSrobert   /* Chain of all hashed _cpp_file instances.  */
348*404b540aSrobert   struct _cpp_file *all_files;
349*404b540aSrobert 
350*404b540aSrobert   struct _cpp_file *main_file;
351*404b540aSrobert 
352*404b540aSrobert   /* File and directory hash table.  */
353*404b540aSrobert   struct htab *file_hash;
354*404b540aSrobert   struct htab *dir_hash;
355*404b540aSrobert   struct file_hash_entry *file_hash_entries;
356*404b540aSrobert   unsigned int file_hash_entries_allocated, file_hash_entries_used;
357*404b540aSrobert 
358*404b540aSrobert   /* Nonzero means don't look for #include "foo" the source-file
359*404b540aSrobert      directory.  */
360*404b540aSrobert   bool quote_ignores_source_dir;
361*404b540aSrobert 
362*404b540aSrobert   /* Nonzero if any file has contained #pragma once or #import has
363*404b540aSrobert      been used.  */
364*404b540aSrobert   bool seen_once_only;
365*404b540aSrobert 
366*404b540aSrobert   /* Multiple include optimization.  */
367*404b540aSrobert   const cpp_hashnode *mi_cmacro;
368*404b540aSrobert   const cpp_hashnode *mi_ind_cmacro;
369*404b540aSrobert   bool mi_valid;
370*404b540aSrobert 
371*404b540aSrobert   /* Lexing.  */
372*404b540aSrobert   cpp_token *cur_token;
373*404b540aSrobert   tokenrun base_run, *cur_run;
374*404b540aSrobert   unsigned int lookaheads;
375*404b540aSrobert 
376*404b540aSrobert   /* Nonzero prevents the lexer from re-using the token runs.  */
377*404b540aSrobert   unsigned int keep_tokens;
378*404b540aSrobert 
379*404b540aSrobert   /* Error counter for exit code.  */
380*404b540aSrobert   unsigned int errors;
381*404b540aSrobert 
382*404b540aSrobert   /* Buffer to hold macro definition string.  */
383*404b540aSrobert   unsigned char *macro_buffer;
384*404b540aSrobert   unsigned int macro_buffer_len;
385*404b540aSrobert 
386*404b540aSrobert   /* Descriptor for converting from the source character set to the
387*404b540aSrobert      execution character set.  */
388*404b540aSrobert   struct cset_converter narrow_cset_desc;
389*404b540aSrobert 
390*404b540aSrobert   /* Descriptor for converting from the source character set to the
391*404b540aSrobert      wide execution character set.  */
392*404b540aSrobert   struct cset_converter wide_cset_desc;
393*404b540aSrobert 
394*404b540aSrobert   /* Date and time text.  Calculated together if either is requested.  */
395*404b540aSrobert   const unsigned char *date;
396*404b540aSrobert   const unsigned char *time;
397*404b540aSrobert 
398*404b540aSrobert   /* EOF token, and a token forcing paste avoidance.  */
399*404b540aSrobert   cpp_token avoid_paste;
400*404b540aSrobert   cpp_token eof;
401*404b540aSrobert 
402*404b540aSrobert   /* Opaque handle to the dependencies of mkdeps.c.  */
403*404b540aSrobert   struct deps *deps;
404*404b540aSrobert 
405*404b540aSrobert   /* Obstack holding all macro hash nodes.  This never shrinks.
406*404b540aSrobert      See identifiers.c */
407*404b540aSrobert   struct obstack hash_ob;
408*404b540aSrobert 
409*404b540aSrobert   /* Obstack holding buffer and conditional structures.  This is a
410*404b540aSrobert      real stack.  See directives.c.  */
411*404b540aSrobert   struct obstack buffer_ob;
412*404b540aSrobert 
413*404b540aSrobert   /* Pragma table - dynamic, because a library user can add to the
414*404b540aSrobert      list of recognized pragmas.  */
415*404b540aSrobert   struct pragma_entry *pragmas;
416*404b540aSrobert 
417*404b540aSrobert   /* Call backs to cpplib client.  */
418*404b540aSrobert   struct cpp_callbacks cb;
419*404b540aSrobert 
420*404b540aSrobert   /* Identifier hash table.  */
421*404b540aSrobert   struct ht *hash_table;
422*404b540aSrobert 
423*404b540aSrobert   /* Expression parser stack.  */
424*404b540aSrobert   struct op *op_stack, *op_limit;
425*404b540aSrobert 
426*404b540aSrobert   /* User visible options.  */
427*404b540aSrobert   struct cpp_options opts;
428*404b540aSrobert 
429*404b540aSrobert   /* Special nodes - identifiers with predefined significance to the
430*404b540aSrobert      preprocessor.  */
431*404b540aSrobert   struct spec_nodes spec_nodes;
432*404b540aSrobert 
433*404b540aSrobert   /* Whether cpplib owns the hashtable.  */
434*404b540aSrobert   bool our_hashtable;
435*404b540aSrobert 
436*404b540aSrobert   /* Traditional preprocessing output buffer (a logical line).  */
437*404b540aSrobert   struct
438*404b540aSrobert   {
439*404b540aSrobert     unsigned char *base;
440*404b540aSrobert     unsigned char *limit;
441*404b540aSrobert     unsigned char *cur;
442*404b540aSrobert     source_location first_line;
443*404b540aSrobert   } out;
444*404b540aSrobert 
445*404b540aSrobert   /* Used for buffer overlays by traditional.c.  */
446*404b540aSrobert   const unsigned char *saved_cur, *saved_rlimit, *saved_line_base;
447*404b540aSrobert 
448*404b540aSrobert   /* A saved list of the defined macros, for dependency checking
449*404b540aSrobert      of precompiled headers.  */
450*404b540aSrobert   struct cpp_savedstate *savedstate;
451*404b540aSrobert };
452*404b540aSrobert 
453*404b540aSrobert /* Character classes.  Based on the more primitive macros in safe-ctype.h.
454*404b540aSrobert    If the definition of `numchar' looks odd to you, please look up the
455*404b540aSrobert    definition of a pp-number in the C standard [section 6.4.8 of C99].
456*404b540aSrobert 
457*404b540aSrobert    In the unlikely event that characters other than \r and \n enter
458*404b540aSrobert    the set is_vspace, the macro handle_newline() in lex.c must be
459*404b540aSrobert    updated.  */
460*404b540aSrobert #define _dollar_ok(x)	((x) == '$' && CPP_OPTION (pfile, dollars_in_ident))
461*404b540aSrobert 
462*404b540aSrobert #define is_idchar(x)	(ISIDNUM(x) || _dollar_ok(x))
463*404b540aSrobert #define is_numchar(x)	ISIDNUM(x)
464*404b540aSrobert #define is_idstart(x)	(ISIDST(x) || _dollar_ok(x))
465*404b540aSrobert #define is_numstart(x)	ISDIGIT(x)
466*404b540aSrobert #define is_hspace(x)	ISBLANK(x)
467*404b540aSrobert #define is_vspace(x)	IS_VSPACE(x)
468*404b540aSrobert #define is_nvspace(x)	IS_NVSPACE(x)
469*404b540aSrobert #define is_space(x)	IS_SPACE_OR_NUL(x)
470*404b540aSrobert 
471*404b540aSrobert /* This table is constant if it can be initialized at compile time,
472*404b540aSrobert    which is the case if cpp was compiled with GCC >=2.7, or another
473*404b540aSrobert    compiler that supports C99.  */
474*404b540aSrobert #if HAVE_DESIGNATED_INITIALIZERS
475*404b540aSrobert extern const unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
476*404b540aSrobert #else
477*404b540aSrobert extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
478*404b540aSrobert #endif
479*404b540aSrobert 
480*404b540aSrobert /* Macros.  */
481*404b540aSrobert 
482*404b540aSrobert static inline int cpp_in_system_header (cpp_reader *);
483*404b540aSrobert static inline int
cpp_in_system_header(cpp_reader * pfile)484*404b540aSrobert cpp_in_system_header (cpp_reader *pfile)
485*404b540aSrobert {
486*404b540aSrobert   return pfile->buffer ? pfile->buffer->sysp : 0;
487*404b540aSrobert }
488*404b540aSrobert #define CPP_PEDANTIC(PF) CPP_OPTION (PF, pedantic)
489*404b540aSrobert #define CPP_WTRADITIONAL(PF) CPP_OPTION (PF, warn_traditional)
490*404b540aSrobert 
491*404b540aSrobert /* In errors.c  */
492*404b540aSrobert extern int _cpp_begin_message (cpp_reader *, int,
493*404b540aSrobert 			       source_location, unsigned int);
494*404b540aSrobert 
495*404b540aSrobert /* In macro.c */
496*404b540aSrobert extern void _cpp_free_definition (cpp_hashnode *);
497*404b540aSrobert extern bool _cpp_create_definition (cpp_reader *, cpp_hashnode *);
498*404b540aSrobert extern void _cpp_pop_context (cpp_reader *);
499*404b540aSrobert extern void _cpp_push_text_context (cpp_reader *, cpp_hashnode *,
500*404b540aSrobert 				    const unsigned char *, size_t);
501*404b540aSrobert extern bool _cpp_save_parameter (cpp_reader *, cpp_macro *, cpp_hashnode *);
502*404b540aSrobert extern bool _cpp_arguments_ok (cpp_reader *, cpp_macro *, const cpp_hashnode *,
503*404b540aSrobert 			       unsigned int);
504*404b540aSrobert extern const unsigned char *_cpp_builtin_macro_text (cpp_reader *,
505*404b540aSrobert 						     cpp_hashnode *);
506*404b540aSrobert extern int _cpp_warn_if_unused_macro (cpp_reader *, cpp_hashnode *, void *);
507*404b540aSrobert extern void _cpp_push_token_context (cpp_reader *, cpp_hashnode *,
508*404b540aSrobert 				     const cpp_token *, unsigned int);
509*404b540aSrobert 
510*404b540aSrobert /* In identifiers.c */
511*404b540aSrobert extern void _cpp_init_hashtable (cpp_reader *, hash_table *);
512*404b540aSrobert extern void _cpp_destroy_hashtable (cpp_reader *);
513*404b540aSrobert 
514*404b540aSrobert /* In files.c */
515*404b540aSrobert typedef struct _cpp_file _cpp_file;
516*404b540aSrobert extern _cpp_file *_cpp_find_file (cpp_reader *, const char *, cpp_dir *,
517*404b540aSrobert 				  bool, int);
518*404b540aSrobert extern bool _cpp_find_failed (_cpp_file *);
519*404b540aSrobert extern void _cpp_mark_file_once_only (cpp_reader *, struct _cpp_file *);
520*404b540aSrobert extern void _cpp_fake_include (cpp_reader *, const char *);
521*404b540aSrobert extern bool _cpp_stack_file (cpp_reader *, _cpp_file*, bool);
522*404b540aSrobert extern bool _cpp_stack_include (cpp_reader *, const char *, int,
523*404b540aSrobert 				enum include_type);
524*404b540aSrobert extern int _cpp_compare_file_date (cpp_reader *, const char *, int);
525*404b540aSrobert extern void _cpp_report_missing_guards (cpp_reader *);
526*404b540aSrobert extern void _cpp_init_files (cpp_reader *);
527*404b540aSrobert extern void _cpp_cleanup_files (cpp_reader *);
528*404b540aSrobert extern void _cpp_pop_file_buffer (cpp_reader *, struct _cpp_file *);
529*404b540aSrobert extern bool _cpp_save_file_entries (cpp_reader *pfile, FILE *f);
530*404b540aSrobert extern bool _cpp_read_file_entries (cpp_reader *, FILE *);
531*404b540aSrobert extern struct stat *_cpp_get_file_stat (_cpp_file *);
532*404b540aSrobert 
533*404b540aSrobert /* In expr.c */
534*404b540aSrobert extern bool _cpp_parse_expr (cpp_reader *);
535*404b540aSrobert extern struct op *_cpp_expand_op_stack (cpp_reader *);
536*404b540aSrobert 
537*404b540aSrobert /* In lex.c */
538*404b540aSrobert extern void _cpp_process_line_notes (cpp_reader *, int);
539*404b540aSrobert extern void _cpp_clean_line (cpp_reader *);
540*404b540aSrobert extern bool _cpp_get_fresh_line (cpp_reader *);
541*404b540aSrobert extern bool _cpp_skip_block_comment (cpp_reader *);
542*404b540aSrobert extern cpp_token *_cpp_temp_token (cpp_reader *);
543*404b540aSrobert extern const cpp_token *_cpp_lex_token (cpp_reader *);
544*404b540aSrobert extern cpp_token *_cpp_lex_direct (cpp_reader *);
545*404b540aSrobert extern int _cpp_equiv_tokens (const cpp_token *, const cpp_token *);
546*404b540aSrobert extern void _cpp_init_tokenrun (tokenrun *, unsigned int);
547*404b540aSrobert 
548*404b540aSrobert /* In init.c.  */
549*404b540aSrobert extern void _cpp_maybe_push_include_file (cpp_reader *);
550*404b540aSrobert 
551*404b540aSrobert /* In directives.c */
552*404b540aSrobert extern int _cpp_test_assertion (cpp_reader *, unsigned int *);
553*404b540aSrobert extern int _cpp_handle_directive (cpp_reader *, int);
554*404b540aSrobert extern void _cpp_define_builtin (cpp_reader *, const char *);
555*404b540aSrobert extern char ** _cpp_save_pragma_names (cpp_reader *);
556*404b540aSrobert extern void _cpp_restore_pragma_names (cpp_reader *, char **);
557*404b540aSrobert extern void _cpp_do__Pragma (cpp_reader *);
558*404b540aSrobert extern void _cpp_init_directives (cpp_reader *);
559*404b540aSrobert extern void _cpp_init_internal_pragmas (cpp_reader *);
560*404b540aSrobert extern void _cpp_do_file_change (cpp_reader *, enum lc_reason, const char *,
561*404b540aSrobert 				 unsigned int, unsigned int);
562*404b540aSrobert extern void _cpp_pop_buffer (cpp_reader *);
563*404b540aSrobert 
564*404b540aSrobert /* In traditional.c.  */
565*404b540aSrobert extern bool _cpp_scan_out_logical_line (cpp_reader *, cpp_macro *);
566*404b540aSrobert extern bool _cpp_read_logical_line_trad (cpp_reader *);
567*404b540aSrobert extern void _cpp_overlay_buffer (cpp_reader *pfile, const unsigned char *,
568*404b540aSrobert 				 size_t);
569*404b540aSrobert extern void _cpp_remove_overlay (cpp_reader *);
570*404b540aSrobert extern bool _cpp_create_trad_definition (cpp_reader *, cpp_macro *);
571*404b540aSrobert extern bool _cpp_expansions_different_trad (const cpp_macro *,
572*404b540aSrobert 					    const cpp_macro *);
573*404b540aSrobert extern unsigned char *_cpp_copy_replacement_text (const cpp_macro *,
574*404b540aSrobert 						  unsigned char *);
575*404b540aSrobert extern size_t _cpp_replacement_text_len (const cpp_macro *);
576*404b540aSrobert 
577*404b540aSrobert /* In charset.c.  */
578*404b540aSrobert 
579*404b540aSrobert /* The normalization state at this point in the sequence.
580*404b540aSrobert    It starts initialized to all zeros, and at the end
581*404b540aSrobert    'level' is the normalization level of the sequence.  */
582*404b540aSrobert 
583*404b540aSrobert struct normalize_state
584*404b540aSrobert {
585*404b540aSrobert   /* The previous character.  */
586*404b540aSrobert   cppchar_t previous;
587*404b540aSrobert   /* The combining class of the previous character.  */
588*404b540aSrobert   unsigned char prev_class;
589*404b540aSrobert   /* The lowest normalization level so far.  */
590*404b540aSrobert   enum cpp_normalize_level level;
591*404b540aSrobert };
592*404b540aSrobert #define INITIAL_NORMALIZE_STATE { 0, 0, normalized_KC }
593*404b540aSrobert #define NORMALIZE_STATE_RESULT(st) ((st)->level)
594*404b540aSrobert 
595*404b540aSrobert /* We saw a character that matches ISIDNUM(), update a
596*404b540aSrobert    normalize_state appropriately.  */
597*404b540aSrobert #define NORMALIZE_STATE_UPDATE_IDNUM(st) \
598*404b540aSrobert   ((st)->previous = 0, (st)->prev_class = 0)
599*404b540aSrobert 
600*404b540aSrobert extern cppchar_t _cpp_valid_ucn (cpp_reader *, const unsigned char **,
601*404b540aSrobert 				 const unsigned char *, int,
602*404b540aSrobert 				 struct normalize_state *state);
603*404b540aSrobert extern void _cpp_destroy_iconv (cpp_reader *);
604*404b540aSrobert extern unsigned char *_cpp_convert_input (cpp_reader *, const char *,
605*404b540aSrobert 					  unsigned char *, size_t, size_t,
606*404b540aSrobert 					  off_t *);
607*404b540aSrobert extern const char *_cpp_default_encoding (void);
608*404b540aSrobert extern cpp_hashnode * _cpp_interpret_identifier (cpp_reader *pfile,
609*404b540aSrobert 						 const unsigned char *id,
610*404b540aSrobert 						 size_t len);
611*404b540aSrobert 
612*404b540aSrobert /* Utility routines and macros.  */
613*404b540aSrobert #define DSC(str) (const unsigned char *)str, sizeof str - 1
614*404b540aSrobert 
615*404b540aSrobert /* These are inline functions instead of macros so we can get type
616*404b540aSrobert    checking.  */
617*404b540aSrobert static inline int ustrcmp (const unsigned char *, const unsigned char *);
618*404b540aSrobert static inline int ustrncmp (const unsigned char *, const unsigned char *,
619*404b540aSrobert 			    size_t);
620*404b540aSrobert static inline size_t ustrlen (const unsigned char *);
621*404b540aSrobert static inline unsigned char *uxstrdup (const unsigned char *);
622*404b540aSrobert static inline unsigned char *ustrchr (const unsigned char *, int);
623*404b540aSrobert static inline int ufputs (const unsigned char *, FILE *);
624*404b540aSrobert 
625*404b540aSrobert /* Use a const char for the second parameter since it is usually a literal.  */
626*404b540aSrobert static inline int ustrcspn (const unsigned char *, const char *);
627*404b540aSrobert 
628*404b540aSrobert static inline int
ustrcmp(const unsigned char * s1,const unsigned char * s2)629*404b540aSrobert ustrcmp (const unsigned char *s1, const unsigned char *s2)
630*404b540aSrobert {
631*404b540aSrobert   return strcmp ((const char *)s1, (const char *)s2);
632*404b540aSrobert }
633*404b540aSrobert 
634*404b540aSrobert static inline int
ustrncmp(const unsigned char * s1,const unsigned char * s2,size_t n)635*404b540aSrobert ustrncmp (const unsigned char *s1, const unsigned char *s2, size_t n)
636*404b540aSrobert {
637*404b540aSrobert   return strncmp ((const char *)s1, (const char *)s2, n);
638*404b540aSrobert }
639*404b540aSrobert 
640*404b540aSrobert static inline int
ustrcspn(const unsigned char * s1,const char * s2)641*404b540aSrobert ustrcspn (const unsigned char *s1, const char *s2)
642*404b540aSrobert {
643*404b540aSrobert   return strcspn ((const char *)s1, s2);
644*404b540aSrobert }
645*404b540aSrobert 
646*404b540aSrobert static inline size_t
ustrlen(const unsigned char * s1)647*404b540aSrobert ustrlen (const unsigned char *s1)
648*404b540aSrobert {
649*404b540aSrobert   return strlen ((const char *)s1);
650*404b540aSrobert }
651*404b540aSrobert 
652*404b540aSrobert static inline unsigned char *
uxstrdup(const unsigned char * s1)653*404b540aSrobert uxstrdup (const unsigned char *s1)
654*404b540aSrobert {
655*404b540aSrobert   return (unsigned char *) xstrdup ((const char *)s1);
656*404b540aSrobert }
657*404b540aSrobert 
658*404b540aSrobert static inline unsigned char *
ustrchr(const unsigned char * s1,int c)659*404b540aSrobert ustrchr (const unsigned char *s1, int c)
660*404b540aSrobert {
661*404b540aSrobert   return (unsigned char *) strchr ((const char *)s1, c);
662*404b540aSrobert }
663*404b540aSrobert 
664*404b540aSrobert static inline int
ufputs(const unsigned char * s,FILE * f)665*404b540aSrobert ufputs (const unsigned char *s, FILE *f)
666*404b540aSrobert {
667*404b540aSrobert   return fputs ((const char *)s, f);
668*404b540aSrobert }
669*404b540aSrobert 
670*404b540aSrobert #endif /* ! LIBCPP_INTERNAL_H */
671