# HG changeset patch # User Aziz K?ksal # Date 1198009432 -3600 # Node ID db7913148b29ac8977ad0ee2813b8ed2f88337cd # Parent 0781ac288537c62cbad87094d2feb57651b28c55 Added constructors and semantic() methods. diff -r 0781ac288537 -r db7913148b29 trunk/src/dil/Expressions.d --- a/trunk/src/dil/Expressions.d Tue Dec 18 15:14:41 2007 +0100 +++ b/trunk/src/dil/Expressions.d Tue Dec 18 21:23:52 2007 +0100 @@ -606,11 +606,32 @@ class SpecialTokenExpression : Expression { - Token* special; - this(Token* special) + Token* specialToken; + this(Token* specialToken) { mixin(set_kind); - this.special = special; + this.specialToken = specialToken; + } + + Expression e; /// The expression created in the semantic phase. + + Expression semantic(Scope) + { + if (type) + return e; + switch (specialToken.type) + { + case TOK.LINE, TOK.VERSION: + e = new IntExpression(specialToken.uint_, Types.Uint); + break; + case TOK.FILE, TOK.DATE, TOK.TIME, TOK.TIMESTAMP, TOK.VENDOR: + e = new StringExpression(specialToken.str); + break; + default: + assert(0); + } + type = e.type; + return e; } } @@ -699,14 +720,40 @@ class IntExpression : Expression { - TOK type; ulong number; - this(TOK type, ulong number) + + this(ulong number, Type type) { mixin(set_kind); this.number = number; this.type = type; } + + this(Token* token) + { + auto type = Types.Int; // Should be most common case. + switch (token.type) + { + // case TOK.Int32: + // type = Types.Int; break; + case TOK.Uint32: + type = Types.Uint; break; + case TOK.Int64: + type = Types.Long; break; + case TOK.Uint64: + type = Types.Ulong; break; + default: + assert(token.type == TOK.Int32); + } + this(token.ulong_, type); + } + + Expression semantic(Scope scop) + { + if (type) + return this; + return this; + } } class RealExpression : Expression @@ -746,20 +793,51 @@ class StringExpression : Expression { - Token*[] strings; - this(Token*[] strings) + Token*[] stringTokens; + this() + { mixin(set_kind); } + + /// Constructor used in parsing phase. + this(Token*[] stringTokens) + { + this.stringTokens = stringTokens; + } + + ubyte[] str; /// The string data. + Type charType; /// The character type of the string. + // Constructors used in semantic phase. + this(ubyte[] str, Type charType) { - mixin(set_kind); - this.strings = strings; + this(); + this.str = str; + this.charType = charType; + type = new TypeSArray(charType, str.length); + } + + this(char[] str) + { + this(cast(ubyte[])str, Types.Char); + } + this(wchar[] str) + { + this(cast(ubyte[])str, Types.Wchar); + } + this(dchar[] str) + { + this(cast(ubyte[])str, Types.Dchar); + } + + Expression semantic() + { + if (type) + return this; } char[] getString() { char[] buffer; - foreach (strTok; strings) - { - buffer ~= strTok.str[0..$-1]; - } + foreach (token; stringTokens) + buffer ~= token.str[0..$-1]; return buffer; } } diff -r 0781ac288537 -r db7913148b29 trunk/src/dil/Parser.d --- a/trunk/src/dil/Parser.d Tue Dec 18 15:14:41 2007 +0100 +++ b/trunk/src/dil/Parser.d Tue Dec 18 21:23:52 2007 +0100 @@ -2749,7 +2749,7 @@ switch (token.type) { case T.Int32, T.Int64, T.Uint32, T.Uint64: - e = new IntExpression(token.type, token.ulong_); + e = new IntExpression(token); nT(); break; case T.Float32, T.Float64, T.Float80, @@ -3302,7 +3302,7 @@ e = new DollarExpression(); break; case T.Int32, T.Int64, T.Uint32, T.Uint64: - e = new IntExpression(token.type, token.ulong_); + e = new IntExpression(token); nT(); break; case T.Float32, T.Float64, T.Float80,