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