Mercurial > projects > ddmd
annotate dmd/IdentityExp.d @ 192:eb38fdcb3e62 default tip
updated to compile with dmd2.062
author | korDen |
---|---|
date | Sat, 02 Mar 2013 01:25:52 -0800 |
parents | 52188e7e3fb5 |
children |
rev | line source |
---|---|
72 | 1 module dmd.IdentityExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
5 import dmd.InterState; | |
6 import dmd.Loc; | |
7 import dmd.Scope; | |
8 import dmd.IRState; | |
9 import dmd.BinExp; | |
0 | 10 import dmd.TOK; |
11 import dmd.Type; | |
12 import dmd.WANT; | |
13 import dmd.TY; | |
73 | 14 import dmd.GlobalExpressions; |
72 | 15 import dmd.expression.Identity; |
16 | |
0 | 17 import dmd.backend.elem; |
18 import dmd.backend.TYM; | |
19 import dmd.backend.OPER; | |
20 import dmd.backend.Util; | |
72 | 21 import dmd.codegen.Util; |
22 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
23 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
24 |
0 | 25 class IdentityExp : BinExp |
26 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
27 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
28 |
0 | 29 this(TOK op, Loc loc, Expression e1, Expression e2) |
30 { | |
178 | 31 register(); |
0 | 32 super(loc, op, IdentityExp.sizeof, e1, e2); |
33 } | |
34 | |
72 | 35 override Expression semantic(Scope sc) |
0 | 36 { |
37 if (type) | |
38 return this; | |
39 | |
40 BinExp.semanticp(sc); | |
41 type = Type.tboolean; | |
42 typeCombine(sc); | |
43 | |
44 if (e1.type != e2.type && e1.type.isfloating() && e2.type.isfloating()) | |
45 { | |
46 // Cast both to complex | |
47 e1 = e1.castTo(sc, Type.tcomplex80); | |
48 e2 = e2.castTo(sc, Type.tcomplex80); | |
49 } | |
50 | |
51 return this; | |
52 } | |
53 | |
191
52188e7e3fb5
Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents:
187
diff
changeset
|
54 override bool isBit() |
0 | 55 { |
56 assert(false); | |
57 } | |
58 | |
72 | 59 override Expression optimize(int result) |
0 | 60 { |
61 //printf("IdentityExp.optimize(result = %d) %s\n", result, toChars()); | |
62 e1 = e1.optimize(WANT.WANTvalue | (result & WANT.WANTinterpret)); | |
63 e2 = e2.optimize(WANT.WANTvalue | (result & WANT.WANTinterpret)); | |
135 | 64 Expression e = this; |
0 | 65 |
66 if ((this.e1.isConst() && this.e2.isConst()) || (this.e1.op == TOK.TOKnull && this.e2.op == TOK.TOKnull)) | |
67 { | |
68 e = Identity(op, type, this.e1, this.e2); | |
73 | 69 if (e is EXP_CANT_INTERPRET) |
70 e = this; | |
0 | 71 } |
72 | |
73 return e; | |
74 } | |
75 | |
72 | 76 override Expression interpret(InterState istate) |
0 | 77 { |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
78 return interpretCommon2(istate, &Identity); |
0 | 79 } |
80 | |
72 | 81 override elem* toElem(IRState* irs) |
0 | 82 { |
83 elem *e; | |
84 OPER eop; | |
85 Type t1 = e1.type.toBasetype(); | |
86 Type t2 = e2.type.toBasetype(); | |
87 | |
88 switch (op) | |
89 { | |
90 case TOK.TOKidentity: eop = OPER.OPeqeq; break; | |
91 case TOK.TOKnotidentity: eop = OPER.OPne; break; | |
92 default: | |
93 dump(0); | |
94 assert(0); | |
95 } | |
96 | |
97 //printf("IdentityExp.toElem() %s\n", toChars()); | |
98 | |
99 if (t1.ty == TY.Tstruct) | |
100 { | |
101 // Do bit compare of struct's | |
102 elem* es1; | |
103 elem* es2; | |
104 elem* ecount; | |
105 | |
106 es1 = e1.toElem(irs); | |
107 es1 = addressElem(es1, e1.type); | |
108 //es1 = el_una(OPaddr, TYnptr, es1); | |
109 es2 = e2.toElem(irs); | |
110 es2 = addressElem(es2, e2.type); | |
111 //es2 = el_una(OPaddr, TYnptr, es2); | |
112 e = el_param(es1, es2); | |
113 ecount = el_long(TYM.TYint, t1.size()); | |
114 e = el_bin(OPER.OPmemcmp, TYM.TYint, e, ecount); | |
115 e = el_bin(eop, TYM.TYint, e, el_long(TYM.TYint, 0)); | |
116 el_setLoc(e,loc); | |
117 } | |
118 else if ((t1.ty == TY.Tarray || t1.ty == TY.Tsarray) && (t2.ty == TY.Tarray || t2.ty == TY.Tsarray)) | |
119 { | |
120 elem* ea1; | |
121 elem* ea2; | |
122 | |
123 ea1 = e1.toElem(irs); | |
124 ea1 = array_toDarray(t1, ea1); | |
125 ea2 = e2.toElem(irs); | |
126 ea2 = array_toDarray(t2, ea2); | |
127 | |
128 e = el_bin(eop, type.totym(), ea1, ea2); | |
129 el_setLoc(e,loc); | |
130 } | |
131 else | |
132 e = toElemBin(irs, eop); | |
133 | |
134 return e; | |
135 } | |
136 } | |
137 |