ObjFW  Check-in [82b9b5f7c8]

Overview
Comment:Add ivar introspection for the ObjFW runtime.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 82b9b5f7c820ce8f894bf5b4f3a59f3bac9cf92f8bca296eab2cbab5b7ea1887
User & Date: js on 2012-07-17 23:59:52
Other Links: manifest | tags
Context
2012-07-18
00:16
Always compile autorelease.m if necessary. check-in: 85cbeeeb04 user: js tags: trunk
2012-07-17
23:59
Add ivar introspection for the ObjFW runtime. check-in: 82b9b5f7c8 user: js tags: trunk
19:44
Export structs for ivar introspection. check-in: 7cab5285df user: js tags: trunk
Changes

Modified src/OFIntrospection.h from [b0660012c7] to [b254a0ceb9].

60
61
62
63
64
65
66
67
68

69
70
71
72
73
74
75

/**
 * \brief A class for describing an instance variable.
 */
@interface OFInstanceVariable: OFObject
{
	OFString *name;
	ptrdiff_t offset;
	const char *typeEncoding;

}

#ifdef OF_HAVE_PROPERTIES
@property (readonly, copy) OFString *name;
@property (readonly) ptrdiff_t offset;
@property (readonly) const char *typeEncoding;
#endif







<

>







60
61
62
63
64
65
66

67
68
69
70
71
72
73
74
75

/**
 * \brief A class for describing an instance variable.
 */
@interface OFInstanceVariable: OFObject
{
	OFString *name;

	const char *typeEncoding;
	ptrdiff_t offset;
}

#ifdef OF_HAVE_PROPERTIES
@property (readonly, copy) OFString *name;
@property (readonly) ptrdiff_t offset;
@property (readonly) const char *typeEncoding;
#endif

Modified src/OFIntrospection.m from [495179aec4] to [fd9ea3d6be].

94
95
96
97
98
99
100


















101
102
103
104
105
106
107
108
109
110
111

112
113
114
115
116
117
118
{
	return [OFString stringWithFormat: @"<OFMethod: %@ [%s]>",
					   name, typeEncoding];
}
@end

@implementation OFInstanceVariable


















#if defined(OF_APPLE_RUNTIME)
- _initWithIvar: (Ivar)ivar
{
	self = [super init];

	@try {
		name = [[OFString alloc]
		    initWithCString: ivar_getName(ivar)
			   encoding: OF_STRING_ENCODING_ASCII];
		offset = ivar_getOffset(ivar);
		typeEncoding = ivar_getTypeEncoding(ivar);

	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|








<

>







94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

128
129
130
131
132
133
134
135
136
{
	return [OFString stringWithFormat: @"<OFMethod: %@ [%s]>",
					   name, typeEncoding];
}
@end

@implementation OFInstanceVariable
#if defined(OF_OBJFW_RUNTIME)
- _initWithIvar: (struct objc_ivar*)ivar
{
	self = [super init];

	@try {
		name = [[OFString alloc]
		    initWithCString: ivar->name
			   encoding: OF_STRING_ENCODING_ASCII];
		typeEncoding = ivar->type;
		offset = ivar->offset;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
#elif defined(OF_APPLE_RUNTIME)
- _initWithIvar: (Ivar)ivar
{
	self = [super init];

	@try {
		name = [[OFString alloc]
		    initWithCString: ivar_getName(ivar)
			   encoding: OF_STRING_ENCODING_ASCII];

		typeEncoding = ivar_getTypeEncoding(ivar);
		offset = ivar_getOffset(ivar);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
242
243
244
245
246
247
248














249
250
251
252
253
254
255
256
				    _initWithMethod: &methodList->methods[i]];
				[instanceMethods addObject:
				    [method autorelease]];
				[pool releaseObjects];
			}
		}















		/* TODO: ivars and properties */
#elif defined(OF_APPLE_RUNTIME)
		methodList = class_copyMethodList(object_getClass(class),
		    &count);
		@try {
			for (i = 0; i < count; i++) {
				[classMethods addObject: [[[OFMethod alloc]
				    _initWithMethod: methodList[i]]







>
>
>
>
>
>
>
>
>
>
>
>
>
>
|







260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
				    _initWithMethod: &methodList->methods[i]];
				[instanceMethods addObject:
				    [method autorelease]];
				[pool releaseObjects];
			}
		}

		if (class->ivars != NULL) {
			unsigned i;

			for (i = 0; i < class->ivars->count; i++) {
				OFInstanceVariable *ivar;

				ivar = [[OFInstanceVariable alloc]
				    _initWithIvar: &class->ivars->ivars[i]];
				[instanceVariables addObject:
				    [ivar autorelease]];
				[pool releaseObjects];
			}
		}

		/* TODO: properties */
#elif defined(OF_APPLE_RUNTIME)
		methodList = class_copyMethodList(object_getClass(class),
		    &count);
		@try {
			for (i = 0; i < count; i++) {
				[classMethods addObject: [[[OFMethod alloc]
				    _initWithMethod: methodList[i]]