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