Mercurial > projects > ldc
comparison dmd/template.c @ 1367:8026319762be
Merged DMD 1.045 !!!
author | Tomas Lindquist Olsen <tomas.l.olsen gmail com> |
---|---|
date | Sat, 16 May 2009 22:21:31 +0200 |
parents | e961851fb8be |
children | 4dca8ed9d8b7 |
comparison
equal
deleted
inserted
replaced
1366:81121ac19f61 | 1367:8026319762be |
---|---|
1748 if (nfparams > 0 && nfargs >= nfparams - 1) | 1748 if (nfparams > 0 && nfargs >= nfparams - 1) |
1749 { | 1749 { |
1750 /* See if 'A' of the template parameter matches 'A' | 1750 /* See if 'A' of the template parameter matches 'A' |
1751 * of the type of the last function parameter. | 1751 * of the type of the last function parameter. |
1752 */ | 1752 */ |
1753 Argument *fparam = (Argument *)tp->parameters->data[nfparams - 1]; | 1753 Argument *fparam = Argument::getNth(tp->parameters, nfparams - 1); |
1754 if (fparam->type->ty != Tident) | 1754 if (fparam->type->ty != Tident) |
1755 goto L1; | 1755 goto L1; |
1756 TypeIdentifier *tid = (TypeIdentifier *)fparam->type; | 1756 TypeIdentifier *tid = (TypeIdentifier *)fparam->type; |
1757 if (tid->idents.dim) | 1757 if (tid->idents.dim) |
1758 goto L1; | 1758 goto L1; |
3057 this->loc = loc; | 3057 this->loc = loc; |
3058 this->name = ident; | 3058 this->name = ident; |
3059 this->tiargs = NULL; | 3059 this->tiargs = NULL; |
3060 this->tempdecl = NULL; | 3060 this->tempdecl = NULL; |
3061 this->inst = NULL; | 3061 this->inst = NULL; |
3062 this->tinst = NULL; | |
3062 this->argsym = NULL; | 3063 this->argsym = NULL; |
3063 this->aliasdecl = NULL; | 3064 this->aliasdecl = NULL; |
3064 this->semanticdone = 0; | 3065 this->semanticdone = 0; |
3065 this->semantictiargsdone = 0; | 3066 this->semantictiargsdone = 0; |
3066 this->withsym = NULL; | 3067 this->withsym = NULL; |
3070 this->errors = 0; | 3071 this->errors = 0; |
3071 | 3072 |
3072 #if IN_LLVM | 3073 #if IN_LLVM |
3073 // LDC | 3074 // LDC |
3074 this->emittedInModule = NULL; | 3075 this->emittedInModule = NULL; |
3075 this->tinst = NULL; | |
3076 this->tmodule = NULL; | 3076 this->tmodule = NULL; |
3077 #endif | 3077 #endif |
3078 } | 3078 } |
3079 | 3079 |
3080 /***************** | 3080 /***************** |
3091 this->loc = loc; | 3091 this->loc = loc; |
3092 this->name = td->ident; | 3092 this->name = td->ident; |
3093 this->tiargs = tiargs; | 3093 this->tiargs = tiargs; |
3094 this->tempdecl = td; | 3094 this->tempdecl = td; |
3095 this->inst = NULL; | 3095 this->inst = NULL; |
3096 this->tinst = NULL; | |
3096 this->argsym = NULL; | 3097 this->argsym = NULL; |
3097 this->aliasdecl = NULL; | 3098 this->aliasdecl = NULL; |
3098 this->semanticdone = 0; | 3099 this->semanticdone = 0; |
3099 this->semantictiargsdone = 1; | 3100 this->semantictiargsdone = 1; |
3100 this->withsym = NULL; | 3101 this->withsym = NULL; |
3172 #if LOG | 3173 #if LOG |
3173 printf("-TemplateInstance::semantic('%s', this=%p) already run\n", inst->toChars(), inst); | 3174 printf("-TemplateInstance::semantic('%s', this=%p) already run\n", inst->toChars(), inst); |
3174 #endif | 3175 #endif |
3175 return; | 3176 return; |
3176 } | 3177 } |
3178 | |
3179 // get the enclosing template instance from the scope tinst | |
3180 tinst = sc->tinst; | |
3177 | 3181 |
3178 if (semanticdone != 0) | 3182 if (semanticdone != 0) |
3179 { | 3183 { |
3180 error(loc, "recursive template expansion"); | 3184 error(loc, "recursive template expansion"); |
3181 // inst = this; | 3185 // inst = this; |
3418 | 3422 |
3419 #if WINDOWS_SEH | 3423 #if WINDOWS_SEH |
3420 __try | 3424 __try |
3421 { | 3425 { |
3422 #endif | 3426 #endif |
3427 static int nest; | |
3428 //printf("%d\n", nest); | |
3429 if (++nest > 500) | |
3430 { | |
3431 global.gag = 0; // ensure error message gets printed | |
3432 error("recursive expansion"); | |
3433 fatal(); | |
3434 } | |
3423 for (int i = 0; i < members->dim; i++) | 3435 for (int i = 0; i < members->dim; i++) |
3424 { | 3436 { |
3425 Dsymbol *s = (Dsymbol *)members->data[i]; | 3437 Dsymbol *s = (Dsymbol *)members->data[i]; |
3426 //printf("\t[%d] semantic on '%s' %p kind %s in '%s'\n", i, s->toChars(), s, s->kind(), this->toChars()); | 3438 //printf("\t[%d] semantic on '%s' %p kind %s in '%s'\n", i, s->toChars(), s, s->kind(), this->toChars()); |
3427 //printf("test: isnested = %d, sc2->parent = %s\n", isnested, sc2->parent->toChars()); | 3439 //printf("test: isnested = %d, sc2->parent = %s\n", isnested, sc2->parent->toChars()); |
3430 //printf("test3: isnested = %d, s->parent = %s\n", isnested, s->parent->toChars()); | 3442 //printf("test3: isnested = %d, s->parent = %s\n", isnested, s->parent->toChars()); |
3431 s->semantic(sc2); | 3443 s->semantic(sc2); |
3432 //printf("test4: isnested = %d, s->parent = %s\n", isnested, s->parent->toChars()); | 3444 //printf("test4: isnested = %d, s->parent = %s\n", isnested, s->parent->toChars()); |
3433 sc2->module->runDeferredSemantic(); | 3445 sc2->module->runDeferredSemantic(); |
3434 } | 3446 } |
3447 --nest; | |
3435 #if WINDOWS_SEH | 3448 #if WINDOWS_SEH |
3436 } | 3449 } |
3437 __except (__ehfilter(GetExceptionInformation())) | 3450 __except (__ehfilter(GetExceptionInformation())) |
3438 { | 3451 { |
3439 global.gag = 0; // ensure error message gets printed | 3452 global.gag = 0; // ensure error message gets printed |
3477 | 3490 |
3478 // Give additional context info if error occurred during instantiation | 3491 // Give additional context info if error occurred during instantiation |
3479 if (global.errors != errorsave) | 3492 if (global.errors != errorsave) |
3480 { | 3493 { |
3481 error("error instantiating"); | 3494 error("error instantiating"); |
3482 if(tinst) | 3495 if (tinst && !global.gag) |
3483 tinst->printInstantiationTrace(); | 3496 { tinst->printInstantiationTrace(); |
3497 fatal(); | |
3498 } | |
3484 errors = 1; | 3499 errors = 1; |
3485 if (global.gag) | 3500 if (global.gag) |
3486 tempdecl->instances.remove(tempdecl_instance_idx); | 3501 tempdecl->instances.remove(tempdecl_instance_idx); |
3487 } | 3502 } |
3488 | 3503 |
3983 else if (sa) | 3998 else if (sa) |
3984 { | 3999 { |
3985 Lsa: | 4000 Lsa: |
3986 buf.writeByte('S'); | 4001 buf.writeByte('S'); |
3987 Declaration *d = sa->isDeclaration(); | 4002 Declaration *d = sa->isDeclaration(); |
3988 if (d && !d->type->deco) | 4003 if (d && (!d->type || !d->type->deco)) |
3989 error("forward reference of %s", d->toChars()); | 4004 error("forward reference of %s", d->toChars()); |
3990 else | 4005 else |
3991 { | 4006 { |
3992 char *p = sa->mangle(); | 4007 char *p = sa->mangle(); |
3993 buf.printf("%zu%s", strlen(p), p); | 4008 buf.printf("%zu%s", strlen(p), p); |
4087 } | 4102 } |
4088 } | 4103 } |
4089 | 4104 |
4090 #if IN_DMD | 4105 #if IN_DMD |
4091 | 4106 |
4107 void TemplateInstance::printInstantiationTrace() | |
4108 { | |
4109 if (global.gag) | |
4110 return; | |
4111 } | |
4112 | |
4092 void TemplateInstance::toObjFile(int multiobj) | 4113 void TemplateInstance::toObjFile(int multiobj) |
4093 { | 4114 { |
4094 #if LOG | 4115 #if LOG |
4095 printf("TemplateInstance::toObjFile('%s', this = %p)\n", toChars(), this); | 4116 printf("TemplateInstance::toObjFile('%s', this = %p)\n", toChars(), this); |
4096 #endif | 4117 #endif |
4198 toCBuffer(&buf, &hgs); | 4219 toCBuffer(&buf, &hgs); |
4199 s = buf.toChars(); | 4220 s = buf.toChars(); |
4200 buf.data = NULL; | 4221 buf.data = NULL; |
4201 return s; | 4222 return s; |
4202 } | 4223 } |
4224 | |
4225 #if IN_LLVM | |
4203 | 4226 |
4204 void TemplateInstance::printInstantiationTrace() | 4227 void TemplateInstance::printInstantiationTrace() |
4205 { | 4228 { |
4206 if(global.gag) | 4229 if(global.gag) |
4207 return; | 4230 return; |
4235 {} | 4258 {} |
4236 for(; i < n_instantiations; ++i, cur = cur->tinst) | 4259 for(; i < n_instantiations; ++i, cur = cur->tinst) |
4237 fprintf(stdmsg," instantiatied in %s: %s\n", cur->loc.toChars(), cur->toChars()); | 4260 fprintf(stdmsg," instantiatied in %s: %s\n", cur->loc.toChars(), cur->toChars()); |
4238 } | 4261 } |
4239 } | 4262 } |
4263 | |
4264 #endif | |
4240 | 4265 |
4241 /* ======================== TemplateMixin ================================ */ | 4266 /* ======================== TemplateMixin ================================ */ |
4242 | 4267 |
4243 TemplateMixin::TemplateMixin(Loc loc, Identifier *ident, Type *tqual, | 4268 TemplateMixin::TemplateMixin(Loc loc, Identifier *ident, Type *tqual, |
4244 Array *idents, Objects *tiargs) | 4269 Array *idents, Objects *tiargs) |
4506 printf("\tdo semantic() on template instance members '%s'\n", toChars()); | 4531 printf("\tdo semantic() on template instance members '%s'\n", toChars()); |
4507 #endif | 4532 #endif |
4508 Scope *sc2; | 4533 Scope *sc2; |
4509 sc2 = scope->push(this); | 4534 sc2 = scope->push(this); |
4510 sc2->offset = sc->offset; | 4535 sc2->offset = sc->offset; |
4536 | |
4537 static int nest; | |
4538 //printf("%d\n", nest); | |
4539 if (++nest > 500) | |
4540 { | |
4541 global.gag = 0; // ensure error message gets printed | |
4542 error("recursive expansion"); | |
4543 fatal(); | |
4544 } | |
4545 | |
4511 for (int i = 0; i < members->dim; i++) | 4546 for (int i = 0; i < members->dim; i++) |
4512 { | 4547 { |
4513 Dsymbol *s = (Dsymbol *)members->data[i]; | 4548 Dsymbol *s = (Dsymbol *)members->data[i]; |
4514 s->semantic(sc2); | 4549 s->semantic(sc2); |
4515 } | 4550 } |
4551 | |
4552 nest--; | |
4553 | |
4516 sc->offset = sc2->offset; | 4554 sc->offset = sc2->offset; |
4517 | 4555 |
4518 /* The problem is when to parse the initializer for a variable. | 4556 /* The problem is when to parse the initializer for a variable. |
4519 * Perhaps VarDeclaration::semantic() should do it like it does | 4557 * Perhaps VarDeclaration::semantic() should do it like it does |
4520 * for initializers inside a function. | 4558 * for initializers inside a function. |