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
00028 #include "config.h"
00029 #include "system.h"
00030
00031 #include "real.h"
00032 #include "rtl.h"
00033 #include "tree.h"
00034 #include "expr.h"
00035 #include "input.h"
00036 #include "output.h"
00037 #include "c-tree.h"
00038 #include "c-common.h"
00039 #include "flags.h"
00040 #include "timevar.h"
00041 #include "cpplib.h"
00042 #include "c-pragma.h"
00043 #include "toplev.h"
00044 #include "intl.h"
00045 #include "tm_p.h"
00046 #include "splay-tree.h"
00047 #include "debug.h"
00048 #ifdef SGI_MONGOOSE
00049 #include "wfe_dst.h"
00050 #endif
00051
00052 #ifdef MULTIBYTE_CHARS
00053 #include "mbchar.h"
00054 #include <locale.h>
00055 #endif
00056
00057
00058 static const struct line_map *map;
00059
00060
00061 static unsigned int src_lineno;
00062
00063
00064 static int header_time, body_time;
00065 static splay_tree file_info_tree;
00066
00067
00068 extern FILE *asm_out_file;
00069
00070 #undef WCHAR_TYPE_SIZE
00071 #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
00072
00073
00074 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
00075
00076 int pending_lang_change;
00077 int c_header_level;
00078
00079
00080 static int ignore_escape_flag;
00081
00082 static tree interpret_integer PARAMS ((const cpp_token *, unsigned int));
00083 static tree interpret_float PARAMS ((const cpp_token *, unsigned int));
00084 static enum integer_type_kind
00085 narrowest_unsigned_type PARAMS ((tree, unsigned int));
00086 static enum integer_type_kind
00087 narrowest_signed_type PARAMS ((tree, unsigned int));
00088 static tree lex_string PARAMS ((const unsigned char *, unsigned int,
00089 int));
00090 static tree lex_charconst PARAMS ((const cpp_token *));
00091 static void update_header_times PARAMS ((const char *));
00092 static int dump_one_header PARAMS ((splay_tree_node, void *));
00093 static void cb_line_change PARAMS ((cpp_reader *, const cpp_token *, int));
00094 static void cb_ident PARAMS ((cpp_reader *, unsigned int,
00095 const cpp_string *));
00096 static void cb_file_change PARAMS ((cpp_reader *, const struct line_map *));
00097 static void cb_def_pragma PARAMS ((cpp_reader *, unsigned int));
00098 static void cb_define PARAMS ((cpp_reader *, unsigned int,
00099 cpp_hashnode *));
00100 static void cb_undef PARAMS ((cpp_reader *, unsigned int,
00101 cpp_hashnode *));
00102
00103 const char *
00104 init_c_lex (filename)
00105 const char *filename;
00106 {
00107 struct cpp_callbacks *cb;
00108 struct c_fileinfo *toplevel;
00109
00110
00111 file_info_tree = splay_tree_new ((splay_tree_compare_fn)strcmp,
00112 0,
00113 (splay_tree_delete_value_fn)free);
00114 toplevel = get_fileinfo ("<top level>");
00115 if (flag_detailed_statistics)
00116 {
00117 header_time = 0;
00118 body_time = get_run_time ();
00119 toplevel->time = body_time;
00120 }
00121
00122 #ifdef MULTIBYTE_CHARS
00123
00124 setlocale (LC_CTYPE, "");
00125 GET_ENVIRONMENT (literal_codeset, "LANG");
00126 #endif
00127
00128 cb = cpp_get_callbacks (parse_in);
00129
00130 cb->line_change = cb_line_change;
00131 cb->ident = cb_ident;
00132 cb->file_change = cb_file_change;
00133 cb->def_pragma = cb_def_pragma;
00134
00135
00136 if (debug_info_level == DINFO_LEVEL_VERBOSE
00137 && (write_symbols == DWARF_DEBUG || write_symbols == DWARF2_DEBUG
00138 || write_symbols == VMS_AND_DWARF2_DEBUG))
00139 {
00140 cb->define = cb_define;
00141 cb->undef = cb_undef;
00142 }
00143
00144
00145 lineno = 0;
00146
00147 return cpp_read_main_file (parse_in, filename, ident_hash);
00148 }
00149
00150
00151
00152
00153
00154
00155 void
00156 c_common_parse_file (set_yydebug)
00157 int set_yydebug ATTRIBUTE_UNUSED;
00158 {
00159 #if YYDEBUG != 0
00160 yydebug = set_yydebug;
00161 #else
00162 warning ("YYDEBUG not defined");
00163 #endif
00164
00165 #ifndef SGI_MONGOOSE
00166 (*debug_hooks->start_source_file) (lineno, input_filename);
00167 cpp_finish_options (parse_in);
00168 #endif
00169
00170 yyparse ();
00171 free_parser_stacks ();
00172 }
00173
00174 struct c_fileinfo *
00175 get_fileinfo (name)
00176 const char *name;
00177 {
00178 splay_tree_node n;
00179 struct c_fileinfo *fi;
00180
00181 n = splay_tree_lookup (file_info_tree, (splay_tree_key) name);
00182 if (n)
00183 return (struct c_fileinfo *) n->value;
00184
00185 fi = (struct c_fileinfo *) xmalloc (sizeof (struct c_fileinfo));
00186 fi->time = 0;
00187 fi->interface_only = 0;
00188 fi->interface_unknown = 1;
00189 splay_tree_insert (file_info_tree, (splay_tree_key) name,
00190 (splay_tree_value) fi);
00191 return fi;
00192 }
00193
00194 static void
00195 update_header_times (name)
00196 const char *name;
00197 {
00198
00199
00200 if (flag_detailed_statistics)
00201 {
00202 int this_time = get_run_time ();
00203 struct c_fileinfo *file = get_fileinfo (name);
00204 header_time += this_time - body_time;
00205 file->time += this_time - body_time;
00206 body_time = this_time;
00207 }
00208 }
00209
00210 static int
00211 dump_one_header (n, dummy)
00212 splay_tree_node n;
00213 void *dummy ATTRIBUTE_UNUSED;
00214 {
00215 print_time ((const char *) n->key,
00216 ((struct c_fileinfo *) n->value)->time);
00217 return 0;
00218 }
00219
00220 void
00221 dump_time_statistics ()
00222 {
00223 struct c_fileinfo *file = get_fileinfo (input_filename);
00224 int this_time = get_run_time ();
00225 file->time += this_time - body_time;
00226
00227 fprintf (stderr, "\n******\n");
00228 print_time ("header files (total)", header_time);
00229 print_time ("main file (total)", this_time - body_time);
00230 fprintf (stderr, "ratio = %g : 1\n",
00231 (double)header_time / (double)(this_time - body_time));
00232 fprintf (stderr, "\n******\n");
00233
00234 splay_tree_foreach (file_info_tree, dump_one_header, 0);
00235 }
00236
00237 static void
00238 cb_ident (pfile, line, str)
00239 cpp_reader *pfile ATTRIBUTE_UNUSED;
00240 unsigned int line ATTRIBUTE_UNUSED;
00241 const cpp_string *str ATTRIBUTE_UNUSED;
00242 {
00243 #ifndef SGI_MONGOOSE
00244
00245
00246 #ifdef ASM_OUTPUT_IDENT
00247 if (! flag_no_ident)
00248 {
00249
00250 tree value = lex_string (str->text, str->len, 0);
00251 ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (value));
00252 }
00253 #endif
00254 #endif
00255 }
00256
00257
00258
00259 static void
00260 cb_line_change (pfile, token, parsing_args)
00261 cpp_reader *pfile ATTRIBUTE_UNUSED;
00262 const cpp_token *token;
00263 int parsing_args;
00264 {
00265 if (token->type == CPP_EOF || parsing_args)
00266 return;
00267
00268 src_lineno = SOURCE_LINE (map, token->line);
00269 #ifdef SGI_MONGOOSE
00270 WFE_Set_Line_And_File (lineno, input_filename);
00271 #endif
00272 }
00273
00274 static void
00275 cb_file_change (pfile, new_map)
00276 cpp_reader *pfile ATTRIBUTE_UNUSED;
00277 const struct line_map *new_map;
00278 {
00279 #ifdef SGI_MONGOOSE
00280 static short int skip_first = 1;
00281 #endif
00282 unsigned int to_line = SOURCE_LINE (new_map, new_map->to_line);
00283
00284 if (new_map->reason == LC_ENTER)
00285 {
00286
00287
00288 if (map == NULL)
00289 main_input_filename = new_map->to_file;
00290 else
00291 {
00292 int included_at = SOURCE_LINE (new_map - 1, new_map->from_line - 1);
00293
00294 lineno = included_at;
00295 push_srcloc (new_map->to_file, 1);
00296 #ifndef SGI_MONGOOSE
00297 (*debug_hooks->start_source_file) (included_at, new_map->to_file);
00298 #endif
00299 #ifndef NO_IMPLICIT_EXTERN_C
00300 if (c_header_level)
00301 ++c_header_level;
00302 else if (new_map->sysp == 2)
00303 {
00304 c_header_level = 1;
00305 ++pending_lang_change;
00306 }
00307 #endif
00308 }
00309 }
00310 else if (new_map->reason == LC_LEAVE)
00311 {
00312 #ifndef NO_IMPLICIT_EXTERN_C
00313 if (c_header_level && --c_header_level == 0)
00314 {
00315 if (new_map->sysp == 2)
00316 warning ("badly nested C headers from preprocessor");
00317 --pending_lang_change;
00318 }
00319 #endif
00320 pop_srcloc ();
00321
00322 #ifndef SGI_MONGOOSE
00323 (*debug_hooks->end_source_file) (to_line);
00324 #endif
00325 }
00326
00327 update_header_times (new_map->to_file);
00328 in_system_header = new_map->sysp != 0;
00329 input_filename = new_map->to_file;
00330 lineno = to_line;
00331 map = new_map;
00332
00333
00334 extract_interface_info ();
00335 #ifdef SGI_MONGOOSE
00336 if (strcmp(input_filename, "<built-in>") != 0 &&
00337 strcmp(input_filename, "<command line>") != 0 &&
00338 skip_first != 1)
00339 WFE_Set_Line_And_File (lineno, input_filename);
00340 skip_first = 0;
00341 #endif
00342 }
00343
00344 static void
00345 cb_def_pragma (pfile, line)
00346 cpp_reader *pfile;
00347 unsigned int line;
00348 {
00349
00350
00351
00352 if (warn_unknown_pragmas > in_system_header)
00353 {
00354 const unsigned char *space, *name;
00355 const cpp_token *s;
00356
00357 space = name = (const unsigned char *) "";
00358 s = cpp_get_token (pfile);
00359 if (s->type != CPP_EOF)
00360 {
00361 space = cpp_token_as_text (pfile, s);
00362 s = cpp_get_token (pfile);
00363 if (s->type == CPP_NAME)
00364 name = cpp_token_as_text (pfile, s);
00365 }
00366
00367 lineno = SOURCE_LINE (map, line);
00368 warning ("ignoring #pragma %s %s", space, name);
00369 }
00370 }
00371
00372
00373 static void
00374 cb_define (pfile, line, node)
00375 cpp_reader *pfile;
00376 unsigned int line;
00377 cpp_hashnode *node;
00378 {
00379 (*debug_hooks->define) (SOURCE_LINE (map, line),
00380 (const char *) cpp_macro_definition (pfile, node));
00381 }
00382
00383
00384 static void
00385 cb_undef (pfile, line, node)
00386 cpp_reader *pfile ATTRIBUTE_UNUSED;
00387 unsigned int line;
00388 cpp_hashnode *node;
00389 {
00390 (*debug_hooks->undef) (SOURCE_LINE (map, line),
00391 (const char *) NODE_NAME (node));
00392 }
00393
00394 #if 0
00395
00396
00397
00398
00399
00400
00401
00402
00403 static inline int
00404 is_extended_char (c)
00405 int c;
00406 {
00407 #ifdef TARGET_EBCDIC
00408 return 0;
00409 #else
00410
00411 if (c < 0x7f)
00412 return 0;
00413
00414
00415
00416 if (c > 0xffff)
00417 {
00418 error ("universal-character-name '\\U%08x' not valid in identifier", c);
00419 return 1;
00420 }
00421
00422
00423 if ((c >= 0x00c0 && c <= 0x00d6)
00424 || (c >= 0x00d8 && c <= 0x00f6)
00425 || (c >= 0x00f8 && c <= 0x01f5)
00426 || (c >= 0x01fa && c <= 0x0217)
00427 || (c >= 0x0250 && c <= 0x02a8)
00428 || (c >= 0x1e00 && c <= 0x1e9a)
00429 || (c >= 0x1ea0 && c <= 0x1ef9))
00430 return 1;
00431
00432
00433 if ((c == 0x0384)
00434 || (c >= 0x0388 && c <= 0x038a)
00435 || (c == 0x038c)
00436 || (c >= 0x038e && c <= 0x03a1)
00437 || (c >= 0x03a3 && c <= 0x03ce)
00438 || (c >= 0x03d0 && c <= 0x03d6)
00439 || (c == 0x03da)
00440 || (c == 0x03dc)
00441 || (c == 0x03de)
00442 || (c == 0x03e0)
00443 || (c >= 0x03e2 && c <= 0x03f3)
00444 || (c >= 0x1f00 && c <= 0x1f15)
00445 || (c >= 0x1f18 && c <= 0x1f1d)
00446 || (c >= 0x1f20 && c <= 0x1f45)
00447 || (c >= 0x1f48 && c <= 0x1f4d)
00448 || (c >= 0x1f50 && c <= 0x1f57)
00449 || (c == 0x1f59)
00450 || (c == 0x1f5b)
00451 || (c == 0x1f5d)
00452 || (c >= 0x1f5f && c <= 0x1f7d)
00453 || (c >= 0x1f80 && c <= 0x1fb4)
00454 || (c >= 0x1fb6 && c <= 0x1fbc)
00455 || (c >= 0x1fc2 && c <= 0x1fc4)
00456 || (c >= 0x1fc6 && c <= 0x1fcc)
00457 || (c >= 0x1fd0 && c <= 0x1fd3)
00458 || (c >= 0x1fd6 && c <= 0x1fdb)
00459 || (c >= 0x1fe0 && c <= 0x1fec)
00460 || (c >= 0x1ff2 && c <= 0x1ff4)
00461 || (c >= 0x1ff6 && c <= 0x1ffc))
00462 return 1;
00463
00464
00465 if ((c >= 0x0401 && c <= 0x040d)
00466 || (c >= 0x040f && c <= 0x044f)
00467 || (c >= 0x0451 && c <= 0x045c)
00468 || (c >= 0x045e && c <= 0x0481)
00469 || (c >= 0x0490 && c <= 0x04c4)
00470 || (c >= 0x04c7 && c <= 0x04c8)
00471 || (c >= 0x04cb && c <= 0x04cc)
00472 || (c >= 0x04d0 && c <= 0x04eb)
00473 || (c >= 0x04ee && c <= 0x04f5)
00474 || (c >= 0x04f8 && c <= 0x04f9))
00475 return 1;
00476
00477
00478 if ((c >= 0x0531 && c <= 0x0556)
00479 || (c >= 0x0561 && c <= 0x0587))
00480 return 1;
00481
00482
00483 if ((c >= 0x05d0 && c <= 0x05ea)
00484 || (c >= 0x05f0 && c <= 0x05f4))
00485 return 1;
00486
00487
00488 if ((c >= 0x0621 && c <= 0x063a)
00489 || (c >= 0x0640 && c <= 0x0652)
00490 || (c >= 0x0670 && c <= 0x06b7)
00491 || (c >= 0x06ba && c <= 0x06be)
00492 || (c >= 0x06c0 && c <= 0x06ce)
00493 || (c >= 0x06e5 && c <= 0x06e7))
00494 return 1;
00495
00496
00497 if ((c >= 0x0905 && c <= 0x0939)
00498 || (c >= 0x0958 && c <= 0x0962))
00499 return 1;
00500
00501
00502 if ((c >= 0x0985 && c <= 0x098c)
00503 || (c >= 0x098f && c <= 0x0990)
00504 || (c >= 0x0993 && c <= 0x09a8)
00505 || (c >= 0x09aa && c <= 0x09b0)
00506 || (c == 0x09b2)
00507 || (c >= 0x09b6 && c <= 0x09b9)
00508 || (c >= 0x09dc && c <= 0x09dd)
00509 || (c >= 0x09df && c <= 0x09e1)
00510 || (c >= 0x09f0 && c <= 0x09f1))
00511 return 1;
00512
00513
00514 if ((c >= 0x0a05 && c <= 0x0a0a)
00515 || (c >= 0x0a0f && c <= 0x0a10)
00516 || (c >= 0x0a13 && c <= 0x0a28)
00517 || (c >= 0x0a2a && c <= 0x0a30)
00518 || (c >= 0x0a32 && c <= 0x0a33)
00519 || (c >= 0x0a35 && c <= 0x0a36)
00520 || (c >= 0x0a38 && c <= 0x0a39)
00521 || (c >= 0x0a59 && c <= 0x0a5c)
00522 || (c == 0x0a5e))
00523 return 1;
00524
00525
00526 if ((c >= 0x0a85 && c <= 0x0a8b)
00527 || (c == 0x0a8d)
00528 || (c >= 0x0a8f && c <= 0x0a91)
00529 || (c >= 0x0a93 && c <= 0x0aa8)
00530 || (c >= 0x0aaa && c <= 0x0ab0)
00531 || (c >= 0x0ab2 && c <= 0x0ab3)
00532 || (c >= 0x0ab5 && c <= 0x0ab9)
00533 || (c == 0x0ae0))
00534 return 1;
00535
00536
00537 if ((c >= 0x0b05 && c <= 0x0b0c)
00538 || (c >= 0x0b0f && c <= 0x0b10)
00539 || (c >= 0x0b13 && c <= 0x0b28)
00540 || (c >= 0x0b2a && c <= 0x0b30)
00541 || (c >= 0x0b32 && c <= 0x0b33)
00542 || (c >= 0x0b36 && c <= 0x0b39)
00543 || (c >= 0x0b5c && c <= 0x0b5d)
00544 || (c >= 0x0b5f && c <= 0x0b61))
00545 return 1;
00546
00547
00548 if ((c >= 0x0b85 && c <= 0x0b8a)
00549 || (c >= 0x0b8e && c <= 0x0b90)
00550 || (c >= 0x0b92 && c <= 0x0b95)
00551 || (c >= 0x0b99 && c <= 0x0b9a)
00552 || (c == 0x0b9c)
00553 || (c >= 0x0b9e && c <= 0x0b9f)
00554 || (c >= 0x0ba3 && c <= 0x0ba4)
00555 || (c >= 0x0ba8 && c <= 0x0baa)
00556 || (c >= 0x0bae && c <= 0x0bb5)
00557 || (c >= 0x0bb7 && c <= 0x0bb9))
00558 return 1;
00559
00560
00561 if ((c >= 0x0c05 && c <= 0x0c0c)
00562 || (c >= 0x0c0e && c <= 0x0c10)
00563 || (c >= 0x0c12 && c <= 0x0c28)
00564 || (c >= 0x0c2a && c <= 0x0c33)
00565 || (c >= 0x0c35 && c <= 0x0c39)
00566 || (c >= 0x0c60 && c <= 0x0c61))
00567 return 1;
00568
00569
00570 if ((c >= 0x0c85 && c <= 0x0c8c)
00571 || (c >= 0x0c8e && c <= 0x0c90)
00572 || (c >= 0x0c92 && c <= 0x0ca8)
00573 || (c >= 0x0caa && c <= 0x0cb3)
00574 || (c >= 0x0cb5 && c <= 0x0cb9)
00575 || (c >= 0x0ce0 && c <= 0x0ce1))
00576 return 1;
00577
00578
00579 if ((c >= 0x0d05 && c <= 0x0d0c)
00580 || (c >= 0x0d0e && c <= 0x0d10)
00581 || (c >= 0x0d12 && c <= 0x0d28)
00582 || (c >= 0x0d2a && c <= 0x0d39)
00583 || (c >= 0x0d60 && c <= 0x0d61))
00584 return 1;
00585
00586
00587 if ((c >= 0x0e01 && c <= 0x0e30)
00588 || (c >= 0x0e32 && c <= 0x0e33)
00589 || (c >= 0x0e40 && c <= 0x0e46)
00590 || (c >= 0x0e4f && c <= 0x0e5b))
00591 return 1;
00592
00593
00594 if ((c >= 0x0e81 && c <= 0x0e82)
00595 || (c == 0x0e84)
00596 || (c == 0x0e87)
00597 || (c == 0x0e88)
00598 || (c == 0x0e8a)
00599 || (c == 0x0e0d)
00600 || (c >= 0x0e94 && c <= 0x0e97)
00601 || (c >= 0x0e99 && c <= 0x0e9f)
00602 || (c >= 0x0ea1 && c <= 0x0ea3)
00603 || (c == 0x0ea5)
00604 || (c == 0x0ea7)
00605 || (c == 0x0eaa)
00606 || (c == 0x0eab)
00607 || (c >= 0x0ead && c <= 0x0eb0)
00608 || (c == 0x0eb2)
00609 || (c == 0x0eb3)
00610 || (c == 0x0ebd)
00611 || (c >= 0x0ec0 && c <= 0x0ec4)
00612 || (c == 0x0ec6))
00613 return 1;
00614
00615
00616 if ((c >= 0x10a0 && c <= 0x10c5)
00617 || (c >= 0x10d0 && c <= 0x10f6))
00618 return 1;
00619
00620
00621 if ((c >= 0x3041 && c <= 0x3094)
00622 || (c >= 0x309b && c <= 0x309e))
00623 return 1;
00624
00625
00626 if ((c >= 0x30a1 && c <= 0x30fe))
00627 return 1;
00628
00629
00630 if ((c >= 0x3105 && c <= 0x312c))
00631 return 1;
00632
00633
00634 if ((c >= 0x1100 && c <= 0x1159)
00635 || (c >= 0x1161 && c <= 0x11a2)
00636 || (c >= 0x11a8 && c <= 0x11f9))
00637 return 1;
00638
00639
00640 if ((c >= 0xf900 && c <= 0xfa2d)
00641 || (c >= 0xfb1f && c <= 0xfb36)
00642 || (c >= 0xfb38 && c <= 0xfb3c)
00643 || (c == 0xfb3e)
00644 || (c >= 0xfb40 && c <= 0xfb41)
00645 || (c >= 0xfb42 && c <= 0xfb44)
00646 || (c >= 0xfb46 && c <= 0xfbb1)
00647 || (c >= 0xfbd3 && c <= 0xfd3f)
00648 || (c >= 0xfd50 && c <= 0xfd8f)
00649 || (c >= 0xfd92 && c <= 0xfdc7)
00650 || (c >= 0xfdf0 && c <= 0xfdfb)
00651 || (c >= 0xfe70 && c <= 0xfe72)
00652 || (c == 0xfe74)
00653 || (c >= 0xfe76 && c <= 0xfefc)
00654 || (c >= 0xff21 && c <= 0xff3a)
00655 || (c >= 0xff41 && c <= 0xff5a)
00656 || (c >= 0xff66 && c <= 0xffbe)
00657 || (c >= 0xffc2 && c <= 0xffc7)
00658 || (c >= 0xffca && c <= 0xffcf)
00659 || (c >= 0xffd2 && c <= 0xffd7)
00660 || (c >= 0xffda && c <= 0xffdc)
00661 || (c >= 0x4e00 && c <= 0x9fa5))
00662 return 1;
00663
00664 error ("universal-character-name '\\u%04x' not valid in identifier", c);
00665 return 1;
00666 #endif
00667 }
00668
00669
00670
00671 static void
00672 utf8_extend_token (c)
00673 int c;
00674 {
00675 int shift, mask;
00676
00677 if (c <= 0x0000007f)
00678 {
00679 extend_token (c);
00680 return;
00681 }
00682 else if (c <= 0x000007ff)
00683 shift = 6, mask = 0xc0;
00684 else if (c <= 0x0000ffff)
00685 shift = 12, mask = 0xe0;
00686 else if (c <= 0x001fffff)
00687 shift = 18, mask = 0xf0;
00688 else if (c <= 0x03ffffff)
00689 shift = 24, mask = 0xf8;
00690 else
00691 shift = 30, mask = 0xfc;
00692
00693 extend_token (mask | (c >> shift));
00694 do
00695 {
00696 shift -= 6;
00697 extend_token ((unsigned char) (0x80 | (c >> shift)));
00698 }
00699 while (shift);
00700 }
00701 #endif
00702
00703 #ifdef KEY
00704 bool in_omp_pragma = FALSE;
00705
00706
00707 extern bool last_token_omp_hash;
00708 #endif
00709
00710 int
00711 c_lex (value)
00712 tree *value;
00713 {
00714 const cpp_token *tok;
00715
00716 retry:
00717 timevar_push (TV_CPP);
00718 do
00719 tok = cpp_get_token (parse_in);
00720 while (tok->type == CPP_PADDING);
00721 timevar_pop (TV_CPP);
00722
00723 #ifdef KEY
00724 if (last_token_omp_hash && tok->type == CPP_NAME)
00725 {
00726 tree name = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node));
00727 last_token_omp_hash = FALSE;
00728 if (TREE_CODE (name) == IDENTIFIER_NODE &&
00729 !strcmp (IDENTIFIER_POINTER (name), "pragma"))
00730 {
00731 tok = cpp_get_token (parse_in);
00732 in_omp_pragma = TRUE;
00733 }
00734 }
00735 #endif // KEY
00736
00737
00738
00739
00740 lineno = src_lineno;
00741
00742 *value = NULL_TREE;
00743 switch (tok->type)
00744 {
00745
00746 case CPP_OTHER:
00747 if (ISGRAPH (tok->val.c))
00748 error ("stray '%c' in program", tok->val.c);
00749 else
00750 error ("stray '\\%o' in program", tok->val.c);
00751 goto retry;
00752
00753 case CPP_NAME:
00754 *value = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node));
00755 break;
00756
00757 case CPP_NUMBER:
00758 {
00759 unsigned int flags = cpp_classify_number (parse_in, tok);
00760
00761 switch (flags & CPP_N_CATEGORY)
00762 {
00763 case CPP_N_INVALID:
00764
00765 *value = error_mark_node;
00766 break;
00767
00768 case CPP_N_INTEGER:
00769 *value = interpret_integer (tok, flags);
00770 break;
00771
00772 case CPP_N_FLOATING:
00773 *value = interpret_float (tok, flags);
00774 break;
00775
00776 default:
00777 abort ();
00778 }
00779 }
00780 break;
00781
00782 case CPP_CHAR:
00783 case CPP_WCHAR:
00784 *value = lex_charconst (tok);
00785 break;
00786
00787 case CPP_STRING:
00788 case CPP_WSTRING:
00789 *value = lex_string (tok->val.str.text, tok->val.str.len,
00790 tok->type == CPP_WSTRING);
00791 break;
00792
00793
00794 case CPP_HEADER_NAME:
00795 case CPP_COMMENT:
00796 case CPP_MACRO_ARG:
00797 abort ();
00798
00799 default: break;
00800 }
00801
00802 return tok->type;
00803 }
00804
00805
00806
00807
00808 static enum integer_type_kind
00809 narrowest_unsigned_type (value, flags)
00810 tree value;
00811 unsigned int flags;
00812 {
00813 enum integer_type_kind itk;
00814
00815 if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
00816 itk = itk_unsigned_int;
00817 else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
00818 itk = itk_unsigned_long;
00819 else
00820 itk = itk_unsigned_long_long;
00821
00822
00823
00824 TREE_TYPE (value) = widest_unsigned_literal_type_node;
00825
00826 for (; itk < itk_none; itk += 2 )
00827 if (int_fits_type_p (value, integer_types[itk]))
00828 return itk;
00829
00830 return itk_none;
00831 }
00832
00833
00834 static enum integer_type_kind
00835 narrowest_signed_type (value, flags)
00836 tree value;
00837 unsigned int flags;
00838 {
00839 enum integer_type_kind itk;
00840
00841 if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
00842 itk = itk_int;
00843 else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
00844 itk = itk_long;
00845 else
00846 itk = itk_long_long;
00847
00848
00849
00850 TREE_TYPE (value) = widest_unsigned_literal_type_node;
00851
00852 for (; itk < itk_none; itk += 2 )
00853 if (int_fits_type_p (value, integer_types[itk]))
00854 return itk;
00855
00856 return itk_none;
00857 }
00858
00859
00860 static tree
00861 interpret_integer (token, flags)
00862 const cpp_token *token;
00863 unsigned int flags;
00864 {
00865 tree value, type;
00866 enum integer_type_kind itk;
00867 cpp_num integer;
00868 cpp_options *options = cpp_get_options (parse_in);
00869
00870 integer = cpp_interpret_integer (parse_in, token, flags);
00871 integer = cpp_num_sign_extend (integer, options->precision);
00872 value = build_int_2_wide (integer.low, integer.high);
00873
00874
00875 if (flags & CPP_N_UNSIGNED)
00876 itk = narrowest_unsigned_type (value, flags);
00877 else
00878 {
00879
00880
00881
00882 enum integer_type_kind itk_u = narrowest_unsigned_type (value, flags);
00883 enum integer_type_kind itk_s = narrowest_signed_type (value, flags);
00884
00885
00886
00887
00888
00889 if ((flags & CPP_N_RADIX) != CPP_N_DECIMAL)
00890 itk = MIN (itk_u, itk_s);
00891 else
00892 {
00893
00894
00895
00896
00897
00898
00899 itk = itk_s;
00900 if (itk_s > itk_u && itk_s > itk_long)
00901 {
00902 #ifndef KEY
00903 if (!flag_isoc99)
00904 #else
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917 if (1)
00918 #endif
00919 {
00920 if (itk_u < itk_unsigned_long)
00921 itk_u = itk_unsigned_long;
00922 itk = itk_u;
00923 warning ("this decimal constant is unsigned only in ISO C90");
00924 }
00925 else if (warn_traditional)
00926 warning ("this decimal constant would be unsigned in ISO C90");
00927 }
00928 }
00929 }
00930
00931 if (itk == itk_none)
00932
00933 type = ((flags & CPP_N_UNSIGNED)
00934 ? widest_unsigned_literal_type_node
00935 : widest_integer_literal_type_node);
00936 else
00937 type = integer_types[itk];
00938
00939 if (itk > itk_unsigned_long
00940 && (flags & CPP_N_WIDTH) != CPP_N_LARGE
00941 && ! in_system_header && ! flag_isoc99)
00942 pedwarn ("integer constant is too large for \"%s\" type",
00943 (flags & CPP_N_UNSIGNED) ? "unsigned long" : "long");
00944
00945 TREE_TYPE (value) = type;
00946
00947
00948 if (flags & CPP_N_IMAGINARY)
00949 value = build_complex (NULL_TREE, convert (type, integer_zero_node), value);
00950
00951 return value;
00952 }
00953
00954
00955
00956 static tree
00957 interpret_float (token, flags)
00958 const cpp_token *token;
00959 unsigned int flags;
00960 {
00961 tree type;
00962 tree value;
00963 REAL_VALUE_TYPE real;
00964 char *copy;
00965 size_t copylen;
00966 const char *typename;
00967
00968
00969 if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
00970 {
00971 type = long_double_type_node;
00972 typename = "long double";
00973 }
00974 else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL
00975 || flag_single_precision_constant)
00976 {
00977 type = float_type_node;
00978 typename = "float";
00979 }
00980 else
00981 {
00982 type = double_type_node;
00983 typename = "double";
00984 }
00985
00986
00987
00988
00989 copylen = token->val.str.len;
00990 if ((flags & CPP_N_WIDTH) != CPP_N_MEDIUM)
00991
00992 copylen--;
00993 if (flags & CPP_N_IMAGINARY)
00994
00995 copylen--;
00996
00997 copy = alloca (copylen + 1);
00998 memcpy (copy, token->val.str.text, copylen);
00999 copy[copylen] = '\0';
01000
01001 real_from_string (&real, copy);
01002 real_convert (&real, TYPE_MODE (type), &real);
01003
01004
01005
01006
01007
01008
01009 if (REAL_VALUE_ISINF (real) && pedantic)
01010 warning ("floating constant exceeds range of \"%s\"", typename);
01011
01012
01013 value = build_real (type, real);
01014 if (flags & CPP_N_IMAGINARY)
01015 value = build_complex (NULL_TREE, convert (type, integer_zero_node), value);
01016
01017 return value;
01018 }
01019
01020 static tree
01021 lex_string (str, len, wide)
01022 const unsigned char *str;
01023 unsigned int len;
01024 int wide;
01025 {
01026 tree value;
01027 char *buf = alloca ((len + 1) * (wide ? WCHAR_BYTES : 1));
01028 char *q = buf;
01029 const unsigned char *p = str, *limit = str + len;
01030 cppchar_t c;
01031
01032 #ifdef MULTIBYTE_CHARS
01033
01034 (void) local_mbtowc (NULL, NULL, 0);
01035 #endif
01036
01037 while (p < limit)
01038 {
01039 #ifdef MULTIBYTE_CHARS
01040 wchar_t wc;
01041 int char_len;
01042
01043 char_len = local_mbtowc (&wc, (const char *) p, limit - p);
01044 if (char_len == -1)
01045 {
01046 warning ("ignoring invalid multibyte character");
01047 char_len = 1;
01048 c = *p++;
01049 }
01050 else
01051 {
01052 p += char_len;
01053 c = wc;
01054 }
01055 #else
01056 c = *p++;
01057 #endif
01058
01059 if (c == '\\' && !ignore_escape_flag)
01060 c = cpp_parse_escape (parse_in, &p, limit, wide);
01061
01062
01063
01064 if (wide)
01065 {
01066 unsigned charwidth = TYPE_PRECISION (char_type_node);
01067 unsigned bytemask = (1 << charwidth) - 1;
01068 int byte;
01069
01070 for (byte = 0; byte < WCHAR_BYTES; ++byte)
01071 {
01072 int n;
01073 if (byte >= (int) sizeof (c))
01074 n = 0;
01075 else
01076 n = (c >> (byte * charwidth)) & bytemask;
01077 if (BYTES_BIG_ENDIAN)
01078 q[WCHAR_BYTES - byte - 1] = n;
01079 else
01080 q[byte] = n;
01081 }
01082 q += WCHAR_BYTES;
01083 }
01084 #ifdef MULTIBYTE_CHARS
01085 else if (char_len > 1)
01086 {
01087
01088 for ( ; char_len >0; --char_len)
01089 {
01090 *q++ = *(p - char_len);
01091 }
01092 }
01093 #endif
01094 else
01095 {
01096 *q++ = c;
01097 }
01098 }
01099
01100
01101
01102
01103 if (wide)
01104 {
01105 memset (q, 0, WCHAR_BYTES);
01106 q += WCHAR_BYTES;
01107 }
01108 else
01109 {
01110 *q++ = '\0';
01111 }
01112
01113 value = build_string (q - buf, buf);
01114
01115 if (wide)
01116 TREE_TYPE (value) = wchar_array_type_node;
01117 else
01118 TREE_TYPE (value) = char_array_type_node;
01119 return value;
01120 }
01121
01122
01123 static tree
01124 lex_charconst (token)
01125 const cpp_token *token;
01126 {
01127 cppchar_t result;
01128 tree type, value;
01129 unsigned int chars_seen;
01130 int unsignedp;
01131
01132 result = cpp_interpret_charconst (parse_in, token,
01133 &chars_seen, &unsignedp);
01134
01135
01136
01137 if (unsignedp || (cppchar_signed_t) result >= 0)
01138 value = build_int_2 (result, 0);
01139 else
01140 value = build_int_2 ((cppchar_signed_t) result, -1);
01141
01142 if (token->type == CPP_WCHAR)
01143 type = wchar_type_node;
01144
01145
01146 else if ((c_language == clk_c) || chars_seen > 1)
01147 type = integer_type_node;
01148 else
01149 type = char_type_node;
01150
01151 TREE_TYPE (value) = type;
01152 return value;
01153 }