8sa1-gcc/gcc/scan.c
Kaveh R. Ghazi 0df6c2c74e c-format.c (maybe_read_dollar_number): Use safe-ctype macros and/or fold extra calls into fewer ones.
* c-format.c (maybe_read_dollar_number): Use safe-ctype macros
	and/or fold extra calls into fewer ones.
	* collect2.c (dump_file): Likewise.
	* cppexp.c (parse_number): Likewise.
	* cpplex.c (_cpp_lex_direct): Likewise.
	* final.c (output_asm_insn, asm_fprintf): Likewise.
	* fix-header.c (inf_scan_ident, main): Likewise.
	* fixinc/fixfixes.c (char_macro_use_fix, char_macro_def_fix):
	Likewise.
	* fold-const.c (real_hex_to_f): Likewise.
	* gen-protos.c (parse_fn_proto): Likewise.
	* genattrtab.c (check_attr_test, check_attr_value): Likewise.
	* genrecog.c (change_state, write_action): Likewise.
	* gensupport.c (shift_output_template): Likewise.
	* local-alloc.c (requires_inout): Likewise.
	* mips-tfile.c (IS_ASM_IDENT): Likewise.
	* protoize.c (is_id_char, main): Likewise.
	* real.c (asctoeg): Likewise.
	* recog.c (asm_operand_ok): Likewise.
	* reload.c (find_reloads): Likewise.
	* scan.c (scan_identget_token): Likewise.
	* sched-vis.c (print_value): Likewise.
	* stringpool.c (ggc_alloc_string): Likewise.
	* toplev.c (read_integral_parameter, decode_g_option): Likewise.
	* tradcif.y (parse_number, yylex, parse_escape): Likewise.
	* tradcpp.c (rescan): Likewise.
	* tree.c (clean_symbol_name): Likewise.
	* varasm.c (decode_reg_name): Likewise.

	* alpha.h (ASM_OUTPUT_ASCII): Likewise.
	* darwin.c (name_needs_quotes, func_name_maybe_scoped): Likewise.
	* dsp16xx.h (ASM_OUTPUT_ASCII): Likewise.
	* m88k.c (output_ascii): Likewise.
	* m88k.h (OVERRIDE_OPTIONS): Likewise.
	* mcore.h (REG_CLASS_FROM_LETTER): Likewise.
	* ns32k/encore.h (ASM_OUTPUT_ASCII): Likewise.
	* sh.h (REG_CLASS_FROM_LETTER): Likewise.

cp:
	* xref.c (GNU_xref_member): Use safe-ctype macros and/or fold
	extra calls into fewer ones.

f:
	* bad.c (ffebad_finish): Use safe-ctype macros and/or fold extra
	calls into fewer ones.
	* implic.c (ffeimplic_lookup_): Likewise.
	* intdoc.c (dumpimp): Likewise.
	* intrin.c (ffeintrin_init_0): Likewise.
	* lex.c (ffelex_backslash_, ffelex_cfebackslash_, ffelex_hash_):
	Likewise.
	* lex.h (ffelex_is_firstnamechar): Likewise.
	* target.c (ffetarget_integerhex): Likewise.

java:
	* gjavah.c (jni_print_char, decode_signature_piece): Use
	safe-ctype macros and/or fold extra calls into fewer ones.
	* lex.c (java_read_unicode, java_lex): Likewise.
	* lex.h (JAVA_START_CHAR_P, JAVA_PART_CHAR_P, JAVA_ASCII_DIGIT,
	JAVA_ASCII_HEXDIGIT, JAVA_ASCII_LETTER): Likewise.
	* mangle_name.c (append_unicode_mangled_name,
	unicode_mangling_length): Likewise.

From-SVN: r46397
2001-10-21 21:32:15 +00:00

258 lines
4.4 KiB
C

/* Utility functions for scan-decls and fix-header programs.
Copyright (C) 1993, 1994, 1998 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "hconfig.h"
#include "system.h"
#include "scan.h"
int lineno = 1;
int source_lineno = 1;
sstring source_filename;
void
make_sstring_space (str, count)
sstring *str;
int count;
{
int cur_pos = str->ptr - str->base;
int cur_size = str->limit - str->base;
int new_size = cur_pos + count + 100;
if (new_size <= cur_size)
return;
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;
{
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;
}
int
scan_ident (fp, s, c)
FILE *fp;
sstring *s;
int c;
{
s->ptr = s->base;
if (ISIDST(c))
{
for (;;)
{
SSTRING_PUT(s, c);
c = getc (fp);
if (c == EOF || ! ISIDNUM(c))
break;
}
}
MAKE_SSTRING_SPACE(s, 1);
*s->ptr = 0;
return c;
}
int
scan_string (fp, s, init)
FILE *fp;
sstring *s;
int init;
{
int c;
for (;;)
{
c = getc (fp);
if (c == EOF || c == '\n')
break;
if (c == init)
{
c = getc (fp);
break;
}
if (c == '\\')
{
c = getc (fp);
if (c == EOF)
break;
if (c == '\n')
continue;
}
SSTRING_PUT(s, c);
}
MAKE_SSTRING_SPACE(s, 1);
*s->ptr = 0;
return c;
}
/* Skip horizontal white spaces (spaces, tabs, and C-style comments). */
int
skip_spaces (fp, c)
FILE *fp;
int c;
{
for (;;)
{
if (c == ' ' || c == '\t')
c = getc (fp);
else if (c == '/')
{
c = getc (fp);
if (c != '*')
{
ungetc (c, fp);
return '/';
}
c = getc (fp);
for (;;)
{
if (c == EOF)
return EOF;
else if (c != '*')
{
if (c == '\n')
source_lineno++, lineno++;
c = getc (fp);
}
else if ((c = getc (fp)) == '/')
return getc (fp);
}
}
else
break;
}
return c;
}
int
read_upto (fp, str, delim)
FILE *fp;
sstring *str;
int delim;
{
int ch;
for (;;)
{
ch = getc (fp);
if (ch == EOF || ch == delim)
break;
SSTRING_PUT(str, ch);
}
MAKE_SSTRING_SPACE(str, 1);
*str->ptr = 0;
return ch;
}
int
get_token (fp, s)
FILE *fp;
sstring *s;
{
int c;
s->ptr = s->base;
retry:
c = ' ';
c = skip_spaces (fp, c);
if (c == '\n')
{
source_lineno++;
lineno++;
goto retry;
}
if (c == '#')
{
c = get_token (fp, s);
if (c == INT_TOKEN)
{
source_lineno = atoi (s->base) - 1; /* '\n' will add 1 */
get_token (fp, &source_filename);
}
for (;;)
{
c = getc (fp);
if (c == EOF)
return EOF;
if (c == '\n')
{
source_lineno++;
lineno++;
goto retry;
}
}
}
if (c == EOF)
return EOF;
if (ISDIGIT (c))
{
do
{
SSTRING_PUT(s, c);
c = getc (fp);
} while (c != EOF && ISDIGIT(c));
ungetc (c, fp);
c = INT_TOKEN;
goto done;
}
if (ISIDST (c))
{
c = scan_ident (fp, s, c);
ungetc (c, fp);
return IDENTIFIER_TOKEN;
}
if (c == '\'' || c == '"')
{
c = scan_string (fp, s, c);
ungetc (c, fp);
return c == '\'' ? CHAR_TOKEN : STRING_TOKEN;
}
SSTRING_PUT(s, c);
done:
MAKE_SSTRING_SPACE(s, 1);
*s->ptr = 0;
return c;
}
unsigned int
hashstr (str, len)
const char *str;
unsigned int len;
{
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;
}