Mercurial > projects > dil
changeset 567:ab9f5020cd02
Added 'is-methods' to class Symbol.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sat, 29 Dec 2007 14:44:09 +0100 |
parents | 84fde575a2fe |
children | c8861b452eb3 |
files | trunk/src/dil/Scope.d trunk/src/dil/Symbol.d trunk/src/dil/Symbols.d |
diffstat | 3 files changed, 18 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/src/dil/Scope.d Fri Dec 28 23:24:08 2007 +0100 +++ b/trunk/src/dil/Scope.d Sat Dec 29 14:44:09 2007 +0100 @@ -76,7 +76,7 @@ auto scop = this; while (scop) { - if (scop.symbol.sid == SYM.Class) + if (scop.symbol.isClass) return scop; scop = scop.parent; } @@ -89,7 +89,7 @@ auto scop = this; while (scop) { - if (scop.symbol.sid == SYM.Module) + if (scop.symbol.isModule) return scop; scop = scop.parent; }
--- a/trunk/src/dil/Symbol.d Fri Dec 28 23:24:08 2007 +0100 +++ b/trunk/src/dil/Symbol.d Sat Dec 29 14:44:09 2007 +0100 @@ -25,4 +25,18 @@ class Symbol { SYM sid; + + // A template macro for building isXYZ() methods. + private template is_(char[] kind) + { + const char[] is_ = `bool is`~kind~`(){ return sid == SYM.`~kind~`; }`; + } + mixin(is_!("Module")); + mixin(is_!("Class")); + mixin(is_!("Interface")); + mixin(is_!("Struct")); + mixin(is_!("Union")); + mixin(is_!("Variable")); + mixin(is_!("Function")); + mixin(is_!("Type")); }
--- a/trunk/src/dil/Symbols.d Fri Dec 28 23:24:08 2007 +0100 +++ b/trunk/src/dil/Symbols.d Sat Dec 29 14:44:09 2007 +0100 @@ -42,10 +42,10 @@ override void insert(Symbol s, Identifier* ident) { - if (s.sid == SYM.Variable) + if (s.isVariable) // Append variable to fields. fields ~= cast(Variable)cast(void*)s; - else if (s.sid == SYM.Function) + else if (s.isFunction) // Append function to funcs. funcs ~= cast(Function)cast(void*)s; super.insert(s, ident);