annotate dmd/ReturnStatement.d @ 63:cab4c37afb89

A bunch of implementations
author korDen
date Mon, 23 Aug 2010 16:52:24 +0400
parents 10317f0c89a5
children f708f0452e81
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.ReturnStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.GotoStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.CompoundStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.AssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.ExpStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.ThisExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.StructDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.CSX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.RET;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.StructLiteralExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.TypeStruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.InlineCostState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.InlineDoState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.InlineScanState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.VarDeclaration;
63
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
35 import dmd.GlobalExpressions;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.BE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.codegen.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.backend.Blockx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.backend.OPER;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import dmd.backend.mTY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 import dmd.backend.BC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 class ReturnStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 this(Loc loc, Expression exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 this.exp = exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 Statement syntaxCopy()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 Expression e = exp ? exp.syntaxCopy() : null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 return new ReturnStatement(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 Statement semantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 //printf("ReturnStatement.semantic() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 FuncDeclaration fd = sc.parent.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 Scope scx = sc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 int implicit0 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 if (sc.fes)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 // Find scope of function foreach is in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 for (; 1; scx = scx.enclosing)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 assert(scx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 if (scx.func !is fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 fd = scx.func; // fd is now function enclosing foreach
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 Type tret = fd.type.nextOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 if (fd.tintro) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 /* We'll be implicitly casting the return expression to tintro
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 tret = fd.tintro.nextOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 Type tbret = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 if (tret) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 tbret = tret.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 // main() returns 0, even if it returns void
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 if (!exp && (!tbret || tbret.ty == TY.Tvoid) && fd.isMain())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 implicit0 = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 exp = new IntegerExp(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 if (sc.incontract || scx.incontract)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 error("return statements cannot be in contracts");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 if (sc.tf || scx.tf)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 error("return statements cannot be in finally, scope(exit) or scope(success) bodies");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 if (fd.isCtorDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 // Constructors implicitly do:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 // return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 if (exp && exp.op != TOK.TOKthis) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 error("cannot return expression from constructor");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 exp = new ThisExp(Loc(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 if (!exp) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 fd.nrvo_can = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 if (exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 fd.hasReturnExp |= 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 exp = exp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 exp = resolveProperties(sc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 exp = exp.optimize(WANT.WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 if (fd.nrvo_can && exp.op == TOK.TOKvar) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 VarExp ve = cast(VarExp)exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 VarDeclaration v = ve.var.isVarDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 if ((cast(TypeFunction)fd.type).isref) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 // Function returns a reference
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 fd.nrvo_can = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 } else if (!v || v.isOut() || v.isRef()) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 fd.nrvo_can = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 } else if (tbret.ty == TY.Tstruct && (cast(TypeStruct)tbret).sym.dtor) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 // Struct being returned has destructors
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 fd.nrvo_can = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 } else if (fd.nrvo_var is null) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 if (!v.isDataseg() && !v.isParameter() && v.toParent2() == fd) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 //printf("Setting nrvo to %s\n", v.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 fd.nrvo_var = v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 fd.nrvo_can = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 } else if (fd.nrvo_var != v) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 fd.nrvo_can = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 fd.nrvo_can = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 if (fd.returnLabel && tbret.ty != TY.Tvoid) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 } else if (fd.inferRetType) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 if (fd.type.nextOf()) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 if (!exp.type.equals(fd.type.nextOf()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 error("mismatched function return type inference of %s and %s", exp.type.toChars(), fd.type.nextOf().toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 (cast(TypeFunction)fd.type).next = exp.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 fd.type = fd.type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 if (!fd.tintro)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 tret = fd.type.nextOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 tbret = tret.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 } else if (tbret.ty != TY.Tvoid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 exp = exp.implicitCastTo(sc, tret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 exp = exp.optimize(WANT.WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 } else if (fd.inferRetType) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 if (fd.type.nextOf())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 if (fd.type.nextOf().ty != TY.Tvoid) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 error("mismatched function return type inference of void and %s", fd.type.nextOf().toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 (cast(TypeFunction*)fd.type).next = Type.tvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 fd.type = fd.type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 if (!fd.tintro)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 tret = Type.tvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 tbret = tret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 else if (tbret.ty != TY.Tvoid) {// if non-void return
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 error("return expression expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 if (sc.fes)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 Statement s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 if (exp && !implicit0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 exp = exp.implicitCastTo(sc, tret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 if (!exp || exp.op == TOK.TOKint64 || exp.op == TOK.TOKfloat64 ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 exp.op == TOK.TOKimaginary80 || exp.op == TOK.TOKcomplex80 ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 exp.op == TOK.TOKthis || exp.op == TOK.TOKsuper || exp.op == TOK.TOKnull ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 exp.op == TOK.TOKstring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 sc.fes.cases.push(cast(void*)this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 // Construct: return cases.dim+1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 s = new ReturnStatement(Loc(0), new IntegerExp(sc.fes.cases.dim + 1));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 else if (fd.type.nextOf().toBasetype() == Type.tvoid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 s = new ReturnStatement(Loc(0), null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 sc.fes.cases.push(cast(void*)s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 // Construct: { exp; return cases.dim + 1; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 Statement s1 = new ExpStatement(loc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 Statement s2 = new ReturnStatement(Loc(0), new IntegerExp(sc.fes.cases.dim + 1));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 s = new CompoundStatement(loc, s1, s2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 // Construct: return vresult;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 if (!fd.vresult)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 // Declare vresult
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 VarDeclaration v = new VarDeclaration(loc, tret, Id.result, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 v.noauto = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 v.semantic(scx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 if (!scx.insert(v)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 v.parent = fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 fd.vresult = v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 s = new ReturnStatement(Loc(0), new VarExp(Loc(0), fd.vresult));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 sc.fes.cases.push(cast(void*)s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 // Construct: { vresult = exp; return cases.dim + 1; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 exp = new AssignExp(loc, new VarExp(Loc(0), fd.vresult), exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 exp.op = TOK.TOKconstruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 exp = exp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 Statement s1 = new ExpStatement(loc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 Statement s2 = new ReturnStatement(Loc(0), new IntegerExp(sc.fes.cases.dim + 1));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 s = new CompoundStatement(loc, s1, s2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 if (exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 if (fd.returnLabel && tbret.ty != TY.Tvoid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 assert(fd.vresult);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 VarExp v = new VarExp(Loc(0), fd.vresult);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 exp = new AssignExp(loc, v, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 exp.op = TOK.TOKconstruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 exp = exp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 if ((cast(TypeFunction)fd.type).isref && !fd.isCtorDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 { // Function returns a reference
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 if (tbret.isMutable())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 exp = exp.modifiableLvalue(sc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 exp = exp.toLvalue(sc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 if (exp.op == TOK.TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 VarExp ve = cast(VarExp)exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 VarDeclaration v = ve.var.isVarDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 if (v && !v.isDataseg() && !(v.storage_class & (STC.STCref | STC.STCout))) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 error("escaping reference to local variable %s", v.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 //exp.dump(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 //exp.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 exp.checkEscape();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 /* BUG: need to issue an error on:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 * this
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 * { if (x) return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 * super();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 * }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 if (sc.callSuper & CSX.CSXany_ctor && !(sc.callSuper & (CSX.CSXthis_ctor | CSX.CSXsuper_ctor))) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 error("return without calling constructor");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 sc.callSuper |= CSX.CSXreturn;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 // See if all returns are instead to be replaced with a goto returnLabel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 if (fd.returnLabel)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 GotoStatement gs = new GotoStatement(loc, Id.returnLabel);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 gs.label = fd.returnLabel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 if (exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 /* Replace: return exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 * with: exp; goto returnLabel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 Statement s = new ExpStatement(Loc(0), exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 return new CompoundStatement(loc, s, gs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 return gs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 if (exp && tbret.ty == TY.Tvoid && !fd.isMain())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 /* Replace:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 * return exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 * with:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 * exp; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 Statement s = new ExpStatement(loc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 loc = Loc(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 exp = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 return new CompoundStatement(loc, s, this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 BE blockExit()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 BE result = BE.BEreturn;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 if (exp && exp.canThrow())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 result |= BE.BEthrow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354
63
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
355 Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
357 version (LOG) {
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
358 printf("ReturnStatement.interpret(%s)\n", exp ? exp.toChars() : "");
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
359 }
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
360 mixin(START!());
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
361 if (!exp)
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
362 return EXP_VOID_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
363 version (LOG) {
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
364 Expression e = exp.interpret(istate);
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
365 printf("e = %p\n", e);
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
366 return e;
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
367 } else {
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
368 return exp.interpret(istate);
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
369 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 int inlineCost(InlineCostState* ics)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 // Can't handle return statements nested in if's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 if (ics.nested)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 return COST_MAX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 return exp ? exp.inlineCost(ics) : 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 Expression doInline(InlineDoState ids)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 //printf("ReturnStatement.doInline() '%s'\n", exp ? exp.toChars() : "");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 return exp ? exp.doInline(ids) : null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 Statement inlineScan(InlineScanState* iss)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 //printf("ReturnStatement.inlineScan()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 if (exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 exp = exp.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 void toIR(IRState* irs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 Blockx* blx = irs.blx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 incUsage(irs, loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 if (exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 elem *e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 FuncDeclaration func = irs.getFunc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 assert(func);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 assert(func.type.ty == TY.Tfunction);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 TypeFunction tf = cast(TypeFunction)(func.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 RET retmethod = tf.retStyle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 if (retmethod == RET.RETstack)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 elem* es;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 /* If returning struct literal, write result
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 * directly into return value
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 if (exp.op == TOK.TOKstructliteral)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 /*
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 StructLiteralExp se = cast(StructLiteralExp)exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 char save[(StructLiteralExp).sizeof];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 memcpy(save, se, sizeof(StructLiteralExp));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 se.sym = irs.shidden;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 se.soffset = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 se.fillHoles = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 e = exp.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 memcpy(se, save, sizeof(StructLiteralExp));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 e = exp.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 assert(e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 if (exp.op == TOK.TOKstructliteral || (func.nrvo_can && func.nrvo_var))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 // Return value via hidden pointer passed as parameter
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 // Write exp; return shidden;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 es = e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 // Return value via hidden pointer passed as parameter
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 // Write *shidden=exp; return shidden;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 int op;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 tym_t ety;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 ety = e.Ety;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 es = el_una(OPER.OPind,ety,el_var(irs.shidden));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 op = (tybasic(ety) == TYM.TYstruct) ? OPER.OPstreq : OPER.OPeq;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 es = el_bin(op, ety, es, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 if (op == OPER.OPstreq)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 es.Enumbytes = cast(uint)exp.type.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 /* Call postBlit() on *shidden
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 Type tb = exp.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 //if (tb.ty == TY.Tstruct) exp.dump(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 if ((exp.op == TOK.TOKvar || exp.op == TOK.TOKdotvar || exp.op == TOK.TOKstar) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 tb.ty == TY.Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 { StructDeclaration sd = (cast(TypeStruct)tb).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 if (sd.postblit)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 FuncDeclaration fd = sd.postblit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 elem* ec = el_var(irs.shidden);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 ec = callfunc(loc, irs, 1, Type.tvoid, ec, tb.pointerTo(), fd, fd.type, null, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 es = el_bin(OPER.OPcomma, ec.Ety, es, ec);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 /* It has been moved, so disable destructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 if (exp.op == TOK.TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477 VarExp ve = cast(VarExp)exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 VarDeclaration v = ve.var.isVarDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 if (v && v.rundtor)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 elem* er = el_var(v.rundtor.toSymbol());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 er = el_bin(OPER.OPeq, TYM.TYint, er, el_long(TYM.TYint, 0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 es = el_bin(OPER.OPcomma, TYM.TYint, es, er);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 e = el_var(irs.shidden);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 e = el_bin(OPER.OPcomma, e.Ety, es, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 ///version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 else if (tf.isref)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 { // Reference return, so convert to a pointer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 Expression ae = exp.addressOf(null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 e = ae.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 e = exp.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 assert(e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 block_appendexp(blx.curblock, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 block_next(blx, BC.BCretexp, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 block_next(blx, BC.BCret, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 ReturnStatement isReturnStatement() { return this; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 }