ObjFW  Check-in [41bf4fe57b]

Overview
Comment:objfw-new: Add support for property attributes
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 41bf4fe57b0dc41180e47d617ddee7fc3ce78d521e50dd3596b0c4f819716ae6
User & Date: js on 2022-08-08 18:53:55
Other Links: manifest | tags
Context
2022-08-08
19:00
objfw-new: Automatically generate dealloc check-in: 8465dcaa25 user: js tags: trunk
18:53
objfw-new: Add support for property attributes check-in: 41bf4fe57b user: js tags: trunk
2022-08-07
23:49
objfw-new: Add initial support for properties check-in: 759d73547f user: js tags: trunk
Changes

Modified utils/objfw-new/NewClass.m from [7272551759] to [4b98e4d222].

68
69
70
71
72
73
74
75
76



























77

78
79
80
81
82
83
84
68
69
70
71
72
73
74


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110







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

+







	for (Property *property in properties)
		[headerFile writeFormat: @"\t%@_%@;\n",
					 property.type, property.name];

	if (properties.count > 0)
		[headerFile writeString: @"}\n\n"];

	for (Property *property in properties)
		[headerFile writeFormat: @"@property %@%@;\n",
	for (Property *property in properties) {
		[headerFile writeString: @"@property "];

		if (property.attributes.count > 0) {
			bool first = true;

			if ([property.attributes containsObject: @"nullable"])
				[headerFile writeString:
				    @"OF_NULLABLE_PROPERTY "];

			[headerFile writeString: @"("];

			for (OFString *attribute in property.attributes) {
				if ([attribute isEqual: @"nullable"])
					continue;

				if (!first)
					[headerFile writeString: @", "];

				[headerFile writeString: attribute];
				first = false;
			}

			[headerFile writeString: @") "];
		}

		[headerFile writeFormat: @"%@_%@;\n",
					 property.type, property.name];
	}

	[headerFile writeString: @"@end\n"
				 @"\n"
				 @"OF_ASSUME_NONNULL_END\n"];

	[implFile writeFormat: @"#import \"%@\"\n"
			       @"\n"

Modified utils/objfw-new/Property.h from [e95ce45cc0] to [e9facd5dfc].

17
18
19
20
21
22
23

24
25
26
27
28
29
30

31
32
33
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35







+







+



#import "OFString.h"

OF_ASSUME_NONNULL_BEGIN

@interface Property: OFObject
{
	OFString *_name, *_type;
	OFArray OF_GENERIC(OFString *) *_attributes;
}

+ (instancetype)propertyWithString: (OFString *)string;
- (instancetype)initWithString: (OFString *)string;

@property (readonly, nonatomic) OFString *name;
@property (readonly, nonatomic) OFString *type;
@property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *attributes;
@end

OF_ASSUME_NONNULL_END

Modified utils/objfw-new/Property.m from [25213351ae] to [b0b533e64d].

13
14
15
16
17
18
19



20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38







+
+
+








-
+







 * file.
 */

#include "config.h"

#import "Property.h"

#import "OFArray.h"
#import "OFString.h"

#import "OFInvalidArgumentException.h"
#import "OFOutOfRangeException.h"

@interface Property ()
- (void)parseString: (OFString *)string;
@end

@implementation Property
@synthesize name = _name, type = _type;
@synthesize name = _name, type = _type, attributes = _attributes;

+ (instancetype)propertyWithString: (OFString *)string
{
	return [[[self alloc] initWithString: string] autorelease];
}

- (instancetype)initWithString: (OFString *)string
44
45
46
47
48
49
50

51
52

53
54
55
56







































57
58
59
60
61
62
63
64
65
66
67
68
69
70


71
72
73
74
75
76
77
78
79
80
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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







+


+




+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+














+
+










	}

	return self;
}

- (void)parseString: (OFString *)string
{
	void *pool = objc_autoreleasePoolPush();
	const char *UTF8String = string.UTF8String;
	size_t length = string.UTF8StringLength, nameIdx = -1;
	OFMutableArray *attributes = nil;

	if (length > SSIZE_MAX)
		@throw [OFOutOfRangeException exception];

	if (UTF8String[0] == '(') {
		for (size_t i = 0, level = 0; i < length; i++) {
			if (UTF8String[i] == '(')
				level++;
			else if (UTF8String[i] == ')') {
				if (--level == 0) {
					OFString *attributesString = [OFString
					    stringWithUTF8String: UTF8String + 1
							  length: i - 1];
					attributes = [[[attributesString
					    componentsSeparatedByString: @","]
					    mutableCopy] autorelease];

					UTF8String += i + 1;
					length += i + 1;

					while (*UTF8String == ' ' ||
					    *UTF8String == '\t') {
						UTF8String++;
						length--;
					}

					break;
				}
			}
		}
	}

	for (size_t i = 0; i < attributes.count; i++) {
		OFString *attribute = [[attributes objectAtIndex: i]
		    stringByDeletingEnclosingWhitespaces];

		[attributes replaceObjectAtIndex: i
				      withObject: attribute];
	}

	[attributes makeImmutable];
	_attributes = [attributes copy];

	for (ssize_t i = (ssize_t)length - 1; i > 0; i--) {
		if (UTF8String[i] == '*' || UTF8String[i] == ' ' ||
		    UTF8String[i] == '\t') {
			nameIdx = i + 1;
			break;
		}
	}

	if (nameIdx < 0)
		@throw [OFInvalidArgumentException exception];

	_name = [[OFString alloc] initWithUTF8String: UTF8String + nameIdx];
	_type = [[OFString alloc] initWithUTF8String: UTF8String
					      length: (size_t)nameIdx];

	objc_autoreleasePoolPop(pool);
}

- (void)dealloc
{
	[_name release];
	[_type release];

	[super dealloc];
}
@end