Mercurial > projects > ddmd
annotate dmd/XorExp.d @ 178:e3afd1303184
Many small bugs fixed
Made all classes derive from TObject to detect memory leaks (functionality is disabled for now)
Began work on overriding backend memory allocations (to avoid memory leaks)
author | korDen |
---|---|
date | Sun, 17 Oct 2010 07:42:00 +0400 |
parents | 60bb0fe4563e |
children | b0d41ff5e0df |
rev | line source |
---|---|
72 | 1 module dmd.XorExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
5 import dmd.Identifier; | |
6 import dmd.InterState; | |
0 | 7 import dmd.MATCH; |
72 | 8 import dmd.Id; |
9 import dmd.Type; | |
10 import dmd.OutBuffer; | |
11 import dmd.Loc; | |
12 import dmd.Scope; | |
13 import dmd.IntRange; | |
14 import dmd.IRState; | |
15 import dmd.ArrayTypes; | |
16 import dmd.BinExp; | |
0 | 17 import dmd.TOK; |
72 | 18 import dmd.TY; |
19 | |
20 import dmd.backend.elem; | |
67 | 21 import dmd.backend.OPER; |
0 | 22 import dmd.expression.Util; |
72 | 23 import dmd.expression.Xor; |
24 | |
0 | 25 class XorExp : BinExp |
26 { | |
27 this(Loc loc, Expression e1, Expression e2) | |
28 { | |
178 | 29 register(); |
0 | 30 super(loc, TOK.TOKxor, XorExp.sizeof, e1, e2); |
31 } | |
32 | |
72 | 33 override Expression semantic(Scope sc) |
0 | 34 { |
35 Expression e; | |
36 | |
37 if (!type) | |
38 { | |
39 BinExp.semanticp(sc); | |
40 e = op_overload(sc); | |
41 if (e) | |
42 return e; | |
43 if (e1.type.toBasetype().ty == Tbool && | |
44 e2.type.toBasetype().ty == Tbool) | |
45 { | |
46 type = e1.type; | |
47 e = this; | |
48 } | |
49 else | |
50 { | |
51 typeCombine(sc); | |
109 | 52 if (!e1.isArrayOperand()) |
0 | 53 e1.checkIntegral(); |
109 | 54 if (!e2.isArrayOperand()) |
0 | 55 e2.checkIntegral(); |
56 } | |
57 } | |
58 return this; | |
59 } | |
60 | |
72 | 61 override Expression optimize(int result) |
0 | 62 { |
63 Expression e; | |
64 | |
65 e1 = e1.optimize(result); | |
66 e2 = e2.optimize(result); | |
67 if (e1.isConst() == 1 && e2.isConst() == 1) | |
68 e = Xor(type, e1, e2); | |
69 else | |
70 e = this; | |
71 | |
72 return e; | |
73 } | |
74 | |
72 | 75 override Expression interpret(InterState istate) |
0 | 76 { |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
77 return interpretCommon(istate, &Xor); |
0 | 78 } |
79 | |
72 | 80 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 81 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
82 Exp_buildArrayIdent(buf, arguments, "Xor"); |
0 | 83 } |
84 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
85 override Expression buildArrayLoop(Parameters fparams) |
0 | 86 { |
123 | 87 return Exp_buildArrayLoop!(typeof(this))(fparams); |
0 | 88 } |
89 | |
72 | 90 override MATCH implicitConvTo(Type t) |
0 | 91 { |
72 | 92 MATCH result = Expression.implicitConvTo(t); |
93 | |
94 if (result == MATCHnomatch) | |
95 { | |
96 MATCH m1 = e1.implicitConvTo(t); | |
97 MATCH m2 = e2.implicitConvTo(t); | |
98 | |
99 // Pick the worst match | |
100 result = (m1 < m2) ? m1 : m2; | |
101 } | |
56 | 102 return result; |
0 | 103 } |
104 | |
72 | 105 override IntRange getIntRange() |
0 | 106 { |
107 assert(false); | |
108 } | |
109 | |
72 | 110 override bool isCommutative() |
0 | 111 { |
112 return true; | |
113 } | |
114 | |
72 | 115 override Identifier opId() |
0 | 116 { |
117 return Id.ixor; | |
118 } | |
119 | |
72 | 120 override Identifier opId_r() |
0 | 121 { |
122 return Id.ixor_r; | |
123 } | |
124 | |
72 | 125 override elem* toElem(IRState* irs) |
0 | 126 { |
67 | 127 return toElemBin(irs,OPxor); |
0 | 128 } |
129 } | |
130 |