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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [scan.c] - Diff between revs 154 and 816

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

Rev 154 Rev 816
/* Utility functions for scan-decls and fix-header programs.
/* Utility functions for scan-decls and fix-header programs.
   Copyright (C) 1993, 1994, 1998, 2002, 2003, 2007 Free Software Foundation, Inc.
   Copyright (C) 1993, 1994, 1998, 2002, 2003, 2007 Free Software Foundation, Inc.
 
 
   This program is free software; you can redistribute it and/or modify it
   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
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 3, or (at your option) any
   Free Software Foundation; either version 3, or (at your option) any
   later version.
   later version.
 
 
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License 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 this program; see the file COPYING3.  If not see
   along with this program; see the file COPYING3.  If not see
   <http://www.gnu.org/licenses/>.  */
   <http://www.gnu.org/licenses/>.  */
 
 
#include "bconfig.h"
#include "bconfig.h"
#include "system.h"
#include "system.h"
#include "coretypes.h"
#include "coretypes.h"
#include "tm.h"
#include "tm.h"
#include "scan.h"
#include "scan.h"
 
 
int lineno = 1;
int lineno = 1;
int source_lineno = 1;
int source_lineno = 1;
sstring source_filename;
sstring source_filename;
 
 
void
void
make_sstring_space (sstring *str, int count)
make_sstring_space (sstring *str, int count)
{
{
  int cur_pos = str->ptr - str->base;
  int cur_pos = str->ptr - str->base;
  int cur_size = str->limit - str->base;
  int cur_size = str->limit - str->base;
  int new_size = cur_pos + count + 100;
  int new_size = cur_pos + count + 100;
 
 
  if (new_size <= cur_size)
  if (new_size <= cur_size)
    return;
    return;
 
 
  str->base = xrealloc (str->base, new_size);
  str->base = xrealloc (str->base, new_size);
  str->ptr = str->base + cur_size;
  str->ptr = str->base + cur_size;
  str->limit = str->base + new_size;
  str->limit = str->base + new_size;
}
}
 
 
void
void
sstring_append (sstring *dst, sstring *src)
sstring_append (sstring *dst, sstring *src)
{
{
  char *d, *s;
  char *d, *s;
  int count = SSTRING_LENGTH (src);
  int count = SSTRING_LENGTH (src);
 
 
  MAKE_SSTRING_SPACE (dst, count + 1);
  MAKE_SSTRING_SPACE (dst, count + 1);
  d = dst->ptr;
  d = dst->ptr;
  s = src->base;
  s = src->base;
  while (--count >= 0) *d++ = *s++;
  while (--count >= 0) *d++ = *s++;
  dst->ptr = d;
  dst->ptr = d;
  *d = 0;
  *d = 0;
}
}
 
 
int
int
scan_ident (FILE *fp, sstring *s, int c)
scan_ident (FILE *fp, sstring *s, int c)
{
{
  s->ptr = s->base;
  s->ptr = s->base;
  if (ISIDST (c))
  if (ISIDST (c))
    {
    {
      for (;;)
      for (;;)
        {
        {
          SSTRING_PUT (s, c);
          SSTRING_PUT (s, c);
          c = getc (fp);
          c = getc (fp);
          if (c == EOF || ! ISIDNUM (c))
          if (c == EOF || ! ISIDNUM (c))
            break;
            break;
        }
        }
    }
    }
  MAKE_SSTRING_SPACE (s, 1);
  MAKE_SSTRING_SPACE (s, 1);
  *s->ptr = 0;
  *s->ptr = 0;
  return c;
  return c;
}
}
 
 
int
int
scan_string (FILE *fp, sstring *s, int init)
scan_string (FILE *fp, sstring *s, int init)
{
{
  int c;
  int c;
 
 
  for (;;)
  for (;;)
    {
    {
      c = getc (fp);
      c = getc (fp);
      if (c == EOF || c == '\n')
      if (c == EOF || c == '\n')
        break;
        break;
      if (c == init)
      if (c == init)
        {
        {
          c = getc (fp);
          c = getc (fp);
          break;
          break;
        }
        }
      if (c == '\\')
      if (c == '\\')
        {
        {
          c = getc (fp);
          c = getc (fp);
          if (c == EOF)
          if (c == EOF)
            break;
            break;
          if (c == '\n')
          if (c == '\n')
            continue;
            continue;
        }
        }
      SSTRING_PUT (s, c);
      SSTRING_PUT (s, c);
    }
    }
  MAKE_SSTRING_SPACE (s, 1);
  MAKE_SSTRING_SPACE (s, 1);
  *s->ptr = 0;
  *s->ptr = 0;
  return c;
  return c;
}
}
 
 
/* Skip horizontal white spaces (spaces, tabs, and C-style comments).  */
/* Skip horizontal white spaces (spaces, tabs, and C-style comments).  */
 
 
int
int
skip_spaces (FILE *fp, int c)
skip_spaces (FILE *fp, int c)
{
{
  for (;;)
  for (;;)
    {
    {
      if (c == ' ' || c == '\t')
      if (c == ' ' || c == '\t')
        c = getc (fp);
        c = getc (fp);
      else if (c == '/')
      else if (c == '/')
        {
        {
          c = getc (fp);
          c = getc (fp);
          if (c != '*')
          if (c != '*')
            {
            {
              ungetc (c, fp);
              ungetc (c, fp);
              return '/';
              return '/';
            }
            }
          c = getc (fp);
          c = getc (fp);
          for (;;)
          for (;;)
            {
            {
              if (c == EOF)
              if (c == EOF)
                return EOF;
                return EOF;
              else if (c != '*')
              else if (c != '*')
                {
                {
                  if (c == '\n')
                  if (c == '\n')
                    source_lineno++, lineno++;
                    source_lineno++, lineno++;
                  c = getc (fp);
                  c = getc (fp);
                }
                }
              else if ((c = getc (fp)) == '/')
              else if ((c = getc (fp)) == '/')
                return getc (fp);
                return getc (fp);
            }
            }
        }
        }
      else
      else
        break;
        break;
    }
    }
  return c;
  return c;
}
}
 
 
int
int
read_upto (FILE *fp, sstring *str, int delim)
read_upto (FILE *fp, sstring *str, int delim)
{
{
  int ch;
  int ch;
 
 
  for (;;)
  for (;;)
    {
    {
      ch = getc (fp);
      ch = getc (fp);
      if (ch == EOF || ch == delim)
      if (ch == EOF || ch == delim)
        break;
        break;
      SSTRING_PUT (str, ch);
      SSTRING_PUT (str, ch);
    }
    }
  MAKE_SSTRING_SPACE (str, 1);
  MAKE_SSTRING_SPACE (str, 1);
  *str->ptr = 0;
  *str->ptr = 0;
  return ch;
  return ch;
}
}
 
 
int
int
get_token (FILE *fp, sstring *s)
get_token (FILE *fp, sstring *s)
{
{
  int c;
  int c;
 
 
  s->ptr = s->base;
  s->ptr = s->base;
 retry:
 retry:
  c = ' ';
  c = ' ';
  c = skip_spaces (fp, c);
  c = skip_spaces (fp, c);
  if (c == '\n')
  if (c == '\n')
    {
    {
      source_lineno++;
      source_lineno++;
      lineno++;
      lineno++;
      goto retry;
      goto retry;
    }
    }
  if (c == '#')
  if (c == '#')
    {
    {
      c = get_token (fp, s);
      c = get_token (fp, s);
      if (c == INT_TOKEN)
      if (c == INT_TOKEN)
        {
        {
          source_lineno = atoi (s->base) - 1; /* '\n' will add 1 */
          source_lineno = atoi (s->base) - 1; /* '\n' will add 1 */
          get_token (fp, &source_filename);
          get_token (fp, &source_filename);
        }
        }
      for (;;)
      for (;;)
        {
        {
          c = getc (fp);
          c = getc (fp);
          if (c == EOF)
          if (c == EOF)
            return EOF;
            return EOF;
          if (c == '\n')
          if (c == '\n')
            {
            {
            source_lineno++;
            source_lineno++;
            lineno++;
            lineno++;
            goto retry;
            goto retry;
            }
            }
        }
        }
    }
    }
  if (c == EOF)
  if (c == EOF)
    return EOF;
    return EOF;
  if (ISDIGIT (c))
  if (ISDIGIT (c))
    {
    {
      do
      do
        {
        {
          SSTRING_PUT (s, c);
          SSTRING_PUT (s, c);
          c = getc (fp);
          c = getc (fp);
        } while (c != EOF && ISDIGIT (c));
        } while (c != EOF && ISDIGIT (c));
      ungetc (c, fp);
      ungetc (c, fp);
      c = INT_TOKEN;
      c = INT_TOKEN;
      goto done;
      goto done;
    }
    }
  if (ISIDST (c))
  if (ISIDST (c))
    {
    {
      c = scan_ident (fp, s, c);
      c = scan_ident (fp, s, c);
      ungetc (c, fp);
      ungetc (c, fp);
      return IDENTIFIER_TOKEN;
      return IDENTIFIER_TOKEN;
    }
    }
  if (c == '\'' || c == '"')
  if (c == '\'' || c == '"')
    {
    {
      c = scan_string (fp, s, c);
      c = scan_string (fp, s, c);
      ungetc (c, fp);
      ungetc (c, fp);
      return c == '\'' ? CHAR_TOKEN : STRING_TOKEN;
      return c == '\'' ? CHAR_TOKEN : STRING_TOKEN;
    }
    }
  SSTRING_PUT (s, c);
  SSTRING_PUT (s, c);
 done:
 done:
  MAKE_SSTRING_SPACE (s, 1);
  MAKE_SSTRING_SPACE (s, 1);
  *s->ptr = 0;
  *s->ptr = 0;
  return c;
  return c;
}
}
 
 
unsigned int
unsigned int
hashstr (const char *str, unsigned int len)
hashstr (const char *str, unsigned int len)
{
{
  unsigned int n = len;
  unsigned int n = len;
  unsigned int r = 0;
  unsigned int r = 0;
  const unsigned char *s = (const unsigned char *) str;
  const unsigned char *s = (const unsigned char *) str;
 
 
  do
  do
    r = r * 67 + (*s++ - 113);
    r = r * 67 + (*s++ - 113);
  while (--n);
  while (--n);
  return r + len;
  return r + len;
}
}
 
 

powered by: WebSVN 2.1.0

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