(arm_comp_type_attributes): Simply and comment tests on type attributes.
[official-gcc.git] / gcc / tree.c
blob4c5a7ef3402df49fac306ed16ee55afdff1b733c
1 /* Language-independent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* This file contains the low level primitives for operating on tree nodes,
24 including allocation, list operations, interning of identifiers,
25 construction of data type nodes and statement nodes,
26 and construction of type conversion nodes. It also contains
27 tables index by tree code that describe how to take apart
28 nodes of that code.
30 It is intended to be language-independent, but occasionally
31 calls language-dependent routines defined (for C) in typecheck.c.
33 The low-level allocation routines oballoc and permalloc
34 are used also for allocating many other kinds of objects
35 by all passes of the compiler. */
37 #include "config.h"
38 #include "system.h"
39 #include "flags.h"
40 #include "tree.h"
41 #include "tm_p.h"
42 #include "function.h"
43 #include "obstack.h"
44 #include "toplev.h"
45 #include "ggc.h"
47 #define obstack_chunk_alloc xmalloc
48 #define obstack_chunk_free free
49 /* obstack.[ch] explicitly declined to prototype this. */
50 extern int _obstack_allocated_p PARAMS ((struct obstack *h, PTR obj));
52 static void unsave_expr_now_r PARAMS ((tree));
54 /* Tree nodes of permanent duration are allocated in this obstack.
55 They are the identifier nodes, and everything outside of
56 the bodies and parameters of function definitions. */
58 struct obstack permanent_obstack;
60 /* The initial RTL, and all ..._TYPE nodes, in a function
61 are allocated in this obstack. Usually they are freed at the
62 end of the function, but if the function is inline they are saved.
63 For top-level functions, this is maybepermanent_obstack.
64 Separate obstacks are made for nested functions. */
66 struct obstack *function_maybepermanent_obstack;
68 /* This is the function_maybepermanent_obstack for top-level functions. */
70 struct obstack maybepermanent_obstack;
72 /* The contents of the current function definition are allocated
73 in this obstack, and all are freed at the end of the function.
74 For top-level functions, this is temporary_obstack.
75 Separate obstacks are made for nested functions. */
77 struct obstack *function_obstack;
79 /* This is used for reading initializers of global variables. */
81 struct obstack temporary_obstack;
83 /* The tree nodes of an expression are allocated
84 in this obstack, and all are freed at the end of the expression. */
86 struct obstack momentary_obstack;
88 /* The tree nodes of a declarator are allocated
89 in this obstack, and all are freed when the declarator
90 has been parsed. */
92 static struct obstack temp_decl_obstack;
94 /* This points at either permanent_obstack
95 or the current function_maybepermanent_obstack. */
97 struct obstack *saveable_obstack;
99 /* This is same as saveable_obstack during parse and expansion phase;
100 it points to the current function's obstack during optimization.
101 This is the obstack to be used for creating rtl objects. */
103 struct obstack *rtl_obstack;
105 /* This points at either permanent_obstack or the current function_obstack. */
107 struct obstack *current_obstack;
109 /* This points at either permanent_obstack or the current function_obstack
110 or momentary_obstack. */
112 struct obstack *expression_obstack;
114 /* Stack of obstack selections for push_obstacks and pop_obstacks. */
116 struct obstack_stack
118 struct obstack_stack *next;
119 struct obstack *current;
120 struct obstack *saveable;
121 struct obstack *expression;
122 struct obstack *rtl;
125 struct obstack_stack *obstack_stack;
127 /* Obstack for allocating struct obstack_stack entries. */
129 static struct obstack obstack_stack_obstack;
131 /* Addresses of first objects in some obstacks.
132 This is for freeing their entire contents. */
133 char *maybepermanent_firstobj;
134 char *temporary_firstobj;
135 char *momentary_firstobj;
136 char *temp_decl_firstobj;
138 /* This is used to preserve objects (mainly array initializers) that need to
139 live until the end of the current function, but no further. */
140 char *momentary_function_firstobj;
142 /* Nonzero means all ..._TYPE nodes should be allocated permanently. */
144 int all_types_permanent;
146 /* Stack of places to restore the momentary obstack back to. */
148 struct momentary_level
150 /* Pointer back to previous such level. */
151 struct momentary_level *prev;
152 /* First object allocated within this level. */
153 char *base;
154 /* Value of expression_obstack saved at entry to this level. */
155 struct obstack *obstack;
158 struct momentary_level *momentary_stack;
160 /* Table indexed by tree code giving a string containing a character
161 classifying the tree code. Possibilities are
162 t, d, s, c, r, <, 1, 2 and e. See tree.def for details. */
164 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
166 char tree_code_type[MAX_TREE_CODES] = {
167 #include "tree.def"
169 #undef DEFTREECODE
171 /* Table indexed by tree code giving number of expression
172 operands beyond the fixed part of the node structure.
173 Not used for types or decls. */
175 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
177 int tree_code_length[MAX_TREE_CODES] = {
178 #include "tree.def"
180 #undef DEFTREECODE
182 /* Names of tree components.
183 Used for printing out the tree and error messages. */
184 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
186 const char *tree_code_name[MAX_TREE_CODES] = {
187 #include "tree.def"
189 #undef DEFTREECODE
191 /* Statistics-gathering stuff. */
192 typedef enum
194 d_kind,
195 t_kind,
196 b_kind,
197 s_kind,
198 r_kind,
199 e_kind,
200 c_kind,
201 id_kind,
202 op_id_kind,
203 perm_list_kind,
204 temp_list_kind,
205 vec_kind,
206 x_kind,
207 lang_decl,
208 lang_type,
209 all_kinds
210 } tree_node_kind;
212 int tree_node_counts[(int)all_kinds];
213 int tree_node_sizes[(int)all_kinds];
214 int id_string_size = 0;
216 static const char * const tree_node_kind_names[] = {
217 "decls",
218 "types",
219 "blocks",
220 "stmts",
221 "refs",
222 "exprs",
223 "constants",
224 "identifiers",
225 "op_identifiers",
226 "perm_tree_lists",
227 "temp_tree_lists",
228 "vecs",
229 "random kinds",
230 "lang_decl kinds",
231 "lang_type kinds"
234 /* Hash table for uniquizing IDENTIFIER_NODEs by name. */
236 #define MAX_HASH_TABLE 1009
237 static tree hash_table[MAX_HASH_TABLE]; /* id hash buckets */
239 /* 0 while creating built-in identifiers. */
240 static int do_identifier_warnings;
242 /* Unique id for next decl created. */
243 static int next_decl_uid;
244 /* Unique id for next type created. */
245 static int next_type_uid = 1;
247 /* The language-specific function for alias analysis. If NULL, the
248 language does not do any special alias analysis. */
249 int (*lang_get_alias_set) PARAMS ((tree));
251 /* Here is how primitive or already-canonicalized types' hash
252 codes are made. */
253 #define TYPE_HASH(TYPE) ((unsigned long) (TYPE) & 0777777)
255 /* Each hash table slot is a bucket containing a chain
256 of these structures. */
258 struct type_hash
260 struct type_hash *next; /* Next structure in the bucket. */
261 int hashcode; /* Hash code of this type. */
262 tree type; /* The type recorded here. */
265 /* Now here is the hash table. When recording a type, it is added
266 to the slot whose index is the hash code mod the table size.
267 Note that the hash table is used for several kinds of types
268 (function types, array types and array index range types, for now).
269 While all these live in the same table, they are completely independent,
270 and the hash code is computed differently for each of these. */
272 #define TYPE_HASH_SIZE 59
273 struct type_hash *type_hash_table[TYPE_HASH_SIZE];
275 static void build_real_from_int_cst_1 PARAMS ((PTR));
276 static void set_type_quals PARAMS ((tree, int));
277 static void append_random_chars PARAMS ((char *));
278 static void mark_type_hash PARAMS ((void *));
279 static void fix_sizetype PARAMS ((tree));
281 /* If non-null, these are language-specific helper functions for
282 unsave_expr_now. If present, LANG_UNSAVE is called before its
283 argument (an UNSAVE_EXPR) is to be unsaved, and all other
284 processing in unsave_expr_now is aborted. LANG_UNSAVE_EXPR_NOW is
285 called from unsave_expr_1 for language-specific tree codes. */
286 void (*lang_unsave) PARAMS ((tree *));
287 void (*lang_unsave_expr_now) PARAMS ((tree));
289 /* The string used as a placeholder instead of a source file name for
290 built-in tree nodes. The variable, which is dynamically allocated,
291 should be used; the macro is only used to initialize it. */
293 static char *built_in_filename;
294 #define BUILT_IN_FILENAME ("<built-in>")
296 tree global_trees[TI_MAX];
298 /* Init the principal obstacks. */
300 void
301 init_obstacks ()
303 gcc_obstack_init (&obstack_stack_obstack);
304 gcc_obstack_init (&permanent_obstack);
306 gcc_obstack_init (&temporary_obstack);
307 temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0);
308 gcc_obstack_init (&momentary_obstack);
309 momentary_firstobj = (char *) obstack_alloc (&momentary_obstack, 0);
310 momentary_function_firstobj = momentary_firstobj;
311 gcc_obstack_init (&maybepermanent_obstack);
312 maybepermanent_firstobj
313 = (char *) obstack_alloc (&maybepermanent_obstack, 0);
314 gcc_obstack_init (&temp_decl_obstack);
315 temp_decl_firstobj = (char *) obstack_alloc (&temp_decl_obstack, 0);
317 function_obstack = &temporary_obstack;
318 function_maybepermanent_obstack = &maybepermanent_obstack;
319 current_obstack = &permanent_obstack;
320 expression_obstack = &permanent_obstack;
321 rtl_obstack = saveable_obstack = &permanent_obstack;
323 /* Init the hash table of identifiers. */
324 bzero ((char *) hash_table, sizeof hash_table);
325 ggc_add_tree_root (hash_table, sizeof hash_table / sizeof (tree));
327 /* Initialize the hash table of types. */
328 bzero ((char *) type_hash_table,
329 sizeof type_hash_table / sizeof type_hash_table[0]);
330 ggc_add_root (type_hash_table,
331 sizeof type_hash_table / sizeof type_hash_table [0],
332 sizeof type_hash_table[0], mark_type_hash);
333 ggc_add_tree_root (global_trees, TI_MAX);
336 void
337 gcc_obstack_init (obstack)
338 struct obstack *obstack;
340 /* Let particular systems override the size of a chunk. */
341 #ifndef OBSTACK_CHUNK_SIZE
342 #define OBSTACK_CHUNK_SIZE 0
343 #endif
344 /* Let them override the alloc and free routines too. */
345 #ifndef OBSTACK_CHUNK_ALLOC
346 #define OBSTACK_CHUNK_ALLOC xmalloc
347 #endif
348 #ifndef OBSTACK_CHUNK_FREE
349 #define OBSTACK_CHUNK_FREE free
350 #endif
351 _obstack_begin (obstack, OBSTACK_CHUNK_SIZE, 0,
352 (void *(*) PARAMS ((long))) OBSTACK_CHUNK_ALLOC,
353 (void (*) PARAMS ((void *))) OBSTACK_CHUNK_FREE);
356 /* Save all variables describing the current status into the structure
357 *P. This function is called whenever we start compiling one
358 function in the midst of compiling another. For example, when
359 compiling a nested function, or, in C++, a template instantiation
360 that is required by the function we are currently compiling.
362 CONTEXT is the decl_function_context for the function we're about to
363 compile; if it isn't current_function_decl, we have to play some games. */
365 void
366 save_tree_status (p)
367 struct function *p;
369 p->all_types_permanent = all_types_permanent;
370 p->momentary_stack = momentary_stack;
371 p->maybepermanent_firstobj = maybepermanent_firstobj;
372 p->temporary_firstobj = temporary_firstobj;
373 p->momentary_firstobj = momentary_firstobj;
374 p->momentary_function_firstobj = momentary_function_firstobj;
375 p->function_obstack = function_obstack;
376 p->function_maybepermanent_obstack = function_maybepermanent_obstack;
377 p->current_obstack = current_obstack;
378 p->expression_obstack = expression_obstack;
379 p->saveable_obstack = saveable_obstack;
380 p->rtl_obstack = rtl_obstack;
382 function_maybepermanent_obstack
383 = (struct obstack *) xmalloc (sizeof (struct obstack));
384 gcc_obstack_init (function_maybepermanent_obstack);
385 maybepermanent_firstobj
386 = (char *) obstack_finish (function_maybepermanent_obstack);
388 function_obstack = (struct obstack *) xmalloc (sizeof (struct obstack));
389 gcc_obstack_init (function_obstack);
391 current_obstack = &permanent_obstack;
392 expression_obstack = &permanent_obstack;
393 rtl_obstack = saveable_obstack = &permanent_obstack;
395 temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0);
396 momentary_firstobj = (char *) obstack_finish (&momentary_obstack);
397 momentary_function_firstobj = momentary_firstobj;
400 /* Restore all variables describing the current status from the structure *P.
401 This is used after a nested function. */
403 void
404 restore_tree_status (p)
405 struct function *p;
407 all_types_permanent = p->all_types_permanent;
408 momentary_stack = p->momentary_stack;
410 obstack_free (&momentary_obstack, momentary_function_firstobj);
412 /* Free saveable storage used by the function just compiled and not
413 saved. */
414 obstack_free (function_maybepermanent_obstack, maybepermanent_firstobj);
415 if (obstack_empty_p (function_maybepermanent_obstack))
417 obstack_free (function_maybepermanent_obstack, NULL);
418 free (function_maybepermanent_obstack);
421 obstack_free (&temporary_obstack, temporary_firstobj);
422 obstack_free (&momentary_obstack, momentary_function_firstobj);
424 obstack_free (function_obstack, NULL);
425 free (function_obstack);
427 temporary_firstobj = p->temporary_firstobj;
428 momentary_firstobj = p->momentary_firstobj;
429 momentary_function_firstobj = p->momentary_function_firstobj;
430 maybepermanent_firstobj = p->maybepermanent_firstobj;
431 function_obstack = p->function_obstack;
432 function_maybepermanent_obstack = p->function_maybepermanent_obstack;
433 current_obstack = p->current_obstack;
434 expression_obstack = p->expression_obstack;
435 saveable_obstack = p->saveable_obstack;
436 rtl_obstack = p->rtl_obstack;
439 /* Start allocating on the temporary (per function) obstack.
440 This is done in start_function before parsing the function body,
441 and before each initialization at top level, and to go back
442 to temporary allocation after doing permanent_allocation. */
444 void
445 temporary_allocation ()
447 /* Note that function_obstack at top level points to temporary_obstack.
448 But within a nested function context, it is a separate obstack. */
449 current_obstack = function_obstack;
450 expression_obstack = function_obstack;
451 rtl_obstack = saveable_obstack = function_maybepermanent_obstack;
452 momentary_stack = 0;
455 /* Start allocating on the permanent obstack but don't
456 free the temporary data. After calling this, call
457 `permanent_allocation' to fully resume permanent allocation status. */
459 void
460 end_temporary_allocation ()
462 current_obstack = &permanent_obstack;
463 expression_obstack = &permanent_obstack;
464 rtl_obstack = saveable_obstack = &permanent_obstack;
467 /* Resume allocating on the temporary obstack, undoing
468 effects of `end_temporary_allocation'. */
470 void
471 resume_temporary_allocation ()
473 current_obstack = function_obstack;
474 expression_obstack = function_obstack;
475 rtl_obstack = saveable_obstack = function_maybepermanent_obstack;
478 /* While doing temporary allocation, switch to allocating in such a
479 way as to save all nodes if the function is inlined. Call
480 resume_temporary_allocation to go back to ordinary temporary
481 allocation. */
483 void
484 saveable_allocation ()
486 /* Note that function_obstack at top level points to temporary_obstack.
487 But within a nested function context, it is a separate obstack. */
488 expression_obstack = current_obstack = saveable_obstack;
491 /* Switch to current obstack CURRENT and maybepermanent obstack SAVEABLE,
492 recording the previously current obstacks on a stack.
493 This does not free any storage in any obstack. */
495 void
496 push_obstacks (current, saveable)
497 struct obstack *current, *saveable;
499 struct obstack_stack *p;
501 p = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,
502 (sizeof (struct obstack_stack)));
504 p->current = current_obstack;
505 p->saveable = saveable_obstack;
506 p->expression = expression_obstack;
507 p->rtl = rtl_obstack;
508 p->next = obstack_stack;
509 obstack_stack = p;
511 current_obstack = current;
512 expression_obstack = current;
513 rtl_obstack = saveable_obstack = saveable;
516 /* Save the current set of obstacks, but don't change them. */
518 void
519 push_obstacks_nochange ()
521 struct obstack_stack *p;
523 p = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,
524 (sizeof (struct obstack_stack)));
526 p->current = current_obstack;
527 p->saveable = saveable_obstack;
528 p->expression = expression_obstack;
529 p->rtl = rtl_obstack;
530 p->next = obstack_stack;
531 obstack_stack = p;
534 /* Pop the obstack selection stack. */
536 void
537 pop_obstacks ()
539 struct obstack_stack *p;
541 p = obstack_stack;
542 obstack_stack = p->next;
544 current_obstack = p->current;
545 saveable_obstack = p->saveable;
546 expression_obstack = p->expression;
547 rtl_obstack = p->rtl;
549 obstack_free (&obstack_stack_obstack, p);
552 /* Nonzero if temporary allocation is currently in effect.
553 Zero if currently doing permanent allocation. */
556 allocation_temporary_p ()
558 return current_obstack != &permanent_obstack;
561 /* Go back to allocating on the permanent obstack
562 and free everything in the temporary obstack.
564 FUNCTION_END is true only if we have just finished compiling a function.
565 In that case, we also free preserved initial values on the momentary
566 obstack. */
568 void
569 permanent_allocation (function_end)
570 int function_end;
572 /* Free up previous temporary obstack data */
573 obstack_free (&temporary_obstack, temporary_firstobj);
574 if (function_end)
576 obstack_free (&momentary_obstack, momentary_function_firstobj);
577 momentary_firstobj = momentary_function_firstobj;
579 else
580 obstack_free (&momentary_obstack, momentary_firstobj);
582 obstack_free (function_maybepermanent_obstack, maybepermanent_firstobj);
583 obstack_free (&temp_decl_obstack, temp_decl_firstobj);
585 current_obstack = &permanent_obstack;
586 expression_obstack = &permanent_obstack;
587 rtl_obstack = saveable_obstack = &permanent_obstack;
590 /* Save permanently everything on the maybepermanent_obstack. */
592 void
593 preserve_data ()
595 maybepermanent_firstobj
596 = (char *) obstack_alloc (function_maybepermanent_obstack, 0);
599 void
600 preserve_initializer ()
602 struct momentary_level *tem;
603 char *old_momentary;
605 temporary_firstobj
606 = (char *) obstack_alloc (&temporary_obstack, 0);
607 maybepermanent_firstobj
608 = (char *) obstack_alloc (function_maybepermanent_obstack, 0);
610 old_momentary = momentary_firstobj;
611 momentary_firstobj
612 = (char *) obstack_alloc (&momentary_obstack, 0);
613 if (momentary_firstobj != old_momentary)
614 for (tem = momentary_stack; tem; tem = tem->prev)
615 tem->base = momentary_firstobj;
618 /* Start allocating new rtl in current_obstack.
619 Use resume_temporary_allocation
620 to go back to allocating rtl in saveable_obstack. */
622 void
623 rtl_in_current_obstack ()
625 rtl_obstack = current_obstack;
628 /* Start allocating rtl from saveable_obstack. Intended to be used after
629 a call to push_obstacks_nochange. */
631 void
632 rtl_in_saveable_obstack ()
634 rtl_obstack = saveable_obstack;
637 /* Allocate SIZE bytes in the current obstack
638 and return a pointer to them.
639 In practice the current obstack is always the temporary one. */
641 char *
642 oballoc (size)
643 int size;
645 return (char *) obstack_alloc (current_obstack, size);
648 /* Free the object PTR in the current obstack
649 as well as everything allocated since PTR.
650 In practice the current obstack is always the temporary one. */
652 void
653 obfree (ptr)
654 char *ptr;
656 obstack_free (current_obstack, ptr);
659 /* Allocate SIZE bytes in the permanent obstack
660 and return a pointer to them. */
662 char *
663 permalloc (size)
664 int size;
666 return (char *) obstack_alloc (&permanent_obstack, size);
669 /* Allocate NELEM items of SIZE bytes in the permanent obstack
670 and return a pointer to them. The storage is cleared before
671 returning the value. */
673 char *
674 perm_calloc (nelem, size)
675 int nelem;
676 long size;
678 char *rval = (char *) obstack_alloc (&permanent_obstack, nelem * size);
679 bzero (rval, nelem * size);
680 return rval;
683 /* Allocate SIZE bytes in the saveable obstack
684 and return a pointer to them. */
686 char *
687 savealloc (size)
688 int size;
690 return (char *) obstack_alloc (saveable_obstack, size);
693 /* Allocate SIZE bytes in the expression obstack
694 and return a pointer to them. */
696 char *
697 expralloc (size)
698 int size;
700 return (char *) obstack_alloc (expression_obstack, size);
703 /* Print out which obstack an object is in. */
705 void
706 print_obstack_name (object, file, prefix)
707 char *object;
708 FILE *file;
709 const char *prefix;
711 struct obstack *obstack = NULL;
712 const char *obstack_name = NULL;
713 struct function *p;
715 for (p = outer_function_chain; p; p = p->next)
717 if (_obstack_allocated_p (p->function_obstack, object))
719 obstack = p->function_obstack;
720 obstack_name = "containing function obstack";
722 if (_obstack_allocated_p (p->function_maybepermanent_obstack, object))
724 obstack = p->function_maybepermanent_obstack;
725 obstack_name = "containing function maybepermanent obstack";
729 if (_obstack_allocated_p (&obstack_stack_obstack, object))
731 obstack = &obstack_stack_obstack;
732 obstack_name = "obstack_stack_obstack";
734 else if (_obstack_allocated_p (function_obstack, object))
736 obstack = function_obstack;
737 obstack_name = "function obstack";
739 else if (_obstack_allocated_p (&permanent_obstack, object))
741 obstack = &permanent_obstack;
742 obstack_name = "permanent_obstack";
744 else if (_obstack_allocated_p (&momentary_obstack, object))
746 obstack = &momentary_obstack;
747 obstack_name = "momentary_obstack";
749 else if (_obstack_allocated_p (function_maybepermanent_obstack, object))
751 obstack = function_maybepermanent_obstack;
752 obstack_name = "function maybepermanent obstack";
754 else if (_obstack_allocated_p (&temp_decl_obstack, object))
756 obstack = &temp_decl_obstack;
757 obstack_name = "temp_decl_obstack";
760 /* Check to see if the object is in the free area of the obstack. */
761 if (obstack != NULL)
763 if (object >= obstack->next_free
764 && object < obstack->chunk_limit)
765 fprintf (file, "%s in free portion of obstack %s",
766 prefix, obstack_name);
767 else
768 fprintf (file, "%s allocated from %s", prefix, obstack_name);
770 else
771 fprintf (file, "%s not allocated from any obstack", prefix);
774 void
775 debug_obstack (object)
776 char *object;
778 print_obstack_name (object, stderr, "object");
779 fprintf (stderr, ".\n");
782 /* Return 1 if OBJ is in the permanent obstack.
783 This is slow, and should be used only for debugging.
784 Use TREE_PERMANENT for other purposes. */
787 object_permanent_p (obj)
788 tree obj;
790 return _obstack_allocated_p (&permanent_obstack, obj);
793 /* Start a level of momentary allocation.
794 In C, each compound statement has its own level
795 and that level is freed at the end of each statement.
796 All expression nodes are allocated in the momentary allocation level. */
798 void
799 push_momentary ()
801 struct momentary_level *tem
802 = (struct momentary_level *) obstack_alloc (&momentary_obstack,
803 sizeof (struct momentary_level));
804 tem->prev = momentary_stack;
805 tem->base = (char *) obstack_base (&momentary_obstack);
806 tem->obstack = expression_obstack;
807 momentary_stack = tem;
808 expression_obstack = &momentary_obstack;
811 /* Set things up so the next clear_momentary will only clear memory
812 past our present position in momentary_obstack. */
814 void
815 preserve_momentary ()
817 momentary_stack->base = (char *) obstack_base (&momentary_obstack);
820 /* Free all the storage in the current momentary-allocation level.
821 In C, this happens at the end of each statement. */
823 void
824 clear_momentary ()
826 obstack_free (&momentary_obstack, momentary_stack->base);
829 /* Discard a level of momentary allocation.
830 In C, this happens at the end of each compound statement.
831 Restore the status of expression node allocation
832 that was in effect before this level was created. */
834 void
835 pop_momentary ()
837 struct momentary_level *tem = momentary_stack;
838 momentary_stack = tem->prev;
839 expression_obstack = tem->obstack;
840 /* We can't free TEM from the momentary_obstack, because there might
841 be objects above it which have been saved. We can free back to the
842 stack of the level we are popping off though. */
843 obstack_free (&momentary_obstack, tem->base);
846 /* Pop back to the previous level of momentary allocation,
847 but don't free any momentary data just yet. */
849 void
850 pop_momentary_nofree ()
852 struct momentary_level *tem = momentary_stack;
853 momentary_stack = tem->prev;
854 expression_obstack = tem->obstack;
857 /* Call when starting to parse a declaration:
858 make expressions in the declaration last the length of the function.
859 Returns an argument that should be passed to resume_momentary later. */
862 suspend_momentary ()
864 register int tem = expression_obstack == &momentary_obstack;
865 expression_obstack = saveable_obstack;
866 return tem;
869 /* Call when finished parsing a declaration:
870 restore the treatment of node-allocation that was
871 in effect before the suspension.
872 YES should be the value previously returned by suspend_momentary. */
874 void
875 resume_momentary (yes)
876 int yes;
878 if (yes)
879 expression_obstack = &momentary_obstack;
882 /* Init the tables indexed by tree code.
883 Note that languages can add to these tables to define their own codes. */
885 void
886 init_tree_codes ()
888 built_in_filename
889 = ggc_alloc_string (BUILT_IN_FILENAME, sizeof (BUILT_IN_FILENAME));
890 ggc_add_string_root (&built_in_filename, 1);
893 /* Return a newly allocated node of code CODE.
894 Initialize the node's unique id and its TREE_PERMANENT flag.
895 For decl and type nodes, some other fields are initialized.
896 The rest of the node is initialized to zero.
898 Achoo! I got a code in the node. */
900 tree
901 make_node (code)
902 enum tree_code code;
904 register tree t;
905 register int type = TREE_CODE_CLASS (code);
906 register int length = 0;
907 register struct obstack *obstack = current_obstack;
908 #ifdef GATHER_STATISTICS
909 register tree_node_kind kind;
910 #endif
912 switch (type)
914 case 'd': /* A decl node */
915 #ifdef GATHER_STATISTICS
916 kind = d_kind;
917 #endif
918 length = sizeof (struct tree_decl);
919 /* All decls in an inline function need to be saved. */
920 if (obstack != &permanent_obstack)
921 obstack = saveable_obstack;
923 /* PARM_DECLs go on the context of the parent. If this is a nested
924 function, then we must allocate the PARM_DECL on the parent's
925 obstack, so that they will live to the end of the parent's
926 closing brace. This is necessary in case we try to inline the
927 function into its parent.
929 PARM_DECLs of top-level functions do not have this problem. However,
930 we allocate them where we put the FUNCTION_DECL for languages such as
931 Ada that need to consult some flags in the PARM_DECLs of the function
932 when calling it.
934 See comment in restore_tree_status for why we can't put this
935 in function_obstack. */
936 if (code == PARM_DECL && obstack != &permanent_obstack)
938 tree context = 0;
939 if (current_function_decl)
940 context = decl_function_context (current_function_decl);
942 if (context)
943 obstack
944 = find_function_data (context)->function_maybepermanent_obstack;
946 break;
948 case 't': /* a type node */
949 #ifdef GATHER_STATISTICS
950 kind = t_kind;
951 #endif
952 length = sizeof (struct tree_type);
953 /* All data types are put where we can preserve them if nec. */
954 if (obstack != &permanent_obstack)
955 obstack = all_types_permanent ? &permanent_obstack : saveable_obstack;
956 break;
958 case 'b': /* a lexical block */
959 #ifdef GATHER_STATISTICS
960 kind = b_kind;
961 #endif
962 length = sizeof (struct tree_block);
963 /* All BLOCK nodes are put where we can preserve them if nec. */
964 if (obstack != &permanent_obstack)
965 obstack = saveable_obstack;
966 break;
968 case 's': /* an expression with side effects */
969 #ifdef GATHER_STATISTICS
970 kind = s_kind;
971 goto usual_kind;
972 #endif
973 case 'r': /* a reference */
974 #ifdef GATHER_STATISTICS
975 kind = r_kind;
976 goto usual_kind;
977 #endif
978 case 'e': /* an expression */
979 case '<': /* a comparison expression */
980 case '1': /* a unary arithmetic expression */
981 case '2': /* a binary arithmetic expression */
982 #ifdef GATHER_STATISTICS
983 kind = e_kind;
984 usual_kind:
985 #endif
986 obstack = expression_obstack;
987 /* All BIND_EXPR nodes are put where we can preserve them if nec. */
988 if (code == BIND_EXPR && obstack != &permanent_obstack)
989 obstack = saveable_obstack;
990 length = sizeof (struct tree_exp)
991 + (tree_code_length[(int) code] - 1) * sizeof (char *);
992 break;
994 case 'c': /* a constant */
995 #ifdef GATHER_STATISTICS
996 kind = c_kind;
997 #endif
998 obstack = expression_obstack;
1000 /* We can't use tree_code_length for INTEGER_CST, since the number of
1001 words is machine-dependent due to varying length of HOST_WIDE_INT,
1002 which might be wider than a pointer (e.g., long long). Similarly
1003 for REAL_CST, since the number of words is machine-dependent due
1004 to varying size and alignment of `double'. */
1006 if (code == INTEGER_CST)
1007 length = sizeof (struct tree_int_cst);
1008 else if (code == REAL_CST)
1009 length = sizeof (struct tree_real_cst);
1010 else
1011 length = sizeof (struct tree_common)
1012 + tree_code_length[(int) code] * sizeof (char *);
1013 break;
1015 case 'x': /* something random, like an identifier. */
1016 #ifdef GATHER_STATISTICS
1017 if (code == IDENTIFIER_NODE)
1018 kind = id_kind;
1019 else if (code == OP_IDENTIFIER)
1020 kind = op_id_kind;
1021 else if (code == TREE_VEC)
1022 kind = vec_kind;
1023 else
1024 kind = x_kind;
1025 #endif
1026 length = sizeof (struct tree_common)
1027 + tree_code_length[(int) code] * sizeof (char *);
1028 /* Identifier nodes are always permanent since they are
1029 unique in a compiler run. */
1030 if (code == IDENTIFIER_NODE) obstack = &permanent_obstack;
1031 break;
1033 default:
1034 abort ();
1037 if (ggc_p)
1038 t = ggc_alloc_tree (length);
1039 else
1041 t = (tree) obstack_alloc (obstack, length);
1042 memset ((PTR) t, 0, length);
1045 #ifdef GATHER_STATISTICS
1046 tree_node_counts[(int)kind]++;
1047 tree_node_sizes[(int)kind] += length;
1048 #endif
1050 TREE_SET_CODE (t, code);
1051 if (obstack == &permanent_obstack)
1052 TREE_PERMANENT (t) = 1;
1054 switch (type)
1056 case 's':
1057 TREE_SIDE_EFFECTS (t) = 1;
1058 TREE_TYPE (t) = void_type_node;
1059 break;
1061 case 'd':
1062 if (code != FUNCTION_DECL)
1063 DECL_ALIGN (t) = 1;
1064 DECL_IN_SYSTEM_HEADER (t)
1065 = in_system_header && (obstack == &permanent_obstack);
1066 DECL_SOURCE_LINE (t) = lineno;
1067 DECL_SOURCE_FILE (t) =
1068 (input_filename) ? input_filename : built_in_filename;
1069 DECL_UID (t) = next_decl_uid++;
1070 /* Note that we have not yet computed the alias set for this
1071 declaration. */
1072 DECL_POINTER_ALIAS_SET (t) = -1;
1073 break;
1075 case 't':
1076 TYPE_UID (t) = next_type_uid++;
1077 TYPE_ALIGN (t) = 1;
1078 TYPE_MAIN_VARIANT (t) = t;
1079 TYPE_OBSTACK (t) = obstack;
1080 TYPE_ATTRIBUTES (t) = NULL_TREE;
1081 #ifdef SET_DEFAULT_TYPE_ATTRIBUTES
1082 SET_DEFAULT_TYPE_ATTRIBUTES (t);
1083 #endif
1084 /* Note that we have not yet computed the alias set for this
1085 type. */
1086 TYPE_ALIAS_SET (t) = -1;
1087 break;
1089 case 'c':
1090 TREE_CONSTANT (t) = 1;
1091 break;
1093 case 'e':
1094 switch (code)
1096 case INIT_EXPR:
1097 case MODIFY_EXPR:
1098 case VA_ARG_EXPR:
1099 case RTL_EXPR:
1100 case PREDECREMENT_EXPR:
1101 case PREINCREMENT_EXPR:
1102 case POSTDECREMENT_EXPR:
1103 case POSTINCREMENT_EXPR:
1104 /* All of these have side-effects, no matter what their
1105 operands are. */
1106 TREE_SIDE_EFFECTS (t) = 1;
1107 break;
1109 default:
1110 break;
1112 break;
1115 return t;
1118 /* A front-end can reset this to an appropriate function if types need
1119 special handling. */
1121 tree (*make_lang_type_fn) PARAMS ((enum tree_code)) = make_node;
1123 /* Return a new type (with the indicated CODE), doing whatever
1124 language-specific processing is required. */
1126 tree
1127 make_lang_type (code)
1128 enum tree_code code;
1130 return (*make_lang_type_fn) (code);
1133 /* Return a new node with the same contents as NODE except that its
1134 TREE_CHAIN is zero and it has a fresh uid. Unlike make_node, this
1135 function always performs the allocation on the CURRENT_OBSTACK;
1136 it's up to the caller to pick the right obstack before calling this
1137 function. */
1139 tree
1140 copy_node (node)
1141 tree node;
1143 register tree t;
1144 register enum tree_code code = TREE_CODE (node);
1145 register int length = 0;
1147 switch (TREE_CODE_CLASS (code))
1149 case 'd': /* A decl node */
1150 length = sizeof (struct tree_decl);
1151 break;
1153 case 't': /* a type node */
1154 length = sizeof (struct tree_type);
1155 break;
1157 case 'b': /* a lexical block node */
1158 length = sizeof (struct tree_block);
1159 break;
1161 case 'r': /* a reference */
1162 case 'e': /* an expression */
1163 case 's': /* an expression with side effects */
1164 case '<': /* a comparison expression */
1165 case '1': /* a unary arithmetic expression */
1166 case '2': /* a binary arithmetic expression */
1167 length = sizeof (struct tree_exp)
1168 + (tree_code_length[(int) code] - 1) * sizeof (char *);
1169 break;
1171 case 'c': /* a constant */
1172 /* We can't use tree_code_length for INTEGER_CST, since the number of
1173 words is machine-dependent due to varying length of HOST_WIDE_INT,
1174 which might be wider than a pointer (e.g., long long). Similarly
1175 for REAL_CST, since the number of words is machine-dependent due
1176 to varying size and alignment of `double'. */
1177 if (code == INTEGER_CST)
1178 length = sizeof (struct tree_int_cst);
1179 else if (code == REAL_CST)
1180 length = sizeof (struct tree_real_cst);
1181 else
1182 length = (sizeof (struct tree_common)
1183 + tree_code_length[(int) code] * sizeof (char *));
1184 break;
1186 case 'x': /* something random, like an identifier. */
1187 length = sizeof (struct tree_common)
1188 + tree_code_length[(int) code] * sizeof (char *);
1189 if (code == TREE_VEC)
1190 length += (TREE_VEC_LENGTH (node) - 1) * sizeof (char *);
1193 if (ggc_p)
1194 t = ggc_alloc_tree (length);
1195 else
1196 t = (tree) obstack_alloc (current_obstack, length);
1197 memcpy (t, node, length);
1199 TREE_CHAIN (t) = 0;
1200 TREE_ASM_WRITTEN (t) = 0;
1202 if (TREE_CODE_CLASS (code) == 'd')
1203 DECL_UID (t) = next_decl_uid++;
1204 else if (TREE_CODE_CLASS (code) == 't')
1206 TYPE_UID (t) = next_type_uid++;
1207 TYPE_OBSTACK (t) = current_obstack;
1209 /* The following is so that the debug code for
1210 the copy is different from the original type.
1211 The two statements usually duplicate each other
1212 (because they clear fields of the same union),
1213 but the optimizer should catch that. */
1214 TYPE_SYMTAB_POINTER (t) = 0;
1215 TYPE_SYMTAB_ADDRESS (t) = 0;
1218 TREE_PERMANENT (t) = (current_obstack == &permanent_obstack);
1220 return t;
1223 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1224 For example, this can copy a list made of TREE_LIST nodes. */
1226 tree
1227 copy_list (list)
1228 tree list;
1230 tree head;
1231 register tree prev, next;
1233 if (list == 0)
1234 return 0;
1236 head = prev = copy_node (list);
1237 next = TREE_CHAIN (list);
1238 while (next)
1240 TREE_CHAIN (prev) = copy_node (next);
1241 prev = TREE_CHAIN (prev);
1242 next = TREE_CHAIN (next);
1244 return head;
1247 #define HASHBITS 30
1249 /* Return an IDENTIFIER_NODE whose name is TEXT (a null-terminated string).
1250 If an identifier with that name has previously been referred to,
1251 the same node is returned this time. */
1253 tree
1254 get_identifier (text)
1255 register const char *text;
1257 register int hi;
1258 register int i;
1259 register tree idp;
1260 register int len, hash_len;
1262 /* Compute length of text in len. */
1263 len = strlen (text);
1265 /* Decide how much of that length to hash on */
1266 hash_len = len;
1267 if (warn_id_clash && len > id_clash_len)
1268 hash_len = id_clash_len;
1270 /* Compute hash code */
1271 hi = hash_len * 613 + (unsigned) text[0];
1272 for (i = 1; i < hash_len; i += 2)
1273 hi = ((hi * 613) + (unsigned) (text[i]));
1275 hi &= (1 << HASHBITS) - 1;
1276 hi %= MAX_HASH_TABLE;
1278 /* Search table for identifier */
1279 for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
1280 if (IDENTIFIER_LENGTH (idp) == len
1281 && IDENTIFIER_POINTER (idp)[0] == text[0]
1282 && !bcmp (IDENTIFIER_POINTER (idp), text, len))
1283 return idp; /* <-- return if found */
1285 /* Not found; optionally warn about a similar identifier */
1286 if (warn_id_clash && do_identifier_warnings && len >= id_clash_len)
1287 for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
1288 if (!strncmp (IDENTIFIER_POINTER (idp), text, id_clash_len))
1290 warning ("`%s' and `%s' identical in first %d characters",
1291 IDENTIFIER_POINTER (idp), text, id_clash_len);
1292 break;
1295 if (tree_code_length[(int) IDENTIFIER_NODE] < 0)
1296 abort (); /* set_identifier_size hasn't been called. */
1298 /* Not found, create one, add to chain */
1299 idp = make_node (IDENTIFIER_NODE);
1300 IDENTIFIER_LENGTH (idp) = len;
1301 #ifdef GATHER_STATISTICS
1302 id_string_size += len;
1303 #endif
1305 if (ggc_p)
1306 IDENTIFIER_POINTER (idp) = ggc_alloc_string (text, len);
1307 else
1308 IDENTIFIER_POINTER (idp) = obstack_copy0 (&permanent_obstack, text, len);
1310 TREE_CHAIN (idp) = hash_table[hi];
1311 hash_table[hi] = idp;
1312 return idp; /* <-- return if created */
1315 /* If an identifier with the name TEXT (a null-terminated string) has
1316 previously been referred to, return that node; otherwise return
1317 NULL_TREE. */
1319 tree
1320 maybe_get_identifier (text)
1321 register const char *text;
1323 register int hi;
1324 register int i;
1325 register tree idp;
1326 register int len, hash_len;
1328 /* Compute length of text in len. */
1329 len = strlen (text);
1331 /* Decide how much of that length to hash on */
1332 hash_len = len;
1333 if (warn_id_clash && len > id_clash_len)
1334 hash_len = id_clash_len;
1336 /* Compute hash code */
1337 hi = hash_len * 613 + (unsigned) text[0];
1338 for (i = 1; i < hash_len; i += 2)
1339 hi = ((hi * 613) + (unsigned) (text[i]));
1341 hi &= (1 << HASHBITS) - 1;
1342 hi %= MAX_HASH_TABLE;
1344 /* Search table for identifier */
1345 for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
1346 if (IDENTIFIER_LENGTH (idp) == len
1347 && IDENTIFIER_POINTER (idp)[0] == text[0]
1348 && !bcmp (IDENTIFIER_POINTER (idp), text, len))
1349 return idp; /* <-- return if found */
1351 return NULL_TREE;
1354 /* Enable warnings on similar identifiers (if requested).
1355 Done after the built-in identifiers are created. */
1357 void
1358 start_identifier_warnings ()
1360 do_identifier_warnings = 1;
1363 /* Record the size of an identifier node for the language in use.
1364 SIZE is the total size in bytes.
1365 This is called by the language-specific files. This must be
1366 called before allocating any identifiers. */
1368 void
1369 set_identifier_size (size)
1370 int size;
1372 tree_code_length[(int) IDENTIFIER_NODE]
1373 = (size - sizeof (struct tree_common)) / sizeof (tree);
1376 /* Return a newly constructed INTEGER_CST node whose constant value
1377 is specified by the two ints LOW and HI.
1378 The TREE_TYPE is set to `int'.
1380 This function should be used via the `build_int_2' macro. */
1382 tree
1383 build_int_2_wide (low, hi)
1384 HOST_WIDE_INT low, hi;
1386 register tree t = make_node (INTEGER_CST);
1388 TREE_INT_CST_LOW (t) = low;
1389 TREE_INT_CST_HIGH (t) = hi;
1390 TREE_TYPE (t) = integer_type_node;
1391 return t;
1394 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1396 tree
1397 build_real (type, d)
1398 tree type;
1399 REAL_VALUE_TYPE d;
1401 tree v;
1402 int overflow = 0;
1404 /* Check for valid float value for this type on this target machine;
1405 if not, can print error message and store a valid value in D. */
1406 #ifdef CHECK_FLOAT_VALUE
1407 CHECK_FLOAT_VALUE (TYPE_MODE (type), d, overflow);
1408 #endif
1410 v = make_node (REAL_CST);
1411 TREE_TYPE (v) = type;
1412 TREE_REAL_CST (v) = d;
1413 TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow;
1414 return v;
1417 /* Return a new REAL_CST node whose type is TYPE
1418 and whose value is the integer value of the INTEGER_CST node I. */
1420 #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
1422 REAL_VALUE_TYPE
1423 real_value_from_int_cst (type, i)
1424 tree type ATTRIBUTE_UNUSED, i;
1426 REAL_VALUE_TYPE d;
1428 #ifdef REAL_ARITHMETIC
1429 /* Clear all bits of the real value type so that we can later do
1430 bitwise comparisons to see if two values are the same. */
1431 bzero ((char *) &d, sizeof d);
1433 if (! TREE_UNSIGNED (TREE_TYPE (i)))
1434 REAL_VALUE_FROM_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i),
1435 TYPE_MODE (type));
1436 else
1437 REAL_VALUE_FROM_UNSIGNED_INT (d, TREE_INT_CST_LOW (i),
1438 TREE_INT_CST_HIGH (i), TYPE_MODE (type));
1439 #else /* not REAL_ARITHMETIC */
1440 /* Some 386 compilers mishandle unsigned int to float conversions,
1441 so introduce a temporary variable E to avoid those bugs. */
1442 if (TREE_INT_CST_HIGH (i) < 0 && ! TREE_UNSIGNED (TREE_TYPE (i)))
1444 REAL_VALUE_TYPE e;
1446 d = (double) (~ TREE_INT_CST_HIGH (i));
1447 e = ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
1448 * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
1449 d *= e;
1450 e = (double) (unsigned HOST_WIDE_INT) (~ TREE_INT_CST_LOW (i));
1451 d += e;
1452 d = (- d - 1.0);
1454 else
1456 REAL_VALUE_TYPE e;
1458 d = (double) (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (i);
1459 e = ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
1460 * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
1461 d *= e;
1462 e = (double) (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (i);
1463 d += e;
1465 #endif /* not REAL_ARITHMETIC */
1466 return d;
1469 /* Args to pass to and from build_real_from_int_cst_1. */
1471 struct brfic_args
1473 tree type; /* Input: type to conver to. */
1474 tree i; /* Input: operand to convert */
1475 REAL_VALUE_TYPE d; /* Output: floating point value. */
1478 /* Convert an integer to a floating point value while protected by a floating
1479 point exception handler. */
1481 static void
1482 build_real_from_int_cst_1 (data)
1483 PTR data;
1485 struct brfic_args *args = (struct brfic_args *) data;
1487 #ifdef REAL_ARITHMETIC
1488 args->d = real_value_from_int_cst (args->type, args->i);
1489 #else
1490 args->d
1491 = REAL_VALUE_TRUNCATE (TYPE_MODE (args->type),
1492 real_value_from_int_cst (args->type, args->i));
1493 #endif
1496 /* Given a tree representing an integer constant I, return a tree
1497 representing the same value as a floating-point constant of type TYPE.
1498 We cannot perform this operation if there is no way of doing arithmetic
1499 on floating-point values. */
1501 tree
1502 build_real_from_int_cst (type, i)
1503 tree type;
1504 tree i;
1506 tree v;
1507 int overflow = TREE_OVERFLOW (i);
1508 REAL_VALUE_TYPE d;
1509 struct brfic_args args;
1511 v = make_node (REAL_CST);
1512 TREE_TYPE (v) = type;
1514 /* Setup input for build_real_from_int_cst_1() */
1515 args.type = type;
1516 args.i = i;
1518 if (do_float_handler (build_real_from_int_cst_1, (PTR) &args))
1519 /* Receive output from build_real_from_int_cst_1() */
1520 d = args.d;
1521 else
1523 /* We got an exception from build_real_from_int_cst_1() */
1524 d = dconst0;
1525 overflow = 1;
1528 /* Check for valid float value for this type on this target machine. */
1530 #ifdef CHECK_FLOAT_VALUE
1531 CHECK_FLOAT_VALUE (TYPE_MODE (type), d, overflow);
1532 #endif
1534 TREE_REAL_CST (v) = d;
1535 TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow;
1536 return v;
1539 #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
1541 /* Return a newly constructed STRING_CST node whose value is
1542 the LEN characters at STR.
1543 The TREE_TYPE is not initialized. */
1545 tree
1546 build_string (len, str)
1547 int len;
1548 const char *str;
1550 /* Put the string in saveable_obstack since it will be placed in the RTL
1551 for an "asm" statement and will also be kept around a while if
1552 deferring constant output in varasm.c. */
1554 register tree s = make_node (STRING_CST);
1556 TREE_STRING_LENGTH (s) = len;
1557 if (ggc_p)
1558 TREE_STRING_POINTER (s) = ggc_alloc_string (str, len);
1559 else
1560 TREE_STRING_POINTER (s) = obstack_copy0 (saveable_obstack, str, len);
1562 return s;
1565 /* Return a newly constructed COMPLEX_CST node whose value is
1566 specified by the real and imaginary parts REAL and IMAG.
1567 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1568 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1570 tree
1571 build_complex (type, real, imag)
1572 tree type;
1573 tree real, imag;
1575 register tree t = make_node (COMPLEX_CST);
1577 TREE_REALPART (t) = real;
1578 TREE_IMAGPART (t) = imag;
1579 TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
1580 TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
1581 TREE_CONSTANT_OVERFLOW (t)
1582 = TREE_CONSTANT_OVERFLOW (real) | TREE_CONSTANT_OVERFLOW (imag);
1583 return t;
1586 /* Build a newly constructed TREE_VEC node of length LEN. */
1588 tree
1589 make_tree_vec (len)
1590 int len;
1592 register tree t;
1593 register int length = (len-1) * sizeof (tree) + sizeof (struct tree_vec);
1594 register struct obstack *obstack = current_obstack;
1596 #ifdef GATHER_STATISTICS
1597 tree_node_counts[(int)vec_kind]++;
1598 tree_node_sizes[(int)vec_kind] += length;
1599 #endif
1601 if (ggc_p)
1602 t = ggc_alloc_tree (length);
1603 else
1605 t = (tree) obstack_alloc (obstack, length);
1606 bzero ((PTR) t, length);
1609 TREE_SET_CODE (t, TREE_VEC);
1610 TREE_VEC_LENGTH (t) = len;
1611 if (obstack == &permanent_obstack)
1612 TREE_PERMANENT (t) = 1;
1614 return t;
1617 /* Return 1 if EXPR is the integer constant zero or a complex constant
1618 of zero. */
1621 integer_zerop (expr)
1622 tree expr;
1624 STRIP_NOPS (expr);
1626 return ((TREE_CODE (expr) == INTEGER_CST
1627 && ! TREE_CONSTANT_OVERFLOW (expr)
1628 && TREE_INT_CST_LOW (expr) == 0
1629 && TREE_INT_CST_HIGH (expr) == 0)
1630 || (TREE_CODE (expr) == COMPLEX_CST
1631 && integer_zerop (TREE_REALPART (expr))
1632 && integer_zerop (TREE_IMAGPART (expr))));
1635 /* Return 1 if EXPR is the integer constant one or the corresponding
1636 complex constant. */
1639 integer_onep (expr)
1640 tree expr;
1642 STRIP_NOPS (expr);
1644 return ((TREE_CODE (expr) == INTEGER_CST
1645 && ! TREE_CONSTANT_OVERFLOW (expr)
1646 && TREE_INT_CST_LOW (expr) == 1
1647 && TREE_INT_CST_HIGH (expr) == 0)
1648 || (TREE_CODE (expr) == COMPLEX_CST
1649 && integer_onep (TREE_REALPART (expr))
1650 && integer_zerop (TREE_IMAGPART (expr))));
1653 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
1654 it contains. Likewise for the corresponding complex constant. */
1657 integer_all_onesp (expr)
1658 tree expr;
1660 register int prec;
1661 register int uns;
1663 STRIP_NOPS (expr);
1665 if (TREE_CODE (expr) == COMPLEX_CST
1666 && integer_all_onesp (TREE_REALPART (expr))
1667 && integer_zerop (TREE_IMAGPART (expr)))
1668 return 1;
1670 else if (TREE_CODE (expr) != INTEGER_CST
1671 || TREE_CONSTANT_OVERFLOW (expr))
1672 return 0;
1674 uns = TREE_UNSIGNED (TREE_TYPE (expr));
1675 if (!uns)
1676 return TREE_INT_CST_LOW (expr) == -1 && TREE_INT_CST_HIGH (expr) == -1;
1678 /* Note that using TYPE_PRECISION here is wrong. We care about the
1679 actual bits, not the (arbitrary) range of the type. */
1680 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr)));
1681 if (prec >= HOST_BITS_PER_WIDE_INT)
1683 int high_value, shift_amount;
1685 shift_amount = prec - HOST_BITS_PER_WIDE_INT;
1687 if (shift_amount > HOST_BITS_PER_WIDE_INT)
1688 /* Can not handle precisions greater than twice the host int size. */
1689 abort ();
1690 else if (shift_amount == HOST_BITS_PER_WIDE_INT)
1691 /* Shifting by the host word size is undefined according to the ANSI
1692 standard, so we must handle this as a special case. */
1693 high_value = -1;
1694 else
1695 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
1697 return TREE_INT_CST_LOW (expr) == -1
1698 && TREE_INT_CST_HIGH (expr) == high_value;
1700 else
1701 return TREE_INT_CST_LOW (expr) == ((HOST_WIDE_INT) 1 << prec) - 1;
1704 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1705 one bit on). */
1708 integer_pow2p (expr)
1709 tree expr;
1711 int prec;
1712 HOST_WIDE_INT high, low;
1714 STRIP_NOPS (expr);
1716 if (TREE_CODE (expr) == COMPLEX_CST
1717 && integer_pow2p (TREE_REALPART (expr))
1718 && integer_zerop (TREE_IMAGPART (expr)))
1719 return 1;
1721 if (TREE_CODE (expr) != INTEGER_CST || TREE_CONSTANT_OVERFLOW (expr))
1722 return 0;
1724 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1725 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1726 high = TREE_INT_CST_HIGH (expr);
1727 low = TREE_INT_CST_LOW (expr);
1729 /* First clear all bits that are beyond the type's precision in case
1730 we've been sign extended. */
1732 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1734 else if (prec > HOST_BITS_PER_WIDE_INT)
1735 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1736 else
1738 high = 0;
1739 if (prec < HOST_BITS_PER_WIDE_INT)
1740 low &= ~((HOST_WIDE_INT) (-1) << prec);
1743 if (high == 0 && low == 0)
1744 return 0;
1746 return ((high == 0 && (low & (low - 1)) == 0)
1747 || (low == 0 && (high & (high - 1)) == 0));
1750 /* Return the power of two represented by a tree node known to be a
1751 power of two. */
1754 tree_log2 (expr)
1755 tree expr;
1757 int prec;
1758 HOST_WIDE_INT high, low;
1760 STRIP_NOPS (expr);
1762 if (TREE_CODE (expr) == COMPLEX_CST)
1763 return tree_log2 (TREE_REALPART (expr));
1765 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1766 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1768 high = TREE_INT_CST_HIGH (expr);
1769 low = TREE_INT_CST_LOW (expr);
1771 /* First clear all bits that are beyond the type's precision in case
1772 we've been sign extended. */
1774 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1776 else if (prec > HOST_BITS_PER_WIDE_INT)
1777 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1778 else
1780 high = 0;
1781 if (prec < HOST_BITS_PER_WIDE_INT)
1782 low &= ~((HOST_WIDE_INT) (-1) << prec);
1785 return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high)
1786 : exact_log2 (low));
1789 /* Return 1 if EXPR is the real constant zero. */
1792 real_zerop (expr)
1793 tree expr;
1795 STRIP_NOPS (expr);
1797 return ((TREE_CODE (expr) == REAL_CST
1798 && ! TREE_CONSTANT_OVERFLOW (expr)
1799 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0))
1800 || (TREE_CODE (expr) == COMPLEX_CST
1801 && real_zerop (TREE_REALPART (expr))
1802 && real_zerop (TREE_IMAGPART (expr))));
1805 /* Return 1 if EXPR is the real constant one in real or complex form. */
1808 real_onep (expr)
1809 tree expr;
1811 STRIP_NOPS (expr);
1813 return ((TREE_CODE (expr) == REAL_CST
1814 && ! TREE_CONSTANT_OVERFLOW (expr)
1815 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1))
1816 || (TREE_CODE (expr) == COMPLEX_CST
1817 && real_onep (TREE_REALPART (expr))
1818 && real_zerop (TREE_IMAGPART (expr))));
1821 /* Return 1 if EXPR is the real constant two. */
1824 real_twop (expr)
1825 tree expr;
1827 STRIP_NOPS (expr);
1829 return ((TREE_CODE (expr) == REAL_CST
1830 && ! TREE_CONSTANT_OVERFLOW (expr)
1831 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2))
1832 || (TREE_CODE (expr) == COMPLEX_CST
1833 && real_twop (TREE_REALPART (expr))
1834 && real_zerop (TREE_IMAGPART (expr))));
1837 /* Nonzero if EXP is a constant or a cast of a constant. */
1840 really_constant_p (exp)
1841 tree exp;
1843 /* This is not quite the same as STRIP_NOPS. It does more. */
1844 while (TREE_CODE (exp) == NOP_EXPR
1845 || TREE_CODE (exp) == CONVERT_EXPR
1846 || TREE_CODE (exp) == NON_LVALUE_EXPR)
1847 exp = TREE_OPERAND (exp, 0);
1848 return TREE_CONSTANT (exp);
1851 /* Return first list element whose TREE_VALUE is ELEM.
1852 Return 0 if ELEM is not in LIST. */
1854 tree
1855 value_member (elem, list)
1856 tree elem, list;
1858 while (list)
1860 if (elem == TREE_VALUE (list))
1861 return list;
1862 list = TREE_CHAIN (list);
1864 return NULL_TREE;
1867 /* Return first list element whose TREE_PURPOSE is ELEM.
1868 Return 0 if ELEM is not in LIST. */
1870 tree
1871 purpose_member (elem, list)
1872 tree elem, list;
1874 while (list)
1876 if (elem == TREE_PURPOSE (list))
1877 return list;
1878 list = TREE_CHAIN (list);
1880 return NULL_TREE;
1883 /* Return first list element whose BINFO_TYPE is ELEM.
1884 Return 0 if ELEM is not in LIST. */
1886 tree
1887 binfo_member (elem, list)
1888 tree elem, list;
1890 while (list)
1892 if (elem == BINFO_TYPE (list))
1893 return list;
1894 list = TREE_CHAIN (list);
1896 return NULL_TREE;
1899 /* Return nonzero if ELEM is part of the chain CHAIN. */
1902 chain_member (elem, chain)
1903 tree elem, chain;
1905 while (chain)
1907 if (elem == chain)
1908 return 1;
1909 chain = TREE_CHAIN (chain);
1912 return 0;
1915 /* Return nonzero if ELEM is equal to TREE_VALUE (CHAIN) for any piece of
1916 chain CHAIN. This and the next function are currently unused, but
1917 are retained for completeness. */
1920 chain_member_value (elem, chain)
1921 tree elem, chain;
1923 while (chain)
1925 if (elem == TREE_VALUE (chain))
1926 return 1;
1927 chain = TREE_CHAIN (chain);
1930 return 0;
1933 /* Return nonzero if ELEM is equal to TREE_PURPOSE (CHAIN)
1934 for any piece of chain CHAIN. */
1937 chain_member_purpose (elem, chain)
1938 tree elem, chain;
1940 while (chain)
1942 if (elem == TREE_PURPOSE (chain))
1943 return 1;
1944 chain = TREE_CHAIN (chain);
1947 return 0;
1950 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1951 We expect a null pointer to mark the end of the chain.
1952 This is the Lisp primitive `length'. */
1955 list_length (t)
1956 tree t;
1958 register tree tail;
1959 register int len = 0;
1961 for (tail = t; tail; tail = TREE_CHAIN (tail))
1962 len++;
1964 return len;
1967 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1968 by modifying the last node in chain 1 to point to chain 2.
1969 This is the Lisp primitive `nconc'. */
1971 tree
1972 chainon (op1, op2)
1973 tree op1, op2;
1976 if (op1)
1978 register tree t1;
1979 #ifdef ENABLE_TREE_CHECKING
1980 register tree t2;
1981 #endif
1983 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
1985 TREE_CHAIN (t1) = op2;
1986 #ifdef ENABLE_TREE_CHECKING
1987 for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
1988 if (t2 == t1)
1989 abort (); /* Circularity created. */
1990 #endif
1991 return op1;
1993 else return op2;
1996 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1998 tree
1999 tree_last (chain)
2000 register tree chain;
2002 register tree next;
2003 if (chain)
2004 while ((next = TREE_CHAIN (chain)))
2005 chain = next;
2006 return chain;
2009 /* Reverse the order of elements in the chain T,
2010 and return the new head of the chain (old last element). */
2012 tree
2013 nreverse (t)
2014 tree t;
2016 register tree prev = 0, decl, next;
2017 for (decl = t; decl; decl = next)
2019 next = TREE_CHAIN (decl);
2020 TREE_CHAIN (decl) = prev;
2021 prev = decl;
2023 return prev;
2026 /* Given a chain CHAIN of tree nodes,
2027 construct and return a list of those nodes. */
2029 tree
2030 listify (chain)
2031 tree chain;
2033 tree result = NULL_TREE;
2034 tree in_tail = chain;
2035 tree out_tail = NULL_TREE;
2037 while (in_tail)
2039 tree next = tree_cons (NULL_TREE, in_tail, NULL_TREE);
2040 if (out_tail)
2041 TREE_CHAIN (out_tail) = next;
2042 else
2043 result = next;
2044 out_tail = next;
2045 in_tail = TREE_CHAIN (in_tail);
2048 return result;
2051 /* Return a newly created TREE_LIST node whose
2052 purpose and value fields are PARM and VALUE. */
2054 tree
2055 build_tree_list (parm, value)
2056 tree parm, value;
2058 register tree t = make_node (TREE_LIST);
2059 TREE_PURPOSE (t) = parm;
2060 TREE_VALUE (t) = value;
2061 return t;
2064 /* Similar, but build on the temp_decl_obstack. */
2066 tree
2067 build_decl_list (parm, value)
2068 tree parm, value;
2070 register tree node;
2071 register struct obstack *ambient_obstack = current_obstack;
2073 current_obstack = &temp_decl_obstack;
2074 node = build_tree_list (parm, value);
2075 current_obstack = ambient_obstack;
2076 return node;
2079 /* Similar, but build on the expression_obstack. */
2081 tree
2082 build_expr_list (parm, value)
2083 tree parm, value;
2085 register tree node;
2086 register struct obstack *ambient_obstack = current_obstack;
2088 current_obstack = expression_obstack;
2089 node = build_tree_list (parm, value);
2090 current_obstack = ambient_obstack;
2091 return node;
2094 /* Return a newly created TREE_LIST node whose
2095 purpose and value fields are PARM and VALUE
2096 and whose TREE_CHAIN is CHAIN. */
2098 tree
2099 tree_cons (purpose, value, chain)
2100 tree purpose, value, chain;
2102 register tree node;
2104 if (ggc_p)
2105 node = ggc_alloc_tree (sizeof (struct tree_list));
2106 else
2108 node = (tree) obstack_alloc (current_obstack, sizeof (struct tree_list));
2109 memset (node, 0, sizeof (struct tree_common));
2112 #ifdef GATHER_STATISTICS
2113 tree_node_counts[(int)x_kind]++;
2114 tree_node_sizes[(int)x_kind] += sizeof (struct tree_list);
2115 #endif
2118 TREE_SET_CODE (node, TREE_LIST);
2119 if (current_obstack == &permanent_obstack)
2120 TREE_PERMANENT (node) = 1;
2122 TREE_CHAIN (node) = chain;
2123 TREE_PURPOSE (node) = purpose;
2124 TREE_VALUE (node) = value;
2125 return node;
2128 /* Similar, but build on the temp_decl_obstack. */
2130 tree
2131 decl_tree_cons (purpose, value, chain)
2132 tree purpose, value, chain;
2134 register tree node;
2135 register struct obstack *ambient_obstack = current_obstack;
2137 current_obstack = &temp_decl_obstack;
2138 node = tree_cons (purpose, value, chain);
2139 current_obstack = ambient_obstack;
2140 return node;
2143 /* Similar, but build on the expression_obstack. */
2145 tree
2146 expr_tree_cons (purpose, value, chain)
2147 tree purpose, value, chain;
2149 register tree node;
2150 register struct obstack *ambient_obstack = current_obstack;
2152 current_obstack = expression_obstack;
2153 node = tree_cons (purpose, value, chain);
2154 current_obstack = ambient_obstack;
2155 return node;
2158 /* Same as `tree_cons' but make a permanent object. */
2160 tree
2161 perm_tree_cons (purpose, value, chain)
2162 tree purpose, value, chain;
2164 register tree node;
2165 register struct obstack *ambient_obstack = current_obstack;
2167 current_obstack = &permanent_obstack;
2168 node = tree_cons (purpose, value, chain);
2169 current_obstack = ambient_obstack;
2170 return node;
2173 /* Same as `tree_cons', but make this node temporary, regardless. */
2175 tree
2176 temp_tree_cons (purpose, value, chain)
2177 tree purpose, value, chain;
2179 register tree node;
2180 register struct obstack *ambient_obstack = current_obstack;
2182 current_obstack = &temporary_obstack;
2183 node = tree_cons (purpose, value, chain);
2184 current_obstack = ambient_obstack;
2185 return node;
2188 /* Same as `tree_cons', but save this node if the function's RTL is saved. */
2190 tree
2191 saveable_tree_cons (purpose, value, chain)
2192 tree purpose, value, chain;
2194 register tree node;
2195 register struct obstack *ambient_obstack = current_obstack;
2197 current_obstack = saveable_obstack;
2198 node = tree_cons (purpose, value, chain);
2199 current_obstack = ambient_obstack;
2200 return node;
2203 /* Return the size nominally occupied by an object of type TYPE
2204 when it resides in memory. The value is measured in units of bytes,
2205 and its data type is that normally used for type sizes
2206 (which is the first type created by make_signed_type or
2207 make_unsigned_type). */
2209 tree
2210 size_in_bytes (type)
2211 tree type;
2213 tree t;
2215 if (type == error_mark_node)
2216 return integer_zero_node;
2218 type = TYPE_MAIN_VARIANT (type);
2219 t = TYPE_SIZE_UNIT (type);
2221 if (t == 0)
2223 incomplete_type_error (NULL_TREE, type);
2224 return integer_zero_node;
2227 if (TREE_CODE (t) == INTEGER_CST)
2228 force_fit_type (t, 0);
2230 return t;
2233 /* Return the size of TYPE (in bytes) as a wide integer
2234 or return -1 if the size can vary or is larger than an integer. */
2236 HOST_WIDE_INT
2237 int_size_in_bytes (type)
2238 tree type;
2240 tree t;
2242 if (type == error_mark_node)
2243 return 0;
2245 type = TYPE_MAIN_VARIANT (type);
2246 t = TYPE_SIZE_UNIT (type);
2247 if (t == 0
2248 || TREE_CODE (t) != INTEGER_CST
2249 || TREE_OVERFLOW (t)
2250 || TREE_INT_CST_HIGH (t) != 0)
2251 return -1;
2253 return TREE_INT_CST_LOW (t);
2256 /* Return the strictest alignment, in bits, that T is known to have. */
2258 unsigned int
2259 expr_align (t)
2260 tree t;
2262 unsigned int align0, align1;
2264 switch (TREE_CODE (t))
2266 case NOP_EXPR: case CONVERT_EXPR: case NON_LVALUE_EXPR:
2267 /* If we have conversions, we know that the alignment of the
2268 object must meet each of the alignments of the types. */
2269 align0 = expr_align (TREE_OPERAND (t, 0));
2270 align1 = TYPE_ALIGN (TREE_TYPE (t));
2271 return MAX (align0, align1);
2273 case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR:
2274 case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR:
2275 case WITH_RECORD_EXPR: case CLEANUP_POINT_EXPR: case UNSAVE_EXPR:
2276 /* These don't change the alignment of an object. */
2277 return expr_align (TREE_OPERAND (t, 0));
2279 case COND_EXPR:
2280 /* The best we can do is say that the alignment is the least aligned
2281 of the two arms. */
2282 align0 = expr_align (TREE_OPERAND (t, 1));
2283 align1 = expr_align (TREE_OPERAND (t, 2));
2284 return MIN (align0, align1);
2286 case LABEL_DECL: case CONST_DECL:
2287 case VAR_DECL: case PARM_DECL: case RESULT_DECL:
2288 if (DECL_ALIGN (t) != 0)
2289 return DECL_ALIGN (t);
2290 break;
2292 case FUNCTION_DECL:
2293 return FUNCTION_BOUNDARY;
2295 default:
2296 break;
2299 /* Otherwise take the alignment from that of the type. */
2300 return TYPE_ALIGN (TREE_TYPE (t));
2303 /* Return, as a tree node, the number of elements for TYPE (which is an
2304 ARRAY_TYPE) minus one. This counts only elements of the top array. */
2306 tree
2307 array_type_nelts (type)
2308 tree type;
2310 tree index_type, min, max;
2312 /* If they did it with unspecified bounds, then we should have already
2313 given an error about it before we got here. */
2314 if (! TYPE_DOMAIN (type))
2315 return error_mark_node;
2317 index_type = TYPE_DOMAIN (type);
2318 min = TYPE_MIN_VALUE (index_type);
2319 max = TYPE_MAX_VALUE (index_type);
2321 return (integer_zerop (min)
2322 ? max
2323 : fold (build (MINUS_EXPR, TREE_TYPE (max), max, min)));
2326 /* Return nonzero if arg is static -- a reference to an object in
2327 static storage. This is not the same as the C meaning of `static'. */
2330 staticp (arg)
2331 tree arg;
2333 switch (TREE_CODE (arg))
2335 case FUNCTION_DECL:
2336 /* Nested functions aren't static, since taking their address
2337 involves a trampoline. */
2338 return (decl_function_context (arg) == 0 || DECL_NO_STATIC_CHAIN (arg))
2339 && ! DECL_NON_ADDR_CONST_P (arg);
2341 case VAR_DECL:
2342 return (TREE_STATIC (arg) || DECL_EXTERNAL (arg))
2343 && ! DECL_NON_ADDR_CONST_P (arg);
2345 case CONSTRUCTOR:
2346 return TREE_STATIC (arg);
2348 case STRING_CST:
2349 return 1;
2351 /* If we are referencing a bitfield, we can't evaluate an
2352 ADDR_EXPR at compile time and so it isn't a constant. */
2353 case COMPONENT_REF:
2354 return (! DECL_BIT_FIELD (TREE_OPERAND (arg, 1))
2355 && staticp (TREE_OPERAND (arg, 0)));
2357 case BIT_FIELD_REF:
2358 return 0;
2360 #if 0
2361 /* This case is technically correct, but results in setting
2362 TREE_CONSTANT on ADDR_EXPRs that cannot be evaluated at
2363 compile time. */
2364 case INDIRECT_REF:
2365 return TREE_CONSTANT (TREE_OPERAND (arg, 0));
2366 #endif
2368 case ARRAY_REF:
2369 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
2370 && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
2371 return staticp (TREE_OPERAND (arg, 0));
2373 default:
2374 return 0;
2378 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
2379 Do this to any expression which may be used in more than one place,
2380 but must be evaluated only once.
2382 Normally, expand_expr would reevaluate the expression each time.
2383 Calling save_expr produces something that is evaluated and recorded
2384 the first time expand_expr is called on it. Subsequent calls to
2385 expand_expr just reuse the recorded value.
2387 The call to expand_expr that generates code that actually computes
2388 the value is the first call *at compile time*. Subsequent calls
2389 *at compile time* generate code to use the saved value.
2390 This produces correct result provided that *at run time* control
2391 always flows through the insns made by the first expand_expr
2392 before reaching the other places where the save_expr was evaluated.
2393 You, the caller of save_expr, must make sure this is so.
2395 Constants, and certain read-only nodes, are returned with no
2396 SAVE_EXPR because that is safe. Expressions containing placeholders
2397 are not touched; see tree.def for an explanation of what these
2398 are used for. */
2400 tree
2401 save_expr (expr)
2402 tree expr;
2404 register tree t = fold (expr);
2406 /* We don't care about whether this can be used as an lvalue in this
2407 context. */
2408 while (TREE_CODE (t) == NON_LVALUE_EXPR)
2409 t = TREE_OPERAND (t, 0);
2411 /* If the tree evaluates to a constant, then we don't want to hide that
2412 fact (i.e. this allows further folding, and direct checks for constants).
2413 However, a read-only object that has side effects cannot be bypassed.
2414 Since it is no problem to reevaluate literals, we just return the
2415 literal node. */
2417 if (TREE_CONSTANT (t) || (TREE_READONLY (t) && ! TREE_SIDE_EFFECTS (t))
2418 || TREE_CODE (t) == SAVE_EXPR || TREE_CODE (t) == ERROR_MARK)
2419 return t;
2421 /* If T contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
2422 it means that the size or offset of some field of an object depends on
2423 the value within another field.
2425 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
2426 and some variable since it would then need to be both evaluated once and
2427 evaluated more than once. Front-ends must assure this case cannot
2428 happen by surrounding any such subexpressions in their own SAVE_EXPR
2429 and forcing evaluation at the proper time. */
2430 if (contains_placeholder_p (t))
2431 return t;
2433 t = build (SAVE_EXPR, TREE_TYPE (expr), t, current_function_decl, NULL_TREE);
2435 /* This expression might be placed ahead of a jump to ensure that the
2436 value was computed on both sides of the jump. So make sure it isn't
2437 eliminated as dead. */
2438 TREE_SIDE_EFFECTS (t) = 1;
2439 return t;
2442 /* Arrange for an expression to be expanded multiple independent
2443 times. This is useful for cleanup actions, as the backend can
2444 expand them multiple times in different places. */
2446 tree
2447 unsave_expr (expr)
2448 tree expr;
2450 tree t;
2452 /* If this is already protected, no sense in protecting it again. */
2453 if (TREE_CODE (expr) == UNSAVE_EXPR)
2454 return expr;
2456 t = build1 (UNSAVE_EXPR, TREE_TYPE (expr), expr);
2457 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (expr);
2458 return t;
2461 /* Returns the index of the first non-tree operand for CODE, or the number
2462 of operands if all are trees. */
2465 first_rtl_op (code)
2466 enum tree_code code;
2468 switch (code)
2470 case SAVE_EXPR:
2471 return 2;
2472 case GOTO_SUBROUTINE_EXPR:
2473 case RTL_EXPR:
2474 return 0;
2475 case CALL_EXPR:
2476 return 2;
2477 case WITH_CLEANUP_EXPR:
2478 /* Should be defined to be 2. */
2479 return 1;
2480 case METHOD_CALL_EXPR:
2481 return 3;
2482 default:
2483 return tree_code_length [(int) code];
2487 /* Perform any modifications to EXPR required when it is unsaved. Does
2488 not recurse into EXPR's subtrees. */
2490 void
2491 unsave_expr_1 (expr)
2492 tree expr;
2494 switch (TREE_CODE (expr))
2496 case SAVE_EXPR:
2497 if (! SAVE_EXPR_PERSISTENT_P (expr))
2498 SAVE_EXPR_RTL (expr) = 0;
2499 break;
2501 case TARGET_EXPR:
2502 TREE_OPERAND (expr, 1) = TREE_OPERAND (expr, 3);
2503 TREE_OPERAND (expr, 3) = NULL_TREE;
2504 break;
2506 case RTL_EXPR:
2507 /* I don't yet know how to emit a sequence multiple times. */
2508 if (RTL_EXPR_SEQUENCE (expr) != 0)
2509 abort ();
2510 break;
2512 case CALL_EXPR:
2513 CALL_EXPR_RTL (expr) = 0;
2514 break;
2516 default:
2517 if (lang_unsave_expr_now != 0)
2518 (*lang_unsave_expr_now) (expr);
2519 break;
2523 /* Helper function for unsave_expr_now. */
2525 static void
2526 unsave_expr_now_r (expr)
2527 tree expr;
2529 enum tree_code code;
2531 /* There's nothing to do for NULL_TREE. */
2532 if (expr == 0)
2533 return;
2535 unsave_expr_1 (expr);
2537 code = TREE_CODE (expr);
2538 if (code == CALL_EXPR
2539 && TREE_OPERAND (expr, 1)
2540 && TREE_CODE (TREE_OPERAND (expr, 1)) == TREE_LIST)
2542 tree exp = TREE_OPERAND (expr, 1);
2543 while (exp)
2545 unsave_expr_now_r (TREE_VALUE (exp));
2546 exp = TREE_CHAIN (exp);
2550 switch (TREE_CODE_CLASS (code))
2552 case 'c': /* a constant */
2553 case 't': /* a type node */
2554 case 'x': /* something random, like an identifier or an ERROR_MARK. */
2555 case 'd': /* A decl node */
2556 case 'b': /* A block node */
2557 break;
2559 case 'e': /* an expression */
2560 case 'r': /* a reference */
2561 case 's': /* an expression with side effects */
2562 case '<': /* a comparison expression */
2563 case '2': /* a binary arithmetic expression */
2564 case '1': /* a unary arithmetic expression */
2566 int i;
2568 for (i = first_rtl_op (code) - 1; i >= 0; i--)
2569 unsave_expr_now_r (TREE_OPERAND (expr, i));
2571 break;
2573 default:
2574 abort ();
2578 /* Modify a tree in place so that all the evaluate only once things
2579 are cleared out. Return the EXPR given. */
2581 tree
2582 unsave_expr_now (expr)
2583 tree expr;
2585 if (lang_unsave!= 0)
2586 (*lang_unsave) (&expr);
2587 else
2588 unsave_expr_now_r (expr);
2590 return expr;
2593 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
2594 or offset that depends on a field within a record. */
2597 contains_placeholder_p (exp)
2598 tree exp;
2600 register enum tree_code code = TREE_CODE (exp);
2601 int result;
2603 /* If we have a WITH_RECORD_EXPR, it "cancels" any PLACEHOLDER_EXPR
2604 in it since it is supplying a value for it. */
2605 if (code == WITH_RECORD_EXPR)
2606 return 0;
2607 else if (code == PLACEHOLDER_EXPR)
2608 return 1;
2610 switch (TREE_CODE_CLASS (code))
2612 case 'r':
2613 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
2614 position computations since they will be converted into a
2615 WITH_RECORD_EXPR involving the reference, which will assume
2616 here will be valid. */
2617 return contains_placeholder_p (TREE_OPERAND (exp, 0));
2619 case 'x':
2620 if (code == TREE_LIST)
2621 return (contains_placeholder_p (TREE_VALUE (exp))
2622 || (TREE_CHAIN (exp) != 0
2623 && contains_placeholder_p (TREE_CHAIN (exp))));
2624 break;
2626 case '1':
2627 case '2': case '<':
2628 case 'e':
2629 switch (code)
2631 case COMPOUND_EXPR:
2632 /* Ignoring the first operand isn't quite right, but works best. */
2633 return contains_placeholder_p (TREE_OPERAND (exp, 1));
2635 case RTL_EXPR:
2636 case CONSTRUCTOR:
2637 return 0;
2639 case COND_EXPR:
2640 return (contains_placeholder_p (TREE_OPERAND (exp, 0))
2641 || contains_placeholder_p (TREE_OPERAND (exp, 1))
2642 || contains_placeholder_p (TREE_OPERAND (exp, 2)));
2644 case SAVE_EXPR:
2645 /* If we already know this doesn't have a placeholder, don't
2646 check again. */
2647 if (SAVE_EXPR_NOPLACEHOLDER (exp) || SAVE_EXPR_RTL (exp) != 0)
2648 return 0;
2650 SAVE_EXPR_NOPLACEHOLDER (exp) = 1;
2651 result = contains_placeholder_p (TREE_OPERAND (exp, 0));
2652 if (result)
2653 SAVE_EXPR_NOPLACEHOLDER (exp) = 0;
2655 return result;
2657 case CALL_EXPR:
2658 return (TREE_OPERAND (exp, 1) != 0
2659 && contains_placeholder_p (TREE_OPERAND (exp, 1)));
2661 default:
2662 break;
2665 switch (tree_code_length[(int) code])
2667 case 1:
2668 return contains_placeholder_p (TREE_OPERAND (exp, 0));
2669 case 2:
2670 return (contains_placeholder_p (TREE_OPERAND (exp, 0))
2671 || contains_placeholder_p (TREE_OPERAND (exp, 1)));
2672 default:
2673 return 0;
2676 default:
2677 return 0;
2679 return 0;
2682 /* Return 1 if EXP contains any expressions that produce cleanups for an
2683 outer scope to deal with. Used by fold. */
2686 has_cleanups (exp)
2687 tree exp;
2689 int i, nops, cmp;
2691 if (! TREE_SIDE_EFFECTS (exp))
2692 return 0;
2694 switch (TREE_CODE (exp))
2696 case TARGET_EXPR:
2697 case GOTO_SUBROUTINE_EXPR:
2698 case WITH_CLEANUP_EXPR:
2699 return 1;
2701 case CLEANUP_POINT_EXPR:
2702 return 0;
2704 case CALL_EXPR:
2705 for (exp = TREE_OPERAND (exp, 1); exp; exp = TREE_CHAIN (exp))
2707 cmp = has_cleanups (TREE_VALUE (exp));
2708 if (cmp)
2709 return cmp;
2711 return 0;
2713 default:
2714 break;
2717 /* This general rule works for most tree codes. All exceptions should be
2718 handled above. If this is a language-specific tree code, we can't
2719 trust what might be in the operand, so say we don't know
2720 the situation. */
2721 if ((int) TREE_CODE (exp) >= (int) LAST_AND_UNUSED_TREE_CODE)
2722 return -1;
2724 nops = first_rtl_op (TREE_CODE (exp));
2725 for (i = 0; i < nops; i++)
2726 if (TREE_OPERAND (exp, i) != 0)
2728 int type = TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, i)));
2729 if (type == 'e' || type == '<' || type == '1' || type == '2'
2730 || type == 'r' || type == 's')
2732 cmp = has_cleanups (TREE_OPERAND (exp, i));
2733 if (cmp)
2734 return cmp;
2738 return 0;
2741 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
2742 return a tree with all occurrences of references to F in a
2743 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP
2744 contains only arithmetic expressions or a CALL_EXPR with a
2745 PLACEHOLDER_EXPR occurring only in its arglist. */
2747 tree
2748 substitute_in_expr (exp, f, r)
2749 tree exp;
2750 tree f;
2751 tree r;
2753 enum tree_code code = TREE_CODE (exp);
2754 tree op0, op1, op2;
2755 tree new;
2756 tree inner;
2758 switch (TREE_CODE_CLASS (code))
2760 case 'c':
2761 case 'd':
2762 return exp;
2764 case 'x':
2765 if (code == PLACEHOLDER_EXPR)
2766 return exp;
2767 else if (code == TREE_LIST)
2769 op0 = (TREE_CHAIN (exp) == 0
2770 ? 0 : substitute_in_expr (TREE_CHAIN (exp), f, r));
2771 op1 = substitute_in_expr (TREE_VALUE (exp), f, r);
2772 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
2773 return exp;
2775 return tree_cons (TREE_PURPOSE (exp), op1, op0);
2778 abort ();
2780 case '1':
2781 case '2':
2782 case '<':
2783 case 'e':
2784 switch (tree_code_length[(int) code])
2786 case 1:
2787 op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2788 if (op0 == TREE_OPERAND (exp, 0))
2789 return exp;
2791 new = fold (build1 (code, TREE_TYPE (exp), op0));
2792 break;
2794 case 2:
2795 /* An RTL_EXPR cannot contain a PLACEHOLDER_EXPR; a CONSTRUCTOR
2796 could, but we don't support it. */
2797 if (code == RTL_EXPR)
2798 return exp;
2799 else if (code == CONSTRUCTOR)
2800 abort ();
2802 op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2803 op1 = substitute_in_expr (TREE_OPERAND (exp, 1), f, r);
2804 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
2805 return exp;
2807 new = fold (build (code, TREE_TYPE (exp), op0, op1));
2808 break;
2810 case 3:
2811 /* It cannot be that anything inside a SAVE_EXPR contains a
2812 PLACEHOLDER_EXPR. */
2813 if (code == SAVE_EXPR)
2814 return exp;
2816 else if (code == CALL_EXPR)
2818 op1 = substitute_in_expr (TREE_OPERAND (exp, 1), f, r);
2819 if (op1 == TREE_OPERAND (exp, 1))
2820 return exp;
2822 return build (code, TREE_TYPE (exp),
2823 TREE_OPERAND (exp, 0), op1, NULL_TREE);
2826 else if (code != COND_EXPR)
2827 abort ();
2829 op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2830 op1 = substitute_in_expr (TREE_OPERAND (exp, 1), f, r);
2831 op2 = substitute_in_expr (TREE_OPERAND (exp, 2), f, r);
2832 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2833 && op2 == TREE_OPERAND (exp, 2))
2834 return exp;
2836 new = fold (build (code, TREE_TYPE (exp), op0, op1, op2));
2837 break;
2839 default:
2840 abort ();
2843 break;
2845 case 'r':
2846 switch (code)
2848 case COMPONENT_REF:
2849 /* If this expression is getting a value from a PLACEHOLDER_EXPR
2850 and it is the right field, replace it with R. */
2851 for (inner = TREE_OPERAND (exp, 0);
2852 TREE_CODE_CLASS (TREE_CODE (inner)) == 'r';
2853 inner = TREE_OPERAND (inner, 0))
2855 if (TREE_CODE (inner) == PLACEHOLDER_EXPR
2856 && TREE_OPERAND (exp, 1) == f)
2857 return r;
2859 /* If this expression hasn't been completed let, leave it
2860 alone. */
2861 if (TREE_CODE (inner) == PLACEHOLDER_EXPR
2862 && TREE_TYPE (inner) == 0)
2863 return exp;
2865 op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2866 if (op0 == TREE_OPERAND (exp, 0))
2867 return exp;
2869 new = fold (build (code, TREE_TYPE (exp), op0,
2870 TREE_OPERAND (exp, 1)));
2871 break;
2873 case BIT_FIELD_REF:
2874 op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2875 op1 = substitute_in_expr (TREE_OPERAND (exp, 1), f, r);
2876 op2 = substitute_in_expr (TREE_OPERAND (exp, 2), f, r);
2877 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2878 && op2 == TREE_OPERAND (exp, 2))
2879 return exp;
2881 new = fold (build (code, TREE_TYPE (exp), op0, op1, op2));
2882 break;
2884 case INDIRECT_REF:
2885 case BUFFER_REF:
2886 op0 = substitute_in_expr (TREE_OPERAND (exp, 0), f, r);
2887 if (op0 == TREE_OPERAND (exp, 0))
2888 return exp;
2890 new = fold (build1 (code, TREE_TYPE (exp), op0));
2891 break;
2893 default:
2894 abort ();
2896 break;
2898 default:
2899 abort ();
2902 TREE_READONLY (new) = TREE_READONLY (exp);
2903 return new;
2906 /* Stabilize a reference so that we can use it any number of times
2907 without causing its operands to be evaluated more than once.
2908 Returns the stabilized reference. This works by means of save_expr,
2909 so see the caveats in the comments about save_expr.
2911 Also allows conversion expressions whose operands are references.
2912 Any other kind of expression is returned unchanged. */
2914 tree
2915 stabilize_reference (ref)
2916 tree ref;
2918 register tree result;
2919 register enum tree_code code = TREE_CODE (ref);
2921 switch (code)
2923 case VAR_DECL:
2924 case PARM_DECL:
2925 case RESULT_DECL:
2926 /* No action is needed in this case. */
2927 return ref;
2929 case NOP_EXPR:
2930 case CONVERT_EXPR:
2931 case FLOAT_EXPR:
2932 case FIX_TRUNC_EXPR:
2933 case FIX_FLOOR_EXPR:
2934 case FIX_ROUND_EXPR:
2935 case FIX_CEIL_EXPR:
2936 result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
2937 break;
2939 case INDIRECT_REF:
2940 result = build_nt (INDIRECT_REF,
2941 stabilize_reference_1 (TREE_OPERAND (ref, 0)));
2942 break;
2944 case COMPONENT_REF:
2945 result = build_nt (COMPONENT_REF,
2946 stabilize_reference (TREE_OPERAND (ref, 0)),
2947 TREE_OPERAND (ref, 1));
2948 break;
2950 case BIT_FIELD_REF:
2951 result = build_nt (BIT_FIELD_REF,
2952 stabilize_reference (TREE_OPERAND (ref, 0)),
2953 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2954 stabilize_reference_1 (TREE_OPERAND (ref, 2)));
2955 break;
2957 case ARRAY_REF:
2958 result = build_nt (ARRAY_REF,
2959 stabilize_reference (TREE_OPERAND (ref, 0)),
2960 stabilize_reference_1 (TREE_OPERAND (ref, 1)));
2961 break;
2963 case COMPOUND_EXPR:
2964 /* We cannot wrap the first expression in a SAVE_EXPR, as then
2965 it wouldn't be ignored. This matters when dealing with
2966 volatiles. */
2967 return stabilize_reference_1 (ref);
2969 case RTL_EXPR:
2970 result = build1 (INDIRECT_REF, TREE_TYPE (ref),
2971 save_expr (build1 (ADDR_EXPR,
2972 build_pointer_type (TREE_TYPE (ref)),
2973 ref)));
2974 break;
2977 /* If arg isn't a kind of lvalue we recognize, make no change.
2978 Caller should recognize the error for an invalid lvalue. */
2979 default:
2980 return ref;
2982 case ERROR_MARK:
2983 return error_mark_node;
2986 TREE_TYPE (result) = TREE_TYPE (ref);
2987 TREE_READONLY (result) = TREE_READONLY (ref);
2988 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
2989 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
2990 TREE_RAISES (result) = TREE_RAISES (ref);
2992 return result;
2995 /* Subroutine of stabilize_reference; this is called for subtrees of
2996 references. Any expression with side-effects must be put in a SAVE_EXPR
2997 to ensure that it is only evaluated once.
2999 We don't put SAVE_EXPR nodes around everything, because assigning very
3000 simple expressions to temporaries causes us to miss good opportunities
3001 for optimizations. Among other things, the opportunity to fold in the
3002 addition of a constant into an addressing mode often gets lost, e.g.
3003 "y[i+1] += x;". In general, we take the approach that we should not make
3004 an assignment unless we are forced into it - i.e., that any non-side effect
3005 operator should be allowed, and that cse should take care of coalescing
3006 multiple utterances of the same expression should that prove fruitful. */
3008 tree
3009 stabilize_reference_1 (e)
3010 tree e;
3012 register tree result;
3013 register enum tree_code code = TREE_CODE (e);
3015 /* We cannot ignore const expressions because it might be a reference
3016 to a const array but whose index contains side-effects. But we can
3017 ignore things that are actual constant or that already have been
3018 handled by this function. */
3020 if (TREE_CONSTANT (e) || code == SAVE_EXPR)
3021 return e;
3023 switch (TREE_CODE_CLASS (code))
3025 case 'x':
3026 case 't':
3027 case 'd':
3028 case 'b':
3029 case '<':
3030 case 's':
3031 case 'e':
3032 case 'r':
3033 /* If the expression has side-effects, then encase it in a SAVE_EXPR
3034 so that it will only be evaluated once. */
3035 /* The reference (r) and comparison (<) classes could be handled as
3036 below, but it is generally faster to only evaluate them once. */
3037 if (TREE_SIDE_EFFECTS (e))
3038 return save_expr (e);
3039 return e;
3041 case 'c':
3042 /* Constants need no processing. In fact, we should never reach
3043 here. */
3044 return e;
3046 case '2':
3047 /* Division is slow and tends to be compiled with jumps,
3048 especially the division by powers of 2 that is often
3049 found inside of an array reference. So do it just once. */
3050 if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
3051 || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
3052 || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
3053 || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
3054 return save_expr (e);
3055 /* Recursively stabilize each operand. */
3056 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
3057 stabilize_reference_1 (TREE_OPERAND (e, 1)));
3058 break;
3060 case '1':
3061 /* Recursively stabilize each operand. */
3062 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
3063 break;
3065 default:
3066 abort ();
3069 TREE_TYPE (result) = TREE_TYPE (e);
3070 TREE_READONLY (result) = TREE_READONLY (e);
3071 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
3072 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
3073 TREE_RAISES (result) = TREE_RAISES (e);
3075 return result;
3078 /* Low-level constructors for expressions. */
3080 /* Build an expression of code CODE, data type TYPE,
3081 and operands as specified by the arguments ARG1 and following arguments.
3082 Expressions and reference nodes can be created this way.
3083 Constants, decls, types and misc nodes cannot be. */
3085 tree
3086 build VPARAMS ((enum tree_code code, tree tt, ...))
3088 #ifndef ANSI_PROTOTYPES
3089 enum tree_code code;
3090 tree tt;
3091 #endif
3092 va_list p;
3093 register tree t;
3094 register int length;
3095 register int i;
3096 int fro;
3098 VA_START (p, tt);
3100 #ifndef ANSI_PROTOTYPES
3101 code = va_arg (p, enum tree_code);
3102 tt = va_arg (p, tree);
3103 #endif
3105 t = make_node (code);
3106 length = tree_code_length[(int) code];
3107 TREE_TYPE (t) = tt;
3109 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_RAISED for
3110 the result based on those same flags for the arguments. But, if
3111 the arguments aren't really even `tree' expressions, we shouldn't
3112 be trying to do this. */
3113 fro = first_rtl_op (code);
3115 if (length == 2)
3117 /* This is equivalent to the loop below, but faster. */
3118 register tree arg0 = va_arg (p, tree);
3119 register tree arg1 = va_arg (p, tree);
3120 TREE_OPERAND (t, 0) = arg0;
3121 TREE_OPERAND (t, 1) = arg1;
3122 if (arg0 && fro > 0)
3124 if (TREE_SIDE_EFFECTS (arg0))
3125 TREE_SIDE_EFFECTS (t) = 1;
3126 if (TREE_RAISES (arg0))
3127 TREE_RAISES (t) = 1;
3129 if (arg1 && fro > 1)
3131 if (TREE_SIDE_EFFECTS (arg1))
3132 TREE_SIDE_EFFECTS (t) = 1;
3133 if (TREE_RAISES (arg1))
3134 TREE_RAISES (t) = 1;
3137 else if (length == 1)
3139 register tree arg0 = va_arg (p, tree);
3141 /* Call build1 for this! */
3142 if (TREE_CODE_CLASS (code) != 's')
3143 abort ();
3144 TREE_OPERAND (t, 0) = arg0;
3145 if (fro > 0)
3147 if (arg0 && TREE_SIDE_EFFECTS (arg0))
3148 TREE_SIDE_EFFECTS (t) = 1;
3149 TREE_RAISES (t) = (arg0 && TREE_RAISES (arg0));
3152 else
3154 for (i = 0; i < length; i++)
3156 register tree operand = va_arg (p, tree);
3157 TREE_OPERAND (t, i) = operand;
3158 if (operand && fro > i)
3160 if (TREE_SIDE_EFFECTS (operand))
3161 TREE_SIDE_EFFECTS (t) = 1;
3162 if (TREE_RAISES (operand))
3163 TREE_RAISES (t) = 1;
3167 va_end (p);
3168 return t;
3171 /* Same as above, but only builds for unary operators.
3172 Saves lions share of calls to `build'; cuts down use
3173 of varargs, which is expensive for RISC machines. */
3175 tree
3176 build1 (code, type, node)
3177 enum tree_code code;
3178 tree type;
3179 tree node;
3181 register struct obstack *obstack = expression_obstack;
3182 register int length;
3183 #ifdef GATHER_STATISTICS
3184 register tree_node_kind kind;
3185 #endif
3186 register tree t;
3188 #ifdef GATHER_STATISTICS
3189 if (TREE_CODE_CLASS (code) == 'r')
3190 kind = r_kind;
3191 else
3192 kind = e_kind;
3193 #endif
3195 length = sizeof (struct tree_exp);
3197 if (ggc_p)
3198 t = ggc_alloc_tree (length);
3199 else
3201 t = (tree) obstack_alloc (obstack, length);
3202 memset ((PTR) t, 0, length);
3205 #ifdef GATHER_STATISTICS
3206 tree_node_counts[(int)kind]++;
3207 tree_node_sizes[(int)kind] += length;
3208 #endif
3210 TREE_TYPE (t) = type;
3211 TREE_SET_CODE (t, code);
3213 if (obstack == &permanent_obstack)
3214 TREE_PERMANENT (t) = 1;
3216 TREE_OPERAND (t, 0) = node;
3217 if (node && first_rtl_op (code) != 0)
3219 if (TREE_SIDE_EFFECTS (node))
3220 TREE_SIDE_EFFECTS (t) = 1;
3221 if (TREE_RAISES (node))
3222 TREE_RAISES (t) = 1;
3225 switch (code)
3227 case INIT_EXPR:
3228 case MODIFY_EXPR:
3229 case VA_ARG_EXPR:
3230 case RTL_EXPR:
3231 case PREDECREMENT_EXPR:
3232 case PREINCREMENT_EXPR:
3233 case POSTDECREMENT_EXPR:
3234 case POSTINCREMENT_EXPR:
3235 /* All of these have side-effects, no matter what their
3236 operands are. */
3237 TREE_SIDE_EFFECTS (t) = 1;
3238 break;
3240 default:
3241 break;
3244 return t;
3247 /* Similar except don't specify the TREE_TYPE
3248 and leave the TREE_SIDE_EFFECTS as 0.
3249 It is permissible for arguments to be null,
3250 or even garbage if their values do not matter. */
3252 tree
3253 build_nt VPARAMS ((enum tree_code code, ...))
3255 #ifndef ANSI_PROTOTYPES
3256 enum tree_code code;
3257 #endif
3258 va_list p;
3259 register tree t;
3260 register int length;
3261 register int i;
3263 VA_START (p, code);
3265 #ifndef ANSI_PROTOTYPES
3266 code = va_arg (p, enum tree_code);
3267 #endif
3269 t = make_node (code);
3270 length = tree_code_length[(int) code];
3272 for (i = 0; i < length; i++)
3273 TREE_OPERAND (t, i) = va_arg (p, tree);
3275 va_end (p);
3276 return t;
3279 /* Similar to `build_nt', except we build
3280 on the temp_decl_obstack, regardless. */
3282 tree
3283 build_parse_node VPARAMS ((enum tree_code code, ...))
3285 #ifndef ANSI_PROTOTYPES
3286 enum tree_code code;
3287 #endif
3288 register struct obstack *ambient_obstack = expression_obstack;
3289 va_list p;
3290 register tree t;
3291 register int length;
3292 register int i;
3294 VA_START (p, code);
3296 #ifndef ANSI_PROTOTYPES
3297 code = va_arg (p, enum tree_code);
3298 #endif
3300 expression_obstack = &temp_decl_obstack;
3302 t = make_node (code);
3303 length = tree_code_length[(int) code];
3305 for (i = 0; i < length; i++)
3306 TREE_OPERAND (t, i) = va_arg (p, tree);
3308 va_end (p);
3309 expression_obstack = ambient_obstack;
3310 return t;
3313 #if 0
3314 /* Commented out because this wants to be done very
3315 differently. See cp-lex.c. */
3316 tree
3317 build_op_identifier (op1, op2)
3318 tree op1, op2;
3320 register tree t = make_node (OP_IDENTIFIER);
3321 TREE_PURPOSE (t) = op1;
3322 TREE_VALUE (t) = op2;
3323 return t;
3325 #endif
3327 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
3328 We do NOT enter this node in any sort of symbol table.
3330 layout_decl is used to set up the decl's storage layout.
3331 Other slots are initialized to 0 or null pointers. */
3333 tree
3334 build_decl (code, name, type)
3335 enum tree_code code;
3336 tree name, type;
3338 register tree t;
3340 t = make_node (code);
3342 /* if (type == error_mark_node)
3343 type = integer_type_node; */
3344 /* That is not done, deliberately, so that having error_mark_node
3345 as the type can suppress useless errors in the use of this variable. */
3347 DECL_NAME (t) = name;
3348 DECL_ASSEMBLER_NAME (t) = name;
3349 TREE_TYPE (t) = type;
3351 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
3352 layout_decl (t, 0);
3353 else if (code == FUNCTION_DECL)
3354 DECL_MODE (t) = FUNCTION_MODE;
3356 return t;
3359 /* BLOCK nodes are used to represent the structure of binding contours
3360 and declarations, once those contours have been exited and their contents
3361 compiled. This information is used for outputting debugging info. */
3363 tree
3364 build_block (vars, tags, subblocks, supercontext, chain)
3365 tree vars, tags ATTRIBUTE_UNUSED, subblocks, supercontext, chain;
3367 register tree block = make_node (BLOCK);
3369 BLOCK_VARS (block) = vars;
3370 BLOCK_SUBBLOCKS (block) = subblocks;
3371 BLOCK_SUPERCONTEXT (block) = supercontext;
3372 BLOCK_CHAIN (block) = chain;
3373 return block;
3376 /* EXPR_WITH_FILE_LOCATION are used to keep track of the exact
3377 location where an expression or an identifier were encountered. It
3378 is necessary for languages where the frontend parser will handle
3379 recursively more than one file (Java is one of them). */
3381 tree
3382 build_expr_wfl (node, file, line, col)
3383 tree node;
3384 const char *file;
3385 int line, col;
3387 static const char *last_file = 0;
3388 static tree last_filenode = NULL_TREE;
3389 register tree wfl = make_node (EXPR_WITH_FILE_LOCATION);
3391 EXPR_WFL_NODE (wfl) = node;
3392 EXPR_WFL_SET_LINECOL (wfl, line, col);
3393 if (file != last_file)
3395 last_file = file;
3396 last_filenode = file ? get_identifier (file) : NULL_TREE;
3399 EXPR_WFL_FILENAME_NODE (wfl) = last_filenode;
3400 if (node)
3402 TREE_SIDE_EFFECTS (wfl) = TREE_SIDE_EFFECTS (node);
3403 TREE_TYPE (wfl) = TREE_TYPE (node);
3406 return wfl;
3409 /* Return a declaration like DDECL except that its DECL_MACHINE_ATTRIBUTE
3410 is ATTRIBUTE. */
3412 tree
3413 build_decl_attribute_variant (ddecl, attribute)
3414 tree ddecl, attribute;
3416 DECL_MACHINE_ATTRIBUTES (ddecl) = attribute;
3417 return ddecl;
3420 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
3421 is ATTRIBUTE.
3423 Record such modified types already made so we don't make duplicates. */
3425 tree
3426 build_type_attribute_variant (ttype, attribute)
3427 tree ttype, attribute;
3429 if ( ! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
3431 register int hashcode;
3432 tree ntype;
3434 push_obstacks (TYPE_OBSTACK (ttype), TYPE_OBSTACK (ttype));
3435 ntype = copy_node (ttype);
3437 TYPE_POINTER_TO (ntype) = 0;
3438 TYPE_REFERENCE_TO (ntype) = 0;
3439 TYPE_ATTRIBUTES (ntype) = attribute;
3441 /* Create a new main variant of TYPE. */
3442 TYPE_MAIN_VARIANT (ntype) = ntype;
3443 TYPE_NEXT_VARIANT (ntype) = 0;
3444 set_type_quals (ntype, TYPE_UNQUALIFIED);
3446 hashcode = TYPE_HASH (TREE_CODE (ntype))
3447 + TYPE_HASH (TREE_TYPE (ntype))
3448 + attribute_hash_list (attribute);
3450 switch (TREE_CODE (ntype))
3452 case FUNCTION_TYPE:
3453 hashcode += TYPE_HASH (TYPE_ARG_TYPES (ntype));
3454 break;
3455 case ARRAY_TYPE:
3456 hashcode += TYPE_HASH (TYPE_DOMAIN (ntype));
3457 break;
3458 case INTEGER_TYPE:
3459 hashcode += TYPE_HASH (TYPE_MAX_VALUE (ntype));
3460 break;
3461 case REAL_TYPE:
3462 hashcode += TYPE_HASH (TYPE_PRECISION (ntype));
3463 break;
3464 default:
3465 break;
3468 ntype = type_hash_canon (hashcode, ntype);
3469 ttype = build_qualified_type (ntype, TYPE_QUALS (ttype));
3470 pop_obstacks ();
3473 return ttype;
3476 /* Return a 1 if ATTR_NAME and ATTR_ARGS is valid for either declaration DECL
3477 or type TYPE and 0 otherwise. Validity is determined the configuration
3478 macros VALID_MACHINE_DECL_ATTRIBUTE and VALID_MACHINE_TYPE_ATTRIBUTE. */
3481 valid_machine_attribute (attr_name, attr_args, decl, type)
3482 tree attr_name;
3483 tree attr_args ATTRIBUTE_UNUSED;
3484 tree decl ATTRIBUTE_UNUSED;
3485 tree type ATTRIBUTE_UNUSED;
3487 int validated = 0;
3488 #ifdef VALID_MACHINE_DECL_ATTRIBUTE
3489 tree decl_attr_list = decl != 0 ? DECL_MACHINE_ATTRIBUTES (decl) : 0;
3490 #endif
3491 #ifdef VALID_MACHINE_TYPE_ATTRIBUTE
3492 tree type_attr_list = TYPE_ATTRIBUTES (type);
3493 #endif
3495 if (TREE_CODE (attr_name) != IDENTIFIER_NODE)
3496 abort ();
3498 #ifdef VALID_MACHINE_DECL_ATTRIBUTE
3499 if (decl != 0
3500 && VALID_MACHINE_DECL_ATTRIBUTE (decl, decl_attr_list, attr_name,
3501 attr_args))
3503 tree attr = lookup_attribute (IDENTIFIER_POINTER (attr_name),
3504 decl_attr_list);
3506 if (attr != NULL_TREE)
3508 /* Override existing arguments. Declarations are unique so we can
3509 modify this in place. */
3510 TREE_VALUE (attr) = attr_args;
3512 else
3514 decl_attr_list = tree_cons (attr_name, attr_args, decl_attr_list);
3515 decl = build_decl_attribute_variant (decl, decl_attr_list);
3518 validated = 1;
3520 #endif
3522 #ifdef VALID_MACHINE_TYPE_ATTRIBUTE
3523 if (validated)
3524 /* Don't apply the attribute to both the decl and the type. */;
3525 else if (VALID_MACHINE_TYPE_ATTRIBUTE (type, type_attr_list, attr_name,
3526 attr_args))
3528 tree attr = lookup_attribute (IDENTIFIER_POINTER (attr_name),
3529 type_attr_list);
3531 if (attr != NULL_TREE)
3533 /* Override existing arguments.
3534 ??? This currently works since attribute arguments are not
3535 included in `attribute_hash_list'. Something more complicated
3536 may be needed in the future. */
3537 TREE_VALUE (attr) = attr_args;
3539 else
3541 /* If this is part of a declaration, create a type variant,
3542 otherwise, this is part of a type definition, so add it
3543 to the base type. */
3544 type_attr_list = tree_cons (attr_name, attr_args, type_attr_list);
3545 if (decl != 0)
3546 type = build_type_attribute_variant (type, type_attr_list);
3547 else
3548 TYPE_ATTRIBUTES (type) = type_attr_list;
3551 if (decl != 0)
3552 TREE_TYPE (decl) = type;
3554 validated = 1;
3557 /* Handle putting a type attribute on pointer-to-function-type by putting
3558 the attribute on the function type. */
3559 else if (POINTER_TYPE_P (type)
3560 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
3561 && VALID_MACHINE_TYPE_ATTRIBUTE (TREE_TYPE (type), type_attr_list,
3562 attr_name, attr_args))
3564 tree inner_type = TREE_TYPE (type);
3565 tree inner_attr_list = TYPE_ATTRIBUTES (inner_type);
3566 tree attr = lookup_attribute (IDENTIFIER_POINTER (attr_name),
3567 type_attr_list);
3569 if (attr != NULL_TREE)
3570 TREE_VALUE (attr) = attr_args;
3571 else
3573 inner_attr_list = tree_cons (attr_name, attr_args, inner_attr_list);
3574 inner_type = build_type_attribute_variant (inner_type,
3575 inner_attr_list);
3578 if (decl != 0)
3579 TREE_TYPE (decl) = build_pointer_type (inner_type);
3580 else
3582 /* Clear TYPE_POINTER_TO for the old inner type, since
3583 `type' won't be pointing to it anymore. */
3584 TYPE_POINTER_TO (TREE_TYPE (type)) = NULL_TREE;
3585 TREE_TYPE (type) = inner_type;
3588 validated = 1;
3590 #endif
3592 return validated;
3595 /* Return non-zero if IDENT is a valid name for attribute ATTR,
3596 or zero if not.
3598 We try both `text' and `__text__', ATTR may be either one. */
3599 /* ??? It might be a reasonable simplification to require ATTR to be only
3600 `text'. One might then also require attribute lists to be stored in
3601 their canonicalized form. */
3604 is_attribute_p (attr, ident)
3605 const char *attr;
3606 tree ident;
3608 int ident_len, attr_len;
3609 char *p;
3611 if (TREE_CODE (ident) != IDENTIFIER_NODE)
3612 return 0;
3614 if (strcmp (attr, IDENTIFIER_POINTER (ident)) == 0)
3615 return 1;
3617 p = IDENTIFIER_POINTER (ident);
3618 ident_len = strlen (p);
3619 attr_len = strlen (attr);
3621 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
3622 if (attr[0] == '_')
3624 if (attr[1] != '_'
3625 || attr[attr_len - 2] != '_'
3626 || attr[attr_len - 1] != '_')
3627 abort ();
3628 if (ident_len == attr_len - 4
3629 && strncmp (attr + 2, p, attr_len - 4) == 0)
3630 return 1;
3632 else
3634 if (ident_len == attr_len + 4
3635 && p[0] == '_' && p[1] == '_'
3636 && p[ident_len - 2] == '_' && p[ident_len - 1] == '_'
3637 && strncmp (attr, p + 2, attr_len) == 0)
3638 return 1;
3641 return 0;
3644 /* Given an attribute name and a list of attributes, return a pointer to the
3645 attribute's list element if the attribute is part of the list, or NULL_TREE
3646 if not found. */
3648 tree
3649 lookup_attribute (attr_name, list)
3650 const char *attr_name;
3651 tree list;
3653 tree l;
3655 for (l = list; l; l = TREE_CHAIN (l))
3657 if (TREE_CODE (TREE_PURPOSE (l)) != IDENTIFIER_NODE)
3658 abort ();
3659 if (is_attribute_p (attr_name, TREE_PURPOSE (l)))
3660 return l;
3663 return NULL_TREE;
3666 /* Return an attribute list that is the union of a1 and a2. */
3668 tree
3669 merge_attributes (a1, a2)
3670 register tree a1, a2;
3672 tree attributes;
3674 /* Either one unset? Take the set one. */
3676 if ((attributes = a1) == 0)
3677 attributes = a2;
3679 /* One that completely contains the other? Take it. */
3681 else if (a2 != 0 && ! attribute_list_contained (a1, a2))
3683 if (attribute_list_contained (a2, a1))
3684 attributes = a2;
3685 else
3687 /* Pick the longest list, and hang on the other list. */
3688 /* ??? For the moment we punt on the issue of attrs with args. */
3690 if (list_length (a1) < list_length (a2))
3691 attributes = a2, a2 = a1;
3693 for (; a2 != 0; a2 = TREE_CHAIN (a2))
3694 if (lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
3695 attributes) == NULL_TREE)
3697 a1 = copy_node (a2);
3698 TREE_CHAIN (a1) = attributes;
3699 attributes = a1;
3703 return attributes;
3706 /* Given types T1 and T2, merge their attributes and return
3707 the result. */
3709 tree
3710 merge_machine_type_attributes (t1, t2)
3711 tree t1, t2;
3713 #ifdef MERGE_MACHINE_TYPE_ATTRIBUTES
3714 return MERGE_MACHINE_TYPE_ATTRIBUTES (t1, t2);
3715 #else
3716 return merge_attributes (TYPE_ATTRIBUTES (t1),
3717 TYPE_ATTRIBUTES (t2));
3718 #endif
3721 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
3722 the result. */
3724 tree
3725 merge_machine_decl_attributes (olddecl, newdecl)
3726 tree olddecl, newdecl;
3728 #ifdef MERGE_MACHINE_DECL_ATTRIBUTES
3729 return MERGE_MACHINE_DECL_ATTRIBUTES (olddecl, newdecl);
3730 #else
3731 return merge_attributes (DECL_MACHINE_ATTRIBUTES (olddecl),
3732 DECL_MACHINE_ATTRIBUTES (newdecl));
3733 #endif
3736 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
3737 of the various TYPE_QUAL values. */
3739 static void
3740 set_type_quals (type, type_quals)
3741 tree type;
3742 int type_quals;
3744 TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
3745 TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
3746 TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
3749 /* Given a type node TYPE and a TYPE_QUALIFIER_SET, return a type for
3750 the same kind of data as TYPE describes. Variants point to the
3751 "main variant" (which has no qualifiers set) via TYPE_MAIN_VARIANT,
3752 and it points to a chain of other variants so that duplicate
3753 variants are never made. Only main variants should ever appear as
3754 types of expressions. */
3756 tree
3757 build_qualified_type (type, type_quals)
3758 tree type;
3759 int type_quals;
3761 register tree t;
3763 /* Search the chain of variants to see if there is already one there just
3764 like the one we need to have. If so, use that existing one. We must
3765 preserve the TYPE_NAME, since there is code that depends on this. */
3767 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
3768 if (TYPE_QUALS (t) == type_quals && TYPE_NAME (t) == TYPE_NAME (type))
3769 return t;
3771 /* We need a new one. */
3772 t = build_type_copy (type);
3773 set_type_quals (t, type_quals);
3774 return t;
3777 /* Create a new variant of TYPE, equivalent but distinct.
3778 This is so the caller can modify it. */
3780 tree
3781 build_type_copy (type)
3782 tree type;
3784 register tree t, m = TYPE_MAIN_VARIANT (type);
3785 register struct obstack *ambient_obstack = current_obstack;
3787 current_obstack = TYPE_OBSTACK (type);
3788 t = copy_node (type);
3789 current_obstack = ambient_obstack;
3791 TYPE_POINTER_TO (t) = 0;
3792 TYPE_REFERENCE_TO (t) = 0;
3794 /* Add this type to the chain of variants of TYPE. */
3795 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
3796 TYPE_NEXT_VARIANT (m) = t;
3798 return t;
3801 /* Hashing of types so that we don't make duplicates.
3802 The entry point is `type_hash_canon'. */
3804 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
3805 with types in the TREE_VALUE slots), by adding the hash codes
3806 of the individual types. */
3809 type_hash_list (list)
3810 tree list;
3812 register int hashcode;
3813 register tree tail;
3815 for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
3816 hashcode += TYPE_HASH (TREE_VALUE (tail));
3818 return hashcode;
3821 /* Look in the type hash table for a type isomorphic to TYPE.
3822 If one is found, return it. Otherwise return 0. */
3824 tree
3825 type_hash_lookup (hashcode, type)
3826 int hashcode;
3827 tree type;
3829 register struct type_hash *h;
3831 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
3832 must call that routine before comparing TYPE_ALIGNs. */
3833 layout_type (type);
3835 for (h = type_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
3836 if (h->hashcode == hashcode
3837 && TREE_CODE (h->type) == TREE_CODE (type)
3838 && TREE_TYPE (h->type) == TREE_TYPE (type)
3839 && attribute_list_equal (TYPE_ATTRIBUTES (h->type),
3840 TYPE_ATTRIBUTES (type))
3841 && TYPE_ALIGN (h->type) == TYPE_ALIGN (type)
3842 && (TYPE_MAX_VALUE (h->type) == TYPE_MAX_VALUE (type)
3843 || tree_int_cst_equal (TYPE_MAX_VALUE (h->type),
3844 TYPE_MAX_VALUE (type)))
3845 && (TYPE_MIN_VALUE (h->type) == TYPE_MIN_VALUE (type)
3846 || tree_int_cst_equal (TYPE_MIN_VALUE (h->type),
3847 TYPE_MIN_VALUE (type)))
3848 /* Note that TYPE_DOMAIN is TYPE_ARG_TYPES for FUNCTION_TYPE. */
3849 && (TYPE_DOMAIN (h->type) == TYPE_DOMAIN (type)
3850 || (TYPE_DOMAIN (h->type)
3851 && TREE_CODE (TYPE_DOMAIN (h->type)) == TREE_LIST
3852 && TYPE_DOMAIN (type)
3853 && TREE_CODE (TYPE_DOMAIN (type)) == TREE_LIST
3854 && type_list_equal (TYPE_DOMAIN (h->type),
3855 TYPE_DOMAIN (type)))))
3856 return h->type;
3858 return 0;
3861 /* Add an entry to the type-hash-table
3862 for a type TYPE whose hash code is HASHCODE. */
3864 void
3865 type_hash_add (hashcode, type)
3866 int hashcode;
3867 tree type;
3869 register struct type_hash *h;
3871 h = (struct type_hash *) permalloc (sizeof (struct type_hash));
3872 h->hashcode = hashcode;
3873 h->type = type;
3874 h->next = type_hash_table[hashcode % TYPE_HASH_SIZE];
3875 type_hash_table[hashcode % TYPE_HASH_SIZE] = h;
3878 /* Given TYPE, and HASHCODE its hash code, return the canonical
3879 object for an identical type if one already exists.
3880 Otherwise, return TYPE, and record it as the canonical object
3881 if it is a permanent object.
3883 To use this function, first create a type of the sort you want.
3884 Then compute its hash code from the fields of the type that
3885 make it different from other similar types.
3886 Then call this function and use the value.
3887 This function frees the type you pass in if it is a duplicate. */
3889 /* Set to 1 to debug without canonicalization. Never set by program. */
3890 int debug_no_type_hash = 0;
3892 tree
3893 type_hash_canon (hashcode, type)
3894 int hashcode;
3895 tree type;
3897 tree t1;
3899 if (debug_no_type_hash)
3900 return type;
3902 t1 = type_hash_lookup (hashcode, type);
3903 if (t1 != 0)
3905 if (!ggc_p)
3906 obstack_free (TYPE_OBSTACK (type), type);
3908 #ifdef GATHER_STATISTICS
3909 tree_node_counts[(int)t_kind]--;
3910 tree_node_sizes[(int)t_kind] -= sizeof (struct tree_type);
3911 #endif
3912 return t1;
3915 /* If this is a permanent type, record it for later reuse. */
3916 if (ggc_p || TREE_PERMANENT (type))
3917 type_hash_add (hashcode, type);
3919 return type;
3922 /* Mark ARG (which is really a struct type_hash **) for GC. */
3924 static void
3925 mark_type_hash (arg)
3926 void *arg;
3928 struct type_hash *t = *(struct type_hash **) arg;
3930 while (t)
3932 ggc_mark_tree (t->type);
3933 t = t->next;
3937 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
3938 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
3939 by adding the hash codes of the individual attributes. */
3942 attribute_hash_list (list)
3943 tree list;
3945 register int hashcode;
3946 register tree tail;
3948 for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
3949 /* ??? Do we want to add in TREE_VALUE too? */
3950 hashcode += TYPE_HASH (TREE_PURPOSE (tail));
3951 return hashcode;
3954 /* Given two lists of attributes, return true if list l2 is
3955 equivalent to l1. */
3958 attribute_list_equal (l1, l2)
3959 tree l1, l2;
3961 return attribute_list_contained (l1, l2)
3962 && attribute_list_contained (l2, l1);
3965 /* Given two lists of attributes, return true if list L2 is
3966 completely contained within L1. */
3967 /* ??? This would be faster if attribute names were stored in a canonicalized
3968 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
3969 must be used to show these elements are equivalent (which they are). */
3970 /* ??? It's not clear that attributes with arguments will always be handled
3971 correctly. */
3974 attribute_list_contained (l1, l2)
3975 tree l1, l2;
3977 register tree t1, t2;
3979 /* First check the obvious, maybe the lists are identical. */
3980 if (l1 == l2)
3981 return 1;
3983 /* Maybe the lists are similar. */
3984 for (t1 = l1, t2 = l2;
3985 t1 != 0 && t2 != 0
3986 && TREE_PURPOSE (t1) == TREE_PURPOSE (t2)
3987 && TREE_VALUE (t1) == TREE_VALUE (t2);
3988 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2));
3990 /* Maybe the lists are equal. */
3991 if (t1 == 0 && t2 == 0)
3992 return 1;
3994 for (; t2 != 0; t2 = TREE_CHAIN (t2))
3996 tree attr
3997 = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)), l1);
3999 if (attr == 0)
4000 return 0;
4002 if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) != 1)
4003 return 0;
4006 return 1;
4009 /* Given two lists of types
4010 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
4011 return 1 if the lists contain the same types in the same order.
4012 Also, the TREE_PURPOSEs must match. */
4015 type_list_equal (l1, l2)
4016 tree l1, l2;
4018 register tree t1, t2;
4020 for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
4021 if (TREE_VALUE (t1) != TREE_VALUE (t2)
4022 || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
4023 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
4024 && (TREE_TYPE (TREE_PURPOSE (t1))
4025 == TREE_TYPE (TREE_PURPOSE (t2))))))
4026 return 0;
4028 return t1 == t2;
4031 /* Nonzero if integer constants T1 and T2
4032 represent the same constant value. */
4035 tree_int_cst_equal (t1, t2)
4036 tree t1, t2;
4038 if (t1 == t2)
4039 return 1;
4041 if (t1 == 0 || t2 == 0)
4042 return 0;
4044 if (TREE_CODE (t1) == INTEGER_CST
4045 && TREE_CODE (t2) == INTEGER_CST
4046 && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
4047 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
4048 return 1;
4050 return 0;
4053 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
4054 The precise way of comparison depends on their data type. */
4057 tree_int_cst_lt (t1, t2)
4058 tree t1, t2;
4060 if (t1 == t2)
4061 return 0;
4063 if (! TREE_UNSIGNED (TREE_TYPE (t1)))
4064 return INT_CST_LT (t1, t2);
4066 return INT_CST_LT_UNSIGNED (t1, t2);
4069 /* Return the most significant bit of the integer constant T. */
4072 tree_int_cst_msb (t)
4073 tree t;
4075 register int prec;
4076 HOST_WIDE_INT h;
4077 HOST_WIDE_INT l;
4079 /* Note that using TYPE_PRECISION here is wrong. We care about the
4080 actual bits, not the (arbitrary) range of the type. */
4081 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t))) - 1;
4082 rshift_double (TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t), prec,
4083 2 * HOST_BITS_PER_WIDE_INT, &l, &h, 0);
4084 return (l & 1) == 1;
4087 /* Return an indication of the sign of the integer constant T.
4088 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
4089 Note that -1 will never be returned it T's type is unsigned. */
4092 tree_int_cst_sgn (t)
4093 tree t;
4095 if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0)
4096 return 0;
4097 else if (TREE_UNSIGNED (TREE_TYPE (t)))
4098 return 1;
4099 else if (TREE_INT_CST_HIGH (t) < 0)
4100 return -1;
4101 else
4102 return 1;
4105 /* Compare two constructor-element-type constants. Return 1 if the lists
4106 are known to be equal; otherwise return 0. */
4109 simple_cst_list_equal (l1, l2)
4110 tree l1, l2;
4112 while (l1 != NULL_TREE && l2 != NULL_TREE)
4114 if (simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2)) != 1)
4115 return 0;
4117 l1 = TREE_CHAIN (l1);
4118 l2 = TREE_CHAIN (l2);
4121 return l1 == l2;
4124 /* Return truthvalue of whether T1 is the same tree structure as T2.
4125 Return 1 if they are the same.
4126 Return 0 if they are understandably different.
4127 Return -1 if either contains tree structure not understood by
4128 this function. */
4131 simple_cst_equal (t1, t2)
4132 tree t1, t2;
4134 register enum tree_code code1, code2;
4135 int cmp;
4136 int i;
4138 if (t1 == t2)
4139 return 1;
4140 if (t1 == 0 || t2 == 0)
4141 return 0;
4143 code1 = TREE_CODE (t1);
4144 code2 = TREE_CODE (t2);
4146 if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
4148 if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
4149 || code2 == NON_LVALUE_EXPR)
4150 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
4151 else
4152 return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
4155 else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
4156 || code2 == NON_LVALUE_EXPR)
4157 return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
4159 if (code1 != code2)
4160 return 0;
4162 switch (code1)
4164 case INTEGER_CST:
4165 return (TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
4166 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2));
4168 case REAL_CST:
4169 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
4171 case STRING_CST:
4172 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
4173 && ! bcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
4174 TREE_STRING_LENGTH (t1)));
4176 case CONSTRUCTOR:
4177 if (CONSTRUCTOR_ELTS (t1) == CONSTRUCTOR_ELTS (t2))
4178 return 1;
4179 else
4180 abort ();
4182 case SAVE_EXPR:
4183 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
4185 case CALL_EXPR:
4186 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
4187 if (cmp <= 0)
4188 return cmp;
4189 return
4190 simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
4192 case TARGET_EXPR:
4193 /* Special case: if either target is an unallocated VAR_DECL,
4194 it means that it's going to be unified with whatever the
4195 TARGET_EXPR is really supposed to initialize, so treat it
4196 as being equivalent to anything. */
4197 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
4198 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
4199 && DECL_RTL (TREE_OPERAND (t1, 0)) == 0)
4200 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
4201 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
4202 && DECL_RTL (TREE_OPERAND (t2, 0)) == 0))
4203 cmp = 1;
4204 else
4205 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
4207 if (cmp <= 0)
4208 return cmp;
4210 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
4212 case WITH_CLEANUP_EXPR:
4213 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
4214 if (cmp <= 0)
4215 return cmp;
4217 return simple_cst_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t1, 2));
4219 case COMPONENT_REF:
4220 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
4221 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
4223 return 0;
4225 case VAR_DECL:
4226 case PARM_DECL:
4227 case CONST_DECL:
4228 case FUNCTION_DECL:
4229 return 0;
4231 default:
4232 break;
4235 /* This general rule works for most tree codes. All exceptions should be
4236 handled above. If this is a language-specific tree code, we can't
4237 trust what might be in the operand, so say we don't know
4238 the situation. */
4239 if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
4240 return -1;
4242 switch (TREE_CODE_CLASS (code1))
4244 case '1':
4245 case '2':
4246 case '<':
4247 case 'e':
4248 case 'r':
4249 case 's':
4250 cmp = 1;
4251 for (i = 0; i < tree_code_length[(int) code1]; i++)
4253 cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
4254 if (cmp <= 0)
4255 return cmp;
4258 return cmp;
4260 default:
4261 return -1;
4265 /* Constructors for pointer, array and function types.
4266 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
4267 constructed by language-dependent code, not here.) */
4269 /* Construct, lay out and return the type of pointers to TO_TYPE.
4270 If such a type has already been constructed, reuse it. */
4272 tree
4273 build_pointer_type (to_type)
4274 tree to_type;
4276 register tree t = TYPE_POINTER_TO (to_type);
4278 /* First, if we already have a type for pointers to TO_TYPE, use it. */
4280 if (t != 0)
4281 return t;
4283 /* We need a new one. Put this in the same obstack as TO_TYPE. */
4284 push_obstacks (TYPE_OBSTACK (to_type), TYPE_OBSTACK (to_type));
4285 t = make_node (POINTER_TYPE);
4286 pop_obstacks ();
4288 TREE_TYPE (t) = to_type;
4290 /* Record this type as the pointer to TO_TYPE. */
4291 TYPE_POINTER_TO (to_type) = t;
4293 /* Lay out the type. This function has many callers that are concerned
4294 with expression-construction, and this simplifies them all.
4295 Also, it guarantees the TYPE_SIZE is in the same obstack as the type. */
4296 layout_type (t);
4298 return t;
4301 /* Build the node for the type of references-to-TO_TYPE. */
4303 tree
4304 build_reference_type (to_type)
4305 tree to_type;
4307 register tree t = TYPE_REFERENCE_TO (to_type);
4309 /* First, if we already have a type for pointers to TO_TYPE, use it. */
4311 if (t)
4312 return t;
4314 /* We need a new one. Put this in the same obstack as TO_TYPE. */
4315 push_obstacks (TYPE_OBSTACK (to_type), TYPE_OBSTACK (to_type));
4316 t = make_node (REFERENCE_TYPE);
4317 pop_obstacks ();
4319 TREE_TYPE (t) = to_type;
4321 /* Record this type as the pointer to TO_TYPE. */
4322 TYPE_REFERENCE_TO (to_type) = t;
4324 layout_type (t);
4326 return t;
4329 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
4330 MAXVAL should be the maximum value in the domain
4331 (one less than the length of the array).
4333 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
4334 We don't enforce this limit, that is up to caller (e.g. language front end).
4335 The limit exists because the result is a signed type and we don't handle
4336 sizes that use more than one HOST_WIDE_INT. */
4338 tree
4339 build_index_type (maxval)
4340 tree maxval;
4342 register tree itype = make_node (INTEGER_TYPE);
4344 TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
4345 TYPE_MIN_VALUE (itype) = size_zero_node;
4347 push_obstacks (TYPE_OBSTACK (itype), TYPE_OBSTACK (itype));
4348 TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);
4349 pop_obstacks ();
4351 TYPE_MODE (itype) = TYPE_MODE (sizetype);
4352 TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
4353 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype);
4354 TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
4355 if (TREE_CODE (maxval) == INTEGER_CST)
4357 int maxint = (int) TREE_INT_CST_LOW (maxval);
4358 /* If the domain should be empty, make sure the maxval
4359 remains -1 and is not spoiled by truncation. */
4360 if (INT_CST_LT (maxval, integer_zero_node))
4362 TYPE_MAX_VALUE (itype) = build_int_2 (-1, -1);
4363 TREE_TYPE (TYPE_MAX_VALUE (itype)) = sizetype;
4365 return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype);
4367 else
4368 return itype;
4371 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
4372 ENUMERAL_TYPE, BOOLEAN_TYPE, or CHAR_TYPE), with
4373 low bound LOWVAL and high bound HIGHVAL.
4374 if TYPE==NULL_TREE, sizetype is used. */
4376 tree
4377 build_range_type (type, lowval, highval)
4378 tree type, lowval, highval;
4380 register tree itype = make_node (INTEGER_TYPE);
4382 TREE_TYPE (itype) = type;
4383 if (type == NULL_TREE)
4384 type = sizetype;
4386 push_obstacks (TYPE_OBSTACK (itype), TYPE_OBSTACK (itype));
4387 TYPE_MIN_VALUE (itype) = convert (type, lowval);
4388 TYPE_MAX_VALUE (itype) = highval ? convert (type, highval) : NULL;
4389 pop_obstacks ();
4391 TYPE_PRECISION (itype) = TYPE_PRECISION (type);
4392 TYPE_MODE (itype) = TYPE_MODE (type);
4393 TYPE_SIZE (itype) = TYPE_SIZE (type);
4394 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
4395 TYPE_ALIGN (itype) = TYPE_ALIGN (type);
4396 if (TREE_CODE (lowval) == INTEGER_CST)
4398 HOST_WIDE_INT lowint, highint;
4399 int maxint;
4401 lowint = TREE_INT_CST_LOW (lowval);
4402 if (highval && TREE_CODE (highval) == INTEGER_CST)
4403 highint = TREE_INT_CST_LOW (highval);
4404 else
4405 highint = (~(unsigned HOST_WIDE_INT)0) >> 1;
4407 maxint = (int) (highint - lowint);
4408 return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype);
4410 else
4411 return itype;
4414 /* Just like build_index_type, but takes lowval and highval instead
4415 of just highval (maxval). */
4417 tree
4418 build_index_2_type (lowval,highval)
4419 tree lowval, highval;
4421 return build_range_type (NULL_TREE, lowval, highval);
4424 /* Return nonzero iff ITYPE1 and ITYPE2 are equal (in the LISP sense).
4425 Needed because when index types are not hashed, equal index types
4426 built at different times appear distinct, even though structurally,
4427 they are not. */
4430 index_type_equal (itype1, itype2)
4431 tree itype1, itype2;
4433 if (TREE_CODE (itype1) != TREE_CODE (itype2))
4434 return 0;
4436 if (TREE_CODE (itype1) == INTEGER_TYPE)
4438 if (TYPE_PRECISION (itype1) != TYPE_PRECISION (itype2)
4439 || TYPE_MODE (itype1) != TYPE_MODE (itype2)
4440 || simple_cst_equal (TYPE_SIZE (itype1), TYPE_SIZE (itype2)) != 1
4441 || TYPE_ALIGN (itype1) != TYPE_ALIGN (itype2))
4442 return 0;
4444 if (1 == simple_cst_equal (TYPE_MIN_VALUE (itype1),
4445 TYPE_MIN_VALUE (itype2))
4446 && 1 == simple_cst_equal (TYPE_MAX_VALUE (itype1),
4447 TYPE_MAX_VALUE (itype2)))
4448 return 1;
4451 return 0;
4454 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
4455 and number of elements specified by the range of values of INDEX_TYPE.
4456 If such a type has already been constructed, reuse it. */
4458 tree
4459 build_array_type (elt_type, index_type)
4460 tree elt_type, index_type;
4462 register tree t;
4463 int hashcode;
4465 if (TREE_CODE (elt_type) == FUNCTION_TYPE)
4467 error ("arrays of functions are not meaningful");
4468 elt_type = integer_type_node;
4471 /* Make sure TYPE_POINTER_TO (elt_type) is filled in. */
4472 build_pointer_type (elt_type);
4474 /* Allocate the array after the pointer type,
4475 in case we free it in type_hash_canon. */
4476 t = make_node (ARRAY_TYPE);
4477 TREE_TYPE (t) = elt_type;
4478 TYPE_DOMAIN (t) = index_type;
4480 if (index_type == 0)
4482 return t;
4485 hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type);
4486 t = type_hash_canon (hashcode, t);
4488 if (TYPE_SIZE (t) == 0)
4489 layout_type (t);
4490 return t;
4493 /* Return the TYPE of the elements comprising
4494 the innermost dimension of ARRAY. */
4496 tree
4497 get_inner_array_type (array)
4498 tree array;
4500 tree type = TREE_TYPE (array);
4502 while (TREE_CODE (type) == ARRAY_TYPE)
4503 type = TREE_TYPE (type);
4505 return type;
4508 /* Construct, lay out and return
4509 the type of functions returning type VALUE_TYPE
4510 given arguments of types ARG_TYPES.
4511 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
4512 are data type nodes for the arguments of the function.
4513 If such a type has already been constructed, reuse it. */
4515 tree
4516 build_function_type (value_type, arg_types)
4517 tree value_type, arg_types;
4519 register tree t;
4520 int hashcode;
4522 if (TREE_CODE (value_type) == FUNCTION_TYPE)
4524 error ("function return type cannot be function");
4525 value_type = integer_type_node;
4528 /* Make a node of the sort we want. */
4529 t = make_node (FUNCTION_TYPE);
4530 TREE_TYPE (t) = value_type;
4531 TYPE_ARG_TYPES (t) = arg_types;
4533 /* If we already have such a type, use the old one and free this one. */
4534 hashcode = TYPE_HASH (value_type) + type_hash_list (arg_types);
4535 t = type_hash_canon (hashcode, t);
4537 if (TYPE_SIZE (t) == 0)
4538 layout_type (t);
4539 return t;
4542 /* Construct, lay out and return the type of methods belonging to class
4543 BASETYPE and whose arguments and values are described by TYPE.
4544 If that type exists already, reuse it.
4545 TYPE must be a FUNCTION_TYPE node. */
4547 tree
4548 build_method_type (basetype, type)
4549 tree basetype, type;
4551 register tree t;
4552 int hashcode;
4554 /* Make a node of the sort we want. */
4555 t = make_node (METHOD_TYPE);
4557 if (TREE_CODE (type) != FUNCTION_TYPE)
4558 abort ();
4560 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
4561 TREE_TYPE (t) = TREE_TYPE (type);
4563 /* The actual arglist for this function includes a "hidden" argument
4564 which is "this". Put it into the list of argument types. */
4566 TYPE_ARG_TYPES (t)
4567 = tree_cons (NULL_TREE,
4568 build_pointer_type (basetype), TYPE_ARG_TYPES (type));
4570 /* If we already have such a type, use the old one and free this one. */
4571 hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
4572 t = type_hash_canon (hashcode, t);
4574 if (TYPE_SIZE (t) == 0)
4575 layout_type (t);
4577 return t;
4580 /* Construct, lay out and return the type of offsets to a value
4581 of type TYPE, within an object of type BASETYPE.
4582 If a suitable offset type exists already, reuse it. */
4584 tree
4585 build_offset_type (basetype, type)
4586 tree basetype, type;
4588 register tree t;
4589 int hashcode;
4591 /* Make a node of the sort we want. */
4592 t = make_node (OFFSET_TYPE);
4594 TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
4595 TREE_TYPE (t) = type;
4597 /* If we already have such a type, use the old one and free this one. */
4598 hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
4599 t = type_hash_canon (hashcode, t);
4601 if (TYPE_SIZE (t) == 0)
4602 layout_type (t);
4604 return t;
4607 /* Create a complex type whose components are COMPONENT_TYPE. */
4609 tree
4610 build_complex_type (component_type)
4611 tree component_type;
4613 register tree t;
4614 int hashcode;
4616 /* Make a node of the sort we want. */
4617 t = make_node (COMPLEX_TYPE);
4619 TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
4620 set_type_quals (t, TYPE_QUALS (component_type));
4622 /* If we already have such a type, use the old one and free this one. */
4623 hashcode = TYPE_HASH (component_type);
4624 t = type_hash_canon (hashcode, t);
4626 if (TYPE_SIZE (t) == 0)
4627 layout_type (t);
4629 /* If we are writing Dwarf2 output we need to create a name,
4630 since complex is a fundamental type. */
4631 if (write_symbols == DWARF2_DEBUG && ! TYPE_NAME (t))
4633 const char *name;
4634 if (component_type == char_type_node)
4635 name = "complex char";
4636 else if (component_type == signed_char_type_node)
4637 name = "complex signed char";
4638 else if (component_type == unsigned_char_type_node)
4639 name = "complex unsigned char";
4640 else if (component_type == short_integer_type_node)
4641 name = "complex short int";
4642 else if (component_type == short_unsigned_type_node)
4643 name = "complex short unsigned int";
4644 else if (component_type == integer_type_node)
4645 name = "complex int";
4646 else if (component_type == unsigned_type_node)
4647 name = "complex unsigned int";
4648 else if (component_type == long_integer_type_node)
4649 name = "complex long int";
4650 else if (component_type == long_unsigned_type_node)
4651 name = "complex long unsigned int";
4652 else if (component_type == long_long_integer_type_node)
4653 name = "complex long long int";
4654 else if (component_type == long_long_unsigned_type_node)
4655 name = "complex long long unsigned int";
4656 else
4657 name = 0;
4659 if (name != 0)
4660 TYPE_NAME (t) = get_identifier (name);
4663 return t;
4666 /* Return OP, stripped of any conversions to wider types as much as is safe.
4667 Converting the value back to OP's type makes a value equivalent to OP.
4669 If FOR_TYPE is nonzero, we return a value which, if converted to
4670 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
4672 If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
4673 narrowest type that can hold the value, even if they don't exactly fit.
4674 Otherwise, bit-field references are changed to a narrower type
4675 only if they can be fetched directly from memory in that type.
4677 OP must have integer, real or enumeral type. Pointers are not allowed!
4679 There are some cases where the obvious value we could return
4680 would regenerate to OP if converted to OP's type,
4681 but would not extend like OP to wider types.
4682 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
4683 For example, if OP is (unsigned short)(signed char)-1,
4684 we avoid returning (signed char)-1 if FOR_TYPE is int,
4685 even though extending that to an unsigned short would regenerate OP,
4686 since the result of extending (signed char)-1 to (int)
4687 is different from (int) OP. */
4689 tree
4690 get_unwidened (op, for_type)
4691 register tree op;
4692 tree for_type;
4694 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
4695 register tree type = TREE_TYPE (op);
4696 register unsigned final_prec
4697 = TYPE_PRECISION (for_type != 0 ? for_type : type);
4698 register int uns
4699 = (for_type != 0 && for_type != type
4700 && final_prec > TYPE_PRECISION (type)
4701 && TREE_UNSIGNED (type));
4702 register tree win = op;
4704 while (TREE_CODE (op) == NOP_EXPR)
4706 register int bitschange
4707 = TYPE_PRECISION (TREE_TYPE (op))
4708 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
4710 /* Truncations are many-one so cannot be removed.
4711 Unless we are later going to truncate down even farther. */
4712 if (bitschange < 0
4713 && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
4714 break;
4716 /* See what's inside this conversion. If we decide to strip it,
4717 we will set WIN. */
4718 op = TREE_OPERAND (op, 0);
4720 /* If we have not stripped any zero-extensions (uns is 0),
4721 we can strip any kind of extension.
4722 If we have previously stripped a zero-extension,
4723 only zero-extensions can safely be stripped.
4724 Any extension can be stripped if the bits it would produce
4725 are all going to be discarded later by truncating to FOR_TYPE. */
4727 if (bitschange > 0)
4729 if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
4730 win = op;
4731 /* TREE_UNSIGNED says whether this is a zero-extension.
4732 Let's avoid computing it if it does not affect WIN
4733 and if UNS will not be needed again. */
4734 if ((uns || TREE_CODE (op) == NOP_EXPR)
4735 && TREE_UNSIGNED (TREE_TYPE (op)))
4737 uns = 1;
4738 win = op;
4743 if (TREE_CODE (op) == COMPONENT_REF
4744 /* Since type_for_size always gives an integer type. */
4745 && TREE_CODE (type) != REAL_TYPE
4746 /* Don't crash if field not laid out yet. */
4747 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0)
4749 unsigned innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
4750 type = type_for_size (innerprec, TREE_UNSIGNED (TREE_OPERAND (op, 1)));
4752 /* We can get this structure field in the narrowest type it fits in.
4753 If FOR_TYPE is 0, do this only for a field that matches the
4754 narrower type exactly and is aligned for it
4755 The resulting extension to its nominal type (a fullword type)
4756 must fit the same conditions as for other extensions. */
4758 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
4759 && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))
4760 && (! uns || final_prec <= innerprec
4761 || TREE_UNSIGNED (TREE_OPERAND (op, 1)))
4762 && type != 0)
4764 win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
4765 TREE_OPERAND (op, 1));
4766 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
4767 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
4768 TREE_RAISES (win) = TREE_RAISES (op);
4771 return win;
4774 /* Return OP or a simpler expression for a narrower value
4775 which can be sign-extended or zero-extended to give back OP.
4776 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
4777 or 0 if the value should be sign-extended. */
4779 tree
4780 get_narrower (op, unsignedp_ptr)
4781 register tree op;
4782 int *unsignedp_ptr;
4784 register int uns = 0;
4785 int first = 1;
4786 register tree win = op;
4788 while (TREE_CODE (op) == NOP_EXPR)
4790 register int bitschange
4791 = (TYPE_PRECISION (TREE_TYPE (op))
4792 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
4794 /* Truncations are many-one so cannot be removed. */
4795 if (bitschange < 0)
4796 break;
4798 /* See what's inside this conversion. If we decide to strip it,
4799 we will set WIN. */
4800 op = TREE_OPERAND (op, 0);
4802 if (bitschange > 0)
4804 /* An extension: the outermost one can be stripped,
4805 but remember whether it is zero or sign extension. */
4806 if (first)
4807 uns = TREE_UNSIGNED (TREE_TYPE (op));
4808 /* Otherwise, if a sign extension has been stripped,
4809 only sign extensions can now be stripped;
4810 if a zero extension has been stripped, only zero-extensions. */
4811 else if (uns != TREE_UNSIGNED (TREE_TYPE (op)))
4812 break;
4813 first = 0;
4815 else /* bitschange == 0 */
4817 /* A change in nominal type can always be stripped, but we must
4818 preserve the unsignedness. */
4819 if (first)
4820 uns = TREE_UNSIGNED (TREE_TYPE (op));
4821 first = 0;
4824 win = op;
4827 if (TREE_CODE (op) == COMPONENT_REF
4828 /* Since type_for_size always gives an integer type. */
4829 && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE)
4831 unsigned innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
4832 tree type = type_for_size (innerprec, TREE_UNSIGNED (op));
4834 /* We can get this structure field in a narrower type that fits it,
4835 but the resulting extension to its nominal type (a fullword type)
4836 must satisfy the same conditions as for other extensions.
4838 Do this only for fields that are aligned (not bit-fields),
4839 because when bit-field insns will be used there is no
4840 advantage in doing this. */
4842 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
4843 && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
4844 && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1)))
4845 && type != 0)
4847 if (first)
4848 uns = TREE_UNSIGNED (TREE_OPERAND (op, 1));
4849 win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
4850 TREE_OPERAND (op, 1));
4851 TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
4852 TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
4853 TREE_RAISES (win) = TREE_RAISES (op);
4856 *unsignedp_ptr = uns;
4857 return win;
4860 /* Nonzero if integer constant C has a value that is permissible
4861 for type TYPE (an INTEGER_TYPE). */
4864 int_fits_type_p (c, type)
4865 tree c, type;
4867 if (TREE_UNSIGNED (type))
4868 return (! (TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
4869 && INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type), c))
4870 && ! (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
4871 && INT_CST_LT_UNSIGNED (c, TYPE_MIN_VALUE (type)))
4872 /* Negative ints never fit unsigned types. */
4873 && ! (TREE_INT_CST_HIGH (c) < 0
4874 && ! TREE_UNSIGNED (TREE_TYPE (c))));
4875 else
4876 return (! (TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
4877 && INT_CST_LT (TYPE_MAX_VALUE (type), c))
4878 && ! (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
4879 && INT_CST_LT (c, TYPE_MIN_VALUE (type)))
4880 /* Unsigned ints with top bit set never fit signed types. */
4881 && ! (TREE_INT_CST_HIGH (c) < 0
4882 && TREE_UNSIGNED (TREE_TYPE (c))));
4885 /* Given a DECL or TYPE, return the scope in which it was declared, or
4886 NUL_TREE if there is no containing scope. */
4888 tree
4889 get_containing_scope (t)
4890 tree t;
4892 return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
4895 /* Return the innermost context enclosing DECL that is
4896 a FUNCTION_DECL, or zero if none. */
4898 tree
4899 decl_function_context (decl)
4900 tree decl;
4902 tree context;
4904 if (TREE_CODE (decl) == ERROR_MARK)
4905 return 0;
4907 if (TREE_CODE (decl) == SAVE_EXPR)
4908 context = SAVE_EXPR_CONTEXT (decl);
4909 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
4910 where we look up the function at runtime. Such functions always take
4911 a first argument of type 'pointer to real context'.
4913 C++ should really be fixed to use DECL_CONTEXT for the real context,
4914 and use something else for the "virtual context". */
4915 else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl))
4916 context = TYPE_MAIN_VARIANT
4917 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4918 else
4919 context = DECL_CONTEXT (decl);
4921 while (context && TREE_CODE (context) != FUNCTION_DECL)
4923 if (TREE_CODE (context) == BLOCK)
4924 context = BLOCK_SUPERCONTEXT (context);
4925 else
4926 context = get_containing_scope (context);
4929 return context;
4932 /* Return the innermost context enclosing DECL that is
4933 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
4934 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
4936 tree
4937 decl_type_context (decl)
4938 tree decl;
4940 tree context = DECL_CONTEXT (decl);
4942 while (context)
4944 if (TREE_CODE (context) == RECORD_TYPE
4945 || TREE_CODE (context) == UNION_TYPE
4946 || TREE_CODE (context) == QUAL_UNION_TYPE)
4947 return context;
4949 if (TREE_CODE (context) == TYPE_DECL
4950 || TREE_CODE (context) == FUNCTION_DECL)
4951 context = DECL_CONTEXT (context);
4953 else if (TREE_CODE (context) == BLOCK)
4954 context = BLOCK_SUPERCONTEXT (context);
4956 else
4957 /* Unhandled CONTEXT!? */
4958 abort ();
4960 return NULL_TREE;
4963 /* CALL is a CALL_EXPR. Return the declaration for the function
4964 called, or NULL_TREE if the called function cannot be
4965 determined. */
4967 tree
4968 get_callee_fndecl (call)
4969 tree call;
4971 tree addr;
4973 /* It's invalid to call this function with anything but a
4974 CALL_EXPR. */
4975 if (TREE_CODE (call) != CALL_EXPR)
4976 abort ();
4978 /* The first operand to the CALL is the address of the function
4979 called. */
4980 addr = TREE_OPERAND (call, 0);
4982 /* If the address is just `&f' for some function `f', then we know
4983 that `f' is being called. */
4984 if (TREE_CODE (addr) == ADDR_EXPR
4985 && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
4986 return TREE_OPERAND (addr, 0);
4988 /* We couldn't figure out what was being called. */
4989 return NULL_TREE;
4992 /* Print debugging information about the obstack O, named STR. */
4994 void
4995 print_obstack_statistics (str, o)
4996 const char *str;
4997 struct obstack *o;
4999 struct _obstack_chunk *chunk = o->chunk;
5000 int n_chunks = 1;
5001 int n_alloc = 0;
5003 n_alloc += o->next_free - chunk->contents;
5004 chunk = chunk->prev;
5005 while (chunk)
5007 n_chunks += 1;
5008 n_alloc += chunk->limit - &chunk->contents[0];
5009 chunk = chunk->prev;
5011 fprintf (stderr, "obstack %s: %u bytes, %d chunks\n",
5012 str, n_alloc, n_chunks);
5015 /* Print debugging information about tree nodes generated during the compile,
5016 and any language-specific information. */
5018 void
5019 dump_tree_statistics ()
5021 #ifdef GATHER_STATISTICS
5022 int i;
5023 int total_nodes, total_bytes;
5024 #endif
5026 fprintf (stderr, "\n??? tree nodes created\n\n");
5027 #ifdef GATHER_STATISTICS
5028 fprintf (stderr, "Kind Nodes Bytes\n");
5029 fprintf (stderr, "-------------------------------------\n");
5030 total_nodes = total_bytes = 0;
5031 for (i = 0; i < (int) all_kinds; i++)
5033 fprintf (stderr, "%-20s %6d %9d\n", tree_node_kind_names[i],
5034 tree_node_counts[i], tree_node_sizes[i]);
5035 total_nodes += tree_node_counts[i];
5036 total_bytes += tree_node_sizes[i];
5038 fprintf (stderr, "%-20s %9d\n", "identifier names", id_string_size);
5039 fprintf (stderr, "-------------------------------------\n");
5040 fprintf (stderr, "%-20s %6d %9d\n", "Total", total_nodes, total_bytes);
5041 fprintf (stderr, "-------------------------------------\n");
5042 #else
5043 fprintf (stderr, "(No per-node statistics)\n");
5044 #endif
5045 print_obstack_statistics ("permanent_obstack", &permanent_obstack);
5046 print_obstack_statistics ("maybepermanent_obstack", &maybepermanent_obstack);
5047 print_obstack_statistics ("temporary_obstack", &temporary_obstack);
5048 print_obstack_statistics ("momentary_obstack", &momentary_obstack);
5049 print_obstack_statistics ("temp_decl_obstack", &temp_decl_obstack);
5050 print_lang_statistics ();
5053 #define FILE_FUNCTION_PREFIX_LEN 9
5055 #ifndef NO_DOLLAR_IN_LABEL
5056 #define FILE_FUNCTION_FORMAT "_GLOBAL_$%s$%s"
5057 #else /* NO_DOLLAR_IN_LABEL */
5058 #ifndef NO_DOT_IN_LABEL
5059 #define FILE_FUNCTION_FORMAT "_GLOBAL_.%s.%s"
5060 #else /* NO_DOT_IN_LABEL */
5061 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
5062 #endif /* NO_DOT_IN_LABEL */
5063 #endif /* NO_DOLLAR_IN_LABEL */
5065 extern char *first_global_object_name;
5066 extern char *weak_global_object_name;
5068 /* Appends 6 random characters to TEMPLATE to (hopefully) avoid name
5069 clashes in cases where we can't reliably choose a unique name.
5071 Derived from mkstemp.c in libiberty. */
5073 static void
5074 append_random_chars (template)
5075 char *template;
5077 static const char letters[]
5078 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
5079 static unsigned HOST_WIDE_INT value;
5080 unsigned HOST_WIDE_INT v;
5082 #ifdef HAVE_GETTIMEOFDAY
5083 struct timeval tv;
5084 #endif
5086 template += strlen (template);
5088 #ifdef HAVE_GETTIMEOFDAY
5089 /* Get some more or less random data. */
5090 gettimeofday (&tv, NULL);
5091 value += ((unsigned HOST_WIDE_INT) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid ();
5092 #else
5093 value += getpid ();
5094 #endif
5096 v = value;
5098 /* Fill in the random bits. */
5099 template[0] = letters[v % 62];
5100 v /= 62;
5101 template[1] = letters[v % 62];
5102 v /= 62;
5103 template[2] = letters[v % 62];
5104 v /= 62;
5105 template[3] = letters[v % 62];
5106 v /= 62;
5107 template[4] = letters[v % 62];
5108 v /= 62;
5109 template[5] = letters[v % 62];
5111 template[6] = '\0';
5114 /* Generate a name for a function unique to this translation unit.
5115 TYPE is some string to identify the purpose of this function to the
5116 linker or collect2. */
5118 tree
5119 get_file_function_name_long (type)
5120 const char *type;
5122 char *buf;
5123 register char *p;
5125 if (first_global_object_name)
5126 p = first_global_object_name;
5127 else
5129 /* We don't have anything that we know to be unique to this translation
5130 unit, so use what we do have and throw in some randomness. */
5132 const char *name = weak_global_object_name;
5133 const char *file = main_input_filename;
5135 if (! name)
5136 name = "";
5137 if (! file)
5138 file = input_filename;
5140 p = (char *) alloca (7 + strlen (name) + strlen (file));
5142 sprintf (p, "%s%s", name, file);
5143 append_random_chars (p);
5146 buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
5147 + strlen (type));
5149 /* Set up the name of the file-level functions we may need.
5150 Use a global object (which is already required to be unique over
5151 the program) rather than the file name (which imposes extra
5152 constraints). */
5153 sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
5155 /* Don't need to pull weird characters out of global names. */
5156 if (p != first_global_object_name)
5158 for (p = buf+11; *p; p++)
5159 if (! ( ISDIGIT(*p)
5160 #if 0 /* we always want labels, which are valid C++ identifiers (+ `$') */
5161 #ifndef ASM_IDENTIFY_GCC /* this is required if `.' is invalid -- k. raeburn */
5162 || *p == '.'
5163 #endif
5164 #endif
5165 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
5166 || *p == '$'
5167 #endif
5168 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
5169 || *p == '.'
5170 #endif
5171 || ISUPPER(*p)
5172 || ISLOWER(*p)))
5173 *p = '_';
5176 return get_identifier (buf);
5179 /* If KIND=='I', return a suitable global initializer (constructor) name.
5180 If KIND=='D', return a suitable global clean-up (destructor) name. */
5182 tree
5183 get_file_function_name (kind)
5184 int kind;
5186 char p[2];
5188 p[0] = kind;
5189 p[1] = 0;
5191 return get_file_function_name_long (p);
5194 /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
5195 The result is placed in BUFFER (which has length BIT_SIZE),
5196 with one bit in each char ('\000' or '\001').
5198 If the constructor is constant, NULL_TREE is returned.
5199 Otherwise, a TREE_LIST of the non-constant elements is emitted. */
5201 tree
5202 get_set_constructor_bits (init, buffer, bit_size)
5203 tree init;
5204 char *buffer;
5205 int bit_size;
5207 int i;
5208 tree vals;
5209 HOST_WIDE_INT domain_min
5210 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (init))));
5211 tree non_const_bits = NULL_TREE;
5212 for (i = 0; i < bit_size; i++)
5213 buffer[i] = 0;
5215 for (vals = TREE_OPERAND (init, 1);
5216 vals != NULL_TREE; vals = TREE_CHAIN (vals))
5218 if (TREE_CODE (TREE_VALUE (vals)) != INTEGER_CST
5219 || (TREE_PURPOSE (vals) != NULL_TREE
5220 && TREE_CODE (TREE_PURPOSE (vals)) != INTEGER_CST))
5221 non_const_bits
5222 = tree_cons (TREE_PURPOSE (vals), TREE_VALUE (vals), non_const_bits);
5223 else if (TREE_PURPOSE (vals) != NULL_TREE)
5225 /* Set a range of bits to ones. */
5226 HOST_WIDE_INT lo_index
5227 = TREE_INT_CST_LOW (TREE_PURPOSE (vals)) - domain_min;
5228 HOST_WIDE_INT hi_index
5229 = TREE_INT_CST_LOW (TREE_VALUE (vals)) - domain_min;
5230 if (lo_index < 0 || lo_index >= bit_size
5231 || hi_index < 0 || hi_index >= bit_size)
5232 abort ();
5233 for ( ; lo_index <= hi_index; lo_index++)
5234 buffer[lo_index] = 1;
5236 else
5238 /* Set a single bit to one. */
5239 HOST_WIDE_INT index
5240 = TREE_INT_CST_LOW (TREE_VALUE (vals)) - domain_min;
5241 if (index < 0 || index >= bit_size)
5243 error ("invalid initializer for bit string");
5244 return NULL_TREE;
5246 buffer[index] = 1;
5249 return non_const_bits;
5252 /* Expand (the constant part of) a SET_TYPE CONSTRUCTOR node.
5253 The result is placed in BUFFER (which is an array of bytes).
5254 If the constructor is constant, NULL_TREE is returned.
5255 Otherwise, a TREE_LIST of the non-constant elements is emitted. */
5257 tree
5258 get_set_constructor_bytes (init, buffer, wd_size)
5259 tree init;
5260 unsigned char *buffer;
5261 int wd_size;
5263 int i;
5264 int set_word_size = BITS_PER_UNIT;
5265 int bit_size = wd_size * set_word_size;
5266 int bit_pos = 0;
5267 unsigned char *bytep = buffer;
5268 char *bit_buffer = (char *) alloca(bit_size);
5269 tree non_const_bits = get_set_constructor_bits (init, bit_buffer, bit_size);
5271 for (i = 0; i < wd_size; i++)
5272 buffer[i] = 0;
5274 for (i = 0; i < bit_size; i++)
5276 if (bit_buffer[i])
5278 if (BYTES_BIG_ENDIAN)
5279 *bytep |= (1 << (set_word_size - 1 - bit_pos));
5280 else
5281 *bytep |= 1 << bit_pos;
5283 bit_pos++;
5284 if (bit_pos >= set_word_size)
5285 bit_pos = 0, bytep++;
5287 return non_const_bits;
5290 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
5291 /* Complain that the tree code of NODE does not match the expected CODE.
5292 FILE, LINE, and FUNCTION are of the caller. */
5293 void
5294 tree_check_failed (node, code, file, line, function)
5295 const tree node;
5296 enum tree_code code;
5297 const char *file;
5298 int line;
5299 const char *function;
5301 error ("Tree check: expected %s, have %s",
5302 tree_code_name[code], tree_code_name[TREE_CODE (node)]);
5303 fancy_abort (file, line, function);
5306 /* Similar to above, except that we check for a class of tree
5307 code, given in CL. */
5308 void
5309 tree_class_check_failed (node, cl, file, line, function)
5310 const tree node;
5311 char cl;
5312 const char *file;
5313 int line;
5314 const char *function;
5316 error ("Tree check: expected class '%c', have '%c' (%s)",
5317 cl, TREE_CODE_CLASS (TREE_CODE (node)),
5318 tree_code_name[TREE_CODE (node)]);
5319 fancy_abort (file, line, function);
5322 #endif /* ENABLE_TREE_CHECKING */
5324 /* Return the alias set for T, which may be either a type or an
5325 expression. */
5328 get_alias_set (t)
5329 tree t;
5331 if (! flag_strict_aliasing || lang_get_alias_set == 0)
5332 /* If we're not doing any lanaguage-specific alias analysis, just
5333 assume everything aliases everything else. */
5334 return 0;
5335 else
5336 return (*lang_get_alias_set) (t);
5339 /* Return a brand-new alias set. */
5342 new_alias_set ()
5344 static int last_alias_set;
5346 if (flag_strict_aliasing)
5347 return ++last_alias_set;
5348 else
5349 return 0;
5352 #ifndef CHAR_TYPE_SIZE
5353 #define CHAR_TYPE_SIZE BITS_PER_UNIT
5354 #endif
5356 #ifndef SHORT_TYPE_SIZE
5357 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
5358 #endif
5360 #ifndef INT_TYPE_SIZE
5361 #define INT_TYPE_SIZE BITS_PER_WORD
5362 #endif
5364 #ifndef LONG_TYPE_SIZE
5365 #define LONG_TYPE_SIZE BITS_PER_WORD
5366 #endif
5368 #ifndef LONG_LONG_TYPE_SIZE
5369 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
5370 #endif
5372 #ifndef FLOAT_TYPE_SIZE
5373 #define FLOAT_TYPE_SIZE BITS_PER_WORD
5374 #endif
5376 #ifndef DOUBLE_TYPE_SIZE
5377 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
5378 #endif
5380 #ifndef LONG_DOUBLE_TYPE_SIZE
5381 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
5382 #endif
5384 /* Create nodes for all integer types (and error_mark_node) using the sizes
5385 of C datatypes. The caller should call set_sizetype soon after calling
5386 this function to select one of the types as sizetype. */
5388 void
5389 build_common_tree_nodes (signed_char)
5390 int signed_char;
5392 error_mark_node = make_node (ERROR_MARK);
5393 TREE_TYPE (error_mark_node) = error_mark_node;
5395 /* Define both `signed char' and `unsigned char'. */
5396 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
5397 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
5399 /* Define `char', which is like either `signed char' or `unsigned char'
5400 but not the same as either. */
5401 char_type_node
5402 = (signed_char
5403 ? make_signed_type (CHAR_TYPE_SIZE)
5404 : make_unsigned_type (CHAR_TYPE_SIZE));
5406 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
5407 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
5408 integer_type_node = make_signed_type (INT_TYPE_SIZE);
5409 /* Define an unsigned integer first. make_unsigned_type and make_signed_type
5410 both call set_sizetype for the first type that we create, and we want this
5411 to be large enough to hold the sizes of various types until we switch to
5412 the real sizetype. */
5413 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
5414 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
5415 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
5416 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
5417 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
5419 intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
5420 intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
5421 intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
5422 intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode));
5423 intTI_type_node = make_signed_type (GET_MODE_BITSIZE (TImode));
5425 unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode));
5426 unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode));
5427 unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode));
5428 unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode));
5429 unsigned_intTI_type_node = make_unsigned_type (GET_MODE_BITSIZE (TImode));
5432 /* For type TYPE, fill in the proper type for TYPE_SIZE and TYPE_SIZE_UNIT. */
5434 static void
5435 fix_sizetype (type)
5436 tree type;
5438 TREE_TYPE (TYPE_SIZE (type)) = bitsizetype;
5439 TREE_TYPE (TYPE_SIZE_UNIT (type)) = sizetype;
5442 /* Call this function after calling build_common_tree_nodes and set_sizetype.
5443 It will fix the previously made nodes to have proper references to
5444 sizetype, and it will create several other common tree nodes. */
5446 void
5447 build_common_tree_nodes_2 (short_double)
5448 int short_double;
5450 fix_sizetype (signed_char_type_node);
5451 fix_sizetype (unsigned_char_type_node);
5452 fix_sizetype (char_type_node);
5453 fix_sizetype (short_integer_type_node);
5454 fix_sizetype (short_unsigned_type_node);
5455 fix_sizetype (integer_type_node);
5456 fix_sizetype (unsigned_type_node);
5457 fix_sizetype (long_unsigned_type_node);
5458 fix_sizetype (long_integer_type_node);
5459 fix_sizetype (long_long_integer_type_node);
5460 fix_sizetype (long_long_unsigned_type_node);
5462 fix_sizetype (intQI_type_node);
5463 fix_sizetype (intHI_type_node);
5464 fix_sizetype (intSI_type_node);
5465 fix_sizetype (intDI_type_node);
5466 fix_sizetype (intTI_type_node);
5467 fix_sizetype (unsigned_intQI_type_node);
5468 fix_sizetype (unsigned_intHI_type_node);
5469 fix_sizetype (unsigned_intSI_type_node);
5470 fix_sizetype (unsigned_intDI_type_node);
5471 fix_sizetype (unsigned_intTI_type_node);
5473 integer_zero_node = build_int_2 (0, 0);
5474 TREE_TYPE (integer_zero_node) = integer_type_node;
5475 integer_one_node = build_int_2 (1, 0);
5476 TREE_TYPE (integer_one_node) = integer_type_node;
5478 size_zero_node = build_int_2 (0, 0);
5479 TREE_TYPE (size_zero_node) = sizetype;
5480 size_one_node = build_int_2 (1, 0);
5481 TREE_TYPE (size_one_node) = sizetype;
5483 void_type_node = make_node (VOID_TYPE);
5484 layout_type (void_type_node); /* Uses size_zero_node */
5486 /* We are not going to have real types in C with less than byte alignment,
5487 so we might as well not have any types that claim to have it. */
5488 TYPE_ALIGN (void_type_node) = BITS_PER_UNIT;
5490 null_pointer_node = build_int_2 (0, 0);
5491 TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
5492 layout_type (TREE_TYPE (null_pointer_node));
5494 ptr_type_node = build_pointer_type (void_type_node);
5495 const_ptr_type_node
5496 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
5498 float_type_node = make_node (REAL_TYPE);
5499 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
5500 layout_type (float_type_node);
5502 double_type_node = make_node (REAL_TYPE);
5503 if (short_double)
5504 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
5505 else
5506 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
5507 layout_type (double_type_node);
5509 long_double_type_node = make_node (REAL_TYPE);
5510 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
5511 layout_type (long_double_type_node);
5513 complex_integer_type_node = make_node (COMPLEX_TYPE);
5514 TREE_TYPE (complex_integer_type_node) = integer_type_node;
5515 layout_type (complex_integer_type_node);
5517 complex_float_type_node = make_node (COMPLEX_TYPE);
5518 TREE_TYPE (complex_float_type_node) = float_type_node;
5519 layout_type (complex_float_type_node);
5521 complex_double_type_node = make_node (COMPLEX_TYPE);
5522 TREE_TYPE (complex_double_type_node) = double_type_node;
5523 layout_type (complex_double_type_node);
5525 complex_long_double_type_node = make_node (COMPLEX_TYPE);
5526 TREE_TYPE (complex_long_double_type_node) = long_double_type_node;
5527 layout_type (complex_long_double_type_node);
5529 #ifdef BUILD_VA_LIST_TYPE
5530 BUILD_VA_LIST_TYPE(va_list_type_node);
5531 #else
5532 va_list_type_node = ptr_type_node;
5533 #endif