Mercurial > projects > dil
changeset 100:538e8b546669
- Added code for parsing IsExpressions.
- Added class SpecializationType for IsExpressions.
- Added missing default statement in parseDeclaratorSuffix().
- Added parameter identOptional to parseDeclarator().
author | aziz |
---|---|
date | Sat, 07 Jul 2007 13:55:01 +0000 |
parents | 6b8c248f5911 |
children | 6f3c5473c5e5 |
files | trunk/src/Expressions.d trunk/src/Parser.d trunk/src/Types.d |
diffstat | 3 files changed, 69 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/src/Expressions.d Sat Jul 07 12:30:01 2007 +0000 +++ b/trunk/src/Expressions.d Sat Jul 07 13:55:01 2007 +0000 @@ -514,6 +514,13 @@ class IsExpression : Expression { - this() - {} + Type type; + string ident; + SpecializationType specType; + this(Type type, string ident, SpecializationType specType) + { + this.type = type; + this.ident = ident; + this.specType = specType; + } }
--- a/trunk/src/Parser.d Sat Jul 07 12:30:01 2007 +0000 +++ b/trunk/src/Parser.d Sat Jul 07 13:55:01 2007 +0000 @@ -559,7 +559,40 @@ e = new TypeidExpression(type); break; case T.Is: -// e = new IsExpression(); + requireNext(T.LParen); + + Type type; + SpecializationType specType; + string ident; // optional Identifier + + type = parseDeclarator(ident, true); + + switch (token.type) + { + case T.Colon, T.Equal: + TOK specTok = token.type; + nT(); + switch (token.type) + { + case T.Typedef, + T.Struct, + T.Union, + T.Class, + T.Interface, + T.Enum, + T.Function, + T.Delegate, + T.Super, + T.Return: + specType = new SpecializationType(specTok, token.type); + break; + default: + specType = new SpecializationType(specTok, parseType()); + } + default: + } + + e = new IsExpression(type, ident, specType); break; case T.LParen: nT(); @@ -736,13 +769,15 @@ auto params = parseParameters(); // new FunctionType(params); break; + default: + break; } break; } return t; } - Type parseDeclarator(ref string ident) + Type parseDeclarator(ref string ident, bool identOptional = false) { auto t = parseBasicType2(parseBasicType()); @@ -751,7 +786,7 @@ ident = token.srcText; nT(); } - else + else if (!identOptional) errorIfNot(T.Identifier); t = parseDeclaratorSuffix(t);
--- a/trunk/src/Types.d Sat Jul 07 12:30:01 2007 +0000 +++ b/trunk/src/Types.d Sat Jul 07 13:55:01 2007 +0000 @@ -90,3 +90,25 @@ this.e = e; } } + +class SpecializationType : Type +{ + TOK specTok; // T.Colon|T.Equal + Type type; + TOK tokType; // T.Typedef|T.Struct|T.Union|T.Class|T.Interface| + // T.Enum| T.Function|T.Delegate|T.Super|T.Return + + this(TOK specTok, TOK tokType) + { + super(TOK.Invalid, null); + this.specTok = specTok; + this.tokType = tokType; + } + + this(TOK specTok, Type type) + { + super(TOK.Invalid, null); + this.specTok = specTok; + this.type = type; + } +}