home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cplusplus-8 / cplus-tree.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-20  |  35.4 KB  |  1,325 lines

  1. /* Language-depednent node constructors for parse phase of GNU compiler.
  2.    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
  3.    Hacked by Michael Tiemann (tiemann@mcc.com)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include "config.h"
  22. #include <stdio.h>
  23. #include "obstack.h"
  24. #include "tree.h"
  25. #include "cplus-tree.h"
  26. #include "flags.h"
  27. #include "assert.h"
  28.  
  29. #define MAX(x,y) ((x) > (y) ? (x) : (y))
  30. #define MIN(x,y) ((x) < (y) ? (x) : (y))
  31. #define CEIL(x,y) (((x) + (y) - 1) / (y))
  32.  
  33. /* Return nonzero if REF is an lvalue valid for this language.
  34.    Lvalues can be assigned, unless they have TREE_READONLY.
  35.    Lvalues can have their address taken, unless they have TREE_REGDECL.  */
  36.  
  37. int
  38. lvalue_p (ref)
  39.      tree ref;
  40. {
  41.   register enum tree_code code = TREE_CODE (ref);
  42.  
  43.   if (language_lvalue_valid (ref))
  44.     switch (code)
  45.       {
  46.       case COMPONENT_REF:
  47.     return lvalue_p (TREE_OPERAND (ref, 0));
  48.  
  49.       case STRING_CST:
  50.     return 1;
  51.  
  52.       case VAR_DECL:
  53.     if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
  54.         && DECL_LANG_SPECIFIC (ref)
  55.         && DECL_IN_AGGR_P (ref))
  56.       return 0;
  57.       case INDIRECT_REF:
  58.       case ARRAY_REF:
  59.       case PARM_DECL:
  60.       case RESULT_DECL:
  61.       case ERROR_MARK:
  62.     if (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
  63.         && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
  64.       return 1;
  65.     break;
  66.  
  67.       case NEW_EXPR:
  68.     return 1;
  69.  
  70.       case CALL_EXPR:
  71.     if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE
  72.         /* unary_complex_lvalue knows how to deal with this case.  */
  73.         || TREE_ADDRESSABLE (TREE_TYPE (ref)))
  74.       return 1;
  75.     break;
  76.  
  77.     /* A currently unresolved scope ref.  */
  78.       case SCOPE_REF:
  79.     abort ();
  80.       case OFFSET_REF:
  81.     if (TREE_CODE (TREE_OPERAND (ref, 1)) == FUNCTION_DECL)
  82.       return 1;
  83.     if (TREE_CODE (TREE_OPERAND (ref, 1)) == VAR_DECL)
  84.       if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
  85.           && DECL_LANG_SPECIFIC (ref)
  86.           && DECL_IN_AGGR_P (ref))
  87.         return 0;
  88.       else
  89.         return 1;
  90.     break;
  91.       }
  92.   return 0;
  93. }
  94.  
  95. /* Return nonzero if REF is an lvalue valid for this language;
  96.    otherwise, print an error message and return zero.  */
  97.  
  98. int
  99. lvalue_or_else (ref, string)
  100.      tree ref;
  101.      char *string;
  102. {
  103.   int win = lvalue_p (ref);
  104.   if (! win)
  105.     error ("invalid lvalue in %s", string);
  106.   return win;
  107. }
  108.  
  109. /* INIT is a CALL_EXPR which needs info about its target.
  110.    TYPE is the type that this initialization should appear to have.
  111.  
  112.    Build an encapsultation of the initialization to perfom
  113.    and return it so that it can be processed by language-independent
  114.    and language-specific expression expanders.  */
  115. tree
  116. build_cplus_new (type, init)
  117.      tree type;
  118.      tree init;
  119. {
  120.   tree slot = build (VAR_DECL, type);
  121.   tree rval = build (CPLUS_NEW_EXPR, type,
  122.              TREE_OPERAND (init, 0), TREE_OPERAND (init, 1), slot);
  123.   TREE_ADDRESSABLE (rval) = 1;
  124.   rval = build (NEW_EXPR, type, slot, rval, 0);
  125.   TREE_ADDRESSABLE (rval) = 1;
  126.   return rval;
  127. }
  128.  
  129. extern struct obstack *current_obstack;
  130. extern struct obstack permanent_obstack, class_obstack;
  131. extern struct obstack *saveable_obstack;
  132.  
  133. /* Return a type like TYPE except that its CLASSTYPE_OFFSET
  134.    is OFFSET.
  135.  
  136.    Such variant types already made are recorded so that duplicates
  137.    are not made.
  138.  
  139.    A variant types should never be used as the type of an expression.
  140.    Use TYPE_MAIN_VARIANT to find the main variant.  */
  141.  
  142. tree
  143. build_classtype_variant (type, offset, virtualp)
  144.      tree type;
  145.      tree offset;
  146.      int virtualp;
  147. {
  148.   register tree t, m = CLASSTYPE_MAIN_VARIANT (type);
  149.   register struct obstack *ambient_obstack = current_obstack;
  150.   register struct obstack *ambient_saveable_obstack = saveable_obstack;
  151.   register int lo = TREE_INT_CST_LOW (offset);
  152.   register int hi = TREE_INT_CST_HIGH (offset);
  153.   /* First search the chain variants for one that is what we want.  */
  154.  
  155.   if (hi == 0 && lo == 0)
  156.     offset = integer_zero_node;
  157.  
  158.   for (t = m; t; t = CLASSTYPE_NEXT_VARIANT (t))
  159.     if (virtualp == TREE_VIA_VIRTUAL (t)
  160.     && lo == TREE_INT_CST_LOW (CLASSTYPE_OFFSET (t))
  161.     && hi == TREE_INT_CST_HIGH (CLASSTYPE_OFFSET (t)))
  162.       return t;
  163.  
  164.   /* We need a new one.  */
  165.   if (TREE_PERMANENT (type))
  166.     saveable_obstack = &permanent_obstack;
  167.   current_obstack = saveable_obstack;
  168.  
  169.   t = copy_node (type);
  170.   copy_type_lang_specific (t);
  171.   CLASSTYPE_AS_LIST (t) = build_tree_list (NULL_TREE, t);
  172.  
  173.   TYPE_POINTER_TO (t) = 0;
  174.   TYPE_REFERENCE_TO (t) = 0;
  175.   CLASSTYPE_OFFSET (t) = offset;
  176.   TREE_VIA_VIRTUAL (t) = virtualp;
  177.  
  178.   /* Always promise to have TYPE_POINTER_TO filled in.  */
  179.   build_pointer_type (t);
  180.  
  181.   /* Add this type to the chain of variants of TYPE.  */
  182.   CLASSTYPE_NEXT_VARIANT (t) = CLASSTYPE_NEXT_VARIANT (m);
  183.   CLASSTYPE_NEXT_VARIANT (m) = t;
  184.  
  185.   current_obstack = ambient_obstack;
  186.   saveable_obstack = ambient_saveable_obstack;
  187.   return t;
  188. }
  189.  
  190. /* Here is how primitive or already-canonicalized types' hash
  191.    codes are made.  MUST BE CONSISTENT WITH tree.c !!! */
  192. #define TYPE_HASH(TYPE) TREE_UID (TYPE)
  193.  
  194. /* Construct, lay out and return the type of methods belonging to class
  195.    BASETYPE and whose arguments and values are described by TYPE.
  196.    If that type exists already, reuse it.
  197.    TYPE must be a FUNCTION_TYPE node.  */
  198.  
  199. tree
  200. build_cplus_method_type (basetype, rettype, argtypes)
  201.      tree basetype, rettype, argtypes;
  202. {
  203.   register tree t;
  204.   tree ptype = build_pointer_type (basetype);
  205.   int hashcode;
  206.  
  207.   /* Make a node of the sort we want.  */
  208.   t = make_node (METHOD_TYPE);
  209.  
  210.   TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
  211.   TREE_TYPE (t) = rettype;
  212.   ptype = build_type_variant (ptype, !flag_this_is_variable, 0);
  213.  
  214.   /* The actual arglist for this function includes a "hidden" argument
  215.      which is "this".  Put it into the list of argument types.  */
  216.  
  217.   TYPE_ARG_TYPES (t) = tree_cons (NULL, ptype, argtypes);
  218.  
  219.   /* If we already have such a type, use the old one and free this one.
  220.      Note that it also frees up the above cons cell if found.  */
  221.   hashcode = TYPE_HASH (basetype) + TYPE_HASH (rettype) + type_hash_list (argtypes);
  222.   t = type_hash_canon (hashcode, t);
  223.  
  224.   if (TYPE_SIZE (t) == 0)
  225.     layout_type (t);
  226.  
  227.   return t;
  228. }
  229.  
  230. tree
  231. build_cplus_array_type (elt_type, index_type)
  232.      tree elt_type;
  233.      tree index_type;
  234. {
  235.   register struct obstack *ambient_obstack = current_obstack;
  236.   register struct obstack *ambient_saveable_obstack = saveable_obstack;
  237.   tree t;
  238.  
  239.   /* We need a new one.  If ELT_TYPE is permanent, make this permanent too.  */
  240.   if (TREE_PERMANENT (elt_type))
  241.     {
  242.       current_obstack = &permanent_obstack;
  243.       saveable_obstack = &permanent_obstack;
  244.     }
  245.  
  246.   t = build_array_type (elt_type, index_type);
  247.  
  248.   /* Push these needs up so that initialization takes place
  249.      more easily.  */
  250.   TYPE_NEEDS_CONSTRUCTING (t) = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type));
  251.   TYPE_NEEDS_DESTRUCTOR (t) = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type));
  252.   current_obstack = ambient_obstack;
  253.   saveable_obstack = ambient_saveable_obstack;
  254.   return t;
  255. }
  256.  
  257. /* This is temporary until later.  */
  258. /* Construct, lay out and return the type of objects which are of type TYPE
  259.    as members of type BASETYPE.  If that type exists already, reuse it.  */
  260. tree
  261. build_member_type (basetype, type)
  262.      tree basetype, type;
  263. {
  264.   register tree t;
  265.   int hashcode;
  266.  
  267.   assert (TREE_CODE (type) != FUNCTION_TYPE);
  268.  
  269.   /* Make a node of the sort we want.  */
  270.   t = make_node (OFFSET_TYPE);
  271.   TYPE_OFFSET_BASETYPE (t) = basetype;
  272.   TREE_TYPE (t) = type;
  273.   hashcode = TREE_UID (basetype) + TREE_UID (type);
  274.   t = type_hash_canon (hashcode, t);
  275.  
  276.   return t;
  277. }
  278.  
  279. /* Compute the actual offsets that our virtual base classes
  280.    will have *for this type*.  This must be performed after
  281.    the fields are laid out, since virtual baseclasses must
  282.    lay down at the end of the record.
  283.  
  284.    Returns the maximum number of virtual functions any of the virtual
  285.    baseclasses provide.  */
  286. int
  287. layout_vbasetypes (rec, max)
  288.      tree rec;
  289.      int max;
  290. {
  291.   /* Get all the virtual base types that this type uses.
  292.      The TREE_VALUE slot holds the virtual baseclass type.  */
  293.   tree vbase_types = get_vbase_types (rec);
  294.  
  295. #ifdef STRUCTURE_SIZE_BOUNDARY
  296.   int record_align = MAX (STRUCTURE_SIZE_BOUNDARY, TYPE_ALIGN (rec));
  297. #else
  298.   int record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (rec));
  299. #endif
  300.  
  301.   /* Record size so far is CONST_SIZE + VAR_SIZE * SIZE_UNIT bits,
  302.      where CONST_SIZE is an integer
  303.      and VAR_SIZE is a tree expression.
  304.      If VAR_SIZE is null, the size is just CONST_SIZE.
  305.      Naturally we try to avoid using VAR_SIZE.  */
  306.   register int const_size = 0;
  307.   register tree var_size = 0;
  308.   register int size_unit = BITS_PER_UNIT;
  309.   int nonvirtual_const_size;
  310.   tree nonvirtual_var_size;
  311.  
  312.   CLASSTYPE_VBASECLASSES (rec) = vbase_types;
  313.  
  314.   if (TREE_CODE (TYPE_SIZE (rec)) == INTEGER_CST)
  315.     const_size = TREE_INT_CST_LOW (TYPE_SIZE (rec)) * TYPE_SIZE_UNIT (rec);
  316.   else
  317.     {
  318.       var_size = TYPE_SIZE (rec);
  319.       size_unit = record_align;
  320.     }
  321.  
  322.   nonvirtual_const_size = const_size;
  323.   nonvirtual_var_size = var_size;
  324.  
  325.   while (vbase_types)
  326.     {
  327.       int inc;
  328.       tree basetype = ASSOC_TYPE (vbase_types);
  329.       tree offset;
  330.  
  331.       if (const_size == 0)
  332.     offset = integer_zero_node;
  333.       else
  334.     offset = convert_units (build_int (const_size), 1, BITS_PER_UNIT);
  335.  
  336.       if (CLASSTYPE_VSIZE (basetype) > max)
  337.     max = CLASSTYPE_VSIZE (basetype);
  338.       ASSOC_OFFSET (vbase_types) = offset;
  339.  
  340.       inc = MAX (record_align,
  341.          (TREE_INT_CST_LOW (TYPE_SIZE (basetype))
  342.           - TREE_INT_CST_LOW (CLASSTYPE_VBASE_SIZE (basetype)))
  343.          * TYPE_SIZE_UNIT (basetype));
  344.  
  345.       const_size += inc;
  346.       vbase_types = TREE_CHAIN (vbase_types);
  347.     }
  348.  
  349.   if (const_size - nonvirtual_const_size)
  350.     {
  351.       CLASSTYPE_VBASE_SIZE (rec) = convert_units (build_int (const_size - nonvirtual_const_size),
  352.                           1, BITS_PER_UNIT);
  353.       TYPE_SIZE (rec) = convert_units (build_int (const_size), 1, BITS_PER_UNIT);
  354.     }
  355.   else
  356.     CLASSTYPE_VBASE_SIZE (rec) = integer_zero_node;
  357.   return max;
  358. }
  359.  
  360. #if 0
  361. /* This function should never be needed.  */
  362. void
  363. fixup_vbase_offsets (type)
  364.      tree type;
  365. {
  366.   tree virtuals = TREE_CHAIN (CLASS_ASSOC_VIRTUALS (type));
  367.  
  368.   while (virtuals)
  369.     {
  370.       tree pfn = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals));
  371.       tree decl = TREE_OPERAND (pfn, 0);
  372.       tree vcontext = get_base_type (DECL_VCONTEXT (decl), DECL_CONTEXT (decl), 0);
  373.       if (vcontext != NULL_TREE && TREE_VIA_VIRTUAL (vcontext))
  374.     {
  375.       tree offset;
  376.       tree vbase_offset_info;
  377.       tree parent_type;
  378.  
  379.       if (DECL_CONTEXT (decl) == TYPE_MAIN_VARIANT (type))
  380.         parent_type = type;
  381.       else
  382.         {
  383.           parent_type = get_base_type (DECL_CONTEXT (decl), type, 0);
  384.           if (parent_type == 0)
  385.         parent_type = type;
  386.         }
  387.       vbase_offset_info = value_member (vcontext,
  388.                         CLASSTYPE_VBASECLASSES (parent_type));
  389.       offset = genop (MINUS_EXPR, CLASSTYPE_OFFSET (parent_type),
  390.               TREE_PURPOSE (vbase_offset_info));
  391.       TREE_VALUE (virtuals) = build_vtable_entry (offset, pfn);
  392.     }
  393.       virtuals = TREE_CHAIN (virtuals);
  394.     }
  395. }
  396. #endif
  397.  
  398. /* Lay out the base types of a record type, REC.
  399.    Tentatively set the size and alignment of REC
  400.    according to the base types alone.
  401.  
  402.    Returns list of virtual base classes in a FIELD_DECL chain.  */
  403. tree
  404. layout_basetypes (rec)
  405.      tree rec;
  406. {
  407.   /* Chain to hold all the new FIELD_DECLs which point at virtual
  408.      base classes.  */
  409.   tree vbase_decls = NULL_TREE;
  410.  
  411. #ifdef STRUCTURE_SIZE_BOUNDARY
  412.   int record_align = MAX (STRUCTURE_SIZE_BOUNDARY, TYPE_ALIGN (rec));
  413. #else
  414.   int record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (rec));
  415. #endif
  416.  
  417.   /* Record size so far is CONST_SIZE + VAR_SIZE * SIZE_UNIT bits,
  418.      where CONST_SIZE is an integer
  419.      and VAR_SIZE is a tree expression.
  420.      If VAR_SIZE is null, the size is just CONST_SIZE.
  421.      Naturally we try to avoid using VAR_SIZE.  */
  422.   register int const_size = 0;
  423.   register tree var_size = 0;
  424.   register int size_unit = BITS_PER_UNIT;
  425.   int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (rec);
  426.  
  427.   /* Handle basetypes almost like fields, but record their
  428.      offsets differently.  */
  429.  
  430.   for (i = 1; i <= n_baseclasses; i++)
  431.     {
  432.       int inc, desired_align;
  433.       register tree basetype = CLASSTYPE_BASECLASS (rec, i);
  434.       tree decl;
  435.  
  436.       if (TYPE_SIZE (basetype) == 0)
  437.     {
  438.       error_with_aggr_type (basetype, "base class `%s' has incomplete type");
  439.       SET_CLASSTYPE_VIAS (rec, i, 1, 0);
  440.       continue;
  441.     }
  442.  
  443.       /* All basetypes are recorded in the association list of the
  444.      derived type.  */
  445.  
  446.       if (CLASSTYPE_VIA_VIRTUAL (rec, i))
  447.     {
  448.       int j;
  449.       char *name = (char *)alloca (TYPE_NAME_LENGTH (basetype)
  450.                        + sizeof (VBASE_NAME) + 1);
  451.       sprintf (name, VBASE_NAME_FORMAT, TYPE_NAME_STRING (basetype));
  452.  
  453.       /* The offset for a virtual base class is only
  454.          used in computing virtual function tables and
  455.          for initializing virtual base pointers.  The assoc
  456.          for this base type is built once `get_vbase_types'
  457.          is called.  */
  458.       CLASSTYPE_BASECLASS (rec, i) = basetype
  459.         = build_classtype_variant (basetype, integer_zero_node, 1);
  460.  
  461.       /* If this basetype can come from another vbase pointer
  462.          without an additional indirection, we will share
  463.          that pointer.  If an indirection is involved, we
  464.          make our own pointer.  */
  465.       for (j = 1; j <= n_baseclasses; j++)
  466.         if (! CLASSTYPE_VIA_VIRTUAL (rec, j)
  467.         && TYPE_USES_VIRTUAL_BASECLASSES (CLASSTYPE_BASECLASS (rec, j))
  468.         && value_member (TYPE_MAIN_VARIANT (basetype),
  469.                  CLASSTYPE_VBASECLASSES (CLASSTYPE_BASECLASS (rec, j))))
  470.           {
  471.         goto got_it;
  472.           }
  473.  
  474.       decl = build_lang_decl (FIELD_DECL, get_identifier (name),
  475.                   build_pointer_type (basetype));
  476.       DECL_FIELD_CONTEXT (decl) = rec;
  477.       SET_DECL_FCONTEXT (decl, TYPE_MAIN_VARIANT (basetype));
  478.       DECL_VBASE_P (decl) = 1;
  479.       TREE_CHAIN (decl) = vbase_decls;
  480.       vbase_decls = decl;
  481.  
  482.     got_it:
  483.       /* The space this decl occupies has already been accounted for.  */
  484.       continue;
  485.     }
  486.       else
  487.     {
  488.       tree class_offset;
  489.       tree assoc;
  490.  
  491.       if (const_size == 0)
  492.         class_offset = integer_zero_node;
  493.       else
  494.         {
  495.           /* Give each base type the alignment it wants.  */
  496.           const_size = CEIL (const_size, TYPE_ALIGN (basetype))
  497.         * TYPE_ALIGN (basetype);
  498.           class_offset = convert_units (build_int (const_size), 1, BITS_PER_UNIT);
  499.           CLASSTYPE_BASECLASS (rec, i) = basetype
  500.         = build_classtype_variant (basetype, class_offset, 0);
  501.         }
  502.  
  503.       if (CLASSTYPE_VSIZE (basetype))
  504.         assoc = make_assoc (class_offset, basetype,
  505.                 CLASS_ASSOC_VTABLE (basetype),
  506.                 CLASS_ASSOC_VIRTUALS (basetype),
  507.                 CLASSTYPE_ASSOC (rec));
  508.       else
  509.         assoc = make_assoc (class_offset, basetype, 0, 0,
  510.                 CLASSTYPE_ASSOC (rec));
  511.       CLASSTYPE_ASSOC (rec) = assoc;
  512.       if (const_size != 0)
  513.         {
  514.           TYPE_NAME (basetype) = copy_node (TYPE_NAME (basetype));
  515.           TREE_TYPE (TYPE_NAME (basetype)) = basetype;
  516.           DECL_OFFSET (TYPE_NAME (basetype)) = const_size;
  517.         }
  518.     }
  519.  
  520.       /* Add only the amount of storage not present in
  521.      the virtual baseclasses.  */
  522.       inc = MAX (record_align,
  523.          (TREE_INT_CST_LOW (TYPE_SIZE (basetype))
  524.           - TREE_INT_CST_LOW (CLASSTYPE_VBASE_SIZE (basetype)))
  525.          * TYPE_SIZE_UNIT (basetype));
  526.  
  527.       /* Record must have at least as much alignment as any field.  */
  528.       desired_align = TYPE_ALIGN (basetype);
  529.       record_align = MAX (record_align, desired_align);
  530.  
  531.       const_size += inc;
  532.     }
  533.  
  534.   if (const_size)
  535.     CLASSTYPE_SIZE (rec) = build_int_2 (const_size, 0);
  536.   else
  537.     CLASSTYPE_SIZE (rec) = integer_zero_node;
  538.   CLASSTYPE_ALIGN (rec) = record_align;
  539.  
  540.   return vbase_decls;
  541. }
  542.  
  543. /* Hashing of lists so that we don't make duplicates.
  544.    The entry point is `list_hash_canon'.  */
  545.  
  546. /* Each hash table slot is a bucket containing a chain
  547.    of these structures.  */
  548.  
  549. struct list_hash
  550. {
  551.   struct list_hash *next;    /* Next structure in the bucket.  */
  552.   int hashcode;            /* Hash code of this list.  */
  553.   tree list;            /* The list recorded here.  */
  554. };
  555.  
  556. /* Now here is the hash table.  When recording a list, it is added
  557.    to the slot whose index is the hash code mod the table size.
  558.    Note that the hash table is used for several kinds of lists.
  559.    While all these live in the same table, they are completely independent,
  560.    and the hash code is computed differently for each of these.  */
  561.  
  562. #define TYPE_HASH_SIZE 59
  563. struct list_hash *list_hash_table[TYPE_HASH_SIZE];
  564.  
  565. /* Here is how primitive or already-canonicalized lists' hash
  566.    codes are made.  */
  567. #define TYPE_HASH(TYPE) TREE_UID (TYPE)
  568.  
  569. /* Compute a hash code for a list (chain of TREE_LIST nodes
  570.    with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
  571.    TREE_COMMON slots), by adding the hash codes of the individual entries.  */
  572.  
  573. int
  574. list_hash (list)
  575.      tree list;
  576. {
  577.   register int hashcode = 0;
  578.  
  579.   if (TREE_CHAIN (list))
  580.     hashcode = TYPE_HASH (TREE_CHAIN (list));
  581.   else
  582.     hashcode = 0;
  583.   if (TREE_VALUE (list))
  584.     hashcode += TYPE_HASH (TREE_VALUE (list));
  585.   else
  586.     hashcode += 1007;
  587.   if (TREE_PURPOSE (list))
  588.     hashcode += TYPE_HASH (TREE_PURPOSE (list));
  589.   else
  590.     hashcode += 1009;
  591.   return hashcode;
  592. }
  593.  
  594. /* Look in the type hash table for a type isomorphic to TYPE.
  595.    If one is found, return it.  Otherwise return 0.  */
  596.  
  597. tree
  598. list_hash_lookup (hashcode, list)
  599.      int hashcode;
  600.      tree list;
  601. {
  602.   register struct list_hash *h;
  603.   for (h = list_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
  604.     if (h->hashcode == hashcode
  605.     && TREE_VIA_VIRTUAL (h->list) == TREE_VIA_VIRTUAL (list)
  606.     && TREE_VIA_PUBLIC (h->list) == TREE_VIA_PUBLIC (list)
  607.     && TREE_PURPOSE (h->list) == TREE_PURPOSE (list)
  608.     && TREE_VALUE (h->list) == TREE_VALUE (list))
  609.       {
  610.     assert (TREE_TYPE (h->list) == TREE_TYPE (list));
  611.     assert (TREE_CHAIN (h->list) == TREE_CHAIN (list));
  612.     return h->list;
  613.       }
  614.   return 0;
  615. }
  616.  
  617. /* Add an entry to the list-hash-table
  618.    for a list TYPE whose hash code is HASHCODE.  */
  619.  
  620. void
  621. list_hash_add (hashcode, list)
  622.      int hashcode;
  623.      tree list;
  624. {
  625.   register struct list_hash *h;
  626.  
  627.   h = (struct list_hash *) obstack_alloc (&class_obstack, sizeof (struct list_hash));
  628.   h->hashcode = hashcode;
  629.   h->list = list;
  630.   h->next = list_hash_table[hashcode % TYPE_HASH_SIZE];
  631.   list_hash_table[hashcode % TYPE_HASH_SIZE] = h;
  632. }
  633.  
  634. /* Given TYPE, and HASHCODE its hash code, return the canonical
  635.    object for an identical list if one already exists.
  636.    Otherwise, return TYPE, and record it as the canonical object
  637.    if it is a permanent object.
  638.  
  639.    To use this function, first create a list of the sort you want.
  640.    Then compute its hash code from the fields of the list that
  641.    make it different from other similar lists.
  642.    Then call this function and use the value.
  643.    This function frees the list you pass in if it is a duplicate.  */
  644.  
  645. /* Set to 1 to debug without canonicalization.  Never set by program.  */
  646. int debug_no_list_hash = 0;
  647.  
  648. tree
  649. list_hash_canon (hashcode, list)
  650.      int hashcode;
  651.      tree list;
  652. {
  653.   tree t1;
  654.  
  655.   if (debug_no_list_hash)
  656.     return list;
  657.  
  658.   t1 = list_hash_lookup (hashcode, list);
  659.   if (t1 != 0)
  660.     {
  661.       obstack_free (&class_obstack, list);
  662.       return t1;
  663.     }
  664.  
  665.   /* If this is a new list, record it for later reuse.  */
  666.   list_hash_add (hashcode, list);
  667.  
  668.   return list;
  669. }
  670.  
  671. tree
  672. hash_tree_cons (via_public, via_virtual, purpose, value, chain)
  673.      int via_public, via_virtual;
  674.      tree purpose, value, chain;
  675. {
  676.   struct obstack *ambient_obstack = current_obstack;
  677.   tree t;
  678.   int hashcode;
  679.  
  680.   current_obstack = &class_obstack;
  681.   t = tree_cons (purpose, value, chain);
  682.   TREE_VIA_PUBLIC (t) = via_public;
  683.   TREE_VIA_VIRTUAL (t) = via_virtual;
  684.   hashcode = list_hash (t);
  685.   t = list_hash_canon (hashcode, t);
  686.   current_obstack = ambient_obstack;
  687.   return t;
  688. }
  689.  
  690. /* Constructor for hashed lists.  */
  691. tree
  692. hash_tree_chain (value, chain)
  693.      tree value, chain;
  694. {
  695.   struct obstack *ambient_obstack = current_obstack;
  696.   tree t;
  697.   int hashcode;
  698.  
  699.   current_obstack = &class_obstack;
  700.   t = tree_cons (NULL_TREE, value, chain);
  701.   hashcode = list_hash (t);
  702.   t = list_hash_canon (hashcode, t);
  703.   current_obstack = ambient_obstack;
  704.   return t;
  705. }
  706.  
  707. /* Similar, but used for concatenating two lists.  */
  708. tree
  709. hash_chainon (list1, list2)
  710.      tree list1, list2;
  711. {
  712.   if (list2 == 0)
  713.     return list1;
  714.   if (list1 == 0)
  715.     return list2;
  716.   if (TREE_CHAIN (list1) == NULL_TREE)
  717.     return hash_tree_chain (TREE_VALUE (list1), list2);
  718.   return hash_tree_chain (TREE_VALUE (list1),
  719.               hash_chainon (TREE_CHAIN (list1), list2));
  720. }
  721.  
  722. tree
  723. build_decl_list_1 (value)
  724.      tree value;
  725. {
  726.   tree list = NULL_TREE;
  727.  
  728.   if (TREE_CODE (value) == IDENTIFIER_NODE)
  729.     {
  730.       list = IDENTIFIER_AS_LIST (value);
  731.       if (list != NULL_TREE
  732.       && (TREE_CODE (list) != TREE_LIST
  733.           || TREE_VALUE (list) != value))
  734.     list = NULL_TREE;
  735.       else if (TREE_TYPE (value) != NULL_TREE
  736.            && TREE_CODE (TREE_TYPE (TREE_TYPE (value))) == RECORD_TYPE)
  737.     {
  738.       tree type = TREE_TYPE (TREE_TYPE (value));
  739.       if (CLASSTYPE_AS_ID_LIST (type) == NULL_TREE)
  740.         CLASSTYPE_AS_ID_LIST (type) = perm_tree_cons (NULL_TREE, value, NULL_TREE);
  741.       list = CLASSTYPE_AS_ID_LIST (type);
  742.     }
  743.     }
  744.   else if (TREE_CODE (value) == RECORD_TYPE
  745.        && TYPE_LANG_SPECIFIC (value))
  746.     list = CLASSTYPE_AS_LIST (value);
  747.  
  748.   if (list != NULL_TREE)
  749.     {
  750.       assert (TREE_CHAIN (list) == NULL_TREE);
  751.       return list;
  752.     }
  753.  
  754. #ifdef OBJCPLUS        /* See comment in cplus-parse.y */
  755.   return build_tree_list (NULL_TREE, value);
  756. #else /* OBJCPLUS */
  757.   return build_decl_list (NULL_TREE, value);
  758. #endif /* OBJCPLUS */
  759. }
  760.  
  761. /* Look in the type hash table for a type isomorphic to
  762.    `build_tree_list (NULL_TREE, VALUE)'.
  763.    If one is found, return it.  Otherwise return 0.  */
  764.  
  765. tree
  766. list_hash_lookup_or_cons (value)
  767.      tree value;
  768. {
  769.   register int hashcode = TYPE_HASH (value);
  770.   register struct list_hash *h;
  771.   struct obstack *ambient_obstack;
  772.   tree list = NULL_TREE;
  773.  
  774.   if (TREE_CODE (value) == IDENTIFIER_NODE)
  775.     {
  776.       list = IDENTIFIER_AS_LIST (value);
  777.       if (list != NULL_TREE
  778.       && (TREE_CODE (list) != TREE_LIST
  779.           || TREE_VALUE (list) != value))
  780.     list = NULL_TREE;
  781.       else if (TREE_TYPE (value) != NULL_TREE
  782.            && TREE_CODE (TREE_TYPE (TREE_TYPE (value))) == RECORD_TYPE)
  783.     {
  784.       tree type = TREE_TYPE (TREE_TYPE (value));
  785.       if (CLASSTYPE_AS_ID_LIST (type) == NULL_TREE)
  786.         CLASSTYPE_AS_ID_LIST (type) = perm_tree_cons (NULL_TREE, value, NULL_TREE);
  787.       list = CLASSTYPE_AS_ID_LIST (type);
  788.     }
  789.     }
  790.   else if (TREE_CODE (value) == TYPE_DECL
  791.        && TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE
  792.        && TYPE_LANG_SPECIFIC (TREE_TYPE (value)))
  793.     list = CLASSTYPE_AS_ID_LIST (TREE_TYPE (value));
  794.   else if (TREE_CODE (value) == RECORD_TYPE
  795.        && TYPE_LANG_SPECIFIC (value))
  796.     list = CLASSTYPE_AS_LIST (value);
  797.  
  798.   if (list != NULL_TREE)
  799.     {
  800.       assert (TREE_CHAIN (list) == NULL_TREE);
  801.       return list;
  802.     }
  803.  
  804.   if (debug_no_list_hash)
  805.     return hash_tree_chain (value, NULL_TREE);
  806.  
  807.   for (h = list_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
  808.     if (h->hashcode == hashcode
  809.     && TREE_VIA_VIRTUAL (h->list) == 0
  810.     && TREE_VIA_PUBLIC (h->list) == 0
  811.     && TREE_PURPOSE (h->list) == 0
  812.     && TREE_VALUE (h->list) == value)
  813.       {
  814.     assert (TREE_TYPE (h->list) == 0);
  815.     assert (TREE_CHAIN (h->list) == 0);
  816.     return h->list;
  817.       }
  818.  
  819.   ambient_obstack = current_obstack;
  820.   current_obstack = &class_obstack;
  821.   list = build_tree_list (NULL_TREE, value);
  822.   list_hash_add (hashcode, list);
  823.   current_obstack = ambient_obstack;
  824.   return list;
  825. }
  826.  
  827. /* Build an association between TYPE and some parameters:
  828.  
  829.    OFFSET is the offset added to `this' to convert it to a pointer
  830.    of type `TYPE *'
  831.  
  832.    VTABLE is the virtual function table with which to initialize
  833.    sub-objects of type TYPE.
  834.  
  835.    VIRTUALS are the virtual functions sitting in VTABLE.
  836.  
  837.    CHAIN are more associations we must retain.  */
  838.  
  839. tree
  840. make_assoc (offset, type, vtable, virtuals, chain)
  841.      tree offset, type;
  842.      tree vtable, virtuals;
  843.      tree chain;
  844. {
  845.   tree assoc = make_tree_vec (4);
  846.  
  847.   TREE_TYPE (assoc) = type;
  848.   TREE_CHAIN (assoc) = chain;
  849.   if (chain)
  850.     TREE_USED (assoc) = TREE_USED (chain);
  851.  
  852.   /* n.b.: TREE_VEC_ELT (assoc, 0) <=> TREE_VALUE (assoc).  */
  853.   TREE_VEC_ELT (assoc, 0) = TYPE_MAIN_VARIANT (type);
  854.   TREE_VEC_ELT (assoc, 1) = offset;
  855.   TREE_VEC_ELT (assoc, 2) = vtable;
  856.   TREE_VEC_ELT (assoc, 3) = virtuals;
  857.   return assoc;
  858. }
  859.  
  860. tree
  861. copy_assoc (list)
  862.      tree list;
  863. {
  864.   tree assoc = copy_list (list);
  865.   tree rval = assoc;
  866.   while (assoc)
  867.     {
  868.       TREE_USED (assoc) = 0;
  869.       assoc = TREE_CHAIN (assoc);
  870.     }
  871.   return rval;
  872. }
  873.  
  874. tree
  875. assoc_value (elem, type)
  876.      tree elem;
  877.      tree type;
  878. {
  879.   tree assoc = CLASSTYPE_ASSOC (type);
  880.   tree rval = NULL_TREE;
  881.  
  882.   /* Dispose quickly of degenerate case.  */
  883.   if (elem == type)
  884.     return assoc;
  885.  
  886.   while (assoc)
  887.     {
  888.       if (elem == ASSOC_VALUE (assoc))
  889.     /* If we find it on the main spine, then
  890.        there can be no ambiguity.  */
  891.     return assoc;
  892.  
  893.       if (ASSOC_VALUE (assoc) != type)
  894.     {
  895.       tree nval = assoc_value (elem, ASSOC_TYPE (assoc));
  896.  
  897.       if (nval)
  898.         if (rval && ASSOC_TYPE (rval) != ASSOC_TYPE (nval))
  899.           /* If we find it underneath, we must make sure that
  900.          there are no two ways to do it.  */
  901.           compiler_error ("base class `%s' ambiguous in assoc_value",
  902.                   TYPE_NAME_STRING (elem));
  903.         else
  904.           rval = nval;
  905.     }
  906.       assoc = TREE_CHAIN (assoc);
  907.     }
  908.   return rval;
  909. }
  910.  
  911. tree
  912. virtual_member (elem, list)
  913.      tree elem;
  914.      tree list;
  915. {
  916.   tree t;
  917.   tree rval, nval;
  918.  
  919.   for (t = list; t; t = TREE_CHAIN (t))
  920.     if (elem == TREE_VALUE (t))
  921.       return t;
  922.   rval = 0;
  923.   for (t = list; t; t = TREE_CHAIN (t))
  924.     {
  925.       int i;
  926.       for (i = CLASSTYPE_N_BASECLASSES (TREE_TYPE (t)); i > 0; i--)
  927.     {
  928.       nval = assoc_value (elem, CLASSTYPE_BASECLASS (TREE_TYPE (t), i));
  929.       if (nval)
  930.         {
  931.           if (rval && TREE_TYPE (nval) != TREE_TYPE (rval))
  932.         abort ();
  933.           rval = nval;
  934.         }
  935.     }
  936.     }
  937.   return rval;
  938. }
  939.  
  940. void
  941. debug_dump_assoc (elem)
  942.      tree elem;
  943. {
  944.   int i;
  945.   tree virtuals;
  946.  
  947.   fprintf (stderr, "type \"%s\"; offset = %d\n",
  948.        IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (ASSOC_VALUE (elem)))),
  949.        TREE_INT_CST_LOW (ASSOC_OFFSET (elem)));
  950.   fprintf (stderr, "vtable type:\n");
  951.   dump_tree (stderr, ASSOC_TYPE (elem));
  952.   if (ASSOC_VTABLE (elem))
  953.     fprintf (stderr, "vtable decl \"%s\"\n", IDENTIFIER_POINTER (DECL_NAME (ASSOC_VTABLE (elem))));
  954.   else
  955.     fprintf (stderr, "no vtable decl yet\n");
  956.   fprintf (stderr, "virtuals:\n");
  957.   virtuals = ASSOC_VIRTUALS (elem);
  958.   if (virtuals != 0)
  959.     virtuals = TREE_CHAIN (virtuals);
  960.   i = 1;
  961.   while (virtuals)
  962.     {
  963.       tree fndecl = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)), 0);
  964.       fprintf (stderr, "%s [%d =? %d]\n",
  965.            IDENTIFIER_POINTER (DECL_NAME (fndecl)),
  966.            i, TREE_INT_CST_LOW (DECL_VINDEX (fndecl)));
  967.       virtuals = TREE_CHAIN (virtuals);
  968.       i += 1;
  969.     }
  970. }
  971.  
  972. char *
  973. lang_printable_name (decl)
  974.      tree decl;
  975. {
  976.   if (TREE_CODE (decl) != FUNCTION_DECL
  977.       || DECL_LANG_SPECIFIC (decl) == 0)
  978.     {
  979.       if (DECL_NAME (decl))
  980.     {
  981.       if (THIS_NAME_P (DECL_NAME (decl)))
  982.         return "this";
  983.       return IDENTIFIER_POINTER (DECL_NAME (decl));
  984.     }
  985.       return "((anonymous))";
  986.     }
  987.   if (DECL_PRINT_NAME (decl) == 0)
  988.     {
  989.       int print_ret_type_p
  990.     = (!DECL_CONSTRUCTOR_P (decl)
  991.        && !DESTRUCTOR_NAME_P (DECL_NAME (decl)));
  992.       int temp = allocation_temporary_p ();
  993.       char *buf = (char *)alloca (8192);
  994.       char *name = (char *)fndecl_as_string (buf, 0, decl, print_ret_type_p);
  995.       end_temporary_allocation ();
  996.       DECL_PRINT_NAME (decl) = oballoc (strlen (name) + 1);
  997.       strcpy (DECL_PRINT_NAME (decl), name);
  998.       if (temp)
  999.     resume_temporary_allocation ();
  1000.     }
  1001.   else if (DECL_NAME (decl) == 0)
  1002.     DECL_PRINT_NAME (decl) = "((anonymous))";
  1003.  
  1004.   return DECL_PRINT_NAME (decl);
  1005. }
  1006.  
  1007. /* Return truthvalue about whether debugger should
  1008.    output full info about this type or not.
  1009.  
  1010.    Current strategy is to permit types which define
  1011.    no member functions to be output normally.  For
  1012.    those which do define member functions, if no
  1013.    member functions have yet been output, then don't
  1014.    output the definition of the type.  If member functions
  1015.    for the type are later seen, a full definition of the
  1016.    type will eventually be output.  */
  1017. int
  1018. lang_output_debug_info (type)
  1019.      tree type;
  1020. {
  1021.   extern tree pending_vtables;
  1022.  
  1023.   if (! IS_AGGR_TYPE (type))
  1024.     return 1;
  1025.   if (TYPE_LANG_SPECIFIC (type) == 0)
  1026.     return 1;
  1027.   if (CLASSTYPE_METHOD_VEC (type) == 0)
  1028.     return 1;
  1029.  
  1030.   if (flag_minimal_debug)
  1031.     {
  1032.       /* Don't output full info about any type
  1033.      which does not have its implementation defined here.  */
  1034.       if (TYPE_VIRTUAL_P (type) && write_virtuals == 2)
  1035.     return value_member (DECL_NAME (TYPE_NAME (type)), pending_vtables) != 0;
  1036.       if (CLASSTYPE_INTERFACE_ONLY (type))
  1037.     return 0;
  1038.  
  1039.       return CLASSTYPE_ASM_WRITTEN (type);
  1040.     }
  1041.   else
  1042.     /* Can't work until GDB is modified.  */
  1043.     return 1;
  1044. }
  1045.  
  1046. /* Comparison function for sorting identifiers in RAISES lists.
  1047.    Note that because IDENTIFIER_NODEs are unique, we can sort
  1048.    them by address, saving an indirection.  */
  1049. static int
  1050. id_cmp (p1, p2)
  1051.      int *p1, *p2;
  1052. {
  1053.   return *p1 - *p2;
  1054. }
  1055.  
  1056. /* Build the FUNCTION_TYPE or METHOD_TYPE which may raise exceptions
  1057.    listed in RAISES.  */
  1058. tree
  1059. build_exception_variant (ctype, type, raises)
  1060.      tree ctype, type;
  1061.      tree raises;
  1062. {
  1063.   int i;
  1064.   tree v = TYPE_MAIN_VARIANT (type);
  1065.   tree t, t2, cname;
  1066.   tree *a = (tree *)alloca ((list_length (raises)+1) * sizeof (tree));
  1067.   int constp = TREE_READONLY (type);
  1068.   int volatilep = TREE_VOLATILE (type);
  1069.  
  1070.   if (raises && TREE_CHAIN (raises))
  1071.     {
  1072.       for (i = 0, t = raises; t; t = TREE_CHAIN (t), i++)
  1073.     a[i] = t;
  1074.       /* NULL terminator for list.  */
  1075.       a[i] = NULL_TREE;
  1076.       qsort (a, i, sizeof (tree), id_cmp);
  1077.       while (i--)
  1078.     TREE_CHAIN (a[i]) = a[i+1];
  1079.       raises = a[0];
  1080.     }
  1081.   else if (raises)
  1082.     /* do nothing.  */;
  1083.   else
  1084.     return build_type_variant (v, constp, volatilep);
  1085.  
  1086.   if (ctype)
  1087.     {
  1088.       cname = TYPE_NAME (ctype);
  1089.       if (TREE_CODE (cname) == TYPE_DECL)
  1090.     cname = DECL_NAME (cname);
  1091.     }
  1092.   else
  1093.     cname = NULL_TREE;
  1094.  
  1095.   for (t = raises; t; t = TREE_CHAIN (t))
  1096.     {
  1097.       /* See that all the exceptions we are thinking about
  1098.      raising have been declared.  */
  1099.       tree this_cname = lookup_exception_cname (ctype, cname, t);
  1100.       tree decl = lookup_exception_object (this_cname, TREE_VALUE (t), 1);
  1101.  
  1102.       if (decl == NULL_TREE)
  1103.     decl = lookup_exception_object (this_cname, TREE_VALUE (t), 0);
  1104.       /* Place canonical exception decl into TREE_TYPE of RAISES list.  */
  1105.       TREE_TYPE (t) = decl;
  1106.     }
  1107.  
  1108.   for (v = TYPE_NEXT_VARIANT (v); v; v = TYPE_NEXT_VARIANT (v))
  1109.     {
  1110.       if (TREE_READONLY (v) != constp
  1111.       || TREE_VOLATILE (v) != volatilep)
  1112.     continue;
  1113.  
  1114.       t = raises;
  1115.       t2 = TYPE_RAISES_EXCEPTIONS (v);
  1116.       while (t && t2)
  1117.     {
  1118.       if (TREE_TYPE (t) == TREE_TYPE (t2))
  1119.         {
  1120.           t = TREE_CHAIN (t);
  1121.           t2 = TREE_CHAIN (t2);
  1122.         }
  1123.       else break;
  1124.     }
  1125.       if (t || t2)
  1126.     continue;
  1127.       /* List of exceptions raised matches previously found list.
  1128.  
  1129.          @@ Nice to free up storage used in consing up the
  1130.      @@ list of exceptions raised.  */
  1131.       return v;
  1132.     }
  1133.  
  1134.   /* Need to build a new variant.  */
  1135.   v = copy_node (type);
  1136.   TYPE_NEXT_VARIANT (v) = TYPE_NEXT_VARIANT (type);
  1137.   TYPE_NEXT_VARIANT (type) = v;
  1138.   if (raises && ! TREE_PERMANENT (raises))
  1139.     {
  1140.       int temporary = allocation_temporary_p ();
  1141.       if (temporary)
  1142.     end_temporary_allocation ();
  1143.       raises = copy_list (raises);
  1144.       if (temporary)
  1145.     resume_temporary_allocation ();
  1146.     }
  1147.   TYPE_RAISES_EXCEPTIONS (v) = raises;
  1148.   return v;
  1149. }
  1150.  
  1151. /* Subroutine of make_permanent_node.
  1152.  
  1153.    Assuming T is a node build bottom-up, make it all exist on
  1154.    permanent obstack, if it is not permanent already.  */
  1155. static tree
  1156. make_deep_copy (t)
  1157.      tree t;
  1158. {
  1159.   enum tree_code code;
  1160.  
  1161.   if (t == NULL_TREE || TREE_PERMANENT (t))
  1162.     return t;
  1163.  
  1164.   switch (code = TREE_CODE (t))
  1165.     {
  1166.     case ERROR_MARK:
  1167.       return error_mark_node;
  1168.  
  1169.     case VAR_DECL:
  1170.     case PARM_DECL:
  1171.     case FUNCTION_DECL:
  1172.     case CONST_DECL:
  1173.       break;
  1174.  
  1175.     case TREE_LIST:
  1176.       {
  1177.     tree chain = TREE_CHAIN (t);
  1178.     t = copy_node (t);
  1179.     TREE_PURPOSE (t) = make_deep_copy (TREE_PURPOSE (t));
  1180.     TREE_VALUE (t) = make_deep_copy (TREE_VALUE (t));
  1181.     TREE_CHAIN (t) = make_deep_copy (chain);
  1182.     return t;
  1183.       }
  1184.  
  1185.     case TREE_VEC:
  1186.       {
  1187.     int len = TREE_VEC_LENGTH (t);
  1188.  
  1189.     t = copy_node (t);
  1190.     while (len--)
  1191.       TREE_VEC_ELT (t, len) = make_deep_copy (TREE_VEC_ELT (t, len));
  1192.     return t;
  1193.       }
  1194.  
  1195.     case INTEGER_CST:
  1196.     case REAL_CST:
  1197.     case STRING_CST:
  1198.       return copy_node (t);
  1199.  
  1200.     case COND_EXPR:
  1201.     case NEW_EXPR:
  1202.       t = copy_node (t);
  1203.       TREE_OPERAND (t, 0) = make_deep_copy (TREE_OPERAND (t, 0));
  1204.       TREE_OPERAND (t, 1) = make_deep_copy (TREE_OPERAND (t, 1));
  1205.       TREE_OPERAND (t, 2) = make_deep_copy (TREE_OPERAND (t, 2));
  1206.       return t;
  1207.  
  1208.     case SAVE_EXPR:
  1209.       t = copy_node (t);
  1210.       TREE_OPERAND (t, 0) = make_deep_copy (TREE_OPERAND (t, 0));
  1211.       return t;
  1212.  
  1213.     case MODIFY_EXPR:
  1214.     case PLUS_EXPR:
  1215.     case MINUS_EXPR:
  1216.     case MULT_EXPR:
  1217.     case TRUNC_DIV_EXPR:
  1218.     case TRUNC_MOD_EXPR:
  1219.     case MIN_EXPR:
  1220.     case MAX_EXPR:
  1221.     case LSHIFT_EXPR:
  1222.     case RSHIFT_EXPR:
  1223.     case BIT_IOR_EXPR:
  1224.     case BIT_XOR_EXPR:
  1225.     case BIT_AND_EXPR:
  1226.     case BIT_ANDTC_EXPR:
  1227.     case TRUTH_ANDIF_EXPR:
  1228.     case TRUTH_ORIF_EXPR:
  1229.     case LT_EXPR:
  1230.     case LE_EXPR:
  1231.     case GT_EXPR:
  1232.     case GE_EXPR:
  1233.     case EQ_EXPR:
  1234.     case NE_EXPR:
  1235.     case CEIL_DIV_EXPR:
  1236.     case FLOOR_DIV_EXPR:
  1237.     case ROUND_DIV_EXPR:
  1238.     case CEIL_MOD_EXPR:
  1239.     case FLOOR_MOD_EXPR:
  1240.     case ROUND_MOD_EXPR:
  1241.     case COMPOUND_EXPR:
  1242.     case PREDECREMENT_EXPR:
  1243.     case PREINCREMENT_EXPR:
  1244.     case POSTDECREMENT_EXPR:
  1245.     case POSTINCREMENT_EXPR:
  1246.     case CALL_EXPR:
  1247.       t = copy_node (t);
  1248.       TREE_OPERAND (t, 0) = make_deep_copy (TREE_OPERAND (t, 0));
  1249.       TREE_OPERAND (t, 1) = make_deep_copy (TREE_OPERAND (t, 1));
  1250.       return t;
  1251.  
  1252.     case CONVERT_EXPR:
  1253.     case ADDR_EXPR:
  1254.     case INDIRECT_REF:
  1255.     case NEGATE_EXPR:
  1256.     case BIT_NOT_EXPR:
  1257.     case TRUTH_NOT_EXPR:
  1258.     case NOP_EXPR:
  1259.     case COMPONENT_REF:
  1260.       t = copy_node (t);
  1261.       TREE_OPERAND (t, 0) = make_deep_copy (TREE_OPERAND (t, 0));
  1262.       return t;
  1263.  
  1264.       /*  This list is incomplete, but should suffice for now.
  1265.       It is very important that `sorry' does not call
  1266.       `report_error_function'.  That could cause an infinite loop.  */
  1267.     default:
  1268.       sorry ("initializer contains unrecognized tree code");
  1269.       return error_mark_node;
  1270.  
  1271.     }
  1272.   abort ();
  1273. }
  1274.  
  1275. /* Assuming T is a node built bottom-up, make it all exist on
  1276.    permanent obstack, if it is not permanent already.  */
  1277. tree
  1278. copy_to_permanent (t)
  1279.      tree t;
  1280. {
  1281.   register struct obstack *ambient_obstack = current_obstack;
  1282.   register struct obstack *ambient_saveable_obstack = saveable_obstack;
  1283.  
  1284.   if (t == NULL_TREE || TREE_PERMANENT (t))
  1285.     return t;
  1286.  
  1287.   saveable_obstack = &permanent_obstack;
  1288.   current_obstack = saveable_obstack;
  1289.  
  1290.   t = make_deep_copy (t);
  1291.  
  1292.   current_obstack = ambient_obstack;
  1293.   saveable_obstack = ambient_saveable_obstack;
  1294.  
  1295.   return t;
  1296. }
  1297.  
  1298. int
  1299. lang_simple_cst_equal (t1, t2)
  1300.      tree t1, t2;
  1301. {
  1302.   register enum tree_code code1, code2;
  1303.   int cmp;
  1304.  
  1305.   if (t1 == t2)
  1306.     return 1;
  1307.   if (t1 == 0 || t2 == 0)
  1308.     return 0;
  1309.  
  1310.   code1 = TREE_CODE (t1);
  1311.   code2 = TREE_CODE (t2);
  1312.  
  1313.   switch (code1)
  1314.     {
  1315.     case CPLUS_NEW_EXPR:
  1316.       cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  1317.       if (cmp <= 0)
  1318.     return cmp;
  1319.       return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
  1320.  
  1321.     default:
  1322.       return -1;
  1323.     }
  1324. }
  1325.