comparison dmd/expression.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 78038e540342
children 229e02867307
comparison
equal deleted inserted replaced
1366:81121ac19f61 1367:8026319762be
97 precedence[TOKint64] = PREC_primary; 97 precedence[TOKint64] = PREC_primary;
98 precedence[TOKfloat64] = PREC_primary; 98 precedence[TOKfloat64] = PREC_primary;
99 precedence[TOKnull] = PREC_primary; 99 precedence[TOKnull] = PREC_primary;
100 precedence[TOKstring] = PREC_primary; 100 precedence[TOKstring] = PREC_primary;
101 precedence[TOKarrayliteral] = PREC_primary; 101 precedence[TOKarrayliteral] = PREC_primary;
102 precedence[TOKtypedot] = PREC_primary;
103 precedence[TOKtypeid] = PREC_primary; 102 precedence[TOKtypeid] = PREC_primary;
104 precedence[TOKis] = PREC_primary; 103 precedence[TOKis] = PREC_primary;
105 precedence[TOKassert] = PREC_primary; 104 precedence[TOKassert] = PREC_primary;
106 precedence[TOKfunction] = PREC_primary; 105 precedence[TOKfunction] = PREC_primary;
107 precedence[TOKvar] = PREC_primary; 106 precedence[TOKvar] = PREC_primary;
1556 buf->printf("N%jd", -value); 1555 buf->printf("N%jd", -value);
1557 else 1556 else
1558 buf->printf("%jd", value); 1557 buf->printf("%jd", value);
1559 } 1558 }
1560 1559
1560 /******************************** ErrorExp **************************/
1561
1562 /* Use this expression for error recovery.
1563 * It should behave as a 'sink' to prevent further cascaded error messages.
1564 */
1565
1566 ErrorExp::ErrorExp()
1567 : IntegerExp(0, 0, Type::terror)
1568 {
1569 }
1570
1571 void ErrorExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
1572 {
1573 buf->writestring("__error");
1574 }
1575
1561 /******************************** RealExp **************************/ 1576 /******************************** RealExp **************************/
1562 1577
1563 RealExp::RealExp(Loc loc, real_t value, Type *type) 1578 RealExp::RealExp(Loc loc, real_t value, Type *type)
1564 : Expression(loc, TOKfloat64, sizeof(RealExp)) 1579 : Expression(loc, TOKfloat64, sizeof(RealExp))
1565 { 1580 {
1938 } 1953 }
1939 else 1954 else
1940 { Type *t = withsym->withstate->wthis->type; 1955 { Type *t = withsym->withstate->wthis->type;
1941 if (t->ty == Tpointer) 1956 if (t->ty == Tpointer)
1942 t = ((TypePointer *)t)->next; 1957 t = ((TypePointer *)t)->next;
1943 e = new TypeDotIdExp(loc, t, ident); 1958 e = typeDotIdExp(loc, t, ident);
1944 } 1959 }
1945 } 1960 }
1946 else 1961 else
1947 { 1962 {
1948 if (!s->parent && scopesym->isArrayScopeSymbol()) 1963 if (!s->parent && scopesym->isArrayScopeSymbol())
3286 * foo.size 3301 * foo.size
3287 * (foo).size 3302 * (foo).size
3288 * cast(foo).size 3303 * cast(foo).size
3289 */ 3304 */
3290 3305
3291 TypeDotIdExp::TypeDotIdExp(Loc loc, Type *type, Identifier *ident) 3306 Expression *typeDotIdExp(Loc loc, Type *type, Identifier *ident)
3292 : Expression(loc, TOKtypedot, sizeof(TypeDotIdExp)) 3307 {
3293 { 3308 return new DotIdExp(loc, new TypeExp(loc, type), ident);
3294 this->type = type; 3309 }
3295 this->ident = ident; 3310
3296 }
3297
3298 Expression *TypeDotIdExp::syntaxCopy()
3299 {
3300 TypeDotIdExp *te = new TypeDotIdExp(loc, type->syntaxCopy(), ident);
3301 return te;
3302 }
3303
3304 Expression *TypeDotIdExp::semantic(Scope *sc)
3305 { Expression *e;
3306
3307 #if LOGSEMANTIC
3308 printf("TypeDotIdExp::semantic()\n");
3309 #endif
3310 e = new DotIdExp(loc, new TypeExp(loc, type), ident);
3311 e = e->semantic(sc);
3312 return e;
3313 }
3314
3315 void TypeDotIdExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
3316 {
3317 buf->writeByte('(');
3318 type->toCBuffer(buf, NULL, hgs);
3319 buf->writeByte(')');
3320 buf->writeByte('.');
3321 buf->writestring(ident->toChars());
3322 }
3323 3311
3324 /************************************************************/ 3312 /************************************************************/
3325 3313
3326 // Mainly just a placeholder 3314 // Mainly just a placeholder
3327 3315
5255 cd = ad->isClassDeclaration(); 5243 cd = ad->isClassDeclaration();
5256 if (cd) 5244 if (cd)
5257 { 5245 {
5258 if (e1->op == TOKthis) 5246 if (e1->op == TOKthis)
5259 { 5247 {
5260 e = new TypeDotIdExp(loc, cd->type, ident); 5248 e = typeDotIdExp(loc, cd->type, ident);
5261 return e->semantic(sc); 5249 return e->semantic(sc);
5262 } 5250 }
5263 else if (cd->baseClass && e1->op == TOKsuper) 5251 else if (cd->baseClass && e1->op == TOKsuper)
5264 { 5252 {
5265 e = new TypeDotIdExp(loc, cd->baseClass->type, ident); 5253 e = typeDotIdExp(loc, cd->baseClass->type, ident);
5266 return e->semantic(sc); 5254 return e->semantic(sc);
5267 } 5255 }
5268 } 5256 }
5269 else 5257 else
5270 { 5258 {
5271 sd = ad->isStructDeclaration(); 5259 sd = ad->isStructDeclaration();
5272 if (sd) 5260 if (sd)
5273 { 5261 {
5274 if (e1->op == TOKthis) 5262 if (e1->op == TOKthis)
5275 { 5263 {
5276 e = new TypeDotIdExp(loc, sd->type, ident); 5264 e = typeDotIdExp(loc, sd->type, ident);
5277 return e->semantic(sc); 5265 return e->semantic(sc);
5278 } 5266 }
5279 } 5267 }
5280 } 5268 }
5281 } 5269 }
5317 if (e1->op == TOKtuple && ident == Id::length) 5305 if (e1->op == TOKtuple && ident == Id::length)
5318 { 5306 {
5319 TupleExp *te = (TupleExp *)e1; 5307 TupleExp *te = (TupleExp *)e1;
5320 e = new IntegerExp(loc, te->exps->dim, Type::tsize_t); 5308 e = new IntegerExp(loc, te->exps->dim, Type::tsize_t);
5321 return e; 5309 return e;
5310 }
5311
5312 if (e1->op == TOKdottd)
5313 {
5314 error("template %s does not have property %s", e1->toChars(), ident->toChars());
5315 return e1;
5316 }
5317
5318 if (!e1->type)
5319 {
5320 error("expression %s does not have property %s", e1->toChars(), ident->toChars());
5321 return e1;
5322 } 5322 }
5323 5323
5324 if (eright->op == TOKimport) // also used for template alias's 5324 if (eright->op == TOKimport) // also used for template alias's
5325 { 5325 {
5326 ScopeExp *ie = (ScopeExp *)eright; 5326 ScopeExp *ie = (ScopeExp *)eright;
5605 } 5605 }
5606 assert(type); 5606 assert(type);
5607 5607
5608 if (!var->isFuncDeclaration()) // for functions, do checks after overload resolution 5608 if (!var->isFuncDeclaration()) // for functions, do checks after overload resolution
5609 { 5609 {
5610 AggregateDeclaration *ad = var->toParent()->isAggregateDeclaration(); 5610 Dsymbol *vparent = var->toParent();
5611 AggregateDeclaration *ad = vparent ? vparent->isAggregateDeclaration() : NULL;
5611 e1 = getRightThis(loc, sc, ad, e1, var); 5612 e1 = getRightThis(loc, sc, ad, e1, var);
5612 if (!sc->noaccesscheck) 5613 if (!sc->noaccesscheck)
5613 accessCheck(loc, sc, e1, var); 5614 accessCheck(loc, sc, e1, var);
5614 5615
5615 VarDeclaration *v = var->isVarDeclaration(); 5616 VarDeclaration *v = var->isVarDeclaration();
5800 5801
5801 assert(s); 5802 assert(s);
5802 id = ti->name; 5803 id = ti->name;
5803 s2 = s->search(loc, id, 0); 5804 s2 = s->search(loc, id, 0);
5804 if (!s2) 5805 if (!s2)
5805 { if (s->ident) 5806 {
5807 if (!s->ident)
5808 error("template identifier %s is not a member of undefined %s", id->toChars(), s->kind());
5809 else
5806 error("template identifier %s is not a member of %s %s", id->toChars(), s->kind(), s->ident->toChars()); 5810 error("template identifier %s is not a member of %s %s", id->toChars(), s->kind(), s->ident->toChars());
5807 else
5808 error("template identifier %s is not a member of %s", id->toChars(), s->kind());
5809 goto Lerr; 5811 goto Lerr;
5810 } 5812 }
5811 s = s2; 5813 s = s2;
5812 s->semantic(sc); 5814 s->semantic(sc);
5813 s = s->toAlias(); 5815 s = s->toAlias();
7262 e = e->semantic(sc); 7264 e = e->semantic(sc);
7263 } 7265 }
7264 else 7266 else
7265 { 7267 {
7266 error("string slice [%ju .. %ju] is out of bounds", i1, i2); 7268 error("string slice [%ju .. %ju] is out of bounds", i1, i2);
7267 e = e1; 7269 e = new IntegerExp(0);
7268 } 7270 }
7269 return e; 7271 return e;
7270 } 7272 }
7271 7273
7272 if (t->ty == Tarray) 7274 if (t->ty == Tarray)
9273 } 9275 }
9274 9276
9275 e = op_overload(sc); 9277 e = op_overload(sc);
9276 if (e) 9278 if (e)
9277 { 9279 {
9278 e = new CmpExp(op, loc, e, new IntegerExp(loc, 0, Type::tint32)); 9280 if (!e->type->isscalar() && e->type->equals(e1->type))
9279 e = e->semantic(sc); 9281 {
9282 error("recursive opCmp expansion");
9283 e = new ErrorExp();
9284 }
9285 else
9286 { e = new CmpExp(op, loc, e, new IntegerExp(loc, 0, Type::tint32));
9287 e = e->semantic(sc);
9288 }
9280 return e; 9289 return e;
9281 } 9290 }
9282 9291
9283 typeCombine(sc); 9292 typeCombine(sc);
9284 type = Type::tboolean; 9293 type = Type::tboolean;