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 in_deferred_pragma;
00210
00211
00212 unsigned char parsing_args;
00213
00214
00215
00216 unsigned char discarding_output;
00217
00218
00219 unsigned int skip_eval;
00220 };
00221
00222
00223 struct spec_nodes
00224 {
00225 cpp_hashnode *n_defined;
00226 cpp_hashnode *n_true;
00227 cpp_hashnode *n_false;
00228 cpp_hashnode *n__VA_ARGS__;
00229 };
00230
00231 typedef struct _cpp_line_note _cpp_line_note;
00232 struct _cpp_line_note
00233 {
00234
00235 const unsigned char *pos;
00236
00237
00238
00239
00240 unsigned int type;
00241 };
00242
00243
00244 struct cpp_buffer
00245 {
00246 const unsigned char *cur;
00247 const unsigned char *line_base;
00248 const unsigned char *next_line;
00249
00250 const unsigned char *buf;
00251 const unsigned char *rlimit;
00252
00253 _cpp_line_note *notes;
00254 unsigned int cur_note;
00255 unsigned int notes_used;
00256 unsigned int notes_cap;
00257
00258 struct cpp_buffer *prev;
00259
00260
00261
00262 struct _cpp_file *file;
00263
00264
00265
00266 struct if_stack *if_stack;
00267
00268
00269 bool need_line;
00270
00271
00272
00273
00274
00275 unsigned int warned_cplusplus_comments : 1;
00276
00277
00278
00279
00280 unsigned int from_stage3 : 1;
00281
00282
00283
00284
00285 unsigned int return_at_eof : 1;
00286
00287
00288
00289 unsigned char sysp;
00290
00291
00292
00293 struct cpp_dir dir;
00294
00295
00296
00297 struct cset_converter input_cset_desc;
00298 };
00299
00300
00301
00302
00303 struct cpp_reader
00304 {
00305
00306 cpp_buffer *buffer;
00307
00308
00309 cpp_buffer *overlaid_buffer;
00310
00311
00312 struct lexer_state state;
00313
00314
00315 struct line_maps *line_table;
00316
00317
00318 source_location directive_line;
00319
00320
00321 _cpp_buff *a_buff;
00322 _cpp_buff *u_buff;
00323 _cpp_buff *free_buffs;
00324
00325
00326 struct cpp_context base_context;
00327 struct cpp_context *context;
00328
00329
00330 const struct directive *directive;
00331
00332
00333 cpp_token directive_result;
00334
00335
00336 struct cpp_dir *quote_include;
00337 struct cpp_dir *bracket_include;
00338 struct cpp_dir no_search_path;
00339
00340
00341 struct _cpp_file *all_files;
00342
00343 struct _cpp_file *main_file;
00344
00345
00346 struct htab *file_hash;
00347 struct htab *dir_hash;
00348 struct file_hash_entry *file_hash_entries;
00349 unsigned int file_hash_entries_allocated, file_hash_entries_used;
00350
00351
00352
00353 bool quote_ignores_source_dir;
00354
00355
00356
00357 bool seen_once_only;
00358
00359
00360 const cpp_hashnode *mi_cmacro;
00361 const cpp_hashnode *mi_ind_cmacro;
00362 bool mi_valid;
00363
00364
00365 cpp_token *cur_token;
00366 tokenrun base_run, *cur_run;
00367 unsigned int lookaheads;
00368
00369
00370 unsigned int keep_tokens;
00371
00372
00373 unsigned int errors;
00374
00375
00376 unsigned char *macro_buffer;
00377 unsigned int macro_buffer_len;
00378
00379
00380
00381 struct cset_converter narrow_cset_desc;
00382
00383
00384
00385 struct cset_converter wide_cset_desc;
00386
00387
00388 const unsigned char *date;
00389 const unsigned char *time;
00390
00391
00392 cpp_token avoid_paste;
00393 cpp_token eof;
00394
00395
00396 struct deps *deps;
00397
00398
00399
00400 struct obstack hash_ob;
00401
00402
00403
00404 struct obstack buffer_ob;
00405
00406
00407
00408 struct pragma_entry *pragmas;
00409
00410
00411 struct cpp_callbacks cb;
00412
00413
00414 struct ht *hash_table;
00415
00416
00417 struct op *op_stack, *op_limit;
00418
00419
00420 struct cpp_options opts;
00421
00422
00423
00424 struct spec_nodes spec_nodes;
00425
00426
00427 bool our_hashtable;
00428
00429
00430 struct
00431 {
00432 unsigned char *base;
00433 unsigned char *limit;
00434 unsigned char *cur;
00435 source_location first_line;
00436 } out;
00437
00438
00439 const unsigned char *saved_cur, *saved_rlimit, *saved_line_base;
00440
00441
00442
00443 struct cpp_savedstate *savedstate;
00444 };
00445
00446
00447
00448
00449
00450
00451
00452
00453 #define _dollar_ok(x) ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident))
00454
00455 #define is_idchar(x) (ISIDNUM(x) || _dollar_ok(x))
00456 #define is_numchar(x) ISIDNUM(x)
00457 #define is_idstart(x) (ISIDST(x) || _dollar_ok(x))
00458 #define is_numstart(x) ISDIGIT(x)
00459 #define is_hspace(x) ISBLANK(x)
00460 #define is_vspace(x) IS_VSPACE(x)
00461 #define is_nvspace(x) IS_NVSPACE(x)
00462 #define is_space(x) IS_SPACE_OR_NUL(x)
00463
00464
00465
00466
00467 #if HAVE_DESIGNATED_INITIALIZERS
00468 extern const unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
00469 #else
00470 extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
00471 #endif
00472
00473
00474
00475 static inline int cpp_in_system_header (cpp_reader *);
00476 static inline int
00477 cpp_in_system_header (cpp_reader *pfile)
00478 {
00479 return pfile->buffer ? pfile->buffer->sysp : 0;
00480 }
00481 #define CPP_PEDANTIC(PF) CPP_OPTION (PF, pedantic)
00482 #define CPP_WTRADITIONAL(PF) CPP_OPTION (PF, warn_traditional)
00483
00484
00485 extern int _cpp_begin_message (cpp_reader *, int,
00486 source_location, unsigned int);
00487
00488
00489 extern void _cpp_free_definition (cpp_hashnode *);
00490 extern bool _cpp_create_definition (cpp_reader *, cpp_hashnode *);
00491 extern void _cpp_pop_context (cpp_reader *);
00492 extern void _cpp_push_text_context (cpp_reader *, cpp_hashnode *,
00493 const unsigned char *, size_t);
00494 extern bool _cpp_save_parameter (cpp_reader *, cpp_macro *, cpp_hashnode *);
00495 extern bool _cpp_arguments_ok (cpp_reader *, cpp_macro *, const cpp_hashnode *,
00496 unsigned int);
00497 extern const unsigned char *_cpp_builtin_macro_text (cpp_reader *,
00498 cpp_hashnode *);
00499 int _cpp_warn_if_unused_macro (cpp_reader *, cpp_hashnode *, void *);
00500
00501 extern void _cpp_init_hashtable (cpp_reader *, hash_table *);
00502 extern void _cpp_destroy_hashtable (cpp_reader *);
00503
00504
00505 typedef struct _cpp_file _cpp_file;
00506 extern _cpp_file *_cpp_find_file (cpp_reader *, const char *fname,
00507 cpp_dir *start_dir, bool fake);
00508 extern bool _cpp_find_failed (_cpp_file *);
00509 extern void _cpp_mark_file_once_only (cpp_reader *, struct _cpp_file *);
00510 extern void _cpp_fake_include (cpp_reader *, const char *);
00511 extern bool _cpp_stack_file (cpp_reader *, _cpp_file*, bool);
00512 extern bool _cpp_stack_include (cpp_reader *, const char *, int,
00513 enum include_type);
00514 extern int _cpp_compare_file_date (cpp_reader *, const char *, int);
00515 extern void _cpp_report_missing_guards (cpp_reader *);
00516 extern void _cpp_init_files (cpp_reader *);
00517 extern void _cpp_cleanup_files (cpp_reader *);
00518 extern void _cpp_pop_file_buffer (cpp_reader *, struct _cpp_file *);
00519 extern bool _cpp_save_file_entries (cpp_reader *pfile, FILE *f);
00520 extern bool _cpp_read_file_entries (cpp_reader *, FILE *);
00521
00522
00523 extern bool _cpp_parse_expr (cpp_reader *);
00524 extern struct op *_cpp_expand_op_stack (cpp_reader *);
00525
00526
00527 extern void _cpp_process_line_notes (cpp_reader *, int);
00528 extern void _cpp_clean_line (cpp_reader *);
00529 extern bool _cpp_get_fresh_line (cpp_reader *);
00530 extern bool _cpp_skip_block_comment (cpp_reader *);
00531 extern cpp_token *_cpp_temp_token (cpp_reader *);
00532 extern const cpp_token *_cpp_lex_token (cpp_reader *);
00533 extern cpp_token *_cpp_lex_direct (cpp_reader *);
00534 extern int _cpp_equiv_tokens (const cpp_token *, const cpp_token *);
00535 extern void _cpp_init_tokenrun (tokenrun *, unsigned int);
00536
00537
00538 extern void _cpp_maybe_push_include_file (cpp_reader *);
00539
00540
00541 extern int _cpp_test_assertion (cpp_reader *, unsigned int *);
00542 extern int _cpp_handle_directive (cpp_reader *, int);
00543 extern void _cpp_define_builtin (cpp_reader *, const char *);
00544 extern char ** _cpp_save_pragma_names (cpp_reader *);
00545 extern void _cpp_restore_pragma_names (cpp_reader *, char **);
00546 extern void _cpp_do__Pragma (cpp_reader *);
00547 extern void _cpp_init_directives (cpp_reader *);
00548 extern void _cpp_init_internal_pragmas (cpp_reader *);
00549 extern void _cpp_do_file_change (cpp_reader *, enum lc_reason, const char *,
00550 unsigned int, unsigned int);
00551 extern void _cpp_pop_buffer (cpp_reader *);
00552
00553
00554 extern bool _cpp_scan_out_logical_line (cpp_reader *, cpp_macro *);
00555 extern bool _cpp_read_logical_line_trad (cpp_reader *);
00556 extern void _cpp_overlay_buffer (cpp_reader *pfile, const unsigned char *,
00557 size_t);
00558 extern void _cpp_remove_overlay (cpp_reader *);
00559 extern bool _cpp_create_trad_definition (cpp_reader *, cpp_macro *);
00560 extern bool _cpp_expansions_different_trad (const cpp_macro *,
00561 const cpp_macro *);
00562 extern unsigned char *_cpp_copy_replacement_text (const cpp_macro *,
00563 unsigned char *);
00564 extern size_t _cpp_replacement_text_len (const cpp_macro *);
00565
00566
00567 extern cppchar_t _cpp_valid_ucn (cpp_reader *, const unsigned char **,
00568 const unsigned char *, int);
00569 extern void _cpp_destroy_iconv (cpp_reader *);
00570 extern unsigned char *_cpp_convert_input (cpp_reader *, const char *,
00571 unsigned char *, size_t, size_t,
00572 off_t *);
00573 extern const char *_cpp_default_encoding (void);
00574
00575
00576 #define DSC(str) (const unsigned char *)str, sizeof str - 1
00577
00578
00579
00580 static inline int ustrcmp (const unsigned char *, const unsigned char *);
00581 static inline int ustrncmp (const unsigned char *, const unsigned char *,
00582 size_t);
00583 static inline size_t ustrlen (const unsigned char *);
00584 static inline unsigned char *uxstrdup (const unsigned char *);
00585 static inline unsigned char *ustrchr (const unsigned char *, int);
00586 static inline int ufputs (const unsigned char *, FILE *);
00587
00588
00589 static inline int ustrcspn (const unsigned char *, const char *);
00590
00591 static inline int
00592 ustrcmp (const unsigned char *s1, const unsigned char *s2)
00593 {
00594 return strcmp ((const char *)s1, (const char *)s2);
00595 }
00596
00597 static inline int
00598 ustrncmp (const unsigned char *s1, const unsigned char *s2, size_t n)
00599 {
00600 return strncmp ((const char *)s1, (const char *)s2, n);
00601 }
00602
00603 static inline int
00604 ustrcspn (const unsigned char *s1, const char *s2)
00605 {
00606 return strcspn ((const char *)s1, s2);
00607 }
00608
00609 static inline size_t
00610 ustrlen (const unsigned char *s1)
00611 {
00612 return strlen ((const char *)s1);
00613 }
00614
00615 static inline unsigned char *
00616 uxstrdup (const unsigned char *s1)
00617 {
00618 return (unsigned char *) xstrdup ((const char *)s1);
00619 }
00620
00621 static inline unsigned char *
00622 ustrchr (const unsigned char *s1, int c)
00623 {
00624 return (unsigned char *) strchr ((const char *)s1, c);
00625 }
00626
00627 static inline int
00628 ufputs (const unsigned char *s, FILE *f)
00629 {
00630 return fputs ((const char *)s, f);
00631 }
00632
00633 #endif