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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.OrOrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 72
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.BinExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.CommaExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.BoolExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.expression.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.backend.OPER;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 class OrOrExp : BinExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 this(Loc loc, Expression e1, Expression e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 114
diff changeset
33 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 super(loc, TOK.TOKoror, OrOrExp.sizeof, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
37 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 uint cs1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 // same as for AndAnd
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 e1 = e1.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 e1 = resolveProperties(sc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 e1 = e1.checkToPointer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 e1 = e1.checkToBoolean();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 cs1 = sc.callSuper;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 if (sc.flags & SCOPE.SCOPEstaticif)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 /* If in static if, don't evaluate e2 if we don't have to.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 e1 = e1.optimize(WANTflags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 if (e1.isBool(true))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 return new IntegerExp(loc, 1, Type.tboolean);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 e2 = e2.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 sc.mergeCallSuper(loc, cs1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 e2 = resolveProperties(sc, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 e2 = e2.checkToPointer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 type = Type.tboolean;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 if (e2.type.ty == Tvoid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 type = Type.tvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 if (e2.op == TOKtype || e2.op == TOKimport)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 error("%s is not an expression", e2.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
72 override Expression checkToBoolean()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 e2 = e2.checkToBoolean();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 187
diff changeset
78 override bool isBit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
83 override Expression optimize(int result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 e1 = e1.optimize(WANTflags | (result & WANTinterpret));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 if (e1.isBool(true))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 // Replace with (e1, 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 e = new CommaExp(loc, e1, new IntegerExp(loc, 1, type));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 e.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 e = e.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 e2 = e2.optimize(WANTflags | (result & WANTinterpret));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 if (result && e2.type.toBasetype().ty == Tvoid && !global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 error("void has no value");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 if (e1.isConst())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 if (e2.isConst())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 int n1 = e1.isBool(1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 int n2 = e2.isBool(1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 e = new IntegerExp(loc, n1 || n2, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 else if (e1.isBool(false))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 e = new BoolExp(loc, e2, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
117 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
122 override bool checkSideEffect(int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 {
56
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
124 if (flag == 2)
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
125 {
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
126 return e1.checkSideEffect(2) || e2.checkSideEffect(2);
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
127 }
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
128 else
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
129 {
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
130 e1.checkSideEffect(1);
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
131 return e2.checkSideEffect(flag);
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
132 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
135 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 elem* e = toElemBin(irs,OPoror);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 if (global.params.cov && e2.loc.linnum)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 e.E2() = el_combine(incUsageElem(irs, e2.loc), e.E2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
142 }