1/* 2 * Copyright (c) 2006-2008, The RubyCocoa Project. 3 * Copyright (c) 2001-2006, FUJIMOTO Hisakuni. 4 * All Rights Reserved. 5 * 6 * RubyCocoa is free software, covered under either the Ruby's license or the 7 * LGPL. See the COPYRIGHT file for more information. 8 */ 9 10#import "libffi.h" 11 12typedef enum { 13 bsTypeModifierIn, 14 bsTypeModifierOut, 15 bsTypeModifierInout 16} bsTypeModifier; 17 18typedef enum { 19 bsCArrayArgUndefined, 20 bsCArrayArgDelimitedByArg, 21 bsCArrayArgFixedLength, 22 bsCArrayArgVariableLength, 23 bsCArrayArgDelimitedByNull 24} bsCArrayArgType; 25 26#define MAX_ARGS 128 27 28struct bsArg { 29 unsigned index; 30 bsTypeModifier type_modifier; 31 bsCArrayArgType c_ary_type; 32 int c_ary_type_value; // not set if arg_type is bsCArrayArgUndefined 33 BOOL null_accepted; 34 char * octypestr; 35 char * sel_of_type; 36 BOOL printf_format; 37}; 38 39struct bsRetval { 40 bsCArrayArgType c_ary_type; 41 int c_ary_type_value; // not set if arg_type is bsCArrayArgUndefined 42 char * octypestr; 43 BOOL should_be_retained; 44}; 45 46struct bsCallEntry { 47 int argc; 48 struct bsArg * argv; 49 struct bsRetval * retval; 50 BOOL is_variadic; 51}; 52 53struct bsFunction { 54 int argc; 55 struct bsArg * argv; 56 struct bsRetval * retval; 57 BOOL is_variadic; 58 char * name; 59 void * sym; 60}; 61 62struct bsClass { 63 char * name; 64 struct st_table * class_methods; 65 struct st_table * instance_methods; 66}; 67 68struct bsMethod { 69 int argc; 70 struct bsArg * argv; 71 struct bsRetval * retval; // can be NULL 72 BOOL is_variadic; 73 char * selector; 74 BOOL is_class_method; 75 BOOL ignore; 76 char * suggestion; // only if ignore is true 77}; 78 79struct bsInformalProtocolMethod { 80 char * selector; 81 BOOL is_class_method; 82 char * encoding; 83 char * protocol_name; 84}; 85 86#define BS_BOXED_OCTYPE_THRESHOLD 1300 87 88struct bsStructField { 89 char * name; 90 char * encoding; 91}; 92 93struct bsStruct { 94 struct bsStructField *fields; 95 int field_count; 96 BOOL opaque; 97}; 98 99struct bsOpaque { 100 // Nothing there yet. 101}; 102 103typedef enum { 104 bsBoxedStructType, 105 bsBoxedOpaqueType 106} bsBoxedType; 107 108struct bsBoxed { 109 bsBoxedType type; 110 char * name; 111 char * encoding; 112 size_t size; 113 ffi_type * ffi_type; 114 VALUE klass; 115 union { 116 struct bsStruct s; 117 struct bsOpaque o; 118 } opt; 119}; 120 121struct bsCFType { 122 char * name; 123 char * encoding; 124 char * bridged_class_name; 125 CFTypeID type_id; 126}; 127 128struct bsConst { 129 char * name; 130 char * encoding; 131 BOOL is_magic_cookie; 132 char * class_name; // set lazily, and only for magic cookies 133 BOOL ignored; 134 char * suggestion; 135}; 136 137extern struct bsFunction *current_function; 138 139VALUE objboxed_s_class(void); 140struct bsBoxed *find_bs_boxed_by_encoding(const char *encoding); 141struct bsBoxed *find_bs_boxed_for_klass (VALUE klass); 142VALUE rb_bs_boxed_new_from_ocdata(struct bsBoxed *bs_boxed, void *ocdata); 143VALUE rb_bs_boxed_ptr_new_from_ocdata(struct bsBoxed *bs_boxed, void *ocdata); 144void *rb_bs_boxed_get_data(VALUE obj, const char *encoding, size_t *size, BOOL *success, BOOL clean_ivars); 145size_t bs_boxed_size(struct bsBoxed *bs_struct); 146 147struct bsCFType *find_bs_cf_type_by_encoding(const char *encoding); 148struct bsCFType *find_bs_cf_type_by_type_id(CFTypeID type_id); 149 150struct bsMethod *find_bs_method(id klass, const char *selector, BOOL is_class_method); 151struct bsArg *find_bs_arg_by_index(struct bsCallEntry *entry, unsigned index, unsigned argc); 152struct bsArg *find_bs_arg_by_c_array_len_arg_index(struct bsCallEntry *entry, unsigned index); 153 154void register_bs_informal_protocol_method(struct bsInformalProtocolMethod *method); 155struct bsInformalProtocolMethod *find_bs_informal_protocol_method(const char *selector, BOOL is_class_method); 156 157struct bsConst *find_magic_cookie_const_by_value(void *value); 158 159void initialize_bridge_support(VALUE mOSX); 160