72
|
1 module dmd.AndAndExp;
|
|
2
|
114
|
3 import dmd.common;
|
72
|
4 import dmd.Expression;
|
|
5 import dmd.InterState;
|
|
6 import dmd.Loc;
|
|
7 import dmd.Scope;
|
0
|
8 import dmd.IRState;
|
|
9 import dmd.CommaExp;
|
|
10 import dmd.Global;
|
72
|
11 import dmd.BoolExp;
|
|
12 import dmd.BinExp;
|
0
|
13 import dmd.TOK;
|
|
14 import dmd.WANT;
|
|
15 import dmd.IntegerExp;
|
|
16 import dmd.Type;
|
72
|
17 import dmd.TY;
|
|
18
|
0
|
19 import dmd.backend.elem;
|
|
20 import dmd.backend.OPER;
|
72
|
21 import dmd.backend.Util;
|
|
22
|
0
|
23 class AndAndExp : BinExp
|
|
24 {
|
|
25 this(Loc loc, Expression e1, Expression e2)
|
|
26 {
|
|
27 super(loc, TOK.TOKandand, AndAndExp.sizeof, e1, e2);
|
|
28 }
|
|
29
|
72
|
30 override Expression semantic(Scope sc)
|
0
|
31 {
|
|
32 uint cs1;
|
|
33
|
|
34 // same as for OrOr
|
|
35 e1 = e1.semantic(sc);
|
|
36 e1 = resolveProperties(sc, e1);
|
|
37 e1 = e1.checkToPointer();
|
|
38 e1 = e1.checkToBoolean();
|
|
39 cs1 = sc.callSuper;
|
|
40
|
|
41 if (sc.flags & SCOPE.SCOPEstaticif)
|
|
42 {
|
|
43 /* If in static if, don't evaluate e2 if we don't have to.
|
|
44 */
|
|
45 e1 = e1.optimize(WANTflags);
|
|
46 if (e1.isBool(false))
|
|
47 {
|
|
48 return new IntegerExp(loc, 0, Type.tboolean);
|
|
49 }
|
|
50 }
|
|
51
|
|
52 e2 = e2.semantic(sc);
|
|
53 sc.mergeCallSuper(loc, cs1);
|
|
54 e2 = resolveProperties(sc, e2);
|
|
55 e2 = e2.checkToPointer();
|
|
56
|
|
57 type = Type.tboolean;
|
|
58 if (e2.type.ty == Tvoid)
|
|
59 type = Type.tvoid;
|
|
60 if (e2.op == TOKtype || e2.op == TOKimport)
|
|
61 error("%s is not an expression", e2.toChars());
|
|
62 return this;
|
|
63 }
|
|
64
|
72
|
65 override Expression checkToBoolean()
|
0
|
66 {
|
|
67 e2 = e2.checkToBoolean();
|
|
68 return this;
|
|
69 }
|
|
70
|
72
|
71 override int isBit()
|
0
|
72 {
|
|
73 assert(false);
|
|
74 }
|
|
75
|
72
|
76 override Expression optimize(int result)
|
0
|
77 {
|
|
78 //printf("AndAndExp::optimize(%d) %s\n", result, toChars());
|
|
79 e1 = e1.optimize(WANTflags | (result & WANTinterpret));
|
|
80 Expression e = this;
|
|
81 if (e1.isBool(false))
|
|
82 {
|
|
83 e = new CommaExp(loc, e1, new IntegerExp(loc, 0, type));
|
|
84 e.type = type;
|
|
85 e = e.optimize(result);
|
|
86 }
|
|
87 else
|
|
88 {
|
|
89 e2 = e2.optimize(WANTflags | (result & WANTinterpret));
|
|
90 if (result && e2.type.toBasetype().ty == Tvoid && !global.errors)
|
|
91 error("void has no value");
|
|
92
|
|
93 if (e1.isConst())
|
|
94 {
|
|
95 if (e2.isConst())
|
|
96 {
|
|
97 int n1 = e1.isBool(1);
|
|
98 int n2 = e2.isBool(1);
|
|
99
|
|
100 e = new IntegerExp(loc, n1 && n2, type);
|
|
101 }
|
|
102 else if (e1.isBool(true))
|
|
103 e = new BoolExp(loc, e2, type);
|
|
104 }
|
|
105 }
|
|
106 return e;
|
|
107 }
|
|
108
|
72
|
109 override Expression interpret(InterState istate)
|
0
|
110 {
|
|
111 assert(false);
|
|
112 }
|
|
113
|
72
|
114 override bool checkSideEffect(int flag)
|
0
|
115 {
|
|
116 assert(false);
|
|
117 }
|
|
118
|
72
|
119 override elem* toElem(IRState* irs)
|
0
|
120 {
|
|
121 elem* e = toElemBin(irs, OPandand);
|
|
122 if (global.params.cov && e2.loc.linnum)
|
|
123 e.E2() = el_combine(incUsageElem(irs, e2.loc), e.E2);
|
|
124 return e;
|
|
125 }
|
|
126 }
|
|
127
|