annotate dmd/RealExp.d @ 73:ef02e2e203c2

Updating to dmd2.033
author korDen
date Sat, 28 Aug 2010 19:42:41 +0400
parents 2e2a5c3f943a
children e28b18c23469
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
1 module dmd.RealExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
2
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
3 import dmd.Expression;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
4 import dmd.backend.elem;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
5 import dmd.InterState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
6 import dmd.Type;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
7 import dmd.OutBuffer;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
8 import dmd.Loc;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
9 import dmd.TOK;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
10 import dmd.Scope;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.IRState;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
12 import dmd.Type;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Port;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.TY;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
16
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.backend.dt_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.backend.mTY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
22 import dmd.Complex;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
23
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
24 import std.stdio;
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
25
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 class RealExp : Expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 real value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 this(Loc loc, real value, Type type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 super(loc, TOK.TOKfloat64, RealExp.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 //printf("RealExp.RealExp(%Lg)\n", value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 this.value = value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 this.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
38 override bool equals(Object o)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
43 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 if (!type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 type = Type.tfloat64;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 type = type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
52 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
57 override string toChars()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
62 override ulong toInteger()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
67 override ulong toUInteger()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
72 override real toReal()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 return type.isreal() ? value : 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
77 override real toImaginary()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 return type.isreal() ? 0 : value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
82 override Complex!(real) toComplex()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 return Complex!(real)(toReal(), toImaginary());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
87 override Expression castTo(Scope sc, Type t)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 Expression e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 if (type != t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 if ((type.isreal() && t.isreal()) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 (type.isimaginary() && t.isimaginary())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 e = copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 e.type = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 e = Expression.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
105 override int isConst()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
110 override bool isBool(bool result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
115 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
120 override void toMangleBuffer(OutBuffer buf)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
125 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 eve c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 tym_t ty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 //printf("RealExp.toElem(%p) %s\n", this, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 ///memset(&c, 0, sizeof(c));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 ty = type.toBasetype().totym();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 switch (tybasic(ty))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 case TYfloat:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 case TYifloat:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 c.Vfloat = value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 if (Port.isSignallingNan(value)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 std.stdio.writeln("signalling float");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 (cast(uint*)&c.Vfloat)[0] &= 0xFFBFFFFFL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 case TYdouble:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 case TYidouble:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 c.Vdouble = value; // unfortunately, this converts SNAN to QNAN
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 if (Port.isSignallingNan(value)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 std.stdio.writeln("signalling double");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 // Put SNAN back
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 (cast(uint*)&c.Vdouble)[1] &= 0xFFF7FFFFL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 case TYldouble:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 case TYildouble:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 c.Vldouble = value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 ///type.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 ///type.toBasetype().print();
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
163 printf("ty = %d, tym = %lx\n", type.ty, ty);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 return el_const(ty, &c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 static private char[6] zeropad;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
171 override dt_t** toDt(dt_t** pdt)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 float fvalue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 double dvalue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 real evalue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 //printf("RealExp.toDt(%Lg)\n", value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 switch (type.toBasetype().ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 case Tfloat32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 case Timaginary32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 fvalue = value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 pdt = dtnbytes(pdt,4,cast(char*)&fvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 case Tfloat64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 case Timaginary64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 dvalue = value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 pdt = dtnbytes(pdt,8,cast(char*)&dvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 case Tfloat80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 case Timaginary80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 evalue = value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 pdt = dtnbytes(pdt,REALSIZE - REALPAD,cast(char*)&evalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 pdt = dtnbytes(pdt,REALPAD,zeropad.ptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 assert(REALPAD <= zeropad.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 writef("%s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 ///type.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 return pdt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209