X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=gcc%2Fscan.c;h=f697d26ec028d9c71a294153eb7670f51fbf699d;hb=879dc1aba2268a570a593f7b8a28345ebe7609e6;hp=a27880780ee03d471b39b5462bf0e8baaf2e1b76;hpb=6aadeb198af01ce0ddaff2d0dec58d1ac784113a;p=pf3gnuchains%2Fgcc-fork.git diff --git a/gcc/scan.c b/gcc/scan.c index a27880780ee..f697d26ec02 100644 --- a/gcc/scan.c +++ b/gcc/scan.c @@ -1,31 +1,32 @@ -/* scan.c - Utility functions for scan-decls and patch-header programs. - Copyright (C) 1993 Free Software Foundation, Inc. - -This program is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any -later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - +/* Utility functions for scan-decls and fix-header programs. + Copyright (C) 1993, 1994, 1998, 2002, 2003, 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3, or (at your option) any + later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING3. If not see + . */ + +#include "bconfig.h" +#include "system.h" +#include "coretypes.h" +#include "tm.h" #include "scan.h" -#include int lineno = 1; int source_lineno = 1; sstring source_filename; void -make_sstring_space (str, count) - sstring *str; - int count; +make_sstring_space (sstring *str, int count) { int cur_pos = str->ptr - str->base; int cur_size = str->limit - str->base; @@ -33,87 +34,50 @@ make_sstring_space (str, count) if (new_size <= cur_size) return; - - if (str->base == NULL) - str->base = xmalloc (new_size); - else - str->base = xrealloc (str->base, new_size); + + str->base = xrealloc (str->base, new_size); str->ptr = str->base + cur_size; str->limit = str->base + new_size; } void -sstring_append (dst, src) - sstring *dst; - sstring *src; +sstring_append (sstring *dst, sstring *src) { - register char *d, *s; - register count = SSTRING_LENGTH(src); - MAKE_SSTRING_SPACE(dst, count + 1); + char *d, *s; + int count = SSTRING_LENGTH (src); + + MAKE_SSTRING_SPACE (dst, count + 1); d = dst->ptr; s = src->base; while (--count >= 0) *d++ = *s++; dst->ptr = d; - *d = 0; -} - -memory_full () -{ - abort(); -} - -char * -xmalloc (size) - unsigned size; -{ - register char *ptr = (char *) malloc (size); - if (ptr != 0) return (ptr); - memory_full (); - /*NOTREACHED*/ - return 0; -} - - -char * -xrealloc (old, size) - char *old; - unsigned size; -{ - register char *ptr = (char *) realloc (old, size); - if (ptr != 0) return (ptr); - memory_full (); - /*NOTREACHED*/ - return 0; + *d = 0; } int -scan_ident (fp, s, c) - register FILE *fp; - register sstring *s; - int c; +scan_ident (FILE *fp, sstring *s, int c) { s->ptr = s->base; - if (isalpha(c) || c == '_') + if (ISIDST (c)) { for (;;) { - SSTRING_PUT(s, c); + SSTRING_PUT (s, c); c = getc (fp); - if (c == EOF || !(isalnum(c) || c == '_')) + if (c == EOF || ! ISIDNUM (c)) break; } } - MAKE_SSTRING_SPACE(s, 1); + MAKE_SSTRING_SPACE (s, 1); *s->ptr = 0; return c; } int -scan_string (fp, s, init) - register FILE *fp; - register sstring *s; +scan_string (FILE *fp, sstring *s, int init) { int c; + for (;;) { c = getc (fp); @@ -132,19 +96,17 @@ scan_string (fp, s, init) if (c == '\n') continue; } - SSTRING_PUT(s, c); + SSTRING_PUT (s, c); } - MAKE_SSTRING_SPACE(s, 1); + MAKE_SSTRING_SPACE (s, 1); *s->ptr = 0; return c; } -/* Skip horizontal white spaces (spaces, tabs, and C-style comments). */ +/* Skip horizontal white spaces (spaces, tabs, and C-style comments). */ int -skip_spaces (fp, c) - register FILE *fp; - int c; +skip_spaces (FILE *fp, int c) { for (;;) { @@ -180,34 +142,30 @@ skip_spaces (fp, c) } int -read_upto (fp, str, delim) - FILE *fp; - sstring *str; - int delim; +read_upto (FILE *fp, sstring *str, int delim) { int ch; + for (;;) { ch = getc (fp); if (ch == EOF || ch == delim) break; - SSTRING_PUT(str, ch); + SSTRING_PUT (str, ch); } - MAKE_SSTRING_SPACE(str, 1); + MAKE_SSTRING_SPACE (str, 1); *str->ptr = 0; return ch; } int -get_token (fp, s) - register FILE *fp; - register sstring *s; +get_token (FILE *fp, sstring *s) { int c; + s->ptr = s->base; retry: c = ' '; - again: c = skip_spaces (fp, c); if (c == '\n') { @@ -220,7 +178,7 @@ get_token (fp, s) c = get_token (fp, s); if (c == INT_TOKEN) { - source_lineno = atoi (s->base); + source_lineno = atoi (s->base) - 1; /* '\n' will add 1 */ get_token (fp, &source_filename); } for (;;) @@ -229,23 +187,27 @@ get_token (fp, s) if (c == EOF) return EOF; if (c == '\n') + { + source_lineno++; + lineno++; goto retry; + } } } if (c == EOF) return EOF; - if (isdigit (c)) + if (ISDIGIT (c)) { do { - SSTRING_PUT(s, c); + SSTRING_PUT (s, c); c = getc (fp); - } while (c != EOF && isdigit(c)); + } while (c != EOF && ISDIGIT (c)); ungetc (c, fp); c = INT_TOKEN; goto done; } - if (isalpha (c) || c == '_') + if (ISIDST (c)) { c = scan_ident (fp, s, c); ungetc (c, fp); @@ -253,24 +215,26 @@ get_token (fp, s) } if (c == '\'' || c == '"') { - int quote = c; c = scan_string (fp, s, c); ungetc (c, fp); return c == '\'' ? CHAR_TOKEN : STRING_TOKEN; } - SSTRING_PUT(s, c); + SSTRING_PUT (s, c); done: - MAKE_SSTRING_SPACE(s, 1); + MAKE_SSTRING_SPACE (s, 1); *s->ptr = 0; return c; } -unsigned long -hash (str) - char *str; +unsigned int +hashstr (const char *str, unsigned int len) { - int h = 0; - /* Replace this with something faster/better! FIXME! */ - while (*str) h = (h << 3) + *str++; - return h & 0x7FFFFFFF; + unsigned int n = len; + unsigned int r = 0; + const unsigned char *s = (const unsigned char *) str; + + do + r = r * 67 + (*s++ - 113); + while (--n); + return r + len; }