00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef LIBCPP_INTERNAL_H
00024 #define LIBCPP_INTERNAL_H
00025
00026 #include "symtab.h"
00027 #include "cpp-id-data.h"
00028
00029 #ifndef HAVE_ICONV_H
00030 #undef HAVE_ICONV
00031 #endif
00032
00033 #if HAVE_ICONV
00034 #include <iconv.h>
00035 #else
00036 #define HAVE_ICONV 0
00037 typedef int iconv_t;
00038 #endif
00039
00040 struct directive;
00041 struct pending_option;
00042 struct op;
00043 struct _cpp_strbuf;
00044
00045 typedef bool (*convert_f) (iconv_t, const unsigned char *, size_t,
00046 struct _cpp_strbuf *);
00047 struct cset_converter
00048 {
00049 convert_f func;
00050 iconv_t cd;
00051 };
00052
00053 #define BITS_PER_CPPCHAR_T (CHAR_BIT * sizeof (cppchar_t))
00054
00055
00056 #define VALID_SIGN(c, prevc) \
00057 (((c) == '+' || (c) == '-') && \
00058 ((prevc) == 'e' || (prevc) == 'E' \
00059 || (((prevc) == 'p' || (prevc) == 'P') \
00060 && CPP_OPTION (pfile, extended_numbers))))
00061
00062 #define CPP_OPTION(PFILE, OPTION) ((PFILE)->opts.OPTION)
00063 #define CPP_BUFFER(PFILE) ((PFILE)->buffer)
00064 #define CPP_BUF_COLUMN(BUF, CUR) ((CUR) - (BUF)->line_base)
00065 #define CPP_BUF_COL(BUF) CPP_BUF_COLUMN(BUF, (BUF)->cur)
00066
00067 #define CPP_INCREMENT_LINE(PFILE, COLS_HINT) do { \
00068 const struct line_maps *line_table = PFILE->line_table; \
00069 const struct line_map *map = &line_table->maps[line_table->used-1]; \
00070 unsigned int line = SOURCE_LINE (map, line_table->highest_line); \
00071 linemap_line_start (PFILE->line_table, line + 1, COLS_HINT); \
00072 } while (0)
00073
00074
00075
00076 #define CPP_STACK_MAX 200
00077
00078
00079 struct dummy
00080 {
00081 char c;
00082 union
00083 {
00084 double d;
00085 int *p;
00086 } u;
00087 };
00088
00089 #define DEFAULT_ALIGNMENT offsetof (struct dummy, u)
00090 #define CPP_ALIGN2(size, align) (((size) + ((align) - 1)) & ~((align) - 1))
00091 #define CPP_ALIGN(size) CPP_ALIGN2 (size, DEFAULT_ALIGNMENT)
00092
00093 #define _cpp_mark_macro_used(NODE) do { \
00094 if ((NODE)->type == NT_MACRO && !((NODE)->flags & NODE_BUILTIN)) \
00095 (NODE)->value.macro->used = 1; } while (0)
00096
00097
00098 typedef struct _cpp_buff _cpp_buff;
00099 struct _cpp_buff
00100 {
00101 struct _cpp_buff *next;
00102 unsigned char *base, *cur, *limit;
00103 };
00104
00105 extern _cpp_buff *_cpp_get_buff (cpp_reader *, size_t);
00106 extern void _cpp_release_buff (cpp_reader *, _cpp_buff *);
00107 extern void _cpp_extend_buff (cpp_reader *, _cpp_buff **, size_t);
00108 extern _cpp_buff *_cpp_append_extend_buff (cpp_reader *, _cpp_buff *, size_t);
00109 extern void _cpp_free_buff (_cpp_buff *);
00110 extern unsigned char *_cpp_aligned_alloc (cpp_reader *, size_t);
00111 extern unsigned char *_cpp_unaligned_alloc (cpp_reader *, size_t);
00112
00113 #define BUFF_ROOM(BUFF) (size_t) ((BUFF)->limit - (BUFF)->cur)
00114 #define BUFF_FRONT(BUFF) ((BUFF)->cur)
00115 #define BUFF_LIMIT(BUFF) ((BUFF)->limit)
00116
00117
00118 enum include_type {IT_INCLUDE, IT_INCLUDE_NEXT, IT_IMPORT, IT_CMDLINE};
00119
00120 union utoken
00121 {
00122 const cpp_token *token;
00123 const cpp_token **ptoken;
00124 };
00125
00126
00127 typedef struct tokenrun tokenrun;
00128 struct tokenrun
00129 {
00130 tokenrun *next, *prev;
00131 cpp_token *base, *limit;
00132 };
00133
00134
00135 #define FIRST(c) ((c)->u.iso.first)
00136 #define LAST(c) ((c)->u.iso.last)
00137 #define CUR(c) ((c)->u.trad.cur)
00138 #define RLIMIT(c) ((c)->u.trad.rlimit)
00139
00140 typedef struct cpp_context cpp_context;
00141 struct cpp_context
00142 {
00143
00144 cpp_context *next, *prev;
00145
00146 union
00147 {
00148
00149
00150
00151 struct
00152 {
00153 union utoken first;
00154 union utoken last;
00155 } iso;
00156
00157
00158 struct
00159 {
00160 const unsigned char *cur;
00161 const unsigned char *rlimit;
00162 } trad;
00163 } u;
00164
00165
00166
00167 _cpp_buff *buff;
00168
00169
00170 cpp_hashnode *macro;
00171
00172
00173 bool direct_p;
00174 };
00175
00176 struct lexer_state
00177 {
00178
00179 unsigned char in_directive;
00180
00181
00182
00183
00184 unsigned char directive_wants_padding;
00185
00186
00187 unsigned char skipping;
00188
00189
00190 unsigned char angled_headers;
00191
00192
00193 unsigned char in_expression;
00194
00195
00196
00197 unsigned char save_comments;
00198
00199
00200 unsigned char va_args_ok;
00201
00202
00203 unsigned char poisoned_ok;
00204
00205
00206 unsigned char prevent_expansion;
00207
00208
00209 unsigned char parsing_args;
00210
00211
00212
00213 unsigned char discarding_output;
00214
00215
00216 unsigned int skip_eval;
00217
00218
00219 unsigned char in_deferred_pragma;
00220
00221
00222 unsigned char pragma_allow_expansion;
00223 };
00224
00225
00226 struct spec_nodes
00227 {
00228 cpp_hashnode *n_defined;
00229 cpp_hashnode *n_true;
00230 cpp_hashnode *n_false;
00231 cpp_hashnode *n__VA_ARGS__;
00232 };
00233
00234 typedef struct _cpp_line_note _cpp_line_note;
00235 struct _cpp_line_note
00236 {
00237
00238 const unsigned char *pos;
00239
00240
00241
00242
00243 unsigned int type;
00244 };
00245
00246
00247 struct cpp_buffer
00248 {
00249 const unsigned char *cur;
00250 const unsigned char *line_base;
00251 const unsigned char *next_line;
00252
00253 const unsigned char *buf;
00254 const unsigned char *rlimit;
00255
00256 _cpp_line_note *notes;
00257 unsigned int cur_note;
00258 unsigned int notes_used;
00259 unsigned int notes_cap;
00260
00261 struct cpp_buffer *prev;
00262
00263
00264
00265 struct _cpp_file *file;
00266
00267
00268
00269 const unsigned char *timestamp;
00270
00271
00272
00273 struct if_stack *if_stack;
00274
00275
00276 bool need_line;
00277
00278
00279
00280
00281
00282 unsigned int warned_cplusplus_comments : 1;
00283
00284
00285
00286
00287 unsigned int from_stage3 : 1;
00288
00289
00290
00291
00292 unsigned int return_at_eof : 1;
00293
00294
00295
00296 unsigned char sysp;
00297
00298
00299
00300 struct cpp_dir dir;
00301
00302
00303
00304 struct cset_converter input_cset_desc;
00305 };
00306
00307
00308
00309
00310 struct cpp_reader
00311 {
00312
00313 cpp_buffer *buffer;
00314
00315
00316 cpp_buffer *overlaid_buffer;
00317
00318
00319 struct lexer_state state;
00320
00321
00322 struct line_maps *line_table;
00323
00324
00325 source_location directive_line;
00326
00327
00328 _cpp_buff *a_buff;
00329 _cpp_buff *u_buff;
00330 _cpp_buff *free_buffs;
00331
00332
00333 struct cpp_context base_context;
00334 struct cpp_context *context;
00335
00336
00337 const struct directive *directive;
00338
00339
00340 cpp_token directive_result;
00341
00342
00343 struct cpp_dir *quote_include;
00344 struct cpp_dir *bracket_include;
00345 struct cpp_dir no_search_path;
00346
00347
00348 struct _cpp_file *all_files;
00349
00350 struct _cpp_file *main_file;
00351
00352
00353 struct htab *file_hash;
00354 struct htab *dir_hash;
00355 struct file_hash_entry *file_hash_entries;
00356 unsigned int file_hash_entries_allocated, file_hash_entries_used;
00357
00358
00359
00360 bool quote_ignores_source_dir;
00361
00362
00363
00364 bool seen_once_only;
00365
00366
00367 const cpp_hashnode *mi_cmacro;
00368 const cpp_hashnode *mi_ind_cmacro;
00369 bool mi_valid;
00370
00371
00372 cpp_token *cur_token;
00373 tokenrun base_run, *cur_run;
00374 unsigned int lookaheads;
00375
00376
00377 unsigned int keep_tokens;
00378
00379
00380 unsigned int errors;
00381
00382
00383 unsigned char *macro_buffer;
00384 unsigned int macro_buffer_len;
00385
00386
00387
00388 struct cset_converter narrow_cset_desc;
00389
00390
00391
00392 struct cset_converter wide_cset_desc;
00393
00394
00395 const unsigned char *date;
00396 const unsigned char *time;
00397
00398
00399 cpp_token avoid_paste;
00400 cpp_token eof;
00401
00402
00403 struct deps *deps;
00404
00405
00406
00407 struct obstack hash_ob;
00408
00409
00410
00411 struct obstack buffer_ob;
00412
00413
00414
00415 struct pragma_entry *pragmas;
00416
00417
00418 struct cpp_callbacks cb;
00419
00420
00421 struct ht *hash_table;
00422
00423
00424 struct op *op_stack, *op_limit;
00425
00426
00427 struct cpp_options opts;
00428
00429
00430
00431 struct spec_nodes spec_nodes;
00432
00433
00434 bool our_hashtable;
00435
00436
00437 struct
00438 {
00439 unsigned char *base;
00440 unsigned char *limit;
00441 unsigned char *cur;
00442 source_location first_line;
00443 } out;
00444
00445
00446 const unsigned char *saved_cur, *saved_rlimit, *saved_line_base;
00447
00448
00449
00450 struct cpp_savedstate *savedstate;
00451 };
00452
00453
00454
00455
00456
00457
00458
00459
00460 #define _dollar_ok(x) ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident))
00461
00462 #define is_idchar(x) (ISIDNUM(x) || _dollar_ok(x))
00463 #define is_numchar(x) ISIDNUM(x)
00464 #define is_idstart(x) (ISIDST(x) || _dollar_ok(x))
00465 #define is_numstart(x) ISDIGIT(x)
00466 #define is_hspace(x) ISBLANK(x)
00467 #define is_vspace(x) IS_VSPACE(x)
00468 #define is_nvspace(x) IS_NVSPACE(x)
00469 #define is_space(x) IS_SPACE_OR_NUL(x)
00470
00471
00472
00473
00474 #if HAVE_DESIGNATED_INITIALIZERS
00475 extern const unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
00476 #else
00477 extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
00478 #endif
00479
00480
00481
00482 static inline int cpp_in_system_header (cpp_reader *);
00483 static inline int
00484 cpp_in_system_header (cpp_reader *pfile)
00485 {
00486 return pfile->buffer ? pfile->buffer->sysp : 0;
00487 }
00488 #define CPP_PEDANTIC(PF) CPP_OPTION (PF, pedantic)
00489 #define CPP_WTRADITIONAL(PF) CPP_OPTION (PF, warn_traditional)
00490
00491
00492 extern int _cpp_begin_message (cpp_reader *, int,
00493 source_location, unsigned int);
00494
00495
00496 extern void _cpp_free_definition (cpp_hashnode *);
00497 extern bool _cpp_create_definition (cpp_reader *, cpp_hashnode *);
00498 extern void _cpp_pop_context (cpp_reader *);
00499 extern void _cpp_push_text_context (cpp_reader *, cpp_hashnode *,
00500 const unsigned char *, size_t);
00501 extern bool _cpp_save_parameter (cpp_reader *, cpp_macro *, cpp_hashnode *);
00502 extern bool _cpp_arguments_ok (cpp_reader *, cpp_macro *, const cpp_hashnode *,
00503 unsigned int);
00504 extern const unsigned char *_cpp_builtin_macro_text (cpp_reader *,
00505 cpp_hashnode *);
00506 extern int _cpp_warn_if_unused_macro (cpp_reader *, cpp_hashnode *, void *);
00507 extern void _cpp_push_token_context (cpp_reader *, cpp_hashnode *,
00508 const cpp_token *, unsigned int);
00509
00510
00511 extern void _cpp_init_hashtable (cpp_reader *, hash_table *);
00512 extern void _cpp_destroy_hashtable (cpp_reader *);
00513
00514
00515 typedef struct _cpp_file _cpp_file;
00516 extern _cpp_file *_cpp_find_file (cpp_reader *, const char *, cpp_dir *,
00517 bool, int);
00518 extern bool _cpp_find_failed (_cpp_file *);
00519 extern void _cpp_mark_file_once_only (cpp_reader *, struct _cpp_file *);
00520 extern void _cpp_fake_include (cpp_reader *, const char *);
00521 extern bool _cpp_stack_file (cpp_reader *, _cpp_file*, bool);
00522 extern bool _cpp_stack_include (cpp_reader *, const char *, int,
00523 enum include_type);
00524 extern int _cpp_compare_file_date (cpp_reader *, const char *, int);
00525 extern void _cpp_report_missing_guards (cpp_reader *);
00526 extern void _cpp_init_files (cpp_reader *);
00527 extern void _cpp_cleanup_files (cpp_reader *);
00528 extern void _cpp_pop_file_buffer (cpp_reader *, struct _cpp_file *);
00529 extern bool _cpp_save_file_entries (cpp_reader *pfile, FILE *f);
00530 extern bool _cpp_read_file_entries (cpp_reader *, FILE *);
00531 extern struct stat *_cpp_get_file_stat (_cpp_file *);
00532
00533
00534 extern bool _cpp_parse_expr (cpp_reader *);
00535 extern struct op *_cpp_expand_op_stack (cpp_reader *);
00536
00537
00538 extern void _cpp_process_line_notes (cpp_reader *, int);
00539 extern void _cpp_clean_line (cpp_reader *);
00540 extern bool _cpp_get_fresh_line (cpp_reader *);
00541 extern bool _cpp_skip_block_comment (cpp_reader *);
00542 extern cpp_token *_cpp_temp_token (cpp_reader *);
00543 extern const cpp_token *_cpp_lex_token (cpp_reader *);
00544 extern cpp_token *_cpp_lex_direct (cpp_reader *);
00545 extern int _cpp_equiv_tokens (const cpp_token *, const cpp_token *);
00546 extern void _cpp_init_tokenrun (tokenrun *, unsigned int);
00547
00548
00549 extern void _cpp_maybe_push_include_file (cpp_reader *);
00550
00551
00552 extern int _cpp_test_assertion (cpp_reader *, unsigned int *);
00553 extern int _cpp_handle_directive (cpp_reader *, int);
00554 extern void _cpp_define_builtin (cpp_reader *, const char *);
00555 extern char ** _cpp_save_pragma_names (cpp_reader *);
00556 extern void _cpp_restore_pragma_names (cpp_reader *, char **);
00557 extern void _cpp_do__Pragma (cpp_reader *);
00558 extern void _cpp_init_directives (cpp_reader *);
00559 extern void _cpp_init_internal_pragmas (cpp_reader *);
00560 extern void _cpp_do_file_change (cpp_reader *, enum lc_reason, const char *,
00561 unsigned int, unsigned int);
00562 extern void _cpp_pop_buffer (cpp_reader *);
00563
00564
00565 extern bool _cpp_scan_out_logical_line (cpp_reader *, cpp_macro *);
00566 extern bool _cpp_read_logical_line_trad (cpp_reader *);
00567 extern void _cpp_overlay_buffer (cpp_reader *pfile, const unsigned char *,
00568 size_t);
00569 extern void _cpp_remove_overlay (cpp_reader *);
00570 extern bool _cpp_create_trad_definition (cpp_reader *, cpp_macro *);
00571 extern bool _cpp_expansions_different_trad (const cpp_macro *,
00572 const cpp_macro *);
00573 extern unsigned char *_cpp_copy_replacement_text (const cpp_macro *,
00574 unsigned char *);
00575 extern size_t _cpp_replacement_text_len (const cpp_macro *);
00576
00577
00578
00579
00580
00581
00582
00583 struct normalize_state
00584 {
00585
00586 cppchar_t previous;
00587
00588 unsigned char prev_class;
00589
00590 enum cpp_normalize_level level;
00591 };
00592 #define INITIAL_NORMALIZE_STATE { 0, 0, normalized_KC }
00593 #define NORMALIZE_STATE_RESULT(st) ((st)->level)
00594
00595
00596
00597 #define NORMALIZE_STATE_UPDATE_IDNUM(st) \
00598 ((st)->previous = 0, (st)->prev_class = 0)
00599
00600 extern cppchar_t _cpp_valid_ucn (cpp_reader *, const unsigned char **,
00601 const unsigned char *, int,
00602 struct normalize_state *state);
00603 extern void _cpp_destroy_iconv (cpp_reader *);
00604 extern unsigned char *_cpp_convert_input (cpp_reader *, const char *,
00605 unsigned char *, size_t, size_t,
00606 off_t *);
00607 extern const char *_cpp_default_encoding (void);
00608 extern cpp_hashnode * _cpp_interpret_identifier (cpp_reader *pfile,
00609 const unsigned char *id,
00610 size_t len);
00611
00612
00613 #define DSC(str) (const unsigned char *)str, sizeof str - 1
00614
00615
00616
00617 static inline int ustrcmp (const unsigned char *, const unsigned char *);
00618 static inline int ustrncmp (const unsigned char *, const unsigned char *,
00619 size_t);
00620 static inline size_t ustrlen (const unsigned char *);
00621 static inline unsigned char *uxstrdup (const unsigned char *);
00622 static inline unsigned char *ustrchr (const unsigned char *, int);
00623 static inline int ufputs (const unsigned char *, FILE *);
00624
00625
00626 static inline int ustrcspn (const unsigned char *, const char *);
00627
00628 static inline int
00629 ustrcmp (const unsigned char *s1, const unsigned char *s2)
00630 {
00631 return strcmp ((const char *)s1, (const char *)s2);
00632 }
00633
00634 static inline int
00635 ustrncmp (const unsigned char *s1, const unsigned char *s2, size_t n)
00636 {
00637 return strncmp ((const char *)s1, (const char *)s2, n);
00638 }
00639
00640 static inline int
00641 ustrcspn (const unsigned char *s1, const char *s2)
00642 {
00643 return strcspn ((const char *)s1, s2);
00644 }
00645
00646 static inline size_t
00647 ustrlen (const unsigned char *s1)
00648 {
00649 return strlen ((const char *)s1);
00650 }
00651
00652 static inline unsigned char *
00653 uxstrdup (const unsigned char *s1)
00654 {
00655 return (unsigned char *) xstrdup ((const char *)s1);
00656 }
00657
00658 static inline unsigned char *
00659 ustrchr (const unsigned char *s1, int c)
00660 {
00661 return (unsigned char *) strchr ((const char *)s1, c);
00662 }
00663
00664 static inline int
00665 ufputs (const unsigned char *s, FILE *f)
00666 {
00667 return fputs ((const char *)s, f);
00668 }
00669
00670 #endif