comparison d2/qtd/meta/Runtime.d @ 365:958e8b9a89bd

Changeset a084e2df3776 is broken. Backing out.
author Max Samukha <maxter@spambox.com>
date Fri, 11 Jun 2010 20:09:25 +0300
parents a084e2df3776
children 185df9220ea7
comparison
equal deleted inserted replaced
364:a084e2df3776 365:958e8b9a89bd
6 module qtd.meta.Runtime; 6 module qtd.meta.Runtime;
7 //TODO: Probably replace switch dispatch with pointer dispatch 7 //TODO: Probably replace switch dispatch with pointer dispatch
8 //and leave switch dispatch only in C interface 8 //and leave switch dispatch only in C interface
9 9
10 import 10 import
11 qtd.Core,
12 qtd.meta.Compiletime, 11 qtd.meta.Compiletime,
13 12
14 std.typetuple, 13 std.typetuple,
15 std.conv, 14 std.conv,
16 std.variant, 15 std.variant,
86 { 85 {
87 super(msg); 86 super(msg);
88 } 87 }
89 } 88 }
90 89
91 abstract class MetaBase 90 abstract class Meta
92 { 91 {
93 alias typeof(this) This; 92 alias typeof(this) This;
94 93
95 string name; 94 string name;
96 MetaAttribute[] attributes; 95 MetaAttribute[] attributes;
97 MetaBase[] members; 96 Meta[] members;
98 97
99 template createImpl(M : This) 98 template createImpl(M : This)
100 { 99 {
101 static M createImpl(alias symbol)() 100 static M createImpl(alias symbol)()
102 { 101 {
152 this.name = name; 151 this.name = name;
153 options = opts; 152 options = opts;
154 } 153 }
155 } 154 }
156 155
157 abstract class MetaType : MetaBase 156 abstract class MetaType : Meta
158 { 157 {
159 } 158 }
160 159
161 abstract class MetaAggregate : MetaType 160 abstract class MetaAggregate : MetaType
162 { 161 {
163 } 162 }
164 163
165 class MetaClass : MetaAggregate 164 class MetaClass : MetaAggregate
166 { 165 {
167 alias typeof(this) This; 166 alias typeof(this) This;
168 167 alias createImpl!This create;
169 private:
170 This base_;
171 This firstDerived_;
172 This next_;
173 TypeInfo_Class classInfo_;
174
175 this() {}
176
177 public:
178 /**
179 Returns the meta-object of the base class.
180 */
181 @property
182 This base()
183 {
184 return base_;
185 }
186
187 /**
188 Returns next meta-object on this level of the derivation hierarchy.
189 */
190 @property
191 This next()
192 {
193 return next_;
194 }
195
196 /**
197 Returns meta-object of the first derived class.
198 */
199 @property
200 This firstDerived()
201 {
202 return firstDerived_;
203 }
204
205 /**
206 D class info.
207 */
208 @property
209 TypeInfo_Class classInfo()
210 {
211 return classInfo_;
212 }
213
214 /* internal */ alias createImpl!This create;
215
216 /* internal */ void construct(T : Object)()
217 {
218 static if (!is(T == Object))
219 {
220 alias BaseClassesTuple!(T)[0] Base;
221 base_ = meta!Base;
222 }
223 classInfo_ = T.classinfo;
224 }
225 } 168 }
226 169
227 class MetaStruct : MetaAggregate 170 class MetaStruct : MetaAggregate
228 { 171 {
229 alias typeof(this) This; 172 alias typeof(this) This;
230 alias createImpl!This create; 173 alias createImpl!This create;
231 } 174 }
232 175
233 @property 176 @property
234 auto meta(alias symbol, M : MetaBase)() 177 auto meta(alias symbol, M : Meta)()
235 { 178 {
236 __gshared static M sharedM; 179 __gshared static M m;
237 static M m; 180
181 {
182 lock.reader.lock;
183 scope(exit)
184 lock.reader.unlock;
185 if (m)
186 return m;
187 }
188
189 lock.writer.lock;
190 scope(exit)
191 lock.writer.unlock;
238 192
239 if (!m) 193 if (!m)
240 { 194 m = M.create!symbol;
241 synchronized(qtdMoLock)
242 {
243 if (!sharedM)
244 sharedM = M.create!symbol;
245 }
246 m = sharedM;
247 }
248
249 return m; 195 return m;
250 } 196 }
251 197
252 // only classes and structs for now 198 // only classes and structs for now
253 @property 199 @property
254 auto meta(T)() 200 auto meta(T)()
255 { 201 {
256 static if (is(T.Meta)) // If the type defines a meta-class - use that. 202 static if (is(typeof(T.staticMetaObject)))
257 return meta!(T, T.Meta); 203 return T.staticMetaObject;
258 else static if (is(T == class)) 204 else static if (is(T == class))
259 return meta!(T, MetaClass); 205 return meta!(T, MetaClass);
260 else static if (is(T == struct)) 206 else static if (is(T == struct))
261 return meta!(T, MetaStruct); 207 return meta!(T, MetaStruct);
262 else 208 else