|
|
1.1 root 1: /* Language-indepednent node constructors for parse phase of GNU compiler.
1.1.1.2 root 2: Copyright (C) 1987, 1988 Free Software Foundation, Inc.
1.1 root 3:
4: This file is part of GNU CC.
5:
6: GNU CC is distributed in the hope that it will be useful,
7: but WITHOUT ANY WARRANTY. No author or distributor
8: accepts responsibility to anyone for the consequences of using it
9: or for whether it serves any particular purpose or works at all,
10: unless he says so in writing. Refer to the GNU CC General Public
11: License for full details.
12:
13: Everyone is granted permission to copy, modify and redistribute
14: GNU CC, but only under the conditions described in the
15: GNU CC General Public License. A copy of this license is
16: supposed to have been given to you along with GNU CC so you
17: can know your rights and responsibilities. It should be in a
18: file named COPYING. Among other things, the copyright notice
19: and this notice must be preserved on all copies. */
20:
21:
22: /* This file contains the low level primitives for operating on tree nodes,
23: including allocation, list operations, interning of identifiers,
24: construction of data type nodes and statement nodes,
25: and construction of type conversion nodes. It also contains
26: tables index by tree code that describe how to take apart
27: nodes of that code.
28:
29: It is intended to be language-independent, but occasionally
30: calls language-dependent routines defined (for C) in typecheck.c.
31:
32: The low-level allocation routines oballoc and permalloc
33: are used also for allocating many other kinds of objects
34: by all passes of the compiler. */
35:
36: #include "config.h"
37: #include <stdio.h>
38: #include "tree.h"
39: #include "obstack.h"
1.1.1.2 root 40: #include "varargs.h"
1.1 root 41:
42: #define obstack_chunk_alloc xmalloc
43: #define obstack_chunk_free free
44:
45: extern int xmalloc ();
46: extern void free ();
47:
48: /* Tree nodes of permanent duration are allocated in this obstack.
49: They are the identifier nodes, and everything outside of
50: the bodies and parameters of function definitions. */
51:
52: struct obstack permanent_obstack;
53:
1.1.1.2 root 54: /* The initial RTL, and all ..._TYPE nodes, in a function
55: are allocated in this obstack. Usually they are freed at the
56: end of the function, but if the function is inline they are saved. */
57:
58: struct obstack maybepermanent_obstack;
59:
1.1 root 60: /* The contents of the current function definition are allocated
61: in this obstack, and all are freed at the end of the function. */
62:
63: struct obstack temporary_obstack;
64:
1.1.1.2 root 65: /* The tree nodes of an expression are allocated
66: in this obstack, and all are freed at the end of the expression. */
67:
68: struct obstack momentary_obstack;
69:
70: /* This points at either permanent_obstack or maybepermanent_obstack. */
71:
72: struct obstack *saveable_obstack;
73:
74: /* This is same as saveable_obstack during parse and expansion phase;
75: it points to temporary_obstack during optimization.
76: This is the obstack to be used for creating rtl objects. */
77:
78: struct obstack *rtl_obstack;
79:
1.1 root 80: /* This points at either permanent_obstack or temporary_obstack. */
81:
82: struct obstack *current_obstack;
83:
1.1.1.2 root 84: /* This points at either permanent_obstack or temporary_obstack
85: or momentary_obstack. */
86:
87: struct obstack *expression_obstack;
88:
89: /* Addresses of first objects in some obstacks.
90: This is for freeing their entire contents. */
91: char *maybepermanent_firstobj;
92: char *temporary_firstobj;
93: char *momentary_firstobj;
94:
1.1.1.5 root 95: /* Nonzero means all ..._TYPE nodes should be allocated permanently. */
96:
97: int all_types_permanent;
98:
1.1.1.2 root 99: /* Stack of places to restore the momentary obstack back to. */
100:
101: struct momentary_level
102: {
103: /* Pointer back to previous such level. */
104: struct momentary_level *prev;
105: /* First object allocated within this level. */
106: char *base;
107: /* Value of expression_obstack saved at entry to this level. */
108: struct obstack *obstack;
109: };
110:
111: struct momentary_level *momentary_stack;
112:
1.1 root 113: /* Table indexed by tree code giving a string containing a character
114: classifying the tree code. Possibilities are
115: t, d, s, c, r and e. See tree.def for details. */
116:
117: #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
118:
119: char *tree_code_type[] = {
120: #include "tree.def"
121: };
122: #undef DEFTREECODE
123:
124: /* Table indexed by tree code giving number of expression
125: operands beyond the fixed part of the node structure.
126: Not used for types or decls. */
127:
128: #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
129:
130: int tree_code_length[] = {
131: #include "tree.def"
132: };
133: #undef DEFTREECODE
134:
135: /* Counter for assigning unique ids to all tree nodes. */
136:
137: int tree_node_counter = 0;
138:
139: /* Hash table for uniquizing IDENTIFIER_NODEs by name. */
140:
1.1.1.2 root 141: #define MAX_HASH_TABLE 1009
1.1 root 142: static tree hash_table[MAX_HASH_TABLE]; /* id hash buckets */
143:
144: /* Init data for node creation, at the beginning of compilation. */
145:
146: void
147: init_tree ()
148: {
149: obstack_init (&permanent_obstack);
1.1.1.2 root 150:
151: obstack_init (&temporary_obstack);
152: temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0);
153: obstack_init (&momentary_obstack);
154: momentary_firstobj = (char *) obstack_alloc (&momentary_obstack, 0);
155: obstack_init (&maybepermanent_obstack);
156: maybepermanent_firstobj
157: = (char *) obstack_alloc (&maybepermanent_obstack, 0);
158:
1.1 root 159: current_obstack = &permanent_obstack;
1.1.1.2 root 160: expression_obstack = &permanent_obstack;
161: rtl_obstack = saveable_obstack = &permanent_obstack;
1.1 root 162: tree_node_counter = 1;
163: bzero (hash_table, sizeof hash_table);
164: }
165:
166: /* Start allocating on the temporary (per function) obstack.
1.1.1.2 root 167: This is done in start_function before parsing the function body,
168: and before each initialization at top level, and to go back
169: to temporary allocation after doing end_temporary_allocation. */
1.1 root 170:
1.1.1.2 root 171: void
1.1 root 172: temporary_allocation ()
173: {
174: current_obstack = &temporary_obstack;
1.1.1.2 root 175: expression_obstack = &temporary_obstack;
176: rtl_obstack = saveable_obstack = &maybepermanent_obstack;
177: momentary_stack = 0;
178: }
179:
180: /* Start allocating on the permanent obstack but don't
181: free the temporary data. After calling this, call
182: `permanent_allocation' to fully resume permanent allocation status. */
183:
184: void
185: end_temporary_allocation ()
186: {
187: current_obstack = &permanent_obstack;
188: expression_obstack = &permanent_obstack;
189: rtl_obstack = saveable_obstack = &permanent_obstack;
1.1 root 190: }
191:
1.1.1.4 root 192: /* Resume allocating on the temporary obstack, undoing
193: effects of `end_temporary_allocation'. */
194:
195: void
196: resume_temporary_allocation ()
197: {
198: current_obstack = &temporary_obstack;
199: expression_obstack = &temporary_obstack;
200: rtl_obstack = saveable_obstack = &maybepermanent_obstack;
201: }
202:
1.1.1.5 root 203: /* Nonzero if temporary allocation is currently in effect.
204: Zero if currently doing permanent allocation. */
205:
206: int
207: allocation_temporary_p ()
208: {
209: return current_obstack == &temporary_obstack;
210: }
211:
1.1 root 212: /* Go back to allocating on the permanent obstack
213: and free everything in the temporary obstack.
214: This is done in finish_function after fully compiling a function. */
215:
1.1.1.2 root 216: void
1.1 root 217: permanent_allocation ()
218: {
219: /* Free up previous temporary obstack data */
1.1.1.2 root 220: obstack_free (&temporary_obstack, temporary_firstobj);
221: obstack_free (&momentary_obstack, momentary_firstobj);
222: obstack_free (&maybepermanent_obstack, maybepermanent_firstobj);
1.1 root 223:
224: current_obstack = &permanent_obstack;
1.1.1.2 root 225: expression_obstack = &permanent_obstack;
226: rtl_obstack = saveable_obstack = &permanent_obstack;
1.1 root 227: }
228:
1.1.1.2 root 229: /* Save permanently everything on the maybepermanent_obstack. */
230:
231: void
232: preserve_data ()
233: {
234: maybepermanent_firstobj
235: = (char *) obstack_alloc (&maybepermanent_obstack, 0);
236: }
237:
1.1 root 238: /* Allocate SIZE bytes in the current obstack
239: and return a pointer to them.
240: In practice the current obstack is always the temporary one. */
241:
242: char *
243: oballoc (size)
244: int size;
245: {
246: return (char *) obstack_alloc (current_obstack, size);
247: }
248:
249: /* Free the object PTR in the current obstack
250: as well as everything allocated since PTR.
251: In practice the current obstack is always the temporary one. */
252:
253: void
254: obfree (ptr)
255: char *ptr;
256: {
257: obstack_free (current_obstack, ptr);
258: }
259:
260: /* Allocate SIZE bytes in the permanent obstack
261: and return a pointer to them. */
262:
263: char *
264: permalloc (size)
265: long size;
266: {
267: return (char *) obstack_alloc (&permanent_obstack, size);
268: }
269:
1.1.1.2 root 270: /* Start a level of momentary allocation.
271: In C, each compound statement has its own level
272: and that level is freed at the end of each statement.
273: All expression nodes are allocated in the momentary allocation level. */
274:
275: void
276: push_momentary ()
277: {
278: struct momentary_level *tem
279: = (struct momentary_level *) obstack_alloc (&momentary_obstack,
280: sizeof (struct momentary_level));
281: tem->prev = momentary_stack;
282: tem->base = (char *) obstack_base (&momentary_obstack);
283: tem->obstack = expression_obstack;
284: momentary_stack = tem;
285: expression_obstack = &momentary_obstack;
286: }
287:
288: /* Free all the storage in the current momentary-allocation level.
289: In C, this happens at the end of each statement. */
290:
291: void
292: clear_momentary ()
293: {
294: obstack_free (&momentary_obstack, momentary_stack->base);
295: }
296:
297: /* Discard a level of momentary allocation.
298: In C, this happens at the end of each compound statement.
299: Restore the status of expression node allocation
300: that was in effect before this level was created. */
301:
302: void
303: pop_momentary ()
304: {
305: struct momentary_level *tem = momentary_stack;
306: momentary_stack = tem->prev;
307: obstack_free (&momentary_obstack, tem);
308: expression_obstack = tem->obstack;
309: }
310:
311: /* Call when starting to parse a declaration:
312: make expressions in the declaration last the length of the function.
313: Returns an argument that should be passed to resume_momentary later. */
314:
315: int
316: suspend_momentary ()
317: {
318: register int tem = expression_obstack == &momentary_obstack;
1.1.1.4 root 319: expression_obstack = saveable_obstack;
1.1.1.2 root 320: return tem;
321: }
322:
323: /* Call when finished parsing a declaration:
324: restore the treatment of node-allocation that was
325: in effect before the suspension.
326: YES should be the value previously returned by suspend_momentary. */
327:
328: void
329: resume_momentary (yes)
330: int yes;
331: {
332: if (yes)
333: expression_obstack = &momentary_obstack;
334: }
335:
1.1 root 336: /* Return a newly allocated node of code CODE.
337: Initialize the node's unique id and its TREE_PERMANENT flag.
338: For decl and type nodes, some other fields are initialized.
339: The rest of the node is initialized to zero.
340:
341: Achoo! I got a code in the node. */
342:
343: tree
344: make_node (code)
345: enum tree_code code;
346: {
347: register tree t;
348: register int type = *tree_code_type[(int) code];
349: register int length;
1.1.1.2 root 350: register struct obstack *obstack = current_obstack;
1.1 root 351: register int i;
352:
353: switch (type)
354: {
355: case 'd': /* A decl node */
356: length = sizeof (struct tree_decl);
1.1.1.2 root 357: /* All decls in an inline function need to be saved. */
358: if (obstack != &permanent_obstack)
359: obstack = saveable_obstack;
1.1 root 360: break;
361:
362: case 't': /* a type node */
363: length = sizeof (struct tree_type);
1.1.1.2 root 364: /* All data types are put where we can preserve them if nec. */
365: if (obstack != &permanent_obstack)
1.1.1.5 root 366: obstack = all_types_permanent ? &permanent_obstack : saveable_obstack;
1.1 root 367: break;
368:
369: case 's': /* a stmt node */
1.1.1.2 root 370: length = sizeof (struct tree_common)
1.1 root 371: + 2 * sizeof (int)
372: + tree_code_length[(int) code] * sizeof (char *);
1.1.1.2 root 373: /* All stmts are put where we can preserve them if nec. */
374: if (obstack != &permanent_obstack)
375: obstack = saveable_obstack;
1.1 root 376: break;
377:
1.1.1.2 root 378: case 'r': /* a reference */
379: case 'e': /* an expression */
380: obstack = expression_obstack;
381: length = sizeof (struct tree_exp)
382: + (tree_code_length[(int) code] - 1) * sizeof (char *);
383: break;
384:
385: case 'c': /* a constant */
386: obstack = expression_obstack;
387: /* We can't use tree_code_length for this, since the number of words
388: is machine-dependent due to varying alignment of `double'. */
389: if (code == REAL_CST)
390: {
391: length = sizeof (struct tree_real_cst);
392: break;
393: }
394:
395: case 'x': /* something random, like an identifier. */
396: length = sizeof (struct tree_common)
1.1 root 397: + tree_code_length[(int) code] * sizeof (char *);
1.1.1.2 root 398: /* Identifier nodes are always permanent since they are
399: unique in a compiler run. */
400: if (code == IDENTIFIER_NODE) obstack = &permanent_obstack;
1.1 root 401: }
402:
403: t = (tree) obstack_alloc (obstack, length);
404:
405: TREE_UID (t) = tree_node_counter++;
406: TREE_TYPE (t) = 0;
407: TREE_CHAIN (t) = 0;
408: for (i = (length / sizeof (int)) - 1;
1.1.1.2 root 409: i >= sizeof (struct tree_common) / sizeof (int) - 1;
1.1 root 410: i--)
411: ((int *) t)[i] = 0;
412:
413: TREE_SET_CODE (t, code);
414: if (obstack == &permanent_obstack)
415: TREE_PERMANENT (t) = 1;
416:
417: if (type == 'd')
418: {
419: extern int lineno;
420:
421: DECL_ALIGN (t) = 1;
422: DECL_SIZE_UNIT (t) = 1;
423: DECL_VOFFSET_UNIT (t) = 1;
424: DECL_SOURCE_LINE (t) = lineno;
425: DECL_SOURCE_FILE (t) = input_filename;
426: }
427:
428: if (type == 't')
429: {
430: TYPE_ALIGN (t) = 1;
431: TYPE_SIZE_UNIT (t) = 1;
432: TYPE_MAIN_VARIANT (t) = t;
433: }
434:
435: if (type == 'c')
436: {
437: TREE_LITERAL (t) = 1;
438: }
439:
440: return t;
441: }
442:
443: /* Return a new node with the same contents as NODE
444: except that its TREE_CHAIN is zero and it has a fresh uid. */
445:
446: tree
447: copy_node (node)
448: tree node;
449: {
450: register tree t;
451: register enum tree_code code = TREE_CODE (node);
452: register int length;
453: register int i;
454:
455: switch (*tree_code_type[(int) code])
456: {
457: case 'd': /* A decl node */
458: length = sizeof (struct tree_decl);
459: break;
460:
461: case 't': /* a type node */
462: length = sizeof (struct tree_type);
463: break;
464:
465: case 's':
1.1.1.2 root 466: length = sizeof (struct tree_common)
1.1 root 467: + 2 * sizeof (int)
468: + tree_code_length[(int) code] * sizeof (char *);
469: break;
470:
1.1.1.2 root 471: case 'r': /* a reference */
472: case 'e': /* a expression */
473: length = sizeof (struct tree_exp)
474: + (tree_code_length[(int) code] - 1) * sizeof (char *);
475: break;
476:
477: case 'c': /* a constant */
478: /* We can't use tree_code_length for this, since the number of words
479: is machine-dependent due to varying alignment of `double'. */
480: if (code == REAL_CST)
481: {
482: length = sizeof (struct tree_real_cst);
483: break;
484: }
485:
486: case 'x': /* something random, like an identifier. */
487: length = sizeof (struct tree_common)
1.1 root 488: + tree_code_length[(int) code] * sizeof (char *);
489: }
490:
491: t = (tree) obstack_alloc (current_obstack, length);
492:
1.1.1.5 root 493: for (i = ((length + sizeof (int) - 1) / sizeof (int)) - 1;
1.1 root 494: i >= 0;
495: i--)
496: ((int *) t)[i] = ((int *) node)[i];
497:
498: TREE_UID (t) = tree_node_counter++;
499: TREE_CHAIN (t) = 0;
500:
501: TREE_PERMANENT (t) = (current_obstack == &permanent_obstack);
502:
503: return t;
504: }
505:
506: #define HASHBITS 30
507:
508: /* Return an IDENTIFIER_NODE whose name is TEXT (a null-terminated string).
509: If an identifier with that name has previously been referred to,
510: the same node is returned this time. */
511:
512: tree
513: get_identifier (text)
514: register char *text;
515: {
516: register int hi;
517: register int i;
518: register tree idp;
519: register int len;
520:
521: /* Compute length of text in len. */
522: for (len = 0; text[len]; len++);
523:
524: /* Compute hash code */
525: hi = len;
526: for (i = 0; i < len; i++)
527: hi = ((hi * 613) + (unsigned)(text[i]));
528:
529: hi &= (1 << HASHBITS) - 1;
530: hi %= MAX_HASH_TABLE;
531:
532: /* Search table for identifier */
533: for (idp = hash_table[hi]; idp!=NULL; idp = TREE_CHAIN (idp))
534: if (IDENTIFIER_LENGTH (idp) == len &&
535: !strcmp (IDENTIFIER_POINTER (idp), text))
536: return idp; /* <-- return if found */
537:
538: /* Not found, create one, add to chain */
539: idp = make_node (IDENTIFIER_NODE);
540: IDENTIFIER_LENGTH (idp) = len;
541:
542: IDENTIFIER_POINTER (idp) = obstack_copy0 (&permanent_obstack, text, len);
543:
544: TREE_CHAIN (idp) = hash_table[hi];
545: hash_table[hi] = idp;
546: return idp; /* <-- return if created */
547: }
548:
549: /* Return a newly constructed INTEGER_CST node whose constant value
550: is specified by the two ints LOW and HI.
1.1.1.2 root 551: The TREE_TYPE is set to `int'. */
1.1 root 552:
553: tree
554: build_int_2 (low, hi)
555: int low, hi;
556: {
557: register tree t = make_node (INTEGER_CST);
558: TREE_INT_CST_LOW (t) = low;
559: TREE_INT_CST_HIGH (t) = hi;
560: TREE_TYPE (t) = integer_type_node;
561: return t;
562: }
563:
1.1.1.4 root 564: /* Return a new REAL_CST node whose type is TYPE and value is D. */
1.1 root 565:
566: tree
1.1.1.4 root 567: build_real (type, d)
568: tree type;
1.1 root 569: double d;
570: {
571: tree v;
572:
1.1.1.4 root 573: /* Check for valid float value for this type on this target machine;
574: if not, can print error message and store a valid value in D. */
575: #ifdef CHECK_FLOAT_VALUE
576: CHECK_FLOAT_VALUE (TYPE_MODE (type), d);
577: #endif
578:
1.1 root 579: v = make_node (REAL_CST);
1.1.1.4 root 580: TREE_TYPE (v) = type;
1.1 root 581: TREE_REAL_CST (v) = d;
582: return v;
583: }
584:
1.1.1.4 root 585: /* Return a new REAL_CST node whose type is TYPE
586: and whose value is the integer value of the INTEGER_CST node I. */
1.1 root 587:
588: tree
1.1.1.4 root 589: build_real_from_int_cst (type, i)
590: tree type;
1.1 root 591: tree i;
592: {
593: tree v;
1.1.1.2 root 594: double d;
1.1 root 595:
596: v = make_node (REAL_CST);
1.1.1.4 root 597: TREE_TYPE (v) = type;
1.1.1.2 root 598:
599: if (TREE_INT_CST_HIGH (i) < 0)
600: {
601: d = (double) (~ TREE_INT_CST_HIGH (i));
602: d *= ((double) (1 << (HOST_BITS_PER_INT / 2))
603: * (double) (1 << (HOST_BITS_PER_INT / 2)));
604: d += (double) (unsigned) (~ TREE_INT_CST_LOW (i));
605: d = (- d - 1.0);
606: }
607: else
608: {
609: d = (double) TREE_INT_CST_HIGH (i);
610: d *= ((double) (1 << (HOST_BITS_PER_INT / 2))
611: * (double) (1 << (HOST_BITS_PER_INT / 2)));
612: d += (double) (unsigned) TREE_INT_CST_LOW (i);
613: }
614:
1.1.1.6 root 615: /* Check for valid float value for this type on this target machine;
616: if not, can print error message and store a valid value in D. */
617: #ifdef CHECK_FLOAT_VALUE
618: CHECK_FLOAT_VALUE (TYPE_MODE (type), d);
619: #endif
620:
1.1.1.2 root 621: TREE_REAL_CST (v) = d;
1.1 root 622: return v;
623: }
624:
625: /* Return a newly constructed STRING_CST node whose value is
626: the LEN characters at STR.
627: The TREE_TYPE is not initialized. */
628:
629: tree
630: build_string (len, str)
631: int len;
632: char *str;
633: {
634: register tree s = make_node (STRING_CST);
635: TREE_STRING_LENGTH (s) = len;
1.1.1.2 root 636: TREE_STRING_POINTER (s) = obstack_copy0 (saveable_obstack, str, len);
1.1 root 637: return s;
638: }
639:
640: /* Return a newly constructed COMPLEX_CST node whose value is
641: specified by the real and imaginary parts REAL and IMAG.
642: Both REAL and IMAG should be constant nodes.
643: The TREE_TYPE is not initialized. */
644:
645: tree
646: build_complex (real, imag)
647: tree real, imag;
648: {
649: register tree t = make_node (COMPLEX_CST);
650: TREE_REALPART (t) = real;
651: TREE_IMAGPART (t) = imag;
652: return t;
653: }
654:
655: /* Return 1 if EXPR is the integer constant zero. */
656:
657: int
658: integer_zerop (expr)
659: tree expr;
660: {
1.1.1.2 root 661: return (TREE_CODE (expr) == INTEGER_CST
662: && TREE_INT_CST_LOW (expr) == 0
663: && TREE_INT_CST_HIGH (expr) == 0);
1.1 root 664: }
665:
666: /* Return 1 if EXPR is the integer constant one. */
667:
668: int
669: integer_onep (expr)
670: tree expr;
671: {
1.1.1.2 root 672: return (TREE_CODE (expr) == INTEGER_CST
673: && TREE_INT_CST_LOW (expr) == 1
674: && TREE_INT_CST_HIGH (expr) == 0);
1.1 root 675: }
676:
677: /* Return 1 if EXPR is an integer containing all 1's
678: in as much precision as it contains. */
679:
680: int
681: integer_all_onesp (expr)
682: tree expr;
683: {
684: register int prec;
685: register int uns;
686:
687: if (TREE_CODE (expr) != INTEGER_CST)
688: return 0;
689:
1.1.1.2 root 690: uns = TREE_UNSIGNED (TREE_TYPE (expr));
1.1 root 691: if (!uns)
692: return TREE_INT_CST_LOW (expr) == -1 && TREE_INT_CST_HIGH (expr) == -1;
693:
694: prec = TYPE_PRECISION (TREE_TYPE (expr));
695: if (prec >= HOST_BITS_PER_INT)
696: return TREE_INT_CST_LOW (expr) == -1
697: && TREE_INT_CST_HIGH (expr) == (1 << (prec - HOST_BITS_PER_INT)) - 1;
698: else
699: return TREE_INT_CST_LOW (expr) == (1 << prec) - 1;
700: }
701:
702: /* Return the length of a chain of nodes chained through TREE_CHAIN.
703: We expect a null pointer to mark the end of the chain.
704: This is the Lisp primitive `length'. */
705:
706: int
707: list_length (t)
708: tree t;
709: {
710: register tree tail;
711: register int len = 0;
712:
713: for (tail = t; tail; tail = TREE_CHAIN (tail))
714: len++;
715:
716: return len;
717: }
718:
719: /* Concatenate two chains of nodes (chained through TREE_CHAIN)
720: by modifying the last node in chain 1 to point to chain 2.
721: This is the Lisp primitive `nconc'. */
722:
723: tree
724: chainon (op1, op2)
725: tree op1, op2;
726: {
727: tree t;
728:
729: if (op1)
730: {
731: for (t = op1; TREE_CHAIN (t); t = TREE_CHAIN (t))
732: if (t == op2) abort (); /* Circularity being created */
733: TREE_CHAIN (t) = op2;
734: return op1;
735: }
736: else return op2;
737: }
738:
739: /* Return a newly created TREE_LIST node whose
740: purpose and value fields are PARM and VALUE. */
741:
742: tree
743: build_tree_list (parm, value)
744: tree parm, value;
745: {
746: register tree t = make_node (TREE_LIST);
747: TREE_PURPOSE (t) = parm;
748: TREE_VALUE (t) = value;
749: return t;
750: }
751:
752: /* Return a newly created TREE_LIST node whose
753: purpose and value fields are PARM and VALUE
754: and whose TREE_CHAIN is CHAIN. */
755:
756: tree
757: tree_cons (purpose, value, chain)
758: tree purpose, value, chain;
759: {
760: register tree node = make_node (TREE_LIST);
761: TREE_CHAIN (node) = chain;
762: TREE_PURPOSE (node) = purpose;
763: TREE_VALUE (node) = value;
764: return node;
765: }
766:
1.1.1.2 root 767: /* Same as `tree_cons' but make a permanent object. */
768:
769: tree
770: perm_tree_cons (purpose, value, chain)
771: tree purpose, value, chain;
772: {
773: register tree node;
774: register struct obstack *ambient_obstack = current_obstack;
775: current_obstack = &permanent_obstack;
776:
777: node = make_node (TREE_LIST);
778: TREE_CHAIN (node) = chain;
779: TREE_PURPOSE (node) = purpose;
780: TREE_VALUE (node) = value;
781:
782: current_obstack = ambient_obstack;
783: return node;
784: }
785:
1.1.1.7 root 786: /* Same as `tree_cons', but make this node temporary, regardless. */
787:
788: tree
789: temp_tree_cons (purpose, value, chain)
790: tree purpose, value, chain;
791: {
792: register tree node;
793: register struct obstack *ambient_obstack = current_obstack;
794: current_obstack = &temporary_obstack;
795:
796: node = make_node (TREE_LIST);
797: TREE_CHAIN (node) = chain;
798: TREE_PURPOSE (node) = purpose;
799: TREE_VALUE (node) = value;
800:
801: current_obstack = ambient_obstack;
802: return node;
803: }
804:
1.1.1.9 ! root 805: /* Same as `tree_cons', but save this node if the function's RTL is saved. */
! 806:
! 807: tree
! 808: saveable_tree_cons (purpose, value, chain)
! 809: tree purpose, value, chain;
! 810: {
! 811: register tree node;
! 812: register struct obstack *ambient_obstack = current_obstack;
! 813: current_obstack = saveable_obstack;
! 814:
! 815: node = make_node (TREE_LIST);
! 816: TREE_CHAIN (node) = chain;
! 817: TREE_PURPOSE (node) = purpose;
! 818: TREE_VALUE (node) = value;
! 819:
! 820: current_obstack = ambient_obstack;
! 821: return node;
! 822: }
! 823:
1.1 root 824: /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
825:
826: tree
827: tree_last (chain)
828: register tree chain;
829: {
830: register tree next;
831: if (chain)
832: while (next = TREE_CHAIN (chain))
833: chain = next;
834: return chain;
835: }
836:
837: /* Reverse the order of elements in the chain T,
838: and return the new head of the chain (old last element). */
839:
840: tree
841: nreverse (t)
842: tree t;
843: {
844: register tree prev = 0, decl, next;
845: for (decl = t; decl; decl = next)
846: {
847: next = TREE_CHAIN (decl);
848: TREE_CHAIN (decl) = prev;
849: prev = decl;
850: }
851: return prev;
852: }
853:
854: /* Return the size nominally occupied by an object of type TYPE
855: when it resides in memory. The value is measured in units of bytes,
856: and its data type is that normally used for type sizes
857: (which is the first type created by make_signed_type or
858: make_unsigned_type). */
859:
860: tree
861: size_in_bytes (type)
862: tree type;
863: {
864: if (type == error_mark_node)
865: return integer_zero_node;
1.1.1.2 root 866: if (TYPE_SIZE (type) == 0)
867: {
868: incomplete_type_error (0, type);
869: return integer_zero_node;
870: }
1.1 root 871: return convert_units (TYPE_SIZE (type), TYPE_SIZE_UNIT (type),
872: BITS_PER_UNIT);
873: }
874:
1.1.1.2 root 875: /* Return the size of TYPE (in bytes) as an integer,
876: or return -1 if the size can vary. */
877:
878: int
879: int_size_in_bytes (type)
880: tree type;
881: {
882: int size;
883: if (type == error_mark_node)
884: return 0;
885: if (TYPE_SIZE (type) == 0)
886: return -1;
887: if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
888: return -1;
889: size = TREE_INT_CST_LOW (TYPE_SIZE (type)) * TYPE_SIZE_UNIT (type);
890: return (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
891: }
892:
1.1.1.7 root 893: /* Return, as an INTEGER_CST node, the number of elements for
894: TYPE (which is an ARRAY_TYPE). */
895:
896: tree
897: array_type_nelts (type)
898: tree type;
899: {
900: tree index_type = TYPE_DOMAIN (type);
901: return (tree_int_cst_equal (TYPE_MIN_VALUE (index_type), integer_zero_node)
902: ? TYPE_MAX_VALUE (index_type)
903: : fold (build (MINUS_EXPR, integer_type_node,
904: TYPE_MAX_VALUE (index_type),
905: TYPE_MIN_VALUE (index_type))));
906: }
907:
1.1 root 908: /* Return nonzero if arg is static -- a reference to an object in
909: static storage. This is not the same as the C meaning of `static'. */
910:
911: int
912: staticp (arg)
913: tree arg;
914: {
915: register enum tree_code code = TREE_CODE (arg);
916:
1.1.1.2 root 917: if ((code == VAR_DECL || code == FUNCTION_DECL || code == CONSTRUCTOR)
1.1 root 918: && (TREE_STATIC (arg) || TREE_EXTERNAL (arg)))
919: return 1;
920:
1.1.1.2 root 921: if (code == STRING_CST)
922: return 1;
923:
1.1 root 924: if (code == COMPONENT_REF)
925: return staticp (TREE_OPERAND (arg, 0));
926:
1.1.1.2 root 927: if (code == ARRAY_REF)
928: {
929: if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
930: && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
931: return staticp (TREE_OPERAND (arg, 0));
932: }
933:
1.1 root 934: return 0;
935: }
936:
1.1.1.2 root 937: /* Return nonzero if REF is an lvalue valid for this language.
938: Lvalues can be assigned, unless they have TREE_READONLY.
939: Lvalues can have their address taken, unless they have TREE_REGDECL. */
1.1 root 940:
941: int
1.1.1.2 root 942: lvalue_p (ref)
1.1 root 943: tree ref;
944: {
945: register enum tree_code code = TREE_CODE (ref);
946:
1.1.1.2 root 947: if (language_lvalue_valid (ref))
948: switch (code)
949: {
950: case COMPONENT_REF:
951: return lvalue_p (TREE_OPERAND (ref, 0));
952:
953: case STRING_CST:
954: return 1;
955:
956: case INDIRECT_REF:
957: case ARRAY_REF:
958: case VAR_DECL:
959: case PARM_DECL:
960: case RESULT_DECL:
961: case ERROR_MARK:
962: if (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE)
963: return 1;
1.1.1.7 root 964: break;
965:
966: case CALL_EXPR:
967: if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
968: return 1;
1.1.1.2 root 969: }
1.1 root 970: return 0;
971: }
1.1.1.2 root 972:
973: /* Return nonzero if REF is an lvalue valid for this language;
974: otherwise, print an error message and return zero. */
975:
976: int
977: lvalue_or_else (ref, string)
978: tree ref;
979: char *string;
980: {
981: int win = lvalue_p (ref);
982: if (! win)
983: error ("invalid lvalue in %s", string);
984: return win;
985: }
1.1 root 986:
987: /* This should be applied to any node which may be used in more than one place,
988: but must be evaluated only once. Normally, the code generator would
989: reevaluate the node each time; this forces it to compute it once and save
990: the result. This is done by encapsulating the node in a SAVE_EXPR. */
991:
992: tree
993: save_expr (expr)
994: tree expr;
995: {
996: register tree t = fold (expr);
997:
1.1.1.2 root 998: /* If the tree evaluates to a constant, then we don't want to hide that
1.1 root 999: fact (i.e. this allows further folding, and direct checks for constants).
1000: Since it is no problem to reevaluate literals, we just return the
1001: literal node. */
1002:
1003: if (TREE_LITERAL (t) || TREE_READONLY (t) || TREE_CODE (t) == SAVE_EXPR)
1004: return t;
1005:
1.1.1.2 root 1006: return build (SAVE_EXPR, TREE_TYPE (expr), t, NULL);
1.1 root 1007: }
1008:
1009: /* Stabilize a reference so that we can use it any number of times
1010: without causing its operands to be evaluated more than once.
1.1.1.2 root 1011: Returns the stabilized reference.
1012:
1013: Also allows conversion expressions whose operands are references.
1014: Any other kind of expression is returned unchanged. */
1.1 root 1015:
1016: tree
1017: stabilize_reference (ref)
1018: tree ref;
1019: {
1020: register tree result;
1021: register enum tree_code code = TREE_CODE (ref);
1022:
1.1.1.2 root 1023: switch (code)
1.1 root 1024: {
1.1.1.2 root 1025: case VAR_DECL:
1026: case PARM_DECL:
1027: case RESULT_DECL:
1.1 root 1028: result = ref;
1.1.1.2 root 1029: break;
1030:
1031: case NOP_EXPR:
1032: case CONVERT_EXPR:
1033: case FLOAT_EXPR:
1034: case FIX_TRUNC_EXPR:
1035: case FIX_FLOOR_EXPR:
1036: case FIX_ROUND_EXPR:
1037: case FIX_CEIL_EXPR:
1038: result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
1039: break;
1040:
1041: case INDIRECT_REF:
1042: result = build_nt (INDIRECT_REF, save_expr (TREE_OPERAND (ref, 0)));
1043: break;
1044:
1045: case COMPONENT_REF:
1046: result = build_nt (COMPONENT_REF,
1047: stabilize_reference (TREE_OPERAND (ref, 0)),
1048: TREE_OPERAND (ref, 1));
1049: break;
1050:
1051: case ARRAY_REF:
1052: result = build_nt (ARRAY_REF, stabilize_reference (TREE_OPERAND (ref, 0)),
1053: save_expr (TREE_OPERAND (ref, 1)));
1054: break;
1055:
1056: /* If arg isn't a kind of lvalue we recognize, make no change.
1057: Caller should recognize the error for an invalid lvalue. */
1058: default:
1059: return ref;
1060:
1061: case ERROR_MARK:
1.1 root 1062: return error_mark_node;
1063: }
1064:
1065: TREE_TYPE (result) = TREE_TYPE (ref);
1.1.1.2 root 1066: TREE_READONLY (result) = TREE_READONLY (ref);
1.1 root 1067: TREE_VOLATILE (result) = TREE_VOLATILE (ref);
1.1.1.2 root 1068: TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
1.1 root 1069:
1070: return result;
1071: }
1072:
1073: /* Low-level constructors for expressions. */
1074:
1.1.1.2 root 1075: /* Build an expression of code CODE, data type TYPE,
1076: and operands as specified by the arguments ARG1 and following arguments.
1077: Expressions and reference nodes can be created this way.
1078: Constants, decls, types and misc nodes cannot be. */
1.1 root 1079:
1080: tree
1.1.1.2 root 1081: build (va_alist)
1082: va_dcl
1.1 root 1083: {
1.1.1.2 root 1084: register va_list p;
1085: enum tree_code code;
1086: register tree t;
1087: register int length;
1088: register int i;
1089:
1090: va_start (p);
1.1 root 1091:
1.1.1.2 root 1092: code = va_arg (p, enum tree_code);
1093: t = make_node (code);
1094: length = tree_code_length[(int) code];
1095: TREE_TYPE (t) = va_arg (p, tree);
1096:
1097: if (length == 2)
1098: {
1099: /* This is equivalent to the loop below, but faster. */
1100: register tree arg0 = va_arg (p, tree);
1101: register tree arg1 = va_arg (p, tree);
1102: TREE_OPERAND (t, 0) = arg0;
1103: TREE_OPERAND (t, 1) = arg1;
1104: TREE_VOLATILE (t)
1105: = (arg0 && TREE_VOLATILE (arg0)) || (arg1 && TREE_VOLATILE (arg1));
1106: }
1107: else
1108: {
1109: for (i = 0; i < length; i++)
1110: {
1111: register tree operand = va_arg (p, tree);
1112: TREE_OPERAND (t, i) = operand;
1113: if (operand && TREE_VOLATILE (operand))
1114: TREE_VOLATILE (t) = 1;
1115: }
1116: }
1117: va_end (p);
1.1 root 1118: return t;
1119: }
1120:
1.1.1.2 root 1121: /* Similar except don't specify the TREE_TYPE
1122: and leave the TREE_VOLATILE as 0.
1123: It is permissible for arguments to be null,
1124: or even garbage if their values do not matter. */
1.1 root 1125:
1126: tree
1.1.1.2 root 1127: build_nt (va_alist)
1128: va_dcl
1.1 root 1129: {
1.1.1.2 root 1130: register va_list p;
1131: register enum tree_code code;
1132: register tree t;
1133: register int length;
1134: register int i;
1135:
1136: va_start (p);
1.1 root 1137:
1.1.1.2 root 1138: code = va_arg (p, enum tree_code);
1139: t = make_node (code);
1140: length = tree_code_length[(int) code];
1141:
1142: for (i = 0; i < length; i++)
1143: TREE_OPERAND (t, i) = va_arg (p, tree);
1144:
1145: va_end (p);
1.1 root 1146: return t;
1147: }
1.1.1.2 root 1148:
1149: /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
1150: We do NOT enter this node in any sort of symbol table.
1.1 root 1151:
1.1.1.2 root 1152: layout_decl is used to set up the decl's storage layout.
1153: Other slots are initialized to 0 or null pointers. */
1.1 root 1154:
1155: tree
1.1.1.2 root 1156: build_decl (code, name, type)
1157: enum tree_code code;
1158: tree name, type;
1159: {
1160: register tree t;
1161:
1162: t = make_node (code);
1163:
1164: /* if (type == error_mark_node)
1165: type = integer_type_node; */
1166: /* That is not done, deliberately, so that having error_mark_node
1167: as the type can suppress useless errors in the use of this variable. */
1168:
1169: DECL_NAME (t) = name;
1170: TREE_TYPE (t) = type;
1171: DECL_ARGUMENTS (t) = NULL_TREE;
1172: DECL_INITIAL (t) = NULL_TREE;
1173:
1174: if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
1175: layout_decl (t, 0);
1176: else if (code == FUNCTION_DECL)
1177: DECL_MODE (t) = FUNCTION_MODE;
1178:
1.1 root 1179: return t;
1180: }
1181:
1.1.1.7 root 1182: #if 0
1.1 root 1183: /* Low-level constructors for statements.
1184: These constructors all expect source file name and line number
1185: as arguments, as well as enough arguments to fill in the data
1186: in the statement node. */
1187:
1188: tree
1189: build_goto (filename, line, label)
1190: char *filename;
1191: int line;
1192: tree label;
1193: {
1194: register tree t = make_node (GOTO_STMT);
1195: STMT_SOURCE_FILE (t) = filename;
1196: STMT_SOURCE_LINE (t) = line;
1197: STMT_BODY (t) = label;
1198: return t;
1199: }
1200:
1201: tree
1202: build_return (filename, line, arg)
1203: char *filename;
1204: int line;
1205: tree arg;
1206: {
1207: register tree t = make_node (RETURN_STMT);
1208:
1209: STMT_SOURCE_FILE (t) = filename;
1210: STMT_SOURCE_LINE (t) = line;
1211: STMT_BODY (t) = arg;
1212: return t;
1213: }
1214:
1215: tree
1216: build_expr_stmt (filename, line, expr)
1217: char *filename;
1218: int line;
1219: tree expr;
1220: {
1221: register tree t = make_node (EXPR_STMT);
1222:
1223: STMT_SOURCE_FILE (t) = filename;
1224: STMT_SOURCE_LINE (t) = line;
1225: STMT_BODY (t) = expr;
1226: return t;
1227: }
1228:
1229: tree
1230: build_if (filename, line, cond, thenclause, elseclause)
1231: char *filename;
1232: int line;
1233: tree cond, thenclause, elseclause;
1234: {
1235: register tree t = make_node (IF_STMT);
1236:
1237: STMT_SOURCE_FILE (t) = filename;
1238: STMT_SOURCE_LINE (t) = line;
1239: STMT_COND (t) = cond;
1240: STMT_THEN (t) = thenclause;
1241: STMT_ELSE (t) = elseclause;
1242: return t;
1243: }
1244:
1245: tree
1246: build_exit (filename, line, cond)
1247: char *filename;
1248: int line;
1249: tree cond;
1250: {
1251: register tree t = make_node (EXIT_STMT);
1252: STMT_SOURCE_FILE (t) = filename;
1253: STMT_SOURCE_LINE (t) = line;
1254: STMT_BODY (t) = cond;
1255: return t;
1256: }
1257:
1258: tree
1259: build_asm_stmt (filename, line, asmcode)
1260: char *filename;
1261: int line;
1262: tree asmcode;
1263: {
1264: register tree t = make_node (ASM_STMT);
1265: STMT_SOURCE_FILE (t) = filename;
1266: STMT_SOURCE_LINE (t) = line;
1267: STMT_BODY (t) = asmcode;
1268: return t;
1269: }
1270:
1271: tree
1272: build_case (filename, line, object, cases)
1273: char *filename;
1274: int line;
1275: tree object, cases;
1276: {
1277: register tree t = make_node (CASE_STMT);
1278: STMT_SOURCE_FILE (t) = filename;
1279: STMT_SOURCE_LINE (t) = line;
1280: STMT_CASE_INDEX (t) = object;
1281: STMT_CASE_LIST (t) = cases;
1282: return t;
1283: }
1284:
1285: tree
1.1.1.7 root 1286: build_loop (filename, line, body)
1.1 root 1287: char *filename;
1288: int line;
1.1.1.7 root 1289: tree body;
1.1 root 1290: {
1.1.1.7 root 1291: register tree t = make_node (LOOP_STMT);
1.1 root 1292: STMT_SOURCE_FILE (t) = filename;
1293: STMT_SOURCE_LINE (t) = line;
1294: STMT_BODY (t) = body;
1295: return t;
1296: }
1297:
1298: tree
1.1.1.7 root 1299: build_compound (filename, line, body)
1.1 root 1300: char *filename;
1301: int line;
1302: tree body;
1303: {
1.1.1.7 root 1304: register tree t = make_node (COMPOUND_STMT);
1.1 root 1305: STMT_SOURCE_FILE (t) = filename;
1306: STMT_SOURCE_LINE (t) = line;
1307: STMT_BODY (t) = body;
1308: return t;
1309: }
1310:
1.1.1.7 root 1311: #endif /* 0 */
1312:
1313: /* LET_STMT nodes are used to represent the structure of binding contours
1314: and declarations, once those contours have been exited and their contents
1315: compiled. This information is used for outputting debugging info. */
1316:
1.1 root 1317: tree
1.1.1.7 root 1318: build_let (filename, line, vars, body, supercontext, tags)
1.1 root 1319: char *filename;
1320: int line;
1.1.1.7 root 1321: tree vars, body, supercontext, tags;
1.1 root 1322: {
1.1.1.7 root 1323: register tree t = make_node (LET_STMT);
1.1 root 1324: STMT_SOURCE_FILE (t) = filename;
1325: STMT_SOURCE_LINE (t) = line;
1.1.1.7 root 1326: STMT_VARS (t) = vars;
1.1 root 1327: STMT_BODY (t) = body;
1.1.1.7 root 1328: STMT_SUPERCONTEXT (t) = supercontext;
1329: STMT_BIND_SIZE (t) = 0;
1330: STMT_TYPE_TAGS (t) = tags;
1.1 root 1331: return t;
1332: }
1333:
1334: /* Return a type like TYPE except that its TREE_READONLY is CONSTP
1335: and its TREE_VOLATILE is VOLATILEP.
1336:
1337: Such variant types already made are recorded so that duplicates
1338: are not made.
1339:
1340: A variant types should never be used as the type of an expression.
1341: Always copy the variant information into the TREE_READONLY
1342: and TREE_VOLATILE of the expression, and then give the expression
1343: as its type the "main variant", the variant whose TREE_READONLY
1344: and TREE_VOLATILE are zero. Use TYPE_MAIN_VARIANT to find the
1345: main variant. */
1346:
1347: tree
1348: build_type_variant (type, constp, volatilep)
1349: tree type;
1350: int constp, volatilep;
1351: {
1352: register tree t, m = TYPE_MAIN_VARIANT (type);
1353: register struct obstack *ambient_obstack = current_obstack;
1354:
1355: /* Treat any nonzero argument as 1. */
1356: constp = !!constp;
1357: volatilep = !!volatilep;
1358:
1359: /* First search the chain variants for one that is what we want. */
1360:
1361: for (t = m; t; t = TYPE_NEXT_VARIANT (t))
1362: if (constp == TREE_READONLY (t)
1363: && volatilep == TREE_VOLATILE (t))
1364: return t;
1365:
1366: /* We need a new one. */
1.1.1.2 root 1367: current_obstack
1368: = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
1.1 root 1369:
1370: t = copy_node (type);
1371: TREE_READONLY (t) = constp;
1372: TREE_VOLATILE (t) = volatilep;
1373: TYPE_POINTER_TO (t) = 0;
1.1.1.7 root 1374: TYPE_REFERENCE_TO (t) = 0;
1.1 root 1375:
1376: /* Add this type to the chain of variants of TYPE. */
1377: TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
1378: TYPE_NEXT_VARIANT (m) = t;
1379:
1380: current_obstack = ambient_obstack;
1381: return t;
1382: }
1383:
1.1.1.2 root 1384: /* Hashing of types so that we don't make duplicates.
1385: The entry point is `type_hash_canon'. */
1386:
1387: /* Each hash table slot is a bucket containing a chain
1388: of these structures. */
1389:
1390: struct type_hash
1391: {
1392: struct type_hash *next; /* Next structure in the bucket. */
1393: int hashcode; /* Hash code of this type. */
1394: tree type; /* The type recorded here. */
1395: };
1396:
1397: /* Now here is the hash table. When recording a type, it is added
1398: to the slot whose index is the hash code mod the table size.
1399: Note that the hash table is used for several kinds of types
1400: (function types, array types and array index range types, for now).
1401: While all these live in the same table, they are completely independent,
1402: and the hash code is computed differently for each of these. */
1403:
1.1.1.7 root 1404: #define TYPE_HASH_SIZE 59
1.1.1.2 root 1405: struct type_hash *type_hash_table[TYPE_HASH_SIZE];
1406:
1407: /* Here is how primitive or already-canonicalized types' hash
1408: codes are made. */
1409: #define TYPE_HASH(TYPE) TREE_UID (TYPE)
1410:
1411: /* Compute a hash code for a list of types (chain of TREE_LIST nodes
1412: with types in the TREE_VALUE slots), by adding the hash codes
1413: of the individual types. */
1414:
1415: int
1416: type_hash_list (list)
1417: tree list;
1418: {
1419: register int hashcode;
1420: register tree tail;
1421: for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
1422: hashcode += TYPE_HASH (TREE_VALUE (tail));
1423: return hashcode;
1424: }
1425:
1426: /* Look in the type hash table for a type isomorphic to TYPE.
1427: If one is found, return it. Otherwise return 0. */
1428:
1429: tree
1430: type_hash_lookup (hashcode, type)
1431: int hashcode;
1432: tree type;
1433: {
1434: register struct type_hash *h;
1435: for (h = type_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
1436: if (h->hashcode == hashcode
1437: && TREE_CODE (h->type) == TREE_CODE (type)
1438: && TREE_TYPE (h->type) == TREE_TYPE (type)
1439: && (TYPE_MAX_VALUE (h->type) == TYPE_MAX_VALUE (type)
1440: || tree_int_cst_equal (TYPE_MAX_VALUE (h->type),
1441: TYPE_MAX_VALUE (type)))
1442: && (TYPE_MIN_VALUE (h->type) == TYPE_MIN_VALUE (type)
1443: || tree_int_cst_equal (TYPE_MIN_VALUE (h->type),
1444: TYPE_MIN_VALUE (type)))
1445: && (TYPE_DOMAIN (h->type) == TYPE_DOMAIN (type)
1446: || (TREE_CODE (TYPE_DOMAIN (h->type)) == TREE_LIST
1447: && TREE_CODE (TYPE_DOMAIN (type)) == TREE_LIST
1448: && type_list_equal (TYPE_DOMAIN (h->type), TYPE_DOMAIN (type)))))
1449: return h->type;
1450: return 0;
1451: }
1452:
1453: /* Add an entry to the type-hash-table
1454: for a type TYPE whose hash code is HASHCODE. */
1455:
1456: void
1457: type_hash_add (hashcode, type)
1458: int hashcode;
1459: tree type;
1460: {
1461: register struct type_hash *h;
1462:
1463: h = (struct type_hash *) oballoc (sizeof (struct type_hash));
1464: h->hashcode = hashcode;
1465: h->type = type;
1466: h->next = type_hash_table[hashcode % TYPE_HASH_SIZE];
1467: type_hash_table[hashcode % TYPE_HASH_SIZE] = h;
1468: }
1469:
1470: /* Given TYPE, and HASHCODE its hash code, return the canonical
1471: object for an identical type if one already exists.
1472: Otherwise, return TYPE, and record it as the canonical object
1473: if it is a permanent object.
1474:
1475: To use this function, first create a type of the sort you want.
1476: Then compute its hash code from the fields of the type that
1477: make it different from other similar types.
1478: Then call this function and use the value.
1479: This function frees the type you pass in if it is a duplicate. */
1480:
1481: /* Set to 1 to debug without canonicalization. Never set by program. */
1482: int debug_no_type_hash = 0;
1483:
1484: tree
1485: type_hash_canon (hashcode, type)
1486: int hashcode;
1487: tree type;
1488: {
1489: tree t1;
1490:
1491: if (debug_no_type_hash)
1492: return type;
1493:
1494: t1 = type_hash_lookup (hashcode, type);
1495: if (t1 != 0)
1496: {
1497: struct obstack *o
1498: = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
1499: obstack_free (o, type);
1500: return t1;
1501: }
1502:
1503: /* If this is a new type, record it for later reuse. */
1504: if (current_obstack == &permanent_obstack)
1505: type_hash_add (hashcode, type);
1506:
1507: return type;
1508: }
1509:
1510: /* Given two lists of types
1511: (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
1.1.1.7 root 1512: return 1 if the lists contain the same types in the same order.
1513: Also, the TREE_PURPOSEs must match. */
1.1.1.2 root 1514:
1515: int
1516: type_list_equal (l1, l2)
1517: tree l1, l2;
1518: {
1519: register tree t1, t2;
1520: for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
1.1.1.7 root 1521: {
1522: if (TREE_VALUE (t1) != TREE_VALUE (t2))
1523: return 0;
1524: if (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
1525: && !simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
1526: return 0;
1527: }
1.1.1.2 root 1528:
1529: return t1 == t2;
1530: }
1531:
1532: /* Nonzero if integer constants T1 and T2
1533: represent the same constant value. */
1534:
1535: int
1536: tree_int_cst_equal (t1, t2)
1537: tree t1, t2;
1538: {
1539: if (t1 == t2)
1540: return 1;
1541: if (t1 == 0 || t2 == 0)
1542: return 0;
1543: if (TREE_CODE (t1) == INTEGER_CST
1544: && TREE_CODE (t2) == INTEGER_CST
1545: && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
1546: && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
1547: return 1;
1548: return 0;
1549: }
1550:
1551: /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
1552: The precise way of comparison depends on their data type. */
1553:
1554: int
1555: tree_int_cst_lt (t1, t2)
1556: tree t1, t2;
1557: {
1558: if (t1 == t2)
1559: return 0;
1560:
1561: if (!TREE_UNSIGNED (TREE_TYPE (t1)))
1562: return INT_CST_LT (t1, t2);
1563: return INT_CST_LT_UNSIGNED (t1, t2);
1564: }
1.1.1.7 root 1565:
1566: /* Compare two constructor-element-type constants. */
1567:
1568: int
1569: simple_cst_equal (t1, t2)
1570: tree t1, t2;
1571: {
1572: register enum tree_code code1, code2;
1573:
1574: if (t1 == t2)
1575: return 1;
1576: if (t1 == 0 || t2 == 0)
1577: return 0;
1578:
1579: code1 = TREE_CODE (t1);
1580: code2 = TREE_CODE (t2);
1581:
1582: if (code1 == NOP_EXPR || code1 == CONVERT_EXPR)
1583: if (code2 == NOP_EXPR || code2 == CONVERT_EXPR)
1584: return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1585: else
1586: return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
1587: else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR)
1588: return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
1589:
1590: if (code1 != code2)
1591: return 0;
1592:
1593: switch (code1)
1594: {
1595: case INTEGER_CST:
1596: return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
1597: && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
1598:
1599: case REAL_CST:
1600: return TREE_REAL_CST (t1) == TREE_REAL_CST (t2);
1601:
1602: case STRING_CST:
1603: return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
1604: && !strcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2));
1605:
1606: case CONSTRUCTOR:
1607: abort ();
1608:
1609: case VAR_DECL:
1610: case PARM_DECL:
1611: case CONST_DECL:
1612: return 0;
1613:
1614: case PLUS_EXPR:
1615: case MINUS_EXPR:
1616: case MULT_EXPR:
1617: case TRUNC_DIV_EXPR:
1618: case TRUNC_MOD_EXPR:
1619: case LSHIFT_EXPR:
1620: case RSHIFT_EXPR:
1621: return (simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
1622: && simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
1623:
1624: case NEGATE_EXPR:
1625: case ADDR_EXPR:
1626: case REFERENCE_EXPR:
1627: return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1628:
1629: default:
1630: abort ();
1631: }
1632: }
1.1.1.2 root 1633:
1.1 root 1634: /* Constructors for pointer, array and function types.
1635: (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
1636: constructed by language-dependent code, not here.) */
1637:
1.1.1.2 root 1638: /* Construct, lay out and return the type of pointers to TO_TYPE.
1639: If such a type has already been constructed, reuse it. */
1640:
1.1 root 1641: tree
1642: build_pointer_type (to_type)
1643: tree to_type;
1644: {
1645: register tree t = TYPE_POINTER_TO (to_type);
1646: register struct obstack *ambient_obstack = current_obstack;
1.1.1.4 root 1647: register struct obstack *ambient_saveable_obstack = saveable_obstack;
1.1 root 1648:
1649: /* First, if we already have a type for pointers to TO_TYPE, use it. */
1650:
1651: if (t)
1652: return t;
1653:
1654: /* We need a new one. If TO_TYPE is permanent, make this permanent too. */
1.1.1.4 root 1655: if (TREE_PERMANENT (to_type))
1656: {
1657: current_obstack = &permanent_obstack;
1658: saveable_obstack = &permanent_obstack;
1659: }
1.1 root 1660:
1661: t = make_node (POINTER_TYPE);
1662: TREE_TYPE (t) = to_type;
1663:
1664: /* Record this type as the pointer to TO_TYPE. */
1665: TYPE_POINTER_TO (to_type) = t;
1666:
1.1.1.2 root 1667: /* Lay out the type. This function has many callers that are concerned
1668: with expression-construction, and this simplifies them all.
1669: Also, it guarantees the TYPE_SIZE is permanent if the type is. */
1670: layout_type (t);
1.1 root 1671:
1672: current_obstack = ambient_obstack;
1.1.1.4 root 1673: saveable_obstack = ambient_saveable_obstack;
1.1 root 1674: return t;
1675: }
1676:
1.1.1.8 root 1677: /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
1678: MAXVAL should be the maximum value in the domain
1679: (one less than the length of the array). */
1680:
1681: tree
1682: build_index_type (maxval)
1683: tree maxval;
1684: {
1685: register tree itype = make_node (INTEGER_TYPE);
1686: int maxint = TREE_INT_CST_LOW (maxval);
1687: TYPE_PRECISION (itype) = BITS_PER_WORD;
1688: TYPE_MIN_VALUE (itype) = build_int_2 (0, 0);
1689: TREE_TYPE (TYPE_MIN_VALUE (itype)) = itype;
1690: TYPE_MAX_VALUE (itype) = maxval;
1691: TREE_TYPE (maxval) = itype;
1692: TYPE_MODE (itype) = SImode;
1693: TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
1694: TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype);
1695: TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
1696: return type_hash_canon (maxint > 0 ? maxint : - maxint, itype);
1697: }
1698:
1.1.1.2 root 1699: /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
1700: and number of elements specified by the range of values of INDEX_TYPE.
1701: If such a type has already been constructed, reuse it. */
1702:
1.1 root 1703: tree
1704: build_array_type (elt_type, index_type)
1705: tree elt_type, index_type;
1706: {
1707: register tree t = make_node (ARRAY_TYPE);
1.1.1.2 root 1708: int hashcode;
1.1 root 1709:
1710: if (TREE_CODE (elt_type) == FUNCTION_TYPE)
1711: {
1.1.1.2 root 1712: error ("arrays of functions are not meaningful");
1.1 root 1713: elt_type = integer_type_node;
1714: }
1715:
1716: TREE_TYPE (t) = elt_type;
1717: TYPE_DOMAIN (t) = index_type;
1.1.1.2 root 1718:
1.1 root 1719: /* Make sure TYPE_POINTER_TO (elt_type) is filled in. */
1720: build_pointer_type (elt_type);
1.1.1.2 root 1721:
1722: if (index_type == 0)
1723: return t;
1724:
1725: hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type);
1726: t = type_hash_canon (hashcode, t);
1727:
1728: if (TYPE_SIZE (t) == 0)
1729: layout_type (t);
1.1 root 1730: return t;
1731: }
1732:
1.1.1.2 root 1733: /* Construct, lay out and return
1734: the type of functions returning type VALUE_TYPE
1735: given arguments of types ARG_TYPES.
1736: ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
1737: are data type nodes for the arguments of the function.
1738: If such a type has already been constructed, reuse it. */
1.1 root 1739:
1740: tree
1741: build_function_type (value_type, arg_types)
1742: tree value_type, arg_types;
1743: {
1744: register tree t;
1.1.1.2 root 1745: int hashcode;
1.1 root 1746:
1.1.1.2 root 1747: if (TREE_CODE (value_type) == FUNCTION_TYPE
1.1 root 1748: || TREE_CODE (value_type) == ARRAY_TYPE)
1749: {
1.1.1.2 root 1750: error ("function return type cannot be function or array");
1.1 root 1751: value_type = integer_type_node;
1752: }
1753:
1.1.1.2 root 1754: /* Make a node of the sort we want. */
1.1 root 1755: t = make_node (FUNCTION_TYPE);
1756: TREE_TYPE (t) = value_type;
1757: TYPE_ARG_TYPES (t) = arg_types;
1.1.1.2 root 1758:
1759: /* If we already have such a type, use the old one and free this one. */
1760: hashcode = TYPE_HASH (value_type) + type_hash_list (arg_types);
1761: t = type_hash_canon (hashcode, t);
1762:
1763: if (TYPE_SIZE (t) == 0)
1764: layout_type (t);
1.1 root 1765: return t;
1766: }
1.1.1.7 root 1767:
1768: /* Build the node for the type of references-to-TO_TYPE. */
1769:
1770: tree
1771: build_reference_type (to_type)
1772: tree to_type;
1773: {
1774: register tree t = TYPE_REFERENCE_TO (to_type);
1775: register struct obstack *ambient_obstack = current_obstack;
1776: register struct obstack *ambient_saveable_obstack = saveable_obstack;
1777:
1778: /* First, if we already have a type for pointers to TO_TYPE, use it. */
1779:
1780: if (t)
1781: return t;
1782:
1783: /* We need a new one. If TO_TYPE is permanent, make this permanent too. */
1784: if (TREE_PERMANENT (to_type))
1785: {
1786: current_obstack = &permanent_obstack;
1787: saveable_obstack = &permanent_obstack;
1788: }
1789:
1790: t = make_node (REFERENCE_TYPE);
1791: TREE_TYPE (t) = to_type;
1792:
1793: /* Record this type as the pointer to TO_TYPE. */
1794: TYPE_REFERENCE_TO (to_type) = t;
1795:
1796: layout_type (t);
1797:
1798: current_obstack = ambient_obstack;
1799: saveable_obstack = ambient_saveable_obstack;
1800: return t;
1801: }
1802:
1803: /* Construct, lay out and return the type of methods belonging to class
1804: BASETYPE and whose arguments and values are described by TYPE.
1805: If that type exists already, reuse it.
1806: TYPE must be a FUNCTION_TYPE node. */
1807:
1808: tree
1809: build_method_type (basetype, type)
1810: tree basetype, type;
1811: {
1812: register tree t;
1813: int hashcode;
1814:
1815: /* Make a node of the sort we want. */
1816: t = make_node (METHOD_TYPE);
1817:
1818: if (TREE_CODE (type) != FUNCTION_TYPE)
1819: abort ();
1820:
1821: TYPE_METHOD_CLASS (t) == basetype;
1822: TREE_TYPE (t) = type;
1823:
1824: /* The actual arglist for this function includes a "hidden" argument
1825: which is "this". Put it into the list of argument types. */
1826:
1827: TYPE_ARG_TYPES (t)
1828: = tree_cons (NULL, build_pointer_type (basetype), TYPE_ARG_TYPES (type));
1829:
1830: /* If we already have such a type, use the old one and free this one. */
1831: hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
1832: t = type_hash_canon (hashcode, t);
1833:
1834: if (TYPE_SIZE (t) == 0)
1835: layout_type (t);
1836:
1837: return t;
1838: }
1.1 root 1839:
1840: /* Return OP, stripped of any conversions to wider types as much as is safe.
1841: Converting the value back to OP's type makes a value equivalent to OP.
1842:
1843: If FOR_TYPE is nonzero, we return a value which, if converted to
1844: type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
1845:
1.1.1.2 root 1846: If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
1847: narrowest type that can hold the value, even if they don't exactly fit.
1848: Otherwise, bit-field references are changed to a narrower type
1849: only if they can be fetched directly from memory in that type.
1850:
1.1 root 1851: OP must have integer, real or enumeral type. Pointers are not allowed!
1852:
1853: There are some cases where the obvious value we could return
1854: would regenerate to OP if converted to OP's type,
1855: but would not extend like OP to wider types.
1856: If FOR_TYPE indicates such extension is contemplated, we eschew such values.
1857: For example, if OP is (unsigned short)(signed char)-1,
1858: we avoid returning (signed char)-1 if FOR_TYPE is int,
1859: even though extending that to an unsigned short would regenerate OP,
1860: since the result of extending (signed char)-1 to (int)
1861: is different from (int) OP. */
1862:
1863: tree
1864: get_unwidened (op, for_type)
1865: register tree op;
1866: tree for_type;
1867: {
1868: /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
1869: /* TYPE_PRECISION is safe in place of type_precision since
1870: pointer types are not allowed. */
1871: register tree type = TREE_TYPE (op);
1872: register int final_prec = TYPE_PRECISION (for_type != 0 ? for_type : type);
1873: register int uns
1874: = (for_type != 0 && for_type != type
1875: && final_prec > TYPE_PRECISION (type)
1.1.1.2 root 1876: && TREE_UNSIGNED (type));
1.1 root 1877: register tree win = op;
1878:
1879: while (TREE_CODE (op) == NOP_EXPR)
1880: {
1881: register int bitschange
1882: = TYPE_PRECISION (TREE_TYPE (op))
1883: - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
1884:
1885: /* Truncations are many-one so cannot be removed.
1886: Unless we are later going to truncate down even farther. */
1887: if (bitschange < 0
1888: && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
1889: break;
1890:
1891: /* See what's inside this conversion. If we decide to strip it,
1892: we will set WIN. */
1893: op = TREE_OPERAND (op, 0);
1894:
1895: /* If we have not stripped any zero-extensions (uns is 0),
1896: we can strip any kind of extension.
1897: If we have previously stripped a zero-extension,
1898: only zero-extensions can safely be stripped.
1899: Any extension can be stripped if the bits it would produce
1900: are all going to be discarded later by truncating to FOR_TYPE. */
1901:
1902: if (bitschange > 0)
1903: {
1904: if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
1905: win = op;
1.1.1.2 root 1906: /* TREE_UNSIGNED says whether this is a zero-extension.
1.1 root 1907: Let's avoid computing it if it does not affect WIN
1908: and if UNS will not be needed again. */
1909: if ((uns || TREE_CODE (op) == NOP_EXPR)
1.1.1.2 root 1910: && TREE_UNSIGNED (TREE_TYPE (op)))
1.1 root 1911: {
1912: uns = 1;
1913: win = op;
1914: }
1915: }
1916: }
1917:
1.1.1.2 root 1918: if (TREE_CODE (op) == COMPONENT_REF
1919: /* Since type_for_size always gives an integer type. */
1920: && TREE_CODE (type) != REAL_TYPE)
1921: {
1922: int innerprec = (TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)))
1923: * DECL_SIZE_UNIT (TREE_OPERAND (op, 1)));
1924: type = type_for_size (innerprec, TREE_UNSIGNED (TREE_OPERAND (op, 1)));
1925:
1926: /* We can get this structure field in the narrowest type it fits in.
1927: If FOR_TYPE is 0, do this only for a field that matches the
1928: narrower type exactly and is aligned for it (i.e. mode isn't BI).
1929: The resulting extension to its nominal type (a fullword type)
1930: must fit the same conditions as for other extensions. */
1931:
1.1.1.3 root 1932: if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
1.1.1.2 root 1933: && (for_type || DECL_MODE (TREE_OPERAND (op, 1)) != BImode)
1934: && (! uns || final_prec <= innerprec
1935: || TREE_UNSIGNED (TREE_OPERAND (op, 1)))
1936: && type != 0)
1937: {
1938: win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
1939: TREE_OPERAND (op, 1));
1940: TREE_VOLATILE (win) = TREE_VOLATILE (op);
1941: TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
1942: }
1943: }
1.1 root 1944: return win;
1945: }
1946:
1947: /* Return OP or a simpler expression for a narrower value
1948: which can be sign-extended or zero-extended to give back OP.
1949: Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
1950: or 0 if the value should be sign-extended. */
1951:
1952: tree
1953: get_narrower (op, unsignedp_ptr)
1954: register tree op;
1955: int *unsignedp_ptr;
1956: {
1957: register int uns = 0;
1958: int first = 1;
1959: register tree win = op;
1960:
1961: while (TREE_CODE (op) == NOP_EXPR)
1962: {
1963: register int bitschange
1964: = TYPE_PRECISION (TREE_TYPE (op))
1965: - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
1966:
1967: /* Truncations are many-one so cannot be removed. */
1968: if (bitschange < 0)
1969: break;
1970:
1971: /* See what's inside this conversion. If we decide to strip it,
1972: we will set WIN. */
1973: op = TREE_OPERAND (op, 0);
1974:
1975: if (bitschange > 0)
1976: {
1977: /* An extension: the outermost one can be stripped,
1978: but remember whether it is zero or sign extension. */
1979: if (first)
1.1.1.2 root 1980: uns = TREE_UNSIGNED (TREE_TYPE (op));
1.1 root 1981: /* Otherwise, if a sign extension has been stripped,
1982: only sign extensions can now be stripped;
1983: if a zero extension has been stripped, only zero-extensions. */
1.1.1.2 root 1984: else if (uns != TREE_UNSIGNED (TREE_TYPE (op)))
1.1 root 1985: break;
1986: first = 0;
1987: }
1988: /* A change in nominal type can always be stripped. */
1989:
1990: win = op;
1991: }
1992:
1.1.1.2 root 1993: if (TREE_CODE (op) == COMPONENT_REF
1994: /* Since type_for_size always gives an integer type. */
1995: && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE)
1.1 root 1996: {
1997: int innerprec = (TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)))
1998: * DECL_SIZE_UNIT (TREE_OPERAND (op, 1)));
1.1.1.2 root 1999: tree type = type_for_size (innerprec, TREE_UNSIGNED (op));
1.1 root 2000:
2001: /* We can get this structure field in a narrower type that fits it,
2002: but the resulting extension to its nominal type (a fullword type)
1.1.1.2 root 2003: must satisfy the same conditions as for other extensions.
2004:
2005: Do this only for fields that are aligned (not BImode),
2006: because when bit-field insns will be used there is no
2007: advantage in doing this. */
1.1 root 2008:
2009: if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
1.1.1.2 root 2010: && DECL_MODE (TREE_OPERAND (op, 1)) != BImode
2011: && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1)))
1.1 root 2012: && type != 0)
2013: {
1.1.1.2 root 2014: if (first)
2015: uns = TREE_UNSIGNED (TREE_OPERAND (op, 1));
2016: win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
2017: TREE_OPERAND (op, 1));
2018: TREE_VOLATILE (win) = TREE_VOLATILE (op);
2019: TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
1.1 root 2020: }
2021: }
2022: *unsignedp_ptr = uns;
2023: return win;
2024: }
2025:
2026: /* Return the precision of a type, for arithmetic purposes.
2027: Supports all types on which arithmetic is possible
2028: (including pointer types).
2029: It's not clear yet what will be right for complex types. */
2030:
2031: int
2032: type_precision (type)
2033: register tree type;
2034: {
2035: return ((TREE_CODE (type) == INTEGER_TYPE
2036: || TREE_CODE (type) == ENUMERAL_TYPE
2037: || TREE_CODE (type) == REAL_TYPE)
1.1.1.2 root 2038: ? TYPE_PRECISION (type) : POINTER_SIZE);
1.1 root 2039: }
2040:
2041: /* Nonzero if integer constant C has a value that is permissible
2042: for type TYPE (an INTEGER_TYPE). */
2043:
2044: int
2045: int_fits_type_p (c, type)
2046: tree c, type;
2047: {
1.1.1.2 root 2048: if (TREE_UNSIGNED (type))
1.1 root 2049: return (!INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type), c)
2050: && !INT_CST_LT_UNSIGNED (c, TYPE_MIN_VALUE (type)));
2051: else
2052: return (!INT_CST_LT (TYPE_MAX_VALUE (type), c)
2053: && !INT_CST_LT (c, TYPE_MIN_VALUE (type)));
2054: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.