Annotation of gcc/tree.c, revision 1.1.1.14

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: 
1.1.1.13  root        6: GNU CC is free software; you can redistribute it and/or modify
                      7: it under the terms of the GNU General Public License as published by
                      8: the Free Software Foundation; either version 1, or (at your option)
                      9: any later version.
                     10: 
1.1       root       11: GNU CC is distributed in the hope that it will be useful,
1.1.1.13  root       12: but WITHOUT ANY WARRANTY; without even the implied warranty of
                     13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     14: GNU General Public License for more details.
                     15: 
                     16: You should have received a copy of the GNU General Public License
                     17: along with GNU CC; see the file COPYING.  If not, write to
                     18: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
1.1       root       19: 
                     20: 
                     21: /* This file contains the low level primitives for operating on tree nodes,
                     22:    including allocation, list operations, interning of identifiers,
                     23:    construction of data type nodes and statement nodes,
                     24:    and construction of type conversion nodes.  It also contains
                     25:    tables index by tree code that describe how to take apart
                     26:    nodes of that code.
                     27: 
                     28:    It is intended to be language-independent, but occasionally
                     29:    calls language-dependent routines defined (for C) in typecheck.c.
                     30: 
                     31:    The low-level allocation routines oballoc and permalloc
                     32:    are used also for allocating many other kinds of objects
                     33:    by all passes of the compiler.  */
                     34: 
                     35: #include "config.h"
                     36: #include <stdio.h>
                     37: #include "tree.h"
                     38: #include "obstack.h"
1.1.1.2   root       39: #include "varargs.h"
1.1.1.14! root       40: #include "flags.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;
1.1.1.14! root      519:   register int len, hash_len;
1.1       root      520: 
                    521:   /* Compute length of text in len.  */
                    522:   for (len = 0; text[len]; len++);
                    523: 
1.1.1.14! root      524:   /* Decide how much of that length to hash on */
        !           525:   hash_len = len;
        !           526:   if (warn_id_clash && len > id_clash_len)
        !           527:     hash_len = id_clash_len;
        !           528: 
1.1       root      529:   /* Compute hash code */
1.1.1.14! root      530:   hi = hash_len;
        !           531:   for (i = 0; i < hash_len; i++)
1.1       root      532:     hi = ((hi * 613) + (unsigned)(text[i]));
                    533: 
                    534:   hi &= (1 << HASHBITS) - 1;
                    535:   hi %= MAX_HASH_TABLE;
                    536:   
                    537:   /* Search table for identifier */
1.1.1.14! root      538:   for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
        !           539:     if (IDENTIFIER_LENGTH (idp) == len
        !           540:        && !strcmp (IDENTIFIER_POINTER (idp), text))
1.1       root      541:       return idp;              /* <-- return if found */
1.1.1.14! root      542:   
        !           543:   /* Not found; optionally warn about a similar identifier */
        !           544:   if (warn_id_clash && len > id_clash_len)
        !           545:     for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
        !           546:       if (!strncmp (IDENTIFIER_POINTER (idp), text, id_clash_len))
        !           547:        {
        !           548:          warning ("`%s' and `%s' identical in first n characters",
        !           549:                   IDENTIFIER_POINTER (idp), text);
        !           550:          break;
        !           551:        }
1.1       root      552: 
                    553:   /* Not found, create one, add to chain */
                    554:   idp = make_node (IDENTIFIER_NODE);
                    555:   IDENTIFIER_LENGTH (idp) = len;
                    556: 
                    557:   IDENTIFIER_POINTER (idp) = obstack_copy0 (&permanent_obstack, text, len);
                    558: 
                    559:   TREE_CHAIN (idp) = hash_table[hi];
                    560:   hash_table[hi] = idp;
                    561:   return idp;                  /* <-- return if created */
                    562: }
                    563: 
                    564: /* Return a newly constructed INTEGER_CST node whose constant value
                    565:    is specified by the two ints LOW and HI.
1.1.1.2   root      566:    The TREE_TYPE is set to `int'.  */
1.1       root      567: 
                    568: tree
                    569: build_int_2 (low, hi)
                    570:      int low, hi;
                    571: {
                    572:   register tree t = make_node (INTEGER_CST);
                    573:   TREE_INT_CST_LOW (t) = low;
                    574:   TREE_INT_CST_HIGH (t) = hi;
                    575:   TREE_TYPE (t) = integer_type_node;
                    576:   return t;
                    577: }
                    578: 
1.1.1.4   root      579: /* Return a new REAL_CST node whose type is TYPE and value is D.  */
1.1       root      580: 
                    581: tree
1.1.1.4   root      582: build_real (type, d)
                    583:      tree type;
1.1.1.12  root      584:      REAL_VALUE_TYPE d;
1.1       root      585: {
                    586:   tree v;
                    587: 
1.1.1.4   root      588:   /* Check for valid float value for this type on this target machine;
                    589:      if not, can print error message and store a valid value in D.  */
                    590: #ifdef CHECK_FLOAT_VALUE
                    591:   CHECK_FLOAT_VALUE (TYPE_MODE (type), d);
                    592: #endif
                    593: 
1.1       root      594:   v = make_node (REAL_CST);
1.1.1.4   root      595:   TREE_TYPE (v) = type;
1.1       root      596:   TREE_REAL_CST (v) = d;
                    597:   return v;
                    598: }
                    599: 
1.1.1.4   root      600: /* Return a new REAL_CST node whose type is TYPE
                    601:    and whose value is the integer value of the INTEGER_CST node I.  */
1.1       root      602: 
1.1.1.12  root      603: #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
                    604: /* This function can't be implemented if we can't do arithmetic
                    605:    on the float representation.  */
                    606: 
1.1       root      607: tree
1.1.1.4   root      608: build_real_from_int_cst (type, i)
                    609:      tree type;
1.1       root      610:      tree i;
                    611: {
                    612:   tree v;
1.1.1.2   root      613:   double d;
1.1       root      614: 
                    615:   v = make_node (REAL_CST);
1.1.1.4   root      616:   TREE_TYPE (v) = type;
1.1.1.2   root      617: 
1.1.1.12  root      618: #ifdef REAL_ARITHMETIC
                    619:   REAL_VALUE_FROM_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i));
                    620: #else /* not REAL_ARITHMETIC */
1.1.1.2   root      621:   if (TREE_INT_CST_HIGH (i) < 0)
                    622:     {
                    623:       d = (double) (~ TREE_INT_CST_HIGH (i));
                    624:       d *= ((double) (1 << (HOST_BITS_PER_INT / 2))
                    625:            * (double) (1 << (HOST_BITS_PER_INT / 2)));
                    626:       d += (double) (unsigned) (~ TREE_INT_CST_LOW (i));
                    627:       d = (- d - 1.0);
                    628:     }
                    629:   else
                    630:     {
                    631:       d = (double) TREE_INT_CST_HIGH (i);
                    632:       d *= ((double) (1 << (HOST_BITS_PER_INT / 2))
                    633:            * (double) (1 << (HOST_BITS_PER_INT / 2)));
                    634:       d += (double) (unsigned) TREE_INT_CST_LOW (i);
                    635:     }
1.1.1.12  root      636: #endif /* not REAL_ARITHMETIC */
1.1.1.2   root      637: 
1.1.1.6   root      638:   /* Check for valid float value for this type on this target machine;
                    639:      if not, can print error message and store a valid value in D.  */
                    640: #ifdef CHECK_FLOAT_VALUE
                    641:   CHECK_FLOAT_VALUE (TYPE_MODE (type), d);
                    642: #endif
                    643: 
1.1.1.2   root      644:   TREE_REAL_CST (v) = d;
1.1       root      645:   return v;
                    646: }
                    647: 
1.1.1.12  root      648: #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
                    649: 
1.1       root      650: /* Return a newly constructed STRING_CST node whose value is
                    651:    the LEN characters at STR.
                    652:    The TREE_TYPE is not initialized.  */
                    653: 
                    654: tree
                    655: build_string (len, str)
                    656:      int len;
                    657:      char *str;
                    658: {
                    659:   register tree s = make_node (STRING_CST);
                    660:   TREE_STRING_LENGTH (s) = len;
1.1.1.2   root      661:   TREE_STRING_POINTER (s) = obstack_copy0 (saveable_obstack, str, len);
1.1       root      662:   return s;
                    663: }
                    664: 
                    665: /* Return a newly constructed COMPLEX_CST node whose value is
                    666:    specified by the real and imaginary parts REAL and IMAG.
                    667:    Both REAL and IMAG should be constant nodes.
                    668:    The TREE_TYPE is not initialized.  */
                    669: 
                    670: tree
                    671: build_complex (real, imag)
                    672:      tree real, imag;
                    673: {
                    674:   register tree t = make_node (COMPLEX_CST);
                    675:   TREE_REALPART (t) = real;
                    676:   TREE_IMAGPART (t) = imag;
                    677:   return t;
                    678: }
                    679: 
                    680: /* Return 1 if EXPR is the integer constant zero.  */
                    681: 
                    682: int
                    683: integer_zerop (expr)
                    684:      tree expr;
                    685: {
1.1.1.2   root      686:   return (TREE_CODE (expr) == INTEGER_CST
                    687:          && TREE_INT_CST_LOW (expr) == 0
                    688:          && TREE_INT_CST_HIGH (expr) == 0);
1.1       root      689: }
                    690: 
                    691: /* Return 1 if EXPR is the integer constant one.  */
                    692: 
                    693: int
                    694: integer_onep (expr)
                    695:      tree expr;
                    696: {
1.1.1.2   root      697:   return (TREE_CODE (expr) == INTEGER_CST
                    698:          && TREE_INT_CST_LOW (expr) == 1
                    699:          && TREE_INT_CST_HIGH (expr) == 0);
1.1       root      700: }
                    701: 
                    702: /* Return 1 if EXPR is an integer containing all 1's
                    703:    in as much precision as it contains.  */
                    704: 
                    705: int
                    706: integer_all_onesp (expr)
                    707:      tree expr;
                    708: {
                    709:   register int prec;
                    710:   register int uns;
                    711: 
                    712:   if (TREE_CODE (expr) != INTEGER_CST)
                    713:     return 0;
                    714: 
1.1.1.2   root      715:   uns = TREE_UNSIGNED (TREE_TYPE (expr));
1.1       root      716:   if (!uns)
                    717:     return TREE_INT_CST_LOW (expr) == -1 && TREE_INT_CST_HIGH (expr) == -1;
                    718: 
                    719:   prec = TYPE_PRECISION (TREE_TYPE (expr));
                    720:   if (prec >= HOST_BITS_PER_INT)
                    721:     return TREE_INT_CST_LOW (expr) == -1
                    722:       && TREE_INT_CST_HIGH (expr) == (1 << (prec - HOST_BITS_PER_INT)) - 1;
                    723:   else
                    724:     return TREE_INT_CST_LOW (expr) == (1 << prec) - 1;
                    725: }
                    726: 
                    727: /* Return the length of a chain of nodes chained through TREE_CHAIN.
                    728:    We expect a null pointer to mark the end of the chain.
                    729:    This is the Lisp primitive `length'.  */
                    730: 
                    731: int
                    732: list_length (t)
                    733:      tree t;
                    734: {
                    735:   register tree tail;
                    736:   register int len = 0;
                    737: 
                    738:   for (tail = t; tail; tail = TREE_CHAIN (tail))
                    739:     len++;
                    740: 
                    741:   return len;
                    742: }
                    743: 
                    744: /* Concatenate two chains of nodes (chained through TREE_CHAIN)
                    745:    by modifying the last node in chain 1 to point to chain 2.
                    746:    This is the Lisp primitive `nconc'.  */
                    747: 
                    748: tree
                    749: chainon (op1, op2)
                    750:      tree op1, op2;
                    751: {
                    752:   tree t;
                    753: 
                    754:   if (op1)
                    755:     {
                    756:       for (t = op1; TREE_CHAIN (t); t = TREE_CHAIN (t))
                    757:        if (t == op2) abort (); /* Circularity being created */
                    758:       TREE_CHAIN (t) = op2;
                    759:       return op1;
                    760:     }
                    761:   else return op2;
                    762: }
                    763: 
                    764: /* Return a newly created TREE_LIST node whose
                    765:    purpose and value fields are PARM and VALUE.  */
                    766: 
                    767: tree
                    768: build_tree_list (parm, value)
                    769:      tree parm, value;
                    770: {
                    771:   register tree t = make_node (TREE_LIST);
                    772:   TREE_PURPOSE (t) = parm;
                    773:   TREE_VALUE (t) = value;
                    774:   return t;
                    775: }
                    776: 
                    777: /* Return a newly created TREE_LIST node whose
                    778:    purpose and value fields are PARM and VALUE
                    779:    and whose TREE_CHAIN is CHAIN.  */
                    780: 
                    781: tree
                    782: tree_cons (purpose, value, chain)
                    783:      tree purpose, value, chain;
                    784: {
                    785:   register tree node = make_node (TREE_LIST);
                    786:   TREE_CHAIN (node) = chain;
                    787:   TREE_PURPOSE (node) = purpose;
                    788:   TREE_VALUE (node) = value;
                    789:   return node;
                    790: }
                    791: 
1.1.1.2   root      792: /* Same as `tree_cons' but make a permanent object.  */
                    793: 
                    794: tree
                    795: perm_tree_cons (purpose, value, chain)
                    796:      tree purpose, value, chain;
                    797: {
                    798:   register tree node;
                    799:   register struct obstack *ambient_obstack = current_obstack;
                    800:   current_obstack = &permanent_obstack;
                    801: 
                    802:   node = make_node (TREE_LIST);
                    803:   TREE_CHAIN (node) = chain;
                    804:   TREE_PURPOSE (node) = purpose;
                    805:   TREE_VALUE (node) = value;
                    806: 
                    807:   current_obstack = ambient_obstack;
                    808:   return node;
                    809: }
                    810: 
1.1.1.7   root      811: /* Same as `tree_cons', but make this node temporary, regardless.  */
                    812: 
                    813: tree
                    814: temp_tree_cons (purpose, value, chain)
                    815:      tree purpose, value, chain;
                    816: {
                    817:   register tree node;
                    818:   register struct obstack *ambient_obstack = current_obstack;
                    819:   current_obstack = &temporary_obstack;
                    820: 
                    821:   node = make_node (TREE_LIST);
                    822:   TREE_CHAIN (node) = chain;
                    823:   TREE_PURPOSE (node) = purpose;
                    824:   TREE_VALUE (node) = value;
                    825: 
                    826:   current_obstack = ambient_obstack;
                    827:   return node;
                    828: }
                    829: 
1.1.1.9   root      830: /* Same as `tree_cons', but save this node if the function's RTL is saved.  */
                    831: 
                    832: tree
                    833: saveable_tree_cons (purpose, value, chain)
                    834:      tree purpose, value, chain;
                    835: {
                    836:   register tree node;
                    837:   register struct obstack *ambient_obstack = current_obstack;
                    838:   current_obstack = saveable_obstack;
                    839: 
                    840:   node = make_node (TREE_LIST);
                    841:   TREE_CHAIN (node) = chain;
                    842:   TREE_PURPOSE (node) = purpose;
                    843:   TREE_VALUE (node) = value;
                    844: 
                    845:   current_obstack = ambient_obstack;
                    846:   return node;
                    847: }
                    848: 
1.1       root      849: /* Return the last node in a chain of nodes (chained through TREE_CHAIN).  */
                    850: 
                    851: tree
                    852: tree_last (chain)
                    853:      register tree chain;
                    854: {
                    855:   register tree next;
                    856:   if (chain)
                    857:     while (next = TREE_CHAIN (chain))
                    858:       chain = next;
                    859:   return chain;
                    860: }
                    861: 
                    862: /* Reverse the order of elements in the chain T,
                    863:    and return the new head of the chain (old last element).  */
                    864: 
                    865: tree
                    866: nreverse (t)
                    867:      tree t;
                    868: {
                    869:   register tree prev = 0, decl, next;
                    870:   for (decl = t; decl; decl = next)
                    871:     {
                    872:       next = TREE_CHAIN (decl);
                    873:       TREE_CHAIN (decl) = prev;
                    874:       prev = decl;
                    875:     }
                    876:   return prev;
                    877: }
                    878: 
                    879: /* Return the size nominally occupied by an object of type TYPE
                    880:    when it resides in memory.  The value is measured in units of bytes,
                    881:    and its data type is that normally used for type sizes
                    882:    (which is the first type created by make_signed_type or
                    883:    make_unsigned_type).  */
                    884: 
                    885: tree
                    886: size_in_bytes (type)
                    887:      tree type;
                    888: {
                    889:   if (type == error_mark_node)
                    890:     return integer_zero_node;
1.1.1.13  root      891:   type = TYPE_MAIN_VARIANT (type);
1.1.1.2   root      892:   if (TYPE_SIZE (type) == 0)
                    893:     {
                    894:       incomplete_type_error (0, type);
                    895:       return integer_zero_node;
                    896:     }
1.1       root      897:   return convert_units (TYPE_SIZE (type), TYPE_SIZE_UNIT (type),
                    898:                        BITS_PER_UNIT);
                    899: }
                    900: 
1.1.1.2   root      901: /* Return the size of TYPE (in bytes) as an integer,
                    902:    or return -1 if the size can vary.  */
                    903: 
                    904: int
                    905: int_size_in_bytes (type)
                    906:      tree type;
                    907: {
                    908:   int size;
                    909:   if (type == error_mark_node)
                    910:     return 0;
1.1.1.13  root      911:   type = TYPE_MAIN_VARIANT (type);
1.1.1.2   root      912:   if (TYPE_SIZE (type) == 0)
                    913:     return -1;
                    914:   if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
                    915:     return -1;
                    916:   size = TREE_INT_CST_LOW (TYPE_SIZE (type)) * TYPE_SIZE_UNIT (type);
                    917:   return (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
                    918: }
                    919: 
1.1.1.7   root      920: /* Return, as an INTEGER_CST node, the number of elements for
                    921:    TYPE (which is an ARRAY_TYPE).  */
                    922: 
                    923: tree
                    924: array_type_nelts (type)
                    925:      tree type;
                    926: {
                    927:   tree index_type = TYPE_DOMAIN (type);
                    928:   return (tree_int_cst_equal (TYPE_MIN_VALUE (index_type), integer_zero_node)
                    929:          ? TYPE_MAX_VALUE (index_type)
                    930:          : fold (build (MINUS_EXPR, integer_type_node,
                    931:                         TYPE_MAX_VALUE (index_type),
                    932:                         TYPE_MIN_VALUE (index_type))));
                    933: }
                    934: 
1.1       root      935: /* Return nonzero if arg is static -- a reference to an object in
                    936:    static storage.  This is not the same as the C meaning of `static'.  */
                    937: 
                    938: int
                    939: staticp (arg)
                    940:      tree arg;
                    941: {
                    942:   register enum tree_code code = TREE_CODE (arg);
                    943: 
1.1.1.2   root      944:   if ((code == VAR_DECL || code == FUNCTION_DECL || code == CONSTRUCTOR)
1.1       root      945:       && (TREE_STATIC (arg) || TREE_EXTERNAL (arg)))
                    946:     return 1;
                    947: 
1.1.1.2   root      948:   if (code == STRING_CST)
                    949:     return 1;
                    950: 
1.1       root      951:   if (code == COMPONENT_REF)
1.1.1.10  root      952:     return (DECL_VOFFSET (TREE_OPERAND (arg, 1)) == 0
                    953:            && staticp (TREE_OPERAND (arg, 0)));
                    954: 
                    955:   if (code == INDIRECT_REF)
                    956:     return TREE_LITERAL (TREE_OPERAND (arg, 0));
1.1       root      957: 
1.1.1.2   root      958:   if (code == ARRAY_REF)
                    959:     {
                    960:       if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
                    961:          && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
                    962:        return staticp (TREE_OPERAND (arg, 0));
                    963:     }
                    964: 
1.1       root      965:   return 0;
                    966: }
                    967: 
1.1.1.2   root      968: /* Return nonzero if REF is an lvalue valid for this language.
                    969:    Lvalues can be assigned, unless they have TREE_READONLY.
                    970:    Lvalues can have their address taken, unless they have TREE_REGDECL.  */
1.1       root      971: 
                    972: int
1.1.1.2   root      973: lvalue_p (ref)
1.1       root      974:      tree ref;
                    975: {
                    976:   register enum tree_code code = TREE_CODE (ref);
                    977: 
1.1.1.2   root      978:   if (language_lvalue_valid (ref))
                    979:     switch (code)
                    980:       {
                    981:       case COMPONENT_REF:
                    982:        return lvalue_p (TREE_OPERAND (ref, 0));
                    983: 
                    984:       case STRING_CST:
                    985:        return 1;
                    986: 
                    987:       case INDIRECT_REF:
                    988:       case ARRAY_REF:
                    989:       case VAR_DECL:
                    990:       case PARM_DECL:
                    991:       case RESULT_DECL:
                    992:       case ERROR_MARK:
                    993:        if (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE)
                    994:          return 1;
1.1.1.7   root      995:        break;
                    996: 
                    997:       case CALL_EXPR:
                    998:        if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
                    999:          return 1;
1.1.1.2   root     1000:       }
1.1       root     1001:   return 0;
                   1002: }
1.1.1.2   root     1003: 
                   1004: /* Return nonzero if REF is an lvalue valid for this language;
                   1005:    otherwise, print an error message and return zero.  */
                   1006: 
                   1007: int
                   1008: lvalue_or_else (ref, string)
                   1009:      tree ref;
                   1010:      char *string;
                   1011: {
                   1012:   int win = lvalue_p (ref);
                   1013:   if (! win)
                   1014:     error ("invalid lvalue in %s", string);
                   1015:   return win;
                   1016: }
1.1       root     1017: 
                   1018: /* This should be applied to any node which may be used in more than one place,
                   1019:    but must be evaluated only once.  Normally, the code generator would
                   1020:    reevaluate the node each time; this forces it to compute it once and save
                   1021:    the result.  This is done by encapsulating the node in a SAVE_EXPR.  */
                   1022: 
                   1023: tree
                   1024: save_expr (expr)
                   1025:      tree expr;
                   1026: {
                   1027:   register tree t = fold (expr);
                   1028: 
1.1.1.2   root     1029:   /* If the tree evaluates to a constant, then we don't want to hide that
1.1       root     1030:      fact (i.e. this allows further folding, and direct checks for constants).
                   1031:      Since it is no problem to reevaluate literals, we just return the 
                   1032:      literal node. */
                   1033: 
                   1034:   if (TREE_LITERAL (t) || TREE_READONLY (t) || TREE_CODE (t) == SAVE_EXPR)
                   1035:     return t;
                   1036: 
1.1.1.2   root     1037:   return build (SAVE_EXPR, TREE_TYPE (expr), t, NULL);
1.1       root     1038: }
                   1039: 
                   1040: /* Stabilize a reference so that we can use it any number of times
                   1041:    without causing its operands to be evaluated more than once.
1.1.1.2   root     1042:    Returns the stabilized reference.
                   1043: 
                   1044:    Also allows conversion expressions whose operands are references.
                   1045:    Any other kind of expression is returned unchanged.  */
1.1       root     1046: 
                   1047: tree
                   1048: stabilize_reference (ref)
                   1049:      tree ref;
                   1050: {
                   1051:   register tree result;
                   1052:   register enum tree_code code = TREE_CODE (ref);
                   1053: 
1.1.1.2   root     1054:   switch (code)
1.1       root     1055:     {
1.1.1.2   root     1056:     case VAR_DECL:
                   1057:     case PARM_DECL:
                   1058:     case RESULT_DECL:
1.1       root     1059:       result = ref;
1.1.1.2   root     1060:       break;
                   1061: 
                   1062:     case NOP_EXPR:
                   1063:     case CONVERT_EXPR:
                   1064:     case FLOAT_EXPR:
                   1065:     case FIX_TRUNC_EXPR:
                   1066:     case FIX_FLOOR_EXPR:
                   1067:     case FIX_ROUND_EXPR:
                   1068:     case FIX_CEIL_EXPR:
                   1069:       result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
                   1070:       break;
                   1071: 
                   1072:     case INDIRECT_REF:
                   1073:       result = build_nt (INDIRECT_REF, save_expr (TREE_OPERAND (ref, 0)));
                   1074:       break;
                   1075: 
                   1076:     case COMPONENT_REF:
                   1077:       result = build_nt (COMPONENT_REF,
                   1078:                         stabilize_reference (TREE_OPERAND (ref, 0)),
                   1079:                         TREE_OPERAND (ref, 1));
                   1080:       break;
                   1081: 
                   1082:     case ARRAY_REF:
                   1083:       result = build_nt (ARRAY_REF, stabilize_reference (TREE_OPERAND (ref, 0)),
                   1084:                         save_expr (TREE_OPERAND (ref, 1)));
                   1085:       break;
                   1086: 
                   1087:       /* If arg isn't a kind of lvalue we recognize, make no change.
                   1088:         Caller should recognize the error for an invalid lvalue.  */
                   1089:     default:
                   1090:       return ref;
                   1091: 
                   1092:     case ERROR_MARK:
1.1       root     1093:       return error_mark_node;
                   1094:     }
                   1095: 
                   1096:   TREE_TYPE (result) = TREE_TYPE (ref);
1.1.1.2   root     1097:   TREE_READONLY (result) = TREE_READONLY (ref);
1.1       root     1098:   TREE_VOLATILE (result) = TREE_VOLATILE (ref);
1.1.1.2   root     1099:   TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
1.1       root     1100: 
                   1101:   return result;
                   1102: }
                   1103: 
                   1104: /* Low-level constructors for expressions.  */
                   1105: 
1.1.1.2   root     1106: /* Build an expression of code CODE, data type TYPE,
                   1107:    and operands as specified by the arguments ARG1 and following arguments.
                   1108:    Expressions and reference nodes can be created this way.
                   1109:    Constants, decls, types and misc nodes cannot be.  */
1.1       root     1110: 
                   1111: tree
1.1.1.2   root     1112: build (va_alist)
                   1113:      va_dcl
1.1       root     1114: {
1.1.1.2   root     1115:   register va_list p;
                   1116:   enum tree_code code;
                   1117:   register tree t;
                   1118:   register int length;
                   1119:   register int i;
                   1120: 
                   1121:   va_start (p);
1.1       root     1122: 
1.1.1.2   root     1123:   code = va_arg (p, enum tree_code);
                   1124:   t = make_node (code);
                   1125:   length = tree_code_length[(int) code];
                   1126:   TREE_TYPE (t) = va_arg (p, tree);
                   1127: 
                   1128:   if (length == 2)
                   1129:     {
                   1130:       /* This is equivalent to the loop below, but faster.  */
                   1131:       register tree arg0 = va_arg (p, tree);
                   1132:       register tree arg1 = va_arg (p, tree);
                   1133:       TREE_OPERAND (t, 0) = arg0;
                   1134:       TREE_OPERAND (t, 1) = arg1;
                   1135:       TREE_VOLATILE (t)
                   1136:        = (arg0 && TREE_VOLATILE (arg0)) || (arg1 && TREE_VOLATILE (arg1));
                   1137:     }
                   1138:   else
                   1139:     {
                   1140:       for (i = 0; i < length; i++)
                   1141:        {
                   1142:          register tree operand = va_arg (p, tree);
                   1143:          TREE_OPERAND (t, i) = operand;
                   1144:          if (operand && TREE_VOLATILE (operand))
                   1145:            TREE_VOLATILE (t) = 1;
                   1146:        }
                   1147:     }
                   1148:   va_end (p);
1.1       root     1149:   return t;
                   1150: }
                   1151: 
1.1.1.2   root     1152: /* Similar except don't specify the TREE_TYPE
                   1153:    and leave the TREE_VOLATILE as 0.
                   1154:    It is permissible for arguments to be null,
                   1155:    or even garbage if their values do not matter.  */
1.1       root     1156: 
                   1157: tree
1.1.1.2   root     1158: build_nt (va_alist)
                   1159:      va_dcl
1.1       root     1160: {
1.1.1.2   root     1161:   register va_list p;
                   1162:   register enum tree_code code;
                   1163:   register tree t;
                   1164:   register int length;
                   1165:   register int i;
                   1166: 
                   1167:   va_start (p);
1.1       root     1168: 
1.1.1.2   root     1169:   code = va_arg (p, enum tree_code);
                   1170:   t = make_node (code);
                   1171:   length = tree_code_length[(int) code];
                   1172: 
                   1173:   for (i = 0; i < length; i++)
                   1174:     TREE_OPERAND (t, i) = va_arg (p, tree);
                   1175: 
                   1176:   va_end (p);
1.1       root     1177:   return t;
                   1178: }
1.1.1.11  root     1179: 
                   1180: tree
                   1181: build_op_identifier (op1, op2)
                   1182:      tree op1, op2;
                   1183: {
                   1184:   register tree t = make_node (OP_IDENTIFIER);
                   1185:   TREE_PURPOSE (t) = op1;
                   1186:   TREE_VALUE (t) = op2;
                   1187:   return t;
                   1188: }
1.1.1.2   root     1189: 
                   1190: /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
                   1191:    We do NOT enter this node in any sort of symbol table.
1.1       root     1192: 
1.1.1.2   root     1193:    layout_decl is used to set up the decl's storage layout.
                   1194:    Other slots are initialized to 0 or null pointers.  */
1.1       root     1195: 
                   1196: tree
1.1.1.2   root     1197: build_decl (code, name, type)
                   1198:      enum tree_code code;
                   1199:      tree name, type;
                   1200: {
                   1201:   register tree t;
                   1202: 
                   1203:   t = make_node (code);
                   1204: 
                   1205: /*  if (type == error_mark_node)
                   1206:     type = integer_type_node; */
                   1207: /* That is not done, deliberately, so that having error_mark_node
                   1208:    as the type can suppress useless errors in the use of this variable.  */
                   1209: 
                   1210:   DECL_NAME (t) = name;
                   1211:   TREE_TYPE (t) = type;
                   1212:   DECL_ARGUMENTS (t) = NULL_TREE;
                   1213:   DECL_INITIAL (t) = NULL_TREE;
                   1214: 
                   1215:   if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
                   1216:     layout_decl (t, 0);
                   1217:   else if (code == FUNCTION_DECL)
                   1218:     DECL_MODE (t) = FUNCTION_MODE;
                   1219: 
1.1       root     1220:   return t;
                   1221: }
                   1222: 
1.1.1.7   root     1223: #if 0
1.1       root     1224: /* Low-level constructors for statements.
                   1225:    These constructors all expect source file name and line number
                   1226:    as arguments, as well as enough arguments to fill in the data
                   1227:    in the statement node.  */
                   1228: 
                   1229: tree
                   1230: build_goto (filename, line, label)
                   1231:      char *filename;
                   1232:      int line;
                   1233:      tree label;
                   1234: {
                   1235:   register tree t = make_node (GOTO_STMT);
                   1236:   STMT_SOURCE_FILE (t) = filename;
                   1237:   STMT_SOURCE_LINE (t) = line;
                   1238:   STMT_BODY (t) = label;
                   1239:   return t;
                   1240: }
                   1241: 
                   1242: tree
                   1243: build_return (filename, line, arg)
                   1244:      char *filename;
                   1245:      int line;
                   1246:      tree arg;
                   1247: {
                   1248:   register tree t = make_node (RETURN_STMT);
                   1249: 
                   1250:   STMT_SOURCE_FILE (t) = filename;
                   1251:   STMT_SOURCE_LINE (t) = line;
                   1252:   STMT_BODY (t) = arg;
                   1253:   return t;
                   1254: }
                   1255: 
                   1256: tree
                   1257: build_expr_stmt (filename, line, expr)
                   1258:      char *filename;
                   1259:      int line;
                   1260:      tree expr;
                   1261: {
                   1262:   register tree t = make_node (EXPR_STMT);
                   1263: 
                   1264:   STMT_SOURCE_FILE (t) = filename;
                   1265:   STMT_SOURCE_LINE (t) = line;
                   1266:   STMT_BODY (t) = expr;
                   1267:   return t;
                   1268: }
                   1269: 
                   1270: tree
                   1271: build_if (filename, line, cond, thenclause, elseclause)
                   1272:      char *filename;
                   1273:      int line;
                   1274:      tree cond, thenclause, elseclause;
                   1275: {
                   1276:   register tree t = make_node (IF_STMT);
                   1277: 
                   1278:   STMT_SOURCE_FILE (t) = filename;
                   1279:   STMT_SOURCE_LINE (t) = line;
                   1280:   STMT_COND (t) = cond;
                   1281:   STMT_THEN (t) = thenclause;
                   1282:   STMT_ELSE (t) = elseclause;
                   1283:   return t;
                   1284: }
                   1285: 
                   1286: tree
                   1287: build_exit (filename, line, cond)
                   1288:      char *filename;
                   1289:      int line;
                   1290:      tree cond;
                   1291: {
                   1292:   register tree t = make_node (EXIT_STMT);
                   1293:   STMT_SOURCE_FILE (t) = filename;
                   1294:   STMT_SOURCE_LINE (t) = line;
                   1295:   STMT_BODY (t) = cond;
                   1296:   return t;
                   1297: }
                   1298: 
                   1299: tree
                   1300: build_asm_stmt (filename, line, asmcode)
                   1301:      char *filename;
                   1302:      int line;
                   1303:      tree asmcode;
                   1304: {
                   1305:   register tree t = make_node (ASM_STMT);
                   1306:   STMT_SOURCE_FILE (t) = filename;
                   1307:   STMT_SOURCE_LINE (t) = line;
                   1308:   STMT_BODY (t) = asmcode;
                   1309:   return t;
                   1310: }
                   1311: 
                   1312: tree
                   1313: build_case (filename, line, object, cases)
                   1314:      char *filename;
                   1315:      int line;
                   1316:      tree object, cases;
                   1317: {
                   1318:   register tree t = make_node (CASE_STMT);
                   1319:   STMT_SOURCE_FILE (t) = filename;
                   1320:   STMT_SOURCE_LINE (t) = line;
                   1321:   STMT_CASE_INDEX (t) = object;
                   1322:   STMT_CASE_LIST (t) = cases;
                   1323:   return t;
                   1324: }
                   1325: 
                   1326: tree
1.1.1.7   root     1327: build_loop (filename, line, body)
1.1       root     1328:      char *filename;
                   1329:      int line;
1.1.1.7   root     1330:      tree body;
1.1       root     1331: {
1.1.1.7   root     1332:   register tree t = make_node (LOOP_STMT);
1.1       root     1333:   STMT_SOURCE_FILE (t) = filename;
                   1334:   STMT_SOURCE_LINE (t) = line;
                   1335:   STMT_BODY (t) = body;
                   1336:   return t;
                   1337: }
                   1338: 
                   1339: tree
1.1.1.7   root     1340: build_compound (filename, line, body)
1.1       root     1341:      char *filename;
                   1342:      int line;
                   1343:      tree body;
                   1344: {
1.1.1.7   root     1345:   register tree t = make_node (COMPOUND_STMT);
1.1       root     1346:   STMT_SOURCE_FILE (t) = filename;
                   1347:   STMT_SOURCE_LINE (t) = line;
                   1348:   STMT_BODY (t) = body;
                   1349:   return t;
                   1350: }
                   1351: 
1.1.1.7   root     1352: #endif /* 0 */
                   1353: 
                   1354: /* LET_STMT nodes are used to represent the structure of binding contours
                   1355:    and declarations, once those contours have been exited and their contents
                   1356:    compiled.  This information is used for outputting debugging info.  */
                   1357: 
1.1       root     1358: tree
1.1.1.7   root     1359: build_let (filename, line, vars, body, supercontext, tags)
1.1       root     1360:      char *filename;
                   1361:      int line;
1.1.1.7   root     1362:      tree vars, body, supercontext, tags;
1.1       root     1363: {
1.1.1.7   root     1364:   register tree t = make_node (LET_STMT);
1.1       root     1365:   STMT_SOURCE_FILE (t) = filename;
                   1366:   STMT_SOURCE_LINE (t) = line;
1.1.1.7   root     1367:   STMT_VARS (t) = vars;
1.1       root     1368:   STMT_BODY (t) = body;
1.1.1.7   root     1369:   STMT_SUPERCONTEXT (t) = supercontext;
                   1370:   STMT_BIND_SIZE (t) = 0;
                   1371:   STMT_TYPE_TAGS (t) = tags;
1.1       root     1372:   return t;
                   1373: }
                   1374: 
                   1375: /* Return a type like TYPE except that its TREE_READONLY is CONSTP
                   1376:    and its TREE_VOLATILE is VOLATILEP.
                   1377: 
                   1378:    Such variant types already made are recorded so that duplicates
                   1379:    are not made.
                   1380: 
                   1381:    A variant types should never be used as the type of an expression.
                   1382:    Always copy the variant information into the TREE_READONLY
                   1383:    and TREE_VOLATILE of the expression, and then give the expression
                   1384:    as its type the "main variant", the variant whose TREE_READONLY
                   1385:    and TREE_VOLATILE are zero.  Use TYPE_MAIN_VARIANT to find the
                   1386:    main variant.  */
                   1387: 
                   1388: tree
                   1389: build_type_variant (type, constp, volatilep)
                   1390:      tree type;
                   1391:      int constp, volatilep;
                   1392: {
                   1393:   register tree t, m = TYPE_MAIN_VARIANT (type);
                   1394:   register struct obstack *ambient_obstack = current_obstack;
                   1395: 
                   1396:   /* Treat any nonzero argument as 1.  */
                   1397:   constp = !!constp;
                   1398:   volatilep = !!volatilep;
                   1399: 
                   1400:   /* First search the chain variants for one that is what we want.  */
                   1401: 
                   1402:   for (t = m; t; t = TYPE_NEXT_VARIANT (t))
                   1403:     if (constp == TREE_READONLY (t)
                   1404:        && volatilep == TREE_VOLATILE (t))
                   1405:       return t;
                   1406: 
                   1407:   /* We need a new one.  */
1.1.1.2   root     1408:   current_obstack
                   1409:     = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
1.1       root     1410: 
                   1411:   t = copy_node (type);
                   1412:   TREE_READONLY (t) = constp;
                   1413:   TREE_VOLATILE (t) = volatilep;
                   1414:   TYPE_POINTER_TO (t) = 0;
1.1.1.7   root     1415:   TYPE_REFERENCE_TO (t) = 0;
1.1       root     1416: 
                   1417:   /* Add this type to the chain of variants of TYPE.  */
                   1418:   TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
                   1419:   TYPE_NEXT_VARIANT (m) = t;
                   1420: 
                   1421:   current_obstack = ambient_obstack;
                   1422:   return t;
                   1423: }
                   1424: 
1.1.1.2   root     1425: /* Hashing of types so that we don't make duplicates.
                   1426:    The entry point is `type_hash_canon'.  */
                   1427: 
                   1428: /* Each hash table slot is a bucket containing a chain
                   1429:    of these structures.  */
                   1430: 
                   1431: struct type_hash
                   1432: {
                   1433:   struct type_hash *next;      /* Next structure in the bucket.  */
                   1434:   int hashcode;                        /* Hash code of this type.  */
                   1435:   tree type;                   /* The type recorded here.  */
                   1436: };
                   1437: 
                   1438: /* Now here is the hash table.  When recording a type, it is added
                   1439:    to the slot whose index is the hash code mod the table size.
                   1440:    Note that the hash table is used for several kinds of types
                   1441:    (function types, array types and array index range types, for now).
                   1442:    While all these live in the same table, they are completely independent,
                   1443:    and the hash code is computed differently for each of these.  */
                   1444: 
1.1.1.7   root     1445: #define TYPE_HASH_SIZE 59
1.1.1.2   root     1446: struct type_hash *type_hash_table[TYPE_HASH_SIZE];
                   1447: 
                   1448: /* Here is how primitive or already-canonicalized types' hash
                   1449:    codes are made.  */
                   1450: #define TYPE_HASH(TYPE) TREE_UID (TYPE)
                   1451: 
                   1452: /* Compute a hash code for a list of types (chain of TREE_LIST nodes
                   1453:    with types in the TREE_VALUE slots), by adding the hash codes
                   1454:    of the individual types.  */
                   1455: 
                   1456: int
                   1457: type_hash_list (list)
                   1458:      tree list;
                   1459: {
                   1460:   register int hashcode;
                   1461:   register tree tail;
                   1462:   for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
                   1463:     hashcode += TYPE_HASH (TREE_VALUE (tail));
                   1464:   return hashcode;
                   1465: }
                   1466: 
                   1467: /* Look in the type hash table for a type isomorphic to TYPE.
                   1468:    If one is found, return it.  Otherwise return 0.  */
                   1469: 
                   1470: tree
                   1471: type_hash_lookup (hashcode, type)
                   1472:      int hashcode;
                   1473:      tree type;
                   1474: {
                   1475:   register struct type_hash *h;
                   1476:   for (h = type_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
                   1477:     if (h->hashcode == hashcode
                   1478:        && TREE_CODE (h->type) == TREE_CODE (type)
                   1479:        && TREE_TYPE (h->type) == TREE_TYPE (type)
                   1480:        && (TYPE_MAX_VALUE (h->type) == TYPE_MAX_VALUE (type)
                   1481:            || tree_int_cst_equal (TYPE_MAX_VALUE (h->type),
                   1482:                                   TYPE_MAX_VALUE (type)))
                   1483:        && (TYPE_MIN_VALUE (h->type) == TYPE_MIN_VALUE (type)
                   1484:            || tree_int_cst_equal (TYPE_MIN_VALUE (h->type),
                   1485:                                   TYPE_MIN_VALUE (type)))
                   1486:        && (TYPE_DOMAIN (h->type) == TYPE_DOMAIN (type)
                   1487:            || (TREE_CODE (TYPE_DOMAIN (h->type)) == TREE_LIST
                   1488:                && TREE_CODE (TYPE_DOMAIN (type)) == TREE_LIST
                   1489:                && type_list_equal (TYPE_DOMAIN (h->type), TYPE_DOMAIN (type)))))
                   1490:       return h->type;
                   1491:   return 0;
                   1492: }
                   1493: 
                   1494: /* Add an entry to the type-hash-table
                   1495:    for a type TYPE whose hash code is HASHCODE.  */
                   1496: 
                   1497: void
                   1498: type_hash_add (hashcode, type)
                   1499:      int hashcode;
                   1500:      tree type;
                   1501: {
                   1502:   register struct type_hash *h;
                   1503: 
                   1504:   h = (struct type_hash *) oballoc (sizeof (struct type_hash));
                   1505:   h->hashcode = hashcode;
                   1506:   h->type = type;
                   1507:   h->next = type_hash_table[hashcode % TYPE_HASH_SIZE];
                   1508:   type_hash_table[hashcode % TYPE_HASH_SIZE] = h;
                   1509: }
                   1510: 
                   1511: /* Given TYPE, and HASHCODE its hash code, return the canonical
                   1512:    object for an identical type if one already exists.
                   1513:    Otherwise, return TYPE, and record it as the canonical object
                   1514:    if it is a permanent object.
                   1515: 
                   1516:    To use this function, first create a type of the sort you want.
                   1517:    Then compute its hash code from the fields of the type that
                   1518:    make it different from other similar types.
                   1519:    Then call this function and use the value.
                   1520:    This function frees the type you pass in if it is a duplicate.  */
                   1521: 
                   1522: /* Set to 1 to debug without canonicalization.  Never set by program.  */
                   1523: int debug_no_type_hash = 0;
                   1524: 
                   1525: tree
                   1526: type_hash_canon (hashcode, type)
                   1527:      int hashcode;
                   1528:      tree type;
                   1529: {
                   1530:   tree t1;
                   1531: 
                   1532:   if (debug_no_type_hash)
                   1533:     return type;
                   1534: 
                   1535:   t1 = type_hash_lookup (hashcode, type);
                   1536:   if (t1 != 0)
                   1537:     {
                   1538:       struct obstack *o
                   1539:        = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
                   1540:       obstack_free (o, type);
                   1541:       return t1;
                   1542:     }
                   1543: 
                   1544:   /* If this is a new type, record it for later reuse.  */
                   1545:   if (current_obstack == &permanent_obstack)
                   1546:     type_hash_add (hashcode, type);
                   1547: 
                   1548:   return type;
                   1549: }
                   1550: 
                   1551: /* Given two lists of types
                   1552:    (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
1.1.1.7   root     1553:    return 1 if the lists contain the same types in the same order.
                   1554:    Also, the TREE_PURPOSEs must match.  */
1.1.1.2   root     1555: 
                   1556: int
                   1557: type_list_equal (l1, l2)
                   1558:      tree l1, l2;
                   1559: {
                   1560:   register tree t1, t2;
                   1561:   for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
1.1.1.7   root     1562:     {
                   1563:       if (TREE_VALUE (t1) != TREE_VALUE (t2))
                   1564:        return 0;
                   1565:       if (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
                   1566:          && !simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
                   1567:        return 0;
                   1568:     }
1.1.1.2   root     1569: 
                   1570:   return t1 == t2;
                   1571: }
                   1572: 
                   1573: /* Nonzero if integer constants T1 and T2
                   1574:    represent the same constant value.  */
                   1575: 
                   1576: int
                   1577: tree_int_cst_equal (t1, t2)
                   1578:      tree t1, t2;
                   1579: {
                   1580:   if (t1 == t2)
                   1581:     return 1;
                   1582:   if (t1 == 0 || t2 == 0)
                   1583:     return 0;
                   1584:   if (TREE_CODE (t1) == INTEGER_CST
                   1585:       && TREE_CODE (t2) == INTEGER_CST
                   1586:       && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
                   1587:       && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
                   1588:     return 1;
                   1589:   return 0;
                   1590: }
                   1591: 
                   1592: /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
                   1593:    The precise way of comparison depends on their data type.  */
                   1594: 
                   1595: int
                   1596: tree_int_cst_lt (t1, t2)
                   1597:      tree t1, t2;
                   1598: {
                   1599:   if (t1 == t2)
                   1600:     return 0;
                   1601: 
                   1602:   if (!TREE_UNSIGNED (TREE_TYPE (t1)))
                   1603:     return INT_CST_LT (t1, t2);
                   1604:   return INT_CST_LT_UNSIGNED (t1, t2);
                   1605: }
1.1.1.7   root     1606: 
                   1607: /* Compare two constructor-element-type constants.  */
                   1608: 
                   1609: int
                   1610: simple_cst_equal (t1, t2)
                   1611:      tree t1, t2;
                   1612: {
                   1613:   register enum tree_code code1, code2;
                   1614: 
                   1615:   if (t1 == t2)
                   1616:     return 1;
                   1617:   if (t1 == 0 || t2 == 0)
                   1618:     return 0;
                   1619: 
                   1620:   code1 = TREE_CODE (t1);
                   1621:   code2 = TREE_CODE (t2);
                   1622: 
                   1623:   if (code1 == NOP_EXPR || code1 == CONVERT_EXPR)
                   1624:     if (code2 == NOP_EXPR || code2 == CONVERT_EXPR)
                   1625:       return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
                   1626:     else
                   1627:       return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
                   1628:   else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR)
                   1629:     return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
                   1630: 
                   1631:   if (code1 != code2)
                   1632:     return 0;
                   1633: 
                   1634:   switch (code1)
                   1635:     {
                   1636:     case INTEGER_CST:
                   1637:       return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
                   1638:        && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
                   1639: 
                   1640:     case REAL_CST:
1.1.1.12  root     1641:       return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
1.1.1.7   root     1642: 
                   1643:     case STRING_CST:
                   1644:       return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
                   1645:        && !strcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2));
                   1646: 
                   1647:     case CONSTRUCTOR:
                   1648:       abort ();
                   1649: 
                   1650:     case VAR_DECL:
                   1651:     case PARM_DECL:
                   1652:     case CONST_DECL:
                   1653:       return 0;
                   1654: 
                   1655:     case PLUS_EXPR:
                   1656:     case MINUS_EXPR:
                   1657:     case MULT_EXPR:
                   1658:     case TRUNC_DIV_EXPR:
                   1659:     case TRUNC_MOD_EXPR:
                   1660:     case LSHIFT_EXPR:
                   1661:     case RSHIFT_EXPR:
                   1662:       return (simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
                   1663:              && simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
                   1664: 
                   1665:     case NEGATE_EXPR:
                   1666:     case ADDR_EXPR:
                   1667:     case REFERENCE_EXPR:
                   1668:       return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
                   1669: 
                   1670:     default:
                   1671:       abort ();
                   1672:     }
                   1673: }
1.1.1.2   root     1674: 
1.1       root     1675: /* Constructors for pointer, array and function types.
                   1676:    (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
                   1677:    constructed by language-dependent code, not here.)  */
                   1678: 
1.1.1.2   root     1679: /* Construct, lay out and return the type of pointers to TO_TYPE.
                   1680:    If such a type has already been constructed, reuse it.  */
                   1681: 
1.1       root     1682: tree
                   1683: build_pointer_type (to_type)
                   1684:      tree to_type;
                   1685: {
                   1686:   register tree t = TYPE_POINTER_TO (to_type);
                   1687:   register struct obstack *ambient_obstack = current_obstack;
1.1.1.4   root     1688:   register struct obstack *ambient_saveable_obstack = saveable_obstack;
1.1       root     1689: 
                   1690:   /* First, if we already have a type for pointers to TO_TYPE, use it.  */
                   1691: 
                   1692:   if (t)
                   1693:     return t;
                   1694: 
                   1695:   /* We need a new one.  If TO_TYPE is permanent, make this permanent too.  */
1.1.1.4   root     1696:   if (TREE_PERMANENT (to_type))
                   1697:     {
                   1698:       current_obstack = &permanent_obstack;
                   1699:       saveable_obstack = &permanent_obstack;
                   1700:     }
1.1       root     1701: 
                   1702:   t = make_node (POINTER_TYPE);
                   1703:   TREE_TYPE (t) = to_type;
                   1704: 
                   1705:   /* Record this type as the pointer to TO_TYPE.  */
                   1706:   TYPE_POINTER_TO (to_type) = t;
                   1707: 
1.1.1.2   root     1708:   /* Lay out the type.  This function has many callers that are concerned
                   1709:      with expression-construction, and this simplifies them all.
                   1710:      Also, it guarantees the TYPE_SIZE is permanent if the type is.  */
                   1711:   layout_type (t);
1.1       root     1712: 
                   1713:   current_obstack = ambient_obstack;
1.1.1.4   root     1714:   saveable_obstack = ambient_saveable_obstack;
1.1       root     1715:   return t;
                   1716: }
                   1717: 
1.1.1.8   root     1718: /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
                   1719:    MAXVAL should be the maximum value in the domain
                   1720:    (one less than the length of the array).  */
                   1721: 
                   1722: tree
                   1723: build_index_type (maxval)
                   1724:      tree maxval;
                   1725: {
                   1726:   register tree itype = make_node (INTEGER_TYPE);
                   1727:   int maxint = TREE_INT_CST_LOW (maxval);
                   1728:   TYPE_PRECISION (itype) = BITS_PER_WORD;
                   1729:   TYPE_MIN_VALUE (itype) = build_int_2 (0, 0);
                   1730:   TREE_TYPE (TYPE_MIN_VALUE (itype)) = itype;
                   1731:   TYPE_MAX_VALUE (itype) = maxval;
                   1732:   TREE_TYPE (maxval) = itype;
                   1733:   TYPE_MODE (itype) = SImode;
                   1734:   TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
                   1735:   TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype);
                   1736:   TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
                   1737:   return type_hash_canon (maxint > 0 ? maxint : - maxint, itype);
                   1738: }
                   1739: 
1.1.1.2   root     1740: /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
                   1741:    and number of elements specified by the range of values of INDEX_TYPE.
                   1742:    If such a type has already been constructed, reuse it.  */
                   1743: 
1.1       root     1744: tree
                   1745: build_array_type (elt_type, index_type)
                   1746:      tree elt_type, index_type;
                   1747: {
                   1748:   register tree t = make_node (ARRAY_TYPE);
1.1.1.2   root     1749:   int hashcode;
1.1       root     1750: 
                   1751:   if (TREE_CODE (elt_type) == FUNCTION_TYPE)
                   1752:     {
1.1.1.2   root     1753:       error ("arrays of functions are not meaningful");
1.1       root     1754:       elt_type = integer_type_node;
                   1755:     }
                   1756: 
                   1757:   TREE_TYPE (t) = elt_type;
                   1758:   TYPE_DOMAIN (t) = index_type;
1.1.1.2   root     1759: 
1.1       root     1760:   /* Make sure TYPE_POINTER_TO (elt_type) is filled in.  */
                   1761:   build_pointer_type (elt_type);
1.1.1.2   root     1762: 
                   1763:   if (index_type == 0)
                   1764:     return t;
                   1765: 
                   1766:   hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type);
                   1767:   t = type_hash_canon (hashcode, t);
                   1768: 
                   1769:   if (TYPE_SIZE (t) == 0)
                   1770:     layout_type (t);
1.1       root     1771:   return t;
                   1772: }
                   1773: 
1.1.1.2   root     1774: /* Construct, lay out and return
                   1775:    the type of functions returning type VALUE_TYPE
                   1776:    given arguments of types ARG_TYPES.
                   1777:    ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
                   1778:    are data type nodes for the arguments of the function.
                   1779:    If such a type has already been constructed, reuse it.  */
1.1       root     1780: 
                   1781: tree
                   1782: build_function_type (value_type, arg_types)
                   1783:      tree value_type, arg_types;
                   1784: {
                   1785:   register tree t;
1.1.1.2   root     1786:   int hashcode;
1.1       root     1787: 
1.1.1.2   root     1788:   if (TREE_CODE (value_type) == FUNCTION_TYPE
1.1       root     1789:       || TREE_CODE (value_type) == ARRAY_TYPE)
                   1790:     {
1.1.1.2   root     1791:       error ("function return type cannot be function or array");
1.1       root     1792:       value_type = integer_type_node;
                   1793:     }
                   1794: 
1.1.1.2   root     1795:   /* Make a node of the sort we want.  */
1.1       root     1796:   t = make_node (FUNCTION_TYPE);
                   1797:   TREE_TYPE (t) = value_type;
                   1798:   TYPE_ARG_TYPES (t) = arg_types;
1.1.1.2   root     1799: 
                   1800:   /* If we already have such a type, use the old one and free this one.  */
                   1801:   hashcode = TYPE_HASH (value_type) + type_hash_list (arg_types);
                   1802:   t = type_hash_canon (hashcode, t);
                   1803: 
                   1804:   if (TYPE_SIZE (t) == 0)
                   1805:     layout_type (t);
1.1       root     1806:   return t;
                   1807: }
1.1.1.7   root     1808: 
                   1809: /* Build the node for the type of references-to-TO_TYPE.  */
                   1810: 
                   1811: tree
                   1812: build_reference_type (to_type)
                   1813:      tree to_type;
                   1814: {
                   1815:   register tree t = TYPE_REFERENCE_TO (to_type);
                   1816:   register struct obstack *ambient_obstack = current_obstack;
                   1817:   register struct obstack *ambient_saveable_obstack = saveable_obstack;
                   1818: 
                   1819:   /* First, if we already have a type for pointers to TO_TYPE, use it.  */
                   1820: 
                   1821:   if (t)
                   1822:     return t;
                   1823: 
                   1824:   /* We need a new one.  If TO_TYPE is permanent, make this permanent too.  */
                   1825:   if (TREE_PERMANENT (to_type))
                   1826:     {
                   1827:       current_obstack = &permanent_obstack;
                   1828:       saveable_obstack = &permanent_obstack;
                   1829:     }
                   1830: 
                   1831:   t = make_node (REFERENCE_TYPE);
                   1832:   TREE_TYPE (t) = to_type;
                   1833: 
                   1834:   /* Record this type as the pointer to TO_TYPE.  */
                   1835:   TYPE_REFERENCE_TO (to_type) = t;
                   1836: 
                   1837:   layout_type (t);
                   1838: 
                   1839:   current_obstack = ambient_obstack;
                   1840:   saveable_obstack = ambient_saveable_obstack;
                   1841:   return t;
                   1842: }
                   1843: 
                   1844: /* Construct, lay out and return the type of methods belonging to class
                   1845:    BASETYPE and whose arguments and values are described by TYPE.
                   1846:    If that type exists already, reuse it.
                   1847:    TYPE must be a FUNCTION_TYPE node.  */
                   1848: 
                   1849: tree
                   1850: build_method_type (basetype, type)
                   1851:      tree basetype, type;
                   1852: {
                   1853:   register tree t;
                   1854:   int hashcode;
                   1855: 
                   1856:   /* Make a node of the sort we want.  */
                   1857:   t = make_node (METHOD_TYPE);
                   1858: 
                   1859:   if (TREE_CODE (type) != FUNCTION_TYPE)
                   1860:     abort ();
                   1861: 
1.1.1.11  root     1862:   TYPE_METHOD_BASETYPE (t) = basetype;
                   1863:   TREE_TYPE (t) = TREE_TYPE (type);
1.1.1.7   root     1864: 
                   1865:   /* The actual arglist for this function includes a "hidden" argument
                   1866:      which is "this".  Put it into the list of argument types.  */
                   1867: 
                   1868:   TYPE_ARG_TYPES (t)
                   1869:     = tree_cons (NULL, build_pointer_type (basetype), TYPE_ARG_TYPES (type));
                   1870: 
                   1871:   /* If we already have such a type, use the old one and free this one.  */
                   1872:   hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
                   1873:   t = type_hash_canon (hashcode, t);
                   1874: 
                   1875:   if (TYPE_SIZE (t) == 0)
                   1876:     layout_type (t);
                   1877: 
                   1878:   return t;
                   1879: }
1.1.1.11  root     1880: 
                   1881: /* Construct, lay out and return the type of methods belonging to class
                   1882:    BASETYPE and whose arguments and values are described by TYPE.
                   1883:    If that type exists already, reuse it.
                   1884:    TYPE must be a FUNCTION_TYPE node.  */
                   1885: 
                   1886: tree
                   1887: build_offset_type (basetype, type)
                   1888:      tree basetype, type;
                   1889: {
                   1890:   register tree t;
                   1891:   int hashcode;
                   1892: 
                   1893:   /* Make a node of the sort we want.  */
                   1894:   t = make_node (OFFSET_TYPE);
                   1895: 
                   1896:   TYPE_OFFSET_BASETYPE (t) = basetype;
                   1897:   TREE_TYPE (t) = type;
                   1898: 
                   1899:   /* If we already have such a type, use the old one and free this one.  */
                   1900:   hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
                   1901:   t = type_hash_canon (hashcode, t);
                   1902: 
                   1903:   if (TYPE_SIZE (t) == 0)
                   1904:     layout_type (t);
                   1905: 
                   1906:   return t;
                   1907: }
1.1       root     1908: 
                   1909: /* Return OP, stripped of any conversions to wider types as much as is safe.
                   1910:    Converting the value back to OP's type makes a value equivalent to OP.
                   1911: 
                   1912:    If FOR_TYPE is nonzero, we return a value which, if converted to
                   1913:    type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
                   1914: 
1.1.1.2   root     1915:    If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
                   1916:    narrowest type that can hold the value, even if they don't exactly fit.
                   1917:    Otherwise, bit-field references are changed to a narrower type
                   1918:    only if they can be fetched directly from memory in that type.
                   1919: 
1.1       root     1920:    OP must have integer, real or enumeral type.  Pointers are not allowed!
                   1921: 
                   1922:    There are some cases where the obvious value we could return
                   1923:    would regenerate to OP if converted to OP's type, 
                   1924:    but would not extend like OP to wider types.
                   1925:    If FOR_TYPE indicates such extension is contemplated, we eschew such values.
                   1926:    For example, if OP is (unsigned short)(signed char)-1,
                   1927:    we avoid returning (signed char)-1 if FOR_TYPE is int,
                   1928:    even though extending that to an unsigned short would regenerate OP,
                   1929:    since the result of extending (signed char)-1 to (int)
                   1930:    is different from (int) OP.  */
                   1931: 
                   1932: tree
                   1933: get_unwidened (op, for_type)
                   1934:      register tree op;
                   1935:      tree for_type;
                   1936: {
                   1937:   /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension.  */
                   1938:   /* TYPE_PRECISION is safe in place of type_precision since
                   1939:      pointer types are not allowed.  */
                   1940:   register tree type = TREE_TYPE (op);
                   1941:   register int final_prec = TYPE_PRECISION (for_type != 0 ? for_type : type);
                   1942:   register int uns
                   1943:     = (for_type != 0 && for_type != type
                   1944:        && final_prec > TYPE_PRECISION (type)
1.1.1.2   root     1945:        && TREE_UNSIGNED (type));
1.1       root     1946:   register tree win = op;
                   1947: 
                   1948:   while (TREE_CODE (op) == NOP_EXPR)
                   1949:     {
                   1950:       register int bitschange
                   1951:        = TYPE_PRECISION (TREE_TYPE (op))
                   1952:          - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
                   1953: 
                   1954:       /* Truncations are many-one so cannot be removed.
                   1955:         Unless we are later going to truncate down even farther.  */
                   1956:       if (bitschange < 0
                   1957:          && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
                   1958:        break;
                   1959: 
                   1960:       /* See what's inside this conversion.  If we decide to strip it,
                   1961:         we will set WIN.  */
                   1962:       op = TREE_OPERAND (op, 0);
                   1963: 
                   1964:       /* If we have not stripped any zero-extensions (uns is 0),
                   1965:         we can strip any kind of extension.
                   1966:         If we have previously stripped a zero-extension,
                   1967:         only zero-extensions can safely be stripped.
                   1968:         Any extension can be stripped if the bits it would produce
                   1969:         are all going to be discarded later by truncating to FOR_TYPE.  */
                   1970: 
                   1971:       if (bitschange > 0)
                   1972:        {
                   1973:          if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
                   1974:            win = op;
1.1.1.2   root     1975:          /* TREE_UNSIGNED says whether this is a zero-extension.
1.1       root     1976:             Let's avoid computing it if it does not affect WIN
                   1977:             and if UNS will not be needed again.  */
                   1978:          if ((uns || TREE_CODE (op) == NOP_EXPR)
1.1.1.2   root     1979:              && TREE_UNSIGNED (TREE_TYPE (op)))
1.1       root     1980:            {
                   1981:              uns = 1;
                   1982:              win = op;
                   1983:            }
                   1984:        }
                   1985:     }
                   1986: 
1.1.1.2   root     1987:   if (TREE_CODE (op) == COMPONENT_REF
                   1988:       /* Since type_for_size always gives an integer type.  */
                   1989:       && TREE_CODE (type) != REAL_TYPE)
                   1990:     {
                   1991:       int innerprec = (TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)))
                   1992:                       * DECL_SIZE_UNIT (TREE_OPERAND (op, 1)));
                   1993:       type = type_for_size (innerprec, TREE_UNSIGNED (TREE_OPERAND (op, 1)));
                   1994: 
                   1995:       /* We can get this structure field in the narrowest type it fits in.
                   1996:         If FOR_TYPE is 0, do this only for a field that matches the
                   1997:         narrower type exactly and is aligned for it (i.e. mode isn't BI).
                   1998:         The resulting extension to its nominal type (a fullword type)
                   1999:         must fit the same conditions as for other extensions.  */
                   2000: 
1.1.1.3   root     2001:       if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
1.1.1.2   root     2002:          && (for_type || DECL_MODE (TREE_OPERAND (op, 1)) != BImode)
                   2003:          && (! uns || final_prec <= innerprec
                   2004:              || TREE_UNSIGNED (TREE_OPERAND (op, 1)))
                   2005:          && type != 0)
                   2006:        {
                   2007:          win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
                   2008:                       TREE_OPERAND (op, 1));
                   2009:          TREE_VOLATILE (win) = TREE_VOLATILE (op);
                   2010:          TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
                   2011:        }
                   2012:     }
1.1       root     2013:   return win;
                   2014: }
                   2015: 
                   2016: /* Return OP or a simpler expression for a narrower value
                   2017:    which can be sign-extended or zero-extended to give back OP.
                   2018:    Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
                   2019:    or 0 if the value should be sign-extended.  */
                   2020: 
                   2021: tree
                   2022: get_narrower (op, unsignedp_ptr)
                   2023:      register tree op;
                   2024:      int *unsignedp_ptr;
                   2025: {
                   2026:   register int uns = 0;
                   2027:   int first = 1;
                   2028:   register tree win = op;
                   2029: 
                   2030:   while (TREE_CODE (op) == NOP_EXPR)
                   2031:     {
                   2032:       register int bitschange
                   2033:        = TYPE_PRECISION (TREE_TYPE (op))
                   2034:          - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
                   2035: 
                   2036:       /* Truncations are many-one so cannot be removed.  */
                   2037:       if (bitschange < 0)
                   2038:        break;
                   2039: 
                   2040:       /* See what's inside this conversion.  If we decide to strip it,
                   2041:         we will set WIN.  */
                   2042:       op = TREE_OPERAND (op, 0);
                   2043: 
                   2044:       if (bitschange > 0)
                   2045:        {
                   2046:          /* An extension: the outermost one can be stripped,
                   2047:             but remember whether it is zero or sign extension.  */
                   2048:          if (first)
1.1.1.2   root     2049:            uns = TREE_UNSIGNED (TREE_TYPE (op));
1.1       root     2050:          /* Otherwise, if a sign extension has been stripped,
                   2051:             only sign extensions can now be stripped;
                   2052:             if a zero extension has been stripped, only zero-extensions.  */
1.1.1.2   root     2053:          else if (uns != TREE_UNSIGNED (TREE_TYPE (op)))
1.1       root     2054:            break;
                   2055:          first = 0;
                   2056:        }
                   2057:       /* A change in nominal type can always be stripped.  */
                   2058: 
                   2059:       win = op;
                   2060:     }
                   2061: 
1.1.1.2   root     2062:   if (TREE_CODE (op) == COMPONENT_REF
                   2063:       /* Since type_for_size always gives an integer type.  */
                   2064:       && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE)
1.1       root     2065:     {
                   2066:       int innerprec = (TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)))
                   2067:                       * DECL_SIZE_UNIT (TREE_OPERAND (op, 1)));
1.1.1.2   root     2068:       tree type = type_for_size (innerprec, TREE_UNSIGNED (op));
1.1       root     2069: 
                   2070:       /* We can get this structure field in a narrower type that fits it,
                   2071:         but the resulting extension to its nominal type (a fullword type)
1.1.1.2   root     2072:         must satisfy the same conditions as for other extensions.
                   2073: 
                   2074:         Do this only for fields that are aligned (not BImode),
                   2075:         because when bit-field insns will be used there is no
                   2076:         advantage in doing this.  */
1.1       root     2077: 
                   2078:       if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
1.1.1.2   root     2079:          && DECL_MODE (TREE_OPERAND (op, 1)) != BImode
                   2080:          && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1)))
1.1       root     2081:          && type != 0)
                   2082:        {
1.1.1.2   root     2083:          if (first)
                   2084:            uns = TREE_UNSIGNED (TREE_OPERAND (op, 1));
                   2085:          win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
                   2086:                       TREE_OPERAND (op, 1));
                   2087:          TREE_VOLATILE (win) = TREE_VOLATILE (op);
                   2088:          TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
1.1       root     2089:        }
                   2090:     }
                   2091:   *unsignedp_ptr = uns;
                   2092:   return win;
                   2093: }
                   2094: 
                   2095: /* Return the precision of a type, for arithmetic purposes.
                   2096:    Supports all types on which arithmetic is possible
                   2097:    (including pointer types).
                   2098:    It's not clear yet what will be right for complex types.  */
                   2099: 
                   2100: int
                   2101: type_precision (type)
                   2102:      register tree type;
                   2103: {
                   2104:   return ((TREE_CODE (type) == INTEGER_TYPE
                   2105:           || TREE_CODE (type) == ENUMERAL_TYPE
                   2106:           || TREE_CODE (type) == REAL_TYPE)
1.1.1.2   root     2107:          ? TYPE_PRECISION (type) : POINTER_SIZE);
1.1       root     2108: }
                   2109: 
                   2110: /* Nonzero if integer constant C has a value that is permissible
                   2111:    for type TYPE (an INTEGER_TYPE).  */
                   2112: 
                   2113: int
                   2114: int_fits_type_p (c, type)
                   2115:      tree c, type;
                   2116: {
1.1.1.2   root     2117:   if (TREE_UNSIGNED (type))
1.1       root     2118:     return (!INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type), c)
                   2119:            && !INT_CST_LT_UNSIGNED (c, TYPE_MIN_VALUE (type)));
                   2120:   else
                   2121:     return (!INT_CST_LT (TYPE_MAX_VALUE (type), c)
                   2122:            && !INT_CST_LT (c, TYPE_MIN_VALUE (type)));
                   2123: }

unix.superglobalmegacorp.com

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