1 /* Language-independent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994 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. */
48 #define obstack_chunk_alloc xmalloc
49 #define obstack_chunk_free free
51 /* Tree nodes of permanent duration are allocated in this obstack.
52 They are the identifier nodes, and everything outside of
53 the bodies and parameters of function definitions. */
55 struct obstack permanent_obstack
;
57 /* The initial RTL, and all ..._TYPE nodes, in a function
58 are allocated in this obstack. Usually they are freed at the
59 end of the function, but if the function is inline they are saved.
60 For top-level functions, this is maybepermanent_obstack.
61 Separate obstacks are made for nested functions. */
63 struct obstack
*function_maybepermanent_obstack
;
65 /* This is the function_maybepermanent_obstack for top-level functions. */
67 struct obstack maybepermanent_obstack
;
69 /* The contents of the current function definition are allocated
70 in this obstack, and all are freed at the end of the function.
71 For top-level functions, this is temporary_obstack.
72 Separate obstacks are made for nested functions. */
74 struct obstack
*function_obstack
;
76 /* This is used for reading initializers of global variables. */
78 struct obstack temporary_obstack
;
80 /* The tree nodes of an expression are allocated
81 in this obstack, and all are freed at the end of the expression. */
83 struct obstack momentary_obstack
;
85 /* The tree nodes of a declarator are allocated
86 in this obstack, and all are freed when the declarator
89 static struct obstack temp_decl_obstack
;
91 /* This points at either permanent_obstack
92 or the current function_maybepermanent_obstack. */
94 struct obstack
*saveable_obstack
;
96 /* This is same as saveable_obstack during parse and expansion phase;
97 it points to the current function's obstack during optimization.
98 This is the obstack to be used for creating rtl objects. */
100 struct obstack
*rtl_obstack
;
102 /* This points at either permanent_obstack or the current function_obstack. */
104 struct obstack
*current_obstack
;
106 /* This points at either permanent_obstack or the current function_obstack
107 or momentary_obstack. */
109 struct obstack
*expression_obstack
;
111 /* Stack of obstack selections for push_obstacks and pop_obstacks. */
115 struct obstack_stack
*next
;
116 struct obstack
*current
;
117 struct obstack
*saveable
;
118 struct obstack
*expression
;
122 struct obstack_stack
*obstack_stack
;
124 /* Obstack for allocating struct obstack_stack entries. */
126 static struct obstack obstack_stack_obstack
;
128 /* Addresses of first objects in some obstacks.
129 This is for freeing their entire contents. */
130 char *maybepermanent_firstobj
;
131 char *temporary_firstobj
;
132 char *momentary_firstobj
;
133 char *temp_decl_firstobj
;
135 /* This is used to preserve objects (mainly array initializers) that need to
136 live until the end of the current function, but no further. */
137 char *momentary_function_firstobj
;
139 /* Nonzero means all ..._TYPE nodes should be allocated permanently. */
141 int all_types_permanent
;
143 /* Stack of places to restore the momentary obstack back to. */
145 struct momentary_level
147 /* Pointer back to previous such level. */
148 struct momentary_level
*prev
;
149 /* First object allocated within this level. */
151 /* Value of expression_obstack saved at entry to this level. */
152 struct obstack
*obstack
;
155 struct momentary_level
*momentary_stack
;
157 /* Table indexed by tree code giving a string containing a character
158 classifying the tree code. Possibilities are
159 t, d, s, c, r, <, 1, 2 and e. See tree.def for details. */
161 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
163 char *standard_tree_code_type
[] = {
168 /* Table indexed by tree code giving number of expression
169 operands beyond the fixed part of the node structure.
170 Not used for types or decls. */
172 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
174 int standard_tree_code_length
[] = {
179 /* Names of tree components.
180 Used for printing out the tree and error messages. */
181 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
183 char *standard_tree_code_name
[] = {
188 /* Table indexed by tree code giving a string containing a character
189 classifying the tree code. Possibilities are
190 t, d, s, c, r, e, <, 1 and 2. See tree.def for details. */
192 char **tree_code_type
;
194 /* Table indexed by tree code giving number of expression
195 operands beyond the fixed part of the node structure.
196 Not used for types or decls. */
198 int *tree_code_length
;
200 /* Table indexed by tree code giving name of tree code, as a string. */
202 char **tree_code_name
;
204 /* Statistics-gathering stuff. */
225 int tree_node_counts
[(int)all_kinds
];
226 int tree_node_sizes
[(int)all_kinds
];
227 int id_string_size
= 0;
229 char *tree_node_kind_names
[] = {
247 /* Hash table for uniquizing IDENTIFIER_NODEs by name. */
249 #define MAX_HASH_TABLE 1009
250 static tree hash_table
[MAX_HASH_TABLE
]; /* id hash buckets */
252 /* 0 while creating built-in identifiers. */
253 static int do_identifier_warnings
;
255 /* Unique id for next decl created. */
256 static int next_decl_uid
;
257 /* Unique id for next type created. */
258 static int next_type_uid
= 1;
260 /* Here is how primitive or already-canonicalized types' hash
262 #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
264 extern char *mode_name
[];
266 void gcc_obstack_init ();
267 static tree
stabilize_reference_1 ();
269 /* Init the principal obstacks. */
274 gcc_obstack_init (&obstack_stack_obstack
);
275 gcc_obstack_init (&permanent_obstack
);
277 gcc_obstack_init (&temporary_obstack
);
278 temporary_firstobj
= (char *) obstack_alloc (&temporary_obstack
, 0);
279 gcc_obstack_init (&momentary_obstack
);
280 momentary_firstobj
= (char *) obstack_alloc (&momentary_obstack
, 0);
281 momentary_function_firstobj
= momentary_firstobj
;
282 gcc_obstack_init (&maybepermanent_obstack
);
283 maybepermanent_firstobj
284 = (char *) obstack_alloc (&maybepermanent_obstack
, 0);
285 gcc_obstack_init (&temp_decl_obstack
);
286 temp_decl_firstobj
= (char *) obstack_alloc (&temp_decl_obstack
, 0);
288 function_obstack
= &temporary_obstack
;
289 function_maybepermanent_obstack
= &maybepermanent_obstack
;
290 current_obstack
= &permanent_obstack
;
291 expression_obstack
= &permanent_obstack
;
292 rtl_obstack
= saveable_obstack
= &permanent_obstack
;
294 /* Init the hash table of identifiers. */
295 bzero ((char *) hash_table
, sizeof hash_table
);
299 gcc_obstack_init (obstack
)
300 struct obstack
*obstack
;
302 /* Let particular systems override the size of a chunk. */
303 #ifndef OBSTACK_CHUNK_SIZE
304 #define OBSTACK_CHUNK_SIZE 0
306 /* Let them override the alloc and free routines too. */
307 #ifndef OBSTACK_CHUNK_ALLOC
308 #define OBSTACK_CHUNK_ALLOC xmalloc
310 #ifndef OBSTACK_CHUNK_FREE
311 #define OBSTACK_CHUNK_FREE free
313 _obstack_begin (obstack
, OBSTACK_CHUNK_SIZE
, 0,
314 (void *(*) ()) OBSTACK_CHUNK_ALLOC
,
315 (void (*) ()) OBSTACK_CHUNK_FREE
);
318 /* Save all variables describing the current status into the structure *P.
319 This is used before starting a nested function. */
325 p
->all_types_permanent
= all_types_permanent
;
326 p
->momentary_stack
= momentary_stack
;
327 p
->maybepermanent_firstobj
= maybepermanent_firstobj
;
328 p
->momentary_firstobj
= momentary_firstobj
;
329 p
->momentary_function_firstobj
= momentary_function_firstobj
;
330 p
->function_obstack
= function_obstack
;
331 p
->function_maybepermanent_obstack
= function_maybepermanent_obstack
;
332 p
->current_obstack
= current_obstack
;
333 p
->expression_obstack
= expression_obstack
;
334 p
->saveable_obstack
= saveable_obstack
;
335 p
->rtl_obstack
= rtl_obstack
;
337 /* Objects that need to be saved in this function can be in the nonsaved
338 obstack of the enclosing function since they can't possibly be needed
339 once it has returned. */
340 function_maybepermanent_obstack
= function_obstack
;
342 function_obstack
= (struct obstack
*) xmalloc (sizeof (struct obstack
));
343 gcc_obstack_init (function_obstack
);
345 current_obstack
= &permanent_obstack
;
346 expression_obstack
= &permanent_obstack
;
347 rtl_obstack
= saveable_obstack
= &permanent_obstack
;
349 momentary_firstobj
= (char *) obstack_finish (&momentary_obstack
);
350 momentary_function_firstobj
= momentary_firstobj
;
351 maybepermanent_firstobj
352 = (char *) obstack_finish (function_maybepermanent_obstack
);
355 /* Restore all variables describing the current status from the structure *P.
356 This is used after a nested function. */
359 restore_tree_status (p
)
362 all_types_permanent
= p
->all_types_permanent
;
363 momentary_stack
= p
->momentary_stack
;
365 obstack_free (&momentary_obstack
, momentary_function_firstobj
);
367 /* Free saveable storage used by the function just compiled and not
370 CAUTION: This is in function_obstack of the containing function. So
371 we must be sure that we never allocate from that obstack during
372 the compilation of a nested function if we expect it to survive past the
373 nested function's end. */
374 obstack_free (function_maybepermanent_obstack
, maybepermanent_firstobj
);
376 obstack_free (function_obstack
, 0);
377 free (function_obstack
);
379 momentary_firstobj
= p
->momentary_firstobj
;
380 momentary_function_firstobj
= p
->momentary_function_firstobj
;
381 maybepermanent_firstobj
= p
->maybepermanent_firstobj
;
382 function_obstack
= p
->function_obstack
;
383 function_maybepermanent_obstack
= p
->function_maybepermanent_obstack
;
384 current_obstack
= p
->current_obstack
;
385 expression_obstack
= p
->expression_obstack
;
386 saveable_obstack
= p
->saveable_obstack
;
387 rtl_obstack
= p
->rtl_obstack
;
390 /* Start allocating on the temporary (per function) obstack.
391 This is done in start_function before parsing the function body,
392 and before each initialization at top level, and to go back
393 to temporary allocation after doing permanent_allocation. */
396 temporary_allocation ()
398 /* Note that function_obstack at top level points to temporary_obstack.
399 But within a nested function context, it is a separate obstack. */
400 current_obstack
= function_obstack
;
401 expression_obstack
= function_obstack
;
402 rtl_obstack
= saveable_obstack
= function_maybepermanent_obstack
;
406 /* Start allocating on the permanent obstack but don't
407 free the temporary data. After calling this, call
408 `permanent_allocation' to fully resume permanent allocation status. */
411 end_temporary_allocation ()
413 current_obstack
= &permanent_obstack
;
414 expression_obstack
= &permanent_obstack
;
415 rtl_obstack
= saveable_obstack
= &permanent_obstack
;
418 /* Resume allocating on the temporary obstack, undoing
419 effects of `end_temporary_allocation'. */
422 resume_temporary_allocation ()
424 current_obstack
= function_obstack
;
425 expression_obstack
= function_obstack
;
426 rtl_obstack
= saveable_obstack
= function_maybepermanent_obstack
;
429 /* While doing temporary allocation, switch to allocating in such a
430 way as to save all nodes if the function is inlined. Call
431 resume_temporary_allocation to go back to ordinary temporary
435 saveable_allocation ()
437 /* Note that function_obstack at top level points to temporary_obstack.
438 But within a nested function context, it is a separate obstack. */
439 expression_obstack
= current_obstack
= saveable_obstack
;
442 /* Switch to current obstack CURRENT and maybepermanent obstack SAVEABLE,
443 recording the previously current obstacks on a stack.
444 This does not free any storage in any obstack. */
447 push_obstacks (current
, saveable
)
448 struct obstack
*current
, *saveable
;
450 struct obstack_stack
*p
451 = (struct obstack_stack
*) obstack_alloc (&obstack_stack_obstack
,
452 (sizeof (struct obstack_stack
)));
454 p
->current
= current_obstack
;
455 p
->saveable
= saveable_obstack
;
456 p
->expression
= expression_obstack
;
457 p
->rtl
= rtl_obstack
;
458 p
->next
= obstack_stack
;
461 current_obstack
= current
;
462 expression_obstack
= current
;
463 rtl_obstack
= saveable_obstack
= saveable
;
466 /* Save the current set of obstacks, but don't change them. */
469 push_obstacks_nochange ()
471 struct obstack_stack
*p
472 = (struct obstack_stack
*) obstack_alloc (&obstack_stack_obstack
,
473 (sizeof (struct obstack_stack
)));
475 p
->current
= current_obstack
;
476 p
->saveable
= saveable_obstack
;
477 p
->expression
= expression_obstack
;
478 p
->rtl
= rtl_obstack
;
479 p
->next
= obstack_stack
;
483 /* Pop the obstack selection stack. */
488 struct obstack_stack
*p
= obstack_stack
;
489 obstack_stack
= p
->next
;
491 current_obstack
= p
->current
;
492 saveable_obstack
= p
->saveable
;
493 expression_obstack
= p
->expression
;
494 rtl_obstack
= p
->rtl
;
496 obstack_free (&obstack_stack_obstack
, p
);
499 /* Nonzero if temporary allocation is currently in effect.
500 Zero if currently doing permanent allocation. */
503 allocation_temporary_p ()
505 return current_obstack
!= &permanent_obstack
;
508 /* Go back to allocating on the permanent obstack
509 and free everything in the temporary obstack.
511 FUNCTION_END is true only if we have just finished compiling a function.
512 In that case, we also free preserved initial values on the momentary
516 permanent_allocation (function_end
)
519 /* Free up previous temporary obstack data */
520 obstack_free (&temporary_obstack
, temporary_firstobj
);
522 obstack_free (&momentary_obstack
, momentary_function_firstobj
);
524 obstack_free (&momentary_obstack
, momentary_firstobj
);
525 obstack_free (&maybepermanent_obstack
, maybepermanent_firstobj
);
526 obstack_free (&temp_decl_obstack
, temp_decl_firstobj
);
528 current_obstack
= &permanent_obstack
;
529 expression_obstack
= &permanent_obstack
;
530 rtl_obstack
= saveable_obstack
= &permanent_obstack
;
533 /* Save permanently everything on the maybepermanent_obstack. */
538 maybepermanent_firstobj
539 = (char *) obstack_alloc (function_maybepermanent_obstack
, 0);
543 preserve_initializer ()
545 struct momentary_level
*tem
;
549 = (char *) obstack_alloc (&temporary_obstack
, 0);
550 maybepermanent_firstobj
551 = (char *) obstack_alloc (function_maybepermanent_obstack
, 0);
553 old_momentary
= momentary_firstobj
;
555 = (char *) obstack_alloc (&momentary_obstack
, 0);
556 if (momentary_firstobj
!= old_momentary
)
557 for (tem
= momentary_stack
; tem
; tem
= tem
->prev
)
558 tem
->base
= momentary_firstobj
;
561 /* Start allocating new rtl in current_obstack.
562 Use resume_temporary_allocation
563 to go back to allocating rtl in saveable_obstack. */
566 rtl_in_current_obstack ()
568 rtl_obstack
= current_obstack
;
571 /* Start allocating rtl from saveable_obstack. Intended to be used after
572 a call to push_obstacks_nochange. */
575 rtl_in_saveable_obstack ()
577 rtl_obstack
= saveable_obstack
;
580 /* Allocate SIZE bytes in the current obstack
581 and return a pointer to them.
582 In practice the current obstack is always the temporary one. */
588 return (char *) obstack_alloc (current_obstack
, size
);
591 /* Free the object PTR in the current obstack
592 as well as everything allocated since PTR.
593 In practice the current obstack is always the temporary one. */
599 obstack_free (current_obstack
, ptr
);
602 /* Allocate SIZE bytes in the permanent obstack
603 and return a pointer to them. */
609 return (char *) obstack_alloc (&permanent_obstack
, size
);
612 /* Allocate NELEM items of SIZE bytes in the permanent obstack
613 and return a pointer to them. The storage is cleared before
614 returning the value. */
617 perm_calloc (nelem
, size
)
621 char *rval
= (char *) obstack_alloc (&permanent_obstack
, nelem
* size
);
622 bzero (rval
, nelem
* size
);
626 /* Allocate SIZE bytes in the saveable obstack
627 and return a pointer to them. */
633 return (char *) obstack_alloc (saveable_obstack
, size
);
636 /* Print out which obstack an object is in. */
639 print_obstack_name (object
, file
, prefix
)
644 struct obstack
*obstack
= NULL
;
645 char *obstack_name
= NULL
;
648 for (p
= outer_function_chain
; p
; p
= p
->next
)
650 if (_obstack_allocated_p (p
->function_obstack
, object
))
652 obstack
= p
->function_obstack
;
653 obstack_name
= "containing function obstack";
655 if (_obstack_allocated_p (p
->function_maybepermanent_obstack
, object
))
657 obstack
= p
->function_maybepermanent_obstack
;
658 obstack_name
= "containing function maybepermanent obstack";
662 if (_obstack_allocated_p (&obstack_stack_obstack
, object
))
664 obstack
= &obstack_stack_obstack
;
665 obstack_name
= "obstack_stack_obstack";
667 else if (_obstack_allocated_p (function_obstack
, object
))
669 obstack
= function_obstack
;
670 obstack_name
= "function obstack";
672 else if (_obstack_allocated_p (&permanent_obstack
, object
))
674 obstack
= &permanent_obstack
;
675 obstack_name
= "permanent_obstack";
677 else if (_obstack_allocated_p (&momentary_obstack
, object
))
679 obstack
= &momentary_obstack
;
680 obstack_name
= "momentary_obstack";
682 else if (_obstack_allocated_p (function_maybepermanent_obstack
, object
))
684 obstack
= function_maybepermanent_obstack
;
685 obstack_name
= "function maybepermanent obstack";
687 else if (_obstack_allocated_p (&temp_decl_obstack
, object
))
689 obstack
= &temp_decl_obstack
;
690 obstack_name
= "temp_decl_obstack";
693 /* Check to see if the object is in the free area of the obstack. */
696 if (object
>= obstack
->next_free
697 && object
< obstack
->chunk_limit
)
698 fprintf (file
, "%s in free portion of obstack %s",
699 prefix
, obstack_name
);
701 fprintf (file
, "%s allocated from %s", prefix
, obstack_name
);
704 fprintf (file
, "%s not allocated from any obstack", prefix
);
708 debug_obstack (object
)
711 print_obstack_name (object
, stderr
, "object");
712 fprintf (stderr
, ".\n");
715 /* Return 1 if OBJ is in the permanent obstack.
716 This is slow, and should be used only for debugging.
717 Use TREE_PERMANENT for other purposes. */
720 object_permanent_p (obj
)
723 return _obstack_allocated_p (&permanent_obstack
, obj
);
726 /* Start a level of momentary allocation.
727 In C, each compound statement has its own level
728 and that level is freed at the end of each statement.
729 All expression nodes are allocated in the momentary allocation level. */
734 struct momentary_level
*tem
735 = (struct momentary_level
*) obstack_alloc (&momentary_obstack
,
736 sizeof (struct momentary_level
));
737 tem
->prev
= momentary_stack
;
738 tem
->base
= (char *) obstack_base (&momentary_obstack
);
739 tem
->obstack
= expression_obstack
;
740 momentary_stack
= tem
;
741 expression_obstack
= &momentary_obstack
;
744 /* Free all the storage in the current momentary-allocation level.
745 In C, this happens at the end of each statement. */
750 obstack_free (&momentary_obstack
, momentary_stack
->base
);
753 /* Discard a level of momentary allocation.
754 In C, this happens at the end of each compound statement.
755 Restore the status of expression node allocation
756 that was in effect before this level was created. */
761 struct momentary_level
*tem
= momentary_stack
;
762 momentary_stack
= tem
->prev
;
763 expression_obstack
= tem
->obstack
;
764 /* We can't free TEM from the momentary_obstack, because there might
765 be objects above it which have been saved. We can free back to the
766 stack of the level we are popping off though. */
767 obstack_free (&momentary_obstack
, tem
->base
);
770 /* Pop back to the previous level of momentary allocation,
771 but don't free any momentary data just yet. */
774 pop_momentary_nofree ()
776 struct momentary_level
*tem
= momentary_stack
;
777 momentary_stack
= tem
->prev
;
778 expression_obstack
= tem
->obstack
;
781 /* Call when starting to parse a declaration:
782 make expressions in the declaration last the length of the function.
783 Returns an argument that should be passed to resume_momentary later. */
788 register int tem
= expression_obstack
== &momentary_obstack
;
789 expression_obstack
= saveable_obstack
;
793 /* Call when finished parsing a declaration:
794 restore the treatment of node-allocation that was
795 in effect before the suspension.
796 YES should be the value previously returned by suspend_momentary. */
799 resume_momentary (yes
)
803 expression_obstack
= &momentary_obstack
;
806 /* Init the tables indexed by tree code.
807 Note that languages can add to these tables to define their own codes. */
812 tree_code_type
= (char **) xmalloc (sizeof (standard_tree_code_type
));
813 tree_code_length
= (int *) xmalloc (sizeof (standard_tree_code_length
));
814 tree_code_name
= (char **) xmalloc (sizeof (standard_tree_code_name
));
815 bcopy ((char *) standard_tree_code_type
, (char *) tree_code_type
,
816 sizeof (standard_tree_code_type
));
817 bcopy ((char *) standard_tree_code_length
, (char *) tree_code_length
,
818 sizeof (standard_tree_code_length
));
819 bcopy ((char *) standard_tree_code_name
, (char *) tree_code_name
,
820 sizeof (standard_tree_code_name
));
823 /* Return a newly allocated node of code CODE.
824 Initialize the node's unique id and its TREE_PERMANENT flag.
825 For decl and type nodes, some other fields are initialized.
826 The rest of the node is initialized to zero.
828 Achoo! I got a code in the node. */
835 register int type
= TREE_CODE_CLASS (code
);
837 register struct obstack
*obstack
= current_obstack
;
839 register tree_node_kind kind
;
843 case 'd': /* A decl node */
844 #ifdef GATHER_STATISTICS
847 length
= sizeof (struct tree_decl
);
848 /* All decls in an inline function need to be saved. */
849 if (obstack
!= &permanent_obstack
)
850 obstack
= saveable_obstack
;
852 /* PARM_DECLs go on the context of the parent. If this is a nested
853 function, then we must allocate the PARM_DECL on the parent's
854 obstack, so that they will live to the end of the parent's
855 closing brace. This is neccesary in case we try to inline the
856 function into its parent.
858 PARM_DECLs of top-level functions do not have this problem. However,
859 we allocate them where we put the FUNCTION_DECL for languauges such as
860 Ada that need to consult some flags in the PARM_DECLs of the function
863 See comment in restore_tree_status for why we can't put this
864 in function_obstack. */
865 if (code
== PARM_DECL
&& obstack
!= &permanent_obstack
)
868 if (current_function_decl
)
869 context
= decl_function_context (current_function_decl
);
873 = find_function_data (context
)->function_maybepermanent_obstack
;
877 case 't': /* a type node */
878 #ifdef GATHER_STATISTICS
881 length
= sizeof (struct tree_type
);
882 /* All data types are put where we can preserve them if nec. */
883 if (obstack
!= &permanent_obstack
)
884 obstack
= all_types_permanent
? &permanent_obstack
: saveable_obstack
;
887 case 'b': /* a lexical block */
888 #ifdef GATHER_STATISTICS
891 length
= sizeof (struct tree_block
);
892 /* All BLOCK nodes are put where we can preserve them if nec. */
893 if (obstack
!= &permanent_obstack
)
894 obstack
= saveable_obstack
;
897 case 's': /* an expression with side effects */
898 #ifdef GATHER_STATISTICS
902 case 'r': /* a reference */
903 #ifdef GATHER_STATISTICS
907 case 'e': /* an expression */
908 case '<': /* a comparison expression */
909 case '1': /* a unary arithmetic expression */
910 case '2': /* a binary arithmetic expression */
911 #ifdef GATHER_STATISTICS
915 obstack
= expression_obstack
;
916 /* All BIND_EXPR nodes are put where we can preserve them if nec. */
917 if (code
== BIND_EXPR
&& obstack
!= &permanent_obstack
)
918 obstack
= saveable_obstack
;
919 length
= sizeof (struct tree_exp
)
920 + (tree_code_length
[(int) code
] - 1) * sizeof (char *);
923 case 'c': /* a constant */
924 #ifdef GATHER_STATISTICS
927 obstack
= expression_obstack
;
929 /* We can't use tree_code_length for INTEGER_CST, since the number of
930 words is machine-dependent due to varying length of HOST_WIDE_INT,
931 which might be wider than a pointer (e.g., long long). Similarly
932 for REAL_CST, since the number of words is machine-dependent due
933 to varying size and alignment of `double'. */
935 if (code
== INTEGER_CST
)
936 length
= sizeof (struct tree_int_cst
);
937 else if (code
== REAL_CST
)
938 length
= sizeof (struct tree_real_cst
);
940 length
= sizeof (struct tree_common
)
941 + tree_code_length
[(int) code
] * sizeof (char *);
944 case 'x': /* something random, like an identifier. */
945 #ifdef GATHER_STATISTICS
946 if (code
== IDENTIFIER_NODE
)
948 else if (code
== OP_IDENTIFIER
)
950 else if (code
== TREE_VEC
)
955 length
= sizeof (struct tree_common
)
956 + tree_code_length
[(int) code
] * sizeof (char *);
957 /* Identifier nodes are always permanent since they are
958 unique in a compiler run. */
959 if (code
== IDENTIFIER_NODE
) obstack
= &permanent_obstack
;
966 t
= (tree
) obstack_alloc (obstack
, length
);
968 #ifdef GATHER_STATISTICS
969 tree_node_counts
[(int)kind
]++;
970 tree_node_sizes
[(int)kind
] += length
;
973 /* Clear a word at a time. */
974 for (i
= (length
/ sizeof (int)) - 1; i
>= 0; i
--)
976 /* Clear any extra bytes. */
977 for (i
= length
/ sizeof (int) * sizeof (int); i
< length
; i
++)
980 TREE_SET_CODE (t
, code
);
981 if (obstack
== &permanent_obstack
)
982 TREE_PERMANENT (t
) = 1;
987 TREE_SIDE_EFFECTS (t
) = 1;
988 TREE_TYPE (t
) = void_type_node
;
992 if (code
!= FUNCTION_DECL
)
994 DECL_IN_SYSTEM_HEADER (t
)
995 = in_system_header
&& (obstack
== &permanent_obstack
);
996 DECL_SOURCE_LINE (t
) = lineno
;
997 DECL_SOURCE_FILE (t
) = (input_filename
) ? input_filename
: "<built-in>";
998 DECL_UID (t
) = next_decl_uid
++;
1002 TYPE_UID (t
) = next_type_uid
++;
1004 TYPE_MAIN_VARIANT (t
) = t
;
1005 TYPE_OBSTACK (t
) = obstack
;
1006 TYPE_ATTRIBUTES (t
) = NULL_TREE
;
1007 #ifdef SET_DEFAULT_TYPE_ATTRIBUTES
1008 SET_DEFAULT_TYPE_ATTRIBUTES (t
);
1013 TREE_CONSTANT (t
) = 1;
1020 /* Return a new node with the same contents as NODE
1021 except that its TREE_CHAIN is zero and it has a fresh uid. */
1028 register enum tree_code code
= TREE_CODE (node
);
1029 register int length
;
1032 switch (TREE_CODE_CLASS (code
))
1034 case 'd': /* A decl node */
1035 length
= sizeof (struct tree_decl
);
1038 case 't': /* a type node */
1039 length
= sizeof (struct tree_type
);
1042 case 'b': /* a lexical block node */
1043 length
= sizeof (struct tree_block
);
1046 case 'r': /* a reference */
1047 case 'e': /* an expression */
1048 case 's': /* an expression with side effects */
1049 case '<': /* a comparison expression */
1050 case '1': /* a unary arithmetic expression */
1051 case '2': /* a binary arithmetic expression */
1052 length
= sizeof (struct tree_exp
)
1053 + (tree_code_length
[(int) code
] - 1) * sizeof (char *);
1056 case 'c': /* a constant */
1057 /* We can't use tree_code_length for INTEGER_CST, since the number of
1058 words is machine-dependent due to varying length of HOST_WIDE_INT,
1059 which might be wider than a pointer (e.g., long long). Similarly
1060 for REAL_CST, since the number of words is machine-dependent due
1061 to varying size and alignment of `double'. */
1062 if (code
== INTEGER_CST
)
1064 length
= sizeof (struct tree_int_cst
);
1067 else if (code
== REAL_CST
)
1069 length
= sizeof (struct tree_real_cst
);
1073 case 'x': /* something random, like an identifier. */
1074 length
= sizeof (struct tree_common
)
1075 + tree_code_length
[(int) code
] * sizeof (char *);
1076 if (code
== TREE_VEC
)
1077 length
+= (TREE_VEC_LENGTH (node
) - 1) * sizeof (char *);
1080 t
= (tree
) obstack_alloc (current_obstack
, length
);
1082 for (i
= (length
/ sizeof (int)) - 1; i
>= 0; i
--)
1083 ((int *) t
)[i
] = ((int *) node
)[i
];
1084 /* Clear any extra bytes. */
1085 for (i
= length
/ sizeof (int) * sizeof (int); i
< length
; i
++)
1086 ((char *) t
)[i
] = ((char *) node
)[i
];
1090 if (TREE_CODE_CLASS (code
) == 'd')
1091 DECL_UID (t
) = next_decl_uid
++;
1092 else if (TREE_CODE_CLASS (code
) == 't')
1094 TYPE_UID (t
) = next_type_uid
++;
1095 TYPE_OBSTACK (t
) = current_obstack
;
1098 TREE_PERMANENT (t
) = (current_obstack
== &permanent_obstack
);
1103 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1104 For example, this can copy a list made of TREE_LIST nodes. */
1111 register tree prev
, next
;
1116 head
= prev
= copy_node (list
);
1117 next
= TREE_CHAIN (list
);
1120 TREE_CHAIN (prev
) = copy_node (next
);
1121 prev
= TREE_CHAIN (prev
);
1122 next
= TREE_CHAIN (next
);
1129 /* Return an IDENTIFIER_NODE whose name is TEXT (a null-terminated string).
1130 If an identifier with that name has previously been referred to,
1131 the same node is returned this time. */
1134 get_identifier (text
)
1135 register char *text
;
1140 register int len
, hash_len
;
1142 /* Compute length of text in len. */
1143 for (len
= 0; text
[len
]; len
++);
1145 /* Decide how much of that length to hash on */
1147 if (warn_id_clash
&& len
> id_clash_len
)
1148 hash_len
= id_clash_len
;
1150 /* Compute hash code */
1151 hi
= hash_len
* 613 + (unsigned)text
[0];
1152 for (i
= 1; i
< hash_len
; i
+= 2)
1153 hi
= ((hi
* 613) + (unsigned)(text
[i
]));
1155 hi
&= (1 << HASHBITS
) - 1;
1156 hi
%= MAX_HASH_TABLE
;
1158 /* Search table for identifier */
1159 for (idp
= hash_table
[hi
]; idp
; idp
= TREE_CHAIN (idp
))
1160 if (IDENTIFIER_LENGTH (idp
) == len
1161 && IDENTIFIER_POINTER (idp
)[0] == text
[0]
1162 && !bcmp (IDENTIFIER_POINTER (idp
), text
, len
))
1163 return idp
; /* <-- return if found */
1165 /* Not found; optionally warn about a similar identifier */
1166 if (warn_id_clash
&& do_identifier_warnings
&& len
>= id_clash_len
)
1167 for (idp
= hash_table
[hi
]; idp
; idp
= TREE_CHAIN (idp
))
1168 if (!strncmp (IDENTIFIER_POINTER (idp
), text
, id_clash_len
))
1170 warning ("`%s' and `%s' identical in first %d characters",
1171 IDENTIFIER_POINTER (idp
), text
, id_clash_len
);
1175 if (tree_code_length
[(int) IDENTIFIER_NODE
] < 0)
1176 abort (); /* set_identifier_size hasn't been called. */
1178 /* Not found, create one, add to chain */
1179 idp
= make_node (IDENTIFIER_NODE
);
1180 IDENTIFIER_LENGTH (idp
) = len
;
1181 #ifdef GATHER_STATISTICS
1182 id_string_size
+= len
;
1185 IDENTIFIER_POINTER (idp
) = obstack_copy0 (&permanent_obstack
, text
, len
);
1187 TREE_CHAIN (idp
) = hash_table
[hi
];
1188 hash_table
[hi
] = idp
;
1189 return idp
; /* <-- return if created */
1192 /* Enable warnings on similar identifiers (if requested).
1193 Done after the built-in identifiers are created. */
1196 start_identifier_warnings ()
1198 do_identifier_warnings
= 1;
1201 /* Record the size of an identifier node for the language in use.
1202 SIZE is the total size in bytes.
1203 This is called by the language-specific files. This must be
1204 called before allocating any identifiers. */
1207 set_identifier_size (size
)
1210 tree_code_length
[(int) IDENTIFIER_NODE
]
1211 = (size
- sizeof (struct tree_common
)) / sizeof (tree
);
1214 /* Return a newly constructed INTEGER_CST node whose constant value
1215 is specified by the two ints LOW and HI.
1216 The TREE_TYPE is set to `int'.
1218 This function should be used via the `build_int_2' macro. */
1221 build_int_2_wide (low
, hi
)
1222 HOST_WIDE_INT low
, hi
;
1224 register tree t
= make_node (INTEGER_CST
);
1225 TREE_INT_CST_LOW (t
) = low
;
1226 TREE_INT_CST_HIGH (t
) = hi
;
1227 TREE_TYPE (t
) = integer_type_node
;
1231 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1234 build_real (type
, d
)
1241 /* Check for valid float value for this type on this target machine;
1242 if not, can print error message and store a valid value in D. */
1243 #ifdef CHECK_FLOAT_VALUE
1244 CHECK_FLOAT_VALUE (TYPE_MODE (type
), d
, overflow
);
1247 v
= make_node (REAL_CST
);
1248 TREE_TYPE (v
) = type
;
1249 TREE_REAL_CST (v
) = d
;
1250 TREE_OVERFLOW (v
) = TREE_CONSTANT_OVERFLOW (v
) = overflow
;
1254 /* Return a new REAL_CST node whose type is TYPE
1255 and whose value is the integer value of the INTEGER_CST node I. */
1257 #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
1260 real_value_from_int_cst (i
)
1265 /* Some 386 compilers mishandle unsigned int to float conversions,
1266 so introduce a temporary variable E to avoid those bugs. */
1268 #ifdef REAL_ARITHMETIC
1269 if (! TREE_UNSIGNED (TREE_TYPE (i
)))
1270 REAL_VALUE_FROM_INT (d
, TREE_INT_CST_LOW (i
), TREE_INT_CST_HIGH (i
));
1272 REAL_VALUE_FROM_UNSIGNED_INT (d
, TREE_INT_CST_LOW (i
), TREE_INT_CST_HIGH (i
));
1273 #else /* not REAL_ARITHMETIC */
1274 if (TREE_INT_CST_HIGH (i
) < 0 && ! TREE_UNSIGNED (TREE_TYPE (i
)))
1276 d
= (double) (~ TREE_INT_CST_HIGH (i
));
1277 e
= ((double) ((HOST_WIDE_INT
) 1 << (HOST_BITS_PER_WIDE_INT
/ 2))
1278 * (double) ((HOST_WIDE_INT
) 1 << (HOST_BITS_PER_WIDE_INT
/ 2)));
1280 e
= (double) (unsigned HOST_WIDE_INT
) (~ TREE_INT_CST_LOW (i
));
1286 d
= (double) (unsigned HOST_WIDE_INT
) TREE_INT_CST_HIGH (i
);
1287 e
= ((double) ((HOST_WIDE_INT
) 1 << (HOST_BITS_PER_WIDE_INT
/ 2))
1288 * (double) ((HOST_WIDE_INT
) 1 << (HOST_BITS_PER_WIDE_INT
/ 2)));
1290 e
= (double) (unsigned HOST_WIDE_INT
) TREE_INT_CST_LOW (i
);
1293 #endif /* not REAL_ARITHMETIC */
1297 /* This function can't be implemented if we can't do arithmetic
1298 on the float representation. */
1301 build_real_from_int_cst (type
, i
)
1306 int overflow
= TREE_OVERFLOW (i
);
1308 jmp_buf float_error
;
1310 v
= make_node (REAL_CST
);
1311 TREE_TYPE (v
) = type
;
1313 if (setjmp (float_error
))
1320 set_float_handler (float_error
);
1322 d
= REAL_VALUE_TRUNCATE (TYPE_MODE (type
), real_value_from_int_cst (i
));
1324 /* Check for valid float value for this type on this target machine. */
1327 set_float_handler (NULL_PTR
);
1329 #ifdef CHECK_FLOAT_VALUE
1330 CHECK_FLOAT_VALUE (TYPE_MODE (type
), d
, overflow
);
1333 TREE_REAL_CST (v
) = d
;
1334 TREE_OVERFLOW (v
) = TREE_CONSTANT_OVERFLOW (v
) = overflow
;
1338 #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
1340 /* Return a newly constructed STRING_CST node whose value is
1341 the LEN characters at STR.
1342 The TREE_TYPE is not initialized. */
1345 build_string (len
, str
)
1349 /* Put the string in saveable_obstack since it will be placed in the RTL
1350 for an "asm" statement and will also be kept around a while if
1351 deferring constant output in varasm.c. */
1353 register tree s
= make_node (STRING_CST
);
1354 TREE_STRING_LENGTH (s
) = len
;
1355 TREE_STRING_POINTER (s
) = obstack_copy0 (saveable_obstack
, str
, len
);
1359 /* Return a newly constructed COMPLEX_CST node whose value is
1360 specified by the real and imaginary parts REAL and IMAG.
1361 Both REAL and IMAG should be constant nodes.
1362 The TREE_TYPE is not initialized. */
1365 build_complex (real
, imag
)
1368 register tree t
= make_node (COMPLEX_CST
);
1370 TREE_REALPART (t
) = real
;
1371 TREE_IMAGPART (t
) = imag
;
1372 TREE_TYPE (t
) = build_complex_type (TREE_TYPE (real
));
1373 TREE_OVERFLOW (t
) = TREE_OVERFLOW (real
) | TREE_OVERFLOW (imag
);
1374 TREE_CONSTANT_OVERFLOW (t
)
1375 = TREE_CONSTANT_OVERFLOW (real
) | TREE_CONSTANT_OVERFLOW (imag
);
1379 /* Build a newly constructed TREE_VEC node of length LEN. */
1385 register int length
= (len
-1) * sizeof (tree
) + sizeof (struct tree_vec
);
1386 register struct obstack
*obstack
= current_obstack
;
1389 #ifdef GATHER_STATISTICS
1390 tree_node_counts
[(int)vec_kind
]++;
1391 tree_node_sizes
[(int)vec_kind
] += length
;
1394 t
= (tree
) obstack_alloc (obstack
, length
);
1396 for (i
= (length
/ sizeof (int)) - 1; i
>= 0; i
--)
1399 TREE_SET_CODE (t
, TREE_VEC
);
1400 TREE_VEC_LENGTH (t
) = len
;
1401 if (obstack
== &permanent_obstack
)
1402 TREE_PERMANENT (t
) = 1;
1407 /* Return 1 if EXPR is the integer constant zero. */
1410 integer_zerop (expr
)
1415 return (TREE_CODE (expr
) == INTEGER_CST
1416 && TREE_INT_CST_LOW (expr
) == 0
1417 && TREE_INT_CST_HIGH (expr
) == 0);
1420 /* Return 1 if EXPR is the integer constant one. */
1428 return (TREE_CODE (expr
) == INTEGER_CST
1429 && TREE_INT_CST_LOW (expr
) == 1
1430 && TREE_INT_CST_HIGH (expr
) == 0);
1433 /* Return 1 if EXPR is an integer containing all 1's
1434 in as much precision as it contains. */
1437 integer_all_onesp (expr
)
1445 if (TREE_CODE (expr
) != INTEGER_CST
)
1448 uns
= TREE_UNSIGNED (TREE_TYPE (expr
));
1450 return TREE_INT_CST_LOW (expr
) == -1 && TREE_INT_CST_HIGH (expr
) == -1;
1452 prec
= TYPE_PRECISION (TREE_TYPE (expr
));
1453 if (prec
>= HOST_BITS_PER_WIDE_INT
)
1455 int high_value
, shift_amount
;
1457 shift_amount
= prec
- HOST_BITS_PER_WIDE_INT
;
1459 if (shift_amount
> HOST_BITS_PER_WIDE_INT
)
1460 /* Can not handle precisions greater than twice the host int size. */
1462 else if (shift_amount
== HOST_BITS_PER_WIDE_INT
)
1463 /* Shifting by the host word size is undefined according to the ANSI
1464 standard, so we must handle this as a special case. */
1467 high_value
= ((HOST_WIDE_INT
) 1 << shift_amount
) - 1;
1469 return TREE_INT_CST_LOW (expr
) == -1
1470 && TREE_INT_CST_HIGH (expr
) == high_value
;
1473 return TREE_INT_CST_LOW (expr
) == ((HOST_WIDE_INT
) 1 << prec
) - 1;
1476 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1480 integer_pow2p (expr
)
1483 HOST_WIDE_INT high
, low
;
1487 if (TREE_CODE (expr
) != INTEGER_CST
)
1490 high
= TREE_INT_CST_HIGH (expr
);
1491 low
= TREE_INT_CST_LOW (expr
);
1493 if (high
== 0 && low
== 0)
1496 return ((high
== 0 && (low
& (low
- 1)) == 0)
1497 || (low
== 0 && (high
& (high
- 1)) == 0));
1500 /* Return 1 if EXPR is the real constant zero. */
1508 return (TREE_CODE (expr
) == REAL_CST
1509 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst0
));
1512 /* Return 1 if EXPR is the real constant one. */
1520 return (TREE_CODE (expr
) == REAL_CST
1521 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst1
));
1524 /* Return 1 if EXPR is the real constant two. */
1532 return (TREE_CODE (expr
) == REAL_CST
1533 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst2
));
1536 /* Nonzero if EXP is a constant or a cast of a constant. */
1539 really_constant_p (exp
)
1542 /* This is not quite the same as STRIP_NOPS. It does more. */
1543 while (TREE_CODE (exp
) == NOP_EXPR
1544 || TREE_CODE (exp
) == CONVERT_EXPR
1545 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
1546 exp
= TREE_OPERAND (exp
, 0);
1547 return TREE_CONSTANT (exp
);
1550 /* Return first list element whose TREE_VALUE is ELEM.
1551 Return 0 if ELEM is not it LIST. */
1554 value_member (elem
, list
)
1559 if (elem
== TREE_VALUE (list
))
1561 list
= TREE_CHAIN (list
);
1566 /* Return first list element whose TREE_PURPOSE is ELEM.
1567 Return 0 if ELEM is not it LIST. */
1570 purpose_member (elem
, list
)
1575 if (elem
== TREE_PURPOSE (list
))
1577 list
= TREE_CHAIN (list
);
1582 /* Return first list element whose BINFO_TYPE is ELEM.
1583 Return 0 if ELEM is not it LIST. */
1586 binfo_member (elem
, list
)
1591 if (elem
== BINFO_TYPE (list
))
1593 list
= TREE_CHAIN (list
);
1598 /* Return nonzero if ELEM is part of the chain CHAIN. */
1601 chain_member (elem
, chain
)
1608 chain
= TREE_CHAIN (chain
);
1614 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1615 We expect a null pointer to mark the end of the chain.
1616 This is the Lisp primitive `length'. */
1623 register int len
= 0;
1625 for (tail
= t
; tail
; tail
= TREE_CHAIN (tail
))
1631 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1632 by modifying the last node in chain 1 to point to chain 2.
1633 This is the Lisp primitive `nconc'. */
1645 for (t1
= op1
; TREE_CHAIN (t1
); t1
= TREE_CHAIN (t1
))
1647 TREE_CHAIN (t1
) = op2
;
1648 for (t2
= op2
; t2
; t2
= TREE_CHAIN (t2
))
1650 abort (); /* Circularity created. */
1656 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1660 register tree chain
;
1664 while (next
= TREE_CHAIN (chain
))
1669 /* Reverse the order of elements in the chain T,
1670 and return the new head of the chain (old last element). */
1676 register tree prev
= 0, decl
, next
;
1677 for (decl
= t
; decl
; decl
= next
)
1679 next
= TREE_CHAIN (decl
);
1680 TREE_CHAIN (decl
) = prev
;
1686 /* Given a chain CHAIN of tree nodes,
1687 construct and return a list of those nodes. */
1693 tree result
= NULL_TREE
;
1694 tree in_tail
= chain
;
1695 tree out_tail
= NULL_TREE
;
1699 tree next
= tree_cons (NULL_TREE
, in_tail
, NULL_TREE
);
1701 TREE_CHAIN (out_tail
) = next
;
1705 in_tail
= TREE_CHAIN (in_tail
);
1711 /* Return a newly created TREE_LIST node whose
1712 purpose and value fields are PARM and VALUE. */
1715 build_tree_list (parm
, value
)
1718 register tree t
= make_node (TREE_LIST
);
1719 TREE_PURPOSE (t
) = parm
;
1720 TREE_VALUE (t
) = value
;
1724 /* Similar, but build on the temp_decl_obstack. */
1727 build_decl_list (parm
, value
)
1731 register struct obstack
*ambient_obstack
= current_obstack
;
1732 current_obstack
= &temp_decl_obstack
;
1733 node
= build_tree_list (parm
, value
);
1734 current_obstack
= ambient_obstack
;
1738 /* Return a newly created TREE_LIST node whose
1739 purpose and value fields are PARM and VALUE
1740 and whose TREE_CHAIN is CHAIN. */
1743 tree_cons (purpose
, value
, chain
)
1744 tree purpose
, value
, chain
;
1747 register tree node
= make_node (TREE_LIST
);
1750 register tree node
= (tree
) obstack_alloc (current_obstack
, sizeof (struct tree_list
));
1751 #ifdef GATHER_STATISTICS
1752 tree_node_counts
[(int)x_kind
]++;
1753 tree_node_sizes
[(int)x_kind
] += sizeof (struct tree_list
);
1756 for (i
= (sizeof (struct tree_common
) / sizeof (int)) - 1; i
>= 0; i
--)
1757 ((int *) node
)[i
] = 0;
1759 TREE_SET_CODE (node
, TREE_LIST
);
1760 if (current_obstack
== &permanent_obstack
)
1761 TREE_PERMANENT (node
) = 1;
1764 TREE_CHAIN (node
) = chain
;
1765 TREE_PURPOSE (node
) = purpose
;
1766 TREE_VALUE (node
) = value
;
1770 /* Similar, but build on the temp_decl_obstack. */
1773 decl_tree_cons (purpose
, value
, chain
)
1774 tree purpose
, value
, chain
;
1777 register struct obstack
*ambient_obstack
= current_obstack
;
1778 current_obstack
= &temp_decl_obstack
;
1779 node
= tree_cons (purpose
, value
, chain
);
1780 current_obstack
= ambient_obstack
;
1784 /* Same as `tree_cons' but make a permanent object. */
1787 perm_tree_cons (purpose
, value
, chain
)
1788 tree purpose
, value
, chain
;
1791 register struct obstack
*ambient_obstack
= current_obstack
;
1792 current_obstack
= &permanent_obstack
;
1794 node
= tree_cons (purpose
, value
, chain
);
1795 current_obstack
= ambient_obstack
;
1799 /* Same as `tree_cons', but make this node temporary, regardless. */
1802 temp_tree_cons (purpose
, value
, chain
)
1803 tree purpose
, value
, chain
;
1806 register struct obstack
*ambient_obstack
= current_obstack
;
1807 current_obstack
= &temporary_obstack
;
1809 node
= tree_cons (purpose
, value
, chain
);
1810 current_obstack
= ambient_obstack
;
1814 /* Same as `tree_cons', but save this node if the function's RTL is saved. */
1817 saveable_tree_cons (purpose
, value
, chain
)
1818 tree purpose
, value
, chain
;
1821 register struct obstack
*ambient_obstack
= current_obstack
;
1822 current_obstack
= saveable_obstack
;
1824 node
= tree_cons (purpose
, value
, chain
);
1825 current_obstack
= ambient_obstack
;
1829 /* Return the size nominally occupied by an object of type TYPE
1830 when it resides in memory. The value is measured in units of bytes,
1831 and its data type is that normally used for type sizes
1832 (which is the first type created by make_signed_type or
1833 make_unsigned_type). */
1836 size_in_bytes (type
)
1841 if (type
== error_mark_node
)
1842 return integer_zero_node
;
1843 type
= TYPE_MAIN_VARIANT (type
);
1844 if (TYPE_SIZE (type
) == 0)
1846 incomplete_type_error (NULL_TREE
, type
);
1847 return integer_zero_node
;
1849 t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1850 size_int (BITS_PER_UNIT
));
1851 if (TREE_CODE (t
) == INTEGER_CST
)
1852 force_fit_type (t
, 0);
1856 /* Return the size of TYPE (in bytes) as an integer,
1857 or return -1 if the size can vary. */
1860 int_size_in_bytes (type
)
1864 if (type
== error_mark_node
)
1866 type
= TYPE_MAIN_VARIANT (type
);
1867 if (TYPE_SIZE (type
) == 0)
1869 if (TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
1871 if (TREE_INT_CST_HIGH (TYPE_SIZE (type
)) != 0)
1873 tree t
= size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (type
),
1874 size_int (BITS_PER_UNIT
));
1875 return TREE_INT_CST_LOW (t
);
1877 size
= TREE_INT_CST_LOW (TYPE_SIZE (type
));
1878 return (size
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
;
1881 /* Return, as a tree node, the number of elements for TYPE (which is an
1882 ARRAY_TYPE) minus one. This counts only elements of the top array. */
1885 array_type_nelts (type
)
1888 tree index_type
= TYPE_DOMAIN (type
);
1890 return (integer_zerop (TYPE_MIN_VALUE (index_type
))
1891 ? TYPE_MAX_VALUE (index_type
)
1892 : fold (build (MINUS_EXPR
, TREE_TYPE (TYPE_MAX_VALUE (index_type
)),
1893 TYPE_MAX_VALUE (index_type
),
1894 TYPE_MIN_VALUE (index_type
))));
1897 /* Return nonzero if arg is static -- a reference to an object in
1898 static storage. This is not the same as the C meaning of `static'. */
1904 switch (TREE_CODE (arg
))
1907 /* Nested functions aren't static. Since taking their address
1908 involves a trampoline. */
1909 if (decl_function_context (arg
) != 0)
1911 /* ... fall through ... */
1913 return TREE_STATIC (arg
) || DECL_EXTERNAL (arg
);
1916 return TREE_STATIC (arg
);
1923 return staticp (TREE_OPERAND (arg
, 0));
1926 return TREE_CONSTANT (TREE_OPERAND (arg
, 0));
1929 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg
))) == INTEGER_CST
1930 && TREE_CODE (TREE_OPERAND (arg
, 1)) == INTEGER_CST
)
1931 return staticp (TREE_OPERAND (arg
, 0));
1937 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
1938 Do this to any expression which may be used in more than one place,
1939 but must be evaluated only once.
1941 Normally, expand_expr would reevaluate the expression each time.
1942 Calling save_expr produces something that is evaluated and recorded
1943 the first time expand_expr is called on it. Subsequent calls to
1944 expand_expr just reuse the recorded value.
1946 The call to expand_expr that generates code that actually computes
1947 the value is the first call *at compile time*. Subsequent calls
1948 *at compile time* generate code to use the saved value.
1949 This produces correct result provided that *at run time* control
1950 always flows through the insns made by the first expand_expr
1951 before reaching the other places where the save_expr was evaluated.
1952 You, the caller of save_expr, must make sure this is so.
1954 Constants, and certain read-only nodes, are returned with no
1955 SAVE_EXPR because that is safe. Expressions containing placeholders
1956 are not touched; see tree.def for an explanation of what these
1963 register tree t
= fold (expr
);
1965 /* We don't care about whether this can be used as an lvalue in this
1967 while (TREE_CODE (t
) == NON_LVALUE_EXPR
)
1968 t
= TREE_OPERAND (t
, 0);
1970 /* If the tree evaluates to a constant, then we don't want to hide that
1971 fact (i.e. this allows further folding, and direct checks for constants).
1972 However, a read-only object that has side effects cannot be bypassed.
1973 Since it is no problem to reevaluate literals, we just return the
1976 if (TREE_CONSTANT (t
) || (TREE_READONLY (t
) && ! TREE_SIDE_EFFECTS (t
))
1977 || TREE_CODE (t
) == SAVE_EXPR
)
1980 /* If T contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
1981 it means that the size or offset of some field of an object depends on
1982 the value within another field.
1984 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
1985 and some variable since it would then need to be both evaluated once and
1986 evaluated more than once. Front-ends must assure this case cannot
1987 happen by surrounding any such subexpressions in their own SAVE_EXPR
1988 and forcing evaluation at the proper time. */
1989 if (contains_placeholder_p (t
))
1992 t
= build (SAVE_EXPR
, TREE_TYPE (expr
), t
, current_function_decl
, NULL_TREE
);
1994 /* This expression might be placed ahead of a jump to ensure that the
1995 value was computed on both sides of the jump. So make sure it isn't
1996 eliminated as dead. */
1997 TREE_SIDE_EFFECTS (t
) = 1;
2001 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
2002 or offset that depends on a field within a record.
2004 Note that we only allow such expressions within simple arithmetic
2008 contains_placeholder_p (exp
)
2011 register enum tree_code code
= TREE_CODE (exp
);
2014 /* If we have a WITH_RECORD_EXPR, it "cancels" any PLACEHOLDER_EXPR
2015 in it since it is supplying a value for it. */
2016 if (code
== WITH_RECORD_EXPR
)
2019 switch (TREE_CODE_CLASS (code
))
2022 for (inner
= TREE_OPERAND (exp
, 0);
2023 TREE_CODE_CLASS (TREE_CODE (inner
)) == 'r';
2024 inner
= TREE_OPERAND (inner
, 0))
2026 return TREE_CODE (inner
) == PLACEHOLDER_EXPR
;
2031 switch (tree_code_length
[(int) code
])
2034 return contains_placeholder_p (TREE_OPERAND (exp
, 0));
2036 return (code
!= RTL_EXPR
2037 && code
!= CONSTRUCTOR
2038 && ! (code
== SAVE_EXPR
&& SAVE_EXPR_RTL (exp
) != 0)
2039 && code
!= WITH_RECORD_EXPR
2040 && (contains_placeholder_p (TREE_OPERAND (exp
, 0))
2041 || contains_placeholder_p (TREE_OPERAND (exp
, 1))));
2043 return (code
== COND_EXPR
2044 && (contains_placeholder_p (TREE_OPERAND (exp
, 0))
2045 || contains_placeholder_p (TREE_OPERAND (exp
, 1))
2046 || contains_placeholder_p (TREE_OPERAND (exp
, 2))));
2053 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
2054 return a tree with all occurrences of references to F in a
2055 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP
2056 contains only arithmetic expressions. */
2059 substitute_in_expr (exp
, f
, r
)
2064 enum tree_code code
= TREE_CODE (exp
);
2067 switch (TREE_CODE_CLASS (code
))
2074 if (code
== PLACEHOLDER_EXPR
)
2082 switch (tree_code_length
[(int) code
])
2085 return fold (build1 (code
, TREE_TYPE (exp
),
2086 substitute_in_expr (TREE_OPERAND (exp
, 0),
2090 /* An RTL_EXPR cannot contain a PLACEHOLDER_EXPR; a CONSTRUCTOR
2091 could, but we don't support it. */
2092 if (code
== RTL_EXPR
)
2094 else if (code
== CONSTRUCTOR
)
2097 return fold (build (code
, TREE_TYPE (exp
),
2098 substitute_in_expr (TREE_OPERAND (exp
, 0), f
, r
),
2099 substitute_in_expr (TREE_OPERAND (exp
, 1),
2103 /* It cannot be that anything inside a SAVE_EXPR contains a
2104 PLACEHOLDER_EXPR. */
2105 if (code
== SAVE_EXPR
)
2108 if (code
!= COND_EXPR
)
2111 return fold (build (code
, TREE_TYPE (exp
),
2112 substitute_in_expr (TREE_OPERAND (exp
, 0), f
, r
),
2113 substitute_in_expr (TREE_OPERAND (exp
, 1), f
, r
),
2114 substitute_in_expr (TREE_OPERAND (exp
, 2),
2124 /* If this expression is getting a value from a PLACEHOLDER_EXPR
2125 and it is the right field, replace it with R. */
2126 for (inner
= TREE_OPERAND (exp
, 0);
2127 TREE_CODE_CLASS (TREE_CODE (inner
)) == 'r';
2128 inner
= TREE_OPERAND (inner
, 0))
2130 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
2131 && TREE_OPERAND (exp
, 1) == f
)
2134 return fold (build (code
, TREE_TYPE (exp
),
2135 substitute_in_expr (TREE_OPERAND (exp
, 0), f
, r
),
2136 TREE_OPERAND (exp
, 1)));
2138 return fold (build (code
, TREE_TYPE (exp
),
2139 substitute_in_expr (TREE_OPERAND (exp
, 0), f
, r
),
2140 substitute_in_expr (TREE_OPERAND (exp
, 1), f
, r
),
2141 substitute_in_expr (TREE_OPERAND (exp
, 2), f
, r
)));
2144 return fold (build1 (code
, TREE_TYPE (exp
),
2145 substitute_in_expr (TREE_OPERAND (exp
, 0),
2148 return fold (build (code
, TREE_TYPE (exp
),
2149 substitute_in_expr (TREE_OPERAND (exp
, 0), f
, r
),
2150 substitute_in_expr (TREE_OPERAND (exp
, 1), f
, r
)));
2154 /* If it wasn't one of the cases we handle, give up. */
2159 /* Given a type T, a FIELD_DECL F, and a replacement value R,
2160 return a new type with all size expressions that contain F
2161 updated by replacing F with R. */
2164 substitute_in_type (t
, f
, r
)
2167 switch (TREE_CODE (t
))
2176 if ((TREE_CODE (TYPE_MIN_VALUE (t
)) != INTEGER_CST
2177 && contains_placeholder_p (TYPE_MIN_VALUE (t
)))
2178 || (TREE_CODE (TYPE_MAX_VALUE (t
)) != INTEGER_CST
2179 && contains_placeholder_p (TYPE_MAX_VALUE (t
))))
2180 return build_range_type (t
,
2181 substitute_in_expr (TYPE_MIN_VALUE (t
), f
, r
),
2182 substitute_in_expr (TYPE_MAX_VALUE (t
), f
, r
));
2186 if ((TYPE_MIN_VALUE (t
) != 0
2187 && TREE_CODE (TYPE_MIN_VALUE (t
)) != REAL_CST
2188 && contains_placeholder_p (TYPE_MIN_VALUE (t
)))
2189 || (TYPE_MAX_VALUE (t
) != 0
2190 && TREE_CODE (TYPE_MAX_VALUE (t
)) != REAL_CST
2191 && contains_placeholder_p (TYPE_MAX_VALUE (t
))))
2193 t
= build_type_copy (t
);
2195 if (TYPE_MIN_VALUE (t
))
2196 TYPE_MIN_VALUE (t
) = substitute_in_expr (TYPE_MIN_VALUE (t
), f
, r
);
2197 if (TYPE_MAX_VALUE (t
))
2198 TYPE_MAX_VALUE (t
) = substitute_in_expr (TYPE_MAX_VALUE (t
), f
, r
);
2203 return build_complex_type (substitute_in_type (TREE_TYPE (t
), f
, r
));
2207 case REFERENCE_TYPE
:
2212 /* Don't know how to do these yet. */
2216 t
= build_array_type (substitute_in_type (TREE_TYPE (t
), f
, r
),
2217 substitute_in_type (TYPE_DOMAIN (t
), f
, r
));
2224 case QUAL_UNION_TYPE
:
2226 tree
new = copy_node (t
);
2228 tree last_field
= 0;
2230 /* Start out with no fields, make new fields, and chain them
2233 TYPE_FIELDS (new) = 0;
2234 TYPE_SIZE (new) = 0;
2236 for (field
= TYPE_FIELDS (t
); field
;
2237 field
= TREE_CHAIN (field
))
2239 tree new_field
= copy_node (field
);
2241 TREE_TYPE (new_field
)
2242 = substitute_in_type (TREE_TYPE (new_field
), f
, r
);
2244 /* If this is an anonymous field and the type of this field is
2245 a UNION_TYPE or RECORD_TYPE with no elements, ignore it. If
2246 the type just has one element, treat that as the field.
2247 But don't do this if we are processing a QUAL_UNION_TYPE. */
2248 if (TREE_CODE (t
) != QUAL_UNION_TYPE
&& DECL_NAME (new_field
) == 0
2249 && (TREE_CODE (TREE_TYPE (new_field
)) == UNION_TYPE
2250 || TREE_CODE (TREE_TYPE (new_field
)) == RECORD_TYPE
))
2252 if (TYPE_FIELDS (TREE_TYPE (new_field
)) == 0)
2255 if (TREE_CHAIN (TYPE_FIELDS (TREE_TYPE (new_field
))) == 0)
2256 new_field
= TYPE_FIELDS (TREE_TYPE (new_field
));
2259 DECL_CONTEXT (new_field
) = new;
2260 DECL_SIZE (new_field
) = 0;
2262 if (TREE_CODE (t
) == QUAL_UNION_TYPE
)
2264 /* Do the substitution inside the qualifier and if we find
2265 that this field will not be present, omit it. */
2266 DECL_QUALIFIER (new_field
)
2267 = substitute_in_expr (DECL_QUALIFIER (field
), f
, r
);
2268 if (integer_zerop (DECL_QUALIFIER (new_field
)))
2272 if (last_field
== 0)
2273 TYPE_FIELDS (new) = new_field
;
2275 TREE_CHAIN (last_field
) = new_field
;
2277 last_field
= new_field
;
2279 /* If this is a qualified type and this field will always be
2280 present, we are done. */
2281 if (TREE_CODE (t
) == QUAL_UNION_TYPE
2282 && integer_onep (DECL_QUALIFIER (new_field
)))
2286 /* If this used to be a qualified union type, but we now know what
2287 field will be present, make this a normal union. */
2288 if (TREE_CODE (new) == QUAL_UNION_TYPE
2289 && (TYPE_FIELDS (new) == 0
2290 || integer_onep (DECL_QUALIFIER (TYPE_FIELDS (new)))))
2291 TREE_SET_CODE (new, UNION_TYPE
);
2299 /* Stabilize a reference so that we can use it any number of times
2300 without causing its operands to be evaluated more than once.
2301 Returns the stabilized reference. This works by means of save_expr,
2302 so see the caveats in the comments about save_expr.
2304 Also allows conversion expressions whose operands are references.
2305 Any other kind of expression is returned unchanged. */
2308 stabilize_reference (ref
)
2311 register tree result
;
2312 register enum tree_code code
= TREE_CODE (ref
);
2319 /* No action is needed in this case. */
2325 case FIX_TRUNC_EXPR
:
2326 case FIX_FLOOR_EXPR
:
2327 case FIX_ROUND_EXPR
:
2329 result
= build_nt (code
, stabilize_reference (TREE_OPERAND (ref
, 0)));
2333 result
= build_nt (INDIRECT_REF
,
2334 stabilize_reference_1 (TREE_OPERAND (ref
, 0)));
2338 result
= build_nt (COMPONENT_REF
,
2339 stabilize_reference (TREE_OPERAND (ref
, 0)),
2340 TREE_OPERAND (ref
, 1));
2344 result
= build_nt (BIT_FIELD_REF
,
2345 stabilize_reference (TREE_OPERAND (ref
, 0)),
2346 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
2347 stabilize_reference_1 (TREE_OPERAND (ref
, 2)));
2351 result
= build_nt (ARRAY_REF
,
2352 stabilize_reference (TREE_OPERAND (ref
, 0)),
2353 stabilize_reference_1 (TREE_OPERAND (ref
, 1)));
2356 /* If arg isn't a kind of lvalue we recognize, make no change.
2357 Caller should recognize the error for an invalid lvalue. */
2362 return error_mark_node
;
2365 TREE_TYPE (result
) = TREE_TYPE (ref
);
2366 TREE_READONLY (result
) = TREE_READONLY (ref
);
2367 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (ref
);
2368 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (ref
);
2369 TREE_RAISES (result
) = TREE_RAISES (ref
);
2374 /* Subroutine of stabilize_reference; this is called for subtrees of
2375 references. Any expression with side-effects must be put in a SAVE_EXPR
2376 to ensure that it is only evaluated once.
2378 We don't put SAVE_EXPR nodes around everything, because assigning very
2379 simple expressions to temporaries causes us to miss good opportunities
2380 for optimizations. Among other things, the opportunity to fold in the
2381 addition of a constant into an addressing mode often gets lost, e.g.
2382 "y[i+1] += x;". In general, we take the approach that we should not make
2383 an assignment unless we are forced into it - i.e., that any non-side effect
2384 operator should be allowed, and that cse should take care of coalescing
2385 multiple utterances of the same expression should that prove fruitful. */
2388 stabilize_reference_1 (e
)
2391 register tree result
;
2392 register enum tree_code code
= TREE_CODE (e
);
2394 /* We cannot ignore const expressions because it might be a reference
2395 to a const array but whose index contains side-effects. But we can
2396 ignore things that are actual constant or that already have been
2397 handled by this function. */
2399 if (TREE_CONSTANT (e
) || code
== SAVE_EXPR
)
2402 switch (TREE_CODE_CLASS (code
))
2412 /* If the expression has side-effects, then encase it in a SAVE_EXPR
2413 so that it will only be evaluated once. */
2414 /* The reference (r) and comparison (<) classes could be handled as
2415 below, but it is generally faster to only evaluate them once. */
2416 if (TREE_SIDE_EFFECTS (e
))
2417 return save_expr (e
);
2421 /* Constants need no processing. In fact, we should never reach
2426 /* Division is slow and tends to be compiled with jumps,
2427 especially the division by powers of 2 that is often
2428 found inside of an array reference. So do it just once. */
2429 if (code
== TRUNC_DIV_EXPR
|| code
== TRUNC_MOD_EXPR
2430 || code
== FLOOR_DIV_EXPR
|| code
== FLOOR_MOD_EXPR
2431 || code
== CEIL_DIV_EXPR
|| code
== CEIL_MOD_EXPR
2432 || code
== ROUND_DIV_EXPR
|| code
== ROUND_MOD_EXPR
)
2433 return save_expr (e
);
2434 /* Recursively stabilize each operand. */
2435 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)),
2436 stabilize_reference_1 (TREE_OPERAND (e
, 1)));
2440 /* Recursively stabilize each operand. */
2441 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)));
2448 TREE_TYPE (result
) = TREE_TYPE (e
);
2449 TREE_READONLY (result
) = TREE_READONLY (e
);
2450 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (e
);
2451 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (e
);
2452 TREE_RAISES (result
) = TREE_RAISES (e
);
2457 /* Low-level constructors for expressions. */
2459 /* Build an expression of code CODE, data type TYPE,
2460 and operands as specified by the arguments ARG1 and following arguments.
2461 Expressions and reference nodes can be created this way.
2462 Constants, decls, types and misc nodes cannot be. */
2465 build
VPROTO((enum tree_code code
, tree tt
, ...))
2468 enum tree_code code
;
2473 register int length
;
2479 code
= va_arg (p
, enum tree_code
);
2480 tt
= va_arg (p
, tree
);
2483 t
= make_node (code
);
2484 length
= tree_code_length
[(int) code
];
2489 /* This is equivalent to the loop below, but faster. */
2490 register tree arg0
= va_arg (p
, tree
);
2491 register tree arg1
= va_arg (p
, tree
);
2492 TREE_OPERAND (t
, 0) = arg0
;
2493 TREE_OPERAND (t
, 1) = arg1
;
2494 if ((arg0
&& TREE_SIDE_EFFECTS (arg0
))
2495 || (arg1
&& TREE_SIDE_EFFECTS (arg1
)))
2496 TREE_SIDE_EFFECTS (t
) = 1;
2498 = (arg0
&& TREE_RAISES (arg0
)) || (arg1
&& TREE_RAISES (arg1
));
2500 else if (length
== 1)
2502 register tree arg0
= va_arg (p
, tree
);
2504 /* Call build1 for this! */
2505 if (TREE_CODE_CLASS (code
) != 's')
2507 TREE_OPERAND (t
, 0) = arg0
;
2508 if (arg0
&& TREE_SIDE_EFFECTS (arg0
))
2509 TREE_SIDE_EFFECTS (t
) = 1;
2510 TREE_RAISES (t
) = (arg0
&& TREE_RAISES (arg0
));
2514 for (i
= 0; i
< length
; i
++)
2516 register tree operand
= va_arg (p
, tree
);
2517 TREE_OPERAND (t
, i
) = operand
;
2520 if (TREE_SIDE_EFFECTS (operand
))
2521 TREE_SIDE_EFFECTS (t
) = 1;
2522 if (TREE_RAISES (operand
))
2523 TREE_RAISES (t
) = 1;
2531 /* Same as above, but only builds for unary operators.
2532 Saves lions share of calls to `build'; cuts down use
2533 of varargs, which is expensive for RISC machines. */
2535 build1 (code
, type
, node
)
2536 enum tree_code code
;
2540 register struct obstack
*obstack
= current_obstack
;
2541 register int i
, length
;
2542 register tree_node_kind kind
;
2545 #ifdef GATHER_STATISTICS
2546 if (TREE_CODE_CLASS (code
) == 'r')
2552 obstack
= expression_obstack
;
2553 length
= sizeof (struct tree_exp
);
2555 t
= (tree
) obstack_alloc (obstack
, length
);
2557 #ifdef GATHER_STATISTICS
2558 tree_node_counts
[(int)kind
]++;
2559 tree_node_sizes
[(int)kind
] += length
;
2562 for (i
= (length
/ sizeof (int)) - 1; i
>= 0; i
--)
2565 TREE_TYPE (t
) = type
;
2566 TREE_SET_CODE (t
, code
);
2568 if (obstack
== &permanent_obstack
)
2569 TREE_PERMANENT (t
) = 1;
2571 TREE_OPERAND (t
, 0) = node
;
2574 if (TREE_SIDE_EFFECTS (node
))
2575 TREE_SIDE_EFFECTS (t
) = 1;
2576 if (TREE_RAISES (node
))
2577 TREE_RAISES (t
) = 1;
2583 /* Similar except don't specify the TREE_TYPE
2584 and leave the TREE_SIDE_EFFECTS as 0.
2585 It is permissible for arguments to be null,
2586 or even garbage if their values do not matter. */
2589 build_nt
VPROTO((enum tree_code code
, ...))
2592 enum tree_code code
;
2596 register int length
;
2602 code
= va_arg (p
, enum tree_code
);
2605 t
= make_node (code
);
2606 length
= tree_code_length
[(int) code
];
2608 for (i
= 0; i
< length
; i
++)
2609 TREE_OPERAND (t
, i
) = va_arg (p
, tree
);
2615 /* Similar to `build_nt', except we build
2616 on the temp_decl_obstack, regardless. */
2619 build_parse_node
VPROTO((enum tree_code code
, ...))
2622 enum tree_code code
;
2624 register struct obstack
*ambient_obstack
= expression_obstack
;
2627 register int length
;
2633 code
= va_arg (p
, enum tree_code
);
2636 expression_obstack
= &temp_decl_obstack
;
2638 t
= make_node (code
);
2639 length
= tree_code_length
[(int) code
];
2641 for (i
= 0; i
< length
; i
++)
2642 TREE_OPERAND (t
, i
) = va_arg (p
, tree
);
2645 expression_obstack
= ambient_obstack
;
2650 /* Commented out because this wants to be done very
2651 differently. See cp-lex.c. */
2653 build_op_identifier (op1
, op2
)
2656 register tree t
= make_node (OP_IDENTIFIER
);
2657 TREE_PURPOSE (t
) = op1
;
2658 TREE_VALUE (t
) = op2
;
2663 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
2664 We do NOT enter this node in any sort of symbol table.
2666 layout_decl is used to set up the decl's storage layout.
2667 Other slots are initialized to 0 or null pointers. */
2670 build_decl (code
, name
, type
)
2671 enum tree_code code
;
2676 t
= make_node (code
);
2678 /* if (type == error_mark_node)
2679 type = integer_type_node; */
2680 /* That is not done, deliberately, so that having error_mark_node
2681 as the type can suppress useless errors in the use of this variable. */
2683 DECL_NAME (t
) = name
;
2684 DECL_ASSEMBLER_NAME (t
) = name
;
2685 TREE_TYPE (t
) = type
;
2687 if (code
== VAR_DECL
|| code
== PARM_DECL
|| code
== RESULT_DECL
)
2689 else if (code
== FUNCTION_DECL
)
2690 DECL_MODE (t
) = FUNCTION_MODE
;
2695 /* BLOCK nodes are used to represent the structure of binding contours
2696 and declarations, once those contours have been exited and their contents
2697 compiled. This information is used for outputting debugging info. */
2700 build_block (vars
, tags
, subblocks
, supercontext
, chain
)
2701 tree vars
, tags
, subblocks
, supercontext
, chain
;
2703 register tree block
= make_node (BLOCK
);
2704 BLOCK_VARS (block
) = vars
;
2705 BLOCK_TYPE_TAGS (block
) = tags
;
2706 BLOCK_SUBBLOCKS (block
) = subblocks
;
2707 BLOCK_SUPERCONTEXT (block
) = supercontext
;
2708 BLOCK_CHAIN (block
) = chain
;
2712 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
2715 Such modified types already made are recorded so that duplicates
2719 build_type_attribute_variant (ttype
, attribute
)
2720 tree ttype
, attribute
;
2722 if ( ! attribute_list_equal (TYPE_ATTRIBUTES (ttype
), attribute
))
2724 register int hashcode
;
2725 register struct obstack
*ambient_obstack
= current_obstack
;
2728 if (ambient_obstack
!= &permanent_obstack
)
2729 current_obstack
= TYPE_OBSTACK (ttype
);
2731 ntype
= copy_node (ttype
);
2732 current_obstack
= ambient_obstack
;
2734 TYPE_POINTER_TO (ntype
) = 0;
2735 TYPE_REFERENCE_TO (ntype
) = 0;
2736 TYPE_ATTRIBUTES (ntype
) = attribute
;
2738 /* Create a new main variant of TYPE. */
2739 TYPE_MAIN_VARIANT (ntype
) = ntype
;
2740 TYPE_NEXT_VARIANT (ntype
) = 0;
2741 TYPE_READONLY (ntype
) = TYPE_VOLATILE (ntype
) = 0;
2743 hashcode
= TYPE_HASH (TREE_CODE (ntype
))
2744 + TYPE_HASH (TREE_TYPE (ntype
))
2745 + type_hash_list (attribute
);
2747 switch (TREE_CODE (ntype
))
2750 hashcode
+= TYPE_HASH (TYPE_ARG_TYPES (ntype
));
2753 hashcode
+= TYPE_HASH (TYPE_DOMAIN (ntype
));
2756 hashcode
+= TYPE_HASH (TYPE_MAX_VALUE (ntype
));
2759 hashcode
+= TYPE_HASH (TYPE_PRECISION (ntype
));
2763 ntype
= type_hash_canon (hashcode
, ntype
);
2764 ttype
= build_type_variant (ntype
, TYPE_READONLY (ttype
),
2765 TYPE_VOLATILE (ttype
));
2771 /* Return a type like TYPE except that its TYPE_READONLY is CONSTP
2772 and its TYPE_VOLATILE is VOLATILEP.
2774 Such variant types already made are recorded so that duplicates
2777 A variant types should never be used as the type of an expression.
2778 Always copy the variant information into the TREE_READONLY
2779 and TREE_THIS_VOLATILE of the expression, and then give the expression
2780 as its type the "main variant", the variant whose TYPE_READONLY
2781 and TYPE_VOLATILE are zero. Use TYPE_MAIN_VARIANT to find the
2785 build_type_variant (type
, constp
, volatilep
)
2787 int constp
, volatilep
;
2791 /* Treat any nonzero argument as 1. */
2793 volatilep
= !!volatilep
;
2795 /* If not generating auxiliary info, search the chain of variants to see
2796 if there is already one there just like the one we need to have. If so,
2797 use that existing one.
2799 We don't do this in the case where we are generating aux info because
2800 in that case we want each typedef names to get it's own distinct type
2801 node, even if the type of this new typedef is the same as some other
2804 if (!flag_gen_aux_info
)
2805 for (t
= TYPE_MAIN_VARIANT(type
); t
; t
= TYPE_NEXT_VARIANT (t
))
2806 if (constp
== TYPE_READONLY (t
) && volatilep
== TYPE_VOLATILE (t
))
2809 /* We need a new one. */
2811 t
= build_type_copy (type
);
2812 TYPE_READONLY (t
) = constp
;
2813 TYPE_VOLATILE (t
) = volatilep
;
2818 /* Give TYPE a new main variant: NEW_MAIN.
2819 This is the right thing to do only when something else
2820 about TYPE is modified in place. */
2823 change_main_variant (type
, new_main
)
2824 tree type
, new_main
;
2827 tree omain
= TYPE_MAIN_VARIANT (type
);
2829 /* Remove TYPE from the TYPE_NEXT_VARIANT chain of its main variant. */
2830 if (TYPE_NEXT_VARIANT (omain
) == type
)
2831 TYPE_NEXT_VARIANT (omain
) = TYPE_NEXT_VARIANT (type
);
2833 for (t
= TYPE_NEXT_VARIANT (omain
); t
&& TYPE_NEXT_VARIANT (t
);
2834 t
= TYPE_NEXT_VARIANT (t
))
2835 if (TYPE_NEXT_VARIANT (t
) == type
)
2837 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (type
);
2841 TYPE_MAIN_VARIANT (type
) = new_main
;
2842 TYPE_NEXT_VARIANT (type
) = TYPE_NEXT_VARIANT (new_main
);
2843 TYPE_NEXT_VARIANT (new_main
) = type
;
2846 /* Create a new variant of TYPE, equivalent but distinct.
2847 This is so the caller can modify it. */
2850 build_type_copy (type
)
2853 register tree t
, m
= TYPE_MAIN_VARIANT (type
);
2854 register struct obstack
*ambient_obstack
= current_obstack
;
2856 current_obstack
= TYPE_OBSTACK (type
);
2857 t
= copy_node (type
);
2858 current_obstack
= ambient_obstack
;
2860 TYPE_POINTER_TO (t
) = 0;
2861 TYPE_REFERENCE_TO (t
) = 0;
2863 /* Add this type to the chain of variants of TYPE. */
2864 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (m
);
2865 TYPE_NEXT_VARIANT (m
) = t
;
2870 /* Hashing of types so that we don't make duplicates.
2871 The entry point is `type_hash_canon'. */
2873 /* Each hash table slot is a bucket containing a chain
2874 of these structures. */
2878 struct type_hash
*next
; /* Next structure in the bucket. */
2879 int hashcode
; /* Hash code of this type. */
2880 tree type
; /* The type recorded here. */
2883 /* Now here is the hash table. When recording a type, it is added
2884 to the slot whose index is the hash code mod the table size.
2885 Note that the hash table is used for several kinds of types
2886 (function types, array types and array index range types, for now).
2887 While all these live in the same table, they are completely independent,
2888 and the hash code is computed differently for each of these. */
2890 #define TYPE_HASH_SIZE 59
2891 struct type_hash
*type_hash_table
[TYPE_HASH_SIZE
];
2893 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
2894 with types in the TREE_VALUE slots), by adding the hash codes
2895 of the individual types. */
2898 type_hash_list (list
)
2901 register int hashcode
;
2903 for (hashcode
= 0, tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
2904 hashcode
+= TYPE_HASH (TREE_VALUE (tail
));
2908 /* Look in the type hash table for a type isomorphic to TYPE.
2909 If one is found, return it. Otherwise return 0. */
2912 type_hash_lookup (hashcode
, type
)
2916 register struct type_hash
*h
;
2917 for (h
= type_hash_table
[hashcode
% TYPE_HASH_SIZE
]; h
; h
= h
->next
)
2918 if (h
->hashcode
== hashcode
2919 && TREE_CODE (h
->type
) == TREE_CODE (type
)
2920 && TREE_TYPE (h
->type
) == TREE_TYPE (type
)
2921 && attribute_list_equal (TYPE_ATTRIBUTES (h
->type
),
2922 TYPE_ATTRIBUTES (type
))
2923 && (TYPE_MAX_VALUE (h
->type
) == TYPE_MAX_VALUE (type
)
2924 || tree_int_cst_equal (TYPE_MAX_VALUE (h
->type
),
2925 TYPE_MAX_VALUE (type
)))
2926 && (TYPE_MIN_VALUE (h
->type
) == TYPE_MIN_VALUE (type
)
2927 || tree_int_cst_equal (TYPE_MIN_VALUE (h
->type
),
2928 TYPE_MIN_VALUE (type
)))
2929 && (TYPE_DOMAIN (h
->type
) == TYPE_DOMAIN (type
)
2930 || (TYPE_DOMAIN (h
->type
)
2931 && TREE_CODE (TYPE_DOMAIN (h
->type
)) == TREE_LIST
2932 && TYPE_DOMAIN (type
)
2933 && TREE_CODE (TYPE_DOMAIN (type
)) == TREE_LIST
2934 && type_list_equal (TYPE_DOMAIN (h
->type
), TYPE_DOMAIN (type
)))))
2939 /* Add an entry to the type-hash-table
2940 for a type TYPE whose hash code is HASHCODE. */
2943 type_hash_add (hashcode
, type
)
2947 register struct type_hash
*h
;
2949 h
= (struct type_hash
*) oballoc (sizeof (struct type_hash
));
2950 h
->hashcode
= hashcode
;
2952 h
->next
= type_hash_table
[hashcode
% TYPE_HASH_SIZE
];
2953 type_hash_table
[hashcode
% TYPE_HASH_SIZE
] = h
;
2956 /* Given TYPE, and HASHCODE its hash code, return the canonical
2957 object for an identical type if one already exists.
2958 Otherwise, return TYPE, and record it as the canonical object
2959 if it is a permanent object.
2961 To use this function, first create a type of the sort you want.
2962 Then compute its hash code from the fields of the type that
2963 make it different from other similar types.
2964 Then call this function and use the value.
2965 This function frees the type you pass in if it is a duplicate. */
2967 /* Set to 1 to debug without canonicalization. Never set by program. */
2968 int debug_no_type_hash
= 0;
2971 type_hash_canon (hashcode
, type
)
2977 if (debug_no_type_hash
)
2980 t1
= type_hash_lookup (hashcode
, type
);
2983 obstack_free (TYPE_OBSTACK (type
), type
);
2984 #ifdef GATHER_STATISTICS
2985 tree_node_counts
[(int)t_kind
]--;
2986 tree_node_sizes
[(int)t_kind
] -= sizeof (struct tree_type
);
2991 /* If this is a permanent type, record it for later reuse. */
2992 if (TREE_PERMANENT (type
))
2993 type_hash_add (hashcode
, type
);
2998 /* Given two lists of attributes, return true if list l2 is
2999 equivalent to l1. */
3002 attribute_list_equal (l1
, l2
)
3005 return attribute_list_contained (l1
, l2
)
3006 && attribute_list_contained (l2
, l1
);
3009 /* Given two lists of attributes, return true if list l2 is
3010 completely contained within l1. */
3013 attribute_list_contained (l1
, l2
)
3016 register tree t1
, t2
;
3018 /* First check the obvious, maybe the lists are identical. */
3022 /* Then check the obvious, maybe the lists are similar. */
3023 for (t1
= l1
, t2
= l2
;
3025 && TREE_VALUE (t1
) == TREE_VALUE (t2
);
3026 t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
));
3028 /* Maybe the lists are equal. */
3029 if (t1
== 0 && t2
== 0)
3032 for (; t2
; t2
= TREE_CHAIN (t2
))
3033 if (!value_member (l1
, t2
))
3038 /* Given two lists of types
3039 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
3040 return 1 if the lists contain the same types in the same order.
3041 Also, the TREE_PURPOSEs must match. */
3044 type_list_equal (l1
, l2
)
3047 register tree t1
, t2
;
3048 for (t1
= l1
, t2
= l2
; t1
&& t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
3050 if (TREE_VALUE (t1
) != TREE_VALUE (t2
))
3052 if (TREE_PURPOSE (t1
) != TREE_PURPOSE (t2
))
3054 int cmp
= simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
));
3065 /* Nonzero if integer constants T1 and T2
3066 represent the same constant value. */
3069 tree_int_cst_equal (t1
, t2
)
3074 if (t1
== 0 || t2
== 0)
3076 if (TREE_CODE (t1
) == INTEGER_CST
3077 && TREE_CODE (t2
) == INTEGER_CST
3078 && TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
3079 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
))
3084 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
3085 The precise way of comparison depends on their data type. */
3088 tree_int_cst_lt (t1
, t2
)
3094 if (!TREE_UNSIGNED (TREE_TYPE (t1
)))
3095 return INT_CST_LT (t1
, t2
);
3096 return INT_CST_LT_UNSIGNED (t1
, t2
);
3099 /* Return an indication of the sign of the integer constant T.
3100 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
3101 Note that -1 will never be returned it T's type is unsigned. */
3104 tree_int_cst_sgn (t
)
3107 if (TREE_INT_CST_LOW (t
) == 0 && TREE_INT_CST_HIGH (t
) == 0)
3109 else if (TREE_UNSIGNED (TREE_TYPE (t
)))
3111 else if (TREE_INT_CST_HIGH (t
) < 0)
3117 /* Compare two constructor-element-type constants. */
3119 simple_cst_list_equal (l1
, l2
)
3122 while (l1
!= NULL_TREE
&& l2
!= NULL_TREE
)
3124 int cmp
= simple_cst_equal (TREE_VALUE (l1
), TREE_VALUE (l2
));
3129 l1
= TREE_CHAIN (l1
);
3130 l2
= TREE_CHAIN (l2
);
3135 /* Return truthvalue of whether T1 is the same tree structure as T2.
3136 Return 1 if they are the same.
3137 Return 0 if they are understandably different.
3138 Return -1 if either contains tree structure not understood by
3142 simple_cst_equal (t1
, t2
)
3145 register enum tree_code code1
, code2
;
3150 if (t1
== 0 || t2
== 0)
3153 code1
= TREE_CODE (t1
);
3154 code2
= TREE_CODE (t2
);
3156 if (code1
== NOP_EXPR
|| code1
== CONVERT_EXPR
|| code1
== NON_LVALUE_EXPR
)
3157 if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
|| code2
== NON_LVALUE_EXPR
)
3158 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3160 return simple_cst_equal (TREE_OPERAND (t1
, 0), t2
);
3161 else if (code2
== NOP_EXPR
|| code2
== CONVERT_EXPR
3162 || code2
== NON_LVALUE_EXPR
)
3163 return simple_cst_equal (t1
, TREE_OPERAND (t2
, 0));
3171 return TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
3172 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
);
3175 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
3178 return TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
3179 && !bcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
3180 TREE_STRING_LENGTH (t1
));
3186 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3189 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3192 return simple_cst_list_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
3195 /* Special case: if either target is an unallocated VAR_DECL,
3196 it means that it's going to be unified with whatever the
3197 TARGET_EXPR is really supposed to initialize, so treat it
3198 as being equivalent to anything. */
3199 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
3200 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
3201 && DECL_RTL (TREE_OPERAND (t1
, 0)) == 0)
3202 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
3203 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
3204 && DECL_RTL (TREE_OPERAND (t2
, 0)) == 0))
3207 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3210 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
3212 case WITH_CLEANUP_EXPR
:
3213 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3216 return simple_cst_equal (TREE_OPERAND (t1
, 2), TREE_OPERAND (t1
, 2));
3219 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
3220 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3230 /* This general rule works for most tree codes.
3231 All exceptions should be handled above. */
3233 switch (TREE_CODE_CLASS (code1
))
3243 for (i
=0; i
<tree_code_length
[(int) code1
]; ++i
)
3245 cmp
= simple_cst_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
3255 /* Constructors for pointer, array and function types.
3256 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
3257 constructed by language-dependent code, not here.) */
3259 /* Construct, lay out and return the type of pointers to TO_TYPE.
3260 If such a type has already been constructed, reuse it. */
3263 build_pointer_type (to_type
)
3266 register tree t
= TYPE_POINTER_TO (to_type
);
3268 /* First, if we already have a type for pointers to TO_TYPE, use it. */
3273 /* We need a new one. Put this in the same obstack as TO_TYPE. */
3274 push_obstacks (TYPE_OBSTACK (to_type
), TYPE_OBSTACK (to_type
));
3275 t
= make_node (POINTER_TYPE
);
3278 TREE_TYPE (t
) = to_type
;
3280 /* Record this type as the pointer to TO_TYPE. */
3281 TYPE_POINTER_TO (to_type
) = t
;
3283 /* Lay out the type. This function has many callers that are concerned
3284 with expression-construction, and this simplifies them all.
3285 Also, it guarantees the TYPE_SIZE is in the same obstack as the type. */
3291 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
3292 MAXVAL should be the maximum value in the domain
3293 (one less than the length of the array). */
3296 build_index_type (maxval
)
3299 register tree itype
= make_node (INTEGER_TYPE
);
3300 TYPE_PRECISION (itype
) = TYPE_PRECISION (sizetype
);
3301 TYPE_MIN_VALUE (itype
) = build_int_2 (0, 0);
3302 TREE_TYPE (TYPE_MIN_VALUE (itype
)) = sizetype
;
3303 TYPE_MAX_VALUE (itype
) = convert (sizetype
, maxval
);
3304 TYPE_MODE (itype
) = TYPE_MODE (sizetype
);
3305 TYPE_SIZE (itype
) = TYPE_SIZE (sizetype
);
3306 TYPE_ALIGN (itype
) = TYPE_ALIGN (sizetype
);
3307 if (TREE_CODE (maxval
) == INTEGER_CST
)
3309 int maxint
= (int) TREE_INT_CST_LOW (maxval
);
3310 /* If the domain should be empty, make sure the maxval
3311 remains -1 and is not spoiled by truncation. */
3312 if (INT_CST_LT (maxval
, integer_zero_node
))
3314 TYPE_MAX_VALUE (itype
) = build_int_2 (-1, -1);
3315 TREE_TYPE (TYPE_MAX_VALUE (itype
)) = sizetype
;
3317 return type_hash_canon (maxint
< 0 ? ~maxint
: maxint
, itype
);
3323 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
3324 ENUMERAL_TYPE, BOOLEAN_TYPE, or CHAR_TYPE), with
3325 low bound LOWVAL and high bound HIGHVAL.
3326 if TYPE==NULL_TREE, sizetype is used. */
3329 build_range_type (type
, lowval
, highval
)
3330 tree type
, lowval
, highval
;
3332 register tree itype
= make_node (INTEGER_TYPE
);
3333 TREE_TYPE (itype
) = type
;
3334 if (type
== NULL_TREE
)
3336 TYPE_PRECISION (itype
) = TYPE_PRECISION (type
);
3337 TYPE_MIN_VALUE (itype
) = convert (type
, lowval
);
3338 TYPE_MAX_VALUE (itype
) = convert (type
, highval
);
3339 TYPE_MODE (itype
) = TYPE_MODE (type
);
3340 TYPE_SIZE (itype
) = TYPE_SIZE (type
);
3341 TYPE_ALIGN (itype
) = TYPE_ALIGN (type
);
3342 if ((TREE_CODE (lowval
) == INTEGER_CST
)
3343 && (TREE_CODE (highval
) == INTEGER_CST
))
3345 HOST_WIDE_INT highint
= TREE_INT_CST_LOW (highval
);
3346 HOST_WIDE_INT lowint
= TREE_INT_CST_LOW (lowval
);
3347 int maxint
= (int) (highint
- lowint
);
3348 return type_hash_canon (maxint
< 0 ? ~maxint
: maxint
, itype
);
3354 /* Just like build_index_type, but takes lowval and highval instead
3355 of just highval (maxval). */
3358 build_index_2_type (lowval
,highval
)
3359 tree lowval
, highval
;
3361 return build_range_type (NULL_TREE
, lowval
, highval
);
3364 /* Return nonzero iff ITYPE1 and ITYPE2 are equal (in the LISP sense).
3365 Needed because when index types are not hashed, equal index types
3366 built at different times appear distinct, even though structurally,
3370 index_type_equal (itype1
, itype2
)
3371 tree itype1
, itype2
;
3373 if (TREE_CODE (itype1
) != TREE_CODE (itype2
))
3375 if (TREE_CODE (itype1
) == INTEGER_TYPE
)
3377 if (TYPE_PRECISION (itype1
) != TYPE_PRECISION (itype2
)
3378 || TYPE_MODE (itype1
) != TYPE_MODE (itype2
)
3379 || ! simple_cst_equal (TYPE_SIZE (itype1
), TYPE_SIZE (itype2
))
3380 || TYPE_ALIGN (itype1
) != TYPE_ALIGN (itype2
))
3382 if (simple_cst_equal (TYPE_MIN_VALUE (itype1
), TYPE_MIN_VALUE (itype2
))
3383 && simple_cst_equal (TYPE_MAX_VALUE (itype1
), TYPE_MAX_VALUE (itype2
)))
3389 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
3390 and number of elements specified by the range of values of INDEX_TYPE.
3391 If such a type has already been constructed, reuse it. */
3394 build_array_type (elt_type
, index_type
)
3395 tree elt_type
, index_type
;
3400 if (TREE_CODE (elt_type
) == FUNCTION_TYPE
)
3402 error ("arrays of functions are not meaningful");
3403 elt_type
= integer_type_node
;
3406 /* Make sure TYPE_POINTER_TO (elt_type) is filled in. */
3407 build_pointer_type (elt_type
);
3409 /* Allocate the array after the pointer type,
3410 in case we free it in type_hash_canon. */
3411 t
= make_node (ARRAY_TYPE
);
3412 TREE_TYPE (t
) = elt_type
;
3413 TYPE_DOMAIN (t
) = index_type
;
3415 if (index_type
== 0)
3420 hashcode
= TYPE_HASH (elt_type
) + TYPE_HASH (index_type
);
3421 t
= type_hash_canon (hashcode
, t
);
3423 #if 0 /* This led to crashes, because it could put a temporary node
3424 on the TYPE_NEXT_VARIANT chain of a permanent one. */
3425 /* The main variant of an array type should always
3426 be an array whose element type is the main variant. */
3427 if (elt_type
!= TYPE_MAIN_VARIANT (elt_type
))
3428 change_main_variant (t
, build_array_type (TYPE_MAIN_VARIANT (elt_type
),
3432 if (TYPE_SIZE (t
) == 0)
3437 /* Construct, lay out and return
3438 the type of functions returning type VALUE_TYPE
3439 given arguments of types ARG_TYPES.
3440 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
3441 are data type nodes for the arguments of the function.
3442 If such a type has already been constructed, reuse it. */
3445 build_function_type (value_type
, arg_types
)
3446 tree value_type
, arg_types
;
3451 if (TREE_CODE (value_type
) == FUNCTION_TYPE
)
3453 error ("function return type cannot be function");
3454 value_type
= integer_type_node
;
3457 /* Make a node of the sort we want. */
3458 t
= make_node (FUNCTION_TYPE
);
3459 TREE_TYPE (t
) = value_type
;
3460 TYPE_ARG_TYPES (t
) = arg_types
;
3462 /* If we already have such a type, use the old one and free this one. */
3463 hashcode
= TYPE_HASH (value_type
) + type_hash_list (arg_types
);
3464 t
= type_hash_canon (hashcode
, t
);
3466 if (TYPE_SIZE (t
) == 0)
3471 /* Build the node for the type of references-to-TO_TYPE. */
3474 build_reference_type (to_type
)
3477 register tree t
= TYPE_REFERENCE_TO (to_type
);
3478 register struct obstack
*ambient_obstack
= current_obstack
;
3479 register struct obstack
*ambient_saveable_obstack
= saveable_obstack
;
3481 /* First, if we already have a type for pointers to TO_TYPE, use it. */
3486 /* We need a new one. If TO_TYPE is permanent, make this permanent too. */
3487 if (TREE_PERMANENT (to_type
))
3489 current_obstack
= &permanent_obstack
;
3490 saveable_obstack
= &permanent_obstack
;
3493 t
= make_node (REFERENCE_TYPE
);
3494 TREE_TYPE (t
) = to_type
;
3496 /* Record this type as the pointer to TO_TYPE. */
3497 TYPE_REFERENCE_TO (to_type
) = t
;
3501 current_obstack
= ambient_obstack
;
3502 saveable_obstack
= ambient_saveable_obstack
;
3506 /* Construct, lay out and return the type of methods belonging to class
3507 BASETYPE and whose arguments and values are described by TYPE.
3508 If that type exists already, reuse it.
3509 TYPE must be a FUNCTION_TYPE node. */
3512 build_method_type (basetype
, type
)
3513 tree basetype
, type
;
3518 /* Make a node of the sort we want. */
3519 t
= make_node (METHOD_TYPE
);
3521 if (TREE_CODE (type
) != FUNCTION_TYPE
)
3524 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
3525 TREE_TYPE (t
) = TREE_TYPE (type
);
3527 /* The actual arglist for this function includes a "hidden" argument
3528 which is "this". Put it into the list of argument types. */
3531 = tree_cons (NULL_TREE
,
3532 build_pointer_type (basetype
), TYPE_ARG_TYPES (type
));
3534 /* If we already have such a type, use the old one and free this one. */
3535 hashcode
= TYPE_HASH (basetype
) + TYPE_HASH (type
);
3536 t
= type_hash_canon (hashcode
, t
);
3538 if (TYPE_SIZE (t
) == 0)
3544 /* Construct, lay out and return the type of offsets to a value
3545 of type TYPE, within an object of type BASETYPE.
3546 If a suitable offset type exists already, reuse it. */
3549 build_offset_type (basetype
, type
)
3550 tree basetype
, type
;
3555 /* Make a node of the sort we want. */
3556 t
= make_node (OFFSET_TYPE
);
3558 TYPE_OFFSET_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
3559 TREE_TYPE (t
) = type
;
3561 /* If we already have such a type, use the old one and free this one. */
3562 hashcode
= TYPE_HASH (basetype
) + TYPE_HASH (type
);
3563 t
= type_hash_canon (hashcode
, t
);
3565 if (TYPE_SIZE (t
) == 0)
3571 /* Create a complex type whose components are COMPONENT_TYPE. */
3574 build_complex_type (component_type
)
3575 tree component_type
;
3580 /* Make a node of the sort we want. */
3581 t
= make_node (COMPLEX_TYPE
);
3583 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (component_type
);
3584 TYPE_VOLATILE (t
) = TYPE_VOLATILE (component_type
);
3585 TYPE_READONLY (t
) = TYPE_READONLY (component_type
);
3587 /* If we already have such a type, use the old one and free this one. */
3588 hashcode
= TYPE_HASH (component_type
);
3589 t
= type_hash_canon (hashcode
, t
);
3591 if (TYPE_SIZE (t
) == 0)
3597 /* Return OP, stripped of any conversions to wider types as much as is safe.
3598 Converting the value back to OP's type makes a value equivalent to OP.
3600 If FOR_TYPE is nonzero, we return a value which, if converted to
3601 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
3603 If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
3604 narrowest type that can hold the value, even if they don't exactly fit.
3605 Otherwise, bit-field references are changed to a narrower type
3606 only if they can be fetched directly from memory in that type.
3608 OP must have integer, real or enumeral type. Pointers are not allowed!
3610 There are some cases where the obvious value we could return
3611 would regenerate to OP if converted to OP's type,
3612 but would not extend like OP to wider types.
3613 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
3614 For example, if OP is (unsigned short)(signed char)-1,
3615 we avoid returning (signed char)-1 if FOR_TYPE is int,
3616 even though extending that to an unsigned short would regenerate OP,
3617 since the result of extending (signed char)-1 to (int)
3618 is different from (int) OP. */
3621 get_unwidened (op
, for_type
)
3625 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
3626 /* TYPE_PRECISION is safe in place of type_precision since
3627 pointer types are not allowed. */
3628 register tree type
= TREE_TYPE (op
);
3629 register unsigned final_prec
3630 = TYPE_PRECISION (for_type
!= 0 ? for_type
: type
);
3632 = (for_type
!= 0 && for_type
!= type
3633 && final_prec
> TYPE_PRECISION (type
)
3634 && TREE_UNSIGNED (type
));
3635 register tree win
= op
;
3637 while (TREE_CODE (op
) == NOP_EXPR
)
3639 register int bitschange
3640 = TYPE_PRECISION (TREE_TYPE (op
))
3641 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0)));
3643 /* Truncations are many-one so cannot be removed.
3644 Unless we are later going to truncate down even farther. */
3646 && final_prec
> TYPE_PRECISION (TREE_TYPE (op
)))
3649 /* See what's inside this conversion. If we decide to strip it,
3651 op
= TREE_OPERAND (op
, 0);
3653 /* If we have not stripped any zero-extensions (uns is 0),
3654 we can strip any kind of extension.
3655 If we have previously stripped a zero-extension,
3656 only zero-extensions can safely be stripped.
3657 Any extension can be stripped if the bits it would produce
3658 are all going to be discarded later by truncating to FOR_TYPE. */
3662 if (! uns
|| final_prec
<= TYPE_PRECISION (TREE_TYPE (op
)))
3664 /* TREE_UNSIGNED says whether this is a zero-extension.
3665 Let's avoid computing it if it does not affect WIN
3666 and if UNS will not be needed again. */
3667 if ((uns
|| TREE_CODE (op
) == NOP_EXPR
)
3668 && TREE_UNSIGNED (TREE_TYPE (op
)))
3676 if (TREE_CODE (op
) == COMPONENT_REF
3677 /* Since type_for_size always gives an integer type. */
3678 && TREE_CODE (type
) != REAL_TYPE
)
3680 unsigned innerprec
= TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op
, 1)));
3681 type
= type_for_size (innerprec
, TREE_UNSIGNED (TREE_OPERAND (op
, 1)));
3683 /* We can get this structure field in the narrowest type it fits in.
3684 If FOR_TYPE is 0, do this only for a field that matches the
3685 narrower type exactly and is aligned for it
3686 The resulting extension to its nominal type (a fullword type)
3687 must fit the same conditions as for other extensions. */
3689 if (innerprec
< TYPE_PRECISION (TREE_TYPE (op
))
3690 && (for_type
|| ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1)))
3691 && (! uns
|| final_prec
<= innerprec
3692 || TREE_UNSIGNED (TREE_OPERAND (op
, 1)))
3695 win
= build (COMPONENT_REF
, type
, TREE_OPERAND (op
, 0),
3696 TREE_OPERAND (op
, 1));
3697 TREE_SIDE_EFFECTS (win
) = TREE_SIDE_EFFECTS (op
);
3698 TREE_THIS_VOLATILE (win
) = TREE_THIS_VOLATILE (op
);
3699 TREE_RAISES (win
) = TREE_RAISES (op
);
3705 /* Return OP or a simpler expression for a narrower value
3706 which can be sign-extended or zero-extended to give back OP.
3707 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
3708 or 0 if the value should be sign-extended. */
3711 get_narrower (op
, unsignedp_ptr
)
3715 register int uns
= 0;
3717 register tree win
= op
;
3719 while (TREE_CODE (op
) == NOP_EXPR
)
3721 register int bitschange
3722 = TYPE_PRECISION (TREE_TYPE (op
))
3723 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0)));
3725 /* Truncations are many-one so cannot be removed. */
3729 /* See what's inside this conversion. If we decide to strip it,
3731 op
= TREE_OPERAND (op
, 0);
3735 /* An extension: the outermost one can be stripped,
3736 but remember whether it is zero or sign extension. */
3738 uns
= TREE_UNSIGNED (TREE_TYPE (op
));
3739 /* Otherwise, if a sign extension has been stripped,
3740 only sign extensions can now be stripped;
3741 if a zero extension has been stripped, only zero-extensions. */
3742 else if (uns
!= TREE_UNSIGNED (TREE_TYPE (op
)))
3746 else /* bitschange == 0 */
3748 /* A change in nominal type can always be stripped, but we must
3749 preserve the unsignedness. */
3751 uns
= TREE_UNSIGNED (TREE_TYPE (op
));
3758 if (TREE_CODE (op
) == COMPONENT_REF
3759 /* Since type_for_size always gives an integer type. */
3760 && TREE_CODE (TREE_TYPE (op
)) != REAL_TYPE
)
3762 unsigned innerprec
= TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op
, 1)));
3763 tree type
= type_for_size (innerprec
, TREE_UNSIGNED (op
));
3765 /* We can get this structure field in a narrower type that fits it,
3766 but the resulting extension to its nominal type (a fullword type)
3767 must satisfy the same conditions as for other extensions.
3769 Do this only for fields that are aligned (not bit-fields),
3770 because when bit-field insns will be used there is no
3771 advantage in doing this. */
3773 if (innerprec
< TYPE_PRECISION (TREE_TYPE (op
))
3774 && ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1))
3775 && (first
|| uns
== TREE_UNSIGNED (TREE_OPERAND (op
, 1)))
3779 uns
= TREE_UNSIGNED (TREE_OPERAND (op
, 1));
3780 win
= build (COMPONENT_REF
, type
, TREE_OPERAND (op
, 0),
3781 TREE_OPERAND (op
, 1));
3782 TREE_SIDE_EFFECTS (win
) = TREE_SIDE_EFFECTS (op
);
3783 TREE_THIS_VOLATILE (win
) = TREE_THIS_VOLATILE (op
);
3784 TREE_RAISES (win
) = TREE_RAISES (op
);
3787 *unsignedp_ptr
= uns
;
3791 /* Return the precision of a type, for arithmetic purposes.
3792 Supports all types on which arithmetic is possible
3793 (including pointer types).
3794 It's not clear yet what will be right for complex types. */
3797 type_precision (type
)
3800 return ((TREE_CODE (type
) == INTEGER_TYPE
3801 || TREE_CODE (type
) == ENUMERAL_TYPE
3802 || TREE_CODE (type
) == REAL_TYPE
)
3803 ? TYPE_PRECISION (type
) : POINTER_SIZE
);
3806 /* Nonzero if integer constant C has a value that is permissible
3807 for type TYPE (an INTEGER_TYPE). */
3810 int_fits_type_p (c
, type
)
3813 if (TREE_UNSIGNED (type
))
3814 return (! (TREE_CODE (TYPE_MAX_VALUE (type
)) == INTEGER_CST
3815 && INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type
), c
))
3816 && ! (TREE_CODE (TYPE_MIN_VALUE (type
)) == INTEGER_CST
3817 && INT_CST_LT_UNSIGNED (c
, TYPE_MIN_VALUE (type
))));
3819 return (! (TREE_CODE (TYPE_MAX_VALUE (type
)) == INTEGER_CST
3820 && INT_CST_LT (TYPE_MAX_VALUE (type
), c
))
3821 && ! (TREE_CODE (TYPE_MIN_VALUE (type
)) == INTEGER_CST
3822 && INT_CST_LT (c
, TYPE_MIN_VALUE (type
))));
3825 /* Return the innermost context enclosing DECL that is
3826 a FUNCTION_DECL, or zero if none. */
3829 decl_function_context (decl
)
3834 if (TREE_CODE (decl
) == ERROR_MARK
)
3837 if (TREE_CODE (decl
) == SAVE_EXPR
)
3838 context
= SAVE_EXPR_CONTEXT (decl
);
3840 context
= DECL_CONTEXT (decl
);
3842 while (context
&& TREE_CODE (context
) != FUNCTION_DECL
)
3844 if (TREE_CODE (context
) == RECORD_TYPE
3845 || TREE_CODE (context
) == UNION_TYPE
)
3846 context
= TYPE_CONTEXT (context
);
3847 else if (TREE_CODE (context
) == TYPE_DECL
)
3848 context
= DECL_CONTEXT (context
);
3849 else if (TREE_CODE (context
) == BLOCK
)
3850 context
= BLOCK_SUPERCONTEXT (context
);
3852 /* Unhandled CONTEXT !? */
3859 /* Return the innermost context enclosing DECL that is
3860 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
3861 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
3864 decl_type_context (decl
)
3867 tree context
= DECL_CONTEXT (decl
);
3871 if (TREE_CODE (context
) == RECORD_TYPE
3872 || TREE_CODE (context
) == UNION_TYPE
3873 || TREE_CODE (context
) == QUAL_UNION_TYPE
)
3875 if (TREE_CODE (context
) == TYPE_DECL
3876 || TREE_CODE (context
) == FUNCTION_DECL
)
3877 context
= DECL_CONTEXT (context
);
3878 else if (TREE_CODE (context
) == BLOCK
)
3879 context
= BLOCK_SUPERCONTEXT (context
);
3881 /* Unhandled CONTEXT!? */
3888 print_obstack_statistics (str
, o
)
3892 struct _obstack_chunk
*chunk
= o
->chunk
;
3899 n_alloc
+= chunk
->limit
- &chunk
->contents
[0];
3900 chunk
= chunk
->prev
;
3902 fprintf (stderr
, "obstack %s: %d bytes, %d chunks\n",
3903 str
, n_alloc
, n_chunks
);
3906 dump_tree_statistics ()
3909 int total_nodes
, total_bytes
;
3911 fprintf (stderr
, "\n??? tree nodes created\n\n");
3912 #ifdef GATHER_STATISTICS
3913 fprintf (stderr
, "Kind Nodes Bytes\n");
3914 fprintf (stderr
, "-------------------------------------\n");
3915 total_nodes
= total_bytes
= 0;
3916 for (i
= 0; i
< (int) all_kinds
; i
++)
3918 fprintf (stderr
, "%-20s %6d %9d\n", tree_node_kind_names
[i
],
3919 tree_node_counts
[i
], tree_node_sizes
[i
]);
3920 total_nodes
+= tree_node_counts
[i
];
3921 total_bytes
+= tree_node_sizes
[i
];
3923 fprintf (stderr
, "%-20s %9d\n", "identifier names", id_string_size
);
3924 fprintf (stderr
, "-------------------------------------\n");
3925 fprintf (stderr
, "%-20s %6d %9d\n", "Total", total_nodes
, total_bytes
);
3926 fprintf (stderr
, "-------------------------------------\n");
3928 fprintf (stderr
, "(No per-node statistics)\n");
3930 print_lang_statistics ();
3933 #define FILE_FUNCTION_PREFIX_LEN 9
3935 #ifndef NO_DOLLAR_IN_LABEL
3936 #define FILE_FUNCTION_FORMAT "_GLOBAL_$D$%s"
3937 #else /* NO_DOLLAR_IN_LABEL */
3938 #ifndef NO_DOT_IN_LABEL
3939 #define FILE_FUNCTION_FORMAT "_GLOBAL_.D.%s"
3940 #else /* NO_DOT_IN_LABEL */
3941 #define FILE_FUNCTION_FORMAT "_GLOBAL__D_%s"
3942 #endif /* NO_DOT_IN_LABEL */
3943 #endif /* NO_DOLLAR_IN_LABEL */
3945 extern char * first_global_object_name
;
3947 /* If KIND=='I', return a suitable global initializer (constructor) name.
3948 If KIND=='D', return a suitable global clean-up (destructor) name. */
3951 get_file_function_name (kind
)
3957 if (first_global_object_name
)
3958 p
= first_global_object_name
;
3959 else if (main_input_filename
)
3960 p
= main_input_filename
;
3964 buf
= (char *) alloca (sizeof (FILE_FUNCTION_FORMAT
) + strlen (p
));
3966 /* Set up the name of the file-level functions we may need. */
3967 /* Use a global object (which is already required to be unique over
3968 the program) rather than the file name (which imposes extra
3969 constraints). -- Raeburn@MIT.EDU, 10 Jan 1990. */
3970 sprintf (buf
, FILE_FUNCTION_FORMAT
, p
);
3972 /* Don't need to pull wierd characters out of global names. */
3973 if (p
!= first_global_object_name
)
3975 for (p
= buf
+11; *p
; p
++)
3976 if (! ((*p
>= '0' && *p
<= '9')
3977 #if 0 /* we always want labels, which are valid C++ identifiers (+ `$') */
3978 #ifndef ASM_IDENTIFY_GCC /* this is required if `.' is invalid -- k. raeburn */
3982 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
3985 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
3988 || (*p
>= 'A' && *p
<= 'Z')
3989 || (*p
>= 'a' && *p
<= 'z')))
3993 buf
[FILE_FUNCTION_PREFIX_LEN
] = kind
;
3995 return get_identifier (buf
);