Mercurial > projects > dil
changeset 539:3418027c3914
Added semantic() method to RealExpression.
Added code to IntExpression.semantic().
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Tue, 18 Dec 2007 22:46:07 +0100 |
parents | d0d40bcca9c6 |
children | 660684f559a4 |
files | trunk/src/dil/Expressions.d trunk/src/dil/Parser.d |
diffstat | 2 files changed, 45 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/src/dil/Expressions.d Tue Dec 18 22:22:30 2007 +0100 +++ b/trunk/src/dil/Expressions.d Tue Dec 18 22:46:07 2007 +0100 @@ -748,24 +748,64 @@ this(token.ulong_, type); } - Expression semantic(Scope scop) + Expression semantic(Scope) { if (type) return this; + + if (number & 0x8000_0000_0000_0000) + type = Types.Ulong; // 0xFFFF_FFFF_FFFF_FFFF + else if (number & 0xFFFF_FFFF_0000_0000) + type = Types.Long; // 0x7FFF_FFFF_FFFF_FFFF + else if (number & 0x8000_0000) + type = Types.Uint; // 0xFFFF_FFFF + else + type = Types.Int; // 0x7FFF_FFFF return this; } } class RealExpression : Expression { - TOK type; real number; - this(TOK type, real number) + + this(real number, Type type) { mixin(set_kind); this.number = number; this.type = type; } + + this(Token* token) + { + auto type = Types.Float; // Most common case? + switch (token.type) + { + // case T.Float32: + // type = Types.Float; break; + case TOK.Float64: + type = Types.Double; break; + case TOK.Float80: + type = Types.Double; break; + case TOK.Imaginary32: + type = Types.Ifloat; break; + case TOK.Imaginary64: + type = Types.Idouble; break; + case TOK.Imaginary80: + type = Types.Ireal; break; + default: + assert(token.type == TOK.Float32); + } + this(token.real_, type); + } + + Expression semantic(Scope) + { + if (type) + return this; + type = Types.Double; + return this; + } } class CharExpression : Expression
--- a/trunk/src/dil/Parser.d Tue Dec 18 22:22:30 2007 +0100 +++ b/trunk/src/dil/Parser.d Tue Dec 18 22:46:07 2007 +0100 @@ -2754,7 +2754,7 @@ break; case T.Float32, T.Float64, T.Float80, T.Imaginary32, T.Imaginary64, T.Imaginary80: - e = new RealExpression(token.type, token.real_); + e = new RealExpression(token); nT(); break; case T.Dollar: @@ -3307,7 +3307,7 @@ break; case T.Float32, T.Float64, T.Float80, T.Imaginary32, T.Imaginary64, T.Imaginary80: - e = new RealExpression(token.type, token.real_); + e = new RealExpression(token); nT(); break; case T.CharLiteral: