1 /* Language-independent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987, 1988, 1992 Free Software Foundation, Inc.
4 This file is part of GNU CC.
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)
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.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This file contains the low level primitives for operating on tree nodes,
22 including allocation, list operations, interning of identifiers,
23 construction of data type nodes and statement nodes,
24 and construction of type conversion nodes. It also contains
25 tables index by tree code that describe how to take apart
28 It is intended to be language-independent, but occasionally
29 calls language-dependent routines defined (for C) in typecheck.c.
31 The low-level allocation routines oballoc and permalloc
32 are used also for allocating many other kinds of objects
33 by all passes of the compiler. */
43 #define obstack_chunk_alloc xmalloc
44 #define obstack_chunk_free free
46 /* Tree nodes of permanent duration are allocated in this obstack.
47 They are the identifier nodes, and everything outside of
48 the bodies and parameters of function definitions. */
50 struct obstack permanent_obstack;
52 /* The initial RTL, and all ..._TYPE nodes, in a function
53 are allocated in this obstack. Usually they are freed at the
54 end of the function, but if the function is inline they are saved.
55 For top-level functions, this is maybepermanent_obstack.
56 Separate obstacks are made for nested functions. */
58 struct obstack *function_maybepermanent_obstack;
60 /* This is the function_maybepermanent_obstack for top-level functions. */
62 struct obstack maybepermanent_obstack;
64 /* The contents of the current function definition are allocated
65 in this obstack, and all are freed at the end of the function.
66 For top-level functions, this is temporary_obstack.
67 Separate obstacks are made for nested functions. */
69 struct obstack *function_obstack;
71 /* This is used for reading initializers of global variables. */
73 struct obstack temporary_obstack;
75 /* The tree nodes of an expression are allocated
76 in this obstack, and all are freed at the end of the expression. */
78 struct obstack momentary_obstack;
80 /* The tree nodes of a declarator are allocated
81 in this obstack, and all are freed when the declarator
84 static struct obstack temp_decl_obstack;
86 /* This points at either permanent_obstack
87 or the current function_maybepermanent_obstack. */
89 struct obstack *saveable_obstack;
91 /* This is same as saveable_obstack during parse and expansion phase;
92 it points to the current function's obstack during optimization.
93 This is the obstack to be used for creating rtl objects. */
95 struct obstack *rtl_obstack;
97 /* This points at either permanent_obstack or the current function_obstack. */
99 struct obstack *current_obstack;
101 /* This points at either permanent_obstack or the current function_obstack
102 or momentary_obstack. */
104 struct obstack *expression_obstack;
106 /* Stack of obstack selections for push_obstacks and pop_obstacks. */
110 struct obstack_stack *next;
111 struct obstack *current;
112 struct obstack *saveable;
113 struct obstack *expression;
117 struct obstack_stack *obstack_stack;
119 /* Obstack for allocating struct obstack_stack entries. */
121 static struct obstack obstack_stack_obstack;
123 /* Addresses of first objects in some obstacks.
124 This is for freeing their entire contents. */
125 char *maybepermanent_firstobj;
126 char *temporary_firstobj;
127 char *momentary_firstobj;
128 char *temp_decl_firstobj;
130 /* Nonzero means all ..._TYPE nodes should be allocated permanently. */
132 int all_types_permanent;
134 /* Stack of places to restore the momentary obstack back to. */
136 struct momentary_level
138 /* Pointer back to previous such level. */
139 struct momentary_level *prev;
140 /* First object allocated within this level. */
142 /* Value of expression_obstack saved at entry to this level. */
143 struct obstack *obstack;
146 struct momentary_level *momentary_stack;
148 /* Table indexed by tree code giving a string containing a character
149 classifying the tree code. Possibilities are
150 t, d, s, c, r, <, 1, 2 and e. See tree.def for details. */
152 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
154 char *standard_tree_code_type[] = {
159 /* Table indexed by tree code giving number of expression
160 operands beyond the fixed part of the node structure.
161 Not used for types or decls. */
163 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
165 int standard_tree_code_length[] = {
170 /* Names of tree components.
171 Used for printing out the tree and error messages. */
172 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
174 char *standard_tree_code_name[] = {
179 /* Table indexed by tree code giving a string containing a character
180 classifying the tree code. Possibilities are
181 t, d, s, c, r, e, <, 1 and 2. See tree.def for details. */
183 char **tree_code_type;
185 /* Table indexed by tree code giving number of expression
186 operands beyond the fixed part of the node structure.
187 Not used for types or decls. */
189 int *tree_code_length;
191 /* Table indexed by tree code giving name of tree code, as a string. */
193 char **tree_code_name;
195 /* Statistics-gathering stuff. */
216 int tree_node_counts[(int)all_kinds];
217 int tree_node_sizes[(int)all_kinds];
218 int id_string_size = 0;
220 char *tree_node_kind_names[] = {
238 /* Hash table for uniquizing IDENTIFIER_NODEs by name. */
240 #define MAX_HASH_TABLE 1009
241 static tree hash_table[MAX_HASH_TABLE]; /* id hash buckets */
243 /* 0 while creating built-in identifiers. */
244 static int do_identifier_warnings;
246 /* Unique id for next decl created. */
247 static int next_decl_uid;
249 extern char *mode_name[];
251 void gcc_obstack_init ();
252 static tree stabilize_reference_1 ();
254 /* Init the principal obstacks. */
259 gcc_obstack_init (&obstack_stack_obstack);
260 gcc_obstack_init (&permanent_obstack);
262 gcc_obstack_init (&temporary_obstack);
263 temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0);
264 gcc_obstack_init (&momentary_obstack);
265 momentary_firstobj = (char *) obstack_alloc (&momentary_obstack, 0);
266 gcc_obstack_init (&maybepermanent_obstack);
267 maybepermanent_firstobj
268 = (char *) obstack_alloc (&maybepermanent_obstack, 0);
269 gcc_obstack_init (&temp_decl_obstack);
270 temp_decl_firstobj = (char *) obstack_alloc (&temp_decl_obstack, 0);
272 function_obstack = &temporary_obstack;
273 function_maybepermanent_obstack = &maybepermanent_obstack;
274 current_obstack = &permanent_obstack;
275 expression_obstack = &permanent_obstack;
276 rtl_obstack = saveable_obstack = &permanent_obstack;
278 /* Init the hash table of identifiers. */
279 bzero (hash_table, sizeof hash_table);
283 gcc_obstack_init (obstack)
284 struct obstack *obstack;
286 /* Let particular systems override the size of a chunk. */
287 #ifndef OBSTACK_CHUNK_SIZE
288 #define OBSTACK_CHUNK_SIZE 0
290 /* Let them override the alloc and free routines too. */
291 #ifndef OBSTACK_CHUNK_ALLOC
292 #define OBSTACK_CHUNK_ALLOC xmalloc
294 #ifndef OBSTACK_CHUNK_FREE
295 #define OBSTACK_CHUNK_FREE free
297 _obstack_begin (obstack, OBSTACK_CHUNK_SIZE, 0,
298 (void *(*) ()) OBSTACK_CHUNK_ALLOC,
299 (void (*) ()) OBSTACK_CHUNK_FREE);
302 /* Save all variables describing the current status into the structure *P.
303 This is used before starting a nested function. */
309 p->all_types_permanent = all_types_permanent;
310 p->momentary_stack = momentary_stack;
311 p->maybepermanent_firstobj = maybepermanent_firstobj;
312 p->momentary_firstobj = momentary_firstobj;
313 p->function_obstack = function_obstack;
314 p->function_maybepermanent_obstack = function_maybepermanent_obstack;
315 p->current_obstack = current_obstack;
316 p->expression_obstack = expression_obstack;
317 p->saveable_obstack = saveable_obstack;
318 p->rtl_obstack = rtl_obstack;
320 function_obstack = (struct obstack *) xmalloc (sizeof (struct obstack));
321 gcc_obstack_init (function_obstack);
323 function_maybepermanent_obstack
324 = (struct obstack *) xmalloc (sizeof (struct obstack));
325 gcc_obstack_init (function_maybepermanent_obstack);
327 current_obstack = &permanent_obstack;
328 expression_obstack = &permanent_obstack;
329 rtl_obstack = saveable_obstack = &permanent_obstack;
331 momentary_firstobj = (char *) obstack_finish (&momentary_obstack);
332 maybepermanent_firstobj
333 = (char *) obstack_finish (function_maybepermanent_obstack);
336 /* Restore all variables describing the current status from the structure *P.
337 This is used after a nested function. */
340 restore_tree_status (p)
343 all_types_permanent = p->all_types_permanent;
344 momentary_stack = p->momentary_stack;
346 obstack_free (&momentary_obstack, momentary_firstobj);
347 obstack_free (function_obstack, 0);
348 obstack_free (function_maybepermanent_obstack, 0);
349 free (function_obstack);
351 momentary_firstobj = p->momentary_firstobj;
352 maybepermanent_firstobj = p->maybepermanent_firstobj;
353 function_obstack = p->function_obstack;
354 function_maybepermanent_obstack = p->function_maybepermanent_obstack;
355 current_obstack = p->current_obstack;
356 expression_obstack = p->expression_obstack;
357 saveable_obstack = p->saveable_obstack;
358 rtl_obstack = p->rtl_obstack;
361 /* Start allocating on the temporary (per function) obstack.
362 This is done in start_function before parsing the function body,
363 and before each initialization at top level, and to go back
364 to temporary allocation after doing end_temporary_allocation. */
367 temporary_allocation ()
369 /* Note that function_obstack at top level points to temporary_obstack.
370 But within a nested function context, it is a separate obstack. */
371 current_obstack = function_obstack;
372 expression_obstack = function_obstack;
373 rtl_obstack = saveable_obstack = function_maybepermanent_obstack;
377 /* Start allocating on the permanent obstack but don't
378 free the temporary data. After calling this, call
379 `permanent_allocation' to fully resume permanent allocation status. */
382 end_temporary_allocation ()
384 current_obstack = &permanent_obstack;
385 expression_obstack = &permanent_obstack;
386 rtl_obstack = saveable_obstack = &permanent_obstack;
389 /* Resume allocating on the temporary obstack, undoing
390 effects of `end_temporary_allocation'. */
393 resume_temporary_allocation ()
395 current_obstack = function_obstack;
396 expression_obstack = function_obstack;
397 rtl_obstack = saveable_obstack = function_maybepermanent_obstack;
400 /* While doing temporary allocation, switch to allocating in such a
401 way as to save all nodes if the function is inlined. Call
402 resume_temporary_allocation to go back to ordinary temporary
406 saveable_allocation ()
408 /* Note that function_obstack at top level points to temporary_obstack.
409 But within a nested function context, it is a separate obstack. */
410 expression_obstack = current_obstack = saveable_obstack;
413 /* Switch to current obstack CURRENT and maybepermanent obstack SAVEABLE,
414 recording the previously current obstacks on a stack.
415 This does not free any storage in any obstack. */
418 push_obstacks (current, saveable)
419 struct obstack *current, *saveable;
421 struct obstack_stack *p
422 = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,
423 (sizeof (struct obstack_stack)));
425 p->current = current_obstack;
426 p->saveable = saveable_obstack;
427 p->expression = expression_obstack;
428 p->rtl = rtl_obstack;
429 p->next = obstack_stack;
432 current_obstack = current;
433 expression_obstack = current;
434 rtl_obstack = saveable_obstack = saveable;
437 /* Save the current set of obstacks, but don't change them. */
440 push_obstacks_nochange ()
442 struct obstack_stack *p
443 = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,
444 (sizeof (struct obstack_stack)));
446 p->current = current_obstack;
447 p->saveable = saveable_obstack;
448 p->expression = expression_obstack;
449 p->rtl = rtl_obstack;
450 p->next = obstack_stack;
454 /* Pop the obstack selection stack. */
459 struct obstack_stack *p = obstack_stack;
460 obstack_stack = p->next;
462 current_obstack = p->current;
463 saveable_obstack = p->saveable;
464 expression_obstack = p->expression;
465 rtl_obstack = p->rtl;
467 obstack_free (&obstack_stack_obstack, p);
470 /* Nonzero if temporary allocation is currently in effect.
471 Zero if currently doing permanent allocation. */
474 allocation_temporary_p ()
476 return current_obstack != &permanent_obstack;
479 /* Go back to allocating on the permanent obstack
480 and free everything in the temporary obstack.
481 This is done in finish_function after fully compiling a function. */
484 permanent_allocation ()
486 /* Free up previous temporary obstack data */
487 obstack_free (&temporary_obstack, temporary_firstobj);
488 obstack_free (&momentary_obstack, momentary_firstobj);
489 obstack_free (&maybepermanent_obstack, maybepermanent_firstobj);
490 obstack_free (&temp_decl_obstack, temp_decl_firstobj);
492 current_obstack = &permanent_obstack;
493 expression_obstack = &permanent_obstack;
494 rtl_obstack = saveable_obstack = &permanent_obstack;
497 /* Save permanently everything on the maybepermanent_obstack. */
502 maybepermanent_firstobj
503 = (char *) obstack_alloc (function_maybepermanent_obstack, 0);
507 preserve_initializer ()
510 = (char *) obstack_alloc (&temporary_obstack, 0);
512 = (char *) obstack_alloc (&momentary_obstack, 0);
513 maybepermanent_firstobj
514 = (char *) obstack_alloc (function_maybepermanent_obstack, 0);
517 /* Start allocating new rtl in current_obstack.
518 Use resume_temporary_allocation
519 to go back to allocating rtl in saveable_obstack. */
522 rtl_in_current_obstack ()
524 rtl_obstack = current_obstack;
527 /* Temporarily allocate rtl from saveable_obstack. Return 1 if we were
528 previously allocating it from current_obstack. */
531 rtl_in_saveable_obstack ()
533 if (rtl_obstack == current_obstack)
535 rtl_obstack = saveable_obstack;
542 /* Allocate SIZE bytes in the current obstack
543 and return a pointer to them.
544 In practice the current obstack is always the temporary one. */
550 return (char *) obstack_alloc (current_obstack, size);
553 /* Free the object PTR in the current obstack
554 as well as everything allocated since PTR.
555 In practice the current obstack is always the temporary one. */
561 obstack_free (current_obstack, ptr);
564 /* Allocate SIZE bytes in the permanent obstack
565 and return a pointer to them. */
571 return (char *) obstack_alloc (&permanent_obstack, size);
574 /* Allocate NELEM items of SIZE bytes in the permanent obstack
575 and return a pointer to them. The storage is cleared before
576 returning the value. */
579 perm_calloc (nelem, size)
583 char *rval = (char *) obstack_alloc (&permanent_obstack, nelem * size);
584 bzero (rval, nelem * size);
588 /* Allocate SIZE bytes in the saveable obstack
589 and return a pointer to them. */
595 return (char *) obstack_alloc (saveable_obstack, size);
598 /* Print out which obstack an object is in. */
601 debug_obstack (object)
604 struct obstack *obstack = NULL;
605 char *obstack_name = NULL;
608 for (p = outer_function_chain; p; p = p->next)
610 if (_obstack_allocated_p (p->function_obstack, object))
612 obstack = p->function_obstack;
613 obstack_name = "containing function obstack";
615 if (_obstack_allocated_p (p->function_maybepermanent_obstack, object))
617 obstack = p->function_maybepermanent_obstack;
618 obstack_name = "containing function maybepermanent obstack";
622 if (_obstack_allocated_p (&obstack_stack_obstack, object))
624 obstack = &obstack_stack_obstack;
625 obstack_name = "obstack_stack_obstack";
627 else if (_obstack_allocated_p (function_obstack, object))
629 obstack = function_obstack;
630 obstack_name = "function obstack";
632 else if (_obstack_allocated_p (&permanent_obstack, object))
634 obstack = &permanent_obstack;
635 obstack_name = "permanent_obstack";
637 else if (_obstack_allocated_p (&momentary_obstack, object))
639 obstack = &momentary_obstack;
640 obstack_name = "momentary_obstack";
642 else if (_obstack_allocated_p (function_maybepermanent_obstack, object))
644 obstack = function_maybepermanent_obstack;
645 obstack_name = "function maybepermanent obstack";
647 else if (_obstack_allocated_p (&temp_decl_obstack, object))
649 obstack = &temp_decl_obstack;
650 obstack_name = "temp_decl_obstack";
653 /* Check to see if the object is in the free area of the obstack. */
656 if (object >= obstack->next_free
657 && object < obstack->chunk_limit)
658 fprintf (stderr, "object in free portion of obstack %s.\n",
661 fprintf (stderr, "object allocated from %s.\n", obstack_name);
664 fprintf (stderr, "object not allocated from any obstack.\n");
667 /* Return 1 if OBJ is in the permanent obstack.
668 This is slow, and should be used only for debugging.
669 Use TREE_PERMANENT for other purposes. */
672 object_permanent_p (obj)
675 return _obstack_allocated_p (&permanent_obstack, obj);
678 /* Start a level of momentary allocation.
679 In C, each compound statement has its own level
680 and that level is freed at the end of each statement.
681 All expression nodes are allocated in the momentary allocation level. */
686 struct momentary_level *tem
687 = (struct momentary_level *) obstack_alloc (&momentary_obstack,
688 sizeof (struct momentary_level));
689 tem->prev = momentary_stack;
690 tem->base = (char *) obstack_base (&momentary_obstack);
691 tem->obstack = expression_obstack;
692 momentary_stack = tem;
693 expression_obstack = &momentary_obstack;
696 /* Free all the storage in the current momentary-allocation level.
697 In C, this happens at the end of each statement. */
702 obstack_free (&momentary_obstack, momentary_stack->base);
705 /* Discard a level of momentary allocation.
706 In C, this happens at the end of each compound statement.
707 Restore the status of expression node allocation
708 that was in effect before this level was created. */
713 struct momentary_level *tem = momentary_stack;
714 momentary_stack = tem->prev;
715 expression_obstack = tem->obstack;
716 obstack_free (&momentary_obstack, tem);
719 /* Call when starting to parse a declaration:
720 make expressions in the declaration last the length of the function.
721 Returns an argument that should be passed to resume_momentary later. */
726 register int tem = expression_obstack == &momentary_obstack;
727 expression_obstack = saveable_obstack;
731 /* Call when finished parsing a declaration:
732 restore the treatment of node-allocation that was
733 in effect before the suspension.
734 YES should be the value previously returned by suspend_momentary. */
737 resume_momentary (yes)
741 expression_obstack = &momentary_obstack;
744 /* Init the tables indexed by tree code.
745 Note that languages can add to these tables to define their own codes. */
750 tree_code_type = (char **) xmalloc (sizeof (standard_tree_code_type));
751 tree_code_length = (int *) xmalloc (sizeof (standard_tree_code_length));
752 tree_code_name = (char **) xmalloc (sizeof (standard_tree_code_name));
753 bcopy (standard_tree_code_type, tree_code_type,
754 sizeof (standard_tree_code_type));
755 bcopy (standard_tree_code_length, tree_code_length,
756 sizeof (standard_tree_code_length));
757 bcopy (standard_tree_code_name, tree_code_name,
758 sizeof (standard_tree_code_name));
761 /* Return a newly allocated node of code CODE.
762 Initialize the node's unique id and its TREE_PERMANENT flag.
763 For decl and type nodes, some other fields are initialized.
764 The rest of the node is initialized to zero.
766 Achoo! I got a code in the node. */
773 register int type = TREE_CODE_CLASS (code);
775 register struct obstack *obstack = current_obstack;
777 register tree_node_kind kind;
781 case 'd': /* A decl node */
782 #ifdef GATHER_STATISTICS
785 length = sizeof (struct tree_decl);
786 /* All decls in an inline function need to be saved. */
787 if (obstack != &permanent_obstack)
788 obstack = saveable_obstack;
789 /* PARM_DECLs always go on saveable_obstack, not permanent,
790 even though we may make them before the function turns
791 on temporary allocation. */
792 else if (code == PARM_DECL)
793 obstack = function_maybepermanent_obstack;
796 case 't': /* a type node */
797 #ifdef GATHER_STATISTICS
800 length = sizeof (struct tree_type);
801 /* All data types are put where we can preserve them if nec. */
802 if (obstack != &permanent_obstack)
803 obstack = all_types_permanent ? &permanent_obstack : saveable_obstack;
806 case 'b': /* a lexical block */
807 #ifdef GATHER_STATISTICS
810 length = sizeof (struct tree_block);
811 /* All BLOCK nodes are put where we can preserve them if nec. */
812 if (obstack != &permanent_obstack)
813 obstack = saveable_obstack;
816 case 's': /* an expression with side effects */
817 #ifdef GATHER_STATISTICS
821 case 'r': /* a reference */
822 #ifdef GATHER_STATISTICS
826 case 'e': /* an expression */
827 case '<': /* a comparison expression */
828 case '1': /* a unary arithmetic expression */
829 case '2': /* a binary arithmetic expression */
830 #ifdef GATHER_STATISTICS
834 obstack = expression_obstack;
835 /* All BIND_EXPR nodes are put where we can preserve them if nec. */
836 if (code == BIND_EXPR && obstack != &permanent_obstack)
837 obstack = saveable_obstack;
838 length = sizeof (struct tree_exp)
839 + (tree_code_length[(int) code] - 1) * sizeof (char *);
842 case 'c': /* a constant */
843 #ifdef GATHER_STATISTICS
846 obstack = expression_obstack;
847 /* We can't use tree_code_length for this, since the number of words
848 is machine-dependent due to varying alignment of `double'. */
849 if (code == REAL_CST)
851 length = sizeof (struct tree_real_cst);
855 case 'x': /* something random, like an identifier. */
856 #ifdef GATHER_STATISTICS
857 if (code == IDENTIFIER_NODE)
859 else if (code == OP_IDENTIFIER)
861 else if (code == TREE_VEC)
866 length = sizeof (struct tree_common)
867 + tree_code_length[(int) code] * sizeof (char *);
868 /* Identifier nodes are always permanent since they are
869 unique in a compiler run. */
870 if (code == IDENTIFIER_NODE) obstack = &permanent_obstack;
873 t = (tree) obstack_alloc (obstack, length);
875 #ifdef GATHER_STATISTICS
876 tree_node_counts[(int)kind]++;
877 tree_node_sizes[(int)kind] += length;
880 /* Clear a word at a time. */
881 for (i = (length / sizeof (int)) - 1; i >= 0; i--)
883 /* Clear any extra bytes. */
884 for (i = length / sizeof (int) * sizeof (int); i < length; i++)
887 TREE_SET_CODE (t, code);
888 if (obstack == &permanent_obstack)
889 TREE_PERMANENT (t) = 1;
894 TREE_SIDE_EFFECTS (t) = 1;
895 TREE_TYPE (t) = void_type_node;
899 if (code != FUNCTION_DECL)
901 DECL_IN_SYSTEM_HEADER (t)
902 = in_system_header && (obstack == &permanent_obstack);
903 DECL_SOURCE_LINE (t) = lineno;
904 DECL_SOURCE_FILE (t) = (input_filename) ? input_filename : "<built-in>";
905 DECL_UID (t) = next_decl_uid++;
910 static unsigned next_type_uid = 1;
912 TYPE_UID (t) = next_type_uid++;
915 TYPE_MAIN_VARIANT (t) = t;
919 TREE_CONSTANT (t) = 1;
926 /* Return a new node with the same contents as NODE
927 except that its TREE_CHAIN is zero and it has a fresh uid. */
934 register enum tree_code code = TREE_CODE (node);
938 switch (TREE_CODE_CLASS (code))
940 case 'd': /* A decl node */
941 length = sizeof (struct tree_decl);
944 case 't': /* a type node */
945 length = sizeof (struct tree_type);
948 case 'b': /* a lexical block node */
949 length = sizeof (struct tree_block);
952 case 'r': /* a reference */
953 case 'e': /* an expression */
954 case 's': /* an expression with side effects */
955 case '<': /* a comparison expression */
956 case '1': /* a unary arithmetic expression */
957 case '2': /* a binary arithmetic expression */
958 length = sizeof (struct tree_exp)
959 + (tree_code_length[(int) code] - 1) * sizeof (char *);
962 case 'c': /* a constant */
963 /* We can't use tree_code_length for this, since the number of words
964 is machine-dependent due to varying alignment of `double'. */
965 if (code == REAL_CST)
967 length = sizeof (struct tree_real_cst);
971 case 'x': /* something random, like an identifier. */
972 length = sizeof (struct tree_common)
973 + tree_code_length[(int) code] * sizeof (char *);
974 if (code == TREE_VEC)
975 length += (TREE_VEC_LENGTH (node) - 1) * sizeof (char *);
978 t = (tree) obstack_alloc (current_obstack, length);
980 for (i = (length / sizeof (int)) - 1; i >= 0; i--)
981 ((int *) t)[i] = ((int *) node)[i];
982 /* Clear any extra bytes. */
983 for (i = length / sizeof (int) * sizeof (int); i < length; i++)
988 TREE_PERMANENT (t) = (current_obstack == &permanent_obstack);
993 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
994 For example, this can copy a list made of TREE_LIST nodes. */
1001 register tree prev, next;
1006 head = prev = copy_node (list);
1007 next = TREE_CHAIN (list);
1010 TREE_CHAIN (prev) = copy_node (next);
1011 prev = TREE_CHAIN (prev);
1012 next = TREE_CHAIN (next);
1019 /* Return an IDENTIFIER_NODE whose name is TEXT (a null-terminated string).
1020 If an identifier with that name has previously been referred to,
1021 the same node is returned this time. */
1024 get_identifier (text)
1025 register char *text;
1030 register int len, hash_len;
1032 /* Compute length of text in len. */
1033 for (len = 0; text[len]; len++);
1035 /* Decide how much of that length to hash on */
1037 if (warn_id_clash && len > id_clash_len)
1038 hash_len = id_clash_len;
1040 /* Compute hash code */
1041 hi = hash_len * 613 + (unsigned)text[0];
1042 for (i = 1; i < hash_len; i += 2)
1043 hi = ((hi * 613) + (unsigned)(text[i]));
1045 hi &= (1 << HASHBITS) - 1;
1046 hi %= MAX_HASH_TABLE;
1048 /* Search table for identifier */
1049 for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
1050 if (IDENTIFIER_LENGTH (idp) == len
1051 && IDENTIFIER_POINTER (idp)[0] == text[0]
1052 && !bcmp (IDENTIFIER_POINTER (idp), text, len))
1053 return idp; /* <-- return if found */
1055 /* Not found; optionally warn about a similar identifier */
1056 if (warn_id_clash && do_identifier_warnings && len >= id_clash_len)
1057 for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
1058 if (!strncmp (IDENTIFIER_POINTER (idp), text, id_clash_len))
1060 warning ("`%s' and `%s' identical in first %d characters",
1061 IDENTIFIER_POINTER (idp), text, id_clash_len);
1065 if (tree_code_length[(int) IDENTIFIER_NODE] < 0)
1066 abort (); /* set_identifier_size hasn't been called. */
1068 /* Not found, create one, add to chain */
1069 idp = make_node (IDENTIFIER_NODE);
1070 IDENTIFIER_LENGTH (idp) = len;
1071 #ifdef GATHER_STATISTICS
1072 id_string_size += len;
1075 IDENTIFIER_POINTER (idp) = obstack_copy0 (&permanent_obstack, text, len);
1077 TREE_CHAIN (idp) = hash_table[hi];
1078 hash_table[hi] = idp;
1079 return idp; /* <-- return if created */
1082 /* Enable warnings on similar identifiers (if requested).
1083 Done after the built-in identifiers are created. */
1086 start_identifier_warnings ()
1088 do_identifier_warnings = 1;
1091 /* Record the size of an identifier node for the language in use.
1092 SIZE is the total size in bytes.
1093 This is called by the language-specific files. This must be
1094 called before allocating any identifiers. */
1097 set_identifier_size (size)
1100 tree_code_length[(int) IDENTIFIER_NODE]
1101 = (size - sizeof (struct tree_common)) / sizeof (tree);
1104 /* Return a newly constructed INTEGER_CST node whose constant value
1105 is specified by the two ints LOW and HI.
1106 The TREE_TYPE is set to `int'.
1108 This function should be used via the `build_int_2' macro. */
1111 build_int_2_wide (low, hi)
1112 HOST_WIDE_INT low, hi;
1114 register tree t = make_node (INTEGER_CST);
1115 TREE_INT_CST_LOW (t) = low;
1116 TREE_INT_CST_HIGH (t) = hi;
1117 TREE_TYPE (t) = integer_type_node;
1121 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1124 build_real (type, d)
1130 /* Check for valid float value for this type on this target machine;
1131 if not, can print error message and store a valid value in D. */
1132 #ifdef CHECK_FLOAT_VALUE
1133 CHECK_FLOAT_VALUE (TYPE_MODE (type), d);
1136 v = make_node (REAL_CST);
1137 TREE_TYPE (v) = type;
1138 TREE_REAL_CST (v) = d;
1142 /* Return a new REAL_CST node whose type is TYPE
1143 and whose value is the integer value of the INTEGER_CST node I. */
1145 #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
1148 real_value_from_int_cst (i)
1152 #ifdef REAL_ARITHMETIC
1153 REAL_VALUE_FROM_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i));
1154 #else /* not REAL_ARITHMETIC */
1155 if (TREE_INT_CST_HIGH (i) < 0 && ! TREE_UNSIGNED (TREE_TYPE (i)))
1157 d = (double) (~ TREE_INT_CST_HIGH (i));
1158 d *= ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
1159 * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
1160 d += (double) (unsigned HOST_WIDE_INT) (~ TREE_INT_CST_LOW (i));
1165 d = (double) (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (i);
1166 d *= ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
1167 * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
1168 d += (double) (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (i);
1170 #endif /* not REAL_ARITHMETIC */
1174 /* This function can't be implemented if we can't do arithmetic
1175 on the float representation. */
1178 build_real_from_int_cst (type, i)
1185 v = make_node (REAL_CST);
1186 TREE_TYPE (v) = type;
1188 d = REAL_VALUE_TRUNCATE (TYPE_MODE (type), real_value_from_int_cst (i));
1189 /* Check for valid float value for this type on this target machine;
1190 if not, can print error message and store a valid value in D. */
1191 #ifdef CHECK_FLOAT_VALUE
1192 CHECK_FLOAT_VALUE (TYPE_MODE (type), d);
1195 TREE_REAL_CST (v) = d;
1199 #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
1201 /* Return a newly constructed STRING_CST node whose value is
1202 the LEN characters at STR.
1203 The TREE_TYPE is not initialized. */
1206 build_string (len, str)
1210 register tree s = make_node (STRING_CST);
1211 TREE_STRING_LENGTH (s) = len;
1212 TREE_STRING_POINTER (s) = obstack_copy0 (saveable_obstack, str, len);
1216 /* Return a newly constructed COMPLEX_CST node whose value is
1217 specified by the real and imaginary parts REAL and IMAG.
1218 Both REAL and IMAG should be constant nodes.
1219 The TREE_TYPE is not initialized. */
1222 build_complex (real, imag)
1225 register tree t = make_node (COMPLEX_CST);
1226 TREE_REALPART (t) = real;
1227 TREE_IMAGPART (t) = imag;
1231 /* Build a newly constructed TREE_VEC node of length LEN. */
1237 register int length = (len-1) * sizeof (tree) + sizeof (struct tree_vec);
1238 register struct obstack *obstack = current_obstack;
1241 #ifdef GATHER_STATISTICS
1242 tree_node_counts[(int)vec_kind]++;
1243 tree_node_sizes[(int)vec_kind] += length;
1246 t = (tree) obstack_alloc (obstack, length);
1248 for (i = (length / sizeof (int)) - 1; i >= 0; i--)
1251 TREE_SET_CODE (t, TREE_VEC);
1252 TREE_VEC_LENGTH (t) = len;
1253 if (obstack == &permanent_obstack)
1254 TREE_PERMANENT (t) = 1;
1259 /* Return 1 if EXPR is the integer constant zero. */
1262 integer_zerop (expr)
1267 return (TREE_CODE (expr) == INTEGER_CST
1268 && TREE_INT_CST_LOW (expr) == 0
1269 && TREE_INT_CST_HIGH (expr) == 0);
1272 /* Return 1 if EXPR is the integer constant one. */
1280 return (TREE_CODE (expr) == INTEGER_CST
1281 && TREE_INT_CST_LOW (expr) == 1
1282 && TREE_INT_CST_HIGH (expr) == 0);
1285 /* Return 1 if EXPR is an integer containing all 1's
1286 in as much precision as it contains. */
1289 integer_all_onesp (expr)
1297 if (TREE_CODE (expr) != INTEGER_CST)
1300 uns = TREE_UNSIGNED (TREE_TYPE (expr));
1302 return TREE_INT_CST_LOW (expr) == -1 && TREE_INT_CST_HIGH (expr) == -1;
1304 prec = TYPE_PRECISION (TREE_TYPE (expr));
1305 if (prec >= HOST_BITS_PER_WIDE_INT)
1307 int high_value, shift_amount;
1309 shift_amount = prec - HOST_BITS_PER_WIDE_INT;
1311 if (shift_amount > HOST_BITS_PER_WIDE_INT)
1312 /* Can not handle precisions greater than twice the host int size. */
1314 else if (shift_amount == HOST_BITS_PER_WIDE_INT)
1315 /* Shifting by the host word size is undefined according to the ANSI
1316 standard, so we must handle this as a special case. */
1319 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
1321 return TREE_INT_CST_LOW (expr) == -1
1322 && TREE_INT_CST_HIGH (expr) == high_value;
1325 return TREE_INT_CST_LOW (expr) == ((HOST_WIDE_INT) 1 << prec) - 1;
1328 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1332 integer_pow2p (expr)
1335 HOST_WIDE_INT high, low;
1339 if (TREE_CODE (expr) != INTEGER_CST)
1342 high = TREE_INT_CST_HIGH (expr);
1343 low = TREE_INT_CST_LOW (expr);
1345 if (high == 0 && low == 0)
1348 return ((high == 0 && (low & (low - 1)) == 0)
1349 || (low == 0 && (high & (high - 1)) == 0));
1352 /* Return 1 if EXPR is the real constant zero. */
1360 return (TREE_CODE (expr) == REAL_CST
1361 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0));
1364 /* Return 1 if EXPR is the real constant one. */
1372 return (TREE_CODE (expr) == REAL_CST
1373 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1));
1376 /* Return 1 if EXPR is the real constant two. */
1384 return (TREE_CODE (expr) == REAL_CST
1385 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2));
1388 /* Nonzero if EXP is a constant or a cast of a constant. */
1391 really_constant_p (exp)
1394 /* This is not quite the same as STRIP_NOPS. It does more. */
1395 while (TREE_CODE (exp) == NOP_EXPR
1396 || TREE_CODE (exp) == CONVERT_EXPR
1397 || TREE_CODE (exp) == NON_LVALUE_EXPR)
1398 exp = TREE_OPERAND (exp, 0);
1399 return TREE_CONSTANT (exp);
1402 /* Return first list element whose TREE_VALUE is ELEM.
1403 Return 0 if ELEM is not it LIST. */
1406 value_member (elem, list)
1411 if (elem == TREE_VALUE (list))
1413 list = TREE_CHAIN (list);
1418 /* Return first list element whose TREE_PURPOSE is ELEM.
1419 Return 0 if ELEM is not it LIST. */
1422 purpose_member (elem, list)
1427 if (elem == TREE_PURPOSE (list))
1429 list = TREE_CHAIN (list);
1434 /* Return first list element whose BINFO_TYPE is ELEM.
1435 Return 0 if ELEM is not it LIST. */
1438 binfo_member (elem, list)
1443 if (elem == BINFO_TYPE (list))
1445 list = TREE_CHAIN (list);
1450 /* Return nonzero if ELEM is part of the chain CHAIN. */
1453 chain_member (elem, chain)
1460 chain = TREE_CHAIN (chain);
1466 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1467 We expect a null pointer to mark the end of the chain.
1468 This is the Lisp primitive `length'. */
1475 register int len = 0;
1477 for (tail = t; tail; tail = TREE_CHAIN (tail))
1483 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1484 by modifying the last node in chain 1 to point to chain 2.
1485 This is the Lisp primitive `nconc'. */
1495 for (t = op1; TREE_CHAIN (t); t = TREE_CHAIN (t))
1496 if (t == op2) abort (); /* Circularity being created */
1497 if (t == op2) abort (); /* Circularity being created */
1498 TREE_CHAIN (t) = op2;
1504 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1508 register tree chain;
1512 while (next = TREE_CHAIN (chain))
1517 /* Reverse the order of elements in the chain T,
1518 and return the new head of the chain (old last element). */
1524 register tree prev = 0, decl, next;
1525 for (decl = t; decl; decl = next)
1527 next = TREE_CHAIN (decl);
1528 TREE_CHAIN (decl) = prev;
1534 /* Given a chain CHAIN of tree nodes,
1535 construct and return a list of those nodes. */
1541 tree result = NULL_TREE;
1542 tree in_tail = chain;
1543 tree out_tail = NULL_TREE;
1547 tree next = tree_cons (NULL_TREE, in_tail, NULL_TREE);
1549 TREE_CHAIN (out_tail) = next;
1553 in_tail = TREE_CHAIN (in_tail);
1559 /* Return a newly created TREE_LIST node whose
1560 purpose and value fields are PARM and VALUE. */
1563 build_tree_list (parm, value)
1566 register tree t = make_node (TREE_LIST);
1567 TREE_PURPOSE (t) = parm;
1568 TREE_VALUE (t) = value;
1572 /* Similar, but build on the temp_decl_obstack. */
1575 build_decl_list (parm, value)
1579 register struct obstack *ambient_obstack = current_obstack;
1580 current_obstack = &temp_decl_obstack;
1581 node = build_tree_list (parm, value);
1582 current_obstack = ambient_obstack;
1586 /* Return a newly created TREE_LIST node whose
1587 purpose and value fields are PARM and VALUE
1588 and whose TREE_CHAIN is CHAIN. */
1591 tree_cons (purpose, value, chain)
1592 tree purpose, value, chain;
1595 register tree node = make_node (TREE_LIST);
1598 register tree node = (tree) obstack_alloc (current_obstack, sizeof (struct tree_list));
1599 #ifdef GATHER_STATISTICS
1600 tree_node_counts[(int)x_kind]++;
1601 tree_node_sizes[(int)x_kind] += sizeof (struct tree_list);
1604 for (i = (sizeof (struct tree_common) / sizeof (int)) - 1; i >= 0; i--)
1605 ((int *) node)[i] = 0;
1607 TREE_SET_CODE (node, TREE_LIST);
1608 if (current_obstack == &permanent_obstack)
1609 TREE_PERMANENT (node) = 1;
1612 TREE_CHAIN (node) = chain;
1613 TREE_PURPOSE (node) = purpose;
1614 TREE_VALUE (node) = value;
1618 /* Similar, but build on the temp_decl_obstack. */
1621 decl_tree_cons (purpose, value, chain)
1622 tree purpose, value, chain;
1625 register struct obstack *ambient_obstack = current_obstack;
1626 current_obstack = &temp_decl_obstack;
1627 node = tree_cons (purpose, value, chain);
1628 current_obstack = ambient_obstack;
1632 /* Same as `tree_cons' but make a permanent object. */
1635 perm_tree_cons (purpose, value, chain)
1636 tree purpose, value, chain;
1639 register struct obstack *ambient_obstack = current_obstack;
1640 current_obstack = &permanent_obstack;
1642 node = tree_cons (purpose, value, chain);
1643 current_obstack = ambient_obstack;
1647 /* Same as `tree_cons', but make this node temporary, regardless. */
1650 temp_tree_cons (purpose, value, chain)
1651 tree purpose, value, chain;
1654 register struct obstack *ambient_obstack = current_obstack;
1655 current_obstack = &temporary_obstack;
1657 node = tree_cons (purpose, value, chain);
1658 current_obstack = ambient_obstack;
1662 /* Same as `tree_cons', but save this node if the function's RTL is saved. */
1665 saveable_tree_cons (purpose, value, chain)
1666 tree purpose, value, chain;
1669 register struct obstack *ambient_obstack = current_obstack;
1670 current_obstack = saveable_obstack;
1672 node = tree_cons (purpose, value, chain);
1673 current_obstack = ambient_obstack;
1677 /* Return the size nominally occupied by an object of type TYPE
1678 when it resides in memory. The value is measured in units of bytes,
1679 and its data type is that normally used for type sizes
1680 (which is the first type created by make_signed_type or
1681 make_unsigned_type). */
1684 size_in_bytes (type)
1687 if (type == error_mark_node)
1688 return integer_zero_node;
1689 type = TYPE_MAIN_VARIANT (type);
1690 if (TYPE_SIZE (type) == 0)
1692 incomplete_type_error (NULL_TREE, type);
1693 return integer_zero_node;
1695 return size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
1696 size_int (BITS_PER_UNIT));
1699 /* Return the size of TYPE (in bytes) as an integer,
1700 or return -1 if the size can vary. */
1703 int_size_in_bytes (type)
1707 if (type == error_mark_node)
1709 type = TYPE_MAIN_VARIANT (type);
1710 if (TYPE_SIZE (type) == 0)
1712 if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1714 size = TREE_INT_CST_LOW (TYPE_SIZE (type));
1715 return (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
1718 /* Return, as an INTEGER_CST node, the number of elements for
1719 TYPE (which is an ARRAY_TYPE) minus one.
1720 This counts only elements of the top array. */
1723 array_type_nelts (type)
1726 tree index_type = TYPE_DOMAIN (type);
1727 return (tree_int_cst_equal (TYPE_MIN_VALUE (index_type), integer_zero_node)
1728 ? TYPE_MAX_VALUE (index_type)
1729 : fold (build (MINUS_EXPR, integer_type_node,
1730 TYPE_MAX_VALUE (index_type),
1731 TYPE_MIN_VALUE (index_type))));
1734 /* Return nonzero if arg is static -- a reference to an object in
1735 static storage. This is not the same as the C meaning of `static'. */
1741 switch (TREE_CODE (arg))
1746 return TREE_STATIC (arg) || DECL_EXTERNAL (arg);
1753 return staticp (TREE_OPERAND (arg, 0));
1756 return TREE_CONSTANT (TREE_OPERAND (arg, 0));
1759 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
1760 && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
1761 return staticp (TREE_OPERAND (arg, 0));
1767 /* This should be applied to any node which may be used in more than one place,
1768 but must be evaluated only once. Normally, the code generator would
1769 reevaluate the node each time; this forces it to compute it once and save
1770 the result. This is done by encapsulating the node in a SAVE_EXPR. */
1776 register tree t = fold (expr);
1778 /* We don't care about whether this can be used as an lvalue in this
1780 while (TREE_CODE (t) == NON_LVALUE_EXPR)
1781 t = TREE_OPERAND (t, 0);
1783 /* If the tree evaluates to a constant, then we don't want to hide that
1784 fact (i.e. this allows further folding, and direct checks for constants).
1785 However, a read-only object that has side effects cannot be bypassed.
1786 Since it is no problem to reevaluate literals, we just return the
1789 if (TREE_CONSTANT (t) || (TREE_READONLY (t) && ! TREE_SIDE_EFFECTS (t))
1790 || TREE_CODE (t) == SAVE_EXPR)
1793 t = build (SAVE_EXPR, TREE_TYPE (expr), t, current_function_decl, NULL_TREE);
1795 /* This expression might be placed ahead of a jump to ensure that the
1796 value was computed on both sides of the jump. So make sure it isn't
1797 eliminated as dead. */
1798 TREE_SIDE_EFFECTS (t) = 1;
1802 /* Stabilize a reference so that we can use it any number of times
1803 without causing its operands to be evaluated more than once.
1804 Returns the stabilized reference.
1806 Also allows conversion expressions whose operands are references.
1807 Any other kind of expression is returned unchanged. */
1810 stabilize_reference (ref)
1813 register tree result;
1814 register enum tree_code code = TREE_CODE (ref);
1821 /* No action is needed in this case. */
1827 case FIX_TRUNC_EXPR:
1828 case FIX_FLOOR_EXPR:
1829 case FIX_ROUND_EXPR:
1831 result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
1835 result = build_nt (INDIRECT_REF,
1836 stabilize_reference_1 (TREE_OPERAND (ref, 0)));
1840 result = build_nt (COMPONENT_REF,
1841 stabilize_reference (TREE_OPERAND (ref, 0)),
1842 TREE_OPERAND (ref, 1));
1846 result = build_nt (BIT_FIELD_REF,
1847 stabilize_reference (TREE_OPERAND (ref, 0)),
1848 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
1849 stabilize_reference_1 (TREE_OPERAND (ref, 2)));
1853 result = build_nt (ARRAY_REF,
1854 stabilize_reference (TREE_OPERAND (ref, 0)),
1855 stabilize_reference_1 (TREE_OPERAND (ref, 1)));
1858 /* If arg isn't a kind of lvalue we recognize, make no change.
1859 Caller should recognize the error for an invalid lvalue. */
1864 return error_mark_node;
1867 TREE_TYPE (result) = TREE_TYPE (ref);
1868 TREE_READONLY (result) = TREE_READONLY (ref);
1869 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
1870 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
1871 TREE_RAISES (result) = TREE_RAISES (ref);
1876 /* Subroutine of stabilize_reference; this is called for subtrees of
1877 references. Any expression with side-effects must be put in a SAVE_EXPR
1878 to ensure that it is only evaluated once.
1880 We don't put SAVE_EXPR nodes around everything, because assigning very
1881 simple expressions to temporaries causes us to miss good opportunities
1882 for optimizations. Among other things, the opportunity to fold in the
1883 addition of a constant into an addressing mode often gets lost, e.g.
1884 "y[i+1] += x;". In general, we take the approach that we should not make
1885 an assignment unless we are forced into it - i.e., that any non-side effect
1886 operator should be allowed, and that cse should take care of coalescing
1887 multiple utterances of the same expression should that prove fruitful. */
1890 stabilize_reference_1 (e)
1893 register tree result;
1894 register int length;
1895 register enum tree_code code = TREE_CODE (e);
1897 /* We cannot ignore const expressions because it might be a reference
1898 to a const array but whose index contains side-effects. But we can
1899 ignore things that are actual constant or that already have been
1900 handled by this function. */
1902 if (TREE_CONSTANT (e) || code == SAVE_EXPR)
1905 switch (TREE_CODE_CLASS (code))
1915 /* If the expression has side-effects, then encase it in a SAVE_EXPR
1916 so that it will only be evaluated once. */
1917 /* The reference (r) and comparison (<) classes could be handled as
1918 below, but it is generally faster to only evaluate them once. */
1919 if (TREE_SIDE_EFFECTS (e))
1920 return save_expr (e);
1924 /* Constants need no processing. In fact, we should never reach
1929 /* Recursively stabilize each operand. */
1930 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
1931 stabilize_reference_1 (TREE_OPERAND (e, 1)));
1935 /* Recursively stabilize each operand. */
1936 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
1940 TREE_TYPE (result) = TREE_TYPE (e);
1941 TREE_READONLY (result) = TREE_READONLY (e);
1942 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
1943 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
1944 TREE_RAISES (result) = TREE_RAISES (e);
1949 /* Low-level constructors for expressions. */
1951 /* Build an expression of code CODE, data type TYPE,
1952 and operands as specified by the arguments ARG1 and following arguments.
1953 Expressions and reference nodes can be created this way.
1954 Constants, decls, types and misc nodes cannot be. */
1961 enum tree_code code;
1963 register int length;
1968 code = va_arg (p, enum tree_code);
1969 t = make_node (code);
1970 length = tree_code_length[(int) code];
1971 TREE_TYPE (t) = va_arg (p, tree);
1975 /* This is equivalent to the loop below, but faster. */
1976 register tree arg0 = va_arg (p, tree);
1977 register tree arg1 = va_arg (p, tree);
1978 TREE_OPERAND (t, 0) = arg0;
1979 TREE_OPERAND (t, 1) = arg1;
1980 if ((arg0 && TREE_SIDE_EFFECTS (arg0))
1981 || (arg1 && TREE_SIDE_EFFECTS (arg1)))
1982 TREE_SIDE_EFFECTS (t) = 1;
1984 = (arg0 && TREE_RAISES (arg0)) || (arg1 && TREE_RAISES (arg1));
1986 else if (length == 1)
1988 register tree arg0 = va_arg (p, tree);
1990 /* Call build1 for this! */
1991 if (TREE_CODE_CLASS (code) != 's')
1993 TREE_OPERAND (t, 0) = arg0;
1994 if (arg0 && TREE_SIDE_EFFECTS (arg0))
1995 TREE_SIDE_EFFECTS (t) = 1;
1996 TREE_RAISES (t) = (arg0 && TREE_RAISES (arg0));
2000 for (i = 0; i < length; i++)
2002 register tree operand = va_arg (p, tree);
2003 TREE_OPERAND (t, i) = operand;
2006 if (TREE_SIDE_EFFECTS (operand))
2007 TREE_SIDE_EFFECTS (t) = 1;
2008 if (TREE_RAISES (operand))
2009 TREE_RAISES (t) = 1;
2017 /* Same as above, but only builds for unary operators.
2018 Saves lions share of calls to `build'; cuts down use
2019 of varargs, which is expensive for RISC machines. */
2021 build1 (code, type, node)
2022 enum tree_code code;
2026 register struct obstack *obstack = current_obstack;
2027 register int i, length;
2028 register tree_node_kind kind;
2031 #ifdef GATHER_STATISTICS
2032 if (TREE_CODE_CLASS (code) == 'r')
2038 obstack = expression_obstack;
2039 length = sizeof (struct tree_exp);
2041 t = (tree) obstack_alloc (obstack, length);
2043 #ifdef GATHER_STATISTICS
2044 tree_node_counts[(int)kind]++;
2045 tree_node_sizes[(int)kind] += length;
2048 for (i = (length / sizeof (int)) - 1; i >= 0; i--)
2051 TREE_TYPE (t) = type;
2052 TREE_SET_CODE (t, code);
2054 if (obstack == &permanent_obstack)
2055 TREE_PERMANENT (t) = 1;
2057 TREE_OPERAND (t, 0) = node;
2060 if (TREE_SIDE_EFFECTS (node))
2061 TREE_SIDE_EFFECTS (t) = 1;
2062 if (TREE_RAISES (node))
2063 TREE_RAISES (t) = 1;
2069 /* Similar except don't specify the TREE_TYPE
2070 and leave the TREE_SIDE_EFFECTS as 0.
2071 It is permissible for arguments to be null,
2072 or even garbage if their values do not matter. */
2079 register enum tree_code code;
2081 register int length;
2086 code = va_arg (p, enum tree_code);
2087 t = make_node (code);
2088 length = tree_code_length[(int) code];
2090 for (i = 0; i < length; i++)
2091 TREE_OPERAND (t, i) = va_arg (p, tree);
2097 /* Similar to `build_nt', except we build
2098 on the temp_decl_obstack, regardless. */
2101 build_parse_node (va_alist)
2104 register struct obstack *ambient_obstack = expression_obstack;
2106 register enum tree_code code;
2108 register int length;
2111 expression_obstack = &temp_decl_obstack;
2115 code = va_arg (p, enum tree_code);
2116 t = make_node (code);
2117 length = tree_code_length[(int) code];
2119 for (i = 0; i < length; i++)
2120 TREE_OPERAND (t, i) = va_arg (p, tree);
2123 expression_obstack = ambient_obstack;
2128 /* Commented out because this wants to be done very
2129 differently. See cp-lex.c. */
2131 build_op_identifier (op1, op2)
2134 register tree t = make_node (OP_IDENTIFIER);
2135 TREE_PURPOSE (t) = op1;
2136 TREE_VALUE (t) = op2;
2141 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
2142 We do NOT enter this node in any sort of symbol table.
2144 layout_decl is used to set up the decl's storage layout.
2145 Other slots are initialized to 0 or null pointers. */
2148 build_decl (code, name, type)
2149 enum tree_code code;
2154 t = make_node (code);
2156 /* if (type == error_mark_node)
2157 type = integer_type_node; */
2158 /* That is not done, deliberately, so that having error_mark_node
2159 as the type can suppress useless errors in the use of this variable. */
2161 DECL_NAME (t) = name;
2162 DECL_ASSEMBLER_NAME (t) = name;
2163 TREE_TYPE (t) = type;
2165 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
2167 else if (code == FUNCTION_DECL)
2168 DECL_MODE (t) = FUNCTION_MODE;
2173 /* BLOCK nodes are used to represent the structure of binding contours
2174 and declarations, once those contours have been exited and their contents
2175 compiled. This information is used for outputting debugging info. */
2178 build_block (vars, tags, subblocks, supercontext, chain)
2179 tree vars, tags, subblocks, supercontext, chain;
2181 register tree block = make_node (BLOCK);
2182 BLOCK_VARS (block) = vars;
2183 BLOCK_TYPE_TAGS (block) = tags;
2184 BLOCK_SUBBLOCKS (block) = subblocks;
2185 BLOCK_SUPERCONTEXT (block) = supercontext;
2186 BLOCK_CHAIN (block) = chain;
2190 /* Return a type like TYPE except that its TYPE_READONLY is CONSTP
2191 and its TYPE_VOLATILE is VOLATILEP.
2193 Such variant types already made are recorded so that duplicates
2196 A variant types should never be used as the type of an expression.
2197 Always copy the variant information into the TREE_READONLY
2198 and TREE_THIS_VOLATILE of the expression, and then give the expression
2199 as its type the "main variant", the variant whose TYPE_READONLY
2200 and TYPE_VOLATILE are zero. Use TYPE_MAIN_VARIANT to find the
2204 build_type_variant (type, constp, volatilep)
2206 int constp, volatilep;
2208 register tree t, m = TYPE_MAIN_VARIANT (type);
2209 register struct obstack *ambient_obstack = current_obstack;
2211 /* Treat any nonzero argument as 1. */
2213 volatilep = !!volatilep;
2215 /* If not generating auxiliary info, search the chain of variants to see
2216 if there is already one there just like the one we need to have. If so,
2217 use that existing one.
2219 We don't do this in the case where we are generating aux info because
2220 in that case we want each typedef names to get it's own distinct type
2221 node, even if the type of this new typedef is the same as some other
2224 if (!flag_gen_aux_info)
2225 for (t = m; t; t = TYPE_NEXT_VARIANT (t))
2226 if (constp == TYPE_READONLY (t) && volatilep == TYPE_VOLATILE (t))
2229 /* We need a new one. */
2231 = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
2233 t = copy_node (type);
2234 TYPE_READONLY (t) = constp;
2235 TYPE_VOLATILE (t) = volatilep;
2236 TYPE_POINTER_TO (t) = 0;
2237 TYPE_REFERENCE_TO (t) = 0;
2239 /* Add this type to the chain of variants of TYPE. */
2240 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
2241 TYPE_NEXT_VARIANT (m) = t;
2243 current_obstack = ambient_obstack;
2247 /* Create a new variant of TYPE, equivalent but distinct.
2248 This is so the caller can modify it. */
2251 build_type_copy (type)
2254 register tree t, m = TYPE_MAIN_VARIANT (type);
2255 register struct obstack *ambient_obstack = current_obstack;
2258 = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
2260 t = copy_node (type);
2261 TYPE_POINTER_TO (t) = 0;
2262 TYPE_REFERENCE_TO (t) = 0;
2264 /* Add this type to the chain of variants of TYPE. */
2265 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
2266 TYPE_NEXT_VARIANT (m) = t;
2268 current_obstack = ambient_obstack;
2272 /* Hashing of types so that we don't make duplicates.
2273 The entry point is `type_hash_canon'. */
2275 /* Each hash table slot is a bucket containing a chain
2276 of these structures. */
2280 struct type_hash *next; /* Next structure in the bucket. */
2281 int hashcode; /* Hash code of this type. */
2282 tree type; /* The type recorded here. */
2285 /* Now here is the hash table. When recording a type, it is added
2286 to the slot whose index is the hash code mod the table size.
2287 Note that the hash table is used for several kinds of types
2288 (function types, array types and array index range types, for now).
2289 While all these live in the same table, they are completely independent,
2290 and the hash code is computed differently for each of these. */
2292 #define TYPE_HASH_SIZE 59
2293 struct type_hash *type_hash_table[TYPE_HASH_SIZE];
2295 /* Here is how primitive or already-canonicalized types' hash
2297 #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
2299 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
2300 with types in the TREE_VALUE slots), by adding the hash codes
2301 of the individual types. */
2304 type_hash_list (list)
2307 register int hashcode;
2309 for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
2310 hashcode += TYPE_HASH (TREE_VALUE (tail));
2314 /* Look in the type hash table for a type isomorphic to TYPE.
2315 If one is found, return it. Otherwise return 0. */
2318 type_hash_lookup (hashcode, type)
2322 register struct type_hash *h;
2323 for (h = type_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
2324 if (h->hashcode == hashcode
2325 && TREE_CODE (h->type) == TREE_CODE (type)
2326 && TREE_TYPE (h->type) == TREE_TYPE (type)
2327 && (TYPE_MAX_VALUE (h->type) == TYPE_MAX_VALUE (type)
2328 || tree_int_cst_equal (TYPE_MAX_VALUE (h->type),
2329 TYPE_MAX_VALUE (type)))
2330 && (TYPE_MIN_VALUE (h->type) == TYPE_MIN_VALUE (type)
2331 || tree_int_cst_equal (TYPE_MIN_VALUE (h->type),
2332 TYPE_MIN_VALUE (type)))
2333 && (TYPE_DOMAIN (h->type) == TYPE_DOMAIN (type)
2334 || (TYPE_DOMAIN (h->type)
2335 && TREE_CODE (TYPE_DOMAIN (h->type)) == TREE_LIST
2336 && TYPE_DOMAIN (type)
2337 && TREE_CODE (TYPE_DOMAIN (type)) == TREE_LIST
2338 && type_list_equal (TYPE_DOMAIN (h->type), TYPE_DOMAIN (type)))))
2343 /* Add an entry to the type-hash-table
2344 for a type TYPE whose hash code is HASHCODE. */
2347 type_hash_add (hashcode, type)
2351 register struct type_hash *h;
2353 h = (struct type_hash *) oballoc (sizeof (struct type_hash));
2354 h->hashcode = hashcode;
2356 h->next = type_hash_table[hashcode % TYPE_HASH_SIZE];
2357 type_hash_table[hashcode % TYPE_HASH_SIZE] = h;
2360 /* Given TYPE, and HASHCODE its hash code, return the canonical
2361 object for an identical type if one already exists.
2362 Otherwise, return TYPE, and record it as the canonical object
2363 if it is a permanent object.
2365 To use this function, first create a type of the sort you want.
2366 Then compute its hash code from the fields of the type that
2367 make it different from other similar types.
2368 Then call this function and use the value.
2369 This function frees the type you pass in if it is a duplicate. */
2371 /* Set to 1 to debug without canonicalization. Never set by program. */
2372 int debug_no_type_hash = 0;
2375 type_hash_canon (hashcode, type)
2381 if (debug_no_type_hash)
2384 t1 = type_hash_lookup (hashcode, type);
2388 = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
2389 obstack_free (o, type);
2390 #ifdef GATHER_STATISTICS
2391 tree_node_counts[(int)t_kind]--;
2392 tree_node_sizes[(int)t_kind] -= sizeof (struct tree_type);
2397 /* If this is a new type, record it for later reuse. */
2398 if (current_obstack == &permanent_obstack)
2399 type_hash_add (hashcode, type);
2404 /* Given two lists of types
2405 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
2406 return 1 if the lists contain the same types in the same order.
2407 Also, the TREE_PURPOSEs must match. */
2410 type_list_equal (l1, l2)
2413 register tree t1, t2;
2414 for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
2416 if (TREE_VALUE (t1) != TREE_VALUE (t2))
2418 if (TREE_PURPOSE (t1) != TREE_PURPOSE (t2))
2420 int cmp = simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
2431 /* Nonzero if integer constants T1 and T2
2432 represent the same constant value. */
2435 tree_int_cst_equal (t1, t2)
2440 if (t1 == 0 || t2 == 0)
2442 if (TREE_CODE (t1) == INTEGER_CST
2443 && TREE_CODE (t2) == INTEGER_CST
2444 && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
2445 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
2450 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
2451 The precise way of comparison depends on their data type. */
2454 tree_int_cst_lt (t1, t2)
2460 if (!TREE_UNSIGNED (TREE_TYPE (t1)))
2461 return INT_CST_LT (t1, t2);
2462 return INT_CST_LT_UNSIGNED (t1, t2);
2465 /* Compare two constructor-element-type constants. */
2467 simple_cst_list_equal (l1, l2)
2470 while (l1 != NULL_TREE && l2 != NULL_TREE)
2472 int cmp = simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2));
2477 l1 = TREE_CHAIN (l1);
2478 l2 = TREE_CHAIN (l2);
2483 /* Return truthvalue of whether T1 is the same tree structure as T2.
2484 Return 1 if they are the same.
2485 Return 0 if they are understandably different.
2486 Return -1 if either contains tree structure not understood by
2490 simple_cst_equal (t1, t2)
2493 register enum tree_code code1, code2;
2498 if (t1 == 0 || t2 == 0)
2501 code1 = TREE_CODE (t1);
2502 code2 = TREE_CODE (t2);
2504 if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
2505 if (code2 == NOP_EXPR || code2 == CONVERT_EXPR || code2 == NON_LVALUE_EXPR)
2506 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2508 return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
2509 else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
2510 || code2 == NON_LVALUE_EXPR)
2511 return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
2519 return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
2520 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
2523 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2526 return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2527 && !bcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2528 TREE_STRING_LENGTH (t1));
2534 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2537 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2540 return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
2543 /* Special case: if either target is an unallocated VAR_DECL,
2544 it means that it's going to be unified with whatever the
2545 TARGET_EXPR is really supposed to initialize, so treat it
2546 as being equivalent to anything. */
2547 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
2548 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
2549 && DECL_RTL (TREE_OPERAND (t1, 0)) == 0)
2550 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
2551 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
2552 && DECL_RTL (TREE_OPERAND (t2, 0)) == 0))
2555 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2558 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
2560 case WITH_CLEANUP_EXPR:
2561 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2564 return simple_cst_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t1, 2));
2567 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
2568 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2572 return (simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
2573 && simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1))
2574 && simple_cst_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t2, 2)));
2585 case TRUNC_DIV_EXPR:
2586 case TRUNC_MOD_EXPR:
2589 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2592 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
2596 case REFERENCE_EXPR:
2598 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2602 return lang_simple_cst_equal (t1, t2);
2609 /* Constructors for pointer, array and function types.
2610 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
2611 constructed by language-dependent code, not here.) */
2613 /* Construct, lay out and return the type of pointers to TO_TYPE.
2614 If such a type has already been constructed, reuse it. */
2617 build_pointer_type (to_type)
2620 register tree t = TYPE_POINTER_TO (to_type);
2621 register struct obstack *ambient_obstack = current_obstack;
2622 register struct obstack *ambient_saveable_obstack = saveable_obstack;
2624 /* First, if we already have a type for pointers to TO_TYPE, use it. */
2629 /* We need a new one. If TO_TYPE is permanent, make this permanent too. */
2630 if (TREE_PERMANENT (to_type))
2632 current_obstack = &permanent_obstack;
2633 saveable_obstack = &permanent_obstack;
2636 t = make_node (POINTER_TYPE);
2637 TREE_TYPE (t) = to_type;
2639 /* Record this type as the pointer to TO_TYPE. */
2640 TYPE_POINTER_TO (to_type) = t;
2642 /* Lay out the type. This function has many callers that are concerned
2643 with expression-construction, and this simplifies them all.
2644 Also, it guarantees the TYPE_SIZE is permanent if the type is. */
2647 current_obstack = ambient_obstack;
2648 saveable_obstack = ambient_saveable_obstack;
2652 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
2653 MAXVAL should be the maximum value in the domain
2654 (one less than the length of the array). */
2657 build_index_type (maxval)
2660 register tree itype = make_node (INTEGER_TYPE);
2661 TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
2662 TYPE_MIN_VALUE (itype) = build_int_2 (0, 0);
2663 TREE_TYPE (TYPE_MIN_VALUE (itype)) = sizetype;
2664 TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);
2665 TYPE_MODE (itype) = TYPE_MODE (sizetype);
2666 TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
2667 TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
2668 if (TREE_CODE (maxval) == INTEGER_CST)
2670 int maxint = (int) TREE_INT_CST_LOW (maxval);
2671 return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype);
2677 /* Just like build_index_type, but takes lowval and highval instead
2678 of just highval (maxval). */
2681 build_index_2_type (lowval,highval)
2682 tree lowval, highval;
2684 register tree itype = make_node (INTEGER_TYPE);
2685 TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
2686 TYPE_MIN_VALUE (itype) = convert (sizetype, lowval);
2687 TYPE_MAX_VALUE (itype) = convert (sizetype, highval);
2688 TYPE_MODE (itype) = TYPE_MODE (sizetype);
2689 TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
2690 TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
2691 if ((TREE_CODE (lowval) == INTEGER_CST)
2692 && (TREE_CODE (highval) == INTEGER_CST))
2694 HOST_WIDE_INT highint = TREE_INT_CST_LOW (highval);
2695 HOST_WIDE_INT lowint = TREE_INT_CST_LOW (lowval);
2696 int maxint = (int) (highint - lowint);
2697 return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype);
2703 /* Return nonzero iff ITYPE1 and ITYPE2 are equal (in the LISP sense).
2704 Needed because when index types are not hashed, equal index types
2705 built at different times appear distinct, even though structurally,
2709 index_type_equal (itype1, itype2)
2710 tree itype1, itype2;
2712 if (TREE_CODE (itype1) != TREE_CODE (itype2))
2714 if (TREE_CODE (itype1) == INTEGER_TYPE)
2716 if (TYPE_PRECISION (itype1) != TYPE_PRECISION (itype2)
2717 || TYPE_MODE (itype1) != TYPE_MODE (itype2)
2718 || ! simple_cst_equal (TYPE_SIZE (itype1), TYPE_SIZE (itype2))
2719 || TYPE_ALIGN (itype1) != TYPE_ALIGN (itype2))
2721 if (simple_cst_equal (TYPE_MIN_VALUE (itype1), TYPE_MIN_VALUE (itype2))
2722 && simple_cst_equal (TYPE_MAX_VALUE (itype1), TYPE_MAX_VALUE (itype2)))
2728 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
2729 and number of elements specified by the range of values of INDEX_TYPE.
2730 If such a type has already been constructed, reuse it. */
2733 build_array_type (elt_type, index_type)
2734 tree elt_type, index_type;
2739 if (TREE_CODE (elt_type) == FUNCTION_TYPE)
2741 error ("arrays of functions are not meaningful");
2742 elt_type = integer_type_node;
2745 /* Make sure TYPE_POINTER_TO (elt_type) is filled in. */
2746 build_pointer_type (elt_type);
2748 /* Allocate the array after the pointer type,
2749 in case we free it in type_hash_canon. */
2750 t = make_node (ARRAY_TYPE);
2751 TREE_TYPE (t) = elt_type;
2752 TYPE_DOMAIN (t) = index_type;
2754 if (index_type == 0)
2757 hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type);
2758 t = type_hash_canon (hashcode, t);
2760 if (TYPE_SIZE (t) == 0)
2765 /* Construct, lay out and return
2766 the type of functions returning type VALUE_TYPE
2767 given arguments of types ARG_TYPES.
2768 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
2769 are data type nodes for the arguments of the function.
2770 If such a type has already been constructed, reuse it. */
2773 build_function_type (value_type, arg_types)
2774 tree value_type, arg_types;
2779 if (TREE_CODE (value_type) == FUNCTION_TYPE
2780 || TREE_CODE (value_type) == ARRAY_TYPE)
2782 error ("function return type cannot be function or array");
2783 value_type = integer_type_node;
2786 /* Make a node of the sort we want. */
2787 t = make_node (FUNCTION_TYPE);
2788 TREE_TYPE (t) = value_type;
2789 TYPE_ARG_TYPES (t) = arg_types;
2791 /* If we already have such a type, use the old one and free this one. */
2792 hashcode = TYPE_HASH (value_type) + type_hash_list (arg_types);
2793 t = type_hash_canon (hashcode, t);
2795 if (TYPE_SIZE (t) == 0)
2800 /* Build the node for the type of references-to-TO_TYPE. */
2803 build_reference_type (to_type)
2806 register tree t = TYPE_REFERENCE_TO (to_type);
2807 register struct obstack *ambient_obstack = current_obstack;
2808 register struct obstack *ambient_saveable_obstack = saveable_obstack;
2810 /* First, if we already have a type for pointers to TO_TYPE, use it. */
2815 /* We need a new one. If TO_TYPE is permanent, make this permanent too. */
2816 if (TREE_PERMANENT (to_type))
2818 current_obstack = &permanent_obstack;
2819 saveable_obstack = &permanent_obstack;
2822 t = make_node (REFERENCE_TYPE);
2823 TREE_TYPE (t) = to_type;
2825 /* Record this type as the pointer to TO_TYPE. */
2826 TYPE_REFERENCE_TO (to_type) = t;
2830 current_obstack = ambient_obstack;
2831 saveable_obstack = ambient_saveable_obstack;
2835 /* Construct, lay out and return the type of methods belonging to class
2836 BASETYPE and whose arguments and values are described by TYPE.
2837 If that type exists already, reuse it.
2838 TYPE must be a FUNCTION_TYPE node. */
2841 build_method_type (basetype, type)
2842 tree basetype, type;
2847 /* Make a node of the sort we want. */
2848 t = make_node (METHOD_TYPE);
2850 if (TREE_CODE (type) != FUNCTION_TYPE)
2853 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
2854 TREE_TYPE (t) = TREE_TYPE (type);
2856 /* The actual arglist for this function includes a "hidden" argument
2857 which is "this". Put it into the list of argument types. */
2860 = tree_cons (NULL_TREE,
2861 build_pointer_type (basetype), TYPE_ARG_TYPES (type));
2863 /* If we already have such a type, use the old one and free this one. */
2864 hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
2865 t = type_hash_canon (hashcode, t);
2867 if (TYPE_SIZE (t) == 0)
2873 /* Construct, lay out and return the type of methods belonging to class
2874 BASETYPE and whose arguments and values are described by TYPE.
2875 If that type exists already, reuse it.
2876 TYPE must be a FUNCTION_TYPE node. */
2879 build_offset_type (basetype, type)
2880 tree basetype, type;
2885 /* Make a node of the sort we want. */
2886 t = make_node (OFFSET_TYPE);
2888 TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
2889 TREE_TYPE (t) = type;
2891 /* If we already have such a type, use the old one and free this one. */
2892 hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
2893 t = type_hash_canon (hashcode, t);
2895 if (TYPE_SIZE (t) == 0)
2901 /* Create a complex type whose components are COMPONENT_TYPE. */
2904 build_complex_type (component_type)
2905 tree component_type;
2910 /* Make a node of the sort we want. */
2911 t = make_node (COMPLEX_TYPE);
2913 TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
2914 TYPE_VOLATILE (t) = TYPE_VOLATILE (component_type);
2915 TYPE_READONLY (t) = TYPE_READONLY (component_type);
2917 /* If we already have such a type, use the old one and free this one. */
2918 hashcode = TYPE_HASH (component_type);
2919 t = type_hash_canon (hashcode, t);
2921 if (TYPE_SIZE (t) == 0)
2927 /* Return OP, stripped of any conversions to wider types as much as is safe.
2928 Converting the value back to OP's type makes a value equivalent to OP.
2930 If FOR_TYPE is nonzero, we return a value which, if converted to
2931 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
2933 If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
2934 narrowest type that can hold the value, even if they don't exactly fit.
2935 Otherwise, bit-field references are changed to a narrower type
2936 only if they can be fetched directly from memory in that type.
2938 OP must have integer, real or enumeral type. Pointers are not allowed!
2940 There are some cases where the obvious value we could return
2941 would regenerate to OP if converted to OP's type,
2942 but would not extend like OP to wider types.
2943 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
2944 For example, if OP is (unsigned short)(signed char)-1,
2945 we avoid returning (signed char)-1 if FOR_TYPE is int,
2946 even though extending that to an unsigned short would regenerate OP,
2947 since the result of extending (signed char)-1 to (int)
2948 is different from (int) OP. */
2951 get_unwidened (op, for_type)
2955 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
2956 /* TYPE_PRECISION is safe in place of type_precision since
2957 pointer types are not allowed. */
2958 register tree type = TREE_TYPE (op);
2959 register unsigned final_prec
2960 = TYPE_PRECISION (for_type != 0 ? for_type : type);
2962 = (for_type != 0 && for_type != type
2963 && final_prec > TYPE_PRECISION (type)
2964 && TREE_UNSIGNED (type));
2965 register tree win = op;
2967 while (TREE_CODE (op) == NOP_EXPR)
2969 register int bitschange
2970 = TYPE_PRECISION (TREE_TYPE (op))
2971 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
2973 /* Truncations are many-one so cannot be removed.
2974 Unless we are later going to truncate down even farther. */
2976 && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
2979 /* See what's inside this conversion. If we decide to strip it,
2981 op = TREE_OPERAND (op, 0);
2983 /* If we have not stripped any zero-extensions (uns is 0),
2984 we can strip any kind of extension.
2985 If we have previously stripped a zero-extension,
2986 only zero-extensions can safely be stripped.
2987 Any extension can be stripped if the bits it would produce
2988 are all going to be discarded later by truncating to FOR_TYPE. */
2992 if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
2994 /* TREE_UNSIGNED says whether this is a zero-extension.
2995 Let's avoid computing it if it does not affect WIN
2996 and if UNS will not be needed again. */
2997 if ((uns || TREE_CODE (op) == NOP_EXPR)
2998 && TREE_UNSIGNED (TREE_TYPE (op)))
3006 if (TREE_CODE (op) == COMPONENT_REF
3007 /* Since type_for_size always gives an integer type. */
3008 && TREE_CODE (type) != REAL_TYPE)
3010 unsigned innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
3011 type = type_for_size (innerprec, TREE_UNSIGNED (TREE_OPERAND (op, 1)));
3013 /* We can get this structure field in the narrowest type it fits in.
3014 If FOR_TYPE is 0, do this only for a field that matches the
3015 narrower type exactly and is aligned for it
3016 The resulting extension to its nominal type (a fullword type)
3017 must fit the same conditions as for other extensions. */
3019 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
3020 && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))
3021 && (! uns || final_prec <= innerprec
3022 || TREE_UNSIGNED (TREE_OPERAND (op, 1)))
3025 win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
3026 TREE_OPERAND (op, 1));
3027 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
3028 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
3029 TREE_RAISES (win) = TREE_RAISES (op);
3035 /* Return OP or a simpler expression for a narrower value
3036 which can be sign-extended or zero-extended to give back OP.
3037 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
3038 or 0 if the value should be sign-extended. */
3041 get_narrower (op, unsignedp_ptr)
3045 register int uns = 0;
3047 register tree win = op;
3049 while (TREE_CODE (op) == NOP_EXPR)
3051 register int bitschange
3052 = TYPE_PRECISION (TREE_TYPE (op))
3053 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
3055 /* Truncations are many-one so cannot be removed. */
3059 /* See what's inside this conversion. If we decide to strip it,
3061 op = TREE_OPERAND (op, 0);
3065 /* An extension: the outermost one can be stripped,
3066 but remember whether it is zero or sign extension. */
3068 uns = TREE_UNSIGNED (TREE_TYPE (op));
3069 /* Otherwise, if a sign extension has been stripped,
3070 only sign extensions can now be stripped;
3071 if a zero extension has been stripped, only zero-extensions. */
3072 else if (uns != TREE_UNSIGNED (TREE_TYPE (op)))
3076 /* A change in nominal type can always be stripped. */
3081 if (TREE_CODE (op) == COMPONENT_REF
3082 /* Since type_for_size always gives an integer type. */
3083 && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE)
3085 unsigned innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
3086 tree type = type_for_size (innerprec, TREE_UNSIGNED (op));
3088 /* We can get this structure field in a narrower type that fits it,
3089 but the resulting extension to its nominal type (a fullword type)
3090 must satisfy the same conditions as for other extensions.
3092 Do this only for fields that are aligned (not bit-fields),
3093 because when bit-field insns will be used there is no
3094 advantage in doing this. */
3096 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
3097 && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
3098 && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1)))
3102 uns = TREE_UNSIGNED (TREE_OPERAND (op, 1));
3103 win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
3104 TREE_OPERAND (op, 1));
3105 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
3106 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
3107 TREE_RAISES (win) = TREE_RAISES (op);
3110 *unsignedp_ptr = uns;
3114 /* Return the precision of a type, for arithmetic purposes.
3115 Supports all types on which arithmetic is possible
3116 (including pointer types).
3117 It's not clear yet what will be right for complex types. */
3120 type_precision (type)
3123 return ((TREE_CODE (type) == INTEGER_TYPE
3124 || TREE_CODE (type) == ENUMERAL_TYPE
3125 || TREE_CODE (type) == REAL_TYPE)
3126 ? TYPE_PRECISION (type) : POINTER_SIZE);
3129 /* Nonzero if integer constant C has a value that is permissible
3130 for type TYPE (an INTEGER_TYPE). */
3133 int_fits_type_p (c, type)
3136 if (TREE_UNSIGNED (type))
3137 return (!INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type), c)
3138 && !INT_CST_LT_UNSIGNED (c, TYPE_MIN_VALUE (type))
3139 && (TREE_INT_CST_HIGH (c) >= 0 || TREE_UNSIGNED (TREE_TYPE (c))));
3141 return (!INT_CST_LT (TYPE_MAX_VALUE (type), c)
3142 && !INT_CST_LT (c, TYPE_MIN_VALUE (type))
3143 && (TREE_INT_CST_HIGH (c) >= 0 || !TREE_UNSIGNED (TREE_TYPE (c))));
3146 /* Return the innermost context enclosing DECL that is
3147 a FUNCTION_DECL, or zero if none. */
3150 decl_function_context (decl)
3155 if (TREE_CODE (decl) == ERROR_MARK)
3158 if (TREE_CODE (decl) == SAVE_EXPR)
3159 context = SAVE_EXPR_CONTEXT (decl);
3161 context = DECL_CONTEXT (decl);
3163 while (context && TREE_CODE (context) != FUNCTION_DECL)
3165 if (TREE_CODE (context) == RECORD_TYPE
3166 || TREE_CODE (context) == UNION_TYPE)
3167 context = TYPE_CONTEXT (context);
3168 else if (TREE_CODE (context) == TYPE_DECL)
3169 context = DECL_CONTEXT (context);
3170 else if (TREE_CODE (context) == BLOCK)
3171 context = BLOCK_SUPERCONTEXT (context);
3173 /* Unhandled CONTEXT !? */
3180 /* Return the innermost context enclosing DECL that is
3181 a RECORD_TYPE or UNION_TYPE, or zero if none.
3182 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
3185 decl_type_context (decl)
3188 tree context = DECL_CONTEXT (decl);
3192 if (TREE_CODE (context) == RECORD_TYPE
3193 || TREE_CODE (context) == UNION_TYPE)
3195 if (TREE_CODE (context) == TYPE_DECL
3196 || TREE_CODE (context) == FUNCTION_DECL)
3197 context = DECL_CONTEXT (context);
3198 else if (TREE_CODE (context) == BLOCK)
3199 context = BLOCK_SUPERCONTEXT (context);
3201 /* Unhandled CONTEXT!? */
3208 print_obstack_statistics (str, o)
3212 struct _obstack_chunk *chunk = o->chunk;
3219 n_alloc += chunk->limit - &chunk->contents[0];
3220 chunk = chunk->prev;
3222 fprintf (stderr, "obstack %s: %d bytes, %d chunks\n",
3223 str, n_alloc, n_chunks);
3226 dump_tree_statistics ()
3229 int total_nodes, total_bytes;
3231 fprintf (stderr, "\n??? tree nodes created\n\n");
3232 #ifdef GATHER_STATISTICS
3233 fprintf (stderr, "Kind Nodes Bytes\n");
3234 fprintf (stderr, "-------------------------------------\n");
3235 total_nodes = total_bytes = 0;
3236 for (i = 0; i < (int) all_kinds; i++)
3238 fprintf (stderr, "%-20s %6d %9d\n", tree_node_kind_names[i],
3239 tree_node_counts[i], tree_node_sizes[i]);
3240 total_nodes += tree_node_counts[i];
3241 total_bytes += tree_node_sizes[i];
3243 fprintf (stderr, "%-20s %9d\n", "identifier names", id_string_size);
3244 fprintf (stderr, "-------------------------------------\n");
3245 fprintf (stderr, "%-20s %6d %9d\n", "Total", total_nodes, total_bytes);
3246 fprintf (stderr, "-------------------------------------\n");
3248 fprintf (stderr, "(No per-node statistics)\n");
3250 print_lang_statistics ();