Mercurial > projects > ddmd
annotate dmd/ShrAssignExp.d @ 135:af1bebfd96a4 dmd2037
dmd 2.038
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Mon, 13 Sep 2010 22:19:42 +0100 |
parents | 206db751bd4c |
children | e3afd1303184 |
rev | line source |
---|---|
0 | 1 module dmd.ShrAssignExp; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.BinExp; |
5 import dmd.Loc; | |
6 import dmd.Expression; | |
7 import dmd.Scope; | |
8 import dmd.InterState; | |
9 import dmd.Identifier; | |
10 import dmd.IRState; | |
11 import dmd.Id; | |
12 import dmd.TOK; | |
13 import dmd.Type; | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
14 import dmd.ArrayLengthExp; |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
15 import dmd.CastExp; |
0 | 16 |
17 import dmd.backend.elem; | |
18 import dmd.backend.OPER; | |
19 | |
117 | 20 import dmd.expression.Shr; |
0 | 21 import dmd.expression.Util; |
22 | |
23 class ShrAssignExp : BinExp | |
24 { | |
25 this(Loc loc, Expression e1, Expression e2) | |
26 { | |
27 super(loc, TOK.TOKshrass, ShrAssignExp.sizeof, e1, e2); | |
28 } | |
29 | |
72 | 30 override Expression semantic(Scope sc) |
0 | 31 { |
32 Expression e; | |
33 | |
34 BinExp.semantic(sc); | |
35 e2 = resolveProperties(sc, e2); | |
36 | |
37 e = op_overload(sc); | |
38 if (e) | |
39 return e; | |
40 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
41 if (e1.op == TOK.TOKarraylength) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
42 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
43 e = ArrayLengthExp.rewriteOpAssign(this); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
44 e = e.semantic(sc); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
45 return e; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
46 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
47 |
0 | 48 e1 = e1.modifiableLvalue(sc, e1); |
49 e1.checkScalar(); | |
50 e1.checkNoBool(); | |
51 type = e1.type; | |
52 typeCombine(sc); | |
53 e1.checkIntegral(); | |
54 e2 = e2.checkIntegral(); | |
55 e2 = e2.castTo(sc, Type.tshiftcnt); | |
56 | |
57 return this; | |
58 } | |
59 | |
72 | 60 override Expression interpret(InterState istate) |
0 | 61 { |
117 | 62 return interpretAssignCommon(istate, &Shr); |
0 | 63 } |
64 | |
72 | 65 override Identifier opId() /* For operator overloading */ |
0 | 66 { |
67 return Id.shrass; | |
68 } | |
69 | |
72 | 70 override elem* toElem(IRState* irs) |
0 | 71 { |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
72 //printf("ShrAssignExp::toElem() %s, %s\n", e1->type->toChars(), e1->toChars()); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
73 Type t1 = e1.type; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
74 if (e1.op == TOK.TOKcast) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
75 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
76 // Use the type before it was integrally promoted to int |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
77 auto ce = cast(CastExp)e1; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
78 t1 = ce.e1.type; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
79 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
80 return toElemBin(irs, t1.isunsigned() ? OPER.OPshrass : OPER.OPashrass); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
117
diff
changeset
|
81 |
0 | 82 } |
72 | 83 } |