Commit e9cd0b25 by Per Bothner

Merge. See ChangeLog.

From-SVN: r5125
parent 690ddf3e
...@@ -198,7 +198,7 @@ read_scan_file (scan_file) ...@@ -198,7 +198,7 @@ read_scan_file (scan_file)
struct partial_proto *partial; struct partial_proto *partial;
struct fn_decl *fn; struct fn_decl *fn;
int ch; int ch;
char *ptr, *fname, *extern_C, *rtype, *args, *file_seen, *line_seen; char *ptr, *fname, *kind, *rtype, *args, *file_seen, *line_seen;
line.ptr = line.base; line.ptr = line.base;
ch = read_upto (scan_file, &line, '\n'); ch = read_upto (scan_file, &line, '\n');
if (ch == EOF) if (ch == EOF)
...@@ -207,11 +207,11 @@ read_scan_file (scan_file) ...@@ -207,11 +207,11 @@ read_scan_file (scan_file)
fname = line.base; fname = line.base;
for (ptr = fname; *ptr != ';'; ) ptr++; for (ptr = fname; *ptr != ';'; ) ptr++;
*ptr = 0; *ptr = 0;
extern_C = ptr + 1; kind = ptr + 1;
for (ptr = extern_C; *ptr != ';'; ) ptr++; for (ptr = kind; *ptr != ';'; ) ptr++;
*ptr = 0; *ptr = 0;
if (*extern_C == 'X') if (*kind == 'X')
{ {
switch (special_file_handling) switch (special_file_handling)
{ {
...@@ -222,7 +222,7 @@ read_scan_file (scan_file) ...@@ -222,7 +222,7 @@ read_scan_file (scan_file)
continue; continue;
} }
if (*extern_C == 'M') if (*kind == 'M')
{ {
/* The original include file defines fname as a macro. */ /* The original include file defines fname as a macro. */
fn = lookup_std_proto (fname); fn = lookup_std_proto (fname);
...@@ -273,7 +273,7 @@ read_scan_file (scan_file) ...@@ -273,7 +273,7 @@ read_scan_file (scan_file)
for (ptr = line_seen; *ptr != ';'; ) ptr++; for (ptr = line_seen; *ptr != ';'; ) ptr++;
*ptr = 0; *ptr = 0;
if (extern_C[0] == 'f') if (kind[0] == 'f')
missing_extern_C_count++; missing_extern_C_count++;
fn = lookup_std_proto (fname); fn = lookup_std_proto (fname);
...@@ -289,6 +289,9 @@ read_scan_file (scan_file) ...@@ -289,6 +289,9 @@ read_scan_file (scan_file)
if (args[0] != '\0') if (args[0] != '\0')
continue; continue;
if (kind[0] == 'I') /* don't edit inline function */
continue;
/* If the partial prototype was included from some other file, /* If the partial prototype was included from some other file,
we don't need to patch it up (in this run). */ we don't need to patch it up (in this run). */
i = strlen (file_seen); i = strlen (file_seen);
...@@ -298,7 +301,7 @@ read_scan_file (scan_file) ...@@ -298,7 +301,7 @@ read_scan_file (scan_file)
if (fn == NULL) if (fn == NULL)
continue; continue;
if (fn->fname[0] == '\0' || strcmp(fn->fname, "void") == 0) if (fn->params[0] == '\0' || strcmp(fn->params, "void") == 0)
continue; continue;
/* We only have a partial function declaration, /* We only have a partial function declaration,
...@@ -329,6 +332,10 @@ read_scan_file (scan_file) ...@@ -329,6 +332,10 @@ read_scan_file (scan_file)
fprintf (stderr, "%s: OK, nothing needs to be done.\n", inc_filename); fprintf (stderr, "%s: OK, nothing needs to be done.\n", inc_filename);
exit (0); exit (0);
} }
if (!verbose)
fprintf (stderr, "%s: fixing %s\n", progname, inc_filename);
else
{
if (required_unseen_count) if (required_unseen_count)
fprintf (stderr, "%s: %d missing function declarations.\n", fprintf (stderr, "%s: %d missing function declarations.\n",
inc_filename, required_unseen_count); inc_filename, required_unseen_count);
...@@ -336,8 +343,10 @@ read_scan_file (scan_file) ...@@ -336,8 +343,10 @@ read_scan_file (scan_file)
fprintf (stderr, "%s: %d non-prototype function declarations.\n", fprintf (stderr, "%s: %d non-prototype function declarations.\n",
inc_filename, partial_count); inc_filename, partial_count);
if (missing_extern_C_count) if (missing_extern_C_count)
fprintf (stderr, "%s: %d declarations not protected by extern \"C\".\n", fprintf (stderr,
"%s: %d declarations not protected by extern \"C\".\n",
inc_filename, missing_extern_C_count); inc_filename, missing_extern_C_count);
}
} }
write_rbrac () write_rbrac ()
...@@ -652,7 +661,7 @@ main(argc, argv) ...@@ -652,7 +661,7 @@ main(argc, argv)
} }
} }
else else
putc (c, outf); fprintf (outf, " %c", c);
} }
} }
else else
......
...@@ -21,8 +21,8 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ ...@@ -21,8 +21,8 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
NAME;C;RTYPE;ARGS;FILENAME;LINENO; NAME;C;RTYPE;ARGS;FILENAME;LINENO;
NAME is the function's name. NAME is the function's name.
C is "F" if the declaration is nested inside 'extern "C"' braces; C is "I" if the function is declared as inline; "F" if the
otherwise "f". declaration is nested inside 'extern "C"' braces; otherwise "f".
RTYPE is the function's return type. RTYPE is the function's return type.
ARGS is the function's argument list. ARGS is the function's argument list.
FILENAME and LINENO is where the declarations was seen FILENAME and LINENO is where the declarations was seen
...@@ -58,18 +58,36 @@ char extern_C_braces[20]; ...@@ -58,18 +58,36 @@ char extern_C_braces[20];
prefixed by extern "C". */ prefixed by extern "C". */
int current_extern_C = 0; int current_extern_C = 0;
static void
skip_to_closing_brace (fp)
FILE *fp;
{
int nesting = 1;
for (;;)
{
int c = get_token (fp, &buf);
if (c == EOF)
break;
if (c == '{')
nesting++;
if (c == '}' && --nesting == 0)
break;
}
}
int int
main () main ()
{ {
FILE *fp = stdin; FILE *fp = stdin;
int c; int c;
int saw_extern; int saw_extern, saw_inline;
new_statement: new_statement:
c = get_token (fp, &buf); c = get_token (fp, &buf);
handle_statement: handle_statement:
current_extern_C = 0; current_extern_C = 0;
saw_extern = 0; saw_extern = 0;
saw_inline = 0;
if (c == '}') if (c == '}')
{ {
/* pop an 'extern "C"' nesting level, if appropriate */ /* pop an 'extern "C"' nesting level, if appropriate */
...@@ -97,6 +115,11 @@ main () ...@@ -97,6 +115,11 @@ main ()
fprintf (stdout, "%s;M;\n", buf.base+16); fprintf (stdout, "%s;M;\n", buf.base+16);
goto new_statement; goto new_statement;
} }
if (strcmp (buf.base, "inline") == 0)
{
saw_inline = 1;
c = get_token (fp, &buf);
}
if (strcmp (buf.base, "extern") == 0) if (strcmp (buf.base, "extern") == 0)
{ {
saw_extern = 1; saw_extern = 1;
...@@ -117,6 +140,10 @@ main () ...@@ -117,6 +140,10 @@ main ()
for (;;) for (;;)
{ {
int followingc = getc (fp); /* char following token in buf */ int followingc = getc (fp); /* char following token in buf */
MAKE_SSTRING_SPACE(&rtype, 1);
*rtype.ptr = 0;
if (c == IDENTIFIER_TOKEN) if (c == IDENTIFIER_TOKEN)
{ {
int nextc = skip_spaces (fp, followingc); int nextc = skip_spaces (fp, followingc);
...@@ -124,12 +151,10 @@ main () ...@@ -124,12 +151,10 @@ main ()
{ {
int nesting = 1; int nesting = 1;
MAKE_SSTRING_SPACE(&rtype, 1);
*rtype.ptr = 0;
fprintf (stdout, "%s;%s;%s;", fprintf (stdout, "%s;%s;%s;",
buf.base, buf.base,
in_extern_C_brace || current_extern_C ? "F" : "f", saw_inline ? "I"
: in_extern_C_brace || current_extern_C ? "F" : "f",
rtype.base); rtype.base);
c = skip_spaces (fp, ' '); c = skip_spaces (fp, ' ');
for (;;) for (;;)
...@@ -148,8 +173,15 @@ main () ...@@ -148,8 +173,15 @@ main ()
} }
fprintf (stdout, ";%s;%d;\n", fprintf (stdout, ";%s;%d;\n",
source_filename.base, source_lineno); source_filename.base, source_lineno);
c = get_token (fp, &buf);
if (c == '{')
{
/* skip body of (normally) inline function */
skip_to_closing_brace (fp);
goto new_statement; goto new_statement;
} }
goto handle_statement;
}
else if (nextc == ';' && saw_extern) else if (nextc == ';' && saw_extern)
{ {
fprintf (stdout, "%s;X;%s;\n", buf.base, rtype.base); fprintf (stdout, "%s;X;%s;\n", buf.base, rtype.base);
......
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