|
|
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 root 805: /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
806:
807: tree
808: tree_last (chain)
809: register tree chain;
810: {
811: register tree next;
812: if (chain)
813: while (next = TREE_CHAIN (chain))
814: chain = next;
815: return chain;
816: }
817:
818: /* Reverse the order of elements in the chain T,
819: and return the new head of the chain (old last element). */
820:
821: tree
822: nreverse (t)
823: tree t;
824: {
825: register tree prev = 0, decl, next;
826: for (decl = t; decl; decl = next)
827: {
828: next = TREE_CHAIN (decl);
829: TREE_CHAIN (decl) = prev;
830: prev = decl;
831: }
832: return prev;
833: }
834:
835: /* Return the size nominally occupied by an object of type TYPE
836: when it resides in memory. The value is measured in units of bytes,
837: and its data type is that normally used for type sizes
838: (which is the first type created by make_signed_type or
839: make_unsigned_type). */
840:
841: tree
842: size_in_bytes (type)
843: tree type;
844: {
845: if (type == error_mark_node)
846: return integer_zero_node;
1.1.1.2 root 847: if (TYPE_SIZE (type) == 0)
848: {
849: incomplete_type_error (0, type);
850: return integer_zero_node;
851: }
1.1 root 852: return convert_units (TYPE_SIZE (type), TYPE_SIZE_UNIT (type),
853: BITS_PER_UNIT);
854: }
855:
1.1.1.2 root 856: /* Return the size of TYPE (in bytes) as an integer,
857: or return -1 if the size can vary. */
858:
859: int
860: int_size_in_bytes (type)
861: tree type;
862: {
863: int size;
864: if (type == error_mark_node)
865: return 0;
866: if (TYPE_SIZE (type) == 0)
867: return -1;
868: if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
869: return -1;
870: size = TREE_INT_CST_LOW (TYPE_SIZE (type)) * TYPE_SIZE_UNIT (type);
871: return (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
872: }
873:
1.1.1.7 root 874: /* Return, as an INTEGER_CST node, the number of elements for
875: TYPE (which is an ARRAY_TYPE). */
876:
877: tree
878: array_type_nelts (type)
879: tree type;
880: {
881: tree index_type = TYPE_DOMAIN (type);
882: return (tree_int_cst_equal (TYPE_MIN_VALUE (index_type), integer_zero_node)
883: ? TYPE_MAX_VALUE (index_type)
884: : fold (build (MINUS_EXPR, integer_type_node,
885: TYPE_MAX_VALUE (index_type),
886: TYPE_MIN_VALUE (index_type))));
887: }
888:
1.1 root 889: /* Return nonzero if arg is static -- a reference to an object in
890: static storage. This is not the same as the C meaning of `static'. */
891:
892: int
893: staticp (arg)
894: tree arg;
895: {
896: register enum tree_code code = TREE_CODE (arg);
897:
1.1.1.2 root 898: if ((code == VAR_DECL || code == FUNCTION_DECL || code == CONSTRUCTOR)
1.1 root 899: && (TREE_STATIC (arg) || TREE_EXTERNAL (arg)))
900: return 1;
901:
1.1.1.2 root 902: if (code == STRING_CST)
903: return 1;
904:
1.1 root 905: if (code == COMPONENT_REF)
906: return staticp (TREE_OPERAND (arg, 0));
907:
1.1.1.2 root 908: if (code == ARRAY_REF)
909: {
910: if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
911: && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
912: return staticp (TREE_OPERAND (arg, 0));
913: }
914:
1.1 root 915: return 0;
916: }
917:
1.1.1.2 root 918: /* Return nonzero if REF is an lvalue valid for this language.
919: Lvalues can be assigned, unless they have TREE_READONLY.
920: Lvalues can have their address taken, unless they have TREE_REGDECL. */
1.1 root 921:
922: int
1.1.1.2 root 923: lvalue_p (ref)
1.1 root 924: tree ref;
925: {
926: register enum tree_code code = TREE_CODE (ref);
927:
1.1.1.2 root 928: if (language_lvalue_valid (ref))
929: switch (code)
930: {
931: case COMPONENT_REF:
932: return lvalue_p (TREE_OPERAND (ref, 0));
933:
934: case STRING_CST:
935: return 1;
936:
937: case INDIRECT_REF:
938: case ARRAY_REF:
939: case VAR_DECL:
940: case PARM_DECL:
941: case RESULT_DECL:
942: case ERROR_MARK:
943: if (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE)
944: return 1;
1.1.1.7 root 945: break;
946:
947: case CALL_EXPR:
948: if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
949: return 1;
1.1.1.2 root 950: }
1.1 root 951: return 0;
952: }
1.1.1.2 root 953:
954: /* Return nonzero if REF is an lvalue valid for this language;
955: otherwise, print an error message and return zero. */
956:
957: int
958: lvalue_or_else (ref, string)
959: tree ref;
960: char *string;
961: {
962: int win = lvalue_p (ref);
963: if (! win)
964: error ("invalid lvalue in %s", string);
965: return win;
966: }
1.1 root 967:
968: /* This should be applied to any node which may be used in more than one place,
969: but must be evaluated only once. Normally, the code generator would
970: reevaluate the node each time; this forces it to compute it once and save
971: the result. This is done by encapsulating the node in a SAVE_EXPR. */
972:
973: tree
974: save_expr (expr)
975: tree expr;
976: {
977: register tree t = fold (expr);
978:
1.1.1.2 root 979: /* If the tree evaluates to a constant, then we don't want to hide that
1.1 root 980: fact (i.e. this allows further folding, and direct checks for constants).
981: Since it is no problem to reevaluate literals, we just return the
982: literal node. */
983:
984: if (TREE_LITERAL (t) || TREE_READONLY (t) || TREE_CODE (t) == SAVE_EXPR)
985: return t;
986:
1.1.1.2 root 987: return build (SAVE_EXPR, TREE_TYPE (expr), t, NULL);
1.1 root 988: }
989:
990: /* Stabilize a reference so that we can use it any number of times
991: without causing its operands to be evaluated more than once.
1.1.1.2 root 992: Returns the stabilized reference.
993:
994: Also allows conversion expressions whose operands are references.
995: Any other kind of expression is returned unchanged. */
1.1 root 996:
997: tree
998: stabilize_reference (ref)
999: tree ref;
1000: {
1001: register tree result;
1002: register enum tree_code code = TREE_CODE (ref);
1003:
1.1.1.2 root 1004: switch (code)
1.1 root 1005: {
1.1.1.2 root 1006: case VAR_DECL:
1007: case PARM_DECL:
1008: case RESULT_DECL:
1.1 root 1009: result = ref;
1.1.1.2 root 1010: break;
1011:
1012: case NOP_EXPR:
1013: case CONVERT_EXPR:
1014: case FLOAT_EXPR:
1015: case FIX_TRUNC_EXPR:
1016: case FIX_FLOOR_EXPR:
1017: case FIX_ROUND_EXPR:
1018: case FIX_CEIL_EXPR:
1019: result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
1020: break;
1021:
1022: case INDIRECT_REF:
1023: result = build_nt (INDIRECT_REF, save_expr (TREE_OPERAND (ref, 0)));
1024: break;
1025:
1026: case COMPONENT_REF:
1027: result = build_nt (COMPONENT_REF,
1028: stabilize_reference (TREE_OPERAND (ref, 0)),
1029: TREE_OPERAND (ref, 1));
1030: break;
1031:
1032: case ARRAY_REF:
1033: result = build_nt (ARRAY_REF, stabilize_reference (TREE_OPERAND (ref, 0)),
1034: save_expr (TREE_OPERAND (ref, 1)));
1035: break;
1036:
1037: /* If arg isn't a kind of lvalue we recognize, make no change.
1038: Caller should recognize the error for an invalid lvalue. */
1039: default:
1040: return ref;
1041:
1042: case ERROR_MARK:
1.1 root 1043: return error_mark_node;
1044: }
1045:
1046: TREE_TYPE (result) = TREE_TYPE (ref);
1.1.1.2 root 1047: TREE_READONLY (result) = TREE_READONLY (ref);
1.1 root 1048: TREE_VOLATILE (result) = TREE_VOLATILE (ref);
1.1.1.2 root 1049: TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
1.1 root 1050:
1051: return result;
1052: }
1053:
1054: /* Low-level constructors for expressions. */
1055:
1.1.1.2 root 1056: /* Build an expression of code CODE, data type TYPE,
1057: and operands as specified by the arguments ARG1 and following arguments.
1058: Expressions and reference nodes can be created this way.
1059: Constants, decls, types and misc nodes cannot be. */
1.1 root 1060:
1061: tree
1.1.1.2 root 1062: build (va_alist)
1063: va_dcl
1.1 root 1064: {
1.1.1.2 root 1065: register va_list p;
1066: enum tree_code code;
1067: register tree t;
1068: register int length;
1069: register int i;
1070:
1071: va_start (p);
1.1 root 1072:
1.1.1.2 root 1073: code = va_arg (p, enum tree_code);
1074: t = make_node (code);
1075: length = tree_code_length[(int) code];
1076: TREE_TYPE (t) = va_arg (p, tree);
1077:
1078: if (length == 2)
1079: {
1080: /* This is equivalent to the loop below, but faster. */
1081: register tree arg0 = va_arg (p, tree);
1082: register tree arg1 = va_arg (p, tree);
1083: TREE_OPERAND (t, 0) = arg0;
1084: TREE_OPERAND (t, 1) = arg1;
1085: TREE_VOLATILE (t)
1086: = (arg0 && TREE_VOLATILE (arg0)) || (arg1 && TREE_VOLATILE (arg1));
1087: }
1088: else
1089: {
1090: for (i = 0; i < length; i++)
1091: {
1092: register tree operand = va_arg (p, tree);
1093: TREE_OPERAND (t, i) = operand;
1094: if (operand && TREE_VOLATILE (operand))
1095: TREE_VOLATILE (t) = 1;
1096: }
1097: }
1098: va_end (p);
1.1 root 1099: return t;
1100: }
1101:
1.1.1.2 root 1102: /* Similar except don't specify the TREE_TYPE
1103: and leave the TREE_VOLATILE as 0.
1104: It is permissible for arguments to be null,
1105: or even garbage if their values do not matter. */
1.1 root 1106:
1107: tree
1.1.1.2 root 1108: build_nt (va_alist)
1109: va_dcl
1.1 root 1110: {
1.1.1.2 root 1111: register va_list p;
1112: register enum tree_code code;
1113: register tree t;
1114: register int length;
1115: register int i;
1116:
1117: va_start (p);
1.1 root 1118:
1.1.1.2 root 1119: code = va_arg (p, enum tree_code);
1120: t = make_node (code);
1121: length = tree_code_length[(int) code];
1122:
1123: for (i = 0; i < length; i++)
1124: TREE_OPERAND (t, i) = va_arg (p, tree);
1125:
1126: va_end (p);
1.1 root 1127: return t;
1128: }
1.1.1.2 root 1129:
1130: /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
1131: We do NOT enter this node in any sort of symbol table.
1.1 root 1132:
1.1.1.2 root 1133: layout_decl is used to set up the decl's storage layout.
1134: Other slots are initialized to 0 or null pointers. */
1.1 root 1135:
1136: tree
1.1.1.2 root 1137: build_decl (code, name, type)
1138: enum tree_code code;
1139: tree name, type;
1140: {
1141: register tree t;
1142:
1143: t = make_node (code);
1144:
1145: /* if (type == error_mark_node)
1146: type = integer_type_node; */
1147: /* That is not done, deliberately, so that having error_mark_node
1148: as the type can suppress useless errors in the use of this variable. */
1149:
1150: DECL_NAME (t) = name;
1151: TREE_TYPE (t) = type;
1152: DECL_ARGUMENTS (t) = NULL_TREE;
1153: DECL_INITIAL (t) = NULL_TREE;
1154:
1155: if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
1156: layout_decl (t, 0);
1157: else if (code == FUNCTION_DECL)
1158: DECL_MODE (t) = FUNCTION_MODE;
1159:
1.1 root 1160: return t;
1161: }
1162:
1.1.1.7 root 1163: #if 0
1.1 root 1164: /* Low-level constructors for statements.
1165: These constructors all expect source file name and line number
1166: as arguments, as well as enough arguments to fill in the data
1167: in the statement node. */
1168:
1169: tree
1170: build_goto (filename, line, label)
1171: char *filename;
1172: int line;
1173: tree label;
1174: {
1175: register tree t = make_node (GOTO_STMT);
1176: STMT_SOURCE_FILE (t) = filename;
1177: STMT_SOURCE_LINE (t) = line;
1178: STMT_BODY (t) = label;
1179: return t;
1180: }
1181:
1182: tree
1183: build_return (filename, line, arg)
1184: char *filename;
1185: int line;
1186: tree arg;
1187: {
1188: register tree t = make_node (RETURN_STMT);
1189:
1190: STMT_SOURCE_FILE (t) = filename;
1191: STMT_SOURCE_LINE (t) = line;
1192: STMT_BODY (t) = arg;
1193: return t;
1194: }
1195:
1196: tree
1197: build_expr_stmt (filename, line, expr)
1198: char *filename;
1199: int line;
1200: tree expr;
1201: {
1202: register tree t = make_node (EXPR_STMT);
1203:
1204: STMT_SOURCE_FILE (t) = filename;
1205: STMT_SOURCE_LINE (t) = line;
1206: STMT_BODY (t) = expr;
1207: return t;
1208: }
1209:
1210: tree
1211: build_if (filename, line, cond, thenclause, elseclause)
1212: char *filename;
1213: int line;
1214: tree cond, thenclause, elseclause;
1215: {
1216: register tree t = make_node (IF_STMT);
1217:
1218: STMT_SOURCE_FILE (t) = filename;
1219: STMT_SOURCE_LINE (t) = line;
1220: STMT_COND (t) = cond;
1221: STMT_THEN (t) = thenclause;
1222: STMT_ELSE (t) = elseclause;
1223: return t;
1224: }
1225:
1226: tree
1227: build_exit (filename, line, cond)
1228: char *filename;
1229: int line;
1230: tree cond;
1231: {
1232: register tree t = make_node (EXIT_STMT);
1233: STMT_SOURCE_FILE (t) = filename;
1234: STMT_SOURCE_LINE (t) = line;
1235: STMT_BODY (t) = cond;
1236: return t;
1237: }
1238:
1239: tree
1240: build_asm_stmt (filename, line, asmcode)
1241: char *filename;
1242: int line;
1243: tree asmcode;
1244: {
1245: register tree t = make_node (ASM_STMT);
1246: STMT_SOURCE_FILE (t) = filename;
1247: STMT_SOURCE_LINE (t) = line;
1248: STMT_BODY (t) = asmcode;
1249: return t;
1250: }
1251:
1252: tree
1253: build_case (filename, line, object, cases)
1254: char *filename;
1255: int line;
1256: tree object, cases;
1257: {
1258: register tree t = make_node (CASE_STMT);
1259: STMT_SOURCE_FILE (t) = filename;
1260: STMT_SOURCE_LINE (t) = line;
1261: STMT_CASE_INDEX (t) = object;
1262: STMT_CASE_LIST (t) = cases;
1263: return t;
1264: }
1265:
1266: tree
1.1.1.7 root 1267: build_loop (filename, line, body)
1.1 root 1268: char *filename;
1269: int line;
1.1.1.7 root 1270: tree body;
1.1 root 1271: {
1.1.1.7 root 1272: register tree t = make_node (LOOP_STMT);
1.1 root 1273: STMT_SOURCE_FILE (t) = filename;
1274: STMT_SOURCE_LINE (t) = line;
1275: STMT_BODY (t) = body;
1276: return t;
1277: }
1278:
1279: tree
1.1.1.7 root 1280: build_compound (filename, line, body)
1.1 root 1281: char *filename;
1282: int line;
1283: tree body;
1284: {
1.1.1.7 root 1285: register tree t = make_node (COMPOUND_STMT);
1.1 root 1286: STMT_SOURCE_FILE (t) = filename;
1287: STMT_SOURCE_LINE (t) = line;
1288: STMT_BODY (t) = body;
1289: return t;
1290: }
1291:
1.1.1.7 root 1292: #endif /* 0 */
1293:
1294: /* LET_STMT nodes are used to represent the structure of binding contours
1295: and declarations, once those contours have been exited and their contents
1296: compiled. This information is used for outputting debugging info. */
1297:
1.1 root 1298: tree
1.1.1.7 root 1299: build_let (filename, line, vars, body, supercontext, tags)
1.1 root 1300: char *filename;
1301: int line;
1.1.1.7 root 1302: tree vars, body, supercontext, tags;
1.1 root 1303: {
1.1.1.7 root 1304: register tree t = make_node (LET_STMT);
1.1 root 1305: STMT_SOURCE_FILE (t) = filename;
1306: STMT_SOURCE_LINE (t) = line;
1.1.1.7 root 1307: STMT_VARS (t) = vars;
1.1 root 1308: STMT_BODY (t) = body;
1.1.1.7 root 1309: STMT_SUPERCONTEXT (t) = supercontext;
1310: STMT_BIND_SIZE (t) = 0;
1311: STMT_TYPE_TAGS (t) = tags;
1.1 root 1312: return t;
1313: }
1314:
1315: /* Return a type like TYPE except that its TREE_READONLY is CONSTP
1316: and its TREE_VOLATILE is VOLATILEP.
1317:
1318: Such variant types already made are recorded so that duplicates
1319: are not made.
1320:
1321: A variant types should never be used as the type of an expression.
1322: Always copy the variant information into the TREE_READONLY
1323: and TREE_VOLATILE of the expression, and then give the expression
1324: as its type the "main variant", the variant whose TREE_READONLY
1325: and TREE_VOLATILE are zero. Use TYPE_MAIN_VARIANT to find the
1326: main variant. */
1327:
1328: tree
1329: build_type_variant (type, constp, volatilep)
1330: tree type;
1331: int constp, volatilep;
1332: {
1333: register tree t, m = TYPE_MAIN_VARIANT (type);
1334: register struct obstack *ambient_obstack = current_obstack;
1335:
1336: /* Treat any nonzero argument as 1. */
1337: constp = !!constp;
1338: volatilep = !!volatilep;
1339:
1340: /* First search the chain variants for one that is what we want. */
1341:
1342: for (t = m; t; t = TYPE_NEXT_VARIANT (t))
1343: if (constp == TREE_READONLY (t)
1344: && volatilep == TREE_VOLATILE (t))
1345: return t;
1346:
1347: /* We need a new one. */
1.1.1.2 root 1348: current_obstack
1349: = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
1.1 root 1350:
1351: t = copy_node (type);
1352: TREE_READONLY (t) = constp;
1353: TREE_VOLATILE (t) = volatilep;
1354: TYPE_POINTER_TO (t) = 0;
1.1.1.7 root 1355: TYPE_REFERENCE_TO (t) = 0;
1.1 root 1356:
1357: /* Add this type to the chain of variants of TYPE. */
1358: TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
1359: TYPE_NEXT_VARIANT (m) = t;
1360:
1361: current_obstack = ambient_obstack;
1362: return t;
1363: }
1364:
1.1.1.2 root 1365: /* Hashing of types so that we don't make duplicates.
1366: The entry point is `type_hash_canon'. */
1367:
1368: /* Each hash table slot is a bucket containing a chain
1369: of these structures. */
1370:
1371: struct type_hash
1372: {
1373: struct type_hash *next; /* Next structure in the bucket. */
1374: int hashcode; /* Hash code of this type. */
1375: tree type; /* The type recorded here. */
1376: };
1377:
1378: /* Now here is the hash table. When recording a type, it is added
1379: to the slot whose index is the hash code mod the table size.
1380: Note that the hash table is used for several kinds of types
1381: (function types, array types and array index range types, for now).
1382: While all these live in the same table, they are completely independent,
1383: and the hash code is computed differently for each of these. */
1384:
1.1.1.7 root 1385: #define TYPE_HASH_SIZE 59
1.1.1.2 root 1386: struct type_hash *type_hash_table[TYPE_HASH_SIZE];
1387:
1388: /* Here is how primitive or already-canonicalized types' hash
1389: codes are made. */
1390: #define TYPE_HASH(TYPE) TREE_UID (TYPE)
1391:
1392: /* Compute a hash code for a list of types (chain of TREE_LIST nodes
1393: with types in the TREE_VALUE slots), by adding the hash codes
1394: of the individual types. */
1395:
1396: int
1397: type_hash_list (list)
1398: tree list;
1399: {
1400: register int hashcode;
1401: register tree tail;
1402: for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
1403: hashcode += TYPE_HASH (TREE_VALUE (tail));
1404: return hashcode;
1405: }
1406:
1407: /* Look in the type hash table for a type isomorphic to TYPE.
1408: If one is found, return it. Otherwise return 0. */
1409:
1410: tree
1411: type_hash_lookup (hashcode, type)
1412: int hashcode;
1413: tree type;
1414: {
1415: register struct type_hash *h;
1416: for (h = type_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
1417: if (h->hashcode == hashcode
1418: && TREE_CODE (h->type) == TREE_CODE (type)
1419: && TREE_TYPE (h->type) == TREE_TYPE (type)
1420: && (TYPE_MAX_VALUE (h->type) == TYPE_MAX_VALUE (type)
1421: || tree_int_cst_equal (TYPE_MAX_VALUE (h->type),
1422: TYPE_MAX_VALUE (type)))
1423: && (TYPE_MIN_VALUE (h->type) == TYPE_MIN_VALUE (type)
1424: || tree_int_cst_equal (TYPE_MIN_VALUE (h->type),
1425: TYPE_MIN_VALUE (type)))
1426: && (TYPE_DOMAIN (h->type) == TYPE_DOMAIN (type)
1427: || (TREE_CODE (TYPE_DOMAIN (h->type)) == TREE_LIST
1428: && TREE_CODE (TYPE_DOMAIN (type)) == TREE_LIST
1429: && type_list_equal (TYPE_DOMAIN (h->type), TYPE_DOMAIN (type)))))
1430: return h->type;
1431: return 0;
1432: }
1433:
1434: /* Add an entry to the type-hash-table
1435: for a type TYPE whose hash code is HASHCODE. */
1436:
1437: void
1438: type_hash_add (hashcode, type)
1439: int hashcode;
1440: tree type;
1441: {
1442: register struct type_hash *h;
1443:
1444: h = (struct type_hash *) oballoc (sizeof (struct type_hash));
1445: h->hashcode = hashcode;
1446: h->type = type;
1447: h->next = type_hash_table[hashcode % TYPE_HASH_SIZE];
1448: type_hash_table[hashcode % TYPE_HASH_SIZE] = h;
1449: }
1450:
1451: /* Given TYPE, and HASHCODE its hash code, return the canonical
1452: object for an identical type if one already exists.
1453: Otherwise, return TYPE, and record it as the canonical object
1454: if it is a permanent object.
1455:
1456: To use this function, first create a type of the sort you want.
1457: Then compute its hash code from the fields of the type that
1458: make it different from other similar types.
1459: Then call this function and use the value.
1460: This function frees the type you pass in if it is a duplicate. */
1461:
1462: /* Set to 1 to debug without canonicalization. Never set by program. */
1463: int debug_no_type_hash = 0;
1464:
1465: tree
1466: type_hash_canon (hashcode, type)
1467: int hashcode;
1468: tree type;
1469: {
1470: tree t1;
1471:
1472: if (debug_no_type_hash)
1473: return type;
1474:
1475: t1 = type_hash_lookup (hashcode, type);
1476: if (t1 != 0)
1477: {
1478: struct obstack *o
1479: = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
1480: obstack_free (o, type);
1481: return t1;
1482: }
1483:
1484: /* If this is a new type, record it for later reuse. */
1485: if (current_obstack == &permanent_obstack)
1486: type_hash_add (hashcode, type);
1487:
1488: return type;
1489: }
1490:
1491: /* Given two lists of types
1492: (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
1.1.1.7 root 1493: return 1 if the lists contain the same types in the same order.
1494: Also, the TREE_PURPOSEs must match. */
1.1.1.2 root 1495:
1496: int
1497: type_list_equal (l1, l2)
1498: tree l1, l2;
1499: {
1500: register tree t1, t2;
1501: for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
1.1.1.7 root 1502: {
1503: if (TREE_VALUE (t1) != TREE_VALUE (t2))
1504: return 0;
1505: if (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
1506: && !simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
1507: return 0;
1508: }
1.1.1.2 root 1509:
1510: return t1 == t2;
1511: }
1512:
1513: /* Nonzero if integer constants T1 and T2
1514: represent the same constant value. */
1515:
1516: int
1517: tree_int_cst_equal (t1, t2)
1518: tree t1, t2;
1519: {
1520: if (t1 == t2)
1521: return 1;
1522: if (t1 == 0 || t2 == 0)
1523: return 0;
1524: if (TREE_CODE (t1) == INTEGER_CST
1525: && TREE_CODE (t2) == INTEGER_CST
1526: && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
1527: && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
1528: return 1;
1529: return 0;
1530: }
1531:
1532: /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
1533: The precise way of comparison depends on their data type. */
1534:
1535: int
1536: tree_int_cst_lt (t1, t2)
1537: tree t1, t2;
1538: {
1539: if (t1 == t2)
1540: return 0;
1541:
1542: if (!TREE_UNSIGNED (TREE_TYPE (t1)))
1543: return INT_CST_LT (t1, t2);
1544: return INT_CST_LT_UNSIGNED (t1, t2);
1545: }
1.1.1.7 root 1546:
1547: /* Compare two constructor-element-type constants. */
1548:
1549: int
1550: simple_cst_equal (t1, t2)
1551: tree t1, t2;
1552: {
1553: register enum tree_code code1, code2;
1554:
1555: if (t1 == t2)
1556: return 1;
1557: if (t1 == 0 || t2 == 0)
1558: return 0;
1559:
1560: code1 = TREE_CODE (t1);
1561: code2 = TREE_CODE (t2);
1562:
1563: if (code1 == NOP_EXPR || code1 == CONVERT_EXPR)
1564: if (code2 == NOP_EXPR || code2 == CONVERT_EXPR)
1565: return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1566: else
1567: return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
1568: else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR)
1569: return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
1570:
1571: if (code1 != code2)
1572: return 0;
1573:
1574: switch (code1)
1575: {
1576: case INTEGER_CST:
1577: return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
1578: && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
1579:
1580: case REAL_CST:
1581: return TREE_REAL_CST (t1) == TREE_REAL_CST (t2);
1582:
1583: case STRING_CST:
1584: return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
1585: && !strcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2));
1586:
1587: case CONSTRUCTOR:
1588: abort ();
1589:
1590: case VAR_DECL:
1591: case PARM_DECL:
1592: case CONST_DECL:
1593: return 0;
1594:
1595: case PLUS_EXPR:
1596: case MINUS_EXPR:
1597: case MULT_EXPR:
1598: case TRUNC_DIV_EXPR:
1599: case TRUNC_MOD_EXPR:
1600: case LSHIFT_EXPR:
1601: case RSHIFT_EXPR:
1602: return (simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
1603: && simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
1604:
1605: case NEGATE_EXPR:
1606: case ADDR_EXPR:
1607: case REFERENCE_EXPR:
1608: return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1609:
1610: default:
1611: abort ();
1612: }
1613: }
1.1.1.2 root 1614:
1.1 root 1615: /* Constructors for pointer, array and function types.
1616: (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
1617: constructed by language-dependent code, not here.) */
1618:
1.1.1.2 root 1619: /* Construct, lay out and return the type of pointers to TO_TYPE.
1620: If such a type has already been constructed, reuse it. */
1621:
1.1 root 1622: tree
1623: build_pointer_type (to_type)
1624: tree to_type;
1625: {
1626: register tree t = TYPE_POINTER_TO (to_type);
1627: register struct obstack *ambient_obstack = current_obstack;
1.1.1.4 root 1628: register struct obstack *ambient_saveable_obstack = saveable_obstack;
1.1 root 1629:
1630: /* First, if we already have a type for pointers to TO_TYPE, use it. */
1631:
1632: if (t)
1633: return t;
1634:
1635: /* We need a new one. If TO_TYPE is permanent, make this permanent too. */
1.1.1.4 root 1636: if (TREE_PERMANENT (to_type))
1637: {
1638: current_obstack = &permanent_obstack;
1639: saveable_obstack = &permanent_obstack;
1640: }
1.1 root 1641:
1642: t = make_node (POINTER_TYPE);
1643: TREE_TYPE (t) = to_type;
1644:
1645: /* Record this type as the pointer to TO_TYPE. */
1646: TYPE_POINTER_TO (to_type) = t;
1647:
1.1.1.2 root 1648: /* Lay out the type. This function has many callers that are concerned
1649: with expression-construction, and this simplifies them all.
1650: Also, it guarantees the TYPE_SIZE is permanent if the type is. */
1651: layout_type (t);
1.1 root 1652:
1653: current_obstack = ambient_obstack;
1.1.1.4 root 1654: saveable_obstack = ambient_saveable_obstack;
1.1 root 1655: return t;
1656: }
1657:
1.1.1.8 ! root 1658: /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
! 1659: MAXVAL should be the maximum value in the domain
! 1660: (one less than the length of the array). */
! 1661:
! 1662: tree
! 1663: build_index_type (maxval)
! 1664: tree maxval;
! 1665: {
! 1666: register tree itype = make_node (INTEGER_TYPE);
! 1667: int maxint = TREE_INT_CST_LOW (maxval);
! 1668: TYPE_PRECISION (itype) = BITS_PER_WORD;
! 1669: TYPE_MIN_VALUE (itype) = build_int_2 (0, 0);
! 1670: TREE_TYPE (TYPE_MIN_VALUE (itype)) = itype;
! 1671: TYPE_MAX_VALUE (itype) = maxval;
! 1672: TREE_TYPE (maxval) = itype;
! 1673: TYPE_MODE (itype) = SImode;
! 1674: TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
! 1675: TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype);
! 1676: TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
! 1677: return type_hash_canon (maxint > 0 ? maxint : - maxint, itype);
! 1678: }
! 1679:
1.1.1.2 root 1680: /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
1681: and number of elements specified by the range of values of INDEX_TYPE.
1682: If such a type has already been constructed, reuse it. */
1683:
1.1 root 1684: tree
1685: build_array_type (elt_type, index_type)
1686: tree elt_type, index_type;
1687: {
1688: register tree t = make_node (ARRAY_TYPE);
1.1.1.2 root 1689: int hashcode;
1.1 root 1690:
1691: if (TREE_CODE (elt_type) == FUNCTION_TYPE)
1692: {
1.1.1.2 root 1693: error ("arrays of functions are not meaningful");
1.1 root 1694: elt_type = integer_type_node;
1695: }
1696:
1697: TREE_TYPE (t) = elt_type;
1698: TYPE_DOMAIN (t) = index_type;
1.1.1.2 root 1699:
1.1 root 1700: /* Make sure TYPE_POINTER_TO (elt_type) is filled in. */
1701: build_pointer_type (elt_type);
1.1.1.2 root 1702:
1703: if (index_type == 0)
1704: return t;
1705:
1706: hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type);
1707: t = type_hash_canon (hashcode, t);
1708:
1709: if (TYPE_SIZE (t) == 0)
1710: layout_type (t);
1.1 root 1711: return t;
1712: }
1713:
1.1.1.2 root 1714: /* Construct, lay out and return
1715: the type of functions returning type VALUE_TYPE
1716: given arguments of types ARG_TYPES.
1717: ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
1718: are data type nodes for the arguments of the function.
1719: If such a type has already been constructed, reuse it. */
1.1 root 1720:
1721: tree
1722: build_function_type (value_type, arg_types)
1723: tree value_type, arg_types;
1724: {
1725: register tree t;
1.1.1.2 root 1726: int hashcode;
1.1 root 1727:
1.1.1.2 root 1728: if (TREE_CODE (value_type) == FUNCTION_TYPE
1.1 root 1729: || TREE_CODE (value_type) == ARRAY_TYPE)
1730: {
1.1.1.2 root 1731: error ("function return type cannot be function or array");
1.1 root 1732: value_type = integer_type_node;
1733: }
1734:
1.1.1.2 root 1735: /* Make a node of the sort we want. */
1.1 root 1736: t = make_node (FUNCTION_TYPE);
1737: TREE_TYPE (t) = value_type;
1738: TYPE_ARG_TYPES (t) = arg_types;
1.1.1.2 root 1739:
1740: /* If we already have such a type, use the old one and free this one. */
1741: hashcode = TYPE_HASH (value_type) + type_hash_list (arg_types);
1742: t = type_hash_canon (hashcode, t);
1743:
1744: if (TYPE_SIZE (t) == 0)
1745: layout_type (t);
1.1 root 1746: return t;
1747: }
1.1.1.7 root 1748:
1749: /* Build the node for the type of references-to-TO_TYPE. */
1750:
1751: tree
1752: build_reference_type (to_type)
1753: tree to_type;
1754: {
1755: register tree t = TYPE_REFERENCE_TO (to_type);
1756: register struct obstack *ambient_obstack = current_obstack;
1757: register struct obstack *ambient_saveable_obstack = saveable_obstack;
1758:
1759: /* First, if we already have a type for pointers to TO_TYPE, use it. */
1760:
1761: if (t)
1762: return t;
1763:
1764: /* We need a new one. If TO_TYPE is permanent, make this permanent too. */
1765: if (TREE_PERMANENT (to_type))
1766: {
1767: current_obstack = &permanent_obstack;
1768: saveable_obstack = &permanent_obstack;
1769: }
1770:
1771: t = make_node (REFERENCE_TYPE);
1772: TREE_TYPE (t) = to_type;
1773:
1774: /* Record this type as the pointer to TO_TYPE. */
1775: TYPE_REFERENCE_TO (to_type) = t;
1776:
1777: layout_type (t);
1778:
1779: current_obstack = ambient_obstack;
1780: saveable_obstack = ambient_saveable_obstack;
1781: return t;
1782: }
1783:
1784: /* Construct, lay out and return the type of methods belonging to class
1785: BASETYPE and whose arguments and values are described by TYPE.
1786: If that type exists already, reuse it.
1787: TYPE must be a FUNCTION_TYPE node. */
1788:
1789: tree
1790: build_method_type (basetype, type)
1791: tree basetype, type;
1792: {
1793: register tree t;
1794: int hashcode;
1795:
1796: /* Make a node of the sort we want. */
1797: t = make_node (METHOD_TYPE);
1798:
1799: if (TREE_CODE (type) != FUNCTION_TYPE)
1800: abort ();
1801:
1802: TYPE_METHOD_CLASS (t) == basetype;
1803: TREE_TYPE (t) = type;
1804:
1805: /* The actual arglist for this function includes a "hidden" argument
1806: which is "this". Put it into the list of argument types. */
1807:
1808: TYPE_ARG_TYPES (t)
1809: = tree_cons (NULL, build_pointer_type (basetype), TYPE_ARG_TYPES (type));
1810:
1811: /* If we already have such a type, use the old one and free this one. */
1812: hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
1813: t = type_hash_canon (hashcode, t);
1814:
1815: if (TYPE_SIZE (t) == 0)
1816: layout_type (t);
1817:
1818: return t;
1819: }
1.1 root 1820:
1821: /* Return OP, stripped of any conversions to wider types as much as is safe.
1822: Converting the value back to OP's type makes a value equivalent to OP.
1823:
1824: If FOR_TYPE is nonzero, we return a value which, if converted to
1825: type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
1826:
1.1.1.2 root 1827: If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
1828: narrowest type that can hold the value, even if they don't exactly fit.
1829: Otherwise, bit-field references are changed to a narrower type
1830: only if they can be fetched directly from memory in that type.
1831:
1.1 root 1832: OP must have integer, real or enumeral type. Pointers are not allowed!
1833:
1834: There are some cases where the obvious value we could return
1835: would regenerate to OP if converted to OP's type,
1836: but would not extend like OP to wider types.
1837: If FOR_TYPE indicates such extension is contemplated, we eschew such values.
1838: For example, if OP is (unsigned short)(signed char)-1,
1839: we avoid returning (signed char)-1 if FOR_TYPE is int,
1840: even though extending that to an unsigned short would regenerate OP,
1841: since the result of extending (signed char)-1 to (int)
1842: is different from (int) OP. */
1843:
1844: tree
1845: get_unwidened (op, for_type)
1846: register tree op;
1847: tree for_type;
1848: {
1849: /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
1850: /* TYPE_PRECISION is safe in place of type_precision since
1851: pointer types are not allowed. */
1852: register tree type = TREE_TYPE (op);
1853: register int final_prec = TYPE_PRECISION (for_type != 0 ? for_type : type);
1854: register int uns
1855: = (for_type != 0 && for_type != type
1856: && final_prec > TYPE_PRECISION (type)
1.1.1.2 root 1857: && TREE_UNSIGNED (type));
1.1 root 1858: register tree win = op;
1859:
1860: while (TREE_CODE (op) == NOP_EXPR)
1861: {
1862: register int bitschange
1863: = TYPE_PRECISION (TREE_TYPE (op))
1864: - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
1865:
1866: /* Truncations are many-one so cannot be removed.
1867: Unless we are later going to truncate down even farther. */
1868: if (bitschange < 0
1869: && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
1870: break;
1871:
1872: /* See what's inside this conversion. If we decide to strip it,
1873: we will set WIN. */
1874: op = TREE_OPERAND (op, 0);
1875:
1876: /* If we have not stripped any zero-extensions (uns is 0),
1877: we can strip any kind of extension.
1878: If we have previously stripped a zero-extension,
1879: only zero-extensions can safely be stripped.
1880: Any extension can be stripped if the bits it would produce
1881: are all going to be discarded later by truncating to FOR_TYPE. */
1882:
1883: if (bitschange > 0)
1884: {
1885: if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
1886: win = op;
1.1.1.2 root 1887: /* TREE_UNSIGNED says whether this is a zero-extension.
1.1 root 1888: Let's avoid computing it if it does not affect WIN
1889: and if UNS will not be needed again. */
1890: if ((uns || TREE_CODE (op) == NOP_EXPR)
1.1.1.2 root 1891: && TREE_UNSIGNED (TREE_TYPE (op)))
1.1 root 1892: {
1893: uns = 1;
1894: win = op;
1895: }
1896: }
1897: }
1898:
1.1.1.2 root 1899: if (TREE_CODE (op) == COMPONENT_REF
1900: /* Since type_for_size always gives an integer type. */
1901: && TREE_CODE (type) != REAL_TYPE)
1902: {
1903: int innerprec = (TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)))
1904: * DECL_SIZE_UNIT (TREE_OPERAND (op, 1)));
1905: type = type_for_size (innerprec, TREE_UNSIGNED (TREE_OPERAND (op, 1)));
1906:
1907: /* We can get this structure field in the narrowest type it fits in.
1908: If FOR_TYPE is 0, do this only for a field that matches the
1909: narrower type exactly and is aligned for it (i.e. mode isn't BI).
1910: The resulting extension to its nominal type (a fullword type)
1911: must fit the same conditions as for other extensions. */
1912:
1.1.1.3 root 1913: if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
1.1.1.2 root 1914: && (for_type || DECL_MODE (TREE_OPERAND (op, 1)) != BImode)
1915: && (! uns || final_prec <= innerprec
1916: || TREE_UNSIGNED (TREE_OPERAND (op, 1)))
1917: && type != 0)
1918: {
1919: win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
1920: TREE_OPERAND (op, 1));
1921: TREE_VOLATILE (win) = TREE_VOLATILE (op);
1922: TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
1923: }
1924: }
1.1 root 1925: return win;
1926: }
1927:
1928: /* Return OP or a simpler expression for a narrower value
1929: which can be sign-extended or zero-extended to give back OP.
1930: Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
1931: or 0 if the value should be sign-extended. */
1932:
1933: tree
1934: get_narrower (op, unsignedp_ptr)
1935: register tree op;
1936: int *unsignedp_ptr;
1937: {
1938: register int uns = 0;
1939: int first = 1;
1940: register tree win = op;
1941:
1942: while (TREE_CODE (op) == NOP_EXPR)
1943: {
1944: register int bitschange
1945: = TYPE_PRECISION (TREE_TYPE (op))
1946: - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
1947:
1948: /* Truncations are many-one so cannot be removed. */
1949: if (bitschange < 0)
1950: break;
1951:
1952: /* See what's inside this conversion. If we decide to strip it,
1953: we will set WIN. */
1954: op = TREE_OPERAND (op, 0);
1955:
1956: if (bitschange > 0)
1957: {
1958: /* An extension: the outermost one can be stripped,
1959: but remember whether it is zero or sign extension. */
1960: if (first)
1.1.1.2 root 1961: uns = TREE_UNSIGNED (TREE_TYPE (op));
1.1 root 1962: /* Otherwise, if a sign extension has been stripped,
1963: only sign extensions can now be stripped;
1964: if a zero extension has been stripped, only zero-extensions. */
1.1.1.2 root 1965: else if (uns != TREE_UNSIGNED (TREE_TYPE (op)))
1.1 root 1966: break;
1967: first = 0;
1968: }
1969: /* A change in nominal type can always be stripped. */
1970:
1971: win = op;
1972: }
1973:
1.1.1.2 root 1974: if (TREE_CODE (op) == COMPONENT_REF
1975: /* Since type_for_size always gives an integer type. */
1976: && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE)
1.1 root 1977: {
1978: int innerprec = (TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)))
1979: * DECL_SIZE_UNIT (TREE_OPERAND (op, 1)));
1.1.1.2 root 1980: tree type = type_for_size (innerprec, TREE_UNSIGNED (op));
1.1 root 1981:
1982: /* We can get this structure field in a narrower type that fits it,
1983: but the resulting extension to its nominal type (a fullword type)
1.1.1.2 root 1984: must satisfy the same conditions as for other extensions.
1985:
1986: Do this only for fields that are aligned (not BImode),
1987: because when bit-field insns will be used there is no
1988: advantage in doing this. */
1.1 root 1989:
1990: if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
1.1.1.2 root 1991: && DECL_MODE (TREE_OPERAND (op, 1)) != BImode
1992: && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1)))
1.1 root 1993: && type != 0)
1994: {
1.1.1.2 root 1995: if (first)
1996: uns = TREE_UNSIGNED (TREE_OPERAND (op, 1));
1997: win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
1998: TREE_OPERAND (op, 1));
1999: TREE_VOLATILE (win) = TREE_VOLATILE (op);
2000: TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
1.1 root 2001: }
2002: }
2003: *unsignedp_ptr = uns;
2004: return win;
2005: }
2006:
2007: /* Return the precision of a type, for arithmetic purposes.
2008: Supports all types on which arithmetic is possible
2009: (including pointer types).
2010: It's not clear yet what will be right for complex types. */
2011:
2012: int
2013: type_precision (type)
2014: register tree type;
2015: {
2016: return ((TREE_CODE (type) == INTEGER_TYPE
2017: || TREE_CODE (type) == ENUMERAL_TYPE
2018: || TREE_CODE (type) == REAL_TYPE)
1.1.1.2 root 2019: ? TYPE_PRECISION (type) : POINTER_SIZE);
1.1 root 2020: }
2021:
2022: /* Nonzero if integer constant C has a value that is permissible
2023: for type TYPE (an INTEGER_TYPE). */
2024:
2025: int
2026: int_fits_type_p (c, type)
2027: tree c, type;
2028: {
1.1.1.2 root 2029: if (TREE_UNSIGNED (type))
1.1 root 2030: return (!INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type), c)
2031: && !INT_CST_LT_UNSIGNED (c, TYPE_MIN_VALUE (type)));
2032: else
2033: return (!INT_CST_LT (TYPE_MAX_VALUE (type), c)
2034: && !INT_CST_LT (c, TYPE_MIN_VALUE (type)));
2035: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.