home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / gcc / tree.c < prev    next >
C/C++ Source or Header  |  1996-12-09  |  125KB  |  4,492 lines

  1. /* Language-independent node constructors for parse phase of GNU compiler.
  2.    Copyright (C) 1987, 88, 92, 93, 94, 1995 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, 59 Temple Place - Suite 330,
  19. Boston, MA 02111-1307, USA.  */
  20.  
  21.  
  22. /* This file contains the low level primitives for operating on tree nodes,
  23.    including allocation, list operations, interning of identifiers,
  24.    construction of data type nodes and statement nodes,
  25.    and construction of type conversion nodes.  It also contains
  26.    tables index by tree code that describe how to take apart
  27.    nodes of that code.
  28.  
  29.    It is intended to be language-independent, but occasionally
  30.    calls language-dependent routines defined (for C) in typecheck.c.
  31.  
  32.    The low-level allocation routines oballoc and permalloc
  33.    are used also for allocating many other kinds of objects
  34.    by all passes of the compiler.  */
  35.  
  36. #include <setjmp.h>
  37. #include "config.h"
  38. #include "flags.h"
  39. #include "tree.h"
  40. #include "objc-act.h"
  41. #include "function.h"
  42. #include "obstack.h"
  43. #ifdef __STDC__
  44. #include <stdarg.h>
  45. #else
  46. #include <varargs.h>
  47. #endif
  48. #include <stdio.h>
  49.  
  50. #define obstack_chunk_alloc xmalloc
  51. #define obstack_chunk_free free
  52.  
  53. /* Tree nodes of permanent duration are allocated in this obstack.
  54.    They are the identifier nodes, and everything outside of
  55.    the bodies and parameters of function definitions.  */
  56.  
  57. struct obstack permanent_obstack;
  58.  
  59. /* The initial RTL, and all ..._TYPE nodes, in a function
  60.    are allocated in this obstack.  Usually they are freed at the
  61.    end of the function, but if the function is inline they are saved.
  62.    For top-level functions, this is maybepermanent_obstack.
  63.    Separate obstacks are made for nested functions.  */
  64.  
  65. struct obstack *function_maybepermanent_obstack;
  66.  
  67. /* This is the function_maybepermanent_obstack for top-level functions.  */
  68.  
  69. struct obstack maybepermanent_obstack;
  70.  
  71. /* This is a list of function_maybepermanent_obstacks for top-level inline
  72.    functions that are compiled in the middle of compiling other functions.  */
  73.  
  74. struct simple_obstack_stack *toplev_inline_obstacks;
  75.  
  76. /* This is a list of function_maybepermanent_obstacks for inline functions
  77.    nested in the current function that were compiled in the middle of
  78.    compiling other functions.  */
  79.  
  80. struct simple_obstack_stack *inline_obstacks;
  81.  
  82. /* The contents of the current function definition are allocated
  83.    in this obstack, and all are freed at the end of the function.
  84.    For top-level functions, this is temporary_obstack.
  85.    Separate obstacks are made for nested functions.  */
  86.  
  87. struct obstack *function_obstack;
  88.  
  89. /* This is used for reading initializers of global variables.  */
  90.  
  91. struct obstack temporary_obstack;
  92.  
  93. /* The tree nodes of an expression are allocated
  94.    in this obstack, and all are freed at the end of the expression.  */
  95.  
  96. struct obstack momentary_obstack;
  97.  
  98. /* The tree nodes of a declarator are allocated
  99.    in this obstack, and all are freed when the declarator
  100.    has been parsed.  */
  101.  
  102. static struct obstack temp_decl_obstack;
  103.  
  104. /* This points at either permanent_obstack
  105.    or the current function_maybepermanent_obstack.  */
  106.  
  107. struct obstack *saveable_obstack;
  108.  
  109. /* This is same as saveable_obstack during parse and expansion phase;
  110.    it points to the current function's obstack during optimization.
  111.    This is the obstack to be used for creating rtl objects.  */
  112.  
  113. struct obstack *rtl_obstack;
  114.  
  115. /* This points at either permanent_obstack or the current function_obstack.  */
  116.  
  117. struct obstack *current_obstack;
  118.  
  119. /* This points at either permanent_obstack or the current function_obstack
  120.    or momentary_obstack.  */
  121.  
  122. struct obstack *expression_obstack;
  123.  
  124. /* Stack of obstack selections for push_obstacks and pop_obstacks.  */
  125.  
  126. struct obstack_stack
  127. {
  128.   struct obstack_stack *next;
  129.   struct obstack *current;
  130.   struct obstack *saveable;
  131.   struct obstack *expression;
  132.   struct obstack *rtl;
  133. };
  134.  
  135. struct obstack_stack *obstack_stack;
  136.  
  137. /* Obstack for allocating struct obstack_stack entries.  */
  138.  
  139. static struct obstack obstack_stack_obstack;
  140.  
  141. /* Addresses of first objects in some obstacks.
  142.    This is for freeing their entire contents.  */
  143. char *maybepermanent_firstobj;
  144. char *temporary_firstobj;
  145. char *momentary_firstobj;
  146. char *temp_decl_firstobj;
  147.  
  148. /* This is used to preserve objects (mainly array initializers) that need to
  149.    live until the end of the current function, but no further.  */
  150. char *momentary_function_firstobj;
  151.  
  152. /* Nonzero means all ..._TYPE nodes should be allocated permanently.  */
  153.  
  154. int all_types_permanent;
  155.  
  156. /* Stack of places to restore the momentary obstack back to.  */
  157.    
  158. struct momentary_level
  159. {
  160.   /* Pointer back to previous such level.  */
  161.   struct momentary_level *prev;
  162.   /* First object allocated within this level.  */
  163.   char *base;
  164.   /* Value of expression_obstack saved at entry to this level.  */
  165.   struct obstack *obstack;
  166. };
  167.  
  168. struct momentary_level *momentary_stack;
  169.  
  170. /* Table indexed by tree code giving a string containing a character
  171.    classifying the tree code.  Possibilities are
  172.    t, d, s, c, r, <, 1, 2 and e.  See tree.def for details.  */
  173.  
  174. #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
  175.  
  176. char *standard_tree_code_type[] = {
  177. #include "tree.def"
  178. };
  179. #undef DEFTREECODE
  180.  
  181. /* Table indexed by tree code giving number of expression
  182.    operands beyond the fixed part of the node structure.
  183.    Not used for types or decls.  */
  184.  
  185. #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
  186.  
  187. int standard_tree_code_length[] = {
  188. #include "tree.def"
  189. };
  190. #undef DEFTREECODE
  191.  
  192. /* Names of tree components.
  193.    Used for printing out the tree and error messages.  */
  194. #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
  195.  
  196. char *standard_tree_code_name[] = {
  197. #include "tree.def"
  198. };
  199. #undef DEFTREECODE
  200.  
  201. /* Table indexed by tree code giving a string containing a character
  202.    classifying the tree code.  Possibilities are
  203.    t, d, s, c, r, e, <, 1 and 2.  See tree.def for details.  */
  204.  
  205. char **tree_code_type;
  206.  
  207. /* Table indexed by tree code giving number of expression
  208.    operands beyond the fixed part of the node structure.
  209.    Not used for types or decls.  */
  210.  
  211. int *tree_code_length;
  212.  
  213. /* Table indexed by tree code giving name of tree code, as a string.  */
  214.  
  215. char **tree_code_name;
  216.  
  217. /* Statistics-gathering stuff.  */
  218. typedef enum
  219. {
  220.   d_kind,
  221.   t_kind,
  222.   b_kind,
  223.   s_kind,
  224.   r_kind,
  225.   e_kind,
  226.   c_kind,
  227.   id_kind,
  228.   op_id_kind,
  229.   perm_list_kind,
  230.   temp_list_kind,
  231.   vec_kind,
  232.   x_kind,
  233.   lang_decl,
  234.   lang_type,
  235.   all_kinds
  236. } tree_node_kind;
  237.  
  238. int tree_node_counts[(int)all_kinds];
  239. int tree_node_sizes[(int)all_kinds];
  240. int id_string_size = 0;
  241.  
  242. char *tree_node_kind_names[] = {
  243.   "decls",
  244.   "types",
  245.   "blocks",
  246.   "stmts",
  247.   "refs",
  248.   "exprs",
  249.   "constants",
  250.   "identifiers",
  251.   "op_identifiers",
  252.   "perm_tree_lists",
  253.   "temp_tree_lists",
  254.   "vecs",
  255.   "random kinds",
  256.   "lang_decl kinds",
  257.   "lang_type kinds"
  258. };
  259.  
  260. /* Hash table for uniquizing IDENTIFIER_NODEs by name.  */
  261.  
  262. #define MAX_HASH_TABLE 1009
  263. static tree hash_table[MAX_HASH_TABLE];    /* id hash buckets */
  264.  
  265. /* 0 while creating built-in identifiers.  */
  266. static int do_identifier_warnings;
  267.  
  268. /* Unique id for next decl created.  */
  269. static int next_decl_uid;
  270. /* Unique id for next type created.  */
  271. static int next_type_uid = 1;
  272.  
  273. /* Here is how primitive or already-canonicalized types' hash
  274.    codes are made.  */
  275. #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
  276.  
  277. extern char *mode_name[];
  278.  
  279. #ifdef NEXT_SEMANTICS
  280. extern short *reg_renumber;
  281. #endif
  282.  
  283. void gcc_obstack_init ();
  284.  
  285. /* Init the principal obstacks.  */
  286.  
  287. void
  288. init_obstacks ()
  289. {
  290.   gcc_obstack_init (&obstack_stack_obstack);
  291.   gcc_obstack_init (&permanent_obstack);
  292.  
  293.   gcc_obstack_init (&temporary_obstack);
  294.   temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0);
  295.   gcc_obstack_init (&momentary_obstack);
  296.   momentary_firstobj = (char *) obstack_alloc (&momentary_obstack, 0);
  297.   momentary_function_firstobj = momentary_firstobj;
  298.   gcc_obstack_init (&maybepermanent_obstack);
  299.   maybepermanent_firstobj
  300.     = (char *) obstack_alloc (&maybepermanent_obstack, 0);
  301.   gcc_obstack_init (&temp_decl_obstack);
  302.   temp_decl_firstobj = (char *) obstack_alloc (&temp_decl_obstack, 0);
  303.  
  304.   function_obstack = &temporary_obstack;
  305.   function_maybepermanent_obstack = &maybepermanent_obstack;
  306.   current_obstack = &permanent_obstack;
  307.   expression_obstack = &permanent_obstack;
  308.   rtl_obstack = saveable_obstack = &permanent_obstack;
  309.  
  310.   /* Init the hash table of identifiers.  */
  311.   bzero ((char *) hash_table, sizeof hash_table);
  312. }
  313.  
  314. void
  315. gcc_obstack_init (obstack)
  316.      struct obstack *obstack;
  317. {
  318.   /* Let particular systems override the size of a chunk.  */
  319. #ifndef OBSTACK_CHUNK_SIZE
  320. #define OBSTACK_CHUNK_SIZE 0
  321. #endif
  322.   /* Let them override the alloc and free routines too.  */
  323. #ifndef OBSTACK_CHUNK_ALLOC
  324. #define OBSTACK_CHUNK_ALLOC xmalloc
  325. #endif
  326. #ifndef OBSTACK_CHUNK_FREE
  327. #define OBSTACK_CHUNK_FREE free
  328. #endif
  329.   _obstack_begin (obstack, OBSTACK_CHUNK_SIZE, 0,
  330.           (void *(*) ()) OBSTACK_CHUNK_ALLOC,
  331.           (void (*) ()) OBSTACK_CHUNK_FREE);
  332. }
  333.  
  334. /* Save all variables describing the current status into the structure *P.
  335.    This is used before starting a nested function.
  336.  
  337.    CONTEXT is the decl_function_context for the function we're about to
  338.    compile; if it isn't current_function_decl, we have to play some games.  */
  339.  
  340. void
  341. save_tree_status (p, context)
  342.      struct function *p;
  343.      tree context;
  344. {
  345.   p->all_types_permanent = all_types_permanent;
  346.   p->momentary_stack = momentary_stack;
  347.   p->maybepermanent_firstobj = maybepermanent_firstobj;
  348.   p->momentary_firstobj = momentary_firstobj;
  349.   p->momentary_function_firstobj = momentary_function_firstobj;
  350.   p->function_obstack = function_obstack;
  351.   p->function_maybepermanent_obstack = function_maybepermanent_obstack;
  352.   p->current_obstack = current_obstack;
  353.   p->expression_obstack = expression_obstack;
  354.   p->saveable_obstack = saveable_obstack;
  355.   p->rtl_obstack = rtl_obstack;
  356.   p->inline_obstacks = inline_obstacks;
  357.  
  358.   if (context == current_function_decl)
  359.     /* Objects that need to be saved in this function can be in the nonsaved
  360.        obstack of the enclosing function since they can't possibly be needed
  361.        once it has returned.  */
  362.     function_maybepermanent_obstack = function_obstack;
  363.   else
  364.     {
  365.       /* We're compiling a function which isn't nested in the current
  366.          function.  We need to create a new maybepermanent_obstack for this
  367.          function, since it can't go onto any of the existing obstacks.  */
  368.       struct simple_obstack_stack **head;
  369.       struct simple_obstack_stack *current;
  370.  
  371.       if (context == NULL_TREE)
  372.     head = &toplev_inline_obstacks;
  373.       else
  374.     {
  375.       struct function *f = find_function_data (context);
  376.       head = &f->inline_obstacks;
  377.     }
  378.  
  379.       current = ((struct simple_obstack_stack *)
  380.          xmalloc (sizeof (struct simple_obstack_stack)));
  381.  
  382.       current->obstack = (struct obstack *) xmalloc (sizeof (struct obstack));
  383.       function_maybepermanent_obstack = current->obstack;
  384.       gcc_obstack_init (function_maybepermanent_obstack);
  385.  
  386.       current->next = *head;
  387.       *head = current;
  388.     }      
  389.  
  390.   maybepermanent_firstobj
  391.     = (char *) obstack_finish (function_maybepermanent_obstack);
  392.  
  393.   function_obstack = (struct obstack *) xmalloc (sizeof (struct obstack));
  394.   gcc_obstack_init (function_obstack);
  395.  
  396.   current_obstack = &permanent_obstack;
  397.   expression_obstack = &permanent_obstack;
  398.   rtl_obstack = saveable_obstack = &permanent_obstack;
  399.  
  400.   momentary_firstobj = (char *) obstack_finish (&momentary_obstack);
  401.   momentary_function_firstobj = momentary_firstobj;
  402. }
  403.  
  404. /* Restore all variables describing the current status from the structure *P.
  405.    This is used after a nested function.  */
  406.  
  407. void
  408. restore_tree_status (p)
  409.      struct function *p;
  410. {
  411.   all_types_permanent = p->all_types_permanent;
  412.   momentary_stack = p->momentary_stack;
  413.  
  414.   obstack_free (&momentary_obstack, momentary_function_firstobj);
  415.  
  416.   /* Free saveable storage used by the function just compiled and not
  417.      saved.
  418.  
  419.      CAUTION: This is in function_obstack of the containing function.
  420.      So we must be sure that we never allocate from that obstack during
  421.      the compilation of a nested function if we expect it to survive
  422.      past the nested function's end.  */
  423.   obstack_free (function_maybepermanent_obstack, maybepermanent_firstobj);
  424.  
  425.   obstack_free (function_obstack, 0);
  426.   free (function_obstack);
  427.  
  428.   momentary_firstobj = p->momentary_firstobj;
  429.   momentary_function_firstobj = p->momentary_function_firstobj;
  430.   maybepermanent_firstobj = p->maybepermanent_firstobj;
  431.   function_obstack = p->function_obstack;
  432.   function_maybepermanent_obstack = p->function_maybepermanent_obstack;
  433.   current_obstack = p->current_obstack;
  434.   expression_obstack = p->expression_obstack;
  435.   saveable_obstack = p->saveable_obstack;
  436.   rtl_obstack = p->rtl_obstack;
  437.   inline_obstacks = p->inline_obstacks;
  438. }
  439.  
  440. /* Start allocating on the temporary (per function) obstack.
  441.    This is done in start_function before parsing the function body,
  442.    and before each initialization at top level, and to go back
  443.    to temporary allocation after doing permanent_allocation.  */
  444.  
  445. void
  446. temporary_allocation ()
  447. {
  448.   /* Note that function_obstack at top level points to temporary_obstack.
  449.      But within a nested function context, it is a separate obstack.  */
  450.   current_obstack = function_obstack;
  451.   expression_obstack = function_obstack;
  452.   rtl_obstack = saveable_obstack = function_maybepermanent_obstack;
  453.   momentary_stack = 0;
  454.   inline_obstacks = 0;
  455. }
  456.  
  457. /* Start allocating on the permanent obstack but don't
  458.    free the temporary data.  After calling this, call
  459.    `permanent_allocation' to fully resume permanent allocation status.  */
  460.  
  461. void
  462. end_temporary_allocation ()
  463. {
  464.   current_obstack = &permanent_obstack;
  465.   expression_obstack = &permanent_obstack;
  466.   rtl_obstack = saveable_obstack = &permanent_obstack;
  467. }
  468.  
  469. /* Resume allocating on the temporary obstack, undoing
  470.    effects of `end_temporary_allocation'.  */
  471.  
  472. void
  473. resume_temporary_allocation ()
  474. {
  475.   current_obstack = function_obstack;
  476.   expression_obstack = function_obstack;
  477.   rtl_obstack = saveable_obstack = function_maybepermanent_obstack;
  478. }
  479.  
  480. /* While doing temporary allocation, switch to allocating in such a
  481.    way as to save all nodes if the function is inlined.  Call
  482.    resume_temporary_allocation to go back to ordinary temporary
  483.    allocation.  */
  484.  
  485. void
  486. saveable_allocation ()
  487. {
  488.   /* Note that function_obstack at top level points to temporary_obstack.
  489.      But within a nested function context, it is a separate obstack.  */
  490.   expression_obstack = current_obstack = saveable_obstack;
  491. }
  492.  
  493. /* Switch to current obstack CURRENT and maybepermanent obstack SAVEABLE,
  494.    recording the previously current obstacks on a stack.
  495.    This does not free any storage in any obstack.  */
  496.  
  497. void
  498. push_obstacks (current, saveable)
  499.      struct obstack *current, *saveable;
  500. {
  501.   struct obstack_stack *p
  502.     = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,
  503.                           (sizeof (struct obstack_stack)));
  504.  
  505.   p->current = current_obstack;
  506.   p->saveable = saveable_obstack;
  507.   p->expression = expression_obstack;
  508.   p->rtl = rtl_obstack;
  509.   p->next = obstack_stack;
  510.   obstack_stack = p;
  511.  
  512.   current_obstack = current;
  513.   expression_obstack = current;
  514.   rtl_obstack = saveable_obstack = saveable;
  515. }
  516.  
  517. /* Save the current set of obstacks, but don't change them.  */
  518.  
  519. void
  520. push_obstacks_nochange ()
  521. {
  522.   struct obstack_stack *p
  523.     = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,
  524.                           (sizeof (struct obstack_stack)));
  525.  
  526.   p->current = current_obstack;
  527.   p->saveable = saveable_obstack;
  528.   p->expression = expression_obstack;
  529.   p->rtl = rtl_obstack;
  530.   p->next = obstack_stack;
  531.   obstack_stack = p;
  532. }
  533.  
  534. /* Pop the obstack selection stack.  */
  535.  
  536. void
  537. pop_obstacks ()
  538. {
  539.   struct obstack_stack *p = obstack_stack;
  540.   obstack_stack = p->next;
  541.  
  542.   current_obstack = p->current;
  543.   saveable_obstack = p->saveable;
  544.   expression_obstack = p->expression;
  545.   rtl_obstack = p->rtl;
  546.  
  547.   obstack_free (&obstack_stack_obstack, p);
  548. }
  549.  
  550. /* Nonzero if temporary allocation is currently in effect.
  551.    Zero if currently doing permanent allocation.  */
  552.  
  553. int
  554. allocation_temporary_p ()
  555. {
  556.   return current_obstack != &permanent_obstack;
  557. }
  558.  
  559. /* Go back to allocating on the permanent obstack
  560.    and free everything in the temporary obstack.
  561.  
  562.    FUNCTION_END is true only if we have just finished compiling a function.
  563.    In that case, we also free preserved initial values on the momentary
  564.    obstack.  */
  565.  
  566. void
  567. permanent_allocation (function_end)
  568.      int function_end;
  569. {
  570.   /* Free up previous temporary obstack data */
  571.   obstack_free (&temporary_obstack, temporary_firstobj);
  572.   if (function_end)
  573.     {
  574.       obstack_free (&momentary_obstack, momentary_function_firstobj);
  575.       momentary_firstobj = momentary_function_firstobj;
  576.     }
  577.   else
  578.     obstack_free (&momentary_obstack, momentary_firstobj);
  579.   obstack_free (function_maybepermanent_obstack, maybepermanent_firstobj);
  580.   obstack_free (&temp_decl_obstack, temp_decl_firstobj);
  581.  
  582.   /* Free up the maybepermanent_obstacks for any of our nested functions
  583.      which were compiled at a lower level.  */
  584.   while (inline_obstacks)
  585.     {
  586.       struct simple_obstack_stack *current = inline_obstacks;
  587.       inline_obstacks = current->next;
  588.       obstack_free (current->obstack, 0);
  589.       free (current->obstack);
  590.       free (current);
  591.     }
  592.  
  593.   current_obstack = &permanent_obstack;
  594.   expression_obstack = &permanent_obstack;
  595.   rtl_obstack = saveable_obstack = &permanent_obstack;
  596. #ifdef NEXT_SEMANTICS
  597.   reg_renumber = 0;
  598. #endif
  599. }
  600.  
  601. /* Save permanently everything on the maybepermanent_obstack.  */
  602.  
  603. void
  604. preserve_data ()
  605. {
  606.   maybepermanent_firstobj
  607.     = (char *) obstack_alloc (function_maybepermanent_obstack, 0);
  608. }
  609.  
  610. void
  611. preserve_initializer ()
  612. {
  613.   struct momentary_level *tem;
  614.   char *old_momentary;
  615.  
  616.   temporary_firstobj
  617.     = (char *) obstack_alloc (&temporary_obstack, 0);
  618.   maybepermanent_firstobj
  619.     = (char *) obstack_alloc (function_maybepermanent_obstack, 0);
  620.  
  621.   old_momentary = momentary_firstobj;
  622.   momentary_firstobj
  623.     = (char *) obstack_alloc (&momentary_obstack, 0);
  624.   if (momentary_firstobj != old_momentary)
  625.     for (tem = momentary_stack; tem; tem = tem->prev)
  626.       tem->base = momentary_firstobj;
  627. }
  628.  
  629. /* Start allocating new rtl in current_obstack.
  630.    Use resume_temporary_allocation
  631.    to go back to allocating rtl in saveable_obstack.  */
  632.  
  633. void
  634. rtl_in_current_obstack ()
  635. {
  636.   rtl_obstack = current_obstack;
  637. }
  638.  
  639. /* Start allocating rtl from saveable_obstack.  Intended to be used after
  640.    a call to push_obstacks_nochange.  */
  641.  
  642. void
  643. rtl_in_saveable_obstack ()
  644. {
  645.   rtl_obstack = saveable_obstack;
  646. }
  647.  
  648. /* Allocate SIZE bytes in the current obstack
  649.    and return a pointer to them.
  650.    In practice the current obstack is always the temporary one.  */
  651.  
  652. char *
  653. oballoc (size)
  654.      int size;
  655. {
  656.   return (char *) obstack_alloc (current_obstack, size);
  657. }
  658.  
  659. /* Free the object PTR in the current obstack
  660.    as well as everything allocated since PTR.
  661.    In practice the current obstack is always the temporary one.  */
  662.  
  663. void
  664. obfree (ptr)
  665.      char *ptr;
  666. {
  667.   obstack_free (current_obstack, ptr);
  668. }
  669.  
  670. /* Allocate SIZE bytes in the permanent obstack
  671.    and return a pointer to them.  */
  672.  
  673. char *
  674. permalloc (size)
  675.      int size;
  676. {
  677.   return (char *) obstack_alloc (&permanent_obstack, size);
  678. }
  679.  
  680. /* Allocate NELEM items of SIZE bytes in the permanent obstack
  681.    and return a pointer to them.  The storage is cleared before
  682.    returning the value.  */
  683.  
  684. char *
  685. perm_calloc (nelem, size)
  686.      int nelem;
  687.      long size;
  688. {
  689.   char *rval = (char *) obstack_alloc (&permanent_obstack, nelem * size);
  690.   bzero (rval, nelem * size);
  691.   return rval;
  692. }
  693.  
  694. /* Allocate SIZE bytes in the saveable obstack
  695.    and return a pointer to them.  */
  696.  
  697. char *
  698. savealloc (size)
  699.      int size;
  700. {
  701.   return (char *) obstack_alloc (saveable_obstack, size);
  702. }
  703.  
  704. /* Print out which obstack an object is in.  */
  705.  
  706. void
  707. print_obstack_name (object, file, prefix)
  708.      char *object;
  709.      FILE *file;
  710.      char *prefix;
  711. {
  712.   struct obstack *obstack = NULL;
  713.   char *obstack_name = NULL;
  714.   struct function *p;
  715.  
  716.   for (p = outer_function_chain; p; p = p->next)
  717.     {
  718.       if (_obstack_allocated_p (p->function_obstack, object))
  719.     {
  720.       obstack = p->function_obstack;
  721.       obstack_name = "containing function obstack";
  722.     }
  723.       if (_obstack_allocated_p (p->function_maybepermanent_obstack, object))
  724.     {
  725.       obstack = p->function_maybepermanent_obstack;
  726.       obstack_name = "containing function maybepermanent obstack";
  727.     }
  728.     }
  729.  
  730.   if (_obstack_allocated_p (&obstack_stack_obstack, object))
  731.     {
  732.       obstack = &obstack_stack_obstack;
  733.       obstack_name = "obstack_stack_obstack";
  734.     }
  735.   else if (_obstack_allocated_p (function_obstack, object))
  736.     {
  737.       obstack = function_obstack;
  738.       obstack_name = "function obstack";
  739.     }
  740.   else if (_obstack_allocated_p (&permanent_obstack, object))
  741.     {
  742.       obstack = &permanent_obstack;
  743.       obstack_name = "permanent_obstack";
  744.     }
  745.   else if (_obstack_allocated_p (&momentary_obstack, object))
  746.     {
  747.       obstack = &momentary_obstack;
  748.       obstack_name = "momentary_obstack";
  749.     }
  750.   else if (_obstack_allocated_p (function_maybepermanent_obstack, object))
  751.     {
  752.       obstack = function_maybepermanent_obstack;
  753.       obstack_name = "function maybepermanent obstack";
  754.     }
  755.   else if (_obstack_allocated_p (&temp_decl_obstack, object))
  756.     {
  757.       obstack = &temp_decl_obstack;
  758.       obstack_name = "temp_decl_obstack";
  759.     }
  760.  
  761.   /* Check to see if the object is in the free area of the obstack. */
  762.   if (obstack != NULL)
  763.     {
  764.       if (object >= obstack->next_free
  765.       && object < obstack->chunk_limit)
  766.     fprintf (file, "%s in free portion of obstack %s",
  767.          prefix, obstack_name);
  768.       else
  769.     fprintf (file, "%s allocated from %s", prefix, obstack_name);
  770.     }
  771.   else
  772.     fprintf (file, "%s not allocated from any obstack", prefix);
  773. }
  774.  
  775. void
  776. debug_obstack (object)
  777.      char *object;
  778. {
  779.   print_obstack_name (object, stderr, "object");
  780.   fprintf (stderr, ".\n");
  781. }
  782.  
  783. /* Return 1 if OBJ is in the permanent obstack.
  784.    This is slow, and should be used only for debugging.
  785.    Use TREE_PERMANENT for other purposes.  */
  786.  
  787. int
  788. object_permanent_p (obj)
  789.      tree obj;
  790. {
  791.   return _obstack_allocated_p (&permanent_obstack, obj);
  792. }
  793.  
  794. /* Start a level of momentary allocation.
  795.    In C, each compound statement has its own level
  796.    and that level is freed at the end of each statement.
  797.    All expression nodes are allocated in the momentary allocation level.  */
  798.  
  799. void
  800. push_momentary ()
  801. {
  802.   struct momentary_level *tem
  803.     = (struct momentary_level *) obstack_alloc (&momentary_obstack,
  804.                         sizeof (struct momentary_level));
  805.   tem->prev = momentary_stack;
  806.   tem->base = (char *) obstack_base (&momentary_obstack);
  807.   tem->obstack = expression_obstack;
  808.   momentary_stack = tem;
  809.   expression_obstack = &momentary_obstack;
  810. }
  811.  
  812. /* Set things up so the next clear_momentary will only clear memory
  813.    past our present position in momentary_obstack.  */
  814.  
  815. void
  816. preserve_momentary ()
  817. {
  818.   momentary_stack->base = (char *) obstack_base (&momentary_obstack);
  819. }
  820.  
  821. /* Free all the storage in the current momentary-allocation level.
  822.    In C, this happens at the end of each statement.  */
  823.  
  824. void
  825. clear_momentary ()
  826. {
  827.   obstack_free (&momentary_obstack, momentary_stack->base);
  828. }
  829.  
  830. /* Discard a level of momentary allocation.
  831.    In C, this happens at the end of each compound statement.
  832.    Restore the status of expression node allocation
  833.    that was in effect before this level was created.  */
  834.  
  835. void
  836. pop_momentary ()
  837. {
  838.   struct momentary_level *tem = momentary_stack;
  839.   momentary_stack = tem->prev;
  840.   expression_obstack = tem->obstack;
  841.   /* We can't free TEM from the momentary_obstack, because there might
  842.      be objects above it which have been saved.  We can free back to the
  843.      stack of the level we are popping off though.  */
  844.   obstack_free (&momentary_obstack, tem->base);
  845. }
  846.  
  847. /* Pop back to the previous level of momentary allocation,
  848.    but don't free any momentary data just yet.  */
  849.  
  850. void
  851. pop_momentary_nofree ()
  852. {
  853.   struct momentary_level *tem = momentary_stack;
  854.   momentary_stack = tem->prev;
  855.   expression_obstack = tem->obstack;
  856. }
  857.  
  858. /* Call when starting to parse a declaration:
  859.    make expressions in the declaration last the length of the function.
  860.    Returns an argument that should be passed to resume_momentary later.  */
  861.  
  862. int
  863. suspend_momentary ()
  864. {
  865.   register int tem = expression_obstack == &momentary_obstack;
  866.   expression_obstack = saveable_obstack;
  867.   return tem;
  868. }
  869.  
  870. /* Call when finished parsing a declaration:
  871.    restore the treatment of node-allocation that was
  872.    in effect before the suspension.
  873.    YES should be the value previously returned by suspend_momentary.  */
  874.  
  875. void
  876. resume_momentary (yes)
  877.      int yes;
  878. {
  879.   if (yes)
  880.     expression_obstack = &momentary_obstack;
  881. }
  882.  
  883. /* Init the tables indexed by tree code.
  884.    Note that languages can add to these tables to define their own codes.  */
  885.  
  886. void
  887. init_tree_codes ()
  888. {
  889.   tree_code_type = (char **) xmalloc (sizeof (standard_tree_code_type));
  890.   tree_code_length = (int *) xmalloc (sizeof (standard_tree_code_length));
  891.   tree_code_name = (char **) xmalloc (sizeof (standard_tree_code_name));
  892.   bcopy ((char *) standard_tree_code_type, (char *) tree_code_type,
  893.      sizeof (standard_tree_code_type));
  894.   bcopy ((char *) standard_tree_code_length, (char *) tree_code_length,
  895.      sizeof (standard_tree_code_length));
  896.   bcopy ((char *) standard_tree_code_name, (char *) tree_code_name,
  897.      sizeof (standard_tree_code_name));
  898. }
  899.  
  900. /* Return a newly allocated node of code CODE.
  901.    Initialize the node's unique id and its TREE_PERMANENT flag.
  902.    For decl and type nodes, some other fields are initialized.
  903.    The rest of the node is initialized to zero.
  904.  
  905.    Achoo!  I got a code in the node.  */
  906.  
  907. tree
  908. make_node (code)
  909.      enum tree_code code;
  910. {
  911.   register tree t;
  912.   register int type = TREE_CODE_CLASS (code);
  913.   register int length;
  914.   register struct obstack *obstack = current_obstack;
  915.   register int i;
  916.   register tree_node_kind kind;
  917.  
  918.   switch (type)
  919.     {
  920.     case 'd':  /* A decl node */
  921. #ifdef GATHER_STATISTICS
  922.       kind = d_kind;
  923. #endif
  924.       length = sizeof (struct tree_decl);
  925.       /* All decls in an inline function need to be saved.  */
  926.       if (obstack != &permanent_obstack)
  927.     obstack = saveable_obstack;
  928.  
  929.       /* PARM_DECLs go on the context of the parent. If this is a nested
  930.      function, then we must allocate the PARM_DECL on the parent's
  931.      obstack, so that they will live to the end of the parent's
  932.      closing brace.  This is necessary in case we try to inline the
  933.      function into its parent.
  934.  
  935.      PARM_DECLs of top-level functions do not have this problem.  However,
  936.      we allocate them where we put the FUNCTION_DECL for languages such as
  937.      Ada that need to consult some flags in the PARM_DECLs of the function
  938.      when calling it. 
  939.  
  940.      See comment in restore_tree_status for why we can't put this
  941.      in function_obstack.  */
  942.       if (code == PARM_DECL && obstack != &permanent_obstack)
  943.     {
  944.       tree context = 0;
  945.       if (current_function_decl)
  946.         context = decl_function_context (current_function_decl);
  947.  
  948.       if (context)
  949.         obstack
  950.           = find_function_data (context)->function_maybepermanent_obstack;
  951.     }
  952.       break;
  953.  
  954.     case 't':  /* a type node */
  955. #ifdef GATHER_STATISTICS
  956.       kind = t_kind;
  957. #endif
  958.       length = sizeof (struct tree_type);
  959.       /* All data types are put where we can preserve them if nec.  */
  960.       if (obstack != &permanent_obstack)
  961.     obstack = all_types_permanent ? &permanent_obstack : saveable_obstack;
  962.       break;
  963.  
  964.     case 'b':  /* a lexical block */
  965. #ifdef GATHER_STATISTICS
  966.       kind = b_kind;
  967. #endif
  968.       length = sizeof (struct tree_block);
  969.       /* All BLOCK nodes are put where we can preserve them if nec.  */
  970.       if (obstack != &permanent_obstack)
  971.     obstack = saveable_obstack;
  972.       break;
  973.  
  974.     case 's':  /* an expression with side effects */
  975. #ifdef GATHER_STATISTICS
  976.       kind = s_kind;
  977.       goto usual_kind;
  978. #endif
  979.     case 'r':  /* a reference */
  980. #ifdef GATHER_STATISTICS
  981.       kind = r_kind;
  982.       goto usual_kind;
  983. #endif
  984.     case 'e':  /* an expression */
  985.     case '<':  /* a comparison expression */
  986.     case '1':  /* a unary arithmetic expression */
  987.     case '2':  /* a binary arithmetic expression */
  988. #ifdef GATHER_STATISTICS
  989.       kind = e_kind;
  990.     usual_kind:
  991. #endif
  992.       obstack = expression_obstack;
  993.       /* All BIND_EXPR nodes are put where we can preserve them if nec.  */
  994.       if (code == BIND_EXPR && obstack != &permanent_obstack)
  995.     obstack = saveable_obstack;
  996.       length = sizeof (struct tree_exp)
  997.     + (tree_code_length[(int) code] - 1) * sizeof (char *);
  998.       break;
  999.  
  1000.     case 'c':  /* a constant */
  1001. #ifdef GATHER_STATISTICS
  1002.       kind = c_kind;
  1003. #endif
  1004.       obstack = expression_obstack;
  1005.  
  1006.       /* We can't use tree_code_length for INTEGER_CST, since the number of
  1007.      words is machine-dependent due to varying length of HOST_WIDE_INT,
  1008.      which might be wider than a pointer (e.g., long long).  Similarly
  1009.      for REAL_CST, since the number of words is machine-dependent due
  1010.      to varying size and alignment of `double'.  */
  1011.  
  1012.       if (code == INTEGER_CST)
  1013.     length = sizeof (struct tree_int_cst);
  1014.       else if (code == REAL_CST)
  1015.     length = sizeof (struct tree_real_cst);
  1016.       else
  1017.     length = sizeof (struct tree_common)
  1018.       + tree_code_length[(int) code] * sizeof (char *);
  1019.       break;
  1020.  
  1021.     case 'x':  /* something random, like an identifier.  */
  1022. #ifdef GATHER_STATISTICS
  1023.       if (code == IDENTIFIER_NODE)
  1024.     kind = id_kind;
  1025.       else if (code == OP_IDENTIFIER)
  1026.     kind = op_id_kind;
  1027.       else if (code == TREE_VEC)
  1028.     kind = vec_kind;
  1029.       else
  1030.     kind = x_kind;
  1031. #endif
  1032.       length = sizeof (struct tree_common)
  1033.     + tree_code_length[(int) code] * sizeof (char *);
  1034.       /* Identifier nodes are always permanent since they are
  1035.      unique in a compiler run.  */
  1036.       if (code == IDENTIFIER_NODE) obstack = &permanent_obstack;
  1037.       break;
  1038.  
  1039.     default:
  1040.       abort ();
  1041.     }
  1042.  
  1043.   t = (tree) obstack_alloc (obstack, length);
  1044.  
  1045. #ifdef GATHER_STATISTICS
  1046.   tree_node_counts[(int)kind]++;
  1047.   tree_node_sizes[(int)kind] += length;
  1048. #endif
  1049.  
  1050.   /* Clear a word at a time.  */
  1051.   for (i = (length / sizeof (int)) - 1; i >= 0; i--)
  1052.     ((int *) t)[i] = 0;
  1053.   /* Clear any extra bytes.  */
  1054.   for (i = length / sizeof (int) * sizeof (int); i < length; i++)
  1055.     ((char *) t)[i] = 0;
  1056.  
  1057.   TREE_SET_CODE (t, code);
  1058.   if (obstack == &permanent_obstack)
  1059.     TREE_PERMANENT (t) = 1;
  1060.  
  1061.   switch (type)
  1062.     {
  1063.     case 's':
  1064.       TREE_SIDE_EFFECTS (t) = 1;
  1065.       TREE_TYPE (t) = void_type_node;
  1066.       break;
  1067.  
  1068.     case 'd':
  1069.       if (code != FUNCTION_DECL)
  1070.     DECL_ALIGN (t) = 1;
  1071.       DECL_IN_SYSTEM_HEADER (t)
  1072.     = in_system_header && (obstack == &permanent_obstack);
  1073.       DECL_SOURCE_LINE (t) = lineno;
  1074.       DECL_SOURCE_FILE (t) = (input_filename) ? input_filename : "<built-in>";
  1075.       DECL_UID (t) = next_decl_uid++;
  1076.       break;
  1077.  
  1078.     case 't':
  1079.       TYPE_UID (t) = next_type_uid++;
  1080.       TYPE_ALIGN (t) = 1;
  1081.       TYPE_MAIN_VARIANT (t) = t;
  1082.       TYPE_OBSTACK (t) = obstack;
  1083.       TYPE_ATTRIBUTES (t) = NULL_TREE;
  1084. #ifdef SET_DEFAULT_TYPE_ATTRIBUTES
  1085.       SET_DEFAULT_TYPE_ATTRIBUTES (t);
  1086. #endif
  1087.       break;
  1088.  
  1089.     case 'c':
  1090.       TREE_CONSTANT (t) = 1;
  1091.       break;
  1092.     }
  1093.  
  1094.   return t;
  1095. }
  1096.  
  1097. /* Return a new node with the same contents as NODE
  1098.    except that its TREE_CHAIN is zero and it has a fresh uid.  */
  1099.  
  1100. tree
  1101. copy_node (node)
  1102.      tree node;
  1103. {
  1104.   register tree t;
  1105.   register enum tree_code code = TREE_CODE (node);
  1106.   register int length;
  1107.   register int i;
  1108.  
  1109.   switch (TREE_CODE_CLASS (code))
  1110.     {
  1111.     case 'd':  /* A decl node */
  1112.       length = sizeof (struct tree_decl);
  1113.       break;
  1114.  
  1115.     case 't':  /* a type node */
  1116.       length = sizeof (struct tree_type);
  1117.       break;
  1118.  
  1119.     case 'b':  /* a lexical block node */
  1120.       length = sizeof (struct tree_block);
  1121.       break;
  1122.  
  1123.     case 'r':  /* a reference */
  1124.     case 'e':  /* an expression */
  1125.     case 's':  /* an expression with side effects */
  1126.     case '<':  /* a comparison expression */
  1127.     case '1':  /* a unary arithmetic expression */
  1128.     case '2':  /* a binary arithmetic expression */
  1129.       length = sizeof (struct tree_exp)
  1130.     + (tree_code_length[(int) code] - 1) * sizeof (char *);
  1131.       break;
  1132.  
  1133.     case 'c':  /* a constant */
  1134.       /* We can't use tree_code_length for INTEGER_CST, since the number of
  1135.      words is machine-dependent due to varying length of HOST_WIDE_INT,
  1136.      which might be wider than a pointer (e.g., long long).  Similarly
  1137.      for REAL_CST, since the number of words is machine-dependent due
  1138.      to varying size and alignment of `double'.  */
  1139.       if (code == INTEGER_CST)
  1140.         {
  1141.           length = sizeof (struct tree_int_cst);
  1142.           break;
  1143.         }
  1144.       else if (code == REAL_CST)
  1145.     {
  1146.       length = sizeof (struct tree_real_cst);
  1147.       break;
  1148.     }
  1149.  
  1150.     case 'x':  /* something random, like an identifier.  */
  1151.       length = sizeof (struct tree_common)
  1152.     + tree_code_length[(int) code] * sizeof (char *);
  1153.       if (code == TREE_VEC)
  1154.     length += (TREE_VEC_LENGTH (node) - 1) * sizeof (char *);
  1155.     }
  1156.  
  1157.   t = (tree) obstack_alloc (current_obstack, length);
  1158.  
  1159.   for (i = (length / sizeof (int)) - 1; i >= 0; i--)
  1160.     ((int *) t)[i] = ((int *) node)[i];
  1161.   /* Clear any extra bytes.  */
  1162.   for (i = length / sizeof (int) * sizeof (int); i < length; i++)
  1163.     ((char *) t)[i] = ((char *) node)[i];
  1164.  
  1165.   TREE_CHAIN (t) = 0;
  1166.  
  1167.   if (TREE_CODE_CLASS (code) == 'd')
  1168.     DECL_UID (t) = next_decl_uid++;
  1169.   else if (TREE_CODE_CLASS (code) == 't')
  1170.     {
  1171.       TYPE_UID (t) = next_type_uid++;
  1172.       TYPE_OBSTACK (t) = current_obstack;
  1173.     }
  1174.  
  1175.   TREE_PERMANENT (t) = (current_obstack == &permanent_obstack);
  1176.  
  1177.   return t;
  1178. }
  1179.  
  1180. /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
  1181.    For example, this can copy a list made of TREE_LIST nodes.  */
  1182.  
  1183. tree
  1184. copy_list (list)
  1185.      tree list;
  1186. {
  1187.   tree head;
  1188.   register tree prev, next;
  1189.  
  1190.   if (list == 0)
  1191.     return 0;
  1192.  
  1193.   head = prev = copy_node (list);
  1194.   next = TREE_CHAIN (list);
  1195.   while (next)
  1196.     {
  1197.       TREE_CHAIN (prev) = copy_node (next);
  1198.       prev = TREE_CHAIN (prev);
  1199.       next = TREE_CHAIN (next);
  1200.     }
  1201.   return head;
  1202. }
  1203.  
  1204. #define HASHBITS 30
  1205.  
  1206. /* Return an IDENTIFIER_NODE whose name is TEXT (a null-terminated string).
  1207.    If an identifier with that name has previously been referred to,
  1208.    the same node is returned this time.  */
  1209.  
  1210. tree
  1211. get_identifier (text)
  1212.      register char *text;
  1213. {
  1214.   register int hi;
  1215.   register int i;
  1216.   register tree idp;
  1217.   register int len, hash_len;
  1218.  
  1219.   /* Compute length of text in len.  */
  1220.   for (len = 0; text[len]; len++);
  1221.  
  1222.   /* Decide how much of that length to hash on */
  1223.   hash_len = len;
  1224.   if (warn_id_clash && len > id_clash_len)
  1225.     hash_len = id_clash_len;
  1226.  
  1227.   /* Compute hash code */
  1228.   hi = hash_len * 613 + (unsigned)text[0];
  1229.   for (i = 1; i < hash_len; i += 2)
  1230.     hi = ((hi * 613) + (unsigned)(text[i]));
  1231.  
  1232.   hi &= (1 << HASHBITS) - 1;
  1233.   hi %= MAX_HASH_TABLE;
  1234.   
  1235.   /* Search table for identifier */
  1236.   for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
  1237.     if (IDENTIFIER_LENGTH (idp) == len
  1238.     && IDENTIFIER_POINTER (idp)[0] == text[0]
  1239.     && !bcmp (IDENTIFIER_POINTER (idp), text, len))
  1240.       return idp;        /* <-- return if found */
  1241.  
  1242.   /* Not found; optionally warn about a similar identifier */
  1243.   if (warn_id_clash && do_identifier_warnings && len >= id_clash_len)
  1244.     for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
  1245.       if (!strncmp (IDENTIFIER_POINTER (idp), text, id_clash_len))
  1246.     {
  1247.       warning ("`%s' and `%s' identical in first %d characters",
  1248.            IDENTIFIER_POINTER (idp), text, id_clash_len);
  1249.       break;
  1250.     }
  1251.  
  1252.   if (tree_code_length[(int) IDENTIFIER_NODE] < 0)
  1253.     abort ();            /* set_identifier_size hasn't been called.  */
  1254.  
  1255.   /* Not found, create one, add to chain */
  1256.   idp = make_node (IDENTIFIER_NODE);
  1257.   IDENTIFIER_LENGTH (idp) = len;
  1258. #ifdef GATHER_STATISTICS
  1259.   id_string_size += len;
  1260. #endif
  1261.  
  1262.   IDENTIFIER_POINTER (idp) = obstack_copy0 (&permanent_obstack, text, len);
  1263.  
  1264.   TREE_CHAIN (idp) = hash_table[hi];
  1265.   hash_table[hi] = idp;
  1266.   return idp;            /* <-- return if created */
  1267. }
  1268.  
  1269. /* Enable warnings on similar identifiers (if requested).
  1270.    Done after the built-in identifiers are created.  */
  1271.  
  1272. void
  1273. start_identifier_warnings ()
  1274. {
  1275.   do_identifier_warnings = 1;
  1276. }
  1277.  
  1278. /* Record the size of an identifier node for the language in use.
  1279.    SIZE is the total size in bytes.
  1280.    This is called by the language-specific files.  This must be
  1281.    called before allocating any identifiers.  */
  1282.  
  1283. void
  1284. set_identifier_size (size)
  1285.      int size;
  1286. {
  1287.   tree_code_length[(int) IDENTIFIER_NODE]
  1288.     = (size - sizeof (struct tree_common)) / sizeof (tree);
  1289. }
  1290.  
  1291. /* Return a newly constructed INTEGER_CST node whose constant value
  1292.    is specified by the two ints LOW and HI.
  1293.    The TREE_TYPE is set to `int'. 
  1294.  
  1295.    This function should be used via the `build_int_2' macro.  */
  1296.  
  1297. tree
  1298. build_int_2_wide (low, hi)
  1299.      HOST_WIDE_INT low, hi;
  1300. {
  1301.   register tree t = make_node (INTEGER_CST);
  1302.   TREE_INT_CST_LOW (t) = low;
  1303.   TREE_INT_CST_HIGH (t) = hi;
  1304.   TREE_TYPE (t) = integer_type_node;
  1305.   return t;
  1306. }
  1307.  
  1308. /* Return a new REAL_CST node whose type is TYPE and value is D.  */
  1309.  
  1310. tree
  1311. build_real (type, d)
  1312.      tree type;
  1313.      REAL_VALUE_TYPE d;
  1314. {
  1315.   tree v;
  1316.   int overflow = 0;
  1317.  
  1318.   /* Check for valid float value for this type on this target machine;
  1319.      if not, can print error message and store a valid value in D.  */
  1320. #ifdef CHECK_FLOAT_VALUE
  1321.   CHECK_FLOAT_VALUE (TYPE_MODE (type), d, overflow);
  1322. #endif
  1323.  
  1324.   v = make_node (REAL_CST);
  1325.   TREE_TYPE (v) = type;
  1326.   TREE_REAL_CST (v) = d;
  1327.   TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow;
  1328.   return v;
  1329. }
  1330.  
  1331. /* Return a new REAL_CST node whose type is TYPE
  1332.    and whose value is the integer value of the INTEGER_CST node I.  */
  1333.  
  1334. #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
  1335.  
  1336. REAL_VALUE_TYPE
  1337. real_value_from_int_cst (i)
  1338.      tree i;
  1339. {
  1340.   REAL_VALUE_TYPE d;
  1341.   REAL_VALUE_TYPE e;
  1342.   /* Some 386 compilers mishandle unsigned int to float conversions,
  1343.      so introduce a temporary variable E to avoid those bugs.  */
  1344.  
  1345. #ifdef REAL_ARITHMETIC
  1346.   if (! TREE_UNSIGNED (TREE_TYPE (i)))
  1347.     REAL_VALUE_FROM_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i));
  1348.   else
  1349.     REAL_VALUE_FROM_UNSIGNED_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i));
  1350. #else /* not REAL_ARITHMETIC */
  1351.   if (TREE_INT_CST_HIGH (i) < 0 && ! TREE_UNSIGNED (TREE_TYPE (i)))
  1352.     {
  1353.       d = (double) (~ TREE_INT_CST_HIGH (i));
  1354.       e = ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
  1355.         * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
  1356.       d *= e;
  1357.       e = (double) (unsigned HOST_WIDE_INT) (~ TREE_INT_CST_LOW (i));
  1358.       d += e;
  1359.       d = (- d - 1.0);
  1360.     }
  1361.   else
  1362.     {
  1363.       d = (double) (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (i);
  1364.       e = ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
  1365.         * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
  1366.       d *= e;
  1367.       e = (double) (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (i);
  1368.       d += e;
  1369.     }
  1370. #endif /* not REAL_ARITHMETIC */
  1371.   return d;
  1372. }
  1373.  
  1374. /* This function can't be implemented if we can't do arithmetic
  1375.    on the float representation.  */
  1376.  
  1377. tree
  1378. build_real_from_int_cst (type, i)
  1379.      tree type;
  1380.      tree i;
  1381. {
  1382.   tree v;
  1383.   int overflow = TREE_OVERFLOW (i);
  1384.   REAL_VALUE_TYPE d;
  1385.   jmp_buf float_error;
  1386.  
  1387.   v = make_node (REAL_CST);
  1388.   TREE_TYPE (v) = type;
  1389.  
  1390.   if (setjmp (float_error))
  1391.     {
  1392.       d = dconst0;
  1393.       overflow = 1;
  1394.       goto got_it;
  1395.     }
  1396.  
  1397.   set_float_handler (float_error);
  1398.  
  1399.   d = REAL_VALUE_TRUNCATE (TYPE_MODE (type), real_value_from_int_cst (i));
  1400.  
  1401.   /* Check for valid float value for this type on this target machine.  */
  1402.  
  1403.  got_it:
  1404.   set_float_handler (NULL_PTR);
  1405.  
  1406. #ifdef CHECK_FLOAT_VALUE
  1407.   CHECK_FLOAT_VALUE (TYPE_MODE (type), d, overflow);
  1408. #endif
  1409.  
  1410.   TREE_REAL_CST (v) = d;
  1411.   TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow;
  1412.   return v;
  1413. }
  1414.  
  1415. #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
  1416.  
  1417. /* Return a newly constructed STRING_CST node whose value is
  1418.    the LEN characters at STR.
  1419.    The TREE_TYPE is not initialized.  */
  1420.  
  1421. tree
  1422. build_string (len, str)
  1423.      int len;
  1424.      char *str;
  1425. {
  1426.   /* Put the string in saveable_obstack since it will be placed in the RTL
  1427.      for an "asm" statement and will also be kept around a while if
  1428.      deferring constant output in varasm.c.  */
  1429.  
  1430.   register tree s = make_node (STRING_CST);
  1431.   TREE_STRING_LENGTH (s) = len;
  1432.   TREE_STRING_POINTER (s) = obstack_copy0 (saveable_obstack, str, len);
  1433.   return s;
  1434. }
  1435.  
  1436. /* Return a newly constructed COMPLEX_CST node whose value is
  1437.    specified by the real and imaginary parts REAL and IMAG.
  1438.    Both REAL and IMAG should be constant nodes.
  1439.    The TREE_TYPE is not initialized.  */
  1440.  
  1441. tree
  1442. build_complex (real, imag)
  1443.      tree real, imag;
  1444. {
  1445.   register tree t = make_node (COMPLEX_CST);
  1446.  
  1447.   TREE_REALPART (t) = real;
  1448.   TREE_IMAGPART (t) = imag;
  1449.   TREE_TYPE (t) = build_complex_type (TREE_TYPE (real));
  1450.   TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
  1451.   TREE_CONSTANT_OVERFLOW (t)
  1452.     = TREE_CONSTANT_OVERFLOW (real) | TREE_CONSTANT_OVERFLOW (imag);
  1453.   return t;
  1454. }
  1455.  
  1456. /* Build a newly constructed TREE_VEC node of length LEN.  */
  1457. tree
  1458. make_tree_vec (len)
  1459.      int len;
  1460. {
  1461.   register tree t;
  1462.   register int length = (len-1) * sizeof (tree) + sizeof (struct tree_vec);
  1463.   register struct obstack *obstack = current_obstack;
  1464.   register int i;
  1465.  
  1466. #ifdef GATHER_STATISTICS
  1467.   tree_node_counts[(int)vec_kind]++;
  1468.   tree_node_sizes[(int)vec_kind] += length;
  1469. #endif
  1470.  
  1471.   t = (tree) obstack_alloc (obstack, length);
  1472.  
  1473.   for (i = (length / sizeof (int)) - 1; i >= 0; i--)
  1474.     ((int *) t)[i] = 0;
  1475.  
  1476.   TREE_SET_CODE (t, TREE_VEC);
  1477.   TREE_VEC_LENGTH (t) = len;
  1478.   if (obstack == &permanent_obstack)
  1479.     TREE_PERMANENT (t) = 1;
  1480.  
  1481.   return t;
  1482. }
  1483.  
  1484. /* Return 1 if EXPR is the integer constant zero or a complex constant
  1485.    of zero.  */
  1486.  
  1487. int
  1488. integer_zerop (expr)
  1489.      tree expr;
  1490. {
  1491.   STRIP_NOPS (expr);
  1492.  
  1493.   return ((TREE_CODE (expr) == INTEGER_CST
  1494.        && TREE_INT_CST_LOW (expr) == 0
  1495.        && TREE_INT_CST_HIGH (expr) == 0)
  1496.       || (TREE_CODE (expr) == COMPLEX_CST
  1497.           && integer_zerop (TREE_REALPART (expr))
  1498.           && integer_zerop (TREE_IMAGPART (expr))));
  1499. }
  1500.  
  1501. /* Return 1 if EXPR is the integer constant one or the corresponding
  1502.    complex constant.  */
  1503.  
  1504. int
  1505. integer_onep (expr)
  1506.      tree expr;
  1507. {
  1508.   STRIP_NOPS (expr);
  1509.  
  1510.   return ((TREE_CODE (expr) == INTEGER_CST
  1511.        && TREE_INT_CST_LOW (expr) == 1
  1512.        && TREE_INT_CST_HIGH (expr) == 0)
  1513.       || (TREE_CODE (expr) == COMPLEX_CST
  1514.           && integer_onep (TREE_REALPART (expr))
  1515.           && integer_zerop (TREE_IMAGPART (expr))));
  1516. }
  1517.  
  1518. /* Return 1 if EXPR is an integer containing all 1's in as much precision as
  1519.    it contains.  Likewise for the corresponding complex constant.  */
  1520.  
  1521. int
  1522. integer_all_onesp (expr)
  1523.      tree expr;
  1524. {
  1525.   register int prec;
  1526.   register int uns;
  1527.  
  1528.   STRIP_NOPS (expr);
  1529.  
  1530.   if (TREE_CODE (expr) == COMPLEX_CST
  1531.       && integer_all_onesp (TREE_REALPART (expr))
  1532.       && integer_zerop (TREE_IMAGPART (expr)))
  1533.     return 1;
  1534.  
  1535.   else if (TREE_CODE (expr) != INTEGER_CST)
  1536.     return 0;
  1537.  
  1538.   uns = TREE_UNSIGNED (TREE_TYPE (expr));
  1539.   if (!uns)
  1540.     return TREE_INT_CST_LOW (expr) == -1 && TREE_INT_CST_HIGH (expr) == -1;
  1541.  
  1542.   /* Note that using TYPE_PRECISION here is wrong.  We care about the
  1543.      actual bits, not the (arbitrary) range of the type.  */
  1544.   prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr)));
  1545.   if (prec >= HOST_BITS_PER_WIDE_INT)
  1546.     {
  1547.       int high_value, shift_amount;
  1548.  
  1549.       shift_amount = prec - HOST_BITS_PER_WIDE_INT;
  1550.  
  1551.       if (shift_amount > HOST_BITS_PER_WIDE_INT)
  1552.     /* Can not handle precisions greater than twice the host int size.  */
  1553.     abort ();
  1554.       else if (shift_amount == HOST_BITS_PER_WIDE_INT)
  1555.     /* Shifting by the host word size is undefined according to the ANSI
  1556.        standard, so we must handle this as a special case.  */
  1557.     high_value = -1;
  1558.       else
  1559.     high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
  1560.  
  1561.       return TREE_INT_CST_LOW (expr) == -1
  1562.     && TREE_INT_CST_HIGH (expr) == high_value;
  1563.     }
  1564.   else
  1565.     return TREE_INT_CST_LOW (expr) == ((HOST_WIDE_INT) 1 << prec) - 1;
  1566. }
  1567.  
  1568. /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
  1569.    one bit on).  */
  1570.  
  1571. int
  1572. integer_pow2p (expr)
  1573.      tree expr;
  1574. {
  1575.   HOST_WIDE_INT high, low;
  1576.  
  1577.   STRIP_NOPS (expr);
  1578.  
  1579.   if (TREE_CODE (expr) == COMPLEX_CST
  1580.       && integer_pow2p (TREE_REALPART (expr))
  1581.       && integer_zerop (TREE_IMAGPART (expr)))
  1582.     return 1;
  1583.  
  1584.   if (TREE_CODE (expr) != INTEGER_CST)
  1585.     return 0;
  1586.  
  1587.   high = TREE_INT_CST_HIGH (expr);
  1588.   low = TREE_INT_CST_LOW (expr);
  1589.  
  1590.   if (high == 0 && low == 0)
  1591.     return 0;
  1592.  
  1593.   return ((high == 0 && (low & (low - 1)) == 0)
  1594.       || (low == 0 && (high & (high - 1)) == 0));
  1595. }
  1596.  
  1597. /* Return 1 if EXPR is the real constant zero.  */
  1598.  
  1599. int
  1600. real_zerop (expr)
  1601.      tree expr;
  1602. {
  1603.   STRIP_NOPS (expr);
  1604.  
  1605.   return ((TREE_CODE (expr) == REAL_CST
  1606.        && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0))
  1607.       || (TREE_CODE (expr) == COMPLEX_CST
  1608.           && real_zerop (TREE_REALPART (expr))
  1609.           && real_zerop (TREE_IMAGPART (expr))));
  1610. }
  1611.  
  1612. /* Return 1 if EXPR is the real constant one in real or complex form.  */
  1613.  
  1614. int
  1615. real_onep (expr)
  1616.      tree expr;
  1617. {
  1618.   STRIP_NOPS (expr);
  1619.  
  1620.   return ((TREE_CODE (expr) == REAL_CST
  1621.        && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1))
  1622.       || (TREE_CODE (expr) == COMPLEX_CST
  1623.           && real_onep (TREE_REALPART (expr))
  1624.           && real_zerop (TREE_IMAGPART (expr))));
  1625. }
  1626.  
  1627. /* Return 1 if EXPR is the real constant two.  */
  1628.  
  1629. int
  1630. real_twop (expr)
  1631.      tree expr;
  1632. {
  1633.   STRIP_NOPS (expr);
  1634.  
  1635.   return ((TREE_CODE (expr) == REAL_CST
  1636.        && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2))
  1637.       || (TREE_CODE (expr) == COMPLEX_CST
  1638.           && real_twop (TREE_REALPART (expr))
  1639.           && real_zerop (TREE_IMAGPART (expr))));
  1640. }
  1641.  
  1642. /* Nonzero if EXP is a constant or a cast of a constant.  */
  1643.  
  1644. int
  1645. really_constant_p (exp)
  1646.      tree exp;
  1647. {
  1648.   /* This is not quite the same as STRIP_NOPS.  It does more.  */
  1649.   while (TREE_CODE (exp) == NOP_EXPR
  1650.      || TREE_CODE (exp) == CONVERT_EXPR
  1651.      || TREE_CODE (exp) == NON_LVALUE_EXPR)
  1652.     exp = TREE_OPERAND (exp, 0);
  1653.   return TREE_CONSTANT (exp);
  1654. }
  1655.  
  1656. /* Return first list element whose TREE_VALUE is ELEM.
  1657.    Return 0 if ELEM is not in LIST.  */
  1658.  
  1659. tree
  1660. value_member (elem, list)
  1661.      tree elem, list;
  1662. {
  1663.   while (list)
  1664.     {
  1665.       if (elem == TREE_VALUE (list))
  1666.     return list;
  1667.       list = TREE_CHAIN (list);
  1668.     }
  1669.   return NULL_TREE;
  1670. }
  1671.  
  1672. /* Return first list element whose TREE_PURPOSE is ELEM.
  1673.    Return 0 if ELEM is not in LIST.  */
  1674.  
  1675. tree
  1676. purpose_member (elem, list)
  1677.      tree elem, list;
  1678. {
  1679.   while (list)
  1680.     {
  1681.       if (elem == TREE_PURPOSE (list))
  1682.     return list;
  1683.       list = TREE_CHAIN (list);
  1684.     }
  1685.   return NULL_TREE;
  1686. }
  1687.  
  1688. /* Return first list element whose BINFO_TYPE is ELEM.
  1689.    Return 0 if ELEM is not in LIST.  */
  1690.  
  1691. tree
  1692. binfo_member (elem, list)
  1693.      tree elem, list;
  1694. {
  1695.   while (list)
  1696.     {
  1697.       if (elem == BINFO_TYPE (list))
  1698.     return list;
  1699.       list = TREE_CHAIN (list);
  1700.     }
  1701.   return NULL_TREE;
  1702. }
  1703.  
  1704. /* Return nonzero if ELEM is part of the chain CHAIN. */
  1705.  
  1706. int
  1707. chain_member (elem, chain)
  1708.      tree elem, chain;
  1709. {
  1710.   while (chain)
  1711.     {
  1712.       if (elem == chain)
  1713.     return 1;
  1714.       chain = TREE_CHAIN (chain);
  1715.     }
  1716.  
  1717.   return 0;
  1718. }
  1719.  
  1720. /* Return nonzero if ELEM is equal to TREE_VALUE (CHAIN) for any piece of
  1721.    chain CHAIN. */
  1722. /* ??? This function was added for machine specific attributes but is no
  1723.    longer used.  It could be deleted if we could confirm all front ends
  1724.    don't use it.  */
  1725.  
  1726. int
  1727. chain_member_value (elem, chain)
  1728.      tree elem, chain;
  1729. {
  1730.   while (chain)
  1731.     {
  1732.       if (elem == TREE_VALUE (chain))
  1733.     return 1;
  1734.       chain = TREE_CHAIN (chain);
  1735.     }
  1736.  
  1737.   return 0;
  1738. }
  1739.  
  1740. /* Return nonzero if ELEM is equal to TREE_PURPOSE (CHAIN)
  1741.    for any piece of chain CHAIN. */
  1742. /* ??? This function was added for machine specific attributes but is no
  1743.    longer used.  It could be deleted if we could confirm all front ends
  1744.    don't use it.  */
  1745.  
  1746. int
  1747. chain_member_purpose (elem, chain)
  1748.      tree elem, chain;
  1749. {
  1750.   while (chain)
  1751.     {
  1752.       if (elem == TREE_PURPOSE (chain))
  1753.     return 1;
  1754.       chain = TREE_CHAIN (chain);
  1755.     }
  1756.  
  1757.   return 0;
  1758. }
  1759.  
  1760. /* Return the length of a chain of nodes chained through TREE_CHAIN.
  1761.    We expect a null pointer to mark the end of the chain.
  1762.    This is the Lisp primitive `length'.  */
  1763.  
  1764. int
  1765. list_length (t)
  1766.      tree t;
  1767. {
  1768.   register tree tail;
  1769.   register int len = 0;
  1770.  
  1771.   for (tail = t; tail; tail = TREE_CHAIN (tail))
  1772.     len++;
  1773.  
  1774.   return len;
  1775. }
  1776.  
  1777. /* Concatenate two chains of nodes (chained through TREE_CHAIN)
  1778.    by modifying the last node in chain 1 to point to chain 2.
  1779.    This is the Lisp primitive `nconc'.  */
  1780.  
  1781. tree
  1782. chainon (op1, op2)
  1783.      tree op1, op2;
  1784. {
  1785.  
  1786.   if (op1)
  1787.     {
  1788.       register tree t1;
  1789.       register tree t2;
  1790.  
  1791.       for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
  1792.     ;
  1793.       TREE_CHAIN (t1) = op2;
  1794.       for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
  1795.         if (t2 == t1)
  1796.           abort ();  /* Circularity created.  */
  1797.       return op1;
  1798.     }
  1799.   else return op2;
  1800. }
  1801.  
  1802. /* Return the last node in a chain of nodes (chained through TREE_CHAIN).  */
  1803.  
  1804. tree
  1805. tree_last (chain)
  1806.      register tree chain;
  1807. {
  1808.   register tree next;
  1809.   if (chain)
  1810.     while (next = TREE_CHAIN (chain))
  1811.       chain = next;
  1812.   return chain;
  1813. }
  1814.  
  1815. /* Reverse the order of elements in the chain T,
  1816.    and return the new head of the chain (old last element).  */
  1817.  
  1818. tree
  1819. nreverse (t)
  1820.      tree t;
  1821. {
  1822.   register tree prev = 0, decl, next;
  1823.   for (decl = t; decl; decl = next)
  1824.     {
  1825.       next = TREE_CHAIN (decl);
  1826.       TREE_CHAIN (decl) = prev;
  1827.       prev = decl;
  1828.     }
  1829.   return prev;
  1830. }
  1831.  
  1832. /* Given a chain CHAIN of tree nodes,
  1833.    construct and return a list of those nodes.  */
  1834.  
  1835. tree
  1836. listify (chain)
  1837.      tree chain;
  1838. {
  1839.   tree result = NULL_TREE;
  1840.   tree in_tail = chain;
  1841.   tree out_tail = NULL_TREE;
  1842.  
  1843.   while (in_tail)
  1844.     {
  1845.       tree next = tree_cons (NULL_TREE, in_tail, NULL_TREE);
  1846.       if (out_tail)
  1847.     TREE_CHAIN (out_tail) = next;
  1848.       else
  1849.     result = next;
  1850.       out_tail = next;
  1851.       in_tail = TREE_CHAIN (in_tail);
  1852.     }
  1853.  
  1854.   return result;
  1855. }
  1856.  
  1857. /* Return a newly created TREE_LIST node whose
  1858.    purpose and value fields are PARM and VALUE.  */
  1859.  
  1860. tree
  1861. build_tree_list (parm, value)
  1862.      tree parm, value;
  1863. {
  1864.   register tree t = make_node (TREE_LIST);
  1865.   TREE_PURPOSE (t) = parm;
  1866.   TREE_VALUE (t) = value;
  1867.   return t;
  1868. }
  1869.  
  1870. /* Similar, but build on the temp_decl_obstack.  */
  1871.  
  1872. tree
  1873. build_decl_list (parm, value)
  1874.      tree parm, value;
  1875. {
  1876.   register tree node;
  1877.   register struct obstack *ambient_obstack = current_obstack;
  1878.   current_obstack = &temp_decl_obstack;
  1879.   node = build_tree_list (parm, value);
  1880.   current_obstack = ambient_obstack;
  1881.   return node;
  1882. }
  1883.  
  1884. /* Return a newly created TREE_LIST node whose
  1885.    purpose and value fields are PARM and VALUE
  1886.    and whose TREE_CHAIN is CHAIN.  */
  1887.  
  1888. tree
  1889. tree_cons (purpose, value, chain)
  1890.      tree purpose, value, chain;
  1891. {
  1892. #if 0
  1893.   register tree node = make_node (TREE_LIST);
  1894. #else
  1895.   register int i;
  1896.   register tree node = (tree) obstack_alloc (current_obstack, sizeof (struct tree_list));
  1897. #ifdef GATHER_STATISTICS
  1898.   tree_node_counts[(int)x_kind]++;
  1899.   tree_node_sizes[(int)x_kind] += sizeof (struct tree_list);
  1900. #endif
  1901.  
  1902.   for (i = (sizeof (struct tree_common) / sizeof (int)) - 1; i >= 0; i--)
  1903.     ((int *) node)[i] = 0;
  1904.  
  1905.   TREE_SET_CODE (node, TREE_LIST);
  1906.   if (current_obstack == &permanent_obstack)
  1907.     TREE_PERMANENT (node) = 1;
  1908. #endif
  1909.  
  1910.   TREE_CHAIN (node) = chain;
  1911.   TREE_PURPOSE (node) = purpose;
  1912.   TREE_VALUE (node) = value;
  1913.   return node;
  1914. }
  1915.  
  1916. /* Similar, but build on the temp_decl_obstack.  */
  1917.  
  1918. tree
  1919. decl_tree_cons (purpose, value, chain)
  1920.      tree purpose, value, chain;
  1921. {
  1922.   register tree node;
  1923.   register struct obstack *ambient_obstack = current_obstack;
  1924.   current_obstack = &temp_decl_obstack;
  1925.   node = tree_cons (purpose, value, chain);
  1926.   current_obstack = ambient_obstack;
  1927.   return node;
  1928. }
  1929.  
  1930. /* Same as `tree_cons' but make a permanent object.  */
  1931.  
  1932. tree
  1933. perm_tree_cons (purpose, value, chain)
  1934.      tree purpose, value, chain;
  1935. {
  1936.   register tree node;
  1937.   register struct obstack *ambient_obstack = current_obstack;
  1938.   current_obstack = &permanent_obstack;
  1939.  
  1940.   node = tree_cons (purpose, value, chain);
  1941.   current_obstack = ambient_obstack;
  1942.   return node;
  1943. }
  1944.  
  1945. /* Same as `tree_cons', but make this node temporary, regardless.  */
  1946.  
  1947. tree
  1948. temp_tree_cons (purpose, value, chain)
  1949.      tree purpose, value, chain;
  1950. {
  1951.   register tree node;
  1952.   register struct obstack *ambient_obstack = current_obstack;
  1953.   current_obstack = &temporary_obstack;
  1954.  
  1955.   node = tree_cons (purpose, value, chain);
  1956.   current_obstack = ambient_obstack;
  1957.   return node;
  1958. }
  1959.  
  1960. /* Same as `tree_cons', but save this node if the function's RTL is saved.  */
  1961.  
  1962. tree
  1963. saveable_tree_cons (purpose, value, chain)
  1964.      tree purpose, value, chain;
  1965. {
  1966.   register tree node;
  1967.   register struct obstack *ambient_obstack = current_obstack;
  1968.   current_obstack = saveable_obstack;
  1969.  
  1970.   node = tree_cons (purpose, value, chain);
  1971.   current_obstack = ambient_obstack;
  1972.   return node;
  1973. }
  1974.  
  1975. /* Return the size nominally occupied by an object of type TYPE
  1976.    when it resides in memory.  The value is measured in units of bytes,
  1977.    and its data type is that normally used for type sizes
  1978.    (which is the first type created by make_signed_type or
  1979.    make_unsigned_type).  */
  1980.  
  1981. tree
  1982. size_in_bytes (type)
  1983.      tree type;
  1984. {
  1985.   tree t;
  1986.  
  1987.   if (type == error_mark_node)
  1988.     return integer_zero_node;
  1989.   type = TYPE_MAIN_VARIANT (type);
  1990.   if (TYPE_SIZE (type) == 0)
  1991.     {
  1992.       incomplete_type_error (NULL_TREE, type);
  1993.       return integer_zero_node;
  1994.     }
  1995.   t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
  1996.           size_int (BITS_PER_UNIT));
  1997.   if (TREE_CODE (t) == INTEGER_CST)
  1998.     force_fit_type (t, 0);
  1999.   return t;
  2000. }
  2001.  
  2002. /* Return the size of TYPE (in bytes) as an integer,
  2003.    or return -1 if the size can vary.  */
  2004.  
  2005. int
  2006. int_size_in_bytes (type)
  2007.      tree type;
  2008. {
  2009.   unsigned int size;
  2010.   if (type == error_mark_node)
  2011.     return 0;
  2012.   type = TYPE_MAIN_VARIANT (type);
  2013.   if (TYPE_SIZE (type) == 0)
  2014.     return -1;
  2015.   if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
  2016.     return -1;
  2017.   if (TREE_INT_CST_HIGH (TYPE_SIZE (type)) != 0)
  2018.     {
  2019.       tree t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
  2020.                size_int (BITS_PER_UNIT));
  2021.       return TREE_INT_CST_LOW (t);
  2022.     }
  2023.   size = TREE_INT_CST_LOW (TYPE_SIZE (type));
  2024.   return (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
  2025. }
  2026.  
  2027. /* Return, as a tree node, the number of elements for TYPE (which is an
  2028.    ARRAY_TYPE) minus one. This counts only elements of the top array.  */
  2029.  
  2030. tree
  2031. array_type_nelts (type)
  2032.      tree type;
  2033. {
  2034.   tree index_type = TYPE_DOMAIN (type);
  2035.  
  2036.   return (integer_zerop (TYPE_MIN_VALUE (index_type))
  2037.       ? TYPE_MAX_VALUE (index_type)
  2038.       : fold (build (MINUS_EXPR, TREE_TYPE (TYPE_MAX_VALUE (index_type)),
  2039.              TYPE_MAX_VALUE (index_type),
  2040.              TYPE_MIN_VALUE (index_type))));
  2041. }
  2042.  
  2043. /* Return nonzero if arg is static -- a reference to an object in
  2044.    static storage.  This is not the same as the C meaning of `static'.  */
  2045.  
  2046. int
  2047. staticp (arg)
  2048.      tree arg;
  2049. {
  2050.   switch (TREE_CODE (arg))
  2051.     {
  2052.     case FUNCTION_DECL:
  2053.       /* Nested functions aren't static, since taking their address
  2054.      involves a trampoline.  */
  2055.        return decl_function_context (arg) == 0;
  2056.     case VAR_DECL:
  2057.       return TREE_STATIC (arg) || DECL_EXTERNAL (arg);
  2058.  
  2059.     case CONSTRUCTOR:
  2060.       return TREE_STATIC (arg);
  2061.  
  2062.     case STRING_CST:
  2063.       return 1;
  2064.  
  2065.     case COMPONENT_REF:
  2066.     case BIT_FIELD_REF:
  2067.       return staticp (TREE_OPERAND (arg, 0));
  2068.  
  2069. #if 0
  2070.        /* This case is technically correct, but results in setting
  2071.       TREE_CONSTANT on ADDR_EXPRs that cannot be evaluated at
  2072.       compile time.  */
  2073.     case INDIRECT_REF:
  2074.       return TREE_CONSTANT (TREE_OPERAND (arg, 0));
  2075. #endif
  2076.  
  2077.     case ARRAY_REF:
  2078.       if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
  2079.       && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
  2080.     return staticp (TREE_OPERAND (arg, 0));
  2081.     }
  2082.  
  2083.   return 0;
  2084. }
  2085.  
  2086. /* Wrap a SAVE_EXPR around EXPR, if appropriate.
  2087.    Do this to any expression which may be used in more than one place,
  2088.    but must be evaluated only once.
  2089.  
  2090.    Normally, expand_expr would reevaluate the expression each time.
  2091.    Calling save_expr produces something that is evaluated and recorded
  2092.    the first time expand_expr is called on it.  Subsequent calls to
  2093.    expand_expr just reuse the recorded value.
  2094.  
  2095.    The call to expand_expr that generates code that actually computes
  2096.    the value is the first call *at compile time*.  Subsequent calls
  2097.    *at compile time* generate code to use the saved value.
  2098.    This produces correct result provided that *at run time* control
  2099.    always flows through the insns made by the first expand_expr
  2100.    before reaching the other places where the save_expr was evaluated.
  2101.    You, the caller of save_expr, must make sure this is so.
  2102.  
  2103.    Constants, and certain read-only nodes, are returned with no
  2104.    SAVE_EXPR because that is safe.  Expressions containing placeholders
  2105.    are not touched; see tree.def for an explanation of what these
  2106.    are used for.  */
  2107.  
  2108. tree
  2109. save_expr (expr)
  2110.      tree expr;
  2111. {
  2112.   register tree t = fold (expr);
  2113.  
  2114.   /* We don't care about whether this can be used as an lvalue in this
  2115.      context.  */
  2116.   while (TREE_CODE (t) == NON_LVALUE_EXPR)
  2117.     t = TREE_OPERAND (t, 0);
  2118.  
  2119.   /* If the tree evaluates to a constant, then we don't want to hide that
  2120.      fact (i.e. this allows further folding, and direct checks for constants).
  2121.      However, a read-only object that has side effects cannot be bypassed.
  2122.      Since it is no problem to reevaluate literals, we just return the 
  2123.      literal node. */
  2124.  
  2125.   if (TREE_CONSTANT (t) || (TREE_READONLY (t) && ! TREE_SIDE_EFFECTS (t))
  2126.       || TREE_CODE (t) == SAVE_EXPR || TREE_CODE (t) == ERROR_MARK)
  2127.     return t;
  2128.  
  2129.   /* If T contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
  2130.      it means that the size or offset of some field of an object depends on
  2131.      the value within another field.
  2132.  
  2133.      Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
  2134.      and some variable since it would then need to be both evaluated once and
  2135.      evaluated more than once.  Front-ends must assure this case cannot
  2136.      happen by surrounding any such subexpressions in their own SAVE_EXPR
  2137.      and forcing evaluation at the proper time.  */
  2138.   if (contains_placeholder_p (t))
  2139.     return t;
  2140.  
  2141.   t = build (SAVE_EXPR, TREE_TYPE (expr), t, current_function_decl, NULL_TREE);
  2142.  
  2143.   /* This expression might be placed ahead of a jump to ensure that the
  2144.      value was computed on both sides of the jump.  So make sure it isn't
  2145.      eliminated as dead.  */
  2146.   TREE_SIDE_EFFECTS (t) = 1;
  2147.   return t;
  2148. }
  2149.  
  2150. /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
  2151.    or offset that depends on a field within a record.
  2152.  
  2153.    Note that we only allow such expressions within simple arithmetic
  2154.    or a COND_EXPR.  */
  2155.  
  2156. int
  2157. contains_placeholder_p (exp)
  2158.      tree exp;
  2159. {
  2160.   register enum tree_code code = TREE_CODE (exp);
  2161.   tree inner;
  2162.  
  2163.   /* If we have a WITH_RECORD_EXPR, it "cancels" any PLACEHOLDER_EXPR
  2164.      in it since it is supplying a value for it.  */
  2165.   if (code == WITH_RECORD_EXPR)
  2166.     return 0;
  2167.  
  2168.   switch (TREE_CODE_CLASS (code))
  2169.     {
  2170.     case 'r':
  2171.       for (inner = TREE_OPERAND (exp, 0);
  2172.        TREE_CODE_CLASS (TREE_CODE (inner)) == 'r';
  2173.        inner = TREE_OPERAND (inner, 0))
  2174.     ;
  2175.       return TREE_CODE (inner) == PLACEHOLDER_EXPR;
  2176.  
  2177.     case '1':
  2178.     case '2':  case '<':
  2179.     case 'e':
  2180.       switch (tree_code_length[(int) code])
  2181.     {
  2182.     case 1:
  2183.       return contains_placeholder_p (TREE_OPERAND (exp, 0));
  2184.     case 2:
  2185.       return (code != RTL_EXPR
  2186.           && code != CONSTRUCTOR
  2187.           && ! (code == SAVE_EXPR && SAVE_EXPR_RTL (exp) != 0)
  2188.           && code != WITH_RECORD_EXPR
  2189.           && (contains_placeholder_p (TREE_OPERAND (exp, 0))
  2190.               || contains_placeholder_p (TREE_OPERAND (exp, 1))));
  2191.     case 3:
  2192.       return (code == COND_EXPR
  2193.           && (contains_placeholder_p (TREE_OPERAND (exp, 0))
  2194.               || contains_placeholder_p (TREE_OPERAND (exp, 1))
  2195.               || contains_placeholder_p (TREE_OPERAND (exp, 2))));
  2196.     }
  2197.     }
  2198.  
  2199.   return 0;
  2200. }
  2201.  
  2202. /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
  2203.    return a tree with all occurrences of references to F in a
  2204.    PLACEHOLDER_EXPR replaced by R.   Note that we assume here that EXP
  2205.    contains only arithmetic expressions.  */
  2206.  
  2207. tree
  2208. substitute_in_expr (exp, f, r)
  2209.      tree exp;
  2210.      tree f;
  2211.      tree r;
  2212. {
  2213.   enum tree_code code = TREE_CODE (exp);
  2214.   tree new = 0;
  2215.   tree inner;
  2216.  
  2217.   switch (TREE_CODE_CLASS (code))
  2218.     {
  2219.     case 'c':
  2220.     case 'd':
  2221.       return exp;
  2222.  
  2223.     case 'x':
  2224.       if (code == PLACEHOLDER_EXPR)
  2225.     return exp;
  2226.       break;
  2227.  
  2228.     case '1':
  2229.     case '2':
  2230.     case '<':
  2231.     case 'e':
  2232.       switch (tree_code_length[(int) code])
  2233.     {
  2234.     case 1:
  2235.       new = fold (build1 (code, TREE_TYPE (exp),
  2236.                   substitute_in_expr (TREE_OPERAND (exp, 0),
  2237.                           f, r)));
  2238.       break;
  2239.  
  2240.     case 2:
  2241.       /* An RTL_EXPR cannot contain a PLACEHOLDER_EXPR; a CONSTRUCTOR
  2242.          could, but we don't support it.  */
  2243.       if (code == RTL_EXPR)
  2244.         return exp;
  2245.       else if (code == CONSTRUCTOR)
  2246.         abort ();
  2247.  
  2248.       new = fold (build (code, TREE_TYPE (exp),
  2249.                  substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
  2250.                  substitute_in_expr (TREE_OPERAND (exp, 1),
  2251.                          f, r)));
  2252.       break;
  2253.  
  2254.     case 3:
  2255.       /* It cannot be that anything inside a SAVE_EXPR contains a
  2256.          PLACEHOLDER_EXPR.  */
  2257.       if (code == SAVE_EXPR)
  2258.         return exp;
  2259.  
  2260.       if (code != COND_EXPR)
  2261.         abort ();
  2262.  
  2263.       new = fold (build (code, TREE_TYPE (exp),
  2264.                  substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
  2265.                  substitute_in_expr (TREE_OPERAND (exp, 1), f, r),
  2266.                  substitute_in_expr (TREE_OPERAND (exp, 2),
  2267.                          f, r)));
  2268.     }
  2269.  
  2270.       break;
  2271.  
  2272.     case 'r':
  2273.       switch (code)
  2274.     {
  2275.     case COMPONENT_REF:
  2276.       /* If this expression is getting a value from a PLACEHOLDER_EXPR
  2277.          and it is the right field, replace it with R.  */
  2278.       for (inner = TREE_OPERAND (exp, 0);
  2279.            TREE_CODE_CLASS (TREE_CODE (inner)) == 'r';
  2280.            inner = TREE_OPERAND (inner, 0))
  2281.         ;
  2282.       if (TREE_CODE (inner) == PLACEHOLDER_EXPR
  2283.           && TREE_OPERAND (exp, 1) == f)
  2284.         return r;
  2285.  
  2286.       new = fold (build (code, TREE_TYPE (exp),
  2287.                  substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
  2288.                  TREE_OPERAND (exp, 1)));
  2289.       break;
  2290.  
  2291.     case BIT_FIELD_REF:
  2292.       new = fold (build (code, TREE_TYPE (exp),
  2293.                  substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
  2294.                  substitute_in_expr (TREE_OPERAND (exp, 1), f, r),
  2295.                  substitute_in_expr (TREE_OPERAND (exp, 2), f, r)));
  2296.       break;
  2297.  
  2298.     case INDIRECT_REF:
  2299.     case BUFFER_REF:
  2300.       new = fold (build1 (code, TREE_TYPE (exp),
  2301.                   substitute_in_expr (TREE_OPERAND (exp, 0),
  2302.                           f, r)));
  2303.       break;
  2304.  
  2305.     case OFFSET_REF:
  2306.       new = fold (build (code, TREE_TYPE (exp),
  2307.                  substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
  2308.                  substitute_in_expr (TREE_OPERAND (exp, 1), f, r)));
  2309.       break;
  2310.     }
  2311.     }
  2312.  
  2313.   /* If it wasn't one of the cases we handle, give up.  */
  2314.   if (new == 0)
  2315.     abort ();
  2316.  
  2317.   TREE_READONLY (new) = TREE_READONLY (exp);
  2318.   return new;
  2319. }
  2320.  
  2321. /* Given a type T, a FIELD_DECL F, and a replacement value R,
  2322.    return a new type with all size expressions that contain F
  2323.    updated by replacing F with R.  */
  2324.  
  2325. tree
  2326. substitute_in_type (t, f, r)
  2327.      tree t, f, r;
  2328. {
  2329.   switch (TREE_CODE (t))
  2330.     {
  2331.     case POINTER_TYPE:
  2332.     case VOID_TYPE:
  2333.       return t;
  2334.     case INTEGER_TYPE:
  2335.     case ENUMERAL_TYPE:
  2336.     case BOOLEAN_TYPE:
  2337.     case CHAR_TYPE:
  2338.       if ((TREE_CODE (TYPE_MIN_VALUE (t)) != INTEGER_CST
  2339.        && contains_placeholder_p (TYPE_MIN_VALUE (t)))
  2340.       || (TREE_CODE (TYPE_MAX_VALUE (t)) != INTEGER_CST
  2341.           && contains_placeholder_p (TYPE_MAX_VALUE (t))))
  2342.     return build_range_type (t,
  2343.                  substitute_in_expr (TYPE_MIN_VALUE (t), f, r),
  2344.                  substitute_in_expr (TYPE_MAX_VALUE (t), f, r));
  2345.       return t;
  2346.  
  2347.     case REAL_TYPE:
  2348.       if ((TYPE_MIN_VALUE (t) != 0
  2349.        && TREE_CODE (TYPE_MIN_VALUE (t)) != REAL_CST
  2350.        && contains_placeholder_p (TYPE_MIN_VALUE (t)))
  2351.       || (TYPE_MAX_VALUE (t) != 0
  2352.           && TREE_CODE (TYPE_MAX_VALUE (t)) != REAL_CST
  2353.           && contains_placeholder_p (TYPE_MAX_VALUE (t))))
  2354.     {
  2355.       t = build_type_copy (t);
  2356.  
  2357.       if (TYPE_MIN_VALUE (t))
  2358.         TYPE_MIN_VALUE (t) = substitute_in_expr (TYPE_MIN_VALUE (t), f, r);
  2359.       if (TYPE_MAX_VALUE (t))
  2360.         TYPE_MAX_VALUE (t) = substitute_in_expr (TYPE_MAX_VALUE (t), f, r);
  2361.     }
  2362.       return t;
  2363.  
  2364.     case COMPLEX_TYPE:
  2365.       return build_complex_type (substitute_in_type (TREE_TYPE (t), f, r));
  2366.  
  2367.     case OFFSET_TYPE:
  2368.     case METHOD_TYPE:
  2369.     case REFERENCE_TYPE:
  2370.     case FILE_TYPE:
  2371.     case SET_TYPE:
  2372.     case FUNCTION_TYPE:
  2373.     case LANG_TYPE:
  2374.       /* Don't know how to do these yet.  */
  2375.       abort ();
  2376.  
  2377.     case ARRAY_TYPE:
  2378.       t = build_array_type (substitute_in_type (TREE_TYPE (t), f, r),
  2379.                 substitute_in_type (TYPE_DOMAIN (t), f, r));
  2380.       TYPE_SIZE (t) = 0;
  2381.       layout_type (t);
  2382.       return t;
  2383.  
  2384.     case RECORD_TYPE:
  2385.     case UNION_TYPE:
  2386.     case QUAL_UNION_TYPE:
  2387.       {
  2388.     tree new = copy_node (t);
  2389.     tree field;
  2390.     tree last_field = 0;
  2391.  
  2392.     /* Start out with no fields, make new fields, and chain them
  2393.        in.  */
  2394.  
  2395.     TYPE_FIELDS (new) = 0;
  2396.     TYPE_SIZE (new) = 0;
  2397.  
  2398.     for (field = TYPE_FIELDS (t); field;
  2399.          field = TREE_CHAIN (field))
  2400.       {
  2401.         tree new_field = copy_node (field);
  2402.  
  2403.         TREE_TYPE (new_field)
  2404.           = substitute_in_type (TREE_TYPE (new_field), f, r);
  2405.  
  2406.         /* If this is an anonymous field and the type of this field is
  2407.            a UNION_TYPE or RECORD_TYPE with no elements, ignore it.  If
  2408.            the type just has one element, treat that as the field. 
  2409.            But don't do this if we are processing a QUAL_UNION_TYPE.  */
  2410.         if (TREE_CODE (t) != QUAL_UNION_TYPE && DECL_NAME (new_field) == 0
  2411.         && (TREE_CODE (TREE_TYPE (new_field)) == UNION_TYPE
  2412.             || TREE_CODE (TREE_TYPE (new_field)) == RECORD_TYPE))
  2413.           {
  2414.         if (TYPE_FIELDS (TREE_TYPE (new_field)) == 0)
  2415.           continue;
  2416.  
  2417.         if (TREE_CHAIN (TYPE_FIELDS (TREE_TYPE (new_field))) == 0)
  2418.           new_field = TYPE_FIELDS (TREE_TYPE (new_field));
  2419.           }
  2420.  
  2421.         DECL_CONTEXT (new_field) = new;
  2422.         DECL_SIZE (new_field) = 0;
  2423.  
  2424.         if (TREE_CODE (t) == QUAL_UNION_TYPE)
  2425.           {
  2426.         /* Do the substitution inside the qualifier and if we find
  2427.            that this field will not be present, omit it.  */
  2428.         DECL_QUALIFIER (new_field)
  2429.           = substitute_in_expr (DECL_QUALIFIER (field), f, r);
  2430.         if (integer_zerop (DECL_QUALIFIER (new_field)))
  2431.           continue;
  2432.           }
  2433.  
  2434.         if (last_field == 0)
  2435.           TYPE_FIELDS (new) = new_field;
  2436.         else
  2437.           TREE_CHAIN (last_field) = new_field;
  2438.  
  2439.         last_field = new_field;
  2440.  
  2441.         /* If this is a qualified type and this field will always be
  2442.            present, we are done.  */
  2443.         if (TREE_CODE (t) == QUAL_UNION_TYPE
  2444.         && integer_onep (DECL_QUALIFIER (new_field)))
  2445.           break;
  2446.       }
  2447.  
  2448.     /* If this used to be a qualified union type, but we now know what
  2449.        field will be present, make this a normal union.  */
  2450.     if (TREE_CODE (new) == QUAL_UNION_TYPE
  2451.         && (TYPE_FIELDS (new) == 0
  2452.         || integer_onep (DECL_QUALIFIER (TYPE_FIELDS (new)))))
  2453.       TREE_SET_CODE (new, UNION_TYPE);
  2454.  
  2455.     layout_type (new);
  2456.     return new;
  2457.       }
  2458.     }
  2459. }
  2460.  
  2461. /* Stabilize a reference so that we can use it any number of times
  2462.    without causing its operands to be evaluated more than once.
  2463.    Returns the stabilized reference.  This works by means of save_expr,
  2464.    so see the caveats in the comments about save_expr.
  2465.  
  2466.    Also allows conversion expressions whose operands are references.
  2467.    Any other kind of expression is returned unchanged.  */
  2468.  
  2469. tree
  2470. stabilize_reference (ref)
  2471.      tree ref;
  2472. {
  2473.   register tree result;
  2474.   register enum tree_code code = TREE_CODE (ref);
  2475.  
  2476.   switch (code)
  2477.     {
  2478.     case VAR_DECL:
  2479.     case PARM_DECL:
  2480.     case RESULT_DECL:
  2481.       /* No action is needed in this case.  */
  2482.       return ref;
  2483.  
  2484.     case NOP_EXPR:
  2485.     case CONVERT_EXPR:
  2486.     case FLOAT_EXPR:
  2487.     case FIX_TRUNC_EXPR:
  2488.     case FIX_FLOOR_EXPR:
  2489.     case FIX_ROUND_EXPR:
  2490.     case FIX_CEIL_EXPR:
  2491.       result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
  2492.       break;
  2493.  
  2494.     case INDIRECT_REF:
  2495.       result = build_nt (INDIRECT_REF,
  2496.              stabilize_reference_1 (TREE_OPERAND (ref, 0)));
  2497.       break;
  2498.  
  2499.     case COMPONENT_REF:
  2500.       result = build_nt (COMPONENT_REF,
  2501.              stabilize_reference (TREE_OPERAND (ref, 0)),
  2502.              TREE_OPERAND (ref, 1));
  2503.       break;
  2504.  
  2505.     case BIT_FIELD_REF:
  2506.       result = build_nt (BIT_FIELD_REF,
  2507.              stabilize_reference (TREE_OPERAND (ref, 0)),
  2508.              stabilize_reference_1 (TREE_OPERAND (ref, 1)),
  2509.              stabilize_reference_1 (TREE_OPERAND (ref, 2)));
  2510.       break;
  2511.  
  2512.     case ARRAY_REF:
  2513.       result = build_nt (ARRAY_REF,
  2514.              stabilize_reference (TREE_OPERAND (ref, 0)),
  2515.              stabilize_reference_1 (TREE_OPERAND (ref, 1)));
  2516.       break;
  2517.  
  2518.     case COMPOUND_EXPR:
  2519.       result = build_nt (COMPOUND_EXPR,
  2520.              stabilize_reference_1 (TREE_OPERAND (ref, 0)),
  2521.              stabilize_reference (TREE_OPERAND (ref, 1)));
  2522.       break;
  2523.  
  2524.     case RTL_EXPR:
  2525.       result = build1 (INDIRECT_REF, TREE_TYPE (ref),
  2526.                save_expr (build1 (ADDR_EXPR,
  2527.                       build_pointer_type (TREE_TYPE (ref)),
  2528.                       ref)));
  2529.       break;
  2530.  
  2531.  
  2532.       /* If arg isn't a kind of lvalue we recognize, make no change.
  2533.      Caller should recognize the error for an invalid lvalue.  */
  2534.     default:
  2535.       return ref;
  2536.  
  2537.     case ERROR_MARK:
  2538.       return error_mark_node;
  2539.     }
  2540.  
  2541.   TREE_TYPE (result) = TREE_TYPE (ref);
  2542.   TREE_READONLY (result) = TREE_READONLY (ref);
  2543.   TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
  2544.   TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
  2545.   TREE_RAISES (result) = TREE_RAISES (ref);
  2546.  
  2547.   return result;
  2548. }
  2549.  
  2550. /* Subroutine of stabilize_reference; this is called for subtrees of
  2551.    references.  Any expression with side-effects must be put in a SAVE_EXPR
  2552.    to ensure that it is only evaluated once.
  2553.  
  2554.    We don't put SAVE_EXPR nodes around everything, because assigning very
  2555.    simple expressions to temporaries causes us to miss good opportunities
  2556.    for optimizations.  Among other things, the opportunity to fold in the
  2557.    addition of a constant into an addressing mode often gets lost, e.g.
  2558.    "y[i+1] += x;".  In general, we take the approach that we should not make
  2559.    an assignment unless we are forced into it - i.e., that any non-side effect
  2560.    operator should be allowed, and that cse should take care of coalescing
  2561.    multiple utterances of the same expression should that prove fruitful.  */
  2562.  
  2563. tree
  2564. stabilize_reference_1 (e)
  2565.      tree e;
  2566. {
  2567.   register tree result;
  2568.   register enum tree_code code = TREE_CODE (e);
  2569.  
  2570.   /* We cannot ignore const expressions because it might be a reference
  2571.      to a const array but whose index contains side-effects.  But we can
  2572.      ignore things that are actual constant or that already have been
  2573.      handled by this function.  */
  2574.  
  2575.   if (TREE_CONSTANT (e) || code == SAVE_EXPR)
  2576.     return e;
  2577.  
  2578.   switch (TREE_CODE_CLASS (code))
  2579.     {
  2580.     case 'x':
  2581.     case 't':
  2582.     case 'd':
  2583.     case 'b':
  2584.     case '<':
  2585.     case 's':
  2586.     case 'e':
  2587.     case 'r':
  2588.       /* If the expression has side-effects, then encase it in a SAVE_EXPR
  2589.      so that it will only be evaluated once.  */
  2590.       /* The reference (r) and comparison (<) classes could be handled as
  2591.      below, but it is generally faster to only evaluate them once.  */
  2592.       if (TREE_SIDE_EFFECTS (e))
  2593.     return save_expr (e);
  2594.       return e;
  2595.  
  2596.     case 'c':
  2597.       /* Constants need no processing.  In fact, we should never reach
  2598.      here.  */
  2599.       return e;
  2600.       
  2601.     case '2':
  2602.       /* Division is slow and tends to be compiled with jumps,
  2603.      especially the division by powers of 2 that is often
  2604.      found inside of an array reference.  So do it just once.  */
  2605.       if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
  2606.       || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
  2607.       || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
  2608.       || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
  2609.     return save_expr (e);
  2610.       /* Recursively stabilize each operand.  */
  2611.       result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
  2612.              stabilize_reference_1 (TREE_OPERAND (e, 1)));
  2613.       break;
  2614.  
  2615.     case '1':
  2616.       /* Recursively stabilize each operand.  */
  2617.       result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
  2618.       break;
  2619.  
  2620.     default:
  2621.       abort ();
  2622.     }
  2623.   
  2624.   TREE_TYPE (result) = TREE_TYPE (e);
  2625.   TREE_READONLY (result) = TREE_READONLY (e);
  2626.   TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
  2627.   TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
  2628.   TREE_RAISES (result) = TREE_RAISES (e);
  2629.  
  2630.   return result;
  2631. }
  2632.  
  2633. /* Low-level constructors for expressions.  */
  2634.  
  2635. /* Build an expression of code CODE, data type TYPE,
  2636.    and operands as specified by the arguments ARG1 and following arguments.
  2637.    Expressions and reference nodes can be created this way.
  2638.    Constants, decls, types and misc nodes cannot be.  */
  2639.  
  2640. tree
  2641. build VPROTO((enum tree_code code, tree tt, ...))
  2642. {
  2643. #ifndef __STDC__
  2644.   enum tree_code code;
  2645.   tree tt;
  2646. #endif
  2647.   va_list p;
  2648.   register tree t;
  2649.   register int length;
  2650.   register int i;
  2651.  
  2652.   VA_START (p, tt);
  2653.  
  2654. #ifndef __STDC__
  2655.   code = va_arg (p, enum tree_code);
  2656.   tt = va_arg (p, tree);
  2657. #endif
  2658.  
  2659.   t = make_node (code);
  2660.   length = tree_code_length[(int) code];
  2661.   TREE_TYPE (t) = tt;
  2662.  
  2663.   if (length == 2)
  2664.     {
  2665.       /* This is equivalent to the loop below, but faster.  */
  2666.       register tree arg0 = va_arg (p, tree);
  2667.       register tree arg1 = va_arg (p, tree);
  2668.       TREE_OPERAND (t, 0) = arg0;
  2669.       TREE_OPERAND (t, 1) = arg1;
  2670.       if ((arg0 && TREE_SIDE_EFFECTS (arg0))
  2671.       || (arg1 && TREE_SIDE_EFFECTS (arg1)))
  2672.     TREE_SIDE_EFFECTS (t) = 1;
  2673.       TREE_RAISES (t)
  2674.     = (arg0 && TREE_RAISES (arg0)) || (arg1 && TREE_RAISES (arg1));
  2675.     }
  2676.   else if (length == 1)
  2677.     {
  2678.       register tree arg0 = va_arg (p, tree);
  2679.  
  2680.       /* Call build1 for this!  */
  2681.       if (TREE_CODE_CLASS (code) != 's')
  2682.     abort ();
  2683.       TREE_OPERAND (t, 0) = arg0;
  2684.       if (arg0 && TREE_SIDE_EFFECTS (arg0))
  2685.     TREE_SIDE_EFFECTS (t) = 1;
  2686.       TREE_RAISES (t) = (arg0 && TREE_RAISES (arg0));
  2687.     }
  2688.   else
  2689.     {
  2690.       for (i = 0; i < length; i++)
  2691.     {
  2692.       register tree operand = va_arg (p, tree);
  2693.       TREE_OPERAND (t, i) = operand;
  2694.       if (operand)
  2695.         {
  2696.           if (TREE_SIDE_EFFECTS (operand))
  2697.         TREE_SIDE_EFFECTS (t) = 1;
  2698.           if (TREE_RAISES (operand))
  2699.         TREE_RAISES (t) = 1;
  2700.         }
  2701.     }
  2702.     }
  2703.   va_end (p);
  2704.   return t;
  2705. }
  2706.  
  2707. /* Same as above, but only builds for unary operators.
  2708.    Saves lions share of calls to `build'; cuts down use
  2709.    of varargs, which is expensive for RISC machines.  */
  2710. tree
  2711. build1 (code, type, node)
  2712.      enum tree_code code;
  2713.      tree type;
  2714.      tree node;
  2715. {
  2716.   register struct obstack *obstack = current_obstack;
  2717.   register int i, length;
  2718.   register tree_node_kind kind;
  2719.   register tree t;
  2720.  
  2721. #ifdef GATHER_STATISTICS
  2722.   if (TREE_CODE_CLASS (code) == 'r')
  2723.     kind = r_kind;
  2724.   else
  2725.     kind = e_kind;
  2726. #endif
  2727.  
  2728.   obstack = expression_obstack;
  2729.   length = sizeof (struct tree_exp);
  2730.  
  2731.   t = (tree) obstack_alloc (obstack, length);
  2732.  
  2733. #ifdef GATHER_STATISTICS
  2734.   tree_node_counts[(int)kind]++;
  2735.   tree_node_sizes[(int)kind] += length;
  2736. #endif
  2737.  
  2738.   for (i = (length / sizeof (int)) - 1; i >= 0; i--)
  2739.     ((int *) t)[i] = 0;
  2740.  
  2741.   TREE_TYPE (t) = type;
  2742.   TREE_SET_CODE (t, code);
  2743.  
  2744.   if (obstack == &permanent_obstack)
  2745.     TREE_PERMANENT (t) = 1;
  2746.  
  2747.   TREE_OPERAND (t, 0) = node;
  2748.   if (node)
  2749.     {
  2750.       if (TREE_SIDE_EFFECTS (node))
  2751.     TREE_SIDE_EFFECTS (t) = 1;
  2752.       if (TREE_RAISES (node))
  2753.     TREE_RAISES (t) = 1;
  2754.     }
  2755.  
  2756.   return t;
  2757. }
  2758.  
  2759. /* Similar except don't specify the TREE_TYPE
  2760.    and leave the TREE_SIDE_EFFECTS as 0.
  2761.    It is permissible for arguments to be null,
  2762.    or even garbage if their values do not matter.  */
  2763.  
  2764. tree
  2765. build_nt VPROTO((enum tree_code code, ...))
  2766. {
  2767. #ifndef __STDC__
  2768.   enum tree_code code;
  2769. #endif
  2770.   va_list p;
  2771.   register tree t;
  2772.   register int length;
  2773.   register int i;
  2774.  
  2775.   VA_START (p, code);
  2776.  
  2777. #ifndef __STDC__
  2778.   code = va_arg (p, enum tree_code);
  2779. #endif
  2780.  
  2781.   t = make_node (code);
  2782.   length = tree_code_length[(int) code];
  2783.  
  2784.   for (i = 0; i < length; i++)
  2785.     TREE_OPERAND (t, i) = va_arg (p, tree);
  2786.  
  2787.   va_end (p);
  2788.   return t;
  2789. }
  2790.  
  2791. /* Similar to `build_nt', except we build
  2792.    on the temp_decl_obstack, regardless.  */
  2793.  
  2794. tree
  2795. build_parse_node VPROTO((enum tree_code code, ...))
  2796. {
  2797. #ifndef __STDC__
  2798.   enum tree_code code;
  2799. #endif
  2800.   register struct obstack *ambient_obstack = expression_obstack;
  2801.   va_list p;
  2802.   register tree t;
  2803.   register int length;
  2804.   register int i;
  2805. #if defined (NEXT_SEMANTICS) || defined (NEXT_PDO)
  2806.   extern int doing_objc_thang;
  2807.   static int objc_compiler = -1;
  2808. #endif
  2809.  
  2810.   VA_START (p, code);
  2811.  
  2812. #ifndef __STDC__
  2813.   code = va_arg (p, enum tree_code);
  2814. #endif
  2815.  
  2816. #if defined (NEXT_SEMANTICS) || defined (NEXT_PDO)
  2817.   if (objc_compiler < 0)
  2818.     objc_compiler = strcmp (lang_identify (), "objc") ? 0 : 1;
  2819.   if (objc_compiler || !doing_objc_thang)
  2820. #endif
  2821.   expression_obstack = &temp_decl_obstack;
  2822.  
  2823.   t = make_node (code);
  2824.   length = tree_code_length[(int) code];
  2825.  
  2826.   for (i = 0; i < length; i++)
  2827.     TREE_OPERAND (t, i) = va_arg (p, tree);
  2828.  
  2829.   va_end (p);
  2830.   expression_obstack = ambient_obstack;
  2831.   return t;
  2832. }
  2833.  
  2834. #if 0
  2835. /* Commented out because this wants to be done very
  2836.    differently.  See cp-lex.c.  */
  2837. tree
  2838. build_op_identifier (op1, op2)
  2839.      tree op1, op2;
  2840. {
  2841.   register tree t = make_node (OP_IDENTIFIER);
  2842.   TREE_PURPOSE (t) = op1;
  2843.   TREE_VALUE (t) = op2;
  2844.   return t;
  2845. }
  2846. #endif
  2847.  
  2848. /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
  2849.    We do NOT enter this node in any sort of symbol table.
  2850.  
  2851.    layout_decl is used to set up the decl's storage layout.
  2852.    Other slots are initialized to 0 or null pointers.  */
  2853.  
  2854. tree
  2855. build_decl (code, name, type)
  2856.      enum tree_code code;
  2857.      tree name, type;
  2858. {
  2859.   register tree t;
  2860.  
  2861.   t = make_node (code);
  2862.  
  2863. /*  if (type == error_mark_node)
  2864.     type = integer_type_node; */
  2865. /* That is not done, deliberately, so that having error_mark_node
  2866.    as the type can suppress useless errors in the use of this variable.  */
  2867.  
  2868.   DECL_NAME (t) = name;
  2869.   DECL_ASSEMBLER_NAME (t) = name;
  2870.   TREE_TYPE (t) = type;
  2871.  
  2872.   if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
  2873.     layout_decl (t, 0);
  2874.   else if (code == FUNCTION_DECL)
  2875.     DECL_MODE (t) = FUNCTION_MODE;
  2876.  
  2877.   return t;
  2878. }
  2879.  
  2880. /* BLOCK nodes are used to represent the structure of binding contours
  2881.    and declarations, once those contours have been exited and their contents
  2882.    compiled.  This information is used for outputting debugging info.  */
  2883.  
  2884. tree
  2885. build_block (vars, tags, subblocks, supercontext, chain)
  2886.      tree vars, tags, subblocks, supercontext, chain;
  2887. {
  2888.   register tree block = make_node (BLOCK);
  2889.   BLOCK_VARS (block) = vars;
  2890.   BLOCK_TYPE_TAGS (block) = tags;
  2891.   BLOCK_SUBBLOCKS (block) = subblocks;
  2892.   BLOCK_SUPERCONTEXT (block) = supercontext;
  2893.   BLOCK_CHAIN (block) = chain;
  2894.   return block;
  2895. }
  2896.  
  2897. /* Return a declaration like DDECL except that its DECL_MACHINE_ATTRIBUTE
  2898.    is ATTRIBUTE. */
  2899.  
  2900. tree
  2901. build_decl_attribute_variant (ddecl, attribute)
  2902.      tree ddecl, attribute;
  2903. {
  2904.   DECL_MACHINE_ATTRIBUTES (ddecl) = attribute;
  2905.   return ddecl;
  2906. }
  2907.  
  2908. /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
  2909.    is ATTRIBUTE.
  2910.  
  2911.    Record such modified types already made so we don't make duplicates.  */
  2912.  
  2913. tree
  2914. build_type_attribute_variant (ttype, attribute)
  2915.      tree ttype, attribute;
  2916. {
  2917.   if ( ! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
  2918.     {
  2919.       register int hashcode;
  2920.       register struct obstack *ambient_obstack = current_obstack;
  2921.       tree ntype;
  2922.  
  2923.       if (ambient_obstack != &permanent_obstack)
  2924.         current_obstack = TYPE_OBSTACK (ttype);
  2925.  
  2926.       ntype = copy_node (ttype);
  2927.       current_obstack = ambient_obstack;
  2928.  
  2929.       TYPE_POINTER_TO (ntype) = 0;
  2930.       TYPE_REFERENCE_TO (ntype) = 0;
  2931.       TYPE_ATTRIBUTES (ntype) = attribute;
  2932.  
  2933.       /* Create a new main variant of TYPE.  */
  2934.       TYPE_MAIN_VARIANT (ntype) = ntype;
  2935.       TYPE_NEXT_VARIANT (ntype) = 0;
  2936.       TYPE_READONLY (ntype) = TYPE_VOLATILE (ntype) = 0;
  2937.  
  2938.       hashcode = TYPE_HASH (TREE_CODE (ntype))
  2939.          + TYPE_HASH (TREE_TYPE (ntype))
  2940.          + attribute_hash_list (attribute);
  2941.  
  2942.       switch (TREE_CODE (ntype))
  2943.         {
  2944.       case FUNCTION_TYPE:
  2945.         hashcode += TYPE_HASH (TYPE_ARG_TYPES (ntype));
  2946.         break;
  2947.       case ARRAY_TYPE:
  2948.         hashcode += TYPE_HASH (TYPE_DOMAIN (ntype));
  2949.         break;
  2950.       case INTEGER_TYPE:
  2951.         hashcode += TYPE_HASH (TYPE_MAX_VALUE (ntype));
  2952.         break;
  2953.       case REAL_TYPE:
  2954.         hashcode += TYPE_HASH (TYPE_PRECISION (ntype));
  2955.         break;
  2956.         }
  2957.  
  2958.       ntype = type_hash_canon (hashcode, ntype);
  2959.       ttype = build_type_variant (ntype, TYPE_READONLY (ttype),
  2960.                   TYPE_VOLATILE (ttype));
  2961.     }
  2962.  
  2963.   return ttype;
  2964. }
  2965.  
  2966. /* Return a 1 if ATTR_NAME and ATTR_ARGS is valid for either declaration DECL
  2967.    or type TYPE and 0 otherwise.  Validity is determined the configuration
  2968.    macros VALID_MACHINE_DECL_ATTRIBUTE and VALID_MACHINE_TYPE_ATTRIBUTE. */
  2969.  
  2970. int
  2971. valid_machine_attribute (attr_name, attr_args, decl, type)
  2972.      tree attr_name, attr_args;
  2973.      tree decl;
  2974.      tree type;
  2975. {
  2976.   int valid = 0;
  2977.   tree decl_attr_list = decl != 0 ? DECL_MACHINE_ATTRIBUTES (decl) : 0;
  2978.   tree type_attr_list = TYPE_ATTRIBUTES (type);
  2979.  
  2980.   if (TREE_CODE (attr_name) != IDENTIFIER_NODE)
  2981.     abort ();
  2982.  
  2983. #ifdef VALID_MACHINE_DECL_ATTRIBUTE
  2984.   if (decl != 0
  2985.       && VALID_MACHINE_DECL_ATTRIBUTE (decl, decl_attr_list, attr_name, attr_args))
  2986.     {
  2987.       tree attr = lookup_attribute (IDENTIFIER_POINTER (attr_name),
  2988.                     decl_attr_list);
  2989.  
  2990.       if (attr != NULL_TREE)
  2991.     {
  2992.       /* Override existing arguments.  Declarations are unique so we can
  2993.          modify this in place.  */
  2994.       TREE_VALUE (attr) = attr_args;
  2995.     }
  2996.       else
  2997.     {
  2998.       decl_attr_list = tree_cons (attr_name, attr_args, decl_attr_list);
  2999.       decl = build_decl_attribute_variant (decl, decl_attr_list);
  3000.     }
  3001.  
  3002.       valid = 1;
  3003.     }
  3004. #endif
  3005.  
  3006. #ifdef VALID_MACHINE_TYPE_ATTRIBUTE
  3007.   if (VALID_MACHINE_TYPE_ATTRIBUTE (type, type_attr_list, attr_name, attr_args))
  3008.     {
  3009.       tree attr = lookup_attribute (IDENTIFIER_POINTER (attr_name),
  3010.                     type_attr_list);
  3011.  
  3012.       if (attr != NULL_TREE)
  3013.     {
  3014.       /* Override existing arguments.
  3015.          ??? This currently works since attribute arguments are not
  3016.          included in `attribute_hash_list'.  Something more complicated
  3017.          may be needed in the future.  */
  3018.       TREE_VALUE (attr) = attr_args;
  3019.     }
  3020.       else
  3021.     {
  3022.       type_attr_list = tree_cons (attr_name, attr_args, type_attr_list);
  3023.       type = build_type_attribute_variant (type, type_attr_list);
  3024.     }
  3025.       if (decl != 0)
  3026.     TREE_TYPE (decl) = type;
  3027.       valid = 1;
  3028.     }
  3029.  
  3030.   /* Handle putting a type attribute on pointer-to-function-type by putting
  3031.      the attribute on the function type.  */
  3032.   else if (TREE_CODE (type) == POINTER_TYPE
  3033.        && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
  3034.        && VALID_MACHINE_TYPE_ATTRIBUTE (TREE_TYPE (type), type_attr_list,
  3035.                         attr_name, attr_args))
  3036.     {
  3037.       tree inner_type = TREE_TYPE (type);
  3038.       tree inner_attr_list = TYPE_ATTRIBUTES (inner_type);
  3039.       tree attr = lookup_attribute (IDENTIFIER_POINTER (attr_name),
  3040.                     type_attr_list);
  3041.  
  3042.       if (attr != NULL_TREE)
  3043.     TREE_VALUE (attr) = attr_args;
  3044.       else
  3045.     {
  3046.       inner_attr_list = tree_cons (attr_name, attr_args, inner_attr_list);
  3047.       inner_type = build_type_attribute_variant (inner_type,
  3048.                              inner_attr_list);
  3049.     }
  3050.  
  3051.       if (decl != 0)
  3052.     TREE_TYPE (decl) = build_pointer_type (inner_type);
  3053.  
  3054.       valid = 1;
  3055.     }
  3056. #endif
  3057.  
  3058.   return valid;
  3059. }
  3060.  
  3061. /* Return non-zero if IDENT is a valid name for attribute ATTR,
  3062.    or zero if not.
  3063.  
  3064.    We try both `text' and `__text__', ATTR may be either one.  */
  3065. /* ??? It might be a reasonable simplification to require ATTR to be only
  3066.    `text'.  One might then also require attribute lists to be stored in
  3067.    their canonicalized form.  */
  3068.  
  3069. int
  3070. is_attribute_p (attr, ident)
  3071.      char *attr;
  3072.      tree ident;
  3073. {
  3074.   int ident_len, attr_len;
  3075.   char *p;
  3076.  
  3077.   if (TREE_CODE (ident) != IDENTIFIER_NODE)
  3078.     return 0;
  3079.  
  3080.   if (strcmp (attr, IDENTIFIER_POINTER (ident)) == 0)
  3081.     return 1;
  3082.  
  3083.   p = IDENTIFIER_POINTER (ident);
  3084.   ident_len = strlen (p);
  3085.   attr_len = strlen (attr);
  3086.  
  3087.   /* If ATTR is `__text__', IDENT must be `text'; and vice versa.  */
  3088.   if (attr[0] == '_')
  3089.     {
  3090.       if (attr[1] != '_'
  3091.       || attr[attr_len - 2] != '_'
  3092.       || attr[attr_len - 1] != '_')
  3093.     abort ();
  3094.       if (ident_len == attr_len - 4
  3095.       && strncmp (attr + 2, p, attr_len - 4) == 0)
  3096.     return 1;
  3097.     }
  3098.   else
  3099.     {
  3100.       if (ident_len == attr_len + 4
  3101.       && p[0] == '_' && p[1] == '_'
  3102.       && p[ident_len - 2] == '_' && p[ident_len - 1] == '_'
  3103.       && strncmp (attr, p + 2, attr_len) == 0)
  3104.     return 1;
  3105.     }
  3106.  
  3107.   return 0;
  3108. }
  3109.  
  3110. /* Given an attribute name and a list of attributes, return a pointer to the
  3111.    attribute's list element if the attribute is part of the list, or NULL_TREE
  3112.    if not found.  */
  3113.  
  3114. tree
  3115. lookup_attribute (attr_name, list)
  3116.      char *attr_name;
  3117.      tree list;
  3118. {
  3119.   tree l;
  3120.  
  3121.   for (l = list; l; l = TREE_CHAIN (l))
  3122.     {
  3123.       if (TREE_CODE (TREE_PURPOSE (l)) != IDENTIFIER_NODE)
  3124.     abort ();
  3125.       if (is_attribute_p (attr_name, TREE_PURPOSE (l)))
  3126.     return l;
  3127.     }
  3128.  
  3129.   return NULL_TREE;
  3130. }
  3131.  
  3132. /* Return a type like TYPE except that its TYPE_READONLY is CONSTP
  3133.    and its TYPE_VOLATILE is VOLATILEP.
  3134.  
  3135.    Such variant types already made are recorded so that duplicates
  3136.    are not made.
  3137.  
  3138.    A variant types should never be used as the type of an expression.
  3139.    Always copy the variant information into the TREE_READONLY
  3140.    and TREE_THIS_VOLATILE of the expression, and then give the expression
  3141.    as its type the "main variant", the variant whose TYPE_READONLY
  3142.    and TYPE_VOLATILE are zero.  Use TYPE_MAIN_VARIANT to find the
  3143.    main variant.  */
  3144.  
  3145. tree
  3146. build_type_variant (type, constp, volatilep)
  3147.      tree type;
  3148.      int constp, volatilep;
  3149. {
  3150.   register tree t;
  3151.  
  3152.   /* Treat any nonzero argument as 1.  */
  3153.   constp = !!constp;
  3154.   volatilep = !!volatilep;
  3155.  
  3156.   /* Search the chain of variants to see if there is already one there just
  3157.      like the one we need to have.  If so, use that existing one.  We must
  3158.      preserve the TYPE_NAME, since there is code that depends on this.  */
  3159.  
  3160.   for (t = TYPE_MAIN_VARIANT(type); t; t = TYPE_NEXT_VARIANT (t))
  3161.     if (constp == TYPE_READONLY (t) && volatilep == TYPE_VOLATILE (t)
  3162.     && TYPE_NAME (t) == TYPE_NAME (type))
  3163.       return t;
  3164.  
  3165.   /* We need a new one.  */
  3166.  
  3167.   t = build_type_copy (type);
  3168.   TYPE_READONLY (t) = constp;
  3169.   TYPE_VOLATILE (t) = volatilep;
  3170.  
  3171.   return t;
  3172. }
  3173.  
  3174. /* Give TYPE a new main variant: NEW_MAIN.
  3175.    This is the right thing to do only when something else
  3176.    about TYPE is modified in place.  */
  3177.  
  3178. void
  3179. change_main_variant (type, new_main)
  3180.      tree type, new_main;
  3181. {
  3182.   tree t;
  3183.   tree omain = TYPE_MAIN_VARIANT (type);
  3184.  
  3185.   /* Remove TYPE from the TYPE_NEXT_VARIANT chain of its main variant.  */
  3186.   if (TYPE_NEXT_VARIANT (omain) == type)
  3187.     TYPE_NEXT_VARIANT (omain) = TYPE_NEXT_VARIANT (type);
  3188.   else
  3189.     for (t = TYPE_NEXT_VARIANT (omain); t && TYPE_NEXT_VARIANT (t);
  3190.      t = TYPE_NEXT_VARIANT (t))
  3191.       if (TYPE_NEXT_VARIANT (t) == type)
  3192.     {
  3193.       TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (type);
  3194.       break;
  3195.     }
  3196.  
  3197.   TYPE_MAIN_VARIANT (type) = new_main;
  3198.   TYPE_NEXT_VARIANT (type) = TYPE_NEXT_VARIANT (new_main);
  3199.   TYPE_NEXT_VARIANT (new_main) = type;
  3200. }
  3201.  
  3202. /* Create a new variant of TYPE, equivalent but distinct.
  3203.    This is so the caller can modify it.  */
  3204.  
  3205. tree
  3206. build_type_copy (type)
  3207.      tree type;
  3208. {
  3209.   register tree t, m = TYPE_MAIN_VARIANT (type);
  3210.   register struct obstack *ambient_obstack = current_obstack;
  3211.  
  3212.   current_obstack = TYPE_OBSTACK (type);
  3213.   t = copy_node (type);
  3214.   current_obstack = ambient_obstack;
  3215.  
  3216.   TYPE_POINTER_TO (t) = 0;
  3217.   TYPE_REFERENCE_TO (t) = 0;
  3218.  
  3219.   /* Add this type to the chain of variants of TYPE.  */
  3220.   TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
  3221.   TYPE_NEXT_VARIANT (m) = t;
  3222.  
  3223.   return t;
  3224. }
  3225.  
  3226. /* Hashing of types so that we don't make duplicates.
  3227.    The entry point is `type_hash_canon'.  */
  3228.  
  3229. /* Each hash table slot is a bucket containing a chain
  3230.    of these structures.  */
  3231.  
  3232. struct type_hash
  3233. {
  3234.   struct type_hash *next;    /* Next structure in the bucket.  */
  3235.   int hashcode;            /* Hash code of this type.  */
  3236.   tree type;            /* The type recorded here.  */
  3237. };
  3238.  
  3239. /* Now here is the hash table.  When recording a type, it is added
  3240.    to the slot whose index is the hash code mod the table size.
  3241.    Note that the hash table is used for several kinds of types
  3242.    (function types, array types and array index range types, for now).
  3243.    While all these live in the same table, they are completely independent,
  3244.    and the hash code is computed differently for each of these.  */
  3245.  
  3246. #define TYPE_HASH_SIZE 59
  3247. struct type_hash *type_hash_table[TYPE_HASH_SIZE];
  3248.  
  3249. /* Compute a hash code for a list of types (chain of TREE_LIST nodes
  3250.    with types in the TREE_VALUE slots), by adding the hash codes
  3251.    of the individual types.  */
  3252.  
  3253. int
  3254. type_hash_list (list)
  3255.      tree list;
  3256. {
  3257.   register int hashcode;
  3258.   register tree tail;
  3259.   for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
  3260.     hashcode += TYPE_HASH (TREE_VALUE (tail));
  3261.   return hashcode;
  3262. }
  3263.  
  3264. /* Look in the type hash table for a type isomorphic to TYPE.
  3265.    If one is found, return it.  Otherwise return 0.  */
  3266.  
  3267. tree
  3268. type_hash_lookup (hashcode, type)
  3269.      int hashcode;
  3270.      tree type;
  3271. {
  3272.   register struct type_hash *h;
  3273.   for (h = type_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
  3274.     if (h->hashcode == hashcode
  3275.     && TREE_CODE (h->type) == TREE_CODE (type)
  3276.     && TREE_TYPE (h->type) == TREE_TYPE (type)
  3277.         && attribute_list_equal (TYPE_ATTRIBUTES (h->type),
  3278.                    TYPE_ATTRIBUTES (type))
  3279.     && (TYPE_MAX_VALUE (h->type) == TYPE_MAX_VALUE (type)
  3280.         || tree_int_cst_equal (TYPE_MAX_VALUE (h->type),
  3281.                    TYPE_MAX_VALUE (type)))
  3282.     && (TYPE_MIN_VALUE (h->type) == TYPE_MIN_VALUE (type)
  3283.         || tree_int_cst_equal (TYPE_MIN_VALUE (h->type),
  3284.                    TYPE_MIN_VALUE (type)))
  3285.     /* Note that TYPE_DOMAIN is TYPE_ARG_TYPES for FUNCTION_TYPE.  */
  3286.     && (TYPE_DOMAIN (h->type) == TYPE_DOMAIN (type)
  3287.         || (TYPE_DOMAIN (h->type)
  3288.         && TREE_CODE (TYPE_DOMAIN (h->type)) == TREE_LIST
  3289.         && TYPE_DOMAIN (type)
  3290.         && TREE_CODE (TYPE_DOMAIN (type)) == TREE_LIST
  3291.         && type_list_equal (TYPE_DOMAIN (h->type),
  3292.                     TYPE_DOMAIN (type)))))
  3293.       return h->type;
  3294.   return 0;
  3295. }
  3296.  
  3297. /* Add an entry to the type-hash-table
  3298.    for a type TYPE whose hash code is HASHCODE.  */
  3299.  
  3300. void
  3301. type_hash_add (hashcode, type)
  3302.      int hashcode;
  3303.      tree type;
  3304. {
  3305.   register struct type_hash *h;
  3306.  
  3307.   h = (struct type_hash *) oballoc (sizeof (struct type_hash));
  3308.   h->hashcode = hashcode;
  3309.   h->type = type;
  3310.   h->next = type_hash_table[hashcode % TYPE_HASH_SIZE];
  3311.   type_hash_table[hashcode % TYPE_HASH_SIZE] = h;
  3312. }
  3313.  
  3314. /* Given TYPE, and HASHCODE its hash code, return the canonical
  3315.    object for an identical type if one already exists.
  3316.    Otherwise, return TYPE, and record it as the canonical object
  3317.    if it is a permanent object.
  3318.  
  3319.    To use this function, first create a type of the sort you want.
  3320.    Then compute its hash code from the fields of the type that
  3321.    make it different from other similar types.
  3322.    Then call this function and use the value.
  3323.    This function frees the type you pass in if it is a duplicate.  */
  3324.  
  3325. /* Set to 1 to debug without canonicalization.  Never set by program.  */
  3326. int debug_no_type_hash = 0;
  3327.  
  3328. tree
  3329. type_hash_canon (hashcode, type)
  3330.      int hashcode;
  3331.      tree type;
  3332. {
  3333.   tree t1;
  3334.  
  3335.   if (debug_no_type_hash)
  3336.     return type;
  3337.  
  3338.   t1 = type_hash_lookup (hashcode, type);
  3339.   if (t1 != 0)
  3340.     {
  3341.       obstack_free (TYPE_OBSTACK (type), type);
  3342. #ifdef GATHER_STATISTICS
  3343.       tree_node_counts[(int)t_kind]--;
  3344.       tree_node_sizes[(int)t_kind] -= sizeof (struct tree_type);
  3345. #endif
  3346.       return t1;
  3347.     }
  3348.  
  3349.   /* If this is a permanent type, record it for later reuse.  */
  3350.   if (TREE_PERMANENT (type))
  3351.     type_hash_add (hashcode, type);
  3352.  
  3353.   return type;
  3354. }
  3355.  
  3356. /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
  3357.    with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
  3358.    by adding the hash codes of the individual attributes.  */
  3359.  
  3360. int
  3361. attribute_hash_list (list)
  3362.      tree list;
  3363. {
  3364.   register int hashcode;
  3365.   register tree tail;
  3366.   for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
  3367.     /* ??? Do we want to add in TREE_VALUE too? */
  3368.     hashcode += TYPE_HASH (TREE_PURPOSE (tail));
  3369.   return hashcode;
  3370. }
  3371.  
  3372. /* Given two lists of attributes, return true if list l2 is
  3373.    equivalent to l1.  */
  3374.  
  3375. int
  3376. attribute_list_equal (l1, l2)
  3377.      tree l1, l2;
  3378. {
  3379.    return attribute_list_contained (l1, l2)
  3380.       && attribute_list_contained (l2, l1);
  3381. }
  3382.  
  3383. /* Given two lists of attributes, return true if list L2 is
  3384.    completely contained within L1.  */
  3385. /* ??? This would be faster if attribute names were stored in a canonicalized
  3386.    form.  Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
  3387.    must be used to show these elements are equivalent (which they are).  */
  3388. /* ??? It's not clear that attributes with arguments will always be handled
  3389.    correctly.  */
  3390.  
  3391. int
  3392. attribute_list_contained (l1, l2)
  3393.      tree l1, l2;
  3394. {
  3395.   register tree t1, t2;
  3396.  
  3397.   /* First check the obvious, maybe the lists are identical.  */
  3398.   if (l1 == l2)
  3399.      return 1;
  3400.  
  3401.   /* Maybe the lists are similar.  */
  3402.   for (t1 = l1, t2 = l2;
  3403.        t1 && t2
  3404.         && TREE_PURPOSE (t1) == TREE_PURPOSE (t2)
  3405.         && TREE_VALUE (t1) == TREE_VALUE (t2);
  3406.        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2));
  3407.  
  3408.   /* Maybe the lists are equal.  */
  3409.   if (t1 == 0 && t2 == 0)
  3410.      return 1;
  3411.  
  3412.   for (; t2; t2 = TREE_CHAIN (t2))
  3413.     {
  3414.       tree attr
  3415.     = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)), l1);
  3416.  
  3417.       if (attr == NULL_TREE)
  3418.     return 0;
  3419.       if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) != 1)
  3420.     return 0;
  3421.     }
  3422.  
  3423.   return 1;
  3424. }
  3425.  
  3426. /* Given two lists of types
  3427.    (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
  3428.    return 1 if the lists contain the same types in the same order.
  3429.    Also, the TREE_PURPOSEs must match.  */
  3430.  
  3431. int
  3432. type_list_equal (l1, l2)
  3433.      tree l1, l2;
  3434. {
  3435.   register tree t1, t2;
  3436.  
  3437.   for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
  3438.     if (TREE_VALUE (t1) != TREE_VALUE (t2)
  3439.     || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
  3440.         && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
  3441.           && (TREE_TYPE (TREE_PURPOSE (t1))
  3442.               == TREE_TYPE (TREE_PURPOSE (t2))))))
  3443.       return 0;
  3444.  
  3445.   return t1 == t2;
  3446. }
  3447.  
  3448. /* Nonzero if integer constants T1 and T2
  3449.    represent the same constant value.  */
  3450.  
  3451. int
  3452. tree_int_cst_equal (t1, t2)
  3453.      tree t1, t2;
  3454. {
  3455.   if (t1 == t2)
  3456.     return 1;
  3457.   if (t1 == 0 || t2 == 0)
  3458.     return 0;
  3459.   if (TREE_CODE (t1) == INTEGER_CST
  3460.       && TREE_CODE (t2) == INTEGER_CST
  3461.       && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
  3462.       && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
  3463.     return 1;
  3464.   return 0;
  3465. }
  3466.  
  3467. /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
  3468.    The precise way of comparison depends on their data type.  */
  3469.  
  3470. int
  3471. tree_int_cst_lt (t1, t2)
  3472.      tree t1, t2;
  3473. {
  3474.   if (t1 == t2)
  3475.     return 0;
  3476.  
  3477.   if (!TREE_UNSIGNED (TREE_TYPE (t1)))
  3478.     return INT_CST_LT (t1, t2);
  3479.   return INT_CST_LT_UNSIGNED (t1, t2);
  3480. }
  3481.  
  3482. /* Return an indication of the sign of the integer constant T.
  3483.    The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
  3484.    Note that -1 will never be returned it T's type is unsigned.  */
  3485.  
  3486. int
  3487. tree_int_cst_sgn (t)
  3488.      tree t;
  3489. {
  3490.   if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0)
  3491.     return 0;
  3492.   else if (TREE_UNSIGNED (TREE_TYPE (t)))
  3493.     return 1;
  3494.   else if (TREE_INT_CST_HIGH (t) < 0)
  3495.     return -1;
  3496.   else
  3497.     return 1;
  3498. }
  3499.  
  3500. /* Compare two constructor-element-type constants.  Return 1 if the lists
  3501.    are known to be equal; otherwise return 0.  */
  3502.  
  3503. int
  3504. simple_cst_list_equal (l1, l2)
  3505.      tree l1, l2;
  3506. {
  3507.   while (l1 != NULL_TREE && l2 != NULL_TREE)
  3508.     {
  3509.       if (simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2)) != 1)
  3510.     return 0;
  3511.  
  3512.       l1 = TREE_CHAIN (l1);
  3513.       l2 = TREE_CHAIN (l2);
  3514.     }
  3515.  
  3516.   return (l1 == l2);
  3517. }
  3518.  
  3519. /* Return truthvalue of whether T1 is the same tree structure as T2.
  3520.    Return 1 if they are the same.
  3521.    Return 0 if they are understandably different.
  3522.    Return -1 if either contains tree structure not understood by
  3523.    this function.  */
  3524.  
  3525. int
  3526. simple_cst_equal (t1, t2)
  3527.      tree t1, t2;
  3528. {
  3529.   register enum tree_code code1, code2;
  3530.   int cmp;
  3531.  
  3532.   if (t1 == t2)
  3533.     return 1;
  3534.   if (t1 == 0 || t2 == 0)
  3535.     return 0;
  3536.  
  3537.   code1 = TREE_CODE (t1);
  3538.   code2 = TREE_CODE (t2);
  3539.  
  3540.   if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
  3541.     if (code2 == NOP_EXPR || code2 == CONVERT_EXPR || code2 == NON_LVALUE_EXPR)
  3542.       return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  3543.     else
  3544.       return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
  3545.   else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
  3546.        || code2 == NON_LVALUE_EXPR)
  3547.     return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
  3548.  
  3549.   if (code1 != code2)
  3550.     return 0;
  3551.  
  3552.   switch (code1)
  3553.     {
  3554.     case INTEGER_CST:
  3555.       return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
  3556.     && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
  3557.  
  3558.     case REAL_CST:
  3559.       return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
  3560.  
  3561.     case STRING_CST:
  3562.       return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
  3563.     && !bcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
  3564.           TREE_STRING_LENGTH (t1));
  3565.  
  3566.     case CONSTRUCTOR:
  3567.       abort ();
  3568.  
  3569.     case SAVE_EXPR:
  3570.       return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  3571.  
  3572.     case CALL_EXPR:
  3573.       cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  3574.       if (cmp <= 0)
  3575.     return cmp;
  3576.       return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
  3577.  
  3578.     case TARGET_EXPR:
  3579.       /* Special case: if either target is an unallocated VAR_DECL,
  3580.      it means that it's going to be unified with whatever the
  3581.      TARGET_EXPR is really supposed to initialize, so treat it
  3582.      as being equivalent to anything.  */
  3583.       if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
  3584.        && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
  3585.        && DECL_RTL (TREE_OPERAND (t1, 0)) == 0)
  3586.       || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
  3587.           && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
  3588.           && DECL_RTL (TREE_OPERAND (t2, 0)) == 0))
  3589.     cmp = 1;
  3590.       else
  3591.     cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  3592.       if (cmp <= 0)
  3593.     return cmp;
  3594.       return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
  3595.  
  3596.     case WITH_CLEANUP_EXPR:
  3597.       cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  3598.       if (cmp <= 0)
  3599.     return cmp;
  3600.       return simple_cst_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t1, 2));
  3601.  
  3602.     case COMPONENT_REF:
  3603.       if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
  3604.     return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  3605.       return 0;
  3606.  
  3607.     case VAR_DECL:
  3608.     case PARM_DECL:
  3609.     case CONST_DECL:
  3610.     case FUNCTION_DECL:
  3611.       return 0;
  3612.     }
  3613.  
  3614.   /* This general rule works for most tree codes.  All exceptions should be
  3615.      handled above.  If this is a language-specific tree code, we can't
  3616.      trust what might be in the operand, so say we don't know
  3617.      the situation.  */
  3618.   if ((int) code1
  3619.       >= sizeof standard_tree_code_type / sizeof standard_tree_code_type[0])
  3620.     return -1;
  3621.  
  3622.   switch (TREE_CODE_CLASS (code1))
  3623.     {
  3624.       int i;
  3625.     case '1':
  3626.     case '2':
  3627.     case '<':
  3628.     case 'e':
  3629.     case 'r':
  3630.     case 's':
  3631.       cmp = 1;
  3632.       for (i=0; i<tree_code_length[(int) code1]; ++i)
  3633.     {
  3634.       cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
  3635.       if (cmp <= 0)
  3636.         return cmp;
  3637.     }
  3638.       return cmp;
  3639.     }
  3640.  
  3641.   return -1;
  3642. }
  3643.  
  3644. /* Constructors for pointer, array and function types.
  3645.    (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
  3646.    constructed by language-dependent code, not here.)  */
  3647.  
  3648. /* Construct, lay out and return the type of pointers to TO_TYPE.
  3649.    If such a type has already been constructed, reuse it.  */
  3650.  
  3651. tree
  3652. build_pointer_type (to_type)
  3653.      tree to_type;
  3654. {
  3655.   register tree t = TYPE_POINTER_TO (to_type);
  3656.  
  3657.   /* First, if we already have a type for pointers to TO_TYPE, use it.  */
  3658.  
  3659.   if (t)
  3660.     return t;
  3661.  
  3662.   /* We need a new one.  Put this in the same obstack as TO_TYPE.   */
  3663.   push_obstacks (TYPE_OBSTACK (to_type), TYPE_OBSTACK (to_type));
  3664.   t = make_node (POINTER_TYPE);
  3665.   pop_obstacks ();
  3666.  
  3667.   TREE_TYPE (t) = to_type;
  3668.  
  3669.   /* Record this type as the pointer to TO_TYPE.  */
  3670.   TYPE_POINTER_TO (to_type) = t;
  3671.  
  3672.   /* Lay out the type.  This function has many callers that are concerned
  3673.      with expression-construction, and this simplifies them all.
  3674.      Also, it guarantees the TYPE_SIZE is in the same obstack as the type.  */
  3675.   layout_type (t);
  3676.  
  3677.   return t;
  3678. }
  3679.  
  3680. /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
  3681.    MAXVAL should be the maximum value in the domain
  3682.    (one less than the length of the array).  */
  3683.  
  3684. tree
  3685. build_index_type (maxval)
  3686.      tree maxval;
  3687. {
  3688.   register tree itype = make_node (INTEGER_TYPE);
  3689.   TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
  3690.   TYPE_MIN_VALUE (itype) = build_int_2 (0, 0);
  3691.   TREE_TYPE (TYPE_MIN_VALUE (itype)) = sizetype;
  3692.   TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);
  3693.   TYPE_MODE (itype) = TYPE_MODE (sizetype);
  3694.   TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
  3695.   TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
  3696.   if (TREE_CODE (maxval) == INTEGER_CST)
  3697.     {
  3698.       int maxint = (int) TREE_INT_CST_LOW (maxval);
  3699.       /* If the domain should be empty, make sure the maxval
  3700.      remains -1 and is not spoiled by truncation.  */
  3701.       if (INT_CST_LT (maxval, integer_zero_node))
  3702.     {
  3703.       TYPE_MAX_VALUE (itype) = build_int_2 (-1, -1);
  3704.       TREE_TYPE (TYPE_MAX_VALUE (itype)) = sizetype;
  3705.     }
  3706.       return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype);
  3707.     }
  3708.   else
  3709.     return itype;
  3710. }
  3711.  
  3712. /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
  3713.    ENUMERAL_TYPE, BOOLEAN_TYPE, or CHAR_TYPE), with
  3714.    low bound LOWVAL and high bound HIGHVAL.
  3715.    if TYPE==NULL_TREE, sizetype is used. */
  3716.  
  3717. tree
  3718. build_range_type (type, lowval, highval)
  3719.      tree type, lowval, highval;
  3720. {
  3721.   register tree itype = make_node (INTEGER_TYPE);
  3722.   TREE_TYPE (itype) = type;
  3723.   if (type == NULL_TREE)
  3724.     type = sizetype;
  3725.   TYPE_PRECISION (itype) = TYPE_PRECISION (type);
  3726.   TYPE_MIN_VALUE (itype) = convert (type, lowval);
  3727.   TYPE_MAX_VALUE (itype) = convert (type, highval);
  3728.   TYPE_MODE (itype) = TYPE_MODE (type);
  3729.   TYPE_SIZE (itype) = TYPE_SIZE (type);
  3730.   TYPE_ALIGN (itype) = TYPE_ALIGN (type);
  3731.   if ((TREE_CODE (lowval) == INTEGER_CST)
  3732.       && (TREE_CODE (highval) == INTEGER_CST))
  3733.     {
  3734.       HOST_WIDE_INT highint = TREE_INT_CST_LOW (highval);
  3735.       HOST_WIDE_INT lowint = TREE_INT_CST_LOW (lowval);
  3736.       int maxint = (int) (highint - lowint);
  3737.       return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype);
  3738.     }
  3739.   else
  3740.     return itype;
  3741. }
  3742.  
  3743. /* Just like build_index_type, but takes lowval and highval instead
  3744.    of just highval (maxval). */
  3745.  
  3746. tree
  3747. build_index_2_type (lowval,highval)
  3748.      tree lowval, highval;
  3749. {
  3750.   return build_range_type (NULL_TREE, lowval, highval);
  3751. }
  3752.  
  3753. /* Return nonzero iff ITYPE1 and ITYPE2 are equal (in the LISP sense).
  3754.    Needed because when index types are not hashed, equal index types
  3755.    built at different times appear distinct, even though structurally,
  3756.    they are not.  */
  3757.  
  3758. int
  3759. index_type_equal (itype1, itype2)
  3760.      tree itype1, itype2;
  3761. {
  3762.   if (TREE_CODE (itype1) != TREE_CODE (itype2))
  3763.     return 0;
  3764.   if (TREE_CODE (itype1) == INTEGER_TYPE)
  3765.     {
  3766.       if (TYPE_PRECISION (itype1) != TYPE_PRECISION (itype2)
  3767.       || TYPE_MODE (itype1) != TYPE_MODE (itype2)
  3768.       || simple_cst_equal (TYPE_SIZE (itype1), TYPE_SIZE (itype2)) != 1
  3769.       || TYPE_ALIGN (itype1) != TYPE_ALIGN (itype2))
  3770.     return 0;
  3771.       if (1 == simple_cst_equal (TYPE_MIN_VALUE (itype1),
  3772.                  TYPE_MIN_VALUE (itype2))
  3773.       && 1 == simple_cst_equal (TYPE_MAX_VALUE (itype1),
  3774.                     TYPE_MAX_VALUE (itype2)))
  3775.     return 1;
  3776.     }
  3777.  
  3778.   return 0;
  3779. }
  3780.  
  3781. /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
  3782.    and number of elements specified by the range of values of INDEX_TYPE.
  3783.    If such a type has already been constructed, reuse it.  */
  3784.  
  3785. tree
  3786. build_array_type (elt_type, index_type)
  3787.      tree elt_type, index_type;
  3788. {
  3789.   register tree t;
  3790.   int hashcode;
  3791.  
  3792.   if (TREE_CODE (elt_type) == FUNCTION_TYPE)
  3793.     {
  3794.       error ("arrays of functions are not meaningful");
  3795.       elt_type = integer_type_node;
  3796.     }
  3797.  
  3798.   /* Make sure TYPE_POINTER_TO (elt_type) is filled in.  */
  3799.   build_pointer_type (elt_type);
  3800.  
  3801.   /* Allocate the array after the pointer type,
  3802.      in case we free it in type_hash_canon.  */
  3803.   t = make_node (ARRAY_TYPE);
  3804.   TREE_TYPE (t) = elt_type;
  3805.   TYPE_DOMAIN (t) = index_type;
  3806.  
  3807.   if (index_type == 0)
  3808.     {
  3809.       return t;
  3810.     }
  3811.  
  3812.   hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type);
  3813.   t = type_hash_canon (hashcode, t);
  3814.  
  3815. #if 0 /* This led to crashes, because it could put a temporary node
  3816.      on the TYPE_NEXT_VARIANT chain of a permanent one.  */
  3817.   /* The main variant of an array type should always
  3818.      be an array whose element type is the main variant.  */
  3819.   if (elt_type != TYPE_MAIN_VARIANT (elt_type))
  3820.     change_main_variant (t, build_array_type (TYPE_MAIN_VARIANT (elt_type),
  3821.                           index_type));
  3822. #endif
  3823.  
  3824.   if (TYPE_SIZE (t) == 0)
  3825.     layout_type (t);
  3826.   return t;
  3827. }
  3828.  
  3829. /* Construct, lay out and return
  3830.    the type of functions returning type VALUE_TYPE
  3831.    given arguments of types ARG_TYPES.
  3832.    ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
  3833.    are data type nodes for the arguments of the function.
  3834.    If such a type has already been constructed, reuse it.  */
  3835.  
  3836. tree
  3837. build_function_type (value_type, arg_types)
  3838.      tree value_type, arg_types;
  3839. {
  3840.   register tree t;
  3841.   int hashcode;
  3842.  
  3843.   if (TREE_CODE (value_type) == FUNCTION_TYPE)
  3844.     {
  3845.       error ("function return type cannot be function");
  3846.       value_type = integer_type_node;
  3847.     }
  3848.  
  3849.   /* Make a node of the sort we want.  */
  3850.   t = make_node (FUNCTION_TYPE);
  3851.   TREE_TYPE (t) = value_type;
  3852.   TYPE_ARG_TYPES (t) = arg_types;
  3853.  
  3854.   /* If we already have such a type, use the old one and free this one.  */
  3855.   hashcode = TYPE_HASH (value_type) + type_hash_list (arg_types);
  3856.   t = type_hash_canon (hashcode, t);
  3857.  
  3858.   if (TYPE_SIZE (t) == 0)
  3859.     layout_type (t);
  3860.   return t;
  3861. }
  3862.  
  3863. /* Build the node for the type of references-to-TO_TYPE.  */
  3864.  
  3865. tree
  3866. build_reference_type (to_type)
  3867.      tree to_type;
  3868. {
  3869.   register tree t = TYPE_REFERENCE_TO (to_type);
  3870.   register struct obstack *ambient_obstack = current_obstack;
  3871.   register struct obstack *ambient_saveable_obstack = saveable_obstack;
  3872.  
  3873.   /* First, if we already have a type for pointers to TO_TYPE, use it.  */
  3874.  
  3875.   if (t)
  3876.     return t;
  3877.  
  3878.   /* We need a new one.  If TO_TYPE is permanent, make this permanent too.  */
  3879.   if (TREE_PERMANENT (to_type))
  3880.     {
  3881.       current_obstack = &permanent_obstack;
  3882.       saveable_obstack = &permanent_obstack;
  3883.     }
  3884.  
  3885.   t = make_node (REFERENCE_TYPE);
  3886.   TREE_TYPE (t) = to_type;
  3887.  
  3888.   /* Record this type as the pointer to TO_TYPE.  */
  3889.   TYPE_REFERENCE_TO (to_type) = t;
  3890.  
  3891.   layout_type (t);
  3892.  
  3893.   current_obstack = ambient_obstack;
  3894.   saveable_obstack = ambient_saveable_obstack;
  3895.   return t;
  3896. }
  3897.  
  3898. /* Construct, lay out and return the type of methods belonging to class
  3899.    BASETYPE and whose arguments and values are described by TYPE.
  3900.    If that type exists already, reuse it.
  3901.    TYPE must be a FUNCTION_TYPE node.  */
  3902.  
  3903. tree
  3904. build_method_type (basetype, type)
  3905.      tree basetype, type;
  3906. {
  3907.   register tree t;
  3908.   int hashcode;
  3909.  
  3910.   /* Make a node of the sort we want.  */
  3911.   t = make_node (METHOD_TYPE);
  3912.  
  3913.   if (TREE_CODE (type) != FUNCTION_TYPE)
  3914.     abort ();
  3915.  
  3916.   TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
  3917.   TREE_TYPE (t) = TREE_TYPE (type);
  3918.  
  3919.   /* The actual arglist for this function includes a "hidden" argument
  3920.      which is "this".  Put it into the list of argument types.  */
  3921.  
  3922.   TYPE_ARG_TYPES (t)
  3923.     = tree_cons (NULL_TREE,
  3924.          build_pointer_type (basetype), TYPE_ARG_TYPES (type));
  3925.  
  3926.   /* If we already have such a type, use the old one and free this one.  */
  3927.   hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
  3928.   t = type_hash_canon (hashcode, t);
  3929.  
  3930.   if (TYPE_SIZE (t) == 0)
  3931.     layout_type (t);
  3932.  
  3933.   return t;
  3934. }
  3935.  
  3936. /* Construct, lay out and return the type of offsets to a value
  3937.    of type TYPE, within an object of type BASETYPE.
  3938.    If a suitable offset type exists already, reuse it.  */
  3939.  
  3940. tree
  3941. build_offset_type (basetype, type)
  3942.      tree basetype, type;
  3943. {
  3944.   register tree t;
  3945.   int hashcode;
  3946.  
  3947.   /* Make a node of the sort we want.  */
  3948.   t = make_node (OFFSET_TYPE);
  3949.  
  3950.   TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
  3951.   TREE_TYPE (t) = type;
  3952.  
  3953.   /* If we already have such a type, use the old one and free this one.  */
  3954.   hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
  3955.   t = type_hash_canon (hashcode, t);
  3956.  
  3957.   if (TYPE_SIZE (t) == 0)
  3958.     layout_type (t);
  3959.  
  3960.   return t;
  3961. }
  3962.  
  3963. /* Create a complex type whose components are COMPONENT_TYPE.  */
  3964.  
  3965. tree
  3966. build_complex_type (component_type)
  3967.      tree component_type;
  3968. {
  3969.   register tree t;
  3970.   int hashcode;
  3971.  
  3972.   /* Make a node of the sort we want.  */
  3973.   t = make_node (COMPLEX_TYPE);
  3974.  
  3975.   TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
  3976.   TYPE_VOLATILE (t) = TYPE_VOLATILE (component_type);
  3977.   TYPE_READONLY (t) = TYPE_READONLY (component_type);
  3978.  
  3979.   /* If we already have such a type, use the old one and free this one.  */
  3980.   hashcode = TYPE_HASH (component_type);
  3981.   t = type_hash_canon (hashcode, t);
  3982.  
  3983.   if (TYPE_SIZE (t) == 0)
  3984.     layout_type (t);
  3985.  
  3986.   return t;
  3987. }
  3988.  
  3989. /* Return OP, stripped of any conversions to wider types as much as is safe.
  3990.    Converting the value back to OP's type makes a value equivalent to OP.
  3991.  
  3992.    If FOR_TYPE is nonzero, we return a value which, if converted to
  3993.    type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
  3994.  
  3995.    If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
  3996.    narrowest type that can hold the value, even if they don't exactly fit.
  3997.    Otherwise, bit-field references are changed to a narrower type
  3998.    only if they can be fetched directly from memory in that type.
  3999.  
  4000.    OP must have integer, real or enumeral type.  Pointers are not allowed!
  4001.  
  4002.    There are some cases where the obvious value we could return
  4003.    would regenerate to OP if converted to OP's type, 
  4004.    but would not extend like OP to wider types.
  4005.    If FOR_TYPE indicates such extension is contemplated, we eschew such values.
  4006.    For example, if OP is (unsigned short)(signed char)-1,
  4007.    we avoid returning (signed char)-1 if FOR_TYPE is int,
  4008.    even though extending that to an unsigned short would regenerate OP,
  4009.    since the result of extending (signed char)-1 to (int)
  4010.    is different from (int) OP.  */
  4011.  
  4012. tree
  4013. get_unwidened (op, for_type)
  4014.      register tree op;
  4015.      tree for_type;
  4016. {
  4017.   /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension.  */
  4018.   /* TYPE_PRECISION is safe in place of type_precision since
  4019.      pointer types are not allowed.  */
  4020.   register tree type = TREE_TYPE (op);
  4021.   register unsigned final_prec
  4022.     = TYPE_PRECISION (for_type != 0 ? for_type : type);
  4023.   register int uns
  4024.     = (for_type != 0 && for_type != type
  4025.        && final_prec > TYPE_PRECISION (type)
  4026.        && TREE_UNSIGNED (type));
  4027.   register tree win = op;
  4028.  
  4029.   while (TREE_CODE (op) == NOP_EXPR)
  4030.     {
  4031.       register int bitschange
  4032.     = TYPE_PRECISION (TREE_TYPE (op))
  4033.       - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
  4034.  
  4035.       /* Truncations are many-one so cannot be removed.
  4036.      Unless we are later going to truncate down even farther.  */
  4037.       if (bitschange < 0
  4038.       && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
  4039.     break;
  4040.  
  4041.       /* See what's inside this conversion.  If we decide to strip it,
  4042.      we will set WIN.  */
  4043.       op = TREE_OPERAND (op, 0);
  4044.  
  4045.       /* If we have not stripped any zero-extensions (uns is 0),
  4046.      we can strip any kind of extension.
  4047.      If we have previously stripped a zero-extension,
  4048.      only zero-extensions can safely be stripped.
  4049.      Any extension can be stripped if the bits it would produce
  4050.      are all going to be discarded later by truncating to FOR_TYPE.  */
  4051.  
  4052.       if (bitschange > 0)
  4053.     {
  4054.       if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
  4055.         win = op;
  4056.       /* TREE_UNSIGNED says whether this is a zero-extension.
  4057.          Let's avoid computing it if it does not affect WIN
  4058.          and if UNS will not be needed again.  */
  4059.       if ((uns || TREE_CODE (op) == NOP_EXPR)
  4060.           && TREE_UNSIGNED (TREE_TYPE (op)))
  4061.         {
  4062.           uns = 1;
  4063.           win = op;
  4064.         }
  4065.     }
  4066.     }
  4067.  
  4068.   if (TREE_CODE (op) == COMPONENT_REF
  4069.       /* Since type_for_size always gives an integer type.  */
  4070.       && TREE_CODE (type) != REAL_TYPE)
  4071.     {
  4072.       unsigned innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
  4073.       type = type_for_size (innerprec, TREE_UNSIGNED (TREE_OPERAND (op, 1)));
  4074.  
  4075.       /* We can get this structure field in the narrowest type it fits in.
  4076.      If FOR_TYPE is 0, do this only for a field that matches the
  4077.      narrower type exactly and is aligned for it
  4078.      The resulting extension to its nominal type (a fullword type)
  4079.      must fit the same conditions as for other extensions.  */
  4080.  
  4081.       if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
  4082.       && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))
  4083.       && (! uns || final_prec <= innerprec
  4084.           || TREE_UNSIGNED (TREE_OPERAND (op, 1)))
  4085.       && type != 0)
  4086.     {
  4087.       win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
  4088.                TREE_OPERAND (op, 1));
  4089.       TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
  4090.       TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
  4091.       TREE_RAISES (win) = TREE_RAISES (op);
  4092.     }
  4093.     }
  4094.   return win;
  4095. }
  4096.  
  4097. /* Return OP or a simpler expression for a narrower value
  4098.    which can be sign-extended or zero-extended to give back OP.
  4099.    Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
  4100.    or 0 if the value should be sign-extended.  */
  4101.  
  4102. tree
  4103. get_narrower (op, unsignedp_ptr)
  4104.      register tree op;
  4105.      int *unsignedp_ptr;
  4106. {
  4107.   register int uns = 0;
  4108.   int first = 1;
  4109.   register tree win = op;
  4110.  
  4111.   while (TREE_CODE (op) == NOP_EXPR)
  4112.     {
  4113.       register int bitschange
  4114.     = TYPE_PRECISION (TREE_TYPE (op))
  4115.       - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
  4116.  
  4117.       /* Truncations are many-one so cannot be removed.  */
  4118.       if (bitschange < 0)
  4119.     break;
  4120.  
  4121.       /* See what's inside this conversion.  If we decide to strip it,
  4122.      we will set WIN.  */
  4123.       op = TREE_OPERAND (op, 0);
  4124.  
  4125.       if (bitschange > 0)
  4126.     {
  4127.       /* An extension: the outermost one can be stripped,
  4128.          but remember whether it is zero or sign extension.  */
  4129.       if (first)
  4130.         uns = TREE_UNSIGNED (TREE_TYPE (op));
  4131.       /* Otherwise, if a sign extension has been stripped,
  4132.          only sign extensions can now be stripped;
  4133.          if a zero extension has been stripped, only zero-extensions.  */
  4134.       else if (uns != TREE_UNSIGNED (TREE_TYPE (op)))
  4135.         break;
  4136.       first = 0;
  4137.     }
  4138.       else /* bitschange == 0 */
  4139.     {
  4140.       /* A change in nominal type can always be stripped, but we must
  4141.          preserve the unsignedness.  */
  4142.       if (first)
  4143.         uns = TREE_UNSIGNED (TREE_TYPE (op));
  4144.       first = 0;
  4145.     }
  4146.  
  4147.       win = op;
  4148.     }
  4149.  
  4150.   if (TREE_CODE (op) == COMPONENT_REF
  4151.       /* Since type_for_size always gives an integer type.  */
  4152.       && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE)
  4153.     {
  4154.       unsigned innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
  4155.       tree type = type_for_size (innerprec, TREE_UNSIGNED (op));
  4156.  
  4157.       /* We can get this structure field in a narrower type that fits it,
  4158.      but the resulting extension to its nominal type (a fullword type)
  4159.      must satisfy the same conditions as for other extensions.
  4160.  
  4161.      Do this only for fields that are aligned (not bit-fields),
  4162.      because when bit-field insns will be used there is no
  4163.      advantage in doing this.  */
  4164.  
  4165.       if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
  4166.       && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
  4167.       && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1)))
  4168.       && type != 0)
  4169.     {
  4170.       if (first)
  4171.         uns = TREE_UNSIGNED (TREE_OPERAND (op, 1));
  4172.       win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
  4173.                TREE_OPERAND (op, 1));
  4174.       TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
  4175.       TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
  4176.       TREE_RAISES (win) = TREE_RAISES (op);
  4177.     }
  4178.     }
  4179.   *unsignedp_ptr = uns;
  4180.   return win;
  4181. }
  4182.  
  4183. /* Return the precision of a type, for arithmetic purposes.
  4184.    Supports all types on which arithmetic is possible
  4185.    (including pointer types).
  4186.    It's not clear yet what will be right for complex types.  */
  4187.  
  4188. int
  4189. type_precision (type)
  4190.      register tree type;
  4191. {
  4192.   return ((TREE_CODE (type) == INTEGER_TYPE
  4193.        || TREE_CODE (type) == ENUMERAL_TYPE
  4194.        || TREE_CODE (type) == REAL_TYPE)
  4195.       ? TYPE_PRECISION (type) : POINTER_SIZE);
  4196. }
  4197.  
  4198. /* Nonzero if integer constant C has a value that is permissible
  4199.    for type TYPE (an INTEGER_TYPE).  */
  4200.  
  4201. int
  4202. int_fits_type_p (c, type)
  4203.      tree c, type;
  4204. {
  4205.   if (TREE_UNSIGNED (type))
  4206.     return (! (TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
  4207.            && INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type), c))
  4208.         && ! (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
  4209.           && INT_CST_LT_UNSIGNED (c, TYPE_MIN_VALUE (type))));
  4210.   else
  4211.     return (! (TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
  4212.            && INT_CST_LT (TYPE_MAX_VALUE (type), c))
  4213.         && ! (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
  4214.           && INT_CST_LT (c, TYPE_MIN_VALUE (type))));
  4215. }
  4216.  
  4217. /* Return the innermost context enclosing DECL that is
  4218.    a FUNCTION_DECL, or zero if none.  */
  4219.  
  4220. tree
  4221. decl_function_context (decl)
  4222.      tree decl;
  4223. {
  4224.   tree context;
  4225.  
  4226.   if (TREE_CODE (decl) == ERROR_MARK)
  4227.     return 0;
  4228.  
  4229. #ifdef METHOD_SEL_NAME
  4230.   if (TREE_CODE (decl) == INSTANCE_METHOD_DECL
  4231.       || TREE_CODE (decl) == CLASS_METHOD_DECL)
  4232.     return 0;
  4233. #endif
  4234.  
  4235.   if (TREE_CODE (decl) == SAVE_EXPR)
  4236.     context = SAVE_EXPR_CONTEXT (decl);
  4237.   else
  4238.     context = DECL_CONTEXT (decl);
  4239.  
  4240.   while (context && TREE_CODE (context) != FUNCTION_DECL)
  4241.     {
  4242.       if (TREE_CODE (context) == RECORD_TYPE
  4243.       || TREE_CODE (context) == UNION_TYPE)
  4244.     context = NULL_TREE;
  4245.       else if (TREE_CODE (context) == TYPE_DECL)
  4246.     context = DECL_CONTEXT (context);
  4247.       else if (TREE_CODE (context) == BLOCK)
  4248.     context = BLOCK_SUPERCONTEXT (context);
  4249.       else
  4250.     /* Unhandled CONTEXT !?  */
  4251.     abort ();
  4252.     }
  4253.  
  4254.   return context;
  4255. }
  4256.  
  4257. /* Return the innermost context enclosing DECL that is
  4258.    a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
  4259.    TYPE_DECLs and FUNCTION_DECLs are transparent to this function.  */
  4260.  
  4261. tree
  4262. decl_type_context (decl)
  4263.      tree decl;
  4264. {
  4265.   tree context = DECL_CONTEXT (decl);
  4266.  
  4267.   while (context)
  4268.     {
  4269.       if (TREE_CODE (context) == RECORD_TYPE
  4270.       || TREE_CODE (context) == UNION_TYPE
  4271.       || TREE_CODE (context) == QUAL_UNION_TYPE)
  4272.     return context;
  4273.       if (TREE_CODE (context) == TYPE_DECL
  4274.       || TREE_CODE (context) == FUNCTION_DECL)
  4275.     context = DECL_CONTEXT (context);
  4276.       else if (TREE_CODE (context) == BLOCK)
  4277.     context = BLOCK_SUPERCONTEXT (context);
  4278.       else
  4279.     /* Unhandled CONTEXT!?  */
  4280.     abort ();
  4281.     }
  4282.   return NULL_TREE;
  4283. }
  4284.  
  4285. void
  4286. print_obstack_statistics (str, o)
  4287.      char *str;
  4288.      struct obstack *o;
  4289. {
  4290.   struct _obstack_chunk *chunk = o->chunk;
  4291.   int n_chunks = 0;
  4292.   int n_alloc = 0;
  4293.  
  4294.   while (chunk)
  4295.     {
  4296.       n_chunks += 1;
  4297.       n_alloc += chunk->limit - &chunk->contents[0];
  4298.       chunk = chunk->prev;
  4299.     }
  4300.   fprintf (stderr, "obstack %s: %d bytes, %d chunks\n",
  4301.        str, n_alloc, n_chunks);
  4302. }
  4303. void
  4304. dump_tree_statistics ()
  4305. {
  4306.   int i;
  4307.   int total_nodes, total_bytes;
  4308.  
  4309.   fprintf (stderr, "\n??? tree nodes created\n\n");
  4310. #ifdef GATHER_STATISTICS
  4311.   fprintf (stderr, "Kind                  Nodes     Bytes\n");
  4312.   fprintf (stderr, "-------------------------------------\n");
  4313.   total_nodes = total_bytes = 0;
  4314.   for (i = 0; i < (int) all_kinds; i++)
  4315.     {
  4316.       fprintf (stderr, "%-20s %6d %9d\n", tree_node_kind_names[i],
  4317.            tree_node_counts[i], tree_node_sizes[i]);
  4318.       total_nodes += tree_node_counts[i];
  4319.       total_bytes += tree_node_sizes[i];
  4320.     }
  4321.   fprintf (stderr, "%-20s        %9d\n", "identifier names", id_string_size);
  4322.   fprintf (stderr, "-------------------------------------\n");
  4323.   fprintf (stderr, "%-20s %6d %9d\n", "Total", total_nodes, total_bytes);
  4324.   fprintf (stderr, "-------------------------------------\n");
  4325. #else
  4326.   fprintf (stderr, "(No per-node statistics)\n");
  4327. #endif
  4328.   print_lang_statistics ();
  4329. }
  4330.  
  4331. #define FILE_FUNCTION_PREFIX_LEN 9
  4332.  
  4333. #ifndef NO_DOLLAR_IN_LABEL
  4334. #define FILE_FUNCTION_FORMAT "_GLOBAL_$D$%s"
  4335. #else /* NO_DOLLAR_IN_LABEL */
  4336. #ifndef NO_DOT_IN_LABEL
  4337. #define FILE_FUNCTION_FORMAT "_GLOBAL_.D.%s"
  4338. #else /* NO_DOT_IN_LABEL */
  4339. #define FILE_FUNCTION_FORMAT "_GLOBAL__D_%s"
  4340. #endif    /* NO_DOT_IN_LABEL */
  4341. #endif    /* NO_DOLLAR_IN_LABEL */
  4342.  
  4343. extern char * first_global_object_name;
  4344.  
  4345. /* If KIND=='I', return a suitable global initializer (constructor) name.
  4346.    If KIND=='D', return a suitable global clean-up (destructor) name. */
  4347.  
  4348. tree
  4349. get_file_function_name (kind)
  4350.      int kind;
  4351. {
  4352.   char *buf;
  4353.   register char *p;
  4354.  
  4355.   if (first_global_object_name)
  4356.     p = first_global_object_name;
  4357.   else if (main_input_filename)
  4358.     p = main_input_filename;
  4359.   else
  4360.     p = input_filename;
  4361.  
  4362.   buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p));
  4363.  
  4364.   /* Set up the name of the file-level functions we may need.  */
  4365.   /* Use a global object (which is already required to be unique over
  4366.      the program) rather than the file name (which imposes extra
  4367.      constraints).  -- Raeburn@MIT.EDU, 10 Jan 1990.  */
  4368.   sprintf (buf, FILE_FUNCTION_FORMAT, p);
  4369.  
  4370.   /* Don't need to pull weird characters out of global names.  */
  4371.   if (p != first_global_object_name)
  4372.     {
  4373.       for (p = buf+11; *p; p++)
  4374.     if (! ((*p >= '0' && *p <= '9')
  4375. #if 0 /* we always want labels, which are valid C++ identifiers (+ `$') */
  4376. #ifndef ASM_IDENTIFY_GCC    /* this is required if `.' is invalid -- k. raeburn */
  4377.            || *p == '.'
  4378. #endif
  4379. #endif
  4380. #ifndef NO_DOLLAR_IN_LABEL    /* this for `$'; unlikely, but... -- kr */
  4381.            || *p == '$'
  4382. #endif
  4383. #ifndef NO_DOT_IN_LABEL        /* this for `.'; unlikely, but... */
  4384.            || *p == '.'
  4385. #endif
  4386.            || (*p >= 'A' && *p <= 'Z')
  4387.            || (*p >= 'a' && *p <= 'z')))
  4388.       *p = '_';
  4389.     }
  4390.  
  4391.   buf[FILE_FUNCTION_PREFIX_LEN] = kind;
  4392.  
  4393.   return get_identifier (buf);
  4394. }
  4395.  
  4396. /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
  4397.    The result is placed in BUFFER (which has length BIT_SIZE),
  4398.    with one bit in each char ('\000' or '\001').
  4399.  
  4400.    If the constructor is constant, NULL_TREE is returned.
  4401.    Otherwise, a TREE_LIST of the non-constant elements is emitted. */
  4402.  
  4403. tree
  4404. get_set_constructor_bits (init, buffer, bit_size)
  4405.      tree init;
  4406.      char *buffer;
  4407.      int bit_size;
  4408. {
  4409.   int i;
  4410.   tree vals;
  4411.   HOST_WIDE_INT domain_min
  4412.     = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (init))));
  4413.   tree non_const_bits = NULL_TREE;
  4414.   for (i = 0; i < bit_size; i++)
  4415.     buffer[i] = 0;
  4416.  
  4417.   for (vals = TREE_OPERAND (init, 1); 
  4418.        vals != NULL_TREE; vals = TREE_CHAIN (vals))
  4419.     {
  4420.       if (TREE_CODE (TREE_VALUE (vals)) != INTEGER_CST
  4421.       || (TREE_PURPOSE (vals) != NULL_TREE
  4422.           && TREE_CODE (TREE_PURPOSE (vals)) != INTEGER_CST))
  4423.     non_const_bits =
  4424.       tree_cons (TREE_PURPOSE (vals), TREE_VALUE (vals), non_const_bits);
  4425.       else if (TREE_PURPOSE (vals) != NULL_TREE)
  4426.     {
  4427.       /* Set a range of bits to ones. */
  4428.       HOST_WIDE_INT lo_index
  4429.         = TREE_INT_CST_LOW (TREE_PURPOSE (vals)) - domain_min;
  4430.       HOST_WIDE_INT hi_index
  4431.         = TREE_INT_CST_LOW (TREE_VALUE (vals)) - domain_min;
  4432.       if (lo_index < 0 || lo_index >= bit_size
  4433.         || hi_index < 0 || hi_index >= bit_size)
  4434.         abort ();
  4435.       for ( ; lo_index <= hi_index; lo_index++)
  4436.         buffer[lo_index] = 1;
  4437.     }
  4438.       else
  4439.     {
  4440.       /* Set a single bit to one. */
  4441.       HOST_WIDE_INT index
  4442.         = TREE_INT_CST_LOW (TREE_VALUE (vals)) - domain_min;
  4443.       if (index < 0 || index >= bit_size)
  4444.         {
  4445.           error ("invalid initializer for bit string");
  4446.           return NULL_TREE;
  4447.         }
  4448.       buffer[index] = 1;
  4449.     }
  4450.     }
  4451.   return non_const_bits;
  4452. }
  4453.  
  4454. /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
  4455.    The result is placed in BUFFER (which is an array of bytes).
  4456.    If the constructor is constant, NULL_TREE is returned.
  4457.    Otherwise, a TREE_LIST of the non-constant elements is emitted. */
  4458.  
  4459. tree
  4460. get_set_constructor_bytes (init, buffer, wd_size)
  4461.      tree init;
  4462.      unsigned char *buffer;
  4463.      int wd_size;
  4464. {
  4465.   int i;
  4466.   tree vals = TREE_OPERAND (init, 1);
  4467.   int set_word_size = BITS_PER_UNIT;
  4468.   int bit_size = wd_size * set_word_size;
  4469.   int bit_pos = 0;
  4470.   unsigned char *bytep = buffer;
  4471.   char *bit_buffer = (char*)alloca(bit_size);
  4472.   tree non_const_bits = get_set_constructor_bits (init, bit_buffer, bit_size);
  4473.  
  4474.   for (i = 0; i < wd_size; i++)
  4475.     buffer[i] = 0;
  4476.  
  4477.   for (i = 0; i < bit_size; i++)
  4478.     {
  4479.       if (bit_buffer[i])
  4480.     {
  4481.       if (BYTES_BIG_ENDIAN)
  4482.         *bytep |= (1 << (set_word_size - 1 - bit_pos));
  4483.       else
  4484.         *bytep |= 1 << bit_pos;
  4485.     }
  4486.       bit_pos++;
  4487.       if (bit_pos >= set_word_size)
  4488.     bit_pos = 0, bytep++;
  4489.     }
  4490.   return non_const_bits;
  4491. }
  4492.