annotate dmd/IdentityExp.d @ 73:ef02e2e203c2

Updating to dmd2.033
author korDen
date Sat, 28 Aug 2010 19:42:41 +0400
parents 2e2a5c3f943a
children e28b18c23469
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
1 module dmd.IdentityExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
2
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
3 import dmd.Expression;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
4 import dmd.InterState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
5 import dmd.Loc;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
6 import dmd.Scope;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
7 import dmd.IRState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
8 import dmd.BinExp;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.TY;
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
13 import dmd.GlobalExpressions;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
14 import dmd.expression.Identity;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
15
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.backend.OPER;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.backend.Util;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
20 import dmd.codegen.Util;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
21
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 class IdentityExp : BinExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 this(TOK op, Loc loc, Expression e1, Expression e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 super(loc, op, IdentityExp.sizeof, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
29 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 if (type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 BinExp.semanticp(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 type = Type.tboolean;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 typeCombine(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 if (e1.type != e2.type && e1.type.isfloating() && e2.type.isfloating())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 // Cast both to complex
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 e1 = e1.castTo(sc, Type.tcomplex80);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 e2 = e2.castTo(sc, Type.tcomplex80);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
48 override int isBit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
53 override Expression optimize(int result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 //printf("IdentityExp.optimize(result = %d) %s\n", result, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 e1 = e1.optimize(WANT.WANTvalue | (result & WANT.WANTinterpret));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 e2 = e2.optimize(WANT.WANTvalue | (result & WANT.WANTinterpret));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 if ((this.e1.isConst() && this.e2.isConst()) || (this.e1.op == TOK.TOKnull && this.e2.op == TOK.TOKnull))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 e = Identity(op, type, this.e1, this.e2);
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
65 if (e is EXP_CANT_INTERPRET)
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
66 e = this;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
72 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
77 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 elem *e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 OPER eop;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 Type t1 = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 Type t2 = e2.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 switch (op)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 case TOK.TOKidentity: eop = OPER.OPeqeq; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 case TOK.TOKnotidentity: eop = OPER.OPne; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 dump(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 //printf("IdentityExp.toElem() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 if (t1.ty == TY.Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 // Do bit compare of struct's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 elem* es1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 elem* es2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 elem* ecount;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 es1 = e1.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 es1 = addressElem(es1, e1.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 //es1 = el_una(OPaddr, TYnptr, es1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 es2 = e2.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 es2 = addressElem(es2, e2.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 //es2 = el_una(OPaddr, TYnptr, es2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 e = el_param(es1, es2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 ecount = el_long(TYM.TYint, t1.size());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 e = el_bin(OPER.OPmemcmp, TYM.TYint, e, ecount);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 e = el_bin(eop, TYM.TYint, e, el_long(TYM.TYint, 0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 el_setLoc(e,loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 else if ((t1.ty == TY.Tarray || t1.ty == TY.Tsarray) && (t2.ty == TY.Tarray || t2.ty == TY.Tsarray))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 elem* ea1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 elem* ea2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 ea1 = e1.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 ea1 = array_toDarray(t1, ea1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 ea2 = e2.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 ea2 = array_toDarray(t2, ea2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 e = el_bin(eop, type.totym(), ea1, ea2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 el_setLoc(e,loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 e = toElemBin(irs, eop);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133