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