Mercurial > projects > ddmd
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 |
rev | line source |
---|---|
0 | 1 module dmd.CommaExp; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Loc; |
5 import dmd.BinExp; | |
6 import dmd.IRState; | |
7 import dmd.Scope; | |
8 import dmd.IntRange; | |
179 | 9 import dmd.DeclarationExp; |
10 import dmd.VarExp; | |
11 import dmd.VarDeclaration; | |
0 | 12 import dmd.Expression; |
163 | 13 import dmd.GlobalExpressions; |
0 | 14 import dmd.MATCH; |
15 import dmd.WANT; | |
16 import dmd.TOK; | |
17 import dmd.Type; | |
18 import dmd.InterState; | |
19 | |
20 import dmd.backend.elem; | |
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:
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 | 25 class CommaExp : BinExp |
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 | 29 this(Loc loc, Expression e1, Expression e2) |
30 { | |
178 | 31 register(); |
32 | |
0 | 33 super(loc, TOK.TOKcomma, CommaExp.sizeof, e1, e2); |
34 } | |
35 | |
72 | 36 override Expression semantic(Scope sc) |
0 | 37 { |
38 if (!type) | |
39 { | |
40 BinExp.semanticp(sc); | |
41 type = e2.type; | |
42 } | |
43 return this; | |
44 } | |
45 | |
72 | 46 override void checkEscape() |
0 | 47 { |
48 e2.checkEscape(); | |
49 } | |
50 | |
135 | 51 override void checkEscapeRef() |
52 { | |
53 e2.checkEscapeRef(); | |
54 } | |
55 | |
72 | 56 override IntRange getIntRange() |
0 | 57 { |
58 assert(false); | |
59 } | |
60 | |
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 | 63 { |
64 return e2.isLvalue(); | |
65 } | |
66 } | |
72 | 67 override Expression toLvalue(Scope sc, Expression e) |
0 | 68 { |
69 e2 = e2.toLvalue(sc, null); | |
70 return this; | |
71 } | |
72 | |
72 | 73 override Expression modifiableLvalue(Scope sc, Expression e) |
0 | 74 { |
75 e2 = e2.modifiableLvalue(sc, e); | |
76 return this; | |
77 } | |
78 | |
72 | 79 override bool isBool(bool result) |
0 | 80 { |
81 return e2.isBool(result); | |
82 } | |
83 | |
72 | 84 override bool checkSideEffect(int flag) |
0 | 85 { |
86 if (flag == 2) | |
87 return e1.checkSideEffect(2) || e2.checkSideEffect(2); | |
88 else | |
89 { | |
90 // Don't check e1 until we cast(void) the a,b code generation | |
91 return e2.checkSideEffect(flag); | |
92 } | |
93 } | |
94 | |
72 | 95 override MATCH implicitConvTo(Type t) |
0 | 96 { |
56 | 97 return e2.implicitConvTo(t); |
0 | 98 } |
99 | |
72 | 100 override Expression castTo(Scope sc, Type t) |
0 | 101 { |
56 | 102 Expression e2c = e2.castTo(sc, t); |
103 Expression e; | |
104 | |
105 if (e2c != e2) | |
106 { | |
107 e = new CommaExp(loc, e1, e2c); | |
108 e.type = e2c.type; | |
109 } | |
110 else | |
111 { | |
112 e = this; | |
113 e.type = e2.type; | |
114 } | |
115 return e; | |
0 | 116 } |
117 | |
72 | 118 override Expression optimize(int result) |
0 | 119 { |
120 Expression e; | |
121 | |
122 //printf("CommaExp.optimize(result = %d) %s\n", result, toChars()); | |
179 | 123 // Comma needs special treatment, because it may |
124 // contain compiler-generated declarations. We can interpret them, but | |
125 // otherwise we must NOT attempt to constant-fold them. | |
126 // In particular, if the comma returns a temporary variable, it needs | |
127 // to be an lvalue (this is particularly important for struct constructors) | |
128 | |
129 if (result & WANTinterpret) | |
130 { | |
131 // Interpreting comma needs special treatment, because it may | |
132 // contain compiler-generated declarations. | |
133 e = interpret(null); | |
134 return (e is EXP_CANT_INTERPRET) ? this : e; | |
135 } | |
136 // Don't constant fold if it is a compiler-generated temporary. | |
137 if (e1.op == TOKdeclaration) | |
138 return this; | |
139 | |
0 | 140 e1 = e1.optimize(result & WANTinterpret); |
141 e2 = e2.optimize(result); | |
142 if (!e1 || e1.op == TOKint64 || e1.op == TOKfloat64 || !e1.checkSideEffect(2)) | |
143 { | |
144 e = e2; | |
145 if (e) | |
146 e.type = type; | |
147 } | |
148 else | |
149 e = this; | |
150 //printf("-CommaExp.optimize(result = %d) %s\n", result, e.toChars()); | |
151 return e; | |
152 } | |
153 | |
72 | 154 override Expression interpret(InterState istate) |
0 | 155 { |
163 | 156 version (LOG) { |
157 printf("CommaExp.interpret() %.*s\n", toChars()); | |
158 } | |
179 | 159 // If the comma returns a temporary variable, it needs to be an lvalue |
160 // (this is particularly important for struct constructors) | |
161 if (e1.op == TOKdeclaration && e2.op == TOKvar | |
162 && (cast(DeclarationExp)e1).declaration == (cast(VarExp)e2).var) | |
163 { | |
164 VarExp ve = cast(VarExp)e2; | |
165 VarDeclaration v = ve.var.isVarDeclaration(); | |
166 if (!v.init && !v.value) | |
167 v.value = v.type.defaultInitLiteral(Loc(0)); | |
168 if (!v.value) | |
169 v.value = v.init.toExpression(); | |
170 v.value = v.value.interpret(istate); | |
171 return e2; | |
172 } | |
173 | |
163 | 174 Expression e = e1.interpret(istate); |
175 if (e !is EXP_CANT_INTERPRET) | |
176 e = e2.interpret(istate); | |
177 return e; | |
0 | 178 } |
179 | |
72 | 180 override elem* toElem(IRState* irs) |
0 | 181 { |
182 assert(e1 && e2); | |
183 elem* eleft = e1.toElem(irs); | |
184 elem* eright = e2.toElem(irs); | |
185 elem* e = el_combine(eleft, eright); | |
186 if (e) | |
187 el_setLoc(e, loc); | |
188 return e; | |
189 } | |
72 | 190 } |