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