|
|
1.1.1.2 root 1: /* Lexical analyzer for C and Objective C. 1.1.1.7 ! root 2: Copyright (C) 1987, 1988, 1989, 1992, 1994 Free Software Foundation, Inc. 1.1 root 3: 4: This file is part of GNU CC. 5: 6: GNU CC is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU CC is distributed in the hope that it will be useful, 12: but WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14: GNU General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU CC; see the file COPYING. If not, write to 18: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ 19: 20: 21: #include <stdio.h> 22: #include <errno.h> 23: #include <setjmp.h> 24: 25: #include "config.h" 26: #include "rtl.h" 27: #include "tree.h" 28: #include "input.h" 29: #include "c-lex.h" 30: #include "c-tree.h" 31: #include "flags.h" 32: #include "c-parse.h" 33: 1.1.1.6 root 34: #include <ctype.h> 35: 1.1 root 36: #ifdef MULTIBYTE_CHARS 37: #include <stdlib.h> 38: #include <locale.h> 39: #endif 40: 41: #ifndef errno 42: extern int errno; 43: #endif 44: 45: /* The elements of `ridpointers' are identifier nodes 46: for the reserved type names and storage classes. 47: It is indexed by a RID_... value. */ 48: tree ridpointers[(int) RID_MAX]; 49: 50: /* Cause the `yydebug' variable to be defined. */ 51: #define YYDEBUG 1 52: 53: /* the declaration found for the last IDENTIFIER token read in. 54: yylex must look this up to detect typedefs, which get token type TYPENAME, 55: so it is left around in case the identifier is not a typedef but is 56: used in a context which makes it a reference to a variable. */ 57: tree lastiddecl; 58: 59: /* Nonzero enables objc features. */ 60: 61: int doing_objc_thang; 62: 1.1.1.5 root 63: extern tree is_class_name (); 1.1 root 64: 65: extern int yydebug; 66: 67: /* File used for outputting assembler code. */ 68: extern FILE *asm_out_file; 69: 70: #ifndef WCHAR_TYPE_SIZE 71: #ifdef INT_TYPE_SIZE 72: #define WCHAR_TYPE_SIZE INT_TYPE_SIZE 73: #else 74: #define WCHAR_TYPE_SIZE BITS_PER_WORD 75: #endif 76: #endif 77: 78: /* Number of bytes in a wide character. */ 79: #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT) 80: 81: static int maxtoken; /* Current nominal length of token buffer. */ 82: char *token_buffer; /* Pointer to token buffer. 83: Actual allocated length is maxtoken + 2. 84: This is not static because objc-parse.y uses it. */ 85: 86: /* Nonzero if end-of-file has been seen on input. */ 87: static int end_of_file; 88: 89: /* Buffered-back input character; faster than using ungetc. */ 90: static int nextchar = -1; 91: 92: int check_newline (); 93: 1.1.1.7 ! root 94: /* Do not insert generated code into the source, instead, include it. ! 95: This allows us to build gcc automatically even for targets that ! 96: need to add or modify the reserved keyword lists. */ ! 97: #include "c-gperf.h" 1.1 root 98: 99: /* Return something to represent absolute declarators containing a *. 100: TARGET is the absolute declarator that the * contains. 101: TYPE_QUALS is a list of modifiers such as const or volatile 102: to apply to the pointer type, represented as identifiers. 103: 104: We return an INDIRECT_REF whose "contents" are TARGET 105: and whose type is the modifier list. */ 106: 107: tree 108: make_pointer_declarator (type_quals, target) 109: tree type_quals, target; 110: { 111: return build1 (INDIRECT_REF, type_quals, target); 112: } 113: 114: void 1.1.1.5 root 115: forget_protocol_qualifiers () 116: { 117: int i, n = sizeof wordlist / sizeof (struct resword); 118: 119: for (i = 0; i < n; i++) 120: if ((int) wordlist[i].rid >= (int) RID_IN 121: && (int) wordlist[i].rid <= (int) RID_ONEWAY) 122: wordlist[i].name = ""; 123: } 124: 125: void 126: remember_protocol_qualifiers () 127: { 128: int i, n = sizeof wordlist / sizeof (struct resword); 129: 130: for (i = 0; i < n; i++) 131: if (wordlist[i].rid == RID_IN) 132: wordlist[i].name = "in"; 133: else if (wordlist[i].rid == RID_OUT) 134: wordlist[i].name = "out"; 135: else if (wordlist[i].rid == RID_INOUT) 136: wordlist[i].name = "inout"; 137: else if (wordlist[i].rid == RID_BYCOPY) 138: wordlist[i].name = "bycopy"; 139: else if (wordlist[i].rid == RID_ONEWAY) 140: wordlist[i].name = "oneway"; 141: } 142: 143: void 1.1 root 144: init_lex () 145: { 146: /* Make identifier nodes long enough for the language-specific slots. */ 147: set_identifier_size (sizeof (struct lang_identifier)); 148: 149: /* Start it at 0, because check_newline is called at the very beginning 150: and will increment it to 1. */ 151: lineno = 0; 152: 153: #ifdef MULTIBYTE_CHARS 154: /* Change to the native locale for multibyte conversions. */ 155: setlocale (LC_CTYPE, ""); 156: #endif 157: 158: maxtoken = 40; 159: token_buffer = (char *) xmalloc (maxtoken + 2); 160: 161: ridpointers[(int) RID_INT] = get_identifier ("int"); 162: ridpointers[(int) RID_CHAR] = get_identifier ("char"); 163: ridpointers[(int) RID_VOID] = get_identifier ("void"); 164: ridpointers[(int) RID_FLOAT] = get_identifier ("float"); 165: ridpointers[(int) RID_DOUBLE] = get_identifier ("double"); 166: ridpointers[(int) RID_SHORT] = get_identifier ("short"); 167: ridpointers[(int) RID_LONG] = get_identifier ("long"); 168: ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned"); 169: ridpointers[(int) RID_SIGNED] = get_identifier ("signed"); 170: ridpointers[(int) RID_INLINE] = get_identifier ("inline"); 171: ridpointers[(int) RID_CONST] = get_identifier ("const"); 172: ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile"); 173: ridpointers[(int) RID_AUTO] = get_identifier ("auto"); 174: ridpointers[(int) RID_STATIC] = get_identifier ("static"); 175: ridpointers[(int) RID_EXTERN] = get_identifier ("extern"); 176: ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef"); 177: ridpointers[(int) RID_REGISTER] = get_identifier ("register"); 1.1.1.5 root 178: ridpointers[(int) RID_ITERATOR] = get_identifier ("iterator"); 179: ridpointers[(int) RID_COMPLEX] = get_identifier ("complex"); 180: ridpointers[(int) RID_ID] = get_identifier ("id"); 181: ridpointers[(int) RID_IN] = get_identifier ("in"); 182: ridpointers[(int) RID_OUT] = get_identifier ("out"); 183: ridpointers[(int) RID_INOUT] = get_identifier ("inout"); 184: ridpointers[(int) RID_BYCOPY] = get_identifier ("bycopy"); 185: ridpointers[(int) RID_ONEWAY] = get_identifier ("oneway"); 186: forget_protocol_qualifiers(); 1.1 root 187: 188: /* Some options inhibit certain reserved words. 189: Clear those words out of the hash table so they won't be recognized. */ 190: #define UNSET_RESERVED_WORD(STRING) \ 191: do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \ 192: if (s) s->name = ""; } while (0) 193: 1.1.1.5 root 194: if (! doing_objc_thang) 195: UNSET_RESERVED_WORD ("id"); 196: 1.1 root 197: if (flag_traditional) 198: { 199: UNSET_RESERVED_WORD ("const"); 200: UNSET_RESERVED_WORD ("volatile"); 201: UNSET_RESERVED_WORD ("typeof"); 202: UNSET_RESERVED_WORD ("signed"); 203: UNSET_RESERVED_WORD ("inline"); 1.1.1.5 root 204: UNSET_RESERVED_WORD ("iterator"); 205: UNSET_RESERVED_WORD ("complex"); 1.1 root 206: } 207: if (flag_no_asm) 208: { 209: UNSET_RESERVED_WORD ("asm"); 210: UNSET_RESERVED_WORD ("typeof"); 211: UNSET_RESERVED_WORD ("inline"); 1.1.1.5 root 212: UNSET_RESERVED_WORD ("iterator"); 213: UNSET_RESERVED_WORD ("complex"); 1.1 root 214: } 215: } 216: 217: void 218: reinit_parse_for_function () 219: { 220: } 221: 222: /* Function used when yydebug is set, to print a token in more detail. */ 223: 224: void 225: yyprint (file, yychar, yylval) 226: FILE *file; 227: int yychar; 228: YYSTYPE yylval; 229: { 230: tree t; 231: switch (yychar) 232: { 233: case IDENTIFIER: 234: case TYPENAME: 1.1.1.5 root 235: case OBJECTNAME: 1.1 root 236: t = yylval.ttype; 237: if (IDENTIFIER_POINTER (t)) 238: fprintf (file, " `%s'", IDENTIFIER_POINTER (t)); 239: break; 240: 241: case CONSTANT: 242: t = yylval.ttype; 243: if (TREE_CODE (t) == INTEGER_CST) 1.1.1.4 root 244: fprintf (file, 245: #if HOST_BITS_PER_WIDE_INT == 64 246: #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT 247: " 0x%lx%016lx", 248: #else 249: " 0x%x%016x", 250: #endif 251: #else 252: #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT 253: " 0x%lx%08lx", 254: #else 255: " 0x%x%08x", 256: #endif 257: #endif 258: TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t)); 1.1 root 259: break; 260: } 261: } 262: 263: 264: /* If C is not whitespace, return C. 265: Otherwise skip whitespace and return first nonwhite char read. */ 266: 267: static int 268: skip_white_space (c) 269: register int c; 270: { 1.1.1.3 root 271: static int newline_warning = 0; 1.1 root 272: 273: for (;;) 274: { 275: switch (c) 276: { 1.1.1.3 root 277: /* We don't recognize comments here, because 278: cpp output can include / and * consecutively as operators. 279: Also, there's no need, since cpp removes all comments. */ 1.1 root 280: 281: case '\n': 282: c = check_newline (); 283: break; 284: 285: case ' ': 286: case '\t': 287: case '\f': 288: case '\v': 289: case '\b': 290: c = getc (finput); 291: break; 292: 1.1.1.3 root 293: case '\r': 294: /* ANSI C says the effects of a carriage return in a source file 295: are undefined. */ 296: if (pedantic && !newline_warning) 297: { 298: warning ("carriage return in source file"); 299: warning ("(we only warn about the first carriage return)"); 300: newline_warning = 1; 301: } 302: c = getc (finput); 303: break; 304: 1.1 root 305: case '\\': 306: c = getc (finput); 307: if (c == '\n') 308: lineno++; 309: else 310: error ("stray '\\' in program"); 311: c = getc (finput); 312: break; 313: 314: default: 315: return (c); 316: } 317: } 318: } 319: 320: /* Skips all of the white space at the current location in the input file. 321: Must use and reset nextchar if it has the next character. */ 322: 323: void 324: position_after_white_space () 325: { 326: register int c; 327: 328: if (nextchar != -1) 329: c = nextchar, nextchar = -1; 330: else 331: c = getc (finput); 332: 333: ungetc (skip_white_space (c), finput); 334: } 335: 336: /* Make the token buffer longer, preserving the data in it. 337: P should point to just beyond the last valid character in the old buffer. 338: The value we return is a pointer to the new buffer 339: at a place corresponding to P. */ 340: 341: static char * 342: extend_token_buffer (p) 343: char *p; 344: { 345: int offset = p - token_buffer; 346: 347: maxtoken = maxtoken * 2 + 10; 348: token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2); 349: 350: return token_buffer + offset; 351: } 352: 353: /* At the beginning of a line, increment the line number 354: and process any #-directive on this line. 355: If the line is a #-directive, read the entire line and return a newline. 356: Otherwise, return the line's first non-whitespace character. */ 357: 358: int 359: check_newline () 360: { 361: register int c; 362: register int token; 363: 364: lineno++; 365: 366: /* Read first nonwhite char on the line. */ 367: 368: c = getc (finput); 369: while (c == ' ' || c == '\t') 370: c = getc (finput); 371: 372: if (c != '#') 373: { 374: /* If not #, return it so caller will use it. */ 375: return c; 376: } 377: 378: /* Read first nonwhite char after the `#'. */ 379: 380: c = getc (finput); 381: while (c == ' ' || c == '\t') 382: c = getc (finput); 383: 384: /* If a letter follows, then if the word here is `line', skip 385: it and ignore it; otherwise, ignore the line, with an error 386: if the word isn't `pragma', `ident', `define', or `undef'. */ 387: 388: if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) 389: { 390: if (c == 'p') 391: { 392: if (getc (finput) == 'r' 393: && getc (finput) == 'a' 394: && getc (finput) == 'g' 395: && getc (finput) == 'm' 396: && getc (finput) == 'a' 397: && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n')) 398: { 1.1.1.4 root 399: #ifdef HANDLE_SYSV_PRAGMA 400: return handle_sysv_pragma (finput, c); 1.1.1.7 ! root 401: #else /* !HANDLE_SYSV_PRAGMA */ 1.1 root 402: #ifdef HANDLE_PRAGMA 403: HANDLE_PRAGMA (finput); 404: #endif /* HANDLE_PRAGMA */ 405: goto skipline; 1.1.1.7 ! root 406: #endif /* !HANDLE_SYSV_PRAGMA */ 1.1 root 407: } 408: } 409: 410: else if (c == 'd') 411: { 412: if (getc (finput) == 'e' 413: && getc (finput) == 'f' 414: && getc (finput) == 'i' 415: && getc (finput) == 'n' 416: && getc (finput) == 'e' 417: && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n')) 418: { 419: #ifdef DWARF_DEBUGGING_INFO 420: if ((debug_info_level == DINFO_LEVEL_VERBOSE) 421: && (write_symbols == DWARF_DEBUG)) 422: dwarfout_define (lineno, get_directive_line (finput)); 423: #endif /* DWARF_DEBUGGING_INFO */ 424: goto skipline; 425: } 426: } 427: else if (c == 'u') 428: { 429: if (getc (finput) == 'n' 430: && getc (finput) == 'd' 431: && getc (finput) == 'e' 432: && getc (finput) == 'f' 433: && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n')) 434: { 435: #ifdef DWARF_DEBUGGING_INFO 436: if ((debug_info_level == DINFO_LEVEL_VERBOSE) 437: && (write_symbols == DWARF_DEBUG)) 438: dwarfout_undef (lineno, get_directive_line (finput)); 439: #endif /* DWARF_DEBUGGING_INFO */ 440: goto skipline; 441: } 442: } 443: else if (c == 'l') 444: { 445: if (getc (finput) == 'i' 446: && getc (finput) == 'n' 447: && getc (finput) == 'e' 448: && ((c = getc (finput)) == ' ' || c == '\t')) 449: goto linenum; 450: } 451: else if (c == 'i') 452: { 453: if (getc (finput) == 'd' 454: && getc (finput) == 'e' 455: && getc (finput) == 'n' 456: && getc (finput) == 't' 457: && ((c = getc (finput)) == ' ' || c == '\t')) 458: { 459: /* #ident. The pedantic warning is now in cccp.c. */ 460: 461: /* Here we have just seen `#ident '. 462: A string constant should follow. */ 463: 464: while (c == ' ' || c == '\t') 465: c = getc (finput); 466: 467: /* If no argument, ignore the line. */ 468: if (c == '\n') 469: return c; 470: 471: ungetc (c, finput); 472: token = yylex (); 473: if (token != STRING 474: || TREE_CODE (yylval.ttype) != STRING_CST) 475: { 476: error ("invalid #ident"); 477: goto skipline; 478: } 479: 480: if (!flag_no_ident) 481: { 482: #ifdef ASM_OUTPUT_IDENT 483: ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype)); 484: #endif 485: } 486: 487: /* Skip the rest of this line. */ 488: goto skipline; 489: } 490: } 491: 492: error ("undefined or invalid # directive"); 493: goto skipline; 494: } 495: 496: linenum: 497: /* Here we have either `#line' or `# <nonletter>'. 498: In either case, it should be a line number; a digit should follow. */ 499: 500: while (c == ' ' || c == '\t') 501: c = getc (finput); 502: 503: /* If the # is the only nonwhite char on the line, 504: just ignore it. Check the new newline. */ 505: if (c == '\n') 506: return c; 507: 508: /* Something follows the #; read a token. */ 509: 510: ungetc (c, finput); 511: token = yylex (); 512: 513: if (token == CONSTANT 514: && TREE_CODE (yylval.ttype) == INTEGER_CST) 515: { 516: int old_lineno = lineno; 517: int used_up = 0; 518: /* subtract one, because it is the following line that 519: gets the specified number */ 520: 521: int l = TREE_INT_CST_LOW (yylval.ttype) - 1; 522: 523: /* Is this the last nonwhite stuff on the line? */ 524: c = getc (finput); 525: while (c == ' ' || c == '\t') 526: c = getc (finput); 527: if (c == '\n') 528: { 529: /* No more: store the line number and check following line. */ 530: lineno = l; 531: return c; 532: } 533: ungetc (c, finput); 534: 535: /* More follows: it must be a string constant (filename). */ 536: 1.1.1.6 root 537: /* Read the string constant. */ 1.1 root 538: token = yylex (); 539: 540: if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST) 541: { 542: error ("invalid #line"); 543: goto skipline; 544: } 545: 546: input_filename 547: = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1); 548: strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype)); 549: lineno = l; 550: 551: /* Each change of file name 552: reinitializes whether we are now in a system header. */ 553: in_system_header = 0; 554: 555: if (main_input_filename == 0) 556: main_input_filename = input_filename; 557: 558: /* Is this the last nonwhite stuff on the line? */ 559: c = getc (finput); 560: while (c == ' ' || c == '\t') 561: c = getc (finput); 562: if (c == '\n') 1.1.1.5 root 563: { 564: /* Update the name in the top element of input_file_stack. */ 565: if (input_file_stack) 566: input_file_stack->name = input_filename; 567: 568: return c; 569: } 1.1 root 570: ungetc (c, finput); 571: 572: token = yylex (); 573: used_up = 0; 574: 575: /* `1' after file name means entering new file. 576: `2' after file name means just left a file. */ 577: 578: if (token == CONSTANT 579: && TREE_CODE (yylval.ttype) == INTEGER_CST) 580: { 581: if (TREE_INT_CST_LOW (yylval.ttype) == 1) 582: { 583: /* Pushing to a new file. */ 584: struct file_stack *p 585: = (struct file_stack *) xmalloc (sizeof (struct file_stack)); 586: input_file_stack->line = old_lineno; 587: p->next = input_file_stack; 588: p->name = input_filename; 589: input_file_stack = p; 590: input_file_stack_tick++; 591: #ifdef DWARF_DEBUGGING_INFO 592: if (debug_info_level == DINFO_LEVEL_VERBOSE 593: && write_symbols == DWARF_DEBUG) 594: dwarfout_start_new_source_file (input_filename); 595: #endif /* DWARF_DEBUGGING_INFO */ 596: 597: used_up = 1; 598: } 599: else if (TREE_INT_CST_LOW (yylval.ttype) == 2) 600: { 601: /* Popping out of a file. */ 602: if (input_file_stack->next) 603: { 604: struct file_stack *p = input_file_stack; 605: input_file_stack = p->next; 606: free (p); 607: input_file_stack_tick++; 608: #ifdef DWARF_DEBUGGING_INFO 609: if (debug_info_level == DINFO_LEVEL_VERBOSE 610: && write_symbols == DWARF_DEBUG) 611: dwarfout_resume_previous_source_file (input_file_stack->line); 612: #endif /* DWARF_DEBUGGING_INFO */ 613: } 614: else 615: error ("#-lines for entering and leaving files don't match"); 616: 617: used_up = 1; 618: } 619: } 620: 1.1.1.5 root 621: /* Now that we've pushed or popped the input stack, 622: update the name in the top element. */ 623: if (input_file_stack) 624: input_file_stack->name = input_filename; 625: 1.1 root 626: /* If we have handled a `1' or a `2', 627: see if there is another number to read. */ 628: if (used_up) 629: { 630: /* Is this the last nonwhite stuff on the line? */ 631: c = getc (finput); 632: while (c == ' ' || c == '\t') 633: c = getc (finput); 634: if (c == '\n') 635: return c; 636: ungetc (c, finput); 637: 638: token = yylex (); 639: used_up = 0; 640: } 641: 642: /* `3' after file name means this is a system header file. */ 643: 644: if (token == CONSTANT 645: && TREE_CODE (yylval.ttype) == INTEGER_CST 646: && TREE_INT_CST_LOW (yylval.ttype) == 3) 647: in_system_header = 1; 648: } 649: else 650: error ("invalid #-line"); 651: 652: /* skip the rest of this line. */ 653: skipline: 654: if (c == '\n') 655: return c; 656: while ((c = getc (finput)) != EOF && c != '\n'); 657: return c; 658: } 659: 1.1.1.4 root 660: #ifdef HANDLE_SYSV_PRAGMA 661: 662: /* Handle a #pragma directive. INPUT is the current input stream, 663: and C is a character to reread. Processes the entire input line 664: and returns a character for the caller to reread: either \n or EOF. */ 665: 666: /* This function has to be in this file, in order to get at 667: the token types. */ 668: 669: int 670: handle_sysv_pragma (input, c) 671: FILE *input; 672: int c; 673: { 674: for (;;) 675: { 676: while (c == ' ' || c == '\t') 677: c = getc (input); 678: if (c == '\n' || c == EOF) 679: { 680: handle_pragma_token (0, 0); 681: return c; 682: } 683: ungetc (c, input); 684: switch (yylex ()) 685: { 686: case IDENTIFIER: 687: case TYPENAME: 688: case STRING: 689: case CONSTANT: 690: handle_pragma_token (token_buffer, yylval.ttype); 691: break; 692: default: 693: handle_pragma_token (token_buffer, 0); 694: } 695: if (nextchar >= 0) 696: c = nextchar, nextchar = -1; 697: else 698: c = getc (input); 699: } 700: } 701: 702: #endif /* HANDLE_SYSV_PRAGMA */ 703: 1.1 root 704: #define ENDFILE -1 /* token that represents end-of-file */ 705: 706: /* Read an escape sequence, returning its equivalent as a character, 1.1.1.4 root 707: or store 1 in *ignore_ptr if it is backslash-newline. */ 1.1 root 708: 709: static int 1.1.1.4 root 710: readescape (ignore_ptr) 711: int *ignore_ptr; 1.1 root 712: { 713: register int c = getc (finput); 714: register int code; 715: register unsigned count; 1.1.1.7 ! root 716: unsigned firstdig = 0; 1.1.1.4 root 717: int nonnull; 1.1 root 718: 719: switch (c) 720: { 721: case 'x': 722: if (warn_traditional) 723: warning ("the meaning of `\\x' varies with -traditional"); 724: 725: if (flag_traditional) 726: return c; 727: 728: code = 0; 729: count = 0; 1.1.1.4 root 730: nonnull = 0; 1.1 root 731: while (1) 732: { 733: c = getc (finput); 734: if (!(c >= 'a' && c <= 'f') 735: && !(c >= 'A' && c <= 'F') 736: && !(c >= '0' && c <= '9')) 737: { 738: ungetc (c, finput); 739: break; 740: } 741: code *= 16; 742: if (c >= 'a' && c <= 'f') 743: code += c - 'a' + 10; 744: if (c >= 'A' && c <= 'F') 745: code += c - 'A' + 10; 746: if (c >= '0' && c <= '9') 747: code += c - '0'; 1.1.1.4 root 748: if (code != 0 || count != 0) 749: { 750: if (count == 0) 751: firstdig = code; 752: count++; 753: } 754: nonnull = 1; 1.1 root 755: } 1.1.1.4 root 756: if (! nonnull) 1.1 root 757: error ("\\x used with no following hex digits"); 1.1.1.4 root 758: else if (count == 0) 759: /* Digits are all 0's. Ok. */ 760: ; 1.1 root 761: else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node) 762: || (count > 1 763: && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4)) 764: <= firstdig))) 765: pedwarn ("hex escape out of range"); 766: return code; 767: 768: case '0': case '1': case '2': case '3': case '4': 769: case '5': case '6': case '7': 770: code = 0; 771: count = 0; 772: while ((c <= '7') && (c >= '0') && (count++ < 3)) 773: { 774: code = (code * 8) + (c - '0'); 775: c = getc (finput); 776: } 777: ungetc (c, finput); 778: return code; 779: 780: case '\\': case '\'': case '"': 781: return c; 782: 783: case '\n': 784: lineno++; 1.1.1.4 root 785: *ignore_ptr = 1; 786: return 0; 1.1 root 787: 788: case 'n': 789: return TARGET_NEWLINE; 790: 791: case 't': 792: return TARGET_TAB; 793: 794: case 'r': 795: return TARGET_CR; 796: 797: case 'f': 798: return TARGET_FF; 799: 800: case 'b': 801: return TARGET_BS; 802: 803: case 'a': 804: if (warn_traditional) 805: warning ("the meaning of `\\a' varies with -traditional"); 806: 807: if (flag_traditional) 808: return c; 809: return TARGET_BELL; 810: 811: case 'v': 812: #if 0 /* Vertical tab is present in common usage compilers. */ 813: if (flag_traditional) 814: return c; 815: #endif 816: return TARGET_VT; 817: 1.1.1.4 root 818: case 'e': 1.1 root 819: case 'E': 1.1.1.4 root 820: if (pedantic) 821: pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c); 1.1 root 822: return 033; 823: 824: case '?': 825: return c; 826: 827: /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */ 828: case '(': 829: case '{': 830: case '[': 1.1.1.5 root 831: /* `\%' is used to prevent SCCS from getting confused. */ 832: case '%': 1.1 root 833: if (pedantic) 834: pedwarn ("non-ANSI escape sequence `\\%c'", c); 835: return c; 836: } 1.1.1.4 root 837: if (c >= 040 && c < 0177) 1.1 root 838: pedwarn ("unknown escape sequence `\\%c'", c); 839: else 840: pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c); 841: return c; 842: } 843: 844: void 845: yyerror (string) 846: char *string; 847: { 848: char buf[200]; 849: 850: strcpy (buf, string); 851: 852: /* We can't print string and character constants well 853: because the token_buffer contains the result of processing escapes. */ 854: if (end_of_file) 855: strcat (buf, " at end of input"); 856: else if (token_buffer[0] == 0) 857: strcat (buf, " at null character"); 858: else if (token_buffer[0] == '"') 859: strcat (buf, " before string constant"); 860: else if (token_buffer[0] == '\'') 861: strcat (buf, " before character constant"); 862: else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177) 863: sprintf (buf + strlen (buf), " before character 0%o", 864: (unsigned char) token_buffer[0]); 865: else 866: strcat (buf, " before `%s'"); 867: 868: error (buf, token_buffer); 869: } 870: 871: #if 0 872: 873: struct try_type 874: { 875: tree *node_var; 876: char unsigned_flag; 877: char long_flag; 878: char long_long_flag; 879: }; 880: 881: struct try_type type_sequence[] = 882: { 883: { &integer_type_node, 0, 0, 0}, 884: { &unsigned_type_node, 1, 0, 0}, 885: { &long_integer_type_node, 0, 1, 0}, 886: { &long_unsigned_type_node, 1, 1, 0}, 887: { &long_long_integer_type_node, 0, 1, 1}, 888: { &long_long_unsigned_type_node, 1, 1, 1} 889: }; 890: #endif /* 0 */ 891: 892: int 893: yylex () 894: { 895: register int c; 896: register char *p; 897: register int value; 898: int wide_flag = 0; 1.1.1.5 root 899: int objc_flag = 0; 1.1 root 900: 901: if (nextchar >= 0) 902: c = nextchar, nextchar = -1; 903: else 904: c = getc (finput); 905: 906: /* Effectively do c = skip_white_space (c) 907: but do it faster in the usual cases. */ 908: while (1) 909: switch (c) 910: { 911: case ' ': 912: case '\t': 913: case '\f': 914: case '\v': 915: case '\b': 916: c = getc (finput); 917: break; 918: 1.1.1.3 root 919: case '\r': 920: /* Call skip_white_space so we can warn if appropriate. */ 921: 1.1 root 922: case '\n': 923: case '/': 924: case '\\': 925: c = skip_white_space (c); 926: default: 927: goto found_nonwhite; 928: } 929: found_nonwhite: 930: 931: token_buffer[0] = c; 932: token_buffer[1] = 0; 933: 934: /* yylloc.first_line = lineno; */ 935: 936: switch (c) 937: { 938: case EOF: 939: end_of_file = 1; 940: token_buffer[0] = 0; 941: value = ENDFILE; 942: break; 943: 944: case '$': 945: if (dollars_in_ident) 946: goto letter; 947: return '$'; 948: 949: case 'L': 950: /* Capital L may start a wide-string or wide-character constant. */ 951: { 952: register int c = getc (finput); 953: if (c == '\'') 954: { 955: wide_flag = 1; 956: goto char_constant; 957: } 958: if (c == '"') 959: { 960: wide_flag = 1; 961: goto string_constant; 962: } 963: ungetc (c, finput); 964: } 965: goto letter; 966: 967: case '@': 968: if (!doing_objc_thang) 969: { 970: value = c; 971: break; 972: } 1.1.1.5 root 973: else 1.1 root 974: { 1.1.1.5 root 975: /* '@' may start a constant string object. */ 976: register int c = getc(finput); 977: if (c == '"') 978: { 979: objc_flag = 1; 980: goto string_constant; 981: } 982: ungetc(c, finput); 983: /* Fall through to treat '@' as the start of an indentifier. */ 1.1 root 984: } 985: 986: case 'A': case 'B': case 'C': case 'D': case 'E': 987: case 'F': case 'G': case 'H': case 'I': case 'J': 988: case 'K': case 'M': case 'N': case 'O': 989: case 'P': case 'Q': case 'R': case 'S': case 'T': 990: case 'U': case 'V': case 'W': case 'X': case 'Y': 991: case 'Z': 992: case 'a': case 'b': case 'c': case 'd': case 'e': 993: case 'f': case 'g': case 'h': case 'i': case 'j': 994: case 'k': case 'l': case 'm': case 'n': case 'o': 995: case 'p': case 'q': case 'r': case 's': case 't': 996: case 'u': case 'v': case 'w': case 'x': case 'y': 997: case 'z': 998: case '_': 999: letter: 1000: p = token_buffer; 1001: while (isalnum (c) || c == '_' || c == '$' || c == '@') 1002: { 1.1.1.5 root 1003: /* Make sure this char really belongs in an identifier. */ 1004: if (c == '@' && ! doing_objc_thang) 1005: break; 1.1 root 1006: if (c == '$' && ! dollars_in_ident) 1007: break; 1008: 1.1.1.5 root 1009: if (p >= token_buffer + maxtoken) 1010: p = extend_token_buffer (p); 1011: 1.1 root 1012: *p++ = c; 1013: c = getc (finput); 1014: } 1015: 1016: *p = 0; 1017: nextchar = c; 1018: 1019: value = IDENTIFIER; 1020: yylval.itype = 0; 1021: 1022: /* Try to recognize a keyword. Uses minimum-perfect hash function */ 1023: 1024: { 1025: register struct resword *ptr; 1026: 1027: if (ptr = is_reserved_word (token_buffer, p - token_buffer)) 1028: { 1029: if (ptr->rid) 1030: yylval.ttype = ridpointers[(int) ptr->rid]; 1031: value = (int) ptr->token; 1032: 1.1.1.5 root 1033: /* Only return OBJECTNAME if it is a typedef. */ 1034: if (doing_objc_thang && value == OBJECTNAME) 1035: { 1036: lastiddecl = lookup_name(yylval.ttype); 1037: 1038: if (lastiddecl == NULL_TREE 1039: || TREE_CODE (lastiddecl) != TYPE_DECL) 1040: value = IDENTIFIER; 1041: } 1042: 1.1 root 1043: /* Even if we decided to recognize asm, still perhaps warn. */ 1044: if (pedantic 1.1.1.2 root 1045: && (value == ASM_KEYWORD || value == TYPEOF 1.1 root 1046: || ptr->rid == RID_INLINE) 1047: && token_buffer[0] != '_') 1048: pedwarn ("ANSI does not permit the keyword `%s'", 1049: token_buffer); 1050: } 1051: } 1052: 1053: /* If we did not find a keyword, look for an identifier 1054: (or a typename). */ 1055: 1056: if (value == IDENTIFIER) 1057: { 1.1.1.5 root 1058: if (token_buffer[0] == '@') 1059: error("invalid identifier `%s'", token_buffer); 1060: 1.1 root 1061: yylval.ttype = get_identifier (token_buffer); 1062: lastiddecl = lookup_name (yylval.ttype); 1063: 1064: if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL) 1065: value = TYPENAME; 1.1.1.3 root 1066: /* A user-invisible read-only initialized variable 1067: should be replaced by its value. 1068: We handle only strings since that's the only case used in C. */ 1069: else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL 1070: && DECL_IGNORED_P (lastiddecl) 1071: && TREE_READONLY (lastiddecl) 1072: && DECL_INITIAL (lastiddecl) != 0 1073: && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST) 1074: { 1.1.1.5 root 1075: tree stringval = DECL_INITIAL (lastiddecl); 1076: 1077: /* Copy the string value so that we won't clobber anything 1078: if we put something in the TREE_CHAIN of this one. */ 1079: yylval.ttype = build_string (TREE_STRING_LENGTH (stringval), 1080: TREE_STRING_POINTER (stringval)); 1.1.1.3 root 1081: value = STRING; 1082: } 1.1 root 1083: else if (doing_objc_thang) 1084: { 1.1.1.5 root 1085: tree objc_interface_decl = is_class_name (yylval.ttype); 1.1 root 1086: 1087: if (objc_interface_decl) 1088: { 1089: value = CLASSNAME; 1090: yylval.ttype = objc_interface_decl; 1091: } 1092: } 1093: } 1094: 1095: break; 1096: 1097: case '0': case '1': case '2': case '3': case '4': 1098: case '5': case '6': case '7': case '8': case '9': 1099: case '.': 1100: { 1101: int base = 10; 1102: int count = 0; 1103: int largest_digit = 0; 1104: int numdigits = 0; 1105: /* for multi-precision arithmetic, 1.1.1.4 root 1106: we actually store only HOST_BITS_PER_CHAR bits in each part. 1107: The number of parts is chosen so as to be sufficient to hold 1108: the enough bits to fit into the two HOST_WIDE_INTs that contain 1109: the integer value (this is always at least as many bits as are 1110: in a target `long long' value, but may be wider). */ 1111: #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2) 1112: int parts[TOTAL_PARTS]; 1.1 root 1113: int overflow = 0; 1114: 1115: enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag 1116: = NOT_FLOAT; 1117: 1.1.1.4 root 1118: for (count = 0; count < TOTAL_PARTS; count++) 1119: parts[count] = 0; 1.1 root 1120: 1121: p = token_buffer; 1122: *p++ = c; 1123: 1124: if (c == '0') 1125: { 1126: *p++ = (c = getc (finput)); 1127: if ((c == 'x') || (c == 'X')) 1128: { 1129: base = 16; 1130: *p++ = (c = getc (finput)); 1131: } 1132: /* Leading 0 forces octal unless the 0 is the only digit. */ 1133: else if (c >= '0' && c <= '9') 1134: { 1135: base = 8; 1136: numdigits++; 1137: } 1138: else 1139: numdigits++; 1140: } 1141: 1142: /* Read all the digits-and-decimal-points. */ 1143: 1144: while (c == '.' 1.1.1.5 root 1145: || (isalnum (c) && c != 'l' && c != 'L' 1146: && c != 'u' && c != 'U' 1147: && c != 'i' && c != 'I' && c != 'j' && c != 'J' 1.1 root 1148: && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F'))))) 1149: { 1150: if (c == '.') 1151: { 1152: if (base == 16) 1153: error ("floating constant may not be in radix 16"); 1.1.1.6 root 1154: if (floatflag == TOO_MANY_POINTS) 1155: /* We have already emitted an error. Don't need another. */ 1156: ; 1157: else if (floatflag == AFTER_POINT) 1.1 root 1158: { 1159: error ("malformed floating constant"); 1160: floatflag = TOO_MANY_POINTS; 1.1.1.6 root 1161: /* Avoid another error from atof by forcing all characters 1162: from here on to be ignored. */ 1163: p[-1] = '\0'; 1.1 root 1164: } 1165: else 1166: floatflag = AFTER_POINT; 1167: 1168: base = 10; 1169: *p++ = c = getc (finput); 1170: /* Accept '.' as the start of a floating-point number 1171: only when it is followed by a digit. 1172: Otherwise, unread the following non-digit 1173: and use the '.' as a structural token. */ 1174: if (p == token_buffer + 2 && !isdigit (c)) 1175: { 1176: if (c == '.') 1177: { 1178: c = getc (finput); 1179: if (c == '.') 1180: { 1181: *p++ = c; 1182: *p = 0; 1183: return ELLIPSIS; 1184: } 1185: error ("parse error at `..'"); 1186: } 1187: ungetc (c, finput); 1188: token_buffer[1] = 0; 1189: value = '.'; 1190: goto done; 1191: } 1192: } 1193: else 1194: { 1195: /* It is not a decimal point. 1196: It should be a digit (perhaps a hex digit). */ 1197: 1198: if (isdigit (c)) 1199: { 1200: c = c - '0'; 1201: } 1202: else if (base <= 10) 1203: { 1.1.1.5 root 1204: if (c == 'e' || c == 'E') 1.1 root 1205: { 1206: base = 10; 1207: floatflag = AFTER_POINT; 1208: break; /* start of exponent */ 1209: } 1210: error ("nondigits in number and not hexadecimal"); 1211: c = 0; 1212: } 1213: else if (c >= 'a') 1214: { 1215: c = c - 'a' + 10; 1216: } 1217: else 1218: { 1219: c = c - 'A' + 10; 1220: } 1221: if (c >= largest_digit) 1222: largest_digit = c; 1223: numdigits++; 1224: 1.1.1.4 root 1225: for (count = 0; count < TOTAL_PARTS; count++) 1.1 root 1226: { 1.1.1.4 root 1227: parts[count] *= base; 1.1 root 1228: if (count) 1229: { 1.1.1.4 root 1230: parts[count] 1231: += (parts[count-1] >> HOST_BITS_PER_CHAR); 1232: parts[count-1] 1233: &= (1 << HOST_BITS_PER_CHAR) - 1; 1.1 root 1234: } 1.1.1.4 root 1235: else 1236: parts[0] += c; 1.1 root 1237: } 1238: 1.1.1.4 root 1239: /* If the extra highest-order part ever gets anything in it, 1240: the number is certainly too big. */ 1241: if (parts[TOTAL_PARTS - 1] != 0) 1242: overflow = 1; 1.1 root 1243: 1244: if (p >= token_buffer + maxtoken - 3) 1245: p = extend_token_buffer (p); 1246: *p++ = (c = getc (finput)); 1247: } 1248: } 1249: 1250: if (numdigits == 0) 1251: error ("numeric constant with no digits"); 1252: 1253: if (largest_digit >= base) 1254: error ("numeric constant contains digits beyond the radix"); 1255: 1256: /* Remove terminating char from the token buffer and delimit the string */ 1257: *--p = 0; 1258: 1259: if (floatflag != NOT_FLOAT) 1260: { 1261: tree type = double_type_node; 1.1.1.4 root 1262: int garbage_chars = 0, exceeds_double = 0; 1.1.1.5 root 1263: int imag = 0; 1.1 root 1264: REAL_VALUE_TYPE value; 1265: jmp_buf handler; 1266: 1267: /* Read explicit exponent if any, and put it in tokenbuf. */ 1268: 1269: if ((c == 'e') || (c == 'E')) 1270: { 1271: if (p >= token_buffer + maxtoken - 3) 1272: p = extend_token_buffer (p); 1273: *p++ = c; 1274: c = getc (finput); 1275: if ((c == '+') || (c == '-')) 1276: { 1277: *p++ = c; 1278: c = getc (finput); 1279: } 1280: if (! isdigit (c)) 1281: error ("floating constant exponent has no digits"); 1282: while (isdigit (c)) 1283: { 1284: if (p >= token_buffer + maxtoken - 3) 1285: p = extend_token_buffer (p); 1286: *p++ = c; 1287: c = getc (finput); 1288: } 1289: } 1290: 1291: *p = 0; 1292: errno = 0; 1293: 1294: /* Convert string to a double, checking for overflow. */ 1295: if (setjmp (handler)) 1296: { 1297: error ("floating constant out of range"); 1298: value = dconst0; 1299: } 1300: else 1301: { 1.1.1.6 root 1302: int fflag = 0, lflag = 0; 1303: /* Copy token_buffer now, while it has just the number 1304: and not the suffixes; once we add `f' or `i', 1305: REAL_VALUE_ATOF may not work any more. */ 1306: char *copy = (char *) alloca (p - token_buffer + 1); 1307: bcopy (token_buffer, copy, p - token_buffer + 1); 1308: 1.1 root 1309: set_float_handler (handler); 1.1.1.5 root 1310: 1.1.1.6 root 1311: while (1) 1312: { 1313: int lose = 0; 1.1 root 1314: 1.1.1.6 root 1315: /* Read the suffixes to choose a data type. */ 1316: switch (c) 1317: { 1318: case 'f': case 'F': 1319: if (fflag) 1320: error ("more than one `f' in numeric constant"); 1321: fflag = 1; 1322: break; 1323: 1324: case 'l': case 'L': 1325: if (lflag) 1326: error ("more than one `l' in numeric constant"); 1327: lflag = 1; 1328: break; 1329: 1330: case 'i': case 'I': 1331: if (imag) 1332: error ("more than one `i' or `j' in numeric constant"); 1.1.1.7 ! root 1333: else if (pedantic) ! 1334: pedwarn ("ANSI C forbids imaginary numeric constants"); 1.1.1.6 root 1335: imag = 1; 1336: break; 1.1.1.5 root 1337: 1.1.1.6 root 1338: default: 1339: lose = 1; 1340: } 1341: 1342: if (lose) 1343: break; 1344: 1345: if (p >= token_buffer + maxtoken - 3) 1346: p = extend_token_buffer (p); 1347: *p++ = c; 1348: *p = 0; 1349: c = getc (finput); 1350: } 1351: 1352: /* The second argument, machine_mode, of REAL_VALUE_ATOF 1353: tells the desired precision of the binary result 1354: of decimal-to-binary conversion. */ 1355: 1356: if (fflag) 1357: { 1358: if (lflag) 1359: error ("both `f' and `l' in floating constant"); 1360: 1361: type = float_type_node; 1362: value = REAL_VALUE_ATOF (copy, TYPE_MODE (type)); 1363: if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT 1364: && REAL_VALUE_ISINF (value) && pedantic) 1365: pedwarn ("floating point number exceeds range of `float'"); 1366: } 1367: else if (lflag) 1368: { 1369: type = long_double_type_node; 1370: value = REAL_VALUE_ATOF (copy, TYPE_MODE (type)); 1371: if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT 1372: && REAL_VALUE_ISINF (value) && pedantic) 1373: pedwarn ("floating point number exceeds range of `long double'"); 1374: } 1375: else 1376: { 1377: value = REAL_VALUE_ATOF (copy, TYPE_MODE (type)); 1378: if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT 1379: && REAL_VALUE_ISINF (value) && pedantic) 1380: pedwarn ("floating point number exceeds range of `double'"); 1381: } 1382: 1383: set_float_handler (NULL_PTR); 1.1.1.5 root 1384: } 1385: #ifdef ERANGE 1386: if (errno == ERANGE && !flag_traditional && pedantic) 1387: { 1388: /* ERANGE is also reported for underflow, 1389: so test the value to distinguish overflow from that. */ 1390: if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT 1391: && (REAL_VALUES_LESS (dconst1, value) 1392: || REAL_VALUES_LESS (value, dconstm1))) 1393: { 1394: pedwarn ("floating point number exceeds range of `double'"); 1395: exceeds_double = 1; 1396: } 1.1.1.4 root 1397: } 1.1.1.5 root 1398: #endif 1.1.1.6 root 1399: garbage_chars = 0; 1.1.1.5 root 1400: while (isalnum (c) || c == '.' || c == '_' 1401: || (!flag_traditional && (c == '+' || c == '-') 1402: && (p[-1] == 'e' || p[-1] == 'E'))) 1.1 root 1403: { 1404: if (p >= token_buffer + maxtoken - 3) 1405: p = extend_token_buffer (p); 1406: *p++ = c; 1407: c = getc (finput); 1.1.1.4 root 1408: garbage_chars++; 1.1 root 1409: } 1.1.1.4 root 1410: if (garbage_chars > 0) 1411: error ("garbage at end of number"); 1.1 root 1412: 1.1.1.7 ! root 1413: /* If the result is not a number, assume it must have been ! 1414: due to some error message above, so silently convert ! 1415: it to a zero. */ ! 1416: if (REAL_VALUE_ISNAN (value)) ! 1417: value = dconst0; ! 1418: 1.1 root 1419: /* Create a node with determined type and value. */ 1.1.1.5 root 1420: if (imag) 1421: yylval.ttype = build_complex (convert (type, integer_zero_node), 1422: build_real (type, value)); 1423: else 1424: yylval.ttype = build_real (type, value); 1.1 root 1425: 1426: ungetc (c, finput); 1427: *p = 0; 1428: } 1429: else 1430: { 1431: tree traditional_type, ansi_type, type; 1.1.1.4 root 1432: HOST_WIDE_INT high, low; 1.1 root 1433: int spec_unsigned = 0; 1434: int spec_long = 0; 1435: int spec_long_long = 0; 1.1.1.5 root 1436: int spec_imag = 0; 1.1 root 1437: int bytes, warn, i; 1438: 1439: while (1) 1440: { 1441: if (c == 'u' || c == 'U') 1442: { 1443: if (spec_unsigned) 1444: error ("two `u's in integer constant"); 1445: spec_unsigned = 1; 1446: } 1447: else if (c == 'l' || c == 'L') 1448: { 1449: if (spec_long) 1450: { 1451: if (spec_long_long) 1452: error ("three `l's in integer constant"); 1453: else if (pedantic) 1454: pedwarn ("ANSI C forbids long long integer constants"); 1455: spec_long_long = 1; 1456: } 1457: spec_long = 1; 1458: } 1.1.1.5 root 1459: else if (c == 'i' || c == 'j' || c == 'I' || c == 'J') 1460: { 1461: if (spec_imag) 1462: error ("more than one `i' or `j' in numeric constant"); 1.1.1.7 ! root 1463: else if (pedantic) ! 1464: pedwarn ("ANSI C forbids imaginary numeric constants"); 1.1.1.5 root 1465: spec_imag = 1; 1466: } 1.1 root 1467: else 1468: { 1.1.1.5 root 1469: if (isalnum (c) || c == '.' || c == '_' 1470: || (!flag_traditional && (c == '+' || c == '-') 1471: && (p[-1] == 'e' || p[-1] == 'E'))) 1.1 root 1472: { 1473: error ("garbage at end of number"); 1.1.1.5 root 1474: while (isalnum (c) || c == '.' || c == '_' 1475: || (!flag_traditional && (c == '+' || c == '-') 1476: && (p[-1] == 'e' || p[-1] == 'E'))) 1.1 root 1477: { 1478: if (p >= token_buffer + maxtoken - 3) 1479: p = extend_token_buffer (p); 1480: *p++ = c; 1481: c = getc (finput); 1482: } 1483: } 1484: break; 1485: } 1486: if (p >= token_buffer + maxtoken - 3) 1487: p = extend_token_buffer (p); 1488: *p++ = c; 1489: c = getc (finput); 1490: } 1491: 1492: ungetc (c, finput); 1493: 1494: /* If the constant is not long long and it won't fit in an 1495: unsigned long, or if the constant is long long and won't fit 1496: in an unsigned long long, then warn that the constant is out 1497: of range. */ 1498: 1499: /* ??? This assumes that long long and long integer types are 1500: a multiple of 8 bits. This better than the original code 1501: though which assumed that long was exactly 32 bits and long 1502: long was exactly 64 bits. */ 1503: 1504: if (spec_long_long) 1505: bytes = TYPE_PRECISION (long_long_integer_type_node) / 8; 1506: else 1507: bytes = TYPE_PRECISION (long_integer_type_node) / 8; 1508: 1.1.1.4 root 1509: warn = overflow; 1510: for (i = bytes; i < TOTAL_PARTS; i++) 1511: if (parts[i]) 1512: warn = 1; 1513: if (warn) 1514: pedwarn ("integer constant out of range"); 1.1 root 1515: 1516: /* This is simplified by the fact that our constant 1517: is always positive. */ 1518: 1.1.1.4 root 1519: high = low = 0; 1520: 1521: for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++) 1522: { 1523: high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT 1524: / HOST_BITS_PER_CHAR)] 1525: << (i * HOST_BITS_PER_CHAR)); 1526: low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR); 1527: } 1528: 1529: yylval.ttype = build_int_2 (low, high); 1530: TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node; 1.1 root 1531: 1532: /* If warn_traditional, calculate both the ANSI type and the 1533: traditional type, then see if they disagree. 1534: Otherwise, calculate only the type for the dialect in use. */ 1535: if (warn_traditional || flag_traditional) 1536: { 1537: /* Calculate the traditional type. */ 1538: /* Traditionally, any constant is signed; 1539: but if unsigned is specified explicitly, obey that. 1540: Use the smallest size with the right number of bits, 1541: except for one special case with decimal constants. */ 1542: if (! spec_long && base != 10 1543: && int_fits_type_p (yylval.ttype, unsigned_type_node)) 1544: traditional_type = (spec_unsigned ? unsigned_type_node 1545: : integer_type_node); 1546: /* A decimal constant must be long 1547: if it does not fit in type int. 1548: I think this is independent of whether 1549: the constant is signed. */ 1550: else if (! spec_long && base == 10 1551: && int_fits_type_p (yylval.ttype, integer_type_node)) 1552: traditional_type = (spec_unsigned ? unsigned_type_node 1553: : integer_type_node); 1.1.1.4 root 1554: else if (! spec_long_long) 1.1 root 1555: traditional_type = (spec_unsigned ? long_unsigned_type_node 1556: : long_integer_type_node); 1557: else 1558: traditional_type = (spec_unsigned 1559: ? long_long_unsigned_type_node 1560: : long_long_integer_type_node); 1561: } 1562: if (warn_traditional || ! flag_traditional) 1563: { 1564: /* Calculate the ANSI type. */ 1565: if (! spec_long && ! spec_unsigned 1566: && int_fits_type_p (yylval.ttype, integer_type_node)) 1567: ansi_type = integer_type_node; 1568: else if (! spec_long && (base != 10 || spec_unsigned) 1569: && int_fits_type_p (yylval.ttype, unsigned_type_node)) 1570: ansi_type = unsigned_type_node; 1571: else if (! spec_unsigned && !spec_long_long 1572: && int_fits_type_p (yylval.ttype, long_integer_type_node)) 1573: ansi_type = long_integer_type_node; 1.1.1.4 root 1574: else if (! spec_long_long) 1.1 root 1575: ansi_type = long_unsigned_type_node; 1576: else if (! spec_unsigned 1.1.1.4 root 1577: /* Verify value does not overflow into sign bit. */ 1578: && TREE_INT_CST_HIGH (yylval.ttype) >= 0 1.1 root 1579: && int_fits_type_p (yylval.ttype, 1580: long_long_integer_type_node)) 1581: ansi_type = long_long_integer_type_node; 1582: else 1583: ansi_type = long_long_unsigned_type_node; 1584: } 1585: 1586: type = flag_traditional ? traditional_type : ansi_type; 1587: 1588: if (warn_traditional && traditional_type != ansi_type) 1589: { 1590: if (TYPE_PRECISION (traditional_type) 1591: != TYPE_PRECISION (ansi_type)) 1592: warning ("width of integer constant changes with -traditional"); 1593: else if (TREE_UNSIGNED (traditional_type) 1594: != TREE_UNSIGNED (ansi_type)) 1595: warning ("integer constant is unsigned in ANSI C, signed with -traditional"); 1.1.1.3 root 1596: else 1597: warning ("width of integer constant may change on other systems with -traditional"); 1.1 root 1598: } 1599: 1.1.1.4 root 1600: if (!flag_traditional && !int_fits_type_p (yylval.ttype, type) 1601: && !warn) 1.1.1.3 root 1602: pedwarn ("integer constant out of range"); 1603: 1.1.1.4 root 1604: if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type)) 1.1.1.5 root 1605: warning ("decimal constant is so large that it is unsigned"); 1.1.1.4 root 1606: 1.1.1.5 root 1607: if (spec_imag) 1608: { 1609: if (TYPE_PRECISION (type) 1610: <= TYPE_PRECISION (integer_type_node)) 1611: yylval.ttype 1612: = build_complex (integer_zero_node, 1613: convert (integer_type_node, yylval.ttype)); 1614: else 1615: error ("complex integer constant is too wide for `complex int'"); 1616: } 1617: else if (flag_traditional && !int_fits_type_p (yylval.ttype, type)) 1.1.1.4 root 1618: /* The traditional constant 0x80000000 is signed 1619: but doesn't fit in the range of int. 1620: This will change it to -0x80000000, which does fit. */ 1621: { 1622: TREE_TYPE (yylval.ttype) = unsigned_type (type); 1623: yylval.ttype = convert (type, yylval.ttype); 1.1.1.7 ! root 1624: TREE_OVERFLOW (yylval.ttype) ! 1625: = TREE_CONSTANT_OVERFLOW (yylval.ttype) = 0; 1.1.1.4 root 1626: } 1627: else 1628: TREE_TYPE (yylval.ttype) = type; 1629: 1.1 root 1630: *p = 0; 1631: } 1632: 1633: value = CONSTANT; break; 1634: } 1635: 1636: case '\'': 1637: char_constant: 1638: { 1639: register int result = 0; 1.1.1.4 root 1640: register int num_chars = 0; 1.1 root 1641: unsigned width = TYPE_PRECISION (char_type_node); 1642: int max_chars; 1643: 1644: if (wide_flag) 1645: { 1646: width = WCHAR_TYPE_SIZE; 1647: #ifdef MULTIBYTE_CHARS 1648: max_chars = MB_CUR_MAX; 1649: #else 1650: max_chars = 1; 1651: #endif 1652: } 1653: else 1654: max_chars = TYPE_PRECISION (integer_type_node) / width; 1655: 1656: while (1) 1657: { 1658: tryagain: 1659: 1660: c = getc (finput); 1661: 1662: if (c == '\'' || c == EOF) 1663: break; 1664: 1665: if (c == '\\') 1666: { 1.1.1.4 root 1667: int ignore = 0; 1668: c = readescape (&ignore); 1669: if (ignore) 1.1 root 1670: goto tryagain; 1671: if (width < HOST_BITS_PER_INT 1672: && (unsigned) c >= (1 << width)) 1673: pedwarn ("escape sequence out of range for character"); 1.1.1.5 root 1674: #ifdef MAP_CHARACTER 1675: if (isprint (c)) 1676: c = MAP_CHARACTER (c); 1677: #endif 1.1 root 1678: } 1679: else if (c == '\n') 1680: { 1681: if (pedantic) 1682: pedwarn ("ANSI C forbids newline in character constant"); 1683: lineno++; 1684: } 1.1.1.5 root 1685: #ifdef MAP_CHARACTER 1686: else 1687: c = MAP_CHARACTER (c); 1688: #endif 1.1 root 1689: 1690: num_chars++; 1691: if (num_chars > maxtoken - 4) 1692: extend_token_buffer (token_buffer); 1693: 1694: token_buffer[num_chars] = c; 1695: 1696: /* Merge character into result; ignore excess chars. */ 1697: if (num_chars < max_chars + 1) 1698: { 1699: if (width < HOST_BITS_PER_INT) 1700: result = (result << width) | (c & ((1 << width) - 1)); 1701: else 1702: result = c; 1703: } 1704: } 1705: 1706: token_buffer[num_chars + 1] = '\''; 1707: token_buffer[num_chars + 2] = 0; 1708: 1709: if (c != '\'') 1710: error ("malformatted character constant"); 1711: else if (num_chars == 0) 1712: error ("empty character constant"); 1713: else if (num_chars > max_chars) 1714: { 1715: num_chars = max_chars; 1716: error ("character constant too long"); 1717: } 1718: else if (num_chars != 1 && ! flag_traditional) 1719: warning ("multi-character character constant"); 1720: 1721: /* If char type is signed, sign-extend the constant. */ 1722: if (! wide_flag) 1723: { 1724: int num_bits = num_chars * width; 1.1.1.5 root 1725: if (num_bits == 0) 1726: /* We already got an error; avoid invalid shift. */ 1727: yylval.ttype = build_int_2 (0, 0); 1728: else if (TREE_UNSIGNED (char_type_node) 1729: || ((result >> (num_bits - 1)) & 1) == 0) 1.1 root 1730: yylval.ttype 1.1.1.4 root 1731: = build_int_2 (result & ((unsigned HOST_WIDE_INT) ~0 1732: >> (HOST_BITS_PER_WIDE_INT - num_bits)), 1.1 root 1733: 0); 1734: else 1735: yylval.ttype 1.1.1.4 root 1736: = build_int_2 (result | ~((unsigned HOST_WIDE_INT) ~0 1737: >> (HOST_BITS_PER_WIDE_INT - num_bits)), 1.1 root 1738: -1); 1.1.1.5 root 1739: TREE_TYPE (yylval.ttype) = integer_type_node; 1.1 root 1740: } 1741: else 1742: { 1743: #ifdef MULTIBYTE_CHARS 1744: /* Set the initial shift state and convert the next sequence. */ 1745: result = 0; 1746: /* In all locales L'\0' is zero and mbtowc will return zero, 1747: so don't use it. */ 1748: if (num_chars > 1 1749: || (num_chars == 1 && token_buffer[1] != '\0')) 1750: { 1751: wchar_t wc; 1.1.1.4 root 1752: (void) mbtowc (NULL_PTR, NULL_PTR, 0); 1.1 root 1753: if (mbtowc (& wc, token_buffer + 1, num_chars) == num_chars) 1754: result = wc; 1755: else 1756: warning ("Ignoring invalid multibyte character"); 1757: } 1758: #endif 1759: yylval.ttype = build_int_2 (result, 0); 1.1.1.5 root 1760: TREE_TYPE (yylval.ttype) = wchar_type_node; 1.1 root 1761: } 1762: 1763: value = CONSTANT; 1764: break; 1765: } 1766: 1767: case '"': 1768: string_constant: 1769: { 1770: c = getc (finput); 1771: p = token_buffer + 1; 1772: 1773: while (c != '"' && c >= 0) 1774: { 1.1.1.6 root 1775: if (c == '\\') 1.1 root 1776: { 1.1.1.4 root 1777: int ignore = 0; 1778: c = readescape (&ignore); 1779: if (ignore) 1.1 root 1780: goto skipnewline; 1.1.1.2 root 1781: if (!wide_flag 1782: && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT 1783: && c >= (1 << TYPE_PRECISION (char_type_node))) 1.1 root 1784: pedwarn ("escape sequence out of range for character"); 1785: } 1786: else if (c == '\n') 1787: { 1788: if (pedantic) 1789: pedwarn ("ANSI C forbids newline in string constant"); 1790: lineno++; 1791: } 1792: 1793: if (p == token_buffer + maxtoken) 1794: p = extend_token_buffer (p); 1795: *p++ = c; 1796: 1797: skipnewline: 1798: c = getc (finput); 1799: } 1800: *p = 0; 1801: 1802: /* We have read the entire constant. 1803: Construct a STRING_CST for the result. */ 1804: 1805: if (wide_flag) 1806: { 1807: /* If this is a L"..." wide-string, convert the multibyte string 1808: to a wide character string. */ 1809: char *widep = (char *) alloca ((p - token_buffer) * WCHAR_BYTES); 1810: int len; 1811: 1812: #ifdef MULTIBYTE_CHARS 1813: len = mbstowcs ((wchar_t *) widep, token_buffer + 1, p - token_buffer); 1.1.1.5 root 1814: if (len < 0 || len >= (p - token_buffer)) 1.1 root 1815: { 1816: warning ("Ignoring invalid multibyte string"); 1817: len = 0; 1818: } 1819: bzero (widep + (len * WCHAR_BYTES), WCHAR_BYTES); 1820: #else 1821: { 1822: union { long l; char c[sizeof (long)]; } u; 1823: int big_endian; 1824: char *wp, *cp; 1825: 1826: /* Determine whether host is little or big endian. */ 1827: u.l = 1; 1828: big_endian = u.c[sizeof (long) - 1]; 1829: wp = widep + (big_endian ? WCHAR_BYTES - 1 : 0); 1830: 1831: bzero (widep, (p - token_buffer) * WCHAR_BYTES); 1832: for (cp = token_buffer + 1; cp < p; cp++) 1833: *wp = *cp, wp += WCHAR_BYTES; 1834: len = p - token_buffer - 1; 1835: } 1836: #endif 1837: yylval.ttype = build_string ((len + 1) * WCHAR_BYTES, widep); 1838: TREE_TYPE (yylval.ttype) = wchar_array_type_node; 1.1.1.5 root 1839: value = STRING; 1840: } 1841: else if (objc_flag) 1842: { 1843: extern tree build_objc_string(); 1844: /* Return an Objective-C @"..." constant string object. */ 1845: yylval.ttype = build_objc_string (p - token_buffer, 1846: token_buffer + 1); 1847: TREE_TYPE (yylval.ttype) = char_array_type_node; 1848: value = OBJC_STRING; 1.1 root 1849: } 1850: else 1851: { 1852: yylval.ttype = build_string (p - token_buffer, token_buffer + 1); 1853: TREE_TYPE (yylval.ttype) = char_array_type_node; 1.1.1.5 root 1854: value = STRING; 1.1 root 1855: } 1856: 1857: *p++ = '"'; 1858: *p = 0; 1859: 1.1.1.5 root 1860: break; 1.1 root 1861: } 1862: 1863: case '+': 1864: case '-': 1865: case '&': 1866: case '|': 1867: case '<': 1868: case '>': 1869: case '*': 1870: case '/': 1871: case '%': 1872: case '^': 1873: case '!': 1874: case '=': 1875: { 1876: register int c1; 1877: 1878: combine: 1879: 1880: switch (c) 1881: { 1882: case '+': 1883: yylval.code = PLUS_EXPR; break; 1884: case '-': 1885: yylval.code = MINUS_EXPR; break; 1886: case '&': 1887: yylval.code = BIT_AND_EXPR; break; 1888: case '|': 1889: yylval.code = BIT_IOR_EXPR; break; 1890: case '*': 1891: yylval.code = MULT_EXPR; break; 1892: case '/': 1893: yylval.code = TRUNC_DIV_EXPR; break; 1894: case '%': 1895: yylval.code = TRUNC_MOD_EXPR; break; 1896: case '^': 1897: yylval.code = BIT_XOR_EXPR; break; 1898: case LSHIFT: 1899: yylval.code = LSHIFT_EXPR; break; 1900: case RSHIFT: 1901: yylval.code = RSHIFT_EXPR; break; 1902: case '<': 1903: yylval.code = LT_EXPR; break; 1904: case '>': 1905: yylval.code = GT_EXPR; break; 1906: } 1907: 1908: token_buffer[1] = c1 = getc (finput); 1909: token_buffer[2] = 0; 1910: 1911: if (c1 == '=') 1912: { 1913: switch (c) 1914: { 1915: case '<': 1916: value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done; 1917: case '>': 1918: value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done; 1919: case '!': 1920: value = EQCOMPARE; yylval.code = NE_EXPR; goto done; 1921: case '=': 1922: value = EQCOMPARE; yylval.code = EQ_EXPR; goto done; 1923: } 1924: value = ASSIGN; goto done; 1925: } 1926: else if (c == c1) 1927: switch (c) 1928: { 1929: case '+': 1930: value = PLUSPLUS; goto done; 1931: case '-': 1932: value = MINUSMINUS; goto done; 1933: case '&': 1934: value = ANDAND; goto done; 1935: case '|': 1936: value = OROR; goto done; 1937: case '<': 1938: c = LSHIFT; 1939: goto combine; 1940: case '>': 1941: c = RSHIFT; 1942: goto combine; 1943: } 1944: else if ((c == '-') && (c1 == '>')) 1945: { value = POINTSAT; goto done; } 1946: ungetc (c1, finput); 1947: token_buffer[1] = 0; 1948: 1949: if ((c == '<') || (c == '>')) 1950: value = ARITHCOMPARE; 1951: else value = c; 1952: goto done; 1953: } 1954: 1955: case 0: 1956: /* Don't make yyparse think this is eof. */ 1957: value = 1; 1958: break; 1959: 1960: default: 1961: value = c; 1962: } 1963: 1964: done: 1965: /* yylloc.last_line = lineno; */ 1966: 1967: return value; 1968: } 1969: 1.1.1.2 root 1970: /* Sets the value of the 'yydebug' variable to VALUE. 1.1 root 1971: This is a function so we don't have to have YYDEBUG defined 1972: in order to build the compiler. */ 1973: 1974: void 1975: set_yydebug (value) 1976: int value; 1977: { 1978: #if YYDEBUG != 0 1979: yydebug = value; 1980: #else 1981: warning ("YYDEBUG not defined."); 1982: #endif 1983: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.