00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef LIBCPP_CPPLIB_H
00025 #define LIBCPP_CPPLIB_H
00026
00027 #include <sys/types.h>
00028 #include "symtab.h"
00029 #include "line-map.h"
00030
00031 #ifdef __cplusplus
00032 extern "C" {
00033 #endif
00034
00035 typedef struct cpp_reader cpp_reader;
00036 typedef struct cpp_buffer cpp_buffer;
00037 typedef struct cpp_options cpp_options;
00038 typedef struct cpp_token cpp_token;
00039 typedef struct cpp_string cpp_string;
00040 typedef struct cpp_hashnode cpp_hashnode;
00041 typedef struct cpp_macro cpp_macro;
00042 typedef struct cpp_callbacks cpp_callbacks;
00043 typedef struct cpp_dir cpp_dir;
00044
00045 struct answer;
00046 struct _cpp_file;
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #define TTYPE_TABLE \
00057 OP(EQ, "=") \
00058 OP(NOT, "!") \
00059 OP(GREATER, ">") \
00060 OP(LESS, "<") \
00061 OP(PLUS, "+") \
00062 OP(MINUS, "-") \
00063 OP(MULT, "*") \
00064 OP(DIV, "/") \
00065 OP(MOD, "%") \
00066 OP(AND, "&") \
00067 OP(OR, "|") \
00068 OP(XOR, "^") \
00069 OP(RSHIFT, ">>") \
00070 OP(LSHIFT, "<<") \
00071 OP(MIN, "<?") \
00072 OP(MAX, ">?") \
00073 \
00074 OP(COMPL, "~") \
00075 OP(AND_AND, "&&") \
00076 OP(OR_OR, "||") \
00077 OP(QUERY, "?") \
00078 OP(COLON, ":") \
00079 OP(COMMA, ",") \
00080 OP(OPEN_PAREN, "(") \
00081 OP(CLOSE_PAREN, ")") \
00082 TK(EOF, NONE) \
00083 OP(EQ_EQ, "==") \
00084 OP(NOT_EQ, "!=") \
00085 OP(GREATER_EQ, ">=") \
00086 OP(LESS_EQ, "<=") \
00087 \
00088 \
00089 OP(PLUS_EQ, "+=") \
00090 OP(MINUS_EQ, "-=") \
00091 \
00092 OP(MULT_EQ, "*=") \
00093 OP(DIV_EQ, "/=") \
00094 OP(MOD_EQ, "%=") \
00095 OP(AND_EQ, "&=") \
00096 OP(OR_EQ, "|=") \
00097 OP(XOR_EQ, "^=") \
00098 OP(RSHIFT_EQ, ">>=") \
00099 OP(LSHIFT_EQ, "<<=") \
00100 OP(MIN_EQ, "<?=") \
00101 OP(MAX_EQ, ">?=") \
00102 \
00103 OP(HASH, "#") \
00104 OP(PASTE, "##") \
00105 OP(OPEN_SQUARE, "[") \
00106 OP(CLOSE_SQUARE, "]") \
00107 OP(OPEN_BRACE, "{") \
00108 OP(CLOSE_BRACE, "}") \
00109 \
00110 OP(SEMICOLON, ";") \
00111 OP(ELLIPSIS, "...") \
00112 OP(PLUS_PLUS, "++") \
00113 OP(MINUS_MINUS, "--") \
00114 OP(DEREF, "->") \
00115 OP(DOT, ".") \
00116 OP(SCOPE, "::") \
00117 OP(DEREF_STAR, "->*") \
00118 OP(DOT_STAR, ".*") \
00119 OP(ATSIGN, "@") /* used in Objective-C */ \
\
TK(NAME, IDENT) /* word */ \
TK(AT_NAME, IDENT) /* @word - Objective-C */ \
TK(NUMBER, LITERAL) /* 34_be+ta */ \
\
TK(CHAR, LITERAL) /* 'char' */ \
TK(WCHAR, LITERAL) /* L'char' */ \
TK(OTHER, LITERAL) /* stray punctuation */ \
\
TK(STRING, LITERAL) /* "string" */ \
00120 TK(WSTRING, LITERAL) \
00121 TK(OBJC_STRING, LITERAL) \
00122 TK(HEADER_NAME, LITERAL) \
00123 \
00124 TK(COMMENT, LITERAL) \
00125 \
00126 TK(MACRO_ARG, NONE) \
00127 TK(PRAGMA, NONE) \
00128 TK(PADDING, NONE)
00129
00130 #define OP(e, s) CPP_ ## e,
00131 #define TK(e, s) CPP_ ## e,
00132 enum cpp_ttype
00133 {
00134 TTYPE_TABLE
00135 N_TTYPES,
00136
00137
00138 CPP_LAST_EQ = CPP_MAX,
00139 CPP_FIRST_DIGRAPH = CPP_HASH,
00140 CPP_LAST_PUNCTUATOR= CPP_DOT_STAR,
00141 CPP_LAST_CPP_OP = CPP_LESS_EQ
00142 };
00143 #undef OP
00144 #undef TK
00145
00146
00147 enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_STDC89, CLK_STDC94, CLK_STDC99,
00148 CLK_GNUCXX, CLK_CXX98, CLK_ASM};
00149
00150
00151 struct cpp_string GTY(())
00152 {
00153 unsigned int len;
00154 const unsigned char *text;
00155 };
00156
00157
00158 #define PREV_WHITE (1 << 0)
00159 #define DIGRAPH (1 << 1)
00160 #define STRINGIFY_ARG (1 << 2)
00161 #define PASTE_LEFT (1 << 3)
00162 #define NAMED_OP (1 << 4)
00163 #define NO_EXPAND (1 << 5)
00164 #define BOL (1 << 6)
00165
00166
00167
00168 enum cpp_token_fld_kind {
00169 CPP_TOKEN_FLD_NODE,
00170 CPP_TOKEN_FLD_SOURCE,
00171 CPP_TOKEN_FLD_STR,
00172 CPP_TOKEN_FLD_ARG_NO,
00173 CPP_TOKEN_FLD_NONE
00174 };
00175
00176
00177
00178 struct cpp_token GTY(())
00179 {
00180 source_location src_loc;
00181 ENUM_BITFIELD(cpp_ttype) type : CHAR_BIT;
00182 unsigned char flags;
00183
00184 union cpp_token_u
00185 {
00186
00187 cpp_hashnode *
00188 GTY ((nested_ptr (union tree_node,
00189 "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
00190 "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL"),
00191 tag ("CPP_TOKEN_FLD_NODE")))
00192 node;
00193
00194
00195 cpp_token * GTY ((tag ("CPP_TOKEN_FLD_SOURCE"))) source;
00196
00197
00198 struct cpp_string GTY ((tag ("CPP_TOKEN_FLD_STR"))) str;
00199
00200
00201 unsigned int GTY ((tag ("CPP_TOKEN_FLD_ARG_NO"))) arg_no;
00202 } GTY ((desc ("cpp_token_val_index (&%1)"))) val;
00203 };
00204
00205
00206 extern enum cpp_token_fld_kind cpp_token_val_index (cpp_token *tok);
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 #if CHAR_BIT * SIZEOF_INT >= 32
00217 # define CPPCHAR_SIGNED_T int
00218 #elif CHAR_BIT * SIZEOF_LONG >= 32
00219 # define CPPCHAR_SIGNED_T long
00220 #else
00221 # error "Cannot find a least-32-bit signed integer type"
00222 #endif
00223 typedef unsigned CPPCHAR_SIGNED_T cppchar_t;
00224 typedef CPPCHAR_SIGNED_T cppchar_signed_t;
00225
00226
00227 enum cpp_deps_style { DEPS_NONE = 0, DEPS_USER, DEPS_SYSTEM };
00228
00229
00230
00231 struct cpp_options
00232 {
00233
00234 unsigned int tabstop;
00235
00236
00237 enum c_lang lang;
00238
00239
00240 unsigned char cplusplus;
00241
00242
00243 unsigned char cplusplus_comments;
00244
00245
00246
00247 unsigned char objc;
00248
00249
00250 unsigned char discard_comments;
00251
00252
00253
00254 unsigned char discard_comments_in_macro_exp;
00255
00256
00257 unsigned char trigraphs;
00258
00259
00260 unsigned char digraphs;
00261
00262
00263 unsigned char extended_numbers;
00264
00265
00266 unsigned char print_include_names;
00267
00268
00269 unsigned char pedantic_errors;
00270
00271
00272 unsigned char inhibit_warnings;
00273
00274
00275 unsigned char warn_deprecated;
00276
00277
00278 unsigned char warn_system_headers;
00279
00280
00281
00282 unsigned char inhibit_errors;
00283
00284
00285 unsigned char warn_comments;
00286
00287
00288
00289 unsigned char warn_missing_include_dirs;
00290
00291
00292 unsigned char warn_trigraphs;
00293
00294
00295 unsigned char warn_multichar;
00296
00297
00298
00299 unsigned char warn_traditional;
00300
00301
00302 unsigned char warn_long_long;
00303
00304
00305 unsigned char warn_endif_labels;
00306
00307
00308
00309 unsigned char warn_num_sign_change;
00310
00311
00312
00313 unsigned char warn_variadic_macros;
00314
00315
00316 unsigned char warnings_are_errors;
00317
00318
00319
00320 unsigned char remap;
00321
00322
00323 unsigned char dollars_in_ident;
00324
00325
00326
00327 unsigned char warn_dollars;
00328
00329
00330 unsigned char warn_undef;
00331
00332
00333 unsigned char warn_unused_macros;
00334
00335
00336 unsigned char c99;
00337
00338
00339 unsigned char std;
00340
00341
00342 unsigned char pedantic;
00343
00344
00345
00346 unsigned char preprocessed;
00347
00348
00349 unsigned char show_column;
00350
00351
00352 unsigned char operator_names;
00353
00354
00355 unsigned char traditional;
00356
00357
00358 const char *narrow_charset;
00359
00360
00361 const char *wide_charset;
00362
00363
00364 const char *input_charset;
00365
00366
00367 bool warn_invalid_pch;
00368
00369
00370 bool restore_pch_deps;
00371
00372
00373 struct
00374 {
00375
00376 enum cpp_deps_style style;
00377
00378
00379 bool missing_files;
00380
00381
00382
00383 bool phony_targets;
00384
00385
00386 bool ignore_main_file;
00387 } deps;
00388
00389
00390
00391
00392
00393 size_t precision, char_precision, int_precision, wchar_precision;
00394
00395
00396 bool unsigned_char, unsigned_wchar;
00397
00398
00399
00400 bool bytes_big_endian;
00401
00402
00403 unsigned char stdc_0_in_system_headers;
00404
00405
00406
00407 bool defer_pragmas;
00408 };
00409
00410
00411
00412
00413
00414
00415
00416 typedef const char *(*missing_header_cb)(cpp_reader *, const char *header, cpp_dir **);
00417
00418
00419 struct cpp_callbacks
00420 {
00421
00422 void (*line_change) (cpp_reader *, const cpp_token *, int);
00423
00424
00425
00426
00427
00428 void (*file_change) (cpp_reader *, const struct line_map *);
00429
00430 void (*dir_change) (cpp_reader *, const char *);
00431 void (*include) (cpp_reader *, unsigned int, const unsigned char *,
00432 const char *, int);
00433 void (*define) (cpp_reader *, unsigned int, cpp_hashnode *);
00434 void (*undef) (cpp_reader *, unsigned int, cpp_hashnode *);
00435 void (*ident) (cpp_reader *, unsigned int, const cpp_string *);
00436 void (*def_pragma) (cpp_reader *, unsigned int);
00437 int (*valid_pch) (cpp_reader *, const char *, int);
00438 void (*read_pch) (cpp_reader *, const char *, int, const char *);
00439 missing_header_cb missing_header;
00440 };
00441
00442
00443 struct cpp_dir
00444 {
00445
00446 struct cpp_dir *next;
00447
00448
00449 char *name;
00450 unsigned int len;
00451
00452
00453
00454 unsigned char sysp;
00455
00456
00457
00458 const char **name_map;
00459
00460
00461
00462
00463
00464 char *(*construct) (const char *header, cpp_dir *dir);
00465
00466
00467
00468 ino_t ino;
00469 dev_t dev;
00470
00471
00472 bool user_supplied_p;
00473 };
00474
00475
00476 extern const char *progname;
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490 #define NODE_OPERATOR (1 << 0)
00491 #define NODE_POISONED (1 << 1)
00492 #define NODE_BUILTIN (1 << 2)
00493 #define NODE_DIAGNOSTIC (1 << 3)
00494 #define NODE_WARN (1 << 4)
00495 #define NODE_DISABLED (1 << 5)
00496 #define NODE_MACRO_ARG (1 << 6)
00497
00498
00499 enum node_type
00500 {
00501 NT_VOID = 0,
00502 NT_MACRO,
00503 NT_ASSERTION
00504 };
00505
00506
00507
00508 enum builtin_type
00509 {
00510 BT_SPECLINE = 0,
00511 BT_DATE,
00512 BT_FILE,
00513 BT_BASE_FILE,
00514 BT_INCLUDE_LEVEL,
00515 BT_TIME,
00516 BT_STDC,
00517 BT_PRAGMA
00518 };
00519
00520 #define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE))
00521 #define HT_NODE(NODE) ((ht_identifier *) (NODE))
00522 #define NODE_LEN(NODE) HT_LEN (&(NODE)->ident)
00523 #define NODE_NAME(NODE) HT_STR (&(NODE)->ident)
00524
00525
00526
00527 enum {
00528 NTV_MACRO,
00529 NTV_ANSWER,
00530 NTV_BUILTIN,
00531 NTV_ARGUMENT,
00532 NTV_NONE
00533 };
00534
00535 #define CPP_HASHNODE_VALUE_IDX(HNODE) \
00536 ((HNODE.flags & NODE_MACRO_ARG) ? NTV_ARGUMENT \
00537 : HNODE.type == NT_MACRO ? ((HNODE.flags & NODE_BUILTIN) \
00538 ? NTV_BUILTIN : NTV_MACRO) \
00539 : HNODE.type == NT_ASSERTION ? NTV_ANSWER \
00540 : NTV_NONE)
00541
00542
00543
00544
00545 struct cpp_hashnode GTY(())
00546 {
00547 struct ht_identifier ident;
00548 unsigned int is_directive : 1;
00549 unsigned int directive_index : 7;
00550
00551
00552 unsigned char rid_code;
00553 ENUM_BITFIELD(node_type) type : 8;
00554 unsigned char flags;
00555
00556 union _cpp_hashnode_value
00557 {
00558
00559 cpp_macro * GTY((tag ("NTV_MACRO"))) macro;
00560
00561 struct answer * GTY ((tag ("NTV_ANSWER"))) answers;
00562
00563 enum builtin_type GTY ((tag ("NTV_BUILTIN"))) builtin;
00564
00565 unsigned short GTY ((tag ("NTV_ARGUMENT"))) arg_index;
00566 } GTY ((desc ("CPP_HASHNODE_VALUE_IDX (%1)"))) value;
00567 };
00568
00569
00570
00571
00572
00573
00574
00575 extern cpp_reader *cpp_create_reader (enum c_lang, struct ht *,
00576 struct line_maps *);
00577
00578
00579
00580 extern void cpp_set_lang (cpp_reader *, enum c_lang);
00581
00582
00583 extern void cpp_set_include_chains (cpp_reader *, cpp_dir *, cpp_dir *, int);
00584
00585
00586
00587
00588
00589
00590 extern cpp_options *cpp_get_options (cpp_reader *);
00591 extern cpp_callbacks *cpp_get_callbacks (cpp_reader *);
00592 extern void cpp_set_callbacks (cpp_reader *, cpp_callbacks *);
00593 extern struct deps *cpp_get_deps (cpp_reader *);
00594
00595
00596
00597
00598
00599
00600 extern const char *cpp_read_main_file (cpp_reader *, const char *);
00601
00602
00603 extern void cpp_init_builtins (cpp_reader *, int);
00604
00605
00606
00607 extern void cpp_post_options (cpp_reader *);
00608
00609
00610 extern void cpp_init_iconv (cpp_reader *);
00611
00612
00613
00614
00615
00616
00617 extern int cpp_finish (cpp_reader *, FILE *deps_stream);
00618
00619
00620
00621
00622 extern void cpp_destroy (cpp_reader *);
00623
00624
00625 extern unsigned int cpp_errors (cpp_reader *);
00626
00627 extern unsigned int cpp_token_len (const cpp_token *);
00628 extern unsigned char *cpp_token_as_text (cpp_reader *, const cpp_token *);
00629 extern unsigned char *cpp_spell_token (cpp_reader *, const cpp_token *,
00630 unsigned char *);
00631 extern void cpp_register_pragma (cpp_reader *, const char *, const char *,
00632 void (*) (cpp_reader *), bool);
00633 extern void cpp_handle_deferred_pragma (cpp_reader *, const cpp_string *);
00634 extern int cpp_avoid_paste (cpp_reader *, const cpp_token *,
00635 const cpp_token *);
00636 extern const cpp_token *cpp_get_token (cpp_reader *);
00637 extern const unsigned char *cpp_macro_definition (cpp_reader *,
00638 const cpp_hashnode *);
00639 extern void _cpp_backup_tokens (cpp_reader *, unsigned int);
00640
00641
00642 extern cppchar_t cpp_interpret_charconst (cpp_reader *, const cpp_token *,
00643 unsigned int *, int *);
00644
00645 extern bool cpp_interpret_string (cpp_reader *,
00646 const cpp_string *, size_t,
00647 cpp_string *, bool);
00648 extern bool cpp_interpret_string_notranslate (cpp_reader *,
00649 const cpp_string *, size_t,
00650 cpp_string *, bool);
00651
00652
00653 extern cppchar_t cpp_host_to_exec_charset (cpp_reader *, cppchar_t);
00654
00655
00656
00657 extern void cpp_define (cpp_reader *, const char *);
00658 extern void cpp_assert (cpp_reader *, const char *);
00659 extern void cpp_undef (cpp_reader *, const char *);
00660 extern void cpp_unassert (cpp_reader *, const char *);
00661
00662
00663 extern void cpp_undef_all (cpp_reader *);
00664
00665 extern cpp_buffer *cpp_push_buffer (cpp_reader *, const unsigned char *,
00666 size_t, int);
00667 extern int cpp_defined (cpp_reader *, const unsigned char *, int);
00668
00669
00670
00671 typedef unsigned HOST_WIDE_INT cpp_num_part;
00672 typedef struct cpp_num cpp_num;
00673 struct cpp_num
00674 {
00675 cpp_num_part high;
00676 cpp_num_part low;
00677 bool unsignedp;
00678 bool overflow;
00679 };
00680
00681
00682
00683
00684
00685
00686
00687
00688 #define CPP_N_CATEGORY 0x000F
00689 #define CPP_N_INVALID 0x0000
00690 #define CPP_N_INTEGER 0x0001
00691 #define CPP_N_FLOATING 0x0002
00692
00693 #define CPP_N_WIDTH 0x00F0
00694 #define CPP_N_SMALL 0x0010
00695 #define CPP_N_MEDIUM 0x0020
00696 #define CPP_N_LARGE 0x0040
00697
00698 #define CPP_N_RADIX 0x0F00
00699 #define CPP_N_DECIMAL 0x0100
00700 #define CPP_N_HEX 0x0200
00701 #define CPP_N_OCTAL 0x0400
00702
00703 #define CPP_N_UNSIGNED 0x1000
00704 #define CPP_N_IMAGINARY 0x2000
00705
00706
00707
00708 extern unsigned cpp_classify_number (cpp_reader *, const cpp_token *);
00709
00710
00711 extern cpp_num cpp_interpret_integer (cpp_reader *, const cpp_token *,
00712 unsigned int type);
00713
00714
00715
00716 cpp_num cpp_num_sign_extend (cpp_num, size_t);
00717
00718
00719
00720
00721
00722
00723 #define CPP_DL_WARNING 0x00
00724
00725 #define CPP_DL_WARNING_SYSHDR 0x01
00726
00727 #define CPP_DL_PEDWARN 0x02
00728
00729 #define CPP_DL_ERROR 0x03
00730
00731
00732 #define CPP_DL_ICE 0x04
00733
00734 #define CPP_DL_EXTRACT(l) (l & 0xf)
00735
00736 #define CPP_DL_WARNING_P(l) (CPP_DL_EXTRACT (l) >= CPP_DL_WARNING \
00737 && CPP_DL_EXTRACT (l) <= CPP_DL_PEDWARN)
00738
00739
00740 extern void cpp_error (cpp_reader *, int, const char *msgid, ...)
00741 ATTRIBUTE_PRINTF_3;
00742
00743
00744
00745 extern void cpp_errno (cpp_reader *, int, const char *msgid);
00746
00747
00748
00749
00750 extern void cpp_error_with_line (cpp_reader *, int, source_location, unsigned,
00751 const char *msgid, ...) ATTRIBUTE_PRINTF_5;
00752
00753
00754 extern int cpp_ideq (const cpp_token *, const char *);
00755 extern void cpp_output_line (cpp_reader *, FILE *);
00756 extern void cpp_output_token (const cpp_token *, FILE *);
00757 extern const char *cpp_type2name (enum cpp_ttype);
00758
00759
00760
00761
00762
00763 extern cppchar_t cpp_parse_escape (cpp_reader *, const unsigned char ** pstr,
00764 const unsigned char *limit, int wide);
00765
00766
00767
00768
00769
00770 extern cpp_hashnode *cpp_lookup (cpp_reader *, const unsigned char *,
00771 unsigned int);
00772
00773 typedef int (*cpp_cb) (cpp_reader *, cpp_hashnode *, void *);
00774 extern void cpp_forall_identifiers (cpp_reader *, cpp_cb, void *);
00775
00776
00777 extern void cpp_scan_nooutput (cpp_reader *);
00778 extern int cpp_sys_macro_p (cpp_reader *);
00779 extern unsigned char *cpp_quote_string (unsigned char *, const unsigned char *,
00780 unsigned int);
00781
00782
00783 extern bool cpp_included (cpp_reader *, const char *);
00784 extern void cpp_make_system_header (cpp_reader *, int, int);
00785 extern bool cpp_push_include (cpp_reader *, const char *);
00786 extern void cpp_change_file (cpp_reader *, enum lc_reason, const char *);
00787 extern const char *cpp_get_path (struct _cpp_file *);
00788 extern cpp_dir *cpp_get_dir (struct _cpp_file *);
00789 extern cpp_buffer *cpp_get_buffer (cpp_reader *);
00790 extern struct _cpp_file *cpp_get_file (cpp_buffer *);
00791 extern cpp_buffer *cpp_get_prev (cpp_buffer *);
00792
00793
00794 struct save_macro_data;
00795 extern int cpp_save_state (cpp_reader *, FILE *);
00796 extern int cpp_write_pch_deps (cpp_reader *, FILE *);
00797 extern int cpp_write_pch_state (cpp_reader *, FILE *);
00798 extern int cpp_valid_state (cpp_reader *, const char *, int);
00799 extern void cpp_prepare_state (cpp_reader *, struct save_macro_data **);
00800 extern int cpp_read_state (cpp_reader *, const char *, FILE *,
00801 struct save_macro_data *);
00802
00803 #ifdef __cplusplus
00804 }
00805 #endif
00806
00807 #endif
00808