diff -uNr dmd-0.161/dmd/src/dmd/cast.c dmd-0.162/dmd/src/dmd/cast.c --- dmd-0.161/dmd/src/dmd/cast.c 2006-06-18 12:43:58.000000000 +0200 +++ dmd-0.162/dmd/src/dmd/cast.c 2006-06-23 11:12:30.000000000 +0200 @@ -566,6 +566,15 @@ return se; } + if (tb->ty != Tsarray && tb->ty != Tarray && tb->ty != Tpointer) + { se->committed = 1; + goto Lcast; + } + if (se->type->ty != Tsarray && se->type->ty != Tarray && se->type->ty != Tpointer) + { se->committed = 1; + goto Lcast; + } + if (se->committed == 1) { if (se->type->next->size() == tb->next->size()) @@ -574,11 +583,8 @@ } goto Lcast; } + se->committed = 1; - if (tb->ty != Tsarray && tb->ty != Tarray && tb->ty != Tpointer) - goto Lcast; - if (se->type->ty != Tsarray && se->type->ty != Tarray && se->type->ty != Tpointer) - goto Lcast; int tfty; int ttty; diff -uNr dmd-0.161/dmd/src/dmd/declaration.c dmd-0.162/dmd/src/dmd/declaration.c --- dmd-0.161/dmd/src/dmd/declaration.c 2006-06-07 16:58:16.000000000 +0200 +++ dmd-0.162/dmd/src/dmd/declaration.c 2006-06-27 02:05:16.000000000 +0200 @@ -848,7 +848,13 @@ cd; cd = cd->baseClass) { - //if (cd->dtor) +#if 1 // delete this; + Expression *ec; + + ec = new VarExp(loc, this); + e = new DeleteExp(loc, ec); + e->type = Type::tvoid; +#else { FuncDeclaration *fd; Expression *efd; Expression *ec; @@ -866,6 +872,7 @@ e->type = fd->type->next; break; } +#endif } } return e; diff -uNr dmd-0.161/dmd/src/dmd/doc.c dmd-0.162/dmd/src/dmd/doc.c --- dmd-0.161/dmd/src/dmd/doc.c 2006-05-22 16:33:26.000000000 +0200 +++ dmd-0.162/dmd/src/dmd/doc.c 2006-06-29 01:12:32.000000000 +0200 @@ -482,7 +482,7 @@ void TemplateDeclaration::emitComment(Scope *sc) { - //printf("TemplateDeclaration::emitComment() '%s'\n", toChars()); + //printf("TemplateDeclaration::emitComment() '%s', kind = %s\n", toChars(), kind()); if (prot() == PROTprivate) return; if (!comment) @@ -511,7 +511,7 @@ buf->writestring(ddoc_decl_s); o = buf->offset; ss->toDocBuffer(buf); - highlightCode(sc, this, buf, o); + //highlightCode(sc, this, buf, o); sc->lastoffset = buf->offset; buf->writestring(ddoc_decl_e); @@ -686,6 +686,7 @@ void ClassDeclaration::toDocBuffer(OutBuffer *buf) { + //printf("ClassDeclaration::toDocbuffer() %s\n", toChars()); if (ident) { #if 0 @@ -701,7 +702,9 @@ highlightCode(NULL, this, buf, o); } else + { buf->printf("%s $(DDOC_PSYMBOL %s)", kind(), toChars()); + } int any = 0; for (int i = 0; i < baseclasses.dim; i++) { BaseClass *bc = (BaseClass *)baseclasses.data[i]; @@ -1588,6 +1591,7 @@ char *sid = s->ident->toChars(); FuncDeclaration *f = s->isFuncDeclaration(); + //printf("highlightCode(s = '%s', kind = %s)\n", sid, s->kind()); for (unsigned i = offset; i < buf->offset; i++) { unsigned char c = buf->data[i]; diff -uNr dmd-0.161/dmd/src/dmd/expression.c dmd-0.162/dmd/src/dmd/expression.c --- dmd-0.161/dmd/src/dmd/expression.c 2006-06-16 13:24:46.000000000 +0200 +++ dmd-0.162/dmd/src/dmd/expression.c 2006-06-28 01:01:30.000000000 +0200 @@ -3875,6 +3875,7 @@ Identifier *id; Type *t1; Expression *eleft = NULL; + Expression *eright; #if LOGSEMANTIC printf("DotTemplateInstanceExp::semantic('%s')\n", toChars()); @@ -3886,9 +3887,18 @@ if (t1) t1 = t1->toBasetype(); //t1->print(); - if (e1->op == TOKimport) + if (e1->op == TOKdotexp) + { DotExp *de = (DotExp *)e1; + eleft = de->e1; + eright = de->e2; + } + else + { eleft = NULL; + eright = e1; + } + if (eright->op == TOKimport) { - s = ((ScopeExp *)e1)->sds; + s = ((ScopeExp *)eright)->sds; } else if (e1->op == TOKtype) { @@ -3987,6 +3997,41 @@ e1 = e1->semantic(sc); type = new TypeDelegate(func->type); type = type->semantic(loc, sc); +//----------------- + /* For func, we need to get the + * right 'this' pointer if func is in an outer class, but our + * existing 'this' pointer is in an inner class. + * This code is analogous to that used for variables + * in DotVarExp::semantic(). + */ + AggregateDeclaration *ad = func->toParent()->isAggregateDeclaration(); + L10: + Type *t = e1->type; + if (func->needThis() && ad && + !(t->ty == Tpointer && t->next->ty == Tstruct && + ((TypeStruct *)t->next)->sym == ad) && + !(t->ty == Tstruct && ((TypeStruct *)t)->sym == ad) + ) + { + ClassDeclaration *cd = ad->isClassDeclaration(); + ClassDeclaration *tcd = t->isClassHandle(); + + if (!cd || !tcd || + !(tcd == cd || cd->isBaseOf(tcd, NULL)) + ) + { + if (tcd && tcd->isNested()) + { // Try again with outer scope + + e1 = new DotVarExp(loc, e1, tcd->vthis); + e1 = e1->semantic(sc); + goto L10; + } + error("this for %s needs to be type %s not type %s", + func->toChars(), ad->toChars(), t->toChars()); + } + } +//----------------- } return this; } diff -uNr dmd-0.161/dmd/src/dmd/func.c dmd-0.162/dmd/src/dmd/func.c --- dmd-0.161/dmd/src/dmd/func.c 2006-06-08 17:26:54.000000000 +0200 +++ dmd-0.162/dmd/src/dmd/func.c 2006-06-28 15:06:52.000000000 +0200 @@ -253,19 +253,17 @@ if (fdv && fdv->ident == ident) { int cov = type->covariant(fdv->type); - //printf("\tcov = %d\n", cov); - if (cov) + //printf("\tbaseclass cov = %d\n", cov); + if (cov == 2) + { + //type->print(); + //fdv->type->print(); + //printf("%s %s\n", type->deco, fdv->type->deco); + error("of type %s overrides but is not covariant with %s of type %s", + type->toChars(), fdv->toPrettyChars(), fdv->type->toChars()); + } + if (cov == 1) { - // Override - //printf("\toverride %p with %p\n", fdv, this); - if (cov == 2) - { - //type->print(); - //fdv->type->print(); - //printf("%s %s\n", type->deco, fdv->type->deco); - error("of type %s overrides but is not covariant with %s of type %s", - type->toChars(), fdv->toPrettyChars(), fdv->type->toChars()); - } if (fdv->isFinal()) error("cannot override final function %s", fdv->toPrettyChars()); if (fdv->toParent() == parent) @@ -304,6 +302,11 @@ } goto L1; } + if (cov == 3) + { + cd->sizeok = 2; // can't finish due to forward reference + return; + } } } } @@ -328,7 +331,7 @@ for (vi = 0; vi < b->base->vtbl.dim; vi++) { Dsymbol *s = (Dsymbol *)b->base->vtbl.data[vi]; - //printf("[%d] %p %s\n", vi, s, s->toChars()); + //printf("interface %d vtbl[%d] %p %s\n", i, vi, s, s->toChars()); FuncDeclaration *fdv = s->isFuncDeclaration(); if (fdv && fdv->ident == ident) { @@ -353,9 +356,18 @@ * offsets differ */ int offset; - if (fdv->type->next->isBaseOf(type->next, &offset) && offset) + if (fdv->type->next->isBaseOf(type->next, &offset)) { ti = fdv->type; +#if 0 + if (offset) + ti = fdv->type; + else if (type->next->ty == Tclass) + { ClassDeclaration *cdn = ((TypeClass *)type->next)->sym; + if (cdn && cdn->sizeok != 1) + ti = fdv->type; + } +#endif } } if (ti) @@ -368,6 +380,11 @@ } goto L2; } + if (cov == 3) + { + cd->sizeok = 2; // can't finish due to forward reference + return; + } } } } diff -uNr dmd-0.161/dmd/src/dmd/mars.c dmd-0.162/dmd/src/dmd/mars.c --- dmd-0.161/dmd/src/dmd/mars.c 2006-06-18 00:20:24.000000000 +0200 +++ dmd-0.162/dmd/src/dmd/mars.c 2006-06-21 20:33:34.000000000 +0200 @@ -58,7 +58,7 @@ copyright = "Copyright (c) 1999-2006 by Digital Mars"; written = "written by Walter Bright"; - version = "v0.161"; + version = "v0.162"; global.structalign = 8; memset(¶ms, 0, sizeof(Param)); diff -uNr dmd-0.161/dmd/src/dmd/mtype.c dmd-0.162/dmd/src/dmd/mtype.c --- dmd-0.161/dmd/src/dmd/mtype.c 2006-06-16 00:26:10.000000000 +0200 +++ dmd-0.162/dmd/src/dmd/mtype.c 2006-06-28 21:04:26.000000000 +0200 @@ -1,5 +1,5 @@ -// Copyright (c) 1999-2005 by Digital Mars +// Copyright (c) 1999-2006 by Digital Mars // All Rights Reserved // written by Walter Bright // www.digitalmars.com @@ -2223,7 +2223,6 @@ Type *TypeFunction::syntaxCopy() { - assert(next); Type *treturn = next ? next->syntaxCopy() : NULL; Array *args = Argument::arraySyntaxCopy(arguments); Type *t = new TypeFunction(args, treturn, varargs, linkage); @@ -2236,6 +2235,7 @@ * 1 this is covariant with t * 2 arguments match as far as overloading goes, * but types are not covariant + * 3 cannot determine covariance because of forward references */ int Type::covariant(Type *t) @@ -2291,6 +2291,14 @@ goto Lcovariant; if (t1n->ty != Tclass || t2n->ty != Tclass) goto Lnotcovariant; + + // If t1n is forward referenced: + ClassDeclaration *cd = ((TypeClass *)t1n)->sym; + if (!cd->baseClass && cd->baseclasses.dim && !cd->isInterfaceDeclaration()) + { + return 3; + } + if (t1n->implicitConvTo(t2n)) goto Lcovariant; goto Lnotcovariant; @@ -2683,6 +2691,7 @@ d_uns64 TypeQualified::size(Loc loc) { error(this->loc, "size of type %s is not known", toChars()); +*(char*)0=0; return 1; } @@ -3609,7 +3618,11 @@ int TypeTypedef::isZeroInit() { if (sym->init) + { + if (sym->init->toExpression()->isBool(FALSE)) + return 1; return 0; // assume not + } return sym->basetype->isZeroInit(); } @@ -3723,7 +3736,8 @@ L1: if (!s) { - return getProperty(e->loc, ident); + //return getProperty(e->loc, ident); + return Type::dotExp(sc, e, ident); } s = s->toAlias(); @@ -3980,7 +3994,8 @@ error(e->loc, ".typeinfo deprecated, use typeid(type)"); return getTypeInfo(sc); } - return getProperty(e->loc, ident); + //return getProperty(e->loc, ident); + return Type::dotExp(sc, e, ident); } s = s->toAlias(); v = s->isVarDeclaration(); diff -uNr dmd-0.161/dmd/src/dmd/parse.c dmd-0.162/dmd/src/dmd/parse.c --- dmd-0.161/dmd/src/dmd/parse.c 2006-06-16 10:25:00.000000000 +0200 +++ dmd-0.162/dmd/src/dmd/parse.c 2006-06-30 00:35:56.000000000 +0200 @@ -3094,10 +3094,15 @@ default: error("found '%s' instead of statement", token.toChars()); + goto Lerror; + Lerror: - while (token.value != TOKsemicolon && token.value != TOKeof) + while (token.value != TOKrcurly && + token.value != TOKsemicolon && + token.value != TOKeof) + nextToken(); + if (token.value == TOKsemicolon) nextToken(); - nextToken(); s = NULL; break; } @@ -3772,7 +3777,10 @@ exp = parseExpression(); check(TOKrparen); t = new TypeTypeof(loc, exp); - goto L1; + if (token.value == TOKdot) + goto L1; + e = new TypeExp(loc, t); + break; } case TOKtypeid: @@ -4093,24 +4101,8 @@ t = parseDeclarator(t,NULL); // ( type ) check(TOKrparen); - // if .identifier - if (token.value == TOKdot) - { - nextToken(); - if (token.value != TOKidentifier) - { error("Identifier expected following cast(type)."); - return NULL; - } - // cast(type).ident - e = new TypeDotIdExp(loc, t, token.ident); - nextToken(); - } - else - { - e = parseUnaryExp(); - e = new CastExp(loc, e, t); - } - + e = parseUnaryExp(); + e = new CastExp(loc, e, t); break; } diff -uNr dmd-0.161/dmd/src/dmd/struct.c dmd-0.162/dmd/src/dmd/struct.c --- dmd-0.161/dmd/src/dmd/struct.c 2006-06-13 02:52:30.000000000 +0200 +++ dmd-0.162/dmd/src/dmd/struct.c 2006-06-28 15:59:14.000000000 +0200 @@ -170,6 +170,11 @@ return; } } + if (t->ty == Tident) + { + sizeok = 2; // cannot finish; flag as forward referenced + return; + } memsize = v->type->size(loc); memalignsize = v->type->alignsize(); diff -uNr dmd-0.161/dmd/src/dmd/template.c dmd-0.162/dmd/src/dmd/template.c --- dmd-0.161/dmd/src/dmd/template.c 2006-06-17 01:24:32.000000000 +0200 +++ dmd-0.162/dmd/src/dmd/template.c 2006-06-30 00:16:30.000000000 +0200 @@ -12,6 +12,11 @@ #include #include +#if _WIN32 +#include +long __cdecl __ehfilter(LPEXCEPTION_POINTERS ep); +#endif + #include "root.h" #include "mem.h" #include "stringtable.h" @@ -1776,7 +1781,7 @@ if (inst) // if semantic() was already run { #if LOG - printf("-TemplateInstance::semantic('%s', this=%p) already run\n", inst->toChars(), inst); + printf("-TemplateInstance::semantic('%s', this=%p) already run\n", inst->toChars(), inst); #endif return; } @@ -1958,7 +1963,7 @@ { Dsymbol *s = (Dsymbol *)members->data[i]; #if LOG - printf("\t[%d] adding member '%s' %p to '%s', memnum = %d\n", i, s->toChars(), s, this->toChars(), memnum); + printf("\t[%d] adding member '%s' %p kind %s to '%s', memnum = %d\n", i, s->toChars(), s, s->kind(), this->toChars(), memnum); #endif memnum |= s->addMember(scope, this, memnum); } @@ -1994,12 +1999,27 @@ Scope *sc2; sc2 = scope->push(this); sc2->parent = this; + +#if _WIN32 + __try + { +#endif for (int i = 0; i < members->dim; i++) { Dsymbol *s = (Dsymbol *)members->data[i]; + //printf("\t[%d] semantic on '%s' %p kind %s in '%s'\n", i, s->toChars(), s, s->kind(), this->toChars()); s->semantic(sc2); sc2->module->runDeferredSemantic(); } +#if _WIN32 + } + __except (__ehfilter(GetExceptionInformation())) + { + global.gag = 0; // ensure error message gets printed + error("recursive expansion"); + fatal(); + } +#endif /* The problem is when to parse the initializer for a variable. * Perhaps VarDeclaration::semantic() should do it like it does @@ -2928,6 +2948,18 @@ return Dsymbol::oneMember(ps); } +char *TemplateMixin::toChars() +{ + OutBuffer buf; + HdrGenState hgs; + char *s; + + TemplateInstance::toCBuffer(&buf, &hgs); + s = buf.toChars(); + buf.data = NULL; + return s; +} + void TemplateMixin::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { buf->writestring("mixin "); diff -uNr dmd-0.161/dmd/src/dmd/template.h dmd-0.162/dmd/src/dmd/template.h --- dmd-0.161/dmd/src/dmd/template.h 2006-06-13 01:58:12.000000000 +0200 +++ dmd-0.162/dmd/src/dmd/template.h 2006-06-30 00:16:30.000000000 +0200 @@ -252,6 +252,7 @@ void inlineScan(); char *kind(); int oneMember(Dsymbol **ps); + char *toChars(); void toCBuffer(OutBuffer *buf, HdrGenState *hgs); void toObjFile(); // compile to .obj file diff -uNr dmd-0.161/dmd/src/dmd/toobj.c dmd-0.162/dmd/src/dmd/toobj.c --- dmd-0.161/dmd/src/dmd/toobj.c 2006-06-17 01:08:08.000000000 +0200 +++ dmd-0.162/dmd/src/dmd/toobj.c 2006-06-25 01:54:20.000000000 +0200 @@ -113,7 +113,10 @@ else dtdword(&dt, 0); - dtdword(&dt, 0); // flags + if (needmoduleinfo) + dtdword(&dt, 0); // flags (4 means MIstandalone) + else + dtdword(&dt, 4); // flags (4 means MIstandalone) if (sctor) dtxoff(&dt, sctor, 0, TYnptr); diff -uNr dmd-0.161/dmd/src/phobos/internal/gc/gc.d dmd-0.162/dmd/src/phobos/internal/gc/gc.d --- dmd-0.161/dmd/src/phobos/internal/gc/gc.d 2006-06-19 21:09:18.000000000 +0200 +++ dmd-0.162/dmd/src/phobos/internal/gc/gc.d 2006-06-30 17:13:56.000000000 +0200 @@ -416,10 +416,105 @@ _d_OutOfMemory(); } +/** + * For non-zero initializers + */ +extern (C) +byte[] _d_arraysetlength2(size_t newlength, size_t sizeelem, Array *p, ...) +in +{ + assert(sizeelem); + assert(!p.length || p.data); +} +body +{ + byte* newdata; + + debug(PRINTF) + { + printf("_d_arraysetlength2(p = %p, sizeelem = %d, newlength = %d)\n", p, sizeelem, newlength); + if (p) + printf("\tp.data = %p, p.length = %d\n", p.data, p.length); + } + + if (newlength) + { + version (D_InlineAsm_X86) + { + size_t newsize = void; + + asm + { + mov EAX,newlength ; + mul EAX,sizeelem ; + mov newsize,EAX ; + jc Loverflow ; + } + } + else + { + size_t newsize = sizeelem * newlength; + + if (newsize / newlength != sizeelem) + goto Loverflow; + } + //printf("newsize = %x, newlength = %x\n", newsize, newlength); + + size_t size = p.length * sizeelem; + if (p.length) + { + newdata = p.data; + if (newlength > p.length) + { + size_t cap = _gc.capacity(p.data); + + if (cap <= newsize) + { + newdata = cast(byte *)_gc.malloc(newsize + 1); + newdata[0 .. size] = p.data[0 .. size]; + } + } + } + else + { + newdata = cast(byte *)_gc.malloc(newsize + 1); + } + + va_list q; + va_start!(Array *)(q, p); // q is pointer to initializer + + if (newsize > size) + { + if (sizeelem == 1) + newdata[size .. newsize] = *(cast(byte*)q); + else + { + for (size_t u = size; u < newsize; u += sizeelem) + { + memcpy(newdata + u, q, sizeelem); + } + } + } + } + else + { + newdata = null; + } + + p.data = newdata; + p.length = newlength; + return newdata[0 .. newlength]; + +Loverflow: + _d_OutOfMemory(); +} + /*************************** * Resize bit[] arrays. */ +version (none) +{ extern (C) bit[] _d_arraysetlengthb(size_t newlength, Array *p) { @@ -462,6 +557,7 @@ p.length = newlength; return (cast(bit *)newdata)[0 .. newlength]; } +} /**************************************** * Append y[] to array x[]. diff -uNr dmd-0.161/dmd/src/phobos/object.d dmd-0.162/dmd/src/phobos/object.d --- dmd-0.161/dmd/src/phobos/object.d 2006-06-19 21:09:16.000000000 +0200 +++ dmd-0.162/dmd/src/phobos/object.d 2006-06-30 17:13:54.000000000 +0200 @@ -18,7 +18,7 @@ { void print(); char[] toString(); - uint toHash(); + hash_t toHash(); int opCmp(Object o); int opEquals(Object o); } diff -uNr dmd-0.161/dmd/src/phobos/std/asserterror.d dmd-0.162/dmd/src/phobos/std/asserterror.d --- dmd-0.161/dmd/src/phobos/std/asserterror.d 2006-06-19 21:09:16.000000000 +0200 +++ dmd-0.162/dmd/src/phobos/std/asserterror.d 2006-06-30 17:13:54.000000000 +0200 @@ -38,7 +38,9 @@ count = snprintf(buffer, len, "AssertError Failure %.*s(%u) %.*s", filename, linnum, msg); if (count >= len || count == -1) - super("AssertError internal failure"); + { super("AssertError internal failure"); + std.c.stdlib.free(buffer); + } else super(buffer[0 .. count]); } @@ -46,7 +48,7 @@ ~this() { - if (msg.ptr) + if (msg.ptr && msg[12] == 'F') // if it was allocated with malloc() { std.c.stdlib.free(msg.ptr); msg = null; } diff -uNr dmd-0.161/dmd/src/phobos/std/moduleinit.d dmd-0.162/dmd/src/phobos/std/moduleinit.d --- dmd-0.161/dmd/src/phobos/std/moduleinit.d 2006-06-19 21:09:16.000000000 +0200 +++ dmd-0.162/dmd/src/phobos/std/moduleinit.d 2006-06-30 17:13:54.000000000 +0200 @@ -14,6 +14,8 @@ enum { MIctorstart = 1, // we've started constructing it MIctordone = 2, // finished construction + MIstandalone = 4, // module ctor does not depend on other module + // ctors being done first } class ModuleInfo @@ -112,7 +114,7 @@ if (m.ctor || m.dtor) { if (m.flags & MIctorstart) - { if (skip) + { if (skip || m.flags & MIstandalone) continue; throw new ModuleCtorError(m); }