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