#include "hconfig.h"
#include "system.h"
#include "cpplib.h"
#include "scan.h"
static void skip_to_closing_brace PARAMS ((cpp_reader *));
static const cpp_token *get_a_token PARAMS ((cpp_reader *));
int brace_nesting = 0;
int extern_C_braces_length = 0;
char extern_C_braces[20];
#define in_extern_C_brace (extern_C_braces_length>0)
int cw_asm_state;
int cw_asm_in_operands;
int current_extern_C = 0;
static const cpp_token *
get_a_token (pfile)
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;
{
int nesting = 1;
for (;;)
{
enum cpp_ttype token = get_a_token (pfile)->type;
if (token == CPP_EOF)
break;
if (token == CPP_OPEN_BRACE)
nesting++;
if (token == CPP_CLOSE_BRACE && --nesting == 0)
break;
}
}
int
scan_decls (pfile, argc, argv)
cpp_reader *pfile;
int argc ATTRIBUTE_UNUSED;
char **argv ATTRIBUTE_UNUSED;
{
int saw_extern, saw_inline;
cpp_token prev_id;
const cpp_token *token;
new_statement:
token = get_a_token (pfile);
handle_statement:
current_extern_C = 0;
saw_extern = 0;
saw_inline = 0;
if (token->type == CPP_OPEN_BRACE)
{
if (extern_C_braces_length
&& extern_C_braces[extern_C_braces_length - 1] == brace_nesting)
extern_C_braces_length--;
brace_nesting--;
goto new_statement;
}
if (token->type == CPP_OPEN_BRACE)
{
brace_nesting++;
goto new_statement;
}
if (token->type == CPP_EOF)
return 0;
if (token->type == CPP_SEMICOLON)
goto new_statement;
if (token->type != CPP_NAME)
goto new_statement;
prev_id.type = CPP_EOF;
for (;;)
{
switch (token->type)
{
default:
goto handle_statement;
case CPP_MULT:
case CPP_AND:
break;
case CPP_COMMA:
case CPP_SEMICOLON:
if (prev_id.type != CPP_EOF && saw_extern)
{
recognized_extern (&prev_id);
}
if (token->type == CPP_COMMA)
break;
case CPP_OPEN_BRACE: case CPP_CLOSE_BRACE:
goto new_statement;
case CPP_EOF:
return 0;
case CPP_OPEN_PAREN:
if (prev_id.type != CPP_EOF)
{
int nesting = 1;
int have_arg_list = 0;
for (;;)
{
token = get_a_token (pfile);
if (token->type == CPP_OPEN_PAREN)
nesting++;
else if (token->type == CPP_CLOSE_PAREN)
{
nesting--;
if (nesting == 0)
break;
}
else if (token->type == CPP_EOF)
break;
else if (token->type == CPP_NAME
|| token->type == CPP_ELLIPSIS)
have_arg_list = 1;
}
recognized_function (&prev_id, token->line,
(saw_inline ? 'I'
: in_extern_C_brace || current_extern_C
? 'F' : 'f'), have_arg_list);
token = get_a_token (pfile);
if (token->type == CPP_OPEN_BRACE)
{
skip_to_closing_brace (pfile);
goto new_statement;
}
while (token->type != CPP_SEMICOLON && token->type != CPP_EOF)
token = get_a_token (pfile);
goto new_statement;
}
break;
case CPP_NAME:
if (cpp_ideq (token, "inline"))
{
saw_inline = 1;
}
else if (cpp_ideq (token, "extern"))
{
saw_extern = 1;
token = get_a_token (pfile);
if (token->type == CPP_STRING
&& token->val.str.len == 1
&& token->val.str.text[0] == 'C')
{
current_extern_C = 1;
token = get_a_token (pfile);
if (token->type == CPP_OPEN_BRACE)
{
brace_nesting++;
extern_C_braces[extern_C_braces_length++]
= brace_nesting;
goto new_statement;
}
}
else
continue;
break;
}
prev_id = *token;
break;
}
token = get_a_token (pfile);
}
}