Mercurial > projects > ddmd
annotate dmd/XorExp.d @ 67:f708f0452e81
some of the backend/codegen stuff implemented
author | korDen |
---|---|
date | Mon, 23 Aug 2010 21:21:05 +0400 |
parents | cab4c37afb89 |
children | 2e2a5c3f943a |
rev | line source |
---|---|
0 | 1 module dmd.XorExp; |
2 | |
3 import dmd.Expression; | |
4 import dmd.Identifier; | |
5 import dmd.InterState; | |
6 import dmd.MATCH; | |
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; | |
16 import dmd.TOK; | |
17 import dmd.TY; | |
18 | |
67 | 19 import dmd.backend.elem; |
20 import dmd.backend.OPER; | |
0 | 21 import dmd.expression.Util; |
22 import dmd.expression.Xor; | |
23 | |
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 | |
31 Expression semantic(Scope sc) | |
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); | |
50 if (e1.op != TOKslice && e2.op != TOKslice) | |
51 { | |
52 e1.checkIntegral(); | |
53 e2.checkIntegral(); | |
54 } | |
55 } | |
56 } | |
57 return this; | |
58 } | |
59 | |
60 Expression optimize(int result) | |
61 { | |
62 Expression e; | |
63 | |
64 e1 = e1.optimize(result); | |
65 e2 = e2.optimize(result); | |
66 if (e1.isConst() == 1 && e2.isConst() == 1) | |
67 e = Xor(type, e1, e2); | |
68 else | |
69 e = this; | |
70 | |
71 return e; | |
72 } | |
73 | |
63 | 74 Expression interpret(InterState istate) |
0 | 75 { |
76 assert(false); | |
77 } | |
78 | |
79 void buildArrayIdent(OutBuffer buf, Expressions arguments) | |
80 { | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
81 Exp_buildArrayIdent(buf, arguments, "Xor"); |
0 | 82 } |
83 | |
84 Expression buildArrayLoop(Arguments fparams) | |
85 { | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
86 /* Evaluate assign expressions left to right |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
87 */ |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
88 Expression ex1 = e1.buildArrayLoop(fparams); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
89 Expression ex2 = e2.buildArrayLoop(fparams); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
90 Expression e = new XorExp(Loc(0), ex1, ex2); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
91 return e; |
0 | 92 } |
93 | |
94 MATCH implicitConvTo(Type t) | |
95 { | |
56 | 96 MATCH result = Expression.implicitConvTo(t); |
97 | |
98 if (result == MATCHnomatch) | |
99 { | |
100 MATCH m1 = e1.implicitConvTo(t); | |
101 MATCH m2 = e2.implicitConvTo(t); | |
102 | |
103 // Pick the worst match | |
104 result = (m1 < m2) ? m1 : m2; | |
105 } | |
106 return result; | |
0 | 107 } |
108 | |
109 IntRange getIntRange() | |
110 { | |
111 assert(false); | |
112 } | |
113 | |
114 bool isCommutative() | |
115 { | |
116 return true; | |
117 } | |
118 | |
119 Identifier opId() | |
120 { | |
121 return Id.ixor; | |
122 } | |
123 | |
124 Identifier opId_r() | |
125 { | |
126 return Id.ixor_r; | |
127 } | |
128 | |
129 elem* toElem(IRState* irs) | |
130 { | |
67 | 131 return toElemBin(irs,OPxor); |
0 | 132 } |
133 } | |
134 |