Mercurial > projects > ldc
comparison dmd/mtype.c @ 336:aaade6ded589 trunk
[svn r357] Merged DMD 1.033
author | lindquist |
---|---|
date | Sat, 12 Jul 2008 19:38:31 +0200 |
parents | 2b72433d5c8c |
children | 3c4460b988bd |
comparison
equal
deleted
inserted
replaced
335:17b844102023 | 336:aaade6ded589 |
---|---|
113 { | 113 { |
114 this->ty = ty; | 114 this->ty = ty; |
115 this->mod = 0; | 115 this->mod = 0; |
116 this->next = next; | 116 this->next = next; |
117 this->deco = NULL; | 117 this->deco = NULL; |
118 #if V2 | 118 #if DMDV2 |
119 this->cto = NULL; | 119 this->cto = NULL; |
120 this->ito = NULL; | 120 this->ito = NULL; |
121 #endif | 121 #endif |
122 this->pto = NULL; | 122 this->pto = NULL; |
123 this->rto = NULL; | 123 this->rto = NULL; |
2223 if (next->isauto()) | 2223 if (next->isauto()) |
2224 error(loc, "cannot have array of auto %s", next->toChars()); | 2224 error(loc, "cannot have array of auto %s", next->toChars()); |
2225 | 2225 |
2226 return merge(); | 2226 return merge(); |
2227 } | 2227 } |
2228 | |
2229 void TypeAArray::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) | |
2230 { | |
2231 //printf("TypeAArray::resolve() %s\n", toChars()); | |
2232 | |
2233 // Deal with the case where we thought the index was a type, but | |
2234 // in reality it was an expression. | |
2235 if (index->ty == Tident || index->ty == Tinstance || index->ty == Tsarray) | |
2236 { | |
2237 Expression *e; | |
2238 Type *t; | |
2239 Dsymbol *s; | |
2240 | |
2241 index->resolve(loc, sc, &e, &t, &s); | |
2242 if (e) | |
2243 { // It was an expression - | |
2244 // Rewrite as a static array | |
2245 | |
2246 TypeSArray *tsa = new TypeSArray(next, e); | |
2247 return tsa->resolve(loc, sc, pe, pt, ps); | |
2248 } | |
2249 else if (t) | |
2250 index = t; | |
2251 else | |
2252 index->error(loc, "index is not a type or an expression"); | |
2253 } | |
2254 Type::resolve(loc, sc, pe, pt, ps); | |
2255 } | |
2256 | |
2228 | 2257 |
2229 Expression *TypeAArray::dotExp(Scope *sc, Expression *e, Identifier *ident) | 2258 Expression *TypeAArray::dotExp(Scope *sc, Expression *e, Identifier *ident) |
2230 { | 2259 { |
2231 #if LOGDOTEXP | 2260 #if LOGDOTEXP |
2232 printf("TypeAArray::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); | 2261 printf("TypeAArray::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); |
3149 *pt = NULL; | 3178 *pt = NULL; |
3150 *ps = NULL; | 3179 *ps = NULL; |
3151 if (s) | 3180 if (s) |
3152 { | 3181 { |
3153 //printf("\t1: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind()); | 3182 //printf("\t1: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind()); |
3183 s->checkDeprecated(loc, sc); // check for deprecated aliases | |
3154 s = s->toAlias(); | 3184 s = s->toAlias(); |
3155 //printf("\t2: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind()); | 3185 //printf("\t2: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind()); |
3156 for (i = 0; i < idents.dim; i++) | 3186 for (i = 0; i < idents.dim; i++) |
3157 { Dsymbol *sm; | 3187 { Dsymbol *sm; |
3158 | 3188 |
3546 | 3576 |
3547 Dsymbol *TypeTypeof::toDsymbol(Scope *sc) | 3577 Dsymbol *TypeTypeof::toDsymbol(Scope *sc) |
3548 { | 3578 { |
3549 Type *t; | 3579 Type *t; |
3550 | 3580 |
3551 t = semantic(0, sc); | 3581 t = semantic(loc, sc); |
3552 if (t == this) | 3582 if (t == this) |
3553 return NULL; | 3583 return NULL; |
3554 return t->toDsymbol(sc); | 3584 return t->toDsymbol(sc); |
3555 } | 3585 } |
3556 | 3586 |
3622 #endif | 3652 #endif |
3623 { | 3653 { |
3624 sc->intypeof++; | 3654 sc->intypeof++; |
3625 exp = exp->semantic(sc); | 3655 exp = exp->semantic(sc); |
3626 sc->intypeof--; | 3656 sc->intypeof--; |
3657 if (exp->op == TOKtype) | |
3658 { | |
3659 error(loc, "argument %s to typeof is not an expression", exp->toChars()); | |
3660 } | |
3627 t = exp->type; | 3661 t = exp->type; |
3628 if (!t) | 3662 if (!t) |
3629 { | 3663 { |
3630 error(loc, "expression (%s) has no type", exp->toChars()); | 3664 error(loc, "expression (%s) has no type", exp->toChars()); |
3631 goto Lerr; | 3665 goto Lerr; |
4172 | 4206 |
4173 if (ident == Id::tupleof) | 4207 if (ident == Id::tupleof) |
4174 { | 4208 { |
4175 /* Create a TupleExp | 4209 /* Create a TupleExp |
4176 */ | 4210 */ |
4211 e = e->semantic(sc); // do this before turning on noaccesscheck | |
4177 Expressions *exps = new Expressions; | 4212 Expressions *exps = new Expressions; |
4178 exps->reserve(sym->fields.dim); | 4213 exps->reserve(sym->fields.dim); |
4179 for (size_t i = 0; i < sym->fields.dim; i++) | 4214 for (size_t i = 0; i < sym->fields.dim; i++) |
4180 { VarDeclaration *v = (VarDeclaration *)sym->fields.data[i]; | 4215 { VarDeclaration *v = (VarDeclaration *)sym->fields.data[i]; |
4181 Expression *fe = new DotVarExp(e->loc, e, v); | 4216 Expression *fe = new DotVarExp(e->loc, e, v); |
4182 exps->push(fe); | 4217 exps->push(fe); |
4183 } | 4218 } |
4184 e = new TupleExp(e->loc, exps); | 4219 e = new TupleExp(e->loc, exps); |
4220 sc = sc->push(); | |
4221 sc->noaccesscheck = 1; | |
4185 e = e->semantic(sc); | 4222 e = e->semantic(sc); |
4223 sc->pop(); | |
4186 return e; | 4224 return e; |
4187 } | 4225 } |
4188 | 4226 |
4189 if (e->op == TOKdotexp) | 4227 if (e->op == TOKdotexp) |
4190 { DotExp *de = (DotExp *)e; | 4228 { DotExp *de = (DotExp *)e; |
4204 if (!s) | 4242 if (!s) |
4205 { | 4243 { |
4206 //return getProperty(e->loc, ident); | 4244 //return getProperty(e->loc, ident); |
4207 return Type::dotExp(sc, e, ident); | 4245 return Type::dotExp(sc, e, ident); |
4208 } | 4246 } |
4247 if (!s->isFuncDeclaration()) // because of overloading | |
4248 s->checkDeprecated(e->loc, sc); | |
4209 s = s->toAlias(); | 4249 s = s->toAlias(); |
4210 | 4250 |
4211 v = s->isVarDeclaration(); | 4251 v = s->isVarDeclaration(); |
4212 if (v && v->isConst()) | 4252 if (v && v->isConst()) |
4213 { ExpInitializer *ei = v->getExpInitializer(); | 4253 { ExpInitializer *ei = v->getExpInitializer(); |
4457 | 4497 |
4458 if (ident == Id::tupleof) | 4498 if (ident == Id::tupleof) |
4459 { | 4499 { |
4460 /* Create a TupleExp | 4500 /* Create a TupleExp |
4461 */ | 4501 */ |
4502 e = e->semantic(sc); // do this before turning on noaccesscheck | |
4462 Expressions *exps = new Expressions; | 4503 Expressions *exps = new Expressions; |
4463 exps->reserve(sym->fields.dim); | 4504 exps->reserve(sym->fields.dim); |
4464 for (size_t i = 0; i < sym->fields.dim; i++) | 4505 for (size_t i = 0; i < sym->fields.dim; i++) |
4465 { VarDeclaration *v = (VarDeclaration *)sym->fields.data[i]; | 4506 { VarDeclaration *v = (VarDeclaration *)sym->fields.data[i]; |
4466 Expression *fe = new DotVarExp(e->loc, e, v); | 4507 Expression *fe = new DotVarExp(e->loc, e, v); |
4467 exps->push(fe); | 4508 exps->push(fe); |
4468 } | 4509 } |
4469 e = new TupleExp(e->loc, exps); | 4510 e = new TupleExp(e->loc, exps); |
4511 sc = sc->push(); | |
4512 sc->noaccesscheck = 1; | |
4470 e = e->semantic(sc); | 4513 e = e->semantic(sc); |
4514 sc->pop(); | |
4471 return e; | 4515 return e; |
4472 } | 4516 } |
4473 | 4517 |
4474 s = sym->search(e->loc, ident, 0); | 4518 s = sym->search(e->loc, ident, 0); |
4475 L1: | 4519 L1: |
4538 * The first member of Interface is the .classinfo, | 4582 * The first member of Interface is the .classinfo, |
4539 * so add an extra pointer indirection. | 4583 * so add an extra pointer indirection. |
4540 */ | 4584 */ |
4541 e = new PtrExp(e->loc, e); | 4585 e = new PtrExp(e->loc, e); |
4542 e->type = ct->next->next->next; | 4586 e->type = ct->next->next->next; |
4587 } | |
4543 } | 4588 } |
4544 | 4589 |
4545 #else | 4590 #else |
4546 | 4591 |
4547 e = new PtrExp(e->loc, e); | 4592 e = new PtrExp(e->loc, e); |
4563 e->type = e->type->pointerTo(); | 4608 e->type = e->type->pointerTo(); |
4564 e = new PtrExp(e->loc, e); | 4609 e = new PtrExp(e->loc, e); |
4565 e->type = t->pointerTo(); | 4610 e->type = t->pointerTo(); |
4566 } | 4611 } |
4567 e = new PtrExp(e->loc, e, t); | 4612 e = new PtrExp(e->loc, e, t); |
4568 | 4613 } |
4569 #endif | 4614 |
4570 } | 4615 #endif // !LLVMDC |
4616 | |
4617 return e; | |
4618 } | |
4619 | |
4620 if (ident == Id::__vptr) | |
4621 { /* The pointer to the vtbl[] | |
4622 * *cast(void***)e | |
4623 */ | |
4624 e = e->castTo(sc, tvoidptr->pointerTo()->pointerTo()); | |
4625 e = new PtrExp(e->loc, e); | |
4626 e = e->semantic(sc); | |
4627 return e; | |
4628 } | |
4629 | |
4630 if (ident == Id::__monitor) | |
4631 { /* The handle to the monitor (call it a void*) | |
4632 * *(cast(void**)e + 1) | |
4633 */ | |
4634 e = e->castTo(sc, tvoidptr->pointerTo()); | |
4635 e = new AddExp(e->loc, e, new IntegerExp(1)); | |
4636 e = new PtrExp(e->loc, e); | |
4637 e = e->semantic(sc); | |
4571 return e; | 4638 return e; |
4572 } | 4639 } |
4573 | 4640 |
4574 if (ident == Id::typeinfo) | 4641 if (ident == Id::typeinfo) |
4575 { | 4642 { |
4585 { | 4652 { |
4586 //return getProperty(e->loc, ident); | 4653 //return getProperty(e->loc, ident); |
4587 return Type::dotExp(sc, e, ident); | 4654 return Type::dotExp(sc, e, ident); |
4588 } | 4655 } |
4589 } | 4656 } |
4657 if (!s->isFuncDeclaration()) // because of overloading | |
4658 s->checkDeprecated(e->loc, sc); | |
4590 s = s->toAlias(); | 4659 s = s->toAlias(); |
4591 v = s->isVarDeclaration(); | 4660 v = s->isVarDeclaration(); |
4592 if (v && v->isConst()) | 4661 if (v && v->isConst()) |
4593 { ExpInitializer *ei = v->getExpInitializer(); | 4662 { ExpInitializer *ei = v->getExpInitializer(); |
4594 | 4663 |