| [2] | 1 | /* Basic data types for Objective C.
|
|---|
| 2 | Copyright (C) 1998 Free Software Foundation, Inc.
|
|---|
| 3 | Contributed by Ovidiu Predescu.
|
|---|
| 4 |
|
|---|
| 5 | This file is part of GNU CC.
|
|---|
| 6 |
|
|---|
| 7 | GNU CC is free software; you can redistribute it and/or modify
|
|---|
| 8 | it under the terms of the GNU General Public License as published by
|
|---|
| 9 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 10 | any later version.
|
|---|
| 11 |
|
|---|
| 12 | GNU CC is distributed in the hope that it will be useful,
|
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 15 | GNU General Public License for more details.
|
|---|
| 16 |
|
|---|
| 17 | You should have received a copy of the GNU General Public License
|
|---|
| 18 | along with GNU CC; see the file COPYING. If not, write to
|
|---|
| 19 | the Free Software Foundation, 59 Temple Place - Suite 330,
|
|---|
| 20 | Boston, MA 02111-1307, USA. */
|
|---|
| 21 |
|
|---|
| 22 | /* As a special exception, if you link this library with files
|
|---|
| 23 | compiled with GCC to produce an executable, this does not cause
|
|---|
| 24 | the resulting executable to be covered by the GNU General Public License.
|
|---|
| 25 | This exception does not however invalidate any other reasons why
|
|---|
| 26 | the executable file might be covered by the GNU General Public License. */
|
|---|
| 27 |
|
|---|
| 28 | #include "tconfig.h"
|
|---|
| 29 | #include "objc.h"
|
|---|
| 30 | #include "encoding.h"
|
|---|
| 31 |
|
|---|
| 32 | #include <assert.h>
|
|---|
| 33 | #include <string.h>
|
|---|
| 34 |
|
|---|
| 35 | #if OBJC_WITH_GC
|
|---|
| 36 |
|
|---|
| 37 | #include <gc.h>
|
|---|
| 38 |
|
|---|
| 39 | /* gc_typed.h uses the following but doesn't declare them */
|
|---|
| 40 | typedef GC_word word;
|
|---|
| 41 | typedef GC_signed_word signed_word;
|
|---|
| 42 |
|
|---|
| 43 | #if BITS_PER_WORD == 32
|
|---|
| 44 | # define LOGWL 5
|
|---|
| 45 | # define modWORDSZ(n) ((n) & 0x1f) /* n mod size of word */
|
|---|
| 46 | #endif
|
|---|
| 47 |
|
|---|
| 48 | #if BITS_PER_WORD == 64
|
|---|
| 49 | # define LOGWL 6
|
|---|
| 50 | # define modWORDSZ(n) ((n) & 0x3f) /* n mod size of word */
|
|---|
| 51 | #endif
|
|---|
| 52 |
|
|---|
| 53 | #define divWORDSZ(n) ((n) >> LOGWL) /* divide n by size of word */
|
|---|
| 54 |
|
|---|
| 55 | #include <gc_typed.h>
|
|---|
| 56 |
|
|---|
| 57 | /* The following functions set up in `mask` the corresponding pointers.
|
|---|
| 58 | The offset is incremented with the size of the type. */
|
|---|
| 59 |
|
|---|
| 60 | #define ROUND(V, A) \
|
|---|
| 61 | ({ typeof(V) __v=(V); typeof(A) __a=(A); \
|
|---|
| 62 | __a*((__v+__a-1)/__a); })
|
|---|
| 63 |
|
|---|
| 64 | #define SET_BIT_FOR_OFFSET(mask, offset) \
|
|---|
| 65 | GC_set_bit(mask, offset / sizeof (void*))
|
|---|
| 66 |
|
|---|
| 67 | /* Some prototypes */
|
|---|
| 68 | static void
|
|---|
| 69 | __objc_gc_setup_struct (GC_bitmap mask, const char *type, int offset);
|
|---|
| 70 | static void
|
|---|
| 71 | __objc_gc_setup_union (GC_bitmap mask, const char *type, int offset);
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 | static void
|
|---|
| 75 | __objc_gc_setup_array (GC_bitmap mask, const char *type, int offset)
|
|---|
| 76 | {
|
|---|
| 77 | int i, len = atoi(type + 1);
|
|---|
| 78 |
|
|---|
| 79 | while (isdigit(*++type))
|
|---|
| 80 | /* do nothing */; /* skip the size of the array */
|
|---|
| 81 |
|
|---|
| 82 | switch (*type) {
|
|---|
| 83 | case _C_ARY_B:
|
|---|
| 84 | for (i = 0; i < len; i++)
|
|---|
| |
|---|