Mercurial > projects > ddmd
annotate dmd/MulExp.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 |
---|---|
72 | 1 module dmd.MulExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
5 import dmd.Identifier; | |
6 import dmd.backend.elem; | |
7 import dmd.InterState; | |
0 | 8 import dmd.OutBuffer; |
72 | 9 import dmd.NegExp; |
10 import dmd.Loc; | |
0 | 11 import dmd.Id; |
72 | 12 import dmd.Scope; |
13 import dmd.IRState; | |
14 import dmd.BinExp; | |
15 import dmd.ArrayTypes; | |
0 | 16 import dmd.TOK; |
17 import dmd.Type; | |
18 import dmd.TY; | |
19 | |
20 import dmd.expression.Util; | |
21 import dmd.expression.Mul; | |
22 import dmd.backend.OPER; | |
72 | 23 import dmd.backend.Util; |
24 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
25 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
|
26 |
0 | 27 class MulExp : BinExp |
28 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
29 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
|
30 |
0 | 31 this(Loc loc, Expression e1, Expression e2) |
72 | 32 { |
178 | 33 register(); |
0 | 34 super(loc, TOK.TOKmul, MulExp.sizeof, e1, e2); |
35 } | |
36 | |
72 | 37 override Expression semantic(Scope sc) |
0 | 38 { |
39 Expression e; | |
40 | |
41 static if (false) { | |
42 printf("MulExp.semantic() %s\n", toChars()); | |
43 } | |
44 if (type) | |
45 { | |
46 return this; | |
47 } | |
48 | |
49 BinExp.semanticp(sc); | |
50 e = op_overload(sc); | |
51 if (e) | |
52 return e; | |
53 | |
54 typeCombine(sc); | |
109 | 55 if (!e1.isArrayOperand()) |
0 | 56 e1.checkArithmetic(); |
109 | 57 if (!e2.isArrayOperand()) |
0 | 58 e2.checkArithmetic(); |
109 | 59 |
0 | 60 if (type.isfloating()) |
61 { | |
62 Type t1 = e1.type; | |
63 Type t2 = e2.type; | |
64 | |
65 if (t1.isreal()) | |
66 { | |
67 type = t2; | |
68 } | |
69 else if (t2.isreal()) | |
70 { | |
71 type = t1; | |
72 } | |
73 else if (t1.isimaginary()) | |
74 { | |
75 if (t2.isimaginary()) | |
76 { | |
77 switch (t1.ty) | |
78 { | |
79 case Timaginary32: type = Type.tfloat32; break; | |
80 case Timaginary64: type = Type.tfloat64; break; | |
81 case Timaginary80: type = Type.tfloat80; break; | |
82 default: assert(0); | |
83 } | |
84 | |
85 // iy * iv = -yv | |
86 e1.type = type; | |
87 e2.type = type; | |
88 Expression ee = new NegExp(loc, this); | |
89 ee = ee.semantic(sc); | |
90 return ee; | |
91 } | |
92 else | |
93 type = t2; // t2 is complex | |
94 } | |
95 else if (t2.isimaginary()) | |
96 { | |
97 type = t1; // t1 is complex | |
98 } | |
99 } | |
100 return this; | |
101 } | |
102 | |
72 | 103 override Expression optimize(int result) |
0 | 104 { |
105 Expression e; | |
106 | |
107 //printf("MulExp.optimize(result = %d) %s\n", result, toChars()); | |
108 e1 = e1.optimize(result); | |
109 e2 = e2.optimize(result); | |
110 if (e1.isConst() == 1 && e2.isConst() == 1) | |
111 { | |
112 e = Mul(type, e1, e2); | |
113 } | |
114 else | |
115 e = this; | |
116 return e; | |
117 } | |
118 | |
72 | 119 override Expression interpret(InterState istate) |
0 | 120 { |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
121 return interpretCommon(istate, &Mul); |
0 | 122 } |
123 | |
72 | 124 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 125 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
126 Exp_buildArrayIdent(buf, arguments, "Mul"); |
0 | 127 } |
128 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
129 override Expression buildArrayLoop(Parameters fparams) |
0 | 130 { |
123 | 131 return Exp_buildArrayLoop!(typeof(this))(fparams); |
0 | 132 } |
133 | |
72 | 134 override bool isCommutative() |
0 | 135 { |
136 return true; | |
137 } | |
138 | |
72 | 139 override Identifier opId() |
0 | 140 { |
141 return Id.mul; | |
142 } | |
143 | |
72 | 144 override Identifier opId_r() |
0 | 145 { |
146 return Id.mul_r; | |
147 } | |
148 | |
72 | 149 override elem* toElem(IRState* irs) |
0 | 150 { |
151 return toElemBin(irs,OPmul); | |
152 } | |
153 } | |
154 |