annotate dmd/IdentityExp.d @ 63:cab4c37afb89

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