annotate dmd/IntegerExp.d @ 68:ee3a9f34dc48

final bits of codegen implementation to compile Phobos
author korDen
date Tue, 24 Aug 2010 16:44:34 +0400
parents cab4c37afb89
children 2e2a5c3f943a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.TypeEnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.TypeTypedef;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.IntRange;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.Complex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.backend.dt_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import core.stdc.ctype : isprint;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 class IntegerExp : Expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 ulong value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 this(Loc loc, ulong value, Type type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 super(loc, TOK.TOKint64, IntegerExp.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 //printf("IntegerExp(value = %lld, type = '%s')\n", value, type ? type.toChars() : "");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 if (type && !type.isscalar())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 //printf("%s, loc = %d\n", toChars(), loc.linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 error("integral constant must be scalar type, not %s", type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 type = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 this.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 this.value = value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 this(ulong value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 super(Loc(0), TOK.TOKint64, IntegerExp.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 this.type = Type.tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 this.value = value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51
45
ccbc1e0bb3f0 StringExp.equals implemented
korDen
parents: 20
diff changeset
52 bool equals(Object o)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 IntegerExp ne;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 if (this == o ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 ((cast(Expression)o).op == TOKint64 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 ((ne = cast(IntegerExp)o), type.toHeadMutable().equals(ne.type.toHeadMutable())) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 value == ne.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 Expression semantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 if (!type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 // Determine what the type of this number is
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 ulong number = value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 if (number & 0x8000000000000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 type = Type.tuns64;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 else if (number & 0xFFFFFFFF80000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 type = Type.tint64;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 type = Type.tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 { if (!type.deco)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 type = type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
63
cab4c37afb89 A bunch of implementations
korDen
parents: 53
diff changeset
87 Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 53
diff changeset
89 version (LOG) {
cab4c37afb89 A bunch of implementations
korDen
parents: 53
diff changeset
90 printf("IntegerExp.interpret() %s\n", toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 53
diff changeset
91 }
cab4c37afb89 A bunch of implementations
korDen
parents: 53
diff changeset
92 return this;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 string toChars()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 return Expression.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 static char buffer[value.sizeof * 3 + 1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 int len = sprintf(buffer.ptr, "%jd", value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 return buffer[0..len].idup;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 void dump(int indent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 IntRange getIntRange()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 {
53
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 50
diff changeset
113 IntRange ir;
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 50
diff changeset
114 ir.imin = value & type.sizemask();
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 50
diff changeset
115 ir.imax = ir.imin;
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 50
diff changeset
116 return ir;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 ulong toInteger()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 t = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 while (t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 switch (t.ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 case TY.Tbit:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 case TY.Tbool: value = (value != 0); break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 case TY.Tint8: value = cast(byte) value; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 case TY.Tchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 case TY.Tuns8: value = cast(ubyte) value; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 case TY.Tint16: value = cast(short) value; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 case TY.Twchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 case TY.Tuns16: value = cast(ushort)value; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 case TY.Tint32: value = cast(int) value; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 case TY.Tdchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 case TY.Tuns32: value = cast(uint) value; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 case TY.Tint64: value = cast(long) value; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 case TY.Tuns64: value = cast(ulong) value; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 case TY.Tpointer:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 if (PTRSIZE == 4)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 value = cast(uint) value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 else if (PTRSIZE == 8)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 value = cast(ulong) value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 case TY.Tenum:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 TypeEnum te = cast(TypeEnum)t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 t = te.sym.memtype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 case TY.Ttypedef:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 TypeTypedef tt = cast(TypeTypedef)t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 t = tt.sym.basetype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 /* This can happen if errors, such as
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 * the type is painted on like in fromConstInitializer().
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 if (!global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 ///type.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 return value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 real toReal()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 t = type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 if (t.ty == Tuns64)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 return cast(real)cast(ulong)value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 return cast(real)cast(long)value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 real toImaginary()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 Complex!(real) toComplex()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 int isConst()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 bool isBool(bool result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 return result ? value != 0 : value == 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 MATCH implicitConvTo(Type t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 printf("IntegerExp.implicitConvTo(this=%s, type=%s, t=%s)\n",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 toChars(), type.toChars(), t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 MATCH m = type.implicitConvTo(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 if (m >= MATCH.MATCHconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 return m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 TY ty = type.toBasetype().ty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 TY toty = t.toBasetype().ty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 if (m == MATCH.MATCHnomatch && t.ty == TY.Tenum)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 switch (ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 case TY.Tbit:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 case TY.Tbool:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 value &= 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 ty = TY.Tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 case TY.Tint8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 value = cast(byte)value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 ty = TY.Tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 case TY.Tchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 case TY.Tuns8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 value &= 0xFF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 ty = TY.Tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 case TY.Tint16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 value = cast(short)value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 ty = TY.Tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 case TY.Tuns16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 case TY.Twchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 value &= 0xFFFF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 ty = TY.Tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 case TY.Tint32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 value = cast(int)value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 case TY.Tuns32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 case TY.Tdchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 value &= 0xFFFFFFFF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 ty = TY.Tuns32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 // Only allow conversion if no change in value
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 switch (toty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 case TY.Tbit:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 case TY.Tbool:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 if ((value & 1) != value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 case TY.Tint8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 if (cast(byte)value != value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 case TY.Tchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 case TY.Tuns8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 //printf("value = %llu %llu\n", (dinteger_t)(unsigned char)value, value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 if (cast(ubyte)value != value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 case TY.Tint16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 if (cast(short)value != value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 case TY.Tuns16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 if (cast(ushort)value != value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 case TY.Tint32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 if (ty == TY.Tuns32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 else if (cast(int)value != value) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 case TY.Tuns32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 if (ty == TY.Tint32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 } else if (cast(uint)value != value) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 case TY.Tdchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 if (value > 0x10FFFF) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 case TY.Twchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 if (cast(ushort)value != value) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 case TY.Tfloat32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 /*volatile*/ float f; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 if (type.isunsigned()) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 f = cast(float)value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 if (f != value) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 f = cast(float)cast(long)value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 if (f != cast(long)value) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 case TY.Tfloat64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 /*volatile*/ double f; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 if (type.isunsigned()) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 f = cast(double)value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 if (f != value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 f = cast(double)cast(long)value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 if (f != cast(long)value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 case TY.Tfloat80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 /*volatile*/ real f; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 if (type.isunsigned()) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 f = cast(real)value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 if (f != value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 f = cast(real)cast(long)value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 if (f != cast(long)value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 case TY.Tpointer:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 //printf("type = %s\n", type.toBasetype().toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 //printf("t = %s\n", t.toBasetype().toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 if (ty == TY.Tpointer && type.toBasetype().nextOf().ty == t.toBasetype().nextOf().ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 /* Allow things like:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 * const char* P = cast(char *)3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 * char* q = P;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 return Expression.implicitConvTo(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 Lyes:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 //printf("MATCHconvert\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 return MATCH.MATCHconvert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 Lno:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 //printf("MATCHnomatch\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 return MATCH.MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 long v = toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 if (type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 Type t = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 switch (t.ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 case TY.Tenum:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 TypeEnum te = cast(TypeEnum)t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 buf.printf("cast(%s)", te.sym.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 t = te.sym.memtype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 case TY.Ttypedef:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 TypeTypedef tt = cast(TypeTypedef)t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 buf.printf("cast(%s)", tt.sym.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 t = tt.sym.basetype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 case TY.Twchar: // BUG: need to cast(wchar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 case TY.Tdchar: // BUG: need to cast(dchar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 if (cast(ulong)v > 0xFF)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 buf.printf("'\\U%08x'", v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 case TY.Tchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 if (v == '\'')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 buf.writestring("'\\''");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 else if (isprint(cast(int)v) && v != '\\')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 buf.printf("'%c'", cast(int)v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 buf.printf("'\\x%02x'", cast(int)v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 case TY.Tint8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 buf.writestring("cast(byte)");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 case TY.Tint16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 buf.writestring("cast(short)");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 case TY.Tint32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 L2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 buf.printf("%d", cast(int)v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 case TY.Tuns8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 buf.writestring("cast(ubyte)");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 goto L3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 case TY.Tuns16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 buf.writestring("cast(ushort)");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 goto L3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 case TY.Tuns32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 L3:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 buf.printf("%du", cast(uint)v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 case TY.Tint64:
68
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 63
diff changeset
477 //buf.printf("%jdL", v);
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 63
diff changeset
478 buf.printf("%sL", v);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 case TY.Tuns64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 L4:
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 45
diff changeset
483 //buf.printf("%juLU", v);
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 45
diff changeset
484 buf.printf("%sLU", v);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 case TY.Tbit:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 case TY.Tbool:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 buf.writestring(v ? "true" : "false");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 case TY.Tpointer:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 buf.writestring("cast(");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 buf.writestring(t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 buf.writeByte(')');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 if (PTRSIZE == 4)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 goto L3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 else if (PTRSIZE == 8)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 goto L4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 /* This can happen if errors, such as
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 * the type is painted on like in fromConstInitializer().
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 if (!global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 writef("%s\n", t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 else if (v & 0x8000000000000000L)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 buf.printf("0x%jx", v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 buf.printf("%jd", v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 void toMangleBuffer(OutBuffer buf)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
525 if (cast(long)value < 0)
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
526 buf.printf("N%d", -value);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
527 else
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
528 buf.printf("%d", value);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 Expression toLvalue(Scope sc, Expression e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 if (!e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 else if (!loc.filename)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 loc = e.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 e.error("constant %s is not an lvalue", e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 elem* toElem(IRState* irs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 elem* e = el_long(type.totym(), value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 el_setLoc(e,loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 dt_t** toDt(dt_t** pdt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 //printf("IntegerExp.toDt() %d\n", op);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 uint sz = cast(uint)type.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 if (value == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 pdt = dtnzeros(pdt, sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 pdt = dtnbytes(pdt, sz, cast(char*)&value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 return pdt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560