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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [scm-exp.c] - Diff between revs 105 and 1765

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

Rev 105 Rev 1765
/* Scheme/Guile language support routines for GDB, the GNU debugger.
/* Scheme/Guile language support routines for GDB, the GNU debugger.
   Copyright 1995 Free Software Foundation, Inc.
   Copyright 1995 Free Software Foundation, Inc.
 
 
   This file is part of GDB.
   This file is part of GDB.
 
 
   This program is free software; you can redistribute it and/or modify
   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
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   (at your option) any 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; if not, write to the Free Software
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330,
   Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */
   Boston, MA 02111-1307, USA.  */
 
 
#include "defs.h"
#include "defs.h"
#include "symtab.h"
#include "symtab.h"
#include "gdbtypes.h"
#include "gdbtypes.h"
#include "expression.h"
#include "expression.h"
#include "parser-defs.h"
#include "parser-defs.h"
#include "language.h"
#include "language.h"
#include "value.h"
#include "value.h"
#include "c-lang.h"
#include "c-lang.h"
#include "scm-lang.h"
#include "scm-lang.h"
#include "scm-tags.h"
#include "scm-tags.h"
 
 
#define USE_EXPRSTRING 0
#define USE_EXPRSTRING 0
 
 
static void scm_lreadparen PARAMS ((int));
static void scm_lreadparen PARAMS ((int));
static int scm_skip_ws PARAMS ((void));
static int scm_skip_ws PARAMS ((void));
static void scm_read_token PARAMS ((int, int));
static void scm_read_token PARAMS ((int, int));
static LONGEST scm_istring2number PARAMS ((char *, int, int));
static LONGEST scm_istring2number PARAMS ((char *, int, int));
static LONGEST scm_istr2int PARAMS ((char *, int, int));
static LONGEST scm_istr2int PARAMS ((char *, int, int));
static void scm_lreadr PARAMS ((int));
static void scm_lreadr PARAMS ((int));
 
 
static LONGEST
static LONGEST
scm_istr2int (str, len, radix)
scm_istr2int (str, len, radix)
     char *str;
     char *str;
     int len;
     int len;
     int radix;
     int radix;
{
{
  int i = 0;
  int i = 0;
  LONGEST inum = 0;
  LONGEST inum = 0;
  int c;
  int c;
  int sign = 0;
  int sign = 0;
 
 
  if (0 >= len)
  if (0 >= len)
    return SCM_BOOL_F;          /* zero scm_length */
    return SCM_BOOL_F;          /* zero scm_length */
  switch (str[0])
  switch (str[0])
    {                           /* leading sign */
    {                           /* leading sign */
    case '-':
    case '-':
    case '+':
    case '+':
      sign = str[0];
      sign = str[0];
      if (++i == len)
      if (++i == len)
        return SCM_BOOL_F;      /* bad if lone `+' or `-' */
        return SCM_BOOL_F;      /* bad if lone `+' or `-' */
    }
    }
  do
  do
    {
    {
      switch (c = str[i++])
      switch (c = str[i++])
        {
        {
        case '0':
        case '0':
        case '1':
        case '1':
        case '2':
        case '2':
        case '3':
        case '3':
        case '4':
        case '4':
        case '5':
        case '5':
        case '6':
        case '6':
        case '7':
        case '7':
        case '8':
        case '8':
        case '9':
        case '9':
          c = c - '0';
          c = c - '0';
          goto accumulate;
          goto accumulate;
        case 'A':
        case 'A':
        case 'B':
        case 'B':
        case 'C':
        case 'C':
        case 'D':
        case 'D':
        case 'E':
        case 'E':
        case 'F':
        case 'F':
          c = c - 'A' + 10;
          c = c - 'A' + 10;
          goto accumulate;
          goto accumulate;
        case 'a':
        case 'a':
        case 'b':
        case 'b':
        case 'c':
        case 'c':
        case 'd':
        case 'd':
        case 'e':
        case 'e':
        case 'f':
        case 'f':
          c = c - 'a' + 10;
          c = c - 'a' + 10;
        accumulate:
        accumulate:
          if (c >= radix)
          if (c >= radix)
            return SCM_BOOL_F;  /* bad digit for radix */
            return SCM_BOOL_F;  /* bad digit for radix */
          inum *= radix;
          inum *= radix;
          inum += c;
          inum += c;
          break;
          break;
        default:
        default:
          return SCM_BOOL_F;    /* not a digit */
          return SCM_BOOL_F;    /* not a digit */
        }
        }
    }
    }
  while (i < len);
  while (i < len);
  if (sign == '-')
  if (sign == '-')
    inum = -inum;
    inum = -inum;
  return SCM_MAKINUM (inum);
  return SCM_MAKINUM (inum);
}
}
 
 
static LONGEST
static LONGEST
scm_istring2number (str, len, radix)
scm_istring2number (str, len, radix)
     char *str;
     char *str;
     int len;
     int len;
     int radix;
     int radix;
{
{
  int i = 0;
  int i = 0;
  char ex = 0;
  char ex = 0;
  char ex_p = 0, rx_p = 0;        /* Only allow 1 exactness and 1 radix prefix */
  char ex_p = 0, rx_p = 0;        /* Only allow 1 exactness and 1 radix prefix */
#if 0
#if 0
  SCM res;
  SCM res;
#endif
#endif
  if (len == 1)
  if (len == 1)
    if (*str == '+' || *str == '-')     /* Catches lone `+' and `-' for speed */
    if (*str == '+' || *str == '-')     /* Catches lone `+' and `-' for speed */
      return SCM_BOOL_F;
      return SCM_BOOL_F;
 
 
  while ((len - i) >= 2 && str[i] == '#' && ++i)
  while ((len - i) >= 2 && str[i] == '#' && ++i)
    switch (str[i++])
    switch (str[i++])
      {
      {
      case 'b':
      case 'b':
      case 'B':
      case 'B':
        if (rx_p++)
        if (rx_p++)
          return SCM_BOOL_F;
          return SCM_BOOL_F;
        radix = 2;
        radix = 2;
        break;
        break;
      case 'o':
      case 'o':
      case 'O':
      case 'O':
        if (rx_p++)
        if (rx_p++)
          return SCM_BOOL_F;
          return SCM_BOOL_F;
        radix = 8;
        radix = 8;
        break;
        break;
      case 'd':
      case 'd':
      case 'D':
      case 'D':
        if (rx_p++)
        if (rx_p++)
          return SCM_BOOL_F;
          return SCM_BOOL_F;
        radix = 10;
        radix = 10;
        break;
        break;
      case 'x':
      case 'x':
      case 'X':
      case 'X':
        if (rx_p++)
        if (rx_p++)
          return SCM_BOOL_F;
          return SCM_BOOL_F;
        radix = 16;
        radix = 16;
        break;
        break;
      case 'i':
      case 'i':
      case 'I':
      case 'I':
        if (ex_p++)
        if (ex_p++)
          return SCM_BOOL_F;
          return SCM_BOOL_F;
        ex = 2;
        ex = 2;
        break;
        break;
      case 'e':
      case 'e':
      case 'E':
      case 'E':
        if (ex_p++)
        if (ex_p++)
          return SCM_BOOL_F;
          return SCM_BOOL_F;
        ex = 1;
        ex = 1;
        break;
        break;
      default:
      default:
        return SCM_BOOL_F;
        return SCM_BOOL_F;
      }
      }
 
 
  switch (ex)
  switch (ex)
    {
    {
    case 1:
    case 1:
      return scm_istr2int (&str[i], len - i, radix);
      return scm_istr2int (&str[i], len - i, radix);
    case 0:
    case 0:
      return scm_istr2int (&str[i], len - i, radix);
      return scm_istr2int (&str[i], len - i, radix);
#if 0
#if 0
      if NFALSEP
      if NFALSEP
        (res) return res;
        (res) return res;
#ifdef FLOATS
#ifdef FLOATS
    case 2:
    case 2:
      return scm_istr2flo (&str[i], len - i, radix);
      return scm_istr2flo (&str[i], len - i, radix);
#endif
#endif
#endif
#endif
    }
    }
  return SCM_BOOL_F;
  return SCM_BOOL_F;
}
}
 
 
static void
static void
scm_read_token (c, weird)
scm_read_token (c, weird)
     int c;
     int c;
     int weird;
     int weird;
{
{
  while (1)
  while (1)
    {
    {
      c = *lexptr++;
      c = *lexptr++;
      switch (c)
      switch (c)
        {
        {
        case '[':
        case '[':
        case ']':
        case ']':
        case '(':
        case '(':
        case ')':
        case ')':
        case '\"':
        case '\"':
        case ';':
        case ';':
        case ' ':
        case ' ':
        case '\t':
        case '\t':
        case '\r':
        case '\r':
        case '\f':
        case '\f':
        case '\n':
        case '\n':
          if (weird)
          if (weird)
            goto default_case;
            goto default_case;
        case '\0':              /* End of line */
        case '\0':              /* End of line */
        eof_case:
        eof_case:
          --lexptr;
          --lexptr;
          return;
          return;
        case '\\':
        case '\\':
          if (!weird)
          if (!weird)
            goto default_case;
            goto default_case;
          else
          else
            {
            {
              c = *lexptr++;
              c = *lexptr++;
              if (c == '\0')
              if (c == '\0')
                goto eof_case;
                goto eof_case;
              else
              else
                goto default_case;
                goto default_case;
            }
            }
        case '}':
        case '}':
          if (!weird)
          if (!weird)
            goto default_case;
            goto default_case;
 
 
          c = *lexptr++;
          c = *lexptr++;
          if (c == '#')
          if (c == '#')
            return;
            return;
          else
          else
            {
            {
              --lexptr;
              --lexptr;
              c = '}';
              c = '}';
              goto default_case;
              goto default_case;
            }
            }
 
 
        default:
        default:
        default_case:
        default_case:
          ;
          ;
        }
        }
    }
    }
}
}
 
 
static int
static int
scm_skip_ws ()
scm_skip_ws ()
{
{
  register int c;
  register int c;
  while (1)
  while (1)
    switch ((c = *lexptr++))
    switch ((c = *lexptr++))
      {
      {
      case '\0':
      case '\0':
      goteof:
      goteof:
        return c;
        return c;
      case ';':
      case ';':
      lp:
      lp:
        switch ((c = *lexptr++))
        switch ((c = *lexptr++))
          {
          {
          case '\0':
          case '\0':
            goto goteof;
            goto goteof;
          default:
          default:
            goto lp;
            goto lp;
          case '\n':
          case '\n':
            break;
            break;
          }
          }
      case ' ':
      case ' ':
      case '\t':
      case '\t':
      case '\r':
      case '\r':
      case '\f':
      case '\f':
      case '\n':
      case '\n':
        break;
        break;
      default:
      default:
        return c;
        return c;
      }
      }
}
}
 
 
static void
static void
scm_lreadparen (skipping)
scm_lreadparen (skipping)
     int skipping;
     int skipping;
{
{
  for (;;)
  for (;;)
    {
    {
      int c = scm_skip_ws ();
      int c = scm_skip_ws ();
      if (')' == c || ']' == c)
      if (')' == c || ']' == c)
        return;
        return;
      --lexptr;
      --lexptr;
      if (c == '\0')
      if (c == '\0')
        error ("missing close paren");
        error ("missing close paren");
      scm_lreadr (skipping);
      scm_lreadr (skipping);
    }
    }
}
}
 
 
static void
static void
scm_lreadr (skipping)
scm_lreadr (skipping)
     int skipping;
     int skipping;
{
{
  int c, j;
  int c, j;
  struct stoken str;
  struct stoken str;
  LONGEST svalue = 0;
  LONGEST svalue = 0;
tryagain:
tryagain:
  c = *lexptr++;
  c = *lexptr++;
  switch (c)
  switch (c)
    {
    {
    case '\0':
    case '\0':
      lexptr--;
      lexptr--;
      return;
      return;
    case '[':
    case '[':
    case '(':
    case '(':
      scm_lreadparen (skipping);
      scm_lreadparen (skipping);
      return;
      return;
    case ']':
    case ']':
    case ')':
    case ')':
      error ("unexpected #\\%c", c);
      error ("unexpected #\\%c", c);
      goto tryagain;
      goto tryagain;
    case '\'':
    case '\'':
    case '`':
    case '`':
      str.ptr = lexptr - 1;
      str.ptr = lexptr - 1;
      scm_lreadr (skipping);
      scm_lreadr (skipping);
      if (!skipping)
      if (!skipping)
        {
        {
          value_ptr val = scm_evaluate_string (str.ptr, lexptr - str.ptr);
          value_ptr val = scm_evaluate_string (str.ptr, lexptr - str.ptr);
          if (!is_scmvalue_type (VALUE_TYPE (val)))
          if (!is_scmvalue_type (VALUE_TYPE (val)))
            error ("quoted scm form yields non-SCM value");
            error ("quoted scm form yields non-SCM value");
          svalue = extract_signed_integer (VALUE_CONTENTS (val),
          svalue = extract_signed_integer (VALUE_CONTENTS (val),
                                           TYPE_LENGTH (VALUE_TYPE (val)));
                                           TYPE_LENGTH (VALUE_TYPE (val)));
          goto handle_immediate;
          goto handle_immediate;
        }
        }
      return;
      return;
    case ',':
    case ',':
      c = *lexptr++;
      c = *lexptr++;
      if ('@' != c)
      if ('@' != c)
        lexptr--;
        lexptr--;
      scm_lreadr (skipping);
      scm_lreadr (skipping);
      return;
      return;
    case '#':
    case '#':
      c = *lexptr++;
      c = *lexptr++;
      switch (c)
      switch (c)
        {
        {
        case '[':
        case '[':
        case '(':
        case '(':
          scm_lreadparen (skipping);
          scm_lreadparen (skipping);
          return;
          return;
        case 't':
        case 't':
        case 'T':
        case 'T':
          svalue = SCM_BOOL_T;
          svalue = SCM_BOOL_T;
          goto handle_immediate;
          goto handle_immediate;
        case 'f':
        case 'f':
        case 'F':
        case 'F':
          svalue = SCM_BOOL_F;
          svalue = SCM_BOOL_F;
          goto handle_immediate;
          goto handle_immediate;
        case 'b':
        case 'b':
        case 'B':
        case 'B':
        case 'o':
        case 'o':
        case 'O':
        case 'O':
        case 'd':
        case 'd':
        case 'D':
        case 'D':
        case 'x':
        case 'x':
        case 'X':
        case 'X':
        case 'i':
        case 'i':
        case 'I':
        case 'I':
        case 'e':
        case 'e':
        case 'E':
        case 'E':
          lexptr--;
          lexptr--;
          c = '#';
          c = '#';
          goto num;
          goto num;
        case '*':               /* bitvector */
        case '*':               /* bitvector */
          scm_read_token (c, 0);
          scm_read_token (c, 0);
          return;
          return;
        case '{':
        case '{':
          scm_read_token (c, 1);
          scm_read_token (c, 1);
          return;
          return;
        case '\\':              /* character */
        case '\\':              /* character */
          c = *lexptr++;
          c = *lexptr++;
          scm_read_token (c, 0);
          scm_read_token (c, 0);
          return;
          return;
        case '|':
        case '|':
          j = 1;                /* here j is the comment nesting depth */
          j = 1;                /* here j is the comment nesting depth */
        lp:
        lp:
          c = *lexptr++;
          c = *lexptr++;
        lpc:
        lpc:
          switch (c)
          switch (c)
            {
            {
            case '\0':
            case '\0':
              error ("unbalanced comment");
              error ("unbalanced comment");
            default:
            default:
              goto lp;
              goto lp;
            case '|':
            case '|':
              if ('#' != (c = *lexptr++))
              if ('#' != (c = *lexptr++))
                goto lpc;
                goto lpc;
              if (--j)
              if (--j)
                goto lp;
                goto lp;
              break;
              break;
            case '#':
            case '#':
              if ('|' != (c = *lexptr++))
              if ('|' != (c = *lexptr++))
                goto lpc;
                goto lpc;
              ++j;
              ++j;
              goto lp;
              goto lp;
            }
            }
          goto tryagain;
          goto tryagain;
        case '.':
        case '.':
        default:
        default:
#if 0
#if 0
        callshrp:
        callshrp:
#endif
#endif
          scm_lreadr (skipping);
          scm_lreadr (skipping);
          return;
          return;
        }
        }
    case '\"':
    case '\"':
      while ('\"' != (c = *lexptr++))
      while ('\"' != (c = *lexptr++))
        {
        {
          if (c == '\\')
          if (c == '\\')
            switch (c = *lexptr++)
            switch (c = *lexptr++)
              {
              {
              case '\0':
              case '\0':
                error ("non-terminated string literal");
                error ("non-terminated string literal");
              case '\n':
              case '\n':
                continue;
                continue;
              case '0':
              case '0':
              case 'f':
              case 'f':
              case 'n':
              case 'n':
              case 'r':
              case 'r':
              case 't':
              case 't':
              case 'a':
              case 'a':
              case 'v':
              case 'v':
                break;
                break;
              }
              }
        }
        }
      return;
      return;
    case '0':
    case '0':
    case '1':
    case '1':
    case '2':
    case '2':
    case '3':
    case '3':
    case '4':
    case '4':
    case '5':
    case '5':
    case '6':
    case '6':
    case '7':
    case '7':
    case '8':
    case '8':
    case '9':
    case '9':
    case '.':
    case '.':
    case '-':
    case '-':
    case '+':
    case '+':
    num:
    num:
      {
      {
        str.ptr = lexptr - 1;
        str.ptr = lexptr - 1;
        scm_read_token (c, 0);
        scm_read_token (c, 0);
        if (!skipping)
        if (!skipping)
          {
          {
            svalue = scm_istring2number (str.ptr, lexptr - str.ptr, 10);
            svalue = scm_istring2number (str.ptr, lexptr - str.ptr, 10);
            if (svalue != SCM_BOOL_F)
            if (svalue != SCM_BOOL_F)
              goto handle_immediate;
              goto handle_immediate;
            goto tok;
            goto tok;
          }
          }
      }
      }
      return;
      return;
    case ':':
    case ':':
      scm_read_token ('-', 0);
      scm_read_token ('-', 0);
      return;
      return;
#if 0
#if 0
    do_symbol:
    do_symbol:
#endif
#endif
    default:
    default:
      str.ptr = lexptr - 1;
      str.ptr = lexptr - 1;
      scm_read_token (c, 0);
      scm_read_token (c, 0);
    tok:
    tok:
      if (!skipping)
      if (!skipping)
        {
        {
          str.length = lexptr - str.ptr;
          str.length = lexptr - str.ptr;
          if (str.ptr[0] == '$')
          if (str.ptr[0] == '$')
            {
            {
              write_dollar_variable (str);
              write_dollar_variable (str);
              return;
              return;
            }
            }
          write_exp_elt_opcode (OP_NAME);
          write_exp_elt_opcode (OP_NAME);
          write_exp_string (str);
          write_exp_string (str);
          write_exp_elt_opcode (OP_NAME);
          write_exp_elt_opcode (OP_NAME);
        }
        }
      return;
      return;
    }
    }
handle_immediate:
handle_immediate:
  if (!skipping)
  if (!skipping)
    {
    {
      write_exp_elt_opcode (OP_LONG);
      write_exp_elt_opcode (OP_LONG);
      write_exp_elt_type (builtin_type_scm);
      write_exp_elt_type (builtin_type_scm);
      write_exp_elt_longcst (svalue);
      write_exp_elt_longcst (svalue);
      write_exp_elt_opcode (OP_LONG);
      write_exp_elt_opcode (OP_LONG);
    }
    }
}
}
 
 
int
int
scm_parse ()
scm_parse ()
{
{
  char *start;
  char *start;
  while (*lexptr == ' ')
  while (*lexptr == ' ')
    lexptr++;
    lexptr++;
  start = lexptr;
  start = lexptr;
  scm_lreadr (USE_EXPRSTRING);
  scm_lreadr (USE_EXPRSTRING);
#if USE_EXPRSTRING
#if USE_EXPRSTRING
  str.length = lexptr - start;
  str.length = lexptr - start;
  str.ptr = start;
  str.ptr = start;
  write_exp_elt_opcode (OP_EXPRSTRING);
  write_exp_elt_opcode (OP_EXPRSTRING);
  write_exp_string (str);
  write_exp_string (str);
  write_exp_elt_opcode (OP_EXPRSTRING);
  write_exp_elt_opcode (OP_EXPRSTRING);
#endif
#endif
  return 0;
  return 0;
}
}
 
 

powered by: WebSVN 2.1.0

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