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