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