Mercurial > projects > ddmd
annotate dmd/XorExp.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.XorExp; |
2 | |
3 import dmd.Expression; | |
4 import dmd.Identifier; | |
5 import dmd.InterState; | |
0 | 6 import dmd.MATCH; |
72 | 7 import dmd.Id; |
8 import dmd.Type; | |
9 import dmd.OutBuffer; | |
10 import dmd.Loc; | |
11 import dmd.Scope; | |
12 import dmd.IntRange; | |
13 import dmd.IRState; | |
14 import dmd.ArrayTypes; | |
15 import dmd.BinExp; | |
0 | 16 import dmd.TOK; |
72 | 17 import dmd.TY; |
18 | |
19 import dmd.backend.elem; | |
67 | 20 import dmd.backend.OPER; |
0 | 21 import dmd.expression.Util; |
72 | 22 import dmd.expression.Xor; |
23 | |
0 | 24 class XorExp : BinExp |
25 { | |
26 this(Loc loc, Expression e1, Expression e2) | |
27 { | |
28 super(loc, TOK.TOKxor, XorExp.sizeof, e1, e2); | |
29 } | |
30 | |
72 | 31 override Expression semantic(Scope sc) |
0 | 32 { |
33 Expression e; | |
34 | |
35 if (!type) | |
36 { | |
37 BinExp.semanticp(sc); | |
38 e = op_overload(sc); | |
39 if (e) | |
40 return e; | |
41 if (e1.type.toBasetype().ty == Tbool && | |
42 e2.type.toBasetype().ty == Tbool) | |
43 { | |
44 type = e1.type; | |
45 e = this; | |
46 } | |
47 else | |
48 { | |
49 typeCombine(sc); | |
109 | 50 if (!e1.isArrayOperand()) |
0 | 51 e1.checkIntegral(); |
109 | 52 if (!e2.isArrayOperand()) |
0 | 53 e2.checkIntegral(); |
54 } | |
55 } | |
56 return this; | |
57 } | |
58 | |
72 | 59 override Expression optimize(int result) |
0 | 60 { |
61 Expression e; | |
62 | |
63 e1 = e1.optimize(result); | |
64 e2 = e2.optimize(result); | |
65 if (e1.isConst() == 1 && e2.isConst() == 1) | |
66 e = Xor(type, e1, e2); | |
67 else | |
68 e = this; | |
69 | |
70 return e; | |
71 } | |
72 | |
72 | 73 override Expression interpret(InterState istate) |
0 | 74 { |
75 assert(false); | |
76 } | |
77 | |
72 | 78 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 79 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
80 Exp_buildArrayIdent(buf, arguments, "Xor"); |
0 | 81 } |
82 | |
72 | 83 override Expression buildArrayLoop(Arguments fparams) |
0 | 84 { |
72 | 85 /* Evaluate assign expressions left to right |
86 */ | |
87 Expression ex1 = e1.buildArrayLoop(fparams); | |
88 Expression ex2 = e2.buildArrayLoop(fparams); | |
89 Expression e = new XorExp(Loc(0), ex1, ex2); | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
90 return e; |
0 | 91 } |
92 | |
72 | 93 override MATCH implicitConvTo(Type t) |
0 | 94 { |
72 | 95 MATCH result = Expression.implicitConvTo(t); |
96 | |
97 if (result == MATCHnomatch) | |
98 { | |
99 MATCH m1 = e1.implicitConvTo(t); | |
100 MATCH m2 = e2.implicitConvTo(t); | |
101 | |
102 // Pick the worst match | |
103 result = (m1 < m2) ? m1 : m2; | |
104 } | |
56 | 105 return result; |
0 | 106 } |
107 | |
72 | 108 override IntRange getIntRange() |
0 | 109 { |
110 assert(false); | |
111 } | |
112 | |
72 | 113 override bool isCommutative() |
0 | 114 { |
115 return true; | |
116 } | |
117 | |
72 | 118 override Identifier opId() |
0 | 119 { |
120 return Id.ixor; | |
121 } | |
122 | |
72 | 123 override Identifier opId_r() |
0 | 124 { |
125 return Id.ixor_r; | |
126 } | |
127 | |
72 | 128 override elem* toElem(IRState* irs) |
0 | 129 { |
67 | 130 return toElemBin(irs,OPxor); |
0 | 131 } |
132 } | |
133 |