Mercurial > projects > ldc
diff 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 |
line wrap: on
line diff
--- a/dmd/expression.c Sat May 16 18:37:16 2009 +0200 +++ b/dmd/expression.c Sat May 16 22:21:31 2009 +0200 @@ -99,7 +99,6 @@ precedence[TOKnull] = PREC_primary; precedence[TOKstring] = PREC_primary; precedence[TOKarrayliteral] = PREC_primary; - precedence[TOKtypedot] = PREC_primary; precedence[TOKtypeid] = PREC_primary; precedence[TOKis] = PREC_primary; precedence[TOKassert] = PREC_primary; @@ -1558,6 +1557,22 @@ buf->printf("%jd", value); } +/******************************** ErrorExp **************************/ + +/* Use this expression for error recovery. + * It should behave as a 'sink' to prevent further cascaded error messages. + */ + +ErrorExp::ErrorExp() + : IntegerExp(0, 0, Type::terror) +{ +} + +void ErrorExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) +{ + buf->writestring("__error"); +} + /******************************** RealExp **************************/ RealExp::RealExp(Loc loc, real_t value, Type *type) @@ -1940,7 +1955,7 @@ { Type *t = withsym->withstate->wthis->type; if (t->ty == Tpointer) t = ((TypePointer *)t)->next; - e = new TypeDotIdExp(loc, t, ident); + e = typeDotIdExp(loc, t, ident); } } else @@ -3288,38 +3303,11 @@ * cast(foo).size */ -TypeDotIdExp::TypeDotIdExp(Loc loc, Type *type, Identifier *ident) - : Expression(loc, TOKtypedot, sizeof(TypeDotIdExp)) -{ - this->type = type; - this->ident = ident; -} - -Expression *TypeDotIdExp::syntaxCopy() -{ - TypeDotIdExp *te = new TypeDotIdExp(loc, type->syntaxCopy(), ident); - return te; -} - -Expression *TypeDotIdExp::semantic(Scope *sc) -{ Expression *e; - -#if LOGSEMANTIC - printf("TypeDotIdExp::semantic()\n"); -#endif - e = new DotIdExp(loc, new TypeExp(loc, type), ident); - e = e->semantic(sc); - return e; -} - -void TypeDotIdExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) -{ - buf->writeByte('('); - type->toCBuffer(buf, NULL, hgs); - buf->writeByte(')'); - buf->writeByte('.'); - buf->writestring(ident->toChars()); -} +Expression *typeDotIdExp(Loc loc, Type *type, Identifier *ident) +{ + return new DotIdExp(loc, new TypeExp(loc, type), ident); +} + /************************************************************/ @@ -5257,12 +5245,12 @@ { if (e1->op == TOKthis) { - e = new TypeDotIdExp(loc, cd->type, ident); + e = typeDotIdExp(loc, cd->type, ident); return e->semantic(sc); } else if (cd->baseClass && e1->op == TOKsuper) { - e = new TypeDotIdExp(loc, cd->baseClass->type, ident); + e = typeDotIdExp(loc, cd->baseClass->type, ident); return e->semantic(sc); } } @@ -5273,7 +5261,7 @@ { if (e1->op == TOKthis) { - e = new TypeDotIdExp(loc, sd->type, ident); + e = typeDotIdExp(loc, sd->type, ident); return e->semantic(sc); } } @@ -5321,6 +5309,18 @@ return e; } + if (e1->op == TOKdottd) + { + error("template %s does not have property %s", e1->toChars(), ident->toChars()); + return e1; + } + + if (!e1->type) + { + error("expression %s does not have property %s", e1->toChars(), ident->toChars()); + return e1; + } + if (eright->op == TOKimport) // also used for template alias's { ScopeExp *ie = (ScopeExp *)eright; @@ -5607,7 +5607,8 @@ if (!var->isFuncDeclaration()) // for functions, do checks after overload resolution { - AggregateDeclaration *ad = var->toParent()->isAggregateDeclaration(); + Dsymbol *vparent = var->toParent(); + AggregateDeclaration *ad = vparent ? vparent->isAggregateDeclaration() : NULL; e1 = getRightThis(loc, sc, ad, e1, var); if (!sc->noaccesscheck) accessCheck(loc, sc, e1, var); @@ -5802,10 +5803,11 @@ id = ti->name; s2 = s->search(loc, id, 0); if (!s2) - { if (s->ident) + { + if (!s->ident) + error("template identifier %s is not a member of undefined %s", id->toChars(), s->kind()); + else error("template identifier %s is not a member of %s %s", id->toChars(), s->kind(), s->ident->toChars()); - else - error("template identifier %s is not a member of %s", id->toChars(), s->kind()); goto Lerr; } s = s2; @@ -7264,7 +7266,7 @@ else { error("string slice [%ju .. %ju] is out of bounds", i1, i2); - e = e1; + e = new IntegerExp(0); } return e; } @@ -9275,8 +9277,15 @@ e = op_overload(sc); if (e) { - e = new CmpExp(op, loc, e, new IntegerExp(loc, 0, Type::tint32)); - e = e->semantic(sc); + if (!e->type->isscalar() && e->type->equals(e1->type)) + { + error("recursive opCmp expansion"); + e = new ErrorExp(); + } + else + { e = new CmpExp(op, loc, e, new IntegerExp(loc, 0, Type::tint32)); + e = e->semantic(sc); + } return e; }