Changeset 1391 for branches/GNU/src/gcc/libobjc/encoding.c
- Timestamp:
- Apr 27, 2004, 8:39:34 PM (21 years ago)
- Location:
- branches/GNU/src/gcc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/gcc
- Property svn:ignore
-
old new 26 26 configure.vr 27 27 configure.vrs 28 dir.info 28 29 Makefile 29 dir.info30 30 lost+found 31 31 update.out
-
- Property svn:ignore
-
branches/GNU/src/gcc/libobjc/encoding.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r1390 r1391 1 1 /* 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. 3 4 Contributed by Kresten Krab Thorup 4 5 Bitfield support by Ovidiu Predescu … … 30 31 #include "objc-api.h" 31 32 #include "encoding.h" 33 #include <stdlib.h> 32 34 33 35 #undef MAX 34 36 #define MAX(X, Y) \ 35 ({ typeof (X) __x = (X), __y = (Y); \37 ({ typeof (X) __x = (X), __y = (Y); \ 36 38 (__x > __y ? __x : __y); }) 37 39 38 40 #undef MIN 39 41 #define MIN(X, Y) \ 40 ({ typeof (X) __x = (X), __y = (Y); \42 ({ typeof (X) __x = (X), __y = (Y); \ 41 43 (__x < __y ? __x : __y); }) 42 44 43 45 #undef ROUND 44 46 #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); }) 47 49 48 50 … … 79 81 /* Some ROUND_TYPE_ALIGN macros use TARGET_foo, and consequently 80 82 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. */ 85 static int __attribute__ ((__unused__)) target_flags = 0; 86 87 /* 88 return the size of an object specified by type 97 89 */ 98 90 99 91 int 100 objc_sizeof_type (const char *type)92 objc_sizeof_type (const char *type) 101 93 { 102 94 /* Skip the variable name if any */ … … 107 99 } 108 100 109 switch (*type) {101 switch (*type) { 110 102 case _C_ID: 111 return sizeof (id);103 return sizeof (id); 112 104 break; 113 105 114 106 case _C_CLASS: 115 return sizeof (Class);107 return sizeof (Class); 116 108 break; 117 109 118 110 case _C_SEL: 119 return sizeof (SEL);111 return sizeof (SEL); 120 112 break; 121 113 122 114 case _C_CHR: 123 return sizeof (char);124 break; 125 115 return sizeof (char); 116 break; 117 126 118 case _C_UCHR: 127 return sizeof (unsigned char);119 return sizeof (unsigned char); 128 120 break; 129 121 130 122 case _C_SHT: 131 return sizeof (short);123 return sizeof (short); 132 124 break; 133 125 134 126 case _C_USHT: 135 return sizeof (unsigned short);127 return sizeof (unsigned short); 136 128 break; 137 129 138 130 case _C_INT: 139 return sizeof (int);131 return sizeof (int); 140 132 break; 141 133 142 134 case _C_UINT: 143 return sizeof (unsigned int);135 return sizeof (unsigned int); 144 136 break; 145 137 146 138 case _C_LNG: 147 return sizeof (long);139 return sizeof (long); 148 140 break; 149 141 150 142 case _C_ULNG: 151 return sizeof (unsigned long);143 return sizeof (unsigned long); 152 144 break; 153 145 154 146 case _C_LNG_LNG: 155 return sizeof (long long);147 return sizeof (long long); 156 148 break; 157 149 158 150 case _C_ULNG_LNG: 159 return sizeof (unsigned long long);151 return sizeof (unsigned long long); 160 152 break; 161 153 162 154 case _C_FLT: 163 return sizeof (float);155 return sizeof (float); 164 156 break; 165 157 166 158 case _C_DBL: 167 return sizeof (double);159 return sizeof (double); 168 160 break; 169 161 170 162 case _C_VOID: 171 return sizeof(void); 172 break; 163 return sizeof (void); 164 break; 165 173 166 case _C_PTR: 174 167 case _C_ATOM: 175 168 case _C_CHARPTR: 176 return sizeof (char*);169 return sizeof (char *); 177 170 break; 178 171 179 172 case _C_ARY_B: 180 173 { 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; 186 180 187 181 case _C_BFLD: … … 192 186 193 187 position = atoi (type + 1); 194 while (isdigit (*++type)); 188 while (isdigit ((unsigned char)*++type)) 189 ; 195 190 size = atoi (type + 1); 196 191 … … 216 211 { 217 212 int max_size = 0; 218 while (*type != _C_UNION_E && *type++ != '=') /* do nothing */; 213 while (*type != _C_UNION_E && *type++ != '=') 214 /* do nothing */; 219 215 while (*type != _C_UNION_E) 220 216 { … … 230 226 return max_size; 231 227 } 232 228 233 229 default: 234 230 { 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); 236 232 return 0; 237 233 } … … 241 237 242 238 /* 243 Return the alignment of an object specified by type 239 Return the alignment of an object specified by type 244 240 */ 245 241 246 242 int 247 objc_alignof_type (const char*type)243 objc_alignof_type (const char *type) 248 244 { 249 245 /* Skip the variable name if any */ … … 253 249 /* do nothing */; 254 250 } 255 switch (*type) {251 switch (*type) { 256 252 case _C_ID: 257 return __alignof__ (id);253 return __alignof__ (id); 258 254 break; 259 255 260 256 case _C_CLASS: 261 return __alignof__ (Class);262 break; 263 257 return __alignof__ (Class); 258 break; 259 264 260 case _C_SEL: 265 return __alignof__ (SEL);261 return __alignof__ (SEL); 266 262 break; 267 263 268 264 case _C_CHR: 269 return __alignof__ (char);270 break; 271 265 return __alignof__ (char); 266 break; 267 272 268 case _C_UCHR: 273 return __alignof__ (unsigned char);269 return __alignof__ (unsigned char); 274 270 break; 275 271 276 272 case _C_SHT: 277 return __alignof__ (short);273 return __alignof__ (short); 278 274 break; 279 275 280 276 case _C_USHT: 281 return __alignof__ (unsigned short);277 return __alignof__ (unsigned short); 282 278 break; 283 279 284 280 case _C_INT: 285 return __alignof__ (int);281 return __alignof__ (int); 286 282 break; 287 283 288 284 case _C_UINT: 289 return __alignof__ (unsigned int);285 return __alignof__ (unsigned int); 290 286 break; 291 287 292 288 case _C_LNG: 293 return __alignof__ (long);289 return __alignof__ (long); 294 290 break; 295 291 296 292 case _C_ULNG: 297 return __alignof__ (unsigned long);293 return __alignof__ (unsigned long); 298 294 break; 299 295 300 296 case _C_LNG_LNG: 301 return __alignof__ (long long);297 return __alignof__ (long long); 302 298 break; 303 299 304 300 case _C_ULNG_LNG: 305 return __alignof__ (unsigned long long);301 return __alignof__ (unsigned long long); 306 302 break; 307 303 308 304 case _C_FLT: 309 return __alignof__ (float);305 return __alignof__ (float); 310 306 break; 311 307 312 308 case _C_DBL: 313 return __alignof__ (double);309 return __alignof__ (double); 314 310 break; 315 311 … … 317 313 case _C_ATOM: 318 314 case _C_CHARPTR: 319 return __alignof__ (char*);315 return __alignof__ (char *); 320 316 break; 321 317 322 318 case _C_ARY_B: 323 while (isdigit(*++type)) /* do nothing */; 319 while (isdigit ((unsigned char)*++type)) 320 /* do nothing */; 324 321 return objc_alignof_type (type); 325 322 … … 340 337 { 341 338 int maxalign = 0; 342 while (*type != _C_UNION_E && *type++ != '=') /* do nothing */; 339 while (*type != _C_UNION_E && *type++ != '=') 340 /* do nothing */; 343 341 while (*type != _C_UNION_E) 344 342 { … … 357 355 default: 358 356 { 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); 360 358 return 0; 361 359 } … … 368 366 369 367 int 370 objc_aligned_size (const char *type)368 objc_aligned_size (const char *type) 371 369 { 372 370 int size, align; … … 387 385 /* 388 386 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 390 int 391 objc_promoted_size (const char *type) 394 392 { 395 393 int size, wordsize; … … 403 401 404 402 size = objc_sizeof_type (type); 405 wordsize = sizeof (void *);403 wordsize = sizeof (void *); 406 404 407 405 return ROUND (size, wordsize); … … 413 411 */ 414 412 415 inline const char *416 objc_skip_type_qualifiers (const char *type)413 inline const char * 414 objc_skip_type_qualifiers (const char *type) 417 415 { 418 416 while (*type == _C_CONST 419 || *type == _C_IN 417 || *type == _C_IN 420 418 || *type == _C_INOUT 421 || *type == _C_OUT 419 || *type == _C_OUT 422 420 || *type == _C_BYCOPY 423 421 || *type == _C_BYREF … … 430 428 } 431 429 432 430 433 431 /* 434 432 Skip one typespec element. If the typespec is prepended by type … … 436 434 */ 437 435 438 const char *439 objc_skip_typespec (const char *type)436 const char * 437 objc_skip_typespec (const char *type) 440 438 { 441 439 /* Skip the variable name if any */ … … 447 445 448 446 type = objc_skip_type_qualifiers (type); 449 447 450 448 switch (*type) { 451 449 … … 458 456 else 459 457 { 460 while (*++type != '"') /* do nothing */; 458 while (*++type != '"') 459 /* do nothing */; 461 460 return type + 1; 462 461 } … … 486 485 case _C_ARY_B: 487 486 /* 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); 491 491 if (*type == _C_ARY_E) 492 492 return ++type; 493 493 else 494 494 { 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); 496 496 return 0; 497 497 } … … 499 499 case _C_BFLD: 500 500 /* 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 */ 503 505 return type; 504 506 505 507 case _C_STRUCT_B: 506 508 /* 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 } 510 516 return ++type; 511 517 512 518 case _C_UNION_B: 513 519 /* 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 } 517 527 return ++type; 518 528 519 529 case _C_PTR: 520 530 /* Just skip the following typespec */ 521 531 522 532 return objc_skip_typespec (++type); 523 533 524 534 default: 525 535 { 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); 527 537 return 0; 528 538 } … … 534 544 '+' if the argument is passed in registers. 535 545 */ 536 inline const char* 537 objc_skip_offset (const char* type) 538 { 539 if (*type == '+') type++; 540 while(isdigit(*++type)); 546 inline const char * 547 objc_skip_offset (const char *type) 548 { 549 if (*type == '+') 550 type++; 551 while (isdigit ((unsigned char) *++type)) 552 ; 541 553 return type; 542 554 } … … 545 557 Skip an argument specification of a method encoding. 546 558 */ 547 const char *548 objc_skip_argspec (const char *type)559 const char * 560 objc_skip_argspec (const char *type) 549 561 { 550 562 type = objc_skip_typespec (type); … … 556 568 Return the number of arguments that the method MTH expects. 557 569 Note that all methods need two implicit arguments `self' and 558 `_cmd'. 570 `_cmd'. 559 571 */ 560 572 int 561 method_get_number_of_arguments (struct objc_method *mth)573 method_get_number_of_arguments (struct objc_method *mth) 562 574 { 563 575 int i = 0; 564 const char *type = mth->method_types;576 const char *type = mth->method_types; 565 577 while (*type) 566 578 { … … 578 590 579 591 int 580 method_get_sizeof_arguments (struct objc_method *mth)581 { 582 const char *type = objc_skip_typespec (mth->method_types);592 method_get_sizeof_arguments (struct objc_method *mth) 593 { 594 const char *type = objc_skip_typespec (mth->method_types); 583 595 return atoi (type); 584 596 } … … 589 601 590 602 { 591 char *datum, *type; 603 char *datum, *type; 592 604 for (datum = method_get_first_argument (method, argframe, &type); 593 605 datum; datum = method_get_next_argument (argframe, &type)) … … 600 612 { 601 613 if ((flags & _F_IN) == _F_IN) 602 [portal encodeData: *(char **)datum ofType: ++type];614 [portal encodeData: *(char **) datum ofType: ++type]; 603 615 } 604 616 } 605 617 } 606 */ 607 608 char* 609 method_get_next_argument (arglist_t argframe, 610 const char **type) 618 */ 619 620 char * 621 method_get_next_argument (arglist_t argframe, const char **type) 611 622 { 612 623 const char *t = objc_skip_argspec (*type); … … 625 636 626 637 /* 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 628 639 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 630 641 method_get_next_argument. 631 642 */ 632 char *633 method_get_first_argument (struct objc_method *m,634 arglist_t argframe, 635 const char **type)643 char * 644 method_get_first_argument (struct objc_method *m, 645 arglist_t argframe, 646 const char **type) 636 647 { 637 648 *type = m->method_types; … … 642 653 Return a pointer to the ARGth argument of the method 643 654 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 658 char * 659 method_get_nth_argument (struct objc_method *m, 660 arglist_t argframe, int arg, 650 661 const char **type) 651 662 { 652 const char *t = objc_skip_argspec (m->method_types);663 const char *t = objc_skip_argspec (m->method_types); 653 664 654 665 if (arg > method_get_number_of_arguments (m)) … … 657 668 while (arg--) 658 669 t = objc_skip_argspec (t); 659 670 660 671 *type = t; 661 672 t = objc_skip_typespec (t); … … 668 679 669 680 unsigned 670 objc_get_type_qualifiers (const char *type)681 objc_get_type_qualifiers (const char *type) 671 682 { 672 683 unsigned res = 0; … … 721 732 if (*type++ != _C_STRUCT_B) 722 733 { 723 objc_error (nil, OBJC_ERR_BAD_TYPE,734 objc_error (nil, OBJC_ERR_BAD_TYPE, 724 735 "record type expected in objc_layout_structure, got %s\n", 725 736 type); … … 750 761 objc_layout_structure_next_member (struct objc_struct_layout *layout) 751 762 { 752 register int known_align = layout->record_size;753 763 register int desired_align = 0; 754 764 755 765 /* 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; 758 768 759 769 /* The current type without the type qualifiers */ … … 770 780 /* Get the bitfield's type */ 771 781 for (bfld_type = type + 1; 772 isdigit (*bfld_type);782 isdigit ((unsigned char)*bfld_type); 773 783 bfld_type++) 774 784 /* do nothing */; … … 794 804 795 805 if (*type != _C_BFLD) 796 desired_align = objc_alignof_type (type) * BITS_PER_UNIT;806 desired_align = objc_alignof_type (type) * BITS_PER_UNIT; 797 807 else 798 808 { 799 809 desired_align = 1; 800 810 /* 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++) 802 814 /* do nothing */; 803 815 … … 819 831 #ifndef PCC_BITFIELD_TYPE_MATTERS 820 832 layout->record_align = MAX (layout->record_align, desired_align); 821 #else 833 #else /* PCC_BITFIELD_TYPE_MATTERS */ 822 834 if (*type == _C_BFLD) 823 835 { … … 851 863 else 852 864 layout->record_align = MAX (layout->record_align, desired_align); 853 #endif 865 #endif /* PCC_BITFIELD_TYPE_MATTERS */ 854 866 855 867 /* Does this field automatically have alignment it needs … … 865 877 layout->record_size = ROUND (layout->record_size, desired_align); 866 878 } 867 879 868 880 /* Jump to the next field in record. */ 869 881 … … 885 897 alignment. */ 886 898 887 #if defined (ROUND_TYPE_ALIGN) && !defined(__sparc__)899 #if defined (ROUND_TYPE_ALIGN) && ! defined (__sparc__) 888 900 layout->record_align = ROUND_TYPE_ALIGN (layout->original_type, 889 901 1, -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.