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