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