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