expr.c (250566) | expr.c (255107) |
---|---|
1/* Parse C expressions for cpplib. 2 Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001, 3 2002, 2004 Free Software Foundation. 4 Contributed by Per Bothner, 1994. 5 6This program is free software; you can redistribute it and/or modify it 7under the terms of the GNU General Public License as published by the 8Free Software Foundation; either version 2, or (at your option) any --- 174 unchanged lines hidden (view full) --- 183 184 /* Require at least one hex digit to classify it as hex. */ 185 if ((*str == 'x' || *str == 'X') 186 && (str[1] == '.' || ISXDIGIT (str[1]))) 187 { 188 radix = 16; 189 str++; 190 } | 1/* Parse C expressions for cpplib. 2 Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001, 3 2002, 2004 Free Software Foundation. 4 Contributed by Per Bothner, 1994. 5 6This program is free software; you can redistribute it and/or modify it 7under the terms of the GNU General Public License as published by the 8Free Software Foundation; either version 2, or (at your option) any --- 174 unchanged lines hidden (view full) --- 183 184 /* Require at least one hex digit to classify it as hex. */ 185 if ((*str == 'x' || *str == 'X') 186 && (str[1] == '.' || ISXDIGIT (str[1]))) 187 { 188 radix = 16; 189 str++; 190 } |
191 else if ((*str == 'b' || *str == 'B') && (str[1] == '0' || str[1] == '1')) 192 { 193 radix = 2; 194 str++; 195 } |
|
191 } 192 193 /* Now scan for a well-formed integer or float. */ 194 for (;;) 195 { 196 unsigned int c = *str++; 197 198 if (ISDIGIT (c) || (ISXDIGIT (c) && radix == 16)) --- 22 unchanged lines hidden (view full) --- 221 break; 222 } 223 } 224 225 if (float_flag != NOT_FLOAT && radix == 8) 226 radix = 10; 227 228 if (max_digit >= radix) | 196 } 197 198 /* Now scan for a well-formed integer or float. */ 199 for (;;) 200 { 201 unsigned int c = *str++; 202 203 if (ISDIGIT (c) || (ISXDIGIT (c) && radix == 16)) --- 22 unchanged lines hidden (view full) --- 226 break; 227 } 228 } 229 230 if (float_flag != NOT_FLOAT && radix == 8) 231 radix = 10; 232 233 if (max_digit >= radix) |
229 SYNTAX_ERROR2 ("invalid digit \"%c\" in octal constant", '0' + max_digit); | 234 { 235 if (radix == 2) 236 SYNTAX_ERROR2 ("invalid digit \"%c\" in binary constant", '0' + max_digit); 237 else 238 SYNTAX_ERROR2 ("invalid digit \"%c\" in octal constant", '0' + max_digit); 239 } |
230 231 if (float_flag != NOT_FLOAT) 232 { | 240 241 if (float_flag != NOT_FLOAT) 242 { |
243 if (radix == 2) 244 { 245 cpp_error (pfile, CPP_DL_ERROR, 246 "invalid prefix \"0b\" for floating constant"); 247 return CPP_N_INVALID; 248 } 249 |
|
233 if (radix == 16 && CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, c99)) 234 cpp_error (pfile, CPP_DL_PEDWARN, 235 "use of C99 hexadecimal floating constant"); 236 237 if (float_flag == AFTER_EXPON) 238 { 239 if (*str == '+' || *str == '-') 240 str++; --- 75 unchanged lines hidden (view full) --- 316 "use of C99 long long integer constant"); 317 318 result |= CPP_N_INTEGER; 319 } 320 321 if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile)) 322 cpp_error (pfile, CPP_DL_PEDWARN, 323 "imaginary constants are a GCC extension"); | 250 if (radix == 16 && CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, c99)) 251 cpp_error (pfile, CPP_DL_PEDWARN, 252 "use of C99 hexadecimal floating constant"); 253 254 if (float_flag == AFTER_EXPON) 255 { 256 if (*str == '+' || *str == '-') 257 str++; --- 75 unchanged lines hidden (view full) --- 333 "use of C99 long long integer constant"); 334 335 result |= CPP_N_INTEGER; 336 } 337 338 if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile)) 339 cpp_error (pfile, CPP_DL_PEDWARN, 340 "imaginary constants are a GCC extension"); |
341 if (radix == 2 && CPP_PEDANTIC (pfile)) 342 cpp_error (pfile, CPP_DL_PEDWARN, 343 "binary constants are a GCC extension"); |
|
324 325 if (radix == 10) 326 result |= CPP_N_DECIMAL; 327 else if (radix == 16) 328 result |= CPP_N_HEX; | 344 345 if (radix == 10) 346 result |= CPP_N_DECIMAL; 347 else if (radix == 16) 348 result |= CPP_N_HEX; |
349 else if (radix == 2) 350 result |= CPP_N_BINARY; |
|
329 else 330 result |= CPP_N_OCTAL; 331 332 return result; 333 334 syntax_error: 335 return CPP_N_INVALID; 336} --- 34 unchanged lines hidden (view full) --- 371 base = 8; 372 p++; 373 } 374 else if ((type & CPP_N_RADIX) == CPP_N_HEX) 375 { 376 base = 16; 377 p += 2; 378 } | 351 else 352 result |= CPP_N_OCTAL; 353 354 return result; 355 356 syntax_error: 357 return CPP_N_INVALID; 358} --- 34 unchanged lines hidden (view full) --- 393 base = 8; 394 p++; 395 } 396 else if ((type & CPP_N_RADIX) == CPP_N_HEX) 397 { 398 base = 16; 399 p += 2; 400 } |
401 else if ((type & CPP_N_RADIX) == CPP_N_BINARY) 402 { 403 base = 2; 404 p += 2; 405 } |
|
379 380 /* We can add a digit to numbers strictly less than this without 381 needing the precision and slowness of double integers. */ 382 max = ~(cpp_num_part) 0; 383 if (precision < PART_PRECISION) 384 max >>= PART_PRECISION - precision; 385 max = (max - base + 1) / base + 1; 386 --- 39 unchanged lines hidden (view full) --- 426 return result; 427} 428 429/* Append DIGIT to NUM, a number of PRECISION bits being read in base BASE. */ 430static cpp_num 431append_digit (cpp_num num, int digit, int base, size_t precision) 432{ 433 cpp_num result; | 406 407 /* We can add a digit to numbers strictly less than this without 408 needing the precision and slowness of double integers. */ 409 max = ~(cpp_num_part) 0; 410 if (precision < PART_PRECISION) 411 max >>= PART_PRECISION - precision; 412 max = (max - base + 1) / base + 1; 413 --- 39 unchanged lines hidden (view full) --- 453 return result; 454} 455 456/* Append DIGIT to NUM, a number of PRECISION bits being read in base BASE. */ 457static cpp_num 458append_digit (cpp_num num, int digit, int base, size_t precision) 459{ 460 cpp_num result; |
434 unsigned int shift = 3 + (base == 16); | 461 unsigned int shift; |
435 bool overflow; 436 cpp_num_part add_high, add_low; 437 | 462 bool overflow; 463 cpp_num_part add_high, add_low; 464 |
438 /* Multiply by 8 or 16. Catching this overflow here means we don't | 465 /* Multiply by 2, 8 or 16. Catching this overflow here means we don't |
439 need to worry about add_high overflowing. */ | 466 need to worry about add_high overflowing. */ |
467 switch (base) 468 { 469 case 2: 470 shift = 1; 471 break; 472 473 case 16: 474 shift = 4; 475 break; 476 477 default: 478 shift = 3; 479 } |
|
440 overflow = !!(num.high >> (PART_PRECISION - shift)); 441 result.high = num.high << shift; 442 result.low = num.low << shift; 443 result.high |= num.low >> (PART_PRECISION - shift); 444 result.unsignedp = num.unsignedp; 445 446 if (base == 10) 447 { --- 1109 unchanged lines hidden --- | 480 overflow = !!(num.high >> (PART_PRECISION - shift)); 481 result.high = num.high << shift; 482 result.low = num.low << shift; 483 result.high |= num.low >> (PART_PRECISION - shift); 484 result.unsignedp = num.unsignedp; 485 486 if (base == 10) 487 { --- 1109 unchanged lines hidden --- |