2002-06-04 09:11:05 +02:00
|
|
|
/* -*- indented-text -*- */
|
|
|
|
/* Process source files and output type information.
|
2004-05-30 02:49:06 +02:00
|
|
|
Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
|
2002-06-04 09:11:05 +02:00
|
|
|
|
|
|
|
This file is part of GCC.
|
|
|
|
|
|
|
|
GCC 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.
|
|
|
|
|
|
|
|
GCC 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 GCC; see the file COPYING. If not, write to the Free
|
|
|
|
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA. */
|
|
|
|
|
|
|
|
%{
|
2002-12-16 19:23:00 +01:00
|
|
|
#include "bconfig.h"
|
|
|
|
#include "coretypes.h"
|
|
|
|
#include "system.h"
|
2003-01-15 18:36:57 +01:00
|
|
|
|
|
|
|
#define malloc xmalloc
|
|
|
|
#define realloc xrealloc
|
|
|
|
|
2002-06-04 09:11:05 +02:00
|
|
|
#include "gengtype.h"
|
|
|
|
#include "gengtype-yacc.h"
|
|
|
|
|
2004-06-28 12:30:21 +02:00
|
|
|
#define YY_INPUT(BUF,RESULT,SIZE) ((RESULT) = macro_input (BUF,SIZE))
|
|
|
|
|
|
|
|
static unsigned macro_input (char *buffer, unsigned);
|
|
|
|
static void push_macro_expansion (const char *, unsigned,
|
|
|
|
const char *, unsigned);
|
2003-07-06 20:59:38 +02:00
|
|
|
static void update_lineno (const char *l, size_t len);
|
2002-06-04 09:11:05 +02:00
|
|
|
|
|
|
|
struct fileloc lexer_line;
|
|
|
|
int lexer_toplevel_done;
|
|
|
|
|
|
|
|
static void
|
2003-07-06 20:59:38 +02:00
|
|
|
update_lineno (const char *l, size_t len)
|
2002-06-04 09:11:05 +02:00
|
|
|
{
|
|
|
|
while (len-- > 0)
|
|
|
|
if (*l++ == '\n')
|
|
|
|
lexer_line.line++;
|
|
|
|
}
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
2002-08-22 04:17:08 +02:00
|
|
|
ID [[:alpha:]_][[:alnum:]_]*
|
2002-06-04 09:11:05 +02:00
|
|
|
WS [[:space:]]+
|
2004-05-13 08:41:07 +02:00
|
|
|
IWORD short|long|(un)?signed|char|int|HOST_WIDE_INT|HOST_WIDEST_INT|bool|size_t|BOOL_BITFIELD
|
2002-06-04 09:11:05 +02:00
|
|
|
ITYPE {IWORD}({WS}{IWORD})*
|
|
|
|
|
|
|
|
%x in_struct in_struct_comment in_comment in_yacc_escape
|
|
|
|
%option warn noyywrap nounput nodefault perf-report
|
|
|
|
%option 8bit never-interactive
|
|
|
|
%%
|
|
|
|
|
|
|
|
[^[:alnum:]_]typedef{WS}(struct|union){WS}{ID}{WS}?[*[:space:]]{WS}?{ID}{WS}?";" {
|
|
|
|
char *tagstart;
|
|
|
|
size_t taglen;
|
|
|
|
char *namestart;
|
|
|
|
size_t namelen;
|
|
|
|
int is_pointer = 0;
|
|
|
|
struct type *t;
|
|
|
|
int union_p;
|
|
|
|
|
|
|
|
tagstart = yytext + strlen (" typedef ");
|
2002-06-09 04:12:21 +02:00
|
|
|
while (ISSPACE (*tagstart))
|
2002-06-04 09:11:05 +02:00
|
|
|
tagstart++;
|
|
|
|
union_p = tagstart[0] == 'u';
|
|
|
|
tagstart += strlen ("union ");
|
2002-06-09 04:12:21 +02:00
|
|
|
while (ISSPACE (*tagstart))
|
2002-06-04 09:11:05 +02:00
|
|
|
tagstart++;
|
2002-06-09 04:12:21 +02:00
|
|
|
for (taglen = 1; ISIDNUM (tagstart[taglen]); taglen++)
|
2002-06-04 09:11:05 +02:00
|
|
|
;
|
|
|
|
for (namestart = tagstart + taglen;
|
2002-06-09 04:12:21 +02:00
|
|
|
! ISIDNUM (*namestart);
|
2002-06-04 09:11:05 +02:00
|
|
|
namestart++)
|
|
|
|
if (*namestart == '*')
|
|
|
|
is_pointer = 1;
|
2002-06-09 04:12:21 +02:00
|
|
|
for (namelen = 1; ISIDNUM (namestart[namelen]); namelen++)
|
2002-06-04 09:11:05 +02:00
|
|
|
;
|
|
|
|
t = find_structure (xmemdup (tagstart, taglen, taglen+1), union_p);
|
|
|
|
if (is_pointer)
|
|
|
|
t = create_pointer (t);
|
2004-06-30 20:21:54 +02:00
|
|
|
namestart = xmemdup (namestart, namelen, namelen+1);
|
|
|
|
#ifdef USE_MAPPED_LOCATION
|
|
|
|
/* temporary kludge - gentype doesn't handle cpp conditionals */
|
2004-07-15 02:02:30 +02:00
|
|
|
if (strcmp (namestart, "location_t") != 0
|
|
|
|
&& strcmp (namestart, "expanded_location") != 0)
|
2004-06-30 20:21:54 +02:00
|
|
|
#endif
|
|
|
|
do_typedef (namestart, t, &lexer_line);
|
2002-06-04 09:11:05 +02:00
|
|
|
update_lineno (yytext, yyleng);
|
|
|
|
}
|
|
|
|
|
|
|
|
[^[:alnum:]_]typedef{WS}{ITYPE}{WS}{ID}{WS}?";" {
|
|
|
|
|
|
|
|
char *namestart;
|
|
|
|
size_t namelen;
|
|
|
|
struct type *t;
|
|
|
|
char *typestart;
|
|
|
|
size_t typelen;
|
|
|
|
|
2002-06-09 04:12:21 +02:00
|
|
|
for (namestart = yytext + yyleng - 2; ISSPACE (*namestart); namestart--)
|
2002-06-04 09:11:05 +02:00
|
|
|
;
|
2002-06-09 04:12:21 +02:00
|
|
|
for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
|
2002-06-04 09:11:05 +02:00
|
|
|
;
|
|
|
|
namestart -= namelen - 1;
|
|
|
|
for (typestart = yytext + strlen (" typedef ");
|
2002-06-09 04:12:21 +02:00
|
|
|
ISSPACE(*typestart);
|
2002-06-04 09:11:05 +02:00
|
|
|
typestart++)
|
|
|
|
;
|
|
|
|
for (typelen = namestart - typestart;
|
2002-06-09 04:12:21 +02:00
|
|
|
ISSPACE(typestart[typelen-1]);
|
2002-06-04 09:11:05 +02:00
|
|
|
typelen--)
|
|
|
|
;
|
|
|
|
|
|
|
|
t = create_scalar_type (typestart, typelen);
|
|
|
|
do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
|
|
|
|
update_lineno (yytext, yyleng);
|
|
|
|
}
|
|
|
|
|
|
|
|
[^[:alnum:]_]typedef{WS}{ID}{WS}{ID}{WS}PARAMS {
|
|
|
|
char *namestart;
|
|
|
|
size_t namelen;
|
|
|
|
struct type *t;
|
|
|
|
|
2002-06-09 04:12:21 +02:00
|
|
|
for (namestart = yytext + yyleng - 7; ISSPACE (*namestart); namestart--)
|
2002-06-04 09:11:05 +02:00
|
|
|
;
|
2002-06-09 04:12:21 +02:00
|
|
|
for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
|
2002-06-04 09:11:05 +02:00
|
|
|
;
|
|
|
|
namestart -= namelen - 1;
|
|
|
|
|
|
|
|
t = create_scalar_type ("function type", sizeof ("function type")-1);
|
|
|
|
do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
|
|
|
|
update_lineno (yytext, yyleng);
|
|
|
|
}
|
2003-10-05 04:49:20 +02:00
|
|
|
|
|
|
|
[^[:alnum:]_]typedef{WS}{ID}{WS}{ID}{WS}"(" {
|
|
|
|
char *namestart;
|
|
|
|
size_t namelen;
|
|
|
|
struct type *t;
|
|
|
|
|
|
|
|
for (namestart = yytext + yyleng - 2; ISSPACE (*namestart); namestart--)
|
|
|
|
;
|
|
|
|
for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
|
|
|
|
;
|
|
|
|
namestart -= namelen - 1;
|
|
|
|
|
|
|
|
t = create_scalar_type ("function type", sizeof ("function type")-1);
|
|
|
|
do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
|
|
|
|
update_lineno (yytext, yyleng);
|
|
|
|
}
|
|
|
|
|
2003-12-10 17:22:32 +01:00
|
|
|
[^[:alnum:]_]typedef{WS}{ID}{WS}?"*"?{WS}?"("{WS}?"*"{WS}?{ID}{WS}?")"{WS}?PARAMS {
|
2002-06-04 09:11:05 +02:00
|
|
|
char *namestart;
|
|
|
|
size_t namelen;
|
|
|
|
struct type *t;
|
|
|
|
|
2002-06-09 04:12:21 +02:00
|
|
|
for (namestart = yytext + yyleng - 7; !ISIDNUM (*namestart); namestart--)
|
2002-06-04 09:11:05 +02:00
|
|
|
;
|
2002-06-09 04:12:21 +02:00
|
|
|
for (namelen = 1; ISIDNUM (namestart[-namelen]); namelen++)
|
2002-06-04 09:11:05 +02:00
|
|
|
;
|
|
|
|
namestart -= namelen - 1;
|
|
|
|
|
|
|
|
t = create_scalar_type ("function type", sizeof ("function type")-1);
|
|
|
|
do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
|
|
|
|
update_lineno (yytext, yyleng);
|
|
|
|
}
|
|
|
|
|
2003-12-10 17:22:32 +01:00
|
|
|
[^[:alnum:]_]typedef{WS}{ID}{WS}?"*"?{WS}?"("{WS}?"*"{WS}?{ID}{WS}?")"{WS}?"(" {
|
2003-10-05 04:49:20 +02:00
|
|
|
char *namestart;
|
|
|
|
size_t namelen;
|
|
|
|
struct type *t;
|
|
|
|
|
|
|
|
for (namestart = yytext + yyleng - 2; !ISIDNUM (*namestart); namestart--)
|
|
|
|
;
|
|
|
|
for (namelen = 1; ISIDNUM (namestart[-namelen]); namelen++)
|
|
|
|
;
|
|
|
|
namestart -= namelen - 1;
|
|
|
|
|
|
|
|
t = create_scalar_type ("function type", sizeof ("function type")-1);
|
|
|
|
do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
|
|
|
|
update_lineno (yytext, yyleng);
|
|
|
|
}
|
|
|
|
|
2002-06-04 09:11:05 +02:00
|
|
|
[^[:alnum:]_](typedef{WS})?(struct|union){WS}{ID}{WS}/"GTY" {
|
|
|
|
char *tagstart;
|
|
|
|
size_t taglen;
|
|
|
|
int typedef_p;
|
|
|
|
int union_p;
|
|
|
|
|
|
|
|
typedef_p = yytext[1] == 't';
|
|
|
|
if (typedef_p)
|
|
|
|
for (tagstart = yytext + strlen (" typedef ");
|
2002-06-09 04:12:21 +02:00
|
|
|
ISSPACE(*tagstart);
|
2002-06-04 09:11:05 +02:00
|
|
|
tagstart++)
|
|
|
|
;
|
|
|
|
else
|
|
|
|
tagstart = yytext + 1;
|
|
|
|
|
|
|
|
union_p = tagstart[0] == 'u';
|
|
|
|
tagstart += strlen ("union ");
|
2002-06-09 04:12:21 +02:00
|
|
|
while (ISSPACE (*tagstart))
|
2002-06-04 09:11:05 +02:00
|
|
|
tagstart++;
|
2002-06-09 04:12:21 +02:00
|
|
|
for (taglen = 1; ISIDNUM (tagstart[taglen]); taglen++)
|
2002-06-04 09:11:05 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
yylval.t = find_structure (xmemdup (tagstart, taglen, taglen + 1), union_p);
|
|
|
|
BEGIN(in_struct);
|
|
|
|
update_lineno (yytext, yyleng);
|
|
|
|
return typedef_p ? ENT_TYPEDEF_STRUCT : ENT_STRUCT;
|
|
|
|
}
|
|
|
|
|
|
|
|
[^[:alnum:]_](extern|static){WS}/"GTY" {
|
|
|
|
BEGIN(in_struct);
|
|
|
|
update_lineno (yytext, yyleng);
|
|
|
|
return ENT_EXTERNSTATIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
^"%union"{WS}"{"{WS}/"GTY" {
|
|
|
|
BEGIN(in_struct);
|
|
|
|
update_lineno (yytext, yyleng);
|
|
|
|
return ENT_YACCUNION;
|
|
|
|
}
|
|
|
|
|
2004-06-28 12:30:21 +02:00
|
|
|
^"DEF_VEC_"[[:alnum:]_]*{WS}?"("{WS}?{ID}{WS}?")" {
|
|
|
|
char *macro, *arg;
|
|
|
|
unsigned macro_len, arg_len;
|
|
|
|
char *ptr = yytext;
|
|
|
|
type_p t;
|
|
|
|
|
|
|
|
/* Locate the macro and argument strings. */
|
|
|
|
macro = ptr;
|
|
|
|
while (*ptr != '(' && !ISSPACE (*ptr))
|
|
|
|
ptr++;
|
|
|
|
macro_len = ptr - macro;
|
|
|
|
while (*ptr == '(' || ISSPACE (*ptr))
|
|
|
|
ptr++;
|
|
|
|
arg = ptr;
|
|
|
|
while (*ptr != ')' && !ISSPACE (*ptr))
|
|
|
|
ptr++;
|
|
|
|
arg_len = ptr - arg;
|
|
|
|
|
|
|
|
/* Push the macro for later expansion. */
|
|
|
|
push_macro_expansion (macro, macro_len, arg, arg_len);
|
|
|
|
|
|
|
|
/* Create the struct and typedef. */
|
|
|
|
ptr = xmemdup ("VEC_", 4, 4 + arg_len + 1);
|
|
|
|
memcpy (&ptr[4], arg, arg_len);
|
|
|
|
ptr[4 + arg_len] = 0;
|
|
|
|
t = find_structure (ptr, 0);
|
|
|
|
do_typedef (ptr, t, &lexer_line);
|
|
|
|
}
|
|
|
|
|
2002-06-04 09:11:05 +02:00
|
|
|
<in_struct>{
|
|
|
|
|
|
|
|
"/*" { BEGIN(in_struct_comment); }
|
|
|
|
|
|
|
|
^"%{" { BEGIN(in_yacc_escape); }
|
|
|
|
|
2003-09-25 03:26:01 +02:00
|
|
|
^"@@".* /* Used for c-parse.in C/ObjC demarcation. */
|
|
|
|
|
2002-06-04 09:11:05 +02:00
|
|
|
{WS} { update_lineno (yytext, yyleng); }
|
|
|
|
|
|
|
|
"const"/[^[:alnum:]_] /* don't care */
|
|
|
|
"GTY"/[^[:alnum:]_] { return GTY_TOKEN; }
|
|
|
|
"union"/[^[:alnum:]_] { return UNION; }
|
|
|
|
"struct"/[^[:alnum:]_] { return STRUCT; }
|
|
|
|
"enum"/[^[:alnum:]_] { return ENUM; }
|
|
|
|
"ptr_alias"/[^[:alnum:]_] { return ALIAS; }
|
2004-05-30 02:49:06 +02:00
|
|
|
"nested_ptr"/[^[:alnum:]_] { return NESTED_PTR; }
|
2002-06-04 09:11:05 +02:00
|
|
|
[0-9]+ { return NUM; }
|
2002-09-16 20:33:23 +02:00
|
|
|
"param"[0-9]*"_is"/[^[:alnum:]_] {
|
|
|
|
yylval.s = xmemdup (yytext, yyleng, yyleng+1);
|
|
|
|
return PARAM_IS;
|
|
|
|
}
|
2002-06-04 09:11:05 +02:00
|
|
|
|
|
|
|
{IWORD}({WS}{IWORD})*/[^[:alnum:]_] |
|
|
|
|
"ENUM_BITFIELD"{WS}?"("{WS}?{ID}{WS}?")" {
|
|
|
|
size_t len;
|
|
|
|
|
2002-06-09 04:12:21 +02:00
|
|
|
for (len = yyleng; ISSPACE (yytext[len-1]); len--)
|
2002-06-04 09:11:05 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
yylval.t = create_scalar_type (yytext, len);
|
|
|
|
update_lineno (yytext, yyleng);
|
|
|
|
return SCALAR;
|
|
|
|
}
|
|
|
|
|
2004-06-28 12:30:21 +02:00
|
|
|
"VEC"{WS}?"("{WS}?{ID}{WS}?")" {
|
|
|
|
char *macro, *arg;
|
|
|
|
unsigned macro_len, arg_len;
|
|
|
|
char *ptr = yytext;
|
|
|
|
|
|
|
|
macro = ptr;
|
|
|
|
while (*ptr != '(' && !ISSPACE (*ptr))
|
|
|
|
ptr++;
|
|
|
|
macro_len = ptr - macro;
|
|
|
|
while (*ptr == '(' || ISSPACE (*ptr))
|
|
|
|
ptr++;
|
|
|
|
arg = ptr;
|
|
|
|
while (*ptr != ')' && !ISSPACE (*ptr))
|
|
|
|
ptr++;
|
|
|
|
arg_len = ptr - arg;
|
|
|
|
ptr = xmemdup (macro, macro_len, macro_len + arg_len + 2);
|
|
|
|
ptr[macro_len] = '_';
|
|
|
|
memcpy (&ptr[macro_len+1], arg, arg_len);
|
|
|
|
yylval.s = ptr;
|
|
|
|
return ID;
|
|
|
|
}
|
|
|
|
|
2002-06-04 09:11:05 +02:00
|
|
|
{ID}/[^[:alnum:]_] {
|
|
|
|
yylval.s = xmemdup (yytext, yyleng, yyleng+1);
|
|
|
|
return ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
\"([^"\\]|\\.)*\" {
|
|
|
|
yylval.s = xmemdup (yytext+1, yyleng-2, yyleng-1);
|
|
|
|
return STRING;
|
|
|
|
}
|
|
|
|
"["[^\[\]]*"]" {
|
|
|
|
yylval.s = xmemdup (yytext+1, yyleng-2, yyleng-1);
|
|
|
|
return ARRAY;
|
|
|
|
}
|
|
|
|
^"%"{ID} {
|
|
|
|
yylval.s = xmemdup (yytext+1, yyleng-1, yyleng);
|
|
|
|
return PERCENT_ID;
|
|
|
|
}
|
|
|
|
"'"("\\".|[^\\])"'" {
|
|
|
|
yylval.s = xmemdup (yytext+1, yyleng-2, yyleng);
|
|
|
|
return CHAR;
|
|
|
|
}
|
|
|
|
|
|
|
|
[(){},*:<>] { return yytext[0]; }
|
|
|
|
|
|
|
|
[;=] {
|
|
|
|
if (lexer_toplevel_done)
|
|
|
|
{
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
lexer_toplevel_done = 0;
|
|
|
|
}
|
|
|
|
return yytext[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
^"%%" {
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
return PERCENTPERCENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
. {
|
|
|
|
error_at_line (&lexer_line, "unexpected character `%s'", yytext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
"/*" { BEGIN(in_comment); }
|
|
|
|
\n { lexer_line.line++; }
|
|
|
|
{ID} |
|
2002-06-06 22:08:13 +02:00
|
|
|
"'"("\\".|[^\\])"'" |
|
2002-06-04 09:11:05 +02:00
|
|
|
[^"/\n] /* do nothing */
|
|
|
|
\"([^"\\]|\\.|\\\n)*\" { update_lineno (yytext, yyleng); }
|
|
|
|
"/"/[^*] /* do nothing */
|
|
|
|
|
|
|
|
<in_comment,in_struct_comment>{
|
|
|
|
\n { lexer_line.line++; }
|
|
|
|
[^*\n]{16} |
|
|
|
|
[^*\n] /* do nothing */
|
|
|
|
"*"/[^/] /* do nothing */
|
|
|
|
}
|
|
|
|
<in_comment>"*/" { BEGIN(INITIAL); }
|
|
|
|
<in_struct_comment>"*/" { BEGIN(in_struct); }
|
|
|
|
|
|
|
|
<in_yacc_escape>{
|
|
|
|
\n { lexer_line.line++; }
|
|
|
|
[^%]{16} |
|
|
|
|
[^%] /* do nothing */
|
|
|
|
"%"/[^}] /* do nothing */
|
|
|
|
"%}" { BEGIN(in_struct); }
|
|
|
|
"%" {
|
|
|
|
error_at_line (&lexer_line,
|
2002-06-09 04:40:08 +02:00
|
|
|
"unterminated %%{; unexpected EOF");
|
2002-06-04 09:11:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
["/] |
|
|
|
|
<in_struct_comment,in_comment>"*" {
|
|
|
|
error_at_line (&lexer_line,
|
|
|
|
"unterminated comment or string; unexpected EOF");
|
|
|
|
}
|
|
|
|
|
2004-05-31 21:49:50 +02:00
|
|
|
^"#define"{WS}"GTY(" /* do nothing */
|
|
|
|
{WS}"GTY"{WS}?"(" {
|
|
|
|
error_at_line (&lexer_line, "stray GTY marker");
|
|
|
|
}
|
|
|
|
|
2002-06-04 09:11:05 +02:00
|
|
|
%%
|
|
|
|
|
2004-06-28 12:30:21 +02:00
|
|
|
/* Deal with the expansion caused by the DEF_VEC_x macros. */
|
|
|
|
|
|
|
|
typedef struct macro
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
const char *expansion;
|
|
|
|
struct macro *next;
|
|
|
|
} macro_t;
|
|
|
|
|
|
|
|
static const macro_t macro_defs[] =
|
|
|
|
{
|
|
|
|
#define IN_GENGTYPE 1
|
|
|
|
#include "vec.h"
|
|
|
|
{NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Chain of macro expansions to do at end of scanning. */
|
|
|
|
static macro_t *macro_expns;
|
|
|
|
|
|
|
|
/* Push macro NAME (NAME_LEN) with argument ARG (ARG_LEN) onto the
|
|
|
|
expansion queue. We ensure NAME is known at this point. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
push_macro_expansion (const char *name, unsigned name_len,
|
|
|
|
const char *arg, unsigned arg_len)
|
|
|
|
{
|
|
|
|
unsigned ix;
|
|
|
|
|
|
|
|
for (ix = 0; macro_defs[ix].name; ix++)
|
|
|
|
if (strlen (macro_defs[ix].name) == name_len
|
|
|
|
&& !memcmp (name, macro_defs[ix].name, name_len))
|
|
|
|
{
|
|
|
|
macro_t *expansion = xmalloc (sizeof (*expansion));
|
|
|
|
|
|
|
|
expansion->next = macro_expns;
|
|
|
|
expansion->name = xmemdup (arg, arg_len, arg_len+1);
|
|
|
|
expansion->expansion = macro_defs[ix].expansion;
|
|
|
|
macro_expns = expansion;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
error_at_line (&lexer_line, "unrecognized macro `%.*s(%.*s)'",
|
|
|
|
name_len, name, arg_len, arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Attempt to read some input. Use fread until we're at the end of
|
|
|
|
file. At end of file expand the next queued macro. We presume the
|
|
|
|
buffer is large enough for the entire expansion. */
|
|
|
|
|
|
|
|
static unsigned
|
|
|
|
macro_input (char *buffer, unsigned size)
|
|
|
|
{
|
|
|
|
unsigned result;
|
|
|
|
|
|
|
|
result = fread (buffer, 1, size, yyin);
|
|
|
|
if (result)
|
|
|
|
/*NOP*/;
|
|
|
|
else if (ferror (yyin))
|
|
|
|
YY_FATAL_ERROR ("read of source file failed");
|
|
|
|
else if (macro_expns)
|
|
|
|
{
|
|
|
|
const char *expn;
|
|
|
|
unsigned len;
|
|
|
|
|
|
|
|
for (expn = macro_expns->expansion; *expn; expn++)
|
|
|
|
{
|
|
|
|
if (*expn == '#')
|
|
|
|
{
|
|
|
|
if (buffer[result-1] == ' ' && buffer[result-2] == '_')
|
|
|
|
result--;
|
|
|
|
len = strlen (macro_expns->name);
|
|
|
|
memcpy (&buffer[result], macro_expns->name, len);
|
|
|
|
result += len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buffer[result++] = *expn;
|
|
|
|
if (*expn == ';' || *expn == '{')
|
|
|
|
buffer[result++] = '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result > size)
|
|
|
|
YY_FATAL_ERROR ("buffer too small to expand macro");
|
|
|
|
macro_expns = macro_expns->next;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-06-04 09:11:05 +02:00
|
|
|
void
|
2003-07-06 20:59:38 +02:00
|
|
|
yyerror (const char *s)
|
2002-06-04 09:11:05 +02:00
|
|
|
{
|
|
|
|
error_at_line (&lexer_line, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-07-06 20:59:38 +02:00
|
|
|
parse_file (const char *fname)
|
2002-06-04 09:11:05 +02:00
|
|
|
{
|
|
|
|
yyin = fopen (fname, "r");
|
|
|
|
lexer_line.file = fname;
|
|
|
|
lexer_line.line = 1;
|
|
|
|
if (yyin == NULL)
|
|
|
|
{
|
|
|
|
perror (fname);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
if (yyparse() != 0)
|
|
|
|
exit (1);
|
|
|
|
fclose (yyin);
|
|
|
|
}
|