0
|
1 module dmd.expression.Identity;
|
|
2
|
114
|
3 import dmd.common;
|
0
|
4 import dmd.Expression;
|
|
5 import dmd.Type;
|
|
6 import dmd.TOK;
|
|
7 import dmd.Loc;
|
|
8 import dmd.SymOffExp;
|
|
9 import dmd.IntegerExp;
|
|
10
|
|
11 import dmd.expression.Equal;
|
|
12
|
|
13 Expression Identity(TOK op, Type type, Expression e1, Expression e2)
|
|
14 {
|
|
15 Expression e;
|
|
16 Loc loc = e1.loc;
|
|
17 int cmp;
|
|
18
|
|
19 if (e1.op == TOK.TOKnull)
|
|
20 {
|
|
21 cmp = (e2.op == TOK.TOKnull);
|
|
22 }
|
|
23 else if (e2.op == TOK.TOKnull)
|
|
24 {
|
|
25 cmp = 0;
|
|
26 }
|
|
27 else if (e1.op == TOK.TOKsymoff && e2.op == TOK.TOKsymoff)
|
|
28 {
|
|
29 SymOffExp es1 = cast(SymOffExp)e1;
|
|
30 SymOffExp es2 = cast(SymOffExp)e2;
|
|
31
|
|
32 cmp = (es1.var == es2.var && es1.offset == es2.offset);
|
|
33 }
|
|
34 else if (e1.isConst() == 1 && e2.isConst() == 1)
|
|
35 return Equal((op == TOK.TOKidentity) ? TOK.TOKequal : TOK.TOKnotequal, type, e1, e2);
|
|
36 else
|
|
37 assert(0);
|
|
38
|
|
39 if (op == TOK.TOKnotidentity)
|
|
40 cmp ^= 1;
|
|
41
|
|
42 return new IntegerExp(loc, cmp, type);
|
|
43 } |