Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 293 lines (256 sloc) 8.862 kB
9c1d230 committing experimental branch content
Laurent Sansonetti authored
1 /*
9595725 update copyrights to 2011
Laurent Sansonetti authored
2 * Copyright (c) 2008-2011, Apple Inc. All rights reserved.
9c1d230 committing experimental branch content
Laurent Sansonetti authored
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
13 * its contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef __BS_H_
30 #define __BS_H_
31
cb65416 the great schism, part I
Laurent Sansonetti authored
32 #if defined(__cplusplus)
33 extern "C" {
34 #endif
35
9c1d230 committing experimental branch content
Laurent Sansonetti authored
36 #include <CoreFoundation/CoreFoundation.h>
37 #include <objc/runtime.h>
38
112362a support for C-level blocks (note: this requires a not-yet-released Br…
Laurent Sansonetti authored
39 /* Extend objc/runtime.h and add function pointers and blocks tokens.
40 * A pointer to `void foo (int, char)' will be encoded as <^vic>.
41 * A `void (^)(int, char)' block will be encoded as <@vic>.
42 */
43
44 #define _MR_C_LAMBDA_B '<'
45 #define _MR_C_LAMBDA_FUNCPTR '^'
46 #define _MR_C_LAMBDA_BLOCK '@'
47 #define _MR_C_LAMBDA_E '>'
a8bf586 Add support for Proc as function pointers (BridgeSupport only)
Thibault Martin-Lagardette authored
48
9c1d230 committing experimental branch content
Laurent Sansonetti authored
49 /* Attribute and element representations.
50 * See BridgeSupport(5) for more information.
51 */
52
53 typedef enum {
54 BS_CARRAY_ARG_UNDEFINED = 0,
55 BS_CARRAY_ARG_LENGTH_IN_ARG,
56 BS_CARRAY_ARG_FIXED_LENGTH,
57 BS_CARRAY_ARG_VARIABLE_LENGTH,
58 BS_CARRAY_ARG_DELIMITED_BY_NULL
59 } bs_carray_arg_type_t;
60
61 typedef enum {
62 BS_TYPE_MODIFIER_UNDEFINED = 0,
63 BS_TYPE_MODIFIER_IN,
64 BS_TYPE_MODIFIER_OUT,
65 BS_TYPE_MODIFIER_INOUT
66 } bs_type_modifier_t;
67
68 typedef struct {
69 char *name;
70 char *type;
71 } bs_element_struct_field_t;
72
73 typedef struct {
74 char *name;
75 char *type;
76 bs_element_struct_field_t *fields;
77 unsigned fields_count;
78 bool opaque;
79 } bs_element_struct_t;
80
81 typedef struct {
82 char *name;
83 char *type;
84 char *tollfree;
85 CFTypeID type_id; /* 0 if unknown */
86 } bs_element_cftype_t;
87
88 typedef struct {
89 char *name;
90 char *type;
91 } bs_element_opaque_t;
92
93 typedef struct {
94 char *name;
95 char *type;
96 bool magic_cookie;
97 bool ignore;
98 char *suggestion;
99 } bs_element_constant_t;
100
101 typedef struct {
102 char *name;
103 char *value;
104 bool nsstring;
105 } bs_element_string_constant_t;
106
107 typedef struct {
108 char *name;
109 char *value;
110 bool ignore;
111 char *suggestion;
112 } bs_element_enum_t;
113
114 struct __bs_element_arg;
115 struct __bs_element_retval;
116 typedef struct __bs_element_arg bs_element_arg_t;
117 typedef struct __bs_element_retval bs_element_retval_t;
118
119 typedef struct {
120 bs_element_arg_t *args;
121 unsigned args_count;
122 bs_element_retval_t *retval;
123 } bs_element_function_pointer_t;
124
125 struct __bs_element_arg {
126 int index; /* if -1, not used */
127 char *type;
128 bs_type_modifier_t type_modifier;
129 bs_carray_arg_type_t carray_type;
130 bs_element_function_pointer_t *function_pointer; /* can be NULL */
131 int carray_type_value;
132 bool null_accepted;
133 bool printf_format;
134 char *sel_of_type;
135 };
136
137 struct __bs_element_retval {
138 char *type;
139 bs_carray_arg_type_t carray_type;
140 bs_element_function_pointer_t *function_pointer; /* can be NULL */
141 int carray_type_value;
142 bool already_retained;
143 };
144
145 typedef struct {
146 char *name;
147 bs_element_arg_t *args;
148 unsigned args_count;
149 bs_element_retval_t *retval;
150 bool variadic;
151 } bs_element_function_t;
152
153 typedef struct {
154 char *name;
155 char *original;
156 } bs_element_function_alias_t;
157
158 typedef struct {
159 SEL name;
160 bs_element_arg_t *args;
161 unsigned args_count;
162 bs_element_retval_t *retval;
163 bool class_method;
164 bool variadic;
165 bool ignore;
166 char *suggestion;
167 } bs_element_method_t;
168
169 typedef struct {
170 char *name;
171 bs_element_method_t *class_methods;
172 unsigned class_methods_count;
173 bs_element_method_t *instance_methods;
174 unsigned instance_methods_count;
175 } bs_element_class_t;
176
177 typedef struct {
178 SEL name;
179 char *type;
180 char *protocol_name;
181 bool class_method;
182 } bs_element_informal_protocol_method_t;
183
184 typedef enum {
185 BS_ELEMENT_STRUCT, /* bs_element_struct_t */
186 BS_ELEMENT_CFTYPE, /* bs_element_cftype_t */
187 BS_ELEMENT_OPAQUE, /* bs_element_opaque_t */
188 BS_ELEMENT_CONSTANT, /* bs_element_constant_t */
189 BS_ELEMENT_STRING_CONSTANT, /* bs_element_string_constant_t */
190 BS_ELEMENT_ENUM, /* bs_element_enum_t */
191 BS_ELEMENT_FUNCTION, /* bs_element_function_t */
192 BS_ELEMENT_FUNCTION_ALIAS, /* bs_element_function_alias_t */
193 BS_ELEMENT_CLASS, /* bs_element_class_t */
194 BS_ELEMENT_INFORMAL_PROTOCOL_METHOD
195 /* bs_element_informal_protocol_method_t */
196 } bs_element_type_t;
197
198 /* bs_find_path()
199 *
200 * Finds the path of a framework's bridge support file, by looking at the
201 * following locations, in order of priority:
202 * - inside the main executable bundle (if any), in the Resources/BridgeSupport directory ;
203 * - inside the framework bundle, in the Resources/BridgeSupport directory ;
204 * - in ~/Library/BridgeSupport ;
205 * - in /Library/BridgeSupport ;
206 * - in /System/Library/BridgeSupport.
207 * Returns true on success, false otherwise.
208 *
209 * framework_path: the full path of the framework.
210 * path: a pointer to a pre-allocated string that will contain the bridge
211 * support path on success.
212 * path_len: the size of the path argument.
213 */
214 bool bs_find_path(const char *framework_path, char *path, const size_t path_len);
215
216 /* bs_parser_new()
217 *
218 * Creates and returns a parser object, required for bs_parser_parse().
219 * Use bs_parser_free() when you're done.
220 */
221 typedef struct _bs_parser bs_parser_t;
222 bs_parser_t *bs_parser_new(void);
223
224 /* bs_parser_free()
225 *
226 * Frees a previously-created parser object.
227 */
228 void bs_parser_free(bs_parser_t *parser);
229
230 typedef void (*bs_parse_callback_t)
231 (bs_parser_t *parser, const char *path, bs_element_type_t type, void *value,
232 void *context);
233
234 typedef enum {
235 /* Default option: parse bridge support files. */
236 BS_PARSE_OPTIONS_DEFAULT = 0,
237 /* Parse bridge support files and dlopen(3) the dylib files, if any. */
238 BS_PARSE_OPTIONS_LOAD_DYLIBS
239 } bs_parse_options_t;
240
241 /* bs_parse()
242 *
243 * Parses a given bridge support file, calling back a given function pointer
244 * for every parsed element. You are responsible to free every element passed
245 * to the callback function, using bs_element_free().
246 * Returns true on success, otherwise false.
247 *
248 * parser: the parser object.
249 * path: the full path of the bridge support file to parse.
250 * framework_path: the full path of the framework this bridge support file
251 * comes from. This is only required if options is BS_PARSE_OPTIONS_LOAD_DYLIBS
252 * in order to locate the dylib files. Pass NULL if you are passing the
253 * default BS_PARSE_OPTIONS_DEFAULT option.
254 * options: parsing options.
255 * callback: a callback function pointer.
256 * context: a contextual data pointer that will be passed to the callback
257 * function.
258 * error: in case this function returns false, this variable is set to a newly
259 * allocated error message. You are responsible to free it. Pass NULL if you
260 * don't need it.
261 */
262 bool bs_parser_parse(bs_parser_t *parser, const char *path,
263 const char *framework_path, bs_parse_options_t options,
264 bs_parse_callback_t callback, void *context, char **error);
265
eedc8a3 determine if we are using old (before the previews) BridgeSupport fil…
Laurent Sansonetti authored
266 /* bs_parser_current_version_number()
267 *
268 * Returns the BridgeSupport version number of the current parsed
269 * file, as an integer value, or 0 in case the parsed file does not contain
270 * a version number.
271 */
272 unsigned int bs_parser_current_version_number(bs_parser_t *parser);
273
274 #define BS_VERSION_UNKNOWN 0
275 #define BS_VERSION_0_9 9 // Leopard or above
276 #define BS_VERSION_1_0 10 // Preview 1-3
277
9c1d230 committing experimental branch content
Laurent Sansonetti authored
278 /* bs_element_free()
279 *
280 * Frees a bridge support element that was returned by bs_parse() through the
281 * callback method.
282 *
283 * type: the type of the bridge support element.
284 * value: a pointer to the bridge support element.
285 */
286 void bs_element_free(bs_element_type_t type, void *value);
287
cb65416 the great schism, part I
Laurent Sansonetti authored
288 #if defined(__cplusplus)
289 }
290 #endif
291
9c1d230 committing experimental branch content
Laurent Sansonetti authored
292 #endif /* __BS_H_ */
Something went wrong with that request. Please try again.