OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc1/] [gcc/] [cp/] [tree.c] - Diff between revs 283 and 338

Only display areas with differences | Details | Blame | View Log

Rev 283 Rev 338
/* Language-dependent node constructors for parse phase of GNU compiler.
/* Language-dependent node constructors for parse phase of GNU compiler.
   Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
   Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
   Free Software Foundation, Inc.
   Free Software Foundation, Inc.
   Hacked by Michael Tiemann (tiemann@cygnus.com)
   Hacked by Michael Tiemann (tiemann@cygnus.com)
 
 
This file is part of GCC.
This file is part of GCC.
 
 
GCC is free software; you can redistribute it and/or modify
GCC 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 3, or (at your option)
the Free Software Foundation; either version 3, or (at your option)
any later version.
any later version.
 
 
GCC is distributed in the hope that it will be useful,
GCC 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 GCC; see the file COPYING3.  If not see
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */
<http://www.gnu.org/licenses/>.  */
 
 
#include "config.h"
#include "config.h"
#include "system.h"
#include "system.h"
#include "coretypes.h"
#include "coretypes.h"
#include "tm.h"
#include "tm.h"
#include "tree.h"
#include "tree.h"
#include "cp-tree.h"
#include "cp-tree.h"
#include "flags.h"
#include "flags.h"
#include "real.h"
#include "real.h"
#include "rtl.h"
#include "rtl.h"
#include "toplev.h"
#include "toplev.h"
#include "insn-config.h"
#include "insn-config.h"
#include "integrate.h"
#include "integrate.h"
#include "tree-inline.h"
#include "tree-inline.h"
#include "debug.h"
#include "debug.h"
#include "target.h"
#include "target.h"
#include "convert.h"
#include "convert.h"
#include "tree-flow.h"
#include "tree-flow.h"
#include "cgraph.h"
#include "cgraph.h"
 
 
static tree bot_manip (tree *, int *, void *);
static tree bot_manip (tree *, int *, void *);
static tree bot_replace (tree *, int *, void *);
static tree bot_replace (tree *, int *, void *);
static int list_hash_eq (const void *, const void *);
static int list_hash_eq (const void *, const void *);
static hashval_t list_hash_pieces (tree, tree, tree);
static hashval_t list_hash_pieces (tree, tree, tree);
static hashval_t list_hash (const void *);
static hashval_t list_hash (const void *);
static cp_lvalue_kind lvalue_p_1 (const_tree);
static cp_lvalue_kind lvalue_p_1 (const_tree);
static tree build_target_expr (tree, tree);
static tree build_target_expr (tree, tree);
static tree count_trees_r (tree *, int *, void *);
static tree count_trees_r (tree *, int *, void *);
static tree verify_stmt_tree_r (tree *, int *, void *);
static tree verify_stmt_tree_r (tree *, int *, void *);
static tree build_local_temp (tree);
static tree build_local_temp (tree);
 
 
static tree handle_java_interface_attribute (tree *, tree, tree, int, bool *);
static tree handle_java_interface_attribute (tree *, tree, tree, int, bool *);
static tree handle_com_interface_attribute (tree *, tree, tree, int, bool *);
static tree handle_com_interface_attribute (tree *, tree, tree, int, bool *);
static tree handle_init_priority_attribute (tree *, tree, tree, int, bool *);
static tree handle_init_priority_attribute (tree *, tree, tree, int, bool *);
 
 
/* If REF is an lvalue, returns the kind of lvalue that REF is.
/* If REF is an lvalue, returns the kind of lvalue that REF is.
   Otherwise, returns clk_none.  */
   Otherwise, returns clk_none.  */
 
 
static cp_lvalue_kind
static cp_lvalue_kind
lvalue_p_1 (const_tree ref)
lvalue_p_1 (const_tree ref)
{
{
  cp_lvalue_kind op1_lvalue_kind = clk_none;
  cp_lvalue_kind op1_lvalue_kind = clk_none;
  cp_lvalue_kind op2_lvalue_kind = clk_none;
  cp_lvalue_kind op2_lvalue_kind = clk_none;
 
 
  /* Expressions of reference type are sometimes wrapped in
  /* Expressions of reference type are sometimes wrapped in
     INDIRECT_REFs.  INDIRECT_REFs are just internal compiler
     INDIRECT_REFs.  INDIRECT_REFs are just internal compiler
     representation, not part of the language, so we have to look
     representation, not part of the language, so we have to look
     through them.  */
     through them.  */
  if (TREE_CODE (ref) == INDIRECT_REF
  if (TREE_CODE (ref) == INDIRECT_REF
      && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0)))
      && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0)))
          == REFERENCE_TYPE)
          == REFERENCE_TYPE)
    return lvalue_p_1 (TREE_OPERAND (ref, 0));
    return lvalue_p_1 (TREE_OPERAND (ref, 0));
 
 
  if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
  if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
    {
    {
      /* unnamed rvalue references are rvalues */
      /* unnamed rvalue references are rvalues */
      if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref))
      if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref))
          && TREE_CODE (ref) != PARM_DECL
          && TREE_CODE (ref) != PARM_DECL
          && TREE_CODE (ref) != VAR_DECL
          && TREE_CODE (ref) != VAR_DECL
          && TREE_CODE (ref) != COMPONENT_REF)
          && TREE_CODE (ref) != COMPONENT_REF)
        return clk_rvalueref;
        return clk_rvalueref;
 
 
      /* lvalue references and named rvalue references are lvalues.  */
      /* lvalue references and named rvalue references are lvalues.  */
      return clk_ordinary;
      return clk_ordinary;
    }
    }
 
 
  if (ref == current_class_ptr)
  if (ref == current_class_ptr)
    return clk_none;
    return clk_none;
 
 
  switch (TREE_CODE (ref))
  switch (TREE_CODE (ref))
    {
    {
    case SAVE_EXPR:
    case SAVE_EXPR:
      return clk_none;
      return clk_none;
      /* preincrements and predecrements are valid lvals, provided
      /* preincrements and predecrements are valid lvals, provided
         what they refer to are valid lvals.  */
         what they refer to are valid lvals.  */
    case PREINCREMENT_EXPR:
    case PREINCREMENT_EXPR:
    case PREDECREMENT_EXPR:
    case PREDECREMENT_EXPR:
    case TRY_CATCH_EXPR:
    case TRY_CATCH_EXPR:
    case WITH_CLEANUP_EXPR:
    case WITH_CLEANUP_EXPR:
    case REALPART_EXPR:
    case REALPART_EXPR:
    case IMAGPART_EXPR:
    case IMAGPART_EXPR:
      return lvalue_p_1 (TREE_OPERAND (ref, 0));
      return lvalue_p_1 (TREE_OPERAND (ref, 0));
 
 
    case COMPONENT_REF:
    case COMPONENT_REF:
      op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0));
      op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0));
      /* Look at the member designator.  */
      /* Look at the member designator.  */
      if (!op1_lvalue_kind)
      if (!op1_lvalue_kind)
        ;
        ;
      else if (is_overloaded_fn (TREE_OPERAND (ref, 1)))
      else if (is_overloaded_fn (TREE_OPERAND (ref, 1)))
        /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
        /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
           situations.  If we're seeing a COMPONENT_REF, it's a non-static
           situations.  If we're seeing a COMPONENT_REF, it's a non-static
           member, so it isn't an lvalue. */
           member, so it isn't an lvalue. */
        op1_lvalue_kind = clk_none;
        op1_lvalue_kind = clk_none;
      else if (TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL)
      else if (TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL)
        /* This can be IDENTIFIER_NODE in a template.  */;
        /* This can be IDENTIFIER_NODE in a template.  */;
      else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1)))
      else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1)))
        {
        {
          /* Clear the ordinary bit.  If this object was a class
          /* Clear the ordinary bit.  If this object was a class
             rvalue we want to preserve that information.  */
             rvalue we want to preserve that information.  */
          op1_lvalue_kind &= ~clk_ordinary;
          op1_lvalue_kind &= ~clk_ordinary;
          /* The lvalue is for a bitfield.  */
          /* The lvalue is for a bitfield.  */
          op1_lvalue_kind |= clk_bitfield;
          op1_lvalue_kind |= clk_bitfield;
        }
        }
      else if (DECL_PACKED (TREE_OPERAND (ref, 1)))
      else if (DECL_PACKED (TREE_OPERAND (ref, 1)))
        op1_lvalue_kind |= clk_packed;
        op1_lvalue_kind |= clk_packed;
 
 
      return op1_lvalue_kind;
      return op1_lvalue_kind;
 
 
    case STRING_CST:
    case STRING_CST:
    case COMPOUND_LITERAL_EXPR:
    case COMPOUND_LITERAL_EXPR:
      return clk_ordinary;
      return clk_ordinary;
 
 
    case CONST_DECL:
    case CONST_DECL:
      /* CONST_DECL without TREE_STATIC are enumeration values and
      /* CONST_DECL without TREE_STATIC are enumeration values and
         thus not lvalues.  With TREE_STATIC they are used by ObjC++
         thus not lvalues.  With TREE_STATIC they are used by ObjC++
         in objc_build_string_object and need to be considered as
         in objc_build_string_object and need to be considered as
         lvalues.  */
         lvalues.  */
      if (! TREE_STATIC (ref))
      if (! TREE_STATIC (ref))
        return clk_none;
        return clk_none;
    case VAR_DECL:
    case VAR_DECL:
      if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
      if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
          && DECL_LANG_SPECIFIC (ref)
          && DECL_LANG_SPECIFIC (ref)
          && DECL_IN_AGGR_P (ref))
          && DECL_IN_AGGR_P (ref))
        return clk_none;
        return clk_none;
    case INDIRECT_REF:
    case INDIRECT_REF:
    case ARRAY_REF:
    case ARRAY_REF:
    case PARM_DECL:
    case PARM_DECL:
    case RESULT_DECL:
    case RESULT_DECL:
      if (TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
      if (TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
        return clk_ordinary;
        return clk_ordinary;
      break;
      break;
 
 
      /* A currently unresolved scope ref.  */
      /* A currently unresolved scope ref.  */
    case SCOPE_REF:
    case SCOPE_REF:
      gcc_unreachable ();
      gcc_unreachable ();
    case MAX_EXPR:
    case MAX_EXPR:
    case MIN_EXPR:
    case MIN_EXPR:
      /* Disallow <? and >? as lvalues if either argument side-effects.  */
      /* Disallow <? and >? as lvalues if either argument side-effects.  */
      if (TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 0))
      if (TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 0))
          || TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 1)))
          || TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 1)))
        return clk_none;
        return clk_none;
      op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0));
      op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 0));
      op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1));
      op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1));
      break;
      break;
 
 
    case COND_EXPR:
    case COND_EXPR:
      op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1)
      op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1)
                                    ? TREE_OPERAND (ref, 1)
                                    ? TREE_OPERAND (ref, 1)
                                    : TREE_OPERAND (ref, 0));
                                    : TREE_OPERAND (ref, 0));
      op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 2));
      op2_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 2));
      break;
      break;
 
 
    case MODIFY_EXPR:
    case MODIFY_EXPR:
      return clk_ordinary;
      return clk_ordinary;
 
 
    case COMPOUND_EXPR:
    case COMPOUND_EXPR:
      return lvalue_p_1 (TREE_OPERAND (ref, 1));
      return lvalue_p_1 (TREE_OPERAND (ref, 1));
 
 
    case TARGET_EXPR:
    case TARGET_EXPR:
      return clk_class;
      return clk_class;
 
 
    case VA_ARG_EXPR:
    case VA_ARG_EXPR:
      return (CLASS_TYPE_P (TREE_TYPE (ref)) ? clk_class : clk_none);
      return (CLASS_TYPE_P (TREE_TYPE (ref)) ? clk_class : clk_none);
 
 
    case CALL_EXPR:
    case CALL_EXPR:
      /* Any class-valued call would be wrapped in a TARGET_EXPR.  */
      /* Any class-valued call would be wrapped in a TARGET_EXPR.  */
      return clk_none;
      return clk_none;
 
 
    case FUNCTION_DECL:
    case FUNCTION_DECL:
      /* All functions (except non-static-member functions) are
      /* All functions (except non-static-member functions) are
         lvalues.  */
         lvalues.  */
      return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref)
      return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref)
              ? clk_none : clk_ordinary);
              ? clk_none : clk_ordinary);
 
 
    case BASELINK:
    case BASELINK:
      /* We now represent a reference to a single static member function
      /* We now represent a reference to a single static member function
         with a BASELINK.  */
         with a BASELINK.  */
      /* This CONST_CAST is okay because BASELINK_FUNCTIONS returns
      /* This CONST_CAST is okay because BASELINK_FUNCTIONS returns
         its argument unmodified and we assign it to a const_tree.  */
         its argument unmodified and we assign it to a const_tree.  */
      return lvalue_p_1 (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref)));
      return lvalue_p_1 (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref)));
 
 
    case NON_DEPENDENT_EXPR:
    case NON_DEPENDENT_EXPR:
      /* We must consider NON_DEPENDENT_EXPRs to be lvalues so that
      /* We must consider NON_DEPENDENT_EXPRs to be lvalues so that
         things like "&E" where "E" is an expression with a
         things like "&E" where "E" is an expression with a
         non-dependent type work. It is safe to be lenient because an
         non-dependent type work. It is safe to be lenient because an
         error will be issued when the template is instantiated if "E"
         error will be issued when the template is instantiated if "E"
         is not an lvalue.  */
         is not an lvalue.  */
      return clk_ordinary;
      return clk_ordinary;
 
 
    default:
    default:
      break;
      break;
    }
    }
 
 
  /* If one operand is not an lvalue at all, then this expression is
  /* If one operand is not an lvalue at all, then this expression is
     not an lvalue.  */
     not an lvalue.  */
  if (!op1_lvalue_kind || !op2_lvalue_kind)
  if (!op1_lvalue_kind || !op2_lvalue_kind)
    return clk_none;
    return clk_none;
 
 
  /* Otherwise, it's an lvalue, and it has all the odd properties
  /* Otherwise, it's an lvalue, and it has all the odd properties
     contributed by either operand.  */
     contributed by either operand.  */
  op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
  op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
  /* It's not an ordinary lvalue if it involves any other kind.  */
  /* It's not an ordinary lvalue if it involves any other kind.  */
  if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
  if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
    op1_lvalue_kind &= ~clk_ordinary;
    op1_lvalue_kind &= ~clk_ordinary;
  /* It can't be both a pseudo-lvalue and a non-addressable lvalue.
  /* It can't be both a pseudo-lvalue and a non-addressable lvalue.
     A COND_EXPR of those should be wrapped in a TARGET_EXPR.  */
     A COND_EXPR of those should be wrapped in a TARGET_EXPR.  */
  if ((op1_lvalue_kind & (clk_rvalueref|clk_class))
  if ((op1_lvalue_kind & (clk_rvalueref|clk_class))
      && (op1_lvalue_kind & (clk_bitfield|clk_packed)))
      && (op1_lvalue_kind & (clk_bitfield|clk_packed)))
    op1_lvalue_kind = clk_none;
    op1_lvalue_kind = clk_none;
  return op1_lvalue_kind;
  return op1_lvalue_kind;
}
}
 
 
/* Returns the kind of lvalue that REF is, in the sense of
/* Returns the kind of lvalue that REF is, in the sense of
   [basic.lval].  This function should really be named lvalue_p; it
   [basic.lval].  This function should really be named lvalue_p; it
   computes the C++ definition of lvalue.  */
   computes the C++ definition of lvalue.  */
 
 
cp_lvalue_kind
cp_lvalue_kind
real_lvalue_p (tree ref)
real_lvalue_p (tree ref)
{
{
  cp_lvalue_kind kind = lvalue_p_1 (ref);
  cp_lvalue_kind kind = lvalue_p_1 (ref);
  if (kind & (clk_rvalueref|clk_class))
  if (kind & (clk_rvalueref|clk_class))
    return clk_none;
    return clk_none;
  else
  else
    return kind;
    return kind;
}
}
 
 
/* This differs from real_lvalue_p in that class rvalues are considered
/* This differs from real_lvalue_p in that class rvalues are considered
   lvalues.  */
   lvalues.  */
 
 
bool
bool
lvalue_p (const_tree ref)
lvalue_p (const_tree ref)
{
{
  return (lvalue_p_1 (ref) != clk_none);
  return (lvalue_p_1 (ref) != clk_none);
}
}
 
 
/* This differs from real_lvalue_p in that rvalues formed by dereferencing
/* This differs from real_lvalue_p in that rvalues formed by dereferencing
   rvalue references are considered rvalues.  */
   rvalue references are considered rvalues.  */
 
 
bool
bool
lvalue_or_rvalue_with_address_p (const_tree ref)
lvalue_or_rvalue_with_address_p (const_tree ref)
{
{
  cp_lvalue_kind kind = lvalue_p_1 (ref);
  cp_lvalue_kind kind = lvalue_p_1 (ref);
  if (kind & clk_class)
  if (kind & clk_class)
    return false;
    return false;
  else
  else
    return (kind != clk_none);
    return (kind != clk_none);
}
}
 
 
/* Test whether DECL is a builtin that may appear in a
/* Test whether DECL is a builtin that may appear in a
   constant-expression. */
   constant-expression. */
 
 
bool
bool
builtin_valid_in_constant_expr_p (const_tree decl)
builtin_valid_in_constant_expr_p (const_tree decl)
{
{
  /* At present BUILT_IN_CONSTANT_P is the only builtin we're allowing
  /* At present BUILT_IN_CONSTANT_P is the only builtin we're allowing
     in constant-expressions.  We may want to add other builtins later. */
     in constant-expressions.  We may want to add other builtins later. */
  return DECL_IS_BUILTIN_CONSTANT_P (decl);
  return DECL_IS_BUILTIN_CONSTANT_P (decl);
}
}
 
 
/* Build a TARGET_EXPR, initializing the DECL with the VALUE.  */
/* Build a TARGET_EXPR, initializing the DECL with the VALUE.  */
 
 
static tree
static tree
build_target_expr (tree decl, tree value)
build_target_expr (tree decl, tree value)
{
{
  tree t;
  tree t;
 
 
#ifdef ENABLE_CHECKING
#ifdef ENABLE_CHECKING
  gcc_assert (VOID_TYPE_P (TREE_TYPE (value))
  gcc_assert (VOID_TYPE_P (TREE_TYPE (value))
              || TREE_TYPE (decl) == TREE_TYPE (value)
              || TREE_TYPE (decl) == TREE_TYPE (value)
              || useless_type_conversion_p (TREE_TYPE (decl),
              || useless_type_conversion_p (TREE_TYPE (decl),
                                            TREE_TYPE (value)));
                                            TREE_TYPE (value)));
#endif
#endif
 
 
  t = build4 (TARGET_EXPR, TREE_TYPE (decl), decl, value,
  t = build4 (TARGET_EXPR, TREE_TYPE (decl), decl, value,
              cxx_maybe_build_cleanup (decl), NULL_TREE);
              cxx_maybe_build_cleanup (decl), NULL_TREE);
  /* We always set TREE_SIDE_EFFECTS so that expand_expr does not
  /* We always set TREE_SIDE_EFFECTS so that expand_expr does not
     ignore the TARGET_EXPR.  If there really turn out to be no
     ignore the TARGET_EXPR.  If there really turn out to be no
     side-effects, then the optimizer should be able to get rid of
     side-effects, then the optimizer should be able to get rid of
     whatever code is generated anyhow.  */
     whatever code is generated anyhow.  */
  TREE_SIDE_EFFECTS (t) = 1;
  TREE_SIDE_EFFECTS (t) = 1;
 
 
  return t;
  return t;
}
}
 
 
/* Return an undeclared local temporary of type TYPE for use in building a
/* Return an undeclared local temporary of type TYPE for use in building a
   TARGET_EXPR.  */
   TARGET_EXPR.  */
 
 
static tree
static tree
build_local_temp (tree type)
build_local_temp (tree type)
{
{
  tree slot = build_decl (input_location,
  tree slot = build_decl (input_location,
                          VAR_DECL, NULL_TREE, type);
                          VAR_DECL, NULL_TREE, type);
  DECL_ARTIFICIAL (slot) = 1;
  DECL_ARTIFICIAL (slot) = 1;
  DECL_IGNORED_P (slot) = 1;
  DECL_IGNORED_P (slot) = 1;
  DECL_CONTEXT (slot) = current_function_decl;
  DECL_CONTEXT (slot) = current_function_decl;
  layout_decl (slot, 0);
  layout_decl (slot, 0);
  return slot;
  return slot;
}
}
 
 
/* Set various status flags when building an AGGR_INIT_EXPR object T.  */
/* Set various status flags when building an AGGR_INIT_EXPR object T.  */
 
 
static void
static void
process_aggr_init_operands (tree t)
process_aggr_init_operands (tree t)
{
{
  bool side_effects;
  bool side_effects;
 
 
  side_effects = TREE_SIDE_EFFECTS (t);
  side_effects = TREE_SIDE_EFFECTS (t);
  if (!side_effects)
  if (!side_effects)
    {
    {
      int i, n;
      int i, n;
      n = TREE_OPERAND_LENGTH (t);
      n = TREE_OPERAND_LENGTH (t);
      for (i = 1; i < n; i++)
      for (i = 1; i < n; i++)
        {
        {
          tree op = TREE_OPERAND (t, i);
          tree op = TREE_OPERAND (t, i);
          if (op && TREE_SIDE_EFFECTS (op))
          if (op && TREE_SIDE_EFFECTS (op))
            {
            {
              side_effects = 1;
              side_effects = 1;
              break;
              break;
            }
            }
        }
        }
    }
    }
  TREE_SIDE_EFFECTS (t) = side_effects;
  TREE_SIDE_EFFECTS (t) = side_effects;
}
}
 
 
/* Build an AGGR_INIT_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE,
/* Build an AGGR_INIT_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE,
   FN, and SLOT.  NARGS is the number of call arguments which are specified
   FN, and SLOT.  NARGS is the number of call arguments which are specified
   as a tree array ARGS.  */
   as a tree array ARGS.  */
 
 
static tree
static tree
build_aggr_init_array (tree return_type, tree fn, tree slot, int nargs,
build_aggr_init_array (tree return_type, tree fn, tree slot, int nargs,
                       tree *args)
                       tree *args)
{
{
  tree t;
  tree t;
  int i;
  int i;
 
 
  t = build_vl_exp (AGGR_INIT_EXPR, nargs + 3);
  t = build_vl_exp (AGGR_INIT_EXPR, nargs + 3);
  TREE_TYPE (t) = return_type;
  TREE_TYPE (t) = return_type;
  AGGR_INIT_EXPR_FN (t) = fn;
  AGGR_INIT_EXPR_FN (t) = fn;
  AGGR_INIT_EXPR_SLOT (t) = slot;
  AGGR_INIT_EXPR_SLOT (t) = slot;
  for (i = 0; i < nargs; i++)
  for (i = 0; i < nargs; i++)
    AGGR_INIT_EXPR_ARG (t, i) = args[i];
    AGGR_INIT_EXPR_ARG (t, i) = args[i];
  process_aggr_init_operands (t);
  process_aggr_init_operands (t);
  return t;
  return t;
}
}
 
 
/* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
/* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
   target.  TYPE is the type to be initialized.
   target.  TYPE is the type to be initialized.
 
 
   Build an AGGR_INIT_EXPR to represent the initialization.  This function
   Build an AGGR_INIT_EXPR to represent the initialization.  This function
   differs from build_cplus_new in that an AGGR_INIT_EXPR can only be used
   differs from build_cplus_new in that an AGGR_INIT_EXPR can only be used
   to initialize another object, whereas a TARGET_EXPR can either
   to initialize another object, whereas a TARGET_EXPR can either
   initialize another object or create its own temporary object, and as a
   initialize another object or create its own temporary object, and as a
   result building up a TARGET_EXPR requires that the type's destructor be
   result building up a TARGET_EXPR requires that the type's destructor be
   callable.  */
   callable.  */
 
 
tree
tree
build_aggr_init_expr (tree type, tree init)
build_aggr_init_expr (tree type, tree init)
{
{
  tree fn;
  tree fn;
  tree slot;
  tree slot;
  tree rval;
  tree rval;
  int is_ctor;
  int is_ctor;
 
 
  /* Make sure that we're not trying to create an instance of an
  /* Make sure that we're not trying to create an instance of an
     abstract class.  */
     abstract class.  */
  abstract_virtuals_error (NULL_TREE, type);
  abstract_virtuals_error (NULL_TREE, type);
 
 
  if (TREE_CODE (init) == CALL_EXPR)
  if (TREE_CODE (init) == CALL_EXPR)
    fn = CALL_EXPR_FN (init);
    fn = CALL_EXPR_FN (init);
  else if (TREE_CODE (init) == AGGR_INIT_EXPR)
  else if (TREE_CODE (init) == AGGR_INIT_EXPR)
    fn = AGGR_INIT_EXPR_FN (init);
    fn = AGGR_INIT_EXPR_FN (init);
  else
  else
    return convert (type, init);
    return convert (type, init);
 
 
  is_ctor = (TREE_CODE (fn) == ADDR_EXPR
  is_ctor = (TREE_CODE (fn) == ADDR_EXPR
             && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
             && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
             && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0)));
             && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0)));
 
 
  /* We split the CALL_EXPR into its function and its arguments here.
  /* We split the CALL_EXPR into its function and its arguments here.
     Then, in expand_expr, we put them back together.  The reason for
     Then, in expand_expr, we put them back together.  The reason for
     this is that this expression might be a default argument
     this is that this expression might be a default argument
     expression.  In that case, we need a new temporary every time the
     expression.  In that case, we need a new temporary every time the
     expression is used.  That's what break_out_target_exprs does; it
     expression is used.  That's what break_out_target_exprs does; it
     replaces every AGGR_INIT_EXPR with a copy that uses a fresh
     replaces every AGGR_INIT_EXPR with a copy that uses a fresh
     temporary slot.  Then, expand_expr builds up a call-expression
     temporary slot.  Then, expand_expr builds up a call-expression
     using the new slot.  */
     using the new slot.  */
 
 
  /* If we don't need to use a constructor to create an object of this
  /* If we don't need to use a constructor to create an object of this
     type, don't mess with AGGR_INIT_EXPR.  */
     type, don't mess with AGGR_INIT_EXPR.  */
  if (is_ctor || TREE_ADDRESSABLE (type))
  if (is_ctor || TREE_ADDRESSABLE (type))
    {
    {
      slot = build_local_temp (type);
      slot = build_local_temp (type);
 
 
      if (TREE_CODE(init) == CALL_EXPR)
      if (TREE_CODE(init) == CALL_EXPR)
        rval = build_aggr_init_array (void_type_node, fn, slot,
        rval = build_aggr_init_array (void_type_node, fn, slot,
                                      call_expr_nargs (init),
                                      call_expr_nargs (init),
                                      CALL_EXPR_ARGP (init));
                                      CALL_EXPR_ARGP (init));
      else
      else
        rval = build_aggr_init_array (void_type_node, fn, slot,
        rval = build_aggr_init_array (void_type_node, fn, slot,
                                      aggr_init_expr_nargs (init),
                                      aggr_init_expr_nargs (init),
                                      AGGR_INIT_EXPR_ARGP (init));
                                      AGGR_INIT_EXPR_ARGP (init));
      TREE_SIDE_EFFECTS (rval) = 1;
      TREE_SIDE_EFFECTS (rval) = 1;
      AGGR_INIT_VIA_CTOR_P (rval) = is_ctor;
      AGGR_INIT_VIA_CTOR_P (rval) = is_ctor;
    }
    }
  else
  else
    rval = init;
    rval = init;
 
 
  return rval;
  return rval;
}
}
 
 
/* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
/* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
   target.  TYPE is the type that this initialization should appear to
   target.  TYPE is the type that this initialization should appear to
   have.
   have.
 
 
   Build an encapsulation of the initialization to perform
   Build an encapsulation of the initialization to perform
   and return it so that it can be processed by language-independent
   and return it so that it can be processed by language-independent
   and language-specific expression expanders.  */
   and language-specific expression expanders.  */
 
 
tree
tree
build_cplus_new (tree type, tree init)
build_cplus_new (tree type, tree init)
{
{
  tree rval = build_aggr_init_expr (type, init);
  tree rval = build_aggr_init_expr (type, init);
  tree slot;
  tree slot;
 
 
  if (TREE_CODE (rval) == AGGR_INIT_EXPR)
  if (TREE_CODE (rval) == AGGR_INIT_EXPR)
    slot = AGGR_INIT_EXPR_SLOT (rval);
    slot = AGGR_INIT_EXPR_SLOT (rval);
  else if (TREE_CODE (rval) == CALL_EXPR)
  else if (TREE_CODE (rval) == CALL_EXPR)
    slot = build_local_temp (type);
    slot = build_local_temp (type);
  else
  else
    return rval;
    return rval;
 
 
  rval = build_target_expr (slot, rval);
  rval = build_target_expr (slot, rval);
  TARGET_EXPR_IMPLICIT_P (rval) = 1;
  TARGET_EXPR_IMPLICIT_P (rval) = 1;
 
 
  return rval;
  return rval;
}
}
 
 
/* Return a TARGET_EXPR which expresses the direct-initialization of one
/* Return a TARGET_EXPR which expresses the direct-initialization of one
   array from another.  */
   array from another.  */
 
 
tree
tree
build_array_copy (tree init)
build_array_copy (tree init)
{
{
  tree type = TREE_TYPE (init);
  tree type = TREE_TYPE (init);
  tree slot = build_local_temp (type);
  tree slot = build_local_temp (type);
  init = build2 (VEC_INIT_EXPR, type, slot, init);
  init = build2 (VEC_INIT_EXPR, type, slot, init);
  SET_EXPR_LOCATION (init, input_location);
  SET_EXPR_LOCATION (init, input_location);
  init = build_target_expr (slot, init);
  init = build_target_expr (slot, init);
  TARGET_EXPR_IMPLICIT_P (init) = 1;
  TARGET_EXPR_IMPLICIT_P (init) = 1;
 
 
  return init;
  return init;
}
}
 
 
/* Build a TARGET_EXPR using INIT to initialize a new temporary of the
/* Build a TARGET_EXPR using INIT to initialize a new temporary of the
   indicated TYPE.  */
   indicated TYPE.  */
 
 
tree
tree
build_target_expr_with_type (tree init, tree type)
build_target_expr_with_type (tree init, tree type)
{
{
  gcc_assert (!VOID_TYPE_P (type));
  gcc_assert (!VOID_TYPE_P (type));
 
 
  if (TREE_CODE (init) == TARGET_EXPR)
  if (TREE_CODE (init) == TARGET_EXPR)
    return init;
    return init;
  else if (CLASS_TYPE_P (type) && !TYPE_HAS_TRIVIAL_INIT_REF (type)
  else if (CLASS_TYPE_P (type) && !TYPE_HAS_TRIVIAL_INIT_REF (type)
           && !VOID_TYPE_P (TREE_TYPE (init))
           && !VOID_TYPE_P (TREE_TYPE (init))
           && TREE_CODE (init) != COND_EXPR
           && TREE_CODE (init) != COND_EXPR
           && TREE_CODE (init) != CONSTRUCTOR
           && TREE_CODE (init) != CONSTRUCTOR
           && TREE_CODE (init) != VA_ARG_EXPR)
           && TREE_CODE (init) != VA_ARG_EXPR)
    /* We need to build up a copy constructor call.  A void initializer
    /* We need to build up a copy constructor call.  A void initializer
       means we're being called from bot_manip.  COND_EXPR is a special
       means we're being called from bot_manip.  COND_EXPR is a special
       case because we already have copies on the arms and we don't want
       case because we already have copies on the arms and we don't want
       another one here.  A CONSTRUCTOR is aggregate initialization, which
       another one here.  A CONSTRUCTOR is aggregate initialization, which
       is handled separately.  A VA_ARG_EXPR is magic creation of an
       is handled separately.  A VA_ARG_EXPR is magic creation of an
       aggregate; there's no additional work to be done.  */
       aggregate; there's no additional work to be done.  */
    return force_rvalue (init);
    return force_rvalue (init);
 
 
  return force_target_expr (type, init);
  return force_target_expr (type, init);
}
}
 
 
/* Like the above function, but without the checking.  This function should
/* Like the above function, but without the checking.  This function should
   only be used by code which is deliberately trying to subvert the type
   only be used by code which is deliberately trying to subvert the type
   system, such as call_builtin_trap.  */
   system, such as call_builtin_trap.  */
 
 
tree
tree
force_target_expr (tree type, tree init)
force_target_expr (tree type, tree init)
{
{
  tree slot;
  tree slot;
 
 
  gcc_assert (!VOID_TYPE_P (type));
  gcc_assert (!VOID_TYPE_P (type));
 
 
  slot = build_local_temp (type);
  slot = build_local_temp (type);
  return build_target_expr (slot, init);
  return build_target_expr (slot, init);
}
}
 
 
/* Like build_target_expr_with_type, but use the type of INIT.  */
/* Like build_target_expr_with_type, but use the type of INIT.  */
 
 
tree
tree
get_target_expr (tree init)
get_target_expr (tree init)
{
{
  if (TREE_CODE (init) == AGGR_INIT_EXPR)
  if (TREE_CODE (init) == AGGR_INIT_EXPR)
    return build_target_expr (AGGR_INIT_EXPR_SLOT (init), init);
    return build_target_expr (AGGR_INIT_EXPR_SLOT (init), init);
  else
  else
    return build_target_expr_with_type (init, TREE_TYPE (init));
    return build_target_expr_with_type (init, TREE_TYPE (init));
}
}
 
 
/* If EXPR is a bitfield reference, convert it to the declared type of
/* If EXPR is a bitfield reference, convert it to the declared type of
   the bitfield, and return the resulting expression.  Otherwise,
   the bitfield, and return the resulting expression.  Otherwise,
   return EXPR itself.  */
   return EXPR itself.  */
 
 
tree
tree
convert_bitfield_to_declared_type (tree expr)
convert_bitfield_to_declared_type (tree expr)
{
{
  tree bitfield_type;
  tree bitfield_type;
 
 
  bitfield_type = is_bitfield_expr_with_lowered_type (expr);
  bitfield_type = is_bitfield_expr_with_lowered_type (expr);
  if (bitfield_type)
  if (bitfield_type)
    expr = convert_to_integer (TYPE_MAIN_VARIANT (bitfield_type),
    expr = convert_to_integer (TYPE_MAIN_VARIANT (bitfield_type),
                               expr);
                               expr);
  return expr;
  return expr;
}
}
 
 
/* EXPR is being used in an rvalue context.  Return a version of EXPR
/* EXPR is being used in an rvalue context.  Return a version of EXPR
   that is marked as an rvalue.  */
   that is marked as an rvalue.  */
 
 
tree
tree
rvalue (tree expr)
rvalue (tree expr)
{
{
  tree type;
  tree type;
 
 
  if (error_operand_p (expr))
  if (error_operand_p (expr))
    return expr;
    return expr;
 
 
  /* [basic.lval]
  /* [basic.lval]
 
 
     Non-class rvalues always have cv-unqualified types.  */
     Non-class rvalues always have cv-unqualified types.  */
  type = TREE_TYPE (expr);
  type = TREE_TYPE (expr);
  if (!CLASS_TYPE_P (type) && cv_qualified_p (type))
  if (!CLASS_TYPE_P (type) && cv_qualified_p (type))
    type = cv_unqualified (type);
    type = cv_unqualified (type);
 
 
  /* We need to do this for rvalue refs as well to get the right answer
  /* We need to do this for rvalue refs as well to get the right answer
     from decltype; see c++/36628.  */
     from decltype; see c++/36628.  */
  if (!processing_template_decl && lvalue_or_rvalue_with_address_p (expr))
  if (!processing_template_decl && lvalue_or_rvalue_with_address_p (expr))
    expr = build1 (NON_LVALUE_EXPR, type, expr);
    expr = build1 (NON_LVALUE_EXPR, type, expr);
  else if (type != TREE_TYPE (expr))
  else if (type != TREE_TYPE (expr))
    expr = build_nop (type, expr);
    expr = build_nop (type, expr);
 
 
  return expr;
  return expr;
}
}
 
 


/* Hash an ARRAY_TYPE.  K is really of type `tree'.  */
/* Hash an ARRAY_TYPE.  K is really of type `tree'.  */
 
 
static hashval_t
static hashval_t
cplus_array_hash (const void* k)
cplus_array_hash (const void* k)
{
{
  hashval_t hash;
  hashval_t hash;
  const_tree const t = (const_tree) k;
  const_tree const t = (const_tree) k;
 
 
  hash = TYPE_UID (TREE_TYPE (t));
  hash = TYPE_UID (TREE_TYPE (t));
  if (TYPE_DOMAIN (t))
  if (TYPE_DOMAIN (t))
    hash ^= TYPE_UID (TYPE_DOMAIN (t));
    hash ^= TYPE_UID (TYPE_DOMAIN (t));
  return hash;
  return hash;
}
}
 
 
typedef struct cplus_array_info {
typedef struct cplus_array_info {
  tree type;
  tree type;
  tree domain;
  tree domain;
} cplus_array_info;
} cplus_array_info;
 
 
/* Compare two ARRAY_TYPEs.  K1 is really of type `tree', K2 is really
/* Compare two ARRAY_TYPEs.  K1 is really of type `tree', K2 is really
   of type `cplus_array_info*'. */
   of type `cplus_array_info*'. */
 
 
static int
static int
cplus_array_compare (const void * k1, const void * k2)
cplus_array_compare (const void * k1, const void * k2)
{
{
  const_tree const t1 = (const_tree) k1;
  const_tree const t1 = (const_tree) k1;
  const cplus_array_info *const t2 = (const cplus_array_info*) k2;
  const cplus_array_info *const t2 = (const cplus_array_info*) k2;
 
 
  return (TREE_TYPE (t1) == t2->type && TYPE_DOMAIN (t1) == t2->domain);
  return (TREE_TYPE (t1) == t2->type && TYPE_DOMAIN (t1) == t2->domain);
}
}
 
 
/* Hash table containing dependent array types, which are unsuitable for
/* Hash table containing dependent array types, which are unsuitable for
   the language-independent type hash table.  */
   the language-independent type hash table.  */
static GTY ((param_is (union tree_node))) htab_t cplus_array_htab;
static GTY ((param_is (union tree_node))) htab_t cplus_array_htab;
 
 
/* Like build_array_type, but handle special C++ semantics.  */
/* Like build_array_type, but handle special C++ semantics.  */
 
 
tree
tree
build_cplus_array_type (tree elt_type, tree index_type)
build_cplus_array_type (tree elt_type, tree index_type)
{
{
  tree t;
  tree t;
 
 
  if (elt_type == error_mark_node || index_type == error_mark_node)
  if (elt_type == error_mark_node || index_type == error_mark_node)
    return error_mark_node;
    return error_mark_node;
 
 
  if (processing_template_decl
  if (processing_template_decl
      && (dependent_type_p (elt_type)
      && (dependent_type_p (elt_type)
          || (index_type && !TREE_CONSTANT (TYPE_MAX_VALUE (index_type)))))
          || (index_type && !TREE_CONSTANT (TYPE_MAX_VALUE (index_type)))))
    {
    {
      void **e;
      void **e;
      cplus_array_info cai;
      cplus_array_info cai;
      hashval_t hash;
      hashval_t hash;
 
 
      if (cplus_array_htab == NULL)
      if (cplus_array_htab == NULL)
        cplus_array_htab = htab_create_ggc (61, &cplus_array_hash,
        cplus_array_htab = htab_create_ggc (61, &cplus_array_hash,
                                            &cplus_array_compare, NULL);
                                            &cplus_array_compare, NULL);
 
 
      hash = TYPE_UID (elt_type);
      hash = TYPE_UID (elt_type);
      if (index_type)
      if (index_type)
        hash ^= TYPE_UID (index_type);
        hash ^= TYPE_UID (index_type);
      cai.type = elt_type;
      cai.type = elt_type;
      cai.domain = index_type;
      cai.domain = index_type;
 
 
      e = htab_find_slot_with_hash (cplus_array_htab, &cai, hash, INSERT);
      e = htab_find_slot_with_hash (cplus_array_htab, &cai, hash, INSERT);
      if (*e)
      if (*e)
        /* We have found the type: we're done.  */
        /* We have found the type: we're done.  */
        return (tree) *e;
        return (tree) *e;
      else
      else
        {
        {
          /* Build a new array type.  */
          /* Build a new array type.  */
          t = cxx_make_type (ARRAY_TYPE);
          t = cxx_make_type (ARRAY_TYPE);
          TREE_TYPE (t) = elt_type;
          TREE_TYPE (t) = elt_type;
          TYPE_DOMAIN (t) = index_type;
          TYPE_DOMAIN (t) = index_type;
 
 
          /* Store it in the hash table. */
          /* Store it in the hash table. */
          *e = t;
          *e = t;
 
 
          /* Set the canonical type for this new node.  */
          /* Set the canonical type for this new node.  */
          if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
          if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
              || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)))
              || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)))
            SET_TYPE_STRUCTURAL_EQUALITY (t);
            SET_TYPE_STRUCTURAL_EQUALITY (t);
          else if (TYPE_CANONICAL (elt_type) != elt_type
          else if (TYPE_CANONICAL (elt_type) != elt_type
                   || (index_type
                   || (index_type
                       && TYPE_CANONICAL (index_type) != index_type))
                       && TYPE_CANONICAL (index_type) != index_type))
            TYPE_CANONICAL (t)
            TYPE_CANONICAL (t)
                = build_cplus_array_type
                = build_cplus_array_type
                   (TYPE_CANONICAL (elt_type),
                   (TYPE_CANONICAL (elt_type),
                    index_type ? TYPE_CANONICAL (index_type) : index_type);
                    index_type ? TYPE_CANONICAL (index_type) : index_type);
          else
          else
            TYPE_CANONICAL (t) = t;
            TYPE_CANONICAL (t) = t;
        }
        }
    }
    }
  else
  else
    t = build_array_type (elt_type, index_type);
    t = build_array_type (elt_type, index_type);
 
 
  /* We want TYPE_MAIN_VARIANT of an array to strip cv-quals from the
  /* We want TYPE_MAIN_VARIANT of an array to strip cv-quals from the
     element type as well, so fix it up if needed.  */
     element type as well, so fix it up if needed.  */
  if (elt_type != TYPE_MAIN_VARIANT (elt_type))
  if (elt_type != TYPE_MAIN_VARIANT (elt_type))
    {
    {
      tree m = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type),
      tree m = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type),
                                       index_type);
                                       index_type);
      if (TYPE_MAIN_VARIANT (t) != m)
      if (TYPE_MAIN_VARIANT (t) != m)
        {
        {
          TYPE_MAIN_VARIANT (t) = m;
          TYPE_MAIN_VARIANT (t) = m;
          TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
          TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
          TYPE_NEXT_VARIANT (m) = t;
          TYPE_NEXT_VARIANT (m) = t;
        }
        }
    }
    }
 
 
  /* Push these needs up so that initialization takes place
  /* Push these needs up so that initialization takes place
     more easily.  */
     more easily.  */
  TYPE_NEEDS_CONSTRUCTING (t)
  TYPE_NEEDS_CONSTRUCTING (t)
    = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type));
    = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type));
  TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
  TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type));
    = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type));
  return t;
  return t;
}
}
 
 
/* Return an ARRAY_TYPE with element type ELT and length N.  */
/* Return an ARRAY_TYPE with element type ELT and length N.  */
 
 
tree
tree
build_array_of_n_type (tree elt, int n)
build_array_of_n_type (tree elt, int n)
{
{
  return build_cplus_array_type (elt, build_index_type (size_int (n - 1)));
  return build_cplus_array_type (elt, build_index_type (size_int (n - 1)));
}
}
 
 
/* Return a reference type node referring to TO_TYPE.  If RVAL is
/* Return a reference type node referring to TO_TYPE.  If RVAL is
   true, return an rvalue reference type, otherwise return an lvalue
   true, return an rvalue reference type, otherwise return an lvalue
   reference type.  If a type node exists, reuse it, otherwise create
   reference type.  If a type node exists, reuse it, otherwise create
   a new one.  */
   a new one.  */
tree
tree
cp_build_reference_type (tree to_type, bool rval)
cp_build_reference_type (tree to_type, bool rval)
{
{
  tree lvalue_ref, t;
  tree lvalue_ref, t;
  lvalue_ref = build_reference_type (to_type);
  lvalue_ref = build_reference_type (to_type);
  if (!rval)
  if (!rval)
    return lvalue_ref;
    return lvalue_ref;
 
 
  /* This code to create rvalue reference types is based on and tied
  /* This code to create rvalue reference types is based on and tied
     to the code creating lvalue reference types in the middle-end
     to the code creating lvalue reference types in the middle-end
     functions build_reference_type_for_mode and build_reference_type.
     functions build_reference_type_for_mode and build_reference_type.
 
 
     It works by putting the rvalue reference type nodes after the
     It works by putting the rvalue reference type nodes after the
     lvalue reference nodes in the TYPE_NEXT_REF_TO linked list, so
     lvalue reference nodes in the TYPE_NEXT_REF_TO linked list, so
     they will effectively be ignored by the middle end.  */
     they will effectively be ignored by the middle end.  */
 
 
  for (t = lvalue_ref; (t = TYPE_NEXT_REF_TO (t)); )
  for (t = lvalue_ref; (t = TYPE_NEXT_REF_TO (t)); )
    if (TYPE_REF_IS_RVALUE (t))
    if (TYPE_REF_IS_RVALUE (t))
      return t;
      return t;
 
 
  t = build_distinct_type_copy (lvalue_ref);
  t = build_distinct_type_copy (lvalue_ref);
 
 
  TYPE_REF_IS_RVALUE (t) = true;
  TYPE_REF_IS_RVALUE (t) = true;
  TYPE_NEXT_REF_TO (t) = TYPE_NEXT_REF_TO (lvalue_ref);
  TYPE_NEXT_REF_TO (t) = TYPE_NEXT_REF_TO (lvalue_ref);
  TYPE_NEXT_REF_TO (lvalue_ref) = t;
  TYPE_NEXT_REF_TO (lvalue_ref) = t;
 
 
  if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
  if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
    SET_TYPE_STRUCTURAL_EQUALITY (t);
    SET_TYPE_STRUCTURAL_EQUALITY (t);
  else if (TYPE_CANONICAL (to_type) != to_type)
  else if (TYPE_CANONICAL (to_type) != to_type)
    TYPE_CANONICAL (t)
    TYPE_CANONICAL (t)
      = cp_build_reference_type (TYPE_CANONICAL (to_type), rval);
      = cp_build_reference_type (TYPE_CANONICAL (to_type), rval);
  else
  else
    TYPE_CANONICAL (t) = t;
    TYPE_CANONICAL (t) = t;
 
 
  layout_type (t);
  layout_type (t);
 
 
  return t;
  return t;
 
 
}
}
 
 
/* Returns EXPR cast to rvalue reference type, like std::move.  */
/* Returns EXPR cast to rvalue reference type, like std::move.  */
 
 
tree
tree
move (tree expr)
move (tree expr)
{
{
  tree type = TREE_TYPE (expr);
  tree type = TREE_TYPE (expr);
  gcc_assert (TREE_CODE (type) != REFERENCE_TYPE);
  gcc_assert (TREE_CODE (type) != REFERENCE_TYPE);
  type = cp_build_reference_type (type, /*rval*/true);
  type = cp_build_reference_type (type, /*rval*/true);
  return build_static_cast (type, expr, tf_warning_or_error);
  return build_static_cast (type, expr, tf_warning_or_error);
}
}
 
 
/* Used by the C++ front end to build qualified array types.  However,
/* Used by the C++ front end to build qualified array types.  However,
   the C version of this function does not properly maintain canonical
   the C version of this function does not properly maintain canonical
   types (which are not used in C).  */
   types (which are not used in C).  */
tree
tree
c_build_qualified_type (tree type, int type_quals)
c_build_qualified_type (tree type, int type_quals)
{
{
  return cp_build_qualified_type (type, type_quals);
  return cp_build_qualified_type (type, type_quals);
}
}
 
 


/* Make a variant of TYPE, qualified with the TYPE_QUALS.  Handles
/* Make a variant of TYPE, qualified with the TYPE_QUALS.  Handles
   arrays correctly.  In particular, if TYPE is an array of T's, and
   arrays correctly.  In particular, if TYPE is an array of T's, and
   TYPE_QUALS is non-empty, returns an array of qualified T's.
   TYPE_QUALS is non-empty, returns an array of qualified T's.
 
 
   FLAGS determines how to deal with ill-formed qualifications. If
   FLAGS determines how to deal with ill-formed qualifications. If
   tf_ignore_bad_quals is set, then bad qualifications are dropped
   tf_ignore_bad_quals is set, then bad qualifications are dropped
   (this is permitted if TYPE was introduced via a typedef or template
   (this is permitted if TYPE was introduced via a typedef or template
   type parameter). If bad qualifications are dropped and tf_warning
   type parameter). If bad qualifications are dropped and tf_warning
   is set, then a warning is issued for non-const qualifications.  If
   is set, then a warning is issued for non-const qualifications.  If
   tf_ignore_bad_quals is not set and tf_error is not set, we
   tf_ignore_bad_quals is not set and tf_error is not set, we
   return error_mark_node. Otherwise, we issue an error, and ignore
   return error_mark_node. Otherwise, we issue an error, and ignore
   the qualifications.
   the qualifications.
 
 
   Qualification of a reference type is valid when the reference came
   Qualification of a reference type is valid when the reference came
   via a typedef or template type argument. [dcl.ref] No such
   via a typedef or template type argument. [dcl.ref] No such
   dispensation is provided for qualifying a function type.  [dcl.fct]
   dispensation is provided for qualifying a function type.  [dcl.fct]
   DR 295 queries this and the proposed resolution brings it into line
   DR 295 queries this and the proposed resolution brings it into line
   with qualifying a reference.  We implement the DR.  We also behave
   with qualifying a reference.  We implement the DR.  We also behave
   in a similar manner for restricting non-pointer types.  */
   in a similar manner for restricting non-pointer types.  */
 
 
tree
tree
cp_build_qualified_type_real (tree type,
cp_build_qualified_type_real (tree type,
                              int type_quals,
                              int type_quals,
                              tsubst_flags_t complain)
                              tsubst_flags_t complain)
{
{
  tree result;
  tree result;
  int bad_quals = TYPE_UNQUALIFIED;
  int bad_quals = TYPE_UNQUALIFIED;
 
 
  if (type == error_mark_node)
  if (type == error_mark_node)
    return type;
    return type;
 
 
  if (type_quals == cp_type_quals (type))
  if (type_quals == cp_type_quals (type))
    return type;
    return type;
 
 
  if (TREE_CODE (type) == ARRAY_TYPE)
  if (TREE_CODE (type) == ARRAY_TYPE)
    {
    {
      /* In C++, the qualification really applies to the array element
      /* In C++, the qualification really applies to the array element
         type.  Obtain the appropriately qualified element type.  */
         type.  Obtain the appropriately qualified element type.  */
      tree t;
      tree t;
      tree element_type
      tree element_type
        = cp_build_qualified_type_real (TREE_TYPE (type),
        = cp_build_qualified_type_real (TREE_TYPE (type),
                                        type_quals,
                                        type_quals,
                                        complain);
                                        complain);
 
 
      if (element_type == error_mark_node)
      if (element_type == error_mark_node)
        return error_mark_node;
        return error_mark_node;
 
 
      /* See if we already have an identically qualified type.  Tests
      /* See if we already have an identically qualified type.  Tests
         should be equivalent to those in check_qualified_type.  */
         should be equivalent to those in check_qualified_type.  */
      for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
      for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
        if (cp_type_quals (t) == type_quals
        if (cp_type_quals (t) == type_quals
            && TYPE_NAME (t) == TYPE_NAME (type)
            && TYPE_NAME (t) == TYPE_NAME (type)
            && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
            && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
            && attribute_list_equal (TYPE_ATTRIBUTES (t),
            && attribute_list_equal (TYPE_ATTRIBUTES (t),
                                     TYPE_ATTRIBUTES (type)))
                                     TYPE_ATTRIBUTES (type)))
          break;
          break;
 
 
      if (!t)
      if (!t)
        {
        {
          t = build_cplus_array_type (element_type, TYPE_DOMAIN (type));
          t = build_cplus_array_type (element_type, TYPE_DOMAIN (type));
 
 
          /* Keep the typedef name.  */
          /* Keep the typedef name.  */
          if (TYPE_NAME (t) != TYPE_NAME (type))
          if (TYPE_NAME (t) != TYPE_NAME (type))
            {
            {
              t = build_variant_type_copy (t);
              t = build_variant_type_copy (t);
              TYPE_NAME (t) = TYPE_NAME (type);
              TYPE_NAME (t) = TYPE_NAME (type);
            }
            }
        }
        }
 
 
      /* Even if we already had this variant, we update
      /* Even if we already had this variant, we update
         TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
         TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
         they changed since the variant was originally created.
         they changed since the variant was originally created.
 
 
         This seems hokey; if there is some way to use a previous
         This seems hokey; if there is some way to use a previous
         variant *without* coming through here,
         variant *without* coming through here,
         TYPE_NEEDS_CONSTRUCTING will never be updated.  */
         TYPE_NEEDS_CONSTRUCTING will never be updated.  */
      TYPE_NEEDS_CONSTRUCTING (t)
      TYPE_NEEDS_CONSTRUCTING (t)
        = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
        = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
      TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
      TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
        = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
        = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
      return t;
      return t;
    }
    }
  else if (TYPE_PTRMEMFUNC_P (type))
  else if (TYPE_PTRMEMFUNC_P (type))
    {
    {
      /* For a pointer-to-member type, we can't just return a
      /* For a pointer-to-member type, we can't just return a
         cv-qualified version of the RECORD_TYPE.  If we do, we
         cv-qualified version of the RECORD_TYPE.  If we do, we
         haven't changed the field that contains the actual pointer to
         haven't changed the field that contains the actual pointer to
         a method, and so TYPE_PTRMEMFUNC_FN_TYPE will be wrong.  */
         a method, and so TYPE_PTRMEMFUNC_FN_TYPE will be wrong.  */
      tree t;
      tree t;
 
 
      t = TYPE_PTRMEMFUNC_FN_TYPE (type);
      t = TYPE_PTRMEMFUNC_FN_TYPE (type);
      t = cp_build_qualified_type_real (t, type_quals, complain);
      t = cp_build_qualified_type_real (t, type_quals, complain);
      return build_ptrmemfunc_type (t);
      return build_ptrmemfunc_type (t);
    }
    }
  else if (TREE_CODE (type) == TYPE_PACK_EXPANSION)
  else if (TREE_CODE (type) == TYPE_PACK_EXPANSION)
    {
    {
      tree t = PACK_EXPANSION_PATTERN (type);
      tree t = PACK_EXPANSION_PATTERN (type);
 
 
      t = cp_build_qualified_type_real (t, type_quals, complain);
      t = cp_build_qualified_type_real (t, type_quals, complain);
      return make_pack_expansion (t);
      return make_pack_expansion (t);
    }
    }
 
 
  /* A reference or method type shall not be cv-qualified.
  /* A reference or method type shall not be cv-qualified.
     [dcl.ref], [dcl.fct]  */
     [dcl.ref], [dcl.fct]  */
  if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
  if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
      && (TREE_CODE (type) == REFERENCE_TYPE
      && (TREE_CODE (type) == REFERENCE_TYPE
          || TREE_CODE (type) == METHOD_TYPE))
          || TREE_CODE (type) == METHOD_TYPE))
    {
    {
      bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
      bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
      type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
      type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
    }
    }
 
 
  /* A restrict-qualified type must be a pointer (or reference)
  /* A restrict-qualified type must be a pointer (or reference)
     to object or incomplete type. */
     to object or incomplete type. */
  if ((type_quals & TYPE_QUAL_RESTRICT)
  if ((type_quals & TYPE_QUAL_RESTRICT)
      && TREE_CODE (type) != TEMPLATE_TYPE_PARM
      && TREE_CODE (type) != TEMPLATE_TYPE_PARM
      && TREE_CODE (type) != TYPENAME_TYPE
      && TREE_CODE (type) != TYPENAME_TYPE
      && !POINTER_TYPE_P (type))
      && !POINTER_TYPE_P (type))
    {
    {
      bad_quals |= TYPE_QUAL_RESTRICT;
      bad_quals |= TYPE_QUAL_RESTRICT;
      type_quals &= ~TYPE_QUAL_RESTRICT;
      type_quals &= ~TYPE_QUAL_RESTRICT;
    }
    }
 
 
  if (bad_quals == TYPE_UNQUALIFIED)
  if (bad_quals == TYPE_UNQUALIFIED)
    /*OK*/;
    /*OK*/;
  else if (!(complain & (tf_error | tf_ignore_bad_quals)))
  else if (!(complain & (tf_error | tf_ignore_bad_quals)))
    return error_mark_node;
    return error_mark_node;
  else
  else
    {
    {
      if (complain & tf_ignore_bad_quals)
      if (complain & tf_ignore_bad_quals)
        /* We're not going to warn about constifying things that can't
        /* We're not going to warn about constifying things that can't
           be constified.  */
           be constified.  */
        bad_quals &= ~TYPE_QUAL_CONST;
        bad_quals &= ~TYPE_QUAL_CONST;
      if (bad_quals)
      if (bad_quals)
        {
        {
          tree bad_type = build_qualified_type (ptr_type_node, bad_quals);
          tree bad_type = build_qualified_type (ptr_type_node, bad_quals);
 
 
          if (!(complain & tf_ignore_bad_quals))
          if (!(complain & tf_ignore_bad_quals))
            error ("%qV qualifiers cannot be applied to %qT",
            error ("%qV qualifiers cannot be applied to %qT",
                   bad_type, type);
                   bad_type, type);
        }
        }
    }
    }
 
 
  /* Retrieve (or create) the appropriately qualified variant.  */
  /* Retrieve (or create) the appropriately qualified variant.  */
  result = build_qualified_type (type, type_quals);
  result = build_qualified_type (type, type_quals);
 
 
  /* If this was a pointer-to-method type, and we just made a copy,
  /* If this was a pointer-to-method type, and we just made a copy,
     then we need to unshare the record that holds the cached
     then we need to unshare the record that holds the cached
     pointer-to-member-function type, because these will be distinct
     pointer-to-member-function type, because these will be distinct
     between the unqualified and qualified types.  */
     between the unqualified and qualified types.  */
  if (result != type
  if (result != type
      && TREE_CODE (type) == POINTER_TYPE
      && TREE_CODE (type) == POINTER_TYPE
      && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE
      && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE
      && TYPE_LANG_SPECIFIC (result) == TYPE_LANG_SPECIFIC (type))
      && TYPE_LANG_SPECIFIC (result) == TYPE_LANG_SPECIFIC (type))
    TYPE_LANG_SPECIFIC (result) = NULL;
    TYPE_LANG_SPECIFIC (result) = NULL;
 
 
  /* We may also have ended up building a new copy of the canonical
  /* We may also have ended up building a new copy of the canonical
     type of a pointer-to-method type, which could have the same
     type of a pointer-to-method type, which could have the same
     sharing problem described above.  */
     sharing problem described above.  */
  if (TYPE_CANONICAL (result) != TYPE_CANONICAL (type)
  if (TYPE_CANONICAL (result) != TYPE_CANONICAL (type)
      && TREE_CODE (type) == POINTER_TYPE
      && TREE_CODE (type) == POINTER_TYPE
      && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE
      && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE
      && (TYPE_LANG_SPECIFIC (TYPE_CANONICAL (result))
      && (TYPE_LANG_SPECIFIC (TYPE_CANONICAL (result))
          == TYPE_LANG_SPECIFIC (TYPE_CANONICAL (type))))
          == TYPE_LANG_SPECIFIC (TYPE_CANONICAL (type))))
    TYPE_LANG_SPECIFIC (TYPE_CANONICAL (result)) = NULL;
    TYPE_LANG_SPECIFIC (TYPE_CANONICAL (result)) = NULL;
 
 
  return result;
  return result;
}
}
 
 
/* Return TYPE with const and volatile removed.  */
/* Return TYPE with const and volatile removed.  */
 
 
tree
tree
cv_unqualified (tree type)
cv_unqualified (tree type)
{
{
  int quals = TYPE_QUALS (type);
  int quals = TYPE_QUALS (type);
  quals &= ~(TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE);
  quals &= ~(TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE);
  return cp_build_qualified_type (type, quals);
  return cp_build_qualified_type (type, quals);
}
}
 
 
/* Builds a qualified variant of T that is not a typedef variant.
/* Builds a qualified variant of T that is not a typedef variant.
   E.g. consider the following declarations:
   E.g. consider the following declarations:
     typedef const int ConstInt;
     typedef const int ConstInt;
     typedef ConstInt* PtrConstInt;
     typedef ConstInt* PtrConstInt;
   If T is PtrConstInt, this function returns a type representing
   If T is PtrConstInt, this function returns a type representing
     const int*.
     const int*.
   In other words, if T is a typedef, the function returns the underlying type.
   In other words, if T is a typedef, the function returns the underlying type.
   The cv-qualification and attributes of the type returned match the
   The cv-qualification and attributes of the type returned match the
   input type.
   input type.
   They will always be compatible types.
   They will always be compatible types.
   The returned type is built so that all of its subtypes
   The returned type is built so that all of its subtypes
   recursively have their typedefs stripped as well.
   recursively have their typedefs stripped as well.
 
 
   This is different from just returning TYPE_CANONICAL (T)
   This is different from just returning TYPE_CANONICAL (T)
   Because of several reasons:
   Because of several reasons:
    * If T is a type that needs structural equality
    * If T is a type that needs structural equality
      its TYPE_CANONICAL (T) will be NULL.
      its TYPE_CANONICAL (T) will be NULL.
    * TYPE_CANONICAL (T) desn't carry type attributes
    * TYPE_CANONICAL (T) desn't carry type attributes
      and looses template parameter names.   */
      and looses template parameter names.   */
 
 
tree
tree
strip_typedefs (tree t)
strip_typedefs (tree t)
{
{
  tree result = NULL, type = NULL, t0 = NULL;
  tree result = NULL, type = NULL, t0 = NULL;
 
 
  if (!t || t == error_mark_node || t == TYPE_CANONICAL (t))
  if (!t || t == error_mark_node || t == TYPE_CANONICAL (t))
    return t;
    return t;
 
 
  gcc_assert (TYPE_P (t));
  gcc_assert (TYPE_P (t));
 
 
  switch (TREE_CODE (t))
  switch (TREE_CODE (t))
    {
    {
    case POINTER_TYPE:
    case POINTER_TYPE:
      type = strip_typedefs (TREE_TYPE (t));
      type = strip_typedefs (TREE_TYPE (t));
      result = build_pointer_type (type);
      result = build_pointer_type (type);
      break;
      break;
    case REFERENCE_TYPE:
    case REFERENCE_TYPE:
      type = strip_typedefs (TREE_TYPE (t));
      type = strip_typedefs (TREE_TYPE (t));
      result = cp_build_reference_type (type, TYPE_REF_IS_RVALUE (t));
      result = cp_build_reference_type (type, TYPE_REF_IS_RVALUE (t));
      break;
      break;
    case OFFSET_TYPE:
    case OFFSET_TYPE:
      t0 = strip_typedefs (TYPE_OFFSET_BASETYPE (t));
      t0 = strip_typedefs (TYPE_OFFSET_BASETYPE (t));
      type = strip_typedefs (TREE_TYPE (t));
      type = strip_typedefs (TREE_TYPE (t));
      result = build_offset_type (t0, type);
      result = build_offset_type (t0, type);
      break;
      break;
    case RECORD_TYPE:
    case RECORD_TYPE:
      if (TYPE_PTRMEMFUNC_P (t))
      if (TYPE_PTRMEMFUNC_P (t))
        {
        {
          t0 = strip_typedefs (TYPE_PTRMEMFUNC_FN_TYPE (t));
          t0 = strip_typedefs (TYPE_PTRMEMFUNC_FN_TYPE (t));
          result = build_ptrmemfunc_type (t0);
          result = build_ptrmemfunc_type (t0);
        }
        }
      break;
      break;
    case ARRAY_TYPE:
    case ARRAY_TYPE:
      type = strip_typedefs (TREE_TYPE (t));
      type = strip_typedefs (TREE_TYPE (t));
      t0  = strip_typedefs (TYPE_DOMAIN (t));;
      t0  = strip_typedefs (TYPE_DOMAIN (t));;
      result = build_cplus_array_type (type, t0);
      result = build_cplus_array_type (type, t0);
      break;
      break;
    case FUNCTION_TYPE:
    case FUNCTION_TYPE:
    case METHOD_TYPE:
    case METHOD_TYPE:
      {
      {
        tree arg_types = NULL, arg_node, arg_type;
        tree arg_types = NULL, arg_node, arg_type;
        for (arg_node = TYPE_ARG_TYPES (t);
        for (arg_node = TYPE_ARG_TYPES (t);
             arg_node;
             arg_node;
             arg_node = TREE_CHAIN (arg_node))
             arg_node = TREE_CHAIN (arg_node))
          {
          {
            if (arg_node == void_list_node)
            if (arg_node == void_list_node)
              break;
              break;
            arg_type = strip_typedefs (TREE_VALUE (arg_node));
            arg_type = strip_typedefs (TREE_VALUE (arg_node));
            gcc_assert (arg_type);
            gcc_assert (arg_type);
 
 
            arg_types =
            arg_types =
              tree_cons (TREE_PURPOSE (arg_node), arg_type, arg_types);
              tree_cons (TREE_PURPOSE (arg_node), arg_type, arg_types);
          }
          }
 
 
        if (arg_types)
        if (arg_types)
          arg_types = nreverse (arg_types);
          arg_types = nreverse (arg_types);
 
 
        /* A list of parameters not ending with an ellipsis
        /* A list of parameters not ending with an ellipsis
           must end with void_list_node.  */
           must end with void_list_node.  */
        if (arg_node)
        if (arg_node)
          arg_types = chainon (arg_types, void_list_node);
          arg_types = chainon (arg_types, void_list_node);
 
 
        type = strip_typedefs (TREE_TYPE (t));
        type = strip_typedefs (TREE_TYPE (t));
        if (TREE_CODE (t) == METHOD_TYPE)
        if (TREE_CODE (t) == METHOD_TYPE)
          {
          {
            tree class_type = TREE_TYPE (TREE_VALUE (arg_types));
            tree class_type = TREE_TYPE (TREE_VALUE (arg_types));
            gcc_assert (class_type);
            gcc_assert (class_type);
            result =
            result =
              build_method_type_directly (class_type, type,
              build_method_type_directly (class_type, type,
                                          TREE_CHAIN (arg_types));
                                          TREE_CHAIN (arg_types));
          }
          }
        else
        else
            result = build_function_type (type,
            result = build_function_type (type,
                                          arg_types);
                                          arg_types);
 
 
        if (TYPE_RAISES_EXCEPTIONS (t))
        if (TYPE_RAISES_EXCEPTIONS (t))
          result = build_exception_variant (result,
          result = build_exception_variant (result,
                                            TYPE_RAISES_EXCEPTIONS (t));
                                            TYPE_RAISES_EXCEPTIONS (t));
      }
      }
      break;
      break;
    default:
    default:
      break;
      break;
    }
    }
 
 
  if (!result)
  if (!result)
      result = TYPE_MAIN_VARIANT (t);
      result = TYPE_MAIN_VARIANT (t);
  if (TYPE_ATTRIBUTES (t))
  if (TYPE_ATTRIBUTES (t))
    result = cp_build_type_attribute_variant (result, TYPE_ATTRIBUTES (t));
    result = cp_build_type_attribute_variant (result, TYPE_ATTRIBUTES (t));
  return cp_build_qualified_type (result, cp_type_quals (t));
  return cp_build_qualified_type (result, cp_type_quals (t));
}
}
 
 
/* Returns true iff TYPE is a type variant created for a typedef. */
/* Returns true iff TYPE is a type variant created for a typedef. */
 
 
bool
bool
typedef_variant_p (tree type)
typedef_variant_p (tree type)
{
{
  return is_typedef_decl (TYPE_NAME (type));
  return is_typedef_decl (TYPE_NAME (type));
}
}
 
 
/* Setup a TYPE_DECL node as a typedef representation.
/* Setup a TYPE_DECL node as a typedef representation.
   See comments of set_underlying_type in c-common.c.  */
   See comments of set_underlying_type in c-common.c.  */
 
 
void
void
cp_set_underlying_type (tree t)
cp_set_underlying_type (tree t)
{
{
  set_underlying_type (t);
  set_underlying_type (t);
  /* If T is a template type parm, make it require structural equality.
  /* If T is a template type parm, make it require structural equality.
     This is useful when comparing two template type parms,
     This is useful when comparing two template type parms,
     because it forces the comparison of the template parameters of their
     because it forces the comparison of the template parameters of their
     decls.  */
     decls.  */
  if (TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM)
  if (TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM)
    SET_TYPE_STRUCTURAL_EQUALITY (TREE_TYPE (t));
    SET_TYPE_STRUCTURAL_EQUALITY (TREE_TYPE (t));
}
}
 
 


/* Makes a copy of BINFO and TYPE, which is to be inherited into a
/* Makes a copy of BINFO and TYPE, which is to be inherited into a
   graph dominated by T.  If BINFO is NULL, TYPE is a dependent base,
   graph dominated by T.  If BINFO is NULL, TYPE is a dependent base,
   and we do a shallow copy.  If BINFO is non-NULL, we do a deep copy.
   and we do a shallow copy.  If BINFO is non-NULL, we do a deep copy.
   VIRT indicates whether TYPE is inherited virtually or not.
   VIRT indicates whether TYPE is inherited virtually or not.
   IGO_PREV points at the previous binfo of the inheritance graph
   IGO_PREV points at the previous binfo of the inheritance graph
   order chain.  The newly copied binfo's TREE_CHAIN forms this
   order chain.  The newly copied binfo's TREE_CHAIN forms this
   ordering.
   ordering.
 
 
   The CLASSTYPE_VBASECLASSES vector of T is constructed in the
   The CLASSTYPE_VBASECLASSES vector of T is constructed in the
   correct order. That is in the order the bases themselves should be
   correct order. That is in the order the bases themselves should be
   constructed in.
   constructed in.
 
 
   The BINFO_INHERITANCE of a virtual base class points to the binfo
   The BINFO_INHERITANCE of a virtual base class points to the binfo
   of the most derived type. ??? We could probably change this so that
   of the most derived type. ??? We could probably change this so that
   BINFO_INHERITANCE becomes synonymous with BINFO_PRIMARY, and hence
   BINFO_INHERITANCE becomes synonymous with BINFO_PRIMARY, and hence
   remove a field.  They currently can only differ for primary virtual
   remove a field.  They currently can only differ for primary virtual
   virtual bases.  */
   virtual bases.  */
 
 
tree
tree
copy_binfo (tree binfo, tree type, tree t, tree *igo_prev, int virt)
copy_binfo (tree binfo, tree type, tree t, tree *igo_prev, int virt)
{
{
  tree new_binfo;
  tree new_binfo;
 
 
  if (virt)
  if (virt)
    {
    {
      /* See if we've already made this virtual base.  */
      /* See if we've already made this virtual base.  */
      new_binfo = binfo_for_vbase (type, t);
      new_binfo = binfo_for_vbase (type, t);
      if (new_binfo)
      if (new_binfo)
        return new_binfo;
        return new_binfo;
    }
    }
 
 
  new_binfo = make_tree_binfo (binfo ? BINFO_N_BASE_BINFOS (binfo) : 0);
  new_binfo = make_tree_binfo (binfo ? BINFO_N_BASE_BINFOS (binfo) : 0);
  BINFO_TYPE (new_binfo) = type;
  BINFO_TYPE (new_binfo) = type;
 
 
  /* Chain it into the inheritance graph.  */
  /* Chain it into the inheritance graph.  */
  TREE_CHAIN (*igo_prev) = new_binfo;
  TREE_CHAIN (*igo_prev) = new_binfo;
  *igo_prev = new_binfo;
  *igo_prev = new_binfo;
 
 
  if (binfo)
  if (binfo)
    {
    {
      int ix;
      int ix;
      tree base_binfo;
      tree base_binfo;
 
 
      gcc_assert (!BINFO_DEPENDENT_BASE_P (binfo));
      gcc_assert (!BINFO_DEPENDENT_BASE_P (binfo));
      gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), type));
      gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), type));
 
 
      BINFO_OFFSET (new_binfo) = BINFO_OFFSET (binfo);
      BINFO_OFFSET (new_binfo) = BINFO_OFFSET (binfo);
      BINFO_VIRTUALS (new_binfo) = BINFO_VIRTUALS (binfo);
      BINFO_VIRTUALS (new_binfo) = BINFO_VIRTUALS (binfo);
 
 
      /* We do not need to copy the accesses, as they are read only.  */
      /* We do not need to copy the accesses, as they are read only.  */
      BINFO_BASE_ACCESSES (new_binfo) = BINFO_BASE_ACCESSES (binfo);
      BINFO_BASE_ACCESSES (new_binfo) = BINFO_BASE_ACCESSES (binfo);
 
 
      /* Recursively copy base binfos of BINFO.  */
      /* Recursively copy base binfos of BINFO.  */
      for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
      for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
        {
        {
          tree new_base_binfo;
          tree new_base_binfo;
 
 
          gcc_assert (!BINFO_DEPENDENT_BASE_P (base_binfo));
          gcc_assert (!BINFO_DEPENDENT_BASE_P (base_binfo));
          new_base_binfo = copy_binfo (base_binfo, BINFO_TYPE (base_binfo),
          new_base_binfo = copy_binfo (base_binfo, BINFO_TYPE (base_binfo),
                                       t, igo_prev,
                                       t, igo_prev,
                                       BINFO_VIRTUAL_P (base_binfo));
                                       BINFO_VIRTUAL_P (base_binfo));
 
 
          if (!BINFO_INHERITANCE_CHAIN (new_base_binfo))
          if (!BINFO_INHERITANCE_CHAIN (new_base_binfo))
            BINFO_INHERITANCE_CHAIN (new_base_binfo) = new_binfo;
            BINFO_INHERITANCE_CHAIN (new_base_binfo) = new_binfo;
          BINFO_BASE_APPEND (new_binfo, new_base_binfo);
          BINFO_BASE_APPEND (new_binfo, new_base_binfo);
        }
        }
    }
    }
  else
  else
    BINFO_DEPENDENT_BASE_P (new_binfo) = 1;
    BINFO_DEPENDENT_BASE_P (new_binfo) = 1;
 
 
  if (virt)
  if (virt)
    {
    {
      /* Push it onto the list after any virtual bases it contains
      /* Push it onto the list after any virtual bases it contains
         will have been pushed.  */
         will have been pushed.  */
      VEC_quick_push (tree, CLASSTYPE_VBASECLASSES (t), new_binfo);
      VEC_quick_push (tree, CLASSTYPE_VBASECLASSES (t), new_binfo);
      BINFO_VIRTUAL_P (new_binfo) = 1;
      BINFO_VIRTUAL_P (new_binfo) = 1;
      BINFO_INHERITANCE_CHAIN (new_binfo) = TYPE_BINFO (t);
      BINFO_INHERITANCE_CHAIN (new_binfo) = TYPE_BINFO (t);
    }
    }
 
 
  return new_binfo;
  return new_binfo;
}
}


/* Hashing of lists so that we don't make duplicates.
/* Hashing of lists so that we don't make duplicates.
   The entry point is `list_hash_canon'.  */
   The entry point is `list_hash_canon'.  */
 
 
/* Now here is the hash table.  When recording a list, it is added
/* Now here is the hash table.  When recording a list, it is added
   to the slot whose index is the hash code mod the table size.
   to the slot whose index is the hash code mod the table size.
   Note that the hash table is used for several kinds of lists.
   Note that the hash table is used for several kinds of lists.
   While all these live in the same table, they are completely independent,
   While all these live in the same table, they are completely independent,
   and the hash code is computed differently for each of these.  */
   and the hash code is computed differently for each of these.  */
 
 
static GTY ((param_is (union tree_node))) htab_t list_hash_table;
static GTY ((param_is (union tree_node))) htab_t list_hash_table;
 
 
struct list_proxy
struct list_proxy
{
{
  tree purpose;
  tree purpose;
  tree value;
  tree value;
  tree chain;
  tree chain;
};
};
 
 
/* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy
/* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy
   for a node we are thinking about adding).  */
   for a node we are thinking about adding).  */
 
 
static int
static int
list_hash_eq (const void* entry, const void* data)
list_hash_eq (const void* entry, const void* data)
{
{
  const_tree const t = (const_tree) entry;
  const_tree const t = (const_tree) entry;
  const struct list_proxy *const proxy = (const struct list_proxy *) data;
  const struct list_proxy *const proxy = (const struct list_proxy *) data;
 
 
  return (TREE_VALUE (t) == proxy->value
  return (TREE_VALUE (t) == proxy->value
          && TREE_PURPOSE (t) == proxy->purpose
          && TREE_PURPOSE (t) == proxy->purpose
          && TREE_CHAIN (t) == proxy->chain);
          && TREE_CHAIN (t) == proxy->chain);
}
}
 
 
/* Compute a hash code for a list (chain of TREE_LIST nodes
/* Compute a hash code for a list (chain of TREE_LIST nodes
   with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
   with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
   TREE_COMMON slots), by adding the hash codes of the individual entries.  */
   TREE_COMMON slots), by adding the hash codes of the individual entries.  */
 
 
static hashval_t
static hashval_t
list_hash_pieces (tree purpose, tree value, tree chain)
list_hash_pieces (tree purpose, tree value, tree chain)
{
{
  hashval_t hashcode = 0;
  hashval_t hashcode = 0;
 
 
  if (chain)
  if (chain)
    hashcode += TREE_HASH (chain);
    hashcode += TREE_HASH (chain);
 
 
  if (value)
  if (value)
    hashcode += TREE_HASH (value);
    hashcode += TREE_HASH (value);
  else
  else
    hashcode += 1007;
    hashcode += 1007;
  if (purpose)
  if (purpose)
    hashcode += TREE_HASH (purpose);
    hashcode += TREE_HASH (purpose);
  else
  else
    hashcode += 1009;
    hashcode += 1009;
  return hashcode;
  return hashcode;
}
}
 
 
/* Hash an already existing TREE_LIST.  */
/* Hash an already existing TREE_LIST.  */
 
 
static hashval_t
static hashval_t
list_hash (const void* p)
list_hash (const void* p)
{
{
  const_tree const t = (const_tree) p;
  const_tree const t = (const_tree) p;
  return list_hash_pieces (TREE_PURPOSE (t),
  return list_hash_pieces (TREE_PURPOSE (t),
                           TREE_VALUE (t),
                           TREE_VALUE (t),
                           TREE_CHAIN (t));
                           TREE_CHAIN (t));
}
}
 
 
/* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
/* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
   object for an identical list if one already exists.  Otherwise, build a
   object for an identical list if one already exists.  Otherwise, build a
   new one, and record it as the canonical object.  */
   new one, and record it as the canonical object.  */
 
 
tree
tree
hash_tree_cons (tree purpose, tree value, tree chain)
hash_tree_cons (tree purpose, tree value, tree chain)
{
{
  int hashcode = 0;
  int hashcode = 0;
  void **slot;
  void **slot;
  struct list_proxy proxy;
  struct list_proxy proxy;
 
 
  /* Hash the list node.  */
  /* Hash the list node.  */
  hashcode = list_hash_pieces (purpose, value, chain);
  hashcode = list_hash_pieces (purpose, value, chain);
  /* Create a proxy for the TREE_LIST we would like to create.  We
  /* Create a proxy for the TREE_LIST we would like to create.  We
     don't actually create it so as to avoid creating garbage.  */
     don't actually create it so as to avoid creating garbage.  */
  proxy.purpose = purpose;
  proxy.purpose = purpose;
  proxy.value = value;
  proxy.value = value;
  proxy.chain = chain;
  proxy.chain = chain;
  /* See if it is already in the table.  */
  /* See if it is already in the table.  */
  slot = htab_find_slot_with_hash (list_hash_table, &proxy, hashcode,
  slot = htab_find_slot_with_hash (list_hash_table, &proxy, hashcode,
                                   INSERT);
                                   INSERT);
  /* If not, create a new node.  */
  /* If not, create a new node.  */
  if (!*slot)
  if (!*slot)
    *slot = tree_cons (purpose, value, chain);
    *slot = tree_cons (purpose, value, chain);
  return (tree) *slot;
  return (tree) *slot;
}
}
 
 
/* Constructor for hashed lists.  */
/* Constructor for hashed lists.  */
 
 
tree
tree
hash_tree_chain (tree value, tree chain)
hash_tree_chain (tree value, tree chain)
{
{
  return hash_tree_cons (NULL_TREE, value, chain);
  return hash_tree_cons (NULL_TREE, value, chain);
}
}


void
void
debug_binfo (tree elem)
debug_binfo (tree elem)
{
{
  HOST_WIDE_INT n;
  HOST_WIDE_INT n;
  tree virtuals;
  tree virtuals;
 
 
  fprintf (stderr, "type \"%s\", offset = " HOST_WIDE_INT_PRINT_DEC
  fprintf (stderr, "type \"%s\", offset = " HOST_WIDE_INT_PRINT_DEC
           "\nvtable type:\n",
           "\nvtable type:\n",
           TYPE_NAME_STRING (BINFO_TYPE (elem)),
           TYPE_NAME_STRING (BINFO_TYPE (elem)),
           TREE_INT_CST_LOW (BINFO_OFFSET (elem)));
           TREE_INT_CST_LOW (BINFO_OFFSET (elem)));
  debug_tree (BINFO_TYPE (elem));
  debug_tree (BINFO_TYPE (elem));
  if (BINFO_VTABLE (elem))
  if (BINFO_VTABLE (elem))
    fprintf (stderr, "vtable decl \"%s\"\n",
    fprintf (stderr, "vtable decl \"%s\"\n",
             IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem))));
             IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem))));
  else
  else
    fprintf (stderr, "no vtable decl yet\n");
    fprintf (stderr, "no vtable decl yet\n");
  fprintf (stderr, "virtuals:\n");
  fprintf (stderr, "virtuals:\n");
  virtuals = BINFO_VIRTUALS (elem);
  virtuals = BINFO_VIRTUALS (elem);
  n = 0;
  n = 0;
 
 
  while (virtuals)
  while (virtuals)
    {
    {
      tree fndecl = TREE_VALUE (virtuals);
      tree fndecl = TREE_VALUE (virtuals);
      fprintf (stderr, "%s [%ld =? %ld]\n",
      fprintf (stderr, "%s [%ld =? %ld]\n",
               IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)),
               IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)),
               (long) n, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl)));
               (long) n, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl)));
      ++n;
      ++n;
      virtuals = TREE_CHAIN (virtuals);
      virtuals = TREE_CHAIN (virtuals);
    }
    }
}
}
 
 
/* Build a representation for the qualified name SCOPE::NAME.  TYPE is
/* Build a representation for the qualified name SCOPE::NAME.  TYPE is
   the type of the result expression, if known, or NULL_TREE if the
   the type of the result expression, if known, or NULL_TREE if the
   resulting expression is type-dependent.  If TEMPLATE_P is true,
   resulting expression is type-dependent.  If TEMPLATE_P is true,
   NAME is known to be a template because the user explicitly used the
   NAME is known to be a template because the user explicitly used the
   "template" keyword after the "::".
   "template" keyword after the "::".
 
 
   All SCOPE_REFs should be built by use of this function.  */
   All SCOPE_REFs should be built by use of this function.  */
 
 
tree
tree
build_qualified_name (tree type, tree scope, tree name, bool template_p)
build_qualified_name (tree type, tree scope, tree name, bool template_p)
{
{
  tree t;
  tree t;
  if (type == error_mark_node
  if (type == error_mark_node
      || scope == error_mark_node
      || scope == error_mark_node
      || name == error_mark_node)
      || name == error_mark_node)
    return error_mark_node;
    return error_mark_node;
  t = build2 (SCOPE_REF, type, scope, name);
  t = build2 (SCOPE_REF, type, scope, name);
  QUALIFIED_NAME_IS_TEMPLATE (t) = template_p;
  QUALIFIED_NAME_IS_TEMPLATE (t) = template_p;
  if (type)
  if (type)
    t = convert_from_reference (t);
    t = convert_from_reference (t);
  return t;
  return t;
}
}
 
 
/* Returns nonzero if X is an expression for a (possibly overloaded)
/* Returns nonzero if X is an expression for a (possibly overloaded)
   function.  If "f" is a function or function template, "f", "c->f",
   function.  If "f" is a function or function template, "f", "c->f",
   "c.f", "C::f", and "f<int>" will all be considered possibly
   "c.f", "C::f", and "f<int>" will all be considered possibly
   overloaded functions.  Returns 2 if the function is actually
   overloaded functions.  Returns 2 if the function is actually
   overloaded, i.e., if it is impossible to know the type of the
   overloaded, i.e., if it is impossible to know the type of the
   function without performing overload resolution.  */
   function without performing overload resolution.  */
 
 
int
int
is_overloaded_fn (tree x)
is_overloaded_fn (tree x)
{
{
  /* A baselink is also considered an overloaded function.  */
  /* A baselink is also considered an overloaded function.  */
  if (TREE_CODE (x) == OFFSET_REF
  if (TREE_CODE (x) == OFFSET_REF
      || TREE_CODE (x) == COMPONENT_REF)
      || TREE_CODE (x) == COMPONENT_REF)
    x = TREE_OPERAND (x, 1);
    x = TREE_OPERAND (x, 1);
  if (BASELINK_P (x))
  if (BASELINK_P (x))
    x = BASELINK_FUNCTIONS (x);
    x = BASELINK_FUNCTIONS (x);
  if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
  if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
    x = TREE_OPERAND (x, 0);
    x = TREE_OPERAND (x, 0);
  if (DECL_FUNCTION_TEMPLATE_P (OVL_CURRENT (x))
  if (DECL_FUNCTION_TEMPLATE_P (OVL_CURRENT (x))
      || (TREE_CODE (x) == OVERLOAD && OVL_CHAIN (x)))
      || (TREE_CODE (x) == OVERLOAD && OVL_CHAIN (x)))
    return 2;
    return 2;
  return  (TREE_CODE (x) == FUNCTION_DECL
  return  (TREE_CODE (x) == FUNCTION_DECL
           || TREE_CODE (x) == OVERLOAD);
           || TREE_CODE (x) == OVERLOAD);
}
}
 
 
/* Returns true iff X is an expression for an overloaded function
/* Returns true iff X is an expression for an overloaded function
   whose type cannot be known without performing overload
   whose type cannot be known without performing overload
   resolution.  */
   resolution.  */
 
 
bool
bool
really_overloaded_fn (tree x)
really_overloaded_fn (tree x)
{
{
  return is_overloaded_fn (x) == 2;
  return is_overloaded_fn (x) == 2;
}
}
 
 
tree
tree
get_first_fn (tree from)
get_first_fn (tree from)
{
{
  gcc_assert (is_overloaded_fn (from));
  gcc_assert (is_overloaded_fn (from));
  /* A baselink is also considered an overloaded function.  */
  /* A baselink is also considered an overloaded function.  */
  if (TREE_CODE (from) == OFFSET_REF
  if (TREE_CODE (from) == OFFSET_REF
      || TREE_CODE (from) == COMPONENT_REF)
      || TREE_CODE (from) == COMPONENT_REF)
    from = TREE_OPERAND (from, 1);
    from = TREE_OPERAND (from, 1);
  if (BASELINK_P (from))
  if (BASELINK_P (from))
    from = BASELINK_FUNCTIONS (from);
    from = BASELINK_FUNCTIONS (from);
  if (TREE_CODE (from) == TEMPLATE_ID_EXPR)
  if (TREE_CODE (from) == TEMPLATE_ID_EXPR)
    from = TREE_OPERAND (from, 0);
    from = TREE_OPERAND (from, 0);
  return OVL_CURRENT (from);
  return OVL_CURRENT (from);
}
}
 
 
/* Return a new OVL node, concatenating it with the old one.  */
/* Return a new OVL node, concatenating it with the old one.  */
 
 
tree
tree
ovl_cons (tree decl, tree chain)
ovl_cons (tree decl, tree chain)
{
{
  tree result = make_node (OVERLOAD);
  tree result = make_node (OVERLOAD);
  TREE_TYPE (result) = unknown_type_node;
  TREE_TYPE (result) = unknown_type_node;
  OVL_FUNCTION (result) = decl;
  OVL_FUNCTION (result) = decl;
  TREE_CHAIN (result) = chain;
  TREE_CHAIN (result) = chain;
 
 
  return result;
  return result;
}
}
 
 
/* Build a new overloaded function. If this is the first one,
/* Build a new overloaded function. If this is the first one,
   just return it; otherwise, ovl_cons the _DECLs */
   just return it; otherwise, ovl_cons the _DECLs */
 
 
tree
tree
build_overload (tree decl, tree chain)
build_overload (tree decl, tree chain)
{
{
  if (! chain && TREE_CODE (decl) != TEMPLATE_DECL)
  if (! chain && TREE_CODE (decl) != TEMPLATE_DECL)
    return decl;
    return decl;
  if (chain && TREE_CODE (chain) != OVERLOAD)
  if (chain && TREE_CODE (chain) != OVERLOAD)
    chain = ovl_cons (chain, NULL_TREE);
    chain = ovl_cons (chain, NULL_TREE);
  return ovl_cons (decl, chain);
  return ovl_cons (decl, chain);
}
}
 
 


#define PRINT_RING_SIZE 4
#define PRINT_RING_SIZE 4
 
 
static const char *
static const char *
cxx_printable_name_internal (tree decl, int v, bool translate)
cxx_printable_name_internal (tree decl, int v, bool translate)
{
{
  static unsigned int uid_ring[PRINT_RING_SIZE];
  static unsigned int uid_ring[PRINT_RING_SIZE];
  static char *print_ring[PRINT_RING_SIZE];
  static char *print_ring[PRINT_RING_SIZE];
  static bool trans_ring[PRINT_RING_SIZE];
  static bool trans_ring[PRINT_RING_SIZE];
  static int ring_counter;
  static int ring_counter;
  int i;
  int i;
 
 
  /* Only cache functions.  */
  /* Only cache functions.  */
  if (v < 2
  if (v < 2
      || TREE_CODE (decl) != FUNCTION_DECL
      || TREE_CODE (decl) != FUNCTION_DECL
      || DECL_LANG_SPECIFIC (decl) == 0)
      || DECL_LANG_SPECIFIC (decl) == 0)
    return lang_decl_name (decl, v, translate);
    return lang_decl_name (decl, v, translate);
 
 
  /* See if this print name is lying around.  */
  /* See if this print name is lying around.  */
  for (i = 0; i < PRINT_RING_SIZE; i++)
  for (i = 0; i < PRINT_RING_SIZE; i++)
    if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i])
    if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i])
      /* yes, so return it.  */
      /* yes, so return it.  */
      return print_ring[i];
      return print_ring[i];
 
 
  if (++ring_counter == PRINT_RING_SIZE)
  if (++ring_counter == PRINT_RING_SIZE)
    ring_counter = 0;
    ring_counter = 0;
 
 
  if (current_function_decl != NULL_TREE)
  if (current_function_decl != NULL_TREE)
    {
    {
      /* There may be both translated and untranslated versions of the
      /* There may be both translated and untranslated versions of the
         name cached.  */
         name cached.  */
      for (i = 0; i < 2; i++)
      for (i = 0; i < 2; i++)
        {
        {
          if (uid_ring[ring_counter] == DECL_UID (current_function_decl))
          if (uid_ring[ring_counter] == DECL_UID (current_function_decl))
            ring_counter += 1;
            ring_counter += 1;
          if (ring_counter == PRINT_RING_SIZE)
          if (ring_counter == PRINT_RING_SIZE)
            ring_counter = 0;
            ring_counter = 0;
        }
        }
      gcc_assert (uid_ring[ring_counter] != DECL_UID (current_function_decl));
      gcc_assert (uid_ring[ring_counter] != DECL_UID (current_function_decl));
    }
    }
 
 
  if (print_ring[ring_counter])
  if (print_ring[ring_counter])
    free (print_ring[ring_counter]);
    free (print_ring[ring_counter]);
 
 
  print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v, translate));
  print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v, translate));
  uid_ring[ring_counter] = DECL_UID (decl);
  uid_ring[ring_counter] = DECL_UID (decl);
  trans_ring[ring_counter] = translate;
  trans_ring[ring_counter] = translate;
  return print_ring[ring_counter];
  return print_ring[ring_counter];
}
}
 
 
const char *
const char *
cxx_printable_name (tree decl, int v)
cxx_printable_name (tree decl, int v)
{
{
  return cxx_printable_name_internal (decl, v, false);
  return cxx_printable_name_internal (decl, v, false);
}
}
 
 
const char *
const char *
cxx_printable_name_translate (tree decl, int v)
cxx_printable_name_translate (tree decl, int v)
{
{
  return cxx_printable_name_internal (decl, v, true);
  return cxx_printable_name_internal (decl, v, true);
}
}


/* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
/* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
   listed in RAISES.  */
   listed in RAISES.  */
 
 
tree
tree
build_exception_variant (tree type, tree raises)
build_exception_variant (tree type, tree raises)
{
{
  tree v = TYPE_MAIN_VARIANT (type);
  tree v = TYPE_MAIN_VARIANT (type);
  int type_quals = TYPE_QUALS (type);
  int type_quals = TYPE_QUALS (type);
 
 
  for (; v; v = TYPE_NEXT_VARIANT (v))
  for (; v; v = TYPE_NEXT_VARIANT (v))
    if (check_qualified_type (v, type, type_quals)
    if (check_qualified_type (v, type, type_quals)
        && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (v), 1))
        && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (v), 1))
      return v;
      return v;
 
 
  /* Need to build a new variant.  */
  /* Need to build a new variant.  */
  v = build_variant_type_copy (type);
  v = build_variant_type_copy (type);
  TYPE_RAISES_EXCEPTIONS (v) = raises;
  TYPE_RAISES_EXCEPTIONS (v) = raises;
  return v;
  return v;
}
}
 
 
/* Given a TEMPLATE_TEMPLATE_PARM node T, create a new
/* Given a TEMPLATE_TEMPLATE_PARM node T, create a new
   BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template
   BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template
   arguments.  */
   arguments.  */
 
 
tree
tree
bind_template_template_parm (tree t, tree newargs)
bind_template_template_parm (tree t, tree newargs)
{
{
  tree decl = TYPE_NAME (t);
  tree decl = TYPE_NAME (t);
  tree t2;
  tree t2;
 
 
  t2 = cxx_make_type (BOUND_TEMPLATE_TEMPLATE_PARM);
  t2 = cxx_make_type (BOUND_TEMPLATE_TEMPLATE_PARM);
  decl = build_decl (input_location,
  decl = build_decl (input_location,
                     TYPE_DECL, DECL_NAME (decl), NULL_TREE);
                     TYPE_DECL, DECL_NAME (decl), NULL_TREE);
 
 
  /* These nodes have to be created to reflect new TYPE_DECL and template
  /* These nodes have to be created to reflect new TYPE_DECL and template
     arguments.  */
     arguments.  */
  TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t));
  TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t));
  TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl;
  TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl;
  TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
  TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
    = build_template_info (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t), newargs);
    = build_template_info (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t), newargs);
 
 
  TREE_TYPE (decl) = t2;
  TREE_TYPE (decl) = t2;
  TYPE_NAME (t2) = decl;
  TYPE_NAME (t2) = decl;
  TYPE_STUB_DECL (t2) = decl;
  TYPE_STUB_DECL (t2) = decl;
  TYPE_SIZE (t2) = 0;
  TYPE_SIZE (t2) = 0;
  SET_TYPE_STRUCTURAL_EQUALITY (t2);
  SET_TYPE_STRUCTURAL_EQUALITY (t2);
 
 
  return t2;
  return t2;
}
}
 
 
/* Called from count_trees via walk_tree.  */
/* Called from count_trees via walk_tree.  */
 
 
static tree
static tree
count_trees_r (tree *tp, int *walk_subtrees, void *data)
count_trees_r (tree *tp, int *walk_subtrees, void *data)
{
{
  ++*((int *) data);
  ++*((int *) data);
 
 
  if (TYPE_P (*tp))
  if (TYPE_P (*tp))
    *walk_subtrees = 0;
    *walk_subtrees = 0;
 
 
  return NULL_TREE;
  return NULL_TREE;
}
}
 
 
/* Debugging function for measuring the rough complexity of a tree
/* Debugging function for measuring the rough complexity of a tree
   representation.  */
   representation.  */
 
 
int
int
count_trees (tree t)
count_trees (tree t)
{
{
  int n_trees = 0;
  int n_trees = 0;
  cp_walk_tree_without_duplicates (&t, count_trees_r, &n_trees);
  cp_walk_tree_without_duplicates (&t, count_trees_r, &n_trees);
  return n_trees;
  return n_trees;
}
}
 
 
/* Called from verify_stmt_tree via walk_tree.  */
/* Called from verify_stmt_tree via walk_tree.  */
 
 
static tree
static tree
verify_stmt_tree_r (tree* tp,
verify_stmt_tree_r (tree* tp,
                    int* walk_subtrees ATTRIBUTE_UNUSED ,
                    int* walk_subtrees ATTRIBUTE_UNUSED ,
                    void* data)
                    void* data)
{
{
  tree t = *tp;
  tree t = *tp;
  htab_t *statements = (htab_t *) data;
  htab_t *statements = (htab_t *) data;
  void **slot;
  void **slot;
 
 
  if (!STATEMENT_CODE_P (TREE_CODE (t)))
  if (!STATEMENT_CODE_P (TREE_CODE (t)))
    return NULL_TREE;
    return NULL_TREE;
 
 
  /* If this statement is already present in the hash table, then
  /* If this statement is already present in the hash table, then
     there is a circularity in the statement tree.  */
     there is a circularity in the statement tree.  */
  gcc_assert (!htab_find (*statements, t));
  gcc_assert (!htab_find (*statements, t));
 
 
  slot = htab_find_slot (*statements, t, INSERT);
  slot = htab_find_slot (*statements, t, INSERT);
  *slot = t;
  *slot = t;
 
 
  return NULL_TREE;
  return NULL_TREE;
}
}
 
 
/* Debugging function to check that the statement T has not been
/* Debugging function to check that the statement T has not been
   corrupted.  For now, this function simply checks that T contains no
   corrupted.  For now, this function simply checks that T contains no
   circularities.  */
   circularities.  */
 
 
void
void
verify_stmt_tree (tree t)
verify_stmt_tree (tree t)
{
{
  htab_t statements;
  htab_t statements;
  statements = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
  statements = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
  cp_walk_tree (&t, verify_stmt_tree_r, &statements, NULL);
  cp_walk_tree (&t, verify_stmt_tree_r, &statements, NULL);
  htab_delete (statements);
  htab_delete (statements);
}
}
 
 
/* Check if the type T depends on a type with no linkage and if so, return
/* Check if the type T depends on a type with no linkage and if so, return
   it.  If RELAXED_P then do not consider a class type declared within
   it.  If RELAXED_P then do not consider a class type declared within
   a vague-linkage function to have no linkage.  */
   a vague-linkage function to have no linkage.  */
 
 
tree
tree
no_linkage_check (tree t, bool relaxed_p)
no_linkage_check (tree t, bool relaxed_p)
{
{
  tree r;
  tree r;
 
 
  /* There's no point in checking linkage on template functions; we
  /* There's no point in checking linkage on template functions; we
     can't know their complete types.  */
     can't know their complete types.  */
  if (processing_template_decl)
  if (processing_template_decl)
    return NULL_TREE;
    return NULL_TREE;
 
 
  switch (TREE_CODE (t))
  switch (TREE_CODE (t))
    {
    {
    case RECORD_TYPE:
    case RECORD_TYPE:
      if (TYPE_PTRMEMFUNC_P (t))
      if (TYPE_PTRMEMFUNC_P (t))
        goto ptrmem;
        goto ptrmem;
      /* Lambda types that don't have mangling scope have no linkage.  We
      /* Lambda types that don't have mangling scope have no linkage.  We
         check CLASSTYPE_LAMBDA_EXPR here rather than LAMBDA_TYPE_P because
         check CLASSTYPE_LAMBDA_EXPR here rather than LAMBDA_TYPE_P because
         when we get here from pushtag none of the lambda information is
         when we get here from pushtag none of the lambda information is
         set up yet, so we want to assume that the lambda has linkage and
         set up yet, so we want to assume that the lambda has linkage and
         fix it up later if not.  */
         fix it up later if not.  */
      if (CLASSTYPE_LAMBDA_EXPR (t)
      if (CLASSTYPE_LAMBDA_EXPR (t)
          && LAMBDA_TYPE_EXTRA_SCOPE (t) == NULL_TREE)
          && LAMBDA_TYPE_EXTRA_SCOPE (t) == NULL_TREE)
        return t;
        return t;
      /* Fall through.  */
      /* Fall through.  */
    case UNION_TYPE:
    case UNION_TYPE:
      if (!CLASS_TYPE_P (t))
      if (!CLASS_TYPE_P (t))
        return NULL_TREE;
        return NULL_TREE;
      /* Fall through.  */
      /* Fall through.  */
    case ENUMERAL_TYPE:
    case ENUMERAL_TYPE:
      /* Only treat anonymous types as having no linkage if they're at
      /* Only treat anonymous types as having no linkage if they're at
         namespace scope.  This is core issue 966.  */
         namespace scope.  This is core issue 966.  */
      if (TYPE_ANONYMOUS_P (t) && TYPE_NAMESPACE_SCOPE_P (t))
      if (TYPE_ANONYMOUS_P (t) && TYPE_NAMESPACE_SCOPE_P (t))
        return t;
        return t;
 
 
      for (r = CP_TYPE_CONTEXT (t); ; )
      for (r = CP_TYPE_CONTEXT (t); ; )
        {
        {
          /* If we're a nested type of a !TREE_PUBLIC class, we might not
          /* If we're a nested type of a !TREE_PUBLIC class, we might not
             have linkage, or we might just be in an anonymous namespace.
             have linkage, or we might just be in an anonymous namespace.
             If we're in a TREE_PUBLIC class, we have linkage.  */
             If we're in a TREE_PUBLIC class, we have linkage.  */
          if (TYPE_P (r) && !TREE_PUBLIC (TYPE_NAME (r)))
          if (TYPE_P (r) && !TREE_PUBLIC (TYPE_NAME (r)))
            return no_linkage_check (TYPE_CONTEXT (t), relaxed_p);
            return no_linkage_check (TYPE_CONTEXT (t), relaxed_p);
          else if (TREE_CODE (r) == FUNCTION_DECL)
          else if (TREE_CODE (r) == FUNCTION_DECL)
            {
            {
              if (!relaxed_p || !vague_linkage_p (r))
              if (!relaxed_p || !vague_linkage_p (r))
                return t;
                return t;
              else
              else
                r = CP_DECL_CONTEXT (r);
                r = CP_DECL_CONTEXT (r);
            }
            }
          else
          else
            break;
            break;
        }
        }
 
 
      return NULL_TREE;
      return NULL_TREE;
 
 
    case ARRAY_TYPE:
    case ARRAY_TYPE:
    case POINTER_TYPE:
    case POINTER_TYPE:
    case REFERENCE_TYPE:
    case REFERENCE_TYPE:
      return no_linkage_check (TREE_TYPE (t), relaxed_p);
      return no_linkage_check (TREE_TYPE (t), relaxed_p);
 
 
    case OFFSET_TYPE:
    case OFFSET_TYPE:
    ptrmem:
    ptrmem:
      r = no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t),
      r = no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t),
                            relaxed_p);
                            relaxed_p);
      if (r)
      if (r)
        return r;
        return r;
      return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t), relaxed_p);
      return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t), relaxed_p);
 
 
    case METHOD_TYPE:
    case METHOD_TYPE:
      r = no_linkage_check (TYPE_METHOD_BASETYPE (t), relaxed_p);
      r = no_linkage_check (TYPE_METHOD_BASETYPE (t), relaxed_p);
      if (r)
      if (r)
        return r;
        return r;
      /* Fall through.  */
      /* Fall through.  */
    case FUNCTION_TYPE:
    case FUNCTION_TYPE:
      {
      {
        tree parm;
        tree parm;
        for (parm = TYPE_ARG_TYPES (t);
        for (parm = TYPE_ARG_TYPES (t);
             parm && parm != void_list_node;
             parm && parm != void_list_node;
             parm = TREE_CHAIN (parm))
             parm = TREE_CHAIN (parm))
          {
          {
            r = no_linkage_check (TREE_VALUE (parm), relaxed_p);
            r = no_linkage_check (TREE_VALUE (parm), relaxed_p);
            if (r)
            if (r)
              return r;
              return r;
          }
          }
        return no_linkage_check (TREE_TYPE (t), relaxed_p);
        return no_linkage_check (TREE_TYPE (t), relaxed_p);
      }
      }
 
 
    default:
    default:
      return NULL_TREE;
      return NULL_TREE;
    }
    }
}
}
 
 
#ifdef GATHER_STATISTICS
#ifdef GATHER_STATISTICS
extern int depth_reached;
extern int depth_reached;
#endif
#endif
 
 
void
void
cxx_print_statistics (void)
cxx_print_statistics (void)
{
{
  print_search_statistics ();
  print_search_statistics ();
  print_class_statistics ();
  print_class_statistics ();
#ifdef GATHER_STATISTICS
#ifdef GATHER_STATISTICS
  fprintf (stderr, "maximum template instantiation depth reached: %d\n",
  fprintf (stderr, "maximum template instantiation depth reached: %d\n",
           depth_reached);
           depth_reached);
#endif
#endif
}
}
 
 
/* Return, as an INTEGER_CST node, the number of elements for TYPE
/* Return, as an INTEGER_CST node, the number of elements for TYPE
   (which is an ARRAY_TYPE).  This counts only elements of the top
   (which is an ARRAY_TYPE).  This counts only elements of the top
   array.  */
   array.  */
 
 
tree
tree
array_type_nelts_top (tree type)
array_type_nelts_top (tree type)
{
{
  return fold_build2_loc (input_location,
  return fold_build2_loc (input_location,
                      PLUS_EXPR, sizetype,
                      PLUS_EXPR, sizetype,
                      array_type_nelts (type),
                      array_type_nelts (type),
                      size_one_node);
                      size_one_node);
}
}
 
 
/* Return, as an INTEGER_CST node, the number of elements for TYPE
/* Return, as an INTEGER_CST node, the number of elements for TYPE
   (which is an ARRAY_TYPE).  This one is a recursive count of all
   (which is an ARRAY_TYPE).  This one is a recursive count of all
   ARRAY_TYPEs that are clumped together.  */
   ARRAY_TYPEs that are clumped together.  */
 
 
tree
tree
array_type_nelts_total (tree type)
array_type_nelts_total (tree type)
{
{
  tree sz = array_type_nelts_top (type);
  tree sz = array_type_nelts_top (type);
  type = TREE_TYPE (type);
  type = TREE_TYPE (type);
  while (TREE_CODE (type) == ARRAY_TYPE)
  while (TREE_CODE (type) == ARRAY_TYPE)
    {
    {
      tree n = array_type_nelts_top (type);
      tree n = array_type_nelts_top (type);
      sz = fold_build2_loc (input_location,
      sz = fold_build2_loc (input_location,
                        MULT_EXPR, sizetype, sz, n);
                        MULT_EXPR, sizetype, sz, n);
      type = TREE_TYPE (type);
      type = TREE_TYPE (type);
    }
    }
  return sz;
  return sz;
}
}
 
 
/* Called from break_out_target_exprs via mapcar.  */
/* Called from break_out_target_exprs via mapcar.  */
 
 
static tree
static tree
bot_manip (tree* tp, int* walk_subtrees, void* data)
bot_manip (tree* tp, int* walk_subtrees, void* data)
{
{
  splay_tree target_remap = ((splay_tree) data);
  splay_tree target_remap = ((splay_tree) data);
  tree t = *tp;
  tree t = *tp;
 
 
  if (!TYPE_P (t) && TREE_CONSTANT (t))
  if (!TYPE_P (t) && TREE_CONSTANT (t))
    {
    {
      /* There can't be any TARGET_EXPRs or their slot variables below
      /* There can't be any TARGET_EXPRs or their slot variables below
         this point.  We used to check !TREE_SIDE_EFFECTS, but then we
         this point.  We used to check !TREE_SIDE_EFFECTS, but then we
         failed to copy an ADDR_EXPR of the slot VAR_DECL.  */
         failed to copy an ADDR_EXPR of the slot VAR_DECL.  */
      *walk_subtrees = 0;
      *walk_subtrees = 0;
      return NULL_TREE;
      return NULL_TREE;
    }
    }
  if (TREE_CODE (t) == TARGET_EXPR)
  if (TREE_CODE (t) == TARGET_EXPR)
    {
    {
      tree u;
      tree u;
 
 
      if (TREE_CODE (TREE_OPERAND (t, 1)) == AGGR_INIT_EXPR)
      if (TREE_CODE (TREE_OPERAND (t, 1)) == AGGR_INIT_EXPR)
        u = build_cplus_new (TREE_TYPE (t), TREE_OPERAND (t, 1));
        u = build_cplus_new (TREE_TYPE (t), TREE_OPERAND (t, 1));
      else
      else
        u = build_target_expr_with_type (TREE_OPERAND (t, 1), TREE_TYPE (t));
        u = build_target_expr_with_type (TREE_OPERAND (t, 1), TREE_TYPE (t));
 
 
      /* Map the old variable to the new one.  */
      /* Map the old variable to the new one.  */
      splay_tree_insert (target_remap,
      splay_tree_insert (target_remap,
                         (splay_tree_key) TREE_OPERAND (t, 0),
                         (splay_tree_key) TREE_OPERAND (t, 0),
                         (splay_tree_value) TREE_OPERAND (u, 0));
                         (splay_tree_value) TREE_OPERAND (u, 0));
 
 
      TREE_OPERAND (u, 1) = break_out_target_exprs (TREE_OPERAND (u, 1));
      TREE_OPERAND (u, 1) = break_out_target_exprs (TREE_OPERAND (u, 1));
 
 
      /* Replace the old expression with the new version.  */
      /* Replace the old expression with the new version.  */
      *tp = u;
      *tp = u;
      /* We don't have to go below this point; the recursive call to
      /* We don't have to go below this point; the recursive call to
         break_out_target_exprs will have handled anything below this
         break_out_target_exprs will have handled anything below this
         point.  */
         point.  */
      *walk_subtrees = 0;
      *walk_subtrees = 0;
      return NULL_TREE;
      return NULL_TREE;
    }
    }
 
 
  /* Make a copy of this node.  */
  /* Make a copy of this node.  */
  return copy_tree_r (tp, walk_subtrees, NULL);
  return copy_tree_r (tp, walk_subtrees, NULL);
}
}
 
 
/* Replace all remapped VAR_DECLs in T with their new equivalents.
/* Replace all remapped VAR_DECLs in T with their new equivalents.
   DATA is really a splay-tree mapping old variables to new
   DATA is really a splay-tree mapping old variables to new
   variables.  */
   variables.  */
 
 
static tree
static tree
bot_replace (tree* t,
bot_replace (tree* t,
             int* walk_subtrees ATTRIBUTE_UNUSED ,
             int* walk_subtrees ATTRIBUTE_UNUSED ,
             void* data)
             void* data)
{
{
  splay_tree target_remap = ((splay_tree) data);
  splay_tree target_remap = ((splay_tree) data);
 
 
  if (TREE_CODE (*t) == VAR_DECL)
  if (TREE_CODE (*t) == VAR_DECL)
    {
    {
      splay_tree_node n = splay_tree_lookup (target_remap,
      splay_tree_node n = splay_tree_lookup (target_remap,
                                             (splay_tree_key) *t);
                                             (splay_tree_key) *t);
      if (n)
      if (n)
        *t = (tree) n->value;
        *t = (tree) n->value;
    }
    }
 
 
  return NULL_TREE;
  return NULL_TREE;
}
}
 
 
/* When we parse a default argument expression, we may create
/* When we parse a default argument expression, we may create
   temporary variables via TARGET_EXPRs.  When we actually use the
   temporary variables via TARGET_EXPRs.  When we actually use the
   default-argument expression, we make a copy of the expression, but
   default-argument expression, we make a copy of the expression, but
   we must replace the temporaries with appropriate local versions.  */
   we must replace the temporaries with appropriate local versions.  */
 
 
tree
tree
break_out_target_exprs (tree t)
break_out_target_exprs (tree t)
{
{
  static int target_remap_count;
  static int target_remap_count;
  static splay_tree target_remap;
  static splay_tree target_remap;
 
 
  if (!target_remap_count++)
  if (!target_remap_count++)
    target_remap = splay_tree_new (splay_tree_compare_pointers,
    target_remap = splay_tree_new (splay_tree_compare_pointers,
                                   /*splay_tree_delete_key_fn=*/NULL,
                                   /*splay_tree_delete_key_fn=*/NULL,
                                   /*splay_tree_delete_value_fn=*/NULL);
                                   /*splay_tree_delete_value_fn=*/NULL);
  cp_walk_tree (&t, bot_manip, target_remap, NULL);
  cp_walk_tree (&t, bot_manip, target_remap, NULL);
  cp_walk_tree (&t, bot_replace, target_remap, NULL);
  cp_walk_tree (&t, bot_replace, target_remap, NULL);
 
 
  if (!--target_remap_count)
  if (!--target_remap_count)
    {
    {
      splay_tree_delete (target_remap);
      splay_tree_delete (target_remap);
      target_remap = NULL;
      target_remap = NULL;
    }
    }
 
 
  return t;
  return t;
}
}
 
 
/* Similar to `build_nt', but for template definitions of dependent
/* Similar to `build_nt', but for template definitions of dependent
   expressions  */
   expressions  */
 
 
tree
tree
build_min_nt (enum tree_code code, ...)
build_min_nt (enum tree_code code, ...)
{
{
  tree t;
  tree t;
  int length;
  int length;
  int i;
  int i;
  va_list p;
  va_list p;
 
 
  gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
  gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
 
 
  va_start (p, code);
  va_start (p, code);
 
 
  t = make_node (code);
  t = make_node (code);
  length = TREE_CODE_LENGTH (code);
  length = TREE_CODE_LENGTH (code);
 
 
  for (i = 0; i < length; i++)
  for (i = 0; i < length; i++)
    {
    {
      tree x = va_arg (p, tree);
      tree x = va_arg (p, tree);
      TREE_OPERAND (t, i) = x;
      TREE_OPERAND (t, i) = x;
    }
    }
 
 
  va_end (p);
  va_end (p);
  return t;
  return t;
}
}
 
 
 
 
/* Similar to `build', but for template definitions.  */
/* Similar to `build', but for template definitions.  */
 
 
tree
tree
build_min (enum tree_code code, tree tt, ...)
build_min (enum tree_code code, tree tt, ...)
{
{
  tree t;
  tree t;
  int length;
  int length;
  int i;
  int i;
  va_list p;
  va_list p;
 
 
  gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
  gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
 
 
  va_start (p, tt);
  va_start (p, tt);
 
 
  t = make_node (code);
  t = make_node (code);
  length = TREE_CODE_LENGTH (code);
  length = TREE_CODE_LENGTH (code);
  TREE_TYPE (t) = tt;
  TREE_TYPE (t) = tt;
 
 
  for (i = 0; i < length; i++)
  for (i = 0; i < length; i++)
    {
    {
      tree x = va_arg (p, tree);
      tree x = va_arg (p, tree);
      TREE_OPERAND (t, i) = x;
      TREE_OPERAND (t, i) = x;
      if (x && !TYPE_P (x) && TREE_SIDE_EFFECTS (x))
      if (x && !TYPE_P (x) && TREE_SIDE_EFFECTS (x))
        TREE_SIDE_EFFECTS (t) = 1;
        TREE_SIDE_EFFECTS (t) = 1;
    }
    }
 
 
  va_end (p);
  va_end (p);
  return t;
  return t;
}
}
 
 
/* Similar to `build', but for template definitions of non-dependent
/* Similar to `build', but for template definitions of non-dependent
   expressions. NON_DEP is the non-dependent expression that has been
   expressions. NON_DEP is the non-dependent expression that has been
   built.  */
   built.  */
 
 
tree
tree
build_min_non_dep (enum tree_code code, tree non_dep, ...)
build_min_non_dep (enum tree_code code, tree non_dep, ...)
{
{
  tree t;
  tree t;
  int length;
  int length;
  int i;
  int i;
  va_list p;
  va_list p;
 
 
  gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
  gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
 
 
  va_start (p, non_dep);
  va_start (p, non_dep);
 
 
  t = make_node (code);
  t = make_node (code);
  length = TREE_CODE_LENGTH (code);
  length = TREE_CODE_LENGTH (code);
  TREE_TYPE (t) = TREE_TYPE (non_dep);
  TREE_TYPE (t) = TREE_TYPE (non_dep);
  TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
  TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
 
 
  for (i = 0; i < length; i++)
  for (i = 0; i < length; i++)
    {
    {
      tree x = va_arg (p, tree);
      tree x = va_arg (p, tree);
      TREE_OPERAND (t, i) = x;
      TREE_OPERAND (t, i) = x;
    }
    }
 
 
  if (code == COMPOUND_EXPR && TREE_CODE (non_dep) != COMPOUND_EXPR)
  if (code == COMPOUND_EXPR && TREE_CODE (non_dep) != COMPOUND_EXPR)
    /* This should not be considered a COMPOUND_EXPR, because it
    /* This should not be considered a COMPOUND_EXPR, because it
       resolves to an overload.  */
       resolves to an overload.  */
    COMPOUND_EXPR_OVERLOADED (t) = 1;
    COMPOUND_EXPR_OVERLOADED (t) = 1;
 
 
  va_end (p);
  va_end (p);
  return t;
  return t;
}
}
 
 
/* Similar to `build_call_list', but for template definitions of non-dependent
/* Similar to `build_call_list', but for template definitions of non-dependent
   expressions. NON_DEP is the non-dependent expression that has been
   expressions. NON_DEP is the non-dependent expression that has been
   built.  */
   built.  */
 
 
tree
tree
build_min_non_dep_call_vec (tree non_dep, tree fn, VEC(tree,gc) *argvec)
build_min_non_dep_call_vec (tree non_dep, tree fn, VEC(tree,gc) *argvec)
{
{
  tree t = build_nt_call_vec (fn, argvec);
  tree t = build_nt_call_vec (fn, argvec);
  TREE_TYPE (t) = TREE_TYPE (non_dep);
  TREE_TYPE (t) = TREE_TYPE (non_dep);
  TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
  TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
  return t;
  return t;
}
}
 
 
tree
tree
get_type_decl (tree t)
get_type_decl (tree t)
{
{
  if (TREE_CODE (t) == TYPE_DECL)
  if (TREE_CODE (t) == TYPE_DECL)
    return t;
    return t;
  if (TYPE_P (t))
  if (TYPE_P (t))
    return TYPE_STUB_DECL (t);
    return TYPE_STUB_DECL (t);
  gcc_assert (t == error_mark_node);
  gcc_assert (t == error_mark_node);
  return t;
  return t;
}
}
 
 
/* Returns the namespace that contains DECL, whether directly or
/* Returns the namespace that contains DECL, whether directly or
   indirectly.  */
   indirectly.  */
 
 
tree
tree
decl_namespace_context (tree decl)
decl_namespace_context (tree decl)
{
{
  while (1)
  while (1)
    {
    {
      if (TREE_CODE (decl) == NAMESPACE_DECL)
      if (TREE_CODE (decl) == NAMESPACE_DECL)
        return decl;
        return decl;
      else if (TYPE_P (decl))
      else if (TYPE_P (decl))
        decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
        decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
      else
      else
        decl = CP_DECL_CONTEXT (decl);
        decl = CP_DECL_CONTEXT (decl);
    }
    }
}
}
 
 
/* Returns true if decl is within an anonymous namespace, however deeply
/* Returns true if decl is within an anonymous namespace, however deeply
   nested, or false otherwise.  */
   nested, or false otherwise.  */
 
 
bool
bool
decl_anon_ns_mem_p (const_tree decl)
decl_anon_ns_mem_p (const_tree decl)
{
{
  while (1)
  while (1)
    {
    {
      if (decl == NULL_TREE || decl == error_mark_node)
      if (decl == NULL_TREE || decl == error_mark_node)
        return false;
        return false;
      if (TREE_CODE (decl) == NAMESPACE_DECL
      if (TREE_CODE (decl) == NAMESPACE_DECL
          && DECL_NAME (decl) == NULL_TREE)
          && DECL_NAME (decl) == NULL_TREE)
        return true;
        return true;
      /* Classes and namespaces inside anonymous namespaces have
      /* Classes and namespaces inside anonymous namespaces have
         TREE_PUBLIC == 0, so we can shortcut the search.  */
         TREE_PUBLIC == 0, so we can shortcut the search.  */
      else if (TYPE_P (decl))
      else if (TYPE_P (decl))
        return (TREE_PUBLIC (TYPE_NAME (decl)) == 0);
        return (TREE_PUBLIC (TYPE_NAME (decl)) == 0);
      else if (TREE_CODE (decl) == NAMESPACE_DECL)
      else if (TREE_CODE (decl) == NAMESPACE_DECL)
        return (TREE_PUBLIC (decl) == 0);
        return (TREE_PUBLIC (decl) == 0);
      else
      else
        decl = DECL_CONTEXT (decl);
        decl = DECL_CONTEXT (decl);
    }
    }
}
}
 
 
/* Return truthvalue of whether T1 is the same tree structure as T2.
/* Return truthvalue of whether T1 is the same tree structure as T2.
   Return 1 if they are the same. Return 0 if they are different.  */
   Return 1 if they are the same. Return 0 if they are different.  */
 
 
bool
bool
cp_tree_equal (tree t1, tree t2)
cp_tree_equal (tree t1, tree t2)
{
{
  enum tree_code code1, code2;
  enum tree_code code1, code2;
 
 
  if (t1 == t2)
  if (t1 == t2)
    return true;
    return true;
  if (!t1 || !t2)
  if (!t1 || !t2)
    return false;
    return false;
 
 
  for (code1 = TREE_CODE (t1);
  for (code1 = TREE_CODE (t1);
       CONVERT_EXPR_CODE_P (code1)
       CONVERT_EXPR_CODE_P (code1)
         || code1 == NON_LVALUE_EXPR;
         || code1 == NON_LVALUE_EXPR;
       code1 = TREE_CODE (t1))
       code1 = TREE_CODE (t1))
    t1 = TREE_OPERAND (t1, 0);
    t1 = TREE_OPERAND (t1, 0);
  for (code2 = TREE_CODE (t2);
  for (code2 = TREE_CODE (t2);
       CONVERT_EXPR_CODE_P (code2)
       CONVERT_EXPR_CODE_P (code2)
         || code1 == NON_LVALUE_EXPR;
         || code1 == NON_LVALUE_EXPR;
       code2 = TREE_CODE (t2))
       code2 = TREE_CODE (t2))
    t2 = TREE_OPERAND (t2, 0);
    t2 = TREE_OPERAND (t2, 0);
 
 
  /* They might have become equal now.  */
  /* They might have become equal now.  */
  if (t1 == t2)
  if (t1 == t2)
    return true;
    return true;
 
 
  if (code1 != code2)
  if (code1 != code2)
    return false;
    return false;
 
 
  switch (code1)
  switch (code1)
    {
    {
    case INTEGER_CST:
    case INTEGER_CST:
      return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
      return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
        && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
        && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
 
 
    case REAL_CST:
    case REAL_CST:
      return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
      return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
 
 
    case STRING_CST:
    case STRING_CST:
      return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
      return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
        && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
        && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
                    TREE_STRING_LENGTH (t1));
                    TREE_STRING_LENGTH (t1));
 
 
    case FIXED_CST:
    case FIXED_CST:
      return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1),
      return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1),
                                     TREE_FIXED_CST (t2));
                                     TREE_FIXED_CST (t2));
 
 
    case COMPLEX_CST:
    case COMPLEX_CST:
      return cp_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
      return cp_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
        && cp_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
        && cp_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
 
 
    case CONSTRUCTOR:
    case CONSTRUCTOR:
      /* We need to do this when determining whether or not two
      /* We need to do this when determining whether or not two
         non-type pointer to member function template arguments
         non-type pointer to member function template arguments
         are the same.  */
         are the same.  */
      if (!(same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
      if (!(same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
            /* The first operand is RTL.  */
            /* The first operand is RTL.  */
            && TREE_OPERAND (t1, 0) == TREE_OPERAND (t2, 0)))
            && TREE_OPERAND (t1, 0) == TREE_OPERAND (t2, 0)))
        return false;
        return false;
      return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
      return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
 
 
    case TREE_LIST:
    case TREE_LIST:
      if (!cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
      if (!cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
        return false;
        return false;
      if (!cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
      if (!cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
        return false;
        return false;
      return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
      return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
 
 
    case SAVE_EXPR:
    case SAVE_EXPR:
      return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
      return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
 
 
    case CALL_EXPR:
    case CALL_EXPR:
      {
      {
        tree arg1, arg2;
        tree arg1, arg2;
        call_expr_arg_iterator iter1, iter2;
        call_expr_arg_iterator iter1, iter2;
        if (!cp_tree_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2)))
        if (!cp_tree_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2)))
          return false;
          return false;
        for (arg1 = first_call_expr_arg (t1, &iter1),
        for (arg1 = first_call_expr_arg (t1, &iter1),
               arg2 = first_call_expr_arg (t2, &iter2);
               arg2 = first_call_expr_arg (t2, &iter2);
             arg1 && arg2;
             arg1 && arg2;
             arg1 = next_call_expr_arg (&iter1),
             arg1 = next_call_expr_arg (&iter1),
               arg2 = next_call_expr_arg (&iter2))
               arg2 = next_call_expr_arg (&iter2))
          if (!cp_tree_equal (arg1, arg2))
          if (!cp_tree_equal (arg1, arg2))
            return false;
            return false;
        if (arg1 || arg2)
        if (arg1 || arg2)
          return false;
          return false;
        return true;
        return true;
      }
      }
 
 
    case TARGET_EXPR:
    case TARGET_EXPR:
      {
      {
        tree o1 = TREE_OPERAND (t1, 0);
        tree o1 = TREE_OPERAND (t1, 0);
        tree o2 = TREE_OPERAND (t2, 0);
        tree o2 = TREE_OPERAND (t2, 0);
 
 
        /* Special case: if either target is an unallocated VAR_DECL,
        /* Special case: if either target is an unallocated VAR_DECL,
           it means that it's going to be unified with whatever the
           it means that it's going to be unified with whatever the
           TARGET_EXPR is really supposed to initialize, so treat it
           TARGET_EXPR is really supposed to initialize, so treat it
           as being equivalent to anything.  */
           as being equivalent to anything.  */
        if (TREE_CODE (o1) == VAR_DECL && DECL_NAME (o1) == NULL_TREE
        if (TREE_CODE (o1) == VAR_DECL && DECL_NAME (o1) == NULL_TREE
            && !DECL_RTL_SET_P (o1))
            && !DECL_RTL_SET_P (o1))
          /*Nop*/;
          /*Nop*/;
        else if (TREE_CODE (o2) == VAR_DECL && DECL_NAME (o2) == NULL_TREE
        else if (TREE_CODE (o2) == VAR_DECL && DECL_NAME (o2) == NULL_TREE
                 && !DECL_RTL_SET_P (o2))
                 && !DECL_RTL_SET_P (o2))
          /*Nop*/;
          /*Nop*/;
        else if (!cp_tree_equal (o1, o2))
        else if (!cp_tree_equal (o1, o2))
          return false;
          return false;
 
 
        return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
        return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
      }
      }
 
 
    case WITH_CLEANUP_EXPR:
    case WITH_CLEANUP_EXPR:
      if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
      if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
        return false;
        return false;
      return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
      return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
 
 
    case COMPONENT_REF:
    case COMPONENT_REF:
      if (TREE_OPERAND (t1, 1) != TREE_OPERAND (t2, 1))
      if (TREE_OPERAND (t1, 1) != TREE_OPERAND (t2, 1))
        return false;
        return false;
      return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
      return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
 
 
    case PARM_DECL:
    case PARM_DECL:
      /* For comparing uses of parameters in late-specified return types
      /* For comparing uses of parameters in late-specified return types
         with an out-of-class definition of the function.  */
         with an out-of-class definition of the function.  */
      if (same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
      if (same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
          && DECL_PARM_INDEX (t1) == DECL_PARM_INDEX (t2))
          && DECL_PARM_INDEX (t1) == DECL_PARM_INDEX (t2))
        return true;
        return true;
      else
      else
        return false;
        return false;
 
 
    case VAR_DECL:
    case VAR_DECL:
    case CONST_DECL:
    case CONST_DECL:
    case FUNCTION_DECL:
    case FUNCTION_DECL:
    case TEMPLATE_DECL:
    case TEMPLATE_DECL:
    case IDENTIFIER_NODE:
    case IDENTIFIER_NODE:
    case SSA_NAME:
    case SSA_NAME:
      return false;
      return false;
 
 
    case BASELINK:
    case BASELINK:
      return (BASELINK_BINFO (t1) == BASELINK_BINFO (t2)
      return (BASELINK_BINFO (t1) == BASELINK_BINFO (t2)
              && BASELINK_ACCESS_BINFO (t1) == BASELINK_ACCESS_BINFO (t2)
              && BASELINK_ACCESS_BINFO (t1) == BASELINK_ACCESS_BINFO (t2)
              && cp_tree_equal (BASELINK_FUNCTIONS (t1),
              && cp_tree_equal (BASELINK_FUNCTIONS (t1),
                                BASELINK_FUNCTIONS (t2)));
                                BASELINK_FUNCTIONS (t2)));
 
 
    case TEMPLATE_PARM_INDEX:
    case TEMPLATE_PARM_INDEX:
      return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
      return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
              && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2)
              && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2)
              && (TEMPLATE_PARM_PARAMETER_PACK (t1)
              && (TEMPLATE_PARM_PARAMETER_PACK (t1)
                  == TEMPLATE_PARM_PARAMETER_PACK (t2))
                  == TEMPLATE_PARM_PARAMETER_PACK (t2))
              && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1)),
              && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1)),
                              TREE_TYPE (TEMPLATE_PARM_DECL (t2))));
                              TREE_TYPE (TEMPLATE_PARM_DECL (t2))));
 
 
    case TEMPLATE_ID_EXPR:
    case TEMPLATE_ID_EXPR:
      {
      {
        unsigned ix;
        unsigned ix;
        tree vec1, vec2;
        tree vec1, vec2;
 
 
        if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
        if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
          return false;
          return false;
        vec1 = TREE_OPERAND (t1, 1);
        vec1 = TREE_OPERAND (t1, 1);
        vec2 = TREE_OPERAND (t2, 1);
        vec2 = TREE_OPERAND (t2, 1);
 
 
        if (!vec1 || !vec2)
        if (!vec1 || !vec2)
          return !vec1 && !vec2;
          return !vec1 && !vec2;
 
 
        if (TREE_VEC_LENGTH (vec1) != TREE_VEC_LENGTH (vec2))
        if (TREE_VEC_LENGTH (vec1) != TREE_VEC_LENGTH (vec2))
          return false;
          return false;
 
 
        for (ix = TREE_VEC_LENGTH (vec1); ix--;)
        for (ix = TREE_VEC_LENGTH (vec1); ix--;)
          if (!cp_tree_equal (TREE_VEC_ELT (vec1, ix),
          if (!cp_tree_equal (TREE_VEC_ELT (vec1, ix),
                              TREE_VEC_ELT (vec2, ix)))
                              TREE_VEC_ELT (vec2, ix)))
            return false;
            return false;
 
 
        return true;
        return true;
      }
      }
 
 
    case SIZEOF_EXPR:
    case SIZEOF_EXPR:
    case ALIGNOF_EXPR:
    case ALIGNOF_EXPR:
      {
      {
        tree o1 = TREE_OPERAND (t1, 0);
        tree o1 = TREE_OPERAND (t1, 0);
        tree o2 = TREE_OPERAND (t2, 0);
        tree o2 = TREE_OPERAND (t2, 0);
 
 
        if (TREE_CODE (o1) != TREE_CODE (o2))
        if (TREE_CODE (o1) != TREE_CODE (o2))
          return false;
          return false;
        if (TYPE_P (o1))
        if (TYPE_P (o1))
          return same_type_p (o1, o2);
          return same_type_p (o1, o2);
        else
        else
          return cp_tree_equal (o1, o2);
          return cp_tree_equal (o1, o2);
      }
      }
 
 
    case MODOP_EXPR:
    case MODOP_EXPR:
      {
      {
        tree t1_op1, t2_op1;
        tree t1_op1, t2_op1;
 
 
        if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
        if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
          return false;
          return false;
 
 
        t1_op1 = TREE_OPERAND (t1, 1);
        t1_op1 = TREE_OPERAND (t1, 1);
        t2_op1 = TREE_OPERAND (t2, 1);
        t2_op1 = TREE_OPERAND (t2, 1);
        if (TREE_CODE (t1_op1) != TREE_CODE (t2_op1))
        if (TREE_CODE (t1_op1) != TREE_CODE (t2_op1))
          return false;
          return false;
 
 
        return cp_tree_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t2, 2));
        return cp_tree_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t2, 2));
      }
      }
 
 
    case PTRMEM_CST:
    case PTRMEM_CST:
      /* Two pointer-to-members are the same if they point to the same
      /* Two pointer-to-members are the same if they point to the same
         field or function in the same class.  */
         field or function in the same class.  */
      if (PTRMEM_CST_MEMBER (t1) != PTRMEM_CST_MEMBER (t2))
      if (PTRMEM_CST_MEMBER (t1) != PTRMEM_CST_MEMBER (t2))
        return false;
        return false;
 
 
      return same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2));
      return same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2));
 
 
    case OVERLOAD:
    case OVERLOAD:
      if (OVL_FUNCTION (t1) != OVL_FUNCTION (t2))
      if (OVL_FUNCTION (t1) != OVL_FUNCTION (t2))
        return false;
        return false;
      return cp_tree_equal (OVL_CHAIN (t1), OVL_CHAIN (t2));
      return cp_tree_equal (OVL_CHAIN (t1), OVL_CHAIN (t2));
 
 
    case TRAIT_EXPR:
    case TRAIT_EXPR:
      if (TRAIT_EXPR_KIND (t1) != TRAIT_EXPR_KIND (t2))
      if (TRAIT_EXPR_KIND (t1) != TRAIT_EXPR_KIND (t2))
        return false;
        return false;
      return same_type_p (TRAIT_EXPR_TYPE1 (t1), TRAIT_EXPR_TYPE1 (t2))
      return same_type_p (TRAIT_EXPR_TYPE1 (t1), TRAIT_EXPR_TYPE1 (t2))
        && same_type_p (TRAIT_EXPR_TYPE2 (t1), TRAIT_EXPR_TYPE2 (t2));
        && same_type_p (TRAIT_EXPR_TYPE2 (t1), TRAIT_EXPR_TYPE2 (t2));
 
 
    default:
    default:
      break;
      break;
    }
    }
 
 
  switch (TREE_CODE_CLASS (code1))
  switch (TREE_CODE_CLASS (code1))
    {
    {
    case tcc_unary:
    case tcc_unary:
    case tcc_binary:
    case tcc_binary:
    case tcc_comparison:
    case tcc_comparison:
    case tcc_expression:
    case tcc_expression:
    case tcc_vl_exp:
    case tcc_vl_exp:
    case tcc_reference:
    case tcc_reference:
    case tcc_statement:
    case tcc_statement:
      {
      {
        int i, n;
        int i, n;
 
 
        n = TREE_OPERAND_LENGTH (t1);
        n = TREE_OPERAND_LENGTH (t1);
        if (TREE_CODE_CLASS (code1) == tcc_vl_exp
        if (TREE_CODE_CLASS (code1) == tcc_vl_exp
            && n != TREE_OPERAND_LENGTH (t2))
            && n != TREE_OPERAND_LENGTH (t2))
          return false;
          return false;
 
 
        for (i = 0; i < n; ++i)
        for (i = 0; i < n; ++i)
          if (!cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
          if (!cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
            return false;
            return false;
 
 
        return true;
        return true;
      }
      }
 
 
    case tcc_type:
    case tcc_type:
      return same_type_p (t1, t2);
      return same_type_p (t1, t2);
    default:
    default:
      gcc_unreachable ();
      gcc_unreachable ();
    }
    }
  /* We can get here with --disable-checking.  */
  /* We can get here with --disable-checking.  */
  return false;
  return false;
}
}
 
 
/* The type of ARG when used as an lvalue.  */
/* The type of ARG when used as an lvalue.  */
 
 
tree
tree
lvalue_type (tree arg)
lvalue_type (tree arg)
{
{
  tree type = TREE_TYPE (arg);
  tree type = TREE_TYPE (arg);
  return type;
  return type;
}
}
 
 
/* The type of ARG for printing error messages; denote lvalues with
/* The type of ARG for printing error messages; denote lvalues with
   reference types.  */
   reference types.  */
 
 
tree
tree
error_type (tree arg)
error_type (tree arg)
{
{
  tree type = TREE_TYPE (arg);
  tree type = TREE_TYPE (arg);
 
 
  if (TREE_CODE (type) == ARRAY_TYPE)
  if (TREE_CODE (type) == ARRAY_TYPE)
    ;
    ;
  else if (TREE_CODE (type) == ERROR_MARK)
  else if (TREE_CODE (type) == ERROR_MARK)
    ;
    ;
  else if (real_lvalue_p (arg))
  else if (real_lvalue_p (arg))
    type = build_reference_type (lvalue_type (arg));
    type = build_reference_type (lvalue_type (arg));
  else if (MAYBE_CLASS_TYPE_P (type))
  else if (MAYBE_CLASS_TYPE_P (type))
    type = lvalue_type (arg);
    type = lvalue_type (arg);
 
 
  return type;
  return type;
}
}
 
 
/* Does FUNCTION use a variable-length argument list?  */
/* Does FUNCTION use a variable-length argument list?  */
 
 
int
int
varargs_function_p (const_tree function)
varargs_function_p (const_tree function)
{
{
  const_tree parm = TYPE_ARG_TYPES (TREE_TYPE (function));
  const_tree parm = TYPE_ARG_TYPES (TREE_TYPE (function));
  for (; parm; parm = TREE_CHAIN (parm))
  for (; parm; parm = TREE_CHAIN (parm))
    if (TREE_VALUE (parm) == void_type_node)
    if (TREE_VALUE (parm) == void_type_node)
      return 0;
      return 0;
  return 1;
  return 1;
}
}
 
 
/* Returns 1 if decl is a member of a class.  */
/* Returns 1 if decl is a member of a class.  */
 
 
int
int
member_p (const_tree decl)
member_p (const_tree decl)
{
{
  const_tree const ctx = DECL_CONTEXT (decl);
  const_tree const ctx = DECL_CONTEXT (decl);
  return (ctx && TYPE_P (ctx));
  return (ctx && TYPE_P (ctx));
}
}
 
 
/* Create a placeholder for member access where we don't actually have an
/* Create a placeholder for member access where we don't actually have an
   object that the access is against.  */
   object that the access is against.  */
 
 
tree
tree
build_dummy_object (tree type)
build_dummy_object (tree type)
{
{
  tree decl = build1 (NOP_EXPR, build_pointer_type (type), void_zero_node);
  tree decl = build1 (NOP_EXPR, build_pointer_type (type), void_zero_node);
  return cp_build_indirect_ref (decl, RO_NULL, tf_warning_or_error);
  return cp_build_indirect_ref (decl, RO_NULL, tf_warning_or_error);
}
}
 
 
/* We've gotten a reference to a member of TYPE.  Return *this if appropriate,
/* We've gotten a reference to a member of TYPE.  Return *this if appropriate,
   or a dummy object otherwise.  If BINFOP is non-0, it is filled with the
   or a dummy object otherwise.  If BINFOP is non-0, it is filled with the
   binfo path from current_class_type to TYPE, or 0.  */
   binfo path from current_class_type to TYPE, or 0.  */
 
 
tree
tree
maybe_dummy_object (tree type, tree* binfop)
maybe_dummy_object (tree type, tree* binfop)
{
{
  tree decl, context;
  tree decl, context;
  tree binfo;
  tree binfo;
 
 
  if (current_class_type
  if (current_class_type
      && (binfo = lookup_base (current_class_type, type,
      && (binfo = lookup_base (current_class_type, type,
                               ba_unique | ba_quiet, NULL)))
                               ba_unique | ba_quiet, NULL)))
    context = current_class_type;
    context = current_class_type;
  else
  else
    {
    {
      /* Reference from a nested class member function.  */
      /* Reference from a nested class member function.  */
      context = type;
      context = type;
      binfo = TYPE_BINFO (type);
      binfo = TYPE_BINFO (type);
    }
    }
 
 
  if (binfop)
  if (binfop)
    *binfop = binfo;
    *binfop = binfo;
 
 
  if (current_class_ref && context == current_class_type
  if (current_class_ref && context == current_class_type
      /* Kludge: Make sure that current_class_type is actually
      /* Kludge: Make sure that current_class_type is actually
         correct.  It might not be if we're in the middle of
         correct.  It might not be if we're in the middle of
         tsubst_default_argument.  */
         tsubst_default_argument.  */
      && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (current_class_ref)),
      && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (current_class_ref)),
                      current_class_type))
                      current_class_type))
    decl = current_class_ref;
    decl = current_class_ref;
  else if (current_class_ref && LAMBDA_TYPE_P (current_class_type)
  else if (current_class_ref && LAMBDA_TYPE_P (current_class_type)
           && context == nonlambda_method_basetype ())
           && context == nonlambda_method_basetype ())
    /* In a lambda, need to go through 'this' capture.  */
    /* In a lambda, need to go through 'this' capture.  */
    decl = (cp_build_indirect_ref
    decl = (cp_build_indirect_ref
            ((lambda_expr_this_capture
            ((lambda_expr_this_capture
              (CLASSTYPE_LAMBDA_EXPR (current_class_type))),
              (CLASSTYPE_LAMBDA_EXPR (current_class_type))),
             RO_NULL, tf_warning_or_error));
             RO_NULL, tf_warning_or_error));
  else
  else
    decl = build_dummy_object (context);
    decl = build_dummy_object (context);
 
 
  return decl;
  return decl;
}
}
 
 
/* Returns 1 if OB is a placeholder object, or a pointer to one.  */
/* Returns 1 if OB is a placeholder object, or a pointer to one.  */
 
 
int
int
is_dummy_object (const_tree ob)
is_dummy_object (const_tree ob)
{
{
  if (TREE_CODE (ob) == INDIRECT_REF)
  if (TREE_CODE (ob) == INDIRECT_REF)
    ob = TREE_OPERAND (ob, 0);
    ob = TREE_OPERAND (ob, 0);
  return (TREE_CODE (ob) == NOP_EXPR
  return (TREE_CODE (ob) == NOP_EXPR
          && TREE_OPERAND (ob, 0) == void_zero_node);
          && TREE_OPERAND (ob, 0) == void_zero_node);
}
}
 
 
/* Returns 1 iff type T is something we want to treat as a scalar type for
/* Returns 1 iff type T is something we want to treat as a scalar type for
   the purpose of deciding whether it is trivial/POD/standard-layout.  */
   the purpose of deciding whether it is trivial/POD/standard-layout.  */
 
 
static bool
static bool
scalarish_type_p (const_tree t)
scalarish_type_p (const_tree t)
{
{
  if (t == error_mark_node)
  if (t == error_mark_node)
    return 1;
    return 1;
 
 
  return (SCALAR_TYPE_P (t)
  return (SCALAR_TYPE_P (t)
          || TREE_CODE (t) == VECTOR_TYPE);
          || TREE_CODE (t) == VECTOR_TYPE);
}
}
 
 
/* Returns true iff T requires non-trivial default initialization.  */
/* Returns true iff T requires non-trivial default initialization.  */
 
 
bool
bool
type_has_nontrivial_default_init (const_tree t)
type_has_nontrivial_default_init (const_tree t)
{
{
  t = strip_array_types (CONST_CAST_TREE (t));
  t = strip_array_types (CONST_CAST_TREE (t));
 
 
  if (CLASS_TYPE_P (t))
  if (CLASS_TYPE_P (t))
    return TYPE_HAS_COMPLEX_DFLT (t);
    return TYPE_HAS_COMPLEX_DFLT (t);
  else
  else
    return 0;
    return 0;
}
}
 
 
/* Returns true iff copying an object of type T is non-trivial.  */
/* Returns true iff copying an object of type T is non-trivial.  */
 
 
bool
bool
type_has_nontrivial_copy_init (const_tree t)
type_has_nontrivial_copy_init (const_tree t)
{
{
  t = strip_array_types (CONST_CAST_TREE (t));
  t = strip_array_types (CONST_CAST_TREE (t));
 
 
  if (CLASS_TYPE_P (t))
  if (CLASS_TYPE_P (t))
    return TYPE_HAS_COMPLEX_INIT_REF (t);
    return TYPE_HAS_COMPLEX_INIT_REF (t);
  else
  else
    return 0;
    return 0;
}
}
 
 
/* Returns 1 iff type T is a trivial type, as defined in [basic.types].  */
/* Returns 1 iff type T is a trivial type, as defined in [basic.types].  */
 
 
bool
bool
trivial_type_p (const_tree t)
trivial_type_p (const_tree t)
{
{
  t = strip_array_types (CONST_CAST_TREE (t));
  t = strip_array_types (CONST_CAST_TREE (t));
 
 
  if (CLASS_TYPE_P (t))
  if (CLASS_TYPE_P (t))
    return (TYPE_HAS_TRIVIAL_DFLT (t)
    return (TYPE_HAS_TRIVIAL_DFLT (t)
            && TYPE_HAS_TRIVIAL_INIT_REF (t)
            && TYPE_HAS_TRIVIAL_INIT_REF (t)
            && TYPE_HAS_TRIVIAL_ASSIGN_REF (t)
            && TYPE_HAS_TRIVIAL_ASSIGN_REF (t)
            && TYPE_HAS_TRIVIAL_DESTRUCTOR (t));
            && TYPE_HAS_TRIVIAL_DESTRUCTOR (t));
  else
  else
    return scalarish_type_p (t);
    return scalarish_type_p (t);
}
}
 
 
/* Returns 1 iff type T is a POD type, as defined in [basic.types].  */
/* Returns 1 iff type T is a POD type, as defined in [basic.types].  */
 
 
bool
bool
pod_type_p (const_tree t)
pod_type_p (const_tree t)
{
{
  /* This CONST_CAST is okay because strip_array_types returns its
  /* This CONST_CAST is okay because strip_array_types returns its
     argument unmodified and we assign it to a const_tree.  */
     argument unmodified and we assign it to a const_tree.  */
  t = strip_array_types (CONST_CAST_TREE(t));
  t = strip_array_types (CONST_CAST_TREE(t));
 
 
  if (!CLASS_TYPE_P (t))
  if (!CLASS_TYPE_P (t))
    return scalarish_type_p (t);
    return scalarish_type_p (t);
  else if (cxx_dialect > cxx98)
  else if (cxx_dialect > cxx98)
    /* [class]/10: A POD struct is a class that is both a trivial class and a
    /* [class]/10: A POD struct is a class that is both a trivial class and a
       standard-layout class, and has no non-static data members of type
       standard-layout class, and has no non-static data members of type
       non-POD struct, non-POD union (or array of such types).
       non-POD struct, non-POD union (or array of such types).
 
 
       We don't need to check individual members because if a member is
       We don't need to check individual members because if a member is
       non-std-layout or non-trivial, the class will be too.  */
       non-std-layout or non-trivial, the class will be too.  */
    return (std_layout_type_p (t) && trivial_type_p (t));
    return (std_layout_type_p (t) && trivial_type_p (t));
  else
  else
    /* The C++98 definition of POD is different.  */
    /* The C++98 definition of POD is different.  */
    return !CLASSTYPE_NON_LAYOUT_POD_P (t);
    return !CLASSTYPE_NON_LAYOUT_POD_P (t);
}
}
 
 
/* Returns true iff T is POD for the purpose of layout, as defined in the
/* Returns true iff T is POD for the purpose of layout, as defined in the
   C++ ABI.  */
   C++ ABI.  */
 
 
bool
bool
layout_pod_type_p (const_tree t)
layout_pod_type_p (const_tree t)
{
{
  t = strip_array_types (CONST_CAST_TREE (t));
  t = strip_array_types (CONST_CAST_TREE (t));
 
 
  if (CLASS_TYPE_P (t))
  if (CLASS_TYPE_P (t))
    return !CLASSTYPE_NON_LAYOUT_POD_P (t);
    return !CLASSTYPE_NON_LAYOUT_POD_P (t);
  else
  else
    return scalarish_type_p (t);
    return scalarish_type_p (t);
}
}
 
 
/* Returns true iff T is a standard-layout type, as defined in
/* Returns true iff T is a standard-layout type, as defined in
   [basic.types].  */
   [basic.types].  */
 
 
bool
bool
std_layout_type_p (const_tree t)
std_layout_type_p (const_tree t)
{
{
  t = strip_array_types (CONST_CAST_TREE (t));
  t = strip_array_types (CONST_CAST_TREE (t));
 
 
  if (CLASS_TYPE_P (t))
  if (CLASS_TYPE_P (t))
    return !CLASSTYPE_NON_STD_LAYOUT (t);
    return !CLASSTYPE_NON_STD_LAYOUT (t);
  else
  else
    return scalarish_type_p (t);
    return scalarish_type_p (t);
}
}
 
 
/* Nonzero iff type T is a class template implicit specialization.  */
/* Nonzero iff type T is a class template implicit specialization.  */
 
 
bool
bool
class_tmpl_impl_spec_p (const_tree t)
class_tmpl_impl_spec_p (const_tree t)
{
{
  return CLASS_TYPE_P (t) && CLASSTYPE_TEMPLATE_INSTANTIATION (t);
  return CLASS_TYPE_P (t) && CLASSTYPE_TEMPLATE_INSTANTIATION (t);
}
}
 
 
/* Returns 1 iff zero initialization of type T means actually storing
/* Returns 1 iff zero initialization of type T means actually storing
   zeros in it.  */
   zeros in it.  */
 
 
int
int
zero_init_p (const_tree t)
zero_init_p (const_tree t)
{
{
  /* This CONST_CAST is okay because strip_array_types returns its
  /* This CONST_CAST is okay because strip_array_types returns its
     argument unmodified and we assign it to a const_tree.  */
     argument unmodified and we assign it to a const_tree.  */
  t = strip_array_types (CONST_CAST_TREE(t));
  t = strip_array_types (CONST_CAST_TREE(t));
 
 
  if (t == error_mark_node)
  if (t == error_mark_node)
    return 1;
    return 1;
 
 
  /* NULL pointers to data members are initialized with -1.  */
  /* NULL pointers to data members are initialized with -1.  */
  if (TYPE_PTRMEM_P (t))
  if (TYPE_PTRMEM_P (t))
    return 0;
    return 0;
 
 
  /* Classes that contain types that can't be zero-initialized, cannot
  /* Classes that contain types that can't be zero-initialized, cannot
     be zero-initialized themselves.  */
     be zero-initialized themselves.  */
  if (CLASS_TYPE_P (t) && CLASSTYPE_NON_ZERO_INIT_P (t))
  if (CLASS_TYPE_P (t) && CLASSTYPE_NON_ZERO_INIT_P (t))
    return 0;
    return 0;
 
 
  return 1;
  return 1;
}
}
 
 
/* Table of valid C++ attributes.  */
/* Table of valid C++ attributes.  */
const struct attribute_spec cxx_attribute_table[] =
const struct attribute_spec cxx_attribute_table[] =
{
{
  /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
  /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
  { "java_interface", 0, 0, false, false, false, handle_java_interface_attribute },
  { "java_interface", 0, 0, false, false, false, handle_java_interface_attribute },
  { "com_interface",  0, 0, false, false, false, handle_com_interface_attribute },
  { "com_interface",  0, 0, false, false, false, handle_com_interface_attribute },
  { "init_priority",  1, 1, true,  false, false, handle_init_priority_attribute },
  { "init_priority",  1, 1, true,  false, false, handle_init_priority_attribute },
  { NULL,             0, 0, false, false, false, NULL }
  { NULL,             0, 0, false, false, false, NULL }
};
};
 
 
/* Handle a "java_interface" attribute; arguments as in
/* Handle a "java_interface" attribute; arguments as in
   struct attribute_spec.handler.  */
   struct attribute_spec.handler.  */
static tree
static tree
handle_java_interface_attribute (tree* node,
handle_java_interface_attribute (tree* node,
                                 tree name,
                                 tree name,
                                 tree args ATTRIBUTE_UNUSED ,
                                 tree args ATTRIBUTE_UNUSED ,
                                 int flags,
                                 int flags,
                                 bool* no_add_attrs)
                                 bool* no_add_attrs)
{
{
  if (DECL_P (*node)
  if (DECL_P (*node)
      || !CLASS_TYPE_P (*node)
      || !CLASS_TYPE_P (*node)
      || !TYPE_FOR_JAVA (*node))
      || !TYPE_FOR_JAVA (*node))
    {
    {
      error ("%qE attribute can only be applied to Java class definitions",
      error ("%qE attribute can only be applied to Java class definitions",
             name);
             name);
      *no_add_attrs = true;
      *no_add_attrs = true;
      return NULL_TREE;
      return NULL_TREE;
    }
    }
  if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
  if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
    *node = build_variant_type_copy (*node);
    *node = build_variant_type_copy (*node);
  TYPE_JAVA_INTERFACE (*node) = 1;
  TYPE_JAVA_INTERFACE (*node) = 1;
 
 
  return NULL_TREE;
  return NULL_TREE;
}
}
 
 
/* Handle a "com_interface" attribute; arguments as in
/* Handle a "com_interface" attribute; arguments as in
   struct attribute_spec.handler.  */
   struct attribute_spec.handler.  */
static tree
static tree
handle_com_interface_attribute (tree* node,
handle_com_interface_attribute (tree* node,
                                tree name,
                                tree name,
                                tree args ATTRIBUTE_UNUSED ,
                                tree args ATTRIBUTE_UNUSED ,
                                int flags ATTRIBUTE_UNUSED ,
                                int flags ATTRIBUTE_UNUSED ,
                                bool* no_add_attrs)
                                bool* no_add_attrs)
{
{
  static int warned;
  static int warned;
 
 
  *no_add_attrs = true;
  *no_add_attrs = true;
 
 
  if (DECL_P (*node)
  if (DECL_P (*node)
      || !CLASS_TYPE_P (*node)
      || !CLASS_TYPE_P (*node)
      || *node != TYPE_MAIN_VARIANT (*node))
      || *node != TYPE_MAIN_VARIANT (*node))
    {
    {
      warning (OPT_Wattributes, "%qE attribute can only be applied "
      warning (OPT_Wattributes, "%qE attribute can only be applied "
               "to class definitions", name);
               "to class definitions", name);
      return NULL_TREE;
      return NULL_TREE;
    }
    }
 
 
  if (!warned++)
  if (!warned++)
    warning (0, "%qE is obsolete; g++ vtables are now COM-compatible by default",
    warning (0, "%qE is obsolete; g++ vtables are now COM-compatible by default",
             name);
             name);
 
 
  return NULL_TREE;
  return NULL_TREE;
}
}
 
 
/* Handle an "init_priority" attribute; arguments as in
/* Handle an "init_priority" attribute; arguments as in
   struct attribute_spec.handler.  */
   struct attribute_spec.handler.  */
static tree
static tree
handle_init_priority_attribute (tree* node,
handle_init_priority_attribute (tree* node,
                                tree name,
                                tree name,
                                tree args,
                                tree args,
                                int flags ATTRIBUTE_UNUSED ,
                                int flags ATTRIBUTE_UNUSED ,
                                bool* no_add_attrs)
                                bool* no_add_attrs)
{
{
  tree initp_expr = TREE_VALUE (args);
  tree initp_expr = TREE_VALUE (args);
  tree decl = *node;
  tree decl = *node;
  tree type = TREE_TYPE (decl);
  tree type = TREE_TYPE (decl);
  int pri;
  int pri;
 
 
  STRIP_NOPS (initp_expr);
  STRIP_NOPS (initp_expr);
 
 
  if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
  if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
    {
    {
      error ("requested init_priority is not an integer constant");
      error ("requested init_priority is not an integer constant");
      *no_add_attrs = true;
      *no_add_attrs = true;
      return NULL_TREE;
      return NULL_TREE;
    }
    }
 
 
  pri = TREE_INT_CST_LOW (initp_expr);
  pri = TREE_INT_CST_LOW (initp_expr);
 
 
  type = strip_array_types (type);
  type = strip_array_types (type);
 
 
  if (decl == NULL_TREE
  if (decl == NULL_TREE
      || TREE_CODE (decl) != VAR_DECL
      || TREE_CODE (decl) != VAR_DECL
      || !TREE_STATIC (decl)
      || !TREE_STATIC (decl)
      || DECL_EXTERNAL (decl)
      || DECL_EXTERNAL (decl)
      || (TREE_CODE (type) != RECORD_TYPE
      || (TREE_CODE (type) != RECORD_TYPE
          && TREE_CODE (type) != UNION_TYPE)
          && TREE_CODE (type) != UNION_TYPE)
      /* Static objects in functions are initialized the
      /* Static objects in functions are initialized the
         first time control passes through that
         first time control passes through that
         function. This is not precise enough to pin down an
         function. This is not precise enough to pin down an
         init_priority value, so don't allow it.  */
         init_priority value, so don't allow it.  */
      || current_function_decl)
      || current_function_decl)
    {
    {
      error ("can only use %qE attribute on file-scope definitions "
      error ("can only use %qE attribute on file-scope definitions "
             "of objects of class type", name);
             "of objects of class type", name);
      *no_add_attrs = true;
      *no_add_attrs = true;
      return NULL_TREE;
      return NULL_TREE;
    }
    }
 
 
  if (pri > MAX_INIT_PRIORITY || pri <= 0)
  if (pri > MAX_INIT_PRIORITY || pri <= 0)
    {
    {
      error ("requested init_priority is out of range");
      error ("requested init_priority is out of range");
      *no_add_attrs = true;
      *no_add_attrs = true;
      return NULL_TREE;
      return NULL_TREE;
    }
    }
 
 
  /* Check for init_priorities that are reserved for
  /* Check for init_priorities that are reserved for
     language and runtime support implementations.*/
     language and runtime support implementations.*/
  if (pri <= MAX_RESERVED_INIT_PRIORITY)
  if (pri <= MAX_RESERVED_INIT_PRIORITY)
    {
    {
      warning
      warning
        (0, "requested init_priority is reserved for internal use");
        (0, "requested init_priority is reserved for internal use");
    }
    }
 
 
  if (SUPPORTS_INIT_PRIORITY)
  if (SUPPORTS_INIT_PRIORITY)
    {
    {
      SET_DECL_INIT_PRIORITY (decl, pri);
      SET_DECL_INIT_PRIORITY (decl, pri);
      DECL_HAS_INIT_PRIORITY_P (decl) = 1;
      DECL_HAS_INIT_PRIORITY_P (decl) = 1;
      return NULL_TREE;
      return NULL_TREE;
    }
    }
  else
  else
    {
    {
      error ("%qE attribute is not supported on this platform", name);
      error ("%qE attribute is not supported on this platform", name);
      *no_add_attrs = true;
      *no_add_attrs = true;
      return NULL_TREE;
      return NULL_TREE;
    }
    }
}
}
 
 
/* Return a new PTRMEM_CST of the indicated TYPE.  The MEMBER is the
/* Return a new PTRMEM_CST of the indicated TYPE.  The MEMBER is the
   thing pointed to by the constant.  */
   thing pointed to by the constant.  */
 
 
tree
tree
make_ptrmem_cst (tree type, tree member)
make_ptrmem_cst (tree type, tree member)
{
{
  tree ptrmem_cst = make_node (PTRMEM_CST);
  tree ptrmem_cst = make_node (PTRMEM_CST);
  TREE_TYPE (ptrmem_cst) = type;
  TREE_TYPE (ptrmem_cst) = type;
  PTRMEM_CST_MEMBER (ptrmem_cst) = member;
  PTRMEM_CST_MEMBER (ptrmem_cst) = member;
  return ptrmem_cst;
  return ptrmem_cst;
}
}
 
 
/* Build a variant of TYPE that has the indicated ATTRIBUTES.  May
/* Build a variant of TYPE that has the indicated ATTRIBUTES.  May
   return an existing type if an appropriate type already exists.  */
   return an existing type if an appropriate type already exists.  */
 
 
tree
tree
cp_build_type_attribute_variant (tree type, tree attributes)
cp_build_type_attribute_variant (tree type, tree attributes)
{
{
  tree new_type;
  tree new_type;
 
 
  new_type = build_type_attribute_variant (type, attributes);
  new_type = build_type_attribute_variant (type, attributes);
  if ((TREE_CODE (new_type) == FUNCTION_TYPE
  if ((TREE_CODE (new_type) == FUNCTION_TYPE
       || TREE_CODE (new_type) == METHOD_TYPE)
       || TREE_CODE (new_type) == METHOD_TYPE)
      && (TYPE_RAISES_EXCEPTIONS (new_type)
      && (TYPE_RAISES_EXCEPTIONS (new_type)
          != TYPE_RAISES_EXCEPTIONS (type)))
          != TYPE_RAISES_EXCEPTIONS (type)))
    new_type = build_exception_variant (new_type,
    new_type = build_exception_variant (new_type,
                                        TYPE_RAISES_EXCEPTIONS (type));
                                        TYPE_RAISES_EXCEPTIONS (type));
 
 
  /* Making a new main variant of a class type is broken.  */
  /* Making a new main variant of a class type is broken.  */
  gcc_assert (!CLASS_TYPE_P (type) || new_type == type);
  gcc_assert (!CLASS_TYPE_P (type) || new_type == type);
 
 
  return new_type;
  return new_type;
}
}
 
 
/* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes.
/* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes.
   Called only after doing all language independent checks.  Only
   Called only after doing all language independent checks.  Only
   to check TYPE_RAISES_EXCEPTIONS for FUNCTION_TYPE, the rest is already
   to check TYPE_RAISES_EXCEPTIONS for FUNCTION_TYPE, the rest is already
   compared in type_hash_eq.  */
   compared in type_hash_eq.  */
 
 
bool
bool
cxx_type_hash_eq (const_tree typea, const_tree typeb)
cxx_type_hash_eq (const_tree typea, const_tree typeb)
{
{
  gcc_assert (TREE_CODE (typea) == FUNCTION_TYPE);
  gcc_assert (TREE_CODE (typea) == FUNCTION_TYPE);
 
 
  return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea),
  return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea),
                            TYPE_RAISES_EXCEPTIONS (typeb), 1);
                            TYPE_RAISES_EXCEPTIONS (typeb), 1);
}
}
 
 
/* Apply FUNC to all language-specific sub-trees of TP in a pre-order
/* Apply FUNC to all language-specific sub-trees of TP in a pre-order
   traversal.  Called from walk_tree.  */
   traversal.  Called from walk_tree.  */
 
 
tree
tree
cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func,
cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func,
                  void *data, struct pointer_set_t *pset)
                  void *data, struct pointer_set_t *pset)
{
{
  enum tree_code code = TREE_CODE (*tp);
  enum tree_code code = TREE_CODE (*tp);
  tree result;
  tree result;
 
 
#define WALK_SUBTREE(NODE)                              \
#define WALK_SUBTREE(NODE)                              \
  do                                                    \
  do                                                    \
    {                                                   \
    {                                                   \
      result = cp_walk_tree (&(NODE), func, data, pset);        \
      result = cp_walk_tree (&(NODE), func, data, pset);        \
      if (result) goto out;                             \
      if (result) goto out;                             \
    }                                                   \
    }                                                   \
  while (0)
  while (0)
 
 
  /* Not one of the easy cases.  We must explicitly go through the
  /* Not one of the easy cases.  We must explicitly go through the
     children.  */
     children.  */
  result = NULL_TREE;
  result = NULL_TREE;
  switch (code)
  switch (code)
    {
    {
    case DEFAULT_ARG:
    case DEFAULT_ARG:
    case TEMPLATE_TEMPLATE_PARM:
    case TEMPLATE_TEMPLATE_PARM:
    case BOUND_TEMPLATE_TEMPLATE_PARM:
    case BOUND_TEMPLATE_TEMPLATE_PARM:
    case UNBOUND_CLASS_TEMPLATE:
    case UNBOUND_CLASS_TEMPLATE:
    case TEMPLATE_PARM_INDEX:
    case TEMPLATE_PARM_INDEX:
    case TEMPLATE_TYPE_PARM:
    case TEMPLATE_TYPE_PARM:
    case TYPENAME_TYPE:
    case TYPENAME_TYPE:
    case TYPEOF_TYPE:
    case TYPEOF_TYPE:
      /* None of these have subtrees other than those already walked
      /* None of these have subtrees other than those already walked
         above.  */
         above.  */
      *walk_subtrees_p = 0;
      *walk_subtrees_p = 0;
      break;
      break;
 
 
    case BASELINK:
    case BASELINK:
      WALK_SUBTREE (BASELINK_FUNCTIONS (*tp));
      WALK_SUBTREE (BASELINK_FUNCTIONS (*tp));
      *walk_subtrees_p = 0;
      *walk_subtrees_p = 0;
      break;
      break;
 
 
    case PTRMEM_CST:
    case PTRMEM_CST:
      WALK_SUBTREE (TREE_TYPE (*tp));
      WALK_SUBTREE (TREE_TYPE (*tp));
      *walk_subtrees_p = 0;
      *walk_subtrees_p = 0;
      break;
      break;
 
 
    case TREE_LIST:
    case TREE_LIST:
      WALK_SUBTREE (TREE_PURPOSE (*tp));
      WALK_SUBTREE (TREE_PURPOSE (*tp));
      break;
      break;
 
 
    case OVERLOAD:
    case OVERLOAD:
      WALK_SUBTREE (OVL_FUNCTION (*tp));
      WALK_SUBTREE (OVL_FUNCTION (*tp));
      WALK_SUBTREE (OVL_CHAIN (*tp));
      WALK_SUBTREE (OVL_CHAIN (*tp));
      *walk_subtrees_p = 0;
      *walk_subtrees_p = 0;
      break;
      break;
 
 
    case USING_DECL:
    case USING_DECL:
      WALK_SUBTREE (DECL_NAME (*tp));
      WALK_SUBTREE (DECL_NAME (*tp));
      WALK_SUBTREE (USING_DECL_SCOPE (*tp));
      WALK_SUBTREE (USING_DECL_SCOPE (*tp));
      WALK_SUBTREE (USING_DECL_DECLS (*tp));
      WALK_SUBTREE (USING_DECL_DECLS (*tp));
      *walk_subtrees_p = 0;
      *walk_subtrees_p = 0;
      break;
      break;
 
 
    case RECORD_TYPE:
    case RECORD_TYPE:
      if (TYPE_PTRMEMFUNC_P (*tp))
      if (TYPE_PTRMEMFUNC_P (*tp))
        WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE (*tp));
        WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE (*tp));
      break;
      break;
 
 
    case TYPE_ARGUMENT_PACK:
    case TYPE_ARGUMENT_PACK:
    case NONTYPE_ARGUMENT_PACK:
    case NONTYPE_ARGUMENT_PACK:
      {
      {
        tree args = ARGUMENT_PACK_ARGS (*tp);
        tree args = ARGUMENT_PACK_ARGS (*tp);
        int i, len = TREE_VEC_LENGTH (args);
        int i, len = TREE_VEC_LENGTH (args);
        for (i = 0; i < len; i++)
        for (i = 0; i < len; i++)
          WALK_SUBTREE (TREE_VEC_ELT (args, i));
          WALK_SUBTREE (TREE_VEC_ELT (args, i));
      }
      }
      break;
      break;
 
 
    case TYPE_PACK_EXPANSION:
    case TYPE_PACK_EXPANSION:
      WALK_SUBTREE (TREE_TYPE (*tp));
      WALK_SUBTREE (TREE_TYPE (*tp));
      *walk_subtrees_p = 0;
      *walk_subtrees_p = 0;
      break;
      break;
 
 
    case EXPR_PACK_EXPANSION:
    case EXPR_PACK_EXPANSION:
      WALK_SUBTREE (TREE_OPERAND (*tp, 0));
      WALK_SUBTREE (TREE_OPERAND (*tp, 0));
      *walk_subtrees_p = 0;
      *walk_subtrees_p = 0;
      break;
      break;
 
 
    case CAST_EXPR:
    case CAST_EXPR:
    case REINTERPRET_CAST_EXPR:
    case REINTERPRET_CAST_EXPR:
    case STATIC_CAST_EXPR:
    case STATIC_CAST_EXPR:
    case CONST_CAST_EXPR:
    case CONST_CAST_EXPR:
    case DYNAMIC_CAST_EXPR:
    case DYNAMIC_CAST_EXPR:
      if (TREE_TYPE (*tp))
      if (TREE_TYPE (*tp))
        WALK_SUBTREE (TREE_TYPE (*tp));
        WALK_SUBTREE (TREE_TYPE (*tp));
 
 
      {
      {
        int i;
        int i;
        for (i = 0; i < TREE_CODE_LENGTH (TREE_CODE (*tp)); ++i)
        for (i = 0; i < TREE_CODE_LENGTH (TREE_CODE (*tp)); ++i)
          WALK_SUBTREE (TREE_OPERAND (*tp, i));
          WALK_SUBTREE (TREE_OPERAND (*tp, i));
      }
      }
      *walk_subtrees_p = 0;
      *walk_subtrees_p = 0;
      break;
      break;
 
 
    case TRAIT_EXPR:
    case TRAIT_EXPR:
      WALK_SUBTREE (TRAIT_EXPR_TYPE1 (*tp));
      WALK_SUBTREE (TRAIT_EXPR_TYPE1 (*tp));
      WALK_SUBTREE (TRAIT_EXPR_TYPE2 (*tp));
      WALK_SUBTREE (TRAIT_EXPR_TYPE2 (*tp));
      *walk_subtrees_p = 0;
      *walk_subtrees_p = 0;
      break;
      break;
 
 
    case DECLTYPE_TYPE:
    case DECLTYPE_TYPE:
      WALK_SUBTREE (DECLTYPE_TYPE_EXPR (*tp));
      WALK_SUBTREE (DECLTYPE_TYPE_EXPR (*tp));
      *walk_subtrees_p = 0;
      *walk_subtrees_p = 0;
      break;
      break;
 
 
 
 
    default:
    default:
      return NULL_TREE;
      return NULL_TREE;
    }
    }
 
 
  /* We didn't find what we were looking for.  */
  /* We didn't find what we were looking for.  */
 out:
 out:
  return result;
  return result;
 
 
#undef WALK_SUBTREE
#undef WALK_SUBTREE
}
}
 
 
/* Like save_expr, but for C++.  */
/* Like save_expr, but for C++.  */
 
 
tree
tree
cp_save_expr (tree expr)
cp_save_expr (tree expr)
{
{
  /* There is no reason to create a SAVE_EXPR within a template; if
  /* There is no reason to create a SAVE_EXPR within a template; if
     needed, we can create the SAVE_EXPR when instantiating the
     needed, we can create the SAVE_EXPR when instantiating the
     template.  Furthermore, the middle-end cannot handle C++-specific
     template.  Furthermore, the middle-end cannot handle C++-specific
     tree codes.  */
     tree codes.  */
  if (processing_template_decl)
  if (processing_template_decl)
    return expr;
    return expr;
  return save_expr (expr);
  return save_expr (expr);
}
}
 
 
/* Initialize tree.c.  */
/* Initialize tree.c.  */
 
 
void
void
init_tree (void)
init_tree (void)
{
{
  list_hash_table = htab_create_ggc (31, list_hash, list_hash_eq, NULL);
  list_hash_table = htab_create_ggc (31, list_hash, list_hash_eq, NULL);
}
}
 
 
/* Returns the kind of special function that DECL (a FUNCTION_DECL)
/* Returns the kind of special function that DECL (a FUNCTION_DECL)
   is.  Note that sfk_none is zero, so this function can be used as a
   is.  Note that sfk_none is zero, so this function can be used as a
   predicate to test whether or not DECL is a special function.  */
   predicate to test whether or not DECL is a special function.  */
 
 
special_function_kind
special_function_kind
special_function_p (const_tree decl)
special_function_p (const_tree decl)
{
{
  /* Rather than doing all this stuff with magic names, we should
  /* Rather than doing all this stuff with magic names, we should
     probably have a field of type `special_function_kind' in
     probably have a field of type `special_function_kind' in
     DECL_LANG_SPECIFIC.  */
     DECL_LANG_SPECIFIC.  */
  if (DECL_COPY_CONSTRUCTOR_P (decl))
  if (DECL_COPY_CONSTRUCTOR_P (decl))
    return sfk_copy_constructor;
    return sfk_copy_constructor;
  if (DECL_MOVE_CONSTRUCTOR_P (decl))
  if (DECL_MOVE_CONSTRUCTOR_P (decl))
    return sfk_move_constructor;
    return sfk_move_constructor;
  if (DECL_CONSTRUCTOR_P (decl))
  if (DECL_CONSTRUCTOR_P (decl))
    return sfk_constructor;
    return sfk_constructor;
  if (DECL_OVERLOADED_OPERATOR_P (decl) == NOP_EXPR)
  if (DECL_OVERLOADED_OPERATOR_P (decl) == NOP_EXPR)
    return sfk_assignment_operator;
    return sfk_assignment_operator;
  if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
  if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
    return sfk_destructor;
    return sfk_destructor;
  if (DECL_COMPLETE_DESTRUCTOR_P (decl))
  if (DECL_COMPLETE_DESTRUCTOR_P (decl))
    return sfk_complete_destructor;
    return sfk_complete_destructor;
  if (DECL_BASE_DESTRUCTOR_P (decl))
  if (DECL_BASE_DESTRUCTOR_P (decl))
    return sfk_base_destructor;
    return sfk_base_destructor;
  if (DECL_DELETING_DESTRUCTOR_P (decl))
  if (DECL_DELETING_DESTRUCTOR_P (decl))
    return sfk_deleting_destructor;
    return sfk_deleting_destructor;
  if (DECL_CONV_FN_P (decl))
  if (DECL_CONV_FN_P (decl))
    return sfk_conversion;
    return sfk_conversion;
 
 
  return sfk_none;
  return sfk_none;
}
}
 
 
/* Returns nonzero if TYPE is a character type, including wchar_t.  */
/* Returns nonzero if TYPE is a character type, including wchar_t.  */
 
 
int
int
char_type_p (tree type)
char_type_p (tree type)
{
{
  return (same_type_p (type, char_type_node)
  return (same_type_p (type, char_type_node)
          || same_type_p (type, unsigned_char_type_node)
          || same_type_p (type, unsigned_char_type_node)
          || same_type_p (type, signed_char_type_node)
          || same_type_p (type, signed_char_type_node)
          || same_type_p (type, char16_type_node)
          || same_type_p (type, char16_type_node)
          || same_type_p (type, char32_type_node)
          || same_type_p (type, char32_type_node)
          || same_type_p (type, wchar_type_node));
          || same_type_p (type, wchar_type_node));
}
}
 
 
/* Returns the kind of linkage associated with the indicated DECL.  Th
/* Returns the kind of linkage associated with the indicated DECL.  Th
   value returned is as specified by the language standard; it is
   value returned is as specified by the language standard; it is
   independent of implementation details regarding template
   independent of implementation details regarding template
   instantiation, etc.  For example, it is possible that a declaration
   instantiation, etc.  For example, it is possible that a declaration
   to which this function assigns external linkage would not show up
   to which this function assigns external linkage would not show up
   as a global symbol when you run `nm' on the resulting object file.  */
   as a global symbol when you run `nm' on the resulting object file.  */
 
 
linkage_kind
linkage_kind
decl_linkage (tree decl)
decl_linkage (tree decl)
{
{
  /* This function doesn't attempt to calculate the linkage from first
  /* This function doesn't attempt to calculate the linkage from first
     principles as given in [basic.link].  Instead, it makes use of
     principles as given in [basic.link].  Instead, it makes use of
     the fact that we have already set TREE_PUBLIC appropriately, and
     the fact that we have already set TREE_PUBLIC appropriately, and
     then handles a few special cases.  Ideally, we would calculate
     then handles a few special cases.  Ideally, we would calculate
     linkage first, and then transform that into a concrete
     linkage first, and then transform that into a concrete
     implementation.  */
     implementation.  */
 
 
  /* Things that don't have names have no linkage.  */
  /* Things that don't have names have no linkage.  */
  if (!DECL_NAME (decl))
  if (!DECL_NAME (decl))
    return lk_none;
    return lk_none;
 
 
  /* Fields have no linkage.  */
  /* Fields have no linkage.  */
  if (TREE_CODE (decl) == FIELD_DECL)
  if (TREE_CODE (decl) == FIELD_DECL)
    return lk_none;
    return lk_none;
 
 
  /* Things that are TREE_PUBLIC have external linkage.  */
  /* Things that are TREE_PUBLIC have external linkage.  */
  if (TREE_PUBLIC (decl))
  if (TREE_PUBLIC (decl))
    return lk_external;
    return lk_external;
 
 
  if (TREE_CODE (decl) == NAMESPACE_DECL)
  if (TREE_CODE (decl) == NAMESPACE_DECL)
    return lk_external;
    return lk_external;
 
 
  /* Linkage of a CONST_DECL depends on the linkage of the enumeration
  /* Linkage of a CONST_DECL depends on the linkage of the enumeration
     type.  */
     type.  */
  if (TREE_CODE (decl) == CONST_DECL)
  if (TREE_CODE (decl) == CONST_DECL)
    return decl_linkage (TYPE_NAME (TREE_TYPE (decl)));
    return decl_linkage (TYPE_NAME (TREE_TYPE (decl)));
 
 
  /* Some things that are not TREE_PUBLIC have external linkage, too.
  /* Some things that are not TREE_PUBLIC have external linkage, too.
     For example, on targets that don't have weak symbols, we make all
     For example, on targets that don't have weak symbols, we make all
     template instantiations have internal linkage (in the object
     template instantiations have internal linkage (in the object
     file), but the symbols should still be treated as having external
     file), but the symbols should still be treated as having external
     linkage from the point of view of the language.  */
     linkage from the point of view of the language.  */
  if ((TREE_CODE (decl) == FUNCTION_DECL
  if ((TREE_CODE (decl) == FUNCTION_DECL
       || TREE_CODE (decl) == VAR_DECL)
       || TREE_CODE (decl) == VAR_DECL)
      && DECL_COMDAT (decl))
      && DECL_COMDAT (decl))
    return lk_external;
    return lk_external;
 
 
  /* Things in local scope do not have linkage, if they don't have
  /* Things in local scope do not have linkage, if they don't have
     TREE_PUBLIC set.  */
     TREE_PUBLIC set.  */
  if (decl_function_context (decl))
  if (decl_function_context (decl))
    return lk_none;
    return lk_none;
 
 
  /* Members of the anonymous namespace also have TREE_PUBLIC unset, but
  /* Members of the anonymous namespace also have TREE_PUBLIC unset, but
     are considered to have external linkage for language purposes.  DECLs
     are considered to have external linkage for language purposes.  DECLs
     really meant to have internal linkage have DECL_THIS_STATIC set.  */
     really meant to have internal linkage have DECL_THIS_STATIC set.  */
  if (TREE_CODE (decl) == TYPE_DECL)
  if (TREE_CODE (decl) == TYPE_DECL)
    return lk_external;
    return lk_external;
  if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
  if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
    {
    {
      if (!DECL_THIS_STATIC (decl))
      if (!DECL_THIS_STATIC (decl))
        return lk_external;
        return lk_external;
 
 
      /* Static data members and static member functions from classes
      /* Static data members and static member functions from classes
         in anonymous namespace also don't have TREE_PUBLIC set.  */
         in anonymous namespace also don't have TREE_PUBLIC set.  */
      if (DECL_CLASS_CONTEXT (decl))
      if (DECL_CLASS_CONTEXT (decl))
        return lk_external;
        return lk_external;
    }
    }
 
 
  /* Everything else has internal linkage.  */
  /* Everything else has internal linkage.  */
  return lk_internal;
  return lk_internal;
}
}


/* EXP is an expression that we want to pre-evaluate.  Returns (in
/* EXP is an expression that we want to pre-evaluate.  Returns (in
   *INITP) an expression that will perform the pre-evaluation.  The
   *INITP) an expression that will perform the pre-evaluation.  The
   value returned by this function is a side-effect free expression
   value returned by this function is a side-effect free expression
   equivalent to the pre-evaluated expression.  Callers must ensure
   equivalent to the pre-evaluated expression.  Callers must ensure
   that *INITP is evaluated before EXP.  */
   that *INITP is evaluated before EXP.  */
 
 
tree
tree
stabilize_expr (tree exp, tree* initp)
stabilize_expr (tree exp, tree* initp)
{
{
  tree init_expr;
  tree init_expr;
 
 
  if (!TREE_SIDE_EFFECTS (exp))
  if (!TREE_SIDE_EFFECTS (exp))
    init_expr = NULL_TREE;
    init_expr = NULL_TREE;
  else if (!real_lvalue_p (exp)
  else if (!real_lvalue_p (exp)
           || !TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (exp)))
           || !TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (exp)))
    {
    {
      init_expr = get_target_expr (exp);
      init_expr = get_target_expr (exp);
      exp = TARGET_EXPR_SLOT (init_expr);
      exp = TARGET_EXPR_SLOT (init_expr);
    }
    }
  else
  else
    {
    {
      exp = cp_build_unary_op (ADDR_EXPR, exp, 1, tf_warning_or_error);
      exp = cp_build_unary_op (ADDR_EXPR, exp, 1, tf_warning_or_error);
      init_expr = get_target_expr (exp);
      init_expr = get_target_expr (exp);
      exp = TARGET_EXPR_SLOT (init_expr);
      exp = TARGET_EXPR_SLOT (init_expr);
      exp = cp_build_indirect_ref (exp, RO_NULL, tf_warning_or_error);
      exp = cp_build_indirect_ref (exp, RO_NULL, tf_warning_or_error);
    }
    }
  *initp = init_expr;
  *initp = init_expr;
 
 
  gcc_assert (!TREE_SIDE_EFFECTS (exp));
  gcc_assert (!TREE_SIDE_EFFECTS (exp));
  return exp;
  return exp;
}
}
 
 
/* Add NEW_EXPR, an expression whose value we don't care about, after the
/* Add NEW_EXPR, an expression whose value we don't care about, after the
   similar expression ORIG.  */
   similar expression ORIG.  */
 
 
tree
tree
add_stmt_to_compound (tree orig, tree new_expr)
add_stmt_to_compound (tree orig, tree new_expr)
{
{
  if (!new_expr || !TREE_SIDE_EFFECTS (new_expr))
  if (!new_expr || !TREE_SIDE_EFFECTS (new_expr))
    return orig;
    return orig;
  if (!orig || !TREE_SIDE_EFFECTS (orig))
  if (!orig || !TREE_SIDE_EFFECTS (orig))
    return new_expr;
    return new_expr;
  return build2 (COMPOUND_EXPR, void_type_node, orig, new_expr);
  return build2 (COMPOUND_EXPR, void_type_node, orig, new_expr);
}
}
 
 
/* Like stabilize_expr, but for a call whose arguments we want to
/* Like stabilize_expr, but for a call whose arguments we want to
   pre-evaluate.  CALL is modified in place to use the pre-evaluated
   pre-evaluate.  CALL is modified in place to use the pre-evaluated
   arguments, while, upon return, *INITP contains an expression to
   arguments, while, upon return, *INITP contains an expression to
   compute the arguments.  */
   compute the arguments.  */
 
 
void
void
stabilize_call (tree call, tree *initp)
stabilize_call (tree call, tree *initp)
{
{
  tree inits = NULL_TREE;
  tree inits = NULL_TREE;
  int i;
  int i;
  int nargs = call_expr_nargs (call);
  int nargs = call_expr_nargs (call);
 
 
  if (call == error_mark_node || processing_template_decl)
  if (call == error_mark_node || processing_template_decl)
    {
    {
      *initp = NULL_TREE;
      *initp = NULL_TREE;
      return;
      return;
    }
    }
 
 
  gcc_assert (TREE_CODE (call) == CALL_EXPR);
  gcc_assert (TREE_CODE (call) == CALL_EXPR);
 
 
  for (i = 0; i < nargs; i++)
  for (i = 0; i < nargs; i++)
    {
    {
      tree init;
      tree init;
      CALL_EXPR_ARG (call, i) =
      CALL_EXPR_ARG (call, i) =
        stabilize_expr (CALL_EXPR_ARG (call, i), &init);
        stabilize_expr (CALL_EXPR_ARG (call, i), &init);
      inits = add_stmt_to_compound (inits, init);
      inits = add_stmt_to_compound (inits, init);
    }
    }
 
 
  *initp = inits;
  *initp = inits;
}
}
 
 
/* Like stabilize_expr, but for an AGGR_INIT_EXPR whose arguments we want
/* Like stabilize_expr, but for an AGGR_INIT_EXPR whose arguments we want
   to pre-evaluate.  CALL is modified in place to use the pre-evaluated
   to pre-evaluate.  CALL is modified in place to use the pre-evaluated
   arguments, while, upon return, *INITP contains an expression to
   arguments, while, upon return, *INITP contains an expression to
   compute the arguments.  */
   compute the arguments.  */
 
 
void
void
stabilize_aggr_init (tree call, tree *initp)
stabilize_aggr_init (tree call, tree *initp)
{
{
  tree inits = NULL_TREE;
  tree inits = NULL_TREE;
  int i;
  int i;
  int nargs = aggr_init_expr_nargs (call);
  int nargs = aggr_init_expr_nargs (call);
 
 
  if (call == error_mark_node)
  if (call == error_mark_node)
    return;
    return;
 
 
  gcc_assert (TREE_CODE (call) == AGGR_INIT_EXPR);
  gcc_assert (TREE_CODE (call) == AGGR_INIT_EXPR);
 
 
  for (i = 0; i < nargs; i++)
  for (i = 0; i < nargs; i++)
    {
    {
      tree init;
      tree init;
      AGGR_INIT_EXPR_ARG (call, i) =
      AGGR_INIT_EXPR_ARG (call, i) =
        stabilize_expr (AGGR_INIT_EXPR_ARG (call, i), &init);
        stabilize_expr (AGGR_INIT_EXPR_ARG (call, i), &init);
      inits = add_stmt_to_compound (inits, init);
      inits = add_stmt_to_compound (inits, init);
    }
    }
 
 
  *initp = inits;
  *initp = inits;
}
}
 
 
/* Like stabilize_expr, but for an initialization.
/* Like stabilize_expr, but for an initialization.
 
 
   If the initialization is for an object of class type, this function
   If the initialization is for an object of class type, this function
   takes care not to introduce additional temporaries.
   takes care not to introduce additional temporaries.
 
 
   Returns TRUE iff the expression was successfully pre-evaluated,
   Returns TRUE iff the expression was successfully pre-evaluated,
   i.e., if INIT is now side-effect free, except for, possible, a
   i.e., if INIT is now side-effect free, except for, possible, a
   single call to a constructor.  */
   single call to a constructor.  */
 
 
bool
bool
stabilize_init (tree init, tree *initp)
stabilize_init (tree init, tree *initp)
{
{
  tree t = init;
  tree t = init;
 
 
  *initp = NULL_TREE;
  *initp = NULL_TREE;
 
 
  if (t == error_mark_node || processing_template_decl)
  if (t == error_mark_node || processing_template_decl)
    return true;
    return true;
 
 
  if (TREE_CODE (t) == INIT_EXPR
  if (TREE_CODE (t) == INIT_EXPR
      && TREE_CODE (TREE_OPERAND (t, 1)) != TARGET_EXPR
      && TREE_CODE (TREE_OPERAND (t, 1)) != TARGET_EXPR
      && TREE_CODE (TREE_OPERAND (t, 1)) != AGGR_INIT_EXPR)
      && TREE_CODE (TREE_OPERAND (t, 1)) != AGGR_INIT_EXPR)
    {
    {
      TREE_OPERAND (t, 1) = stabilize_expr (TREE_OPERAND (t, 1), initp);
      TREE_OPERAND (t, 1) = stabilize_expr (TREE_OPERAND (t, 1), initp);
      return true;
      return true;
    }
    }
 
 
  if (TREE_CODE (t) == INIT_EXPR)
  if (TREE_CODE (t) == INIT_EXPR)
    t = TREE_OPERAND (t, 1);
    t = TREE_OPERAND (t, 1);
  if (TREE_CODE (t) == TARGET_EXPR)
  if (TREE_CODE (t) == TARGET_EXPR)
    t = TARGET_EXPR_INITIAL (t);
    t = TARGET_EXPR_INITIAL (t);
  if (TREE_CODE (t) == COMPOUND_EXPR)
  if (TREE_CODE (t) == COMPOUND_EXPR)
    t = expr_last (t);
    t = expr_last (t);
  if (TREE_CODE (t) == CONSTRUCTOR
  if (TREE_CODE (t) == CONSTRUCTOR
      && EMPTY_CONSTRUCTOR_P (t))
      && EMPTY_CONSTRUCTOR_P (t))
    /* Default-initialization.  */
    /* Default-initialization.  */
    return true;
    return true;
 
 
  /* If the initializer is a COND_EXPR, we can't preevaluate
  /* If the initializer is a COND_EXPR, we can't preevaluate
     anything.  */
     anything.  */
  if (TREE_CODE (t) == COND_EXPR)
  if (TREE_CODE (t) == COND_EXPR)
    return false;
    return false;
 
 
  if (TREE_CODE (t) == CALL_EXPR)
  if (TREE_CODE (t) == CALL_EXPR)
    {
    {
      stabilize_call (t, initp);
      stabilize_call (t, initp);
      return true;
      return true;
    }
    }
 
 
  if (TREE_CODE (t) == AGGR_INIT_EXPR)
  if (TREE_CODE (t) == AGGR_INIT_EXPR)
    {
    {
      stabilize_aggr_init (t, initp);
      stabilize_aggr_init (t, initp);
      return true;
      return true;
    }
    }
 
 
  /* The initialization is being performed via a bitwise copy -- and
  /* The initialization is being performed via a bitwise copy -- and
     the item copied may have side effects.  */
     the item copied may have side effects.  */
  return TREE_SIDE_EFFECTS (init);
  return TREE_SIDE_EFFECTS (init);
}
}
 
 
/* Like "fold", but should be used whenever we might be processing the
/* Like "fold", but should be used whenever we might be processing the
   body of a template.  */
   body of a template.  */
 
 
tree
tree
fold_if_not_in_template (tree expr)
fold_if_not_in_template (tree expr)
{
{
  /* In the body of a template, there is never any need to call
  /* In the body of a template, there is never any need to call
     "fold".  We will call fold later when actually instantiating the
     "fold".  We will call fold later when actually instantiating the
     template.  Integral constant expressions in templates will be
     template.  Integral constant expressions in templates will be
     evaluated via fold_non_dependent_expr, as necessary.  */
     evaluated via fold_non_dependent_expr, as necessary.  */
  if (processing_template_decl)
  if (processing_template_decl)
    return expr;
    return expr;
 
 
  /* Fold C++ front-end specific tree codes.  */
  /* Fold C++ front-end specific tree codes.  */
  if (TREE_CODE (expr) == UNARY_PLUS_EXPR)
  if (TREE_CODE (expr) == UNARY_PLUS_EXPR)
    return fold_convert (TREE_TYPE (expr), TREE_OPERAND (expr, 0));
    return fold_convert (TREE_TYPE (expr), TREE_OPERAND (expr, 0));
 
 
  return fold (expr);
  return fold (expr);
}
}
 
 
/* Returns true if a cast to TYPE may appear in an integral constant
/* Returns true if a cast to TYPE may appear in an integral constant
   expression.  */
   expression.  */
 
 
bool
bool
cast_valid_in_integral_constant_expression_p (tree type)
cast_valid_in_integral_constant_expression_p (tree type)
{
{
  return (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
  return (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
          || dependent_type_p (type)
          || dependent_type_p (type)
          || type == error_mark_node);
          || type == error_mark_node);
}
}
 
 
/* Return true if we need to fix linkage information of DECL.  */
/* Return true if we need to fix linkage information of DECL.  */
 
 
static bool
static bool
cp_fix_function_decl_p (tree decl)
cp_fix_function_decl_p (tree decl)
{
{
  /* Skip if DECL is not externally visible.  */
  /* Skip if DECL is not externally visible.  */
  if (!TREE_PUBLIC (decl))
  if (!TREE_PUBLIC (decl))
    return false;
    return false;
 
 
  /* We need to fix DECL if it a appears to be exported but with no
  /* We need to fix DECL if it a appears to be exported but with no
     function body.  Thunks do not have CFGs and we may need to
     function body.  Thunks do not have CFGs and we may need to
     handle them specially later.   */
     handle them specially later.   */
  if (!gimple_has_body_p (decl)
  if (!gimple_has_body_p (decl)
      && !DECL_THUNK_P (decl)
      && !DECL_THUNK_P (decl)
      && !DECL_EXTERNAL (decl))
      && !DECL_EXTERNAL (decl))
    {
    {
      struct cgraph_node *node = cgraph_get_node (decl);
      struct cgraph_node *node = cgraph_get_node (decl);
 
 
      /* Don't fix same_body aliases.  Although they don't have their own
      /* Don't fix same_body aliases.  Although they don't have their own
         CFG, they share it with what they alias to.  */
         CFG, they share it with what they alias to.  */
      if (!node
      if (!node
          || node->decl == decl
          || node->decl == decl
          || !node->same_body)
          || !node->same_body)
        return true;
        return true;
    }
    }
 
 
  return false;
  return false;
}
}
 
 
/* Clean the C++ specific parts of the tree T. */
/* Clean the C++ specific parts of the tree T. */
 
 
void
void
cp_free_lang_data (tree t)
cp_free_lang_data (tree t)
{
{
  if (TREE_CODE (t) == METHOD_TYPE
  if (TREE_CODE (t) == METHOD_TYPE
      || TREE_CODE (t) == FUNCTION_TYPE)
      || TREE_CODE (t) == FUNCTION_TYPE)
    {
    {
      /* Default args are not interesting anymore.  */
      /* Default args are not interesting anymore.  */
      tree argtypes = TYPE_ARG_TYPES (t);
      tree argtypes = TYPE_ARG_TYPES (t);
      while (argtypes)
      while (argtypes)
        {
        {
          TREE_PURPOSE (argtypes) = 0;
          TREE_PURPOSE (argtypes) = 0;
          argtypes = TREE_CHAIN (argtypes);
          argtypes = TREE_CHAIN (argtypes);
        }
        }
    }
    }
  else if (TREE_CODE (t) == FUNCTION_DECL
  else if (TREE_CODE (t) == FUNCTION_DECL
           && cp_fix_function_decl_p (t))
           && cp_fix_function_decl_p (t))
    {
    {
      /* If T is used in this translation unit at all,  the definition
      /* If T is used in this translation unit at all,  the definition
         must exist somewhere else since we have decided to not emit it
         must exist somewhere else since we have decided to not emit it
         in this TU.  So make it an external reference.  */
         in this TU.  So make it an external reference.  */
      DECL_EXTERNAL (t) = 1;
      DECL_EXTERNAL (t) = 1;
      TREE_STATIC (t) = 0;
      TREE_STATIC (t) = 0;
    }
    }
  if (CP_AGGREGATE_TYPE_P (t)
  if (CP_AGGREGATE_TYPE_P (t)
      && TYPE_NAME (t))
      && TYPE_NAME (t))
    {
    {
      tree name = TYPE_NAME (t);
      tree name = TYPE_NAME (t);
      if (TREE_CODE (name) == TYPE_DECL)
      if (TREE_CODE (name) == TYPE_DECL)
        name = DECL_NAME (name);
        name = DECL_NAME (name);
      /* Drop anonymous names.  */
      /* Drop anonymous names.  */
      if (name != NULL_TREE
      if (name != NULL_TREE
          && ANON_AGGRNAME_P (name))
          && ANON_AGGRNAME_P (name))
        TYPE_NAME (t) = NULL_TREE;
        TYPE_NAME (t) = NULL_TREE;
    }
    }
}
}
 
 


#if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
#if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
/* Complain that some language-specific thing hanging off a tree
/* Complain that some language-specific thing hanging off a tree
   node has been accessed improperly.  */
   node has been accessed improperly.  */
 
 
void
void
lang_check_failed (const char* file, int line, const char* function)
lang_check_failed (const char* file, int line, const char* function)
{
{
  internal_error ("lang_* check: failed in %s, at %s:%d",
  internal_error ("lang_* check: failed in %s, at %s:%d",
                  function, trim_filename (file), line);
                  function, trim_filename (file), line);
}
}
#endif /* ENABLE_TREE_CHECKING */
#endif /* ENABLE_TREE_CHECKING */
 
 
#include "gt-cp-tree.h"
#include "gt-cp-tree.h"
 
 

powered by: WebSVN 2.1.0

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