Mercurial > projects > ddmd
annotate dmd/AndAndExp.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 |
---|---|
72 | 1 module dmd.AndAndExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
5 import dmd.InterState; | |
6 import dmd.Loc; | |
7 import dmd.Scope; | |
0 | 8 import dmd.IRState; |
9 import dmd.CommaExp; | |
10 import dmd.Global; | |
72 | 11 import dmd.BoolExp; |
12 import dmd.BinExp; | |
0 | 13 import dmd.TOK; |
14 import dmd.WANT; | |
15 import dmd.IntegerExp; | |
16 import dmd.Type; | |
72 | 17 import dmd.TY; |
18 | |
0 | 19 import dmd.backend.elem; |
20 import dmd.backend.OPER; | |
72 | 21 import dmd.backend.Util; |
22 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
23 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
|
24 |
0 | 25 class AndAndExp : BinExp |
26 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
27 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
|
28 |
0 | 29 this(Loc loc, Expression e1, Expression e2) |
30 { | |
178 | 31 register(); |
0 | 32 super(loc, TOK.TOKandand, AndAndExp.sizeof, e1, e2); |
33 } | |
34 | |
72 | 35 override Expression semantic(Scope sc) |
0 | 36 { |
37 uint cs1; | |
38 | |
39 // same as for OrOr | |
40 e1 = e1.semantic(sc); | |
41 e1 = resolveProperties(sc, e1); | |
42 e1 = e1.checkToPointer(); | |
43 e1 = e1.checkToBoolean(); | |
44 cs1 = sc.callSuper; | |
45 | |
46 if (sc.flags & SCOPE.SCOPEstaticif) | |
47 { | |
48 /* If in static if, don't evaluate e2 if we don't have to. | |
49 */ | |
50 e1 = e1.optimize(WANTflags); | |
51 if (e1.isBool(false)) | |
52 { | |
53 return new IntegerExp(loc, 0, Type.tboolean); | |
54 } | |
55 } | |
56 | |
57 e2 = e2.semantic(sc); | |
58 sc.mergeCallSuper(loc, cs1); | |
59 e2 = resolveProperties(sc, e2); | |
60 e2 = e2.checkToPointer(); | |
61 | |
62 type = Type.tboolean; | |
63 if (e2.type.ty == Tvoid) | |
64 type = Type.tvoid; | |
65 if (e2.op == TOKtype || e2.op == TOKimport) | |
66 error("%s is not an expression", e2.toChars()); | |
67 return this; | |
68 } | |
69 | |
72 | 70 override Expression checkToBoolean() |
0 | 71 { |
72 e2 = e2.checkToBoolean(); | |
73 return this; | |
74 } | |
75 | |
191
52188e7e3fb5
Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents:
187
diff
changeset
|
76 override bool isBit() |
0 | 77 { |
78 assert(false); | |
79 } | |
80 | |
72 | 81 override Expression optimize(int result) |
0 | 82 { |
83 //printf("AndAndExp::optimize(%d) %s\n", result, toChars()); | |
84 e1 = e1.optimize(WANTflags | (result & WANTinterpret)); | |
85 Expression e = this; | |
86 if (e1.isBool(false)) | |
87 { | |
88 e = new CommaExp(loc, e1, new IntegerExp(loc, 0, 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 | |
98 if (e1.isConst()) | |
99 { | |
100 if (e2.isConst()) | |
101 { | |
102 int n1 = e1.isBool(1); | |
103 int n2 = e2.isBool(1); | |
104 | |
105 e = new IntegerExp(loc, n1 && n2, type); | |
106 } | |
107 else if (e1.isBool(true)) | |
108 e = new BoolExp(loc, e2, type); | |
109 } | |
110 } | |
111 return e; | |
112 } | |
113 | |
72 | 114 override Expression interpret(InterState istate) |
0 | 115 { |
116 assert(false); | |
117 } | |
118 | |
72 | 119 override bool checkSideEffect(int flag) |
0 | 120 { |
121 assert(false); | |
122 } | |
123 | |
72 | 124 override elem* toElem(IRState* irs) |
0 | 125 { |
126 elem* e = toElemBin(irs, OPandand); | |
127 if (global.params.cov && e2.loc.linnum) | |
128 e.E2() = el_combine(incUsageElem(irs, e2.loc), e.E2); | |
129 return e; | |
130 } | |
131 } | |
132 |