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