~ubuntu-branches/ubuntu/edgy/sope/edgy

« back to all changes in this revision

Viewing changes to libFoundation/config/generic/generic.h

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Ley
  • Date: 2005-08-19 16:53:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050819165331-hs683wz1osm708pw
Tags: upstream-4.4rc.2
ImportĀ upstreamĀ versionĀ 4.4rc.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   generic.h
 
3
 
 
4
   Copyright (C) 1995, 1996, 1997 Ovidiu Predescu and Mircea Oancea.
 
5
   All rights reserved.
 
6
 
 
7
   Author: Ovidiu Predescu <ovidiu@net-community.com>
 
8
   Date: May 1997
 
9
 
 
10
   This file is part of libFoundation.
 
11
 
 
12
   Permission to use, copy, modify, and distribute this software and its
 
13
   documentation for any purpose and without fee is hereby granted, provided
 
14
   that the above copyright notice appear in all copies and that both that
 
15
   copyright notice and this permission notice appear in supporting
 
16
   documentation.
 
17
 
 
18
   We disclaim all warranties with regard to this software, including all
 
19
   implied warranties of merchantability and fitness, in no event shall
 
20
   we be liable for any special, indirect or consequential damages or any
 
21
   damages whatsoever resulting from loss of use, data or profits, whether in
 
22
   an action of contract, negligence or other tortious action, arising out of
 
23
   or in connection with the use or performance of this software.
 
24
*/
 
25
 
 
26
#ifndef __generic_h__
 
27
#define __generic_h__
 
28
 
 
29
#ifndef OBJC_FORWARDING_STACK_OFFSET
 
30
#define OBJC_FORWARDING_STACK_OFFSET    0
 
31
#endif
 
32
 
 
33
#ifndef OBJC_FORWARDING_MIN_OFFSET
 
34
#define OBJC_FORWARDING_MIN_OFFSET 0
 
35
#endif
 
36
 
 
37
/* Define the size of the block returned by __builtin_apply_args. This value is
 
38
   computed by the function in expr.c. The block contains in order: a pointer
 
39
   to the stack arguments frame, the structure value address unless this is
 
40
   passed as an "invisible" first argument and all registers that may be used
 
41
   in calling a function. */
 
42
 
 
43
#define APPLY_ARGS_SIZE 8
 
44
 
 
45
/* Define the size of the result block returned by the __builtin_apply. This
 
46
   block contains all registers that could be used to return the function
 
47
   value. This value is computed by apply_result_size function in expr.c. There
 
48
   are also machines where this value is predefined in the machine description
 
49
   file, so that machine specific information can be stored. */
 
50
 
 
51
#define APPLY_RESULT_SIZE       8
 
52
 
 
53
/* Define how to find the value returned by a function. TYPE is a Objective-C
 
54
   encoding string describing the type of the returned value. ARGS is the
 
55
   arguments frame passed to __builtin_apply. RESULT_FRAME is the address of
 
56
   the block returned by __builtin_apply. RETURN_VALUE is an address where
 
57
   this macro should put the returned value. */
 
58
 
 
59
#define FUNCTION_VALUE(TYPE, ARGS, RESULT_FRAME, RETURN_VALUE) \
 
60
    ({  int type_size = objc_sizeof_type(TYPE); \
 
61
        memcpy((RETURN_VALUE), (RESULT_FRAME), type_size); })
 
62
 
 
63
/* Set the value in RETURN_VALUE to be the value returned by a function.
 
64
   Assume that the fucntion was previously called and RESULT_FRAME is the
 
65
   address of the block returned by __builtin_apply. TYPE is the actual
 
66
   type of this value. ARGS is the address of block that was passed
 
67
   to __builtin_apply. */
 
68
 
 
69
#define FUNCTION_SET_VALUE(TYPE, ARGS, RESULT_FRAME, RETURN_VALUE) \
 
70
    ({  int type_size = objc_sizeof_type(TYPE); \
 
71
        memcpy((RESULT_FRAME), (RETURN_VALUE), type_size); })
 
72
 
 
73
/* If the RETTYPE is a structure and the address of the structure value is
 
74
   passed to the called function, then obtain from ARGS its address. In general
 
75
   this address is the second pointer into the arguments frame. This macro
 
76
   should produce 0 if the RETTYPE doesn't match the conditions above. */
 
77
 
 
78
#define GET_STRUCT_VALUE_ADDRESS(ARGS, RETTYPE) \
 
79
    ((*(RETTYPE) == _C_STRUCT_B || *(RETTYPE) == _C_UNION_B \
 
80
            || *(RETTYPE) == _C_ARY_B) ? \
 
81
          *(void**)(((char*)(ARGS)) + sizeof(void*)) \
 
82
        : 0)
 
83
 
 
84
/* Prepare ARGS for calling the function. If the function returns a struct by
 
85
   value, it's the caller responsability to pass to the called function the
 
86
   address of where to store the structure value. */
 
87
 
 
88
#define SET_STRUCT_VALUE_ADDRESS(ARGS, ADDR, RETTYPE) \
 
89
    *(void**)(((char*)(ARGS)) + sizeof(void*)) = (ADDR)
 
90
 
 
91
 
 
92
/* The following macros are used to determine the encoding of a selector given
 
93
   the types of arguments. This macros follows the similar ones defined in the
 
94
   target machine description from the compiler sources. */
 
95
 
 
96
/* Define a data type for recording info about the arguments list of a method.
 
97
   A variable of this type is further used by FUNCTION_ARG_ENCODING to
 
98
   determine the encoding of an argument. This type should record all info
 
99
   about arguments processed so far. */
 
100
 
 
101
#define CUMULATIVE_ARGS int
 
102
 
 
103
/* Initialize a variable of type CUMULATIVE_ARGS. This macro is called before
 
104
   processing the first argument of a method. */
 
105
 
 
106
#define INIT_CUMULATIVE_ARGS(CUM)       ((CUM) = 0)
 
107
 
 
108
/* This macro determines the encoding of the next argument of a method. It is
 
109
   called repetitively, starting with the first argument and continuing to the
 
110
   last one. CUM is a variable of type CUMULATIVE_ARGS. TYPE is a NSString
 
111
   which represents the type of the argument processed. This macro must
 
112
   produce a NSString whose value represents the encoding and position of the
 
113
   current argument. STACKSIZE is a variable that counts the number of bytes
 
114
   occupied by the arguments on the stack. */
 
115
 
 
116
#ifndef ROUND
 
117
#define ROUND(V, A) \
 
118
  ({ typeof(V) __v=(V); typeof(A) __a=(A); \
 
119
     __a*((__v+__a-1)/__a); })
 
120
#endif
 
121
 
 
122
#define FUNCTION_ARG_ENCODING(CUM, TYPE, STACK_ARGSIZE) \
 
123
    ({  id encoding; \
 
124
        const char* type = [(TYPE) cString]; \
 
125
        int align = objc_alignof_type(type); \
 
126
        int type_size = objc_sizeof_type(type); \
 
127
\
 
128
        (CUM) = ROUND((CUM), align); \
 
129
        encoding = [NSString stringWithFormat:@"%@%d", \
 
130
                                    (TYPE), \
 
131
                                    (CUM) + OBJC_FORWARDING_STACK_OFFSET]; \
 
132
        (STACK_ARGSIZE) = (CUM) + type_size; \
 
133
        (CUM) += ROUND(type_size, sizeof(void*)); \
 
134
        encoding; })
 
135
 
 
136
#endif /* __generic_h__ */
 
137
 
 
138
/*
 
139
  Local Variables:
 
140
  c-basic-offset: 4
 
141
  tab-width: 8
 
142
  End:
 
143
*/