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