Mercurial > projects > ddmd
annotate dmd/FuncDeclaration.d @ 131:206db751bd4c
dmdfe 2.037 compiles now
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Fri, 10 Sep 2010 00:27:37 +0100 |
parents | 60bb0fe4563e |
children | af1bebfd96a4 |
rev | line source |
---|---|
0 | 1 module dmd.FuncDeclaration; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Declaration; |
5 import dmd.DotIdExp; | |
63 | 6 import dmd.AddrExp; |
0 | 7 import dmd.TryFinallyStatement; |
73 | 8 import dmd.TryCatchStatement; |
9 import dmd.Catch; | |
10 import dmd.DeclarationStatement; | |
0 | 11 import dmd.StaticDtorDeclaration; |
63 | 12 import dmd.GlobalExpressions; |
0 | 13 import dmd.PeelStatement; |
14 import dmd.SynchronizedStatement; | |
15 import dmd.TOK; | |
16 import dmd.SymOffExp; | |
17 import dmd.AssignExp; | |
18 import dmd.ExpInitializer; | |
19 import dmd.BE; | |
20 import dmd.Id; | |
93
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
21 import dmd.StorageClassDeclaration; |
0 | 22 import dmd.StringExp; |
23 import dmd.DsymbolExp; | |
24 import dmd.HaltExp; | |
25 import dmd.CommaExp; | |
26 import dmd.ReturnStatement; | |
27 import dmd.IntegerExp; | |
28 import dmd.ExpStatement; | |
29 import dmd.CSX; | |
30 import dmd.CompoundStatement; | |
31 import dmd.LabelStatement; | |
32 import dmd.ThisExp; | |
33 import dmd.SuperExp; | |
34 import dmd.IdentifierExp; | |
35 import dmd.AssertExp; | |
36 import dmd.CallExp; | |
37 import dmd.RET; | |
38 import dmd.VarExp; | |
39 import dmd.TupleDeclaration; | |
40 import dmd.ThisDeclaration; | |
41 import dmd.TypeTuple; | |
42 import dmd.TemplateInstance; | |
43 import dmd.ScopeDsymbol; | |
44 import dmd.AliasDeclaration; | |
45 import dmd.MOD; | |
46 import dmd.PROT; | |
47 import dmd.Lexer; | |
48 import dmd.LINK; | |
49 import dmd.CtorDeclaration; | |
50 import dmd.Global; | |
51 import dmd.DtorDeclaration; | |
52 import dmd.InvariantDeclaration; | |
53 import dmd.TY; | |
54 import dmd.PtrExp; | |
55 import dmd.DeclarationExp; | |
56 import dmd.InlineDoState; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
57 import dmd.Parameter; |
0 | 58 import dmd.StructDeclaration; |
59 import dmd.ClassDeclaration; | |
60 import dmd.InterfaceDeclaration; | |
61 import dmd.Array; | |
62 import dmd.Statement; | |
63 import dmd.Identifier; | |
64 import dmd.VarDeclaration; | |
65 import dmd.LabelDsymbol; | |
66 import dmd.DsymbolTable; | |
67 import dmd.ArrayTypes; | |
68 import dmd.Loc; | |
69 import dmd.ILS; | |
70 import dmd.ForeachStatement; | |
71 import dmd.Type; | |
72 import dmd.BUILTIN; | |
73 import dmd.TypeFunction; | |
74 import dmd.Expression; | |
75 import dmd.STC; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
76 import dmd.TRUST; |
0 | 77 import dmd.Dsymbol; |
78 import dmd.Scope; | |
79 import dmd.OutBuffer; | |
80 import dmd.HdrGenState; | |
81 import dmd.MATCH; | |
82 import dmd.AggregateDeclaration; | |
83 import dmd.InterState; | |
84 import dmd.InlineScanState; | |
85 import dmd.IRState; | |
86 import dmd.Util; | |
87 import dmd.BaseClass; | |
88 import dmd.Module; | |
89 import dmd.InlineCostState; | |
90 | |
91 import dmd.expression.Util; | |
92 | |
93 import dmd.declaration.Match; | |
94 | |
95 import dmd.backend.Symbol; | |
96 import dmd.backend.func_t; | |
97 import dmd.backend.Util; | |
98 import dmd.backend.glue; | |
99 import dmd.backend.SC; | |
100 import dmd.backend.F; | |
101 import dmd.backend.Cstate; | |
102 import dmd.backend.TYM; | |
103 import dmd.backend.OPER; | |
104 import dmd.backend.TYFL; | |
105 import dmd.backend.TYPE; | |
106 import dmd.backend.SFL; | |
107 import dmd.backend.mTY; | |
108 import dmd.backend.FL; | |
109 import dmd.backend.REG; | |
110 import dmd.backend.block; | |
111 import dmd.backend.Blockx; | |
112 import dmd.backend.Config; | |
113 import dmd.backend.BC; | |
114 import dmd.backend.elem; | |
115 import dmd.backend.targ_types; | |
116 import dmd.backend.mTYman; | |
117 import dmd.backend.RTLSYM; | |
118 import dmd.backend.LIST; | |
119 | |
120 import core.stdc.stdio; | |
121 import core.stdc.string; | |
63 | 122 version (Bug4054) import core.memory; |
123 | |
72 | 124 import dmd.interpret.Util; |
0 | 125 |
126 import std.string; | |
127 | |
128 class FuncDeclaration : Declaration | |
129 { | |
130 Array fthrows; // Array of Type's of exceptions (not used) | |
131 Statement frequire; | |
132 Statement fensure; | |
133 Statement fbody; | |
73 | 134 |
135 FuncDeclarations foverrides; // functions this function overrides | |
136 FuncDeclaration fdrequire; // function that does the in contract | |
137 FuncDeclaration fdensure; // function that does the out contract | |
0 | 138 |
139 Identifier outId; // identifier for out statement | |
140 VarDeclaration vresult; // variable corresponding to outId | |
141 LabelDsymbol returnLabel; // where the return goes | |
142 | |
143 DsymbolTable localsymtab; // used to prevent symbols in different | |
144 // scopes from having the same name | |
145 VarDeclaration vthis; // 'this' parameter (member and nested) | |
146 VarDeclaration v_arguments; // '_arguments' parameter | |
147 version (IN_GCC) { | |
148 VarDeclaration v_argptr; // '_argptr' variable | |
149 } | |
150 Dsymbols parameters; // Array of VarDeclaration's for parameters | |
151 DsymbolTable labtab; // statement label symbol table | |
152 Declaration overnext; // next in overload list | |
153 Loc endloc; // location of closing curly bracket | |
73 | 154 int vtblIndex; // for member functions, index into vtbl[] |
0 | 155 int naked; // !=0 if naked |
156 int inlineAsm; // !=0 if has inline assembler | |
73 | 157 ILS inlineStatus; |
0 | 158 int inlineNest; // !=0 if nested inline |
159 int cantInterpret; // !=0 if cannot interpret function | |
160 int semanticRun; // 1 semantic() run | |
161 // 2 semantic2() run | |
162 // 3 semantic3() started | |
163 // 4 semantic3() done | |
164 // 5 toObjFile() run | |
165 // this function's frame ptr | |
166 ForeachStatement fes; // if foreach body, this is the foreach | |
167 int introducing; // !=0 if 'introducing' function | |
168 Type tintro; // if !=null, then this is the type | |
169 // of the 'introducing' function | |
170 // this one is overriding | |
171 int inferRetType; // !=0 if return type is to be inferred | |
172 | |
173 // Things that should really go into Scope | |
174 int hasReturnExp; // 1 if there's a return exp; statement | |
175 // 2 if there's a throw statement | |
176 // 4 if there's an assert(0) | |
177 // 8 if there's inline asm | |
178 | |
179 // Support for NRVO (named return value optimization) | |
180 bool nrvo_can = true; // !=0 means we can do it | |
181 VarDeclaration nrvo_var; // variable to replace with shidden | |
182 Symbol* shidden; // hidden pointer passed to function | |
183 | |
184 version (DMDV2) { | |
185 BUILTIN builtin; // set if this is a known, builtin | |
186 // function we can evaluate at compile | |
187 // time | |
188 | |
189 int tookAddressOf; // set if someone took the address of | |
190 // this function | |
191 Dsymbols closureVars; // local variables in this function | |
192 // which are referenced by nested | |
193 // functions | |
194 } else { | |
195 int nestedFrameRef; // !=0 if nested variables referenced | |
196 } | |
197 | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
198 this(Loc loc, Loc endloc, Identifier id, StorageClass storage_class, Type type) |
0 | 199 { |
200 super(id); | |
201 | |
202 //printf("FuncDeclaration(id = '%s', type = %p)\n", id.toChars(), type); | |
203 //printf("storage_class = x%x\n", storage_class); | |
204 this.storage_class = storage_class; | |
205 this.type = type; | |
206 this.loc = loc; | |
207 this.endloc = endloc; | |
73 | 208 fthrows = null; |
209 frequire = null; | |
210 fdrequire = null; | |
211 fdensure = null; | |
212 outId = null; | |
213 vresult = null; | |
214 returnLabel = null; | |
215 fensure = null; | |
216 fbody = null; | |
217 localsymtab = null; | |
218 vthis = null; | |
219 v_arguments = null; | |
220 version (IN_GCC) { | |
221 v_argptr = null; | |
222 } | |
223 parameters = null; | |
224 labtab = null; | |
225 overnext = null; | |
226 vtblIndex = -1; | |
227 hasReturnExp = 0; | |
228 naked = 0; | |
229 inlineStatus = ILS.ILSuninitialized; | |
230 inlineNest = 0; | |
231 inlineAsm = 0; | |
232 cantInterpret = 0; | |
233 semanticRun = 0; | |
234 version (DMDV1) { | |
235 nestedFrameRef = 0; | |
236 } | |
237 fes = null; | |
238 introducing = 0; | |
239 tintro = null; | |
0 | 240 /* The type given for "infer the return type" is a TypeFunction with |
241 * null for the return type. | |
242 */ | |
243 inferRetType = (type && type.nextOf() is null); | |
73 | 244 hasReturnExp = 0; |
245 nrvo_can = 1; | |
246 nrvo_var = null; | |
247 shidden = null; | |
248 version (DMDV2) { | |
249 builtin = BUILTINunknown; | |
250 tookAddressOf = 0; | |
251 } | |
252 foverrides = new FuncDeclarations(); | |
0 | 253 closureVars = new Dsymbols(); |
254 } | |
255 | |
72 | 256 override Dsymbol syntaxCopy(Dsymbol s) |
0 | 257 { |
258 FuncDeclaration f; | |
259 | |
260 //printf("FuncDeclaration::syntaxCopy('%s')\n", toChars()); | |
261 if (s) | |
262 f = cast(FuncDeclaration)s; | |
263 else | |
264 f = new FuncDeclaration(loc, endloc, ident, storage_class, type.syntaxCopy()); | |
265 | |
266 f.outId = outId; | |
267 f.frequire = frequire ? frequire.syntaxCopy() : null; | |
268 f.fensure = fensure ? fensure.syntaxCopy() : null; | |
269 f.fbody = fbody ? fbody.syntaxCopy() : null; | |
270 assert(!fthrows); // deprecated | |
271 | |
272 return f; | |
273 } | |
274 | |
275 // Do the semantic analysis on the external interface to the function. | |
72 | 276 override void semantic(Scope sc) |
0 | 277 { |
278 TypeFunction f; | |
279 StructDeclaration sd; | |
280 ClassDeclaration cd; | |
281 InterfaceDeclaration id; | |
282 Dsymbol pd; | |
283 | |
79 | 284 static if (false) |
285 { | |
0 | 286 printf("FuncDeclaration.semantic(sc = %p, this = %p, '%s', linkage = %d)\n", sc, this, toPrettyChars(), sc.linkage); |
287 if (isFuncLiteralDeclaration()) | |
288 printf("\tFuncLiteralDeclaration()\n"); | |
289 printf("sc.parent = %s, parent = %s\n", sc.parent.toChars(), parent ? parent.toChars() : ""); | |
290 printf("type: %p, %s\n", type, type.toChars()); | |
291 } | |
292 | |
293 if (semanticRun && isFuncLiteralDeclaration()) | |
294 { | |
79 | 295 /* Member functions that have return types that are |
296 * forward references can have semantic() run more than | |
297 * once on them. | |
298 * See test\interface2.d, test20 | |
299 */ | |
300 return; | |
0 | 301 } |
302 assert(semanticRun <= 1); | |
303 semanticRun = 1; | |
304 | |
305 storage_class |= sc.stc & ~STC.STCref; | |
306 //printf("function storage_class = x%x\n", storage_class); | |
307 | |
308 if (!originalType) | |
79 | 309 originalType = type; |
0 | 310 if (!type.deco) |
311 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
312 /* Apply const, immutable and shared storage class |
79 | 313 * to the function type |
314 */ | |
315 type = type.semantic(loc, sc); | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
316 StorageClass stc = storage_class; |
79 | 317 if (type.isInvariant()) |
318 stc |= STC.STCimmutable; | |
319 if (type.isConst()) | |
320 stc |= STC.STCconst; | |
321 if (type.isShared() || storage_class & STC.STCsynchronized) | |
322 stc |= STC.STCshared; | |
323 switch (stc & STC.STC_TYPECTOR) | |
324 { | |
325 case STC.STCimmutable: | |
326 case STC.STCimmutable | STC.STCconst: | |
327 case STC.STCimmutable | STC.STCconst | STC.STCshared: | |
328 case STC.STCimmutable | STC.STCshared: | |
329 // Don't use toInvariant(), as that will do a merge() | |
330 type = type.makeInvariant(); | |
331 goto Lmerge; | |
332 | |
333 case STC.STCconst: | |
334 type = type.makeConst(); | |
335 goto Lmerge; | |
336 | |
337 case STC.STCshared | STC.STCconst: | |
338 type = type.makeSharedConst(); | |
339 goto Lmerge; | |
340 | |
341 case STC.STCshared: | |
342 type = type.makeShared(); | |
343 Lmerge: | |
344 if (!(type.ty == Tfunction && !type.nextOf())) | |
345 /* Can't do merge if return type is not known yet | |
346 */ | |
347 type.deco = type.merge().deco; | |
348 break; | |
349 | |
350 case STC.STCundefined: | |
351 break; | |
352 | |
353 default: | |
354 assert(0); | |
355 } | |
0 | 356 } |
357 //type.print(); | |
358 if (type.ty != TY.Tfunction) | |
359 { | |
360 error("%s must be a function", toChars()); | |
361 return; | |
362 } | |
363 f = cast(TypeFunction)type; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
364 size_t nparams = Parameter.dim(f.parameters); |
0 | 365 |
366 linkage = sc.linkage; | |
367 // if (!parent) | |
368 { | |
369 //parent = sc.scopesym; | |
370 parent = sc.parent; | |
371 } | |
372 protection = sc.protection; | |
373 Dsymbol parent = toParent(); | |
374 | |
375 if (storage_class & STC.STCscope) | |
376 error("functions cannot be scope"); | |
377 | |
378 if (isAbstract() && !isVirtual()) | |
379 error("non-virtual functions cannot be abstract"); | |
380 | |
381 if ((f.isConst() || f.isInvariant()) && !isThis()) | |
382 error("without 'this' cannot be const/immutable"); | |
383 | |
384 if (isAbstract() && isFinal()) | |
385 error("cannot be both final and abstract"); | |
386 static if (false) { | |
387 if (isAbstract() && fbody) | |
388 error("abstract functions cannot have bodies"); | |
389 } | |
390 | |
391 static if (false) { | |
392 if (isStaticConstructor() || isStaticDestructor()) | |
393 { | |
394 if (!isStatic() || type.nextOf().ty != Tvoid) | |
395 error("static constructors / destructors must be static void"); | |
396 if (f.arguments && f.arguments.dim) | |
397 error("static constructors / destructors must have empty parameter list"); | |
398 // BUG: check for invalid storage classes | |
399 } | |
400 } | |
401 | |
402 version (IN_GCC) { | |
403 AggregateDeclaration ad; | |
404 | |
405 ad = parent.isAggregateDeclaration(); | |
406 if (ad) | |
407 ad.methods.push(cast(void*)this); | |
408 } | |
409 sd = parent.isStructDeclaration(); | |
410 if (sd) | |
411 { | |
412 if (isCtorDeclaration()) | |
413 { | |
414 return; | |
415 } | |
416 static if (false) { | |
417 // Verify no constructors, destructors, etc. | |
418 if (isCtorDeclaration() | |
419 //||isDtorDeclaration() | |
420 //|| isInvariantDeclaration() | |
421 //|| isUnitTestDeclaration() | |
422 ) | |
423 { | |
424 error("special member functions not allowed for %ss", sd.kind()); | |
425 } | |
426 | |
427 if (!sd.inv) | |
428 sd.inv = isInvariantDeclaration(); | |
429 | |
430 if (!sd.aggNew) | |
431 sd.aggNew = isNewDeclaration(); | |
432 | |
433 if (isDelete()) | |
434 { | |
435 if (sd.aggDelete) | |
436 error("multiple delete's for struct %s", sd.toChars()); | |
437 sd.aggDelete = cast(DeleteDeclaration)this; | |
438 } | |
439 } | |
440 } | |
441 | |
442 id = parent.isInterfaceDeclaration(); | |
443 if (id) | |
444 { | |
445 storage_class |= STC.STCabstract; | |
446 | |
447 if (isCtorDeclaration() || | |
448 ///static if (DMDV2) { | |
449 isPostBlitDeclaration() || | |
450 ///} | |
451 isDtorDeclaration() || | |
452 isInvariantDeclaration() || | |
453 isUnitTestDeclaration() || isNewDeclaration() || isDelete()) | |
454 error("special function not allowed in interface %s", id.toChars()); | |
455 if (fbody) | |
456 error("function body is not abstract in interface %s", id.toChars()); | |
457 } | |
458 | |
459 /* Template member functions aren't virtual: | |
460 * interface TestInterface { void tpl(T)(); } | |
461 * and so won't work in interfaces | |
462 */ | |
463 if ((pd = toParent()) !is null && | |
464 pd.isTemplateInstance() && | |
465 (pd = toParent2()) !is null && | |
466 (id = pd.isInterfaceDeclaration()) !is null) | |
467 { | |
468 error("template member function not allowed in interface %s", id.toChars()); | |
469 } | |
470 | |
471 cd = parent.isClassDeclaration(); | |
472 if (cd) | |
473 { int vi; | |
474 CtorDeclaration ctor; | |
475 DtorDeclaration dtor; | |
476 InvariantDeclaration inv; | |
477 | |
478 if (isCtorDeclaration()) | |
479 { | |
480 // ctor = cast(CtorDeclaration)this; | |
481 // if (!cd.ctor) | |
482 // cd.ctor = ctor; | |
483 return; | |
484 } | |
485 | |
486 static if (false) { | |
487 dtor = isDtorDeclaration(); | |
488 if (dtor) | |
489 { | |
490 if (cd.dtor) | |
491 error("multiple destructors for class %s", cd.toChars()); | |
492 cd.dtor = dtor; | |
493 } | |
494 | |
495 inv = isInvariantDeclaration(); | |
496 if (inv) | |
497 { | |
498 cd.inv = inv; | |
499 } | |
500 | |
501 if (isNewDeclaration()) | |
502 { | |
503 if (!cd.aggNew) | |
504 cd.aggNew = cast(NewDeclaration)this; | |
505 } | |
506 | |
507 if (isDelete()) | |
508 { | |
509 if (cd.aggDelete) | |
510 error("multiple delete's for class %s", cd.toChars()); | |
511 cd.aggDelete = cast(DeleteDeclaration)this; | |
512 } | |
513 } | |
514 | |
515 if (storage_class & STC.STCabstract) | |
516 cd.isabstract = true; | |
517 | |
518 // if static function, do not put in vtbl[] | |
519 if (!isVirtual()) | |
520 { | |
521 //printf("\tnot virtual\n"); | |
522 goto Ldone; | |
523 } | |
524 | |
525 // Find index of existing function in vtbl[] to override | |
526 vi = findVtblIndex(cd.vtbl, cd.baseClass ? cd.baseClass.vtbl.dim : 0); | |
527 switch (vi) | |
528 { | |
529 case -1: | |
530 /* Didn't find one, so | |
531 * This is an 'introducing' function which gets a new | |
532 * slot in the vtbl[]. | |
533 */ | |
534 | |
535 // Verify this doesn't override previous final function | |
536 if (cd.baseClass) | |
537 { | |
538 Dsymbol s = cd.baseClass.search(loc, ident, 0); | |
539 if (s) | |
540 { | |
541 FuncDeclaration ff = s.isFuncDeclaration(); | |
542 ff = ff.overloadExactMatch(type); | |
543 if (ff && ff.isFinal() && ff.prot() != PROT.PROTprivate) | |
544 error("cannot override final function %s", ff.toPrettyChars()); | |
545 } | |
546 } | |
547 | |
548 if (isFinal()) | |
549 { | |
550 if (isOverride()) | |
551 error("does not override any function"); | |
552 cd.vtblFinal.push(cast(void*)this); | |
553 } | |
554 else | |
555 { | |
556 // Append to end of vtbl[] | |
557 //printf("\tintroducing function\n"); | |
558 introducing = 1; | |
559 vi = cd.vtbl.dim; | |
560 cd.vtbl.push(cast(void*)this); | |
561 vtblIndex = vi; | |
562 } | |
563 break; | |
564 | |
565 case -2: // can't determine because of fwd refs | |
566 cd.sizeok = 2; // can't finish due to forward reference | |
567 return; | |
568 | |
569 default: | |
570 { | |
571 FuncDeclaration fdv = cast(FuncDeclaration)cd.vtbl.data[vi]; | |
572 // This function is covariant with fdv | |
573 if (fdv.isFinal()) | |
574 error("cannot override final function %s", fdv.toPrettyChars()); | |
575 | |
576 version (DMDV2) { | |
577 if (!isOverride()) | |
578 warning(loc, "overrides base class function %s, but is not marked with 'override'", fdv.toPrettyChars()); | |
579 } | |
580 | |
581 if (fdv.toParent() == parent) | |
582 { | |
583 // If both are mixins, then error. | |
584 // If either is not, the one that is not overrides | |
585 // the other. | |
586 if (fdv.parent.isClassDeclaration()) | |
587 break; | |
588 if (!this.parent.isClassDeclaration() | |
589 ///static if (!BREAKABI) { | |
590 && !isDtorDeclaration() | |
591 ///} | |
592 ///version (DMDV2) { | |
593 && !isPostBlitDeclaration() | |
594 ///} | |
595 ) | |
596 error("multiple overrides of same function"); | |
597 } | |
598 cd.vtbl.data[vi] = cast(void*)this; | |
599 vtblIndex = vi; | |
73 | 600 |
601 /* Remember which functions this overrides | |
602 */ | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
73
diff
changeset
|
603 foverrides.push(fdv); |
0 | 604 |
605 /* This works by whenever this function is called, | |
606 * it actually returns tintro, which gets dynamically | |
607 * cast to type. But we know that tintro is a base | |
608 * of type, so we could optimize it by not doing a | |
609 * dynamic cast, but just subtracting the isBaseOf() | |
610 * offset if the value is != null. | |
611 */ | |
612 | |
613 if (fdv.tintro) | |
614 tintro = fdv.tintro; | |
615 else if (!type.equals(fdv.type)) | |
616 { | |
617 /* Only need to have a tintro if the vptr | |
618 * offsets differ | |
619 */ | |
620 int offset; | |
621 if (fdv.type.nextOf().isBaseOf(type.nextOf(), &offset)) | |
622 { | |
623 tintro = fdv.type; | |
624 } | |
625 } | |
626 break; | |
627 } | |
628 } | |
629 | |
630 /* Go through all the interface bases. | |
631 * If this function is covariant with any members of those interface | |
632 * functions, set the tintro. | |
633 */ | |
634 for (int i = 0; i < cd.interfaces_dim; i++) | |
635 { | |
636 BaseClass b = cd.interfaces[i]; | |
637 vi = findVtblIndex(b.base.vtbl, b.base.vtbl.dim); | |
638 switch (vi) | |
639 { | |
640 case -1: | |
641 break; | |
642 | |
643 case -2: | |
644 cd.sizeok = 2; // can't finish due to forward reference | |
645 return; | |
646 | |
647 default: | |
648 { FuncDeclaration fdv = cast(FuncDeclaration)b.base.vtbl.data[vi]; | |
649 Type ti = null; | |
73 | 650 |
651 /* Remember which functions this overrides | |
652 */ | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
73
diff
changeset
|
653 foverrides.push(fdv); |
0 | 654 |
655 if (fdv.tintro) | |
73 | 656 ti = fdv.tintro; |
0 | 657 else if (!type.equals(fdv.type)) |
658 { | |
659 /* Only need to have a tintro if the vptr | |
660 * offsets differ | |
661 */ | |
662 int offset; | |
663 if (fdv.type.nextOf().isBaseOf(type.nextOf(), &offset)) | |
664 { | |
665 ti = fdv.type; | |
666 static if (false) { | |
667 if (offset) | |
668 ti = fdv.type; | |
669 else if (type.nextOf().ty == Tclass) | |
670 { | |
671 ClassDeclaration cdn = (cast(TypeClass)type.nextOf()).sym; | |
672 if (cdn && cdn.sizeok != 1) | |
673 ti = fdv.type; | |
674 } | |
675 } | |
676 } | |
677 } | |
678 if (ti) | |
679 { | |
680 if (tintro && !tintro.equals(ti)) | |
681 { | |
682 error("incompatible covariant types %s and %s", tintro.toChars(), ti.toChars()); | |
683 } | |
684 tintro = ti; | |
685 } | |
686 goto L2; | |
687 } | |
688 } | |
689 } | |
690 | |
691 if (introducing && isOverride()) | |
692 { | |
693 error("does not override any function"); | |
694 } | |
695 | |
696 L2: ; | |
697 } | |
698 else if (isOverride() && !parent.isTemplateInstance()) | |
699 error("override only applies to class member functions"); | |
700 | |
701 /* Do not allow template instances to add virtual functions | |
702 * to a class. | |
703 */ | |
704 if (isVirtual()) | |
705 { | |
706 TemplateInstance ti = parent.isTemplateInstance(); | |
707 if (ti) | |
708 { | |
709 // Take care of nested templates | |
710 while (1) | |
711 { | |
712 TemplateInstance ti2 = ti.tempdecl.parent.isTemplateInstance(); | |
713 if (!ti2) | |
714 break; | |
715 ti = ti2; | |
716 } | |
717 | |
718 // If it's a member template | |
719 ClassDeclaration cdd = ti.tempdecl.isClassMember(); | |
720 if (cdd) | |
721 { | |
722 error("cannot use template to add virtual function to class '%s'", cdd.toChars()); | |
723 } | |
724 } | |
725 } | |
726 | |
727 if (isMain()) | |
728 { | |
729 // Check parameters to see if they are either () or (char[][] args) | |
730 switch (nparams) | |
731 { | |
732 case 0: | |
733 break; | |
734 | |
735 case 1: | |
736 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
737 auto arg0 = Parameter.getNth(f.parameters, 0); |
0 | 738 if (arg0.type.ty != TY.Tarray || |
739 arg0.type.nextOf().ty != TY.Tarray || | |
740 arg0.type.nextOf().nextOf().ty != TY.Tchar || | |
741 arg0.storageClass & (STC.STCout | STC.STCref | STC.STClazy)) | |
742 goto Lmainerr; | |
743 break; | |
744 } | |
745 | |
746 default: | |
747 goto Lmainerr; | |
748 } | |
749 | |
79 | 750 if (!f.nextOf()) |
751 error("must return int or void"); | |
752 else if (f.nextOf().ty != TY.Tint32 && f.nextOf().ty != TY.Tvoid) | |
0 | 753 error("must return int or void, not %s", f.nextOf().toChars()); |
754 if (f.varargs) | |
755 { | |
756 Lmainerr: | |
757 error("parameters must be main() or main(char[][] args)"); | |
758 } | |
759 } | |
760 | |
761 if (ident == Id.assign && (sd || cd)) | |
762 { // Disallow identity assignment operator. | |
763 | |
764 // opAssign(...) | |
765 if (nparams == 0) | |
766 { if (f.varargs == 1) | |
767 goto Lassignerr; | |
768 } | |
769 else | |
770 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
771 auto arg0 = Parameter.getNth(f.parameters, 0); |
0 | 772 Type t0 = arg0.type.toBasetype(); |
773 Type tb = sd ? sd.type : cd.type; | |
774 if (arg0.type.implicitConvTo(tb) || | |
775 (sd && t0.ty == TY.Tpointer && t0.nextOf().implicitConvTo(tb)) | |
776 ) | |
777 { | |
778 if (nparams == 1) | |
779 goto Lassignerr; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
780 auto arg1 = Parameter.getNth(f.parameters, 1); |
0 | 781 if (arg1.defaultArg) |
782 goto Lassignerr; | |
783 } | |
784 } | |
785 } | |
73 | 786 |
787 if (isVirtual()) | |
788 { | |
789 /* Rewrite contracts as nested functions, then call them. | |
790 * Doing it as nested functions means that overriding functions | |
791 * can call them. | |
792 */ | |
793 if (frequire) | |
794 { | |
795 /* in { ... } | |
796 * becomes: | |
797 * void __require() { ... } | |
798 * __require(); | |
799 */ | |
800 Loc loc = frequire.loc; | |
801 TypeFunction tf = new TypeFunction(null, Type.tvoid, 0, LINKd); | |
802 FuncDeclaration fd = new FuncDeclaration(loc, loc, Id.require, STCundefined, tf); | |
803 fd.fbody = frequire; | |
804 Statement s1 = new DeclarationStatement(loc, fd); | |
805 Expression e = new CallExp(loc, new VarExp(loc, fd, 0), cast(Expressions)null); | |
806 Statement s2 = new ExpStatement(loc, e); | |
807 frequire = new CompoundStatement(loc, s1, s2); | |
808 fdrequire = fd; | |
809 } | |
810 | |
811 if (fensure) | |
812 { /* out (result) { ... } | |
813 * becomes: | |
814 * tret __ensure(ref tret result) { ... } | |
815 * __ensure(result); | |
816 */ | |
817 if (!outId && f.nextOf().toBasetype().ty != Tvoid) | |
818 outId = Id.result; // provide a default | |
819 | |
820 Loc loc = fensure.loc; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
821 auto arguments = new Parameters(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
822 Parameter a = null; |
73 | 823 if (outId) |
824 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
825 a = new Parameter(STCref, f.nextOf(), outId, null); |
126
1765f3ef917d
ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
122
diff
changeset
|
826 arguments.push(a); |
73 | 827 } |
828 TypeFunction tf = new TypeFunction(arguments, Type.tvoid, 0, LINKd); | |
829 FuncDeclaration fd = new FuncDeclaration(loc, loc, Id.ensure, STCundefined, tf); | |
830 fd.fbody = fensure; | |
831 Statement s1 = new DeclarationStatement(loc, fd); | |
832 Expression eresult = null; | |
833 if (outId) | |
834 eresult = new IdentifierExp(loc, outId); | |
835 Expression e = new CallExp(loc, new VarExp(loc, fd, 0), eresult); | |
836 Statement s2 = new ExpStatement(loc, e); | |
837 fensure = new CompoundStatement(loc, s1, s2); | |
838 fdensure = fd; | |
839 } | |
840 } | |
0 | 841 |
842 Ldone: | |
843 /* Save scope for possible later use (if we need the | |
844 * function internals) | |
845 */ | |
87
b17640f0e4e8
Fixed a bug with a Scope.this(Scope enclosing) being called instead of Scope.clone() method (as a copy ctor replacement)
korDen
parents:
79
diff
changeset
|
846 scope_ = sc.clone(); |
0 | 847 scope_.setNoFree(); |
848 return; | |
849 | |
850 Lassignerr: | |
851 if (sd) | |
852 { | |
853 sd.hasIdentityAssign = 1; // don't need to generate it | |
854 goto Ldone; | |
855 } | |
856 error("identity assignment operator overload is illegal"); | |
857 } | |
858 | |
72 | 859 override void semantic2(Scope sc) |
0 | 860 { |
861 } | |
862 | |
863 // Do the semantic analysis on the internals of the function. | |
72 | 864 override void semantic3(Scope sc) |
0 | 865 { |
866 TypeFunction f; | |
867 VarDeclaration argptr = null; | |
868 VarDeclaration _arguments = null; | |
869 | |
870 if (!parent) | |
871 { | |
872 if (global.errors) | |
873 return; | |
874 //printf("FuncDeclaration.semantic3(%s '%s', sc = %p)\n", kind(), toChars(), sc); | |
875 assert(0); | |
876 } | |
877 //printf("FuncDeclaration.semantic3('%s.%s', sc = %p, loc = %s)\n", parent.toChars(), toChars(), sc, loc.toChars()); | |
878 //fflush(stdout); | |
879 //printf("storage class = x%x %x\n", sc.stc, storage_class); | |
880 //{ static int x; if (++x == 2) *(char*)0=0; } | |
881 //printf("\tlinkage = %d\n", sc.linkage); | |
882 | |
883 //printf(" sc.incontract = %d\n", sc.incontract); | |
884 if (semanticRun >= 3) | |
885 return; | |
886 semanticRun = 3; | |
887 | |
888 if (!type || type.ty != TY.Tfunction) | |
889 return; | |
890 f = cast(TypeFunction)(type); | |
891 | |
892 // Check the 'throws' clause | |
893 if (fthrows) | |
894 { | |
895 for (int i = 0; i < fthrows.dim; i++) | |
896 { | |
897 Type t = cast(Type)fthrows.data[i]; | |
898 | |
899 t = t.semantic(loc, sc); | |
900 if (!t.isClassHandle()) | |
901 error("can only throw classes, not %s", t.toChars()); | |
902 } | |
903 } | |
73 | 904 |
905 frequire = mergeFrequire(frequire); | |
906 fensure = mergeFensure(fensure); | |
0 | 907 |
908 if (fbody || frequire) | |
909 { | |
910 /* Symbol table into which we place parameters and nested functions, | |
911 * solely to diagnose name collisions. | |
912 */ | |
913 localsymtab = new DsymbolTable(); | |
914 | |
915 // Establish function scope | |
916 ScopeDsymbol ss = new ScopeDsymbol(); | |
917 ss.parent = sc.scopesym; | |
918 Scope sc2 = sc.push(ss); | |
919 sc2.func = this; | |
920 sc2.parent = this; | |
921 sc2.callSuper = 0; | |
922 sc2.sbreak = null; | |
923 sc2.scontinue = null; | |
924 sc2.sw = null; | |
925 sc2.fes = fes; | |
926 sc2.linkage = LINK.LINKd; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
927 sc2.stc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCabstract | STC.STCdeprecated | |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
928 STC.STC_TYPECTOR | STC.STCfinal | STC.STCtls | STC.STCgshared | STC.STCref | |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
929 STCproperty | STCsafe | STCtrusted | STCsystem); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
930 sc2.protection = PROT.PROTpublic; |
0 | 931 sc2.explicitProtection = 0; |
932 sc2.structalign = 8; | |
933 sc2.incontract = 0; | |
934 sc2.tf = null; | |
935 sc2.noctor = 0; | |
936 | |
937 // Declare 'this' | |
938 AggregateDeclaration ad = isThis(); | |
939 if (ad) | |
940 { VarDeclaration v; | |
941 | |
942 if (isFuncLiteralDeclaration() && isNested()) | |
943 { | |
944 error("literals cannot be class members"); | |
945 return; | |
946 } | |
947 else | |
948 { | |
949 assert(!isNested()); // can't be both member and nested | |
950 assert(ad.handle); | |
951 Type thandle = ad.handle; | |
952 version (STRUCTTHISREF) { | |
953 thandle = thandle.addMod(type.mod); | |
954 thandle = thandle.addStorageClass(storage_class); | |
955 if (isPure()) | |
956 thandle = thandle.addMod(MOD.MODconst); | |
957 } else { | |
958 if (storage_class & STC.STCconst || type.isConst()) | |
959 { | |
960 assert(0); // BUG: shared not handled | |
961 if (thandle.ty == TY.Tclass) | |
962 thandle = thandle.constOf(); | |
963 else | |
964 { assert(thandle.ty == TY.Tpointer); | |
965 thandle = thandle.nextOf().constOf().pointerTo(); | |
966 } | |
967 } | |
968 else if (storage_class & STC.STCimmutable || type.isInvariant()) | |
969 { | |
970 if (thandle.ty == TY.Tclass) | |
971 thandle = thandle.invariantOf(); | |
972 else | |
973 { assert(thandle.ty == TY.Tpointer); | |
974 thandle = thandle.nextOf().invariantOf().pointerTo(); | |
975 } | |
976 } | |
977 else if (storage_class & STC.STCshared || type.isShared()) | |
978 { | |
979 assert(0); // not implemented | |
980 } | |
981 } | |
982 v = new ThisDeclaration(loc, thandle); | |
983 v.storage_class |= STC.STCparameter; | |
984 version (STRUCTTHISREF) { | |
985 if (thandle.ty == TY.Tstruct) | |
986 v.storage_class |= STC.STCref; | |
987 } | |
988 v.semantic(sc2); | |
989 if (!sc2.insert(v)) | |
990 assert(0); | |
991 v.parent = this; | |
992 vthis = v; | |
993 } | |
994 } | |
995 else if (isNested()) | |
996 { | |
997 /* The 'this' for a nested function is the link to the | |
998 * enclosing function's stack frame. | |
999 * Note that nested functions and member functions are disjoint. | |
1000 */ | |
1001 VarDeclaration v = new ThisDeclaration(loc, Type.tvoid.pointerTo()); | |
1002 v.storage_class |= STC.STCparameter; | |
1003 v.semantic(sc2); | |
1004 if (!sc2.insert(v)) | |
1005 assert(0); | |
1006 v.parent = this; | |
1007 vthis = v; | |
1008 } | |
1009 | |
1010 // Declare hidden variable _arguments[] and _argptr | |
1011 if (f.varargs == 1) | |
1012 { | |
1013 version (TARGET_NET) { | |
1014 varArgs(sc2, f, argptr, _arguments); | |
1015 } else { | |
1016 Type t; | |
1017 | |
1018 if (f.linkage == LINK.LINKd) | |
1019 { | |
1020 // Declare _arguments[] | |
1021 version (BREAKABI) { | |
1022 v_arguments = new VarDeclaration(Loc(0), Type.typeinfotypelist.type, Id._arguments_typeinfo, null); | |
1023 v_arguments.storage_class = STCparameter; | |
1024 v_arguments.semantic(sc2); | |
1025 sc2.insert(v_arguments); | |
1026 v_arguments.parent = this; | |
1027 | |
1028 //t = Type.typeinfo.type.constOf().arrayOf(); | |
1029 t = Type.typeinfo.type.arrayOf(); | |
1030 _arguments = new VarDeclaration(Loc(0), t, Id._arguments, null); | |
1031 _arguments.semantic(sc2); | |
1032 sc2.insert(_arguments); | |
1033 _arguments.parent = this; | |
1034 } else { | |
1035 t = Type.typeinfo.type.arrayOf(); | |
1036 v_arguments = new VarDeclaration(Loc(0), t, Id._arguments, null); | |
1037 v_arguments.storage_class = STC.STCparameter | STC.STCin; | |
1038 v_arguments.semantic(sc2); | |
1039 sc2.insert(v_arguments); | |
1040 v_arguments.parent = this; | |
1041 } | |
1042 } | |
1043 if (f.linkage == LINK.LINKd || (parameters && parameters.dim)) | |
1044 { // Declare _argptr | |
1045 version (IN_GCC) { | |
1046 t = d_gcc_builtin_va_list_d_type; | |
1047 } else { | |
1048 t = Type.tvoid.pointerTo(); | |
1049 } | |
1050 argptr = new VarDeclaration(Loc(0), t, Id._argptr, null); | |
1051 argptr.semantic(sc2); | |
1052 sc2.insert(argptr); | |
1053 argptr.parent = this; | |
1054 } | |
1055 } | |
1056 } | |
1057 | |
1058 // Propagate storage class from tuple parameters to their element-parameters. | |
1059 if (f.parameters) | |
1060 { | |
126
1765f3ef917d
ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
122
diff
changeset
|
1061 foreach (arg; f.parameters) |
1765f3ef917d
ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
122
diff
changeset
|
1062 { |
0 | 1063 //printf("[%d] arg.type.ty = %d %s\n", i, arg.type.ty, arg.type.toChars()); |
1064 if (arg.type.ty == TY.Ttuple) | |
126
1765f3ef917d
ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
122
diff
changeset
|
1065 { auto t = cast(TypeTuple)arg.type; |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
1066 size_t dim = Parameter.dim(t.arguments); |
0 | 1067 for (size_t j = 0; j < dim; j++) |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
1068 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
1069 auto narg = Parameter.getNth(t.arguments, j); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
1070 narg.storageClass = arg.storageClass; |
0 | 1071 } |
1072 } | |
1073 } | |
1074 } | |
1075 | |
1076 /* Declare all the function parameters as variables | |
1077 * and install them in parameters[] | |
1078 */ | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
1079 size_t nparams = Parameter.dim(f.parameters); |
0 | 1080 if (nparams) |
1081 { /* parameters[] has all the tuples removed, as the back end | |
1082 * doesn't know about tuples | |
1083 */ | |
1084 parameters = new Dsymbols(); | |
1085 parameters.reserve(nparams); | |
1086 for (size_t i = 0; i < nparams; i++) | |
1087 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
1088 auto arg = Parameter.getNth(f.parameters, i); |
0 | 1089 Identifier id = arg.ident; |
1090 if (!id) | |
1091 { | |
1092 /* Generate identifier for un-named parameter, | |
1093 * because we need it later on. | |
1094 */ | |
1095 arg.ident = id = Identifier.generateId("_param_", i); | |
1096 } | |
1097 Type vtype = arg.type; | |
1098 if (isPure()) | |
1099 vtype = vtype.addMod(MOD.MODconst); | |
1100 VarDeclaration v = new VarDeclaration(loc, vtype, id, null); | |
1101 //printf("declaring parameter %s of type %s\n", v.toChars(), v.type.toChars()); | |
1102 v.storage_class |= STC.STCparameter; | |
1103 if (f.varargs == 2 && i + 1 == nparams) | |
1104 v.storage_class |= STC.STCvariadic; | |
1105 v.storage_class |= arg.storageClass & (STC.STCin | STC.STCout | STC.STCref | STC.STClazy | STC.STCfinal | STC.STC_TYPECTOR | STC.STCnodtor); | |
1106 v.semantic(sc2); | |
1107 if (!sc2.insert(v)) | |
1108 error("parameter %s.%s is already defined", toChars(), v.toChars()); | |
1109 else | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
73
diff
changeset
|
1110 parameters.push(v); |
0 | 1111 localsymtab.insert(v); |
1112 v.parent = this; | |
1113 } | |
1114 } | |
1115 | |
1116 // Declare the tuple symbols and put them in the symbol table, | |
1117 // but not in parameters[]. | |
1118 if (f.parameters) | |
1119 { | |
126
1765f3ef917d
ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
122
diff
changeset
|
1120 foreach (arg; f.parameters) |
1765f3ef917d
ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
122
diff
changeset
|
1121 { |
0 | 1122 if (!arg.ident) |
1123 continue; // never used, so ignore | |
1124 if (arg.type.ty == TY.Ttuple) | |
126
1765f3ef917d
ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
122
diff
changeset
|
1125 { auto t = cast(TypeTuple)arg.type; |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
1126 size_t dim = Parameter.dim(t.arguments); |
0 | 1127 Objects exps = new Objects(); |
1128 exps.setDim(dim); | |
1129 for (size_t j = 0; j < dim; j++) | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
1130 { auto narg = Parameter.getNth(t.arguments, j); |
0 | 1131 assert(narg.ident); |
1132 VarDeclaration v = sc2.search(Loc(0), narg.ident, null).isVarDeclaration(); | |
1133 assert(v); | |
1134 Expression e = new VarExp(v.loc, v); | |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
93
diff
changeset
|
1135 exps[j] = e; |
0 | 1136 } |
1137 assert(arg.ident); | |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
93
diff
changeset
|
1138 auto v = new TupleDeclaration(loc, arg.ident, exps); |
0 | 1139 //printf("declaring tuple %s\n", v.toChars()); |
1140 v.isexp = 1; | |
1141 if (!sc2.insert(v)) | |
1142 error("parameter %s.%s is already defined", toChars(), v.toChars()); | |
1143 localsymtab.insert(v); | |
1144 v.parent = this; | |
1145 } | |
1146 } | |
1147 } | |
1148 | |
1149 /* Do the semantic analysis on the [in] preconditions and | |
1150 * [out] postconditions. | |
1151 */ | |
1152 sc2.incontract++; | |
1153 | |
1154 if (frequire) | |
1155 { /* frequire is composed of the [in] contracts | |
1156 */ | |
1157 // BUG: need to error if accessing out parameters | |
1158 // BUG: need to treat parameters as const | |
1159 // BUG: need to disallow returns and throws | |
1160 // BUG: verify that all in and ref parameters are read | |
1161 frequire = frequire.semantic(sc2); | |
1162 labtab = null; // so body can't refer to labels | |
1163 } | |
1164 | |
1165 if (fensure || addPostInvariant()) | |
79 | 1166 { |
1167 /* fensure is composed of the [out] contracts | |
0 | 1168 */ |
79 | 1169 if (!type.nextOf()) // if return type is inferred |
1170 { | |
1171 /* This case: | |
1172 * auto fp = function() out { } body { }; | |
1173 * Can fix by doing semantic() onf fbody first. | |
1174 */ | |
1175 error("post conditions are not supported if the return type is inferred"); | |
1176 return; | |
1177 } | |
1178 | |
0 | 1179 ScopeDsymbol sym = new ScopeDsymbol(); |
1180 sym.parent = sc2.scopesym; | |
1181 sc2 = sc2.push(sym); | |
1182 | |
1183 assert(type.nextOf()); | |
1184 if (type.nextOf().ty == TY.Tvoid) | |
1185 { | |
1186 if (outId) | |
1187 error("void functions have no result"); | |
1188 } | |
1189 else | |
1190 { | |
1191 if (!outId) | |
1192 outId = Id.result; // provide a default | |
1193 } | |
1194 | |
1195 if (outId) | |
1196 { // Declare result variable | |
1197 Loc loc = this.loc; | |
1198 | |
1199 if (fensure) | |
1200 loc = fensure.loc; | |
1201 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
1202 auto v = new VarDeclaration(loc, type.nextOf(), outId, null); |
0 | 1203 v.noauto = true; |
1204 version (DMDV2) { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
1205 if (!isVirtual()) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
1206 v.storage_class |= STC.STCconst; |
0 | 1207 if (f.isref) |
1208 { | |
1209 v.storage_class |= STC.STCref | STC.STCforeach; | |
1210 } | |
1211 } | |
1212 sc2.incontract--; | |
1213 v.semantic(sc2); | |
1214 sc2.incontract++; | |
1215 if (!sc2.insert(v)) | |
1216 error("out result %s is already defined", v.toChars()); | |
1217 v.parent = this; | |
1218 vresult = v; | |
1219 | |
1220 // vresult gets initialized with the function return value | |
1221 // in ReturnStatement.semantic() | |
1222 } | |
1223 | |
1224 // BUG: need to treat parameters as const | |
1225 // BUG: need to disallow returns and throws | |
1226 if (fensure) | |
1227 { fensure = fensure.semantic(sc2); | |
1228 labtab = null; // so body can't refer to labels | |
1229 } | |
1230 | |
1231 if (!global.params.useOut) | |
1232 { fensure = null; // discard | |
1233 vresult = null; | |
1234 } | |
1235 | |
1236 // Postcondition invariant | |
1237 if (addPostInvariant()) | |
1238 { | |
1239 Expression e = null; | |
1240 if (isCtorDeclaration()) | |
1241 { | |
1242 // Call invariant directly only if it exists | |
1243 InvariantDeclaration inv = ad.inv; | |
1244 ClassDeclaration cd = ad.isClassDeclaration(); | |
1245 | |
1246 while (!inv && cd) | |
1247 { | |
1248 cd = cd.baseClass; | |
1249 if (!cd) | |
1250 break; | |
1251 inv = cd.inv; | |
1252 } | |
1253 if (inv) | |
1254 { | |
1255 e = new DsymbolExp(Loc(0), inv); | |
1256 e = new CallExp(Loc(0), e); | |
1257 e = e.semantic(sc2); | |
1258 } | |
1259 } | |
1260 else | |
1261 { // Call invariant virtually | |
1262 Expression v = new ThisExp(Loc(0)); | |
1263 v.type = vthis.type; | |
1264 version (STRUCTTHISREF) { | |
1265 if (ad.isStructDeclaration()) | |
1266 v = v.addressOf(sc); | |
1267 } | |
1268 e = new AssertExp(Loc(0), v); | |
1269 } | |
1270 if (e) | |
1271 { | |
1272 ExpStatement s = new ExpStatement(Loc(0), e); | |
1273 if (fensure) | |
1274 fensure = new CompoundStatement(Loc(0), s, fensure); | |
1275 else | |
1276 fensure = s; | |
1277 } | |
1278 } | |
1279 | |
1280 if (fensure) | |
1281 { returnLabel = new LabelDsymbol(Id.returnLabel); | |
1282 LabelStatement ls = new LabelStatement(Loc(0), Id.returnLabel, fensure); | |
1283 ls.isReturnLabel = 1; | |
1284 returnLabel.statement = ls; | |
1285 } | |
1286 sc2 = sc2.pop(); | |
1287 } | |
1288 | |
1289 sc2.incontract--; | |
1290 | |
1291 if (fbody) | |
1292 { ClassDeclaration cd = isClassMember(); | |
1293 | |
1294 /* If this is a class constructor | |
1295 */ | |
1296 if (isCtorDeclaration() && cd) | |
1297 { | |
79 | 1298 for (int i = 0; i < cd.fields.dim; i++) |
1299 { VarDeclaration v = cast(VarDeclaration)cd.fields[i]; | |
1300 | |
1301 v.ctorinit = 0; | |
1302 } | |
0 | 1303 } |
1304 | |
1305 if (inferRetType || f.retStyle() != RET.RETstack) | |
1306 nrvo_can = 0; | |
1307 | |
1308 fbody = fbody.semantic(sc2); | |
1309 if (!fbody) | |
1310 fbody = new CompoundStatement(Loc(0), new Statements()); | |
1311 | |
1312 if (inferRetType) | |
1313 { // If no return type inferred yet, then infer a void | |
1314 if (!type.nextOf()) | |
1315 { | |
1316 (cast(TypeFunction)type).next = Type.tvoid; | |
1317 type = type.semantic(loc, sc); | |
1318 } | |
1319 f = cast(TypeFunction)type; | |
1320 } | |
1321 | |
1322 if (isStaticCtorDeclaration()) | |
1323 { | |
1324 /* It's a static constructor. Ensure that all | |
1325 * ctor consts were initialized. | |
1326 */ | |
1327 | |
1328 Dsymbol p = toParent(); | |
1329 ScopeDsymbol add = p.isScopeDsymbol(); | |
1330 if (!add) | |
1331 { | |
1332 error("static constructor can only be member of struct/class/module, not %s %s", p.kind(), p.toChars()); | |
1333 } | |
1334 else | |
1335 { | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
1336 foreach (Dsymbol s; add.members) |
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
1337 { |
0 | 1338 s.checkCtorConstInit(); |
1339 } | |
1340 } | |
1341 } | |
1342 | |
1343 if (isCtorDeclaration() && cd) | |
1344 { | |
1345 //printf("callSuper = x%x\n", sc2.callSuper); | |
1346 | |
1347 // Verify that all the ctorinit fields got initialized | |
1348 if (!(sc2.callSuper & CSX.CSXthis_ctor)) | |
1349 { | |
1350 for (int i = 0; i < cd.fields.dim; i++) | |
79 | 1351 { VarDeclaration v = cast(VarDeclaration)cd.fields[i]; |
0 | 1352 |
1353 if (v.ctorinit == 0 && v.isCtorinit()) | |
1354 error("missing initializer for final field %s", v.toChars()); | |
1355 } | |
1356 } | |
1357 | |
1358 if (!(sc2.callSuper & CSX.CSXany_ctor) && | |
1359 cd.baseClass && cd.baseClass.ctor) | |
1360 { | |
1361 sc2.callSuper = 0; | |
1362 | |
1363 // Insert implicit super() at start of fbody | |
1364 Expression e1 = new SuperExp(Loc(0)); | |
1365 Expression e = new CallExp(Loc(0), e1); | |
1366 | |
1367 e = e.trySemantic(sc2); | |
1368 if (!e) | |
1369 error("no match for implicit super() call in constructor"); | |
1370 else | |
1371 { | |
1372 Statement s = new ExpStatement(Loc(0), e); | |
1373 fbody = new CompoundStatement(Loc(0), s, fbody); | |
1374 } | |
1375 } | |
1376 } | |
1377 else if (fes) | |
1378 { // For foreach(){} body, append a return 0; | |
1379 Expression e = new IntegerExp(0); | |
1380 Statement s = new ReturnStatement(Loc(0), e); | |
1381 fbody = new CompoundStatement(Loc(0), fbody, s); | |
1382 assert(!returnLabel); | |
1383 } | |
1384 else if (!hasReturnExp && type.nextOf().ty != TY.Tvoid) | |
1385 error("expected to return a value of type %s", type.nextOf().toChars()); | |
1386 else if (!inlineAsm) | |
1387 { | |
1388 version (DMDV2) { | |
1389 BE blockexit = fbody ? fbody.blockExit() : BE.BEfallthru; | |
1390 if (f.isnothrow && blockexit & BE.BEthrow) | |
1391 error("'%s' is nothrow yet may throw", toChars()); | |
1392 | |
1393 int offend = blockexit & BE.BEfallthru; | |
1394 } | |
1395 if (type.nextOf().ty == TY.Tvoid) | |
1396 { | |
1397 if (offend && isMain()) | |
1398 { // Add a return 0; statement | |
1399 Statement s = new ReturnStatement(Loc(0), new IntegerExp(0)); | |
1400 fbody = new CompoundStatement(Loc(0), fbody, s); | |
1401 } | |
1402 } | |
1403 else | |
1404 { | |
1405 if (offend) | |
1406 { | |
1407 Expression e; | |
1408 version (DMDV1) { | |
1409 warning(loc, "no return exp; or assert(0); at end of function"); | |
1410 } else { | |
1411 error("no return exp; or assert(0); at end of function"); | |
1412 } | |
1413 if (global.params.useAssert && | |
1414 !global.params.useInline) | |
1415 { /* Add an assert(0, msg); where the missing return | |
1416 * should be. | |
1417 */ | |
1418 e = new AssertExp( | |
1419 endloc, | |
1420 new IntegerExp(0), | |
1421 new StringExp(loc, "missing return expression") | |
1422 ); | |
1423 } | |
1424 else | |
1425 e = new HaltExp(endloc); | |
1426 | |
1427 e = new CommaExp(Loc(0), e, type.nextOf().defaultInit(Loc(0))); | |
1428 e = e.semantic(sc2); | |
1429 Statement s = new ExpStatement(Loc(0), e); | |
1430 fbody = new CompoundStatement(Loc(0), fbody, s); | |
1431 } | |
1432 } | |
1433 } | |
1434 } | |
1435 | |
1436 { | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1437 auto a = new Statements(); |
0 | 1438 |
1439 // Merge in initialization of 'out' parameters | |
1440 if (parameters) | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
1441 { foreach (Dsymbol s; parameters) |
0 | 1442 { |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
1443 auto v = cast(VarDeclaration)s; |
0 | 1444 if (v.storage_class & STC.STCout) |
1445 { | |
1446 assert(v.init); | |
1447 ExpInitializer ie = v.init.isExpInitializer(); | |
1448 assert(ie); | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1449 a.push(new ExpStatement(Loc(0), ie.exp)); |
0 | 1450 } |
1451 } | |
1452 } | |
1453 | |
1454 if (argptr) | |
1455 { // Initialize _argptr to point past non-variadic arg | |
1456 version (IN_GCC) { | |
73 | 1457 // Handled in FuncDeclaration.toObjFile |
1458 v_argptr = argptr; | |
1459 v_argptr.init = new VoidInitializer(loc); | |
0 | 1460 } else { |
73 | 1461 Type t = argptr.type; |
1462 VarDeclaration p; | |
1463 uint offset; | |
1464 | |
1465 Expression e1 = new VarExp(Loc(0), argptr); | |
1466 if (parameters && parameters.dim) | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
1467 p = cast(VarDeclaration)parameters[parameters.length - 1]; |
73 | 1468 else |
1469 p = v_arguments; // last parameter is _arguments[] | |
1470 if (p.storage_class & STClazy) | |
1471 // If the last parameter is lazy, it's the size of a delegate | |
1472 offset = PTRSIZE * 2; | |
1473 else | |
1474 offset = cast(size_t)p.type.size(); | |
1475 offset = (offset + 3) & ~3; // assume stack aligns on 4 | |
1476 Expression e = new SymOffExp(Loc(0), p, offset); | |
1477 e = new AssignExp(Loc(0), e1, e); | |
1478 e.type = t; | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1479 a.push(new ExpStatement(Loc(0), e)); |
98 | 1480 p.isargptr = true; |
0 | 1481 } |
1482 } | |
1483 | |
1484 if (_arguments) | |
1485 { | |
1486 /* Advance to elements[] member of TypeInfo_Tuple with: | |
1487 * _arguments = v_arguments.elements; | |
1488 */ | |
1489 Expression e = new VarExp(Loc(0), v_arguments); | |
1490 e = new DotIdExp(Loc(0), e, Id.elements); | |
1491 Expression e1 = new VarExp(Loc(0), _arguments); | |
1492 e = new AssignExp(Loc(0), e1, e); | |
1493 e.op = TOK.TOKconstruct; | |
1494 e = e.semantic(sc2); | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1495 a.push(new ExpStatement(Loc(0), e)); |
0 | 1496 } |
1497 | |
1498 // Merge contracts together with body into one compound statement | |
1499 | |
1500 version (_DH) { | |
1501 if (frequire && global.params.useIn) | |
1502 { frequire.incontract = 1; | |
1503 a.push(frequire); | |
1504 } | |
1505 } else { | |
1506 if (frequire && global.params.useIn) | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1507 a.push(frequire); |
0 | 1508 } |
1509 | |
1510 // Precondition invariant | |
1511 if (addPreInvariant()) | |
1512 { | |
1513 Expression e = null; | |
1514 if (isDtorDeclaration()) | |
1515 { | |
1516 // Call invariant directly only if it exists | |
1517 InvariantDeclaration inv = ad.inv; | |
1518 ClassDeclaration cd = ad.isClassDeclaration(); | |
1519 | |
1520 while (!inv && cd) | |
1521 { | |
1522 cd = cd.baseClass; | |
1523 if (!cd) | |
1524 break; | |
1525 inv = cd.inv; | |
1526 } | |
1527 if (inv) | |
1528 { | |
1529 e = new DsymbolExp(Loc(0), inv); | |
1530 e = new CallExp(Loc(0), e); | |
1531 e = e.semantic(sc2); | |
1532 } | |
1533 } | |
1534 else | |
1535 { // Call invariant virtually | |
1536 Expression v = new ThisExp(Loc(0)); | |
1537 v.type = vthis.type; | |
1538 version (STRUCTTHISREF) { | |
1539 if (ad.isStructDeclaration()) | |
1540 v = v.addressOf(sc); | |
1541 } | |
1542 Expression se = new StringExp(Loc(0), "null this"); | |
1543 se = se.semantic(sc); | |
1544 se.type = Type.tchar.arrayOf(); | |
1545 e = new AssertExp(loc, v, se); | |
1546 } | |
1547 if (e) | |
1548 { | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1549 auto s = new ExpStatement(Loc(0), e); |
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1550 a.push(s); |
0 | 1551 } |
1552 } | |
1553 | |
1554 if (fbody) | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1555 a.push(fbody); |
0 | 1556 |
1557 if (fensure) | |
1558 { | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1559 a.push(returnLabel.statement); |
0 | 1560 |
1561 if (type.nextOf().ty != TY.Tvoid) | |
1562 { | |
1563 // Create: return vresult; | |
1564 assert(vresult); | |
1565 Expression e = new VarExp(Loc(0), vresult); | |
1566 if (tintro) | |
1567 { e = e.implicitCastTo(sc, tintro.nextOf()); | |
1568 e = e.semantic(sc); | |
1569 } | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1570 auto s = new ReturnStatement(Loc(0), e); |
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1571 a.push(s); |
0 | 1572 } |
1573 } | |
1574 | |
1575 fbody = new CompoundStatement(Loc(0), a); | |
1576 version (DMDV2) { | |
1577 /* Append destructor calls for parameters as finally blocks. | |
1578 */ | |
1579 if (parameters) | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
1580 { foreach(Dsymbol symb; parameters) |
0 | 1581 { |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
1582 auto v = cast(VarDeclaration)symb; |
0 | 1583 |
1584 if (v.storage_class & (STC.STCref | STC.STCout)) | |
1585 continue; | |
1586 | |
1587 /* Don't do this for static arrays, since static | |
1588 * arrays are called by reference. Remove this | |
1589 * when we change them to call by value. | |
1590 */ | |
1591 if (v.type.toBasetype().ty == TY.Tsarray) | |
1592 continue; | |
1593 | |
1594 Expression e = v.callAutoDtor(sc); | |
1595 if (e) | |
1596 { Statement s = new ExpStatement(Loc(0), e); | |
1597 s = s.semantic(sc); | |
1598 if (fbody.blockExit() == BE.BEfallthru) | |
1599 fbody = new CompoundStatement(Loc(0), fbody, s); | |
1600 else | |
1601 fbody = new TryFinallyStatement(Loc(0), fbody, s); | |
1602 } | |
1603 } | |
1604 } | |
1605 } | |
1606 | |
1607 static if (true) { | |
1608 if (isSynchronized()) | |
1609 { /* Wrap the entire function body in a synchronized statement | |
1610 */ | |
1611 ClassDeclaration cd = parent.isClassDeclaration(); | |
1612 if (cd) | |
1613 { | |
1614 ///version (TARGET_WINDOS) { | |
1615 if (/*config.flags2 & CFG2.CFG2seh &&*/ // always on for WINDOS | |
1616 !isStatic() && !fbody.usesEH()) | |
1617 { | |
1618 /* The back end uses the "jmonitor" hack for syncing; | |
1619 * no need to do the sync at this level. | |
1620 */ | |
1621 } | |
1622 else | |
1623 ///} | |
1624 { | |
1625 Expression vsync; | |
1626 if (isStatic()) | |
1627 { | |
1628 // The monitor is in the ClassInfo | |
1629 vsync = new DotIdExp(loc, new DsymbolExp(loc, cd), Id.classinfo_); | |
1630 } | |
1631 else | |
1632 { // 'this' is the monitor | |
1633 vsync = new VarExp(loc, vthis); | |
1634 } | |
1635 fbody = new PeelStatement(fbody); // don't redo semantic() | |
1636 fbody = new SynchronizedStatement(loc, vsync, fbody); | |
1637 fbody = fbody.semantic(sc2); | |
1638 } | |
1639 } | |
1640 else | |
1641 { | |
1642 error("synchronized function %s must be a member of a class", toChars()); | |
1643 } | |
1644 } | |
1645 } | |
1646 } | |
1647 | |
1648 sc2.callSuper = 0; | |
1649 sc2.pop(); | |
1650 } | |
1651 semanticRun = 4; | |
1652 } | |
1653 | |
1654 // called from semantic3 | |
1655 void varArgs(Scope sc, TypeFunction, ref VarDeclaration, ref VarDeclaration) | |
1656 { | |
1657 assert(false); | |
1658 } | |
93
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1659 |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1660 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 1661 { |
93
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1662 // writef("FuncDeclaration.toCBuffer() '%s'\n", toChars()); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1663 |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1664 StorageClassDeclaration.stcToCBuffer(buf, storage_class); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1665 type.toCBuffer(buf, ident, hgs); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1666 bodyToCBuffer(buf, hgs); |
0 | 1667 } |
1668 | |
93
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1669 void bodyToCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 1670 { |
93
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1671 if (fbody && |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1672 (!hgs.hdrgen || hgs.tpltMember || canInline(1,1)) |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1673 ) |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1674 { |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1675 buf.writenl(); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1676 |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1677 // in{} |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1678 if (frequire) |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1679 { |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1680 buf.writestring("in"); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1681 buf.writenl(); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1682 frequire.toCBuffer(buf, hgs); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1683 } |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1684 |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1685 // out{} |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1686 if (fensure) |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1687 { |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1688 buf.writestring("out"); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1689 if (outId) |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1690 { |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1691 buf.writebyte('('); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1692 buf.writestring(outId.toChars()); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1693 buf.writebyte(')'); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1694 } |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1695 buf.writenl(); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1696 fensure.toCBuffer(buf, hgs); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1697 } |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1698 |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1699 if (frequire || fensure) |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1700 { |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1701 buf.writestring("body"); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1702 buf.writenl(); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1703 } |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1704 |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1705 buf.writebyte('{'); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1706 buf.writenl(); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1707 fbody.toCBuffer(buf, hgs); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1708 buf.writebyte('}'); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1709 buf.writenl(); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1710 } |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1711 else |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1712 { buf.writeByte(';'); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1713 buf.writenl(); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
91
diff
changeset
|
1714 } |
0 | 1715 } |
1716 | |
1717 /**************************************************** | |
1718 * Determine if 'this' overrides fd. | |
1719 * Return true if it does. | |
1720 */ | |
1721 bool overrides(FuncDeclaration fd) | |
1722 { | |
1723 bool result = false; | |
1724 | |
1725 if (fd.ident == ident) | |
1726 { | |
1727 int cov = type.covariant(fd.type); | |
1728 if (cov) | |
1729 { | |
1730 ClassDeclaration cd1 = toParent().isClassDeclaration(); | |
1731 ClassDeclaration cd2 = fd.toParent().isClassDeclaration(); | |
1732 | |
1733 if (cd1 && cd2 && cd2.isBaseOf(cd1, null)) | |
1734 result = true; | |
1735 } | |
1736 } | |
1737 return result; | |
1738 } | |
1739 | |
1740 /************************************************* | |
1741 * Find index of function in vtbl[0..dim] that | |
1742 * this function overrides. | |
1743 * Returns: | |
1744 * -1 didn't find one | |
1745 * -2 can't determine because of forward references | |
1746 */ | |
1747 int findVtblIndex(Array vtbl, int dim) | |
1748 { | |
1749 for (int vi = 0; vi < dim; vi++) | |
1750 { | |
1751 FuncDeclaration fdv = (cast(Dsymbol)vtbl.data[vi]).isFuncDeclaration(); | |
1752 if (fdv && fdv.ident is ident) | |
1753 { | |
1754 int cov = type.covariant(fdv.type); | |
1755 //printf("\tbaseclass cov = %d\n", cov); | |
1756 switch (cov) | |
1757 { | |
1758 case 0: // types are distinct | |
1759 break; | |
1760 | |
1761 case 1: | |
1762 return vi; | |
1763 | |
1764 case 2: | |
1765 //type.print(); | |
1766 //fdv.type.print(); | |
1767 //printf("%s %s\n", type.deco, fdv.type.deco); | |
1768 error("of type %s overrides but is not covariant with %s of type %s", | |
1769 type.toChars(), fdv.toPrettyChars(), fdv.type.toChars()); | |
1770 break; | |
1771 | |
1772 case 3: | |
1773 return -2; // forward references | |
1774 } | |
1775 } | |
1776 } | |
1777 return -1; | |
1778 } | |
1779 | |
1780 /**************************************************** | |
1781 * Overload this FuncDeclaration with the new one f. | |
1782 * Return !=0 if successful; i.e. no conflict. | |
1783 */ | |
72 | 1784 override bool overloadInsert(Dsymbol s) |
0 | 1785 { |
1786 FuncDeclaration f; | |
1787 AliasDeclaration a; | |
1788 | |
1789 //writef("FuncDeclaration.overloadInsert(%s)\n", s.toChars()); | |
1790 a = s.isAliasDeclaration(); | |
1791 if (a) | |
1792 { | |
1793 if (overnext) | |
1794 return overnext.overloadInsert(a); | |
1795 | |
1796 if (!a.aliassym && a.type.ty != TY.Tident && a.type.ty != TY.Tinstance) | |
1797 { | |
1798 //writef("\ta = '%s'\n", a.type.toChars()); | |
1799 return false; | |
1800 } | |
1801 overnext = a; | |
1802 //printf("\ttrue: no conflict\n"); | |
1803 return true; | |
1804 } | |
1805 f = s.isFuncDeclaration(); | |
1806 if (!f) | |
1807 return false; | |
1808 | |
1809 static if (false) { | |
1810 /* Disable this check because: | |
1811 * const void foo(); | |
1812 * semantic() isn't run yet on foo(), so the const hasn't been | |
1813 * applied yet. | |
1814 */ | |
1815 if (type) | |
1816 { | |
1817 printf("type = %s\n", type.toChars()); | |
1818 printf("f.type = %s\n", f.type.toChars()); | |
1819 } | |
1820 if (type && f.type && // can be null for overloaded constructors | |
1821 f.type.covariant(type) && | |
1822 f.type.mod == type.mod && | |
1823 !isFuncAliasDeclaration()) | |
1824 { | |
1825 //printf("\tfalse: conflict %s\n", kind()); | |
1826 return false; | |
1827 } | |
1828 } | |
1829 | |
1830 if (overnext) | |
1831 return overnext.overloadInsert(f); | |
1832 overnext = f; | |
1833 //printf("\ttrue: no conflict\n"); | |
1834 return true; | |
1835 } | |
1836 | |
1837 FuncDeclaration overloadExactMatch(Type t) | |
1838 { | |
1839 Param1 p; | |
1840 p.t = t; | |
1841 p.f = null; | |
17
ddae60498573
Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents:
14
diff
changeset
|
1842 overloadApply(this, &p.fp1, &p); |
0 | 1843 return p.f; |
1844 } | |
1845 | |
1846 FuncDeclaration overloadResolve(Loc loc, Expression ethis, Expressions arguments, int flags = 0) | |
1847 { | |
1848 TypeFunction tf; | |
1849 Match m; | |
1850 | |
1851 static if (false) { | |
1852 printf("FuncDeclaration.overloadResolve('%s')\n", toChars()); | |
1853 if (arguments) | |
1854 { | |
1855 int i; | |
1856 | |
1857 for (i = 0; i < arguments.dim; i++) | |
1858 { | |
1859 Expression arg; | |
1860 | |
1861 arg = cast(Expression)arguments.data[i]; | |
1862 assert(arg.type); | |
1863 printf("\t%s: ", arg.toChars()); | |
1864 arg.type.print(); | |
1865 } | |
1866 } | |
1867 } | |
1868 | |
1869 m.last = MATCH.MATCHnomatch; | |
1870 overloadResolveX(&m, this, ethis, arguments); | |
1871 | |
1872 if (m.count == 1) // exactly one match | |
1873 { | |
1874 return m.lastf; | |
1875 } | |
1876 else | |
1877 { | |
1878 scope OutBuffer buf = new OutBuffer(); | |
1879 | |
1880 buf.writeByte('('); | |
1881 if (arguments) | |
1882 { | |
1883 HdrGenState hgs; | |
1884 | |
1885 argExpTypesToCBuffer(buf, arguments, &hgs); | |
1886 buf.writeByte(')'); | |
1887 if (ethis) | |
1888 ethis.type.modToBuffer(buf); | |
1889 } | |
1890 else | |
1891 buf.writeByte(')'); | |
1892 | |
1893 if (m.last == MATCH.MATCHnomatch) | |
1894 { | |
1895 if (flags & 1) // if do not print error messages | |
1896 return null; // no match | |
1897 | |
1898 tf = cast(TypeFunction)type; | |
1899 | |
1900 scope OutBuffer buf2 = new OutBuffer(); | |
1901 tf.modToBuffer(buf2); | |
1902 | |
1903 //printf("tf = %s, args = %s\n", tf.deco, ((Expression *)arguments.data[0]).type.deco); | |
1904 error(loc, "%s%s is not callable using argument types %s", | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
1905 Parameter.argsTypesToChars(tf.parameters, tf.varargs), |
0 | 1906 buf2.toChars(), |
1907 buf.toChars()); | |
1908 return m.anyf; // as long as it's not a FuncAliasDeclaration | |
1909 } | |
1910 else | |
1911 { | |
1912 static if (true) { | |
1913 TypeFunction t1 = cast(TypeFunction)m.lastf.type; | |
1914 TypeFunction t2 = cast(TypeFunction)m.nextf.type; | |
1915 | |
1916 error(loc, "called with argument types:\n\t(%s)\nmatches both:\n\t%s%s\nand:\n\t%s%s", | |
1917 buf.toChars(), | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
1918 m.lastf.toPrettyChars(), Parameter.argsTypesToChars(t1.parameters, t1.varargs), |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
1919 m.nextf.toPrettyChars(), Parameter.argsTypesToChars(t2.parameters, t2.varargs)); |
0 | 1920 } else { |
1921 error(loc, "overloads %s and %s both match argument list for %s", | |
1922 m.lastf.type.toChars(), | |
1923 m.nextf.type.toChars(), | |
1924 m.lastf.toChars()); | |
1925 } | |
1926 return m.lastf; | |
1927 } | |
1928 } | |
1929 } | |
1930 | |
1931 /************************************* | |
1932 * Determine partial specialization order of 'this' vs g. | |
1933 * This is very similar to TemplateDeclaration.leastAsSpecialized(). | |
1934 * Returns: | |
1935 * match 'this' is at least as specialized as g | |
1936 * 0 g is more specialized than 'this' | |
1937 */ | |
1938 MATCH leastAsSpecialized(FuncDeclaration g) | |
1939 { | |
1940 version (LOG_LEASTAS) { | |
1941 printf("%s.leastAsSpecialized(%s)\n", toChars(), g.toChars()); | |
1942 } | |
1943 | |
1944 /* This works by calling g() with f()'s parameters, and | |
1945 * if that is possible, then f() is at least as specialized | |
1946 * as g() is. | |
1947 */ | |
1948 | |
1949 TypeFunction tf = cast(TypeFunction)type; | |
1950 TypeFunction tg = cast(TypeFunction)g.type; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
1951 size_t nfparams = Parameter.dim(tf.parameters); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
1952 size_t ngparams = Parameter.dim(tg.parameters); |
0 | 1953 MATCH match = MATCHexact; |
1954 | |
1955 /* If both functions have a 'this' pointer, and the mods are not | |
1956 * the same and g's is not const, then this is less specialized. | |
1957 */ | |
1958 if (needThis() && g.needThis()) | |
1959 { | |
1960 if (tf.mod != tg.mod) | |
1961 { | |
1962 if (tg.mod == MODconst) | |
1963 match = MATCHconst; | |
1964 else | |
1965 return MATCHnomatch; | |
1966 } | |
1967 } | |
1968 | |
1969 /* Create a dummy array of arguments out of the parameters to f() | |
1970 */ | |
1971 scope Expressions args = new Expressions(); | |
1972 args.setDim(nfparams); | |
1973 for (int u = 0; u < nfparams; u++) | |
1974 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
1975 auto p = Parameter.getNth(tf.parameters, u); |
0 | 1976 Expression e; |
1977 if (p.storageClass & (STCref | STCout)) | |
1978 { | |
1979 e = new IdentifierExp(Loc(0), p.ident); | |
1980 e.type = p.type; | |
1981 } | |
1982 else | |
1983 e = p.type.defaultInit(Loc(0)); | |
1984 | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
1985 args[u] = e; |
0 | 1986 } |
1987 | |
1988 MATCH m = cast(MATCH) tg.callMatch(null, args); | |
1989 if (m) | |
1990 { | |
1991 /* A variadic parameter list is less specialized than a | |
1992 * non-variadic one. | |
1993 */ | |
1994 if (tf.varargs && !tg.varargs) | |
1995 goto L1; // less specialized | |
1996 | |
1997 version (LOG_LEASTAS) { | |
1998 printf(" matches %d, so is least as specialized\n", m); | |
1999 } | |
2000 return m; | |
2001 } | |
2002 L1: | |
2003 version (LOG_LEASTAS) { | |
2004 printf(" doesn't match, so is not as specialized\n"); | |
2005 } | |
2006 return MATCHnomatch; | |
2007 } | |
72 | 2008 |
0 | 2009 /******************************** |
2010 * Labels are in a separate scope, one per function. | |
2011 */ | |
2012 LabelDsymbol searchLabel(Identifier ident) | |
2013 { | |
2014 Dsymbol s; | |
2015 | |
2016 if (!labtab) | |
2017 labtab = new DsymbolTable(); // guess we need one | |
2018 | |
2019 s = labtab.lookup(ident); | |
2020 if (!s) | |
2021 { | |
2022 s = new LabelDsymbol(ident); | |
2023 labtab.insert(s); | |
2024 } | |
2025 | |
2026 return cast(LabelDsymbol)s; | |
2027 } | |
2028 | |
2029 /**************************************** | |
2030 * If non-static member function that has a 'this' pointer, | |
2031 * return the aggregate it is a member of. | |
2032 * Otherwise, return null. | |
2033 */ | |
72 | 2034 override AggregateDeclaration isThis() |
0 | 2035 { |
2036 AggregateDeclaration ad = null; | |
2037 | |
2038 //printf("+FuncDeclaration.isThis() '%s'\n", toChars()); | |
2039 if ((storage_class & STC.STCstatic) == 0) | |
2040 { | |
2041 ad = isMember2(); | |
2042 } | |
2043 //printf("-FuncDeclaration.isThis() %p\n", ad); | |
2044 return ad; | |
2045 } | |
2046 | |
2047 AggregateDeclaration isMember2() | |
2048 { | |
2049 AggregateDeclaration ad = null; | |
2050 | |
2051 //printf("+FuncDeclaration.isMember2() '%s'\n", toChars()); | |
2052 for (Dsymbol s = this; s; s = s.parent) | |
2053 { | |
2054 //printf("\ts = '%s', parent = '%s', kind = %s\n", s.toChars(), s.parent.toChars(), s.parent.kind()); | |
2055 ad = s.isMember(); | |
2056 if (ad) | |
2057 { //printf("test4\n"); | |
2058 break; | |
2059 } | |
2060 if (!s.parent || (!s.parent.isTemplateInstance())) | |
2061 { //printf("test5\n"); | |
2062 break; | |
2063 } | |
2064 } | |
2065 //printf("-FuncDeclaration.isMember2() %p\n", ad); | |
2066 return ad; | |
2067 } | |
2068 | |
2069 /***************************************** | |
2070 * Determine lexical level difference from 'this' to nested function 'fd'. | |
2071 * Error if this cannot call fd. | |
2072 * Returns: | |
2073 * 0 same level | |
2074 * -1 increase nesting by 1 (fd is nested within 'this') | |
2075 * >0 decrease nesting by number | |
2076 */ | |
2077 int getLevel(Loc loc, FuncDeclaration fd) // lexical nesting level difference | |
2078 { | |
2079 int level; | |
2080 Dsymbol s; | |
2081 Dsymbol fdparent; | |
2082 | |
2083 //printf("FuncDeclaration.getLevel(fd = '%s')\n", fd.toChars()); | |
2084 fdparent = fd.toParent2(); | |
2085 if (fdparent == this) | |
2086 return -1; | |
2087 s = this; | |
2088 level = 0; | |
2089 while (fd != s && fdparent != s.toParent2()) | |
2090 { | |
2091 //printf("\ts = '%s'\n", s.toChars()); | |
2092 FuncDeclaration thisfd = s.isFuncDeclaration(); | |
2093 if (thisfd) | |
2094 { | |
2095 if (!thisfd.isNested() && !thisfd.vthis) | |
2096 goto Lerr; | |
2097 } | |
2098 else | |
2099 { | |
2100 AggregateDeclaration thiscd = s.isAggregateDeclaration(); | |
2101 if (thiscd) | |
2102 { | |
2103 if (!thiscd.isNested()) | |
2104 goto Lerr; | |
2105 } | |
2106 else | |
2107 goto Lerr; | |
2108 } | |
2109 | |
2110 s = s.toParent2(); | |
2111 assert(s); | |
2112 level++; | |
2113 } | |
2114 return level; | |
2115 | |
2116 Lerr: | |
2117 error(loc, "cannot access frame of function %s", fd.toChars()); | |
2118 return 1; | |
2119 } | |
2120 | |
2121 void appendExp(Expression e) | |
2122 { | |
2123 assert(false); | |
2124 } | |
2125 | |
2126 void appendState(Statement s) | |
2127 { | |
2128 assert(false); | |
2129 } | |
2130 | |
72 | 2131 override string mangle() |
0 | 2132 out (result) |
2133 { | |
2134 assert(result.length > 0); | |
2135 } | |
2136 body | |
2137 { | |
2138 if (isMain()) { | |
2139 return "_Dmain"; | |
2140 } | |
2141 | |
2142 if (isWinMain() || isDllMain() || ident == Id.tls_get_addr) | |
2143 return ident.toChars(); | |
2144 | |
2145 assert(this); | |
2146 | |
2147 return Declaration.mangle(); | |
2148 } | |
2149 | |
72 | 2150 override string toPrettyChars() |
0 | 2151 { |
2152 if (isMain()) | |
2153 return "D main"; | |
2154 else | |
2155 return Dsymbol.toPrettyChars(); | |
2156 } | |
2157 | |
2158 int isMain() | |
2159 { | |
2160 return ident is Id.main && linkage != LINK.LINKc && !isMember() && !isNested(); | |
2161 } | |
2162 | |
2163 int isWinMain() | |
2164 { | |
2165 //printf("FuncDeclaration::isWinMain() %s\n", toChars()); | |
2166 static if (false) { | |
2167 int x = ident == Id.WinMain && | |
2168 linkage != LINK.LINKc && !isMember(); | |
2169 printf("%s\n", x ? "yes" : "no"); | |
2170 return x; | |
2171 } else { | |
2172 return ident == Id.WinMain && linkage != LINK.LINKc && !isMember(); | |
2173 } | |
2174 } | |
2175 | |
2176 int isDllMain() | |
2177 { | |
2178 return ident == Id.DllMain && linkage != LINK.LINKc && !isMember(); | |
2179 } | |
2180 | |
2181 /********************************** | |
2182 * Determine if function is a builtin one that we can | |
2183 * evaluate at compile time. | |
2184 */ | |
2185 BUILTIN isBuiltin() | |
2186 { | |
2187 static string FeZe = "FNaNbeZe"; // pure nothrow real function(real) | |
2188 | |
2189 //printf("FuncDeclaration::isBuiltin() %s\n", toChars()); | |
2190 if (builtin == BUILTIN.BUILTINunknown) | |
2191 { | |
2192 builtin = BUILTIN.BUILTINnot; | |
2193 if (parent && parent.isModule()) | |
2194 { | |
2195 // If it's in the std.math package | |
2196 if (parent.ident == Id.math && parent.parent && parent.parent.ident == Id.std && !parent.parent.parent) | |
2197 { | |
2198 //printf("deco = %s\n", type.deco); | |
2199 if (type.deco == FeZe) | |
2200 { | |
2201 if (ident == Id.sin) | |
2202 builtin = BUILTIN.BUILTINsin; | |
2203 else if (ident == Id.cos) | |
2204 builtin = BUILTIN.BUILTINcos; | |
2205 else if (ident == Id.tan) | |
2206 builtin = BUILTIN.BUILTINtan; | |
2207 else if (ident == Id._sqrt) | |
2208 builtin = BUILTIN.BUILTINsqrt; | |
2209 else if (ident == Id.fabs) | |
2210 builtin = BUILTIN.BUILTINfabs; | |
2211 //printf("builtin = %d\n", builtin); | |
2212 } | |
2213 // if float or double versions | |
2214 else if (type.deco == "FNaNbdZd" || type.deco == "FNaNbfZf") | |
2215 { | |
2216 if (ident == Id._sqrt) | |
2217 builtin = BUILTIN.BUILTINsqrt; | |
2218 } | |
2219 } | |
2220 } | |
2221 } | |
2222 | |
2223 return builtin; | |
2224 } | |
2225 | |
72 | 2226 override bool isExport() |
0 | 2227 { |
2228 return protection == PROT.PROTexport; | |
2229 } | |
2230 | |
72 | 2231 override bool isImportedSymbol() |
0 | 2232 { |
2233 //printf("isImportedSymbol()\n"); | |
2234 //printf("protection = %d\n", protection); | |
2235 return (protection == PROT.PROTexport) && !fbody; | |
2236 } | |
2237 | |
72 | 2238 override bool isAbstract() |
0 | 2239 { |
2240 return (storage_class & STC.STCabstract) != 0; | |
2241 } | |
2242 | |
72 | 2243 override bool isCodeseg() |
0 | 2244 { |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
63
diff
changeset
|
2245 return true; // functions are always in the code segment |
0 | 2246 } |
2247 | |
72 | 2248 override bool isOverloadable() |
0 | 2249 { |
63 | 2250 return 1; // functions can be overloaded |
0 | 2251 } |
2252 | |
2253 bool isPure() | |
2254 { | |
2255 //printf("FuncDeclaration::isPure() '%s'\n", toChars()); | |
2256 assert(type.ty == TY.Tfunction); | |
2257 return (cast(TypeFunction)this.type).ispure; | |
2258 } | |
2259 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2260 int isSafe() |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2261 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2262 assert(type.ty == TY.Tfunction); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2263 return (cast(TypeFunction)this.type).trust == TRUST.TRUSTsafe; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2264 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2265 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2266 int isTrusted() |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2267 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2268 assert(type.ty == TY.Tfunction); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2269 return (cast(TypeFunction)this.type).trust == TRUST.TRUSTtrusted; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2270 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2271 |
0 | 2272 bool isNested() |
2273 { | |
2274 //if (!toParent()) | |
2275 //printf("FuncDeclaration.isNested('%s') parent=%p\n", toChars(), parent); | |
2276 //printf("\ttoParent2() = '%s'\n", toParent2().toChars()); | |
2277 return ((storage_class & STC.STCstatic) == 0) && | |
2278 (toParent2().isFuncDeclaration() !is null); | |
2279 } | |
2280 | |
72 | 2281 override bool needThis() |
0 | 2282 { |
2283 //printf("FuncDeclaration.needThis() '%s'\n", toChars()); | |
2284 bool needThis = isThis() !is null; | |
2285 | |
2286 //printf("\t%d\n", i); | |
2287 if (!needThis) { | |
2288 if (auto fa = isFuncAliasDeclaration()) { | |
2289 needThis = fa.funcalias.needThis(); | |
2290 } | |
2291 } | |
2292 | |
2293 return needThis; | |
2294 } | |
2295 | |
2296 bool isVirtual() | |
2297 { | |
2298 static if (false) { | |
2299 printf("FuncDeclaration.isVirtual(%s)\n", toChars()); | |
2300 printf("isMember:%p isStatic:%d private:%d ctor:%d !Dlinkage:%d\n", isMember(), isStatic(), protection == PROT.PROTprivate, isCtorDeclaration(), linkage != LINK.LINKd); | |
2301 printf("result is %d\n", | |
2302 isMember() && !(isStatic() || protection == PROT.PROTprivate || protection == PROT.PROTpackage) && toParent().isClassDeclaration()); | |
2303 } | |
2304 return isMember() && !(isStatic() || protection == PROT.PROTprivate || protection == PROT.PROTpackage) && toParent().isClassDeclaration(); | |
2305 } | |
2306 | |
72 | 2307 override int isFinal() |
0 | 2308 { |
2309 ClassDeclaration cd; | |
2310 static if (false) { | |
2311 printf("FuncDeclaration.isFinal(%s)\n", toChars()); | |
2312 printf("%p %d %d %d %d\n", isMember(), isStatic(), protection == PROT.PROTprivate, isCtorDeclaration(), linkage != LINK.LINKd); | |
2313 printf("result is %d\n", | |
2314 isMember() && !(isStatic() || protection == PROT.PROTprivate || protection == PROT.PROTpackage) && (cd = toParent().isClassDeclaration()) !is null && cd.storage_class & STC.STCfinal); | |
2315 } | |
2316 return isMember() && (Declaration.isFinal() || ((cd = toParent().isClassDeclaration()) !is null && cd.storage_class & STC.STCfinal)); | |
2317 } | |
2318 | |
2319 bool addPreInvariant() | |
2320 { | |
2321 AggregateDeclaration ad = isThis(); | |
2322 return (ad && | |
2323 //ad.isClassDeclaration() && | |
2324 global.params.useInvariants && | |
2325 (protection == PROT.PROTpublic || protection == PROT.PROTexport) && | |
2326 !naked && | |
2327 ident !is Id.cpctor); | |
2328 } | |
2329 | |
2330 bool addPostInvariant() | |
2331 { | |
2332 AggregateDeclaration ad = isThis(); | |
2333 return (ad && ad.inv && | |
2334 //ad.isClassDeclaration() && | |
2335 global.params.useInvariants && | |
2336 (protection == PROT.PROTpublic || protection == PROT.PROTexport) && | |
2337 !naked && | |
2338 ident !is Id.cpctor); | |
2339 } | |
2340 | |
63 | 2341 /************************************* |
2342 * Attempt to interpret a function given the arguments. | |
2343 * Input: | |
2344 * istate state for calling function (null if none) | |
2345 * arguments function arguments | |
2346 * thisarg 'this', if a needThis() function, null if not. | |
2347 * | |
2348 * Return result expression if successful, null if not. | |
2349 */ | |
2350 Expression interpret(InterState istate, Expressions arguments, Expression thisarg = null) | |
0 | 2351 { |
63 | 2352 version (LOG) { |
2353 printf("\n********\nFuncDeclaration.interpret(istate = %p) %s\n", istate, toChars()); | |
2354 printf("cantInterpret = %d, semanticRun = %d\n", cantInterpret, semanticRun); | |
2355 } | |
2356 if (global.errors) | |
2357 return null; | |
107 | 2358 version(DMDV1) |
2359 { | |
63 | 2360 if (ident == Id.aaLen) |
2361 return interpret_aaLen(istate, arguments); | |
2362 else if (ident == Id.aaKeys) | |
2363 return interpret_aaKeys(istate, arguments); | |
2364 else if (ident == Id.aaValues) | |
2365 return interpret_aaValues(istate, arguments); | |
107 | 2366 } |
2367 else version(DMDV2) | |
2368 { | |
2369 if (thisarg && (!arguments || arguments.dim == 0)) | |
2370 { | |
2371 if (ident == Id.length) | |
2372 return interpret_length(istate, thisarg); | |
2373 else if (ident == Id.keys) | |
2374 return interpret_keys(istate, thisarg, this); | |
2375 else if (ident == Id.values) | |
2376 return interpret_values(istate, thisarg, this); | |
2377 } | |
2378 } | |
2379 | |
63 | 2380 if (cantInterpret || semanticRun == 3) |
2381 return null; | |
2382 | |
2383 if (!fbody) | |
2384 { | |
2385 cantInterpret = 1; | |
2386 return null; | |
2387 } | |
2388 | |
2389 if (semanticRun < 3 && scope_) | |
2390 { | |
2391 semantic3(scope_); | |
2392 if (global.errors) // if errors compiling this function | |
2393 return null; | |
2394 } | |
2395 if (semanticRun < 4) | |
2396 return null; | |
2397 | |
2398 Type tb = type.toBasetype(); | |
2399 assert(tb.ty == Tfunction); | |
2400 TypeFunction tf = cast(TypeFunction)tb; | |
2401 Type tret = tf.next.toBasetype(); | |
2402 if (tf.varargs) | |
2403 { | |
2404 cantInterpret = 1; | |
2405 error("Variadic functions are not yet implemented in CTFE"); | |
2406 return null; | |
2407 } | |
2408 | |
2409 // Ensure there are no lazy parameters | |
2410 if (tf.parameters) | |
2411 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2412 size_t dim = Parameter.dim(tf.parameters); |
63 | 2413 for (size_t i = 0; i < dim; i++) |
2414 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2415 auto arg = Parameter.getNth(tf.parameters, i); |
63 | 2416 if (arg.storageClass & STClazy) |
2417 { | |
2418 cantInterpret = 1; | |
2419 return null; | |
2420 } | |
2421 } | |
2422 } | |
2423 | |
2424 scope InterState istatex = new InterState(); | |
2425 istatex.caller = istate; | |
2426 istatex.fd = this; | |
2427 istatex.localThis = thisarg; | |
2428 | |
2429 scope Expressions vsave = new Expressions(); // place to save previous parameter values | |
2430 size_t dim = 0; | |
2431 if (needThis() && !thisarg) | |
2432 { | |
2433 cantInterpret = 1; | |
2434 // error, no this. Prevent segfault. | |
2435 error("need 'this' to access member %s", toChars()); | |
2436 return null; | |
2437 } | |
2438 if (arguments) | |
2439 { | |
2440 dim = arguments.dim; | |
2441 assert(!dim || (parameters && (parameters.dim == dim))); | |
2442 vsave.setDim(dim); | |
2443 | |
2444 /* Evaluate all the arguments to the function, | |
2445 * store the results in eargs[] | |
2446 */ | |
2447 scope Expressions eargs = new Expressions(); | |
2448 eargs.setDim(dim); | |
2449 | |
2450 for (size_t i = 0; i < dim; i++) | |
2451 { | |
90
39648eb578f6
more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
88
diff
changeset
|
2452 Expression earg = arguments[i]; |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2453 auto arg = Parameter.getNth(tf.parameters, i); |
63 | 2454 |
2455 if (arg.storageClass & (STCout | STCref)) | |
2456 { | |
2457 } | |
2458 else | |
2459 { /* Value parameters | |
2460 */ | |
2461 Type ta = arg.type.toBasetype(); | |
2462 if (ta.ty == Tsarray && earg.op == TOKaddress) | |
2463 { | |
2464 /* Static arrays are passed by a simple pointer. | |
2465 * Skip past this to get at the actual arg. | |
2466 */ | |
2467 earg = (cast(AddrExp)earg).e1; | |
2468 } | |
2469 earg = earg.interpret(istate ? istate : istatex); | |
2470 if (earg is EXP_CANT_INTERPRET) | |
2471 { | |
2472 cantInterpret = 1; | |
2473 return null; | |
2474 } | |
2475 } | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
2476 eargs[i] = earg; |
63 | 2477 } |
2478 | |
2479 for (size_t i = 0; i < dim; i++) | |
2480 { | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
2481 auto earg = eargs[i]; |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2482 auto arg = Parameter.getNth(tf.parameters, i); |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
2483 auto v = cast(VarDeclaration)parameters[i]; |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
2484 vsave[i] = v.value; |
63 | 2485 version (LOG) { |
2486 printf("arg[%d] = %s\n", i, earg.toChars()); | |
2487 } | |
2488 if (arg.storageClass & (STCout | STCref) && earg.op==TOKvar) | |
2489 { | |
2490 /* Bind out or ref parameter to the corresponding | |
2491 * variable v2 | |
2492 */ | |
2493 if (!istate) | |
2494 { | |
2495 cantInterpret = 1; | |
2496 error("%s cannot be by passed by reference at compile time", earg.toChars()); | |
2497 return null; // can't bind to non-interpreted vars | |
2498 } | |
2499 // We need to chase down all of the the passed parameters until | |
2500 // we find something that isn't a TOKvar, then create a variable | |
2501 // containg that expression. | |
2502 VarDeclaration v2; | |
2503 while (1) | |
2504 { | |
2505 VarExp ve = cast(VarExp)earg; | |
2506 v2 = ve.var.isVarDeclaration(); | |
2507 if (!v2) | |
2508 { | |
2509 cantInterpret = 1; | |
2510 return null; | |
2511 } | |
2512 if (!v2.value || v2.value.op != TOKvar) | |
2513 break; | |
2514 if ((cast(VarExp)v2.value).var.isSymbolDeclaration()) | |
2515 { | |
2516 // This can happen if v is a struct initialized to | |
2517 // 0 using an __initZ SymbolDeclaration from | |
2518 // TypeStruct.defaultInit() | |
2519 break; // eg default-initialized variable | |
2520 } | |
2521 earg = v2.value; | |
2522 } | |
2523 | |
2524 v.value = new VarExp(earg.loc, v2); | |
2525 | |
2526 /* Don't restore the value of v2 upon function return | |
2527 */ | |
2528 assert(istate); | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
2529 foreach(size_t j, Dsymbol s2; istate.vars)// (size_t j = 0; j < istate.vars.dim; j++) |
63 | 2530 { |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
2531 auto vd = cast(VarDeclaration)s2; |
63 | 2532 if (vd == v2) |
2533 { | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
2534 istate.vars[j] = null; |
63 | 2535 break; |
2536 } | |
2537 } | |
2538 } | |
2539 else | |
2540 { | |
2541 // Value parameters and non-trivial references | |
2542 v.value = earg; | |
2543 } | |
2544 version (LOG) { | |
2545 printf("interpreted arg[%d] = %s\n", i, earg.toChars()); | |
2546 } | |
2547 } | |
2548 } | |
2549 // Don't restore the value of 'this' upon function return | |
2550 if (needThis() && thisarg.op==TOKvar) { | |
2551 VarDeclaration thisvar = (cast(VarExp)thisarg).var.isVarDeclaration(); | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
2552 foreach (size_t i, Dsymbol s; istate.vars) |
63 | 2553 { |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
2554 auto v = cast(VarDeclaration)s; |
63 | 2555 if (v == thisvar) |
2556 { | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
2557 istate.vars[i] = null; |
63 | 2558 break; |
2559 } | |
2560 } | |
2561 } | |
2562 | |
2563 /* Save the values of the local variables used | |
2564 */ | |
2565 scope Expressions valueSaves = new Expressions(); | |
2566 if (istate && !isNested()) | |
2567 { | |
2568 //printf("saving local variables...\n"); | |
2569 valueSaves.setDim(istate.vars.dim); | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
2570 foreach (size_t i, Dsymbol s3; istate.vars) |
63 | 2571 { |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
2572 if (auto v = cast(VarDeclaration)s3) |
63 | 2573 { |
2574 //printf("\tsaving [%d] %s = %s\n", i, v.toChars(), v.value ? v.value.toChars() : ""); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
2575 valueSaves[i] = v.value; |
63 | 2576 v.value = null; |
2577 } | |
2578 } | |
2579 } | |
2580 | |
2581 Expression e = null; | |
2582 while (1) | |
2583 { | |
2584 e = fbody.interpret(istatex); | |
2585 if (e is EXP_CANT_INTERPRET) | |
2586 { | |
2587 version (LOG) { | |
2588 printf("function body failed to interpret\n"); | |
2589 } | |
2590 e = null; | |
2591 } | |
2592 | |
2593 /* This is how we deal with a recursive statement AST | |
2594 * that has arbitrary goto statements in it. | |
2595 * Bubble up a 'result' which is the target of the goto | |
2596 * statement, then go recursively down the AST looking | |
2597 * for that statement, then execute starting there. | |
2598 */ | |
2599 if (e is EXP_GOTO_INTERPRET) | |
2600 { | |
2601 istatex.start = istatex.gotoTarget; // set starting statement | |
2602 istatex.gotoTarget = null; | |
2603 } | |
2604 else | |
2605 break; | |
2606 } | |
2607 /* Restore the parameter values | |
2608 */ | |
2609 for (size_t i = 0; i < dim; i++) | |
2610 { | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
2611 auto v = cast(VarDeclaration)parameters[i]; |
90
39648eb578f6
more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
88
diff
changeset
|
2612 v.value = vsave[i]; |
63 | 2613 } |
2614 | |
2615 if (istate && !isNested()) | |
2616 { | |
2617 /* Restore the variable values | |
2618 */ | |
2619 //printf("restoring local variables...\n"); | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
2620 foreach (size_t i , Dsymbol s3; istate.vars) |
63 | 2621 { |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
2622 if (auto v = cast(VarDeclaration)s3) |
63 | 2623 { |
90
39648eb578f6
more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
88
diff
changeset
|
2624 v.value = valueSaves[i]; |
63 | 2625 //printf("\trestoring [%d] %s = %s\n", i, v.toChars(), v.value ? v.value.toChars() : ""); |
2626 } | |
2627 } | |
2628 } | |
2629 return e; | |
0 | 2630 } |
2631 | |
72 | 2632 override void inlineScan() |
0 | 2633 { |
2634 InlineScanState iss; | |
2635 | |
2636 version (LOG) { | |
2637 printf("FuncDeclaration.inlineScan('%s')\n", toChars()); | |
2638 } | |
2639 ///memset(&iss, 0, sizeof(iss)); | |
2640 iss.fd = this; | |
2641 if (fbody) | |
2642 { | |
2643 inlineNest++; | |
2644 fbody = fbody.inlineScan(&iss); | |
2645 inlineNest--; | |
2646 } | |
2647 } | |
2648 | |
2649 int canInline(int hasthis, int hdrscan = 0) | |
2650 { | |
2651 int cost; | |
2652 | |
2653 // #define CANINLINE_LOG 0 | |
2654 | |
2655 version (CANINLINE_LOG) { | |
2656 printf("FuncDeclaration.canInline(hasthis = %d, '%s')\n", hasthis, toChars()); | |
2657 } | |
2658 | |
2659 if (needThis() && !hasthis) | |
2660 return 0; | |
2661 | |
2662 if (inlineNest || (semanticRun < 3 && !hdrscan)) | |
2663 { | |
2664 version (CANINLINE_LOG) { | |
2665 printf("\t1: no, inlineNest = %d, semanticRun = %d\n", inlineNest, semanticRun); | |
2666 } | |
2667 return 0; | |
2668 } | |
2669 | |
2670 switch (inlineStatus) | |
2671 { | |
2672 case ILS.ILSyes: | |
2673 version (CANINLINE_LOG) { | |
2674 printf("\t1: yes %s\n", toChars()); | |
2675 } | |
2676 return 1; | |
2677 | |
2678 case ILS.ILSno: | |
2679 version (CANINLINE_LOG) { | |
2680 printf("\t1: no %s\n", toChars()); | |
2681 } | |
2682 return 0; | |
2683 | |
2684 case ILS.ILSuninitialized: | |
2685 break; | |
2686 | |
2687 default: | |
2688 assert(0); | |
2689 } | |
2690 | |
2691 if (type) | |
2692 { | |
2693 assert(type.ty == Tfunction); | |
2694 TypeFunction tf = cast(TypeFunction)type; | |
2695 if (tf.varargs == 1) // no variadic parameter lists | |
2696 goto Lno; | |
2697 | |
2698 /* Don't inline a function that returns non-void, but has | |
2699 * no return expression. | |
2700 */ | |
2701 if (tf.next && tf.next.ty != Tvoid && | |
2702 !(hasReturnExp & 1) && | |
2703 !hdrscan) | |
2704 goto Lno; | |
2705 } | |
2706 else | |
2707 { | |
2708 CtorDeclaration ctor = isCtorDeclaration(); | |
2709 if (ctor && ctor.varargs == 1) | |
2710 goto Lno; | |
2711 } | |
2712 | |
2713 if ( | |
2714 !fbody || | |
2715 !hdrscan && | |
2716 ( | |
2717 /// static if (false) { | |
2718 /// isCtorDeclaration() || // cannot because need to convert: | |
2719 /// // return; | |
2720 /// // to: | |
2721 /// // return this; | |
2722 /// } | |
2723 isSynchronized() || | |
2724 isImportedSymbol() || | |
2725 /// version (DMDV2) { | |
2726 closureVars.dim || // no nested references to this frame | |
2727 /// } else { | |
2728 /// nestedFrameRef || // no nested references to this frame | |
2729 /// } | |
2730 (isVirtual() && !isFinal()) | |
2731 )) | |
2732 { | |
2733 goto Lno; | |
2734 } | |
2735 | |
2736 /* If any parameters are Tsarray's (which are passed by reference) | |
2737 * or out parameters (also passed by reference), don't do inlining. | |
2738 */ | |
2739 if (parameters) | |
2740 { | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
2741 foreach (Dsymbol s3; parameters) |
0 | 2742 { |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
2743 auto v = cast(VarDeclaration)s3; |
0 | 2744 if (v.isOut() || v.isRef() || v.type.toBasetype().ty == Tsarray) |
2745 goto Lno; | |
2746 } | |
2747 } | |
2748 | |
2749 InlineCostState ics; | |
2750 ///memset(&ics, 0, sizeof(ics)); | |
2751 ics.hasthis = hasthis; | |
2752 ics.fd = this; | |
2753 ics.hdrscan = hdrscan; | |
2754 cost = fbody.inlineCost(&ics); | |
2755 version (CANINLINE_LOG) { | |
2756 printf("cost = %d\n", cost); | |
2757 } | |
2758 if (cost >= COST_MAX) | |
2759 goto Lno; | |
2760 | |
2761 if (!hdrscan) // Don't scan recursively for header content scan | |
2762 inlineScan(); | |
2763 | |
2764 Lyes: | |
2765 if (!hdrscan) // Don't modify inlineStatus for header content scan | |
2766 inlineStatus = ILS.ILSyes; | |
2767 version (CANINLINE_LOG) { | |
2768 printf("\t2: yes %s\n", toChars()); | |
2769 } | |
2770 return 1; | |
2771 | |
2772 Lno: | |
2773 if (!hdrscan) // Don't modify inlineStatus for header content scan | |
2774 inlineStatus = ILS.ILSno; | |
2775 version (CANINLINE_LOG) { | |
2776 printf("\t2: no %s\n", toChars()); | |
2777 } | |
2778 return 0; | |
2779 } | |
2780 | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
2781 Expression doInline(InlineScanState* iss, Expression ethis, Expressions arguments) |
0 | 2782 { |
2783 InlineDoState ids = new InlineDoState(); | |
2784 DeclarationExp de; | |
2785 Expression e = null; | |
2786 | |
2787 version (LOG) { | |
2788 printf("FuncDeclaration.doInline('%s')\n", toChars()); | |
2789 } | |
2790 | |
2791 ///memset(&ids, 0, sizeof(ids)); | |
2792 ids.parent = iss.fd; | |
2793 | |
2794 // Set up vthis | |
2795 if (ethis) | |
2796 { | |
2797 VarDeclaration vthis; | |
2798 ExpInitializer ei; | |
2799 VarExp ve; | |
2800 | |
2801 version (STRUCTTHISREF) { | |
2802 if (ethis.type.ty == Tpointer) | |
2803 { | |
2804 Type t = ethis.type.nextOf(); | |
2805 ethis = new PtrExp(ethis.loc, ethis); | |
2806 ethis.type = t; | |
2807 } | |
2808 ei = new ExpInitializer(ethis.loc, ethis); | |
2809 | |
2810 vthis = new VarDeclaration(ethis.loc, ethis.type, Id.This, ei); | |
2811 if (ethis.type.ty != Tclass) | |
2812 vthis.storage_class = STCref; | |
2813 else | |
2814 vthis.storage_class = STCin; | |
2815 } else { | |
2816 if (ethis.type.ty != Tclass && ethis.type.ty != Tpointer) | |
2817 { | |
2818 ethis = ethis.addressOf(null); | |
2819 } | |
2820 | |
2821 ei = new ExpInitializer(ethis.loc, ethis); | |
2822 | |
2823 vthis = new VarDeclaration(ethis.loc, ethis.type, Id.This, ei); | |
2824 vthis.storage_class = STCin; | |
2825 } | |
2826 vthis.linkage = LINKd; | |
2827 vthis.parent = iss.fd; | |
2828 | |
2829 ve = new VarExp(vthis.loc, vthis); | |
2830 ve.type = vthis.type; | |
2831 | |
2832 ei.exp = new AssignExp(vthis.loc, ve, ethis); | |
2833 ei.exp.type = ve.type; | |
2834 version (STRUCTTHISREF) { | |
2835 if (ethis.type.ty != Tclass) | |
2836 { | |
2837 /* This is a reference initialization, not a simple assignment. | |
2838 */ | |
2839 ei.exp.op = TOKconstruct; | |
2840 } | |
2841 } | |
2842 | |
2843 ids.vthis = vthis; | |
2844 } | |
2845 | |
2846 // Set up parameters | |
2847 if (ethis) | |
2848 { | |
2849 e = new DeclarationExp(Loc(0), ids.vthis); | |
2850 e.type = Type.tvoid; | |
2851 } | |
2852 | |
2853 if (arguments && arguments.dim) | |
2854 { | |
2855 assert(parameters.dim == arguments.dim); | |
2856 | |
2857 for (int i = 0; i < arguments.dim; i++) | |
2858 { | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
2859 auto vfrom = cast(VarDeclaration)parameters[i]; |
0 | 2860 VarDeclaration vto; |
90
39648eb578f6
more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
88
diff
changeset
|
2861 Expression arg = arguments[i]; |
0 | 2862 ExpInitializer ei; |
2863 VarExp ve; | |
2864 | |
2865 ei = new ExpInitializer(arg.loc, arg); | |
2866 | |
2867 vto = new VarDeclaration(vfrom.loc, vfrom.type, vfrom.ident, ei); | |
2868 vto.storage_class |= vfrom.storage_class & (STCin | STCout | STClazy | STCref); | |
2869 vto.linkage = vfrom.linkage; | |
2870 vto.parent = iss.fd; | |
2871 //printf("vto = '%s', vto.storage_class = x%x\n", vto.toChars(), vto.storage_class); | |
2872 //printf("vto.parent = '%s'\n", iss.fd.toChars()); | |
2873 | |
2874 ve = new VarExp(vto.loc, vto); | |
2875 //ve.type = vto.type; | |
2876 ve.type = arg.type; | |
2877 | |
2878 ei.exp = new AssignExp(vto.loc, ve, arg); | |
2879 ei.exp.type = ve.type; | |
2880 //ve.type.print(); | |
2881 //arg.type.print(); | |
2882 //ei.exp.print(); | |
2883 | |
2884 ids.from.push(cast(void*)vfrom); | |
2885 ids.to.push(cast(void*)vto); | |
2886 | |
2887 de = new DeclarationExp(Loc(0), vto); | |
2888 de.type = Type.tvoid; | |
2889 | |
2890 e = Expression.combine(e, de); | |
2891 } | |
2892 } | |
2893 | |
2894 inlineNest++; | |
2895 Expression eb = fbody.doInline(ids); | |
2896 inlineNest--; | |
2897 //eb.type.print(); | |
2898 //eb.print(); | |
2899 //eb.dump(0); | |
2900 return Expression.combine(e, eb); | |
2901 } | |
2902 | |
72 | 2903 override string kind() |
0 | 2904 { |
2905 return "function"; | |
2906 } | |
2907 | |
72 | 2908 override void toDocBuffer(OutBuffer buf) |
0 | 2909 { |
2910 assert(false); | |
2911 } | |
2912 | |
2913 FuncDeclaration isUnique() | |
2914 { | |
2915 assert(false); | |
2916 } | |
2917 | |
2918 /******************************* | |
2919 * Look at all the variables in this function that are referenced | |
2920 * by nested functions, and determine if a closure needs to be | |
2921 * created for them. | |
2922 */ | |
2923 bool needsClosure() | |
2924 { | |
2925 /* Need a closure for all the closureVars[] if any of the | |
2926 * closureVars[] are accessed by a | |
2927 * function that escapes the scope of this function. | |
2928 * We take the conservative approach and decide that any function that: | |
2929 * 1) is a virtual function | |
2930 * 2) has its address taken | |
2931 * 3) has a parent that escapes | |
2932 * | |
2933 * Note that since a non-virtual function can be called by | |
2934 * a virtual one, if that non-virtual function accesses a closure | |
2935 * var, the closure still has to be taken. Hence, we check for isThis() | |
2936 * instead of isVirtual(). (thanks to David Friedman) | |
2937 */ | |
2938 | |
2939 //printf("FuncDeclaration.needsClosure() %s\n", toChars()); | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
2940 foreach (Dsymbol s3; closureVars) |
0 | 2941 { |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
2942 auto v = cast(VarDeclaration)s3; |
0 | 2943 assert(v.isVarDeclaration()); |
2944 //printf("\tv = %s\n", v.toChars()); | |
2945 | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
2946 foreach(FuncDeclaration f; v.nestedrefs) |
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
2947 { |
0 | 2948 assert(f != this); |
2949 | |
2950 //printf("\t\tf = %s, %d, %p, %d\n", f.toChars(), f.isVirtual(), f.isThis(), f.tookAddressOf); | |
2951 if (f.isThis() || f.tookAddressOf) | |
2952 goto Lyes; // assume f escapes this function's scope | |
2953 | |
2954 // Look to see if any parents of f that are below this escape | |
2955 for (Dsymbol s = f.parent; s && s !is this; s = s.parent) | |
2956 { | |
2957 f = s.isFuncDeclaration(); | |
2958 if (f && (f.isThis() || f.tookAddressOf)) { | |
2959 goto Lyes; | |
2960 } | |
2961 } | |
2962 } | |
2963 } | |
2964 return false; | |
2965 | |
2966 Lyes: | |
2967 //printf("\tneeds closure\n"); | |
2968 return true; | |
2969 } | |
2970 | |
73 | 2971 /**************************************************** |
2972 * Merge into this function the 'in' contracts of all it overrides. | |
2973 * 'in's are OR'd together, i.e. only one of them needs to pass. | |
2974 */ | |
2975 | |
2976 Statement mergeFrequire(Statement sf) | |
2977 { | |
2978 /* Implementing this is done by having the overriding function call | |
2979 * nested functions (the fdrequire functions) nested inside the overridden | |
2980 * function. This requires that the stack layout of the calling function's | |
2981 * parameters and 'this' pointer be in the same place (as the nested | |
2982 * function refers to them). | |
2983 * This is easy for the parameters, as they are all on the stack in the same | |
2984 * place by definition, since it's an overriding function. The problem is | |
2985 * getting the 'this' pointer in the same place, since it is a local variable. | |
2986 * We did some hacks in the code generator to make this happen: | |
2987 * 1. always generate exception handler frame, or at least leave space for it | |
2988 * in the frame (Windows 32 SEH only) | |
2989 * 2. always generate an EBP style frame | |
2990 * 3. since 'this' is passed in a register that is subsequently copied into | |
2991 * a stack local, allocate that local immediately following the exception | |
2992 * handler block, so it is always at the same offset from EBP. | |
2993 */ | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
2994 foreach(FuncDeclaration fdv; foverrides) //(int i = 0; i < foverrides.dim; i++) |
73 | 2995 { |
2996 sf = fdv.mergeFrequire(sf); | |
98 | 2997 if (fdv.fdrequire) |
73 | 2998 { |
2999 //printf("fdv.frequire: %s\n", fdv.frequire.toChars()); | |
3000 /* Make the call: | |
3001 * try { __require(); } | |
3002 * catch { frequire; } | |
3003 */ | |
3004 Expression eresult = null; | |
3005 Expression e = new CallExp(loc, new VarExp(loc, fdv.fdrequire, 0), eresult); | |
3006 Statement s2 = new ExpStatement(loc, e); | |
3007 | |
3008 if (sf) | |
3009 { | |
3010 Catch c = new Catch(loc, null, null, sf); | |
3011 Array catches = new Array(); | |
3012 catches.push(cast(void*)c); | |
3013 sf = new TryCatchStatement(loc, s2, catches); | |
3014 } | |
3015 else | |
3016 sf = s2; | |
3017 } | |
3018 } | |
3019 return sf; | |
3020 } | |
3021 | |
3022 /**************************************************** | |
3023 * Merge into this function the 'out' contracts of all it overrides. | |
3024 * 'out's are AND'd together, i.e. all of them need to pass. | |
3025 */ | |
3026 | |
3027 Statement mergeFensure(Statement sf) | |
3028 { | |
3029 /* Same comments as for mergeFrequire(), except that we take care | |
3030 * of generating a consistent reference to the 'result' local by | |
3031 * explicitly passing 'result' to the nested function as a reference | |
3032 * argument. | |
3033 * This won't work for the 'this' parameter as it would require changing | |
3034 * the semantic code for the nested function so that it looks on the parameter | |
3035 * list for the 'this' pointer, something that would need an unknown amount | |
3036 * of tweaking of various parts of the compiler that I'd rather leave alone. | |
3037 */ | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
3038 foreach (FuncDeclaration fdv; foverrides) |
73 | 3039 { |
3040 sf = fdv.mergeFensure(sf); | |
98 | 3041 if (fdv.fdensure) |
73 | 3042 { |
3043 //printf("fdv.fensure: %s\n", fdv.fensure.toChars()); | |
3044 // Make the call: __ensure(result) | |
3045 Expression eresult = null; | |
3046 if (outId) | |
3047 eresult = new IdentifierExp(loc, outId); | |
3048 Expression e = new CallExp(loc, new VarExp(loc, fdv.fdensure, 0), eresult); | |
3049 Statement s2 = new ExpStatement(loc, e); | |
3050 | |
3051 if (sf) | |
3052 { | |
3053 sf = new CompoundStatement(fensure.loc, s2, sf); | |
3054 } | |
3055 else | |
3056 sf = s2; | |
3057 } | |
3058 } | |
3059 return sf; | |
3060 } | |
3061 | |
0 | 3062 static FuncDeclaration genCfunc(Type treturn, string name) |
3063 { | |
3064 return genCfunc(treturn, Lexer.idPool(name)); | |
3065 } | |
3066 | |
3067 /********************************** | |
3068 * Generate a FuncDeclaration for a runtime library function. | |
3069 */ | |
3070 static FuncDeclaration genCfunc(Type treturn, Identifier id) | |
3071 { | |
3072 FuncDeclaration fd; | |
3073 TypeFunction tf; | |
3074 Dsymbol s; | |
3075 static DsymbolTable st = null; | |
3076 | |
3077 //printf("genCfunc(name = '%s')\n", id.toChars()); | |
3078 //printf("treturn\n\t"); treturn.print(); | |
3079 | |
3080 // See if already in table | |
3081 if (!st) | |
3082 st = new DsymbolTable(); | |
3083 | |
3084 s = st.lookup(id); | |
3085 if (s) | |
3086 { | |
3087 fd = s.isFuncDeclaration(); | |
3088 assert(fd); | |
3089 assert(fd.type.nextOf().equals(treturn)); | |
3090 } | |
3091 else | |
3092 { | |
3093 tf = new TypeFunction(null, treturn, 0, LINK.LINKc); | |
3094 fd = new FuncDeclaration(Loc(0), Loc(0), id, STCstatic, tf); | |
3095 fd.protection = PROT.PROTpublic; | |
3096 fd.linkage = LINK.LINKc; | |
3097 | |
3098 st.insert(fd); | |
3099 } | |
3100 return fd; | |
3101 } | |
3102 | |
72 | 3103 override Symbol* toSymbol() |
0 | 3104 { |
3105 if (!csym) | |
3106 { | |
3107 Symbol* s; | |
3108 TYPE* t; | |
3109 string id; | |
3110 | |
3111 static if (false) { | |
3112 id = ident.toChars(); | |
3113 } else { | |
3114 id = mangle(); | |
3115 } | |
3116 //writef("FuncDeclaration.toSymbol(%s %s)\n", kind(), toChars()); | |
3117 //writef("\tid = '%s'\n", id); | |
3118 //writef("\ttype = %s\n", type.toChars()); | |
3119 s = symbol_calloc(toStringz(id)); | |
3120 slist_add(s); | |
3121 | |
3122 { | |
3123 s.prettyIdent = toStringz(toPrettyChars()); | |
3124 s.Sclass = SC.SCglobal; | |
3125 symbol_func(s); | |
3126 func_t* f = s.Sfunc; | |
3127 if (isVirtual()) | |
3128 f.Fflags |= F.Fvirtual; | |
3129 else if (isMember2()) | |
3130 f.Fflags |= F.Fstatic; | |
3131 f.Fstartline.Slinnum = loc.linnum; | |
3132 f.Fstartline.Sfilename = cast(char*)toStringz(loc.filename); | |
3133 if (endloc.linnum) | |
3134 { | |
3135 f.Fendline.Slinnum = endloc.linnum; | |
3136 f.Fendline.Sfilename = cast(char*)toStringz(endloc.filename); | |
3137 } | |
3138 else | |
3139 { | |
3140 f.Fendline.Slinnum = loc.linnum; | |
3141 f.Fendline.Sfilename = cast(char*)toStringz(loc.filename); | |
3142 } | |
3143 t = type.toCtype(); | |
3144 } | |
3145 | |
3146 mangle_t msave = t.Tmangle; | |
3147 if (isMain()) | |
3148 { | |
3149 t.Tty = TYM.TYnfunc; | |
3150 t.Tmangle = mTYman.mTYman_c; | |
3151 } | |
3152 else | |
3153 { | |
3154 switch (linkage) | |
3155 { | |
3156 case LINK.LINKwindows: | |
3157 t.Tmangle = mTYman.mTYman_std; | |
3158 break; | |
3159 | |
3160 case LINK.LINKpascal: | |
3161 t.Tty = TYM.TYnpfunc; | |
3162 t.Tmangle = mTYman.mTYman_pas; | |
3163 break; | |
3164 | |
3165 case LINK.LINKc: | |
3166 t.Tmangle = mTYman.mTYman_c; | |
3167 break; | |
3168 | |
3169 case LINK.LINKd: | |
3170 t.Tmangle = mTYman.mTYman_d; | |
3171 break; | |
3172 | |
3173 case LINK.LINKcpp: | |
3174 { t.Tmangle = mTYman.mTYman_cpp; | |
3175 version (TARGET_WINDOS) { | |
3176 if (isThis()) | |
3177 t.Tty = TYM.TYmfunc; | |
3178 } | |
3179 s.Sflags |= SFL.SFLpublic; | |
3180 Dsymbol parent = toParent(); | |
3181 ClassDeclaration cd = parent.isClassDeclaration(); | |
3182 if (cd) | |
3183 { | |
3184 .type* tt = cd.type.toCtype(); | |
3185 s.Sscope = tt.Tnext.Ttag; | |
3186 } | |
3187 break; | |
3188 } | |
3189 default: | |
3190 writef("linkage = %d\n", linkage); | |
3191 assert(0); | |
3192 } | |
3193 } | |
3194 if (msave) | |
3195 assert(msave == t.Tmangle); | |
3196 //printf("Tty = %x, mangle = x%x\n", t.Tty, t.Tmangle); | |
3197 t.Tcount++; | |
3198 s.Stype = t; | |
3199 //s.Sfielddef = this; | |
3200 | |
3201 csym = s; | |
3202 } | |
3203 return csym; | |
3204 } | |
3205 | |
3206 Symbol* toThunkSymbol(int offset) // thunk version | |
3207 { | |
3208 Symbol *sthunk; | |
3209 | |
3210 toSymbol(); | |
3211 | |
3212 static if (false) { | |
3213 char *id; | |
3214 char *n; | |
3215 type *t; | |
3216 | |
3217 n = sym.Sident; | |
72 | 3218 version (Bug4054) { |
63 | 3219 id = cast(char*) GC.malloc(8 + 5 + strlen(n) + 1); |
72 | 3220 } else { |
63 | 3221 id = cast(char*) alloca(8 + 5 + strlen(n) + 1); |
3222 } | |
0 | 3223 sprintf(id, "_thunk%d__%s", offset, n); |
3224 s = symbol_calloc(id); | |
3225 slist_add(s); | |
3226 s.Stype = csym.Stype; | |
3227 s.Stype.Tcount++; | |
3228 } | |
3229 sthunk = symbol_generate(SCstatic, csym.Stype); | |
3230 sthunk.Sflags |= SFLimplem; | |
3231 cod3_thunk(sthunk, csym, 0, TYnptr, -offset, -1, 0); | |
3232 return sthunk; | |
3233 } | |
3234 | |
72 | 3235 override void toObjFile(int multiobj) // compile to .obj file |
0 | 3236 { |
3237 Symbol* s; | |
3238 func_t* f; | |
3239 Symbol* senter; | |
3240 Symbol* sexit; | |
3241 | |
3242 FuncDeclaration func = this; | |
3243 ClassDeclaration cd = func.parent.isClassDeclaration(); | |
3244 int reverse; | |
89 | 3245 |
0 | 3246 int has_arguments; |
3247 | |
3248 //printf("FuncDeclaration.toObjFile(%p, %s.%s)\n", func, parent.toChars(), func.toChars()); | |
98 | 3249 static if (false) |
3250 { | |
0 | 3251 //printf("line = %d\n",func.getWhere() / LINEINC); |
3252 EEcontext ee = env.getEEcontext(); | |
3253 if (ee.EEcompile == 2) | |
3254 { | |
3255 if (ee.EElinnum < (func.getWhere() / LINEINC) || | |
3256 ee.EElinnum > (func.endwhere / LINEINC) | |
3257 ) | |
3258 return; // don't compile this function | |
3259 ee.EEfunc = func.toSymbol(); | |
3260 } | |
3261 } | |
3262 | |
3263 if (multiobj && !isStaticDtorDeclaration() && !isStaticCtorDeclaration()) | |
3264 { | |
3265 obj_append(this); | |
3266 return; | |
3267 } | |
3268 | |
3269 if (semanticRun >= 5) // if toObjFile() already run | |
3270 return; | |
3271 | |
3272 semanticRun = 5; | |
3273 | |
3274 if (!func.fbody) | |
3275 { | |
3276 return; | |
3277 } | |
3278 | |
3279 if (func.isUnitTestDeclaration() && !global.params.useUnitTests) | |
3280 return; | |
3281 | |
3282 if (global.params.verbose) | |
3283 writef("function %s\n",func.toChars()); | |
3284 | |
3285 s = func.toSymbol(); | |
3286 f = s.Sfunc; | |
73 | 3287 |
98 | 3288 version (TARGET_WINDOS) |
3289 { | |
73 | 3290 /* This is done so that the 'this' pointer on the stack is the same |
3291 * distance away from the function parameters, so that an overriding | |
3292 * function can call the nested fdensure or fdrequire of its overridden function | |
3293 * and the stack offsets are the same. | |
3294 */ | |
3295 if (isVirtual() && (fensure || frequire)) | |
3296 f.Fflags3 |= F3.Ffakeeh; | |
3297 } | |
0 | 3298 |
3299 version (TARGET_OSX) { | |
3300 s.Sclass = SC.SCcomdat; | |
3301 } else { | |
3302 s.Sclass = SC.SCglobal; | |
3303 } | |
3304 | |
3305 for (Dsymbol p = parent; p; p = p.parent) | |
3306 { | |
3307 if (p.isTemplateInstance()) | |
3308 { | |
3309 s.Sclass = SC.SCcomdat; | |
3310 break; | |
3311 } | |
3312 } | |
3313 | |
3314 if (isNested()) | |
3315 { | |
3316 // if (!(config.flags3 & CFG3pic)) | |
3317 // s.Sclass = SCstatic; | |
3318 f.Fflags3 |= F3.Fnested; | |
3319 } | |
3320 else | |
3321 { | |
3322 const(char)* libname = (global.params.symdebug) ? global.params.debuglibname : global.params.defaultlibname; | |
3323 | |
3324 // Pull in RTL startup code | |
3325 if (func.isMain()) | |
3326 { objextdef("_main"); | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
17
diff
changeset
|
3327 version (POSIX) { ///TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS |
0 | 3328 obj_ehsections(); // initialize exception handling sections |
3329 } else { | |
3330 objextdef("__acrtused_con"); | |
3331 } | |
3332 obj_includelib(libname); | |
3333 s.Sclass = SC.SCglobal; | |
3334 } | |
3335 else if (strcmp(s.Sident.ptr, "main".ptr) == 0 && linkage == LINK.LINKc) | |
3336 s.Sclass = SC.SCglobal; | |
3337 | |
3338 else if (func.isWinMain()) | |
3339 { | |
3340 objextdef("__acrtused"); | |
3341 obj_includelib(libname); | |
3342 s.Sclass = SC.SCglobal; | |
3343 } | |
3344 | |
3345 // Pull in RTL startup code | |
3346 else if (func.isDllMain()) | |
3347 { | |
3348 objextdef("__acrtused_dll"); | |
3349 obj_includelib(libname); | |
3350 s.Sclass = SC.SCglobal; | |
3351 } | |
3352 } | |
3353 | |
3354 cstate.CSpsymtab = &f.Flocsym; | |
3355 | |
3356 // Find module m for this function | |
3357 Module m = null; | |
3358 for (Dsymbol p = parent; p; p = p.parent) | |
3359 { | |
3360 m = p.isModule(); | |
3361 if (m) | |
3362 break; | |
3363 } | |
3364 | |
3365 IRState irs = IRState(m, func); | |
3366 Array deferToObj = new Array(); // write these to OBJ file later | |
3367 irs.deferToObj = deferToObj; | |
3368 | |
3369 TypeFunction tf; | |
3370 RET retmethod; | |
3371 Symbol* shidden = null; | |
3372 Symbol* sthis = null; | |
3373 tym_t tyf; | |
3374 | |
3375 tyf = tybasic(s.Stype.Tty); | |
3376 //printf("linkage = %d, tyf = x%x\n", linkage, tyf); | |
3377 reverse = tyrevfunc(s.Stype.Tty); | |
3378 | |
3379 assert(func.type.ty == TY.Tfunction); | |
3380 tf = cast(TypeFunction)(func.type); | |
3381 has_arguments = (tf.linkage == LINK.LINKd) && (tf.varargs == 1); | |
3382 retmethod = tf.retStyle(); | |
3383 if (retmethod == RET.RETstack) | |
3384 { | |
3385 // If function returns a struct, put a pointer to that | |
3386 // as the first argument | |
3387 .type* thidden = tf.next.pointerTo().toCtype(); | |
3388 char hiddenparam[5+4+1]; | |
3389 static int hiddenparami; // how many we've generated so far | |
3390 | |
3391 sprintf(hiddenparam.ptr, "__HID%d".ptr, ++hiddenparami); | |
3392 shidden = symbol_name(hiddenparam.ptr, SC.SCparameter, thidden); | |
3393 shidden.Sflags |= SFL.SFLtrue | SFL.SFLfree; | |
3394 | |
3395 version (DMDV1) { | |
3396 bool nestedref = func.nrvo_can && func.nrvo_var && func.nrvo_var.nestedref; | |
3397 } else { | |
3398 bool nestedref = func.nrvo_can && func.nrvo_var && (func.nrvo_var.nestedrefs.dim != 0); | |
3399 } | |
3400 if (nestedref) { | |
3401 type_setcv(&shidden.Stype, shidden.Stype.Tty | mTY.mTYvolatile); | |
3402 } | |
3403 | |
3404 irs.shidden = shidden; | |
3405 this.shidden = shidden; | |
3406 } | |
3407 | |
3408 if (vthis) | |
3409 { | |
3410 assert(!vthis.csym); | |
3411 sthis = vthis.toSymbol(); | |
3412 irs.sthis = sthis; | |
3413 if (!(f.Fflags3 & F3.Fnested)) | |
3414 f.Fflags3 |= F3.Fmember; | |
3415 } | |
3416 | |
3417 Symbol** params; | |
3418 uint pi; | |
3419 | |
3420 // Estimate number of parameters, pi | |
3421 pi = (v_arguments !is null); | |
3422 if (parameters) | |
3423 pi += parameters.dim; | |
3424 | |
3425 // Allow extra 2 for sthis and shidden | |
72 | 3426 version (Bug4054) |
14
2cc604139636
Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
3427 params = cast(Symbol**)GC.malloc((pi + 2) * (Symbol*).sizeof); |
72 | 3428 else |
0 | 3429 params = cast(Symbol**)alloca((pi + 2) * (Symbol*).sizeof); |
3430 | |
3431 // Get the actual number of parameters, pi, and fill in the params[] | |
3432 pi = 0; | |
3433 if (v_arguments) | |
3434 { | |
3435 params[pi] = v_arguments.toSymbol(); | |
3436 pi += 1; | |
3437 } | |
3438 if (parameters) | |
3439 { | |
89 | 3440 size_t i = 0; |
3441 for ( ; i < parameters.dim; ++i) | |
0 | 3442 { |
89 | 3443 auto v = cast(VarDeclaration)parameters[i]; |
98 | 3444 |
0 | 3445 if (v.csym) |
98 | 3446 { |
3447 error("compiler error, parameter '%s', bugzilla 2962?", v.toChars()); | |
3448 assert(false); | |
3449 } | |
0 | 3450 params[pi + i] = v.toSymbol(); |
3451 } | |
3452 pi += i; | |
3453 } | |
3454 | |
3455 if (reverse) | |
3456 { | |
3457 // Reverse params[] entries | |
89 | 3458 for (size_t i = 0; i < pi/2; i++) |
0 | 3459 { |
3460 Symbol* sptmp = params[i]; | |
3461 params[i] = params[pi - 1 - i]; | |
3462 params[pi - 1 - i] = sptmp; | |
3463 } | |
3464 } | |
3465 | |
3466 if (shidden) | |
3467 { | |
3468 static if (false) { | |
3469 // shidden becomes last parameter | |
3470 params[pi] = shidden; | |
3471 } else { | |
3472 // shidden becomes first parameter | |
3473 memmove(params + 1, params, pi * (*params).sizeof); | |
3474 params[0] = shidden; | |
3475 } | |
3476 pi++; | |
3477 } | |
3478 | |
3479 | |
3480 if (sthis) | |
3481 { | |
3482 static if (false) { | |
3483 // sthis becomes last parameter | |
3484 params[pi] = sthis; | |
3485 } else { | |
3486 // sthis becomes first parameter | |
3487 memmove(params + 1, params, pi * (*params).sizeof); | |
3488 params[0] = sthis; | |
3489 } | |
3490 pi++; | |
3491 } | |
3492 | |
3493 if ((global.params.isLinux || global.params.isOSX || global.params.isFreeBSD || global.params.isSolaris) && | |
3494 linkage != LINK.LINKd && shidden && sthis) | |
3495 { | |
3496 /* swap shidden and sthis | |
3497 */ | |
3498 Symbol* sp = params[0]; | |
3499 params[0] = params[1]; | |
3500 params[1] = sp; | |
3501 } | |
3502 | |
89 | 3503 for (size_t i = 0; i < pi; i++) |
0 | 3504 { |
3505 Symbol *sp = params[i]; | |
3506 sp.Sclass = SC.SCparameter; | |
3507 sp.Sflags &= ~SFL.SFLspill; | |
3508 sp.Sfl = FL.FLpara; | |
3509 symbol_add(sp); | |
3510 } | |
3511 | |
3512 // First parameter goes in register | |
3513 if (pi) | |
3514 { | |
3515 Symbol* sp = params[0]; | |
3516 if ((tyf == TYM.TYjfunc || tyf == TYM.TYmfunc) && type_jparam(sp.Stype)) | |
3517 { | |
3518 sp.Sclass = SC.SCfastpar; | |
3519 sp.Spreg = (tyf == TYM.TYjfunc) ? REG.AX : REG.CX; | |
3520 sp.Sfl = FL.FLauto; | |
3521 //printf("'%s' is SCfastpar\n",sp.Sident); | |
3522 } | |
3523 } | |
3524 | |
3525 if (func.fbody) | |
3526 { | |
3527 block* b; | |
3528 Blockx bx; | |
3529 Statement sbody; | |
3530 | |
3531 localgot = null; | |
3532 | |
3533 sbody = func.fbody; | |
3534 ///memset(&bx, 0, (bx).sizeof); | |
3535 bx.startblock = block_calloc(); | |
3536 bx.curblock = bx.startblock; | |
3537 bx.funcsym = s; | |
3538 bx.scope_index = -1; | |
3539 bx.classdec = cd; | |
3540 bx.member = func; | |
3541 bx.module_ = getModule(); | |
3542 irs.blx = &bx; | |
3543 | |
3544 buildClosure(&irs); | |
3545 | |
3546 static if (false) { | |
3547 if (func.isSynchronized()) | |
3548 { | |
3549 if (cd) | |
3550 { | |
3551 elem *esync; | |
3552 if (func.isStatic()) | |
3553 { // monitor is in ClassInfo | |
3554 esync = el_ptr(cd.toSymbol()); | |
3555 } | |
3556 else | |
3557 { // 'this' is the monitor | |
3558 esync = el_var(sthis); | |
3559 } | |
3560 | |
3561 if (func.isStatic() || sbody.usesEH() || | |
3562 !(config.flags2 & CFG2.CFG2seh)) | |
3563 { // BUG: what if frequire or fensure uses EH? | |
3564 | |
3565 sbody = new SynchronizedStatement(func.loc, esync, sbody); | |
3566 } | |
3567 else | |
3568 { | |
3569 version (TARGET_WINDOS) { | |
3570 if (config.flags2 & CFG2.CFG2seh) | |
3571 { | |
3572 /* The "jmonitor" uses an optimized exception handling frame | |
3573 * which is a little shorter than the more general EH frame. | |
3574 * It isn't strictly necessary. | |
3575 */ | |
3576 s.Sfunc.Fflags3 |= Fjmonitor; | |
3577 } | |
3578 } | |
3579 el_free(esync); | |
3580 } | |
3581 } | |
3582 else | |
3583 { | |
3584 error("synchronized function %s must be a member of a class", func.toChars()); | |
3585 } | |
3586 } | |
3587 } else version (TARGET_WINDOS) { | |
3588 if (func.isSynchronized() && cd && config.flags2 & CFG2.CFG2seh && | |
3589 !func.isStatic() && !sbody.usesEH()) | |
3590 { | |
3591 /* The "jmonitor" hack uses an optimized exception handling frame | |
3592 * which is a little shorter than the more general EH frame. | |
3593 */ | |
3594 s.Sfunc.Fflags3 |= F3.Fjmonitor; | |
3595 } | |
3596 } | |
3597 | |
3598 sbody.toIR(&irs); | |
3599 bx.curblock.BC = BC.BCret; | |
3600 | |
3601 f.Fstartblock = bx.startblock; | |
3602 // einit = el_combine(einit,bx.init); | |
3603 | |
3604 if (isCtorDeclaration()) | |
3605 { | |
3606 assert(sthis); | |
3607 for (b = f.Fstartblock; b; b = b.Bnext) | |
3608 { | |
3609 if (b.BC == BC.BCret) | |
3610 { | |
3611 b.BC = BC.BCretexp; | |
3612 b.Belem = el_combine(b.Belem, el_var(sthis)); | |
3613 } | |
3614 } | |
3615 } | |
3616 } | |
3617 | |
3618 // If static constructor | |
3619 if (isStaticConstructor()) | |
3620 { | |
3621 elem* e = el_una(OPER.OPucall, TYM.TYvoid, el_var(s)); | |
3622 ector = el_combine(ector, e); | |
3623 } | |
3624 | |
3625 // If static destructor | |
3626 if (isStaticDestructor()) | |
3627 { | |
3628 elem* e; | |
3629 | |
3630 version (STATICCTOR) { | |
3631 e = el_bin(OPER.OPcall, TYM.TYvoid, el_var(rtlsym[RTLSYM.RTLSYM_FATEXIT]), el_ptr(s)); | |
3632 ector = el_combine(ector, e); | |
3633 dtorcount++; | |
3634 } else { | |
3635 StaticDtorDeclaration f2 = isStaticDtorDeclaration(); | |
3636 assert(f2); | |
3637 if (f2.vgate) | |
3638 { | |
3639 /* Increment destructor's vgate at construction time | |
3640 */ | |
3641 ectorgates.push(cast(void*)f2); | |
3642 } | |
3643 | |
3644 e = el_una(OPER.OPucall, TYM.TYvoid, el_var(s)); | |
3645 edtor = el_combine(e, edtor); | |
3646 } | |
3647 } | |
3648 | |
3649 // If unit test | |
3650 if (isUnitTestDeclaration()) | |
3651 { | |
3652 elem* e = el_una(OPER.OPucall, TYM.TYvoid, el_var(s)); | |
3653 etest = el_combine(etest, e); | |
3654 } | |
3655 | |
3656 if (global.errors) | |
3657 return; | |
3658 | |
3659 writefunc(s); | |
3660 | |
3661 if (isExport()) { | |
3662 obj_export(s, Poffset); | |
3663 } | |
3664 | |
89 | 3665 for (size_t i = 0; i < irs.deferToObj.dim; i++) |
0 | 3666 { |
3667 Dsymbol ss = cast(Dsymbol)irs.deferToObj.data[i]; | |
3668 ss.toObjFile(0); | |
3669 } | |
3670 | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
17
diff
changeset
|
3671 version (POSIX) { ///TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS |
0 | 3672 // A hack to get a pointer to this function put in the .dtors segment |
3673 if (ident && ident.toChars() == "_STD") { | |
3674 obj_staticdtor(s); | |
3675 } | |
3676 } | |
3677 version (DMDV2) { | |
3678 if (irs.startaddress) | |
3679 { | |
3680 writef("Setting start address\n"); | |
3681 obj_startaddress(irs.startaddress); | |
3682 } | |
3683 } | |
3684 } | |
3685 | |
72 | 3686 override int cvMember(ubyte* p) |
0 | 3687 { |
3688 assert(false); | |
3689 } | |
3690 | |
3691 /************************************* | |
3692 * Closures are implemented by taking the local variables that | |
3693 * need to survive the scope of the function, and copying them | |
3694 * into a gc allocated chuck of memory. That chunk, called the | |
3695 * closure here, is inserted into the linked list of stack | |
3696 * frames instead of the usual stack frame. | |
3697 * | |
3698 * buildClosure() inserts code just after the function prolog | |
3699 * is complete. It allocates memory for the closure, allocates | |
3700 * a local variable (sclosure) to point to it, inserts into it | |
3701 * the link to the enclosing frame, and copies into it the parameters | |
3702 * that are referred to in nested functions. | |
3703 * In VarExp.toElem and SymOffExp.toElem, when referring to a | |
3704 * variable that is in a closure, takes the offset from sclosure rather | |
3705 * than from the frame pointer. | |
3706 * | |
3707 * getEthis() and NewExp.toElem need to use sclosure, if set, rather | |
3708 * than the current frame pointer. | |
3709 */ | |
3710 void buildClosure(IRState* irs) | |
3711 { | |
3712 if (needsClosure()) | |
3713 { | |
3714 // Generate closure on the heap | |
3715 // BUG: doesn't capture variadic arguments passed to this function | |
3716 | |
3717 version (DMDV2) { | |
3718 /* BUG: doesn't handle destructors for the local variables. | |
3719 * The way to do it is to make the closure variables the fields | |
3720 * of a class object: | |
3721 * class Closure | |
3722 * { vtbl[] | |
3723 * monitor | |
3724 * ptr to destructor | |
3725 * sthis | |
3726 * ... closure variables ... | |
3727 * ~this() { call destructor } | |
3728 * } | |
3729 */ | |
3730 } | |
3731 //printf("FuncDeclaration.buildClosure()\n"); | |
3732 Symbol* sclosure; | |
3733 sclosure = symbol_name("__closptr".ptr, SC.SCauto, Type.tvoidptr.toCtype()); | |
3734 sclosure.Sflags |= SFL.SFLtrue | SFL.SFLfree; | |
3735 symbol_add(sclosure); | |
3736 irs.sclosure = sclosure; | |
3737 | |
3738 uint offset = PTRSIZE; // leave room for previous sthis | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
3739 foreach (Dsymbol s3; closureVars) |
0 | 3740 { |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
3741 auto v = cast(VarDeclaration)s3; |
0 | 3742 assert(v.isVarDeclaration()); |
3743 | |
3744 version (DMDV2) { | |
3745 if (v.needsAutoDtor()) | |
3746 v.error("has scoped destruction, cannot build closure"); | |
3747 } | |
3748 /* Align and allocate space for v in the closure | |
3749 * just like AggregateDeclaration.addField() does. | |
3750 */ | |
3751 uint memsize; | |
3752 uint memalignsize; | |
3753 uint xalign; | |
3754 /// version (DMDV2) { | |
3755 if (v.storage_class & STC.STClazy) | |
3756 { | |
3757 /* Lazy variables are really delegates, | |
3758 * so give same answers that TypeDelegate would | |
3759 */ | |
3760 memsize = PTRSIZE * 2; | |
3761 memalignsize = memsize; | |
3762 xalign = global.structalign; | |
3763 } | |
3764 else | |
3765 /// } | |
3766 { | |
3767 memsize = cast(uint)v.type.size(); | |
3768 memalignsize = v.type.alignsize(); | |
3769 xalign = v.type.memalign(global.structalign); | |
3770 } | |
3771 AggregateDeclaration.alignmember(xalign, memalignsize, &offset); | |
3772 v.offset = offset; | |
3773 offset += memsize; | |
3774 | |
3775 /* Can't do nrvo if the variable is put in a closure, since | |
3776 * what the shidden points to may no longer exist. | |
3777 */ | |
3778 if (nrvo_can && nrvo_var == v) | |
3779 { | |
3780 nrvo_can = 0; | |
3781 } | |
3782 } | |
3783 // offset is now the size of the closure | |
3784 | |
3785 // Allocate memory for the closure | |
3786 elem* e; | |
3787 e = el_long(TYM.TYint, offset); | |
3788 e = el_bin(OPER.OPcall, TYM.TYnptr, el_var(rtlsym[RTLSYM.RTLSYM_ALLOCMEMORY]), e); | |
3789 | |
3790 // Assign block of memory to sclosure | |
3791 // sclosure = allocmemory(sz); | |
3792 e = el_bin(OPER.OPeq, TYM.TYvoid, el_var(sclosure), e); | |
3793 | |
3794 // Set the first element to sthis | |
3795 // *(sclosure + 0) = sthis; | |
3796 elem* ethis; | |
3797 if (irs.sthis) | |
3798 ethis = el_var(irs.sthis); | |
3799 else | |
3800 ethis = el_long(TYM.TYnptr, 0); | |
3801 elem *ex = el_una(OPER.OPind, TYM.TYnptr, el_var(sclosure)); | |
3802 ex = el_bin(OPER.OPeq, TYM.TYnptr, ex, ethis); | |
3803 e = el_combine(e, ex); | |
3804 | |
3805 // Copy function parameters into closure | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
3806 foreach (Dsymbol s3; closureVars) |
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
3807 { auto v = cast(VarDeclaration)s3; |
0 | 3808 |
3809 if (!v.isParameter()) | |
3810 continue; | |
3811 TYM tym = v.type.totym(); | |
3812 if (v.type.toBasetype().ty == TY.Tsarray || v.isOut() || v.isRef()) | |
3813 tym = TYM.TYnptr; // reference parameters are just pointers | |
3814 /// version (DMDV2) { | |
3815 else if (v.storage_class & STC.STClazy) | |
3816 tym = TYM.TYdelegate; | |
3817 /// } | |
3818 ex = el_bin(OPER.OPadd, TYM.TYnptr, el_var(sclosure), el_long(TYM.TYint, v.offset)); | |
3819 ex = el_una(OPER.OPind, tym, ex); | |
3820 if (ex.Ety == TYM.TYstruct) | |
3821 { | |
3822 ex.Enumbytes = cast(uint)v.type.size(); | |
3823 ex = el_bin(OPER.OPstreq, tym, ex, el_var(v.toSymbol())); | |
3824 ex.Enumbytes = cast(uint)v.type.size(); | |
3825 } | |
3826 else | |
3827 { | |
3828 ex = el_bin(OPER.OPeq, tym, ex, el_var(v.toSymbol())); | |
3829 } | |
3830 | |
3831 e = el_combine(e, ex); | |
3832 } | |
3833 | |
3834 block_appendexp(irs.blx.curblock, e); | |
3835 } | |
3836 } | |
3837 | |
72 | 3838 override FuncDeclaration isFuncDeclaration() { return this; } |
3839 } | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
73
diff
changeset
|
3840 |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
3841 alias Vector!FuncDeclaration FuncDeclarations; |