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