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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [intl/] [eval-plural.h] - Diff between revs 154 and 816

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

Rev 154 Rev 816
/* Plural expression evaluation.
/* Plural expression evaluation.
   Copyright (C) 2000-2002 Free Software Foundation, Inc.
   Copyright (C) 2000-2002 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 Library General Public License as published
   under the terms of the GNU Library General Public License as published
   by the Free Software Foundation; either version 2, or (at your option)
   by the Free Software Foundation; either version 2, or (at your option)
   any later version.
   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 GNU
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.
   Library General Public License for more details.
 
 
   You should have received a copy of the GNU Library General Public
   You should have received a copy of the GNU Library General Public
   License along with this program; if not, write to the Free Software
   License along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
   USA.  */
   USA.  */
 
 
#ifndef STATIC
#ifndef STATIC
#define STATIC static
#define STATIC static
#endif
#endif
 
 
/* Evaluate the plural expression and return an index value.  */
/* Evaluate the plural expression and return an index value.  */
STATIC unsigned long int plural_eval PARAMS ((struct expression *pexp,
STATIC unsigned long int plural_eval PARAMS ((struct expression *pexp,
                                              unsigned long int n))
                                              unsigned long int n))
     internal_function;
     internal_function;
 
 
STATIC
STATIC
unsigned long int
unsigned long int
internal_function
internal_function
plural_eval (pexp, n)
plural_eval (pexp, n)
     struct expression *pexp;
     struct expression *pexp;
     unsigned long int n;
     unsigned long int n;
{
{
  switch (pexp->nargs)
  switch (pexp->nargs)
    {
    {
    case 0:
    case 0:
      switch (pexp->operation)
      switch (pexp->operation)
        {
        {
        case var:
        case var:
          return n;
          return n;
        case num:
        case num:
          return pexp->val.num;
          return pexp->val.num;
        default:
        default:
          break;
          break;
        }
        }
      /* NOTREACHED */
      /* NOTREACHED */
      break;
      break;
    case 1:
    case 1:
      {
      {
        /* pexp->operation must be lnot.  */
        /* pexp->operation must be lnot.  */
        unsigned long int arg = plural_eval (pexp->val.args[0], n);
        unsigned long int arg = plural_eval (pexp->val.args[0], n);
        return ! arg;
        return ! arg;
      }
      }
    case 2:
    case 2:
      {
      {
        unsigned long int leftarg = plural_eval (pexp->val.args[0], n);
        unsigned long int leftarg = plural_eval (pexp->val.args[0], n);
        if (pexp->operation == lor)
        if (pexp->operation == lor)
          return leftarg || plural_eval (pexp->val.args[1], n);
          return leftarg || plural_eval (pexp->val.args[1], n);
        else if (pexp->operation == land)
        else if (pexp->operation == land)
          return leftarg && plural_eval (pexp->val.args[1], n);
          return leftarg && plural_eval (pexp->val.args[1], n);
        else
        else
          {
          {
            unsigned long int rightarg = plural_eval (pexp->val.args[1], n);
            unsigned long int rightarg = plural_eval (pexp->val.args[1], n);
 
 
            switch (pexp->operation)
            switch (pexp->operation)
              {
              {
              case mult:
              case mult:
                return leftarg * rightarg;
                return leftarg * rightarg;
              case divide:
              case divide:
#if !INTDIV0_RAISES_SIGFPE
#if !INTDIV0_RAISES_SIGFPE
                if (rightarg == 0)
                if (rightarg == 0)
                  raise (SIGFPE);
                  raise (SIGFPE);
#endif
#endif
                return leftarg / rightarg;
                return leftarg / rightarg;
              case module:
              case module:
#if !INTDIV0_RAISES_SIGFPE
#if !INTDIV0_RAISES_SIGFPE
                if (rightarg == 0)
                if (rightarg == 0)
                  raise (SIGFPE);
                  raise (SIGFPE);
#endif
#endif
                return leftarg % rightarg;
                return leftarg % rightarg;
              case plus:
              case plus:
                return leftarg + rightarg;
                return leftarg + rightarg;
              case minus:
              case minus:
                return leftarg - rightarg;
                return leftarg - rightarg;
              case less_than:
              case less_than:
                return leftarg < rightarg;
                return leftarg < rightarg;
              case greater_than:
              case greater_than:
                return leftarg > rightarg;
                return leftarg > rightarg;
              case less_or_equal:
              case less_or_equal:
                return leftarg <= rightarg;
                return leftarg <= rightarg;
              case greater_or_equal:
              case greater_or_equal:
                return leftarg >= rightarg;
                return leftarg >= rightarg;
              case equal:
              case equal:
                return leftarg == rightarg;
                return leftarg == rightarg;
              case not_equal:
              case not_equal:
                return leftarg != rightarg;
                return leftarg != rightarg;
              default:
              default:
                break;
                break;
              }
              }
          }
          }
        /* NOTREACHED */
        /* NOTREACHED */
        break;
        break;
      }
      }
    case 3:
    case 3:
      {
      {
        /* pexp->operation must be qmop.  */
        /* pexp->operation must be qmop.  */
        unsigned long int boolarg = plural_eval (pexp->val.args[0], n);
        unsigned long int boolarg = plural_eval (pexp->val.args[0], n);
        return plural_eval (pexp->val.args[boolarg ? 1 : 2], n);
        return plural_eval (pexp->val.args[boolarg ? 1 : 2], n);
      }
      }
    }
    }
  /* NOTREACHED */
  /* NOTREACHED */
  return 0;
  return 0;
}
}
 
 

powered by: WebSVN 2.1.0

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