Commit b3ca463c by Per Bothner

Re-write fixproto/fix-header/etc to use cpplib.

From-SVN: r9316
parent 355142da
......@@ -1736,9 +1736,9 @@ deduced.h: $(GCC_PASSES) $(srcdir)/scan-types.sh stmp-int-hdrs
$(SHELL) $(srcdir)/scan-types.sh "$(srcdir)" >tmp-deduced.h
mv tmp-deduced.h deduced.h
gen-protos: gen-protos.o scan.o $(HOST_LIBDEPS)
gen-protos: gen-protos.o scan.o cppalloc.o $(HOST_LIBDEPS)
${HOST_CC} $(HOST_CFLAGS) $(HOST_LDFLAGS) -o gen-protos \
gen-protos.o scan.o $(HOST_LIBS)
gen-protos.o scan.o cppalloc.o $(HOST_LIBS)
gen-protos.o: gen-protos.c scan.h hconfig.h
$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/gen-protos.c
......@@ -1755,9 +1755,9 @@ xsys-protos.h: $(GCC_PASSES) $(srcdir)/sys-protos.h deduced.h gen-protos Makefil
mv xsys-protos.hT xsys-protos.h
rm -rf fixtmp.c
fix-header: fix-header.o scan-decls.o scan.o xsys-protos.h $(HOST_LIBDEPS)
fix-header: fix-header.o scan-decls.o scan.o xsys-protos.h $(HOST_LIBDEPS) cpplib.o cpphash.o cppalloc.o cppexp.o cpperror.o version.o
$(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o fix-header \
fix-header.o scan-decls.o scan.o $(HOST_LIBS)
fix-header.o scan-decls.o scan.o cpplib.o cpphash.o cppalloc.o version.o cppexp.o $(HOST_LIBS)
fix-header.o: fix-header.c obstack.h scan.h xsys-protos.h hconfig.h
$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/fix-header.c
......@@ -1785,9 +1785,8 @@ stmp-fixproto: fixhdr.ready fixproto stmp-headers
-if [ -f include/fixed ] ; then true; \
else \
: This line works around a 'make' bug in BSDI 1.1.; \
CPP="$(GCC_FOR_TARGET) -E"; export CPP; \
FIXPROTO_DEFINES="$(FIXPROTO_DEFINES)"; export FIXPROTO_DEFINES; \
$(SHELL) ${srcdir}/fixproto include include $(SYSTEM_HEADER_DIR); \
FIXPROTO_DEFINES="$(FIXPROTO_DEFINES)"; export FIXPROTO_DEFINES; \
$(SHELL) ${srcdir}/fixproto include include $(SYSTEM_HEADER_DIR); \
touch include/fixed; \
fi
touch stmp-fixproto
......
......@@ -56,7 +56,6 @@
progname=$0
progname=`basename $progname`
original_dir=`pwd`
CPP=${CPP-./cpp}
FIX_HEADER=${FIX_HEADER-$original_dir/fix-header}
DEFINES="-D__STDC__=0 -D__cplusplus ${FIXPROTO_DEFINES}"
......@@ -243,92 +242,10 @@ for code in ALL STD ; do
&& grep "$rel_source_file" fixproto.list >/dev/null
then true
else
# echo doing $rel_source_file from $abs_source_dir
required_list=
extra_check_list=
case $rel_source_file in
ctype.h)
required_list="isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit tolower toupper" ;;
dirent.h)
required_list="closedir opendir readdir rewinddir" ;;
errno.h)
extra_check_list="errno" ;;
curses.h)
required_list="box delwin endwin getcurx getcury initscr mvcur mvwprintw mvwscanw newwin overlay overwrite scroll subwin touchwin waddstr wclear wclrtobot wclrtoeol waddch wdelch wdeleteln werase wgetch wgetstr winsch winsertln wmove wprintw wrefresh wscanw wstandend wstandout" ;;
fcntl.h)
required_list="creat fcntl open" ;;
grp.h)
#Maybe also "getgrent fgetgrent setgrent endgrent" */
required_list="getgrgid getgrnam" ;;
limit.h)
required_list= /* Lots of macros */ ;;
locale.h)
required_list="localeconv setlocale" ;;
math.h)
required_list="acos asin atan atan2 ceil cos cosh exp fabs floor fmod frexp ldexp log10 log modf pow sin sinh sqrt tan tanh"
extra_check_list="HUGE_VAL" ;;
pwd.h)
required_list="getpwnam getpwuid" ;;
setjmp.h)
# Left out siglongjmp sigsetjmp - these depend on sigjmp_buf.
required_list="longjmp setjmp" ;;
signal.h)
# Left out signal() - its prototype is too complex for us!
# Also left out "sigaction sigaddset sigdelset sigemptyset
# sigfillset sigismember sigpending sigprocmask sigsuspend"
# because these need sigset_t or struct sigaction.
# Most systems that provide them will also declare them.
required_list="kill raise" ;;
stdio.h)
required_list="clearerr fclose feof ferror fflush fgetc fgetpos fgets fopen fprintf fputc fputs fread freopen fscanf fseek fsetpos ftell fwrite getc getchar gets pclose perror popen printf putc putchar puts remove rename rewind scanf setbuf setvbuf sprintf sscanf vprintf vsprintf vfprintf tmpfile tmpnam ungetc"
if grep '[^_a-zA-Z0-9]_flsbuf' <$abs_source_file >/dev/null; then
required_list="$required_list _flsbuf _filbuf"
fi
# Should perhaps also handle NULL, EOF, ... ?
;;
stdlib.h)
required_list="$required_stdlib_h" ;;
string.h)
required_list="memchr memcmp memcpy memmove memset strcat strchr strcmp strcoll strcpy strcspn strerror strlen strncat strncmp strncpy strpbrk strrchr strspn strstr strtok strxfrm" ;;
# Should perhaps also add NULL and size_t
sys/stat.h)
required_list="chmod fstat mkdir mkfifo stat lstat umask"
extra_check_list="S_ISDIR S_ISBLK S_ISCHR S_ISFIFO S_ISREG S_ISLNK S_IFDIR S_IFBLK S_IFCHR S_IFIFO S_IFREG S_IFLNK" ;;
sys/times.h)
required_list="times" ;;
# "sys/types.h" add types (not in old g++-include)
sys/utsname.h)
required_list="uname" ;;
sys/wait.h)
required_list="wait waitpid"
extra_check_list="WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED WSTOPSIG WTERMSIG WNOHANG WNOTRACED" ;;
tar.h)
required_list= ;;
termios.h)
required_list="cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcdrain tcflow tcflush tcgetattr tcsendbreak tcsetattr" ;;
time.h)
required_list="asctime clock ctime difftime gmtime localtime mktime strftime time tzset" ;;
unistd.h)
required_list="$required_unistd_h" ;;
esac
rm -f fixtmp.c fixtmp.i
echo "#include <${rel_source_file}>" >fixtmp.c
for macro in ${required_list} ${extra_check_list}
do
echo "#ifdef ${macro}" >>fixtmp.c
echo "__DEFINED_MACRO_${macro};" >>fixtmp.c
echo "#endif" >>fixtmp.c
done
if ${CPP} ${DEFINES} $include_path fixtmp.c >fixtmp.i 2>/dev/null
then
$FIX_HEADER $rel_source_file $abs_source_file $abs_target_file "$required_list" <fixtmp.i
else
echo "${progname}: cpp could not parse ${abs_source_file} (ignored)"
fi
$FIX_HEADER $rel_source_file $abs_source_file $abs_target_file ${DEFINES} $include_path
echo "${rel_source_file}" >>fixproto.list
fi
done
rm -f fixtmp.c fixtmp.i
done
done_dirs="$done_dir $rel_source_dir"
done
......@@ -348,7 +265,7 @@ do
#define ${rel_source_ident}
#endif
EOF
${FIX_HEADER} $rel_source_file tmp.h $abs_target_dir/$rel_source_file "$required_list" </dev/null
${FIX_HEADER} $rel_source_file tmp.h $abs_target_dir/$rel_source_file ${DEFINES} $include_path
rm tmp.h
fi
done
......
......@@ -19,9 +19,25 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <ctype.h>
#include "hconfig.h"
#include "scan.h"
#include "cpplib.h"
#include "cpphash.h"
#define HASH_SIZE 2503 /* a prime */
int
hashf (name, len, hashsize)
register U_CHAR *name;
register int len;
int hashsize;
{
register int r = 0;
while (len--)
r = HASHSTEP (r, *name++);
return MAKE_POS (r) % hashsize;
}
int hash_tab[HASH_SIZE];
int verbose = 0;
......@@ -119,7 +135,7 @@ main (argc, argv)
/* NOTE: If you edit this,
also edit lookup_std_proto in fix-header.c !! */
i = hash (name_start) % HASH_SIZE;
i = hashf (name_start, name_end - name_start, HASH_SIZE);
i0 = i;
if (hash_tab[i] != 0)
{
......@@ -153,3 +169,14 @@ main (argc, argv)
return 0;
}
void
fatal (s)
char *s;
{
fprintf (stderr, "%s: %s\n", "gen-protos", s);
#ifndef FAILURE_EXIT_CODE
#define FAILURE_EXIT_CODE 33 /* gnu cc command understands this */
#endif
exit (FAILURE_EXIT_CODE);
}
......@@ -20,11 +20,7 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#include <stdio.h>
#include <ctype.h>
#include "hconfig.h"
#include "scan.h"
sstring buf;
sstring rtype;
sstring arg_list;
#include "cpplib.h"
int brace_nesting = 0;
......@@ -40,18 +36,18 @@ char extern_C_braces[20];
int current_extern_C = 0;
static void
skip_to_closing_brace (fp)
FILE *fp;
skip_to_closing_brace (pfile)
cpp_reader *pfile;
{
int nesting = 1;
for (;;)
{
int c = get_token (fp, &buf);
if (c == EOF)
enum cpp_token token = cpp_get_token (pfile);
if (token == CPP_EOF)
break;
if (c == '{')
if (token == CPP_LBRACE)
nesting++;
if (c == '}' && --nesting == 0)
if (token == CPP_RBRACE && --nesting == 0)
break;
}
}
......@@ -61,19 +57,26 @@ skip_to_closing_brace (fp)
other interesting sequences (external variables and macros). */
int
scan_decls (fp)
FILE *fp;
scan_decls (pfile, argc, argv)
cpp_reader *pfile;
int argc;
char**argv;
{
int c;
int saw_extern, saw_inline;
int old_written;
int prev_id_start, prev_id_end;
enum cpp_token token;
new_statement:
c = get_token (fp, &buf);
CPP_SET_WRITTEN (pfile, 0);
token = cpp_get_token (pfile);
handle_statement:
current_extern_C = 0;
saw_extern = 0;
saw_inline = 0;
if (c == '}')
if (token == CPP_RBRACE)
{
/* Pop an 'extern "C"' nesting level, if appropriate. */
if (extern_C_braces_length
......@@ -82,121 +85,117 @@ scan_decls (fp)
brace_nesting--;
goto new_statement;
}
if (c == '{')
if (token == CPP_LBRACE)
{
brace_nesting++;
goto new_statement;
}
if (c == EOF)
if (token == CPP_EOF)
return 0;
if (c == ';')
if (token == CPP_SEMICOLON)
goto new_statement;
if (c != IDENTIFIER_TOKEN)
if (token != CPP_NAME)
goto new_statement;
rtype.ptr = rtype.base;
if (SSTRING_LENGTH (&buf) > 16
&& strncmp (buf.base, "__DEFINED_MACRO_", 16) == 0)
{
/* For certain interesting macro names, fixproto puts
#ifdef FOO
__DEFINED_MACRO_FOO
#endif
into the file to be pre-processed. So if we see __DEFINED_MACRO_FOO,
it means FOO was defined, which we may want to make a note of. */
recognized_macro (buf.base+16);
goto new_statement;
}
if (strcmp (buf.base, "inline") == 0)
{
if (strcmp (pfile->token_buffer, "inline") == 0)
{
saw_inline = 1;
c = get_token (fp, &buf);
CPP_SET_WRITTEN (pfile, 0);
token = cpp_get_non_space_token (pfile);
}
if (strcmp (buf.base, "extern") == 0)
if (strcmp (pfile->token_buffer, "extern") == 0)
{
saw_extern = 1;
c = get_token (fp, &buf);
if (c == STRING_TOKEN && strcmp (buf.base, "C") == 0)
CPP_SET_WRITTEN (pfile, 0);
token = cpp_get_non_space_token (pfile);
if (token == CPP_STRING
&& strcmp (pfile->token_buffer, "\"C\"") == 0)
{
CPP_SET_WRITTEN (pfile, 0);
current_extern_C = 1;
c = get_token (fp, &buf);
if (c == '{')
token = cpp_get_non_space_token (pfile);
if (token == CPP_LPAREN)
{
brace_nesting++;
extern_C_braces[extern_C_braces_length++] = brace_nesting;
goto new_statement;
}
c = get_token (fp, &buf);
token = cpp_get_non_space_token (pfile);
}
}
prev_id_start = NULL;
for (;;)
{
int followingc = getc (fp); /* char following token in buf */
MAKE_SSTRING_SPACE (&rtype, 1);
*rtype.ptr = 0;
if (c == IDENTIFIER_TOKEN)
int start_written = CPP_WRITTEN (pfile);
token = cpp_get_token (pfile);
switch (token)
{
int nextc = skip_spaces (fp, followingc);
if (nextc == '(')
case CPP_LPAREN:
if (prev_id_start)
{
int nesting = 1;
int func_lineno = source_lineno;
char *args;
arg_list.ptr = arg_list.base;
int have_arg_list = 0;
cpp_buffer *fbuf = cpp_file_buffer (pfile);
long func_lineno;
cpp_buf_line_and_col (fbuf, &func_lineno, NULL);
for (;;)
{
c = getc (fp);
if (c == '(')
token = cpp_get_token (pfile);
if (token == CPP_LPAREN)
nesting++;
else if (c == ')')
if (--nesting == 0)
break;
if (c == EOF)
break;
if (c == '\n')
else if (token == CPP_RPAREN)
{
c = ' ';
source_lineno++;
lineno++;
nesting--;
if (nesting == 0)
break;
}
SSTRING_PUT (&arg_list, c);
else if (token == CPP_EOF)
break;
else if (token == CPP_NAME || token == CPP_3DOTS)
have_arg_list = 1;
}
SSTRING_PUT (&arg_list, '\0');
args = arg_list.base;
while (*args == ' ')
args++;
recognized_function (buf.base,
recognized_function (pfile->token_buffer + prev_id_start,
prev_id_end - prev_id_start,
(saw_inline ? 'I'
: in_extern_C_brace || current_extern_C
? 'F' : 'f'),
rtype.base, args,
source_filename.base, func_lineno);
c = get_token (fp, &buf);
if (c == '{')
pfile->token_buffer, prev_id_start,
have_arg_list,
fbuf->nominal_fname, func_lineno);
token = cpp_get_non_space_token (pfile);
if (token == CPP_LBRACE)
{
/* skip body of (normally) inline function */
skip_to_closing_brace (fp);
skip_to_closing_brace (pfile);
goto new_statement;
}
goto handle_statement;
}
else if (nextc == ';' && saw_extern)
break;
case CPP_SEMICOLON:
if (prev_id_start && saw_extern)
{
recognized_extern (buf.base, rtype.base);
goto new_statement;
recognized_extern (pfile->token_buffer + prev_id_start,
prev_id_end - prev_id_start,
pfile->token_buffer,
prev_id_start);
}
else
ungetc (nextc, fp);
goto new_statement;
case CPP_NAME:
prev_id_start = start_written;
prev_id_end = CPP_WRITTEN (pfile);
break;
case CPP_EOF:
return; /* ??? FIXME */
case CPP_LBRACE: case CPP_RBRACE: case CPP_DIRECTIVE:
goto new_statement; /* handle_statement? */
case CPP_HSPACE: case CPP_VSPACE: case CPP_COMMENT: case CPP_POP:
break;
default:
prev_id_start = NULL;
}
else if (followingc != EOF)
ungetc (followingc, fp);
if (c == ';' || c == '{' || c == '}' || c == EOF)
goto handle_statement;
sstring_append (&rtype, &buf);
if (followingc == ' ' || followingc == '\t' || followingc == '\n')
SSTRING_PUT (&rtype, ' ');
c = get_token (fp, &buf);
}
}
......@@ -58,35 +58,6 @@ sstring_append (dst, src)
*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;
}
int
scan_ident (fp, s, c)
register FILE *fp;
......@@ -267,13 +238,3 @@ get_token (fp, s)
*s->ptr = 0;
return c;
}
unsigned long
hash (str)
char *str;
{
int h = 0;
/* Replace this with something faster/better! FIXME! */
while (*str) h = (h << 3) + *str++;
return h & 0x7FFFFFFF;
}
......@@ -59,7 +59,7 @@ extern int scan_string _PARAMS((FILE*, sstring *, int));
extern int read_upto _PARAMS((FILE*, sstring*, int));
extern char *xmalloc _PARAMS((unsigned));
extern char *xrealloc _PARAMS((char *, unsigned));
extern unsigned long hash _PARAMS((char*));
extern unsigned long hash _PARAMS((const char*));
/* get_token is a simple C lexer. */
#define IDENTIFIER_TOKEN 300
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment