Mercurial > projects > ddmd
annotate dmd/DivAssignExp.d @ 130:60bb0fe4563e
dmdfe 2.037 first main iteration
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Thu, 09 Sep 2010 22:51:44 +0100 |
parents | 9e39c7de8438 |
children | e3afd1303184 |
rev | line source |
---|---|
0 | 1 module dmd.DivAssignExp; |
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.OutBuffer; | |
10 import dmd.ArrayTypes; | |
11 import dmd.Identifier; | |
12 import dmd.IRState; | |
13 import dmd.TOK; | |
14 import dmd.Type; | |
15 import dmd.TY; | |
16 import dmd.Id; | |
17 import dmd.CommaExp; | |
18 import dmd.RealExp; | |
19 import dmd.AssignExp; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
20 import dmd.ArrayLengthExp; |
0 | 21 |
22 import dmd.backend.elem; | |
23 import dmd.backend.OPER; | |
24 import dmd.backend.Util; | |
117 | 25 import dmd.expression.Div; |
0 | 26 import dmd.expression.Util; |
27 | |
28 class DivAssignExp : BinExp | |
29 { | |
30 this(Loc loc, Expression e1, Expression e2) | |
31 { | |
32 super(loc, TOK.TOKdivass, DivAssignExp.sizeof, e1, e2); | |
33 } | |
34 | |
72 | 35 override Expression semantic(Scope sc) |
0 | 36 { |
37 Expression e; | |
38 | |
39 BinExp.semantic(sc); | |
40 e2 = resolveProperties(sc, e2); | |
41 | |
42 e = op_overload(sc); | |
43 if (e) | |
44 return e; | |
45 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
46 version(DMDV2) { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
47 if (e1.op == TOK.TOKarraylength) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
48 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
49 e = ArrayLengthExp.rewriteOpAssign(this); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
50 e = e.semantic(sc); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
51 return e; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
52 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
53 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
54 |
0 | 55 if (e1.op == TOKslice) |
56 { // T[] -= ... | |
57 typeCombine(sc); | |
58 type = e1.type; | |
59 return arrayOp(sc); | |
60 } | |
61 | |
62 e1 = e1.modifiableLvalue(sc, e1); | |
63 e1.checkScalar(); | |
64 e1.checkNoBool(); | |
65 type = e1.type; | |
66 typeCombine(sc); | |
67 e1.checkArithmetic(); | |
68 e2.checkArithmetic(); | |
73 | 69 checkComplexMulAssign(); |
0 | 70 if (e2.type.isimaginary()) |
71 { | |
72 Type t1; | |
73 Type t2; | |
74 | |
75 t1 = e1.type; | |
76 if (t1.isreal()) | |
77 { | |
78 // x/iv = i(-x/v) | |
79 // Therefore, the result is 0 | |
80 e2 = new CommaExp(loc, e2, new RealExp(loc, 0, t1)); | |
81 e2.type = t1; | |
82 e = new AssignExp(loc, e1, e2); | |
83 e.type = t1; | |
84 return e; | |
85 } | |
86 else if (t1.isimaginary()) | |
87 { | |
88 Expression e3; | |
89 | |
90 switch (t1.ty) | |
91 { | |
92 case Timaginary32: t2 = Type.tfloat32; break; | |
93 case Timaginary64: t2 = Type.tfloat64; break; | |
94 case Timaginary80: t2 = Type.tfloat80; break; | |
95 default: | |
96 assert(0); | |
97 } | |
98 e2 = e2.castTo(sc, t2); | |
99 e3 = new AssignExp(loc, e1, e2); | |
100 e3.type = t1; | |
101 return e3; | |
102 } | |
103 } | |
104 return this; | |
105 } | |
106 | |
72 | 107 override Expression interpret(InterState istate) |
0 | 108 { |
117 | 109 return interpretAssignCommon(istate, &Div); |
0 | 110 } |
111 | |
72 | 112 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 113 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
114 AssignExp_buildArrayIdent(buf, arguments, "Div"); |
0 | 115 } |
116 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
117 override Expression buildArrayLoop(Parameters fparams) |
0 | 118 { |
123 | 119 return AssignExp_buildArrayLoop!(typeof(this))(fparams); |
0 | 120 } |
121 | |
72 | 122 override Identifier opId() /* For operator overloading */ |
0 | 123 { |
124 return Id.divass; | |
125 } | |
126 | |
72 | 127 override elem* toElem(IRState* irs) |
0 | 128 { |
129 return toElemBin(irs,OPdivass); | |
130 } | |
72 | 131 } |