Mercurial > projects > ldc
comparison dmd/mtype.c @ 1587:def7a1d494fd
Merge DMD 1.051
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Fri, 06 Nov 2009 23:58:01 +0100 |
parents | 05c235309d6f |
children | 207a8a438dea |
comparison
equal
deleted
inserted
replaced
1586:7f728c52e63c | 1587:def7a1d494fd |
---|---|
1512 if (this == to) | 1512 if (this == to) |
1513 return MATCHexact; | 1513 return MATCHexact; |
1514 | 1514 |
1515 if (ty == Tvoid || to->ty == Tvoid) | 1515 if (ty == Tvoid || to->ty == Tvoid) |
1516 return MATCHnomatch; | 1516 return MATCHnomatch; |
1517 if (1 || global.params.Dversion == 1) | 1517 if (to->ty == Tbool) |
1518 { | 1518 return MATCHnomatch; |
1519 if (to->ty == Tbool) | |
1520 return MATCHnomatch; | |
1521 } | |
1522 else | |
1523 { | |
1524 if (ty == Tbool || to->ty == Tbool) | |
1525 return MATCHnomatch; | |
1526 } | |
1527 if (!to->isTypeBasic()) | 1519 if (!to->isTypeBasic()) |
1528 return MATCHnomatch; | 1520 return MATCHnomatch; |
1529 | 1521 |
1530 TypeBasic *tob = (TypeBasic *)to; | 1522 TypeBasic *tob = (TypeBasic *)to; |
1531 if (flags & TFLAGSintegral) | 1523 if (flags & TFLAGSintegral) |
1532 { | 1524 { |
1533 // Disallow implicit conversion of integers to imaginary or complex | 1525 // Disallow implicit conversion of integers to imaginary or complex |
1534 if (tob->flags & (TFLAGSimaginary | TFLAGScomplex)) | 1526 if (tob->flags & (TFLAGSimaginary | TFLAGScomplex)) |
1535 return MATCHnomatch; | 1527 return MATCHnomatch; |
1536 | 1528 |
1529 #if DMDV2 | |
1537 // If converting to integral | 1530 // If converting to integral |
1538 if (0 && global.params.Dversion > 1 && tob->flags & TFLAGSintegral) | 1531 if (0 && global.params.Dversion > 1 && tob->flags & TFLAGSintegral) |
1539 { d_uns64 sz = size(0); | 1532 { d_uns64 sz = size(0); |
1540 d_uns64 tosz = tob->size(0); | 1533 d_uns64 tosz = tob->size(0); |
1541 | 1534 |
1545 return MATCHnomatch; | 1538 return MATCHnomatch; |
1546 | 1539 |
1547 /*if (sz == tosz && (flags ^ tob->flags) & TFLAGSunsigned) | 1540 /*if (sz == tosz && (flags ^ tob->flags) & TFLAGSunsigned) |
1548 return MATCHnomatch;*/ | 1541 return MATCHnomatch;*/ |
1549 } | 1542 } |
1543 #endif | |
1550 } | 1544 } |
1551 else if (flags & TFLAGSfloating) | 1545 else if (flags & TFLAGSfloating) |
1552 { | 1546 { |
1553 // Disallow implicit conversion of floating point to integer | 1547 // Disallow implicit conversion of floating point to integer |
1554 if (tob->flags & TFLAGSintegral) | 1548 if (tob->flags & TFLAGSintegral) |
2345 case Tbit: | 2339 case Tbit: |
2346 case Tbool: | 2340 case Tbool: |
2347 case Tfunction: | 2341 case Tfunction: |
2348 case Tvoid: | 2342 case Tvoid: |
2349 case Tnone: | 2343 case Tnone: |
2344 case Ttuple: | |
2350 error(loc, "can't have associative array key of %s", key->toChars()); | 2345 error(loc, "can't have associative array key of %s", key->toChars()); |
2351 break; | 2346 break; |
2352 } | 2347 } |
2353 next = next->semantic(loc,sc); | 2348 next = next->semantic(loc,sc); |
2354 switch (next->toBasetype()->ty) | 2349 switch (next->toBasetype()->ty) |
2555 return t; | 2550 return t; |
2556 } | 2551 } |
2557 | 2552 |
2558 Type *TypePointer::semantic(Loc loc, Scope *sc) | 2553 Type *TypePointer::semantic(Loc loc, Scope *sc) |
2559 { | 2554 { |
2555 if (deco) | |
2556 return this; | |
2557 | |
2560 //printf("TypePointer::semantic()\n"); | 2558 //printf("TypePointer::semantic()\n"); |
2561 Type *n = next->semantic(loc, sc); | 2559 Type *n = next->semantic(loc, sc); |
2562 switch (n->toBasetype()->ty) | 2560 switch (n->toBasetype()->ty) |
2563 { | 2561 { |
2564 case Ttuple: | 2562 case Ttuple: |
2790 goto Lnotcovariant; | 2788 goto Lnotcovariant; |
2791 | 2789 |
2792 Type *t1n = t1->next; | 2790 Type *t1n = t1->next; |
2793 Type *t2n = t2->next; | 2791 Type *t2n = t2->next; |
2794 | 2792 |
2793 if (!t1n || !t2n) // happens with return type inference | |
2794 goto Lnotcovariant; | |
2795 | |
2795 if (t1n->equals(t2n)) | 2796 if (t1n->equals(t2n)) |
2796 goto Lcovariant; | 2797 goto Lcovariant; |
2797 if (t1n->ty != Tclass || t2n->ty != Tclass) | 2798 if (t1n->ty != Tclass || t2n->ty != Tclass) |
2798 goto Lnotcovariant; | 2799 goto Lnotcovariant; |
2799 | 2800 |
2934 if (hgs->ddoc != 1) | 2935 if (hgs->ddoc != 1) |
2935 { | 2936 { |
2936 switch (linkage) | 2937 switch (linkage) |
2937 { | 2938 { |
2938 case LINKd: p = NULL; break; | 2939 case LINKd: p = NULL; break; |
2939 case LINKc: p = "C "; break; | 2940 case LINKc: p = " C"; break; |
2940 case LINKwindows: p = "Windows "; break; | 2941 case LINKwindows: p = " Windows"; break; |
2941 case LINKpascal: p = "Pascal "; break; | 2942 case LINKpascal: p = " Pascal"; break; |
2942 case LINKcpp: p = "C++ "; break; | 2943 case LINKcpp: p = " C++"; break; |
2943 | 2944 |
2944 // LDC | 2945 // LDC |
2945 case LINKintrinsic: p = "Intrinsic"; break; | 2946 case LINKintrinsic: p = "Intrinsic"; break; |
2946 | 2947 |
2947 default: | 2948 default: |
2976 tf->parameters->data[i] = (void *)cpy; | 2977 tf->parameters->data[i] = (void *)cpy; |
2977 } | 2978 } |
2978 } | 2979 } |
2979 | 2980 |
2980 tf->linkage = sc->linkage; | 2981 tf->linkage = sc->linkage; |
2981 if (!tf->next) | 2982 if (tf->next) |
2982 { | 2983 { |
2983 assert(global.errors); | 2984 tf->next = tf->next->semantic(loc,sc); |
2984 tf->next = tvoid; | 2985 if (tf->next->toBasetype()->ty == Tsarray) |
2985 } | 2986 { error(loc, "functions cannot return static array %s", tf->next->toChars()); |
2986 tf->next = tf->next->semantic(loc,sc); | 2987 tf->next = Type::terror; |
2987 if (tf->next->toBasetype()->ty == Tsarray) | 2988 } |
2988 { error(loc, "functions cannot return static array %s", tf->next->toChars()); | 2989 if (tf->next->toBasetype()->ty == Tfunction) |
2989 tf->next = Type::terror; | 2990 { error(loc, "functions cannot return a function"); |
2990 } | 2991 tf->next = Type::terror; |
2991 if (tf->next->toBasetype()->ty == Tfunction) | 2992 } |
2992 { error(loc, "functions cannot return a function"); | 2993 if (tf->next->toBasetype()->ty == Ttuple) |
2993 tf->next = Type::terror; | 2994 { error(loc, "functions cannot return a tuple"); |
2994 } | 2995 tf->next = Type::terror; |
2995 if (tf->next->toBasetype()->ty == Ttuple) | 2996 } |
2996 { error(loc, "functions cannot return a tuple"); | 2997 if (tf->next->isscope() && !(sc->flags & SCOPEctor)) |
2997 tf->next = Type::terror; | 2998 error(loc, "functions cannot return scope %s", tf->next->toChars()); |
2998 } | 2999 } |
2999 if (tf->next->isscope() && !(sc->flags & SCOPEctor)) | |
3000 error(loc, "functions cannot return scope %s", tf->next->toChars()); | |
3001 | 3000 |
3002 if (tf->parameters) | 3001 if (tf->parameters) |
3003 { size_t dim = Argument::dim(tf->parameters); | 3002 { |
3004 | 3003 /* Create a scope for evaluating the default arguments for the parameters |
3004 */ | |
3005 Scope *argsc = sc->push(); | |
3006 argsc->stc = 0; // don't inherit storage class | |
3007 argsc->protection = PROTpublic; | |
3008 | |
3009 size_t dim = Argument::dim(tf->parameters); | |
3005 for (size_t i = 0; i < dim; i++) | 3010 for (size_t i = 0; i < dim; i++) |
3006 { Argument *arg = Argument::getNth(tf->parameters, i); | 3011 { Argument *arg = Argument::getNth(tf->parameters, i); |
3007 Type *t; | |
3008 | 3012 |
3009 tf->inuse++; | 3013 tf->inuse++; |
3010 arg->type = arg->type->semantic(loc,sc); | 3014 arg->type = arg->type->semantic(loc, argsc); |
3011 if (tf->inuse == 1) tf->inuse--; | 3015 if (tf->inuse == 1) tf->inuse--; |
3012 | 3016 |
3013 // each function needs its own copy of a tuple arg, since | 3017 // each function needs its own copy of a tuple arg, since |
3014 // they mustn't share arg flags like inreg, ... | 3018 // they mustn't share arg flags like inreg, ... |
3015 if (arg->type->ty == Ttuple) { | 3019 if (arg->type->ty == Ttuple) { |
3017 tf->inuse++; | 3021 tf->inuse++; |
3018 arg->type = arg->type->semantic(loc,sc); | 3022 arg->type = arg->type->semantic(loc,sc); |
3019 if (tf->inuse == 1) tf->inuse--; | 3023 if (tf->inuse == 1) tf->inuse--; |
3020 } | 3024 } |
3021 | 3025 |
3022 t = arg->type->toBasetype(); | 3026 Type *t = arg->type->toBasetype(); |
3023 | 3027 |
3024 if (arg->storageClass & (STCout | STCref | STClazy)) | 3028 if (arg->storageClass & (STCout | STCref | STClazy)) |
3025 { | 3029 { |
3026 if (t->ty == Tsarray) | 3030 if (t->ty == Tsarray) |
3027 error(loc, "cannot have out or ref parameter of type %s", t->toChars()); | 3031 error(loc, "cannot have out or ref parameter of type %s", t->toChars()); |
3029 if (!(arg->storageClass & STClazy) && t->ty == Tvoid) | 3033 if (!(arg->storageClass & STClazy) && t->ty == Tvoid) |
3030 error(loc, "cannot have parameter of type %s", arg->type->toChars()); | 3034 error(loc, "cannot have parameter of type %s", arg->type->toChars()); |
3031 | 3035 |
3032 if (arg->defaultArg) | 3036 if (arg->defaultArg) |
3033 { | 3037 { |
3034 arg->defaultArg = arg->defaultArg->semantic(sc); | 3038 arg->defaultArg = arg->defaultArg->semantic(argsc); |
3035 arg->defaultArg = resolveProperties(sc, arg->defaultArg); | 3039 arg->defaultArg = resolveProperties(argsc, arg->defaultArg); |
3036 arg->defaultArg = arg->defaultArg->implicitCastTo(sc, arg->type); | 3040 arg->defaultArg = arg->defaultArg->implicitCastTo(argsc, arg->type); |
3037 } | 3041 } |
3038 | 3042 |
3039 /* If arg turns out to be a tuple, the number of parameters may | 3043 /* If arg turns out to be a tuple, the number of parameters may |
3040 * change. | 3044 * change. |
3041 */ | 3045 */ |
3042 if (t->ty == Ttuple) | 3046 if (t->ty == Ttuple) |
3043 { dim = Argument::dim(tf->parameters); | 3047 { dim = Argument::dim(tf->parameters); |
3044 i--; | 3048 i--; |
3045 } | 3049 } |
3046 } | 3050 } |
3047 } | 3051 argsc->pop(); |
3048 tf->deco = tf->merge()->deco; | 3052 } |
3053 if (tf->next) | |
3054 tf->deco = tf->merge()->deco; | |
3049 | 3055 |
3050 if (tf->inuse) | 3056 if (tf->inuse) |
3051 { error(loc, "recursive type"); | 3057 { error(loc, "recursive type"); |
3052 tf->inuse = 0; | 3058 tf->inuse = 0; |
3053 return terror; | 3059 return terror; |
3417 t = e->type; | 3423 t = e->type; |
3418 if (!t) | 3424 if (!t) |
3419 goto Lerror; | 3425 goto Lerror; |
3420 goto L3; | 3426 goto L3; |
3421 } | 3427 } |
3428 else if (v && id == Id::stringof) | |
3429 { | |
3430 e = new DsymbolExp(loc, s); | |
3431 do | |
3432 { | |
3433 id = (Identifier *)idents.data[i]; | |
3434 e = new DotIdExp(loc, e, id); | |
3435 } while (++i < idents.dim); | |
3436 e = e->semantic(sc); | |
3437 *pe = e; | |
3438 return; | |
3439 } | |
3440 | |
3422 t = s->getType(); | 3441 t = s->getType(); |
3423 if (!t && s->isDeclaration()) | 3442 if (!t && s->isDeclaration()) |
3424 t = s->isDeclaration()->type; | 3443 t = s->isDeclaration()->type; |
3425 if (t) | 3444 if (t) |
3426 { | 3445 { |
3513 | 3532 |
3514 if (t != this) | 3533 if (t != this) |
3515 { | 3534 { |
3516 if (t->reliesOnTident()) | 3535 if (t->reliesOnTident()) |
3517 { | 3536 { |
3518 Scope *scx; | 3537 if (s->scope) |
3519 | 3538 t = t->semantic(loc, s->scope); |
3520 for (scx = sc; 1; scx = scx->enclosing) | 3539 else |
3521 { | 3540 { |
3522 if (!scx) | 3541 /* Attempt to find correct scope in which to evaluate t. |
3523 { error(loc, "forward reference to '%s'", t->toChars()); | 3542 * Not sure if this is right or not, or if we should just |
3524 return; | 3543 * give forward reference error if s->scope is not set. |
3544 */ | |
3545 for (Scope *scx = sc; 1; scx = scx->enclosing) | |
3546 { | |
3547 if (!scx) | |
3548 { error(loc, "forward reference to '%s'", t->toChars()); | |
3549 return; | |
3550 } | |
3551 if (scx->scopesym == scopesym) | |
3552 { | |
3553 t = t->semantic(loc, scx); | |
3554 break; | |
3555 } | |
3525 } | 3556 } |
3526 if (scx->scopesym == scopesym) | |
3527 break; | |
3528 } | 3557 } |
3529 t = t->semantic(loc, scx); | |
3530 //((TypeIdentifier *)t)->resolve(loc, scx, pe, &t, ps); | |
3531 } | 3558 } |
3532 } | 3559 } |
3533 if (t->ty == Ttuple) | 3560 if (t->ty == Ttuple) |
3534 *pt = t; | 3561 *pt = t; |
3562 else if (t->ty == Ttypeof) | |
3563 *pt = t->semantic(loc, sc); | |
3535 else | 3564 else |
3536 *pt = t->merge(); | 3565 *pt = t->merge(); |
3537 } | 3566 } |
3538 if (!s) | 3567 if (!s) |
3539 { | 3568 { |
3760 resolve(loc, sc, &e, &t, &s); | 3789 resolve(loc, sc, &e, &t, &s); |
3761 | 3790 |
3762 if (!t) | 3791 if (!t) |
3763 { | 3792 { |
3764 #ifdef DEBUG | 3793 #ifdef DEBUG |
3765 printf("2: "); | 3794 if (s) printf("s = %s\n", s->kind()); |
3795 printf("2: e:%p s:%p ", e, s); | |
3766 #endif | 3796 #endif |
3767 error(loc, "%s is used as a type", toChars()); | 3797 error(loc, "%s is used as a type", toChars()); |
3768 t = tvoid; | 3798 t = tvoid; |
3769 } | 3799 } |
3770 return t; | 3800 return t; |
3835 } | 3865 } |
3836 buf->writestring("typeof("); | 3866 buf->writestring("typeof("); |
3837 exp->toCBuffer(buf, hgs); | 3867 exp->toCBuffer(buf, hgs); |
3838 buf->writeByte(')'); | 3868 buf->writeByte(')'); |
3839 toCBuffer2Helper(buf, hgs); | 3869 toCBuffer2Helper(buf, hgs); |
3870 } | |
3871 | |
3872 void TypeTypeof::toDecoBuffer(OutBuffer *buf, bool mangle) | |
3873 { | |
3874 assert(0); | |
3840 } | 3875 } |
3841 | 3876 |
3842 Type *TypeTypeof::semantic(Loc loc, Scope *sc) | 3877 Type *TypeTypeof::semantic(Loc loc, Scope *sc) |
3843 { Expression *e; | 3878 { Expression *e; |
3844 Type *t; | 3879 Type *t; |
3968 return this; | 4003 return this; |
3969 } | 4004 } |
3970 | 4005 |
3971 Type *TypeEnum::semantic(Loc loc, Scope *sc) | 4006 Type *TypeEnum::semantic(Loc loc, Scope *sc) |
3972 { | 4007 { |
3973 sym->semantic(sc); | 4008 //sym->semantic(sc); |
3974 return merge(); | 4009 return merge(); |
3975 } | 4010 } |
3976 | 4011 |
3977 d_uns64 TypeEnum::size(Loc loc) | 4012 d_uns64 TypeEnum::size(Loc loc) |
3978 { | 4013 { |
4560 return e; | 4595 return e; |
4561 } | 4596 } |
4562 | 4597 |
4563 TemplateInstance *ti = s->isTemplateInstance(); | 4598 TemplateInstance *ti = s->isTemplateInstance(); |
4564 if (ti) | 4599 if (ti) |
4565 { if (!ti->semanticdone) | 4600 { if (!ti->semanticRun) |
4566 ti->semantic(sc); | 4601 ti->semantic(sc); |
4567 s = ti->inst->toAlias(); | 4602 s = ti->inst->toAlias(); |
4568 if (!s->isTemplateInstance()) | 4603 if (!s->isTemplateInstance()) |
4569 goto L1; | 4604 goto L1; |
4570 Expression *de = new DotExp(e->loc, e, new ScopeExp(e->loc, ti)); | 4605 Expression *de = new DotExp(e->loc, e, new ScopeExp(e->loc, ti)); |
4693 this->sym = sym; | 4728 this->sym = sym; |
4694 } | 4729 } |
4695 | 4730 |
4696 char *TypeClass::toChars() | 4731 char *TypeClass::toChars() |
4697 { | 4732 { |
4698 return sym->toPrettyChars(); | 4733 return (char *)sym->toPrettyChars(); |
4699 } | 4734 } |
4700 | 4735 |
4701 Type *TypeClass::syntaxCopy() | 4736 Type *TypeClass::syntaxCopy() |
4702 { | 4737 { |
4703 return this; | 4738 return this; |
4704 } | 4739 } |
4705 | 4740 |
4706 Type *TypeClass::semantic(Loc loc, Scope *sc) | 4741 Type *TypeClass::semantic(Loc loc, Scope *sc) |
4707 { | 4742 { |
4708 //printf("TypeClass::semantic(%s)\n", sym->toChars()); | 4743 //printf("TypeClass::semantic(%s)\n", sym->toChars()); |
4709 if (sym->scope) | 4744 if (deco) |
4710 sym->semantic(sym->scope); | 4745 return this; |
4711 return merge(); | 4746 return merge(); |
4712 } | 4747 } |
4713 | 4748 |
4714 d_uns64 TypeClass::size(Loc loc) | 4749 d_uns64 TypeClass::size(Loc loc) |
4715 { | 4750 { |
4973 return e; | 5008 return e; |
4974 } | 5009 } |
4975 | 5010 |
4976 TemplateInstance *ti = s->isTemplateInstance(); | 5011 TemplateInstance *ti = s->isTemplateInstance(); |
4977 if (ti) | 5012 if (ti) |
4978 { if (!ti->semanticdone) | 5013 { if (!ti->semanticRun) |
4979 ti->semantic(sc); | 5014 ti->semantic(sc); |
4980 s = ti->inst->toAlias(); | 5015 s = ti->inst->toAlias(); |
4981 if (!s->isTemplateInstance()) | 5016 if (!s->isTemplateInstance()) |
4982 goto L1; | 5017 goto L1; |
4983 Expression *de = new DotExp(e->loc, e, new ScopeExp(e->loc, ti)); | 5018 Expression *de = new DotExp(e->loc, e, new ScopeExp(e->loc, ti)); |
4992 return new IntegerExp(e->loc, 1, Type::tint32); | 5027 return new IntegerExp(e->loc, 1, Type::tint32); |
4993 } | 5028 } |
4994 | 5029 |
4995 if (e->op == TOKtype) | 5030 if (e->op == TOKtype) |
4996 { | 5031 { |
4997 VarExp *ve; | 5032 /* It's: |
4998 | 5033 * Class.d |
4999 if (d->needThis() && (hasThis(sc) || !d->isFuncDeclaration())) | 5034 */ |
5035 if (d->isTupleDeclaration()) | |
5036 { | |
5037 e = new TupleExp(e->loc, d->isTupleDeclaration()); | |
5038 e = e->semantic(sc); | |
5039 return e; | |
5040 } | |
5041 else if (d->needThis() && (hasThis(sc) || !(sc->intypeof || d->isFuncDeclaration()))) | |
5000 { | 5042 { |
5001 if (sc->func) | 5043 if (sc->func) |
5002 { | 5044 { |
5003 ClassDeclaration *thiscd; | 5045 ClassDeclaration *thiscd; |
5004 thiscd = sc->func->toParent()->isClassDeclaration(); | 5046 thiscd = sc->func->toParent()->isClassDeclaration(); |
5023 | 5065 |
5024 de = new DotVarExp(e->loc, new ThisExp(e->loc), d); | 5066 de = new DotVarExp(e->loc, new ThisExp(e->loc), d); |
5025 e = de->semantic(sc); | 5067 e = de->semantic(sc); |
5026 return e; | 5068 return e; |
5027 } | 5069 } |
5028 else if (d->isTupleDeclaration()) | |
5029 { | |
5030 e = new TupleExp(e->loc, d->isTupleDeclaration()); | |
5031 e = e->semantic(sc); | |
5032 return e; | |
5033 } | |
5034 else | 5070 else |
5035 ve = new VarExp(e->loc, d); | 5071 { |
5036 return ve; | 5072 VarExp *ve = new VarExp(e->loc, d); |
5073 return ve; | |
5074 } | |
5037 } | 5075 } |
5038 | 5076 |
5039 if (d->isDataseg()) | 5077 if (d->isDataseg()) |
5040 { | 5078 { |
5041 // (e, d) | 5079 // (e, d) |