Mercurial > projects > ddmd
annotate dmd/MulExp.d @ 115:6caaf0256da1
+ interpretation of (non-assign) binary expressions
+ BinExp.isunsigned
+ EqualExp.isBit
author | Trass3r |
---|---|
date | Thu, 02 Sep 2010 01:29:29 +0200 |
parents | e28b18c23469 |
children | 9e39c7de8438 |
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 | |
0 | 25 class MulExp : BinExp |
26 { | |
27 this(Loc loc, Expression e1, Expression e2) | |
72 | 28 { |
0 | 29 super(loc, TOK.TOKmul, MulExp.sizeof, e1, e2); |
30 } | |
31 | |
72 | 32 override Expression semantic(Scope sc) |
0 | 33 { |
34 Expression e; | |
35 | |
36 static if (false) { | |
37 printf("MulExp.semantic() %s\n", toChars()); | |
38 } | |
39 if (type) | |
40 { | |
41 return this; | |
42 } | |
43 | |
44 BinExp.semanticp(sc); | |
45 e = op_overload(sc); | |
46 if (e) | |
47 return e; | |
48 | |
49 typeCombine(sc); | |
109 | 50 if (!e1.isArrayOperand()) |
0 | 51 e1.checkArithmetic(); |
109 | 52 if (!e2.isArrayOperand()) |
0 | 53 e2.checkArithmetic(); |
109 | 54 |
0 | 55 if (type.isfloating()) |
56 { | |
57 Type t1 = e1.type; | |
58 Type t2 = e2.type; | |
59 | |
60 if (t1.isreal()) | |
61 { | |
62 type = t2; | |
63 } | |
64 else if (t2.isreal()) | |
65 { | |
66 type = t1; | |
67 } | |
68 else if (t1.isimaginary()) | |
69 { | |
70 if (t2.isimaginary()) | |
71 { | |
72 switch (t1.ty) | |
73 { | |
74 case Timaginary32: type = Type.tfloat32; break; | |
75 case Timaginary64: type = Type.tfloat64; break; | |
76 case Timaginary80: type = Type.tfloat80; break; | |
77 default: assert(0); | |
78 } | |
79 | |
80 // iy * iv = -yv | |
81 e1.type = type; | |
82 e2.type = type; | |
83 Expression ee = new NegExp(loc, this); | |
84 ee = ee.semantic(sc); | |
85 return ee; | |
86 } | |
87 else | |
88 type = t2; // t2 is complex | |
89 } | |
90 else if (t2.isimaginary()) | |
91 { | |
92 type = t1; // t1 is complex | |
93 } | |
94 } | |
95 return this; | |
96 } | |
97 | |
72 | 98 override Expression optimize(int result) |
0 | 99 { |
100 Expression e; | |
101 | |
102 //printf("MulExp.optimize(result = %d) %s\n", result, toChars()); | |
103 e1 = e1.optimize(result); | |
104 e2 = e2.optimize(result); | |
105 if (e1.isConst() == 1 && e2.isConst() == 1) | |
106 { | |
107 e = Mul(type, e1, e2); | |
108 } | |
109 else | |
110 e = this; | |
111 return e; | |
112 } | |
113 | |
72 | 114 override Expression interpret(InterState istate) |
0 | 115 { |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
116 return interpretCommon(istate, &Mul); |
0 | 117 } |
118 | |
72 | 119 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 120 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
121 Exp_buildArrayIdent(buf, arguments, "Mul"); |
0 | 122 } |
123 | |
72 | 124 override Expression buildArrayLoop(Arguments fparams) |
0 | 125 { |
72 | 126 /* Evaluate assign expressions left to right |
127 */ | |
128 Expression ex1 = e1.buildArrayLoop(fparams); | |
129 Expression ex2 = e2.buildArrayLoop(fparams); | |
130 Expression e = new MulExp(Loc(0), ex1, ex2); | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
131 return e; |
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 |