OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [gengtype-lex.l] - Diff between revs 154 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 154 Rev 816
/* -*- indented-text -*- */
/* -*- indented-text -*- */
/* Process source files and output type information.
/* Process source files and output type information.
   Copyright (C) 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
   Copyright (C) 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
This file is part of GCC.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
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
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
Software Foundation; either version 3, or (at your option) any later
version.
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.
for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
along with GCC; see the file COPYING3.  If not see
.  */
.  */
%{
%{
#include "bconfig.h"
#include "bconfig.h"
#include "coretypes.h"
#include "coretypes.h"
#include "system.h"
#include "system.h"
#define malloc xmalloc
#define malloc xmalloc
#define realloc xrealloc
#define realloc xrealloc
#include "gengtype.h"
#include "gengtype.h"
#include "gengtype-yacc.h"
#include "gengtype-yacc.h"
#define YY_INPUT(BUF,RESULT,SIZE) ((RESULT) = macro_input (BUF,SIZE))
#define YY_INPUT(BUF,RESULT,SIZE) ((RESULT) = macro_input (BUF,SIZE))
static unsigned macro_input (char *buffer, unsigned);
static unsigned macro_input (char *buffer, unsigned);
static const char *push_macro_expansion (const char *, unsigned,
static const char *push_macro_expansion (const char *, unsigned,
                                         const char *, unsigned);
                                         const char *, unsigned);
static char *mangle_macro_name (const char *, unsigned,
static char *mangle_macro_name (const char *, unsigned,
                                const char *, unsigned);
                                const char *, unsigned);
static void update_lineno (const char *l, size_t len);
static void update_lineno (const char *l, size_t len);
struct fileloc lexer_line;
struct fileloc lexer_line;
int lexer_toplevel_done;
int lexer_toplevel_done;
static void
static void
update_lineno (const char *l, size_t len)
update_lineno (const char *l, size_t len)
{
{
  while (len-- > 0)
  while (len-- > 0)
    if (*l++ == '\n')
    if (*l++ == '\n')
      lexer_line.line++;
      lexer_line.line++;
}
}
%}
%}
ID      [[:alpha:]_][[:alnum:]_]*
ID      [[:alpha:]_][[:alnum:]_]*
WS      [[:space:]]+
WS      [[:space:]]+
IWORD   short|long|(un)?signed|char|int|HOST_WIDE_INT|HOST_WIDEST_INT|bool|size_t|BOOL_BITFIELD
IWORD   short|long|(un)?signed|char|int|HOST_WIDE_INT|HOST_WIDEST_INT|bool|size_t|BOOL_BITFIELD
ITYPE   {IWORD}({WS}{IWORD})*
ITYPE   {IWORD}({WS}{IWORD})*
%x in_struct in_struct_comment in_comment in_yacc_escape
%x in_struct in_struct_comment in_comment in_yacc_escape
%option warn noyywrap nounput nodefault perf-report
%option warn noyywrap nounput nodefault perf-report
%option 8bit never-interactive
%option 8bit never-interactive
%%
%%
[^[:alnum:]_]typedef{WS}(struct|union){WS}{ID}{WS}?[*[:space:]]{WS}?{ID}{WS}?";" {
[^[:alnum:]_]typedef{WS}(struct|union){WS}{ID}{WS}?[*[:space:]]{WS}?{ID}{WS}?";" {
  char *tagstart;
  char *tagstart;
  size_t taglen;
  size_t taglen;
  char *namestart;
  char *namestart;
  size_t namelen;
  size_t namelen;
  int is_pointer = 0;
  int is_pointer = 0;
  struct type *t;
  struct type *t;
  int union_p;
  int union_p;
  tagstart = yytext + strlen (" typedef ");
  tagstart = yytext + strlen (" typedef ");
  while (ISSPACE (*tagstart))
  while (ISSPACE (*tagstart))
    tagstart++;
    tagstart++;
  union_p = tagstart[0] == 'u';
  union_p = tagstart[0] == 'u';
  tagstart += strlen ("union ");
  tagstart += strlen ("union ");
  while (ISSPACE (*tagstart))
  while (ISSPACE (*tagstart))
    tagstart++;
    tagstart++;
  for (taglen = 1; ISIDNUM (tagstart[taglen]); taglen++)
  for (taglen = 1; ISIDNUM (tagstart[taglen]); taglen++)
    ;
    ;
  for (namestart = tagstart + taglen;
  for (namestart = tagstart + taglen;
       ! ISIDNUM (*namestart);
       ! ISIDNUM (*namestart);
       namestart++)
       namestart++)
    if (*namestart == '*')
    if (*namestart == '*')
      is_pointer = 1;
      is_pointer = 1;
  for (namelen = 1; ISIDNUM (namestart[namelen]); namelen++)
  for (namelen = 1; ISIDNUM (namestart[namelen]); namelen++)
    ;
    ;
  t = find_structure ((const char *) xmemdup (tagstart, taglen, taglen+1),
  t = find_structure ((const char *) xmemdup (tagstart, taglen, taglen+1),
                      union_p);
                      union_p);
  if (is_pointer)
  if (is_pointer)
    t = create_pointer (t);
    t = create_pointer (t);
  namestart = (char *) xmemdup (namestart, namelen, namelen+1);
  namestart = (char *) xmemdup (namestart, namelen, namelen+1);
#ifdef USE_MAPPED_LOCATION
#ifdef USE_MAPPED_LOCATION
  /* temporary kludge - gentype doesn't handle cpp conditionals */
  /* temporary kludge - gentype doesn't handle cpp conditionals */
  if (strcmp (namestart, "location_t") != 0
  if (strcmp (namestart, "location_t") != 0
      && strcmp (namestart, "expanded_location") != 0)
      && strcmp (namestart, "expanded_location") != 0)
#endif
#endif
  do_typedef (namestart, t, &lexer_line);
  do_typedef (namestart, t, &lexer_line);
  update_lineno (yytext, yyleng);
  update_lineno (yytext, yyleng);
}
}
[^[:alnum:]_]typedef{WS}{ITYPE}{WS}{ID}{WS}?";" {
[^[:alnum:]_]typedef{WS}{ITYPE}{WS}{ID}{WS}?";" {
  char *namestart;
  char *namestart;
  size_t namelen;
  size_t namelen;
  struct type *t;
  struct type *t;
  char *typestart;
  char *typestart;
  size_t typelen;
  size_t typelen;
  for (namestart = yytext + yyleng - 2; ISSPACE (*namestart); namestart--)
  for (namestart = yytext + yyleng - 2; ISSPACE (*namestart); namestart--)
    ;
    ;
  for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
  for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
    ;
    ;
  namestart -= namelen - 1;
  namestart -= namelen - 1;
  for (typestart = yytext + strlen (" typedef ");
  for (typestart = yytext + strlen (" typedef ");
       ISSPACE(*typestart);
       ISSPACE(*typestart);
       typestart++)
       typestart++)
    ;
    ;
  for (typelen = namestart - typestart;
  for (typelen = namestart - typestart;
       ISSPACE (typestart[typelen-1]);
       ISSPACE (typestart[typelen-1]);
       typelen--)
       typelen--)
    ;
    ;
  t = create_scalar_type (typestart, typelen);
  t = create_scalar_type (typestart, typelen);
  do_typedef ((const char *) xmemdup (namestart, namelen, namelen+1), t,
  do_typedef ((const char *) xmemdup (namestart, namelen, namelen+1), t,
              &lexer_line);
              &lexer_line);
  update_lineno (yytext, yyleng);
  update_lineno (yytext, yyleng);
}
}
[^[:alnum:]_]typedef{WS}{ID}{WS}{ID}{WS}PARAMS {
[^[:alnum:]_]typedef{WS}{ID}{WS}{ID}{WS}PARAMS {
  char *namestart;
  char *namestart;
  size_t namelen;
  size_t namelen;
  struct type *t;
  struct type *t;
  for (namestart = yytext + yyleng - 7; ISSPACE (*namestart); namestart--)
  for (namestart = yytext + yyleng - 7; ISSPACE (*namestart); namestart--)
    ;
    ;
  for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
  for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
    ;
    ;
  namestart -= namelen - 1;
  namestart -= namelen - 1;
  t = create_scalar_type ("function type", sizeof ("function type")-1);
  t = create_scalar_type ("function type", sizeof ("function type")-1);
  do_typedef ((const char *) xmemdup (namestart, namelen, namelen+1), t,
  do_typedef ((const char *) xmemdup (namestart, namelen, namelen+1), t,
              &lexer_line);
              &lexer_line);
  update_lineno (yytext, yyleng);
  update_lineno (yytext, yyleng);
}
}
[^[:alnum:]_]typedef{WS}{ID}{WS}{ID}{WS}"(" {
[^[:alnum:]_]typedef{WS}{ID}{WS}{ID}{WS}"(" {
  char *namestart;
  char *namestart;
  size_t namelen;
  size_t namelen;
  struct type *t;
  struct type *t;
  for (namestart = yytext + yyleng - 2; ISSPACE (*namestart); namestart--)
  for (namestart = yytext + yyleng - 2; ISSPACE (*namestart); namestart--)
    ;
    ;
  for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
  for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
    ;
    ;
  namestart -= namelen - 1;
  namestart -= namelen - 1;
  t = create_scalar_type ("function type", sizeof ("function type")-1);
  t = create_scalar_type ("function type", sizeof ("function type")-1);
  do_typedef ((const char *) xmemdup (namestart, namelen, namelen+1), t,
  do_typedef ((const char *) xmemdup (namestart, namelen, namelen+1), t,
              &lexer_line);
              &lexer_line);
  update_lineno (yytext, yyleng);
  update_lineno (yytext, yyleng);
}
}
[^[:alnum:]_]typedef{WS}{ID}{WS}?"*"?{WS}?"("{WS}?"*"{WS}?{ID}{WS}?")"{WS}?PARAMS {
[^[:alnum:]_]typedef{WS}{ID}{WS}?"*"?{WS}?"("{WS}?"*"{WS}?{ID}{WS}?")"{WS}?PARAMS {
  char *namestart;
  char *namestart;
  size_t namelen;
  size_t namelen;
  struct type *t;
  struct type *t;
  for (namestart = yytext + yyleng - 7; !ISIDNUM (*namestart); namestart--)
  for (namestart = yytext + yyleng - 7; !ISIDNUM (*namestart); namestart--)
    ;
    ;
  for (namelen = 1; ISIDNUM (namestart[-namelen]); namelen++)
  for (namelen = 1; ISIDNUM (namestart[-namelen]); namelen++)
    ;
    ;
  namestart -= namelen - 1;
  namestart -= namelen - 1;
  t = create_scalar_type ("function type", sizeof ("function type")-1);
  t = create_scalar_type ("function type", sizeof ("function type")-1);
  do_typedef ((const char *) xmemdup (namestart, namelen, namelen+1), t,
  do_typedef ((const char *) xmemdup (namestart, namelen, namelen+1), t,
              &lexer_line);
              &lexer_line);
  update_lineno (yytext, yyleng);
  update_lineno (yytext, yyleng);
}
}
[^[:alnum:]_]typedef{WS}{ID}{WS}?"*"?{WS}?"("{WS}?"*"{WS}?{ID}{WS}?")"{WS}?"(" {
[^[:alnum:]_]typedef{WS}{ID}{WS}?"*"?{WS}?"("{WS}?"*"{WS}?{ID}{WS}?")"{WS}?"(" {
  char *namestart;
  char *namestart;
  size_t namelen;
  size_t namelen;
  struct type *t;
  struct type *t;
  for (namestart = yytext + yyleng - 2; !ISIDNUM (*namestart); namestart--)
  for (namestart = yytext + yyleng - 2; !ISIDNUM (*namestart); namestart--)
    ;
    ;
  for (namelen = 1; ISIDNUM (namestart[-namelen]); namelen++)
  for (namelen = 1; ISIDNUM (namestart[-namelen]); namelen++)
    ;
    ;
  namestart -= namelen - 1;
  namestart -= namelen - 1;
  t = create_scalar_type ("function type", sizeof ("function type")-1);
  t = create_scalar_type ("function type", sizeof ("function type")-1);
  do_typedef ((const char *) xmemdup (namestart, namelen, namelen+1), t,
  do_typedef ((const char *) xmemdup (namestart, namelen, namelen+1), t,
              &lexer_line);
              &lexer_line);
  update_lineno (yytext, yyleng);
  update_lineno (yytext, yyleng);
}
}
[^[:alnum:]_](typedef{WS})?(struct|union){WS}{ID}{WS}/"GTY" {
[^[:alnum:]_](typedef{WS})?(struct|union){WS}{ID}{WS}/"GTY" {
  char *tagstart;
  char *tagstart;
  size_t taglen;
  size_t taglen;
  int typedef_p;
  int typedef_p;
  int union_p;
  int union_p;
  typedef_p = yytext[1] == 't';
  typedef_p = yytext[1] == 't';
  if (typedef_p)
  if (typedef_p)
    for (tagstart = yytext + strlen (" typedef ");
    for (tagstart = yytext + strlen (" typedef ");
         ISSPACE(*tagstart);
         ISSPACE(*tagstart);
         tagstart++)
         tagstart++)
      ;
      ;
  else
  else
    tagstart = yytext + 1;
    tagstart = yytext + 1;
  union_p = tagstart[0] == 'u';
  union_p = tagstart[0] == 'u';
  tagstart += strlen ("union ");
  tagstart += strlen ("union ");
  while (ISSPACE (*tagstart))
  while (ISSPACE (*tagstart))
    tagstart++;
    tagstart++;
  for (taglen = 1; ISIDNUM (tagstart[taglen]); taglen++)
  for (taglen = 1; ISIDNUM (tagstart[taglen]); taglen++)
    ;
    ;
  yylval.t = find_structure ((const char *) xmemdup (tagstart, taglen,
  yylval.t = find_structure ((const char *) xmemdup (tagstart, taglen,
                                                     taglen + 1),
                                                     taglen + 1),
                             union_p);
                             union_p);
  BEGIN(in_struct);
  BEGIN(in_struct);
  update_lineno (yytext, yyleng);
  update_lineno (yytext, yyleng);
  return typedef_p ? ENT_TYPEDEF_STRUCT : ENT_STRUCT;
  return typedef_p ? ENT_TYPEDEF_STRUCT : ENT_STRUCT;
}
}
[^[:alnum:]_](extern|static){WS}/"GTY" {
[^[:alnum:]_](extern|static){WS}/"GTY" {
  BEGIN(in_struct);
  BEGIN(in_struct);
  update_lineno (yytext, yyleng);
  update_lineno (yytext, yyleng);
  return ENT_EXTERNSTATIC;
  return ENT_EXTERNSTATIC;
}
}
^"%union"{WS}"{"{WS}/"GTY" {
^"%union"{WS}"{"{WS}/"GTY" {
  BEGIN(in_struct);
  BEGIN(in_struct);
  update_lineno (yytext, yyleng);
  update_lineno (yytext, yyleng);
  return ENT_YACCUNION;
  return ENT_YACCUNION;
}
}
^"DEF_VEC_"[[:alnum:]_]*{WS}?"("{WS}?{ID}{WS}?(","{WS}?{ID}{WS}?)*")" {
^"DEF_VEC_"[[:alnum:]_]*{WS}?"("{WS}?{ID}{WS}?(","{WS}?{ID}{WS}?)*")" {
  char *macro, *arg;
  char *macro, *arg;
  unsigned macro_len, arg_len;
  unsigned macro_len, arg_len;
  char *ptr = yytext;
  char *ptr = yytext;
  const char *additional;
  const char *additional;
  type_p t;
  type_p t;
  /* Find the macro name.  */
  /* Find the macro name.  */
  for (macro = ptr; *ptr != '(' && !ISSPACE (*ptr); ptr++)
  for (macro = ptr; *ptr != '(' && !ISSPACE (*ptr); ptr++)
    continue;
    continue;
  for (macro_len = ptr - macro; !(ISALNUM (*ptr) || *ptr == '_'); ptr++)
  for (macro_len = ptr - macro; !(ISALNUM (*ptr) || *ptr == '_'); ptr++)
    continue;
    continue;
  /* Find the argument(s).  */
  /* Find the argument(s).  */
  for (arg = ptr; *ptr != ')'; ptr++)
  for (arg = ptr; *ptr != ')'; ptr++)
    continue;
    continue;
  arg_len = ptr - arg;
  arg_len = ptr - arg;
  /* Create the struct and typedef.  */
  /* Create the struct and typedef.  */
  ptr = mangle_macro_name ("VEC", 3, arg, arg_len);
  ptr = mangle_macro_name ("VEC", 3, arg, arg_len);
  t = find_structure (ptr, 0);
  t = find_structure (ptr, 0);
  do_typedef (ptr, t, &lexer_line);
  do_typedef (ptr, t, &lexer_line);
  /* Push the macro for later expansion.  */
  /* Push the macro for later expansion.  */
  additional = push_macro_expansion (macro, macro_len, arg, arg_len);
  additional = push_macro_expansion (macro, macro_len, arg, arg_len);
  if (additional)
  if (additional)
    {
    {
      ptr = mangle_macro_name (ptr, strlen (ptr),
      ptr = mangle_macro_name (ptr, strlen (ptr),
                               additional, strlen (additional));
                               additional, strlen (additional));
      t = find_structure (ptr, 0);
      t = find_structure (ptr, 0);
      do_typedef (ptr, t, &lexer_line);
      do_typedef (ptr, t, &lexer_line);
    }
    }
}
}
{
{
"/*"                            { BEGIN(in_struct_comment); }
"/*"                            { BEGIN(in_struct_comment); }
^"%{"                           { BEGIN(in_yacc_escape); } /* } */
^"%{"                           { BEGIN(in_yacc_escape); } /* } */
{WS}                            { update_lineno (yytext, yyleng); }
{WS}                            { update_lineno (yytext, yyleng); }
"const"/[^[:alnum:]_]           /* don't care */
"const"/[^[:alnum:]_]           /* don't care */
"GTY"/[^[:alnum:]_]             { return GTY_TOKEN; }
"GTY"/[^[:alnum:]_]             { return GTY_TOKEN; }
"union"/[^[:alnum:]_]           { return UNION; }
"union"/[^[:alnum:]_]           { return UNION; }
"struct"/[^[:alnum:]_]          { return STRUCT; }
"struct"/[^[:alnum:]_]          { return STRUCT; }
"enum"/[^[:alnum:]_]            { return ENUM; }
"enum"/[^[:alnum:]_]            { return ENUM; }
"ptr_alias"/[^[:alnum:]_]       { return ALIAS; }
"ptr_alias"/[^[:alnum:]_]       { return ALIAS; }
"nested_ptr"/[^[:alnum:]_]      { return NESTED_PTR; }
"nested_ptr"/[^[:alnum:]_]      { return NESTED_PTR; }
[0-9]+                          { return NUM; }
[0-9]+                          { return NUM; }
"param"[0-9]*"_is"/[^[:alnum:]_]                {
"param"[0-9]*"_is"/[^[:alnum:]_]                {
  yylval.s = (const char *) xmemdup (yytext, yyleng, yyleng+1);
  yylval.s = (const char *) xmemdup (yytext, yyleng, yyleng+1);
  return PARAM_IS;
  return PARAM_IS;
}
}
{IWORD}({WS}{IWORD})*/[^[:alnum:]_]             |
{IWORD}({WS}{IWORD})*/[^[:alnum:]_]             |
"ENUM_BITFIELD"{WS}?"("{WS}?{ID}{WS}?")"        {
"ENUM_BITFIELD"{WS}?"("{WS}?{ID}{WS}?")"        {
  size_t len;
  size_t len;
  for (len = yyleng; ISSPACE (yytext[len-1]); len--)
  for (len = yyleng; ISSPACE (yytext[len-1]); len--)
    ;
    ;
  yylval.t = create_scalar_type (yytext, len);
  yylval.t = create_scalar_type (yytext, len);
  update_lineno (yytext, yyleng);
  update_lineno (yytext, yyleng);
  return SCALAR;
  return SCALAR;
}
}
"VEC"{WS}?"("{WS}?{ID}{WS}?(","{WS}?{ID}{WS}?)*")" {
"VEC"{WS}?"("{WS}?{ID}{WS}?(","{WS}?{ID}{WS}?)*")" {
  char *macro, *arg;
  char *macro, *arg;
  unsigned macro_len, arg_len;
  unsigned macro_len, arg_len;
  char *ptr = yytext;
  char *ptr = yytext;
  /* Find the macro name */
  /* Find the macro name */
  for (macro = ptr; *ptr != '(' && !ISSPACE (*ptr); ptr++)
  for (macro = ptr; *ptr != '(' && !ISSPACE (*ptr); ptr++)
    continue;
    continue;
  for (macro_len = ptr - macro; !(ISALNUM(*ptr) || *ptr == '_'); ptr++)
  for (macro_len = ptr - macro; !(ISALNUM(*ptr) || *ptr == '_'); ptr++)
    continue;
    continue;
  /* Find the arguments.  */
  /* Find the arguments.  */
  for (arg = ptr; *ptr != ')'; ptr++)
  for (arg = ptr; *ptr != ')'; ptr++)
    continue;
    continue;
  arg_len = ptr - arg;
  arg_len = ptr - arg;
  ptr = mangle_macro_name (macro, macro_len, arg, arg_len);
  ptr = mangle_macro_name (macro, macro_len, arg, arg_len);
  yylval.s = ptr;
  yylval.s = ptr;
  return ID;
  return ID;
}
}
{ID}/[^[:alnum:]_]              {
{ID}/[^[:alnum:]_]              {
  yylval.s = (const char *) xmemdup (yytext, yyleng, yyleng+1);
  yylval.s = (const char *) xmemdup (yytext, yyleng, yyleng+1);
  return ID;
  return ID;
}
}
\"([^"\\]|\\.)*\"               {
\"([^"\\]|\\.)*\"               {
  yylval.s = (const char *) xmemdup (yytext+1, yyleng-2, yyleng-1);
  yylval.s = (const char *) xmemdup (yytext+1, yyleng-2, yyleng-1);
  return STRING;
  return STRING;
}
}
"["[^\[\]]*"]"                  {
"["[^\[\]]*"]"                  {
  yylval.s = (const char *) xmemdup (yytext+1, yyleng-2, yyleng-1);
  yylval.s = (const char *) xmemdup (yytext+1, yyleng-2, yyleng-1);
  return ARRAY;
  return ARRAY;
}
}
^"%"{ID}                        {
^"%"{ID}                        {
  yylval.s = (const char *) xmemdup (yytext+1, yyleng-1, yyleng);
  yylval.s = (const char *) xmemdup (yytext+1, yyleng-1, yyleng);
  return PERCENT_ID;
  return PERCENT_ID;
}
}
"'"("\\".|[^\\])"'"             {
"'"("\\".|[^\\])"'"             {
  yylval.s = (const char *) xmemdup (yytext+1, yyleng-2, yyleng);
  yylval.s = (const char *) xmemdup (yytext+1, yyleng-2, yyleng);
  return CHAR;
  return CHAR;
}
}
[(){},*:<>]                     { return yytext[0]; }
[(){},*:<>]                     { return yytext[0]; }
[;=]                            {
[;=]                            {
  if (lexer_toplevel_done)
  if (lexer_toplevel_done)
    {
    {
      BEGIN(INITIAL);
      BEGIN(INITIAL);
      lexer_toplevel_done = 0;
      lexer_toplevel_done = 0;
    }
    }
  return yytext[0];
  return yytext[0];
}
}
^"%%"                           {
^"%%"                           {
  BEGIN(INITIAL);
  BEGIN(INITIAL);
  return PERCENTPERCENT;
  return PERCENTPERCENT;
}
}
"#define"[^\n]*\n               {lexer_line.line++;}
"#define"[^\n]*\n               {lexer_line.line++;}
.                               {
.                               {
  error_at_line (&lexer_line, "unexpected character `%s'", yytext);
  error_at_line (&lexer_line, "unexpected character `%s'", yytext);
}
}
}
}
"/*"                    { BEGIN(in_comment); }
"/*"                    { BEGIN(in_comment); }
\n                      { lexer_line.line++; }
\n                      { lexer_line.line++; }
{ID}                    |
{ID}                    |
"'"("\\".|[^\\])"'"     |
"'"("\\".|[^\\])"'"     |
[^"/\n]                 /* do nothing */
[^"/\n]                 /* do nothing */
\"([^"\\]|\\.|\\\n)*\"  { update_lineno (yytext, yyleng); }
\"([^"\\]|\\.|\\\n)*\"  { update_lineno (yytext, yyleng); }
"/"/[^*]                /* do nothing */
"/"/[^*]                /* do nothing */
{
{
\n              { lexer_line.line++; }
\n              { lexer_line.line++; }
[^*\n]{16}      |
[^*\n]{16}      |
[^*\n]          /* do nothing */
[^*\n]          /* do nothing */
"*"/[^/]        /* do nothing */
"*"/[^/]        /* do nothing */
}
}
"*/"    { BEGIN(INITIAL); }
"*/"    { BEGIN(INITIAL); }
"*/"    { BEGIN(in_struct); }
"*/"    { BEGIN(in_struct); }
{
{
\n              { lexer_line.line++; }
\n              { lexer_line.line++; }
[^%]{16}        |
[^%]{16}        |
[^%]            /* do nothing */
[^%]            /* do nothing */
"%"/[^}]        /* do nothing */
"%"/[^}]        /* do nothing */
"%}"            { BEGIN(in_struct); }
"%}"            { BEGIN(in_struct); }
"%"             {
"%"             {
  error_at_line (&lexer_line,
  error_at_line (&lexer_line,
                 "unterminated %%{; unexpected EOF");
                 "unterminated %%{; unexpected EOF");
}
}
}
}
["/]                    |
["/]                    |
"*"     {
"*"     {
  error_at_line (&lexer_line,
  error_at_line (&lexer_line,
                 "unterminated comment or string; unexpected EOF");
                 "unterminated comment or string; unexpected EOF");
}
}
^"#define"{WS}"GTY(" /* do nothing */
^"#define"{WS}"GTY(" /* do nothing */
{WS}"GTY"{WS}?"("       {
{WS}"GTY"{WS}?"("       {
  error_at_line (&lexer_line, "stray GTY marker");
  error_at_line (&lexer_line, "stray GTY marker");
}
}
%%
%%
/* Deal with the expansion caused by the DEF_VEC_x macros.  */
/* Deal with the expansion caused by the DEF_VEC_x macros.  */
/* Mangle a macro and argument list as done by cpp concatenation in
/* Mangle a macro and argument list as done by cpp concatenation in
   the compiler proper.  */
   the compiler proper.  */
static char *
static char *
mangle_macro_name (const char *macro, unsigned macro_len,
mangle_macro_name (const char *macro, unsigned macro_len,
                   const char *arg, unsigned arg_len)
                   const char *arg, unsigned arg_len)
{
{
  char *ptr = (char *) xmemdup (macro, macro_len, macro_len + arg_len + 2);
  char *ptr = (char *) xmemdup (macro, macro_len, macro_len + arg_len + 2);
  /* Now copy and concatenate each argument */
  /* Now copy and concatenate each argument */
  while (arg_len)
  while (arg_len)
    {
    {
      ptr[macro_len++] = '_';
      ptr[macro_len++] = '_';
      for (; arg_len && (ISALNUM(*arg) || *arg == '_'); arg_len--)
      for (; arg_len && (ISALNUM(*arg) || *arg == '_'); arg_len--)
        ptr[macro_len++] = *arg++;
        ptr[macro_len++] = *arg++;
      for (; arg_len && !(ISALNUM(*arg) || *arg == '_'); arg_len--)
      for (; arg_len && !(ISALNUM(*arg) || *arg == '_'); arg_len--)
        arg++;
        arg++;
    }
    }
  ptr[macro_len] = 0;
  ptr[macro_len] = 0;
  return ptr;
  return ptr;
}
}
typedef struct macro_def
typedef struct macro_def
{
{
  const char *name;
  const char *name;
  const char *expansion;
  const char *expansion;
  const char *additional;
  const char *additional;
} macro_def_t;
} macro_def_t;
typedef struct macro
typedef struct macro
{
{
  const macro_def_t *def;
  const macro_def_t *def;
  struct macro *next;
  struct macro *next;
  const char *args[10];
  const char *args[10];
} macro_t;
} macro_t;
static const macro_def_t macro_defs[] =
static const macro_def_t macro_defs[] =
{
{
#define IN_GENGTYPE 1
#define IN_GENGTYPE 1
#include "vec.h"
#include "vec.h"
  {NULL, NULL, NULL}
  {NULL, NULL, NULL}
};
};
/* Chain of macro expansions to do at end of scanning.  */
/* Chain of macro expansions to do at end of scanning.  */
static macro_t *macro_expns;
static macro_t *macro_expns;
static macro_t *macro_expns_end;
static macro_t *macro_expns_end;
/* Push macro NAME (NAME_LEN) with argument ARG (ARG_LEN) onto the
/* Push macro NAME (NAME_LEN) with argument ARG (ARG_LEN) onto the
   expansion queue.  We ensure NAME is known at this point.  */
   expansion queue.  We ensure NAME is known at this point.  */
static const char *
static const char *
push_macro_expansion (const char *name, unsigned name_len,
push_macro_expansion (const char *name, unsigned name_len,
                      const char *arg, unsigned arg_len)
                      const char *arg, unsigned arg_len)
{
{
  unsigned ix;
  unsigned ix;
  for (ix = 0; macro_defs[ix].name; ix++)
  for (ix = 0; macro_defs[ix].name; ix++)
    if (strlen (macro_defs[ix].name) == name_len
    if (strlen (macro_defs[ix].name) == name_len
        && !memcmp (name, macro_defs[ix].name, name_len))
        && !memcmp (name, macro_defs[ix].name, name_len))
      {
      {
        macro_t *expansion = XNEW (macro_t);
        macro_t *expansion = XNEW (macro_t);
        char *args;
        char *args;
        unsigned argno, last_arg;
        unsigned argno, last_arg;
        expansion->def = ¯o_defs[ix];
        expansion->def = ¯o_defs[ix];
        expansion->next = NULL;
        expansion->next = NULL;
        args = (char *) xmemdup (arg, arg_len, arg_len+1);
        args = (char *) xmemdup (arg, arg_len, arg_len+1);
        args[arg_len] = 0;
        args[arg_len] = 0;
        for (argno = 0; *args;)
        for (argno = 0; *args;)
          {
          {
            expansion->args[argno++] = args;
            expansion->args[argno++] = args;
            while (*args && (ISALNUM (*args) || *args == '_'))
            while (*args && (ISALNUM (*args) || *args == '_'))
              args++;
              args++;
            if (argno == 1)
            if (argno == 1)
              expansion->args[argno++] = "base";
              expansion->args[argno++] = "base";
            if (!*args)
            if (!*args)
              break;
              break;
            *args++ = 0;
            *args++ = 0;
            while (*args && !(ISALNUM (*args) || *args == '_'))
            while (*args && !(ISALNUM (*args) || *args == '_'))
              args++;
              args++;
          }
          }
        last_arg = argno;
        last_arg = argno;
        for (; argno != 10; argno++)
        for (; argno != 10; argno++)
          expansion->args[argno] = NULL;
          expansion->args[argno] = NULL;
        if (macro_expns_end)
        if (macro_expns_end)
          macro_expns_end->next = expansion;
          macro_expns_end->next = expansion;
        else
        else
          macro_expns = expansion;
          macro_expns = expansion;
        macro_expns_end = expansion;
        macro_expns_end = expansion;
        if (macro_defs[ix].additional)
        if (macro_defs[ix].additional)
          {
          {
            macro_t *expn2 = XNEW (macro_t);
            macro_t *expn2 = XNEW (macro_t);
            memcpy (expn2, expansion, sizeof (*expn2));
            memcpy (expn2, expansion, sizeof (*expn2));
            expansion = expn2;
            expansion = expn2;
            expansion->def += 1;
            expansion->def += 1;
            expansion->args[last_arg++] = macro_defs[ix].additional;
            expansion->args[last_arg++] = macro_defs[ix].additional;
            macro_expns_end->next = expansion;
            macro_expns_end->next = expansion;
            macro_expns_end = expansion;
            macro_expns_end = expansion;
          }
          }
        if (last_arg > 2 && strcmp (expansion->args[last_arg - 1], "heap"))
        if (last_arg > 2 && strcmp (expansion->args[last_arg - 1], "heap"))
          expansion->args[last_arg++] = "GTY (())";
          expansion->args[last_arg++] = "GTY (())";
        return macro_defs[ix].additional;
        return macro_defs[ix].additional;
      }
      }
  error_at_line (&lexer_line, "unrecognized macro `%.*s(%.*s)'",
  error_at_line (&lexer_line, "unrecognized macro `%.*s(%.*s)'",
                 name_len, name, arg_len, arg);
                 name_len, name, arg_len, arg);
  return NULL;
  return NULL;
}
}
/* Attempt to read some input.  Use fread until we're at the end of
/* 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
   file.  At end of file expand the next queued macro.  We presume the
   buffer is large enough for the entire expansion.  */
   buffer is large enough for the entire expansion.  */
static unsigned
static unsigned
macro_input (char *buffer, unsigned size)
macro_input (char *buffer, unsigned size)
{
{
  unsigned result;
  unsigned result;
  result = fread (buffer, 1, size, yyin);
  result = fread (buffer, 1, size, yyin);
  if (result)
  if (result)
    /*NOP*/;
    /*NOP*/;
  else if (ferror (yyin))
  else if (ferror (yyin))
    YY_FATAL_ERROR ("read of source file failed");
    YY_FATAL_ERROR ("read of source file failed");
  else if (macro_expns)
  else if (macro_expns)
    {
    {
      const char *expn;
      const char *expn;
      unsigned len;
      unsigned len;
      for (expn = macro_expns->def->expansion; *expn; expn++)
      for (expn = macro_expns->def->expansion; *expn; expn++)
        {
        {
          if (*expn == '#')
          if (*expn == '#')
            {
            {
              int argno;
              int argno;
              argno = expn[1] - '0';
              argno = expn[1] - '0';
              expn += 1;
              expn += 1;
              /* Remove inserted space? */
              /* Remove inserted space? */
              if (buffer[result-1] == ' ' && buffer[result-2] == '_')
              if (buffer[result-1] == ' ' && buffer[result-2] == '_')
                result--;
                result--;
              /* Insert the argument value */
              /* Insert the argument value */
              if (macro_expns->args[argno])
              if (macro_expns->args[argno])
                {
                {
                  len = strlen (macro_expns->args[argno]);
                  len = strlen (macro_expns->args[argno]);
                  memcpy (&buffer[result], macro_expns->args[argno], len);
                  memcpy (&buffer[result], macro_expns->args[argno], len);
                  result += len;
                  result += len;
                }
                }
              /* Skip next space? */
              /* Skip next space? */
              if (expn[1] == ' ' && expn[2] == '_')
              if (expn[1] == ' ' && expn[2] == '_')
                expn++;
                expn++;
            }
            }
          else
          else
            {
            {
              buffer[result++] = *expn;
              buffer[result++] = *expn;
              if (*expn == ';' || *expn == '{')
              if (*expn == ';' || *expn == '{')
                buffer[result++] = '\n';
                buffer[result++] = '\n';
            }
            }
        }
        }
      if (result > size)
      if (result > size)
        YY_FATAL_ERROR ("buffer too small to expand macro");
        YY_FATAL_ERROR ("buffer too small to expand macro");
      macro_expns = macro_expns->next;
      macro_expns = macro_expns->next;
      if (!macro_expns)
      if (!macro_expns)
        macro_expns_end = NULL;
        macro_expns_end = NULL;
    }
    }
  return result;
  return result;
}
}
void
void
yyerror (const char *s)
yyerror (const char *s)
{
{
  error_at_line (&lexer_line, s);
  error_at_line (&lexer_line, s);
}
}
void
void
parse_file (const char *fname)
parse_file (const char *fname)
{
{
  yyin = fopen (fname, "r");
  yyin = fopen (fname, "r");
  lexer_line.file = fname;
  lexer_line.file = fname;
  lexer_line.line = 1;
  lexer_line.line = 1;
  if (yyin == NULL)
  if (yyin == NULL)
    {
    {
      perror (fname);
      perror (fname);
      exit (1);
      exit (1);
    }
    }
  if (yyparse() != 0)
  if (yyparse() != 0)
    exit (1);
    exit (1);
  fclose (yyin);
  fclose (yyin);
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.