00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef GCC_CPPLIB_H
00028 #define GCC_CPPLIB_H
00029
00030 #include <sys/types.h>
00031 #include "hashtable.h"
00032 #include "line-map.h"
00033
00034 #ifdef __cplusplus
00035 extern "C" {
00036 #endif
00037
00038
00039 #ifndef GCC_C_PRAGMA_H
00040 typedef struct cpp_reader cpp_reader;
00041 #endif
00042 typedef struct cpp_buffer cpp_buffer;
00043 typedef struct cpp_options cpp_options;
00044 typedef struct cpp_token cpp_token;
00045 typedef struct cpp_string cpp_string;
00046 typedef struct cpp_hashnode cpp_hashnode;
00047 typedef struct cpp_macro cpp_macro;
00048 typedef struct cpp_callbacks cpp_callbacks;
00049
00050 struct answer;
00051 struct file_name_map_list;
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 #define CPP_LAST_EQ CPP_MAX
00063 #define CPP_FIRST_DIGRAPH CPP_HASH
00064 #define CPP_LAST_PUNCTUATOR CPP_DOT_STAR
00065 #define CPP_LAST_CPP_OP CPP_LESS_EQ
00066
00067 #define TTYPE_TABLE \
00068 OP(CPP_EQ = 0, "=") \
00069 OP(CPP_NOT, "!") \
00070 OP(CPP_GREATER, ">") \
00071 OP(CPP_LESS, "<") \
00072 OP(CPP_PLUS, "+") \
00073 OP(CPP_MINUS, "-") \
00074 OP(CPP_MULT, "*") \
00075 OP(CPP_DIV, "/") \
00076 OP(CPP_MOD, "%") \
00077 OP(CPP_AND, "&") \
00078 OP(CPP_OR, "|") \
00079 OP(CPP_XOR, "^") \
00080 OP(CPP_RSHIFT, ">>") \
00081 OP(CPP_LSHIFT, "<<") \
00082 OP(CPP_MIN, "<?") \
00083 OP(CPP_MAX, ">?") \
00084 \
00085 OP(CPP_COMPL, "~") \
00086 OP(CPP_AND_AND, "&&") \
00087 OP(CPP_OR_OR, "||") \
00088 OP(CPP_QUERY, "?") \
00089 OP(CPP_COLON, ":") \
00090 OP(CPP_COMMA, ",") \
00091 OP(CPP_OPEN_PAREN, "(") \
00092 OP(CPP_CLOSE_PAREN, ")") \
00093 TK(CPP_EOF, SPELL_NONE) \
00094 OP(CPP_EQ_EQ, "==") \
00095 OP(CPP_NOT_EQ, "!=") \
00096 OP(CPP_GREATER_EQ, ">=") \
00097 OP(CPP_LESS_EQ, "<=") \
00098 \
00099 \
00100 OP(CPP_PLUS_EQ, "+=") \
00101 OP(CPP_MINUS_EQ, "-=") \
00102 \
00103 OP(CPP_MULT_EQ, "*=") \
00104 OP(CPP_DIV_EQ, "/=") \
00105 OP(CPP_MOD_EQ, "%=") \
00106 OP(CPP_AND_EQ, "&=") \
00107 OP(CPP_OR_EQ, "|=") \
00108 OP(CPP_XOR_EQ, "^=") \
00109 OP(CPP_RSHIFT_EQ, ">>=") \
00110 OP(CPP_LSHIFT_EQ, "<<=") \
00111 OP(CPP_MIN_EQ, "<?=") \
00112 OP(CPP_MAX_EQ, ">?=") \
00113 \
00114 OP(CPP_HASH, "#") \
00115 OP(CPP_PASTE, "##") \
00116 OP(CPP_OPEN_SQUARE, "[") \
00117 OP(CPP_CLOSE_SQUARE, "]") \
00118 OP(CPP_OPEN_BRACE, "{") \
00119 OP(CPP_CLOSE_BRACE, "}") \
00120 \
00121 OP(CPP_SEMICOLON, ";") \
00122 OP(CPP_ELLIPSIS, "...") \
00123 OP(CPP_PLUS_PLUS, "++") \
00124 OP(CPP_MINUS_MINUS, "--") \
00125 OP(CPP_DEREF, "->") \
00126 OP(CPP_DOT, ".") \
00127 OP(CPP_SCOPE, "::") \
00128 OP(CPP_DEREF_STAR, "->*") \
00129 OP(CPP_DOT_STAR, ".*") \
00130 OP(CPP_ATSIGN, "@") /* used in Objective-C */ \
\
TK(CPP_NAME, SPELL_IDENT) /* word */ \
TK(CPP_NUMBER, SPELL_NUMBER) /* 34_be+ta */ \
\
TK(CPP_CHAR, SPELL_STRING) /* 'char' */ \
TK(CPP_WCHAR, SPELL_STRING) /* L'char' */ \
TK(CPP_OTHER, SPELL_CHAR) /* stray punctuation */ \
\
TK(CPP_STRING, SPELL_STRING) /* "string" */ \
00131 TK(CPP_WSTRING, SPELL_STRING) \
00132 TK(CPP_HEADER_NAME, SPELL_STRING) \
00133 \
00134 TK(CPP_COMMENT, SPELL_NUMBER) \
00135 \
00136 TK(CPP_MACRO_ARG, SPELL_NONE) \
00137 TK(CPP_PADDING, SPELL_NONE)
00138
00139 #define OP(e, s) e,
00140 #define TK(e, s) e,
00141 enum cpp_ttype
00142 {
00143 TTYPE_TABLE
00144 N_TTYPES
00145 };
00146 #undef OP
00147 #undef TK
00148
00149
00150 enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_STDC89, CLK_STDC94, CLK_STDC99,
00151 CLK_GNUCXX, CLK_CXX98, CLK_ASM};
00152
00153
00154 struct cpp_string
00155 {
00156 unsigned int len;
00157 const unsigned char *text;
00158 };
00159
00160
00161 #define PREV_WHITE (1 << 0)
00162 #define DIGRAPH (1 << 1)
00163 #define STRINGIFY_ARG (1 << 2)
00164 #define PASTE_LEFT (1 << 3)
00165 #define NAMED_OP (1 << 4)
00166 #define NO_EXPAND (1 << 5)
00167 #define BOL (1 << 6)
00168
00169
00170
00171 struct cpp_token
00172 {
00173 unsigned int line;
00174 unsigned short col;
00175 ENUM_BITFIELD(cpp_ttype) type : CHAR_BIT;
00176 unsigned char flags;
00177
00178 union
00179 {
00180 cpp_hashnode *node;
00181 const cpp_token *source;
00182 struct cpp_string str;
00183 unsigned int arg_no;
00184 unsigned char c;
00185 } val;
00186 };
00187
00188
00189
00190
00191 #ifndef MAX_WCHAR_TYPE_SIZE
00192 # define MAX_WCHAR_TYPE_SIZE WCHAR_TYPE_SIZE
00193 #endif
00194 #if CHAR_BIT * SIZEOF_INT >= MAX_WCHAR_TYPE_SIZE
00195 # define CPPCHAR_SIGNED_T int
00196 #else
00197 # if CHAR_BIT * SIZEOF_LONG >= MAX_WCHAR_TYPE_SIZE || !HAVE_LONG_LONG
00198 # define CPPCHAR_SIGNED_T long
00199 # else
00200 # define CPPCHAR_SIGNED_T long long
00201 # endif
00202 #endif
00203 typedef unsigned CPPCHAR_SIGNED_T cppchar_t;
00204 typedef CPPCHAR_SIGNED_T cppchar_signed_t;
00205
00206
00207
00208
00209
00210
00211
00212
00213 enum { dump_none = 0, dump_only, dump_names, dump_definitions };
00214
00215
00216
00217 struct cpp_options
00218 {
00219
00220 unsigned int tabstop;
00221
00222
00223 struct cpp_pending *pending;
00224
00225
00226 struct search_path *quote_include;
00227 struct search_path *bracket_include;
00228
00229
00230
00231 struct file_name_map_list *map_list;
00232
00233
00234
00235 const char *include_prefix;
00236 unsigned int include_prefix_len;
00237
00238
00239 enum c_lang lang;
00240
00241
00242 unsigned char verbose;
00243
00244
00245 unsigned char cplusplus;
00246
00247
00248 unsigned char cplusplus_comments;
00249
00250
00251
00252 unsigned char objc;
00253
00254
00255 unsigned char discard_comments;
00256
00257
00258
00259 unsigned char discard_comments_in_macro_exp;
00260
00261
00262 unsigned char trigraphs;
00263
00264
00265 unsigned char digraphs;
00266
00267
00268 unsigned char extended_numbers;
00269
00270
00271 unsigned char print_include_names;
00272
00273
00274 unsigned char pedantic_errors;
00275
00276
00277 unsigned char inhibit_warnings;
00278
00279
00280 unsigned char warn_deprecated;
00281
00282
00283 unsigned char warn_system_headers;
00284
00285
00286
00287 unsigned char inhibit_errors;
00288
00289
00290 unsigned char warn_comments;
00291
00292
00293 unsigned char warn_trigraphs;
00294
00295
00296 unsigned char warn_import;
00297
00298
00299 unsigned char warn_multichar;
00300
00301
00302
00303 unsigned char warn_traditional;
00304
00305
00306 unsigned char warn_long_long;
00307
00308
00309 unsigned char warn_endif_labels;
00310
00311
00312
00313 unsigned char warn_num_sign_change;
00314
00315
00316 unsigned char warnings_are_errors;
00317
00318
00319
00320 unsigned char no_output;
00321
00322
00323
00324 unsigned char remap;
00325
00326
00327 unsigned char no_line_commands;
00328
00329
00330
00331 unsigned char ignore_srcdir;
00332
00333
00334 unsigned char dollars_in_ident;
00335
00336
00337 unsigned char warn_undef;
00338
00339
00340 unsigned char warn_unused_macros;
00341
00342
00343 unsigned char c99;
00344
00345
00346 unsigned char std;
00347
00348
00349 unsigned char pedantic;
00350
00351
00352
00353 unsigned char preprocessed;
00354
00355
00356 unsigned char no_standard_includes;
00357
00358
00359 unsigned char no_standard_cplusplus_includes;
00360
00361
00362 unsigned char dump_macros;
00363
00364
00365 unsigned char dump_includes;
00366
00367
00368 unsigned char show_column;
00369
00370
00371 unsigned char operator_names;
00372
00373
00374 unsigned char traditional;
00375
00376
00377 struct
00378 {
00379
00380 enum {DEPS_NONE = 0, DEPS_USER, DEPS_SYSTEM } style;
00381
00382
00383 bool missing_files;
00384
00385
00386
00387 bool phony_targets;
00388
00389
00390 bool ignore_main_file;
00391 } deps;
00392
00393
00394
00395
00396
00397 size_t precision, char_precision, int_precision, wchar_precision;
00398
00399
00400 bool unsigned_char, unsigned_wchar;
00401
00402
00403 unsigned char stdc_0_in_system_headers;
00404 };
00405
00406
00407 struct cpp_callbacks
00408 {
00409
00410 void (*line_change) PARAMS ((cpp_reader *, const cpp_token *, int));
00411 void (*file_change) PARAMS ((cpp_reader *, const struct line_map *));
00412 void (*include) PARAMS ((cpp_reader *, unsigned int,
00413 const unsigned char *, const cpp_token *));
00414 void (*define) PARAMS ((cpp_reader *, unsigned int, cpp_hashnode *));
00415 void (*undef) PARAMS ((cpp_reader *, unsigned int, cpp_hashnode *));
00416 void (*ident) PARAMS ((cpp_reader *, unsigned int, const cpp_string *));
00417 void (*def_pragma) PARAMS ((cpp_reader *, unsigned int));
00418
00419
00420 void (*register_builtins) PARAMS ((cpp_reader *));
00421 };
00422
00423
00424 extern const char *progname;
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438 #define NODE_OPERATOR (1 << 0)
00439 #define NODE_POISONED (1 << 1)
00440 #define NODE_BUILTIN (1 << 2)
00441 #define NODE_DIAGNOSTIC (1 << 3)
00442 #define NODE_WARN (1 << 4)
00443 #define NODE_DISABLED (1 << 5)
00444
00445
00446 enum node_type
00447 {
00448 NT_VOID = 0,
00449 NT_MACRO,
00450 NT_ASSERTION
00451 };
00452
00453
00454
00455 enum builtin_type
00456 {
00457 BT_SPECLINE = 0,
00458 BT_DATE,
00459 BT_FILE,
00460 BT_BASE_FILE,
00461 BT_INCLUDE_LEVEL,
00462 BT_TIME,
00463 BT_STDC,
00464 BT_PRAGMA
00465 };
00466
00467 #define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE))
00468 #define HT_NODE(NODE) ((ht_identifier *) (NODE))
00469 #define NODE_LEN(NODE) HT_LEN (&(NODE)->ident)
00470 #define NODE_NAME(NODE) HT_STR (&(NODE)->ident)
00471
00472
00473
00474
00475 struct cpp_hashnode
00476 {
00477 struct ht_identifier ident;
00478 unsigned short arg_index;
00479 unsigned char directive_index;
00480 unsigned char rid_code;
00481 ENUM_BITFIELD(node_type) type : 8;
00482 unsigned char flags;
00483
00484 union
00485 {
00486 cpp_macro *macro;
00487 struct answer *answers;
00488 #ifdef SGI_MONGOOSE
00489 enum cpp_ttype operator_code;
00490 #else
00491 enum cpp_ttype operator;
00492 #endif
00493 enum builtin_type builtin;
00494 } value;
00495 };
00496
00497
00498 extern cpp_reader *cpp_create_reader PARAMS ((enum c_lang));
00499
00500
00501
00502 extern void cpp_set_lang PARAMS ((cpp_reader *, enum c_lang));
00503
00504
00505
00506
00507
00508 extern void cpp_add_dependency_target PARAMS ((cpp_reader *,
00509 const char * target,
00510 int quote));
00511
00512
00513
00514
00515
00516
00517 extern cpp_options *cpp_get_options PARAMS ((cpp_reader *));
00518 extern const struct line_maps *cpp_get_line_maps PARAMS ((cpp_reader *));
00519 extern cpp_callbacks *cpp_get_callbacks PARAMS ((cpp_reader *));
00520 extern void cpp_set_callbacks PARAMS ((cpp_reader *, cpp_callbacks *));
00521
00522
00523
00524
00525
00526
00527 extern int cpp_handle_options PARAMS ((cpp_reader *, int, char **));
00528 extern int cpp_handle_option PARAMS ((cpp_reader *, int, char **));
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540 extern const char *cpp_read_main_file PARAMS ((cpp_reader *, const char *,
00541 struct ht *));
00542
00543
00544
00545
00546
00547
00548 extern void cpp_finish_options PARAMS ((cpp_reader *));
00549
00550
00551
00552
00553
00554
00555 extern int cpp_finish PARAMS ((cpp_reader *, FILE *deps_stream));
00556
00557
00558
00559
00560 extern void cpp_destroy PARAMS ((cpp_reader *));
00561
00562
00563 extern unsigned int cpp_errors PARAMS ((cpp_reader *));
00564
00565 extern unsigned int cpp_token_len PARAMS ((const cpp_token *));
00566 extern unsigned char *cpp_token_as_text PARAMS ((cpp_reader *,
00567 const cpp_token *));
00568 extern unsigned char *cpp_spell_token PARAMS ((cpp_reader *, const cpp_token *,
00569 unsigned char *));
00570 extern void cpp_register_pragma PARAMS ((cpp_reader *,
00571 const char *, const char *,
00572 void (*) PARAMS ((cpp_reader *))));
00573
00574 extern int cpp_avoid_paste PARAMS ((cpp_reader *, const cpp_token *,
00575 const cpp_token *));
00576 extern const cpp_token *cpp_get_token PARAMS ((cpp_reader *));
00577 extern const unsigned char *cpp_macro_definition PARAMS ((cpp_reader *,
00578 const cpp_hashnode *));
00579 extern void _cpp_backup_tokens PARAMS ((cpp_reader *, unsigned int));
00580
00581
00582 extern cppchar_t
00583 cpp_interpret_charconst PARAMS ((cpp_reader *, const cpp_token *,
00584 unsigned int *, int *));
00585
00586
00587
00588 extern void cpp_define PARAMS ((cpp_reader *, const char *));
00589 extern void cpp_assert PARAMS ((cpp_reader *, const char *));
00590 extern void cpp_undef PARAMS ((cpp_reader *, const char *));
00591 extern void cpp_unassert PARAMS ((cpp_reader *, const char *));
00592
00593 extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
00594 const unsigned char *, size_t,
00595 int, int));
00596 extern int cpp_defined PARAMS ((cpp_reader *, const unsigned char *, int));
00597
00598
00599
00600 typedef unsigned HOST_WIDE_INT cpp_num_part;
00601 typedef struct cpp_num cpp_num;
00602 struct cpp_num
00603 {
00604 cpp_num_part high;
00605 cpp_num_part low;
00606 bool unsignedp;
00607 bool overflow;
00608 };
00609
00610
00611
00612
00613
00614
00615
00616
00617 #define CPP_N_CATEGORY 0x000F
00618 #define CPP_N_INVALID 0x0000
00619 #define CPP_N_INTEGER 0x0001
00620 #define CPP_N_FLOATING 0x0002
00621
00622 #define CPP_N_WIDTH 0x00F0
00623 #define CPP_N_SMALL 0x0010
00624 #define CPP_N_MEDIUM 0x0020
00625 #define CPP_N_LARGE 0x0040
00626
00627 #define CPP_N_RADIX 0x0F00
00628 #define CPP_N_DECIMAL 0x0100
00629 #define CPP_N_HEX 0x0200
00630 #define CPP_N_OCTAL 0x0400
00631
00632 #define CPP_N_UNSIGNED 0x1000
00633 #define CPP_N_IMAGINARY 0x2000
00634
00635
00636
00637 extern unsigned cpp_classify_number PARAMS ((cpp_reader *, const cpp_token *));
00638
00639
00640 extern cpp_num cpp_interpret_integer PARAMS ((cpp_reader *, const cpp_token *,
00641 unsigned int type));
00642
00643
00644
00645 cpp_num cpp_num_sign_extend PARAMS ((cpp_num, size_t));
00646
00647
00648
00649
00650
00651
00652 #define DL_WARNING 0x00
00653
00654 #define DL_WARNING_SYSHDR 0x01
00655
00656 #define DL_PEDWARN 0x02
00657
00658 #define DL_ERROR 0x03
00659
00660
00661 #define DL_ICE 0x04
00662
00663 #define DL_EXTRACT(l) (l & 0xf)
00664
00665 #define DL_WARNING_P(l) (DL_EXTRACT (l) >= DL_WARNING \
00666 && DL_EXTRACT (l) <= DL_PEDWARN)
00667
00668
00669
00670
00671
00672
00673
00674
00675 extern void cpp_error PARAMS ((cpp_reader *, int, const char *msgid, ...))
00676 ATTRIBUTE_PRINTF_3;
00677
00678
00679
00680 extern void cpp_errno PARAMS ((cpp_reader *, int level, const char *msg));
00681
00682
00683
00684
00685 extern void cpp_error_with_line PARAMS ((cpp_reader *, int, unsigned, unsigned, const char *msgid, ...))
00686 ATTRIBUTE_PRINTF_5;
00687
00688
00689 extern int cpp_ideq PARAMS ((const cpp_token *,
00690 const char *));
00691 extern void cpp_output_line PARAMS ((cpp_reader *, FILE *));
00692 extern void cpp_output_token PARAMS ((const cpp_token *, FILE *));
00693 extern const char *cpp_type2name PARAMS ((enum cpp_ttype));
00694
00695
00696
00697
00698
00699 extern cppchar_t cpp_parse_escape PARAMS ((cpp_reader *,
00700 const unsigned char ** pstr,
00701 const unsigned char *limit,
00702 int wide));
00703
00704
00705
00706
00707
00708 extern cpp_hashnode *cpp_lookup PARAMS ((cpp_reader *,
00709 const unsigned char *,
00710 unsigned int));
00711
00712 typedef int (*cpp_cb) PARAMS ((cpp_reader *, cpp_hashnode *, void *));
00713 extern void cpp_forall_identifiers PARAMS ((cpp_reader *,
00714 cpp_cb, void *));
00715
00716
00717 extern void cpp_scan_nooutput PARAMS ((cpp_reader *));
00718 extern int cpp_sys_macro_p PARAMS ((cpp_reader *));
00719 extern unsigned char *cpp_quote_string PARAMS ((unsigned char *,
00720 const unsigned char *,
00721 unsigned int));
00722
00723
00724 extern int cpp_included PARAMS ((cpp_reader *, const char *));
00725 extern void cpp_make_system_header PARAMS ((cpp_reader *, int, int));
00726
00727
00728 extern void cpp_preprocess_file PARAMS ((cpp_reader *, const char *, FILE *));
00729
00730 #ifdef __cplusplus
00731 }
00732 #endif
00733
00734 #endif
00735