Mercurial > projects > ddmd
annotate dmd/MulAssignExp.d @ 187:b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author | Abscissa |
---|---|
date | Tue, 07 Jun 2011 23:37:34 -0400 |
parents | e3afd1303184 |
children |
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 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
24 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
25 |
0 | 26 class MulAssignExp : BinExp |
27 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
28 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
29 |
0 | 30 this(Loc loc, Expression e1, Expression e2) |
31 { | |
178 | 32 register(); |
0 | 33 super(loc, TOK.TOKmulass, MulAssignExp.sizeof, e1, e2); |
34 } | |
35 | |
72 | 36 override Expression semantic(Scope sc) |
0 | 37 { |
38 Expression e; | |
39 | |
40 BinExp.semantic(sc); | |
41 e2 = resolveProperties(sc, e2); | |
42 | |
43 e = op_overload(sc); | |
44 if (e) | |
45 return e; | |
46 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
47 version(DMDV2) { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
48 if (e1.op == TOK.TOKarraylength) |
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 e = ArrayLengthExp.rewriteOpAssign(this); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
51 e = e.semantic(sc); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
52 return e; |
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 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
55 |
0 | 56 if (e1.op == TOKslice) |
57 { // T[] -= ... | |
58 typeCombine(sc); | |
59 type = e1.type; | |
60 return arrayOp(sc); | |
61 } | |
62 | |
63 e1 = e1.modifiableLvalue(sc, e1); | |
64 e1.checkScalar(); | |
65 e1.checkNoBool(); | |
66 type = e1.type; | |
67 typeCombine(sc); | |
68 e1.checkArithmetic(); | |
69 e2.checkArithmetic(); | |
73 | 70 checkComplexMulAssign(); |
0 | 71 if (e2.type.isfloating()) |
72 { | |
73 Type t1; | |
74 Type t2; | |
75 | |
76 t1 = e1.type; | |
77 t2 = e2.type; | |
78 if (t1.isreal()) | |
79 { | |
80 if (t2.isimaginary() || t2.iscomplex()) | |
81 { | |
82 e2 = e2.castTo(sc, t1); | |
83 } | |
84 } | |
85 else if (t1.isimaginary()) | |
86 { | |
87 if (t2.isimaginary() || t2.iscomplex()) | |
88 { | |
89 switch (t1.ty) | |
90 { | |
91 case Timaginary32: t2 = Type.tfloat32; break; | |
92 case Timaginary64: t2 = Type.tfloat64; break; | |
93 case Timaginary80: t2 = Type.tfloat80; break; | |
94 default: | |
95 assert(0); | |
96 } | |
97 e2 = e2.castTo(sc, t2); | |
98 } | |
99 } | |
100 } | |
101 return this; | |
102 } | |
103 | |
72 | 104 override Expression interpret(InterState istate) |
0 | 105 { |
117 | 106 return interpretAssignCommon(istate, &Mul); |
0 | 107 } |
108 | |
72 | 109 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 110 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
111 AssignExp_buildArrayIdent(buf, arguments, "Mul"); |
0 | 112 } |
113 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
114 override Expression buildArrayLoop(Parameters fparams) |
0 | 115 { |
123 | 116 return AssignExp_buildArrayLoop!(typeof(this))(fparams); |
0 | 117 } |
118 | |
72 | 119 override Identifier opId() /* For operator overloading */ |
0 | 120 { |
121 return Id.mulass; | |
122 } | |
123 | |
72 | 124 override elem* toElem(IRState* irs) |
0 | 125 { |
126 return toElemBin(irs,OPmulass); | |
127 } | |
72 | 128 } |