Annotation of gcc/tree.c, revision 1.1.1.6

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.