Ignore:
Timestamp:
Apr 27, 2004, 8:39:34 PM (21 years ago)
Author:
bird
Message:

GCC v3.3.3 sources.

Location:
branches/GNU/src/gcc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/gcc

    • Property svn:ignore
      •  

        old new  
        2626configure.vr
        2727configure.vrs
         28dir.info
        2829Makefile
        29 dir.info
        3030lost+found
        3131update.out
  • branches/GNU/src/gcc/libobjc/encoding.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r1390 r1391  
    11/* Encoding of types for Objective C.
    2    Copyright (C) 1993, 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
     2   Copyright (C) 1993, 1995, 1996, 1997, 1998, 2000, 2002
     3   Free Software Foundation, Inc.
    34   Contributed by Kresten Krab Thorup
    45   Bitfield support by Ovidiu Predescu
     
    3031#include "objc-api.h"
    3132#include "encoding.h"
     33#include <stdlib.h>
    3234
    3335#undef  MAX
    3436#define MAX(X, Y)                    \
    35   ({ typeof(X) __x = (X), __y = (Y); \
     37  ({ typeof (X) __x = (X), __y = (Y); \
    3638     (__x > __y ? __x : __y); })
    3739
    3840#undef  MIN
    3941#define MIN(X, Y)                    \
    40   ({ typeof(X) __x = (X), __y = (Y); \
     42  ({ typeof (X) __x = (X), __y = (Y); \
    4143     (__x < __y ? __x : __y); })
    4244
    4345#undef  ROUND
    4446#define ROUND(V, A) \
    45   ({ typeof(V) __v=(V); typeof(A) __a=(A); \
    46      __a*((__v+__a-1)/__a); })
     47  ({ typeof (V) __v = (V); typeof (A) __a = (A); \
     48     __a * ((__v+__a - 1)/__a); })
    4749
    4850
     
    7981/* Some ROUND_TYPE_ALIGN macros use TARGET_foo, and consequently
    8082   target_flags.  Define a dummy entry here to so we don't die.  */
    81 
    82 static int target_flags = 0;
    83 
    84 static inline int
    85 atoi (const char* str)
    86 {
    87   int res = 0;
    88  
    89   while (isdigit (*str))
    90     res *= 10, res += (*str++ - '0');
    91 
    92   return res;
    93 }
    94 
    95 /*
    96   return the size of an object specified by type
     83/* ??? FIXME: As of 2002-06-21, the attribute `unused' doesn't seem to
     84   eliminate the warning.  */
     85static int __attribute__ ((__unused__)) target_flags = 0;
     86
     87/*
     88  return the size of an object specified by type
    9789*/
    9890
    9991int
    100 objc_sizeof_type (const char* type)
     92objc_sizeof_type (const char *type)
    10193{
    10294  /* Skip the variable name if any */
     
    10799    }
    108100
    109   switch(*type) {
     101  switch (*type) {
    110102  case _C_ID:
    111     return sizeof(id);
     103    return sizeof (id);
    112104    break;
    113105
    114106  case _C_CLASS:
    115     return sizeof(Class);
     107    return sizeof (Class);
    116108    break;
    117109
    118110  case _C_SEL:
    119     return sizeof(SEL);
     111    return sizeof (SEL);
    120112    break;
    121113
    122114  case _C_CHR:
    123     return sizeof(char);
    124     break;
    125    
     115    return sizeof (char);
     116    break;
     117
    126118  case _C_UCHR:
    127     return sizeof(unsigned char);
     119    return sizeof (unsigned char);
    128120    break;
    129121
    130122  case _C_SHT:
    131     return sizeof(short);
     123    return sizeof (short);
    132124    break;
    133125
    134126  case _C_USHT:
    135     return sizeof(unsigned short);
     127    return sizeof (unsigned short);
    136128    break;
    137129
    138130  case _C_INT:
    139     return sizeof(int);
     131    return sizeof (int);
    140132    break;
    141133
    142134  case _C_UINT:
    143     return sizeof(unsigned int);
     135    return sizeof (unsigned int);
    144136    break;
    145137
    146138  case _C_LNG:
    147     return sizeof(long);
     139    return sizeof (long);
    148140    break;
    149141
    150142  case _C_ULNG:
    151     return sizeof(unsigned long);
     143    return sizeof (unsigned long);
    152144    break;
    153145
    154146  case _C_LNG_LNG:
    155     return sizeof(long long);
     147    return sizeof (long long);
    156148    break;
    157149
    158150  case _C_ULNG_LNG:
    159     return sizeof(unsigned long long);
     151    return sizeof (unsigned long long);
    160152    break;
    161153
    162154  case _C_FLT:
    163     return sizeof(float);
     155    return sizeof (float);
    164156    break;
    165157
    166158  case _C_DBL:
    167     return sizeof(double);
     159    return sizeof (double);
    168160    break;
    169161
    170162  case _C_VOID:
    171     return sizeof(void);
    172     break;
     163    return sizeof (void);
     164    break;
     165
    173166  case _C_PTR:
    174167  case _C_ATOM:
    175168  case _C_CHARPTR:
    176     return sizeof(char*);
     169    return sizeof (char *);
    177170    break;
    178171
    179172  case _C_ARY_B:
    180173    {
    181       int len = atoi(type+1);
    182       while (isdigit(*++type));
    183       return len*objc_aligned_size (type);
    184     }
    185     break;
     174      int len = atoi (type + 1);
     175      while (isdigit ((unsigned char)*++type))
     176        ;
     177      return len * objc_aligned_size (type);
     178    }
     179    break;
    186180
    187181  case _C_BFLD:
     
    192186
    193187      position = atoi (type + 1);
    194       while (isdigit (*++type));
     188      while (isdigit ((unsigned char)*++type))
     189        ;
    195190      size = atoi (type + 1);
    196191
     
    216211    {
    217212      int max_size = 0;
    218       while (*type != _C_UNION_E && *type++ != '=') /* do nothing */;
     213      while (*type != _C_UNION_E && *type++ != '=')
     214        /* do nothing */;
    219215      while (*type != _C_UNION_E)
    220216        {
     
    230226      return max_size;
    231227    }
    232    
     228
    233229  default:
    234230    {
    235       objc_error(nil, OBJC_ERR_BAD_TYPE, "unknown type %s\n", type);
     231      objc_error (nil, OBJC_ERR_BAD_TYPE, "unknown type %s\n", type);
    236232      return 0;
    237233    }
     
    241237
    242238/*
    243   Return the alignment of an object specified by type 
     239  Return the alignment of an object specified by type
    244240*/
    245241
    246242int
    247 objc_alignof_type(const char* type)
     243objc_alignof_type (const char *type)
    248244{
    249245  /* Skip the variable name if any */
     
    253249        /* do nothing */;
    254250    }
    255   switch(*type) {
     251  switch (*type) {
    256252  case _C_ID:
    257     return __alignof__(id);
     253    return __alignof__ (id);
    258254    break;
    259255
    260256  case _C_CLASS:
    261     return __alignof__(Class);
    262     break;
    263    
     257    return __alignof__ (Class);
     258    break;
     259
    264260  case _C_SEL:
    265     return __alignof__(SEL);
     261    return __alignof__ (SEL);
    266262    break;
    267263
    268264  case _C_CHR:
    269     return __alignof__(char);
    270     break;
    271    
     265    return __alignof__ (char);
     266    break;
     267
    272268  case _C_UCHR:
    273     return __alignof__(unsigned char);
     269    return __alignof__ (unsigned char);
    274270    break;
    275271
    276272  case _C_SHT:
    277     return __alignof__(short);
     273    return __alignof__ (short);
    278274    break;
    279275
    280276  case _C_USHT:
    281     return __alignof__(unsigned short);
     277    return __alignof__ (unsigned short);
    282278    break;
    283279
    284280  case _C_INT:
    285     return __alignof__(int);
     281    return __alignof__ (int);
    286282    break;
    287283
    288284  case _C_UINT:
    289     return __alignof__(unsigned int);
     285    return __alignof__ (unsigned int);
    290286    break;
    291287
    292288  case _C_LNG:
    293     return __alignof__(long);
     289    return __alignof__ (long);
    294290    break;
    295291
    296292  case _C_ULNG:
    297     return __alignof__(unsigned long);
     293    return __alignof__ (unsigned long);
    298294    break;
    299295
    300296  case _C_LNG_LNG:
    301     return __alignof__(long long);
     297    return __alignof__ (long long);
    302298    break;
    303299
    304300  case _C_ULNG_LNG:
    305     return __alignof__(unsigned long long);
     301    return __alignof__ (unsigned long long);
    306302    break;
    307303
    308304  case _C_FLT:
    309     return __alignof__(float);
     305    return __alignof__ (float);
    310306    break;
    311307
    312308  case _C_DBL:
    313     return __alignof__(double);
     309    return __alignof__ (double);
    314310    break;
    315311
     
    317313  case _C_ATOM:
    318314  case _C_CHARPTR:
    319     return __alignof__(char*);
     315    return __alignof__ (char *);
    320316    break;
    321317
    322318  case _C_ARY_B:
    323     while (isdigit(*++type)) /* do nothing */;
     319    while (isdigit ((unsigned char)*++type))
     320      /* do nothing */;
    324321    return objc_alignof_type (type);
    325322
     
    340337    {
    341338      int maxalign = 0;
    342       while (*type != _C_UNION_E && *type++ != '=') /* do nothing */;
     339      while (*type != _C_UNION_E && *type++ != '=')
     340        /* do nothing */;
    343341      while (*type != _C_UNION_E)
    344342        {
     
    357355  default:
    358356    {
    359       objc_error(nil, OBJC_ERR_BAD_TYPE, "unknown type %s\n", type);
     357      objc_error (nil, OBJC_ERR_BAD_TYPE, "unknown type %s\n", type);
    360358      return 0;
    361359    }
     
    368366
    369367int
    370 objc_aligned_size (const char* type)
     368objc_aligned_size (const char *type)
    371369{
    372370  int size, align;
     
    387385/*
    388386  The size rounded up to the nearest integral of the wordsize, taken
    389   to be the size of a void*.
    390 */
    391 
    392 int 
    393 objc_promoted_size (const char* type)
     387  to be the size of a void *.
     388*/
     389
     390int
     391objc_promoted_size (const char *type)
    394392{
    395393  int size, wordsize;
     
    403401
    404402  size = objc_sizeof_type (type);
    405   wordsize = sizeof (void*);
     403  wordsize = sizeof (void *);
    406404
    407405  return ROUND (size, wordsize);
     
    413411*/
    414412
    415 inline const char*
    416 objc_skip_type_qualifiers (const char* type)
     413inline const char *
     414objc_skip_type_qualifiers (const char *type)
    417415{
    418416  while (*type == _C_CONST
    419          || *type == _C_IN 
     417         || *type == _C_IN
    420418         || *type == _C_INOUT
    421          || *type == _C_OUT 
     419         || *type == _C_OUT
    422420         || *type == _C_BYCOPY
    423421         || *type == _C_BYREF
     
    430428}
    431429
    432  
     430
    433431/*
    434432  Skip one typespec element.  If the typespec is prepended by type
     
    436434*/
    437435
    438 const char*
    439 objc_skip_typespec (const char* type)
     436const char *
     437objc_skip_typespec (const char *type)
    440438{
    441439  /* Skip the variable name if any */
     
    447445
    448446  type = objc_skip_type_qualifiers (type);
    449  
     447
    450448  switch (*type) {
    451449
     
    458456    else
    459457      {
    460         while (*++type != '"') /* do nothing */;
     458        while (*++type != '"')
     459          /* do nothing */;
    461460        return type + 1;
    462461      }
     
    486485  case _C_ARY_B:
    487486    /* skip digits, typespec and closing ']' */
    488    
    489     while(isdigit(*++type));
    490     type = objc_skip_typespec(type);
     487
     488    while (isdigit ((unsigned char)*++type))
     489      ;
     490    type = objc_skip_typespec (type);
    491491    if (*type == _C_ARY_E)
    492492      return ++type;
    493493    else
    494494      {
    495         objc_error(nil, OBJC_ERR_BAD_TYPE, "bad array type %s\n", type);
     495        objc_error (nil, OBJC_ERR_BAD_TYPE, "bad array type %s\n", type);
    496496        return 0;
    497497      }
     
    499499  case _C_BFLD:
    500500    /* The new encoding of bitfields is: b 'position' 'type' 'size' */
    501     while (isdigit (*++type));  /* skip position */
    502     while (isdigit (*++type));  /* skip type and size */
     501    while (isdigit ((unsigned char)*++type))
     502      ; /* skip position */
     503    while (isdigit ((unsigned char)*++type))
     504      ; /* skip type and size */
    503505    return type;
    504506
    505507  case _C_STRUCT_B:
    506508    /* skip name, and elements until closing '}'  */
    507    
    508     while (*type != _C_STRUCT_E && *type++ != '=');
    509     while (*type != _C_STRUCT_E) { type = objc_skip_typespec (type); }
     509
     510    while (*type != _C_STRUCT_E && *type++ != '=')
     511      ;
     512    while (*type != _C_STRUCT_E)
     513      {
     514        type = objc_skip_typespec (type);
     515      }
    510516    return ++type;
    511517
    512518  case _C_UNION_B:
    513519    /* skip name, and elements until closing ')'  */
    514    
    515     while (*type != _C_UNION_E && *type++ != '=');
    516     while (*type != _C_UNION_E) { type = objc_skip_typespec (type); }
     520
     521    while (*type != _C_UNION_E && *type++ != '=')
     522      ;
     523    while (*type != _C_UNION_E)
     524      {
     525        type = objc_skip_typespec (type);
     526      }
    517527    return ++type;
    518528
    519529  case _C_PTR:
    520530    /* Just skip the following typespec */
    521    
     531
    522532    return objc_skip_typespec (++type);
    523    
     533
    524534  default:
    525535    {
    526       objc_error(nil, OBJC_ERR_BAD_TYPE, "unknown type %s\n", type);
     536      objc_error (nil, OBJC_ERR_BAD_TYPE, "unknown type %s\n", type);
    527537      return 0;
    528538    }
     
    534544  '+' if the argument is passed in registers.
    535545*/
    536 inline const char*
    537 objc_skip_offset (const char* type)
    538 {
    539   if (*type == '+') type++;
    540   while(isdigit(*++type));
     546inline const char *
     547objc_skip_offset (const char *type)
     548{
     549  if (*type == '+')
     550    type++;
     551  while (isdigit ((unsigned char) *++type))
     552    ;
    541553  return type;
    542554}
     
    545557  Skip an argument specification of a method encoding.
    546558*/
    547 const char*
    548 objc_skip_argspec (const char* type)
     559const char *
     560objc_skip_argspec (const char *type)
    549561{
    550562  type = objc_skip_typespec (type);
     
    556568  Return the number of arguments that the method MTH expects.
    557569  Note that all methods need two implicit arguments `self' and
    558   `_cmd'. 
     570  `_cmd'.
    559571*/
    560572int
    561 method_get_number_of_arguments (struct objc_method* mth)
     573method_get_number_of_arguments (struct objc_method *mth)
    562574{
    563575  int i = 0;
    564   const char* type = mth->method_types;
     576  const char *type = mth->method_types;
    565577  while (*type)
    566578    {
     
    578590
    579591int
    580 method_get_sizeof_arguments (struct objc_method* mth)
    581 {
    582   const char* type = objc_skip_typespec (mth->method_types);
     592method_get_sizeof_arguments (struct objc_method *mth)
     593{
     594  const char *type = objc_skip_typespec (mth->method_types);
    583595  return atoi (type);
    584596}
     
    589601
    590602  {
    591     char *datum, *type; 
     603    char *datum, *type;
    592604    for (datum = method_get_first_argument (method, argframe, &type);
    593605         datum; datum = method_get_next_argument (argframe, &type))
     
    600612          {
    601613            if ((flags & _F_IN) == _F_IN)
    602               [portal encodeData: *(char**)datum ofType: ++type];
     614              [portal encodeData: *(char **) datum ofType: ++type];
    603615          }
    604616      }
    605617  }
    606 */ 
    607 
    608 char*
    609 method_get_next_argument (arglist_t argframe,
    610                           const char **type)
     618*/
     619
     620char *
     621method_get_next_argument (arglist_t argframe, const char **type)
    611622{
    612623  const char *t = objc_skip_argspec (*type);
     
    625636
    626637/*
    627   Return a pointer to the value of the first argument of the method 
     638  Return a pointer to the value of the first argument of the method
    628639  described in M with the given argumentframe ARGFRAME.  The type
    629   is returned in TYPE.  type must be passed to successive calls of 
     640  is returned in TYPE.  type must be passed to successive calls of
    630641  method_get_next_argument.
    631642*/
    632 char*
    633 method_get_first_argument (struct objc_method* m,
    634                            arglist_t argframe, 
    635                            const char** type)
     643char *
     644method_get_first_argument (struct objc_method *m,
     645                           arglist_t argframe,
     646                           const char **type)
    636647{
    637648  *type = m->method_types;
     
    642653   Return a pointer to the ARGth argument of the method
    643654   M from the frame ARGFRAME.  The type of the argument
    644    is returned in the value-result argument TYPE 
    645 */
    646 
    647 char*
    648 method_get_nth_argument (struct objc_method* m,
    649                          arglist_t argframe, int arg, 
     655   is returned in the value-result argument TYPE
     656*/
     657
     658char *
     659method_get_nth_argument (struct objc_method *m,
     660                         arglist_t argframe, int arg,
    650661                         const char **type)
    651662{
    652   const char* t = objc_skip_argspec (m->method_types);
     663  const char *t = objc_skip_argspec (m->method_types);
    653664
    654665  if (arg > method_get_number_of_arguments (m))
     
    657668  while (arg--)
    658669    t = objc_skip_argspec (t);
    659  
     670
    660671  *type = t;
    661672  t = objc_skip_typespec (t);
     
    668679
    669680unsigned
    670 objc_get_type_qualifiers (const char* type)
     681objc_get_type_qualifiers (const char *type)
    671682{
    672683  unsigned res = 0;
     
    721732  if (*type++ != _C_STRUCT_B)
    722733    {
    723       objc_error(nil, OBJC_ERR_BAD_TYPE,
     734      objc_error (nil, OBJC_ERR_BAD_TYPE,
    724735                 "record type expected in objc_layout_structure, got %s\n",
    725736                 type);
     
    750761objc_layout_structure_next_member (struct objc_struct_layout *layout)
    751762{
    752   register int known_align = layout->record_size;
    753763  register int desired_align = 0;
    754764
    755765  /* The following are used only if the field is a bitfield */
    756   register const char *bfld_type;
    757   register int bfld_type_size, bfld_type_align, bfld_field_size;
     766  register const char *bfld_type = 0;
     767  register int bfld_type_size, bfld_type_align = 0, bfld_field_size = 0;
    758768
    759769  /* The current type without the type qualifiers */
     
    770780        /* Get the bitfield's type */
    771781        for (bfld_type = type + 1;
    772              isdigit(*bfld_type);
     782             isdigit ((unsigned char)*bfld_type);
    773783             bfld_type++)
    774784          /* do nothing */;
     
    794804
    795805  if (*type != _C_BFLD)
    796     desired_align = objc_alignof_type(type) * BITS_PER_UNIT;
     806    desired_align = objc_alignof_type (type) * BITS_PER_UNIT;
    797807  else
    798808    {
    799809      desired_align = 1;
    800810      /* Skip the bitfield's offset */
    801       for (bfld_type = type + 1; isdigit(*bfld_type); bfld_type++)
     811      for (bfld_type = type + 1;
     812           isdigit ((unsigned char) *bfld_type);
     813           bfld_type++)
    802814        /* do nothing */;
    803815
     
    819831#ifndef PCC_BITFIELD_TYPE_MATTERS
    820832  layout->record_align = MAX (layout->record_align, desired_align);
    821 #else
     833#else   /* PCC_BITFIELD_TYPE_MATTERS */
    822834  if (*type == _C_BFLD)
    823835    {
     
    851863  else
    852864    layout->record_align = MAX (layout->record_align, desired_align);
    853 #endif
     865#endif  /* PCC_BITFIELD_TYPE_MATTERS */
    854866
    855867  /* Does this field automatically have alignment it needs
     
    865877      layout->record_size = ROUND (layout->record_size, desired_align);
    866878    }
    867  
     879
    868880  /* Jump to the next field in record. */
    869881
     
    885897         alignment. */
    886898
    887 #if defined(ROUND_TYPE_ALIGN) && !defined(__sparc__)
     899#if defined (ROUND_TYPE_ALIGN) && ! defined (__sparc__)
    888900      layout->record_align = ROUND_TYPE_ALIGN (layout->original_type,
    889901                                               1,
Note: See TracChangeset for help on using the changeset viewer.