Mercurial > projects > ddmd
annotate dmd/OrOrExp.d @ 191:52188e7e3fb5
Fixed deprecated features, now compiles with DMD2.058
Also changed Array allocation policy:
Now doesn't reallocate but malloc's, followed by a memcpy (no free).
(this fixes a crash while compiling druntime. Same bug in dmd)
author | korDen@korDen-pc |
---|---|
date | Sun, 25 Mar 2012 03:11:12 +0400 |
parents | b0d41ff5e0df |
children |
rev | line source |
---|---|
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 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
25 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
26 |
0 | 27 class OrOrExp : BinExp |
28 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
29 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
30 |
0 | 31 this(Loc loc, Expression e1, Expression e2) |
32 { | |
178 | 33 register(); |
0 | 34 super(loc, TOK.TOKoror, OrOrExp.sizeof, e1, e2); |
35 } | |
36 | |
72 | 37 override Expression semantic(Scope sc) |
0 | 38 { |
39 uint cs1; | |
40 | |
41 // same as for AndAnd | |
42 e1 = e1.semantic(sc); | |
43 e1 = resolveProperties(sc, e1); | |
44 e1 = e1.checkToPointer(); | |
45 e1 = e1.checkToBoolean(); | |
46 cs1 = sc.callSuper; | |
47 | |
48 if (sc.flags & SCOPE.SCOPEstaticif) | |
49 { | |
50 /* If in static if, don't evaluate e2 if we don't have to. | |
51 */ | |
52 e1 = e1.optimize(WANTflags); | |
53 if (e1.isBool(true)) | |
54 { | |
55 return new IntegerExp(loc, 1, Type.tboolean); | |
56 } | |
57 } | |
58 | |
59 e2 = e2.semantic(sc); | |
60 sc.mergeCallSuper(loc, cs1); | |
61 e2 = resolveProperties(sc, e2); | |
62 e2 = e2.checkToPointer(); | |
63 | |
64 type = Type.tboolean; | |
65 if (e2.type.ty == Tvoid) | |
66 type = Type.tvoid; | |
67 if (e2.op == TOKtype || e2.op == TOKimport) | |
68 error("%s is not an expression", e2.toChars()); | |
69 return this; | |
70 } | |
71 | |
72 | 72 override Expression checkToBoolean() |
0 | 73 { |
74 e2 = e2.checkToBoolean(); | |
75 return this; | |
76 } | |
77 | |
191
52188e7e3fb5
Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents:
187
diff
changeset
|
78 override bool isBit() |
0 | 79 { |
80 assert(false); | |
81 } | |
82 | |
72 | 83 override Expression optimize(int result) |
0 | 84 { |
85 Expression e; | |
86 | |
87 e1 = e1.optimize(WANTflags | (result & WANTinterpret)); | |
88 e = this; | |
89 if (e1.isBool(true)) | |
90 { | |
91 // Replace with (e1, 1) | |
92 e = new CommaExp(loc, e1, new IntegerExp(loc, 1, type)); | |
93 e.type = type; | |
94 e = e.optimize(result); | |
95 } | |
96 else | |
97 { | |
98 e2 = e2.optimize(WANTflags | (result & WANTinterpret)); | |
99 if (result && e2.type.toBasetype().ty == Tvoid && !global.errors) | |
100 error("void has no value"); | |
101 if (e1.isConst()) | |
102 { | |
103 if (e2.isConst()) | |
104 { | |
105 int n1 = e1.isBool(1); | |
106 int n2 = e2.isBool(1); | |
107 | |
108 e = new IntegerExp(loc, n1 || n2, type); | |
109 } | |
110 else if (e1.isBool(false)) | |
111 e = new BoolExp(loc, e2, type); | |
112 } | |
113 } | |
114 return e; | |
115 } | |
116 | |
72 | 117 override Expression interpret(InterState istate) |
0 | 118 { |
119 assert(false); | |
120 } | |
121 | |
72 | 122 override bool checkSideEffect(int flag) |
0 | 123 { |
56 | 124 if (flag == 2) |
125 { | |
126 return e1.checkSideEffect(2) || e2.checkSideEffect(2); | |
127 } | |
128 else | |
129 { | |
130 e1.checkSideEffect(1); | |
131 return e2.checkSideEffect(flag); | |
132 } | |
0 | 133 } |
134 | |
72 | 135 override elem* toElem(IRState* irs) |
0 | 136 { |
137 elem* e = toElemBin(irs,OPoror); | |
138 if (global.params.cov && e2.loc.linnum) | |
139 e.E2() = el_combine(incUsageElem(irs, e2.loc), e.E2); | |
140 return e; | |
141 } | |
72 | 142 } |