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