home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cc-61.0.1 / cc / tree.c < prev    next >
C/C++ Source or Header  |  1991-07-26  |  83KB  |  3,037 lines

  1. /* Language-independent node constructors for parse phase of GNU compiler.
  2.    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This file contains the low level primitives for operating on tree nodes,
  22.    including allocation, list operations, interning of identifiers,
  23.    construction of data type nodes and statement nodes,
  24.    and construction of type conversion nodes.  It also contains
  25.    tables index by tree code that describe how to take apart
  26.    nodes of that code.
  27.  
  28.    It is intended to be language-independent, but occasionally
  29.    calls language-dependent routines defined (for C) in typecheck.c.
  30.  
  31.    The low-level allocation routines oballoc and permalloc
  32.    are used also for allocating many other kinds of objects
  33.    by all passes of the compiler.  */
  34.  
  35. #include "config.h"
  36. #include <stdio.h>
  37. #include "flags.h"
  38. #include "function.h"
  39. #include "tree.h"
  40. #include "obstack.h"
  41. #include "gvarargs.h"
  42.  
  43. #define obstack_chunk_alloc xmalloc
  44. #define obstack_chunk_free free
  45.  
  46. extern int xmalloc ();
  47. extern void free ();
  48.  
  49. /* Tree nodes of permanent duration are allocated in this obstack.
  50.    They are the identifier nodes, and everything outside of
  51.    the bodies and parameters of function definitions.  */
  52.  
  53. struct obstack permanent_obstack;
  54.  
  55. /* The initial RTL, and all ..._TYPE nodes, in a function
  56.    are allocated in this obstack.  Usually they are freed at the
  57.    end of the function, but if the function is inline they are saved.
  58.    For top-level functions, this is maybepermanent_obstack.
  59.    Separate obstacks are made for nested functions.  */
  60.  
  61. struct obstack *function_maybepermanent_obstack;
  62.  
  63. /* This is the function_maybepermanent_obstack for top-level functions.  */
  64.  
  65. struct obstack maybepermanent_obstack;
  66.  
  67. /* The contents of the current function definition are allocated
  68.    in this obstack, and all are freed at the end of the function.
  69.    For top-level functions, this is temporary_obstack.
  70.    Separate obstacks are made for nested functions.  */
  71.  
  72. struct obstack *function_obstack;
  73.  
  74. /* This is used for reading initializers of global variables.  */
  75.  
  76. struct obstack temporary_obstack;
  77.  
  78. /* The tree nodes of an expression are allocated
  79.    in this obstack, and all are freed at the end of the expression.  */
  80.  
  81. struct obstack momentary_obstack;
  82.  
  83. /* The tree nodes of a declarator are allocated
  84.    in this obstack, and all are freed when the declarator
  85.    has been parsed.  */
  86.  
  87. static struct obstack temp_decl_obstack;
  88.  
  89. /* This points at either permanent_obstack
  90.    or the current function_maybepermanent_obstack.  */
  91.  
  92. struct obstack *saveable_obstack;
  93.  
  94. /* This is same as saveable_obstack during parse and expansion phase;
  95.    it points to the current function's obstack during optimization.
  96.    This is the obstack to be used for creating rtl objects.  */
  97.  
  98. struct obstack *rtl_obstack;
  99.  
  100. /* This points at either permanent_obstack or the current function_obstack.  */
  101.  
  102. struct obstack *current_obstack;
  103.  
  104. /* This points at either permanent_obstack or the current function_obstack
  105.    or momentary_obstack.  */
  106.  
  107. struct obstack *expression_obstack;
  108.  
  109. /* Stack of obstack selections for push_obstacks and pop_obstacks.  */
  110.  
  111. struct obstack_stack
  112. {
  113.   struct obstack_stack *next;
  114.   struct obstack *current;
  115.   struct obstack *saveable;
  116. };
  117.  
  118. struct obstack_stack *obstack_stack;
  119.  
  120. /* Obstack for allocating struct obstack_stack entries.  */
  121.  
  122. static struct obstack obstack_stack_obstack;
  123.  
  124. /* Addresses of first objects in some obstacks.
  125.    This is for freeing their entire contents.  */
  126. char *maybepermanent_firstobj;
  127. char *temporary_firstobj;
  128. char *momentary_firstobj;
  129. char *temp_decl_firstobj;
  130.  
  131. /* Nonzero means all ..._TYPE nodes should be allocated permanently.  */
  132.  
  133. int all_types_permanent;
  134.  
  135. /* Stack of places to restore the momentary obstack back to.  */
  136.    
  137. struct momentary_level
  138. {
  139.   /* Pointer back to previous such level.  */
  140.   struct momentary_level *prev;
  141.   /* First object allocated within this level.  */
  142.   char *base;
  143.   /* Value of expression_obstack saved at entry to this level.  */
  144.   struct obstack *obstack;
  145. };
  146.  
  147. struct momentary_level *momentary_stack;
  148.  
  149. /* Table indexed by tree code giving a string containing a character
  150.    classifying the tree code.  Possibilities are
  151.    t, d, s, c, r, <, 1, 2 and e.  See tree.def for details.  */
  152.  
  153. #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
  154.  
  155. char *standard_tree_code_type[] = {
  156. #include "tree.def"
  157. };
  158. #undef DEFTREECODE
  159.  
  160. /* Table indexed by tree code giving number of expression
  161.    operands beyond the fixed part of the node structure.
  162.    Not used for types or decls.  */
  163.  
  164. #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
  165.  
  166. int standard_tree_code_length[] = {
  167. #include "tree.def"
  168. };
  169. #undef DEFTREECODE
  170.  
  171. /* Names of tree components.
  172.    Used for printing out the tree and error messages.  */
  173. #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
  174.  
  175. char *standard_tree_code_name[] = {
  176. #include "tree.def"
  177. };
  178. #undef DEFTREECODE
  179.  
  180. /* Table indexed by tree code giving a string containing a character
  181.    classifying the tree code.  Possibilities are
  182.    t, d, s, c, r, e, <, 1 and 2.  See tree.def for details.  */
  183.  
  184. char **tree_code_type;
  185.  
  186. /* Table indexed by tree code giving number of expression
  187.    operands beyond the fixed part of the node structure.
  188.    Not used for types or decls.  */
  189.  
  190. int *tree_code_length;
  191.  
  192. /* Table indexed by tree code giving name of tree code, as a string.  */
  193.  
  194. char **tree_code_name;
  195.  
  196. /* Statistics-gathering stuff.  */
  197. typedef enum
  198. {
  199.   d_kind, t_kind, s_kind, r_kind, e_kind, c_kind,
  200.   id_kind, op_id_kind, perm_list_kind, temp_list_kind,
  201.   x_kind, lang_decl, lang_type, all_kinds
  202. } tree_node_kind;
  203. int tree_node_counts[(int)all_kinds];
  204. int tree_node_sizes[(int)all_kinds];
  205. int id_string_size = 0;
  206. char *tree_node_kind_names[] = { "decls", "types", "stmts", "refs", "exprs", "constants",
  207.                  "identifiers", "op_identifiers", "perm_tree_lists", "temp_tree_lists",
  208.                  "random kinds", "lang_decl kinds", "lang_type kinds" };
  209.  
  210. /* Hash table for uniquizing IDENTIFIER_NODEs by name.  */
  211.  
  212. #define MAX_HASH_TABLE 1009
  213. static tree hash_table[MAX_HASH_TABLE];    /* id hash buckets */
  214.  
  215. /* 0 while creating built-in identifiers.  */
  216. static int do_identifier_warnings;
  217.  
  218. extern char *mode_name[];
  219.  
  220. void gcc_obstack_init ();
  221. static tree stabilize_reference_1 ();
  222.  
  223. /* Init the principal obstacks.  */
  224.  
  225. void
  226. init_obstacks ()
  227. {
  228.   gcc_obstack_init (&obstack_stack_obstack);
  229.   gcc_obstack_init (&permanent_obstack);
  230.  
  231.   gcc_obstack_init (&temporary_obstack);
  232.   temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0);
  233.   gcc_obstack_init (&momentary_obstack);
  234.   momentary_firstobj = (char *) obstack_alloc (&momentary_obstack, 0);
  235.   gcc_obstack_init (&maybepermanent_obstack);
  236.   maybepermanent_firstobj
  237.     = (char *) obstack_alloc (&maybepermanent_obstack, 0);
  238.   gcc_obstack_init (&temp_decl_obstack);
  239.   temp_decl_firstobj = (char *) obstack_alloc (&temp_decl_obstack, 0);
  240.  
  241.   function_obstack = &temporary_obstack;
  242.   function_maybepermanent_obstack = &maybepermanent_obstack;
  243.   current_obstack = &permanent_obstack;
  244.   expression_obstack = &permanent_obstack;
  245.   rtl_obstack = saveable_obstack = &permanent_obstack;
  246.  
  247.   /* Init the hash table of identifiers.  */
  248.   bzero (hash_table, sizeof hash_table);
  249. }
  250.  
  251. void
  252. gcc_obstack_init (obstack)
  253.      struct obstack *obstack;
  254. {
  255.   /* Let particular systems override the size of a chunk.  */
  256. #ifndef OBSTACK_CHUNK_SIZE
  257. #define OBSTACK_CHUNK_SIZE 0
  258. #endif
  259.   /* Let them override the alloc and free routines too.  */
  260. #ifndef OBSTACK_CHUNK_ALLOC
  261. #define OBSTACK_CHUNK_ALLOC xmalloc
  262. #endif
  263. #ifndef OBSTACK_CHUNK_FREE
  264. #define OBSTACK_CHUNK_FREE free
  265. #endif
  266.   _obstack_begin (obstack, OBSTACK_CHUNK_SIZE, 0,
  267.           (void *(*) ()) OBSTACK_CHUNK_ALLOC,
  268.           (void (*) ()) OBSTACK_CHUNK_FREE);
  269. }
  270.  
  271. /* Save all variables describing the current status into the structure *P.
  272.    This is used before starting a nested function.  */
  273.  
  274. void
  275. save_tree_status (p)
  276.      struct function *p;
  277. {
  278.   p->all_types_permanent = all_types_permanent;
  279.   p->momentary_stack = momentary_stack;
  280.   p->maybepermanent_firstobj = maybepermanent_firstobj;
  281.   p->momentary_firstobj = momentary_firstobj;
  282.   p->function_obstack = function_obstack;
  283.   p->function_maybepermanent_obstack = function_maybepermanent_obstack;
  284.   p->current_obstack = current_obstack;
  285.   p->expression_obstack = expression_obstack;
  286.   p->saveable_obstack = saveable_obstack;
  287.   p->rtl_obstack = rtl_obstack;
  288.  
  289.   function_obstack = (struct obstack *) xmalloc (sizeof (struct obstack));
  290.   gcc_obstack_init (function_obstack);
  291.  
  292.   function_maybepermanent_obstack
  293.     = (struct obstack *) xmalloc (sizeof (struct obstack));
  294.   gcc_obstack_init (function_maybepermanent_obstack);
  295.  
  296.   current_obstack = &permanent_obstack;
  297.   expression_obstack = &permanent_obstack;
  298.   rtl_obstack = saveable_obstack = &permanent_obstack;
  299.  
  300.   momentary_firstobj = (char *) obstack_finish (&momentary_obstack);
  301.   maybepermanent_firstobj
  302.     = (char *) obstack_finish (function_maybepermanent_obstack);
  303. }
  304.  
  305. /* Restore all variables describing the current status from the structure *P.
  306.    This is used after a nested function.  */
  307.  
  308. void
  309. restore_tree_status (p)
  310.      struct function *p;
  311. {
  312.   all_types_permanent = p->all_types_permanent;
  313.   momentary_stack = p->momentary_stack;
  314.  
  315.   obstack_free (&momentary_obstack, momentary_firstobj);
  316.   obstack_free (function_obstack, 0);
  317.   obstack_free (function_maybepermanent_obstack, 0);
  318.   free (function_obstack);
  319.  
  320.   momentary_firstobj = p->momentary_firstobj;
  321.   maybepermanent_firstobj = p->maybepermanent_firstobj;
  322.   function_obstack = p->function_obstack;
  323.   function_maybepermanent_obstack = p->function_maybepermanent_obstack;
  324.   current_obstack = p->current_obstack;
  325.   expression_obstack = p->expression_obstack;
  326.   saveable_obstack = p->saveable_obstack;
  327.   rtl_obstack = p->rtl_obstack;
  328. }
  329.  
  330. /* Start allocating on the temporary (per function) obstack.
  331.    This is done in start_function before parsing the function body,
  332.    and before each initialization at top level, and to go back
  333.    to temporary allocation after doing end_temporary_allocation.  */
  334.  
  335. void
  336. temporary_allocation ()
  337. {
  338.   /* Note that function_obstack at top level points to temporary_obstack.
  339.      But within a nested function context, it is a separate obstack.  */
  340.   current_obstack = function_obstack;
  341.   expression_obstack = function_obstack;
  342.   rtl_obstack = saveable_obstack = function_maybepermanent_obstack;
  343.   momentary_stack = 0;
  344. }
  345.  
  346. /* Start allocating on the permanent obstack but don't
  347.    free the temporary data.  After calling this, call
  348.    `permanent_allocation' to fully resume permanent allocation status.  */
  349.  
  350. void
  351. end_temporary_allocation ()
  352. {
  353.   current_obstack = &permanent_obstack;
  354.   expression_obstack = &permanent_obstack;
  355.   rtl_obstack = saveable_obstack = &permanent_obstack;
  356. }
  357.  
  358. /* Resume allocating on the temporary obstack, undoing
  359.    effects of `end_temporary_allocation'.  */
  360.  
  361. void
  362. resume_temporary_allocation ()
  363. {
  364.   current_obstack = function_obstack;
  365.   expression_obstack = function_obstack;
  366.   rtl_obstack = saveable_obstack = function_maybepermanent_obstack;
  367. }
  368.  
  369. /* Switch to current obstack CURRENT and maybepermanent obstack SAVEABLE,
  370.    recording the previously current obstacks on a stack.
  371.    This does not free any storage in any obstack.  */
  372.  
  373. void
  374. push_obstacks (current, saveable)
  375.      struct obstack *current, *saveable;
  376. {
  377.   struct obstack_stack *p
  378.     = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,
  379.                           (sizeof (struct obstack_stack)));
  380.  
  381.   p->current = current_obstack;
  382.   p->saveable = saveable_obstack;
  383.   p->next = obstack_stack;
  384.   obstack_stack = p;
  385.  
  386.   current_obstack = current;
  387.   expression_obstack = current;
  388.   rtl_obstack = saveable_obstack = saveable;
  389. }
  390.  
  391. /* Pop the obstack selection stack.  */
  392.  
  393. void
  394. pop_obstacks ()
  395. {
  396.   struct obstack_stack *p = obstack_stack;
  397.   obstack_stack = p->next;
  398.  
  399.   expression_obstack = current_obstack = p->current;
  400.   rtl_obstack = saveable_obstack = p->saveable;
  401.  
  402.   obstack_free (&obstack_stack_obstack, p);
  403. }
  404.  
  405. /* Nonzero if temporary allocation is currently in effect.
  406.    Zero if currently doing permanent allocation.  */
  407.  
  408. int
  409. allocation_temporary_p ()
  410. {
  411.   return current_obstack != &permanent_obstack;
  412. }
  413.  
  414. /* Go back to allocating on the permanent obstack
  415.    and free everything in the temporary obstack.
  416.    This is done in finish_function after fully compiling a function.  */
  417.  
  418. void
  419. permanent_allocation ()
  420. {
  421.   /* Free up previous temporary obstack data */
  422.   obstack_free (&temporary_obstack, temporary_firstobj);
  423.   obstack_free (&momentary_obstack, momentary_firstobj);
  424.   obstack_free (&maybepermanent_obstack, maybepermanent_firstobj);
  425.   obstack_free (&temp_decl_obstack, temp_decl_firstobj);
  426.  
  427.   current_obstack = &permanent_obstack;
  428.   expression_obstack = &permanent_obstack;
  429.   rtl_obstack = saveable_obstack = &permanent_obstack;
  430. }
  431.  
  432. /* Save permanently everything on the maybepermanent_obstack.  */
  433.  
  434. void
  435. preserve_data ()
  436. {
  437.   maybepermanent_firstobj
  438.     = (char *) obstack_alloc (function_maybepermanent_obstack, 0);
  439. }
  440.  
  441. void
  442. preserve_initializer ()
  443. {
  444.   temporary_firstobj
  445.     = (char *) obstack_alloc (&temporary_obstack, 0);
  446.   momentary_firstobj
  447.     = (char *) obstack_alloc (&momentary_obstack, 0);
  448.   maybepermanent_firstobj
  449.     = (char *) obstack_alloc (function_maybepermanent_obstack, 0);
  450. }
  451.  
  452. /* Start allocating new rtl in current_obstack.
  453.    Use resume_temporary_allocation
  454.    to go back to allocating rtl in saveable_obstack.  */
  455.  
  456. void
  457. rtl_in_current_obstack ()
  458. {
  459.   rtl_obstack = current_obstack;
  460. }
  461.  
  462. /* Temporarily allocate rtl from saveable_obstack.  Return 1 if we were
  463.    previously allocating it from current_obstack.  */
  464.  
  465. int
  466. rtl_in_saveable_obstack ()
  467. {
  468.   if (rtl_obstack == current_obstack)
  469.     {
  470.       rtl_obstack = saveable_obstack;
  471.       return 1;
  472.     }
  473.   else
  474.     return 0;
  475. }
  476.  
  477. /* Allocate SIZE bytes in the current obstack
  478.    and return a pointer to them.
  479.    In practice the current obstack is always the temporary one.  */
  480.  
  481. char *
  482. oballoc (size)
  483.      int size;
  484. {
  485.   return (char *) obstack_alloc (current_obstack, size);
  486. }
  487.  
  488. /* Free the object PTR in the current obstack
  489.    as well as everything allocated since PTR.
  490.    In practice the current obstack is always the temporary one.  */
  491.  
  492. void
  493. obfree (ptr)
  494.      char *ptr;
  495. {
  496.   obstack_free (current_obstack, ptr);
  497. }
  498.  
  499. /* Allocate SIZE bytes in the permanent obstack
  500.    and return a pointer to them.  */
  501.  
  502. char *
  503. permalloc (size)
  504.      long size;
  505. {
  506.   return (char *) obstack_alloc (&permanent_obstack, size);
  507. }
  508.  
  509. /* Allocate NELEM items of SIZE bytes in the permanent obstack
  510.    and return a pointer to them.  The storage is cleared before
  511.    returning the value.  */
  512.  
  513. char *
  514. perm_calloc (nelem, size)
  515.      int nelem;
  516.      long size;
  517. {
  518.   char *rval = (char *) obstack_alloc (&permanent_obstack, nelem * size);
  519.   bzero (rval, nelem * size);
  520.   return rval;
  521. }
  522.  
  523. /* Allocate SIZE bytes in the saveable obstack
  524.    and return a pointer to them.  */
  525.  
  526. char *
  527. savealloc (size)
  528.      int size;
  529. {
  530.   return (char *) obstack_alloc (saveable_obstack, size);
  531. }
  532.  
  533. /* Print out which obstack an object is in.  */
  534.  
  535. void
  536. debug_obstack (object)
  537.      char *object;
  538. {
  539.   struct obstack *obstack = NULL;
  540.   char *obstack_name = NULL;
  541.   struct function *p;
  542.  
  543.   for (p = outer_function_chain; p; p = p->next)
  544.     {
  545.       if (_obstack_allocated_p (p->function_obstack, object))
  546.     {
  547.       obstack = p->function_obstack;
  548.       obstack_name = "containing function obstack";
  549.     }
  550.       if (_obstack_allocated_p (p->function_maybepermanent_obstack, object))
  551.     {
  552.       obstack = p->function_maybepermanent_obstack;
  553.       obstack_name = "containing function maybepermanent obstack";
  554.     }
  555.     }
  556.  
  557.   if (_obstack_allocated_p (&obstack_stack_obstack, object))
  558.     {
  559.       obstack = &obstack_stack_obstack;
  560.       obstack_name = "obstack_stack_obstack";
  561.     }
  562.   else if (_obstack_allocated_p (function_obstack, object))
  563.     {
  564.       obstack = function_obstack;
  565.       obstack_name = "function obstack";
  566.     }
  567.   else if (_obstack_allocated_p (&permanent_obstack, object))
  568.     {
  569.       obstack = &permanent_obstack;
  570.       obstack_name = "permanent_obstack";
  571.     }
  572.   else if (_obstack_allocated_p (&momentary_obstack, object))
  573.     {
  574.       obstack = &momentary_obstack;
  575.       obstack_name = "momentary_obstack";
  576.     }
  577.   else if (_obstack_allocated_p (function_maybepermanent_obstack, object))
  578.     {
  579.       obstack = function_maybepermanent_obstack;
  580.       obstack_name = "function maybepermanent obstack";
  581.     }
  582.   else if (_obstack_allocated_p (&temp_decl_obstack, object))
  583.     {
  584.       obstack = &temp_decl_obstack;
  585.       obstack_name = "temp_decl_obstack";
  586.     }
  587.  
  588.   /* Check to see if the object is in the free area of the obstack. */
  589.   if (obstack != NULL)
  590.     {
  591.       if (object >= obstack->next_free
  592.       && object < obstack->chunk_limit)
  593.     fprintf (stderr, "object in free portion of obstack %s.\n",
  594.          obstack_name);
  595.       else
  596.     fprintf (stderr, "object allocated from %s.\n", obstack_name);
  597.     }
  598.   else
  599.     fprintf (stderr, "object not allocated from any obstack.\n");
  600. }
  601.  
  602. /* Return 1 if OBJ is in the permanent obstack.
  603.    This is slow, and should be used only for debugging.
  604.    Use TREE_PERMANENT for other purposes.  */
  605.  
  606. object_permanent_p (obj)
  607.      tree obj;
  608. {
  609.   return _obstack_allocated_p (&permanent_obstack, obj);
  610. }
  611.  
  612. /* Start a level of momentary allocation.
  613.    In C, each compound statement has its own level
  614.    and that level is freed at the end of each statement.
  615.    All expression nodes are allocated in the momentary allocation level.  */
  616.  
  617. void
  618. push_momentary ()
  619. {
  620.   struct momentary_level *tem
  621.     = (struct momentary_level *) obstack_alloc (&momentary_obstack,
  622.                         sizeof (struct momentary_level));
  623.   tem->prev = momentary_stack;
  624.   tem->base = (char *) obstack_base (&momentary_obstack);
  625.   tem->obstack = expression_obstack;
  626.   momentary_stack = tem;
  627.   expression_obstack = &momentary_obstack;
  628. }
  629.  
  630. /* Free all the storage in the current momentary-allocation level.
  631.    In C, this happens at the end of each statement.  */
  632.  
  633. void
  634. clear_momentary ()
  635. {
  636.   obstack_free (&momentary_obstack, momentary_stack->base);
  637. }
  638.  
  639. /* Discard a level of momentary allocation.
  640.    In C, this happens at the end of each compound statement.
  641.    Restore the status of expression node allocation
  642.    that was in effect before this level was created.  */
  643.  
  644. void
  645. pop_momentary ()
  646. {
  647.   struct momentary_level *tem = momentary_stack;
  648.   momentary_stack = tem->prev;
  649.   obstack_free (&momentary_obstack, tem);
  650.   expression_obstack = tem->obstack;
  651. }
  652.  
  653. /* Call when starting to parse a declaration:
  654.    make expressions in the declaration last the length of the function.
  655.    Returns an argument that should be passed to resume_momentary later.  */
  656.  
  657. int
  658. suspend_momentary ()
  659. {
  660.   register int tem = expression_obstack == &momentary_obstack;
  661.   expression_obstack = saveable_obstack;
  662.   return tem;
  663. }
  664.  
  665. /* Call when finished parsing a declaration:
  666.    restore the treatment of node-allocation that was
  667.    in effect before the suspension.
  668.    YES should be the value previously returned by suspend_momentary.  */
  669.  
  670. void
  671. resume_momentary (yes)
  672.      int yes;
  673. {
  674.   if (yes)
  675.     expression_obstack = &momentary_obstack;
  676. }
  677.  
  678. /* Init the tables indexed by tree code.
  679.    Note that languages can add to these tables to define their own codes.  */
  680.  
  681. init_tree_codes ()
  682. {
  683.   tree_code_type = (char **) xmalloc (sizeof (standard_tree_code_type));
  684.   tree_code_length = (int *) xmalloc (sizeof (standard_tree_code_length));
  685.   tree_code_name = (char **) xmalloc (sizeof (standard_tree_code_name));
  686.   bcopy (standard_tree_code_type, tree_code_type,
  687.      sizeof (standard_tree_code_type));
  688.   bcopy (standard_tree_code_length, tree_code_length,
  689.      sizeof (standard_tree_code_length));
  690.   bcopy (standard_tree_code_name, tree_code_name,
  691.      sizeof (standard_tree_code_name));
  692. }
  693.  
  694. /* Return a newly allocated node of code CODE.
  695.    Initialize the node's unique id and its TREE_PERMANENT flag.
  696.    For decl and type nodes, some other fields are initialized.
  697.    The rest of the node is initialized to zero.
  698.  
  699.    Achoo!  I got a code in the node.  */
  700.  
  701. tree
  702. make_node (code)
  703.      enum tree_code code;
  704. {
  705.   register tree t;
  706.   register int type = TREE_CODE_CLASS (code);
  707.   register int length;
  708.   register struct obstack *obstack = current_obstack;
  709.   register int i;
  710.   register tree_node_kind kind;
  711.  
  712.   switch (type)
  713.     {
  714.     case 'd':  /* A decl node */
  715. #ifdef GATHER_STATISTICS
  716.       kind = d_kind;
  717. #endif
  718.       length = sizeof (struct tree_decl);
  719.       /* All decls in an inline function need to be saved.  */
  720.       if (obstack != &permanent_obstack)
  721.     obstack = saveable_obstack;
  722. #if 0 /* This breaks Objective-C!  Fix better later.  */
  723.       /* PARM_DECLs always go on saveable_obstack, not permanent,
  724.      even though we may make them before the function turns
  725.      on temporary allocation.  */
  726.       else if (code == PARM_DECL)
  727.     obstack = function_maybepermanent_obstack;
  728. #endif
  729.       break;
  730.  
  731.     case 't':  /* a type node */
  732. #ifdef GATHER_STATISTICS
  733.       kind = t_kind;
  734. #endif
  735.       length = sizeof (struct tree_type);
  736.       /* All data types are put where we can preserve them if nec.  */
  737.       if (obstack != &permanent_obstack)
  738.     obstack = all_types_permanent ? &permanent_obstack : saveable_obstack;
  739.       break;
  740.  
  741.     case 's':  /* an expression with side effects */
  742. #ifdef GATHER_STATISTICS
  743.       kind = s_kind;
  744.       goto usual_kind;
  745. #endif
  746.     case 'r':  /* a reference */
  747. #ifdef GATHER_STATISTICS
  748.       kind = r_kind;
  749.       goto usual_kind;
  750. #endif
  751.     case 'e':  /* an expression */
  752.     case '<':  /* a comparison expression */
  753.     case '1':  /* a unary arithmetic expression */
  754.     case '2':  /* a binary arithmetic expression */
  755. #ifdef GATHER_STATISTICS
  756.       kind = e_kind;
  757.     usual_kind:
  758. #endif
  759.       obstack = expression_obstack;
  760.       /* All BLOCK nodes are put where we can preserve them if nec.
  761.      Also their potential controllers.  */
  762.       if ((code == BLOCK || code == BIND_EXPR)
  763.       && obstack != &permanent_obstack)
  764.     obstack = saveable_obstack;
  765.       length = sizeof (struct tree_exp)
  766.     + (tree_code_length[(int) code] - 1) * sizeof (char *);
  767.       break;
  768.  
  769.     case 'c':  /* a constant */
  770. #ifdef GATHER_STATISTICS
  771.       kind = c_kind;
  772. #endif
  773.       obstack = expression_obstack;
  774.       /* We can't use tree_code_length for this, since the number of words
  775.      is machine-dependent due to varying alignment of `double'.  */
  776.       if (code == REAL_CST)
  777.     {
  778.       length = sizeof (struct tree_real_cst);
  779.       break;
  780.     }
  781.  
  782.     case 'x':  /* something random, like an identifier.  */
  783. #ifdef GATHER_STATISTICS
  784.       if (code == IDENTIFIER_NODE)
  785.     kind = id_kind;
  786.       else if (code == OP_IDENTIFIER)
  787.     kind = op_id_kind;
  788.       else
  789.     kind = x_kind;
  790. #endif
  791.       length = sizeof (struct tree_common)
  792.     + tree_code_length[(int) code] * sizeof (char *);
  793.       /* Identifier nodes are always permanent since they are
  794.      unique in a compiler run.  */
  795.       if (code == IDENTIFIER_NODE) obstack = &permanent_obstack;
  796.     }
  797.  
  798.   t = (tree) obstack_alloc (obstack, length);
  799.  
  800. #ifdef GATHER_STATISTICS
  801.   tree_node_counts[(int)kind]++;
  802.   tree_node_sizes[(int)kind] += length;
  803. #endif
  804.  
  805.   TREE_TYPE (t) = 0;
  806.   TREE_CHAIN (t) = 0;
  807.   for (i = (length / sizeof (int)) - 1;
  808.        i >= sizeof (struct tree_common) / sizeof (int) - 1;
  809.        i--)
  810.     ((int *) t)[i] = 0;
  811.  
  812.   TREE_SET_CODE (t, code);
  813.   if (obstack == &permanent_obstack)
  814.     TREE_PERMANENT (t) = 1;
  815.  
  816.   switch (type)
  817.     {
  818.     case 's':
  819.       TREE_SIDE_EFFECTS (t) = 1;
  820.       TREE_TYPE (t) = void_type_node;
  821.       break;
  822.  
  823.     case 'd':
  824.       DECL_ALIGN (t) = 1;
  825.       DECL_SOURCE_LINE (t) = lineno;
  826.       DECL_SOURCE_FILE (t) = (input_filename) ? input_filename : "<built-in>";
  827.       break;
  828.  
  829.     case 't':
  830.       TYPE_ALIGN (t) = 1;
  831.       TYPE_MAIN_VARIANT (t) = t;
  832.       break;
  833.  
  834.     case 'c':
  835.       TREE_CONSTANT (t) = 1;
  836.       break;
  837.     }
  838.  
  839.   return t;
  840. }
  841.  
  842. /* Return a new node with the same contents as NODE
  843.    except that its TREE_CHAIN is zero and it has a fresh uid.  */
  844.  
  845. tree
  846. copy_node (node)
  847.      tree node;
  848. {
  849.   register tree t;
  850.   register enum tree_code code = TREE_CODE (node);
  851.   register int length;
  852.   register int i;
  853.  
  854.   switch (TREE_CODE_CLASS (code))
  855.     {
  856.     case 'd':  /* A decl node */
  857.       length = sizeof (struct tree_decl);
  858.       break;
  859.  
  860.     case 't':  /* a type node */
  861.       length = sizeof (struct tree_type);
  862.       break;
  863.  
  864.     case 'r':  /* a reference */
  865.     case 'e':  /* a expression */
  866.     case 's':  /* an expression with side effects */
  867.     case '<':  /* a comparison expression */
  868.     case '1':  /* a unary arithmetic expression */
  869.     case '2':  /* a binary arithmetic expression */
  870.       length = sizeof (struct tree_exp)
  871.     + (tree_code_length[(int) code] - 1) * sizeof (char *);
  872.       break;
  873.  
  874.     case 'c':  /* a constant */
  875.       /* We can't use tree_code_length for this, since the number of words
  876.      is machine-dependent due to varying alignment of `double'.  */
  877.       if (code == REAL_CST)
  878.     {
  879.       length = sizeof (struct tree_real_cst);
  880.       break;
  881.     }
  882.  
  883.     case 'x':  /* something random, like an identifier.  */
  884.       length = sizeof (struct tree_common)
  885.     + tree_code_length[(int) code] * sizeof (char *);
  886.       if (code == TREE_VEC)
  887.     length += (TREE_VEC_LENGTH (node) - 1) * sizeof (char *);
  888.     }
  889.  
  890.   t = (tree) obstack_alloc (current_obstack, length);
  891.  
  892.   for (i = ((length + sizeof (int) - 1) / sizeof (int)) - 1;
  893.        i >= 0;
  894.        i--)
  895.     ((int *) t)[i] = ((int *) node)[i];
  896.  
  897.   TREE_CHAIN (t) = 0;
  898.  
  899.   TREE_PERMANENT (t) = (current_obstack == &permanent_obstack);
  900.  
  901.   return t;
  902. }
  903.  
  904. /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
  905.    For example, this can copy a list made of TREE_LIST nodes.  */
  906.  
  907. tree
  908. copy_list (list)
  909.      tree list;
  910. {
  911.   tree head;
  912.   register tree prev, next;
  913.  
  914.   if (list == 0)
  915.     return 0;
  916.  
  917.   head = prev = copy_node (list);
  918.   next = TREE_CHAIN (list);
  919.   while (next)
  920.     {
  921.       TREE_CHAIN (prev) = copy_node (next);
  922.       prev = TREE_CHAIN (prev);
  923.       next = TREE_CHAIN (next);
  924.     }
  925.   return head;
  926. }
  927.  
  928. #define HASHBITS 30
  929.  
  930. /* Return an IDENTIFIER_NODE whose name is TEXT (a null-terminated string).
  931.    If an identifier with that name has previously been referred to,
  932.    the same node is returned this time.  */
  933.  
  934. tree
  935. get_identifier (text)
  936.      register char *text;
  937. {
  938.   register int hi;
  939.   register int i;
  940.   register tree idp;
  941.   register int len, hash_len;
  942.  
  943.   /* Compute length of text in len.  */
  944.   for (len = 0; text[len]; len++);
  945.  
  946.   /* Decide how much of that length to hash on */
  947.   hash_len = len;
  948.   if (warn_id_clash && len > id_clash_len)
  949.     hash_len = id_clash_len;
  950.  
  951.   /* Compute hash code */
  952.   hi = hash_len * 613 + (unsigned)text[0];
  953.   for (i = 1; i < hash_len; i += 2)
  954.     hi = ((hi * 613) + (unsigned)(text[i]));
  955.  
  956.   hi &= (1 << HASHBITS) - 1;
  957.   hi %= MAX_HASH_TABLE;
  958.   
  959.   /* Search table for identifier */
  960.   for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
  961.     if (IDENTIFIER_LENGTH (idp) == len
  962.     && IDENTIFIER_POINTER (idp)[0] == text[0]
  963.     && !bcmp (IDENTIFIER_POINTER (idp), text, len))
  964.       return idp;        /* <-- return if found */
  965.  
  966.   /* Not found; optionally warn about a similar identifier */
  967.   if (warn_id_clash && do_identifier_warnings && len >= id_clash_len)
  968.     for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
  969.       if (!strncmp (IDENTIFIER_POINTER (idp), text, id_clash_len))
  970.     {
  971.       warning ("`%s' and `%s' identical in first n characters",
  972.            IDENTIFIER_POINTER (idp), text);
  973.       break;
  974.     }
  975.  
  976.   if (tree_code_length[(int) IDENTIFIER_NODE] < 0)
  977.     abort ();            /* set_identifier_size hasn't been called.  */
  978.  
  979.   /* Not found, create one, add to chain */
  980.   idp = make_node (IDENTIFIER_NODE);
  981.   IDENTIFIER_LENGTH (idp) = len;
  982. #ifdef GATHER_STATISTICS
  983.   id_string_size += len;
  984. #endif
  985.  
  986.   IDENTIFIER_POINTER (idp) = obstack_copy0 (&permanent_obstack, text, len);
  987.  
  988.   TREE_CHAIN (idp) = hash_table[hi];
  989.   hash_table[hi] = idp;
  990.   return idp;            /* <-- return if created */
  991. }
  992.  
  993. /* Enable warnings on similar identifiers (if requested).
  994.    Done after the built-in identifiers are created.  */
  995.  
  996. void
  997. start_identifier_warnings ()
  998. {
  999.   do_identifier_warnings = 1;
  1000. }
  1001.  
  1002. /* Record the size of an identifier node for the language in use.
  1003.    SIZE is the total size in bytes.
  1004.    This is called by the language-specific files.  This must be
  1005.    called before allocating any identifiers.  */
  1006.  
  1007. void
  1008. set_identifier_size (size)
  1009.      int size;
  1010. {
  1011.   tree_code_length[(int) IDENTIFIER_NODE]
  1012.     = (size - sizeof (struct tree_common)) / sizeof (tree);
  1013. }
  1014.  
  1015. /* Return a newly constructed INTEGER_CST node whose constant value
  1016.    is specified by the two ints LOW and HI.
  1017.    The TREE_TYPE is set to `int'.  */
  1018.  
  1019. tree
  1020. build_int_2 (low, hi)
  1021.      int low, hi;
  1022. {
  1023.   register tree t = make_node (INTEGER_CST);
  1024.   TREE_INT_CST_LOW (t) = low;
  1025.   TREE_INT_CST_HIGH (t) = hi;
  1026.   TREE_TYPE (t) = integer_type_node;
  1027.   return t;
  1028. }
  1029.  
  1030. /* Return a new REAL_CST node whose type is TYPE and value is D.  */
  1031.  
  1032. tree
  1033. build_real (type, d)
  1034.      tree type;
  1035.      REAL_VALUE_TYPE d;
  1036. {
  1037.   tree v;
  1038.  
  1039.   /* Check for valid float value for this type on this target machine;
  1040.      if not, can print error message and store a valid value in D.  */
  1041. #ifdef CHECK_FLOAT_VALUE
  1042.   CHECK_FLOAT_VALUE (TYPE_MODE (type), d);
  1043. #endif
  1044.  
  1045.   v = make_node (REAL_CST);
  1046.   TREE_TYPE (v) = type;
  1047.   TREE_REAL_CST (v) = d;
  1048.   return v;
  1049. }
  1050.  
  1051. /* Return a new REAL_CST node whose type is TYPE
  1052.    and whose value is the integer value of the INTEGER_CST node I.  */
  1053.  
  1054. #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
  1055.  
  1056. REAL_VALUE_TYPE
  1057. real_value_from_int_cst (i)
  1058.      tree i;
  1059. {
  1060.   REAL_VALUE_TYPE d;
  1061. #ifdef REAL_ARITHMETIC
  1062.   REAL_VALUE_FROM_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i));
  1063. #else /* not REAL_ARITHMETIC */
  1064.   if (TREE_INT_CST_HIGH (i) < 0)
  1065.     {
  1066.       d = (double) (~ TREE_INT_CST_HIGH (i));
  1067.       d *= ((double) (1 << (HOST_BITS_PER_INT / 2))
  1068.         * (double) (1 << (HOST_BITS_PER_INT / 2)));
  1069.       d += (double) (unsigned) (~ TREE_INT_CST_LOW (i));
  1070.       d = (- d - 1.0);
  1071.     }
  1072.   else
  1073.     {
  1074.       d = (double) TREE_INT_CST_HIGH (i);
  1075.       d *= ((double) (1 << (HOST_BITS_PER_INT / 2))
  1076.         * (double) (1 << (HOST_BITS_PER_INT / 2)));
  1077.       d += (double) (unsigned) TREE_INT_CST_LOW (i);
  1078.     }
  1079. #endif /* not REAL_ARITHMETIC */
  1080.   return d;
  1081. }
  1082.  
  1083. /* This function can't be implemented if we can't do arithmetic
  1084.    on the float representation.  */
  1085.  
  1086. tree
  1087. build_real_from_int_cst (type, i)
  1088.      tree type;
  1089.      tree i;
  1090. {
  1091.   tree v;
  1092.   REAL_VALUE_TYPE d;
  1093.  
  1094.   v = make_node (REAL_CST);
  1095.   TREE_TYPE (v) = type;
  1096.  
  1097.   d = real_value_from_int_cst (i);
  1098.   /* Check for valid float value for this type on this target machine;
  1099.      if not, can print error message and store a valid value in D.  */
  1100. #ifdef CHECK_FLOAT_VALUE
  1101.   CHECK_FLOAT_VALUE (TYPE_MODE (type), d);
  1102. #endif
  1103.  
  1104.   TREE_REAL_CST (v) = d;
  1105.   return v;
  1106. }
  1107.  
  1108. #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
  1109.  
  1110. /* Return a newly constructed STRING_CST node whose value is
  1111.    the LEN characters at STR.
  1112.    The TREE_TYPE is not initialized.  */
  1113.  
  1114. tree
  1115. build_string (len, str)
  1116.      int len;
  1117.      char *str;
  1118. {
  1119.   register tree s = make_node (STRING_CST);
  1120.   TREE_STRING_LENGTH (s) = len;
  1121.   TREE_STRING_POINTER (s) = obstack_copy0 (saveable_obstack, str, len);
  1122.   return s;
  1123. }
  1124.  
  1125. /* Return a newly constructed COMPLEX_CST node whose value is
  1126.    specified by the real and imaginary parts REAL and IMAG.
  1127.    Both REAL and IMAG should be constant nodes.
  1128.    The TREE_TYPE is not initialized.  */
  1129.  
  1130. tree
  1131. build_complex (real, imag)
  1132.      tree real, imag;
  1133. {
  1134.   register tree t = make_node (COMPLEX_CST);
  1135.   TREE_REALPART (t) = real;
  1136.   TREE_IMAGPART (t) = imag;
  1137.   return t;
  1138. }
  1139.  
  1140. /* Build a newly constructed TREE_VEC node of length LEN.  */
  1141. tree
  1142. make_tree_vec (len)
  1143.      int len;
  1144. {
  1145.   register tree t;
  1146.   register int length = (len-1) * sizeof (tree) + sizeof (struct tree_vec);
  1147.   register struct obstack *obstack = current_obstack;
  1148.   register int i;
  1149.  
  1150. #ifdef GATHER_STATISTICS
  1151.   tree_node_counts[(int)x_kind]++;
  1152.   tree_node_sizes[(int)x_kind] += length;
  1153. #endif
  1154.  
  1155.   t = (tree) obstack_alloc (obstack, length);
  1156.  
  1157.   TREE_TYPE (t) = 0;
  1158.   TREE_CHAIN (t) = 0;
  1159.   for (i = (length / sizeof (int)) - 1;
  1160.        i >= sizeof (struct tree_common) / sizeof (int) - 1;
  1161.        i--)
  1162.     ((int *) t)[i] = 0;
  1163.   TREE_SET_CODE (t, TREE_VEC);
  1164.   TREE_VEC_LENGTH (t) = len;
  1165.   if (obstack == &permanent_obstack)
  1166.     TREE_PERMANENT (t) = 1;
  1167.  
  1168.   return t;
  1169. }
  1170.  
  1171. /* Return 1 if EXPR is the integer constant zero.  */
  1172.  
  1173. int
  1174. integer_zerop (expr)
  1175.      tree expr;
  1176. {
  1177.   while (TREE_CODE (expr) == NON_LVALUE_EXPR)
  1178.     expr = TREE_OPERAND (expr, 0);
  1179.  
  1180.   return (TREE_CODE (expr) == INTEGER_CST
  1181.       && TREE_INT_CST_LOW (expr) == 0
  1182.       && TREE_INT_CST_HIGH (expr) == 0);
  1183. }
  1184.  
  1185. /* Return 1 if EXPR is the integer constant one.  */
  1186.  
  1187. int
  1188. integer_onep (expr)
  1189.      tree expr;
  1190. {
  1191.   while (TREE_CODE (expr) == NON_LVALUE_EXPR)
  1192.     expr = TREE_OPERAND (expr, 0);
  1193.  
  1194.   return (TREE_CODE (expr) == INTEGER_CST
  1195.       && TREE_INT_CST_LOW (expr) == 1
  1196.       && TREE_INT_CST_HIGH (expr) == 0);
  1197. }
  1198.  
  1199. /* Return 1 if EXPR is an integer containing all 1's
  1200.    in as much precision as it contains.  */
  1201.  
  1202. int
  1203. integer_all_onesp (expr)
  1204.      tree expr;
  1205. {
  1206.   register int prec;
  1207.   register int uns;
  1208.  
  1209.   while (TREE_CODE (expr) == NON_LVALUE_EXPR)
  1210.     expr = TREE_OPERAND (expr, 0);
  1211.  
  1212.   if (TREE_CODE (expr) != INTEGER_CST)
  1213.     return 0;
  1214.  
  1215.   uns = TREE_UNSIGNED (TREE_TYPE (expr));
  1216.   if (!uns)
  1217.     return TREE_INT_CST_LOW (expr) == -1 && TREE_INT_CST_HIGH (expr) == -1;
  1218.  
  1219.   prec = TYPE_PRECISION (TREE_TYPE (expr));
  1220.   if (prec >= HOST_BITS_PER_INT)
  1221.     return TREE_INT_CST_LOW (expr) == -1
  1222.       && TREE_INT_CST_HIGH (expr) == (1 << (prec - HOST_BITS_PER_INT)) - 1;
  1223.   else
  1224.     return TREE_INT_CST_LOW (expr) == (1 << prec) - 1;
  1225. }
  1226.  
  1227. /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
  1228.    one bit on).  */
  1229.  
  1230. int
  1231. integer_pow2p (expr)
  1232.      tree expr;
  1233. {
  1234.   int high, low;
  1235.  
  1236.   while (TREE_CODE (expr) == NON_LVALUE_EXPR)
  1237.     expr = TREE_OPERAND (expr, 0);
  1238.  
  1239.   if (TREE_CODE (expr) != INTEGER_CST)
  1240.     return 0;
  1241.  
  1242.   high = TREE_INT_CST_HIGH (expr);
  1243.   low = TREE_INT_CST_LOW (expr);
  1244.  
  1245.   if (high == 0 && low == 0)
  1246.     return 0;
  1247.  
  1248.   return ((high == 0 && (low & (low - 1)) == 0)
  1249.       || (low == 0 && (high & (high - 1)) == 0));
  1250. }
  1251.  
  1252. /* Return 1 if EXPR is the real constant zero.  */
  1253.  
  1254. int
  1255. real_zerop (expr)
  1256.      tree expr;
  1257. {
  1258.   while (TREE_CODE (expr) == NON_LVALUE_EXPR)
  1259.     expr = TREE_OPERAND (expr, 0);
  1260.  
  1261.   return (TREE_CODE (expr) == REAL_CST
  1262.       && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0));
  1263. }
  1264.  
  1265. /* Return 1 if EXPR is the real constant one.  */
  1266.  
  1267. int
  1268. real_onep (expr)
  1269.      tree expr;
  1270. {
  1271.   while (TREE_CODE (expr) == NON_LVALUE_EXPR)
  1272.     expr = TREE_OPERAND (expr, 0);
  1273.  
  1274.   return (TREE_CODE (expr) == REAL_CST
  1275.       && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1));
  1276. }
  1277.  
  1278. /* Return 1 if EXPR is the real constant two.  */
  1279.  
  1280. int
  1281. real_twop (expr)
  1282.      tree expr;
  1283. {
  1284.   while (TREE_CODE (expr) == NON_LVALUE_EXPR)
  1285.     expr = TREE_OPERAND (expr, 0);
  1286.  
  1287.   return (TREE_CODE (expr) == REAL_CST
  1288.       && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2));
  1289. }
  1290.  
  1291. /* Nonzero if EXP is a constant or a cast of a constant.  */
  1292.  
  1293. int
  1294. really_constant_p (exp)
  1295.      tree exp;
  1296. {
  1297.   while (TREE_CODE (exp) == NOP_EXPR
  1298.      || TREE_CODE (exp) == CONVERT_EXPR
  1299.      || TREE_CODE (exp) == NON_LVALUE_EXPR)
  1300.     exp = TREE_OPERAND (exp, 0);
  1301.   return TREE_CONSTANT (exp);
  1302. }
  1303.  
  1304. /* Return first list element whose TREE_VALUE is ELEM.
  1305.    Return 0 if ELEM is not it LIST.  */
  1306.  
  1307. tree
  1308. value_member (elem, list)
  1309.      tree elem, list;
  1310. {
  1311.   while (list)
  1312.     {
  1313.       if (elem == TREE_VALUE (list))
  1314.     return list;
  1315.       list = TREE_CHAIN (list);
  1316.     }
  1317.   return NULL_TREE;
  1318. }
  1319.  
  1320. /* Return first list element whose TREE_PURPOSE is ELEM.
  1321.    Return 0 if ELEM is not it LIST.  */
  1322.  
  1323. tree
  1324. purpose_member (elem, list)
  1325.      tree elem, list;
  1326. {
  1327.   while (list)
  1328.     {
  1329.       if (elem == TREE_PURPOSE (list))
  1330.     return list;
  1331.       list = TREE_CHAIN (list);
  1332.     }
  1333.   return NULL_TREE;
  1334. }
  1335.  
  1336. /* Return the length of a chain of nodes chained through TREE_CHAIN.
  1337.    We expect a null pointer to mark the end of the chain.
  1338.    This is the Lisp primitive `length'.  */
  1339.  
  1340. int
  1341. list_length (t)
  1342.      tree t;
  1343. {
  1344.   register tree tail;
  1345.   register int len = 0;
  1346.  
  1347.   for (tail = t; tail; tail = TREE_CHAIN (tail))
  1348.     len++;
  1349.  
  1350.   return len;
  1351. }
  1352.  
  1353. /* Concatenate two chains of nodes (chained through TREE_CHAIN)
  1354.    by modifying the last node in chain 1 to point to chain 2.
  1355.    This is the Lisp primitive `nconc'.  */
  1356.  
  1357. tree
  1358. chainon (op1, op2)
  1359.      tree op1, op2;
  1360. {
  1361.   tree t;
  1362.  
  1363.   if (op1)
  1364.     {
  1365.       for (t = op1; TREE_CHAIN (t); t = TREE_CHAIN (t))
  1366.     if (t == op2) abort ();    /* Circularity being created */
  1367.       TREE_CHAIN (t) = op2;
  1368.       return op1;
  1369.     }
  1370.   else return op2;
  1371. }
  1372.  
  1373. /* Return the last node in a chain of nodes (chained through TREE_CHAIN).  */
  1374.  
  1375. tree
  1376. tree_last (chain)
  1377.      register tree chain;
  1378. {
  1379.   register tree next;
  1380.   if (chain)
  1381.     while (next = TREE_CHAIN (chain))
  1382.       chain = next;
  1383.   return chain;
  1384. }
  1385.  
  1386. /* Reverse the order of elements in the chain T,
  1387.    and return the new head of the chain (old last element).  */
  1388.  
  1389. tree
  1390. nreverse (t)
  1391.      tree t;
  1392. {
  1393.   register tree prev = 0, decl, next;
  1394.   for (decl = t; decl; decl = next)
  1395.     {
  1396.       next = TREE_CHAIN (decl);
  1397.       TREE_CHAIN (decl) = prev;
  1398.       prev = decl;
  1399.     }
  1400.   return prev;
  1401. }
  1402.  
  1403. /* Given a chain CHAIN of tree nodes,
  1404.    construct and return a list of those nodes.  */
  1405.  
  1406. tree
  1407. listify (chain)
  1408.      tree chain;
  1409. {
  1410.   tree result = NULL_TREE;
  1411.   tree in_tail = chain;
  1412.   tree out_tail = NULL_TREE;
  1413.  
  1414.   while (in_tail)
  1415.     {
  1416.       tree next = tree_cons (NULL_TREE, in_tail, NULL_TREE);
  1417.       if (out_tail)
  1418.     TREE_CHAIN (out_tail) = next;
  1419.       else
  1420.     result = next;
  1421.       out_tail = next;
  1422.       in_tail = TREE_CHAIN (in_tail);
  1423.     }
  1424.  
  1425.   return result;
  1426. }
  1427.  
  1428. /* Return a newly created TREE_LIST node whose
  1429.    purpose and value fields are PARM and VALUE.  */
  1430.  
  1431. tree
  1432. build_tree_list (parm, value)
  1433.      tree parm, value;
  1434. {
  1435.   register tree t = make_node (TREE_LIST);
  1436.   TREE_PURPOSE (t) = parm;
  1437.   TREE_VALUE (t) = value;
  1438.   return t;
  1439. }
  1440.  
  1441. /* Similar, but build on the temp_decl_obstack.  */
  1442.  
  1443. tree
  1444. build_decl_list (parm, value)
  1445.      tree parm, value;
  1446. {
  1447.   register tree node;
  1448.   register struct obstack *ambient_obstack = current_obstack;
  1449.   current_obstack = &temp_decl_obstack;
  1450.   node = build_tree_list (parm, value);
  1451.   current_obstack = ambient_obstack;
  1452.   return node;
  1453. }
  1454.  
  1455. /* Return a newly created TREE_LIST node whose
  1456.    purpose and value fields are PARM and VALUE
  1457.    and whose TREE_CHAIN is CHAIN.  */
  1458.  
  1459. tree
  1460. tree_cons (purpose, value, chain)
  1461.      tree purpose, value, chain;
  1462. {
  1463. #if 0
  1464.   register tree node = make_node (TREE_LIST);
  1465. #else
  1466.   register int i;
  1467.   register tree node = (tree) obstack_alloc (current_obstack, sizeof (struct tree_list));
  1468. #ifdef GATHER_STATISTICS
  1469.   tree_node_counts[(int)x_kind]++;
  1470.   tree_node_sizes[(int)x_kind] += sizeof (struct tree_list);
  1471. #endif
  1472.  
  1473.   ((int *)node)[(sizeof (struct tree_common)/sizeof (int)) - 1] = 0;
  1474.   TREE_SET_CODE (node, TREE_LIST);
  1475.   if (current_obstack == &permanent_obstack)
  1476.     TREE_PERMANENT (node) = 1;
  1477.   TREE_TYPE (node) = 0;
  1478. #endif
  1479.  
  1480.   TREE_CHAIN (node) = chain;
  1481.   TREE_PURPOSE (node) = purpose;
  1482.   TREE_VALUE (node) = value;
  1483.   return node;
  1484. }
  1485.  
  1486. /* Similar, but build on the temp_decl_obstack.  */
  1487.  
  1488. tree
  1489. decl_tree_cons (purpose, value, chain)
  1490.      tree purpose, value, chain;
  1491. {
  1492.   register tree node;
  1493.   register struct obstack *ambient_obstack = current_obstack;
  1494.   current_obstack = &temp_decl_obstack;
  1495.   node = tree_cons (purpose, value, chain);
  1496.   current_obstack = ambient_obstack;
  1497.   return node;
  1498. }
  1499.  
  1500. /* Same as `tree_cons' but make a permanent object.  */
  1501.  
  1502. tree
  1503. perm_tree_cons (purpose, value, chain)
  1504.      tree purpose, value, chain;
  1505. {
  1506.   register tree node;
  1507.   register struct obstack *ambient_obstack = current_obstack;
  1508.   current_obstack = &permanent_obstack;
  1509.  
  1510.   node = tree_cons (purpose, value, chain);
  1511.   current_obstack = ambient_obstack;
  1512.   return node;
  1513. }
  1514.  
  1515. /* Same as `tree_cons', but make this node temporary, regardless.  */
  1516.  
  1517. tree
  1518. temp_tree_cons (purpose, value, chain)
  1519.      tree purpose, value, chain;
  1520. {
  1521.   register tree node;
  1522.   register struct obstack *ambient_obstack = current_obstack;
  1523.   current_obstack = &temporary_obstack;
  1524.  
  1525.   node = tree_cons (purpose, value, chain);
  1526.   current_obstack = ambient_obstack;
  1527.   return node;
  1528. }
  1529.  
  1530. /* Same as `tree_cons', but save this node if the function's RTL is saved.  */
  1531.  
  1532. tree
  1533. saveable_tree_cons (purpose, value, chain)
  1534.      tree purpose, value, chain;
  1535. {
  1536.   register tree node;
  1537.   register struct obstack *ambient_obstack = current_obstack;
  1538.   current_obstack = saveable_obstack;
  1539.  
  1540.   node = tree_cons (purpose, value, chain);
  1541.   current_obstack = ambient_obstack;
  1542.   return node;
  1543. }
  1544.  
  1545. /* Return the size nominally occupied by an object of type TYPE
  1546.    when it resides in memory.  The value is measured in units of bytes,
  1547.    and its data type is that normally used for type sizes
  1548.    (which is the first type created by make_signed_type or
  1549.    make_unsigned_type).  */
  1550.  
  1551. tree
  1552. size_in_bytes (type)
  1553.      tree type;
  1554. {
  1555.   if (type == error_mark_node)
  1556.     return integer_zero_node;
  1557.   type = TYPE_MAIN_VARIANT (type);
  1558.   if (TYPE_SIZE (type) == 0)
  1559.     {
  1560.       incomplete_type_error (0, type);
  1561.       return integer_zero_node;
  1562.     }
  1563.   return size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
  1564.              size_int (BITS_PER_UNIT));
  1565. }
  1566.  
  1567. /* Return the size of TYPE (in bytes) as an integer,
  1568.    or return -1 if the size can vary.  */
  1569.  
  1570. int
  1571. int_size_in_bytes (type)
  1572.      tree type;
  1573. {
  1574.   int size;
  1575.   if (type == error_mark_node)
  1576.     return 0;
  1577.   type = TYPE_MAIN_VARIANT (type);
  1578.   if (TYPE_SIZE (type) == 0)
  1579.     return -1;
  1580.   if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
  1581.     return -1;
  1582.   size = TREE_INT_CST_LOW (TYPE_SIZE (type));
  1583.   return (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
  1584. }
  1585.  
  1586. /* Return, as an INTEGER_CST node, the number of elements for
  1587.    TYPE (which is an ARRAY_TYPE).  */
  1588.  
  1589. tree
  1590. array_type_nelts (type)
  1591.      tree type;
  1592. {
  1593.   tree index_type = TYPE_DOMAIN (type);
  1594.   return (tree_int_cst_equal (TYPE_MIN_VALUE (index_type), integer_zero_node)
  1595.       ? TYPE_MAX_VALUE (index_type)
  1596.       : fold (build (MINUS_EXPR, integer_type_node,
  1597.              TYPE_MAX_VALUE (index_type),
  1598.              TYPE_MIN_VALUE (index_type))));
  1599. }
  1600.  
  1601. /* Return nonzero if arg is static -- a reference to an object in
  1602.    static storage.  This is not the same as the C meaning of `static'.  */
  1603.  
  1604. int
  1605. staticp (arg)
  1606.      tree arg;
  1607. {
  1608.   switch (TREE_CODE (arg))
  1609.     {
  1610.     case VAR_DECL:
  1611.     case FUNCTION_DECL:
  1612.     case CONSTRUCTOR:
  1613.       return TREE_STATIC (arg) || TREE_EXTERNAL (arg);
  1614.  
  1615.     case STRING_CST:
  1616.       return 1;
  1617.  
  1618.     case COMPONENT_REF:
  1619.     case BIT_FIELD_REF:
  1620.       return staticp (TREE_OPERAND (arg, 0));
  1621.  
  1622.     case INDIRECT_REF:
  1623.       return TREE_CONSTANT (TREE_OPERAND (arg, 0));
  1624.  
  1625.     case ARRAY_REF:
  1626.       if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
  1627.       && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
  1628.     return staticp (TREE_OPERAND (arg, 0));
  1629.     }
  1630.  
  1631.   return 0;
  1632. }
  1633.  
  1634. /* This should be applied to any node which may be used in more than one place,
  1635.    but must be evaluated only once.  Normally, the code generator would
  1636.    reevaluate the node each time; this forces it to compute it once and save
  1637.    the result.  This is done by encapsulating the node in a SAVE_EXPR.  */
  1638.  
  1639. tree
  1640. save_expr (expr)
  1641.      tree expr;
  1642. {
  1643.   register tree t = fold (expr);
  1644.  
  1645.   /* We don't care about whether this can be used as an lvalue in this
  1646.      context.  */
  1647.   while (TREE_CODE (t) == NON_LVALUE_EXPR)
  1648.     t = TREE_OPERAND (t, 0);
  1649.  
  1650.   /* If the tree evaluates to a constant, then we don't want to hide that
  1651.      fact (i.e. this allows further folding, and direct checks for constants).
  1652.      Since it is no problem to reevaluate literals, we just return the 
  1653.      literal node. */
  1654.  
  1655.   if (TREE_CONSTANT (t) || TREE_READONLY (t) || TREE_CODE (t) == SAVE_EXPR)
  1656.     return t;
  1657.  
  1658.   t = build (SAVE_EXPR, TREE_TYPE (expr), t, current_function_decl, NULL);
  1659.  
  1660.   /* This expression might be placed ahead of a jump to ensure that the
  1661.      value was computed on both sides of the jump.  So make sure it isn't
  1662.      eliminated as dead.  */
  1663.   TREE_SIDE_EFFECTS (t) = 1;
  1664.   return t;
  1665. }
  1666.  
  1667. /* Stabilize a reference so that we can use it any number of times
  1668.    without causing its operands to be evaluated more than once.
  1669.    Returns the stabilized reference.
  1670.  
  1671.    Also allows conversion expressions whose operands are references.
  1672.    Any other kind of expression is returned unchanged.  */
  1673.  
  1674. tree
  1675. stabilize_reference (ref)
  1676.      tree ref;
  1677. {
  1678.   register tree result;
  1679.   register enum tree_code code = TREE_CODE (ref);
  1680.  
  1681.   switch (code)
  1682.     {
  1683.     case VAR_DECL:
  1684.     case PARM_DECL:
  1685.     case RESULT_DECL:
  1686.       /* No action is needed in this case.  */
  1687.       return ref;
  1688.  
  1689.     case NOP_EXPR:
  1690.     case CONVERT_EXPR:
  1691.     case FLOAT_EXPR:
  1692.     case FIX_TRUNC_EXPR:
  1693.     case FIX_FLOOR_EXPR:
  1694.     case FIX_ROUND_EXPR:
  1695.     case FIX_CEIL_EXPR:
  1696.       result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
  1697.       break;
  1698.  
  1699.     case INDIRECT_REF:
  1700.       result = build_nt (INDIRECT_REF,
  1701.              stabilize_reference_1 (TREE_OPERAND (ref, 0)));
  1702.       break;
  1703.  
  1704.     case COMPONENT_REF:
  1705.       result = build_nt (COMPONENT_REF,
  1706.              stabilize_reference (TREE_OPERAND (ref, 0)),
  1707.              TREE_OPERAND (ref, 1));
  1708.       break;
  1709.  
  1710.     case BIT_FIELD_REF:
  1711.       result = build_nt (BIT_FIELD_REF,
  1712.              stabilize_reference (TREE_OPERAND (ref, 0)),
  1713.              stabilize_reference_1 (TREE_OPERAND (ref, 1)),
  1714.              stabilize_reference_1 (TREE_OPERAND (ref, 2)));
  1715.       break;
  1716.  
  1717.     case ARRAY_REF:
  1718.       result = build_nt (ARRAY_REF,
  1719.              stabilize_reference (TREE_OPERAND (ref, 0)),
  1720.              stabilize_reference_1 (TREE_OPERAND (ref, 1)));
  1721.       break;
  1722.  
  1723.       /* If arg isn't a kind of lvalue we recognize, make no change.
  1724.      Caller should recognize the error for an invalid lvalue.  */
  1725.     default:
  1726.       return ref;
  1727.  
  1728.     case ERROR_MARK:
  1729.       return error_mark_node;
  1730.     }
  1731.  
  1732.   TREE_TYPE (result) = TREE_TYPE (ref);
  1733.   TREE_READONLY (result) = TREE_READONLY (ref);
  1734.   TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
  1735.   TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
  1736.   TREE_RAISES (result) = TREE_RAISES (ref);
  1737.  
  1738.   return result;
  1739. }
  1740.  
  1741. /* Subroutine of stabilize_reference; this is called for subtrees of
  1742.    references.  Any expression with side-effects must be put in a SAVE_EXPR
  1743.    to ensure that it is only evaluated once.
  1744.  
  1745.    We don't put SAVE_EXPR nodes around everything, because assigning very
  1746.    simple expressions to temporaries causes us to miss good opportunities
  1747.    for optimizations.  Among other things, the opportunity to fold in the
  1748.    addition of a constant into an addressing mode often gets lost, e.g.
  1749.    "y[i+1] += x;".  In general, we take the approach that we should not make
  1750.    an assignment unless we are forced into it - i.e., that any non-side effect
  1751.    operator should be allowed, and that cse should take care of coalescing
  1752.    multiple utterances of the same expression should that prove fruitful.  */
  1753.  
  1754. static tree
  1755. stabilize_reference_1 (e)
  1756.      tree e;
  1757. {
  1758.   register tree result;
  1759.   register int length;
  1760.   register enum tree_code code = TREE_CODE (e);
  1761.  
  1762.   if (TREE_CONSTANT (e) || TREE_READONLY (e) || code == SAVE_EXPR)
  1763.     return e;
  1764.  
  1765.   switch (TREE_CODE_CLASS (code))
  1766.     {
  1767.     case 'x':
  1768.     case 't':
  1769.     case 'd':
  1770.     case '<':
  1771.     case 's':
  1772.     case 'e':
  1773.     case 'r':
  1774.       /* If the expression has side-effects, then encase it in a SAVE_EXPR
  1775.      so that it will only be evaluated once.  */
  1776.       /* The reference (r) and comparison (<) classes could be handled as
  1777.      below, but it is generally faster to only evaluate them once.  */
  1778.       if (TREE_SIDE_EFFECTS (e))
  1779.     return save_expr (e);
  1780.       return e;
  1781.  
  1782.     case 'c':
  1783.       /* Constants need no processing.  In fact, we should never reach
  1784.      here.  */
  1785.       return e;
  1786.       
  1787.     case '2':
  1788.       /* Recursively stabilize each operand.  */
  1789.       result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
  1790.              stabilize_reference_1 (TREE_OPERAND (e, 1)));
  1791.       break;
  1792.  
  1793.     case '1':
  1794.       /* Recursively stabilize each operand.  */
  1795.       result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
  1796.       break;
  1797.     }
  1798.   
  1799.   TREE_TYPE (result) = TREE_TYPE (e);
  1800.   TREE_READONLY (result) = TREE_READONLY (e);
  1801.   TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
  1802.   TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
  1803.   TREE_RAISES (result) = TREE_RAISES (e);
  1804.  
  1805.   return result;
  1806. }
  1807.  
  1808. /* Low-level constructors for expressions.  */
  1809.  
  1810. /* Build an expression of code CODE, data type TYPE,
  1811.    and operands as specified by the arguments ARG1 and following arguments.
  1812.    Expressions and reference nodes can be created this way.
  1813.    Constants, decls, types and misc nodes cannot be.  */
  1814.  
  1815. tree
  1816. build (va_alist)
  1817.      va_dcl
  1818. {
  1819.   register va_list p;
  1820.   enum tree_code code;
  1821.   register tree t;
  1822.   register int length;
  1823.   register int i;
  1824.  
  1825.   va_start (p);
  1826.  
  1827.   code = va_arg (p, enum tree_code);
  1828.   t = make_node (code);
  1829.   length = tree_code_length[(int) code];
  1830.   TREE_TYPE (t) = va_arg (p, tree);
  1831.  
  1832.   if (length == 2)
  1833.     {
  1834.       /* This is equivalent to the loop below, but faster.  */
  1835.       register tree arg0 = va_arg (p, tree);
  1836.       register tree arg1 = va_arg (p, tree);
  1837.       TREE_OPERAND (t, 0) = arg0;
  1838.       TREE_OPERAND (t, 1) = arg1;
  1839.       if ((arg0 && TREE_SIDE_EFFECTS (arg0))
  1840.       || (arg1 && TREE_SIDE_EFFECTS (arg1)))
  1841.     TREE_SIDE_EFFECTS (t) = 1;
  1842.       TREE_RAISES (t)
  1843.     = (arg0 && TREE_RAISES (arg0)) || (arg1 && TREE_RAISES (arg1));
  1844.     }
  1845.   else if (length == 1)
  1846.     {
  1847.       register tree arg0 = va_arg (p, tree);
  1848.  
  1849.       /* Call build1 for this!  */
  1850.       if (TREE_CODE_CLASS (code) != 's')
  1851.     abort ();
  1852.       TREE_OPERAND (t, 0) = arg0;
  1853.       if (arg0 && TREE_SIDE_EFFECTS (arg0))
  1854.     TREE_SIDE_EFFECTS (t) = 1;
  1855.       TREE_RAISES (t) = (arg0 && TREE_RAISES (arg0));
  1856.     }
  1857.   else
  1858.     {
  1859.       for (i = 0; i < length; i++)
  1860.     {
  1861.       register tree operand = va_arg (p, tree);
  1862.       TREE_OPERAND (t, i) = operand;
  1863.       if (operand)
  1864.         {
  1865.           if (TREE_SIDE_EFFECTS (operand))
  1866.         TREE_SIDE_EFFECTS (t) = 1;
  1867.           if (TREE_RAISES (operand))
  1868.         TREE_RAISES (t) = 1;
  1869.         }
  1870.     }
  1871.     }
  1872.   va_end (p);
  1873.   return t;
  1874. }
  1875.  
  1876. /* Same as above, but only builds for unary operators.
  1877.    Saves lions share of calls to `build'; cuts down use
  1878.    of varargs, which is expensive for RISC machines.  */
  1879. tree
  1880. build1 (code, type, node)
  1881.      enum tree_code code;
  1882.      tree type;
  1883.      tree node;
  1884. {
  1885.   register struct obstack *obstack = current_obstack;
  1886.   register int i, length;
  1887.   register tree_node_kind kind;
  1888.   register tree t;
  1889.  
  1890. #ifdef GATHER_STATISTICS
  1891.   if (TREE_CODE_CLASS (code) == 'r')
  1892.     kind = r_kind;
  1893.   else
  1894.     kind = e_kind;
  1895. #endif
  1896.  
  1897.   obstack = expression_obstack;
  1898.   length = sizeof (struct tree_exp);
  1899.  
  1900.   t = (tree) obstack_alloc (obstack, length);
  1901.  
  1902. #ifdef GATHER_STATISTICS
  1903.   tree_node_counts[(int)kind]++;
  1904.   tree_node_sizes[(int)kind] += length;
  1905. #endif
  1906.  
  1907.   TREE_TYPE (t) = type;
  1908.   TREE_CHAIN (t) = 0;
  1909.  
  1910.   for (i = (length / sizeof (int)) - 2;
  1911.        i >= sizeof (struct tree_common) / sizeof (int) - 1;
  1912.        i--)
  1913.     ((int *) t)[i] = 0;
  1914.   TREE_SET_CODE (t, code);
  1915.  
  1916.   if (obstack == &permanent_obstack)
  1917.     TREE_PERMANENT (t) = 1;
  1918.  
  1919.   TREE_OPERAND (t, 0) = node;
  1920.   if (node)
  1921.     {
  1922.       if (TREE_SIDE_EFFECTS (node))
  1923.     TREE_SIDE_EFFECTS (t) = 1;
  1924.       if (TREE_RAISES (node))
  1925.     TREE_RAISES (t) = 1;
  1926.     }
  1927.  
  1928.   return t;
  1929. }
  1930.  
  1931. /* Similar except don't specify the TREE_TYPE
  1932.    and leave the TREE_SIDE_EFFECTS as 0.
  1933.    It is permissible for arguments to be null,
  1934.    or even garbage if their values do not matter.  */
  1935.  
  1936. tree
  1937. build_nt (va_alist)
  1938.      va_dcl
  1939. {
  1940.   register va_list p;
  1941.   register enum tree_code code;
  1942.   register tree t;
  1943.   register int length;
  1944.   register int i;
  1945.  
  1946.   va_start (p);
  1947.  
  1948.   code = va_arg (p, enum tree_code);
  1949.   t = make_node (code);
  1950.   length = tree_code_length[(int) code];
  1951.  
  1952.   for (i = 0; i < length; i++)
  1953.     TREE_OPERAND (t, i) = va_arg (p, tree);
  1954.  
  1955.   va_end (p);
  1956.   return t;
  1957. }
  1958.  
  1959. /* Similar to `build_nt', except we build
  1960.    on the temp_decl_obstack, regardless.  */
  1961.  
  1962. tree
  1963. build_parse_node (va_alist)
  1964.      va_dcl
  1965. {
  1966.   register struct obstack *ambient_obstack = expression_obstack;
  1967.   register va_list p;
  1968.   register enum tree_code code;
  1969.   register tree t;
  1970.   register int length;
  1971.   register int i;
  1972.  
  1973.   expression_obstack = &temp_decl_obstack;
  1974.  
  1975.   va_start (p);
  1976.  
  1977.   code = va_arg (p, enum tree_code);
  1978.   t = make_node (code);
  1979.   length = tree_code_length[(int) code];
  1980.  
  1981.   for (i = 0; i < length; i++)
  1982.     TREE_OPERAND (t, i) = va_arg (p, tree);
  1983.  
  1984.   va_end (p);
  1985.   expression_obstack = ambient_obstack;
  1986.   return t;
  1987. }
  1988.  
  1989. #if 0
  1990. /* Commented out because this wants to be done very
  1991.    differently.  See cplus-lex.c.  */
  1992. tree
  1993. build_op_identifier (op1, op2)
  1994.      tree op1, op2;
  1995. {
  1996.   register tree t = make_node (OP_IDENTIFIER);
  1997.   TREE_PURPOSE (t) = op1;
  1998.   TREE_VALUE (t) = op2;
  1999.   return t;
  2000. }
  2001. #endif
  2002.  
  2003. /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
  2004.    We do NOT enter this node in any sort of symbol table.
  2005.  
  2006.    layout_decl is used to set up the decl's storage layout.
  2007.    Other slots are initialized to 0 or null pointers.  */
  2008.  
  2009. tree
  2010. build_decl (code, name, type)
  2011.      enum tree_code code;
  2012.      tree name, type;
  2013. {
  2014.   register tree t;
  2015.  
  2016.   t = make_node (code);
  2017.  
  2018. /*  if (type == error_mark_node)
  2019.     type = integer_type_node; */
  2020. /* That is not done, deliberately, so that having error_mark_node
  2021.    as the type can suppress useless errors in the use of this variable.  */
  2022.  
  2023.   DECL_NAME (t) = name;
  2024.   if (name)
  2025.     {
  2026.       DECL_ASSEMBLER_NAME (t) = IDENTIFIER_POINTER (name);
  2027.     }
  2028.   TREE_TYPE (t) = type;
  2029.  
  2030.   if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
  2031.     layout_decl (t, 0);
  2032.   else if (code == FUNCTION_DECL)
  2033.     DECL_MODE (t) = FUNCTION_MODE;
  2034.  
  2035.   return t;
  2036. }
  2037.  
  2038. /* BLOCK nodes are used to represent the structure of binding contours
  2039.    and declarations, once those contours have been exited and their contents
  2040.    compiled.  This information is used for outputting debugging info.
  2041.    A BLOCK may have a "controller" which is a BIND_EXPR node.
  2042.    Then the BLOCK is ignored unless the controller has the TREE_USED flag.  */
  2043.  
  2044. tree
  2045. build_block (vars, tags, subblocks, supercontext, chain)
  2046.      tree vars, tags, subblocks, supercontext, chain;
  2047. {
  2048.   register tree block = make_node (BLOCK);
  2049.   BLOCK_VARS (block) = vars;
  2050.   BLOCK_TYPE_TAGS (block) = tags;
  2051.   BLOCK_SUBBLOCKS (block) = subblocks;
  2052.   BLOCK_SUPERCONTEXT (block) = supercontext;
  2053.   BLOCK_CHAIN (block) = chain;
  2054.   return block;
  2055. }
  2056.  
  2057. /* Return a type like TYPE except that its TYPE_READONLY is CONSTP
  2058.    and its TYPE_VOLATILE is VOLATILEP.
  2059.  
  2060.    Such variant types already made are recorded so that duplicates
  2061.    are not made.
  2062.  
  2063.    A variant types should never be used as the type of an expression.
  2064.    Always copy the variant information into the TREE_READONLY
  2065.    and TREE_THIS_VOLATILE of the expression, and then give the expression
  2066.    as its type the "main variant", the variant whose TYPE_READONLY
  2067.    and TYPE_VOLATILE are zero.  Use TYPE_MAIN_VARIANT to find the
  2068.    main variant.  */
  2069.  
  2070. tree
  2071. build_type_variant (type, constp, volatilep)
  2072.      tree type;
  2073.      int constp, volatilep;
  2074. {
  2075.   register tree t, m = TYPE_MAIN_VARIANT (type);
  2076.   register struct obstack *ambient_obstack = current_obstack;
  2077.  
  2078.   /* Treat any nonzero argument as 1.  */
  2079.   constp = !!constp;
  2080.   volatilep = !!volatilep;
  2081.  
  2082.   /* If not generating auxilliary info, search the chain of variants to see
  2083.      if there is already one there just like the one we need to have.  If so,
  2084.      use that existing one.
  2085.  
  2086.      We don't do this in the case where we are generating aux info because
  2087.      in that case we want each typedef names to get it's own distinct type
  2088.      node, even if the type of this new typedef is the same as some other
  2089.      (existing) type.  */
  2090.  
  2091.   if (!flag_gen_aux_info)
  2092.     for (t = m; t; t = TYPE_NEXT_VARIANT (t))
  2093.       if (constp == TYPE_READONLY (t) && volatilep == TYPE_VOLATILE (t))
  2094.         return t;
  2095.  
  2096.   /* We need a new one.  */
  2097.   current_obstack
  2098.     = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
  2099.  
  2100.   t = copy_node (type);
  2101.   TYPE_READONLY (t) = constp;
  2102.   TYPE_VOLATILE (t) = volatilep;
  2103.   TYPE_POINTER_TO (t) = 0;
  2104.   TYPE_REFERENCE_TO (t) = 0;
  2105.  
  2106.   /* Add this type to the chain of variants of TYPE.  */
  2107.   TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
  2108.   TYPE_NEXT_VARIANT (m) = t;
  2109.  
  2110.   current_obstack = ambient_obstack;
  2111.   return t;
  2112. }
  2113.  
  2114. /* Hashing of types so that we don't make duplicates.
  2115.    The entry point is `type_hash_canon'.  */
  2116.  
  2117. /* Each hash table slot is a bucket containing a chain
  2118.    of these structures.  */
  2119.  
  2120. struct type_hash
  2121. {
  2122.   struct type_hash *next;    /* Next structure in the bucket.  */
  2123.   int hashcode;            /* Hash code of this type.  */
  2124.   tree type;            /* The type recorded here.  */
  2125. };
  2126.  
  2127. /* Now here is the hash table.  When recording a type, it is added
  2128.    to the slot whose index is the hash code mod the table size.
  2129.    Note that the hash table is used for several kinds of types
  2130.    (function types, array types and array index range types, for now).
  2131.    While all these live in the same table, they are completely independent,
  2132.    and the hash code is computed differently for each of these.  */
  2133.  
  2134. #define TYPE_HASH_SIZE 59
  2135. struct type_hash *type_hash_table[TYPE_HASH_SIZE];
  2136.  
  2137. /* Here is how primitive or already-canonicalized types' hash
  2138.    codes are made.  */
  2139. #define TYPE_HASH(TYPE) ((int) (TYPE) & 0777777)
  2140.  
  2141. /* Compute a hash code for a list of types (chain of TREE_LIST nodes
  2142.    with types in the TREE_VALUE slots), by adding the hash codes
  2143.    of the individual types.  */
  2144.  
  2145. int
  2146. type_hash_list (list)
  2147.      tree list;
  2148. {
  2149.   register int hashcode;
  2150.   register tree tail;
  2151.   for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
  2152.     hashcode += TYPE_HASH (TREE_VALUE (tail));
  2153.   return hashcode;
  2154. }
  2155.  
  2156. /* Look in the type hash table for a type isomorphic to TYPE.
  2157.    If one is found, return it.  Otherwise return 0.  */
  2158.  
  2159. tree
  2160. type_hash_lookup (hashcode, type)
  2161.      int hashcode;
  2162.      tree type;
  2163. {
  2164.   register struct type_hash *h;
  2165.   for (h = type_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
  2166.     if (h->hashcode == hashcode
  2167.     && TREE_CODE (h->type) == TREE_CODE (type)
  2168.     && TREE_TYPE (h->type) == TREE_TYPE (type)
  2169.     && (TYPE_MAX_VALUE (h->type) == TYPE_MAX_VALUE (type)
  2170.         || tree_int_cst_equal (TYPE_MAX_VALUE (h->type),
  2171.                    TYPE_MAX_VALUE (type)))
  2172.     && (TYPE_MIN_VALUE (h->type) == TYPE_MIN_VALUE (type)
  2173.         || tree_int_cst_equal (TYPE_MIN_VALUE (h->type),
  2174.                    TYPE_MIN_VALUE (type)))
  2175.     && (TYPE_DOMAIN (h->type) == TYPE_DOMAIN (type)
  2176.         || (TYPE_DOMAIN (h->type)
  2177.         && TREE_CODE (TYPE_DOMAIN (h->type)) == TREE_LIST
  2178.         && TYPE_DOMAIN (type)
  2179.         && TREE_CODE (TYPE_DOMAIN (type)) == TREE_LIST
  2180.         && type_list_equal (TYPE_DOMAIN (h->type), TYPE_DOMAIN (type)))))
  2181.       return h->type;
  2182.   return 0;
  2183. }
  2184.  
  2185. /* Add an entry to the type-hash-table
  2186.    for a type TYPE whose hash code is HASHCODE.  */
  2187.  
  2188. void
  2189. type_hash_add (hashcode, type)
  2190.      int hashcode;
  2191.      tree type;
  2192. {
  2193.   register struct type_hash *h;
  2194.  
  2195.   h = (struct type_hash *) oballoc (sizeof (struct type_hash));
  2196.   h->hashcode = hashcode;
  2197.   h->type = type;
  2198.   h->next = type_hash_table[hashcode % TYPE_HASH_SIZE];
  2199.   type_hash_table[hashcode % TYPE_HASH_SIZE] = h;
  2200. }
  2201.  
  2202. /* Given TYPE, and HASHCODE its hash code, return the canonical
  2203.    object for an identical type if one already exists.
  2204.    Otherwise, return TYPE, and record it as the canonical object
  2205.    if it is a permanent object.
  2206.  
  2207.    To use this function, first create a type of the sort you want.
  2208.    Then compute its hash code from the fields of the type that
  2209.    make it different from other similar types.
  2210.    Then call this function and use the value.
  2211.    This function frees the type you pass in if it is a duplicate.  */
  2212.  
  2213. /* Set to 1 to debug without canonicalization.  Never set by program.  */
  2214. int debug_no_type_hash = 0;
  2215.  
  2216. tree
  2217. type_hash_canon (hashcode, type)
  2218.      int hashcode;
  2219.      tree type;
  2220. {
  2221.   tree t1;
  2222.  
  2223.   if (debug_no_type_hash)
  2224.     return type;
  2225.  
  2226.   t1 = type_hash_lookup (hashcode, type);
  2227.   if (t1 != 0)
  2228.     {
  2229.       struct obstack *o
  2230.     = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
  2231.       obstack_free (o, type);
  2232. #ifdef GATHER_STATISTICS
  2233.       tree_node_counts[(int)t_kind]--;
  2234.       tree_node_sizes[(int)t_kind] -= sizeof (struct tree_type);
  2235. #endif
  2236.       return t1;
  2237.     }
  2238.  
  2239.   /* If this is a new type, record it for later reuse.  */
  2240.   if (current_obstack == &permanent_obstack)
  2241.     type_hash_add (hashcode, type);
  2242.  
  2243.   return type;
  2244. }
  2245.  
  2246. /* Given two lists of types
  2247.    (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
  2248.    return 1 if the lists contain the same types in the same order.
  2249.    Also, the TREE_PURPOSEs must match.  */
  2250.  
  2251. int
  2252. type_list_equal (l1, l2)
  2253.      tree l1, l2;
  2254. {
  2255.   register tree t1, t2;
  2256.   for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
  2257.     {
  2258.       if (TREE_VALUE (t1) != TREE_VALUE (t2))
  2259.     return 0;
  2260.       if (TREE_PURPOSE (t1) != TREE_PURPOSE (t2))
  2261.     {
  2262.       int cmp = simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
  2263.       if (cmp < 0)
  2264.         abort ();
  2265.       if (cmp == 0)
  2266.         return 0;
  2267.     }
  2268.     }
  2269.  
  2270.   return t1 == t2;
  2271. }
  2272.  
  2273. /* Nonzero if integer constants T1 and T2
  2274.    represent the same constant value.  */
  2275.  
  2276. int
  2277. tree_int_cst_equal (t1, t2)
  2278.      tree t1, t2;
  2279. {
  2280.   if (t1 == t2)
  2281.     return 1;
  2282.   if (t1 == 0 || t2 == 0)
  2283.     return 0;
  2284.   if (TREE_CODE (t1) == INTEGER_CST
  2285.       && TREE_CODE (t2) == INTEGER_CST
  2286.       && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
  2287.       && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
  2288.     return 1;
  2289.   return 0;
  2290. }
  2291.  
  2292. /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
  2293.    The precise way of comparison depends on their data type.  */
  2294.  
  2295. int
  2296. tree_int_cst_lt (t1, t2)
  2297.      tree t1, t2;
  2298. {
  2299.   if (t1 == t2)
  2300.     return 0;
  2301.  
  2302.   if (!TREE_UNSIGNED (TREE_TYPE (t1)))
  2303.     return INT_CST_LT (t1, t2);
  2304.   return INT_CST_LT_UNSIGNED (t1, t2);
  2305. }
  2306.  
  2307. /* Compare two constructor-element-type constants.  */
  2308. int
  2309. simple_cst_list_equal (l1, l2)
  2310.      tree l1, l2;
  2311. {
  2312.   while (l1 != NULL_TREE && l2 != NULL_TREE)
  2313.     {
  2314.       int cmp = simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2));
  2315.       if (cmp < 0)
  2316.     abort ();
  2317.       if (cmp == 0)
  2318.     return 0;
  2319.       l1 = TREE_CHAIN (l1);
  2320.       l2 = TREE_CHAIN (l2);
  2321.     }
  2322.   return (l1 == l2);
  2323. }
  2324.  
  2325. /* Return truthvalue of whether T1 is the same tree structure as T2.
  2326.    Return 1 if they are the same.
  2327.    Return 0 if they are understandably different.
  2328.    Return -1 if either contains tree structure not understood by
  2329.    this function.  */
  2330.  
  2331. int
  2332. simple_cst_equal (t1, t2)
  2333.      tree t1, t2;
  2334. {
  2335.   register enum tree_code code1, code2;
  2336.   int cmp;
  2337.  
  2338.   if (t1 == t2)
  2339.     return 1;
  2340.   if (t1 == 0 || t2 == 0)
  2341.     return 0;
  2342.  
  2343.   code1 = TREE_CODE (t1);
  2344.   code2 = TREE_CODE (t2);
  2345.  
  2346.   if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
  2347.     if (code2 == NOP_EXPR || code2 == CONVERT_EXPR || code2 == NON_LVALUE_EXPR)
  2348.       return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  2349.     else
  2350.       return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
  2351.   else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
  2352.        || code2 == NON_LVALUE_EXPR)
  2353.     return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
  2354.  
  2355.   if (code1 != code2)
  2356.     return 0;
  2357.  
  2358.   switch (code1)
  2359.     {
  2360.     case INTEGER_CST:
  2361.       return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
  2362.     && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
  2363.  
  2364.     case REAL_CST:
  2365.       return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
  2366.  
  2367.     case STRING_CST:
  2368.       return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
  2369.     && !bcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
  2370.           TREE_STRING_LENGTH (t1));
  2371.  
  2372.     case CONSTRUCTOR:
  2373.       abort ();
  2374.  
  2375.     case SAVE_EXPR:
  2376.       return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  2377.  
  2378.     case CALL_EXPR:
  2379.     case TARGET_EXPR:
  2380.       cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  2381.       if (cmp <= 0)
  2382.     return cmp;
  2383.       return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
  2384.  
  2385.     case COMPONENT_REF:
  2386.       if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
  2387.     return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  2388.       return 0;
  2389.  
  2390.     case BIT_FIELD_REF:
  2391.       return (simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
  2392.           && simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1))
  2393.           && simple_cst_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t2, 2)));
  2394.  
  2395.     case VAR_DECL:
  2396.     case PARM_DECL:
  2397.     case CONST_DECL:
  2398.     case FUNCTION_DECL:
  2399.       return 0;
  2400.  
  2401.     case PLUS_EXPR:
  2402.     case MINUS_EXPR:
  2403.     case MULT_EXPR:
  2404.     case TRUNC_DIV_EXPR:
  2405.     case TRUNC_MOD_EXPR:
  2406.     case LSHIFT_EXPR:
  2407.     case RSHIFT_EXPR:
  2408.       cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  2409.       if (cmp <= 0)
  2410.     return cmp;
  2411.       return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
  2412.  
  2413.     case NEGATE_EXPR:
  2414.     case ADDR_EXPR:
  2415.     case REFERENCE_EXPR:
  2416.     case INDIRECT_REF:
  2417.       return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  2418.  
  2419.     default:
  2420.       return -1;
  2421.     }
  2422. }
  2423.  
  2424. /* Constructors for pointer, array and function types.
  2425.    (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
  2426.    constructed by language-dependent code, not here.)  */
  2427.  
  2428. /* Construct, lay out and return the type of pointers to TO_TYPE.
  2429.    If such a type has already been constructed, reuse it.  */
  2430.  
  2431. tree
  2432. build_pointer_type (to_type)
  2433.      tree to_type;
  2434. {
  2435.   register tree t = TYPE_POINTER_TO (to_type);
  2436.   register struct obstack *ambient_obstack = current_obstack;
  2437.   register struct obstack *ambient_saveable_obstack = saveable_obstack;
  2438.  
  2439.   /* First, if we already have a type for pointers to TO_TYPE, use it.  */
  2440.  
  2441.   if (t)
  2442.     return t;
  2443.  
  2444.   /* We need a new one.  If TO_TYPE is permanent, make this permanent too.  */
  2445.   if (TREE_PERMANENT (to_type))
  2446.     {
  2447.       current_obstack = &permanent_obstack;
  2448.       saveable_obstack = &permanent_obstack;
  2449.     }
  2450.  
  2451.   t = make_node (POINTER_TYPE);
  2452.   TREE_TYPE (t) = to_type;
  2453.  
  2454.   /* Record this type as the pointer to TO_TYPE.  */
  2455.   TYPE_POINTER_TO (to_type) = t;
  2456.  
  2457.   /* Lay out the type.  This function has many callers that are concerned
  2458.      with expression-construction, and this simplifies them all.
  2459.      Also, it guarantees the TYPE_SIZE is permanent if the type is.  */
  2460.   layout_type (t);
  2461.  
  2462.   current_obstack = ambient_obstack;
  2463.   saveable_obstack = ambient_saveable_obstack;
  2464.   return t;
  2465. }
  2466.  
  2467. /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
  2468.    MAXVAL should be the maximum value in the domain
  2469.    (one less than the length of the array).  */
  2470.  
  2471. tree
  2472. build_index_type (maxval)
  2473.      tree maxval;
  2474. {
  2475.   register tree itype = make_node (INTEGER_TYPE);
  2476.   TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
  2477.   TYPE_MIN_VALUE (itype) = build_int_2 (0, 0);
  2478.   TREE_TYPE (TYPE_MIN_VALUE (itype)) = sizetype;
  2479.   TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);
  2480.   TYPE_MODE (itype) = SImode;
  2481.   TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
  2482.   TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
  2483.   if (TREE_CODE (maxval) == INTEGER_CST)
  2484.     {
  2485.       int maxint = TREE_INT_CST_LOW (maxval);
  2486.       return type_hash_canon (maxint > 0 ? maxint : - maxint, itype);
  2487.     }
  2488.   else
  2489.     return itype;
  2490. }
  2491.  
  2492. /* Just like build_index_type, but takes lowval and highval instead
  2493.    of just highval (maxval). */
  2494.  
  2495. tree
  2496. build_index_2_type (lowval,highval)
  2497.      tree lowval, highval;
  2498. {
  2499.   register tree itype = make_node (INTEGER_TYPE);
  2500.   TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
  2501.   TYPE_MIN_VALUE (itype) = convert (sizetype, lowval);
  2502.   TREE_TYPE (TYPE_MIN_VALUE (itype)) = sizetype;
  2503.   TYPE_MAX_VALUE (itype) = convert (sizetype, highval);
  2504.   TYPE_MODE (itype) = SImode;
  2505.   TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
  2506.   TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
  2507.   if ((TREE_CODE (lowval) == INTEGER_CST)
  2508.       && (TREE_CODE (highval) == INTEGER_CST))
  2509.     {
  2510.       int highint = TREE_INT_CST_LOW (highval);
  2511.       int lowint = TREE_INT_CST_LOW (lowval);
  2512.       int maxint = highint - lowint;
  2513.       return type_hash_canon (maxint > 0 ? maxint : - maxint, itype);
  2514.     }
  2515.   else
  2516.     return itype;
  2517. }
  2518.  
  2519. /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
  2520.    and number of elements specified by the range of values of INDEX_TYPE.
  2521.    If such a type has already been constructed, reuse it.  */
  2522.  
  2523. tree
  2524. build_array_type (elt_type, index_type)
  2525.      tree elt_type, index_type;
  2526. {
  2527.   register tree t = make_node (ARRAY_TYPE);
  2528.   int hashcode;
  2529.  
  2530.   if (TREE_CODE (elt_type) == FUNCTION_TYPE)
  2531.     {
  2532.       error ("arrays of functions are not meaningful");
  2533.       elt_type = integer_type_node;
  2534.     }
  2535.  
  2536.   TREE_TYPE (t) = elt_type;
  2537.   TYPE_DOMAIN (t) = index_type;
  2538.  
  2539.   /* Make sure TYPE_POINTER_TO (elt_type) is filled in.  */
  2540.   build_pointer_type (elt_type);
  2541.  
  2542.   if (index_type == 0)
  2543.     return t;
  2544.  
  2545.   hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type);
  2546.   t = type_hash_canon (hashcode, t);
  2547.  
  2548.   if (TYPE_SIZE (t) == 0)
  2549.     layout_type (t);
  2550.   return t;
  2551. }
  2552.  
  2553. /* Construct, lay out and return
  2554.    the type of functions returning type VALUE_TYPE
  2555.    given arguments of types ARG_TYPES.
  2556.    ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
  2557.    are data type nodes for the arguments of the function.
  2558.    If such a type has already been constructed, reuse it.  */
  2559.  
  2560. tree
  2561. build_function_type (value_type, arg_types)
  2562.      tree value_type, arg_types;
  2563. {
  2564.   register tree t;
  2565.   int hashcode;
  2566.  
  2567.   if (TREE_CODE (value_type) == FUNCTION_TYPE
  2568.       || TREE_CODE (value_type) == ARRAY_TYPE)
  2569.     {
  2570.       error ("function return type cannot be function or array");
  2571.       value_type = integer_type_node;
  2572.     }
  2573.  
  2574.   /* Make a node of the sort we want.  */
  2575.   t = make_node (FUNCTION_TYPE);
  2576.   TREE_TYPE (t) = value_type;
  2577.   TYPE_ARG_TYPES (t) = arg_types;
  2578.  
  2579.   /* If we already have such a type, use the old one and free this one.  */
  2580.   hashcode = TYPE_HASH (value_type) + type_hash_list (arg_types);
  2581.   t = type_hash_canon (hashcode, t);
  2582.  
  2583.   if (TYPE_SIZE (t) == 0)
  2584.     layout_type (t);
  2585.   return t;
  2586. }
  2587.  
  2588. /* Build the node for the type of references-to-TO_TYPE.  */
  2589.  
  2590. tree
  2591. build_reference_type (to_type)
  2592.      tree to_type;
  2593. {
  2594.   register tree t = TYPE_REFERENCE_TO (to_type);
  2595.   register struct obstack *ambient_obstack = current_obstack;
  2596.   register struct obstack *ambient_saveable_obstack = saveable_obstack;
  2597.  
  2598.   /* First, if we already have a type for pointers to TO_TYPE, use it.  */
  2599.  
  2600.   if (t)
  2601.     return t;
  2602.  
  2603.   /* We need a new one.  If TO_TYPE is permanent, make this permanent too.  */
  2604.   if (TREE_PERMANENT (to_type))
  2605.     {
  2606.       current_obstack = &permanent_obstack;
  2607.       saveable_obstack = &permanent_obstack;
  2608.     }
  2609.  
  2610.   t = make_node (REFERENCE_TYPE);
  2611.   TREE_TYPE (t) = to_type;
  2612.  
  2613.   /* Record this type as the pointer to TO_TYPE.  */
  2614.   TYPE_REFERENCE_TO (to_type) = t;
  2615.  
  2616.   layout_type (t);
  2617.  
  2618.   current_obstack = ambient_obstack;
  2619.   saveable_obstack = ambient_saveable_obstack;
  2620.   return t;
  2621. }
  2622.  
  2623. /* Construct, lay out and return the type of methods belonging to class
  2624.    BASETYPE and whose arguments and values are described by TYPE.
  2625.    If that type exists already, reuse it.
  2626.    TYPE must be a FUNCTION_TYPE node.  */
  2627.  
  2628. tree
  2629. build_method_type (basetype, type)
  2630.      tree basetype, type;
  2631. {
  2632.   register tree t;
  2633.   int hashcode;
  2634.  
  2635.   /* Make a node of the sort we want.  */
  2636.   t = make_node (METHOD_TYPE);
  2637.  
  2638.   if (TREE_CODE (type) != FUNCTION_TYPE)
  2639.     abort ();
  2640.  
  2641.   TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
  2642.   TREE_TYPE (t) = TREE_TYPE (type);
  2643.  
  2644.   /* The actual arglist for this function includes a "hidden" argument
  2645.      which is "this".  Put it into the list of argument types.  */
  2646.  
  2647.   TYPE_ARG_TYPES (t)
  2648.     = tree_cons (NULL, build_pointer_type (basetype), TYPE_ARG_TYPES (type));
  2649.  
  2650.   /* If we already have such a type, use the old one and free this one.  */
  2651.   hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
  2652.   t = type_hash_canon (hashcode, t);
  2653.  
  2654.   if (TYPE_SIZE (t) == 0)
  2655.     layout_type (t);
  2656.  
  2657.   return t;
  2658. }
  2659.  
  2660. /* Construct, lay out and return the type of methods belonging to class
  2661.    BASETYPE and whose arguments and values are described by TYPE.
  2662.    If that type exists already, reuse it.
  2663.    TYPE must be a FUNCTION_TYPE node.  */
  2664.  
  2665. tree
  2666. build_offset_type (basetype, type)
  2667.      tree basetype, type;
  2668. {
  2669.   register tree t;
  2670.   int hashcode;
  2671.  
  2672.   /* Make a node of the sort we want.  */
  2673.   t = make_node (OFFSET_TYPE);
  2674.  
  2675.   TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
  2676.   TREE_TYPE (t) = type;
  2677.  
  2678.   /* If we already have such a type, use the old one and free this one.  */
  2679.   hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
  2680.   t = type_hash_canon (hashcode, t);
  2681.  
  2682.   if (TYPE_SIZE (t) == 0)
  2683.     layout_type (t);
  2684.  
  2685.   return t;
  2686. }
  2687.  
  2688. /* Create a complex type whose components are COMPONENT_TYPE.  */
  2689.  
  2690. tree
  2691. build_complex_type (component_type)
  2692.      tree component_type;
  2693. {
  2694.   register tree t;
  2695.   int hashcode;
  2696.  
  2697.   /* Make a node of the sort we want.  */
  2698.   t = make_node (COMPLEX_TYPE);
  2699.  
  2700.   TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
  2701.   TYPE_VOLATILE (t) = TYPE_VOLATILE (component_type);
  2702.   TYPE_READONLY (t) = TYPE_READONLY (component_type);
  2703.  
  2704.   /* If we already have such a type, use the old one and free this one.  */
  2705.   hashcode = TYPE_HASH (component_type);
  2706.   t = type_hash_canon (hashcode, t);
  2707.  
  2708.   if (TYPE_SIZE (t) == 0)
  2709.     layout_type (t);
  2710.  
  2711.   return t;
  2712. }
  2713.  
  2714. /* Return OP, stripped of any conversions to wider types as much as is safe.
  2715.    Converting the value back to OP's type makes a value equivalent to OP.
  2716.  
  2717.    If FOR_TYPE is nonzero, we return a value which, if converted to
  2718.    type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
  2719.  
  2720.    If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
  2721.    narrowest type that can hold the value, even if they don't exactly fit.
  2722.    Otherwise, bit-field references are changed to a narrower type
  2723.    only if they can be fetched directly from memory in that type.
  2724.  
  2725.    OP must have integer, real or enumeral type.  Pointers are not allowed!
  2726.  
  2727.    There are some cases where the obvious value we could return
  2728.    would regenerate to OP if converted to OP's type, 
  2729.    but would not extend like OP to wider types.
  2730.    If FOR_TYPE indicates such extension is contemplated, we eschew such values.
  2731.    For example, if OP is (unsigned short)(signed char)-1,
  2732.    we avoid returning (signed char)-1 if FOR_TYPE is int,
  2733.    even though extending that to an unsigned short would regenerate OP,
  2734.    since the result of extending (signed char)-1 to (int)
  2735.    is different from (int) OP.  */
  2736.  
  2737. tree
  2738. get_unwidened (op, for_type)
  2739.      register tree op;
  2740.      tree for_type;
  2741. {
  2742.   /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension.  */
  2743.   /* TYPE_PRECISION is safe in place of type_precision since
  2744.      pointer types are not allowed.  */
  2745.   register tree type = TREE_TYPE (op);
  2746.   register int final_prec = TYPE_PRECISION (for_type != 0 ? for_type : type);
  2747.   register int uns
  2748.     = (for_type != 0 && for_type != type
  2749.        && final_prec > TYPE_PRECISION (type)
  2750.        && TREE_UNSIGNED (type));
  2751.   register tree win = op;
  2752.  
  2753.   while (TREE_CODE (op) == NOP_EXPR)
  2754.     {
  2755.       register int bitschange
  2756.     = TYPE_PRECISION (TREE_TYPE (op))
  2757.       - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
  2758.  
  2759.       /* Truncations are many-one so cannot be removed.
  2760.      Unless we are later going to truncate down even farther.  */
  2761.       if (bitschange < 0
  2762.       && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
  2763.     break;
  2764.  
  2765.       /* See what's inside this conversion.  If we decide to strip it,
  2766.      we will set WIN.  */
  2767.       op = TREE_OPERAND (op, 0);
  2768.  
  2769.       /* If we have not stripped any zero-extensions (uns is 0),
  2770.      we can strip any kind of extension.
  2771.      If we have previously stripped a zero-extension,
  2772.      only zero-extensions can safely be stripped.
  2773.      Any extension can be stripped if the bits it would produce
  2774.      are all going to be discarded later by truncating to FOR_TYPE.  */
  2775.  
  2776.       if (bitschange > 0)
  2777.     {
  2778.       if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
  2779.         win = op;
  2780.       /* TREE_UNSIGNED says whether this is a zero-extension.
  2781.          Let's avoid computing it if it does not affect WIN
  2782.          and if UNS will not be needed again.  */
  2783.       if ((uns || TREE_CODE (op) == NOP_EXPR)
  2784.           && TREE_UNSIGNED (TREE_TYPE (op)))
  2785.         {
  2786.           uns = 1;
  2787.           win = op;
  2788.         }
  2789.     }
  2790.     }
  2791.  
  2792.   if (TREE_CODE (op) == COMPONENT_REF
  2793.       /* Since type_for_size always gives an integer type.  */
  2794.       && TREE_CODE (type) != REAL_TYPE)
  2795.     {
  2796.       int innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
  2797.       type = type_for_size (innerprec, TREE_UNSIGNED (TREE_OPERAND (op, 1)));
  2798.  
  2799.       /* We can get this structure field in the narrowest type it fits in.
  2800.      If FOR_TYPE is 0, do this only for a field that matches the
  2801.      narrower type exactly and is aligned for it
  2802.      The resulting extension to its nominal type (a fullword type)
  2803.      must fit the same conditions as for other extensions.  */
  2804.  
  2805.       if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
  2806.       && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))
  2807.       && (! uns || final_prec <= innerprec
  2808.           || TREE_UNSIGNED (TREE_OPERAND (op, 1)))
  2809.       && type != 0)
  2810.     {
  2811.       win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
  2812.                TREE_OPERAND (op, 1));
  2813.       TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
  2814.       TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
  2815.       TREE_RAISES (win) = TREE_RAISES (op);
  2816.     }
  2817.     }
  2818.   return win;
  2819. }
  2820.  
  2821. /* Return OP or a simpler expression for a narrower value
  2822.    which can be sign-extended or zero-extended to give back OP.
  2823.    Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
  2824.    or 0 if the value should be sign-extended.  */
  2825.  
  2826. tree
  2827. get_narrower (op, unsignedp_ptr)
  2828.      register tree op;
  2829.      int *unsignedp_ptr;
  2830. {
  2831.   register int uns = 0;
  2832.   int first = 1;
  2833.   register tree win = op;
  2834.  
  2835.   while (TREE_CODE (op) == NOP_EXPR)
  2836.     {
  2837.       register int bitschange
  2838.     = TYPE_PRECISION (TREE_TYPE (op))
  2839.       - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
  2840.  
  2841.       /* Truncations are many-one so cannot be removed.  */
  2842.       if (bitschange < 0)
  2843.     break;
  2844.  
  2845.       /* See what's inside this conversion.  If we decide to strip it,
  2846.      we will set WIN.  */
  2847.       op = TREE_OPERAND (op, 0);
  2848.  
  2849.       if (bitschange > 0)
  2850.     {
  2851.       /* An extension: the outermost one can be stripped,
  2852.          but remember whether it is zero or sign extension.  */
  2853.       if (first)
  2854.         uns = TREE_UNSIGNED (TREE_TYPE (op));
  2855.       /* Otherwise, if a sign extension has been stripped,
  2856.          only sign extensions can now be stripped;
  2857.          if a zero extension has been stripped, only zero-extensions.  */
  2858.       else if (uns != TREE_UNSIGNED (TREE_TYPE (op)))
  2859.         break;
  2860.       first = 0;
  2861.     }
  2862.       /* A change in nominal type can always be stripped.  */
  2863.  
  2864.       win = op;
  2865.     }
  2866.  
  2867.   if (TREE_CODE (op) == COMPONENT_REF
  2868.       /* Since type_for_size always gives an integer type.  */
  2869.       && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE)
  2870.     {
  2871.       int innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
  2872.       tree type = type_for_size (innerprec, TREE_UNSIGNED (op));
  2873.  
  2874.       /* We can get this structure field in a narrower type that fits it,
  2875.      but the resulting extension to its nominal type (a fullword type)
  2876.      must satisfy the same conditions as for other extensions.
  2877.  
  2878.      Do this only for fields that are aligned (not bit-fields),
  2879.      because when bit-field insns will be used there is no
  2880.      advantage in doing this.  */
  2881.  
  2882.       if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
  2883.       && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
  2884.       && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1)))
  2885.       && type != 0)
  2886.     {
  2887.       if (first)
  2888.         uns = TREE_UNSIGNED (TREE_OPERAND (op, 1));
  2889.       win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
  2890.                TREE_OPERAND (op, 1));
  2891.       TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
  2892.       TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
  2893.       TREE_RAISES (win) = TREE_RAISES (op);
  2894.     }
  2895.     }
  2896.   *unsignedp_ptr = uns;
  2897.   return win;
  2898. }
  2899.  
  2900. /* Return the precision of a type, for arithmetic purposes.
  2901.    Supports all types on which arithmetic is possible
  2902.    (including pointer types).
  2903.    It's not clear yet what will be right for complex types.  */
  2904.  
  2905. int
  2906. type_precision (type)
  2907.      register tree type;
  2908. {
  2909.   return ((TREE_CODE (type) == INTEGER_TYPE
  2910.        || TREE_CODE (type) == ENUMERAL_TYPE
  2911.        || TREE_CODE (type) == REAL_TYPE)
  2912.       ? TYPE_PRECISION (type) : POINTER_SIZE);
  2913. }
  2914.  
  2915. /* Nonzero if integer constant C has a value that is permissible
  2916.    for type TYPE (an INTEGER_TYPE).  */
  2917.  
  2918. int
  2919. int_fits_type_p (c, type)
  2920.      tree c, type;
  2921. {
  2922.   if (TREE_UNSIGNED (type))
  2923.     return (!INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type), c)
  2924.         && !INT_CST_LT_UNSIGNED (c, TYPE_MIN_VALUE (type)));
  2925.   else
  2926.     return (!INT_CST_LT (TYPE_MAX_VALUE (type), c)
  2927.         && !INT_CST_LT (c, TYPE_MIN_VALUE (type)));
  2928. }
  2929.  
  2930. /* Return the innermost context enclosing FNDECL that is
  2931.    a FUNCTION_DECL, or zero if none.  */
  2932.  
  2933. tree
  2934. decl_function_context (fndecl)
  2935.      tree fndecl;
  2936. {
  2937.   tree context;
  2938.  
  2939.   if (TREE_CODE (fndecl) == ERROR_MARK)
  2940.     return 0;
  2941.  
  2942.   if (TREE_CODE (fndecl) == SAVE_EXPR)
  2943.     context = SAVE_EXPR_CONTEXT (fndecl);
  2944.   else
  2945.     context = DECL_CONTEXT (fndecl);
  2946.  
  2947.   while (context && TREE_CODE (context) != FUNCTION_DECL)
  2948.     {
  2949.       if (TREE_CODE (context) == RECORD_TYPE
  2950.       || TREE_CODE (context) == UNION_TYPE)
  2951.     context = TYPE_CONTEXT (context);
  2952.       else if (TREE_CODE (context) == TYPE_DECL)
  2953.     context = DECL_CONTEXT (context);
  2954.       else if (TREE_CODE (context) == BLOCK)
  2955.     context = BLOCK_SUPERCONTEXT (context);
  2956.       else
  2957.     /* Unhandled CONTEXT !?  */
  2958.     abort ();
  2959.     }
  2960.  
  2961.   return context;
  2962. }
  2963.  
  2964. /* Return the innermost context enclosing FNDECL that is
  2965.    a RECORD_TYPE or UNION_TYPE, or zero if none.
  2966.    TYPE_DECLs and FUNCTION_DECLs are transparent to this function.  */
  2967.  
  2968. tree
  2969. decl_type_context (fndecl)
  2970.      tree fndecl;
  2971. {
  2972.   tree context = DECL_CONTEXT (fndecl);
  2973.  
  2974.   while (context)
  2975.     {
  2976.       if (TREE_CODE (context) == RECORD_TYPE
  2977.       || TREE_CODE (context) == UNION_TYPE)
  2978.     return context;
  2979.       if (TREE_CODE (context) == TYPE_DECL
  2980.       || TREE_CODE (context) == FUNCTION_DECL)
  2981.     context = DECL_CONTEXT (context);
  2982.       else if (TREE_CODE (context) == BLOCK)
  2983.     context = BLOCK_SUPERCONTEXT (context);
  2984.       else
  2985.     /* Unhandled CONTEXT!?  */
  2986.     abort ();
  2987.     }
  2988.   return NULL_TREE;
  2989. }
  2990.  
  2991. void
  2992. print_obstack_statistics (str, o)
  2993.      char *str;
  2994.      struct obstack *o;
  2995. {
  2996.   struct _obstack_chunk *chunk = o->chunk;
  2997.   int n_chunks = 0;
  2998.   int n_alloc = 0;
  2999.  
  3000.   while (chunk)
  3001.     {
  3002.       n_chunks += 1;
  3003.       n_alloc += chunk->limit - &chunk->contents[0];
  3004.       chunk = chunk->prev;
  3005.     }
  3006.   fprintf (stderr, "obstack %s: %d bytes, %d chunks\n",
  3007.        str, n_alloc, n_chunks);
  3008. }
  3009. void
  3010. dump_tree_statistics ()
  3011. {
  3012.   int i;
  3013.   int total_nodes, total_bytes;
  3014.   extern struct obstack class_obstack;
  3015.  
  3016.   fprintf (stderr, "\n??? tree nodes created\n\n");
  3017. #ifdef GATHER_STATISTICS
  3018.   fprintf (stderr, "Kind                  Nodes     Bytes\n");
  3019.   fprintf (stderr, "-------------------------------------\n");
  3020.   total_nodes = total_bytes = 0;
  3021.   for (i = 0; i < (int) all_kinds; i++)
  3022.     {
  3023.       fprintf (stderr, "%-20s %6d %9d\n", tree_node_kind_names[i],
  3024.            tree_node_counts[i], tree_node_sizes[i]);
  3025.       total_nodes += tree_node_counts[i];
  3026.       total_bytes += tree_node_sizes[i];
  3027.     }
  3028.   fprintf (stderr, "%-20s        %9d\n", "identifier names", id_string_size);
  3029.   fprintf (stderr, "-------------------------------------\n");
  3030.   fprintf (stderr, "%-20s %6d %9d\n", "Total", total_nodes, total_bytes);
  3031.   fprintf (stderr, "-------------------------------------\n");
  3032. #else
  3033.   fprintf (stderr, "(No per-node statistics)\n");
  3034. #endif
  3035.   print_lang_statistics ();
  3036. }
  3037.