Mercurial > projects > ddmd
annotate dmd/MulAssignExp.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.MulAssignExp; |
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.Id; | |
11 import dmd.ArrayTypes; | |
12 import dmd.Identifier; | |
13 import dmd.IRState; | |
14 import dmd.TOK; | |
15 import dmd.Type; | |
16 import dmd.TY; | |
17 | |
18 import dmd.backend.elem; | |
19 import dmd.backend.OPER; | |
117 | 20 import dmd.expression.Mul; |
0 | 21 import dmd.expression.Util; |
22 | |
23 class MulAssignExp : BinExp | |
24 { | |
25 this(Loc loc, Expression e1, Expression e2) | |
26 { | |
27 super(loc, TOK.TOKmulass, MulAssignExp.sizeof, e1, e2); | |
28 } | |
29 | |
72 | 30 override Expression semantic(Scope sc) |
0 | 31 { |
32 Expression e; | |
33 | |
34 BinExp.semantic(sc); | |
35 e2 = resolveProperties(sc, e2); | |
36 | |
37 e = op_overload(sc); | |
38 if (e) | |
39 return e; | |
40 | |
41 if (e1.op == TOKslice) | |
42 { // T[] -= ... | |
43 typeCombine(sc); | |
44 type = e1.type; | |
45 return arrayOp(sc); | |
46 } | |
47 | |
48 e1 = e1.modifiableLvalue(sc, e1); | |
49 e1.checkScalar(); | |
50 e1.checkNoBool(); | |
51 type = e1.type; | |
52 typeCombine(sc); | |
53 e1.checkArithmetic(); | |
54 e2.checkArithmetic(); | |
73 | 55 checkComplexMulAssign(); |
0 | 56 if (e2.type.isfloating()) |
57 { | |
58 Type t1; | |
59 Type t2; | |
60 | |
61 t1 = e1.type; | |
62 t2 = e2.type; | |
63 if (t1.isreal()) | |
64 { | |
65 if (t2.isimaginary() || t2.iscomplex()) | |
66 { | |
67 e2 = e2.castTo(sc, t1); | |
68 } | |
69 } | |
70 else if (t1.isimaginary()) | |
71 { | |
72 if (t2.isimaginary() || t2.iscomplex()) | |
73 { | |
74 switch (t1.ty) | |
75 { | |
76 case Timaginary32: t2 = Type.tfloat32; break; | |
77 case Timaginary64: t2 = Type.tfloat64; break; | |
78 case Timaginary80: t2 = Type.tfloat80; break; | |
79 default: | |
80 assert(0); | |
81 } | |
82 e2 = e2.castTo(sc, t2); | |
83 } | |
84 } | |
85 } | |
86 return this; | |
87 } | |
88 | |
72 | 89 override Expression interpret(InterState istate) |
0 | 90 { |
117 | 91 return interpretAssignCommon(istate, &Mul); |
0 | 92 } |
93 | |
72 | 94 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 95 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
96 AssignExp_buildArrayIdent(buf, arguments, "Mul"); |
0 | 97 } |
98 | |
72 | 99 override Expression buildArrayLoop(Arguments fparams) |
0 | 100 { |
101 assert(false); | |
102 } | |
103 | |
72 | 104 override Identifier opId() /* For operator overloading */ |
0 | 105 { |
106 return Id.mulass; | |
107 } | |
108 | |
72 | 109 override elem* toElem(IRState* irs) |
0 | 110 { |
111 return toElemBin(irs,OPmulass); | |
112 } | |
72 | 113 } |