annotate dmd/RealExp.d @ 123:9e39c7de8438

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