LCOV - code coverage report
Current view: top level - gcc/m2/gm2-gcc - m2type.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 80.6 % 1173 946
Test Date: 2023-09-09 13:19:57 Functions: 87.3 % 197 172
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* m2type.cc provides an interface to GCC type trees.
       2                 :             : 
       3                 :             : Copyright (C) 2012-2023 Free Software Foundation, Inc.
       4                 :             : Contributed by Gaius Mulley <gaius@glam.ac.uk>.
       5                 :             : 
       6                 :             : This file is part of GNU Modula-2.
       7                 :             : 
       8                 :             : GNU Modula-2 is free software; you can redistribute it and/or modify
       9                 :             : it under the terms of the GNU General Public License as published by
      10                 :             : the Free Software Foundation; either version 3, or (at your option)
      11                 :             : any later version.
      12                 :             : 
      13                 :             : GNU Modula-2 is distributed in the hope that it will be useful, but
      14                 :             : WITHOUT ANY WARRANTY; without even the implied warranty of
      15                 :             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16                 :             : General Public License for more details.
      17                 :             : 
      18                 :             : You should have received a copy of the GNU General Public License
      19                 :             : along with GNU Modula-2; see the file COPYING3.  If not see
      20                 :             : <http://www.gnu.org/licenses/>.  */
      21                 :             : 
      22                 :             : #include "gcc-consolidation.h"
      23                 :             : 
      24                 :             : #include "../gm2-lang.h"
      25                 :             : #include "../m2-tree.h"
      26                 :             : 
      27                 :             : #define m2type_c
      28                 :             : #include "m2assert.h"
      29                 :             : #include "m2block.h"
      30                 :             : #include "m2builtins.h"
      31                 :             : #include "m2convert.h"
      32                 :             : #include "m2decl.h"
      33                 :             : #include "m2except.h"
      34                 :             : #include "m2expr.h"
      35                 :             : #include "m2linemap.h"
      36                 :             : #include "m2tree.h"
      37                 :             : #include "m2treelib.h"
      38                 :             : #include "m2type.h"
      39                 :             : #include "m2options.h"
      40                 :             : 
      41                 :             : #define USE_BOOLEAN
      42                 :             : static int broken_set_debugging_info = true;
      43                 :             : 
      44                 :             : 
      45                 :             : struct GTY (()) struct_constructor
      46                 :             : {
      47                 :             :   /* Constructor_type, the type that we are constructing.  */
      48                 :             :   tree GTY ((skip (""))) constructor_type;
      49                 :             :   /* Constructor_fields, the list of fields belonging to
      50                 :             :      constructor_type.  Used by SET and RECORD constructors.  */
      51                 :             :   tree GTY ((skip (""))) constructor_fields;
      52                 :             :   /* Constructor_element_list, the list of constants used by SET and
      53                 :             :      RECORD constructors.  */
      54                 :             :   tree GTY ((skip (""))) constructor_element_list;
      55                 :             :   /* Constructor_elements, used by an ARRAY initializer all elements
      56                 :             :      are held in reverse order.  */
      57                 :             :   vec<constructor_elt, va_gc> *constructor_elements;
      58                 :             :   /* Level, the next level down in the constructor stack.  */
      59                 :             :   struct struct_constructor *level;
      60                 :             : };
      61                 :             : 
      62                 :             : static GTY (()) struct struct_constructor *top_constructor = NULL;
      63                 :             : 
      64                 :             : typedef struct GTY (()) array_desc
      65                 :             : {
      66                 :             :   int type;
      67                 :             :   tree index;
      68                 :             :   tree array;
      69                 :             :   struct array_desc *next;
      70                 :             : } array_desc;
      71                 :             : 
      72                 :             : static GTY (()) array_desc *list_of_arrays = NULL;
      73                 :             : /* Used in BuildStartFunctionType.  */
      74                 :             : static GTY (()) tree param_type_list;
      75                 :             : 
      76                 :             : static GTY (()) tree proc_type_node;
      77                 :             : static GTY (()) tree bitset_type_node;
      78                 :             : static GTY (()) tree bitnum_type_node;
      79                 :             : static GTY (()) tree m2_char_type_node;
      80                 :             : static GTY (()) tree m2_integer_type_node;
      81                 :             : static GTY (()) tree m2_cardinal_type_node;
      82                 :             : static GTY (()) tree m2_short_real_type_node;
      83                 :             : static GTY (()) tree m2_real_type_node;
      84                 :             : static GTY (()) tree m2_long_real_type_node;
      85                 :             : static GTY (()) tree m2_long_int_type_node;
      86                 :             : static GTY (()) tree m2_long_card_type_node;
      87                 :             : static GTY (()) tree m2_short_int_type_node;
      88                 :             : static GTY (()) tree m2_short_card_type_node;
      89                 :             : static GTY (()) tree m2_z_type_node;
      90                 :             : static GTY (()) tree m2_iso_loc_type_node;
      91                 :             : static GTY (()) tree m2_iso_byte_type_node;
      92                 :             : static GTY (()) tree m2_iso_word_type_node;
      93                 :             : static GTY (()) tree m2_integer8_type_node;
      94                 :             : static GTY (()) tree m2_integer16_type_node;
      95                 :             : static GTY (()) tree m2_integer32_type_node;
      96                 :             : static GTY (()) tree m2_integer64_type_node;
      97                 :             : static GTY (()) tree m2_cardinal8_type_node;
      98                 :             : static GTY (()) tree m2_cardinal16_type_node;
      99                 :             : static GTY (()) tree m2_cardinal32_type_node;
     100                 :             : static GTY (()) tree m2_cardinal64_type_node;
     101                 :             : static GTY (()) tree m2_word16_type_node;
     102                 :             : static GTY (()) tree m2_word32_type_node;
     103                 :             : static GTY (()) tree m2_word64_type_node;
     104                 :             : static GTY (()) tree m2_bitset8_type_node;
     105                 :             : static GTY (()) tree m2_bitset16_type_node;
     106                 :             : static GTY (()) tree m2_bitset32_type_node;
     107                 :             : static GTY (()) tree m2_real32_type_node;
     108                 :             : static GTY (()) tree m2_real64_type_node;
     109                 :             : static GTY (()) tree m2_real96_type_node;
     110                 :             : static GTY (()) tree m2_real128_type_node;
     111                 :             : static GTY (()) tree m2_complex_type_node;
     112                 :             : static GTY (()) tree m2_long_complex_type_node;
     113                 :             : static GTY (()) tree m2_short_complex_type_node;
     114                 :             : static GTY (()) tree m2_c_type_node;
     115                 :             : static GTY (()) tree m2_complex32_type_node;
     116                 :             : static GTY (()) tree m2_complex64_type_node;
     117                 :             : static GTY (()) tree m2_complex96_type_node;
     118                 :             : static GTY (()) tree m2_complex128_type_node;
     119                 :             : static GTY (()) tree m2_packed_boolean_type_node;
     120                 :             : static GTY (()) tree m2_cardinal_address_type_node;
     121                 :             : 
     122                 :             : /* gm2_canonicalize_array - returns a unique array node based on
     123                 :             :    index_type and type.  */
     124                 :             : 
     125                 :             : static tree
     126                 :      137570 : gm2_canonicalize_array (tree index_type, int type)
     127                 :             : {
     128                 :      137570 :   array_desc *l = list_of_arrays;
     129                 :             : 
     130                 :      329141 :   while (l != NULL)
     131                 :             :     {
     132                 :      273065 :       if (l->type == type && l->index == index_type)
     133                 :       81494 :         return l->array;
     134                 :             :       else
     135                 :      191571 :         l = l->next;
     136                 :             :     }
     137                 :       56076 :   l = ggc_alloc<array_desc> ();
     138                 :       56076 :   l->next = list_of_arrays;
     139                 :       56076 :   l->type = type;
     140                 :       56076 :   l->index = index_type;
     141                 :       56076 :   l->array = make_node (ARRAY_TYPE);
     142                 :       56076 :   TREE_TYPE (l->array) = NULL_TREE;
     143                 :       56076 :   TYPE_DOMAIN (l->array) = index_type;
     144                 :       56076 :   list_of_arrays = l;
     145                 :       56076 :   return l->array;
     146                 :             : }
     147                 :             : 
     148                 :             : /* BuildStartArrayType - creates an array with an indextype and
     149                 :             :    elttype.  The front end symbol type is also passed to allow the
     150                 :             :    gccgm2 to return the canonical edition of the array type even if
     151                 :             :    the GCC elttype is NULL_TREE.  */
     152                 :             : 
     153                 :             : tree
     154                 :       69154 : m2type_BuildStartArrayType (tree index_type, tree elt_type, int type)
     155                 :             : {
     156                 :       69154 :   tree t;
     157                 :             : 
     158                 :       69154 :   elt_type = m2tree_skip_type_decl (elt_type);
     159                 :       69154 :   ASSERT_CONDITION (index_type != NULL_TREE);
     160                 :       69154 :   if (elt_type == NULL_TREE)
     161                 :             :     {
     162                 :             :       /* Cannot use GCC canonicalization routines yet, so we use our front
     163                 :             :          end version based on the front end type.  */
     164                 :        3717 :       return gm2_canonicalize_array (index_type, type);
     165                 :             :     }
     166                 :       65437 :   t = gm2_canonicalize_array (index_type, type);
     167                 :       65437 :   if (TREE_TYPE (t) == NULL_TREE)
     168                 :       53157 :     TREE_TYPE (t) = elt_type;
     169                 :             :   else
     170                 :       12280 :     ASSERT_CONDITION (TREE_TYPE (t) == elt_type);
     171                 :             : 
     172                 :             :   return t;
     173                 :             : }
     174                 :             : 
     175                 :             : /* PutArrayType assignes TREE_TYPE (array) to the skipped type.  */
     176                 :             : 
     177                 :             : void
     178                 :        2979 : m2type_PutArrayType (tree array, tree type)
     179                 :             : {
     180                 :        2979 :   TREE_TYPE (array) = m2tree_skip_type_decl (type);
     181                 :        2979 : }
     182                 :             : 
     183                 :             : /* gccgm2_GetArrayNoOfElements returns the number of elements in
     184                 :             :    arraytype.  */
     185                 :             : 
     186                 :             : tree
     187                 :         820 : m2type_GetArrayNoOfElements (location_t location, tree arraytype)
     188                 :             : {
     189                 :         820 :   tree index_type = TYPE_DOMAIN (m2tree_skip_type_decl (arraytype));
     190                 :         820 :   tree min = TYPE_MIN_VALUE (index_type);
     191                 :         820 :   tree max = TYPE_MAX_VALUE (index_type);
     192                 :             : 
     193                 :         820 :   m2assert_AssertLocation (location);
     194                 :         820 :   return m2expr_FoldAndStrip (m2expr_BuildSub (location, max, min, false));
     195                 :             : }
     196                 :             : 
     197                 :             : /* gm2_finish_build_array_type complete building the partially
     198                 :             :    created array type, arrayType.  The arrayType is now known to be
     199                 :             :    declared as: ARRAY index_type OF elt_type.  There will only ever
     200                 :             :    be one gcc tree type for this array definition.  The third
     201                 :             :    parameter type is a front end type and this is necessary so that
     202                 :             :    the canonicalization creates unique array types for each type.  */
     203                 :             : 
     204                 :             : static tree
     205                 :       68416 : gm2_finish_build_array_type (tree arrayType, tree elt_type, tree index_type,
     206                 :             :                              int type)
     207                 :             : {
     208                 :       68416 :   tree old = arrayType;
     209                 :             : 
     210                 :       68416 :   elt_type = m2tree_skip_type_decl (elt_type);
     211                 :       68416 :   ASSERT_CONDITION (index_type != NULL_TREE);
     212                 :       68416 :   if (TREE_CODE (elt_type) == FUNCTION_TYPE)
     213                 :             :     {
     214                 :           0 :       error ("arrays of functions are not meaningful");
     215                 :           0 :       elt_type = integer_type_node;
     216                 :             :     }
     217                 :             : 
     218                 :       68416 :   TREE_TYPE (arrayType) = elt_type;
     219                 :       68416 :   TYPE_DOMAIN (arrayType) = index_type;
     220                 :             : 
     221                 :       68416 :   arrayType = gm2_canonicalize_array (index_type, type);
     222                 :       68416 :   if (arrayType != old)
     223                 :           0 :     internal_error ("array declaration canonicalization has failed");
     224                 :             : 
     225                 :       68416 :   if (!COMPLETE_TYPE_P (arrayType))
     226                 :       56076 :     layout_type (arrayType);
     227                 :       68416 :   return arrayType;
     228                 :             : }
     229                 :             : 
     230                 :             : /* BuildEndArrayType returns a type which is an array indexed by
     231                 :             :    IndexType and which has ElementType elements.  */
     232                 :             : 
     233                 :             : tree
     234                 :       68416 : m2type_BuildEndArrayType (tree arraytype, tree elementtype, tree indextype,
     235                 :             :                           int type)
     236                 :             : {
     237                 :       68416 :   elementtype = m2tree_skip_type_decl (elementtype);
     238                 :       68416 :   ASSERT (indextype == TYPE_DOMAIN (arraytype), indextype);
     239                 :             : 
     240                 :       68416 :   if (TREE_CODE (elementtype) == FUNCTION_TYPE)
     241                 :           0 :     return gm2_finish_build_array_type (arraytype, ptr_type_node, indextype,
     242                 :           0 :                                         type);
     243                 :             :   else
     244                 :       68416 :     return gm2_finish_build_array_type (
     245                 :       68416 :         arraytype, m2tree_skip_type_decl (elementtype), indextype, type);
     246                 :             : }
     247                 :             : 
     248                 :             : /* gm2_build_array_type returns a type which is an array indexed by
     249                 :             :    IndexType and which has ElementType elements.  */
     250                 :             : 
     251                 :             : static tree
     252                 :       46608 : gm2_build_array_type (tree elementtype, tree indextype, int fetype)
     253                 :             : {
     254                 :       46608 :   tree arrayType = m2type_BuildStartArrayType (indextype, elementtype, fetype);
     255                 :       46608 :   return m2type_BuildEndArrayType (arrayType, elementtype, indextype, fetype);
     256                 :             : }
     257                 :             : 
     258                 :             : /* ValueInTypeRange returns true if the constant, value, lies within
     259                 :             :    the range of type.  */
     260                 :             : 
     261                 :             : bool
     262                 :       51050 : m2type_ValueInTypeRange (tree type, tree value)
     263                 :             : {
     264                 :       51050 :   tree low_type = m2tree_skip_type_decl (type);
     265                 :       51050 :   tree min_value = TYPE_MIN_VALUE (low_type);
     266                 :       51050 :   tree max_value = TYPE_MAX_VALUE (low_type);
     267                 :             : 
     268                 :       51050 :   value = m2expr_FoldAndStrip (value);
     269                 :       51050 :   return ((tree_int_cst_compare (min_value, value) <= 0)
     270                 :       51050 :           && (tree_int_cst_compare (value, max_value) <= 0));
     271                 :             : }
     272                 :             : 
     273                 :             : /* ValueOutOfTypeRange returns true if the constant, value, exceeds
     274                 :             :    the range of type.  */
     275                 :             : 
     276                 :             : bool
     277                 :       51050 : m2type_ValueOutOfTypeRange (tree type, tree value)
     278                 :             : {
     279                 :       51050 :   return (!m2type_ValueInTypeRange (type, value));
     280                 :             : }
     281                 :             : 
     282                 :             : /* ExceedsTypeRange return true if low or high exceed the range of
     283                 :             :    type.  */
     284                 :             : 
     285                 :             : bool
     286                 :       25525 : m2type_ExceedsTypeRange (tree type, tree low, tree high)
     287                 :             : {
     288                 :       25525 :   return (m2type_ValueOutOfTypeRange (type, low)
     289                 :       25525 :           || m2type_ValueOutOfTypeRange (type, high));
     290                 :             : }
     291                 :             : 
     292                 :             : /* WithinTypeRange return true if low and high are within the range
     293                 :             :    of type.  */
     294                 :             : 
     295                 :             : bool
     296                 :           0 : m2type_WithinTypeRange (tree type, tree low, tree high)
     297                 :             : {
     298                 :           0 :   return (m2type_ValueInTypeRange (type, low)
     299                 :           0 :           && m2type_ValueInTypeRange (type, high));
     300                 :             : }
     301                 :             : 
     302                 :             : /* BuildArrayIndexType creates an integer index which accesses an
     303                 :             :    array.  low and high are the min, max elements of the array.  GCC
     304                 :             :    insists we access an array with an integer indice.  */
     305                 :             : 
     306                 :             : tree
     307                 :       72133 : m2type_BuildArrayIndexType (tree low, tree high)
     308                 :             : {
     309                 :       72133 :   tree sizelow = convert (m2type_GetIntegerType (), m2expr_FoldAndStrip (low));
     310                 :       72133 :   tree sizehigh
     311                 :       72133 :       = convert (m2type_GetIntegerType (), m2expr_FoldAndStrip (high));
     312                 :             : 
     313                 :       72133 :   if (m2expr_TreeOverflow (sizelow))
     314                 :           0 :     error ("low bound for the array is outside the ztype limits");
     315                 :       72133 :   if (m2expr_TreeOverflow (sizehigh))
     316                 :           0 :     error ("high bound for the array is outside the ztype limits");
     317                 :             : 
     318                 :       72133 :   return build_range_type (m2type_GetIntegerType (),
     319                 :             :                            m2expr_FoldAndStrip (sizelow),
     320                 :       72133 :                            m2expr_FoldAndStrip (sizehigh));
     321                 :             : }
     322                 :             : 
     323                 :             : /* build_m2_type_node_by_array builds a ISO Modula-2 word type from
     324                 :             :    ARRAY [low..high] OF arrayType.  This matches the front end data
     325                 :             :    type fetype which is only used during canonicalization.  */
     326                 :             : 
     327                 :             : static tree
     328                 :       34956 : build_m2_type_node_by_array (tree arrayType, tree low, tree high, int fetype)
     329                 :             : {
     330                 :       34956 :   return gm2_build_array_type (arrayType,
     331                 :       34956 :                                m2type_BuildArrayIndexType (low, high), fetype);
     332                 :             : }
     333                 :             : 
     334                 :             : /* build_m2_word16_type_node build an ISO 16 bit word as an ARRAY
     335                 :             :    [0..1] OF loc.  */
     336                 :             : 
     337                 :             : static tree
     338                 :       11652 : build_m2_word16_type_node (location_t location, int loc)
     339                 :             : {
     340                 :       11652 :   return build_m2_type_node_by_array (m2type_GetISOLocType (),
     341                 :             :                                       m2expr_GetIntegerZero (location),
     342                 :       11652 :                                       m2expr_GetIntegerOne (location), loc);
     343                 :             : }
     344                 :             : 
     345                 :             : /* build_m2_word32_type_node build an ISO 32 bit word as an ARRAY
     346                 :             :    [0..3] OF loc.  */
     347                 :             : 
     348                 :             : static tree
     349                 :       11652 : build_m2_word32_type_node (location_t location, int loc)
     350                 :             : {
     351                 :       11652 :   return build_m2_type_node_by_array (m2type_GetISOLocType (),
     352                 :             :                                       m2expr_GetIntegerZero (location),
     353                 :       11652 :                                       m2decl_BuildIntegerConstant (3), loc);
     354                 :             : }
     355                 :             : 
     356                 :             : /* build_m2_word64_type_node build an ISO 32 bit word as an ARRAY
     357                 :             :    [0..7] OF loc.  */
     358                 :             : 
     359                 :             : static tree
     360                 :       11652 : build_m2_word64_type_node (location_t location, int loc)
     361                 :             : {
     362                 :       11652 :   return build_m2_type_node_by_array (m2type_GetISOLocType (),
     363                 :             :                                       m2expr_GetIntegerZero (location),
     364                 :       11652 :                                       m2decl_BuildIntegerConstant (7), loc);
     365                 :             : }
     366                 :             : 
     367                 :             : 
     368                 :             : /* GetM2Complex32 return the fixed size complex type.  */
     369                 :             : 
     370                 :             : tree
     371                 :       23025 : m2type_GetM2Complex32 (void)
     372                 :             : {
     373                 :       23025 :   return m2_complex32_type_node;
     374                 :             : }
     375                 :             : 
     376                 :             : /* GetM2Complex64 return the fixed size complex type.  */
     377                 :             : 
     378                 :             : tree
     379                 :       23025 : m2type_GetM2Complex64 (void)
     380                 :             : {
     381                 :       23025 :   return m2_complex64_type_node;
     382                 :             : }
     383                 :             : 
     384                 :             : /* GetM2Complex96 return the fixed size complex type.  */
     385                 :             : 
     386                 :             : tree
     387                 :       23025 : m2type_GetM2Complex96 (void)
     388                 :             : {
     389                 :       23025 :   return m2_complex96_type_node;
     390                 :             : }
     391                 :             : 
     392                 :             : /* GetM2Complex128 return the fixed size complex type.  */
     393                 :             : 
     394                 :             : tree
     395                 :       23025 : m2type_GetM2Complex128 (void)
     396                 :             : {
     397                 :       23025 :   return m2_complex128_type_node;
     398                 :             : }
     399                 :             : 
     400                 :             : /* GetM2CType a test function.  */
     401                 :             : 
     402                 :             : tree
     403                 :       23205 : m2type_GetM2CType (void)
     404                 :             : {
     405                 :       23205 :   return m2_c_type_node;
     406                 :             : }
     407                 :             : 
     408                 :             : /* GetM2ShortComplexType return the short complex type.  */
     409                 :             : 
     410                 :             : tree
     411                 :       46329 : m2type_GetM2ShortComplexType (void)
     412                 :             : {
     413                 :       46329 :   return m2_short_complex_type_node;
     414                 :             : }
     415                 :             : 
     416                 :             : /* GetM2LongComplexType return the long complex type.  */
     417                 :             : 
     418                 :             : tree
     419                 :       46329 : m2type_GetM2LongComplexType (void)
     420                 :             : {
     421                 :       46329 :   return m2_long_complex_type_node;
     422                 :             : }
     423                 :             : 
     424                 :             : /* GetM2ComplexType return the complex type.  */
     425                 :             : 
     426                 :             : tree
     427                 :       46329 : m2type_GetM2ComplexType (void)
     428                 :             : {
     429                 :       46329 :   return m2_complex_type_node;
     430                 :             : }
     431                 :             : 
     432                 :             : /* GetM2Real128 return the real 128 bit type.  */
     433                 :             : 
     434                 :             : tree
     435                 :       23025 : m2type_GetM2Real128 (void)
     436                 :             : {
     437                 :       23025 :   return m2_real128_type_node;
     438                 :             : }
     439                 :             : 
     440                 :             : /* GetM2Real96 return the real 96 bit type.  */
     441                 :             : 
     442                 :             : tree
     443                 :       23025 : m2type_GetM2Real96 (void)
     444                 :             : {
     445                 :       23025 :   return m2_real96_type_node;
     446                 :             : }
     447                 :             : 
     448                 :             : /* GetM2Real64 return the real 64 bit type.  */
     449                 :             : 
     450                 :             : tree
     451                 :       23025 : m2type_GetM2Real64 (void)
     452                 :             : {
     453                 :       23025 :   return m2_real64_type_node;
     454                 :             : }
     455                 :             : 
     456                 :             : /* GetM2Real32 return the real 32 bit type.  */
     457                 :             : 
     458                 :             : tree
     459                 :       23025 : m2type_GetM2Real32 (void)
     460                 :             : {
     461                 :       23025 :   return m2_real32_type_node;
     462                 :             : }
     463                 :             : 
     464                 :             : /* GetM2Bitset32 return the bitset 32 bit type.  */
     465                 :             : 
     466                 :             : tree
     467                 :       23025 : m2type_GetM2Bitset32 (void)
     468                 :             : {
     469                 :       23025 :   return m2_bitset32_type_node;
     470                 :             : }
     471                 :             : 
     472                 :             : /* GetM2Bitset16 return the bitset 16 bit type.  */
     473                 :             : 
     474                 :             : tree
     475                 :       23025 : m2type_GetM2Bitset16 (void)
     476                 :             : {
     477                 :       23025 :   return m2_bitset16_type_node;
     478                 :             : }
     479                 :             : 
     480                 :             : /* GetM2Bitset8 return the bitset 8 bit type.  */
     481                 :             : 
     482                 :             : tree
     483                 :       23025 : m2type_GetM2Bitset8 (void)
     484                 :             : {
     485                 :       23025 :   return m2_bitset8_type_node;
     486                 :             : }
     487                 :             : 
     488                 :             : /* GetM2Word64 return the word 64 bit type.  */
     489                 :             : 
     490                 :             : tree
     491                 :     8433274 : m2type_GetM2Word64 (void)
     492                 :             : {
     493                 :     8433274 :   return m2_word64_type_node;
     494                 :             : }
     495                 :             : 
     496                 :             : /* GetM2Word32 return the word 32 bit type.  */
     497                 :             : 
     498                 :             : tree
     499                 :     8433274 : m2type_GetM2Word32 (void)
     500                 :             : {
     501                 :     8433274 :   return m2_word32_type_node;
     502                 :             : }
     503                 :             : 
     504                 :             : /* GetM2Word16 return the word 16 bit type.  */
     505                 :             : 
     506                 :             : tree
     507                 :     8433274 : m2type_GetM2Word16 (void)
     508                 :             : {
     509                 :     8433274 :   return m2_word16_type_node;
     510                 :             : }
     511                 :             : 
     512                 :             : /* GetM2Cardinal64 return the cardinal 64 bit type.  */
     513                 :             : 
     514                 :             : tree
     515                 :      186889 : m2type_GetM2Cardinal64 (void)
     516                 :             : {
     517                 :      186889 :   return m2_cardinal64_type_node;
     518                 :             : }
     519                 :             : 
     520                 :             : /* GetM2Cardinal32 return the cardinal 32 bit type.  */
     521                 :             : 
     522                 :             : tree
     523                 :      186889 : m2type_GetM2Cardinal32 (void)
     524                 :             : {
     525                 :      186889 :   return m2_cardinal32_type_node;
     526                 :             : }
     527                 :             : 
     528                 :             : /* GetM2Cardinal16 return the cardinal 16 bit type.  */
     529                 :             : 
     530                 :             : tree
     531                 :      186889 : m2type_GetM2Cardinal16 (void)
     532                 :             : {
     533                 :      186889 :   return m2_cardinal16_type_node;
     534                 :             : }
     535                 :             : 
     536                 :             : /* GetM2Cardinal8 return the cardinal 8 bit type.  */
     537                 :             : 
     538                 :             : tree
     539                 :       23025 : m2type_GetM2Cardinal8 (void)
     540                 :             : {
     541                 :       23025 :   return m2_cardinal8_type_node;
     542                 :             : }
     543                 :             : 
     544                 :             : /* GetM2Integer64 return the integer 64 bit type.  */
     545                 :             : 
     546                 :             : tree
     547                 :       23025 : m2type_GetM2Integer64 (void)
     548                 :             : {
     549                 :       23025 :   return m2_integer64_type_node;
     550                 :             : }
     551                 :             : 
     552                 :             : /* GetM2Integer32 return the integer 32 bit type.  */
     553                 :             : 
     554                 :             : tree
     555                 :       23025 : m2type_GetM2Integer32 (void)
     556                 :             : {
     557                 :       23025 :   return m2_integer32_type_node;
     558                 :             : }
     559                 :             : 
     560                 :             : /* GetM2Integer16 return the integer 16 bit type.  */
     561                 :             : 
     562                 :             : tree
     563                 :       23025 : m2type_GetM2Integer16 (void)
     564                 :             : {
     565                 :       23025 :   return m2_integer16_type_node;
     566                 :             : }
     567                 :             : 
     568                 :             : /* GetM2Integer8 return the integer 8 bit type.  */
     569                 :             : 
     570                 :             : tree
     571                 :       23025 : m2type_GetM2Integer8 (void)
     572                 :             : {
     573                 :       23025 :   return m2_integer8_type_node;
     574                 :             : }
     575                 :             : 
     576                 :             : /* GetM2RType return the ISO R data type, the longest real
     577                 :             :    datatype.  */
     578                 :             : 
     579                 :             : tree
     580                 :       55211 : m2type_GetM2RType (void)
     581                 :             : {
     582                 :       55211 :   return long_double_type_node;
     583                 :             : }
     584                 :             : 
     585                 :             : /* GetM2ZType return the ISO Z data type, the longest int datatype.  */
     586                 :             : 
     587                 :             : tree
     588                 :     1206902 : m2type_GetM2ZType (void)
     589                 :             : {
     590                 :     1206902 :   return m2_z_type_node;
     591                 :             : }
     592                 :             : 
     593                 :             : /* GetShortCardType return the C short unsigned data type.  */
     594                 :             : 
     595                 :             : tree
     596                 :           0 : m2type_GetShortCardType (void)
     597                 :             : {
     598                 :           0 :   return short_unsigned_type_node;
     599                 :             : }
     600                 :             : 
     601                 :             : /* GetM2ShortCardType return the m2 short cardinal data type.  */
     602                 :             : 
     603                 :             : tree
     604                 :       69633 : m2type_GetM2ShortCardType (void)
     605                 :             : {
     606                 :       69633 :   return m2_short_card_type_node;
     607                 :             : }
     608                 :             : 
     609                 :             : /* GetShortIntType return the C short int data type.  */
     610                 :             : 
     611                 :             : tree
     612                 :           0 : m2type_GetShortIntType (void)
     613                 :             : {
     614                 :           0 :   return short_integer_type_node;
     615                 :             : }
     616                 :             : 
     617                 :             : /* GetM2ShortIntType return the m2 short integer data type.  */
     618                 :             : 
     619                 :             : tree
     620                 :       69633 : m2type_GetM2ShortIntType (void)
     621                 :             : {
     622                 :       69633 :   return m2_short_int_type_node;
     623                 :             : }
     624                 :             : 
     625                 :             : /* GetM2LongCardType return the m2 long cardinal data type.  */
     626                 :             : 
     627                 :             : tree
     628                 :       69633 : m2type_GetM2LongCardType (void)
     629                 :             : {
     630                 :       69633 :   return m2_long_card_type_node;
     631                 :             : }
     632                 :             : 
     633                 :             : /* GetM2LongIntType return the m2 long integer data type.  */
     634                 :             : 
     635                 :             : tree
     636                 :       69633 : m2type_GetM2LongIntType (void)
     637                 :             : {
     638                 :       69633 :   return m2_long_int_type_node;
     639                 :             : }
     640                 :             : 
     641                 :             : /* GetM2LongRealType return the m2 long real data type.  */
     642                 :             : 
     643                 :             : tree
     644                 :       69633 : m2type_GetM2LongRealType (void)
     645                 :             : {
     646                 :       69633 :   return m2_long_real_type_node;
     647                 :             : }
     648                 :             : 
     649                 :             : /* GetM2RealType return the m2 real data type.  */
     650                 :             : 
     651                 :             : tree
     652                 :       69633 : m2type_GetM2RealType (void)
     653                 :             : {
     654                 :       69633 :   return m2_real_type_node;
     655                 :             : }
     656                 :             : 
     657                 :             : /* GetM2ShortRealType return the m2 short real data type.  */
     658                 :             : 
     659                 :             : tree
     660                 :       69633 : m2type_GetM2ShortRealType (void)
     661                 :             : {
     662                 :       69633 :   return m2_short_real_type_node;
     663                 :             : }
     664                 :             : 
     665                 :             : /* GetM2CardinalType return the m2 cardinal data type.  */
     666                 :             : 
     667                 :             : tree
     668                 :       58461 : m2type_GetM2CardinalType (void)
     669                 :             : {
     670                 :       58461 :   return m2_cardinal_type_node;
     671                 :             : }
     672                 :             : 
     673                 :             : /* GetM2IntegerType return the m2 integer data type.  */
     674                 :             : 
     675                 :             : tree
     676                 :       58269 : m2type_GetM2IntegerType (void)
     677                 :             : {
     678                 :       58269 :   return m2_integer_type_node;
     679                 :             : }
     680                 :             : 
     681                 :             : /* GetM2CharType return the m2 char data type.  */
     682                 :             : 
     683                 :             : tree
     684                 :       81760 : m2type_GetM2CharType (void)
     685                 :             : {
     686                 :       81760 :   return m2_char_type_node;
     687                 :             : }
     688                 :             : 
     689                 :             : /* GetProcType return the m2 proc data type.  */
     690                 :             : 
     691                 :             : tree
     692                 :       23025 : m2type_GetProcType (void)
     693                 :             : {
     694                 :       23025 :   return proc_type_node;
     695                 :             : }
     696                 :             : 
     697                 :             : /* GetISOWordType return the m2 iso word data type.  */
     698                 :             : 
     699                 :             : tree
     700                 :     8527679 : m2type_GetISOWordType (void)
     701                 :             : {
     702                 :     8527679 :   return m2_iso_word_type_node;
     703                 :             : }
     704                 :             : 
     705                 :             : /* GetISOByteType return the m2 iso byte data type.  */
     706                 :             : 
     707                 :             : tree
     708                 :     5573173 : m2type_GetISOByteType (void)
     709                 :             : {
     710                 :     5573173 :   return m2_iso_byte_type_node;
     711                 :             : }
     712                 :             : 
     713                 :             : /* GetISOLocType return the m2 loc word data type.  */
     714                 :             : 
     715                 :             : tree
     716                 :     5566242 : m2type_GetISOLocType (void)
     717                 :             : {
     718                 :     5566242 :   return m2_iso_loc_type_node;
     719                 :             : }
     720                 :             : 
     721                 :             : /* GetWordType return the C unsigned data type.  */
     722                 :             : 
     723                 :             : tree
     724                 :     2114610 : m2type_GetWordType (void)
     725                 :             : {
     726                 :     2114610 :   return unsigned_type_node;
     727                 :             : }
     728                 :             : 
     729                 :             : /* GetLongIntType return the C long int data type.  */
     730                 :             : 
     731                 :             : tree
     732                 :           0 : m2type_GetLongIntType (void)
     733                 :             : {
     734                 :           0 :   return long_integer_type_node;
     735                 :             : }
     736                 :             : 
     737                 :             : /* GetShortRealType return the C float data type.  */
     738                 :             : 
     739                 :             : tree
     740                 :     1454616 : m2type_GetShortRealType (void)
     741                 :             : {
     742                 :     1454616 :   return float_type_node;
     743                 :             : }
     744                 :             : 
     745                 :             : /* GetLongRealType return the C long double data type.  */
     746                 :             : 
     747                 :             : tree
     748                 :     1492590 : m2type_GetLongRealType (void)
     749                 :             : {
     750                 :     1492590 :   return long_double_type_node;
     751                 :             : }
     752                 :             : 
     753                 :             : /* GetRealType returns the C double_type_node.  */
     754                 :             : 
     755                 :             : tree
     756                 :     1501224 : m2type_GetRealType (void)
     757                 :             : {
     758                 :     1501224 :   return double_type_node;
     759                 :             : }
     760                 :             : 
     761                 :             : /* GetBitnumType return the ISO bitnum type.  */
     762                 :             : 
     763                 :             : tree
     764                 :       11373 : m2type_GetBitnumType (void)
     765                 :             : {
     766                 :       11373 :   return bitnum_type_node;
     767                 :             : }
     768                 :             : 
     769                 :             : /* GetBitsetType return the bitset type.  */
     770                 :             : 
     771                 :             : tree
     772                 :       53303 : m2type_GetBitsetType (void)
     773                 :             : {
     774                 :       53303 :   return bitset_type_node;
     775                 :             : }
     776                 :             : 
     777                 :             : /* GetCardinalType return the cardinal type.  */
     778                 :             : 
     779                 :             : tree
     780                 :      115051 : m2type_GetCardinalType (void)
     781                 :             : {
     782                 :      115051 :   return unsigned_type_node;
     783                 :             : }
     784                 :             : 
     785                 :             : /* GetPointerType return the GCC ptr type node.  Equivalent to
     786                 :             :    (void *).  */
     787                 :             : 
     788                 :             : tree
     789                 :      186685 : m2type_GetPointerType (void)
     790                 :             : {
     791                 :      186685 :   return ptr_type_node;
     792                 :             : }
     793                 :             : 
     794                 :             : /* GetVoidType return the C void type.  */
     795                 :             : 
     796                 :             : tree
     797                 :           0 : m2type_GetVoidType (void)
     798                 :             : {
     799                 :           0 :   return void_type_node;
     800                 :             : }
     801                 :             : 
     802                 :             : /* GetByteType return the byte type node.  */
     803                 :             : 
     804                 :             : tree
     805                 :     5828346 : m2type_GetByteType (void)
     806                 :             : {
     807                 :     5828346 :   return unsigned_char_type_node;
     808                 :             : }
     809                 :             : 
     810                 :             : /* GetCharType return the char type node.  */
     811                 :             : 
     812                 :             : tree
     813                 :           0 : m2type_GetCharType (void)
     814                 :             : {
     815                 :           0 :   return char_type_node;
     816                 :             : }
     817                 :             : 
     818                 :             : /* GetIntegerType return the integer type node.  */
     819                 :             : 
     820                 :             : tree
     821                 :     1582993 : m2type_GetIntegerType (void)
     822                 :             : {
     823                 :     1582993 :   return integer_type_node;
     824                 :             : }
     825                 :             : 
     826                 :             : /* GetCSizeTType return a type representing, size_t on this system.  */
     827                 :             : 
     828                 :             : tree
     829                 :       23025 : m2type_GetCSizeTType (void)
     830                 :             : {
     831                 :       23025 :   return sizetype;
     832                 :             : }
     833                 :             : 
     834                 :             : /* GetCSSizeTType return a type representing, size_t on this
     835                 :             :    system.  */
     836                 :             : 
     837                 :             : tree
     838                 :       23025 : m2type_GetCSSizeTType (void)
     839                 :             : {
     840                 :       23025 :   return ssizetype;
     841                 :             : }
     842                 :             : 
     843                 :             : /* GetPackedBooleanType return the packed boolean data type node.  */
     844                 :             : 
     845                 :             : tree
     846                 :       11373 : m2type_GetPackedBooleanType (void)
     847                 :             : {
     848                 :       11373 :   return m2_packed_boolean_type_node;
     849                 :             : }
     850                 :             : 
     851                 :             : /* GetBooleanTrue return modula-2 true.  */
     852                 :             : 
     853                 :             : tree
     854                 :       55545 : m2type_GetBooleanTrue (void)
     855                 :             : {
     856                 :             : #if defined(USE_BOOLEAN)
     857                 :       55545 :   return boolean_true_node;
     858                 :             : #else /* !USE_BOOLEAN  */
     859                 :             :   return m2expr_GetIntegerOne (m2linemap_BuiltinsLocation ());
     860                 :             : #endif /* !USE_BOOLEAN  */
     861                 :             : }
     862                 :             : 
     863                 :             : /* GetBooleanFalse return modula-2 FALSE.  */
     864                 :             : 
     865                 :             : tree
     866                 :       14673 : m2type_GetBooleanFalse (void)
     867                 :             : {
     868                 :             : #if defined(USE_BOOLEAN)
     869                 :       14673 :   return boolean_false_node;
     870                 :             : #else /* !USE_BOOLEAN  */
     871                 :             :   return m2expr_GetIntegerZero (m2linemap_BuiltinsLocation ());
     872                 :             : #endif /* !USE_BOOLEAN  */
     873                 :             : }
     874                 :             : 
     875                 :             : /* GetBooleanType return the modula-2 BOOLEAN type.  */
     876                 :             : 
     877                 :             : tree
     878                 :       79931 : m2type_GetBooleanType (void)
     879                 :             : {
     880                 :             : #if defined(USE_BOOLEAN)
     881                 :       79931 :   return boolean_type_node;
     882                 :             : #else /* !USE_BOOLEAN  */
     883                 :             :   return integer_type_node;
     884                 :             : #endif /* !USE_BOOLEAN  */
     885                 :             : }
     886                 :             : 
     887                 :             : /* GetCardinalAddressType returns the internal data type for
     888                 :             :    computing binary arithmetic upon the ADDRESS datatype.  */
     889                 :             : 
     890                 :             : tree
     891                 :       24772 : m2type_GetCardinalAddressType (void)
     892                 :             : {
     893                 :       24772 :   return m2_cardinal_address_type_node;
     894                 :             : }
     895                 :             : 
     896                 :             : /* noBitsRequired returns the number of bits required to contain,
     897                 :             :    values.  How many bits are required to represent all numbers
     898                 :             :    between: 0..values-1 */
     899                 :             : 
     900                 :             : static tree
     901                 :         156 : noBitsRequired (tree values)
     902                 :             : {
     903                 :         156 :   int bits = tree_floor_log2 (values);
     904                 :             : 
     905                 :         156 :   if (integer_pow2p (values))
     906                 :             :     /* remember we start counting from zero.  */
     907                 :         132 :     return m2decl_BuildIntegerConstant (bits);
     908                 :             :   else
     909                 :          24 :     return m2decl_BuildIntegerConstant (bits + 1);
     910                 :             : }
     911                 :             : 
     912                 :             : #if 0
     913                 :             : /* build_set_type creates a set type from the, domain, [low..high].
     914                 :             :    The values low..high all have type, range_type.  */
     915                 :             : 
     916                 :             : static tree
     917                 :             : build_set_type (tree domain, tree range_type, int allow_void, int ispacked)
     918                 :             : {
     919                 :             :   tree type;
     920                 :             : 
     921                 :             :   if (!m2tree_IsOrdinal (domain)
     922                 :             :       && !(allow_void && TREE_CODE (domain) == VOID_TYPE))
     923                 :             :     {
     924                 :             :       error ("set base type must be an ordinal type");
     925                 :             :       return NULL;
     926                 :             :     }
     927                 :             : 
     928                 :             :   if (TYPE_SIZE (range_type) == 0)
     929                 :             :     layout_type (range_type);
     930                 :             : 
     931                 :             :   if (TYPE_SIZE (domain) == 0)
     932                 :             :     layout_type (domain);
     933                 :             : 
     934                 :             :   type = make_node (SET_TYPE);
     935                 :             :   TREE_TYPE (type) = range_type;
     936                 :             :   TYPE_DOMAIN (type) = domain;
     937                 :             :   TYPE_PACKED (type) = ispacked;
     938                 :             : 
     939                 :             :   return type;
     940                 :             : }
     941                 :             : 
     942                 :             : 
     943                 :             : /* convert_type_to_range does the conversion and copies the range
     944                 :             :    type */
     945                 :             : 
     946                 :             : static tree
     947                 :             : convert_type_to_range (tree type)
     948                 :             : {
     949                 :             :   tree min, max;
     950                 :             :   tree itype;
     951                 :             : 
     952                 :             :   if (!m2tree_IsOrdinal (type))
     953                 :             :     {
     954                 :             :       error ("ordinal type expected");
     955                 :             :       return error_mark_node;
     956                 :             :     }
     957                 :             : 
     958                 :             :   min = TYPE_MIN_VALUE (type);
     959                 :             :   max = TYPE_MAX_VALUE (type);
     960                 :             : 
     961                 :             :   if (TREE_TYPE (min) != TREE_TYPE (max))
     962                 :             :     {
     963                 :             :       error ("range limits are not of the same type");
     964                 :             :       return error_mark_node;
     965                 :             :     }
     966                 :             : 
     967                 :             :   itype = build_range_type (TREE_TYPE (min), min, max);
     968                 :             : 
     969                 :             :   if (TREE_TYPE (type) == NULL_TREE)
     970                 :             :     {
     971                 :             :       layout_type (type);
     972                 :             :       TREE_TYPE (itype) = type;
     973                 :             :     }
     974                 :             :   else
     975                 :             :     {
     976                 :             :       layout_type (TREE_TYPE (type));
     977                 :             :       TREE_TYPE (itype) = TREE_TYPE (type);
     978                 :             :     }
     979                 :             : 
     980                 :             :   layout_type (itype);
     981                 :             :   return itype;
     982                 :             : }
     983                 :             : #endif
     984                 :             : 
     985                 :             : /* build_bitset_type builds the type BITSET which is exported from
     986                 :             :    SYSTEM.  It also builds BITNUM (the subrange from which BITSET is
     987                 :             :    created).  */
     988                 :             : 
     989                 :             : static tree
     990                 :       11652 : build_bitset_type (location_t location)
     991                 :             : {
     992                 :       11652 :   m2assert_AssertLocation (location);
     993                 :       11652 :   bitnum_type_node = build_range_type (
     994                 :             :       m2tree_skip_type_decl (m2type_GetCardinalType ()),
     995                 :             :       m2decl_BuildIntegerConstant (0),
     996                 :       11652 :       m2decl_BuildIntegerConstant (m2decl_GetBitsPerBitset () - 1));
     997                 :       11652 :   layout_type (bitnum_type_node);
     998                 :             : 
     999                 :             : #if 1
    1000                 :       11652 :   if (broken_set_debugging_info)
    1001                 :       11652 :     return unsigned_type_node;
    1002                 :             : #endif
    1003                 :             : 
    1004                 :           0 :   ASSERT ((COMPLETE_TYPE_P (bitnum_type_node)), bitnum_type_node);
    1005                 :             : 
    1006                 :           0 :   return m2type_BuildSetTypeFromSubrange (
    1007                 :             :       location, NULL, bitnum_type_node, m2decl_BuildIntegerConstant (0),
    1008                 :           0 :       m2decl_BuildIntegerConstant (m2decl_GetBitsPerBitset () - 1), false);
    1009                 :             : }
    1010                 :             : 
    1011                 :             : /* BuildSetTypeFromSubrange constructs a set type from a
    1012                 :             :    subrangeType.  --fixme-- revisit once gdb/gcc supports dwarf-5 set type.  */
    1013                 :             : 
    1014                 :             : tree
    1015                 :       26195 : m2type_BuildSetTypeFromSubrange (location_t location,
    1016                 :             :                                  char *name __attribute__ ((unused)),
    1017                 :             :                                  tree subrangeType __attribute__ ((unused)),
    1018                 :             :                                  tree lowval, tree highval, bool ispacked)
    1019                 :             : {
    1020                 :       26195 :   m2assert_AssertLocation (location);
    1021                 :       26195 :   lowval = m2expr_FoldAndStrip (lowval);
    1022                 :       26195 :   highval = m2expr_FoldAndStrip (highval);
    1023                 :             : 
    1024                 :             : #if 0
    1025                 :             :   if (broken_set_debugging_info)
    1026                 :             :     return unsigned_type_node;
    1027                 :             :   else
    1028                 :             : #endif
    1029                 :       26195 :     if (ispacked)
    1030                 :             :     {
    1031                 :          84 :       tree noelements = m2expr_BuildAdd (
    1032                 :             :           location, m2expr_BuildSub (location, highval, lowval, false),
    1033                 :             :           integer_one_node, false);
    1034                 :          84 :       highval = m2expr_FoldAndStrip (m2expr_BuildSub (
    1035                 :             :             location, m2expr_BuildLSL (location, m2expr_GetWordOne (location),
    1036                 :             :                                        noelements, false),
    1037                 :             :             m2expr_GetIntegerOne (location), false));
    1038                 :          84 :       lowval = m2expr_GetIntegerZero (location);
    1039                 :          84 :       return m2type_BuildSmallestTypeRange (location, lowval, highval);
    1040                 :             :     }
    1041                 :             :   else
    1042                 :       26111 :     return unsigned_type_node;
    1043                 :             : }
    1044                 :             : 
    1045                 :             : /* build_m2_size_set_type build and return a set type with
    1046                 :             :    precision bits.  */
    1047                 :             : 
    1048                 :             : static tree
    1049                 :           0 : build_m2_size_set_type (location_t location, int precision)
    1050                 :             : {
    1051                 :           0 :   tree bitnum_type_node
    1052                 :           0 :       = build_range_type (m2tree_skip_type_decl (m2type_GetCardinalType ()),
    1053                 :             :                           m2decl_BuildIntegerConstant (0),
    1054                 :             :                           m2decl_BuildIntegerConstant (precision - 1));
    1055                 :           0 :   layout_type (bitnum_type_node);
    1056                 :           0 :   m2assert_AssertLocation (location);
    1057                 :             : 
    1058                 :           0 :   if (broken_set_debugging_info)
    1059                 :           0 :     return unsigned_type_node;
    1060                 :             : 
    1061                 :           0 :   ASSERT ((COMPLETE_TYPE_P (bitnum_type_node)), bitnum_type_node);
    1062                 :             : 
    1063                 :           0 :   return m2type_BuildSetTypeFromSubrange (
    1064                 :             :       location, NULL, bitnum_type_node, m2decl_BuildIntegerConstant (0),
    1065                 :           0 :       m2decl_BuildIntegerConstant (precision - 1), false);
    1066                 :             : }
    1067                 :             : 
    1068                 :             : /* build_m2_specific_size_type build a specific data type matching
    1069                 :             :    number of bits precision whether it is_signed.  It creates a
    1070                 :             :    set type if base == SET_TYPE or returns the already created real,
    1071                 :             :    if REAL_TYPE is specified.  */
    1072                 :             : 
    1073                 :             : static tree
    1074                 :      186588 : build_m2_specific_size_type (location_t location, enum tree_code base,
    1075                 :             :                              int precision, int is_signed)
    1076                 :             : {
    1077                 :      186588 :   tree c;
    1078                 :             : 
    1079                 :      186588 :   m2assert_AssertLocation (location);
    1080                 :             : 
    1081                 :      186588 :   c = make_node (base);
    1082                 :      186588 :   TYPE_PRECISION (c) = precision;
    1083                 :             : 
    1084                 :      186588 :   if (base == REAL_TYPE)
    1085                 :             :     {
    1086                 :       46608 :       if (!float_mode_for_size (TYPE_PRECISION (c)).exists ())
    1087                 :             :         return NULL;
    1088                 :       34956 :       layout_type (c);
    1089                 :             :     }
    1090                 :      139980 :   else if (base == SET_TYPE)
    1091                 :           0 :     return build_m2_size_set_type (location, precision);
    1092                 :             :   else
    1093                 :             :     {
    1094                 :      139980 :       TYPE_SIZE (c) = 0;
    1095                 :             : 
    1096                 :      139980 :       if (is_signed)
    1097                 :             :         {
    1098                 :       46608 :           fixup_signed_type (c);
    1099                 :       46608 :           TYPE_UNSIGNED (c) = false;
    1100                 :             :         }
    1101                 :             :       else
    1102                 :             :         {
    1103                 :       93372 :           fixup_unsigned_type (c);
    1104                 :       93372 :           TYPE_UNSIGNED (c) = true;
    1105                 :             :         }
    1106                 :             :     }
    1107                 :             : 
    1108                 :             :   return c;
    1109                 :             : }
    1110                 :             : 
    1111                 :             : /* BuildSmallestTypeRange returns the smallest INTEGER_TYPE which
    1112                 :             :    is sufficient to contain values: low..high.  */
    1113                 :             : 
    1114                 :             : tree
    1115                 :         156 : m2type_BuildSmallestTypeRange (location_t location, tree low, tree high)
    1116                 :             : {
    1117                 :         156 :   tree bits;
    1118                 :             : 
    1119                 :         156 :   m2assert_AssertLocation (location);
    1120                 :         156 :   low = fold (low);
    1121                 :         156 :   high = fold (high);
    1122                 :         156 :   bits = fold (noBitsRequired (
    1123                 :             :       m2expr_BuildAdd (location, m2expr_BuildSub (location, high, low, false),
    1124                 :             :                        m2expr_GetIntegerOne (location), false)));
    1125                 :         468 :   return build_m2_specific_size_type (location, INTEGER_TYPE,
    1126                 :         156 :                                       TREE_INT_CST_LOW (bits),
    1127                 :         156 :                                       tree_int_cst_sgn (low) < 0);
    1128                 :             : }
    1129                 :             : 
    1130                 :             : /* GetTreeType returns TREE_TYPE (t).  */
    1131                 :             : 
    1132                 :             : tree
    1133                 :       19647 : m2type_GetTreeType (tree t)
    1134                 :             : {
    1135                 :       19647 :   return TREE_TYPE (t);
    1136                 :             : }
    1137                 :             : 
    1138                 :             : /* finish_build_pointer_type finish building a POINTER_TYPE node.
    1139                 :             :    necessary to solve self references in procedure types.  */
    1140                 :             : 
    1141                 :             : /* Code taken from tree.cc:build_pointer_type_for_mode.  */
    1142                 :             : 
    1143                 :             : static tree
    1144                 :       44586 : finish_build_pointer_type (tree t, tree to_type, enum machine_mode mode,
    1145                 :             :                            bool can_alias_all)
    1146                 :             : {
    1147                 :       44586 :   TREE_TYPE (t) = to_type;
    1148                 :       44586 :   SET_TYPE_MODE (t, mode);
    1149                 :       44586 :   TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
    1150                 :       44586 :   TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
    1151                 :       44586 :   TYPE_POINTER_TO (to_type) = t;
    1152                 :             : 
    1153                 :             :   /* Lay out the type.  */
    1154                 :             :   /* layout_type (t);  */
    1155                 :       44586 :   layout_type (t);
    1156                 :             : 
    1157                 :       44586 :   return t;
    1158                 :             : }
    1159                 :             : 
    1160                 :             : /* BuildParameterDeclaration creates and returns one parameter
    1161                 :             :    from, name, and, type.  It appends this parameter to the internal
    1162                 :             :    param_type_list.  */
    1163                 :             : 
    1164                 :             : tree
    1165                 :       63233 : m2type_BuildProcTypeParameterDeclaration (location_t location, tree type,
    1166                 :             :                                           bool isreference)
    1167                 :             : {
    1168                 :       63233 :   m2assert_AssertLocation (location);
    1169                 :       63233 :   ASSERT_BOOL (isreference);
    1170                 :       63233 :   type = m2tree_skip_type_decl (type);
    1171                 :       63233 :   if (isreference)
    1172                 :        5190 :     type = build_reference_type (type);
    1173                 :             : 
    1174                 :       63233 :   param_type_list = tree_cons (NULL_TREE, type, param_type_list);
    1175                 :       63233 :   return type;
    1176                 :             : }
    1177                 :             : 
    1178                 :             : /* BuildEndFunctionType build a function type which would return a,
    1179                 :             :    value.  The arguments have been created by
    1180                 :             :    BuildParameterDeclaration.  */
    1181                 :             : 
    1182                 :             : tree
    1183                 :       44586 : m2type_BuildEndFunctionType (tree func, tree return_type, bool uses_varargs)
    1184                 :             : {
    1185                 :       44586 :   tree last;
    1186                 :             : 
    1187                 :       44586 :   if (return_type == NULL_TREE)
    1188                 :       38316 :     return_type = void_type_node;
    1189                 :             :   else
    1190                 :        6270 :     return_type = m2tree_skip_type_decl (return_type);
    1191                 :             : 
    1192                 :       44586 :   if (uses_varargs)
    1193                 :             :     {
    1194                 :           0 :       if (param_type_list != NULL_TREE)
    1195                 :             :         {
    1196                 :           0 :           param_type_list = nreverse (param_type_list);
    1197                 :           0 :           last = param_type_list;
    1198                 :           0 :           param_type_list = nreverse (param_type_list);
    1199                 :           0 :           gcc_assert (last != void_list_node);
    1200                 :             :         }
    1201                 :             :     }
    1202                 :       44586 :   else if (param_type_list == NULL_TREE)
    1203                 :       16035 :     param_type_list = void_list_node;
    1204                 :             :   else
    1205                 :             :     {
    1206                 :       28551 :       param_type_list = nreverse (param_type_list);
    1207                 :       28551 :       last = param_type_list;
    1208                 :       28551 :       param_type_list = nreverse (param_type_list);
    1209                 :       28551 :       TREE_CHAIN (last) = void_list_node;
    1210                 :             :     }
    1211                 :       44586 :   param_type_list = build_function_type (return_type, param_type_list);
    1212                 :             : 
    1213                 :       44586 :   func = finish_build_pointer_type (func, param_type_list, ptr_mode, false);
    1214                 :       44586 :   TYPE_SIZE (func) = 0;
    1215                 :       44586 :   layout_type (func);
    1216                 :       44586 :   return func;
    1217                 :             : }
    1218                 :             : 
    1219                 :             : /* BuildStartFunctionType creates a pointer type, necessary to
    1220                 :             :    create a function type.  */
    1221                 :             : 
    1222                 :             : tree
    1223                 :       44586 : m2type_BuildStartFunctionType (location_t location ATTRIBUTE_UNUSED,
    1224                 :             :                                char *name ATTRIBUTE_UNUSED)
    1225                 :             : {
    1226                 :       44586 :   tree n = make_node (POINTER_TYPE);
    1227                 :             : 
    1228                 :       44586 :   m2assert_AssertLocation (location);
    1229                 :       44586 :   return n;
    1230                 :             : }
    1231                 :             : 
    1232                 :             : /* InitFunctionTypeParameters resets the current function type
    1233                 :             :    parameter list.  */
    1234                 :             : 
    1235                 :             : void
    1236                 :       44586 : m2type_InitFunctionTypeParameters (void)
    1237                 :             : {
    1238                 :       44586 :   param_type_list = NULL_TREE;
    1239                 :       44586 : }
    1240                 :             : 
    1241                 :             : /* gm2_finish_decl finishes VAR, TYPE and FUNCTION declarations.  */
    1242                 :             : 
    1243                 :             : static void
    1244                 :      799861 : gm2_finish_decl (location_t location, tree decl)
    1245                 :             : {
    1246                 :      799861 :   tree type = TREE_TYPE (decl);
    1247                 :      799861 :   int was_incomplete = (DECL_SIZE (decl) == 0);
    1248                 :             : 
    1249                 :      799861 :   m2assert_AssertLocation (location);
    1250                 :      799861 :   if (VAR_P (decl))
    1251                 :             :     {
    1252                 :           0 :       if (DECL_SIZE (decl) == 0 && TREE_TYPE (decl) != error_mark_node
    1253                 :           0 :           && COMPLETE_TYPE_P (TREE_TYPE (decl)))
    1254                 :           0 :         layout_decl (decl, 0);
    1255                 :             : 
    1256                 :           0 :       if (DECL_SIZE (decl) == 0
    1257                 :             :           /* Don't give an error if we already gave one earlier.  */
    1258                 :           0 :           && TREE_TYPE (decl) != error_mark_node)
    1259                 :             :         {
    1260                 :           0 :           error_at (location, "storage size of %q+D isn%'t known", decl);
    1261                 :           0 :           TREE_TYPE (decl) = error_mark_node;
    1262                 :             :         }
    1263                 :             : 
    1264                 :           0 :       if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
    1265                 :           0 :           && DECL_SIZE (decl) != 0)
    1266                 :             :         {
    1267                 :           0 :           if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
    1268                 :           0 :             m2expr_ConstantExpressionWarning (DECL_SIZE (decl));
    1269                 :             :           else
    1270                 :           0 :             error_at (location, "storage size of %q+D isn%'t constant", decl);
    1271                 :             :         }
    1272                 :             : 
    1273                 :           0 :       if (TREE_USED (type))
    1274                 :           0 :         TREE_USED (decl) = 1;
    1275                 :             :     }
    1276                 :             : 
    1277                 :             :   /* Output the assembler code and/or RTL code for variables and
    1278                 :             :      functions, unless the type is an undefined structure or union.  If
    1279                 :             :      not, it will get done when the type is completed.  */
    1280                 :             : 
    1281                 :      799861 :   if (VAR_P (decl) || TREE_CODE (decl) == FUNCTION_DECL)
    1282                 :             :     {
    1283                 :           0 :       if (DECL_FILE_SCOPE_P (decl))
    1284                 :             :         {
    1285                 :           0 :           if (DECL_INITIAL (decl) == NULL_TREE
    1286                 :           0 :               || DECL_INITIAL (decl) == error_mark_node)
    1287                 :             : 
    1288                 :             :             /* Don't output anything when a tentative file-scope definition is
    1289                 :             :                seen.  But at end of compilation, do output code for them.  */
    1290                 :           0 :             DECL_DEFER_OUTPUT (decl) = 1;
    1291                 :           0 :           rest_of_decl_compilation (decl, true, 0);
    1292                 :             :         }
    1293                 :             : 
    1294                 :           0 :       if (!DECL_FILE_SCOPE_P (decl))
    1295                 :             :         {
    1296                 :             : 
    1297                 :             :           /* Recompute the RTL of a local array now if it used to be an
    1298                 :             :              incomplete type.  */
    1299                 :           0 :           if (was_incomplete && !TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
    1300                 :             :             {
    1301                 :             :               /* If we used it already as memory, it must stay in memory.  */
    1302                 :           0 :               TREE_ADDRESSABLE (decl) = TREE_USED (decl);
    1303                 :             :               /* If it's still incomplete now, no init will save it.  */
    1304                 :           0 :               if (DECL_SIZE (decl) == 0)
    1305                 :           0 :                 DECL_INITIAL (decl) = 0;
    1306                 :             :             }
    1307                 :             :         }
    1308                 :             :     }
    1309                 :             : 
    1310                 :      799861 :   if (TREE_CODE (decl) == TYPE_DECL)
    1311                 :             :     {
    1312                 :     1004970 :       if (!DECL_FILE_SCOPE_P (decl)
    1313                 :      502543 :           && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
    1314                 :           0 :         m2block_pushDecl (build_stmt (location, DECL_EXPR, decl));
    1315                 :             : 
    1316                 :     1004912 :       rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0);
    1317                 :             :     }
    1318                 :      799861 : }
    1319                 :             : 
    1320                 :             : /* BuildVariableArrayAndDeclare creates a variable length array.
    1321                 :             :    high is the maximum legal elements (which is a runtime variable).
    1322                 :             :    This creates and array index, array type and local variable.  */
    1323                 :             : 
    1324                 :             : tree
    1325                 :           0 : m2type_BuildVariableArrayAndDeclare (location_t location, tree elementtype,
    1326                 :             :                                      tree high, char *name, tree scope)
    1327                 :             : {
    1328                 :           0 :   tree indextype = build_index_type (variable_size (high));
    1329                 :           0 :   tree arraytype = build_array_type (elementtype, indextype);
    1330                 :           0 :   tree id = get_identifier (name);
    1331                 :           0 :   tree decl;
    1332                 :             : 
    1333                 :           0 :   m2assert_AssertLocation (location);
    1334                 :           0 :   decl = build_decl (location, VAR_DECL, id, arraytype);
    1335                 :             : 
    1336                 :           0 :   DECL_EXTERNAL (decl) = false;
    1337                 :           0 :   TREE_PUBLIC (decl) = true;
    1338                 :           0 :   DECL_CONTEXT (decl) = scope;
    1339                 :           0 :   TREE_USED (arraytype) = true;
    1340                 :           0 :   TREE_USED (decl) = true;
    1341                 :             : 
    1342                 :           0 :   m2block_pushDecl (decl);
    1343                 :             : 
    1344                 :           0 :   gm2_finish_decl (location, indextype);
    1345                 :           0 :   gm2_finish_decl (location, arraytype);
    1346                 :           0 :   add_stmt (location, build_stmt (location, DECL_EXPR, decl));
    1347                 :             : 
    1348                 :           0 :   return decl;
    1349                 :             : }
    1350                 :             : 
    1351                 :             : static tree
    1352                 :       11652 : build_m2_iso_word_node (location_t location, int loc)
    1353                 :             : {
    1354                 :       11652 :   tree c;
    1355                 :             : 
    1356                 :       11652 :   m2assert_AssertLocation (location);
    1357                 :             :   /* Define `WORD' as specified in ISO m2
    1358                 :             : 
    1359                 :             :      WORD = ARRAY [0..SizeOfWord / SizeOfLoc] OF LOC ; */
    1360                 :             : 
    1361                 :       11652 :   if (m2decl_GetBitsPerInt () == BITS_PER_UNIT)
    1362                 :           0 :     c = m2type_GetISOLocType ();
    1363                 :             :   else
    1364                 :       23304 :     c = gm2_build_array_type (
    1365                 :             :         m2type_GetISOLocType (),
    1366                 :             :         m2type_BuildArrayIndexType (
    1367                 :             :             m2expr_GetIntegerZero (location),
    1368                 :             :             (m2expr_BuildSub (location,
    1369                 :             :                               m2decl_BuildIntegerConstant (
    1370                 :       11652 :                                   m2decl_GetBitsPerInt () / BITS_PER_UNIT),
    1371                 :             :                               m2expr_GetIntegerOne (location), false))),
    1372                 :             :         loc);
    1373                 :       11652 :   return c;
    1374                 :             : }
    1375                 :             : 
    1376                 :             : static tree
    1377                 :       11652 : build_m2_iso_byte_node (location_t location, int loc)
    1378                 :             : {
    1379                 :       11652 :   tree c;
    1380                 :             : 
    1381                 :             :   /* Define `BYTE' as specified in ISO m2
    1382                 :             : 
    1383                 :             :      BYTE = ARRAY [0..SizeOfByte / SizeOfLoc] OF LOC ; */
    1384                 :             : 
    1385                 :       11652 :   if (BITS_PER_UNIT == 8)
    1386                 :           0 :     c = m2type_GetISOLocType ();
    1387                 :             :   else
    1388                 :             :     c = gm2_build_array_type (
    1389                 :             :         m2type_GetISOLocType (),
    1390                 :             :         m2type_BuildArrayIndexType (
    1391                 :             :             m2expr_GetIntegerZero (location),
    1392                 :             :             m2decl_BuildIntegerConstant (BITS_PER_UNIT / 8)),
    1393                 :             :         loc);
    1394                 :       11652 :   return c;
    1395                 :             : }
    1396                 :             : 
    1397                 :             : /* m2type_InitSystemTypes initialise loc and word derivatives.  */
    1398                 :             : 
    1399                 :             : void
    1400                 :       11652 : m2type_InitSystemTypes (location_t location, int loc)
    1401                 :             : {
    1402                 :       11652 :   m2assert_AssertLocation (location);
    1403                 :             : 
    1404                 :       11652 :   m2_iso_word_type_node = build_m2_iso_word_node (location, loc);
    1405                 :       11652 :   m2_iso_byte_type_node = build_m2_iso_byte_node (location, loc);
    1406                 :             : 
    1407                 :       11652 :   m2_word16_type_node = build_m2_word16_type_node (location, loc);
    1408                 :       11652 :   m2_word32_type_node = build_m2_word32_type_node (location, loc);
    1409                 :       11652 :   m2_word64_type_node = build_m2_word64_type_node (location, loc);
    1410                 :       11652 : }
    1411                 :             : 
    1412                 :             : static tree
    1413                 :       11652 : build_m2_integer_node (void)
    1414                 :             : {
    1415                 :           0 :   return m2type_GetIntegerType ();
    1416                 :             : }
    1417                 :             : 
    1418                 :             : static tree
    1419                 :       11652 : build_m2_cardinal_node (void)
    1420                 :             : {
    1421                 :           0 :   return m2type_GetCardinalType ();
    1422                 :             : }
    1423                 :             : 
    1424                 :             : static tree
    1425                 :       11652 : build_m2_char_node (void)
    1426                 :             : {
    1427                 :       11652 :   tree c;
    1428                 :             : 
    1429                 :             :   /* Define `CHAR', to be an unsigned char.  */
    1430                 :             : 
    1431                 :       11652 :   c = make_unsigned_type (CHAR_TYPE_SIZE);
    1432                 :       11652 :   layout_type (c);
    1433                 :       11652 :   return c;
    1434                 :             : }
    1435                 :             : 
    1436                 :             : static tree
    1437                 :       11652 : build_m2_short_real_node (void)
    1438                 :             : {
    1439                 :       11652 :   tree c;
    1440                 :             : 
    1441                 :             :   /* Define `REAL'.  */
    1442                 :             : 
    1443                 :       11652 :   c = make_node (REAL_TYPE);
    1444                 :       11652 :   TYPE_PRECISION (c) = FLOAT_TYPE_SIZE;
    1445                 :       11652 :   layout_type (c);
    1446                 :             : 
    1447                 :       11652 :   return c;
    1448                 :             : }
    1449                 :             : 
    1450                 :             : static tree
    1451                 :       11652 : build_m2_real_node (void)
    1452                 :             : {
    1453                 :       11652 :   tree c;
    1454                 :             : 
    1455                 :             :   /* Define `REAL'.  */
    1456                 :             : 
    1457                 :       11652 :   c = make_node (REAL_TYPE);
    1458                 :       11652 :   TYPE_PRECISION (c) = DOUBLE_TYPE_SIZE;
    1459                 :       11652 :   layout_type (c);
    1460                 :             : 
    1461                 :       11652 :   return c;
    1462                 :             : }
    1463                 :             : 
    1464                 :             : static tree
    1465                 :       11652 : build_m2_long_real_node (void)
    1466                 :             : {
    1467                 :       11652 :   tree c;
    1468                 :             : 
    1469                 :             :   /* Define `LONGREAL'.  */
    1470                 :             : 
    1471                 :       11652 :   c = make_node (REAL_TYPE);
    1472                 :       23304 :   TYPE_PRECISION (c) = LONG_DOUBLE_TYPE_SIZE;
    1473                 :       11652 :   layout_type (c);
    1474                 :             : 
    1475                 :       11652 :   return c;
    1476                 :             : }
    1477                 :             : 
    1478                 :             : static tree
    1479                 :       11652 : build_m2_ztype_node (void)
    1480                 :             : {
    1481                 :       11652 :   tree ztype_node;
    1482                 :             : 
    1483                 :             :   /* Define `ZTYPE'.  */
    1484                 :             : 
    1485                 :       11652 :   if (targetm.scalar_mode_supported_p (TImode))
    1486                 :       11366 :     ztype_node = gm2_type_for_size (128, 0);
    1487                 :             :   else
    1488                 :         286 :     ztype_node = gm2_type_for_size (64, 0);
    1489                 :       11652 :   layout_type (ztype_node);
    1490                 :             : 
    1491                 :       11652 :   return ztype_node;
    1492                 :             : }
    1493                 :             : 
    1494                 :             : static tree
    1495                 :       11652 : build_m2_long_int_node (void)
    1496                 :             : {
    1497                 :       11652 :   tree c;
    1498                 :             : 
    1499                 :             :   /* Define `LONGINT'.  */
    1500                 :             : 
    1501                 :       11652 :   c = make_signed_type (LONG_LONG_TYPE_SIZE);
    1502                 :       11652 :   layout_type (c);
    1503                 :             : 
    1504                 :       11652 :   return c;
    1505                 :             : }
    1506                 :             : 
    1507                 :             : static tree
    1508                 :       11652 : build_m2_long_card_node (void)
    1509                 :             : {
    1510                 :       11652 :   tree c;
    1511                 :             : 
    1512                 :             :   /* Define `LONGCARD'.  */
    1513                 :             : 
    1514                 :       11652 :   c = make_unsigned_type (LONG_LONG_TYPE_SIZE);
    1515                 :       11652 :   layout_type (c);
    1516                 :             : 
    1517                 :       11652 :   return c;
    1518                 :             : }
    1519                 :             : 
    1520                 :             : static tree
    1521                 :       11652 : build_m2_short_int_node (void)
    1522                 :             : {
    1523                 :       11652 :   tree c;
    1524                 :             : 
    1525                 :             :   /* Define `SHORTINT'.  */
    1526                 :             : 
    1527                 :       11652 :   c = make_signed_type (SHORT_TYPE_SIZE);
    1528                 :       11652 :   layout_type (c);
    1529                 :             : 
    1530                 :       11652 :   return c;
    1531                 :             : }
    1532                 :             : 
    1533                 :             : static tree
    1534                 :       11652 : build_m2_short_card_node (void)
    1535                 :             : {
    1536                 :       11652 :   tree c;
    1537                 :             : 
    1538                 :             :   /* Define `SHORTCARD'.  */
    1539                 :             : 
    1540                 :       11652 :   c = make_unsigned_type (SHORT_TYPE_SIZE);
    1541                 :       11652 :   layout_type (c);
    1542                 :             : 
    1543                 :       11652 :   return c;
    1544                 :             : }
    1545                 :             : 
    1546                 :             : static tree
    1547                 :       11652 : build_m2_iso_loc_node (void)
    1548                 :             : {
    1549                 :       11652 :   tree c;
    1550                 :             : 
    1551                 :             :   /* Define `LOC' as specified in ISO m2.  */
    1552                 :             : 
    1553                 :       11652 :   c = make_node (INTEGER_TYPE);
    1554                 :       11652 :   TYPE_PRECISION (c) = BITS_PER_UNIT;
    1555                 :       11652 :   TYPE_SIZE (c) = 0;
    1556                 :             : 
    1557                 :       11652 :   fixup_unsigned_type (c);
    1558                 :       11652 :   TYPE_UNSIGNED (c) = 1;
    1559                 :             : 
    1560                 :       11652 :   return c;
    1561                 :             : }
    1562                 :             : 
    1563                 :             : static tree
    1564                 :       11652 : build_m2_integer8_type_node (location_t location)
    1565                 :             : {
    1566                 :       11652 :   m2assert_AssertLocation (location);
    1567                 :       11652 :   return build_m2_specific_size_type (location, INTEGER_TYPE, 8, true);
    1568                 :             : }
    1569                 :             : 
    1570                 :             : static tree
    1571                 :       11652 : build_m2_integer16_type_node (location_t location)
    1572                 :             : {
    1573                 :       11652 :   m2assert_AssertLocation (location);
    1574                 :       11652 :   return build_m2_specific_size_type (location, INTEGER_TYPE, 16, true);
    1575                 :             : }
    1576                 :             : 
    1577                 :             : static tree
    1578                 :       11652 : build_m2_integer32_type_node (location_t location)
    1579                 :             : {
    1580                 :       11652 :   m2assert_AssertLocation (location);
    1581                 :       11652 :   return build_m2_specific_size_type (location, INTEGER_TYPE, 32, true);
    1582                 :             : }
    1583                 :             : 
    1584                 :             : static tree
    1585                 :       11652 : build_m2_integer64_type_node (location_t location)
    1586                 :             : {
    1587                 :       11652 :   m2assert_AssertLocation (location);
    1588                 :       11652 :   return build_m2_specific_size_type (location, INTEGER_TYPE, 64, true);
    1589                 :             : }
    1590                 :             : 
    1591                 :             : static tree
    1592                 :       11652 : build_m2_cardinal8_type_node (location_t location)
    1593                 :             : {
    1594                 :       11652 :   m2assert_AssertLocation (location);
    1595                 :       11652 :   return build_m2_specific_size_type (location, INTEGER_TYPE, 8, false);
    1596                 :             : }
    1597                 :             : 
    1598                 :             : static tree
    1599                 :       11652 : build_m2_cardinal16_type_node (location_t location)
    1600                 :             : {
    1601                 :       11652 :   m2assert_AssertLocation (location);
    1602                 :       11652 :   return build_m2_specific_size_type (location, INTEGER_TYPE, 16, false);
    1603                 :             : }
    1604                 :             : 
    1605                 :             : static tree
    1606                 :       11652 : build_m2_cardinal32_type_node (location_t location)
    1607                 :             : {
    1608                 :       11652 :   m2assert_AssertLocation (location);
    1609                 :       11652 :   return build_m2_specific_size_type (location, INTEGER_TYPE, 32, false);
    1610                 :             : }
    1611                 :             : 
    1612                 :             : static tree
    1613                 :       11652 : build_m2_cardinal64_type_node (location_t location)
    1614                 :             : {
    1615                 :       11652 :   m2assert_AssertLocation (location);
    1616                 :       11652 :   return build_m2_specific_size_type (location, INTEGER_TYPE, 64, false);
    1617                 :             : }
    1618                 :             : 
    1619                 :             : static tree
    1620                 :       11652 : build_m2_bitset8_type_node (location_t location)
    1621                 :             : {
    1622                 :       11652 :   m2assert_AssertLocation (location);
    1623                 :       11652 :   if (broken_set_debugging_info)
    1624                 :       11652 :     return build_m2_specific_size_type (location, INTEGER_TYPE, 8, false);
    1625                 :             :   else
    1626                 :           0 :     return build_m2_specific_size_type (location, SET_TYPE, 8, false);
    1627                 :             : }
    1628                 :             : 
    1629                 :             : static tree
    1630                 :       11652 : build_m2_bitset16_type_node (location_t location)
    1631                 :             : {
    1632                 :       11652 :   m2assert_AssertLocation (location);
    1633                 :       11652 :   if (broken_set_debugging_info)
    1634                 :       11652 :     return build_m2_specific_size_type (location, INTEGER_TYPE, 16, false);
    1635                 :             :   else
    1636                 :           0 :     return build_m2_specific_size_type (location, SET_TYPE, 16, false);
    1637                 :             : }
    1638                 :             : 
    1639                 :             : static tree
    1640                 :       11652 : build_m2_bitset32_type_node (location_t location)
    1641                 :             : {
    1642                 :       11652 :   m2assert_AssertLocation (location);
    1643                 :       11652 :   if (broken_set_debugging_info)
    1644                 :       11652 :     return build_m2_specific_size_type (location, INTEGER_TYPE, 32, false);
    1645                 :             :   else
    1646                 :           0 :     return build_m2_specific_size_type (location, SET_TYPE, 32, false);
    1647                 :             : }
    1648                 :             : 
    1649                 :             : static tree
    1650                 :       11652 : build_m2_real32_type_node (location_t location)
    1651                 :             : {
    1652                 :       11652 :   m2assert_AssertLocation (location);
    1653                 :       11652 :   return build_m2_specific_size_type (location, REAL_TYPE, 32, true);
    1654                 :             : }
    1655                 :             : 
    1656                 :             : static tree
    1657                 :       11652 : build_m2_real64_type_node (location_t location)
    1658                 :             : {
    1659                 :       11652 :   m2assert_AssertLocation (location);
    1660                 :       11652 :   return build_m2_specific_size_type (location, REAL_TYPE, 64, true);
    1661                 :             : }
    1662                 :             : 
    1663                 :             : static tree
    1664                 :       11652 : build_m2_real96_type_node (location_t location)
    1665                 :             : {
    1666                 :       11652 :   m2assert_AssertLocation (location);
    1667                 :       11652 :   return build_m2_specific_size_type (location, REAL_TYPE, 96, true);
    1668                 :             : }
    1669                 :             : 
    1670                 :             : static tree
    1671                 :       11652 : build_m2_real128_type_node (location_t location)
    1672                 :             : {
    1673                 :       11652 :   m2assert_AssertLocation (location);
    1674                 :       11652 :   return build_m2_specific_size_type (location, REAL_TYPE, 128, true);
    1675                 :             : }
    1676                 :             : 
    1677                 :             : static tree
    1678                 :       93216 : build_m2_complex_type_from (tree scalar_type)
    1679                 :             : {
    1680                 :       93216 :   tree new_type;
    1681                 :             : 
    1682                 :       93216 :   if (scalar_type == NULL)
    1683                 :             :     return NULL;
    1684                 :       81564 :   if (scalar_type == float_type_node)
    1685                 :           0 :     return complex_float_type_node;
    1686                 :       81564 :   if (scalar_type == double_type_node)
    1687                 :           0 :     return complex_double_type_node;
    1688                 :       81564 :   if (scalar_type == long_double_type_node)
    1689                 :           0 :     return complex_long_double_type_node;
    1690                 :             : 
    1691                 :       81564 :   new_type = make_node (COMPLEX_TYPE);
    1692                 :       81564 :   TREE_TYPE (new_type) = scalar_type;
    1693                 :       81564 :   layout_type (new_type);
    1694                 :       81564 :   return new_type;
    1695                 :             : }
    1696                 :             : 
    1697                 :             : static tree
    1698                 :       11652 : build_m2_complex_type_node (void)
    1699                 :             : {
    1700                 :           0 :   return build_m2_complex_type_from (m2_real_type_node);
    1701                 :             : }
    1702                 :             : 
    1703                 :             : static tree
    1704                 :       23304 : build_m2_long_complex_type_node (void)
    1705                 :             : {
    1706                 :           0 :   return build_m2_complex_type_from (m2_long_real_type_node);
    1707                 :             : }
    1708                 :             : 
    1709                 :             : static tree
    1710                 :       11652 : build_m2_short_complex_type_node (void)
    1711                 :             : {
    1712                 :           0 :   return build_m2_complex_type_from (m2_short_real_type_node);
    1713                 :             : }
    1714                 :             : 
    1715                 :             : static tree
    1716                 :       11652 : build_m2_complex32_type_node (void)
    1717                 :             : {
    1718                 :           0 :   return build_m2_complex_type_from (m2_real32_type_node);
    1719                 :             : }
    1720                 :             : 
    1721                 :             : static tree
    1722                 :       11652 : build_m2_complex64_type_node (void)
    1723                 :             : {
    1724                 :           0 :   return build_m2_complex_type_from (m2_real64_type_node);
    1725                 :             : }
    1726                 :             : 
    1727                 :             : static tree
    1728                 :       11652 : build_m2_complex96_type_node (void)
    1729                 :             : {
    1730                 :           0 :   return build_m2_complex_type_from (m2_real96_type_node);
    1731                 :             : }
    1732                 :             : 
    1733                 :             : static tree
    1734                 :       11652 : build_m2_complex128_type_node (void)
    1735                 :             : {
    1736                 :           0 :   return build_m2_complex_type_from (m2_real128_type_node);
    1737                 :             : }
    1738                 :             : 
    1739                 :             : static tree
    1740                 :       11652 : build_m2_cardinal_address_type_node (location_t location)
    1741                 :             : {
    1742                 :       11652 :   tree size = size_in_bytes (ptr_type_node);
    1743                 :       11652 :   int bits = TREE_INT_CST_LOW (size) * BITS_PER_UNIT;
    1744                 :             : 
    1745                 :       11652 :   return build_m2_specific_size_type (location, INTEGER_TYPE, bits, false);
    1746                 :             : }
    1747                 :             : 
    1748                 :             : static void
    1749                 :       11652 : build_m2_boolean (location_t location)
    1750                 :             : {
    1751                 :       11652 :   tree tname = get_identifier ("BOOLEAN");
    1752                 :       11652 :   tree typedecl = build_decl (location, TYPE_DECL, tname, boolean_type_node);
    1753                 :       11652 :   DECL_ARTIFICIAL (typedecl) = 1;
    1754                 :       11652 :   TYPE_NAME (boolean_type_node) = typedecl;
    1755                 :       11652 : }
    1756                 :             : 
    1757                 :             : /* InitBaseTypes create the Modula-2 base types.  */
    1758                 :             : 
    1759                 :             : void
    1760                 :       11652 : m2type_InitBaseTypes (location_t location)
    1761                 :             : {
    1762                 :       11652 :   m2assert_AssertLocation (location);
    1763                 :       11652 :   m2block_init ();
    1764                 :             : 
    1765                 :       11652 :   ptr_type_node = build_pointer_type (void_type_node);
    1766                 :             : 
    1767                 :       11652 :   proc_type_node
    1768                 :       11652 :       = build_pointer_type (build_function_type (void_type_node, NULL_TREE));
    1769                 :             : 
    1770                 :       11652 :   bitset_type_node = build_bitset_type (location);
    1771                 :       11652 :   m2_char_type_node = build_m2_char_node ();
    1772                 :       11652 :   m2_integer_type_node = build_m2_integer_node ();
    1773                 :       11652 :   m2_cardinal_type_node = build_m2_cardinal_node ();
    1774                 :       11652 :   m2_short_real_type_node = build_m2_short_real_node ();
    1775                 :       11652 :   m2_real_type_node = build_m2_real_node ();
    1776                 :       11652 :   m2_long_real_type_node = build_m2_long_real_node ();
    1777                 :       11652 :   m2_long_int_type_node = build_m2_long_int_node ();
    1778                 :       11652 :   m2_long_card_type_node = build_m2_long_card_node ();
    1779                 :       11652 :   m2_short_int_type_node = build_m2_short_int_node ();
    1780                 :       11652 :   m2_short_card_type_node = build_m2_short_card_node ();
    1781                 :       11652 :   m2_z_type_node = build_m2_ztype_node ();
    1782                 :       11652 :   m2_integer8_type_node = build_m2_integer8_type_node (location);
    1783                 :       11652 :   m2_integer16_type_node = build_m2_integer16_type_node (location);
    1784                 :       11652 :   m2_integer32_type_node = build_m2_integer32_type_node (location);
    1785                 :       11652 :   m2_integer64_type_node = build_m2_integer64_type_node (location);
    1786                 :       11652 :   m2_cardinal8_type_node = build_m2_cardinal8_type_node (location);
    1787                 :       11652 :   m2_cardinal16_type_node = build_m2_cardinal16_type_node (location);
    1788                 :       11652 :   m2_cardinal32_type_node = build_m2_cardinal32_type_node (location);
    1789                 :       11652 :   m2_cardinal64_type_node = build_m2_cardinal64_type_node (location);
    1790                 :       11652 :   m2_bitset8_type_node = build_m2_bitset8_type_node (location);
    1791                 :       11652 :   m2_bitset16_type_node = build_m2_bitset16_type_node (location);
    1792                 :       11652 :   m2_bitset32_type_node = build_m2_bitset32_type_node (location);
    1793                 :       11652 :   m2_real32_type_node = build_m2_real32_type_node (location);
    1794                 :       11652 :   m2_real64_type_node = build_m2_real64_type_node (location);
    1795                 :       11652 :   m2_real96_type_node = build_m2_real96_type_node (location);
    1796                 :       11652 :   m2_real128_type_node = build_m2_real128_type_node (location);
    1797                 :       11652 :   m2_complex_type_node = build_m2_complex_type_node ();
    1798                 :       11652 :   m2_long_complex_type_node = build_m2_long_complex_type_node ();
    1799                 :       11652 :   m2_short_complex_type_node = build_m2_short_complex_type_node ();
    1800                 :       11652 :   m2_c_type_node = build_m2_long_complex_type_node ();
    1801                 :       11652 :   m2_complex32_type_node = build_m2_complex32_type_node ();
    1802                 :       11652 :   m2_complex64_type_node = build_m2_complex64_type_node ();
    1803                 :       11652 :   m2_complex96_type_node = build_m2_complex96_type_node ();
    1804                 :       11652 :   m2_complex128_type_node = build_m2_complex128_type_node ();
    1805                 :       11652 :   m2_iso_loc_type_node = build_m2_iso_loc_node ();
    1806                 :             : 
    1807                 :       11652 :   m2_cardinal_address_type_node
    1808                 :       11652 :       = build_m2_cardinal_address_type_node (location);
    1809                 :             : 
    1810                 :       11652 :   m2_packed_boolean_type_node = build_nonstandard_integer_type (1, true);
    1811                 :       11652 :   build_m2_boolean (location);
    1812                 :             : 
    1813                 :       11652 :   if (M2Options_GetPPOnly ())
    1814                 :             :     return;
    1815                 :             : 
    1816                 :       11652 :   m2builtins_init (location);
    1817                 :       11652 :   m2except_InitExceptions (location);
    1818                 :       11652 :   m2expr_init (location);
    1819                 :             : }
    1820                 :             : 
    1821                 :             : /* BuildStartType given a, type, with a, name, return a GCC
    1822                 :             :    declaration of this type.  TYPE name = foo ;
    1823                 :             : 
    1824                 :             :    the type, foo, maybe a partially created type (which has
    1825                 :             :    yet to be 'gm2_finish_decl'ed).  */
    1826                 :             : 
    1827                 :             : tree
    1828                 :      502485 : m2type_BuildStartType (location_t location, char *name, tree type)
    1829                 :             : {
    1830                 :      502485 :   tree id = get_identifier (name);
    1831                 :      502485 :   tree decl, tem;
    1832                 :             : 
    1833                 :      502485 :   m2assert_AssertLocation (location);
    1834                 :      502485 :   ASSERT (m2tree_is_type (type), type);
    1835                 :      502485 :   type = m2tree_skip_type_decl (type);
    1836                 :      502485 :   decl = build_decl (location, TYPE_DECL, id, type);
    1837                 :             : 
    1838                 :      502485 :   tem = m2block_pushDecl (decl);
    1839                 :      502485 :   ASSERT (tem == decl, decl);
    1840                 :      502485 :   ASSERT (m2tree_is_type (decl), decl);
    1841                 :             : 
    1842                 :      502485 :   return tem;
    1843                 :             : }
    1844                 :             : 
    1845                 :             : /* BuildEndType finish declaring, type, and return, type.  */
    1846                 :             : 
    1847                 :             : tree
    1848                 :      502485 : m2type_BuildEndType (location_t location, tree type)
    1849                 :             : {
    1850                 :      502485 :   m2assert_AssertLocation (location);
    1851                 :      502485 :   layout_type (TREE_TYPE (type));
    1852                 :      502485 :   gm2_finish_decl (location, type);
    1853                 :      502485 :   return type;
    1854                 :             : }
    1855                 :             : 
    1856                 :             : /* DeclareKnownType given a, type, with a, name, return a GCC
    1857                 :             :    declaration of this type.  TYPE name = foo ; */
    1858                 :             : 
    1859                 :             : tree
    1860                 :      478901 : m2type_DeclareKnownType (location_t location, char *name, tree type)
    1861                 :             : {
    1862                 :      478901 :   m2assert_AssertLocation (location);
    1863                 :      478901 :   return m2type_BuildEndType (location,
    1864                 :      478901 :                               m2type_BuildStartType (location, name, type));
    1865                 :             : }
    1866                 :             : 
    1867                 :             : /* GetDefaultType given a, type, with a, name, return a GCC
    1868                 :             :    declaration of this type.  Checks to see whether the type name has
    1869                 :             :    already been declared as a default type and if so it returns this
    1870                 :             :    declaration.  Otherwise it declares the type.  In Modula-2 this is
    1871                 :             :    equivalent to:
    1872                 :             : 
    1873                 :             :    TYPE name = type ;
    1874                 :             : 
    1875                 :             :    We need this function during gm2 initialization as it allows
    1876                 :             :    gm2 to access default types before creating Modula-2 types.  */
    1877                 :             : 
    1878                 :             : tree
    1879                 :      477666 : m2type_GetDefaultType (location_t location, char *name, tree type)
    1880                 :             : {
    1881                 :      477666 :   tree id = maybe_get_identifier (name);
    1882                 :             : 
    1883                 :      477666 :   m2assert_AssertLocation (location);
    1884                 :      477666 :   if (id == NULL)
    1885                 :             :     {
    1886                 :             :       tree prev = type;
    1887                 :             :       tree t;
    1888                 :             : 
    1889                 :     1106011 :       while (prev != NULL)
    1890                 :             :         {
    1891                 :      628345 :           if (TYPE_NAME (prev) == NULL)
    1892                 :      452090 :             TYPE_NAME (prev) = get_identifier (name);
    1893                 :      628345 :           prev = TREE_TYPE (prev);
    1894                 :             :         }
    1895                 :      477666 :       t = m2type_DeclareKnownType (location, name, type);
    1896                 :      477666 :       return t;
    1897                 :             :     }
    1898                 :             :   else
    1899                 :             :     return id;
    1900                 :             : }
    1901                 :             : 
    1902                 :             : tree
    1903                 :       34956 : do_min_real (tree type)
    1904                 :             : {
    1905                 :       34956 :   REAL_VALUE_TYPE r;
    1906                 :       34956 :   char buf[128];
    1907                 :       34956 :   enum machine_mode mode = TYPE_MODE (type);
    1908                 :             : 
    1909                 :       34956 :   get_max_float (REAL_MODE_FORMAT (mode), buf, sizeof (buf), false);
    1910                 :       34956 :   real_from_string (&r, buf);
    1911                 :       34956 :   return build1 (NEGATE_EXPR, type, build_real (type, r));
    1912                 :             : }
    1913                 :             : 
    1914                 :             : /* GetMinFrom given a, type, return a constant representing the
    1915                 :             :    minimum legal value.  */
    1916                 :             : 
    1917                 :             : tree
    1918                 :      762264 : m2type_GetMinFrom (location_t location, tree type)
    1919                 :             : {
    1920                 :      762264 :   m2assert_AssertLocation (location);
    1921                 :             : 
    1922                 :      762264 :   if (type == m2_real_type_node || type == m2type_GetRealType ())
    1923                 :       11652 :     return do_min_real (type);
    1924                 :      750612 :   if (type == m2_long_real_type_node || type == m2type_GetLongRealType ())
    1925                 :       11652 :     return do_min_real (type);
    1926                 :      738960 :   if (type == m2_short_real_type_node || type == m2type_GetShortRealType ())
    1927                 :       11652 :     return do_min_real (type);
    1928                 :      727308 :   if (type == ptr_type_node)
    1929                 :       11652 :     return m2expr_GetPointerZero (location);
    1930                 :             : 
    1931                 :      715656 :   return TYPE_MIN_VALUE (m2tree_skip_type_decl (type));
    1932                 :             : }
    1933                 :             : 
    1934                 :             : tree
    1935                 :       34956 : do_max_real (tree type)
    1936                 :             : {
    1937                 :       34956 :   REAL_VALUE_TYPE r;
    1938                 :       34956 :   char buf[128];
    1939                 :       34956 :   enum machine_mode mode = TYPE_MODE (type);
    1940                 :             : 
    1941                 :       34956 :   get_max_float (REAL_MODE_FORMAT (mode), buf, sizeof (buf), false);
    1942                 :       34956 :   real_from_string (&r, buf);
    1943                 :       34956 :   return build_real (type, r);
    1944                 :             : }
    1945                 :             : 
    1946                 :             : /* GetMaxFrom given a, type, return a constant representing the
    1947                 :             :    maximum legal value.  */
    1948                 :             : 
    1949                 :             : tree
    1950                 :      762264 : m2type_GetMaxFrom (location_t location, tree type)
    1951                 :             : {
    1952                 :      762264 :   m2assert_AssertLocation (location);
    1953                 :             : 
    1954                 :      762264 :   if (type == m2_real_type_node || type == m2type_GetRealType ())
    1955                 :       11652 :     return do_max_real (type);
    1956                 :      750612 :   if (type == m2_long_real_type_node || type == m2type_GetLongRealType ())
    1957                 :       11652 :     return do_max_real (type);
    1958                 :      738960 :   if (type == m2_short_real_type_node || type == m2type_GetShortRealType ())
    1959                 :       11652 :     return do_max_real (type);
    1960                 :      727308 :   if (type == ptr_type_node)
    1961                 :       11652 :     return fold (m2expr_BuildSub (location, m2expr_GetPointerZero (location),
    1962                 :       11652 :                                   m2expr_GetPointerOne (location), false));
    1963                 :             : 
    1964                 :      715656 :   return TYPE_MAX_VALUE (m2tree_skip_type_decl (type));
    1965                 :             : }
    1966                 :             : 
    1967                 :             : /* BuildTypeDeclaration adds the, type, to the current statement
    1968                 :             :    list.  */
    1969                 :             : 
    1970                 :             : void
    1971                 :       39626 : m2type_BuildTypeDeclaration (location_t location, tree type)
    1972                 :             : {
    1973                 :       39626 :   enum tree_code code = TREE_CODE (type);
    1974                 :             : 
    1975                 :       39626 :   m2assert_AssertLocation (location);
    1976                 :       39626 :   if (code == TYPE_DECL || code == RECORD_TYPE || code == POINTER_TYPE)
    1977                 :             :     {
    1978                 :       39626 :       m2block_pushDecl (build_decl (location, TYPE_DECL, NULL, type));
    1979                 :             :     }
    1980                 :           0 :   else if (code == VAR_DECL)
    1981                 :             :     {
    1982                 :           0 :       m2type_BuildTypeDeclaration (location, TREE_TYPE (type));
    1983                 :           0 :       m2block_pushDecl (
    1984                 :             :           build_stmt (location, DECL_EXPR,
    1985                 :             :                       type));  /* Is this safe?  --fixme--.  */
    1986                 :             :     }
    1987                 :       39626 : }
    1988                 :             : 
    1989                 :             : /* Begin compiling the definition of an enumeration type.  NAME is
    1990                 :             :    its name (or null if anonymous).  Returns the type object, as yet
    1991                 :             :    incomplete.  Also records info about it so that build_enumerator may
    1992                 :             :    be used to declare the individual values as they are read.  */
    1993                 :             : 
    1994                 :             : static tree
    1995                 :       19845 : gm2_start_enum (location_t location, tree name, int ispacked)
    1996                 :             : {
    1997                 :       19845 :   tree enumtype = make_node (ENUMERAL_TYPE);
    1998                 :             : 
    1999                 :       19845 :   m2assert_AssertLocation (location);
    2000                 :       19845 :   if (TYPE_VALUES (enumtype) != 0)
    2001                 :             :     {
    2002                 :             :       /* This enum is a named one that has been declared already.  */
    2003                 :           0 :       error_at (location, "redeclaration of enum %qs",
    2004                 :           0 :                 IDENTIFIER_POINTER (name));
    2005                 :             : 
    2006                 :             :       /* Completely replace its old definition.  The old enumerators remain
    2007                 :             :          defined, however.  */
    2008                 :           0 :       TYPE_VALUES (enumtype) = 0;
    2009                 :             :     }
    2010                 :             : 
    2011                 :       19845 :   TYPE_PACKED (enumtype) = ispacked;
    2012                 :       19845 :   TREE_TYPE (enumtype) = m2type_GetIntegerType ();
    2013                 :             : 
    2014                 :             :   /* This is required as rest_of_type_compilation will use this field
    2015                 :             :      when called from gm2_finish_enum.
    2016                 :             : 
    2017                 :             :      Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
    2018                 :             :      tagged type we just added to the current scope.  This fake NULL-named
    2019                 :             :      TYPE_DECL node helps dwarfout.cc to know when it needs to output a
    2020                 :             :      representation of a tagged type, and it also gives us a convenient
    2021                 :             :      place to record the "scope start" address for the tagged type.  */
    2022                 :             : 
    2023                 :       19845 :   TYPE_STUB_DECL (enumtype) = m2block_pushDecl (
    2024                 :             :       build_decl (location, TYPE_DECL, NULL_TREE, enumtype));
    2025                 :             : 
    2026                 :       19845 :   return enumtype;
    2027                 :             : }
    2028                 :             : 
    2029                 :             : /* After processing and defining all the values of an enumeration
    2030                 :             :    type, install their decls in the enumeration type and finish it off.
    2031                 :             :    ENUMTYPE is the type object, VALUES a list of decl-value pairs, and
    2032                 :             :    ATTRIBUTES are the specified attributes.  Returns ENUMTYPE.  */
    2033                 :             : 
    2034                 :             : static tree
    2035                 :       19845 : gm2_finish_enum (location_t location, tree enumtype, tree values)
    2036                 :             : {
    2037                 :       19845 :   tree pair, tem;
    2038                 :       19845 :   tree minnode = 0, maxnode = 0;
    2039                 :       19845 :   int precision;
    2040                 :       19845 :   signop sign;
    2041                 :             : 
    2042                 :             :   /* Calculate the maximum value of any enumerator in this type.  */
    2043                 :             : 
    2044                 :       19845 :   if (values == error_mark_node)
    2045                 :           0 :     minnode = maxnode = integer_zero_node;
    2046                 :             :   else
    2047                 :             :     {
    2048                 :       19845 :       minnode = maxnode = TREE_VALUE (values);
    2049                 :      357353 :       for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
    2050                 :             :         {
    2051                 :      337508 :           tree value = TREE_VALUE (pair);
    2052                 :      337508 :           if (tree_int_cst_lt (maxnode, value))
    2053                 :          72 :             maxnode = value;
    2054                 :      337508 :           if (tree_int_cst_lt (value, minnode))
    2055                 :      337420 :             minnode = value;
    2056                 :             :         }
    2057                 :             :     }
    2058                 :             : 
    2059                 :             :   /* Construct the final type of this enumeration.  It is the same as
    2060                 :             :      one of the integral types the narrowest one that fits, except that
    2061                 :             :      normally we only go as narrow as int and signed iff any of the
    2062                 :             :      values are negative.  */
    2063                 :       19845 :   sign = (tree_int_cst_sgn (minnode) >= 0) ? UNSIGNED : SIGNED;
    2064                 :       19845 :   precision = MAX (tree_int_cst_min_precision (minnode, sign),
    2065                 :             :                    tree_int_cst_min_precision (maxnode, sign));
    2066                 :             : 
    2067                 :       19845 :   if (precision > TYPE_PRECISION (integer_type_node))
    2068                 :             :     {
    2069                 :           0 :       warning (0, "enumeration values exceed range of integer");
    2070                 :           0 :       tem = long_long_integer_type_node;
    2071                 :             :     }
    2072                 :       19845 :   else if (TYPE_PACKED (enumtype))
    2073                 :          24 :     tem = m2type_BuildSmallestTypeRange (location, minnode, maxnode);
    2074                 :             :   else
    2075                 :       19821 :     tem = sign == UNSIGNED ? unsigned_type_node : integer_type_node;
    2076                 :             : 
    2077                 :       19845 :   TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (tem);
    2078                 :       19845 :   TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (tem);
    2079                 :       19845 :   TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (tem);
    2080                 :       19845 :   TYPE_SIZE (enumtype) = 0;
    2081                 :             : 
    2082                 :             :   /* If the precision of the type was specific with an attribute and it
    2083                 :             :      was too small, give an error.  Otherwise, use it.  */
    2084                 :       19845 :   if (TYPE_PRECISION (enumtype))
    2085                 :             :     {
    2086                 :           0 :       if (precision > TYPE_PRECISION (enumtype))
    2087                 :           0 :         error ("specified mode too small for enumerated values");
    2088                 :             :     }
    2089                 :             :   else
    2090                 :       19845 :     TYPE_PRECISION (enumtype) = TYPE_PRECISION (tem);
    2091                 :             : 
    2092                 :       19845 :   layout_type (enumtype);
    2093                 :             : 
    2094                 :       19845 :   if (values != error_mark_node)
    2095                 :             :     {
    2096                 :             : 
    2097                 :             :       /* Change the type of the enumerators to be the enum type.  We need
    2098                 :             :          to do this irrespective of the size of the enum, for proper type
    2099                 :             :          checking.  Replace the DECL_INITIALs of the enumerators, and the
    2100                 :             :          value slots of the list, with copies that have the enum type; they
    2101                 :             :          cannot be modified in place because they may be shared (e.g.
    2102                 :             :          integer_zero_node) Finally, change the purpose slots to point to the
    2103                 :             :          names of the decls.  */
    2104                 :      377198 :       for (pair = values; pair; pair = TREE_CHAIN (pair))
    2105                 :             :         {
    2106                 :      357353 :           tree enu = TREE_PURPOSE (pair);
    2107                 :      357353 :           tree ini = DECL_INITIAL (enu);
    2108                 :             : 
    2109                 :      357353 :           TREE_TYPE (enu) = enumtype;
    2110                 :             : 
    2111                 :      357353 :           if (TREE_TYPE (ini) != integer_type_node)
    2112                 :           0 :             ini = convert (enumtype, ini);
    2113                 :             : 
    2114                 :      357353 :           DECL_INITIAL (enu) = ini;
    2115                 :      357353 :           TREE_PURPOSE (pair) = DECL_NAME (enu);
    2116                 :      357353 :           TREE_VALUE (pair) = ini;
    2117                 :             :         }
    2118                 :             : 
    2119                 :       19845 :       TYPE_VALUES (enumtype) = values;
    2120                 :             :     }
    2121                 :             : 
    2122                 :             :   /* Fix up all variant types of this enum type.  */
    2123                 :       39690 :   for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
    2124                 :             :     {
    2125                 :       19845 :       if (tem == enumtype)
    2126                 :       19845 :         continue;
    2127                 :           0 :       TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
    2128                 :           0 :       TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
    2129                 :           0 :       TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
    2130                 :           0 :       TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
    2131                 :           0 :       TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype);
    2132                 :           0 :       SET_TYPE_MODE (tem, TYPE_MODE (enumtype));
    2133                 :           0 :       TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
    2134                 :           0 :       SET_TYPE_ALIGN (tem, TYPE_ALIGN (enumtype));
    2135                 :           0 :       TYPE_USER_ALIGN (tem) = TYPE_USER_ALIGN (enumtype);
    2136                 :           0 :       TYPE_UNSIGNED (tem) = TYPE_UNSIGNED (enumtype);
    2137                 :           0 :       TYPE_LANG_SPECIFIC (tem) = TYPE_LANG_SPECIFIC (enumtype);
    2138                 :             :     }
    2139                 :             : 
    2140                 :             :   /* Finish debugging output for this type.  */
    2141                 :       19845 :   rest_of_type_compilation (enumtype, m2block_toplevel ());
    2142                 :       19845 :   return enumtype;
    2143                 :             : }
    2144                 :             : 
    2145                 :             : /* BuildStartEnumeration create an enumerated type in gcc.  */
    2146                 :             : 
    2147                 :             : tree
    2148                 :       19845 : m2type_BuildStartEnumeration (location_t location, char *name, bool ispacked)
    2149                 :             : {
    2150                 :       19845 :   tree id;
    2151                 :             : 
    2152                 :       19845 :   m2assert_AssertLocation (location);
    2153                 :       19845 :   if ((name == NULL) || (strcmp (name, "") == 0))
    2154                 :             :     id = NULL_TREE;
    2155                 :             :   else
    2156                 :       19634 :     id = get_identifier (name);
    2157                 :             : 
    2158                 :       19845 :   return gm2_start_enum (location, id, ispacked);
    2159                 :             : }
    2160                 :             : 
    2161                 :             : /* BuildEndEnumeration finish building the enumeration, it uses the
    2162                 :             :    enum list, enumvalues, and returns a enumeration type tree.  */
    2163                 :             : 
    2164                 :             : tree
    2165                 :       19845 : m2type_BuildEndEnumeration (location_t location, tree enumtype,
    2166                 :             :                             tree enumvalues)
    2167                 :             : {
    2168                 :       19845 :   tree finished ATTRIBUTE_UNUSED
    2169                 :       19845 :       = gm2_finish_enum (location, enumtype, enumvalues);
    2170                 :       19845 :   return enumtype;
    2171                 :             : }
    2172                 :             : 
    2173                 :             : /* Build and install a CONST_DECL for one value of the current
    2174                 :             :    enumeration type (one that was begun with start_enum).  Return a
    2175                 :             :    tree-list containing the CONST_DECL and its value.  Assignment of
    2176                 :             :    sequential values by default is handled here.  */
    2177                 :             : 
    2178                 :             : static tree
    2179                 :      357353 : gm2_build_enumerator (location_t location, tree name, tree value)
    2180                 :             : {
    2181                 :      357353 :   tree decl, type;
    2182                 :             : 
    2183                 :      357353 :   m2assert_AssertLocation (location);
    2184                 :             :   /* Remove no-op casts from the value.  */
    2185                 :      357353 :   if (value)
    2186                 :      357353 :     STRIP_TYPE_NOPS (value);
    2187                 :             : 
    2188                 :             :   /* Now create a declaration for the enum value name.  */
    2189                 :             : 
    2190                 :      357353 :   type = TREE_TYPE (value);
    2191                 :             : 
    2192                 :      357353 :   decl = build_decl (location, CONST_DECL, name, type);
    2193                 :      357353 :   DECL_INITIAL (decl) = convert (type, value);
    2194                 :      357353 :   m2block_pushDecl (decl);
    2195                 :             : 
    2196                 :      357353 :   return tree_cons (decl, value, NULL_TREE);
    2197                 :             : }
    2198                 :             : 
    2199                 :             : /* BuildEnumerator build an enumerator and add it to the,
    2200                 :             :    enumvalues, list.  It returns a copy of the value.  */
    2201                 :             : 
    2202                 :             : tree
    2203                 :      357353 : m2type_BuildEnumerator (location_t location, char *name, tree value,
    2204                 :             :                         tree *enumvalues)
    2205                 :             : {
    2206                 :      357353 :   tree id = get_identifier (name);
    2207                 :      357353 :   tree copy_of_value = copy_node (value);
    2208                 :      357353 :   tree gccenum = gm2_build_enumerator (location, id, copy_of_value);
    2209                 :             : 
    2210                 :      357353 :   m2assert_AssertLocation (location);
    2211                 :             :   /* Choose copy_of_value for enum value.  */
    2212                 :      357353 :   *enumvalues = chainon (gccenum, *enumvalues);
    2213                 :      357353 :   return copy_of_value;
    2214                 :             : }
    2215                 :             : 
    2216                 :             : /* BuildPointerType returns a type which is a pointer to, totype.  */
    2217                 :             : 
    2218                 :             : tree
    2219                 :      139493 : m2type_BuildPointerType (tree totype)
    2220                 :             : {
    2221                 :      139493 :   return build_pointer_type (m2tree_skip_type_decl (totype));
    2222                 :             : }
    2223                 :             : 
    2224                 :             : /* BuildConstPointerType returns a type which is a const pointer
    2225                 :             :    to, totype.  */
    2226                 :             : 
    2227                 :             : tree
    2228                 :          54 : m2type_BuildConstPointerType (tree totype)
    2229                 :             : {
    2230                 :          54 :   tree t = build_pointer_type (m2tree_skip_type_decl (totype));
    2231                 :          54 :   TYPE_READONLY (t) = true;
    2232                 :          54 :   return t;
    2233                 :             : }
    2234                 :             : 
    2235                 :             : /* BuildSetType creates a SET OF [lowval..highval].  */
    2236                 :             : 
    2237                 :             : tree
    2238                 :       26195 : m2type_BuildSetType (location_t location, char *name, tree type, tree lowval,
    2239                 :             :                      tree highval, bool ispacked)
    2240                 :             : {
    2241                 :       26195 :   tree range = build_range_type (m2tree_skip_type_decl (type),
    2242                 :             :                                  m2expr_FoldAndStrip (lowval),
    2243                 :             :                                  m2expr_FoldAndStrip (highval));
    2244                 :             : 
    2245                 :       26195 :   TYPE_PACKED (range) = ispacked;
    2246                 :       26195 :   m2assert_AssertLocation (location);
    2247                 :       26195 :   return m2type_BuildSetTypeFromSubrange (location, name, range,
    2248                 :             :                                           m2expr_FoldAndStrip (lowval),
    2249                 :             :                                           m2expr_FoldAndStrip (highval),
    2250                 :       26195 :                                           ispacked);
    2251                 :             : }
    2252                 :             : 
    2253                 :             : /* push_constructor returns a new compound constructor frame.  */
    2254                 :             : 
    2255                 :             : static struct struct_constructor *
    2256                 :        5125 : push_constructor (void)
    2257                 :             : {
    2258                 :           0 :   struct struct_constructor *p = ggc_alloc<struct_constructor> ();
    2259                 :             : 
    2260                 :        5125 :   p->level = top_constructor;
    2261                 :        5125 :   top_constructor = p;
    2262                 :        5125 :   return p;
    2263                 :             : }
    2264                 :             : 
    2265                 :             : /* pop_constructor throws away the top constructor frame on the
    2266                 :             :    stack.  */
    2267                 :             : 
    2268                 :             : static void
    2269                 :        5125 : pop_constructor (struct struct_constructor *p)
    2270                 :             : {
    2271                 :        5125 :   ASSERT_CONDITION (p
    2272                 :        5125 :                     == top_constructor); /* p should be the top_constructor.  */
    2273                 :        5125 :   top_constructor = top_constructor->level;
    2274                 :        5125 : }
    2275                 :             : 
    2276                 :             : /* BuildStartSetConstructor starts to create a set constant.
    2277                 :             :    Remember that type is really a record type.  */
    2278                 :             : 
    2279                 :             : void *
    2280                 :        1679 : m2type_BuildStartSetConstructor (tree type)
    2281                 :             : {
    2282                 :        1679 :   struct struct_constructor *p = push_constructor ();
    2283                 :             : 
    2284                 :        1679 :   type = m2tree_skip_type_decl (type);
    2285                 :        1679 :   layout_type (type);
    2286                 :        1679 :   p->constructor_type = type;
    2287                 :        1679 :   p->constructor_fields = TYPE_FIELDS (type);
    2288                 :        1679 :   p->constructor_element_list = NULL_TREE;
    2289                 :        1679 :   vec_alloc (p->constructor_elements, 1);
    2290                 :        1679 :   return (void *)p;
    2291                 :             : }
    2292                 :             : 
    2293                 :             : /* BuildSetConstructorElement adds, value, to the
    2294                 :             :    constructor_element_list.  */
    2295                 :             : 
    2296                 :             : void
    2297                 :       27598 : m2type_BuildSetConstructorElement (void *p, tree value)
    2298                 :             : {
    2299                 :       27598 :   struct struct_constructor *c = (struct struct_constructor *)p;
    2300                 :             : 
    2301                 :       27598 :   if (value == NULL_TREE)
    2302                 :             :     {
    2303                 :           0 :       internal_error ("set type cannot be initialized with a %qs",
    2304                 :             :                       "NULL_TREE");
    2305                 :             :       return;
    2306                 :             :     }
    2307                 :             : 
    2308                 :       27598 :   if (c->constructor_fields == NULL)
    2309                 :             :     {
    2310                 :           0 :       internal_error ("set type does not take another integer value");
    2311                 :             :       return;
    2312                 :             :     }
    2313                 :             : 
    2314                 :       27598 :   c->constructor_element_list
    2315                 :       27598 :       = tree_cons (c->constructor_fields, value, c->constructor_element_list);
    2316                 :       27598 :   c->constructor_fields = TREE_CHAIN (c->constructor_fields);
    2317                 :             : }
    2318                 :             : 
    2319                 :             : /* BuildEndSetConstructor finishes building a set constant.  */
    2320                 :             : 
    2321                 :             : tree
    2322                 :        1679 : m2type_BuildEndSetConstructor (void *p)
    2323                 :             : {
    2324                 :        1679 :   tree constructor;
    2325                 :        1679 :   tree link;
    2326                 :        1679 :   struct struct_constructor *c = (struct struct_constructor *)p;
    2327                 :             : 
    2328                 :       19725 :   for (link = c->constructor_element_list; link; link = TREE_CHAIN (link))
    2329                 :             :     {
    2330                 :       18046 :       tree field = TREE_PURPOSE (link);
    2331                 :       18046 :       DECL_SIZE (field) = bitsize_int (SET_WORD_SIZE);
    2332                 :       18046 :       DECL_BIT_FIELD (field) = 1;
    2333                 :             :     }
    2334                 :             : 
    2335                 :        1679 :   constructor = build_constructor_from_list (
    2336                 :             :       c->constructor_type, nreverse (c->constructor_element_list));
    2337                 :        1679 :   TREE_CONSTANT (constructor) = 1;
    2338                 :        1679 :   TREE_STATIC (constructor) = 1;
    2339                 :             : 
    2340                 :        1679 :   pop_constructor (c);
    2341                 :             : 
    2342                 :        1679 :   return constructor;
    2343                 :             : }
    2344                 :             : 
    2345                 :             : /* BuildStartRecordConstructor initializes a record compound
    2346                 :             :    constructor frame.  */
    2347                 :             : 
    2348                 :             : void *
    2349                 :        2296 : m2type_BuildStartRecordConstructor (tree type)
    2350                 :             : {
    2351                 :        2296 :   struct struct_constructor *p = push_constructor ();
    2352                 :             : 
    2353                 :        2296 :   type = m2tree_skip_type_decl (type);
    2354                 :        2296 :   layout_type (type);
    2355                 :        2296 :   p->constructor_type = type;
    2356                 :        2296 :   p->constructor_fields = TYPE_FIELDS (type);
    2357                 :        2296 :   p->constructor_element_list = NULL_TREE;
    2358                 :        2296 :   vec_alloc (p->constructor_elements, 1);
    2359                 :        2296 :   return (void *)p;
    2360                 :             : }
    2361                 :             : 
    2362                 :             : /* BuildEndRecordConstructor returns a tree containing the record
    2363                 :             :    compound literal.  */
    2364                 :             : 
    2365                 :             : tree
    2366                 :        2296 : m2type_BuildEndRecordConstructor (void *p)
    2367                 :             : {
    2368                 :        2296 :   struct struct_constructor *c = (struct struct_constructor *)p;
    2369                 :        2296 :   tree constructor = build_constructor_from_list (
    2370                 :             :       c->constructor_type, nreverse (c->constructor_element_list));
    2371                 :        2296 :   TREE_CONSTANT (constructor) = 1;
    2372                 :        2296 :   TREE_STATIC (constructor) = 1;
    2373                 :             : 
    2374                 :        2296 :   pop_constructor (c);
    2375                 :             : 
    2376                 :        2296 :   return constructor;
    2377                 :             : }
    2378                 :             : 
    2379                 :             : /* BuildRecordConstructorElement adds, value, to the
    2380                 :             :    constructor_element_list.  */
    2381                 :             : 
    2382                 :             : void
    2383                 :        9552 : m2type_BuildRecordConstructorElement (void *p, tree value)
    2384                 :             : {
    2385                 :        9552 :   m2type_BuildSetConstructorElement (p, value);
    2386                 :        9552 : }
    2387                 :             : 
    2388                 :             : /* BuildStartArrayConstructor initializes an array compound
    2389                 :             :    constructor frame.  */
    2390                 :             : 
    2391                 :             : void *
    2392                 :        1150 : m2type_BuildStartArrayConstructor (tree type)
    2393                 :             : {
    2394                 :        1150 :   struct struct_constructor *p = push_constructor ();
    2395                 :             : 
    2396                 :        1150 :   type = m2tree_skip_type_decl (type);
    2397                 :        1150 :   layout_type (type);
    2398                 :        1150 :   p->constructor_type = type;
    2399                 :        1150 :   p->constructor_fields = TREE_TYPE (type);
    2400                 :        1150 :   p->constructor_element_list = NULL_TREE;
    2401                 :        1150 :   vec_alloc (p->constructor_elements, 1);
    2402                 :        1150 :   return (void *)p;
    2403                 :             : }
    2404                 :             : 
    2405                 :             : /* BuildEndArrayConstructor returns a tree containing the array
    2406                 :             :    compound literal.  */
    2407                 :             : 
    2408                 :             : tree
    2409                 :        1150 : m2type_BuildEndArrayConstructor (void *p)
    2410                 :             : {
    2411                 :        1150 :   struct struct_constructor *c = (struct struct_constructor *)p;
    2412                 :        1150 :   tree constructor;
    2413                 :             : 
    2414                 :        1150 :   constructor
    2415                 :        1150 :       = build_constructor (c->constructor_type, c->constructor_elements);
    2416                 :        1150 :   TREE_CONSTANT (constructor) = true;
    2417                 :        1150 :   TREE_STATIC (constructor) = true;
    2418                 :             : 
    2419                 :        1150 :   pop_constructor (c);
    2420                 :             : 
    2421                 :        1150 :   return constructor;
    2422                 :             : }
    2423                 :             : 
    2424                 :             : /* BuildArrayConstructorElement adds, value, to the
    2425                 :             :    constructor_element_list.  */
    2426                 :             : 
    2427                 :             : void
    2428                 :       13088 : m2type_BuildArrayConstructorElement (void *p, tree value, tree indice)
    2429                 :             : {
    2430                 :       13088 :   struct struct_constructor *c = (struct struct_constructor *)p;
    2431                 :       13088 :   constructor_elt celt;
    2432                 :             : 
    2433                 :       13088 :   if (value == NULL_TREE)
    2434                 :             :     {
    2435                 :           0 :       internal_error ("array cannot be initialized with a %qs", "NULL_TREE");
    2436                 :             :       return;
    2437                 :             :     }
    2438                 :             : 
    2439                 :       13088 :   if (c->constructor_fields == NULL_TREE)
    2440                 :             :     {
    2441                 :           0 :       internal_error ("array type must be initialized");
    2442                 :             :       return;
    2443                 :             :     }
    2444                 :             : 
    2445                 :       13088 :   if (c->constructor_fields != TREE_TYPE (value))
    2446                 :             :     {
    2447                 :           0 :       internal_error (
    2448                 :             :           "array element value must be the same type as its declaration");
    2449                 :             :       return;
    2450                 :             :     }
    2451                 :             : 
    2452                 :       13088 :   celt.index = indice;
    2453                 :       13088 :   celt.value = value;
    2454                 :       13088 :   vec_safe_push (c->constructor_elements, celt);
    2455                 :             : }
    2456                 :             : 
    2457                 :             : /* BuildArrayStringConstructor creates an array constructor for,
    2458                 :             :    arrayType, consisting of the character elements defined by, str,
    2459                 :             :    of, length, characters.  */
    2460                 :             : 
    2461                 :             : tree
    2462                 :          24 : m2type_BuildArrayStringConstructor (location_t location, tree arrayType,
    2463                 :             :                                     tree str, tree length)
    2464                 :             : {
    2465                 :          24 :   tree n;
    2466                 :          24 :   tree val;
    2467                 :          24 :   int i = 0;
    2468                 :          24 :   const char *p = TREE_STRING_POINTER (str);
    2469                 :          24 :   tree type = m2tree_skip_type_decl (TREE_TYPE (arrayType));
    2470                 :          24 :   struct struct_constructor *c
    2471                 :          24 :       = (struct struct_constructor *)m2type_BuildStartArrayConstructor (
    2472                 :             :           arrayType);
    2473                 :          24 :   char nul[1];
    2474                 :          24 :   int len = strlen (p);
    2475                 :             : 
    2476                 :          24 :   nul[0] = (char)0;
    2477                 :             : 
    2478                 :          24 :   m2assert_AssertLocation (location);
    2479                 :          24 :   n = m2expr_GetIntegerZero (location);
    2480                 :         336 :   while (m2expr_CompareTrees (n, length) < 0)
    2481                 :             :     {
    2482                 :         288 :       if (i < len)
    2483                 :         264 :         val = m2convert_BuildConvert (
    2484                 :         264 :             location, type, m2type_BuildCharConstant (location, &p[i]), false);
    2485                 :             :       else
    2486                 :          24 :         val = m2type_BuildCharConstant (location, &nul[0]);
    2487                 :         288 :       m2type_BuildArrayConstructorElement (c, val, n);
    2488                 :         288 :       i += 1;
    2489                 :         288 :       n = m2expr_BuildAdd (location, n, m2expr_GetIntegerOne (location),
    2490                 :             :                            false);
    2491                 :             :     }
    2492                 :          24 :   return m2type_BuildEndArrayConstructor (c);
    2493                 :             : }
    2494                 :             : 
    2495                 :             : /* BuildSubrangeType creates a subrange of, type, with, lowval,
    2496                 :             :    highval.  */
    2497                 :             : 
    2498                 :             : tree
    2499                 :       55298 : m2type_BuildSubrangeType (location_t location, char *name, tree type,
    2500                 :             :                           tree lowval, tree highval)
    2501                 :             : {
    2502                 :       55298 :   tree range_type;
    2503                 :             : 
    2504                 :       55298 :   m2assert_AssertLocation (location);
    2505                 :       55298 :   type = m2tree_skip_type_decl (type);
    2506                 :             : 
    2507                 :       55298 :   lowval = m2expr_FoldAndStrip (lowval);
    2508                 :       55298 :   highval = m2expr_FoldAndStrip (highval);
    2509                 :             : 
    2510                 :       55298 :   if (m2expr_TreeOverflow (lowval))
    2511                 :           0 :     error ("low bound for the subrange has overflowed");
    2512                 :       55298 :   if (m2expr_TreeOverflow (highval))
    2513                 :           0 :     error ("high bound for the subrange has overflowed");
    2514                 :             : 
    2515                 :             :   /* First build a type with the base range.  */
    2516                 :       55298 :   range_type = build_range_type (type, TYPE_MIN_VALUE (type),
    2517                 :       55298 :                                  TYPE_MAX_VALUE (type));
    2518                 :             : 
    2519                 :       55298 :   TYPE_UNSIGNED (range_type) = TYPE_UNSIGNED (type);
    2520                 :             : #if 0
    2521                 :             :   /* Then set the actual range.  */
    2522                 :             :   SET_TYPE_RM_MIN_VALUE (range_type, lowval);
    2523                 :             :   SET_TYPE_RM_MAX_VALUE (range_type, highval);
    2524                 :             : #endif
    2525                 :             : 
    2526                 :       55298 :   if ((name != NULL) && (strcmp (name, "") != 0))
    2527                 :             :     {
    2528                 :             :       /* Declared as TYPE foo = [x..y];  */
    2529                 :        1235 :       range_type = m2type_DeclareKnownType (location, name, range_type);
    2530                 :        1235 :       layout_type (m2tree_skip_type_decl (range_type));
    2531                 :             :     }
    2532                 :             : 
    2533                 :       55298 :   return range_type;
    2534                 :             : }
    2535                 :             : 
    2536                 :             : /* BuildCharConstantChar creates a character constant given a character, ch.  */
    2537                 :             : 
    2538                 :             : tree
    2539                 :       20179 : m2type_BuildCharConstantChar (location_t location, char ch)
    2540                 :             : {
    2541                 :       20179 :   tree id = build_int_cst (char_type_node, (int) ch);
    2542                 :       20179 :   id = m2convert_BuildConvert (location, m2type_GetM2CharType (), id, false);
    2543                 :       20179 :   return m2block_RememberConstant (id);
    2544                 :             : }
    2545                 :             : 
    2546                 :             : /* BuildCharConstant creates a character constant given a, string.  */
    2547                 :             : 
    2548                 :             : tree
    2549                 :       16315 : m2type_BuildCharConstant (location_t location, const char *string)
    2550                 :             : {
    2551                 :       16315 :   return m2type_BuildCharConstantChar (location, string[0]);
    2552                 :             : }
    2553                 :             : 
    2554                 :             : /* RealToTree convert a real number into a Tree.  */
    2555                 :             : 
    2556                 :             : tree
    2557                 :        4890 : m2type_RealToTree (char *name)
    2558                 :             : {
    2559                 :        4890 :   return build_real (
    2560                 :             :       m2type_GetLongRealType (),
    2561                 :        4890 :       REAL_VALUE_ATOF (name, TYPE_MODE (m2type_GetLongRealType ())));
    2562                 :             : }
    2563                 :             : 
    2564                 :             : /* gm2_start_struct start to create a struct.  */
    2565                 :             : 
    2566                 :             : static tree
    2567                 :       69759 : gm2_start_struct (location_t location, enum tree_code code, char *name)
    2568                 :             : {
    2569                 :       69759 :   tree s = make_node (code);
    2570                 :       69759 :   tree id;
    2571                 :             : 
    2572                 :       69759 :   m2assert_AssertLocation (location);
    2573                 :       69759 :   if ((name == NULL) || (strcmp (name, "") == 0))
    2574                 :             :     id = NULL_TREE;
    2575                 :             :   else
    2576                 :       44006 :     id = get_identifier (name);
    2577                 :             : 
    2578                 :       69759 :   TYPE_PACKED (s) = false; /* This maybe set true later if necessary.  */
    2579                 :             : 
    2580                 :       69759 :   m2block_pushDecl (build_decl (location, TYPE_DECL, id, s));
    2581                 :       69759 :   return s;
    2582                 :             : }
    2583                 :             : 
    2584                 :             : /* BuildStartRecord return a RECORD tree.  */
    2585                 :             : 
    2586                 :             : tree
    2587                 :       69483 : m2type_BuildStartRecord (location_t location, char *name)
    2588                 :             : {
    2589                 :       69483 :   m2assert_AssertLocation (location);
    2590                 :       69483 :   return gm2_start_struct (location, RECORD_TYPE, name);
    2591                 :             : }
    2592                 :             : 
    2593                 :             : /* BuildStartUnion return a union tree.  */
    2594                 :             : 
    2595                 :             : tree
    2596                 :         276 : m2type_BuildStartUnion (location_t location, char *name)
    2597                 :             : {
    2598                 :         276 :   m2assert_AssertLocation (location);
    2599                 :         276 :   return gm2_start_struct (location, UNION_TYPE, name);
    2600                 :             : }
    2601                 :             : 
    2602                 :             : /* m2type_BuildStartVarient builds a varient record.  It creates a
    2603                 :             :    record field which has a, name, and whose type is a union.  */
    2604                 :             : 
    2605                 :             : tree
    2606                 :         276 : m2type_BuildStartVarient (location_t location, char *name)
    2607                 :             : {
    2608                 :         276 :   tree varient = m2type_BuildStartUnion (location, name);
    2609                 :         276 :   tree field = m2type_BuildStartFieldRecord (location, name, varient);
    2610                 :         276 :   m2assert_AssertLocation (location);
    2611                 :         276 :   return field;
    2612                 :             : }
    2613                 :             : 
    2614                 :             : /* m2type_BuildEndVarient finish the varientField by calling
    2615                 :             :    decl_finish and also finish the type of varientField (which is a
    2616                 :             :    union).  */
    2617                 :             : 
    2618                 :             : tree
    2619                 :         276 : m2type_BuildEndVarient (location_t location, tree varientField,
    2620                 :             :                         tree varientList, bool isPacked)
    2621                 :             : {
    2622                 :         276 :   tree varient = TREE_TYPE (varientField);
    2623                 :         276 :   m2assert_AssertLocation (location);
    2624                 :         276 :   varient = m2type_BuildEndRecord (location, varient, varientList, isPacked);
    2625                 :         276 :   gm2_finish_decl (location, varientField);
    2626                 :         276 :   return varientField;
    2627                 :             : }
    2628                 :             : 
    2629                 :             : /* m2type_BuildStartFieldVarient builds a field varient record.  It
    2630                 :             :    creates a record field which has a, name, and whose type is a
    2631                 :             :    record.  */
    2632                 :             : 
    2633                 :             : tree
    2634                 :         666 : m2type_BuildStartFieldVarient (location_t location, char *name)
    2635                 :             : {
    2636                 :         666 :   tree record = m2type_BuildStartRecord (location, name);
    2637                 :         666 :   tree field = m2type_BuildStartFieldRecord (location, name, record);
    2638                 :         666 :   m2assert_AssertLocation (location);
    2639                 :         666 :   return field;
    2640                 :             : }
    2641                 :             : 
    2642                 :             : /* BuildEndRecord a heavily pruned finish_struct from c-decl.cc.  It
    2643                 :             :    sets the context for each field to, t, propagates isPacked
    2644                 :             :    throughout the fields in the structure.  */
    2645                 :             : 
    2646                 :             : tree
    2647                 :       69759 : m2type_BuildEndRecord (location_t location, tree record, tree fieldlist,
    2648                 :             :                        bool isPacked)
    2649                 :             : {
    2650                 :       69759 :   tree x, d;
    2651                 :             : 
    2652                 :       69759 :   m2assert_AssertLocation (location);
    2653                 :             : 
    2654                 :             :   /* If this type was previously laid out as a forward reference, make
    2655                 :             :      sure we lay it out again.  */
    2656                 :             : 
    2657                 :       69759 :   TYPE_SIZE (record) = 0;
    2658                 :             : 
    2659                 :             :   /* Install struct as DECL_CONTEXT of each field decl.  Also process
    2660                 :             :      specified field sizes, found in the DECL_INITIAL, storing 0 there
    2661                 :             :      after the type has been changed to precision equal to its width,
    2662                 :             :      rather than the precision of the specified standard type.  (Correct
    2663                 :             :      layout requires the original type to have been preserved until now).  */
    2664                 :             : 
    2665                 :      367105 :   for (x = fieldlist; x; x = TREE_CHAIN (x))
    2666                 :             :     {
    2667                 :      297346 :       DECL_CONTEXT (x) = record;
    2668                 :             : 
    2669                 :      297346 :       if (TYPE_PACKED (record) && TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT)
    2670                 :           0 :         DECL_PACKED (x) = 1;
    2671                 :             : 
    2672                 :      297346 :       if (isPacked)
    2673                 :             :         {
    2674                 :          72 :           DECL_PACKED (x) = 1;
    2675                 :          72 :           DECL_BIT_FIELD (x) = 1;
    2676                 :             :         }
    2677                 :             :     }
    2678                 :             : 
    2679                 :             :   /* Now we have the nearly final fieldlist.  Record it, then lay out
    2680                 :             :      the structure or union (including the fields).  */
    2681                 :             : 
    2682                 :       69759 :   TYPE_FIELDS (record) = fieldlist;
    2683                 :       69759 :   layout_type (record);
    2684                 :             : 
    2685                 :             :   /* Now we have the truly final field list.  Store it in this type and
    2686                 :             :      in the variants.  */
    2687                 :             : 
    2688                 :      139518 :   for (x = TYPE_MAIN_VARIANT (record); x; x = TYPE_NEXT_VARIANT (x))
    2689                 :             :     {
    2690                 :       69759 :       TYPE_FIELDS (x) = TYPE_FIELDS (record);
    2691                 :       69759 :       TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (record);
    2692                 :       69759 :       SET_TYPE_ALIGN (x, TYPE_ALIGN (record));
    2693                 :       69759 :       TYPE_USER_ALIGN (x) = TYPE_USER_ALIGN (record);
    2694                 :             :     }
    2695                 :             : 
    2696                 :       69759 :   d = build_decl (location, TYPE_DECL, NULL, record);
    2697                 :       69759 :   TYPE_STUB_DECL (record) = d;
    2698                 :             : 
    2699                 :             :   /* Finish debugging output for this type.  This must be done after we have
    2700                 :             :      called build_decl.  */
    2701                 :       69759 :   rest_of_type_compilation (record, m2block_toplevel ());
    2702                 :             : 
    2703                 :       69759 :   return record;
    2704                 :             : }
    2705                 :             : 
    2706                 :             : /* m2type_BuildEndFieldVarient finish the varientField by calling
    2707                 :             :    decl_finish and also finish the type of varientField (which is a
    2708                 :             :    record).  */
    2709                 :             : 
    2710                 :             : tree
    2711                 :         666 : m2type_BuildEndFieldVarient (location_t location, tree varientField,
    2712                 :             :                              tree varientList, bool isPacked)
    2713                 :             : {
    2714                 :         666 :   tree record = TREE_TYPE (varientField);
    2715                 :             : 
    2716                 :         666 :   m2assert_AssertLocation (location);
    2717                 :         666 :   record = m2type_BuildEndRecord (location, record, varientList, isPacked);
    2718                 :         666 :   gm2_finish_decl (location, varientField);
    2719                 :         666 :   return varientField;
    2720                 :             : }
    2721                 :             : 
    2722                 :             : /* m2type_BuildStartFieldRecord starts building a field record.  It
    2723                 :             :    returns the field which must be completed by calling
    2724                 :             :    gm2_finish_decl.  */
    2725                 :             : 
    2726                 :             : tree
    2727                 :      297376 : m2type_BuildStartFieldRecord (location_t location, char *name, tree type)
    2728                 :             : {
    2729                 :      297376 :   tree field, declarator;
    2730                 :             : 
    2731                 :      297376 :   m2assert_AssertLocation (location);
    2732                 :      297376 :   if ((name == NULL) || (strcmp (name, "") == 0))
    2733                 :             :     declarator = NULL_TREE;
    2734                 :             :   else
    2735                 :      271744 :     declarator = get_identifier (name);
    2736                 :             : 
    2737                 :      297376 :   field = build_decl (location, FIELD_DECL, declarator,
    2738                 :             :                       m2tree_skip_type_decl (type));
    2739                 :      297376 :   return field;
    2740                 :             : }
    2741                 :             : 
    2742                 :             : /* Build a record field with name (name maybe NULL), returning the
    2743                 :             :    new field declaration, FIELD_DECL.
    2744                 :             : 
    2745                 :             :    This is done during the parsing of the struct declaration.  The
    2746                 :             :    FIELD_DECL nodes are chained together and the lot of them are
    2747                 :             :    ultimately passed to `build_struct' to make the RECORD_TYPE node.  */
    2748                 :             : 
    2749                 :             : tree
    2750                 :      296434 : m2type_BuildFieldRecord (location_t location, char *name, tree type)
    2751                 :             : {
    2752                 :      296434 :   tree field = m2type_BuildStartFieldRecord (location, name, type);
    2753                 :             : 
    2754                 :      296434 :   m2assert_AssertLocation (location);
    2755                 :      296434 :   gm2_finish_decl (location, field);
    2756                 :      296434 :   return field;
    2757                 :             : }
    2758                 :             : 
    2759                 :             : /* ChainOn interface so that Modula-2 can also create chains of
    2760                 :             :    declarations.  */
    2761                 :             : 
    2762                 :             : tree
    2763                 :      297346 : m2type_ChainOn (tree t1, tree t2)
    2764                 :             : {
    2765                 :      297346 :   return chainon (t1, t2);
    2766                 :             : }
    2767                 :             : 
    2768                 :             : /* ChainOnParamValue adds a list node {{name, str}, value} into the
    2769                 :             :    tree list.  */
    2770                 :             : 
    2771                 :             : tree
    2772                 :          24 : m2type_ChainOnParamValue (tree list, tree name, tree str, tree value)
    2773                 :             : {
    2774                 :          24 :   return chainon (list, build_tree_list (build_tree_list (name, str), value));
    2775                 :             : }
    2776                 :             : 
    2777                 :             : /* AddStringToTreeList adds, string, to list.  */
    2778                 :             : 
    2779                 :             : tree
    2780                 :           0 : m2type_AddStringToTreeList (tree list, tree string)
    2781                 :             : {
    2782                 :           0 :   return tree_cons (NULL_TREE, string, list);
    2783                 :             : }
    2784                 :             : 
    2785                 :             : /* SetAlignment sets the alignment of a, node, to, align.  It
    2786                 :             :    duplicates the, node, and sets the alignment to prevent alignment
    2787                 :             :    effecting behaviour elsewhere.  */
    2788                 :             : 
    2789                 :             : tree
    2790                 :          84 : m2type_SetAlignment (tree node, tree align)
    2791                 :             : {
    2792                 :          84 :   tree type = NULL_TREE;
    2793                 :          84 :   tree decl = NULL_TREE;
    2794                 :          84 :   bool is_type = false;
    2795                 :          84 :   int i;
    2796                 :             : 
    2797                 :          84 :   if (DECL_P (node))
    2798                 :             :     {
    2799                 :          42 :       decl = node;
    2800                 :          42 :       is_type = (TREE_CODE (node) == TYPE_DECL);
    2801                 :          42 :       type = TREE_TYPE (decl);
    2802                 :             :     }
    2803                 :          42 :   else if (TYPE_P (node))
    2804                 :             :     {
    2805                 :          42 :       is_type = true;
    2806                 :          42 :       type = node;
    2807                 :             :     }
    2808                 :             : 
    2809                 :          84 :   if (TREE_CODE (align) != INTEGER_CST)
    2810                 :           0 :     error ("requested alignment is not a constant");
    2811                 :          84 :   else if ((i = tree_log2 (align)) == -1)
    2812                 :           0 :     error ("requested alignment is not a power of 2");
    2813                 :          84 :   else if (i > HOST_BITS_PER_INT - 2)
    2814                 :           0 :     error ("requested alignment is too large");
    2815                 :          84 :   else if (is_type)
    2816                 :             :     {
    2817                 :             : 
    2818                 :             :       /* If we have a TYPE_DECL, then copy the type, so that we don't
    2819                 :             :          accidentally modify a builtin type.  See pushdecl.  */
    2820                 :          18 :       if (decl && TREE_TYPE (decl) != error_mark_node
    2821                 :          78 :           && DECL_ORIGINAL_TYPE (decl) == NULL_TREE)
    2822                 :             :         {
    2823                 :          18 :           tree tt = TREE_TYPE (decl);
    2824                 :          18 :           type = build_variant_type_copy (type);
    2825                 :          18 :           DECL_ORIGINAL_TYPE (decl) = tt;
    2826                 :          18 :           TYPE_NAME (type) = decl;
    2827                 :          18 :           TREE_USED (type) = TREE_USED (decl);
    2828                 :          18 :           TREE_TYPE (decl) = type;
    2829                 :             :         }
    2830                 :             : 
    2831                 :          60 :       SET_TYPE_ALIGN (type, (1 << i) * BITS_PER_UNIT);
    2832                 :          60 :       TYPE_USER_ALIGN (type) = 1;
    2833                 :             : 
    2834                 :          60 :       if (decl)
    2835                 :             :         {
    2836                 :          18 :           SET_DECL_ALIGN (decl, (1 << i) * BITS_PER_UNIT);
    2837                 :          18 :           DECL_USER_ALIGN (decl) = 1;
    2838                 :             :         }
    2839                 :             :     }
    2840                 :          24 :   else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FIELD_DECL)
    2841                 :           0 :     error ("alignment may not be specified for %qD", decl);
    2842                 :             :   else
    2843                 :             :     {
    2844                 :          24 :       SET_DECL_ALIGN (decl, (1 << i) * BITS_PER_UNIT);
    2845                 :          24 :       DECL_USER_ALIGN (decl) = 1;
    2846                 :             :     }
    2847                 :          84 :   return node;
    2848                 :             : }
    2849                 :             : 
    2850                 :             : /* SetDeclPacked sets the packed bit in decl TREE, node.  It
    2851                 :             :    returns the node.  */
    2852                 :             : 
    2853                 :             : tree
    2854                 :         144 : m2type_SetDeclPacked (tree node)
    2855                 :             : {
    2856                 :         144 :   DECL_PACKED (node) = 1;
    2857                 :         144 :   return node;
    2858                 :             : }
    2859                 :             : 
    2860                 :             : /* SetTypePacked sets the packed bit in type TREE, node.  It
    2861                 :             :    returns the node.  */
    2862                 :             : 
    2863                 :             : tree
    2864                 :          24 : m2type_SetTypePacked (tree node)
    2865                 :             : {
    2866                 :          24 :   TYPE_PACKED (node) = 1;
    2867                 :          24 :   return node;
    2868                 :             : }
    2869                 :             : 
    2870                 :             : /* SetRecordFieldOffset returns field after the byteOffset and
    2871                 :             :    bitOffset has been applied to it.  */
    2872                 :             : 
    2873                 :             : tree
    2874                 :          72 : m2type_SetRecordFieldOffset (tree field, tree byteOffset, tree bitOffset,
    2875                 :             :                              tree fieldtype, tree nbits)
    2876                 :             : {
    2877                 :          72 :   DECL_FIELD_OFFSET (field) = byteOffset;
    2878                 :          72 :   DECL_FIELD_BIT_OFFSET (field) = bitOffset;
    2879                 :          72 :   TREE_TYPE (field) = m2tree_skip_type_decl (fieldtype);
    2880                 :          72 :   DECL_SIZE (field) = bitsize_int (TREE_INT_CST_LOW (nbits));
    2881                 :          72 :   return field;
    2882                 :             : }
    2883                 :             : 
    2884                 :             : /* BuildPackedFieldRecord builds a packed field record of, name,
    2885                 :             :    and, fieldtype.  */
    2886                 :             : 
    2887                 :             : tree
    2888                 :           0 : m2type_BuildPackedFieldRecord (location_t location, char *name, tree fieldtype)
    2889                 :             : {
    2890                 :           0 :   m2assert_AssertLocation (location);
    2891                 :           0 :   return m2type_BuildFieldRecord (location, name, fieldtype);
    2892                 :             : }
    2893                 :             : 
    2894                 :             : /* BuildNumberOfArrayElements returns the number of elements in an
    2895                 :             :    arrayType.  */
    2896                 :             : 
    2897                 :             : tree
    2898                 :         456 : m2type_BuildNumberOfArrayElements (location_t location, tree arrayType)
    2899                 :             : {
    2900                 :         456 :   tree index = TYPE_DOMAIN (arrayType);
    2901                 :         456 :   tree high = TYPE_MAX_VALUE (index);
    2902                 :         456 :   tree low = TYPE_MIN_VALUE (index);
    2903                 :         456 :   tree elements = m2expr_BuildAdd (
    2904                 :             :       location, m2expr_BuildSub (location, high, low, false),
    2905                 :             :       m2expr_GetIntegerOne (location), false);
    2906                 :         456 :   m2assert_AssertLocation (location);
    2907                 :         456 :   return elements;
    2908                 :             : }
    2909                 :             : 
    2910                 :             : /* AddStatement maps onto add_stmt.  */
    2911                 :             : 
    2912                 :             : void
    2913                 :      260354 : m2type_AddStatement (location_t location, tree t)
    2914                 :             : {
    2915                 :      260354 :   if (t != NULL_TREE)
    2916                 :      182490 :     add_stmt (location, t);
    2917                 :      260354 : }
    2918                 :             : 
    2919                 :             : /* MarkFunctionReferenced marks a function as referenced.  */
    2920                 :             : 
    2921                 :             : void
    2922                 :       13489 : m2type_MarkFunctionReferenced (tree f)
    2923                 :             : {
    2924                 :       13489 :   if (f != NULL_TREE)
    2925                 :        7688 :     if (TREE_CODE (f) == FUNCTION_DECL)
    2926                 :        5356 :       mark_decl_referenced (f);
    2927                 :       13489 : }
    2928                 :             : 
    2929                 :             : /* GarbageCollect force gcc to garbage collect.  */
    2930                 :             : 
    2931                 :             : void
    2932                 :           0 : m2type_GarbageCollect (void)
    2933                 :             : {
    2934                 :           0 :   ggc_collect ();
    2935                 :           0 : }
    2936                 :             : 
    2937                 :             : /* gm2_type_for_size return an integer type with BITS bits of
    2938                 :             :    precision, that is unsigned if UNSIGNEDP is nonzero, otherwise
    2939                 :             :    signed.  */
    2940                 :             : 
    2941                 :             : tree
    2942                 :           0 : m2type_gm2_type_for_size (unsigned int bits, bool unsignedp)
    2943                 :             : {
    2944                 :           0 :   if (bits == TYPE_PRECISION (integer_type_node))
    2945                 :           0 :     return unsignedp ? unsigned_type_node : integer_type_node;
    2946                 :             : 
    2947                 :           0 :   if (bits == TYPE_PRECISION (signed_char_type_node))
    2948                 :           0 :     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
    2949                 :             : 
    2950                 :           0 :   if (bits == TYPE_PRECISION (short_integer_type_node))
    2951                 :           0 :     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
    2952                 :             : 
    2953                 :           0 :   if (bits == TYPE_PRECISION (long_integer_type_node))
    2954                 :           0 :     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
    2955                 :             : 
    2956                 :           0 :   if (bits == TYPE_PRECISION (long_long_integer_type_node))
    2957                 :           0 :     return (unsignedp ? long_long_unsigned_type_node
    2958                 :           0 :                       : long_long_integer_type_node);
    2959                 :             : 
    2960                 :           0 :   if (bits <= TYPE_PRECISION (intQI_type_node))
    2961                 :           0 :     return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
    2962                 :             : 
    2963                 :           0 :   if (bits <= TYPE_PRECISION (intHI_type_node))
    2964                 :           0 :     return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
    2965                 :             : 
    2966                 :           0 :   if (bits <= TYPE_PRECISION (intSI_type_node))
    2967                 :           0 :     return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
    2968                 :             : 
    2969                 :           0 :   if (bits <= TYPE_PRECISION (intDI_type_node))
    2970                 :           0 :     return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
    2971                 :             : 
    2972                 :             :   return 0;
    2973                 :             : }
    2974                 :             : 
    2975                 :             : /* gm2_unsigned_type return an unsigned type the same as TYPE in
    2976                 :             :    other respects.  */
    2977                 :             : 
    2978                 :             : tree
    2979                 :           6 : m2type_gm2_unsigned_type (tree type)
    2980                 :             : {
    2981                 :           6 :   tree type1 = TYPE_MAIN_VARIANT (type);
    2982                 :           6 :   if (type1 == signed_char_type_node || type1 == char_type_node)
    2983                 :           0 :     return unsigned_char_type_node;
    2984                 :           6 :   if (type1 == integer_type_node)
    2985                 :           6 :     return unsigned_type_node;
    2986                 :           0 :   if (type1 == short_integer_type_node)
    2987                 :           0 :     return short_unsigned_type_node;
    2988                 :           0 :   if (type1 == long_integer_type_node)
    2989                 :           0 :     return long_unsigned_type_node;
    2990                 :           0 :   if (type1 == long_long_integer_type_node)
    2991                 :           0 :     return long_long_unsigned_type_node;
    2992                 :             : 
    2993                 :             : #if HOST_BITS_PER_WIDE_INT >= 64
    2994                 :           0 :   if (type1 == intTI_type_node)
    2995                 :           0 :     return unsigned_intTI_type_node;
    2996                 :             : #endif
    2997                 :           0 :   if (type1 == intDI_type_node)
    2998                 :           0 :     return unsigned_intDI_type_node;
    2999                 :           0 :   if (type1 == intSI_type_node)
    3000                 :           0 :     return unsigned_intSI_type_node;
    3001                 :           0 :   if (type1 == intHI_type_node)
    3002                 :           0 :     return unsigned_intHI_type_node;
    3003                 :           0 :   if (type1 == intQI_type_node)
    3004                 :           0 :     return unsigned_intQI_type_node;
    3005                 :             : 
    3006                 :           0 :   return m2type_gm2_signed_or_unsigned_type (true, type);
    3007                 :             : }
    3008                 :             : 
    3009                 :             : /* gm2_signed_type return a signed type the same as TYPE in other
    3010                 :             :    respects.  */
    3011                 :             : 
    3012                 :             : tree
    3013                 :          12 : m2type_gm2_signed_type (tree type)
    3014                 :             : {
    3015                 :          12 :   tree type1 = TYPE_MAIN_VARIANT (type);
    3016                 :          12 :   if (type1 == unsigned_char_type_node || type1 == char_type_node)
    3017                 :           0 :     return signed_char_type_node;
    3018                 :          12 :   if (type1 == unsigned_type_node)
    3019                 :          12 :     return integer_type_node;
    3020                 :           0 :   if (type1 == short_unsigned_type_node)
    3021                 :           0 :     return short_integer_type_node;
    3022                 :           0 :   if (type1 == long_unsigned_type_node)
    3023                 :           0 :     return long_integer_type_node;
    3024                 :           0 :   if (type1 == long_long_unsigned_type_node)
    3025                 :           0 :     return long_long_integer_type_node;
    3026                 :             : 
    3027                 :             : #if HOST_BITS_PER_WIDE_INT >= 64
    3028                 :           0 :   if (type1 == unsigned_intTI_type_node)
    3029                 :           0 :     return intTI_type_node;
    3030                 :             : #endif
    3031                 :           0 :   if (type1 == unsigned_intDI_type_node)
    3032                 :           0 :     return intDI_type_node;
    3033                 :           0 :   if (type1 == unsigned_intSI_type_node)
    3034                 :           0 :     return intSI_type_node;
    3035                 :           0 :   if (type1 == unsigned_intHI_type_node)
    3036                 :           0 :     return intHI_type_node;
    3037                 :           0 :   if (type1 == unsigned_intQI_type_node)
    3038                 :           0 :     return intQI_type_node;
    3039                 :             : 
    3040                 :           0 :   return m2type_gm2_signed_or_unsigned_type (false, type);
    3041                 :             : }
    3042                 :             : 
    3043                 :             : /* check_type if the precision of baseType and type are the same
    3044                 :             :    then return true and set the signed or unsigned type in result
    3045                 :             :    else return false.  */
    3046                 :             : 
    3047                 :             : static int
    3048                 :           0 : check_type (tree baseType, tree type, int unsignedp, tree baseu, tree bases,
    3049                 :             :             tree *result)
    3050                 :             : {
    3051                 :           0 :   if (TYPE_PRECISION (baseType) == TYPE_PRECISION (type))
    3052                 :             :     {
    3053                 :           0 :       if (unsignedp)
    3054                 :           0 :         *result = baseu;
    3055                 :             :       else
    3056                 :           0 :         *result = bases;
    3057                 :           0 :       return true;
    3058                 :             :     }
    3059                 :             :   return false;
    3060                 :             : }
    3061                 :             : 
    3062                 :             : /* gm2_signed_or_unsigned_type return a type the same as TYPE
    3063                 :             :    except unsigned or signed according to UNSIGNEDP.  */
    3064                 :             : 
    3065                 :             : tree
    3066                 :           0 : m2type_gm2_signed_or_unsigned_type (int unsignedp, tree type)
    3067                 :             : {
    3068                 :           0 :   tree result;
    3069                 :             : 
    3070                 :           0 :   if (!INTEGRAL_TYPE_P (type) || TYPE_UNSIGNED (type) == unsignedp)
    3071                 :             :     return type;
    3072                 :             : 
    3073                 :             :   /* For INTEGER_TYPEs we must check the precision as well, so as to
    3074                 :             :      yield correct results for bit-field types.  */
    3075                 :             : 
    3076                 :           0 :   if (check_type (signed_char_type_node, type, unsignedp,
    3077                 :             :                   unsigned_char_type_node, signed_char_type_node, &result))
    3078                 :           0 :     return result;
    3079                 :           0 :   if (check_type (integer_type_node, type, unsignedp, unsigned_type_node,
    3080                 :             :                   integer_type_node, &result))
    3081                 :           0 :     return result;
    3082                 :           0 :   if (check_type (short_integer_type_node, type, unsignedp,
    3083                 :             :                   short_unsigned_type_node, short_integer_type_node, &result))
    3084                 :           0 :     return result;
    3085                 :           0 :   if (check_type (long_integer_type_node, type, unsignedp,
    3086                 :             :                   long_unsigned_type_node, long_integer_type_node, &result))
    3087                 :           0 :     return result;
    3088                 :           0 :   if (check_type (long_long_integer_type_node, type, unsignedp,
    3089                 :             :                   long_long_unsigned_type_node, long_long_integer_type_node,
    3090                 :             :                   &result))
    3091                 :           0 :     return result;
    3092                 :             : 
    3093                 :             : #if HOST_BITS_PER_WIDE_INT >= 64
    3094                 :           0 :   if (check_type (intTI_type_node, type, unsignedp, unsigned_intTI_type_node,
    3095                 :             :                   intTI_type_node, &result))
    3096                 :           0 :     return result;
    3097                 :             : #endif
    3098                 :           0 :   if (check_type (intDI_type_node, type, unsignedp, unsigned_intDI_type_node,
    3099                 :             :                   intDI_type_node, &result))
    3100                 :           0 :     return result;
    3101                 :           0 :   if (check_type (intSI_type_node, type, unsignedp, unsigned_intSI_type_node,
    3102                 :             :                   intSI_type_node, &result))
    3103                 :           0 :     return result;
    3104                 :           0 :   if (check_type (intHI_type_node, type, unsignedp, unsigned_intHI_type_node,
    3105                 :             :                   intHI_type_node, &result))
    3106                 :           0 :     return result;
    3107                 :           0 :   if (check_type (intQI_type_node, type, unsignedp, unsigned_intQI_type_node,
    3108                 :             :                   intQI_type_node, &result))
    3109                 :           0 :     return result;
    3110                 :             : #undef TYPE_OK
    3111                 :             : 
    3112                 :             :   return type;
    3113                 :             : }
    3114                 :             : 
    3115                 :             : /* IsAddress returns true if the type is an ADDRESS.  */
    3116                 :             : 
    3117                 :             : int
    3118                 :     1527988 : m2type_IsAddress (tree type)
    3119                 :             : {
    3120                 :     1527988 :   return type == ptr_type_node;
    3121                 :             : }
    3122                 :             : 
    3123                 :             : #include "gt-m2-m2type.h"
        

Generated by: LCOV version 2.0-1

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.