annotate dmd/IdentityExp.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 af1bebfd96a4
children b0d41ff5e0df
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
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 73
diff changeset
3 import dmd.common;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
4 import dmd.Expression;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
5 import dmd.InterState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
6 import dmd.Loc;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
7 import dmd.Scope;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
8 import dmd.IRState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
9 import dmd.BinExp;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.TY;
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
14 import dmd.GlobalExpressions;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
15 import dmd.expression.Identity;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
16
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.backend.OPER;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.backend.Util;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
21 import dmd.codegen.Util;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
22
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 class IdentityExp : BinExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 this(TOK op, Loc loc, Expression e1, Expression e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 135
diff changeset
27 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 super(loc, op, IdentityExp.sizeof, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
31 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 if (type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 BinExp.semanticp(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 type = Type.tboolean;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 typeCombine(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 if (e1.type != e2.type && e1.type.isfloating() && e2.type.isfloating())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 // Cast both to complex
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 e1 = e1.castTo(sc, Type.tcomplex80);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 e2 = e2.castTo(sc, Type.tcomplex80);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
50 override int isBit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
55 override Expression optimize(int result)
0
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));
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 115
diff changeset
60 Expression e = this;
0
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 {
115
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
74 return interpretCommon2(istate, &Identity);
0
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