diff -uNr dmd-0.162/dmd/src/dmd/access.c dmd-0.163/dmd/src/dmd/access.c --- dmd-0.162/dmd/src/dmd/access.c 2006-02-05 02:27:34.000000000 +0100 +++ dmd-0.163/dmd/src/dmd/access.c 2006-07-15 13:14:36.000000000 +0200 @@ -32,6 +32,8 @@ /* Code to do access checks */ +int hasPackageAccess(Scope *sc, Dsymbol *s); + /**************************************** * Return PROT access for Dsymbol smember in this declaration. */ @@ -222,7 +224,7 @@ result = access >= PROTpublic || hasPrivateAccess(f) || isFriendOf(cdscope) || - (access == PROTpackage && hasPackageAccess(sc)); + (access == PROTpackage && hasPackageAccess(sc, this)); #if LOG printf("result1 = %d\n", result); #endif @@ -234,7 +236,7 @@ printf("result2 = %d\n", result); #endif } - else if (access == PROTpackage && hasPackageAccess(sc)) + else if (access == PROTpackage && hasPackageAccess(sc, this)) { result = 1; #if LOG @@ -283,30 +285,29 @@ } /**************************************** - * Determine if scope sc has package level access to 'this'. + * Determine if scope sc has package level access to s. */ -int AggregateDeclaration::hasPackageAccess(Scope *sc) +int hasPackageAccess(Scope *sc, Dsymbol *s) { #if LOG - printf("AggregateDeclaration::hasPackageAccess(this = '%s', sc = '%p')\n", toChars(), sc); + printf("hasPackageAccess(s = '%s', sc = '%p')\n", s->toChars(), sc); #endif - Dsymbol *mthis; - for (mthis = this; mthis; mthis = mthis->parent) + for (; s; s = s->parent) { - if (mthis->isPackage() && !mthis->isModule()) + if (s->isPackage() && !s->isModule()) break; } #if LOG - if (mthis) - printf("\tthis is in package '%s'\n", mthis->toChars()); + if (s) + printf("\tthis is in package '%s'\n", s->toChars()); #endif - if (mthis && mthis == sc->module->parent) + if (s && s == sc->module->parent) { #if LOG - printf("\t'this' is in same package as cd\n"); + printf("\ts is in same package as sc\n"); #endif return 1; } @@ -379,10 +380,24 @@ void accessCheck(Loc loc, Scope *sc, Expression *e, Declaration *d) { #if LOG - printf("accessCheck(%s . %s)\n", e->toChars(), d->toChars()); - printf("\te->type = %s\n", e->type->toChars()); + if (e) + { printf("accessCheck(%s . %s)\n", e->toChars(), d->toChars()); + printf("\te->type = %s\n", e->type->toChars()); + } + else + { + //printf("accessCheck(%s)\n", d->toChars()); + } #endif - if (e->type->ty == Tclass) + if (!e) + { + if (d->prot() == PROTprivate && d->getModule() != sc->module || + d->prot() == PROTpackage && !hasPackageAccess(sc, d)) + + error(loc, "%s %s.%s is not accessible from %s", + d->kind(), d->getModule()->toChars(), d->toChars(), sc->module->toChars()); + } + else if (e->type->ty == Tclass) { // Do access check ClassDeclaration *cd; diff -uNr dmd-0.162/dmd/src/dmd/aggregate.h dmd-0.163/dmd/src/dmd/aggregate.h --- dmd-0.162/dmd/src/dmd/aggregate.h 2006-04-09 12:19:48.000000000 +0200 +++ dmd-0.163/dmd/src/dmd/aggregate.h 2006-07-14 15:00:56.000000000 +0200 @@ -75,7 +75,6 @@ // For access checking virtual PROT getAccess(Dsymbol *smember); // determine access to smember int isFriendOf(AggregateDeclaration *cd); - int hasPackageAccess(Scope *sc); int hasPrivateAccess(Dsymbol *smember); // does smember have private access to members of this class? void accessCheck(Loc loc, Scope *sc, Dsymbol *smember); diff -uNr dmd-0.162/dmd/src/dmd/attrib.c dmd-0.163/dmd/src/dmd/attrib.c --- dmd-0.162/dmd/src/dmd/attrib.c 2006-06-03 01:52:38.000000000 +0200 +++ dmd-0.163/dmd/src/dmd/attrib.c 2006-07-14 16:16:34.000000000 +0200 @@ -457,8 +457,10 @@ { if (decl) { enum PROT protection_save = sc->protection; + int explicitProtection_save = sc->explicitProtection; sc->protection = protection; + sc->explicitProtection = 1; for (unsigned i = 0; i < decl->dim; i++) { Dsymbol *s = (Dsymbol *)decl->data[i]; @@ -466,9 +468,12 @@ s->semantic(sc); } sc->protection = protection_save; + sc->explicitProtection = explicitProtection_save; } else - sc->protection = protection; + { sc->protection = protection; + sc->explicitProtection = 1; + } } void ProtDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) diff -uNr dmd-0.162/dmd/src/dmd/class.c dmd-0.163/dmd/src/dmd/class.c --- dmd-0.162/dmd/src/dmd/class.c 2006-06-28 15:13:08.000000000 +0200 +++ dmd-0.163/dmd/src/dmd/class.c 2006-07-14 16:17:44.000000000 +0200 @@ -440,6 +440,7 @@ if (isCOMclass()) sc->linkage = LINKwindows; sc->protection = PROTpublic; + sc->explicitProtection = 0; sc->structalign = 8; structalign = sc->structalign; if (baseClass) diff -uNr dmd-0.162/dmd/src/dmd/declaration.c dmd-0.163/dmd/src/dmd/declaration.c --- dmd-0.162/dmd/src/dmd/declaration.c 2006-06-27 02:05:16.000000000 +0200 +++ dmd-0.163/dmd/src/dmd/declaration.c 2006-07-12 12:31:20.000000000 +0200 @@ -91,6 +91,7 @@ this->hbasetype = NULL; #endif this->sem = 0; + this->inuse = 0; this->loc = loc; } diff -uNr dmd-0.162/dmd/src/dmd/declaration.h dmd-0.163/dmd/src/dmd/declaration.h --- dmd-0.162/dmd/src/dmd/declaration.h 2006-06-09 23:36:12.000000000 +0200 +++ dmd-0.163/dmd/src/dmd/declaration.h 2006-07-12 12:31:20.000000000 +0200 @@ -118,6 +118,7 @@ // 1: semantic() is in progress // 2: semantic() has been run // 3: semantic2() has been run + int inuse; // used to detect typedef cycles TypedefDeclaration(Loc loc, Identifier *ident, Type *basetype, Initializer *init); Dsymbol *syntaxCopy(Dsymbol *); diff -uNr dmd-0.162/dmd/src/dmd/enum.c dmd-0.163/dmd/src/dmd/enum.c --- dmd-0.162/dmd/src/dmd/enum.c 2006-06-01 18:35:12.000000000 +0200 +++ dmd-0.163/dmd/src/dmd/enum.c 2006-07-13 15:26:34.000000000 +0200 @@ -107,6 +107,59 @@ } else { // Default is the previous number plus 1 + + // Check for overflow + if (!first) + { + switch (t->toBasetype()->ty) + { + case Tbool: + if (number == 2) goto Loverflow; + break; + + case Tint8: + if (number == 128) goto Loverflow; + break; + + case Tchar: + case Tuns8: + if (number == 256) goto Loverflow; + break; + + case Tint16: + if (number == 0x8000) goto Loverflow; + break; + + case Twchar: + case Tuns16: + if (number == 0x10000) goto Loverflow; + break; + + case Tint32: + if (number == 0x80000000) goto Loverflow; + break; + + case Tdchar: + case Tuns32: + if (number == 0x100000000LL) goto Loverflow; + break; + + case Tint64: + if (number == 0x8000000000000000LL) goto Loverflow; + break; + + case Tuns64: + if (number == 0) goto Loverflow; + break; + + Loverflow: + error("overflow of enum value"); + break; + + default: + assert(0); + } + } e = new IntegerExp(em->loc, number, t); } em->value = e; diff -uNr dmd-0.162/dmd/src/dmd/expression.c dmd-0.163/dmd/src/dmd/expression.c --- dmd-0.162/dmd/src/dmd/expression.c 2006-06-28 01:01:30.000000000 +0200 +++ dmd-0.163/dmd/src/dmd/expression.c 2006-07-15 13:09:38.000000000 +0200 @@ -1689,7 +1689,8 @@ TemplateInstance *ti = s->isTemplateInstance(); if (ti && !global.errors) - { ti->semantic(sc); + { if (!ti->semanticdone) + ti->semantic(sc); s = ti->inst->toAlias(); if (!s->isTemplateInstance()) goto Lagain; @@ -2251,6 +2252,8 @@ ScopeExp::ScopeExp(Loc loc, ScopeDsymbol *pkg) : Expression(loc, TOKimport, sizeof(ScopeExp)) { + //printf("ScopeExp::ScopeExp(pkg = '%s')\n", pkg->toChars()); + //static int count; if (++count == 38) *(char*)0=0; this->sds = pkg; } @@ -2272,7 +2275,8 @@ ti = sds->isTemplateInstance(); if (ti && !global.errors) { Dsymbol *s; - ti->semantic(sc); + if (!ti->semanticdone) + ti->semantic(sc); s = ti->inst->toAlias(); sds2 = s->isScopeDsymbol(); if (!sds2) @@ -4441,6 +4445,8 @@ goto Lagain; } + accessCheck(loc, sc, NULL, f); + ve->var = f; ve->type = f->type; t1 = f->type; @@ -5319,7 +5325,10 @@ Expression *IndexExp::modifiableLvalue(Scope *sc, Expression *e) { + //printf("IndexExp::modifiableLvalue(%s)\n", toChars()); modifiable = 1; + if (e1->op == TOKstring) + error("string literals are immutable"); if (e1->type->toBasetype()->ty == Taarray) e1 = e1->modifiableLvalue(sc, e1); return toLvalue(e); @@ -5544,9 +5553,10 @@ else if (e1->op == TOKslice) ; else - // Try to do a decent error message with the expression + { // Try to do a decent error message with the expression // before it got constant folded e1 = e1->modifiableLvalue(sc, e1old); + } if (e1->op == TOKslice && t1->next && diff -uNr dmd-0.162/dmd/src/dmd/func.c dmd-0.163/dmd/src/dmd/func.c --- dmd-0.162/dmd/src/dmd/func.c 2006-06-28 15:06:52.000000000 +0200 +++ dmd-0.163/dmd/src/dmd/func.c 2006-07-14 16:18:36.000000000 +0200 @@ -237,7 +237,10 @@ // if static function, do not put in vtbl[] if (!isVirtual()) + { + //printf("\tnot virtual\n"); return; + } // Find index of existing function in vtbl[] to override if (cd->baseClass) @@ -313,7 +316,7 @@ // This is an 'introducing' function. // Append to end of vtbl[] - //printf("\tappend with %p\n", this); + //printf("\tintroducing function\n"); introducing = 1; vi = cd->vtbl.dim; cd->vtbl.push(this); @@ -520,7 +523,9 @@ sc2->linkage = LINKd; sc2->stc &= ~(STCauto | STCstatic | STCabstract | STCdeprecated); sc2->protection = PROTpublic; + sc2->explicitProtection = 0; sc2->structalign = 8; + sc2->incontract = 0; // Declare 'this' ad = isThis(); diff -uNr dmd-0.162/dmd/src/dmd/import.c dmd-0.163/dmd/src/dmd/import.c --- dmd-0.162/dmd/src/dmd/import.c 2006-06-19 18:08:00.000000000 +0200 +++ dmd-0.163/dmd/src/dmd/import.c 2006-07-17 14:37:38.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 @@ -20,20 +20,34 @@ /********************************* Import ****************************/ -Import::Import(Loc loc, Array *packages, Identifier *id) +Import::Import(Loc loc, Array *packages, Identifier *id, Identifier *aliasId, + int isstatic) : Dsymbol(id) { this->loc = loc; this->packages = packages; this->id = id; + this->aliasId = aliasId; + this->isstatic = isstatic; pkg = NULL; mod = NULL; + if (aliasId) + this->ident = aliasId; // Kludge to change Import identifier to first package - if (packages && packages->dim) + else if (packages && packages->dim) this->ident = (Identifier *)packages->data[0]; } +void Import::addAlias(Identifier *name, Identifier *alias) +{ + if (!aliasId) + this->ident = NULL; // make it an anonymous import + + names.push(name); + aliases.push(alias); +} + char *Import::kind() { return "import"; @@ -46,7 +60,13 @@ Import *si; - si = new Import(loc, packages, id); + si = new Import(loc, packages, id, aliasId, isstatic); + + for (size_t i = 0; i < names.dim; i++) + { + si->addAlias((Identifier *)names.data[i], (Identifier *)aliases.data[i]); + } + return si; } @@ -98,24 +118,100 @@ */ mod->importedFrom = sc->module->importedFrom; - sc->scopesym->importScope(mod, sc->protection); + if (!isstatic && !aliasId && !names.dim) + { + /* Default to private importing + */ + enum PROT prot = sc->protection; + if (!sc->explicitProtection) + prot = PROTprivate; + sc->scopesym->importScope(mod, prot); + } // Modules need a list of each imported module sc->module->aimports.push(mod); if (mod->needmoduleinfo) sc->module->needmoduleinfo = 1; + + sc = sc->push(mod); + for (size_t i = 0; i < aliasdecls.dim; i++) + { Dsymbol *s = (Dsymbol *)aliasdecls.data[i]; + + //printf("\tImport alias semantic('%s')\n", s->toChars()); + if (!mod->search((Identifier *)names.data[i], 0)) + error("%s not found", ((Identifier *)names.data[i])->toChars()); + + s->semantic(sc); + } + sc = sc->pop(); } //printf("-Import::semantic('%s'), pkg = %p\n", toChars(), pkg); } void Import::semantic2(Scope *sc) { + //printf("Import::semantic2('%s')\n", toChars()); mod->semantic2(); if (mod->needmoduleinfo) sc->module->needmoduleinfo = 1; } +Dsymbol *Import::toAlias() +{ + if (aliasId) + return mod; + return this; +} + +int Import::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) +{ + int result = 0; + + if (names.dim == 0) + return Dsymbol::addMember(sc, sd, memnum); + + if (aliasId) + result = Dsymbol::addMember(sc, sd, memnum); + + for (size_t i = 0; i < names.dim; i++) + { + Identifier *name = (Identifier *)names.data[i]; + Identifier *alias = (Identifier *)aliases.data[i]; + + if (!alias) + alias = name; + +#if 1 + TypeIdentifier *tname = new TypeIdentifier(loc, name); +#else + TypeIdentifier *tname = new TypeIdentifier(loc, NULL); + if (packages) + { + for (size_t j = 0; j < packages->dim; j++) + { Identifier *pid = (Identifier *)packages->data[j]; + + if (!tname->ident) + tname->ident = pid; + else + tname->addIdent(pid); + } + } + if (!tname->ident) + tname->ident = id; + else + tname->addIdent(id); + tname->addIdent(name); +#endif + AliasDeclaration *ad = new AliasDeclaration(loc, alias, tname); + result |= ad->addMember(sc, sd, memnum); + + aliasdecls.push(ad); + } + + return result; +} + Dsymbol *Import::search(Identifier *ident, int flags) { //printf("%s.Import::search(ident = '%s', flags = x%x)\n", toChars(), ident->toChars(), flags); @@ -138,11 +234,16 @@ if (hgs->hdrgen && id == Id::object) return; // object is imported by default + if (isstatic) + buf->writestring("static "); buf->writestring("import "); + if (aliasId) + { + buf->printf("%s = ", aliasId->toChars()); + } if (packages && packages->dim) - { int i; - - for (i = 0; i < packages->dim; i++) + { + for (size_t i = 0; i < packages->dim; i++) { Identifier *pid = (Identifier *)packages->data[i]; buf->printf("%s.", pid->toChars()); diff -uNr dmd-0.162/dmd/src/dmd/import.h dmd-0.163/dmd/src/dmd/import.h --- dmd-0.162/dmd/src/dmd/import.h 2006-06-19 18:08:34.000000000 +0200 +++ dmd-0.163/dmd/src/dmd/import.h 2006-07-17 00:42:16.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 @@ -22,6 +22,7 @@ struct OutBuffer; struct Module; struct Package; +struct AliasDeclaration; #ifdef _DH struct HdrGenState; #endif @@ -30,16 +31,29 @@ { Array *packages; // array of Identifier's representing packages Identifier *id; // module Identifier + Identifier *aliasId; + int isstatic; // !=0 if static import + + // Pairs of alias=name to bind into current namespace + Array names; + Array aliases; + + Array aliasdecls; // AliasDeclarations for names/aliases Module *mod; Package *pkg; // leftmost package/module - Import(Loc loc, Array *packages, Identifier *id); + Import(Loc loc, Array *packages, Identifier *id, Identifier *aliasId, + int isstatic); + void addAlias(Identifier *name, Identifier *alias); + char *kind(); Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees void load(); void semantic(Scope *sc); void semantic2(Scope *sc); + Dsymbol *toAlias(); + int addMember(Scope *sc, ScopeDsymbol *s, int memnum); Dsymbol *search(Identifier *ident, int flags); int overloadInsert(Dsymbol *s); void toCBuffer(OutBuffer *buf, HdrGenState *hgs); diff -uNr dmd-0.162/dmd/src/dmd/mars.c dmd-0.163/dmd/src/dmd/mars.c --- dmd-0.162/dmd/src/dmd/mars.c 2006-06-21 20:33:34.000000000 +0200 +++ dmd-0.163/dmd/src/dmd/mars.c 2006-07-07 00:43:28.000000000 +0200 @@ -58,7 +58,7 @@ copyright = "Copyright (c) 1999-2006 by Digital Mars"; written = "written by Walter Bright"; - version = "v0.162"; + version = "v0.163"; global.structalign = 8; memset(¶ms, 0, sizeof(Param)); diff -uNr dmd-0.162/dmd/src/dmd/module.c dmd-0.163/dmd/src/dmd/module.c --- dmd-0.162/dmd/src/dmd/module.c 2006-06-19 18:07:46.000000000 +0200 +++ dmd-0.163/dmd/src/dmd/module.c 2006-07-15 02:14:50.000000000 +0200 @@ -607,7 +607,7 @@ // Add import of "object" if this module isn't "object" if (ident != Id::object) { - Import *im = new Import(0, NULL, Id::object); + Import *im = new Import(0, NULL, Id::object, NULL, 0); members->shift(im); } diff -uNr dmd-0.162/dmd/src/dmd/mtype.c dmd-0.163/dmd/src/dmd/mtype.c --- dmd-0.162/dmd/src/dmd/mtype.c 2006-06-28 21:04:26.000000000 +0200 +++ dmd-0.163/dmd/src/dmd/mtype.c 2006-07-12 12:34:26.000000000 +0200 @@ -1130,12 +1130,12 @@ return Type::getProperty(loc, ident); Livalue: - e = new IntegerExp(0, ivalue, this); + e = new IntegerExp(loc, ivalue, this); return e; Lfvalue: if (isreal() || isimaginary()) - e = new RealExp(0, fvalue, this); + e = new RealExp(loc, fvalue, this); else { complex_t cvalue; @@ -1151,12 +1151,12 @@ //for (int i = 0; i < 20; i++) // printf("%02x ", ((unsigned char *)&cvalue)[i]); //printf("\n"); - e = new ComplexExp(0, cvalue, this); + e = new ComplexExp(loc, cvalue, this); } return e; Lint: - e = new IntegerExp(0, ivalue, Type::tint32); + e = new IntegerExp(loc, ivalue, Type::tint32); return e; } @@ -2751,7 +2751,8 @@ return; } ti->tempdecl = td; - ti->semantic(sc); + if (!ti->semanticdone) + ti->semantic(sc); sm = ti->toAlias(); } else @@ -3002,7 +3003,8 @@ break; } ti->tempdecl = td; - ti->semantic(sc); + if (!ti->semanticdone) + ti->semantic(sc); sm = ti->toAlias(); } else @@ -3576,7 +3578,16 @@ Type *TypeTypedef::toBasetype() { - return sym->basetype->toBasetype(); + if (sym->inuse) + { + sym->error("circular definition"); + sym->basetype = Type::terror; + return Type::terror; + } + sym->inuse = 1; + Type *t = sym->basetype->toBasetype(); + sym->inuse = 0; + return t; } int TypeTypedef::implicitConvTo(Type *to) diff -uNr dmd-0.162/dmd/src/dmd/mtype.h dmd-0.163/dmd/src/dmd/mtype.h --- dmd-0.162/dmd/src/dmd/mtype.h 2006-03-18 14:17:58.000000000 +0100 +++ dmd-0.163/dmd/src/dmd/mtype.h 2006-07-12 17:21:32.000000000 +0200 @@ -302,6 +302,7 @@ int implicitConvTo(Type *to); Expression *defaultInit(); dt_t **toDt(dt_t **pdt); + dt_t **toDtElem(dt_t **pdt, Expression *e); MATCH deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters, Array *atypes); TypeInfoDeclaration *getTypeInfoDeclaration(); diff -uNr dmd-0.162/dmd/src/dmd/parse.c dmd-0.163/dmd/src/dmd/parse.c --- dmd-0.162/dmd/src/dmd/parse.c 2006-06-30 00:35:56.000000000 +0200 +++ dmd-0.163/dmd/src/dmd/parse.c 2006-07-15 16:03:50.000000000 +0200 @@ -159,7 +159,7 @@ break; case TOKimport: - s = parseImport(decldefs); + s = parseImport(decldefs, 0); break; case TOKtemplate: @@ -228,6 +228,10 @@ s = new StaticIfDeclaration(condition, a, aelse); break; } + else if (token.value == TOKimport) + { + s = parseImport(decldefs, 1); + } else { stc = STCstatic; goto Lstc2; @@ -586,12 +590,11 @@ Condition *Parser::parseVersionCondition() { Condition *c; + unsigned level = 1; + Identifier *id = NULL; if (token.value == TOKlparen) { - unsigned level = 1; - Identifier *id = NULL; - nextToken(); if (token.value == TOKidentifier) id = token.ident; @@ -602,12 +605,10 @@ nextToken(); check(TOKrparen); - c = new VersionCondition(mod, level, id); } else - { error("(condition) expected following version"); - c = NULL; - } + error("(condition) expected following version"); + c = new VersionCondition(mod, level, id); return c; } @@ -1152,7 +1153,7 @@ protection = PROTpublic; continue; default: - error("base classes expected"); + error("base classes expected instead of %s", token.toChars()); return NULL; } BaseClass *b = new BaseClass(parseBasicType(), protection); @@ -1378,7 +1379,7 @@ TemplateMixin *tm; Identifier *id; TypeTypeof *tqual; - Array *tiargs; + Objects *tiargs; Array *idents; //printf("parseMixin()\n"); @@ -1468,10 +1469,10 @@ * current token is one after closing ')' */ -Array *Parser::parseTemplateArgumentList() +Objects *Parser::parseTemplateArgumentList() { //printf("Parser::parseTemplateArgumentList()\n"); - Array *tiargs = new Array(); + Objects *tiargs = new Objects(); if (token.value != TOKlparen) { error("!(TemplateArgumentList) expected following TemplateIdentifier"); return tiargs; @@ -1509,15 +1510,17 @@ return tiargs; } -Import *Parser::parseImport(Array *decldefs) +Import *Parser::parseImport(Array *decldefs, int isstatic) { Import *s; Identifier *id; + Identifier *aliasid = NULL; Array *a; Loc loc; //printf("Parser::parseImport()\n"); do { + L1: nextToken(); if (token.value != TOKidentifier) { error("Identifier expected following import"); @@ -1527,7 +1530,13 @@ loc = this->loc; a = NULL; id = token.ident; - while (nextToken() == TOKdot) + nextToken(); + if (!aliasid && token.value == TOKassign) + { + aliasid = id; + goto L1; + } + while (token.value == TOKdot) { if (!a) a = new Array(); @@ -1538,10 +1547,49 @@ break; } id = token.ident; + nextToken(); } - s = new Import(loc, a, token.ident); + s = new Import(loc, a, token.ident, aliasid, isstatic); decldefs->push(s); + + /* Look for + * : alias=name, alias=name; + * syntax. + */ + if (token.value == TOKcolon) + { + do + { Identifier *name; + Identifier *alias; + + nextToken(); + if (token.value != TOKidentifier) + { error("Identifier expected following :"); + break; + } + alias = token.ident; + nextToken(); + if (token.value == TOKassign) + { + nextToken(); + if (token.value != TOKidentifier) + { error("Identifier expected following %s=", alias->toChars()); + break; + } + name = token.ident; + nextToken(); + } + else + { name = alias; + alias = NULL; + } + s->addAlias(name, alias); + } while (token.value == TOKcomma); + break; // no comma-separated imports of this form + } + + aliasid = NULL; } while (token.value == TOKcomma); if (token.value == TOKsemicolon) @@ -4564,7 +4612,10 @@ if (token.value == TOKlparen) arguments = parseArguments(); - BaseClasses *baseclasses = parseBaseClasses(); + BaseClasses *baseclasses = NULL; + if (token.value != TOKlcurly) + baseclasses = parseBaseClasses(); + Identifier *id = NULL; ClassDeclaration *cd = new ClassDeclaration(loc, id, baseclasses); diff -uNr dmd-0.162/dmd/src/dmd/parse.h dmd-0.163/dmd/src/dmd/parse.h --- dmd-0.162/dmd/src/dmd/parse.h 2006-06-02 11:22:24.000000000 +0200 +++ dmd-0.163/dmd/src/dmd/parse.h 2006-07-15 02:13:06.000000000 +0200 @@ -57,7 +57,7 @@ TemplateParameters *parseTemplateParameterList(); TemplateInstance *parseTemplateInstance(); Dsymbol *parseMixin(); - Array *parseTemplateArgumentList(); + Objects *parseTemplateArgumentList(); StaticAssert *parseStaticAssert(); enum LINK parseLinkage(); Condition *parseDebugCondition(); @@ -76,7 +76,7 @@ EnumDeclaration *parseEnum(); Dsymbol *parseAggregate(); BaseClasses *parseBaseClasses(); - Import *parseImport(Array *decldefs); + Import *parseImport(Array *decldefs, int isstatic); Type *parseBasicType(); Type *parseBasicType2(Type *t); Type *parseDeclarator(Type *t, Identifier **pident, TemplateParameters **tpl = NULL); diff -uNr dmd-0.162/dmd/src/dmd/scope.c dmd-0.163/dmd/src/dmd/scope.c --- dmd-0.162/dmd/src/dmd/scope.c 2006-02-22 01:22:04.000000000 +0100 +++ dmd-0.163/dmd/src/dmd/scope.c 2006-07-14 16:19:30.000000000 +0200 @@ -56,6 +56,7 @@ this->slabel = NULL; this->linkage = LINKd; this->protection = PROTpublic; + this->explicitProtection = 0; this->stc = 0; this->offset = 0; this->inunion = 0; @@ -87,6 +88,7 @@ this->slabel = NULL; this->linkage = enclosing->linkage; this->protection = enclosing->protection; + this->explicitProtection = enclosing->explicitProtection; this->stc = enclosing->stc; this->offset = 0; this->inunion = enclosing->inunion; diff -uNr dmd-0.162/dmd/src/dmd/scope.h dmd-0.163/dmd/src/dmd/scope.h --- dmd-0.162/dmd/src/dmd/scope.h 2006-01-05 20:33:20.000000000 +0100 +++ dmd-0.163/dmd/src/dmd/scope.h 2006-07-14 16:13:50.000000000 +0200 @@ -65,7 +65,10 @@ unsigned structalign; // alignment for struct members enum LINK linkage; // linkage for external functions + enum PROT protection; // protection for class members + int explicitProtection; // set if in an explicit protection attribute + unsigned stc; // storage class unsigned flags; diff -uNr dmd-0.162/dmd/src/dmd/struct.c dmd-0.163/dmd/src/dmd/struct.c --- dmd-0.162/dmd/src/dmd/struct.c 2006-06-28 15:59:14.000000000 +0200 +++ dmd-0.163/dmd/src/dmd/struct.c 2006-07-14 16:18:58.000000000 +0200 @@ -270,6 +270,7 @@ if (isUnionDeclaration()) sc2->inunion = 1; sc2->protection = PROTpublic; + sc2->explicitProtection = 0; int members_dim = members->dim; for (i = 0; i < members_dim; i++) diff -uNr dmd-0.162/dmd/src/dmd/template.c dmd-0.163/dmd/src/dmd/template.c --- dmd-0.162/dmd/src/dmd/template.c 2006-06-30 00:16:30.000000000 +0200 +++ dmd-0.163/dmd/src/dmd/template.c 2006-07-09 01:41:10.000000000 +0200 @@ -251,12 +251,12 @@ */ MATCH TemplateDeclaration::matchWithInstance(TemplateInstance *ti, - Array *dedtypes, int flag) + Objects *dedtypes, int flag) { MATCH m; int dim = dedtypes->dim; #if LOG - printf("+TemplateDeclaration::matchWithInstance(this = %p, ti = %p)\n", this, ti); + printf("+TemplateDeclaration::matchWithInstance(this = %p, ti = %p, flag = %d)\n", this, ti, flag); #endif dedtypes->zero(); @@ -389,7 +389,7 @@ */ TemplateInstance ti(0, ident); // create dummy template instance - Array dedtypes; + Objects dedtypes; #define LOG_LEASTAS 0 @@ -399,7 +399,7 @@ // Set type arguments to dummy template instance to be types // generated from the parameters to this template declaration - ti.tiargs = new Array(); + ti.tiargs = new Objects(); ti.tiargs->setDim(parameters->dim); for (int i = 0; i < ti.tiargs->dim; i++) { @@ -436,7 +436,8 @@ * dedargs Expression/Type deduced template arguments */ -MATCH TemplateDeclaration::deduceMatch(Array *targsi, Array *fargs, Array *dedargs) +MATCH TemplateDeclaration::deduceMatch(Objects *targsi, Expressions *fargs, + Objects *dedargs) { size_t i; size_t nfparams; @@ -445,7 +446,7 @@ MATCH match = MATCHexact; FuncDeclaration *fd = onemember->toAlias()->isFuncDeclaration(); TypeFunction *fdtype; - Array dedtypes; // for T:T*, the dedargs is the T*, dedtypes is the T + Objects dedtypes; // for T:T*, the dedargs is the T*, dedtypes is the T assert((size_t)scope > 0x10000); @@ -556,6 +557,7 @@ TemplateParameter *tp = (TemplateParameter *)parameters->data[i]; Object *oarg = (Object *)dedargs->data[i]; Object *o = (Object *)dedtypes.data[i]; + //printf("1dedargs[%d] = %p, dedtypes[%d] = %p\n", i, oarg, i, o); if (!oarg) { if (o) @@ -635,12 +637,13 @@ * fargs arguments to function */ -FuncDeclaration *TemplateDeclaration::deduce(Scope *sc, Loc loc, Array *targsi, Expressions *fargs) +FuncDeclaration *TemplateDeclaration::deduce(Scope *sc, Loc loc, + Objects *targsi, Expressions *fargs) { MATCH m_best = MATCHnomatch; TemplateDeclaration *td_ambig = NULL; TemplateDeclaration *td_best = NULL; - Array *tdargs = new Array(); + Objects *tdargs = new Objects(); TemplateInstance *ti; FuncDeclaration *fd; @@ -658,7 +661,7 @@ } MATCH m; - Array dedargs; + Objects dedargs; m = td->deduceMatch(targsi, fargs, &dedargs); if (!m) // if no match @@ -1166,7 +1169,8 @@ MATCH TemplateTypeParameter::matchArg(Scope *sc, Object *oarg, - int i, TemplateParameters *parameters, Array *dedtypes, Declaration **psparam) + int i, TemplateParameters *parameters, Objects *dedtypes, + Declaration **psparam) { //printf("TemplateTypeParameter::matchArg()\n"); @@ -1349,7 +1353,8 @@ } MATCH TemplateAliasParameter::matchArg(Scope *sc, - Object *oarg, int i, TemplateParameters *parameters, Array *dedtypes, Declaration **psparam) + Object *oarg, int i, TemplateParameters *parameters, Objects *dedtypes, + Declaration **psparam) { Dsymbol *sa; @@ -1556,7 +1561,8 @@ MATCH TemplateValueParameter::matchArg(Scope *sc, - Object *oarg, int i, TemplateParameters *parameters, Array *dedtypes, Declaration **psparam) + Object *oarg, int i, TemplateParameters *parameters, Objects *dedtypes, + Declaration **psparam) { //printf("TemplateValueParameter::matchArg()\n"); @@ -1564,6 +1570,8 @@ Declaration *sparam; Expression *ei = isExpression(oarg); MATCH m = MATCHexact; + Type *vt; + if (!ei && oarg) goto Lnomatch; @@ -1594,11 +1602,12 @@ goto Lnomatch; } Lmatch: - //printf("valType: %s\n", valType->toChars()); + //printf("valType: %s, ty = %d\n", valType->toChars(), valType->ty); + vt = valType->semantic(0, sc); //printf("ei: %s, %s\n", ei->toChars(), ei->type->toChars()); if (ei->type) { - m = (MATCH)ei->implicitConvTo(valType); + m = (MATCH)ei->implicitConvTo(vt); //printf("m: %d\n", m); if (!m) goto Lnomatch; @@ -1606,7 +1615,7 @@ dedtypes->data[i] = ei; init = new ExpInitializer(loc, ei); - sparam = new VarDeclaration(loc, valType, ident, init); + sparam = new VarDeclaration(loc, vt, ident, init); sparam->storage_class = STCconst; *psparam = sparam; return m; @@ -1701,7 +1710,7 @@ } -TemplateInstance::TemplateInstance(Loc loc, TemplateDeclaration *td, Array *tiargs) +TemplateInstance::TemplateInstance(Loc loc, TemplateDeclaration *td, Objects *tiargs) : ScopeDsymbol(NULL) { #if LOG @@ -1737,7 +1746,7 @@ for (i = 1; i < idents.dim; i++) ti->idents.data[i] = idents.data[i]; - ti->tiargs = new Array(); + ti->tiargs = new Objects(); ti->tiargs->setDim(tiargs->dim); for (i = 0; i < tiargs->dim; i++) { @@ -2187,7 +2196,7 @@ TemplateDeclaration *td_ambig = NULL; TemplateDeclaration *td_best = NULL; MATCH m_best = MATCHnomatch; - Array dedtypes; + Objects dedtypes; for (TemplateDeclaration *td = tempdecl; td; td = td->overnext) { @@ -2388,6 +2397,7 @@ //Object *o = (Object *)tiargs->data[i]; Object *o = (Object *)tdtypes.data[i]; + //printf("\ttdtypes[%d] = %p\n", i, o); tempdecl->declareParameter(scope, tp, o); } } @@ -2583,14 +2593,14 @@ /* ======================== TemplateMixin ================================ */ TemplateMixin::TemplateMixin(Loc loc, Identifier *ident, TypeTypeof *tqual, - Array *idents, Array *tiargs) + Array *idents, Objects *tiargs) : TemplateInstance(loc, (Identifier *)idents->data[idents->dim - 1]) { //printf("TemplateMixin(ident = '%s')\n", ident ? ident->toChars() : ""); this->ident = ident; this->tqual = tqual; this->idents = idents; - this->tiargs = tiargs ? tiargs : new Array(); + this->tiargs = tiargs ? tiargs : new Objects(); this->scope = NULL; } @@ -2624,9 +2634,18 @@ #if LOG printf("+TemplateMixin::semantic('%s', this=%p)\n", toChars(), this); #endif - if (semanticdone) + if (semanticdone && + // This for when a class/struct contains mixin members, and + // is done over because of forward references + !toParent()->isAggregateDeclaration()) + { +#if LOG + printf("\tsemantic done\n"); +#endif return; - semanticdone = 1; + } + if (!semanticdone) + semanticdone = 1; #if LOG printf("\tdo semantic\n"); #endif @@ -2898,7 +2917,7 @@ { Dsymbol *s = (Dsymbol *)members->data[i]; #if LOG -printf("\tmember '%s', kind = '%s'\n", s->toChars(), s->kind()); + printf("\tmember '%s', kind = '%s'\n", s->toChars(), s->kind()); #endif s->semantic2(sc); } diff -uNr dmd-0.162/dmd/src/dmd/template.h dmd-0.163/dmd/src/dmd/template.h --- dmd-0.162/dmd/src/dmd/template.h 2006-06-30 00:16:30.000000000 +0200 +++ dmd-0.163/dmd/src/dmd/template.h 2006-07-07 01:10:36.000000000 +0200 @@ -54,11 +54,11 @@ void emitComment(Scope *sc); // void toDocBuffer(OutBuffer *buf); - MATCH matchWithInstance(TemplateInstance *ti, Array *atypes, int flag); + MATCH matchWithInstance(TemplateInstance *ti, Objects *atypes, int flag); int leastAsSpecialized(TemplateDeclaration *td2); - MATCH deduceMatch(Array *targsi, Array *fargs, Array *dedargs); - FuncDeclaration *deduce(Scope *sc, Loc loc, Array *targsi, Expressions *fargs); + MATCH deduceMatch(Objects *targsi, Expressions *fargs, Objects *dedargs); + FuncDeclaration *deduce(Scope *sc, Loc loc, Objects *targsi, Expressions *fargs); void declareParameter(Scope *sc, TemplateParameter *tp, Object *o); TemplateDeclaration *isTemplateDeclaration() { return this; } @@ -98,7 +98,7 @@ /* Match actual argument against parameter. */ - virtual MATCH matchArg(Scope *sc, Object *oarg, int i, TemplateParameters *parameters, Array *dedtypes, Declaration **psparam) = 0; + virtual MATCH matchArg(Scope *sc, Object *oarg, int i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam) = 0; /* Create dummy argument based on parameter. */ @@ -123,7 +123,7 @@ Object *specialization(); Object *defaultArg(Scope *sc); int overloadMatch(TemplateParameter *); - MATCH matchArg(Scope *sc, Object *oarg, int i, TemplateParameters *parameters, Array *dedtypes, Declaration **psparam); + MATCH matchArg(Scope *sc, Object *oarg, int i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam); void *dummyArg(); }; @@ -149,7 +149,7 @@ Object *specialization(); Object *defaultArg(Scope *sc); int overloadMatch(TemplateParameter *); - MATCH matchArg(Scope *sc, Object *oarg, int i, TemplateParameters *parameters, Array *dedtypes, Declaration **psparam); + MATCH matchArg(Scope *sc, Object *oarg, int i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam); void *dummyArg(); }; @@ -176,7 +176,7 @@ Object *specialization(); Object *defaultArg(Scope *sc); int overloadMatch(TemplateParameter *); - MATCH matchArg(Scope *sc, Object *oarg, int i, TemplateParameters *parameters, Array *dedtypes, Declaration **psparam); + MATCH matchArg(Scope *sc, Object *oarg, int i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam); void *dummyArg(); }; @@ -187,10 +187,10 @@ * instance foo.bar.abc(int*, char, 10*10) */ Array idents; // Array of Identifiers [foo, bar, abc] - Array *tiargs; // Array of Types/Expressions of template + Objects *tiargs; // Array of Types/Expressions of template // instance arguments [int*, char, 10*10] - Array tdtypes; // Array of Types/Expressions corresponding + Objects tdtypes; // Array of Types/Expressions corresponding // to TemplateDeclaration.parameters // [int, char, 100] @@ -211,7 +211,7 @@ #endif TemplateInstance(Loc loc, Identifier *temp_id); - TemplateInstance(Loc loc, TemplateDeclaration *tempdecl, Array *tiargs); + TemplateInstance(Loc loc, TemplateDeclaration *tempdecl, Objects *tiargs); Dsymbol *syntaxCopy(Dsymbol *); void addIdent(Identifier *ident); void semantic(Scope *sc); @@ -244,7 +244,7 @@ Scope *scope; // for forward referencing - TemplateMixin(Loc loc, Identifier *ident, TypeTypeof *tqual, Array *idents, Array *tiargs); + TemplateMixin(Loc loc, Identifier *ident, TypeTypeof *tqual, Array *idents, Objects *tiargs); Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); void semantic2(Scope *sc); diff -uNr dmd-0.162/dmd/src/dmd/todt.c dmd-0.163/dmd/src/dmd/todt.c --- dmd-0.162/dmd/src/dmd/todt.c 2006-01-03 03:06:30.000000000 +0100 +++ dmd-0.163/dmd/src/dmd/todt.c 2006-07-12 17:25:10.000000000 +0200 @@ -625,7 +625,12 @@ init = v->init; if (init) { //printf("\t\t%s has initializer %s\n", v->toChars(), init->toChars()); - dt = init->toDt(); + ExpInitializer *ei = init->isExpInitializer(); + Type *tb = v->type->toBasetype(); + if (ei && tb->ty == Tsarray) + ((TypeSArray *)tb)->toDtElem(&dt, ei->exp); + else + dt = init->toDt(); } else if (v->offset >= offset) { //printf("\t\tdefault initializer\n"); @@ -698,7 +703,12 @@ init = v->init; if (init) { //printf("\t\thas initializer %s\n", init->toChars()); - dt = init->toDt(); + ExpInitializer *ei = init->isExpInitializer(); + Type *tb = v->type->toBasetype(); + if (ei && tb->ty == Tsarray) + ((TypeSArray *)tb)->toDtElem(&dt, ei->exp); + else + dt = init->toDt(); } else if (v->offset >= offset) v->type->toDt(&dt); @@ -733,6 +743,11 @@ dt_t **TypeSArray::toDt(dt_t **pdt) { + return toDtElem(pdt, NULL); +} + +dt_t **TypeSArray::toDtElem(dt_t **pdt, Expression *e) +{ int i; unsigned len; @@ -751,7 +766,8 @@ tnext = tbn->next; tbn = tnext->toBasetype(); } - Expression *e = tnext->defaultInit(); + if (!e) // if not already supplied + e = tnext->defaultInit(); // use default initializer if (tbn->ty == Tbit) { Bits databits; diff -uNr dmd-0.162/dmd/src/phobos/internal/object.d dmd-0.163/dmd/src/phobos/internal/object.d --- dmd-0.162/dmd/src/phobos/internal/object.d 2006-06-30 17:13:56.000000000 +0200 +++ dmd-0.163/dmd/src/phobos/internal/object.d 2006-07-18 12:58:44.000000000 +0200 @@ -112,7 +112,9 @@ int opCmp(Object o) { // BUG: this prevents a compacting GC from working, needs to be fixed - return cast(int)cast(void *)this - cast(int)cast(void *)o; + //return cast(int)cast(void *)this - cast(int)cast(void *)o; + + throw new Error("need opCmp for class " ~ this.classinfo.name); } /** diff -uNr dmd-0.162/dmd/src/phobos/std/c/linux/linux.d dmd-0.163/dmd/src/phobos/std/c/linux/linux.d --- dmd-0.162/dmd/src/phobos/std/c/linux/linux.d 2006-06-30 17:13:56.000000000 +0200 +++ dmd-0.163/dmd/src/phobos/std/c/linux/linux.d 2006-07-18 12:58:44.000000000 +0200 @@ -8,7 +8,7 @@ module std.c.linux.linux; -import std.c.linux.linuxextern; +public import std.c.linux.linuxextern; alias int pid_t; alias int off_t; diff -uNr dmd-0.162/dmd/src/phobos/std/regexp.d dmd-0.163/dmd/src/phobos/std/regexp.d --- dmd-0.162/dmd/src/phobos/std/regexp.d 2006-06-30 17:13:54.000000000 +0200 +++ dmd-0.163/dmd/src/phobos/std/regexp.d 2006-07-18 12:58:44.000000000 +0200 @@ -2961,7 +2961,7 @@ // Static version that doesn't require a RegExp object to be created -private static rchar[] replace3(rchar[] format, rchar[] input, regmatch_t[] pmatch) +public static rchar[] replace3(rchar[] format, rchar[] input, regmatch_t[] pmatch) { rchar[] result; uint c2; diff -uNr dmd-0.162/dmd/src/phobos/std/stdio.d dmd-0.163/dmd/src/phobos/std/stdio.d --- dmd-0.162/dmd/src/phobos/std/stdio.d 2006-06-30 17:13:54.000000000 +0200 +++ dmd-0.163/dmd/src/phobos/std/stdio.d 2006-07-18 12:58:44.000000000 +0200 @@ -14,9 +14,10 @@ module std.stdio; -import std.c.stdio; -private import std.format; -private import std.utf; +public import std.c.stdio; + +import std.format; +import std.utf; version (DigitalMars) { diff -uNr dmd-0.162/dmd/src/phobos/std/stream.d dmd-0.163/dmd/src/phobos/std/stream.d --- dmd-0.162/dmd/src/phobos/std/stream.d 2006-06-30 17:13:54.000000000 +0200 +++ dmd-0.163/dmd/src/phobos/std/stream.d 2006-07-18 12:58:44.000000000 +0200 @@ -72,6 +72,7 @@ import std.system; // for Endian enumeration import std.intrinsic; // for bswap import std.utf; + import std.stdarg; } version (Windows) {