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