Mercurial > projects > ddmd
comparison dmd/OrOrExp.d @ 0:10317f0c89a5
Initial commit
author | korDen |
---|---|
date | Sat, 24 Oct 2009 08:42:06 +0400 |
parents | |
children | 51605de93870 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:10317f0c89a5 |
---|---|
1 module dmd.OrOrExp; | |
2 | |
3 import dmd.BinExp; | |
4 import dmd.Scope; | |
5 import dmd.InterState; | |
6 import dmd.TOK; | |
7 import dmd.Expression; | |
8 import dmd.Loc; | |
9 import dmd.IRState; | |
10 import dmd.TY; | |
11 import dmd.WANT; | |
12 import dmd.IntegerExp; | |
13 import dmd.Type; | |
14 import dmd.CommaExp; | |
15 import dmd.Global; | |
16 import dmd.BoolExp; | |
17 | |
18 import dmd.expression.Util; | |
19 | |
20 import dmd.backend.elem; | |
21 import dmd.backend.OPER; | |
22 import dmd.backend.Util; | |
23 | |
24 class OrOrExp : BinExp | |
25 { | |
26 this(Loc loc, Expression e1, Expression e2) | |
27 { | |
28 super(loc, TOK.TOKoror, OrOrExp.sizeof, e1, e2); | |
29 } | |
30 | |
31 Expression semantic(Scope sc) | |
32 { | |
33 uint cs1; | |
34 | |
35 // same as for AndAnd | |
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(true)) | |
48 { | |
49 return new IntegerExp(loc, 1, 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 | |
66 Expression checkToBoolean() | |
67 { | |
68 e2 = e2.checkToBoolean(); | |
69 return this; | |
70 } | |
71 | |
72 int isBit() | |
73 { | |
74 assert(false); | |
75 } | |
76 | |
77 Expression optimize(int result) | |
78 { | |
79 Expression e; | |
80 | |
81 e1 = e1.optimize(WANTflags | (result & WANTinterpret)); | |
82 e = this; | |
83 if (e1.isBool(true)) | |
84 { | |
85 // Replace with (e1, 1) | |
86 e = new CommaExp(loc, e1, new IntegerExp(loc, 1, type)); | |
87 e.type = type; | |
88 e = e.optimize(result); | |
89 } | |
90 else | |
91 { | |
92 e2 = e2.optimize(WANTflags | (result & WANTinterpret)); | |
93 if (result && e2.type.toBasetype().ty == Tvoid && !global.errors) | |
94 error("void has no value"); | |
95 if (e1.isConst()) | |
96 { | |
97 if (e2.isConst()) | |
98 { | |
99 int n1 = e1.isBool(1); | |
100 int n2 = e2.isBool(1); | |
101 | |
102 e = new IntegerExp(loc, n1 || n2, type); | |
103 } | |
104 else if (e1.isBool(false)) | |
105 e = new BoolExp(loc, e2, type); | |
106 } | |
107 } | |
108 return e; | |
109 } | |
110 | |
111 Expression interpret(InterState* istate) | |
112 { | |
113 assert(false); | |
114 } | |
115 | |
116 bool checkSideEffect(int flag) | |
117 { | |
118 assert(false); | |
119 } | |
120 | |
121 elem* toElem(IRState* irs) | |
122 { | |
123 elem* e = toElemBin(irs,OPoror); | |
124 if (global.params.cov && e2.loc.linnum) | |
125 e.E2() = el_combine(incUsageElem(irs, e2.loc), e.E2); | |
126 return e; | |
127 } | |
128 } |