Mercurial > projects > ddmd
annotate dmd/DivAssignExp.d @ 117:fe941d774f4a
+ ctfe of assign operations
author | Trass3r |
---|---|
date | Thu, 02 Sep 2010 02:50:19 +0200 |
parents | e28b18c23469 |
children | 9e39c7de8438 |
rev | line source |
---|---|
0 | 1 module dmd.DivAssignExp; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.BinExp; |
5 import dmd.Loc; | |
6 import dmd.Expression; | |
7 import dmd.Scope; | |
8 import dmd.InterState; | |
9 import dmd.OutBuffer; | |
10 import dmd.ArrayTypes; | |
11 import dmd.Identifier; | |
12 import dmd.IRState; | |
13 import dmd.TOK; | |
14 import dmd.Type; | |
15 import dmd.TY; | |
16 import dmd.Id; | |
17 import dmd.CommaExp; | |
18 import dmd.RealExp; | |
19 import dmd.AssignExp; | |
20 | |
21 import dmd.backend.elem; | |
22 import dmd.backend.OPER; | |
23 import dmd.backend.Util; | |
117 | 24 import dmd.expression.Div; |
0 | 25 import dmd.expression.Util; |
26 | |
27 class DivAssignExp : BinExp | |
28 { | |
29 this(Loc loc, Expression e1, Expression e2) | |
30 { | |
31 super(loc, TOK.TOKdivass, DivAssignExp.sizeof, e1, e2); | |
32 } | |
33 | |
72 | 34 override Expression semantic(Scope sc) |
0 | 35 { |
36 Expression e; | |
37 | |
38 BinExp.semantic(sc); | |
39 e2 = resolveProperties(sc, e2); | |
40 | |
41 e = op_overload(sc); | |
42 if (e) | |
43 return e; | |
44 | |
45 if (e1.op == TOKslice) | |
46 { // T[] -= ... | |
47 typeCombine(sc); | |
48 type = e1.type; | |
49 return arrayOp(sc); | |
50 } | |
51 | |
52 e1 = e1.modifiableLvalue(sc, e1); | |
53 e1.checkScalar(); | |
54 e1.checkNoBool(); | |
55 type = e1.type; | |
56 typeCombine(sc); | |
57 e1.checkArithmetic(); | |
58 e2.checkArithmetic(); | |
73 | 59 checkComplexMulAssign(); |
0 | 60 if (e2.type.isimaginary()) |
61 { | |
62 Type t1; | |
63 Type t2; | |
64 | |
65 t1 = e1.type; | |
66 if (t1.isreal()) | |
67 { | |
68 // x/iv = i(-x/v) | |
69 // Therefore, the result is 0 | |
70 e2 = new CommaExp(loc, e2, new RealExp(loc, 0, t1)); | |
71 e2.type = t1; | |
72 e = new AssignExp(loc, e1, e2); | |
73 e.type = t1; | |
74 return e; | |
75 } | |
76 else if (t1.isimaginary()) | |
77 { | |
78 Expression e3; | |
79 | |
80 switch (t1.ty) | |
81 { | |
82 case Timaginary32: t2 = Type.tfloat32; break; | |
83 case Timaginary64: t2 = Type.tfloat64; break; | |
84 case Timaginary80: t2 = Type.tfloat80; break; | |
85 default: | |
86 assert(0); | |
87 } | |
88 e2 = e2.castTo(sc, t2); | |
89 e3 = new AssignExp(loc, e1, e2); | |
90 e3.type = t1; | |
91 return e3; | |
92 } | |
93 } | |
94 return this; | |
95 } | |
96 | |
72 | 97 override Expression interpret(InterState istate) |
0 | 98 { |
117 | 99 return interpretAssignCommon(istate, &Div); |
0 | 100 } |
101 | |
72 | 102 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 103 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
104 AssignExp_buildArrayIdent(buf, arguments, "Div"); |
0 | 105 } |
106 | |
72 | 107 override Expression buildArrayLoop(Arguments fparams) |
0 | 108 { |
109 assert(false); | |
110 } | |
111 | |
72 | 112 override Identifier opId() /* For operator overloading */ |
0 | 113 { |
114 return Id.divass; | |
115 } | |
116 | |
72 | 117 override elem* toElem(IRState* irs) |
0 | 118 { |
119 return toElemBin(irs,OPdivass); | |
120 } | |
72 | 121 } |