ObjFW  Diff

Differences From Artifact [22873e1cb7]:

To Artifact [f35aa9485e]:


118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154

155
156
157
158
159
160
161
162

163
164
165

166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190

191
192
193
194
195
196
197
198
199
200

201
202



203
204
205
206

207
208
209
210
211
212


213
214

215
216
217
218
219






220
221
222


223
224
225


226
227

228
229
230
231
232
233

234
235
236
237
238
239
240







241



242
243

244
245

246
247
248
249
250
251

252
253
254
255

256
257
258
259
260
261
262
263
264
118
119
120
121
122
123
124
























125
126
127
128
129

130
131
132
133
134




135



136

























137








138

139


140
141
142




143



144


145
146


147
148




149
150
151
152
153
154



155
156



157
158


159






160



161



162
163
164
165
166
167
168
169
170
171
172
173

174


175






176




177


178
179
180
181
182
183
184







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





-
+




-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-

-
+
-
-
+
+
+
-
-
-
-
+
-
-
-

-
-
+
+
-
-
+

-
-
-
-
+
+
+
+
+
+
-
-
-
+
+
-
-
-
+
+
-
-
+
-
-
-
-
-
-
+
-
-
-

-
-
-
+
+
+
+
+
+
+

+
+
+

-
+
-
-
+
-
-
-
-
-
-
+
-
-
-
-
+
-
-







@synthesize getter = _getter, setter = _setter, iVar = _iVar;

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

#if defined(OF_OBJFW_RUNTIME)
- (instancetype)of_initWithProperty: (struct objc_property *)property
{
	self = [super init];

	@try {
		_name = [[OFString alloc] initWithUTF8String: property->name];
		_attributes =
		    property->attributes | (property->extendedAttributes << 8);

		if (property->getter.name != NULL)
			_getter = [[OFString alloc]
			    initWithUTF8String: property->getter.name];
		if (property->setter.name != NULL)
			_setter = [[OFString alloc]
			    initWithUTF8String: property->setter.name];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
#elif defined(OF_APPLE_RUNTIME)
- (instancetype)of_initWithProperty: (objc_property_t)property
{
	self = [super init];

	@try {
		const char *attributes;
		char *value;

		_name = [[OFString alloc]
		    initWithUTF8String: property_getName(property)];

		if ((attributes = property_getAttributes(property)) == NULL)
			@throw [OFInitializationFailedException
			    exceptionWithClass: self.class];

		value = property_copyAttributeValue(property, "G");
		while (*attributes != '\0') {
			const char *start;

		if (value != NULL) {
			switch (*attributes) {
			case 'T':
				while (*attributes != ',' &&
				    *attributes != '\0')
					attributes++;
				break;
			case 'R':
				_attributes |= OF_PROPERTY_READONLY;
				attributes++;
				break;
			case 'C':
				_attributes |= OF_PROPERTY_COPY;
				attributes++;
				break;
			case '&':
				_attributes |= OF_PROPERTY_RETAIN;
				attributes++;
				break;
			case 'N':
				_attributes |= OF_PROPERTY_NONATOMIC;
				attributes++;
				break;
			case 'G':
				start = ++attributes;

			@try {
				if (_getter != nil)
					@throw [OFInitializationFailedException
					    exceptionWithClass: self.class];

				while (*attributes != ',' &&
				    *attributes != '\0')
					attributes++;

				_getter = [[OFString alloc]
				    initWithUTF8String: start
				    initWithUTF8String: value];
						length: attributes - start];

			} @finally {
				free(value);
			}
				break;
			case 'S':
				start = ++attributes;

		}
				if (_setter != nil)
					@throw [OFInitializationFailedException
					    exceptionWithClass: self.class];

				while (*attributes != ',' &&
				    *attributes != '\0')
		value = property_copyAttributeValue(property, "S");
		if (value != NULL) {
					attributes++;

			@try {
				_setter = [[OFString alloc]
				    initWithUTF8String: start
						length: attributes - start];

				break;
				    initWithUTF8String: value];
			} @finally {
				free(value);
			}
		}

			case 'D':
				_attributes |= OF_PROPERTY_DYNAMIC;
				attributes++;
#define BOOL_ATTRIBUTE(name, flag)					\
		value = property_copyAttributeValue(property, name);	\
				break;
			case 'W':
				_attributes |= OF_PROPERTY_WEAK;
		if (value != NULL) {					\
			_attributes |= flag;				\
				attributes++;
				break;
			free(value);					\
			case 'P':
				attributes++;
				break;
			case 'V':
				start = ++attributes;

		}
				if (_iVar != nil)
					@throw [OFInitializationFailedException
					    exceptionWithClass: self.class];

				while (*attributes != ',' &&
				    *attributes != '\0')
					attributes++;
		BOOL_ATTRIBUTE("R", OF_PROPERTY_READONLY)
		BOOL_ATTRIBUTE("C", OF_PROPERTY_COPY)
		BOOL_ATTRIBUTE("&", OF_PROPERTY_RETAIN)
		BOOL_ATTRIBUTE("N", OF_PROPERTY_NONATOMIC)
		BOOL_ATTRIBUTE("D", OF_PROPERTY_DYNAMIC)
		BOOL_ATTRIBUTE("W", OF_PROPERTY_WEAK)
#undef BOOL_ATTRIBUTE

		value = property_copyAttributeValue(property, "V");
		if (value != NULL) {
			@try {
				_iVar = [[OFString alloc]
				    initWithUTF8String: start
				    initWithUTF8String: value];
						length: attributes - start];

			} @finally {
				break;
			default:
				@throw [OFInitializationFailedException
				    exceptionWithClass: self.class];
			}

				free(value);
			if (*attributes != ',' && *attributes != '\0')
				@throw [OFInitializationFailedException
				    exceptionWithClass: self.class];

			}
			if (*attributes != '\0')
				attributes++;
		}

		if (!(_attributes & OF_PROPERTY_READONLY))
			_attributes |= OF_PROPERTY_READWRITE;

		if (!(_attributes & OF_PROPERTY_COPY) &&
		    !(_attributes & OF_PROPERTY_RETAIN))
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
207
208
209
210
211
212
213



214
215
216
217
218
219
220







-
-
-







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

	return self;
}
#else
# error Invalid ObjC runtime!
#endif

- (void)dealloc
{
	[_name release];
	[_getter release];
	[_setter release];

419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
336
337
338
339
340
341
342



343

344
345
346
347
348
349
350







-
-
-

-







- (instancetype)initWithClass: (Class)class
{
	self = [super init];

	@try {
		Method *methodList;
		Ivar *iVarList;
#if defined(OF_OBJFW_RUNTIME)
		struct objc_property_list *propertyList;
#elif defined(OF_APPLE_RUNTIME)
		objc_property_t *propertyList;
#endif
		unsigned count;
		void *pool;

		_classMethods = [[OFMutableArray alloc] init];
		_instanceMethods = [[OFMutableArray alloc] init];
		_properties = [[OFMutableArray alloc] init];
		_instanceVariables = [[OFMutableArray alloc] init];
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
388
389
390
391
392
393
394













395
396
397
398
399
400
401
402
403
404
405
406
407



408
409
410
411
412
413
414







-
-
-
-
-
-
-
-
-
-
-
-
-













-
-
-







				    of_initWithIVar: iVarList[i]] autorelease]];

			objc_autoreleasePoolPop(pool);
		} @finally {
			free(iVarList);
		}

#if defined(OF_OBJFW_RUNTIME)
		for (propertyList = class->properties; propertyList != NULL;
		    propertyList = propertyList->next) {
			pool = objc_autoreleasePoolPush();

			for (unsigned int i = 0; i < propertyList->count; i++)
				[_properties addObject: [[[OFProperty alloc]
				    of_initWithProperty:
				    &propertyList->properties[i]] autorelease]];

			objc_autoreleasePoolPop(pool);
		}
#elif defined(OF_APPLE_RUNTIME)
		propertyList = class_copyPropertyList(class, &count);
		@try {
			pool = objc_autoreleasePoolPush();

			for (unsigned int i = 0; i < count; i++)
				[_properties addObject: [[[OFProperty alloc]
				    of_initWithProperty: propertyList[i]]
				    autorelease]];

			objc_autoreleasePoolPop(pool);
		} @finally {
			free(propertyList);
		}
#else
# error Invalid ObjC runtime!
#endif

		[_classMethods makeImmutable];
		[_instanceMethods makeImmutable];
		[_properties makeImmutable];
		[_instanceVariables makeImmutable];
	} @catch (id e) {
		[self release];