# HG changeset patch # User aziz # Date 1183735384 0 # Node ID 0fe650a7a8d1f415e4eb5d318f66383eb1652fd7 # Parent 9f8b6c205ecc7e9af43ea089e348d1439813f52c - Renamed Type enum to InfoType in module Information. - Changed 'TOK type' member of TypeDotIdExpression to 'Type type'. - Added module Types. - Implemented most of parseBasicType(). - Indented code of 'BasicType . Identifier' parser and creating Type instance. diff -r 9f8b6c205ecc -r 0fe650a7a8d1 trunk/src/Expressions.d --- a/trunk/src/Expressions.d Fri Jul 06 10:18:03 2007 +0000 +++ b/trunk/src/Expressions.d Fri Jul 06 15:23:04 2007 +0000 @@ -4,6 +4,7 @@ +/ module Expressions; import Token; +import Types; class Expression { @@ -467,9 +468,9 @@ class TypeDotIdExpression : Expression { - TOK type; + Type type; string ident; - this(TOK type, string ident) + this(Type type, string ident) { this.type = type; this.ident = ident; diff -r 9f8b6c205ecc -r 0fe650a7a8d1 trunk/src/Information.d --- a/trunk/src/Information.d Fri Jul 06 10:18:03 2007 +0000 +++ b/trunk/src/Information.d Fri Jul 06 15:23:04 2007 +0000 @@ -7,7 +7,7 @@ import std.string; import std.stdarg; -enum Type +enum InfoType { Lexer, Parser, @@ -17,11 +17,11 @@ class Information { MID id; - Type type; + InfoType type; uint loc; string[] arguments; - this(Type type, MID id, uint loc, string[] arguments) + this(InfoType type, MID id, uint loc, string[] arguments) { this.id = id; this.type = type; diff -r 9f8b6c205ecc -r 0fe650a7a8d1 trunk/src/Lexer.d --- a/trunk/src/Lexer.d Fri Jul 06 10:18:03 2007 +0000 +++ b/trunk/src/Lexer.d Fri Jul 06 15:23:04 2007 +0000 @@ -1436,7 +1436,7 @@ void error(MID id, ...) { - errors ~= new Information(Information.Type.Lexer, id, loc, arguments(_arguments, _argptr)); + errors ~= new Information(InfoType.Lexer, id, loc, arguments(_arguments, _argptr)); } public TOK nextToken() diff -r 9f8b6c205ecc -r 0fe650a7a8d1 trunk/src/Parser.d --- a/trunk/src/Parser.d Fri Jul 06 10:18:03 2007 +0000 +++ b/trunk/src/Parser.d Fri Jul 06 15:23:04 2007 +0000 @@ -8,6 +8,7 @@ import Messages; import Information; import Expressions; +import Types; enum STC { @@ -530,24 +531,26 @@ case T.LParen: break; // BasicType . Identifier - case T.Void, T.Char, T.Wchar, T.Dchar, T.Bool, T.Byte, T.Ubyte, - T.Short, T.Ushort, T.Int, T.Uint, T.Long, T.Ulong, - T.Float, T.Double, T.Real, T.Ifloat, T.Idouble, T.Ireal, + case T.Void, T.Char, T.Wchar, T.Dchar, T.Bool, + T.Byte, T.Ubyte, T.Short, T.Ushort, + T.Int, T.Uint, T.Long, T.Ulong, + T.Float, T.Double, T.Real, + T.Ifloat, T.Idouble, T.Ireal, T.Cfloat, T.Cdouble, T.Creal: - TOK type = token.type; + auto type = new Type(token.type); - requireNext(T.Dot); + requireNext(T.Dot); - string ident; - if (token.type == T.Identifier) - { - ident = token.srcText; - nT(); - } - else - errorIfNot(T.Identifier); + string ident; + if (token.type == T.Identifier) + { + ident = token.srcText; + nT(); + } + else + errorIfNot(T.Identifier); - e = new TypeDotIdExpression(type, ident); + e = new TypeDotIdExpression(type, ident); default: // error(); } @@ -581,6 +584,54 @@ return es; } + Type parseBasicType() + { + Type t; + IdentifierType tident; + + switch (token.type) + { + case T.Void, T.Char, T.Wchar, T.Dchar, T.Bool, + T.Byte, T.Ubyte, T.Short, T.Ushort, + T.Int, T.Uint, T.Long, T.Ulong, + T.Float, T.Double, T.Real, + T.Ifloat, T.Idouble, T.Ireal, + T.Cfloat, T.Cdouble, T.Creal: + t = new Type(token.type); + nT(); + break; + case T.Identifier, T.Dot: + tident = new IdentifierType([token.srcText]); + nT(); +// if (token.type == T.Not) +// parse template instance + Lident: + while (token.type == T.Dot) + { + nT(); + if (token.type == T.Identifier) + { + tident ~= token.srcText; + } + else + errorIfNot(T.Identifier); + nT(); +// if (token.type == T.Not) +// parse template instance + } + t = tident; + break; + case T.Typeof: + requireNext(T.LParen); + tident = new TypeofType(parseExpression()); + require(T.RParen); + goto Lident; + default: +// error(); + } + return t; + } + void errorIfNot(TOK tok) { if (token.type != tok) @@ -606,6 +657,6 @@ void error(MID id, ...) { - errors ~= new Information(Information.Type.Parser, id, lx.loc, arguments(_arguments, _argptr)); + errors ~= new Information(InfoType.Parser, id, lx.loc, arguments(_arguments, _argptr)); } } diff -r 9f8b6c205ecc -r 0fe650a7a8d1 trunk/src/Types.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/Types.d Fri Jul 06 15:23:04 2007 +0000 @@ -0,0 +1,47 @@ +/++ + Author: Aziz Köksal + License: GPL2 ++/ +module Types; +import Token; +import Expressions; + +class Type +{ + TOK type; + this(TOK type) + { + this.type = type; + } +} + +class IdentifierType : Type +{ + string[] idents; + + this(string[] idents) + { + super(TOK.Identifier); + this.idents = idents; + } + + this(TOK type) + { + super(type); + } + + void opCatAssign(string ident) + { + this.idents ~= ident; + } +} + +class TypeofType : IdentifierType +{ + Expression e; + this(Expression e) + { + super(TOK.Typeof); + this.e = e; + } +}