annotate dmd/expression/Shr.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children e28b18c23469
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.expression.Shr;
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.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 Expression Shr(Type type, Expression e1, Expression e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 Loc loc = e1.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 long value = e1.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 uint count = cast(uint)e2.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 switch (e1.type.toBasetype().ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 case TY.Tint8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 value = cast(byte)(value) >> count;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 case TY.Tuns8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 value = cast(ubyte)(value) >> count;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 case TY.Tint16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 value = cast(short)(value) >> count;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 case TY.Tuns16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 value = cast(ushort)(value) >> count;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 case TY.Tint32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 value = cast(int)(value) >> count;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 case TY.Tuns32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 value = cast(uint)(value) >> count;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 case TY.Tint64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 value = cast(long)(value) >> count;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 case TY.Tuns64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 value = cast(ulong)(value) >> count;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 return new IntegerExp(loc, value, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 }