ObjFW  Diff

Differences From Artifact [061b43fb0e]:

To Artifact [afc6aa5a2f]:

  • File src/OFIntrospection.h — part of check-in [48980f2297] at 2015-11-29 11:43:05 on branch trunk — Make properties a requirement and clean up code

    This increases the required GCC version from 4.0 to 4.6 (exception:
    Apple GCC, which already supports this with >= 4.0 starting with OS X
    10.5). Since even GCC 4.6 is really old by now, there is no point in
    still supporting something even older and making the code ugly because
    of that. While some hardware and OS support was dropped from GCC 4.6
    compared to GCC 4.0, there is nothing in there that would be an
    interesting target with the exception of BeOS maybe - but a port to BeOS
    can also be achieved using the Haiku support. The other dropped OSes are
    mostly old versions of OSes while newer ones are still being supported
    (and those newer versions of those OSes still support the same
    hardware). (user: js, size: 5652) [annotate] [blame] [check-ins using]


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
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
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
265
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



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






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







-
-
-
-
-
-

-
-
-
+

-
+


-
-
-
+

-
+


-
-
-
+

-
+














-
-
-
-
-
-

-
-
-
+

-
+


-
+














-
-

-
+


-
-
-
+

-
+


-
-
-
+

-
+














-
-
-
-
-
-

-
-
-
+

-
+


-
-
-
+

-
+


-
-
-
+

-
+















-
-
-
-
-
-
-
-

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

-
+


-
+
-
-

-
+


-
+

















-
-
+
+
+
+
+

+
-
+

+
+

-
+

-
+

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



@interface OFMethod: OFObject
{
	SEL _selector;
	OFString *_name;
	const char *_typeEncoding;
}

#ifdef OF_HAVE_PROPERTIES
@property (readonly) SEL selector;
@property (readonly, copy) OFString *name;
@property OF_NULLABLE_PROPERTY (assign, readonly) const char *typeEncoding;
#endif

/*!
 * @brief Returns the selector of the method.
 *
 * @return The selector of the method
 * The selector of the method.
 */
- (SEL)selector;
@property (readonly) SEL selector;

/*!
 * @brief Returns the name of the method.
 *
 * @return The name of the method
 * The name of the method.
 */
- (OFString*)name;
@property (readonly, copy) OFString *name;

/*!
 * @brief Returns the type encoding for the method.
 *
 * @return The type encoding for the method
 * The type encoding for the method.
 */
- (nullable const char*)typeEncoding;
@property OF_NULLABLE_PROPERTY (readonly) const char *typeEncoding;
@end

/*!
 * @class OFProperty OFIntrospection.h ObjFW/OFIntrospection.h
 *
 * @brief A class for describing a property.
 */
@interface OFProperty: OFObject
{
	OFString *_name;
	unsigned _attributes;
	OFString *_getter, *_setter;
}

#ifdef OF_HAVE_PROPERTIES
@property (readonly, copy) OFString *name;
@property (readonly) unsigned attributes;
@property OF_NULLABLE_PROPERTY (copy, readonly) OFString *getter, *setter;
#endif

/*!
 * @brief Returns the name of the property.
 *
 * @return The name of the property
 * The name of the property.
 */
- (OFString*)name;
@property (readonly, copy) OFString *name;

/*!
 * @brief Returns the attributes of the property.
 * The attributes of the property.
 *
 * The attributes are a bitmask with the following possible flags:@n
 * Flag                          | Description
 * ------------------------------|-------------------------------------
 * OF_PROPERTY_READONLY          | The property is declared `readonly`
 * OF_PROPERTY_READWRITE         | The property is declared `readwrite`
 * OF_PROPERTY_ASSIGN            | The property is declared `assign`
 * OF_PROPERTY_RETAIN            | The property is declared `retain`
 * OF_PROPERTY_COPY              | The property is declared `copy`
 * OF_PROPERTY_NONATOMIC         | The property is declared `nonatomic`
 * OF_PROPERTY_ATOMIC            | The property is declared `atomic`
 * OF_PROPERTY_WEAK              | The property is declared `weak`
 * OF_PROPERTY_SYNTHESIZED       | The property is synthesized
 * OF_PROPERTY_DYNAMIC           | The property is dynamic
 *
 * @return The attributes of the property
 */
- (unsigned)attributes;
@property (readonly) unsigned attributes;

/*!
 * @brief Returns the name of the getter.
 *
 * @return The name of the getter
 * The name of the getter.
 */
- (nullable OFString*)getter;
@property OF_NULLABLE_PROPERTY (readonly, copy) OFString *getter;

/*!
 * @brief Returns the name of the setter.
 *
 * @return The name of the setter
 * @return The name of the setter.
 */
- (nullable OFString*)setter;
@property OF_NULLABLE_PROPERTY (readonly, copy) OFString *setter;
@end

/*!
 * @class OFInstanceVariable OFIntrospection.h ObjFW/OFIntrospection.h
 *
 * @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 OF_NULLABLE_PROPERTY (assign, readonly) const char *typeEncoding;
#endif

/*!
 * @brief Returns the name of the instance variable.
 *
 * @return The name of the instance variable
 * The name of the instance variable.
 */
- (OFString*)name;
@property (readonly, copy) OFString *name;

/*!
 * @brief Returns the offset of the instance variable.
 *
 * @return The offset of the instance variable
 * The offset of the instance variable.
 */
- (ptrdiff_t)offset;
@property (readonly) ptrdiff_t offset;

/*!
 * @brief Returns the type encoding for the instance variable.
 *
 * @return The type encoding for the instance variable
 * The type encoding for the instance variable.
 */
- (nullable const char*)typeEncoding;
@property OF_NULLABLE_PROPERTY (readonly) const char *typeEncoding;
@end

/*!
 * @class OFIntrospection OFIntrospection.h ObjFW/OFIntrospection.h
 *
 * @brief A class for introspecting classes.
 */
@interface OFIntrospection: OFObject
{
	OFMutableArray OF_GENERIC(OFMethod*) *_classMethods;
	OFMutableArray OF_GENERIC(OFMethod*) *_instanceMethods;
	OFMutableArray OF_GENERIC(OFProperty*) *_properties;
	OFMutableArray OF_GENERIC(OFInstanceVariable*) *_instanceVariables;
}

#ifdef OF_HAVE_PROPERTIES
@property (readonly, copy) OFArray OF_GENERIC(OFMethod*) *classMethods;
@property (readonly, copy) OFArray OF_GENERIC(OFMethod*) *instanceMethods;
@property (readonly, copy) OFArray OF_GENERIC(OFProperty*) *properties;
@property (readonly, copy)
    OFArray OF_GENERIC(OFInstanceVariable*) *instanceVariables;
#endif

/*!
 * @brief Creates a new introspection for the specified class.
 *
 * @return A new, autoreleased introspection for the specified class
 */
+ (instancetype)introspectionWithClass: (Class)class_;

/*!
 * @brief Initializes an already allocated OFIntrospection with the specified
 *	  class.
 *
 * @return An initialized OFIntrospection
 */
- initWithClass: (Class)class_;

/*!
 * @brief Returns the class methods of the class.
 * The class methods of the class.
 *
 * @return An array of objects of class @ref OFMethod
 */
- (OFArray OF_GENERIC(OFMethod*)*)classMethods;
@property (readonly, copy) OFArray OF_GENERIC(OFMethod*) *classMethods;

/*!
 * @brief Returns the instance methods of the class.
 * The instance methods of the class.
 *
 * @return An array of objects of class @ref OFMethod
 */
- (OFArray OF_GENERIC(OFMethod*)*)instanceMethods;
@property (readonly, copy) OFArray OF_GENERIC(OFMethod*) *instanceMethods;

/*!
 * @brief Returns the properties of the class.
 * The properties of the class.
 *
 * @warning **Do not rely on this, as this behaves differently depending on the
 *	    compiler and ABI used!**
 *
 * @warning For the ObjFW ABI, Clang only emits data for property introspection
 *	    if `@``synthesize` or `@``dynamic` has been used on the property,
 *	    not if the property has only been implemented by methods. Using
 *	    `@``synthesize` and manually implementing the methods works,
 *	    though.
 *
 * @warning For the Apple ABI, Clang and GCC both emit data for property
 *	    introspection for every property that has been declared using
 *	    `@``property`, even if no `@``synchronize` or `@``dynamic` has been
 *	    used.
 *
 * @warning GCC does not emit any data for property introspection for the GNU
 *	    ABI.
 *
 * @return An array of objects of class @ref OFProperty
 */
@property (readonly, copy) OFArray OF_GENERIC(OFProperty*) *properties;

/*!
 * The instance variables of the class.
 */
@property (readonly, copy)
- (OFArray OF_GENERIC(OFProperty*)*)properties;
    OFArray OF_GENERIC(OFInstanceVariable*) *instanceVariables;

/* TODO: protocols */

/*!
 * @brief Returns the instance variables of the class.
 * @brief Creates a new introspection for the specified class.
 *
 * @return An array of objects of class @ref OFInstanceVariable
 * @return A new, autoreleased introspection for the specified class
 */
+ (instancetype)introspectionWithClass: (Class)class_;
- (OFArray OF_GENERIC(OFInstanceVariable*)*)instanceVariables;


/*!
 * @brief Initializes an already allocated OFIntrospection with the specified
 *	  class.
 *
/* TODO: protocols */
 * @return An initialized OFIntrospection
 */
- initWithClass: (Class)class_;
@end

OF_ASSUME_NONNULL_END