annotate dmd/CommaExp.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.CommaExp;
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.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.BinExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.IntRange;
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
9 import dmd.DeclarationExp;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
10 import dmd.VarExp;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
11 import dmd.VarDeclaration;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Expression;
163
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
13 import dmd.GlobalExpressions;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
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: 179
diff changeset
24
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 class CommaExp : BinExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
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: 179
diff changeset
28
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 this(Loc loc, Expression e1, Expression e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 163
diff changeset
31 register();
e3afd1303184 Many small bugs fixed
korDen
parents: 163
diff changeset
32
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 super(loc, TOK.TOKcomma, CommaExp.sizeof, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
36 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 if (!type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 BinExp.semanticp(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 type = e2.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
46 override void checkEscape()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 e2.checkEscape();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
51 override void checkEscapeRef()
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
52 {
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
53 e2.checkEscapeRef();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
54 }
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
55
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
56 override IntRange getIntRange()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 version (DMDV2) {
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 187
diff changeset
62 override bool isLvalue()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 return e2.isLvalue();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
67 override Expression toLvalue(Scope sc, Expression e)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 e2 = e2.toLvalue(sc, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
73 override Expression modifiableLvalue(Scope sc, Expression e)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 e2 = e2.modifiableLvalue(sc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
79 override bool isBool(bool result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 return e2.isBool(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
84 override bool checkSideEffect(int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 if (flag == 2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 return e1.checkSideEffect(2) || e2.checkSideEffect(2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 // Don't check e1 until we cast(void) the a,b code generation
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 return e2.checkSideEffect(flag);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
95 override MATCH implicitConvTo(Type t)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 {
56
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
97 return e2.implicitConvTo(t);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
100 override Expression castTo(Scope sc, Type t)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 {
56
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
102 Expression e2c = e2.castTo(sc, t);
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
103 Expression e;
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
104
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
105 if (e2c != e2)
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
106 {
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
107 e = new CommaExp(loc, e1, e2c);
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
108 e.type = e2c.type;
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
109 }
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
110 else
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
111 {
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
112 e = this;
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
113 e.type = e2.type;
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
114 }
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
115 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
118 override Expression optimize(int result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 //printf("CommaExp.optimize(result = %d) %s\n", result, toChars());
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
123 // Comma needs special treatment, because it may
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
124 // contain compiler-generated declarations. We can interpret them, but
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
125 // otherwise we must NOT attempt to constant-fold them.
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
126 // In particular, if the comma returns a temporary variable, it needs
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
127 // to be an lvalue (this is particularly important for struct constructors)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
128
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
129 if (result & WANTinterpret)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
130 {
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
131 // Interpreting comma needs special treatment, because it may
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
132 // contain compiler-generated declarations.
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
133 e = interpret(null);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
134 return (e is EXP_CANT_INTERPRET) ? this : e;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
135 }
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
136 // Don't constant fold if it is a compiler-generated temporary.
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
137 if (e1.op == TOKdeclaration)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
138 return this;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
139
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 e1 = e1.optimize(result & WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 e2 = e2.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 if (!e1 || e1.op == TOKint64 || e1.op == TOKfloat64 || !e1.checkSideEffect(2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 e = e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 e.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 //printf("-CommaExp.optimize(result = %d) %s\n", result, e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
154 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 {
163
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
156 version (LOG) {
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
157 printf("CommaExp.interpret() %.*s\n", toChars());
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
158 }
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
159 // If the comma returns a temporary variable, it needs to be an lvalue
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
160 // (this is particularly important for struct constructors)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
161 if (e1.op == TOKdeclaration && e2.op == TOKvar
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
162 && (cast(DeclarationExp)e1).declaration == (cast(VarExp)e2).var)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
163 {
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
164 VarExp ve = cast(VarExp)e2;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
165 VarDeclaration v = ve.var.isVarDeclaration();
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
166 if (!v.init && !v.value)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
167 v.value = v.type.defaultInitLiteral(Loc(0));
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
168 if (!v.value)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
169 v.value = v.init.toExpression();
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
170 v.value = v.value.interpret(istate);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
171 return e2;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
172 }
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
173
163
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
174 Expression e = e1.interpret(istate);
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
175 if (e !is EXP_CANT_INTERPRET)
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
176 e = e2.interpret(istate);
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
177 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
180 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 assert(e1 && e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 elem* eleft = e1.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 elem* eright = e2.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 elem* e = el_combine(eleft, eright);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 el_setLoc(e, loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
190 }