Mercurial > projects > ddmd
annotate dmd/DivExp.d @ 109:ceda59b4d255
expression.c changes, now only ddoc should be left
author | Trass3r |
---|---|
date | Tue, 31 Aug 2010 22:08:52 +0200 |
parents | 2e2a5c3f943a |
children | e28b18c23469 |
rev | line source |
---|---|
72 | 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 | |
0 | 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 | |
72 | 31 override Expression semantic(Scope sc) |
0 | 32 { |
72 | 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); | |
109 | 44 if (!e1.isArrayOperand()) |
72 | 45 e1.checkArithmetic(); |
109 | 46 if (!e2.isArrayOperand()) |
72 | 47 e2.checkArithmetic(); |
109 | 48 |
72 | 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 } | |
0 | 89 return this; |
90 } | |
91 | |
72 | 92 override Expression optimize(int result) |
0 | 93 { |
72 | 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; | |
0 | 105 return e; |
106 } | |
107 | |
72 | 108 override Expression interpret(InterState istate) |
0 | 109 { |
110 assert(false); | |
111 } | |
112 | |
72 | 113 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 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 | |
72 | 118 override Expression buildArrayLoop(Arguments fparams) |
0 | 119 { |
72 | 120 /* Evaluate assign expressions left to right |
121 */ | |
122 Expression ex1 = e1.buildArrayLoop(fparams); | |
123 Expression ex2 = e2.buildArrayLoop(fparams); | |
124 Expression e = new DivExp(Loc(0), ex1, ex2); | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
125 return e; |
0 | 126 } |
127 | |
72 | 128 override IntRange getIntRange() |
0 | 129 { |
130 assert(false); | |
131 } | |
132 | |
72 | 133 override Identifier opId() |
0 | 134 { |
135 return Id.div; | |
136 } | |
137 | |
72 | 138 override Identifier opId_r() |
0 | 139 { |
140 return Id.div_r; | |
141 } | |
142 | |
72 | 143 override elem* toElem(IRState* irs) |
0 | 144 { |
145 return toElemBin(irs,OPdiv); | |
146 } | |
147 } | |
148 |