Mercurial > projects > ldc
annotate dmd/func.c @ 57:a9d29e9f1fed trunk
[svn r61] Added support for D-style variadic functions :)
author | lindquist |
---|---|
date | Thu, 25 Oct 2007 02:39:53 +0200 |
parents | 6fcc08a4d406 |
children | d8dd47ef3973 |
rev | line source |
---|---|
1 | 1 |
2 // Compiler implementation of the D programming language | |
3 // Copyright (c) 1999-2007 by Digital Mars | |
4 // All Rights Reserved | |
5 // written by Walter Bright | |
6 // http://www.digitalmars.com | |
7 // License for redistribution is by either the Artistic License | |
8 // in artistic.txt, or the GNU General Public License in gnu.txt. | |
9 // See the included readme.txt for details. | |
10 | |
11 #include <stdio.h> | |
12 #include <assert.h> | |
13 | |
14 #include "mars.h" | |
15 #include "init.h" | |
16 #include "declaration.h" | |
17 #include "attrib.h" | |
18 #include "expression.h" | |
19 #include "scope.h" | |
20 #include "mtype.h" | |
21 #include "aggregate.h" | |
22 #include "identifier.h" | |
23 #include "id.h" | |
24 #include "module.h" | |
25 #include "statement.h" | |
26 #include "template.h" | |
27 #include "hdrgen.h" | |
28 | |
29 #ifdef IN_GCC | |
30 #include "d-dmd-gcc.h" | |
31 #endif | |
32 | |
33 /********************************* FuncDeclaration ****************************/ | |
34 | |
35 FuncDeclaration::FuncDeclaration(Loc loc, Loc endloc, Identifier *id, enum STC storage_class, Type *type) | |
36 : Declaration(id) | |
37 { | |
38 this->storage_class = storage_class; | |
39 this->type = type; | |
40 this->loc = loc; | |
41 this->endloc = endloc; | |
42 fthrows = NULL; | |
43 frequire = NULL; | |
44 outId = NULL; | |
45 vresult = NULL; | |
46 returnLabel = NULL; | |
47 fensure = NULL; | |
48 fbody = NULL; | |
49 localsymtab = NULL; | |
50 vthis = NULL; | |
51 v_arguments = NULL; | |
52 #if IN_GCC | |
53 v_argptr = NULL; | |
54 #endif | |
55 parameters = NULL; | |
56 labtab = NULL; | |
57 overnext = NULL; | |
58 vtblIndex = -1; | |
59 hasReturnExp = 0; | |
60 naked = 0; | |
61 inlineStatus = ILSuninitialized; | |
62 inlineNest = 0; | |
63 inlineAsm = 0; | |
64 cantInterpret = 0; | |
65 semanticRun = 0; | |
66 nestedFrameRef = 0; | |
67 fes = NULL; | |
68 introducing = 0; | |
69 tintro = NULL; | |
70 inferRetType = (type && type->nextOf() == NULL); | |
71 scope = NULL; | |
72 hasReturnExp = 0; | |
73 nrvo_can = 1; | |
74 nrvo_var = NULL; | |
75 shidden = NULL; | |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
1
diff
changeset
|
76 llvmQueued = false; |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
11
diff
changeset
|
77 llvmThisVar = NULL; |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
35
diff
changeset
|
78 llvmNested = NULL; |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
50
diff
changeset
|
79 llvmArguments = NULL; |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
50
diff
changeset
|
80 llvmArgPtr = NULL; |
1 | 81 } |
82 | |
83 Dsymbol *FuncDeclaration::syntaxCopy(Dsymbol *s) | |
84 { | |
85 FuncDeclaration *f; | |
86 | |
87 //printf("FuncDeclaration::syntaxCopy('%s')\n", toChars()); | |
88 if (s) | |
89 f = (FuncDeclaration *)s; | |
90 else | |
91 f = new FuncDeclaration(loc, endloc, ident, (enum STC) storage_class, type->syntaxCopy()); | |
92 f->outId = outId; | |
93 f->frequire = frequire ? frequire->syntaxCopy() : NULL; | |
94 f->fensure = fensure ? fensure->syntaxCopy() : NULL; | |
95 f->fbody = fbody ? fbody->syntaxCopy() : NULL; | |
96 assert(!fthrows); // deprecated | |
97 return f; | |
98 } | |
99 | |
100 | |
101 // Do the semantic analysis on the external interface to the function. | |
102 | |
103 void FuncDeclaration::semantic(Scope *sc) | |
104 { TypeFunction *f; | |
105 StructDeclaration *sd; | |
106 ClassDeclaration *cd; | |
107 InterfaceDeclaration *id; | |
108 | |
109 #if 0 | |
110 printf("FuncDeclaration::semantic(sc = %p, this = %p, '%s', linkage = %d)\n", sc, this, toPrettyChars(), sc->linkage); | |
111 if (isFuncLiteralDeclaration()) | |
112 printf("\tFuncLiteralDeclaration()\n"); | |
113 printf("sc->parent = %s\n", sc->parent->toChars()); | |
114 printf("type: %s\n", type->toChars()); | |
115 #endif | |
116 | |
117 if (type->nextOf()) | |
118 type = type->semantic(loc, sc); | |
119 //type->print(); | |
120 if (type->ty != Tfunction) | |
121 { | |
122 error("%s must be a function", toChars()); | |
123 return; | |
124 } | |
125 f = (TypeFunction *)(type); | |
126 size_t nparams = Argument::dim(f->parameters); | |
127 | |
128 linkage = sc->linkage; | |
129 // if (!parent) | |
130 { | |
131 //parent = sc->scopesym; | |
132 parent = sc->parent; | |
133 } | |
134 protection = sc->protection; | |
135 storage_class |= sc->stc; | |
136 //printf("function storage_class = x%x\n", storage_class); | |
137 Dsymbol *parent = toParent(); | |
138 | |
139 if (isConst() || isAuto() || isScope()) | |
140 error("functions cannot be const or auto"); | |
141 | |
142 if (isAbstract() && !isVirtual()) | |
143 error("non-virtual functions cannot be abstract"); | |
144 #if 0 | |
145 if (isAbstract() && fbody) | |
146 error("abstract functions cannot have bodies"); | |
147 #endif | |
148 | |
149 #if 0 | |
150 if (isStaticConstructor() || isStaticDestructor()) | |
151 { | |
152 if (!isStatic() || type->nextOf()->ty != Tvoid) | |
153 error("static constructors / destructors must be static void"); | |
154 if (f->arguments && f->arguments->dim) | |
155 error("static constructors / destructors must have empty parameter list"); | |
156 // BUG: check for invalid storage classes | |
157 } | |
158 #endif | |
159 | |
160 #ifdef IN_GCC | |
161 AggregateDeclaration *ad; | |
162 | |
163 ad = parent->isAggregateDeclaration(); | |
164 if (ad) | |
165 ad->methods.push(this); | |
166 #endif | |
167 sd = parent->isStructDeclaration(); | |
168 if (sd) | |
169 { | |
170 // Verify no constructors, destructors, etc. | |
171 if (isCtorDeclaration() || | |
172 isDtorDeclaration() | |
173 //|| isInvariantDeclaration() | |
174 //|| isUnitTestDeclaration() | |
175 ) | |
176 { | |
177 error("special member functions not allowed for %ss", sd->kind()); | |
178 } | |
179 | |
180 #if 0 | |
181 if (!sd->inv) | |
182 sd->inv = isInvariantDeclaration(); | |
183 | |
184 if (!sd->aggNew) | |
185 sd->aggNew = isNewDeclaration(); | |
186 | |
187 if (isDelete()) | |
188 { | |
189 if (sd->aggDelete) | |
190 error("multiple delete's for struct %s", sd->toChars()); | |
191 sd->aggDelete = (DeleteDeclaration *)(this); | |
192 } | |
193 #endif | |
194 } | |
195 | |
196 id = parent->isInterfaceDeclaration(); | |
197 if (id) | |
198 { | |
199 storage_class |= STCabstract; | |
200 | |
201 if (isCtorDeclaration() || | |
202 isDtorDeclaration() || | |
203 isInvariantDeclaration() || | |
204 isUnitTestDeclaration() || isNewDeclaration() || isDelete()) | |
205 error("special function not allowed in interface %s", id->toChars()); | |
206 if (fbody) | |
207 error("function body is not abstract in interface %s", id->toChars()); | |
208 } | |
209 | |
210 cd = parent->isClassDeclaration(); | |
211 if (cd) | |
212 { int vi; | |
213 CtorDeclaration *ctor; | |
214 DtorDeclaration *dtor; | |
215 InvariantDeclaration *inv; | |
216 | |
217 if (isCtorDeclaration()) | |
218 { | |
219 // ctor = (CtorDeclaration *)this; | |
220 // if (!cd->ctor) | |
221 // cd->ctor = ctor; | |
222 return; | |
223 } | |
224 | |
225 #if 0 | |
226 dtor = isDtorDeclaration(); | |
227 if (dtor) | |
228 { | |
229 if (cd->dtor) | |
230 error("multiple destructors for class %s", cd->toChars()); | |
231 cd->dtor = dtor; | |
232 } | |
233 | |
234 inv = isInvariantDeclaration(); | |
235 if (inv) | |
236 { | |
237 cd->inv = inv; | |
238 } | |
239 | |
240 if (isNewDeclaration()) | |
241 { | |
242 if (!cd->aggNew) | |
243 cd->aggNew = (NewDeclaration *)(this); | |
244 } | |
245 | |
246 if (isDelete()) | |
247 { | |
248 if (cd->aggDelete) | |
249 error("multiple delete's for class %s", cd->toChars()); | |
250 cd->aggDelete = (DeleteDeclaration *)(this); | |
251 } | |
252 #endif | |
253 | |
254 if (storage_class & STCabstract) | |
255 cd->isabstract = 1; | |
256 | |
257 // if static function, do not put in vtbl[] | |
258 if (!isVirtual()) | |
259 { | |
260 //printf("\tnot virtual\n"); | |
19 | 261 goto Ldone; |
1 | 262 } |
263 | |
264 // Find index of existing function in vtbl[] to override | |
265 if (cd->baseClass) | |
266 { | |
267 for (vi = 0; vi < cd->baseClass->vtbl.dim; vi++) | |
268 { | |
269 FuncDeclaration *fdv = ((Dsymbol *)cd->vtbl.data[vi])->isFuncDeclaration(); | |
270 | |
271 // BUG: should give error if argument types match, | |
272 // but return type does not? | |
273 | |
274 //printf("\tvtbl[%d] = '%s'\n", vi, fdv ? fdv->ident->toChars() : ""); | |
275 if (fdv && fdv->ident == ident) | |
276 { | |
277 int cov = type->covariant(fdv->type); | |
278 //printf("\tbaseclass cov = %d\n", cov); | |
279 if (cov == 2) | |
280 { | |
281 //type->print(); | |
282 //fdv->type->print(); | |
283 //printf("%s %s\n", type->deco, fdv->type->deco); | |
284 error("of type %s overrides but is not covariant with %s of type %s", | |
285 type->toChars(), fdv->toPrettyChars(), fdv->type->toChars()); | |
286 } | |
287 if (cov == 1) | |
288 { | |
289 if (fdv->isFinal()) | |
290 error("cannot override final function %s", fdv->toPrettyChars()); | |
291 if (fdv->toParent() == parent) | |
292 { | |
293 // If both are mixins, then error. | |
294 // If either is not, the one that is not overrides | |
295 // the other. | |
296 if (fdv->parent->isClassDeclaration()) | |
297 goto L1; | |
298 if (!this->parent->isClassDeclaration() | |
299 #if !BREAKABI | |
300 && !isDtorDeclaration() | |
301 #endif | |
302 ) | |
303 error("multiple overrides of same function"); | |
304 } | |
305 cd->vtbl.data[vi] = (void *)this; | |
306 vtblIndex = vi; | |
307 | |
308 /* This works by whenever this function is called, | |
309 * it actually returns tintro, which gets dynamically | |
310 * cast to type. But we know that tintro is a base | |
311 * of type, so we could optimize it by not doing a | |
312 * dynamic cast, but just subtracting the isBaseOf() | |
313 * offset if the value is != null. | |
314 */ | |
315 | |
316 if (fdv->tintro) | |
317 tintro = fdv->tintro; | |
318 else if (!type->equals(fdv->type)) | |
319 { | |
320 /* Only need to have a tintro if the vptr | |
321 * offsets differ | |
322 */ | |
323 int offset; | |
324 if (fdv->type->nextOf()->isBaseOf(type->nextOf(), &offset)) | |
325 { | |
326 tintro = fdv->type; | |
327 } | |
328 } | |
329 goto L1; | |
330 } | |
331 if (cov == 3) | |
332 { | |
333 cd->sizeok = 2; // can't finish due to forward reference | |
334 return; | |
335 } | |
336 } | |
337 } | |
338 } | |
339 | |
340 // This is an 'introducing' function. | |
341 | |
342 // Verify this doesn't override previous final function | |
343 if (cd->baseClass) | |
344 { Dsymbol *s = cd->baseClass->search(loc, ident, 0); | |
345 if (s) | |
346 { | |
347 FuncDeclaration *f = s->isFuncDeclaration(); | |
348 f = f->overloadExactMatch(type); | |
349 if (f && f->isFinal() && f->prot() != PROTprivate) | |
350 error("cannot override final function %s", f->toPrettyChars()); | |
351 } | |
352 } | |
353 | |
354 if (isFinal()) | |
355 { | |
356 cd->vtblFinal.push(this); | |
357 } | |
358 else | |
359 { | |
360 // Append to end of vtbl[] | |
361 //printf("\tintroducing function\n"); | |
362 introducing = 1; | |
363 vi = cd->vtbl.dim; | |
364 cd->vtbl.push(this); | |
365 vtblIndex = vi; | |
366 } | |
367 | |
368 L1: ; | |
369 | |
370 /* Go through all the interface bases. | |
371 * If this function is covariant with any members of those interface | |
372 * functions, set the tintro. | |
373 */ | |
374 for (int i = 0; i < cd->interfaces_dim; i++) | |
375 { | |
376 BaseClass *b = cd->interfaces[i]; | |
377 for (vi = 0; vi < b->base->vtbl.dim; vi++) | |
378 { | |
379 Dsymbol *s = (Dsymbol *)b->base->vtbl.data[vi]; | |
380 //printf("interface %d vtbl[%d] %p %s\n", i, vi, s, s->toChars()); | |
381 FuncDeclaration *fdv = s->isFuncDeclaration(); | |
382 if (fdv && fdv->ident == ident) | |
383 { | |
384 int cov = type->covariant(fdv->type); | |
385 //printf("\tcov = %d\n", cov); | |
386 if (cov == 2) | |
387 { | |
388 //type->print(); | |
389 //fdv->type->print(); | |
390 //printf("%s %s\n", type->deco, fdv->type->deco); | |
391 error("of type %s overrides but is not covariant with %s of type %s", | |
392 type->toChars(), fdv->toPrettyChars(), fdv->type->toChars()); | |
393 } | |
394 if (cov == 1) | |
395 { Type *ti = NULL; | |
396 | |
397 if (fdv->tintro) | |
398 ti = fdv->tintro; | |
399 else if (!type->equals(fdv->type)) | |
400 { | |
401 /* Only need to have a tintro if the vptr | |
402 * offsets differ | |
403 */ | |
404 int offset; | |
405 if (fdv->type->nextOf()->isBaseOf(type->nextOf(), &offset)) | |
406 { | |
407 ti = fdv->type; | |
408 #if 0 | |
409 if (offset) | |
410 ti = fdv->type; | |
19 | 411 else if (type->nextOf()->ty == Tclass) |
412 { ClassDeclaration *cdn = ((TypeClass *)type->nextOf())->sym; | |
1 | 413 if (cdn && cdn->sizeok != 1) |
414 ti = fdv->type; | |
415 } | |
416 #endif | |
417 } | |
418 } | |
419 if (ti) | |
420 { | |
421 if (tintro && !tintro->equals(ti)) | |
422 { | |
423 error("incompatible covariant types %s and %s", tintro->toChars(), ti->toChars()); | |
424 } | |
425 tintro = ti; | |
426 } | |
427 goto L2; | |
428 } | |
429 if (cov == 3) | |
430 { | |
431 cd->sizeok = 2; // can't finish due to forward reference | |
432 return; | |
433 } | |
434 } | |
435 } | |
436 } | |
437 | |
438 if (introducing && isOverride()) | |
439 { | |
440 error("function %s does not override any", toChars()); | |
441 } | |
442 | |
443 L2: ; | |
444 } | |
445 else if (isOverride() && !parent->isTemplateInstance()) | |
446 error("override only applies to class member functions"); | |
447 | |
448 /* Do not allow template instances to add virtual functions | |
449 * to a class. | |
450 */ | |
451 if (isVirtual()) | |
452 { | |
453 TemplateInstance *ti = parent->isTemplateInstance(); | |
454 if (ti) | |
455 { | |
456 // Take care of nested templates | |
457 while (1) | |
458 { | |
459 TemplateInstance *ti2 = ti->tempdecl->parent->isTemplateInstance(); | |
460 if (!ti2) | |
461 break; | |
462 ti = ti2; | |
463 } | |
464 | |
465 // If it's a member template | |
466 ClassDeclaration *cd = ti->tempdecl->isClassMember(); | |
467 if (cd) | |
468 { | |
469 error("cannot use template to add virtual function to class '%s'", cd->toChars()); | |
470 } | |
471 } | |
472 } | |
473 | |
474 if (isMain()) | |
475 { | |
476 // Check parameters to see if they are either () or (char[][] args) | |
477 switch (nparams) | |
478 { | |
479 case 0: | |
480 break; | |
481 | |
482 case 1: | |
483 { | |
484 Argument *arg0 = Argument::getNth(f->parameters, 0); | |
485 if (arg0->type->ty != Tarray || | |
19 | 486 arg0->type->nextOf()->ty != Tarray || |
487 arg0->type->nextOf()->nextOf()->ty != Tchar || | |
1 | 488 arg0->storageClass & (STCout | STCref | STClazy)) |
489 goto Lmainerr; | |
490 break; | |
491 } | |
492 | |
493 default: | |
494 goto Lmainerr; | |
495 } | |
496 | |
497 if (f->nextOf()->ty != Tint32 && f->nextOf()->ty != Tvoid) | |
498 error("must return int or void, not %s", f->nextOf()->toChars()); | |
499 if (f->varargs) | |
500 { | |
501 Lmainerr: | |
502 error("parameters must be main() or main(char[][] args)"); | |
503 } | |
504 } | |
505 | |
506 if (ident == Id::assign && (sd || cd)) | |
507 { // Disallow identity assignment operator. | |
508 | |
509 // opAssign(...) | |
510 if (nparams == 0) | |
511 { if (f->varargs == 1) | |
512 goto Lassignerr; | |
513 } | |
514 else | |
515 { | |
516 Argument *arg0 = Argument::getNth(f->parameters, 0); | |
517 Type *t0 = arg0->type->toBasetype(); | |
518 Type *tb = sd ? sd->type : cd->type; | |
519 if (arg0->type->implicitConvTo(tb) || | |
520 (sd && t0->ty == Tpointer && t0->nextOf()->implicitConvTo(tb)) | |
521 ) | |
522 { | |
523 if (nparams == 1) | |
524 goto Lassignerr; | |
525 Argument *arg1 = Argument::getNth(f->parameters, 1); | |
526 if (arg1->defaultArg) | |
527 goto Lassignerr; | |
528 } | |
529 } | |
530 } | |
531 | |
19 | 532 Ldone: |
1 | 533 /* Save scope for possible later use (if we need the |
534 * function internals) | |
535 */ | |
536 scope = new Scope(*sc); | |
537 scope->setNoFree(); | |
538 return; | |
539 | |
540 Lassignerr: | |
541 error("identity assignment operator overload is illegal"); | |
542 } | |
543 | |
544 void FuncDeclaration::semantic2(Scope *sc) | |
545 { | |
546 } | |
547 | |
548 // Do the semantic analysis on the internals of the function. | |
549 | |
550 void FuncDeclaration::semantic3(Scope *sc) | |
551 { TypeFunction *f; | |
552 AggregateDeclaration *ad; | |
553 VarDeclaration *argptr = NULL; | |
554 VarDeclaration *_arguments = NULL; | |
555 | |
556 if (!parent) | |
557 { | |
558 printf("FuncDeclaration::semantic3(%s '%s', sc = %p)\n", kind(), toChars(), sc); | |
559 assert(0); | |
560 } | |
561 //printf("FuncDeclaration::semantic3('%s.%s', sc = %p)\n", parent->toChars(), toChars(), sc); | |
562 //fflush(stdout); | |
563 //{ static int x; if (++x == 2) *(char*)0=0; } | |
564 //printf("\tlinkage = %d\n", sc->linkage); | |
565 | |
566 //printf(" sc->incontract = %d\n", sc->incontract); | |
567 if (semanticRun) | |
568 return; | |
569 semanticRun = 1; | |
570 | |
571 if (!type || type->ty != Tfunction) | |
572 return; | |
573 f = (TypeFunction *)(type); | |
574 size_t nparams = Argument::dim(f->parameters); | |
575 | |
576 // Check the 'throws' clause | |
577 if (fthrows) | |
578 { int i; | |
579 | |
580 for (i = 0; i < fthrows->dim; i++) | |
581 { | |
582 Type *t = (Type *)fthrows->data[i]; | |
583 | |
584 t = t->semantic(loc, sc); | |
585 if (!t->isClassHandle()) | |
586 error("can only throw classes, not %s", t->toChars()); | |
587 } | |
588 } | |
589 | |
590 if (fbody || frequire) | |
591 { | |
592 // Establish function scope | |
593 ScopeDsymbol *ss; | |
594 Scope *sc2; | |
595 | |
596 localsymtab = new DsymbolTable(); | |
597 | |
598 ss = new ScopeDsymbol(); | |
599 ss->parent = sc->scopesym; | |
600 sc2 = sc->push(ss); | |
601 sc2->func = this; | |
602 sc2->parent = this; | |
603 sc2->callSuper = 0; | |
604 sc2->sbreak = NULL; | |
605 sc2->scontinue = NULL; | |
606 sc2->sw = NULL; | |
607 sc2->fes = fes; | |
608 sc2->linkage = LINKd; | |
609 sc2->stc &= ~(STCauto | STCscope | STCstatic | STCabstract | STCdeprecated); | |
610 sc2->protection = PROTpublic; | |
611 sc2->explicitProtection = 0; | |
612 sc2->structalign = 8; | |
613 sc2->incontract = 0; | |
614 sc2->tf = NULL; | |
615 sc2->noctor = 0; | |
616 | |
617 // Declare 'this' | |
618 ad = isThis(); | |
619 if (ad) | |
620 { VarDeclaration *v; | |
621 | |
622 if (isFuncLiteralDeclaration() && isNested()) | |
623 { | |
624 error("literals cannot be class members"); | |
625 return; | |
626 } | |
627 else | |
628 { | |
629 assert(!isNested()); // can't be both member and nested | |
630 assert(ad->handle); | |
631 v = new ThisDeclaration(ad->handle); | |
632 v->storage_class |= STCparameter | STCin; | |
633 v->semantic(sc2); | |
634 if (!sc2->insert(v)) | |
635 assert(0); | |
636 v->parent = this; | |
637 vthis = v; | |
638 } | |
639 } | |
640 else if (isNested()) | |
641 { | |
642 VarDeclaration *v; | |
643 | |
644 v = new ThisDeclaration(Type::tvoid->pointerTo()); | |
645 v->storage_class |= STCparameter | STCin; | |
646 v->semantic(sc2); | |
647 if (!sc2->insert(v)) | |
648 assert(0); | |
649 v->parent = this; | |
650 vthis = v; | |
651 } | |
652 | |
653 // Declare hidden variable _arguments[] and _argptr | |
654 if (f->varargs == 1) | |
655 { Type *t; | |
656 | |
657 if (f->linkage == LINKd) | |
658 { // Declare _arguments[] | |
659 #if BREAKABI | |
660 v_arguments = new VarDeclaration(0, Type::typeinfotypelist->type, Id::_arguments_typeinfo, NULL); | |
661 v_arguments->storage_class = STCparameter | STCin; | |
662 v_arguments->semantic(sc2); | |
663 sc2->insert(v_arguments); | |
664 v_arguments->parent = this; | |
665 | |
666 t = Type::typeinfo->type->arrayOf(); | |
667 _arguments = new VarDeclaration(0, t, Id::_arguments, NULL); | |
668 _arguments->semantic(sc2); | |
669 sc2->insert(_arguments); | |
670 _arguments->parent = this; | |
671 #else | |
672 t = Type::typeinfo->type->arrayOf(); | |
673 v_arguments = new VarDeclaration(0, t, Id::_arguments, NULL); | |
674 v_arguments->storage_class = STCparameter | STCin; | |
675 v_arguments->semantic(sc2); | |
676 sc2->insert(v_arguments); | |
677 v_arguments->parent = this; | |
678 #endif | |
679 } | |
680 if (f->linkage == LINKd || (parameters && parameters->dim)) | |
681 { // Declare _argptr | |
682 #if IN_GCC | |
683 t = d_gcc_builtin_va_list_d_type; | |
684 #else | |
685 t = Type::tvoid->pointerTo(); | |
686 #endif | |
687 argptr = new VarDeclaration(0, t, Id::_argptr, NULL); | |
688 argptr->semantic(sc2); | |
689 sc2->insert(argptr); | |
690 argptr->parent = this; | |
691 } | |
692 } | |
693 | |
694 // Propagate storage class from tuple arguments to their sub-arguments. | |
695 if (f->parameters) | |
696 { | |
697 for (size_t i = 0; i < f->parameters->dim; i++) | |
698 { Argument *arg = (Argument *)f->parameters->data[i]; | |
699 | |
700 if (arg->type->ty == Ttuple) | |
701 { TypeTuple *t = (TypeTuple *)arg->type; | |
702 size_t dim = Argument::dim(t->arguments); | |
703 for (size_t j = 0; j < dim; j++) | |
704 { Argument *narg = Argument::getNth(t->arguments, j); | |
705 narg->storageClass = arg->storageClass; | |
706 } | |
707 } | |
708 } | |
709 } | |
710 | |
711 // Declare all the function parameters as variables | |
712 if (nparams) | |
713 { // parameters[] has all the tuples removed, as the back end | |
714 // doesn't know about tuples | |
715 parameters = new Dsymbols(); | |
716 parameters->reserve(nparams); | |
717 for (size_t i = 0; i < nparams; i++) | |
718 { | |
719 Argument *arg = Argument::getNth(f->parameters, i); | |
720 Identifier *id = arg->ident; | |
721 if (!id) | |
722 { | |
723 //error("no identifier for parameter %d of %s", i + 1, toChars()); | |
724 OutBuffer buf; | |
725 buf.printf("_param_%zu", i); | |
726 char *name = (char *)buf.extractData(); | |
727 id = new Identifier(name, TOKidentifier); | |
728 arg->ident = id; | |
729 } | |
730 VarDeclaration *v = new VarDeclaration(0, arg->type, id, NULL); | |
731 //printf("declaring parameter %s of type %s\n", v->toChars(), v->type->toChars()); | |
732 v->storage_class |= STCparameter; | |
733 if (f->varargs == 2 && i + 1 == nparams) | |
734 v->storage_class |= STCvariadic; | |
735 v->storage_class |= arg->storageClass & (STCin | STCout | STCref | STClazy); | |
736 if (v->storage_class & STClazy) | |
737 v->storage_class |= STCin; | |
738 v->semantic(sc2); | |
739 if (!sc2->insert(v)) | |
740 error("parameter %s.%s is already defined", toChars(), v->toChars()); | |
741 else | |
742 parameters->push(v); | |
743 localsymtab->insert(v); | |
744 v->parent = this; | |
745 // for llvm d | |
746 arg->vardecl = v; | |
747 } | |
748 } | |
749 | |
750 // Declare the tuple symbols and put them in the symbol table, | |
751 // but not in parameters[]. | |
752 if (f->parameters) | |
753 { | |
754 for (size_t i = 0; i < f->parameters->dim; i++) | |
755 { Argument *arg = (Argument *)f->parameters->data[i]; | |
756 | |
757 if (!arg->ident) | |
758 continue; // never used, so ignore | |
759 if (arg->type->ty == Ttuple) | |
760 { TypeTuple *t = (TypeTuple *)arg->type; | |
761 size_t dim = Argument::dim(t->arguments); | |
762 Objects *exps = new Objects(); | |
763 exps->setDim(dim); | |
764 for (size_t j = 0; j < dim; j++) | |
765 { Argument *narg = Argument::getNth(t->arguments, j); | |
766 assert(narg->ident); | |
767 VarDeclaration *v = sc2->search(0, narg->ident, NULL)->isVarDeclaration(); | |
768 assert(v); | |
769 Expression *e = new VarExp(0, v); | |
770 exps->data[j] = (void *)e; | |
771 } | |
772 assert(arg->ident); | |
773 TupleDeclaration *v = new TupleDeclaration(0, arg->ident, exps); | |
774 //printf("declaring tuple %s\n", v->toChars()); | |
775 v->isexp = 1; | |
776 if (!sc2->insert(v)) | |
777 error("parameter %s.%s is already defined", toChars(), v->toChars()); | |
778 localsymtab->insert(v); | |
779 v->parent = this; | |
780 } | |
781 } | |
782 } | |
783 | |
784 sc2->incontract++; | |
785 | |
786 if (frequire) | |
787 { | |
788 // BUG: need to error if accessing out parameters | |
789 // BUG: need to treat parameters as const | |
790 // BUG: need to disallow returns and throws | |
791 // BUG: verify that all in and ref parameters are read | |
792 frequire = frequire->semantic(sc2); | |
793 labtab = NULL; // so body can't refer to labels | |
794 } | |
795 | |
796 if (fensure || addPostInvariant()) | |
797 { | |
798 ScopeDsymbol *sym; | |
799 | |
800 sym = new ScopeDsymbol(); | |
801 sym->parent = sc2->scopesym; | |
802 sc2 = sc2->push(sym); | |
803 | |
804 assert(type->nextOf()); | |
805 if (type->nextOf()->ty == Tvoid) | |
806 { | |
807 if (outId) | |
808 error("void functions have no result"); | |
809 } | |
810 else | |
811 { | |
812 if (!outId) | |
813 outId = Id::result; // provide a default | |
814 } | |
815 | |
816 if (outId) | |
817 { // Declare result variable | |
818 VarDeclaration *v; | |
819 Loc loc = this->loc; | |
820 | |
821 if (fensure) | |
822 loc = fensure->loc; | |
823 | |
824 v = new VarDeclaration(loc, type->nextOf(), outId, NULL); | |
825 v->noauto = 1; | |
826 sc2->incontract--; | |
827 v->semantic(sc2); | |
828 sc2->incontract++; | |
829 if (!sc2->insert(v)) | |
830 error("out result %s is already defined", v->toChars()); | |
831 v->parent = this; | |
832 vresult = v; | |
833 | |
834 // vresult gets initialized with the function return value | |
835 // in ReturnStatement::semantic() | |
836 } | |
837 | |
838 // BUG: need to treat parameters as const | |
839 // BUG: need to disallow returns and throws | |
840 if (fensure) | |
841 { fensure = fensure->semantic(sc2); | |
842 labtab = NULL; // so body can't refer to labels | |
843 } | |
844 | |
845 if (!global.params.useOut) | |
846 { fensure = NULL; // discard | |
847 vresult = NULL; | |
848 } | |
849 | |
850 // Postcondition invariant | |
851 if (addPostInvariant()) | |
852 { | |
853 Expression *e = NULL; | |
854 if (isCtorDeclaration()) | |
855 { | |
856 // Call invariant directly only if it exists | |
857 InvariantDeclaration *inv = ad->inv; | |
858 ClassDeclaration *cd = ad->isClassDeclaration(); | |
859 | |
860 while (!inv && cd) | |
861 { | |
862 cd = cd->baseClass; | |
863 if (!cd) | |
864 break; | |
865 inv = cd->inv; | |
866 } | |
867 if (inv) | |
868 { | |
869 e = new DsymbolExp(0, inv); | |
870 e = new CallExp(0, e); | |
871 e = e->semantic(sc2); | |
872 } | |
873 } | |
874 else | |
875 { // Call invariant virtually | |
876 ThisExp *v = new ThisExp(0); | |
877 v->type = vthis->type; | |
878 e = new AssertExp(0, v); | |
879 } | |
880 if (e) | |
881 { | |
882 ExpStatement *s = new ExpStatement(0, e); | |
883 if (fensure) | |
884 fensure = new CompoundStatement(0, s, fensure); | |
885 else | |
886 fensure = s; | |
887 } | |
888 } | |
889 | |
890 if (fensure) | |
891 { returnLabel = new LabelDsymbol(Id::returnLabel); | |
892 LabelStatement *ls = new LabelStatement(0, Id::returnLabel, fensure); | |
893 ls->isReturnLabel = 1; | |
894 returnLabel->statement = ls; | |
895 } | |
896 sc2 = sc2->pop(); | |
897 } | |
898 | |
899 sc2->incontract--; | |
900 | |
901 if (fbody) | |
902 { ClassDeclaration *cd = isClassMember(); | |
903 | |
904 if (isCtorDeclaration() && cd) | |
905 { | |
906 for (int i = 0; i < cd->fields.dim; i++) | |
907 { VarDeclaration *v = (VarDeclaration *)cd->fields.data[i]; | |
908 | |
909 v->ctorinit = 0; | |
910 } | |
911 } | |
912 | |
913 if (inferRetType || f->retStyle() != RETstack) | |
914 nrvo_can = 0; | |
915 | |
916 fbody = fbody->semantic(sc2); | |
917 | |
918 if (inferRetType) | |
919 { // If no return type inferred yet, then infer a void | |
920 if (!type->nextOf()) | |
921 { | |
922 type->next = Type::tvoid; | |
923 type = type->semantic(loc, sc); | |
924 } | |
925 f = (TypeFunction *)type; | |
926 } | |
927 | |
928 int offend = fbody ? fbody->fallOffEnd() : TRUE; | |
929 | |
930 if (isStaticCtorDeclaration()) | |
931 { /* It's a static constructor. Ensure that all | |
932 * ctor consts were initialized. | |
933 */ | |
934 | |
35
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
19
diff
changeset
|
935 Dsymbol *p = toParent(); |
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
19
diff
changeset
|
936 ScopeDsymbol *ad = p->isScopeDsymbol(); |
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
19
diff
changeset
|
937 if (!ad) |
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
19
diff
changeset
|
938 { |
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
19
diff
changeset
|
939 error("static constructor can only be member of struct/class/module, not %s %s", p->kind(), p->toChars()); |
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
19
diff
changeset
|
940 } |
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
19
diff
changeset
|
941 else |
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
19
diff
changeset
|
942 { |
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
19
diff
changeset
|
943 for (int i = 0; i < ad->members->dim; i++) |
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
19
diff
changeset
|
944 { Dsymbol *s = (Dsymbol *)ad->members->data[i]; |
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
19
diff
changeset
|
945 |
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
19
diff
changeset
|
946 s->checkCtorConstInit(); |
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
19
diff
changeset
|
947 } |
1 | 948 } |
949 } | |
950 | |
951 if (isCtorDeclaration() && cd) | |
952 { | |
953 //printf("callSuper = x%x\n", sc2->callSuper); | |
954 | |
955 // Verify that all the ctorinit fields got initialized | |
956 if (!(sc2->callSuper & CSXthis_ctor)) | |
957 { | |
958 for (int i = 0; i < cd->fields.dim; i++) | |
959 { VarDeclaration *v = (VarDeclaration *)cd->fields.data[i]; | |
960 | |
961 if (v->ctorinit == 0 && v->isCtorinit()) | |
962 error("missing initializer for const field %s", v->toChars()); | |
963 } | |
964 } | |
965 | |
966 if (!(sc2->callSuper & CSXany_ctor) && | |
967 cd->baseClass && cd->baseClass->ctor) | |
968 { | |
969 sc2->callSuper = 0; | |
970 | |
971 // Insert implicit super() at start of fbody | |
972 Expression *e1 = new SuperExp(0); | |
973 Expression *e = new CallExp(0, e1); | |
974 | |
975 unsigned errors = global.errors; | |
976 global.gag++; | |
977 e = e->semantic(sc2); | |
978 global.gag--; | |
979 if (errors != global.errors) | |
980 error("no match for implicit super() call in constructor"); | |
981 | |
982 Statement *s = new ExpStatement(0, e); | |
983 fbody = new CompoundStatement(0, s, fbody); | |
984 } | |
985 } | |
986 else if (fes) | |
987 { // For foreach(){} body, append a return 0; | |
988 Expression *e = new IntegerExp(0); | |
989 Statement *s = new ReturnStatement(0, e); | |
990 fbody = new CompoundStatement(0, fbody, s); | |
991 assert(!returnLabel); | |
992 } | |
993 else if (!hasReturnExp && type->nextOf()->ty != Tvoid) | |
994 error("expected to return a value of type %s", type->nextOf()->toChars()); | |
995 else if (!inlineAsm) | |
996 { | |
997 if (type->nextOf()->ty == Tvoid) | |
998 { | |
999 if (offend && isMain()) | |
1000 { // Add a return 0; statement | |
1001 Statement *s = new ReturnStatement(0, new IntegerExp(0)); | |
1002 fbody = new CompoundStatement(0, fbody, s); | |
1003 } | |
1004 } | |
1005 else | |
1006 { | |
1007 if (offend) | |
1008 { Expression *e; | |
1009 | |
1010 if (global.params.warnings) | |
1011 { fprintf(stdmsg, "warning - "); | |
1012 error("no return at end of function"); | |
1013 } | |
1014 | |
1015 if (global.params.useAssert && | |
1016 !global.params.useInline) | |
1017 { /* Add an assert(0, msg); where the missing return | |
1018 * should be. | |
1019 */ | |
1020 e = new AssertExp( | |
1021 endloc, | |
1022 new IntegerExp(0), | |
1023 new StringExp(loc, "missing return expression") | |
1024 ); | |
1025 } | |
1026 else | |
1027 e = new HaltExp(endloc); | |
1028 e = new CommaExp(0, e, type->nextOf()->defaultInit()); | |
1029 e = e->semantic(sc2); | |
1030 Statement *s = new ExpStatement(0, e); | |
1031 fbody = new CompoundStatement(0, fbody, s); | |
1032 } | |
1033 } | |
1034 } | |
1035 } | |
1036 | |
1037 { | |
1038 Statements *a = new Statements(); | |
1039 | |
1040 // Merge in initialization of 'out' parameters | |
1041 if (parameters) | |
1042 { for (size_t i = 0; i < parameters->dim; i++) | |
1043 { VarDeclaration *v; | |
1044 | |
1045 v = (VarDeclaration *)parameters->data[i]; | |
1046 if (v->storage_class & STCout) | |
1047 { | |
1048 assert(v->init); | |
1049 ExpInitializer *ie = v->init->isExpInitializer(); | |
1050 assert(ie); | |
1051 a->push(new ExpStatement(0, ie->exp)); | |
1052 } | |
1053 } | |
1054 } | |
1055 | |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
50
diff
changeset
|
1056 // we'll handle variadics ourselves |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
50
diff
changeset
|
1057 #if !IN_LLVM |
1 | 1058 if (argptr) |
1059 { // Initialize _argptr to point past non-variadic arg | |
1060 #if IN_GCC | |
1061 // Handled in FuncDeclaration::toObjFile | |
1062 v_argptr = argptr; | |
1063 v_argptr->init = new VoidInitializer(loc); | |
1064 #else | |
1065 Expression *e1; | |
1066 Expression *e; | |
1067 Type *t = argptr->type; | |
1068 VarDeclaration *p; | |
1069 unsigned offset; | |
1070 | |
1071 e1 = new VarExp(0, argptr); | |
1072 if (parameters && parameters->dim) | |
1073 p = (VarDeclaration *)parameters->data[parameters->dim - 1]; | |
1074 else | |
1075 p = v_arguments; // last parameter is _arguments[] | |
1076 offset = p->type->size(); | |
1077 offset = (offset + 3) & ~3; // assume stack aligns on 4 | |
1078 e = new SymOffExp(0, p, offset); | |
1079 e = new AssignExp(0, e1, e); | |
1080 e->type = t; | |
1081 a->push(new ExpStatement(0, e)); | |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
50
diff
changeset
|
1082 #endif // IN_GCC |
1 | 1083 } |
1084 | |
1085 if (_arguments) | |
1086 { | |
1087 /* Advance to elements[] member of TypeInfo_Tuple with: | |
1088 * _arguments = v_arguments.elements; | |
1089 */ | |
1090 Expression *e = new VarExp(0, v_arguments); | |
1091 e = new DotIdExp(0, e, Id::elements); | |
1092 Expression *e1 = new VarExp(0, _arguments); | |
1093 e = new AssignExp(0, e1, e); | |
1094 e = e->semantic(sc); | |
1095 a->push(new ExpStatement(0, e)); | |
1096 } | |
1097 | |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
50
diff
changeset
|
1098 #endif // !IN_LLVM |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
50
diff
changeset
|
1099 |
1 | 1100 // Merge contracts together with body into one compound statement |
1101 | |
1102 #ifdef _DH | |
1103 if (frequire && global.params.useIn) | |
1104 { frequire->incontract = 1; | |
1105 a->push(frequire); | |
1106 } | |
1107 #else | |
1108 if (frequire && global.params.useIn) | |
1109 a->push(frequire); | |
1110 #endif | |
1111 | |
1112 // Precondition invariant | |
1113 if (addPreInvariant()) | |
1114 { | |
1115 Expression *e = NULL; | |
1116 if (isDtorDeclaration()) | |
1117 { | |
1118 // Call invariant directly only if it exists | |
1119 InvariantDeclaration *inv = ad->inv; | |
1120 ClassDeclaration *cd = ad->isClassDeclaration(); | |
1121 | |
1122 while (!inv && cd) | |
1123 { | |
1124 cd = cd->baseClass; | |
1125 if (!cd) | |
1126 break; | |
1127 inv = cd->inv; | |
1128 } | |
1129 if (inv) | |
1130 { | |
1131 e = new DsymbolExp(0, inv); | |
1132 e = new CallExp(0, e); | |
1133 e = e->semantic(sc2); | |
1134 } | |
1135 } | |
1136 else | |
1137 { // Call invariant virtually | |
1138 ThisExp *v = new ThisExp(0); | |
1139 v->type = vthis->type; | |
1140 Expression *se = new StringExp(0, "null this"); | |
1141 se = se->semantic(sc); | |
1142 se->type = Type::tchar->arrayOf(); | |
1143 e = new AssertExp(loc, v, se); | |
1144 } | |
1145 if (e) | |
1146 { | |
1147 ExpStatement *s = new ExpStatement(0, e); | |
1148 a->push(s); | |
1149 } | |
1150 } | |
1151 | |
1152 if (fbody) | |
1153 a->push(fbody); | |
1154 | |
1155 if (fensure) | |
1156 { | |
1157 a->push(returnLabel->statement); | |
1158 | |
1159 if (type->nextOf()->ty != Tvoid) | |
1160 { | |
1161 // Create: return vresult; | |
1162 assert(vresult); | |
1163 Expression *e = new VarExp(0, vresult); | |
1164 if (tintro) | |
1165 { e = e->implicitCastTo(sc, tintro->nextOf()); | |
1166 e = e->semantic(sc); | |
1167 } | |
1168 ReturnStatement *s = new ReturnStatement(0, e); | |
1169 a->push(s); | |
1170 } | |
1171 } | |
1172 | |
1173 fbody = new CompoundStatement(0, a); | |
1174 } | |
1175 | |
1176 sc2->callSuper = 0; | |
1177 sc2->pop(); | |
1178 } | |
1179 semanticRun = 2; | |
1180 } | |
1181 | |
1182 void FuncDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
1183 { | |
1184 //printf("FuncDeclaration::toCBuffer() '%s'\n", toChars()); | |
1185 | |
1186 type->toCBuffer(buf, ident, hgs); | |
1187 bodyToCBuffer(buf, hgs); | |
1188 } | |
1189 | |
1190 | |
1191 void FuncDeclaration::bodyToCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
1192 { | |
1193 if (fbody && | |
1194 (!hgs->hdrgen || hgs->tpltMember || canInline(1,1)) | |
1195 ) | |
1196 { buf->writenl(); | |
1197 | |
1198 // in{} | |
1199 if (frequire) | |
1200 { buf->writestring("in"); | |
1201 buf->writenl(); | |
1202 frequire->toCBuffer(buf, hgs); | |
1203 } | |
1204 | |
1205 // out{} | |
1206 if (fensure) | |
1207 { buf->writestring("out"); | |
1208 if (outId) | |
1209 { buf->writebyte('('); | |
1210 buf->writestring(outId->toChars()); | |
1211 buf->writebyte(')'); | |
1212 } | |
1213 buf->writenl(); | |
1214 fensure->toCBuffer(buf, hgs); | |
1215 } | |
1216 | |
1217 if (frequire || fensure) | |
1218 { buf->writestring("body"); | |
1219 buf->writenl(); | |
1220 } | |
1221 | |
1222 buf->writebyte('{'); | |
1223 buf->writenl(); | |
1224 fbody->toCBuffer(buf, hgs); | |
1225 buf->writebyte('}'); | |
1226 buf->writenl(); | |
1227 } | |
1228 else | |
1229 { buf->writeByte(';'); | |
1230 buf->writenl(); | |
1231 } | |
1232 } | |
1233 | |
1234 /**************************************************** | |
1235 * Determine if 'this' overrides fd. | |
1236 * Return !=0 if it does. | |
1237 */ | |
1238 | |
1239 int FuncDeclaration::overrides(FuncDeclaration *fd) | |
1240 { int result = 0; | |
1241 | |
1242 if (fd->ident == ident) | |
1243 { | |
1244 int cov = type->covariant(fd->type); | |
1245 if (cov) | |
1246 { ClassDeclaration *cd1 = toParent()->isClassDeclaration(); | |
1247 ClassDeclaration *cd2 = fd->toParent()->isClassDeclaration(); | |
1248 | |
1249 if (cd1 && cd2 && cd2->isBaseOf(cd1, NULL)) | |
1250 result = 1; | |
1251 } | |
1252 } | |
1253 return result; | |
1254 } | |
1255 | |
1256 /**************************************************** | |
1257 * Overload this FuncDeclaration with the new one f. | |
1258 * Return !=0 if successful; i.e. no conflict. | |
1259 */ | |
1260 | |
1261 int FuncDeclaration::overloadInsert(Dsymbol *s) | |
1262 { | |
1263 FuncDeclaration *f; | |
1264 AliasDeclaration *a; | |
1265 | |
1266 //printf("FuncDeclaration::overloadInsert(%s)\n", s->toChars()); | |
1267 a = s->isAliasDeclaration(); | |
1268 if (a) | |
1269 { | |
1270 if (overnext) | |
1271 return overnext->overloadInsert(a); | |
1272 if (!a->aliassym && a->type->ty != Tident && a->type->ty != Tinstance) | |
1273 { | |
1274 //printf("\ta = '%s'\n", a->type->toChars()); | |
1275 return FALSE; | |
1276 } | |
1277 overnext = a; | |
1278 //printf("\ttrue: no conflict\n"); | |
1279 return TRUE; | |
1280 } | |
1281 f = s->isFuncDeclaration(); | |
1282 if (!f) | |
1283 return FALSE; | |
1284 | |
1285 if (type && f->type && // can be NULL for overloaded constructors | |
1286 f->type->covariant(type) && | |
1287 !isFuncAliasDeclaration()) | |
1288 { | |
1289 //printf("\tfalse: conflict %s\n", kind()); | |
1290 return FALSE; | |
1291 } | |
1292 | |
1293 if (overnext) | |
1294 return overnext->overloadInsert(f); | |
1295 overnext = f; | |
1296 //printf("\ttrue: no conflict\n"); | |
1297 return TRUE; | |
1298 } | |
1299 | |
1300 /******************************************** | |
1301 * Find function in overload list that exactly matches t. | |
1302 */ | |
1303 | |
1304 /*************************************************** | |
1305 * Visit each overloaded function in turn, and call | |
1306 * (*fp)(param, f) on it. | |
1307 * Exit when no more, or (*fp)(param, f) returns 1. | |
1308 * Returns: | |
1309 * 0 continue | |
1310 * 1 done | |
1311 */ | |
1312 | |
1313 int overloadApply(FuncDeclaration *fstart, | |
1314 int (*fp)(void *, FuncDeclaration *), | |
1315 void *param) | |
1316 { | |
1317 FuncDeclaration *f; | |
1318 Declaration *d; | |
1319 Declaration *next; | |
1320 | |
1321 for (d = fstart; d; d = next) | |
1322 { FuncAliasDeclaration *fa = d->isFuncAliasDeclaration(); | |
1323 | |
1324 if (fa) | |
1325 { | |
1326 if (overloadApply(fa->funcalias, fp, param)) | |
1327 return 1; | |
1328 next = fa->overnext; | |
1329 } | |
1330 else | |
1331 { | |
1332 AliasDeclaration *a = d->isAliasDeclaration(); | |
1333 | |
1334 if (a) | |
1335 { | |
1336 Dsymbol *s = a->toAlias(); | |
1337 next = s->isDeclaration(); | |
1338 if (next == a) | |
1339 break; | |
1340 if (next == fstart) | |
1341 break; | |
1342 } | |
1343 else | |
1344 { | |
1345 f = d->isFuncDeclaration(); | |
1346 if (!f) | |
1347 { d->error("is aliased to a function"); | |
1348 break; // BUG: should print error message? | |
1349 } | |
1350 if ((*fp)(param, f)) | |
1351 return 1; | |
1352 | |
1353 next = f->overnext; | |
1354 } | |
1355 } | |
1356 } | |
1357 return 0; | |
1358 } | |
1359 | |
1360 /******************************************** | |
1361 * Find function in overload list that exactly matches t. | |
1362 */ | |
1363 | |
1364 struct Param1 | |
1365 { | |
1366 Type *t; // type to match | |
1367 FuncDeclaration *f; // return value | |
1368 }; | |
1369 | |
1370 int fp1(void *param, FuncDeclaration *f) | |
1371 { Param1 *p = (Param1 *)param; | |
1372 Type *t = p->t; | |
1373 | |
1374 if (t->equals(f->type)) | |
1375 { p->f = f; | |
1376 return 1; | |
1377 } | |
1378 | |
1379 #if V2 | |
1380 /* Allow covariant matches, if it's just a const conversion | |
1381 * of the return type | |
1382 */ | |
1383 if (t->ty == Tfunction) | |
1384 { TypeFunction *tf = (TypeFunction *)f->type; | |
1385 if (tf->covariant(t) == 1 && | |
1386 tf->nextOf()->implicitConvTo(t->nextOf()) >= MATCHconst) | |
1387 { | |
1388 p->f = f; | |
1389 return 1; | |
1390 } | |
1391 } | |
1392 #endif | |
1393 return 0; | |
1394 } | |
1395 | |
1396 FuncDeclaration *FuncDeclaration::overloadExactMatch(Type *t) | |
1397 { | |
1398 Param1 p; | |
1399 p.t = t; | |
1400 p.f = NULL; | |
1401 overloadApply(this, &fp1, &p); | |
1402 return p.f; | |
1403 } | |
1404 | |
1405 #if 0 | |
1406 FuncDeclaration *FuncDeclaration::overloadExactMatch(Type *t) | |
1407 { | |
1408 FuncDeclaration *f; | |
1409 Declaration *d; | |
1410 Declaration *next; | |
1411 | |
1412 for (d = this; d; d = next) | |
1413 { FuncAliasDeclaration *fa = d->isFuncAliasDeclaration(); | |
1414 | |
1415 if (fa) | |
1416 { | |
1417 FuncDeclaration *f2 = fa->funcalias->overloadExactMatch(t); | |
1418 if (f2) | |
1419 return f2; | |
1420 next = fa->overnext; | |
1421 } | |
1422 else | |
1423 { | |
1424 AliasDeclaration *a = d->isAliasDeclaration(); | |
1425 | |
1426 if (a) | |
1427 { | |
1428 Dsymbol *s = a->toAlias(); | |
1429 next = s->isDeclaration(); | |
1430 if (next == a) | |
1431 break; | |
1432 } | |
1433 else | |
1434 { | |
1435 f = d->isFuncDeclaration(); | |
1436 if (!f) | |
1437 break; // BUG: should print error message? | |
1438 if (t->equals(d->type)) | |
1439 return f; | |
1440 next = f->overnext; | |
1441 } | |
1442 } | |
1443 } | |
1444 return NULL; | |
1445 } | |
1446 #endif | |
1447 | |
1448 /******************************************** | |
1449 * Decide which function matches the arguments best. | |
1450 */ | |
1451 | |
1452 struct Param2 | |
1453 { | |
1454 Match *m; | |
1455 Expressions *arguments; | |
1456 }; | |
1457 | |
1458 int fp2(void *param, FuncDeclaration *f) | |
1459 { Param2 *p = (Param2 *)param; | |
1460 Match *m = p->m; | |
1461 Expressions *arguments = p->arguments; | |
1462 MATCH match; | |
1463 | |
1464 if (f != m->lastf) // skip duplicates | |
1465 { | |
1466 TypeFunction *tf; | |
1467 | |
1468 m->anyf = f; | |
1469 tf = (TypeFunction *)f->type; | |
1470 match = (MATCH) tf->callMatch(arguments); | |
1471 //printf("match = %d\n", match); | |
1472 if (match != MATCHnomatch) | |
1473 { | |
1474 if (match > m->last) | |
1475 goto LfIsBetter; | |
1476 | |
1477 if (match < m->last) | |
1478 goto LlastIsBetter; | |
1479 | |
1480 /* See if one of the matches overrides the other. | |
1481 */ | |
1482 if (m->lastf->overrides(f)) | |
1483 goto LlastIsBetter; | |
1484 else if (f->overrides(m->lastf)) | |
1485 goto LfIsBetter; | |
1486 | |
1487 Lambiguous: | |
1488 m->nextf = f; | |
1489 m->count++; | |
1490 return 0; | |
1491 | |
1492 LfIsBetter: | |
1493 m->last = match; | |
1494 m->lastf = f; | |
1495 m->count = 1; | |
1496 return 0; | |
1497 | |
1498 LlastIsBetter: | |
1499 return 0; | |
1500 } | |
1501 } | |
1502 return 0; | |
1503 } | |
1504 | |
1505 | |
1506 void overloadResolveX(Match *m, FuncDeclaration *fstart, Expressions *arguments) | |
1507 { | |
1508 Param2 p; | |
1509 p.m = m; | |
1510 p.arguments = arguments; | |
1511 overloadApply(fstart, &fp2, &p); | |
1512 } | |
1513 | |
1514 #if 0 | |
1515 // Recursive helper function | |
1516 | |
1517 void overloadResolveX(Match *m, FuncDeclaration *fstart, Expressions *arguments) | |
1518 { | |
1519 MATCH match; | |
1520 Declaration *d; | |
1521 Declaration *next; | |
1522 | |
1523 for (d = fstart; d; d = next) | |
1524 { | |
1525 FuncDeclaration *f; | |
1526 FuncAliasDeclaration *fa; | |
1527 AliasDeclaration *a; | |
1528 | |
1529 fa = d->isFuncAliasDeclaration(); | |
1530 if (fa) | |
1531 { | |
1532 overloadResolveX(m, fa->funcalias, arguments); | |
1533 next = fa->overnext; | |
1534 } | |
1535 else if ((f = d->isFuncDeclaration()) != NULL) | |
1536 { | |
1537 next = f->overnext; | |
1538 if (f == m->lastf) | |
1539 continue; // skip duplicates | |
1540 else | |
1541 { | |
1542 TypeFunction *tf; | |
1543 | |
1544 m->anyf = f; | |
1545 tf = (TypeFunction *)f->type; | |
1546 match = (MATCH) tf->callMatch(arguments); | |
1547 //printf("match = %d\n", match); | |
1548 if (match != MATCHnomatch) | |
1549 { | |
1550 if (match > m->last) | |
1551 goto LfIsBetter; | |
1552 | |
1553 if (match < m->last) | |
1554 goto LlastIsBetter; | |
1555 | |
1556 /* See if one of the matches overrides the other. | |
1557 */ | |
1558 if (m->lastf->overrides(f)) | |
1559 goto LlastIsBetter; | |
1560 else if (f->overrides(m->lastf)) | |
1561 goto LfIsBetter; | |
1562 | |
1563 Lambiguous: | |
1564 m->nextf = f; | |
1565 m->count++; | |
1566 continue; | |
1567 | |
1568 LfIsBetter: | |
1569 m->last = match; | |
1570 m->lastf = f; | |
1571 m->count = 1; | |
1572 continue; | |
1573 | |
1574 LlastIsBetter: | |
1575 continue; | |
1576 } | |
1577 } | |
1578 } | |
1579 else if ((a = d->isAliasDeclaration()) != NULL) | |
1580 { | |
1581 Dsymbol *s = a->toAlias(); | |
1582 next = s->isDeclaration(); | |
1583 if (next == a) | |
1584 break; | |
1585 if (next == fstart) | |
1586 break; | |
1587 } | |
1588 else | |
1589 { d->error("is aliased to a function"); | |
1590 break; | |
1591 } | |
1592 } | |
1593 } | |
1594 #endif | |
1595 | |
1596 FuncDeclaration *FuncDeclaration::overloadResolve(Loc loc, Expressions *arguments) | |
1597 { | |
1598 TypeFunction *tf; | |
1599 Match m; | |
1600 | |
1601 #if 0 | |
1602 printf("FuncDeclaration::overloadResolve('%s')\n", toChars()); | |
1603 if (arguments) | |
1604 { int i; | |
1605 | |
1606 for (i = 0; i < arguments->dim; i++) | |
1607 { Expression *arg; | |
1608 | |
1609 arg = (Expression *)arguments->data[i]; | |
1610 assert(arg->type); | |
1611 printf("\t%s: ", arg->toChars()); | |
1612 arg->type->print(); | |
1613 } | |
1614 } | |
1615 #endif | |
1616 | |
1617 memset(&m, 0, sizeof(m)); | |
1618 m.last = MATCHnomatch; | |
1619 overloadResolveX(&m, this, arguments); | |
1620 | |
1621 if (m.count == 1) // exactly one match | |
1622 { | |
1623 return m.lastf; | |
1624 } | |
1625 else | |
1626 { | |
1627 OutBuffer buf; | |
1628 | |
1629 if (arguments) | |
1630 { | |
1631 HdrGenState hgs; | |
1632 | |
1633 argExpTypesToCBuffer(&buf, arguments, &hgs); | |
1634 } | |
1635 | |
1636 if (m.last == MATCHnomatch) | |
1637 { | |
1638 tf = (TypeFunction *)type; | |
1639 | |
1640 //printf("tf = %s, args = %s\n", tf->deco, ((Expression *)arguments->data[0])->type->deco); | |
1641 error(loc, "%s does not match parameter types (%s)", | |
1642 Argument::argsTypesToChars(tf->parameters, tf->varargs), | |
1643 buf.toChars()); | |
1644 return m.anyf; // as long as it's not a FuncAliasDeclaration | |
1645 } | |
1646 else | |
1647 { | |
1648 #if 1 | |
1649 TypeFunction *t1 = (TypeFunction *)m.lastf->type; | |
1650 TypeFunction *t2 = (TypeFunction *)m.nextf->type; | |
1651 | |
1652 error(loc, "called with argument types:\n\t(%s)\nmatches both:\n\t%s%s\nand:\n\t%s%s", | |
1653 buf.toChars(), | |
1654 m.lastf->toPrettyChars(), Argument::argsTypesToChars(t1->parameters, t1->varargs), | |
1655 m.nextf->toPrettyChars(), Argument::argsTypesToChars(t2->parameters, t2->varargs)); | |
1656 #else | |
1657 error(loc, "overloads %s and %s both match argument list for %s", | |
1658 m.lastf->type->toChars(), | |
1659 m.nextf->type->toChars(), | |
1660 m.lastf->toChars()); | |
1661 #endif | |
1662 return m.lastf; | |
1663 } | |
1664 } | |
1665 } | |
1666 | |
1667 /******************************** | |
1668 * Labels are in a separate scope, one per function. | |
1669 */ | |
1670 | |
1671 LabelDsymbol *FuncDeclaration::searchLabel(Identifier *ident) | |
1672 { Dsymbol *s; | |
1673 | |
1674 if (!labtab) | |
1675 labtab = new DsymbolTable(); // guess we need one | |
1676 | |
1677 s = labtab->lookup(ident); | |
1678 if (!s) | |
1679 { | |
1680 s = new LabelDsymbol(ident); | |
1681 labtab->insert(s); | |
1682 } | |
1683 return (LabelDsymbol *)s; | |
1684 } | |
1685 | |
1686 AggregateDeclaration *FuncDeclaration::isThis() | |
1687 { AggregateDeclaration *ad; | |
1688 | |
1689 //printf("+FuncDeclaration::isThis() '%s'\n", toChars()); | |
1690 ad = NULL; | |
1691 if ((storage_class & STCstatic) == 0) | |
1692 { | |
1693 ad = isMember2(); | |
1694 } | |
1695 //printf("-FuncDeclaration::isThis() %p\n", ad); | |
1696 return ad; | |
1697 } | |
1698 | |
1699 AggregateDeclaration *FuncDeclaration::isMember2() | |
1700 { AggregateDeclaration *ad; | |
1701 | |
1702 //printf("+FuncDeclaration::isMember2() '%s'\n", toChars()); | |
1703 ad = NULL; | |
1704 for (Dsymbol *s = this; s; s = s->parent) | |
1705 { | |
1706 //printf("\ts = '%s', parent = '%s', kind = %s\n", s->toChars(), s->parent->toChars(), s->parent->kind()); | |
1707 ad = s->isMember(); | |
1708 if (ad) | |
1709 { //printf("test4\n"); | |
1710 break; | |
1711 } | |
1712 if (!s->parent || | |
1713 (!s->parent->isTemplateInstance())) | |
1714 { //printf("test5\n"); | |
1715 break; | |
1716 } | |
1717 } | |
1718 //printf("-FuncDeclaration::isMember2() %p\n", ad); | |
1719 return ad; | |
1720 } | |
1721 | |
1722 /***************************************** | |
1723 * Determine lexical level difference from 'this' to nested function 'fd'. | |
1724 * Error if this cannot call fd. | |
1725 * Returns: | |
1726 * 0 same level | |
1727 * -1 increase nesting by 1 (fd is nested within 'this') | |
1728 * >0 decrease nesting by number | |
1729 */ | |
1730 | |
1731 int FuncDeclaration::getLevel(Loc loc, FuncDeclaration *fd) | |
1732 { int level; | |
1733 Dsymbol *s; | |
1734 Dsymbol *fdparent; | |
1735 | |
1736 //printf("FuncDeclaration::getLevel(fd = '%s')\n", fd->toChars()); | |
1737 fdparent = fd->toParent2(); | |
1738 if (fdparent == this) | |
1739 return -1; | |
1740 s = this; | |
1741 level = 0; | |
1742 while (fd != s && fdparent != s->toParent2()) | |
1743 { | |
1744 //printf("\ts = '%s'\n", s->toChars()); | |
1745 FuncDeclaration *thisfd = s->isFuncDeclaration(); | |
1746 if (thisfd) | |
1747 { if (!thisfd->isNested() && !thisfd->vthis) | |
1748 goto Lerr; | |
1749 } | |
1750 else | |
1751 { | |
1752 ClassDeclaration *thiscd = s->isClassDeclaration(); | |
1753 if (thiscd) | |
1754 { if (!thiscd->isNested()) | |
1755 goto Lerr; | |
1756 } | |
1757 else | |
1758 goto Lerr; | |
1759 } | |
1760 | |
1761 s = s->toParent2(); | |
1762 assert(s); | |
1763 level++; | |
1764 } | |
1765 return level; | |
1766 | |
1767 Lerr: | |
1768 error(loc, "cannot access frame of function %s", fd->toChars()); | |
1769 return 1; | |
1770 } | |
1771 | |
1772 void FuncDeclaration::appendExp(Expression *e) | |
1773 { Statement *s; | |
1774 | |
1775 s = new ExpStatement(0, e); | |
1776 appendState(s); | |
1777 } | |
1778 | |
1779 void FuncDeclaration::appendState(Statement *s) | |
1780 { CompoundStatement *cs; | |
1781 | |
1782 if (!fbody) | |
1783 { Statements *a; | |
1784 | |
1785 a = new Statements(); | |
1786 fbody = new CompoundStatement(0, a); | |
1787 } | |
1788 cs = fbody->isCompoundStatement(); | |
1789 cs->statements->push(s); | |
1790 } | |
1791 | |
1792 | |
1793 int FuncDeclaration::isMain() | |
1794 { | |
1795 return ident == Id::main && | |
1796 linkage != LINKc && !isMember() && !isNested(); | |
1797 } | |
1798 | |
1799 int FuncDeclaration::isWinMain() | |
1800 { | |
1801 return ident == Id::WinMain && | |
1802 linkage != LINKc && !isMember(); | |
1803 } | |
1804 | |
1805 int FuncDeclaration::isDllMain() | |
1806 { | |
1807 return ident == Id::DllMain && | |
1808 linkage != LINKc && !isMember(); | |
1809 } | |
1810 | |
1811 int FuncDeclaration::isExport() | |
1812 { | |
1813 return protection == PROTexport; | |
1814 } | |
1815 | |
1816 int FuncDeclaration::isImportedSymbol() | |
1817 { | |
1818 //printf("isImportedSymbol()\n"); | |
1819 //printf("protection = %d\n", protection); | |
1820 return (protection == PROTexport) && !fbody; | |
1821 } | |
1822 | |
1823 // Determine if function goes into virtual function pointer table | |
1824 | |
1825 int FuncDeclaration::isVirtual() | |
1826 { | |
1827 #if 0 | |
1828 printf("FuncDeclaration::isVirtual(%s)\n", toChars()); | |
1829 printf("%p %d %d %d %d\n", isMember(), isStatic(), protection == PROTprivate, isCtorDeclaration(), linkage != LINKd); | |
1830 printf("result is %d\n", | |
1831 isMember() && | |
1832 !(isStatic() || protection == PROTprivate || protection == PROTpackage) && | |
1833 toParent()->isClassDeclaration()); | |
1834 #endif | |
1835 return isMember() && | |
1836 !(isStatic() || protection == PROTprivate || protection == PROTpackage) && | |
1837 toParent()->isClassDeclaration(); | |
1838 } | |
1839 | |
1840 int FuncDeclaration::isAbstract() | |
1841 { | |
1842 return storage_class & STCabstract; | |
1843 } | |
1844 | |
1845 int FuncDeclaration::isCodeseg() | |
1846 { | |
1847 return TRUE; // functions are always in the code segment | |
1848 } | |
1849 | |
1850 // Determine if function needs | |
1851 // a static frame pointer to its lexically enclosing function | |
1852 | |
1853 int FuncDeclaration::isNested() | |
1854 { | |
1855 //if (!toParent()) | |
1856 //printf("FuncDeclaration::isNested('%s') parent=%p\n", toChars(), parent); | |
1857 //printf("\ttoParent() = '%s'\n", toParent()->toChars()); | |
1858 return ((storage_class & STCstatic) == 0) && | |
1859 (toParent2()->isFuncDeclaration() != NULL); | |
1860 } | |
1861 | |
1862 int FuncDeclaration::needThis() | |
1863 { | |
1864 //printf("FuncDeclaration::needThis() '%s'\n", toChars()); | |
1865 int i = isThis() != NULL; | |
1866 //printf("\t%d\n", i); | |
1867 if (!i && isFuncAliasDeclaration()) | |
1868 i = ((FuncAliasDeclaration *)this)->funcalias->needThis(); | |
1869 return i; | |
1870 } | |
1871 | |
1872 int FuncDeclaration::addPreInvariant() | |
1873 { | |
1874 AggregateDeclaration *ad = isThis(); | |
1875 return (ad && | |
1876 //ad->isClassDeclaration() && | |
1877 global.params.useInvariants && | |
1878 (protection == PROTpublic || protection == PROTexport) && | |
1879 !naked); | |
1880 } | |
1881 | |
1882 int FuncDeclaration::addPostInvariant() | |
1883 { | |
1884 AggregateDeclaration *ad = isThis(); | |
1885 return (ad && | |
1886 ad->inv && | |
1887 //ad->isClassDeclaration() && | |
1888 global.params.useInvariants && | |
1889 (protection == PROTpublic || protection == PROTexport) && | |
1890 !naked); | |
1891 } | |
1892 | |
1893 /********************************** | |
1894 * Generate a FuncDeclaration for a runtime library function. | |
1895 */ | |
1896 | |
1897 FuncDeclaration *FuncDeclaration::genCfunc(Type *treturn, char *name) | |
1898 { | |
1899 return genCfunc(treturn, Lexer::idPool(name)); | |
1900 } | |
1901 | |
1902 FuncDeclaration *FuncDeclaration::genCfunc(Type *treturn, Identifier *id) | |
1903 { | |
1904 FuncDeclaration *fd; | |
1905 TypeFunction *tf; | |
1906 Dsymbol *s; | |
1907 static DsymbolTable *st = NULL; | |
1908 | |
1909 //printf("genCfunc(name = '%s')\n", id->toChars()); | |
1910 //printf("treturn\n\t"); treturn->print(); | |
1911 | |
1912 // See if already in table | |
1913 if (!st) | |
1914 st = new DsymbolTable(); | |
1915 s = st->lookup(id); | |
1916 if (s) | |
1917 { | |
1918 fd = s->isFuncDeclaration(); | |
1919 assert(fd); | |
1920 assert(fd->type->nextOf()->equals(treturn)); | |
1921 } | |
1922 else | |
1923 { | |
1924 tf = new TypeFunction(NULL, treturn, 0, LINKc); | |
1925 fd = new FuncDeclaration(0, 0, id, STCstatic, tf); | |
1926 fd->protection = PROTpublic; | |
1927 fd->linkage = LINKc; | |
1928 | |
1929 st->insert(fd); | |
1930 } | |
1931 return fd; | |
1932 } | |
1933 | |
1934 char *FuncDeclaration::kind() | |
1935 { | |
1936 return "function"; | |
1937 } | |
1938 | |
1939 /****************************** FuncAliasDeclaration ************************/ | |
1940 | |
1941 // Used as a way to import a set of functions from another scope into this one. | |
1942 | |
1943 FuncAliasDeclaration::FuncAliasDeclaration(FuncDeclaration *funcalias) | |
1944 : FuncDeclaration(funcalias->loc, funcalias->endloc, funcalias->ident, | |
1945 (enum STC)funcalias->storage_class, funcalias->type) | |
1946 { | |
1947 assert(funcalias != this); | |
1948 this->funcalias = funcalias; | |
1949 } | |
1950 | |
1951 char *FuncAliasDeclaration::kind() | |
1952 { | |
1953 return "function alias"; | |
1954 } | |
1955 | |
1956 | |
1957 /****************************** FuncLiteralDeclaration ************************/ | |
1958 | |
1959 FuncLiteralDeclaration::FuncLiteralDeclaration(Loc loc, Loc endloc, Type *type, | |
1960 enum TOK tok, ForeachStatement *fes) | |
1961 : FuncDeclaration(loc, endloc, NULL, STCundefined, type) | |
1962 { | |
1963 char *id; | |
1964 | |
1965 if (fes) | |
1966 id = "__foreachbody"; | |
1967 else if (tok == TOKdelegate) | |
1968 id = "__dgliteral"; | |
1969 else | |
1970 id = "__funcliteral"; | |
1971 this->ident = Identifier::generateId(id); | |
1972 this->tok = tok; | |
1973 this->fes = fes; | |
1974 //printf("FuncLiteralDeclaration() id = '%s', type = '%s'\n", this->ident->toChars(), type->toChars()); | |
1975 } | |
1976 | |
1977 Dsymbol *FuncLiteralDeclaration::syntaxCopy(Dsymbol *s) | |
1978 { | |
1979 FuncLiteralDeclaration *f; | |
1980 | |
1981 //printf("FuncLiteralDeclaration::syntaxCopy('%s')\n", toChars()); | |
1982 if (s) | |
1983 f = (FuncLiteralDeclaration *)s; | |
1984 else | |
1985 f = new FuncLiteralDeclaration(loc, endloc, type->syntaxCopy(), tok, fes); | |
1986 FuncDeclaration::syntaxCopy(f); | |
1987 return f; | |
1988 } | |
1989 | |
1990 int FuncLiteralDeclaration::isNested() | |
1991 { | |
1992 //printf("FuncLiteralDeclaration::isNested() '%s'\n", toChars()); | |
1993 return (tok == TOKdelegate); | |
1994 } | |
1995 | |
1996 char *FuncLiteralDeclaration::kind() | |
1997 { | |
1998 // GCC requires the (char*) casts | |
1999 return (tok == TOKdelegate) ? (char*)"delegate" : (char*)"function"; | |
2000 } | |
2001 | |
2002 void FuncLiteralDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
2003 { | |
2004 static Identifier *idfunc; | |
2005 static Identifier *iddel; | |
2006 | |
2007 if (!idfunc) | |
2008 idfunc = new Identifier("function", 0); | |
2009 if (!iddel) | |
2010 iddel = new Identifier("delegate", 0); | |
2011 | |
2012 type->toCBuffer(buf, ((tok == TOKdelegate) ? iddel : idfunc), hgs); | |
2013 bodyToCBuffer(buf, hgs); | |
2014 } | |
2015 | |
2016 | |
2017 /********************************* CtorDeclaration ****************************/ | |
2018 | |
2019 CtorDeclaration::CtorDeclaration(Loc loc, Loc endloc, Arguments *arguments, int varargs) | |
2020 : FuncDeclaration(loc, endloc, Id::ctor, STCundefined, NULL) | |
2021 { | |
2022 this->arguments = arguments; | |
2023 this->varargs = varargs; | |
2024 //printf("CtorDeclaration() %s\n", toChars()); | |
2025 } | |
2026 | |
2027 Dsymbol *CtorDeclaration::syntaxCopy(Dsymbol *s) | |
2028 { | |
2029 CtorDeclaration *f; | |
2030 | |
2031 f = new CtorDeclaration(loc, endloc, NULL, varargs); | |
2032 | |
2033 f->outId = outId; | |
2034 f->frequire = frequire ? frequire->syntaxCopy() : NULL; | |
2035 f->fensure = fensure ? fensure->syntaxCopy() : NULL; | |
2036 f->fbody = fbody ? fbody->syntaxCopy() : NULL; | |
2037 assert(!fthrows); // deprecated | |
2038 | |
2039 f->arguments = Argument::arraySyntaxCopy(arguments); | |
2040 return f; | |
2041 } | |
2042 | |
2043 | |
2044 void CtorDeclaration::semantic(Scope *sc) | |
2045 { | |
2046 ClassDeclaration *cd; | |
2047 Type *tret; | |
2048 | |
2049 //printf("CtorDeclaration::semantic()\n"); | |
2050 | |
2051 sc = sc->push(); | |
2052 sc->stc &= ~STCstatic; // not a static constructor | |
2053 | |
2054 parent = sc->parent; | |
2055 Dsymbol *parent = toParent(); | |
2056 cd = parent->isClassDeclaration(); | |
2057 if (!cd) | |
2058 { | |
2059 error("constructors only are for class definitions"); | |
2060 tret = Type::tvoid; | |
2061 } | |
2062 else | |
2063 tret = cd->type; //->referenceTo(); | |
2064 type = new TypeFunction(arguments, tret, varargs, LINKd); | |
2065 | |
2066 sc->flags |= SCOPEctor; | |
2067 type = type->semantic(loc, sc); | |
2068 sc->flags &= ~SCOPEctor; | |
2069 | |
2070 // Append: | |
2071 // return this; | |
2072 // to the function body | |
2073 if (fbody) | |
2074 { Expression *e; | |
2075 Statement *s; | |
2076 | |
2077 e = new ThisExp(0); | |
2078 s = new ReturnStatement(0, e); | |
2079 fbody = new CompoundStatement(0, fbody, s); | |
2080 } | |
2081 | |
2082 FuncDeclaration::semantic(sc); | |
2083 | |
2084 sc->pop(); | |
2085 | |
2086 // See if it's the default constructor | |
2087 if (cd && varargs == 0 && Argument::dim(arguments) == 0) | |
2088 cd->defaultCtor = this; | |
2089 } | |
2090 | |
2091 char *CtorDeclaration::kind() | |
2092 { | |
2093 return "constructor"; | |
2094 } | |
2095 | |
2096 char *CtorDeclaration::toChars() | |
2097 { | |
2098 return "this"; | |
2099 } | |
2100 | |
2101 int CtorDeclaration::isVirtual() | |
2102 { | |
2103 return FALSE; | |
2104 } | |
2105 | |
2106 int CtorDeclaration::addPreInvariant() | |
2107 { | |
2108 return FALSE; | |
2109 } | |
2110 | |
2111 int CtorDeclaration::addPostInvariant() | |
2112 { | |
2113 return (vthis && global.params.useInvariants); | |
2114 } | |
2115 | |
2116 | |
2117 void CtorDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
2118 { | |
2119 buf->writestring("this"); | |
2120 Argument::argsToCBuffer(buf, hgs, arguments, varargs); | |
2121 bodyToCBuffer(buf, hgs); | |
2122 } | |
2123 | |
2124 /********************************* DtorDeclaration ****************************/ | |
2125 | |
2126 DtorDeclaration::DtorDeclaration(Loc loc, Loc endloc) | |
2127 : FuncDeclaration(loc, endloc, Id::dtor, STCundefined, NULL) | |
2128 { | |
2129 } | |
2130 | |
2131 Dsymbol *DtorDeclaration::syntaxCopy(Dsymbol *s) | |
2132 { | |
2133 DtorDeclaration *dd; | |
2134 | |
2135 assert(!s); | |
2136 dd = new DtorDeclaration(loc, endloc); | |
2137 return FuncDeclaration::syntaxCopy(dd); | |
2138 } | |
2139 | |
2140 | |
2141 void DtorDeclaration::semantic(Scope *sc) | |
2142 { | |
2143 ClassDeclaration *cd; | |
2144 | |
2145 parent = sc->parent; | |
2146 Dsymbol *parent = toParent(); | |
2147 cd = parent->isClassDeclaration(); | |
2148 if (!cd) | |
2149 { | |
2150 error("destructors only are for class definitions"); | |
2151 } | |
2152 else | |
2153 cd->dtors.push(this); | |
2154 type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); | |
2155 | |
2156 sc = sc->push(); | |
2157 sc->stc &= ~STCstatic; // not a static destructor | |
2158 sc->linkage = LINKd; | |
2159 | |
2160 FuncDeclaration::semantic(sc); | |
2161 | |
2162 sc->pop(); | |
2163 } | |
2164 | |
2165 int DtorDeclaration::overloadInsert(Dsymbol *s) | |
2166 { | |
2167 return FALSE; // cannot overload destructors | |
2168 } | |
2169 | |
2170 int DtorDeclaration::addPreInvariant() | |
2171 { | |
2172 return (vthis && global.params.useInvariants); | |
2173 } | |
2174 | |
2175 int DtorDeclaration::addPostInvariant() | |
2176 { | |
2177 return FALSE; | |
2178 } | |
2179 | |
2180 int DtorDeclaration::isVirtual() | |
2181 { | |
2182 /* This should be FALSE so that dtor's don't get put into the vtbl[], | |
2183 * but doing so will require recompiling everything. | |
2184 */ | |
2185 #if BREAKABI | |
2186 return FALSE; | |
2187 #else | |
2188 return FuncDeclaration::isVirtual(); | |
2189 #endif | |
2190 } | |
2191 | |
2192 void DtorDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
2193 { | |
2194 if (hgs->hdrgen) | |
2195 return; | |
2196 buf->writestring("~this()"); | |
2197 bodyToCBuffer(buf, hgs); | |
2198 } | |
2199 | |
2200 /********************************* StaticCtorDeclaration ****************************/ | |
2201 | |
2202 StaticCtorDeclaration::StaticCtorDeclaration(Loc loc, Loc endloc) | |
19 | 2203 : FuncDeclaration(loc, endloc, |
2204 Identifier::generateId("_staticCtor"), STCstatic, NULL) | |
1 | 2205 { |
2206 } | |
2207 | |
2208 Dsymbol *StaticCtorDeclaration::syntaxCopy(Dsymbol *s) | |
2209 { | |
2210 StaticCtorDeclaration *scd; | |
2211 | |
2212 assert(!s); | |
2213 scd = new StaticCtorDeclaration(loc, endloc); | |
2214 return FuncDeclaration::syntaxCopy(scd); | |
2215 } | |
2216 | |
2217 | |
2218 void StaticCtorDeclaration::semantic(Scope *sc) | |
2219 { | |
2220 //printf("StaticCtorDeclaration::semantic()\n"); | |
2221 | |
2222 type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); | |
2223 | |
2224 FuncDeclaration::semantic(sc); | |
2225 | |
2226 // We're going to need ModuleInfo | |
2227 Module *m = getModule(); | |
2228 if (!m) | |
2229 m = sc->module; | |
2230 if (m) | |
2231 { m->needmoduleinfo = 1; | |
2232 #ifdef IN_GCC | |
2233 m->strictlyneedmoduleinfo = 1; | |
2234 #endif | |
2235 } | |
2236 } | |
2237 | |
2238 AggregateDeclaration *StaticCtorDeclaration::isThis() | |
2239 { | |
2240 return NULL; | |
2241 } | |
2242 | |
2243 int StaticCtorDeclaration::isStaticConstructor() | |
2244 { | |
2245 return TRUE; | |
2246 } | |
2247 | |
2248 int StaticCtorDeclaration::isVirtual() | |
2249 { | |
2250 return FALSE; | |
2251 } | |
2252 | |
2253 int StaticCtorDeclaration::addPreInvariant() | |
2254 { | |
2255 return FALSE; | |
2256 } | |
2257 | |
2258 int StaticCtorDeclaration::addPostInvariant() | |
2259 { | |
2260 return FALSE; | |
2261 } | |
2262 | |
2263 void StaticCtorDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
2264 { | |
2265 if (hgs->hdrgen) | |
35
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
19
diff
changeset
|
2266 { buf->writestring("static this();\n"); |
1 | 2267 return; |
2268 } | |
2269 buf->writestring("static this()"); | |
2270 bodyToCBuffer(buf, hgs); | |
2271 } | |
2272 | |
2273 /********************************* StaticDtorDeclaration ****************************/ | |
2274 | |
2275 StaticDtorDeclaration::StaticDtorDeclaration(Loc loc, Loc endloc) | |
19 | 2276 : FuncDeclaration(loc, endloc, |
2277 Identifier::generateId("_staticDtor"), STCstatic, NULL) | |
1 | 2278 { |
2279 } | |
2280 | |
2281 Dsymbol *StaticDtorDeclaration::syntaxCopy(Dsymbol *s) | |
2282 { | |
2283 StaticDtorDeclaration *sdd; | |
2284 | |
2285 assert(!s); | |
2286 sdd = new StaticDtorDeclaration(loc, endloc); | |
2287 return FuncDeclaration::syntaxCopy(sdd); | |
2288 } | |
2289 | |
2290 | |
2291 void StaticDtorDeclaration::semantic(Scope *sc) | |
2292 { | |
2293 ClassDeclaration *cd; | |
2294 Type *tret; | |
2295 | |
2296 cd = sc->scopesym->isClassDeclaration(); | |
2297 if (!cd) | |
2298 { | |
2299 } | |
2300 type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); | |
2301 | |
2302 FuncDeclaration::semantic(sc); | |
2303 | |
2304 // We're going to need ModuleInfo | |
2305 Module *m = getModule(); | |
2306 if (!m) | |
2307 m = sc->module; | |
2308 if (m) | |
2309 { m->needmoduleinfo = 1; | |
2310 #ifdef IN_GCC | |
2311 m->strictlyneedmoduleinfo = 1; | |
2312 #endif | |
2313 } | |
2314 } | |
2315 | |
2316 AggregateDeclaration *StaticDtorDeclaration::isThis() | |
2317 { | |
2318 return NULL; | |
2319 } | |
2320 | |
2321 int StaticDtorDeclaration::isStaticDestructor() | |
2322 { | |
2323 return TRUE; | |
2324 } | |
2325 | |
2326 int StaticDtorDeclaration::isVirtual() | |
2327 { | |
2328 return FALSE; | |
2329 } | |
2330 | |
2331 int StaticDtorDeclaration::addPreInvariant() | |
2332 { | |
2333 return FALSE; | |
2334 } | |
2335 | |
2336 int StaticDtorDeclaration::addPostInvariant() | |
2337 { | |
2338 return FALSE; | |
2339 } | |
2340 | |
2341 void StaticDtorDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
2342 { | |
2343 if (hgs->hdrgen) | |
2344 return; | |
2345 buf->writestring("static ~this()"); | |
2346 bodyToCBuffer(buf, hgs); | |
2347 } | |
2348 | |
2349 /********************************* InvariantDeclaration ****************************/ | |
2350 | |
2351 InvariantDeclaration::InvariantDeclaration(Loc loc, Loc endloc) | |
2352 : FuncDeclaration(loc, endloc, Id::classInvariant, STCundefined, NULL) | |
2353 { | |
2354 } | |
2355 | |
2356 Dsymbol *InvariantDeclaration::syntaxCopy(Dsymbol *s) | |
2357 { | |
2358 InvariantDeclaration *id; | |
2359 | |
2360 assert(!s); | |
2361 id = new InvariantDeclaration(loc, endloc); | |
2362 FuncDeclaration::syntaxCopy(id); | |
2363 return id; | |
2364 } | |
2365 | |
2366 | |
2367 void InvariantDeclaration::semantic(Scope *sc) | |
2368 { | |
2369 AggregateDeclaration *ad; | |
2370 Type *tret; | |
2371 | |
2372 parent = sc->parent; | |
2373 Dsymbol *parent = toParent(); | |
2374 ad = parent->isAggregateDeclaration(); | |
2375 if (!ad) | |
2376 { | |
2377 error("invariants only are for struct/union/class definitions"); | |
2378 return; | |
2379 } | |
2380 else if (ad->inv && ad->inv != this) | |
2381 { | |
2382 error("more than one invariant for %s", ad->toChars()); | |
2383 } | |
2384 ad->inv = this; | |
2385 type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); | |
2386 | |
2387 sc = sc->push(); | |
2388 sc->stc &= ~STCstatic; // not a static invariant | |
2389 sc->incontract++; | |
2390 sc->linkage = LINKd; | |
2391 | |
2392 FuncDeclaration::semantic(sc); | |
2393 | |
2394 sc->pop(); | |
2395 } | |
2396 | |
2397 int InvariantDeclaration::isVirtual() | |
2398 { | |
2399 return FALSE; | |
2400 } | |
2401 | |
2402 int InvariantDeclaration::addPreInvariant() | |
2403 { | |
2404 return FALSE; | |
2405 } | |
2406 | |
2407 int InvariantDeclaration::addPostInvariant() | |
2408 { | |
2409 return FALSE; | |
2410 } | |
2411 | |
2412 void InvariantDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
2413 { | |
2414 if (hgs->hdrgen) | |
2415 return; | |
2416 buf->writestring("invariant"); | |
2417 bodyToCBuffer(buf, hgs); | |
2418 } | |
2419 | |
2420 | |
2421 /********************************* UnitTestDeclaration ****************************/ | |
2422 | |
2423 /******************************* | |
2424 * Generate unique unittest function Id so we can have multiple | |
2425 * instances per module. | |
2426 */ | |
2427 | |
2428 static Identifier *unitTestId() | |
2429 { | |
2430 static int n; | |
2431 char buffer[10 + sizeof(n)*3 + 1]; | |
2432 | |
2433 sprintf(buffer,"__unittest%d", n); | |
2434 n++; | |
2435 return Lexer::idPool(buffer); | |
2436 } | |
2437 | |
2438 UnitTestDeclaration::UnitTestDeclaration(Loc loc, Loc endloc) | |
2439 : FuncDeclaration(loc, endloc, unitTestId(), STCundefined, NULL) | |
2440 { | |
2441 } | |
2442 | |
2443 Dsymbol *UnitTestDeclaration::syntaxCopy(Dsymbol *s) | |
2444 { | |
2445 UnitTestDeclaration *utd; | |
2446 | |
2447 assert(!s); | |
2448 utd = new UnitTestDeclaration(loc, endloc); | |
2449 return FuncDeclaration::syntaxCopy(utd); | |
2450 } | |
2451 | |
2452 | |
2453 void UnitTestDeclaration::semantic(Scope *sc) | |
2454 { | |
2455 if (global.params.useUnitTests) | |
2456 { | |
2457 Type *tret; | |
2458 | |
2459 type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); | |
2460 FuncDeclaration::semantic(sc); | |
2461 } | |
2462 | |
2463 // We're going to need ModuleInfo even if the unit tests are not | |
2464 // compiled in, because other modules may import this module and refer | |
2465 // to this ModuleInfo. | |
2466 Module *m = getModule(); | |
2467 if (!m) | |
2468 m = sc->module; | |
2469 if (m) | |
2470 m->needmoduleinfo = 1; | |
2471 } | |
2472 | |
2473 AggregateDeclaration *UnitTestDeclaration::isThis() | |
2474 { | |
2475 return NULL; | |
2476 } | |
2477 | |
2478 int UnitTestDeclaration::isVirtual() | |
2479 { | |
2480 return FALSE; | |
2481 } | |
2482 | |
2483 int UnitTestDeclaration::addPreInvariant() | |
2484 { | |
2485 return FALSE; | |
2486 } | |
2487 | |
2488 int UnitTestDeclaration::addPostInvariant() | |
2489 { | |
2490 return FALSE; | |
2491 } | |
2492 | |
2493 void UnitTestDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
2494 { | |
2495 if (hgs->hdrgen) | |
2496 return; | |
2497 buf->writestring("unittest"); | |
2498 bodyToCBuffer(buf, hgs); | |
2499 } | |
2500 | |
2501 /********************************* NewDeclaration ****************************/ | |
2502 | |
2503 NewDeclaration::NewDeclaration(Loc loc, Loc endloc, Arguments *arguments, int varargs) | |
2504 : FuncDeclaration(loc, endloc, Id::classNew, STCstatic, NULL) | |
2505 { | |
2506 this->arguments = arguments; | |
2507 this->varargs = varargs; | |
2508 } | |
2509 | |
2510 Dsymbol *NewDeclaration::syntaxCopy(Dsymbol *s) | |
2511 { | |
2512 NewDeclaration *f; | |
2513 | |
2514 f = new NewDeclaration(loc, endloc, NULL, varargs); | |
2515 | |
2516 FuncDeclaration::syntaxCopy(f); | |
2517 | |
2518 f->arguments = Argument::arraySyntaxCopy(arguments); | |
2519 | |
2520 return f; | |
2521 } | |
2522 | |
2523 | |
2524 void NewDeclaration::semantic(Scope *sc) | |
2525 { | |
2526 ClassDeclaration *cd; | |
2527 Type *tret; | |
2528 | |
2529 //printf("NewDeclaration::semantic()\n"); | |
2530 | |
2531 parent = sc->parent; | |
2532 Dsymbol *parent = toParent(); | |
2533 cd = parent->isClassDeclaration(); | |
2534 if (!cd && !parent->isStructDeclaration()) | |
2535 { | |
2536 error("new allocators only are for class or struct definitions"); | |
2537 } | |
2538 tret = Type::tvoid->pointerTo(); | |
2539 type = new TypeFunction(arguments, tret, varargs, LINKd); | |
2540 | |
2541 type = type->semantic(loc, sc); | |
2542 assert(type->ty == Tfunction); | |
2543 | |
2544 // Check that there is at least one argument of type uint | |
2545 TypeFunction *tf = (TypeFunction *)type; | |
2546 if (Argument::dim(tf->parameters) < 1) | |
2547 { | |
2548 error("at least one argument of type uint expected"); | |
2549 } | |
2550 else | |
2551 { | |
2552 Argument *a = Argument::getNth(tf->parameters, 0); | |
2553 if (!a->type->equals(Type::tuns32)) | |
2554 error("first argument must be type uint, not %s", a->type->toChars()); | |
2555 } | |
2556 | |
2557 FuncDeclaration::semantic(sc); | |
2558 } | |
2559 | |
2560 char *NewDeclaration::kind() | |
2561 { | |
2562 return "allocator"; | |
2563 } | |
2564 | |
2565 int NewDeclaration::isVirtual() | |
2566 { | |
2567 return FALSE; | |
2568 } | |
2569 | |
2570 int NewDeclaration::addPreInvariant() | |
2571 { | |
2572 return FALSE; | |
2573 } | |
2574 | |
2575 int NewDeclaration::addPostInvariant() | |
2576 { | |
2577 return FALSE; | |
2578 } | |
2579 | |
2580 void NewDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
2581 { | |
2582 buf->writestring("new"); | |
2583 Argument::argsToCBuffer(buf, hgs, arguments, varargs); | |
2584 bodyToCBuffer(buf, hgs); | |
2585 } | |
2586 | |
2587 | |
2588 /********************************* DeleteDeclaration ****************************/ | |
2589 | |
2590 DeleteDeclaration::DeleteDeclaration(Loc loc, Loc endloc, Arguments *arguments) | |
2591 : FuncDeclaration(loc, endloc, Id::classDelete, STCstatic, NULL) | |
2592 { | |
2593 this->arguments = arguments; | |
2594 } | |
2595 | |
2596 Dsymbol *DeleteDeclaration::syntaxCopy(Dsymbol *s) | |
2597 { | |
2598 DeleteDeclaration *f; | |
2599 | |
2600 f = new DeleteDeclaration(loc, endloc, NULL); | |
2601 | |
2602 FuncDeclaration::syntaxCopy(f); | |
2603 | |
2604 f->arguments = Argument::arraySyntaxCopy(arguments); | |
2605 | |
2606 return f; | |
2607 } | |
2608 | |
2609 | |
2610 void DeleteDeclaration::semantic(Scope *sc) | |
2611 { | |
2612 ClassDeclaration *cd; | |
2613 | |
2614 //printf("DeleteDeclaration::semantic()\n"); | |
2615 | |
2616 parent = sc->parent; | |
2617 Dsymbol *parent = toParent(); | |
2618 cd = parent->isClassDeclaration(); | |
2619 if (!cd && !parent->isStructDeclaration()) | |
2620 { | |
2621 error("new allocators only are for class or struct definitions"); | |
2622 } | |
2623 type = new TypeFunction(arguments, Type::tvoid, 0, LINKd); | |
2624 | |
2625 type = type->semantic(loc, sc); | |
2626 assert(type->ty == Tfunction); | |
2627 | |
2628 // Check that there is only one argument of type void* | |
2629 TypeFunction *tf = (TypeFunction *)type; | |
2630 if (Argument::dim(tf->parameters) != 1) | |
2631 { | |
2632 error("one argument of type void* expected"); | |
2633 } | |
2634 else | |
2635 { | |
2636 Argument *a = Argument::getNth(tf->parameters, 0); | |
2637 if (!a->type->equals(Type::tvoid->pointerTo())) | |
2638 error("one argument of type void* expected, not %s", a->type->toChars()); | |
2639 } | |
2640 | |
2641 FuncDeclaration::semantic(sc); | |
2642 } | |
2643 | |
2644 char *DeleteDeclaration::kind() | |
2645 { | |
2646 return "deallocator"; | |
2647 } | |
2648 | |
2649 int DeleteDeclaration::isDelete() | |
2650 { | |
2651 return TRUE; | |
2652 } | |
2653 | |
2654 int DeleteDeclaration::isVirtual() | |
2655 { | |
2656 return FALSE; | |
2657 } | |
2658 | |
2659 int DeleteDeclaration::addPreInvariant() | |
2660 { | |
2661 return FALSE; | |
2662 } | |
2663 | |
2664 int DeleteDeclaration::addPostInvariant() | |
2665 { | |
2666 return FALSE; | |
2667 } | |
2668 | |
2669 void DeleteDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
2670 { | |
2671 buf->writestring("delete"); | |
2672 Argument::argsToCBuffer(buf, hgs, arguments, 0); | |
2673 bodyToCBuffer(buf, hgs); | |
2674 } | |
2675 | |
2676 | |
2677 | |
2678 |