/* scan-decls.c - Extracts declarations from cpp output.
Copyright (C) 1993, 1995, 1997, 1998,
- 1999, 2000 Free Software Foundation, Inc.
+ 1999, 2000, 2003 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
Written by Per Bothner <bothner@cygnus.com>, July 1993. */
-#include "hconfig.h"
+#include "bconfig.h"
#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
#include "cpplib.h"
#include "scan.h"
-static void skip_to_closing_brace PARAMS ((cpp_reader *));
+static void skip_to_closing_brace (cpp_reader *);
+static const cpp_token *get_a_token (cpp_reader *);
int brace_nesting = 0;
prefixed by extern "C". */
int current_extern_C = 0;
+/* Get a token but skip padding. */
+static const cpp_token *
+get_a_token (cpp_reader *pfile)
+{
+ for (;;)
+ {
+ const cpp_token *result = cpp_get_token (pfile);
+ if (result->type != CPP_PADDING)
+ return result;
+ }
+}
+
static void
-skip_to_closing_brace (pfile)
- cpp_reader *pfile;
+skip_to_closing_brace (cpp_reader *pfile)
{
int nesting = 1;
for (;;)
{
- enum cpp_ttype token = cpp_get_token (pfile)->type;
+ enum cpp_ttype token = get_a_token (pfile)->type;
+
if (token == CPP_EOF)
break;
if (token == CPP_OPEN_BRACE)
/* This function scans a C source file (actually, the output of cpp),
reading from FP. It looks for function declarations, and
- external variable declarations.
+ external variable declarations.
The following grammar (as well as some extra stuff) is recognized:
*/
int
-scan_decls (pfile, argc, argv)
- cpp_reader *pfile;
- int argc ATTRIBUTE_UNUSED;
- char **argv ATTRIBUTE_UNUSED;
+scan_decls (cpp_reader *pfile, int argc ATTRIBUTE_UNUSED,
+ char **argv ATTRIBUTE_UNUSED)
{
int saw_extern, saw_inline;
- const cpp_token *prev_id;
+ cpp_token prev_id;
const cpp_token *token;
new_statement:
- token = cpp_get_token (pfile);
+ token = get_a_token (pfile);
handle_statement:
current_extern_C = 0;
brace_nesting++;
goto new_statement;
}
+
if (token->type == CPP_EOF)
- {
- cpp_pop_buffer (pfile);
- if (CPP_BUFFER (pfile) == NULL)
- return 0;
+ return 0;
- goto new_statement;
- }
if (token->type == CPP_SEMICOLON)
goto new_statement;
if (token->type != CPP_NAME)
goto new_statement;
- prev_id = 0;
+ prev_id.type = CPP_EOF;
for (;;)
{
switch (token->type)
goto handle_statement;
case CPP_MULT:
case CPP_AND:
- case CPP_PLACEMARKER:
/* skip */
break;
case CPP_COMMA:
case CPP_SEMICOLON:
- if (prev_id && saw_extern)
+ if (prev_id.type != CPP_EOF && saw_extern)
{
- recognized_extern (prev_id);
+ recognized_extern (&prev_id);
}
if (token->type == CPP_COMMA)
break;
/* ... fall through ... */
case CPP_OPEN_BRACE: case CPP_CLOSE_BRACE:
goto new_statement;
-
+
case CPP_EOF:
- cpp_pop_buffer (pfile);
- if (CPP_BUFFER (pfile) == NULL)
- return 0;
- break;
+ return 0;
case CPP_OPEN_PAREN:
/* Looks like this is the start of a formal parameter list. */
- if (prev_id)
+ if (prev_id.type != CPP_EOF)
{
int nesting = 1;
int have_arg_list = 0;
for (;;)
{
- token = cpp_get_token (pfile);
+ token = get_a_token (pfile);
if (token->type == CPP_OPEN_PAREN)
nesting++;
else if (token->type == CPP_CLOSE_PAREN)
|| token->type == CPP_ELLIPSIS)
have_arg_list = 1;
}
- recognized_function (prev_id,
+ recognized_function (&prev_id, token->line,
(saw_inline ? 'I'
: in_extern_C_brace || current_extern_C
- ? 'F' : 'f'), have_arg_list,
- CPP_BUFFER (pfile)->nominal_fname);
- token = cpp_get_token (pfile);
+ ? 'F' : 'f'), have_arg_list);
+ token = get_a_token (pfile);
if (token->type == CPP_OPEN_BRACE)
{
/* skip body of (normally) inline function */
skip_to_closing_brace (pfile);
goto new_statement;
}
- if (token->type == CPP_SEMICOLON)
- goto new_statement;
+
+ /* skip a possible __attribute__ or throw expression after the
+ parameter list */
+ while (token->type != CPP_SEMICOLON && token->type != CPP_EOF)
+ token = get_a_token (pfile);
+ goto new_statement;
}
break;
case CPP_NAME:
/* "inline" and "extern" are recognized but skipped */
- if (!cpp_idcmp (token->val.name.text, token->val.name.len, "inline"))
+ if (cpp_ideq (token, "inline"))
{
saw_inline = 1;
}
- else if (!cpp_idcmp (token->val.name.text,
- token->val.name.len, "extern"))
+ else if (cpp_ideq (token, "extern"))
{
saw_extern = 1;
- token = cpp_get_token (pfile);
+ token = get_a_token (pfile);
if (token->type == CPP_STRING
- && !cpp_idcmp (token->val.name.text,
- token->val.name.len, "C"))
+ && token->val.str.len == 1
+ && token->val.str.text[0] == 'C')
{
current_extern_C = 1;
- token = cpp_get_token (pfile);
+ token = get_a_token (pfile);
if (token->type == CPP_OPEN_BRACE)
{
brace_nesting++;
break;
}
/* This may be the name of a variable or function. */
- prev_id = token;
+ prev_id = *token;
break;
}
- token = cpp_get_token (pfile);
+ token = get_a_token (pfile);
}
}