Mercurial > projects > ddmd
annotate dmd/AndExp.d @ 12:832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
Some unittest-specific functions implemented
author | korDen |
---|---|
date | Mon, 12 Apr 2010 15:13:00 +0400 |
parents | 10317f0c89a5 |
children | a8b50ff7f201 |
rev | line source |
---|---|
0 | 1 module dmd.AndExp; |
2 | |
3 import dmd.Expression; | |
4 import dmd.Identifier; | |
5 import dmd.InterState; | |
6 import dmd.OutBuffer; | |
7 import dmd.Loc; | |
8 import dmd.Scope; | |
9 import dmd.IntRange; | |
10 import dmd.IRState; | |
11 import dmd.BinExp; | |
12 import dmd.TOK; | |
13 import dmd.ArrayTypes; | |
14 import dmd.TY; | |
15 import dmd.Type; | |
16 import dmd.Id; | |
17 import dmd.Global; | |
18 | |
19 import dmd.backend.elem; | |
20 import dmd.backend.Util; | |
21 import dmd.backend.OPER; | |
22 import dmd.expression.Util; | |
23 import dmd.expression.And; | |
24 | |
25 class AndExp : BinExp | |
26 { | |
27 this(Loc loc, Expression e1, Expression e2) | |
28 { | |
29 super(loc, TOK.TOKand, AndExp.sizeof, e1, e2); | |
30 } | |
31 | |
32 Expression semantic(Scope sc) | |
33 { | |
34 Expression e; | |
35 | |
36 if (!type) | |
37 { | |
38 BinExp.semanticp(sc); | |
39 e = op_overload(sc); | |
40 | |
41 if (e) | |
42 return e; | |
43 | |
44 if (e1.type.toBasetype().ty == TY.Tbool && e2.type.toBasetype().ty == TY.Tbool) | |
45 { | |
46 type = e1.type; | |
47 e = this; | |
48 } | |
49 else | |
50 { | |
51 typeCombine(sc); | |
52 if (e1.op != TOK.TOKslice && e2.op != TOK.TOKslice) | |
53 { | |
54 e1.checkIntegral(); | |
55 e2.checkIntegral(); | |
56 } | |
57 } | |
58 } | |
59 return this; | |
60 } | |
61 | |
62 Expression optimize(int result) | |
63 { | |
64 Expression e; | |
65 | |
66 e1 = e1.optimize(result); | |
67 e2 = e2.optimize(result); | |
68 if (e1.isConst() == 1 && e2.isConst() == 1) | |
69 e = And(type, e1, e2); | |
70 else | |
71 e = this; | |
72 | |
73 return e; | |
74 } | |
75 | |
76 Expression interpret(InterState* istate) | |
77 { | |
78 assert(false); | |
79 } | |
80 | |
81 void buildArrayIdent(OutBuffer buf, Expressions arguments) | |
82 { | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
83 Exp_buildArrayIdent(buf, arguments, "And"); |
0 | 84 } |
85 | |
86 Expression buildArrayLoop(Arguments fparams) | |
87 { | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
88 /* Evaluate assign expressions left to right |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
89 */ |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
90 Expression ex1 = e1.buildArrayLoop(fparams); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
91 Expression ex2 = e2.buildArrayLoop(fparams); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
92 Expression e = new AndExp(Loc(0), ex1, ex2); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
93 return e; |
0 | 94 } |
95 | |
96 IntRange getIntRange() | |
97 { | |
98 assert(false); | |
99 } | |
100 | |
101 bool isCommutative() | |
102 { | |
103 return true; | |
104 } | |
105 | |
106 Identifier opId() | |
107 { | |
108 return Id.iand; | |
109 } | |
110 | |
111 Identifier opId_r() | |
112 { | |
113 return Id.iand_r; | |
114 } | |
115 | |
116 elem* toElem(IRState* irs) | |
117 { | |
118 return toElemBin(irs, OPER.OPand); | |
119 } | |
120 } | |
121 |