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