comparison libcpp/expr.c @ 63:b7f97abdc517 gcc-4.6-20100522

update gcc from gcc-4.5.0 to gcc-4.6
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Mon, 24 May 2010 12:47:05 +0900
parents 77e2b8dfacca
children f6334be47118
comparison
equal deleted inserted replaced
56:3c8a44c06a95 63:b7f97abdc517
1 /* Parse C expressions for cpplib. 1 /* Parse C expressions for cpplib.
2 Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001, 2 Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
3 2002, 2004, 2008, 2009 Free Software Foundation. 3 2002, 2004, 2008, 2009, 2010 Free Software Foundation.
4 Contributed by Per Bothner, 1994. 4 Contributed by Per Bothner, 1994.
5 5
6 This program is free software; you can redistribute it and/or modify it 6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the 7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any 8 Free Software Foundation; either version 3, or (at your option) any
227 { 227 {
228 const uchar *str = token->val.str.text; 228 const uchar *str = token->val.str.text;
229 const uchar *limit; 229 const uchar *limit;
230 unsigned int max_digit, result, radix; 230 unsigned int max_digit, result, radix;
231 enum {NOT_FLOAT = 0, AFTER_POINT, AFTER_EXPON} float_flag; 231 enum {NOT_FLOAT = 0, AFTER_POINT, AFTER_EXPON} float_flag;
232 bool seen_digit;
232 233
233 /* If the lexer has done its job, length one can only be a single 234 /* If the lexer has done its job, length one can only be a single
234 digit. Fast-path this very common case. */ 235 digit. Fast-path this very common case. */
235 if (token->val.str.len == 1) 236 if (token->val.str.len == 1)
236 return CPP_N_INTEGER | CPP_N_SMALL | CPP_N_DECIMAL; 237 return CPP_N_INTEGER | CPP_N_SMALL | CPP_N_DECIMAL;
237 238
238 limit = str + token->val.str.len; 239 limit = str + token->val.str.len;
239 float_flag = NOT_FLOAT; 240 float_flag = NOT_FLOAT;
240 max_digit = 0; 241 max_digit = 0;
241 radix = 10; 242 radix = 10;
243 seen_digit = false;
242 244
243 /* First, interpret the radix. */ 245 /* First, interpret the radix. */
244 if (*str == '0') 246 if (*str == '0')
245 { 247 {
246 radix = 8; 248 radix = 8;
265 { 267 {
266 unsigned int c = *str++; 268 unsigned int c = *str++;
267 269
268 if (ISDIGIT (c) || (ISXDIGIT (c) && radix == 16)) 270 if (ISDIGIT (c) || (ISXDIGIT (c) && radix == 16))
269 { 271 {
272 seen_digit = true;
270 c = hex_value (c); 273 c = hex_value (c);
271 if (c > max_digit) 274 if (c > max_digit)
272 max_digit = c; 275 max_digit = c;
273 } 276 }
274 else if (c == '.') 277 else if (c == '.')
330 cpp_error (pfile, CPP_DL_ERROR, 333 cpp_error (pfile, CPP_DL_ERROR,
331 "invalid prefix \"0b\" for floating constant"); 334 "invalid prefix \"0b\" for floating constant");
332 return CPP_N_INVALID; 335 return CPP_N_INVALID;
333 } 336 }
334 337
338 if (radix == 16 && !seen_digit)
339 SYNTAX_ERROR ("no digits in hexadecimal floating constant");
340
335 if (radix == 16 && CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, c99)) 341 if (radix == 16 && CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, c99))
336 cpp_error (pfile, CPP_DL_PEDWARN, 342 cpp_error (pfile, CPP_DL_PEDWARN,
337 "use of C99 hexadecimal floating constant"); 343 "use of C99 hexadecimal floating constant");
338 344
339 if (float_flag == AFTER_EXPON) 345 if (float_flag == AFTER_EXPON)
363 369
364 /* Traditional C didn't accept any floating suffixes. */ 370 /* Traditional C didn't accept any floating suffixes. */
365 if (limit != str 371 if (limit != str
366 && CPP_WTRADITIONAL (pfile) 372 && CPP_WTRADITIONAL (pfile)
367 && ! cpp_sys_macro_p (pfile)) 373 && ! cpp_sys_macro_p (pfile))
368 cpp_error (pfile, CPP_DL_WARNING, 374 cpp_warning (pfile, CPP_W_TRADITIONAL,
369 "traditional C rejects the \"%.*s\" suffix", 375 "traditional C rejects the \"%.*s\" suffix",
370 (int) (limit - str), str); 376 (int) (limit - str), str);
371 377
372 /* A suffix for double is a GCC extension via decimal float support. 378 /* A suffix for double is a GCC extension via decimal float support.
373 If the suffix also specifies an imaginary value we'll catch that 379 If the suffix also specifies an imaginary value we'll catch that
374 later. */ 380 later. */
375 if ((result == CPP_N_MEDIUM) && CPP_PEDANTIC (pfile)) 381 if ((result == CPP_N_MEDIUM) && CPP_PEDANTIC (pfile))
409 /* Traditional C only accepted the 'L' suffix. 415 /* Traditional C only accepted the 'L' suffix.
410 Suppress warning about 'LL' with -Wno-long-long. */ 416 Suppress warning about 'LL' with -Wno-long-long. */
411 if (CPP_WTRADITIONAL (pfile) && ! cpp_sys_macro_p (pfile)) 417 if (CPP_WTRADITIONAL (pfile) && ! cpp_sys_macro_p (pfile))
412 { 418 {
413 int u_or_i = (result & (CPP_N_UNSIGNED|CPP_N_IMAGINARY)); 419 int u_or_i = (result & (CPP_N_UNSIGNED|CPP_N_IMAGINARY));
414 int large = (result & CPP_N_WIDTH) == CPP_N_LARGE; 420 int large = (result & CPP_N_WIDTH) == CPP_N_LARGE
415 421 && CPP_OPTION (pfile, warn_long_long);
416 if (u_or_i || (large && CPP_OPTION (pfile, warn_long_long))) 422
417 cpp_error (pfile, CPP_DL_WARNING, 423 if (u_or_i || large)
418 "traditional C rejects the \"%.*s\" suffix", 424 cpp_warning (pfile, large ? CPP_W_LONG_LONG : CPP_W_TRADITIONAL,
419 (int) (limit - str), str); 425 "traditional C rejects the \"%.*s\" suffix",
426 (int) (limit - str), str);
420 } 427 }
421 428
422 if ((result & CPP_N_WIDTH) == CPP_N_LARGE 429 if ((result & CPP_N_WIDTH) == CPP_N_LARGE
423 && CPP_OPTION (pfile, warn_long_long)) 430 && CPP_OPTION (pfile, warn_long_long))
424 cpp_error (pfile, 431 {
425 CPP_OPTION (pfile, c99) ? CPP_DL_WARNING : CPP_DL_PEDWARN, 432 const char *message = CPP_OPTION (pfile, cplusplus)
426 CPP_OPTION (pfile, cplusplus) 433 ? N_("use of C++0x long long integer constant")
427 ? "use of C++0x long long integer constant" 434 : N_("use of C99 long long integer constant");
428 : "use of C99 long long integer constant"); 435
436 if (CPP_OPTION (pfile, c99))
437 cpp_warning (pfile, CPP_W_LONG_LONG, message);
438 else
439 cpp_pedwarning (pfile, CPP_W_LONG_LONG, message);
440 }
429 441
430 result |= CPP_N_INTEGER; 442 result |= CPP_N_INTEGER;
431 } 443 }
432 444
433 syntax_ok: 445 syntax_ok:
784 else 796 else
785 { 797 {
786 result.high = 0; 798 result.high = 0;
787 result.low = 0; 799 result.low = 0;
788 if (CPP_OPTION (pfile, warn_undef) && !pfile->state.skip_eval) 800 if (CPP_OPTION (pfile, warn_undef) && !pfile->state.skip_eval)
789 cpp_error (pfile, CPP_DL_WARNING, "\"%s\" is not defined", 801 cpp_warning (pfile, CPP_W_UNDEF, "\"%s\" is not defined",
790 NODE_NAME (token->val.node.node)); 802 NODE_NAME (token->val.node.node));
791 } 803 }
792 break; 804 break;
793 805
794 case CPP_HASH: 806 case CPP_HASH:
795 if (!pfile->state.skipping) 807 if (!pfile->state.skipping)
798 warning here. */ 810 warning here. */
799 if (CPP_PEDANTIC (pfile)) 811 if (CPP_PEDANTIC (pfile))
800 cpp_error (pfile, CPP_DL_PEDWARN, 812 cpp_error (pfile, CPP_DL_PEDWARN,
801 "assertions are a GCC extension"); 813 "assertions are a GCC extension");
802 else if (CPP_OPTION (pfile, warn_deprecated)) 814 else if (CPP_OPTION (pfile, warn_deprecated))
803 cpp_error (pfile, CPP_DL_WARNING, 815 cpp_warning (pfile, CPP_W_DEPRECATED,
804 "assertions are a deprecated extension"); 816 "assertions are a deprecated extension");
805 } 817 }
806 _cpp_test_assertion (pfile, &temp); 818 _cpp_test_assertion (pfile, &temp);
807 result.high = 0; 819 result.high = 0;
808 result.low = temp; 820 result.low = temp;
809 break; 821 break;
1494 { 1506 {
1495 switch (op) 1507 switch (op)
1496 { 1508 {
1497 case CPP_UPLUS: 1509 case CPP_UPLUS:
1498 if (CPP_WTRADITIONAL (pfile) && !pfile->state.skip_eval) 1510 if (CPP_WTRADITIONAL (pfile) && !pfile->state.skip_eval)
1499 cpp_error (pfile, CPP_DL_WARNING, 1511 cpp_warning (pfile, CPP_W_TRADITIONAL,
1500 "traditional C rejects the unary plus operator"); 1512 "traditional C rejects the unary plus operator");
1501 num.overflow = false; 1513 num.overflow = false;
1502 break; 1514 break;
1503 1515
1504 case CPP_UMINUS: 1516 case CPP_UMINUS:
1505 num = num_negate (num, CPP_OPTION (pfile, precision)); 1517 num = num_negate (num, CPP_OPTION (pfile, precision));