annotate dmd/IdentityExp.d @ 135:af1bebfd96a4 dmd2037

dmd 2.038
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Mon, 13 Sep 2010 22:19:42 +0100
parents 6caaf0256da1
children e3afd1303184
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 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 super(loc, op, IdentityExp.sizeof, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
30 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 if (type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 BinExp.semanticp(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 type = Type.tboolean;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 typeCombine(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 if (e1.type != e2.type && e1.type.isfloating() && e2.type.isfloating())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 // Cast both to complex
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 e1 = e1.castTo(sc, Type.tcomplex80);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 e2 = e2.castTo(sc, Type.tcomplex80);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
49 override int isBit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
54 override Expression optimize(int result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 //printf("IdentityExp.optimize(result = %d) %s\n", result, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 e1 = e1.optimize(WANT.WANTvalue | (result & WANT.WANTinterpret));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 e2 = e2.optimize(WANT.WANTvalue | (result & WANT.WANTinterpret));
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 115
diff changeset
59 Expression e = this;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 if ((this.e1.isConst() && this.e2.isConst()) || (this.e1.op == TOK.TOKnull && this.e2.op == TOK.TOKnull))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 e = Identity(op, type, this.e1, this.e2);
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
64 if (e is EXP_CANT_INTERPRET)
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
65 e = this;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
71 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 {
115
6caaf0256da1 + interpretation of (non-assign) binary expressions
Trass3r
parents: 114
diff changeset
73 return interpretCommon2(istate, &Identity);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
76 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 elem *e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 OPER eop;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 Type t1 = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 Type t2 = e2.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 switch (op)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 case TOK.TOKidentity: eop = OPER.OPeqeq; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 case TOK.TOKnotidentity: eop = OPER.OPne; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 dump(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 //printf("IdentityExp.toElem() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 if (t1.ty == TY.Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 // Do bit compare of struct's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 elem* es1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 elem* es2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 elem* ecount;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 es1 = e1.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 es1 = addressElem(es1, e1.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 //es1 = el_una(OPaddr, TYnptr, es1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 es2 = e2.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 es2 = addressElem(es2, e2.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 //es2 = el_una(OPaddr, TYnptr, es2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 e = el_param(es1, es2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 ecount = el_long(TYM.TYint, t1.size());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 e = el_bin(OPER.OPmemcmp, TYM.TYint, e, ecount);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 e = el_bin(eop, TYM.TYint, e, el_long(TYM.TYint, 0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 el_setLoc(e,loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 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
114 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 elem* ea1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 elem* ea2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 ea1 = e1.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 ea1 = array_toDarray(t1, ea1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 ea2 = e2.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 ea2 = array_toDarray(t2, ea2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 e = el_bin(eop, type.totym(), ea1, ea2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 el_setLoc(e,loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 e = toElemBin(irs, eop);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132