Mercurial > projects > qtd
diff 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 |
line wrap: on
line diff
--- a/d2/qtd/meta/Runtime.d Fri Jun 11 12:16:09 2010 +0300 +++ b/d2/qtd/meta/Runtime.d Fri Jun 11 20:09:25 2010 +0300 @@ -8,7 +8,6 @@ //and leave switch dispatch only in C interface import - qtd.Core, qtd.meta.Compiletime, std.typetuple, @@ -88,13 +87,13 @@ } } -abstract class MetaBase +abstract class Meta { alias typeof(this) This; string name; MetaAttribute[] attributes; - MetaBase[] members; + Meta[] members; template createImpl(M : This) { @@ -154,7 +153,7 @@ } } -abstract class MetaType : MetaBase +abstract class MetaType : Meta { } @@ -165,63 +164,7 @@ class MetaClass : MetaAggregate { alias typeof(this) This; - -private: - This base_; - This firstDerived_; - This next_; - TypeInfo_Class classInfo_; - - this() {} - -public: - /** - Returns the meta-object of the base class. - */ - @property - This base() - { - return base_; - } - - /** - Returns next meta-object on this level of the derivation hierarchy. - */ - @property - This next() - { - return next_; - } - - /** - Returns meta-object of the first derived class. - */ - @property - This firstDerived() - { - return firstDerived_; - } - - /** - D class info. - */ - @property - TypeInfo_Class classInfo() - { - return classInfo_; - } - - /* internal */ alias createImpl!This create; - - /* internal */ void construct(T : Object)() - { - static if (!is(T == Object)) - { - alias BaseClassesTuple!(T)[0] Base; - base_ = meta!Base; - } - classInfo_ = T.classinfo; - } + alias createImpl!This create; } class MetaStruct : MetaAggregate @@ -231,21 +174,24 @@ } @property -auto meta(alias symbol, M : MetaBase)() +auto meta(alias symbol, M : Meta)() { - __gshared static M sharedM; - static M m; + __gshared static M m; + + { + lock.reader.lock; + scope(exit) + lock.reader.unlock; + if (m) + return m; + } + + lock.writer.lock; + scope(exit) + lock.writer.unlock; if (!m) - { - synchronized(qtdMoLock) - { - if (!sharedM) - sharedM = M.create!symbol; - } - m = sharedM; - } - + m = M.create!symbol; return m; } @@ -253,8 +199,8 @@ @property auto meta(T)() { - static if (is(T.Meta)) // If the type defines a meta-class - use that. - return meta!(T, T.Meta); + static if (is(typeof(T.staticMetaObject))) + return T.staticMetaObject; else static if (is(T == class)) return meta!(T, MetaClass); else static if (is(T == struct))