diff -uNr dmd-0.120/dmd/src/dmd/attrib.c dmd-0.121/dmd/src/dmd/attrib.c --- dmd-0.120/dmd/src/dmd/attrib.c 2005-04-01 16:07:38.000000000 +0200 +++ dmd-0.121/dmd/src/dmd/attrib.c 2005-04-12 21:51:34.000000000 +0200 @@ -556,9 +556,10 @@ /********************************* PragmaDeclaration ****************************/ -PragmaDeclaration::PragmaDeclaration(Identifier *ident, Array *args, Array *decl) +PragmaDeclaration::PragmaDeclaration(Loc loc, Identifier *ident, Array *args, Array *decl) : AttribDeclaration(decl) { + this->loc = loc; this->ident = ident; this->args = args; } @@ -568,13 +569,14 @@ PragmaDeclaration *pd; assert(!s); - pd = new PragmaDeclaration(ident, + pd = new PragmaDeclaration(loc, ident, Expression::arraySyntaxCopy(args), Dsymbol::arraySyntaxCopy(decl)); return pd; } void PragmaDeclaration::semantic(Scope *sc) -{ +{ // Should be merged with PragmaStatement + //printf("\tPragmaDeclaration::semantic '%s'\n",toChars()); if (ident == Id::msg) { @@ -591,7 +593,7 @@ printf("%.*s", se->len, se->string); } else - error("string expected for pragma msg, not '%s'", e->toChars()); + error("string expected for message, not '%s'", e->toChars()); } printf("\n"); } @@ -599,7 +601,7 @@ else if (ident == Id::lib) { if (!args || args->dim != 1) - error("string argument expected for pragma(lib, \"libname\")"); + error("string expected for library name"); else { Expression *e = (Expression *)args->data[0]; @@ -607,7 +609,7 @@ e = e->semantic(sc); args->data[0] = (void *)e; if (e->op != TOKstring) - error("string expected for pragma msg, not '%s'", e->toChars()); + error("string expected for library name, not '%s'", e->toChars()); } } else @@ -624,6 +626,11 @@ } } +char *PragmaDeclaration::kind() +{ + return "pragma"; +} + void PragmaDeclaration::toObjFile() { if (ident == Id::lib) diff -uNr dmd-0.120/dmd/src/dmd/attrib.h dmd-0.121/dmd/src/dmd/attrib.h --- dmd-0.120/dmd/src/dmd/attrib.h 2005-03-08 22:58:04.000000000 +0100 +++ dmd-0.121/dmd/src/dmd/attrib.h 2005-04-12 10:17:32.000000000 +0200 @@ -99,13 +99,14 @@ }; struct PragmaDeclaration : AttribDeclaration -{ Identifier *ident; +{ Array *args; // array of Expression's - PragmaDeclaration(Identifier *ident, Array *args, Array *decl); + PragmaDeclaration(Loc loc, Identifier *ident, Array *args, Array *decl); Dsymbol *syntaxCopy(Dsymbol *s); void semantic(Scope *sc); void toCBuffer(OutBuffer *buf); + char *kind(); void toObjFile(); // compile to .obj file }; diff -uNr dmd-0.120/dmd/src/dmd/cast.c dmd-0.121/dmd/src/dmd/cast.c --- dmd-0.120/dmd/src/dmd/cast.c 2005-04-02 17:40:32.000000000 +0200 +++ dmd-0.121/dmd/src/dmd/cast.c 2005-04-09 01:45:40.000000000 +0200 @@ -933,6 +933,16 @@ else goto Lincompatible; } + else if ((t1->ty == Tsarray || t1->ty == Tarray) && + e2->op == TOKnull && t2->ty == Tpointer && t2->next->ty == Tvoid) + { + goto Lx1; + } + else if ((t2->ty == Tsarray || t2->ty == Tarray) && + e1->op == TOKnull && t1->ty == Tpointer && t1->next->ty == Tvoid) + { + goto Lx2; + } else if ((t1->ty == Tsarray || t1->ty == Tarray) && t1->implicitConvTo(t2)) { goto Lt2; @@ -980,6 +990,7 @@ else if (t1->ty == Tsarray && t2->ty == Tsarray && e2->implicitConvTo(t1->next->arrayOf())) { + Lx1: t = t1->next->arrayOf(); e1 = e1->castTo(t); e2 = e2->castTo(t); @@ -987,6 +998,7 @@ else if (t1->ty == Tsarray && t2->ty == Tsarray && e1->implicitConvTo(t2->next->arrayOf())) { + Lx2: t = t2->next->arrayOf(); e1 = e1->castTo(t); e2 = e2->castTo(t); diff -uNr dmd-0.120/dmd/src/dmd/class.c dmd-0.121/dmd/src/dmd/class.c --- dmd-0.120/dmd/src/dmd/class.c 2005-03-20 15:43:36.000000000 +0100 +++ dmd-0.121/dmd/src/dmd/class.c 2005-04-13 10:08:10.000000000 +0200 @@ -69,17 +69,41 @@ Module::moduleinfo = this; // BUG: What if this is the wrong TypeInfo, i.e. it is nested? - if (!Type::typeinfo && id == Id::TypeInfo) - Type::typeinfo = this; + if (id->toChars()[0] == 'T') + { + if (!Type::typeinfo && id == Id::TypeInfo) + Type::typeinfo = this; + + if (!Type::typeinfoclass && id == Id::TypeInfo_Class) + Type::typeinfoclass = this; + + if (!Type::typeinfostruct && id == Id::TypeInfo_Struct) + Type::typeinfostruct = this; + + if (!Type::typeinfotypedef && id == Id::TypeInfo_Typedef) + Type::typeinfotypedef = this; + + if (!Type::typeinfopointer && id == Id::TypeInfo_Pointer) + Type::typeinfopointer = this; - if (!Type::typeinfoclass && id == Id::TypeInfo_Class) - Type::typeinfoclass = this; + if (!Type::typeinfoarray && id == Id::TypeInfo_Array) + Type::typeinfoarray = this; - if (!Type::typeinfostruct && id == Id::TypeInfo_Struct) - Type::typeinfostruct = this; + if (!Type::typeinfostaticarray && id == Id::TypeInfo_StaticArray) + Type::typeinfostaticarray = this; - if (!Type::typeinfotypedef && id == Id::TypeInfo_Typedef) - Type::typeinfotypedef = this; + if (!Type::typeinfoassociativearray && id == Id::TypeInfo_AssociativeArray) + Type::typeinfoassociativearray = this; + + if (!Type::typeinfoenum && id == Id::TypeInfo_Enum) + Type::typeinfoenum = this; + + if (!Type::typeinfofunction && id == Id::TypeInfo_Function) + Type::typeinfofunction = this; + + if (!Type::typeinfodelegate && id == Id::TypeInfo_Delegate) + Type::typeinfodelegate = this; + } com = 0; #if 0 @@ -349,9 +373,9 @@ if (dtor && dtor->toParent() != this) dtor = NULL; - inv = (InvariantDeclaration *)search(Id::classInvariant, 0); - if (inv && inv->toParent() != this) - inv = NULL; +// inv = (InvariantDeclaration *)search(Id::classInvariant, 0); +// if (inv && inv->toParent() != this) +// inv = NULL; // Can be in base class aggNew = (NewDeclaration *)search(Id::classNew, 0); diff -uNr dmd-0.120/dmd/src/dmd/constfold.c dmd-0.121/dmd/src/dmd/constfold.c --- dmd-0.120/dmd/src/dmd/constfold.c 2005-04-02 18:00:04.000000000 +0200 +++ dmd-0.121/dmd/src/dmd/constfold.c 2005-04-15 01:02:50.000000000 +0200 @@ -311,6 +311,10 @@ n1 = e1->toInteger(); n2 = e2->toInteger(); + if (n2 == 0) + { error("divide by 0"); + n2 = 1; + } if (isunsigned()) n = ((d_uns64) n1) / ((d_uns64) n2); else diff -uNr dmd-0.120/dmd/src/dmd/declaration.c dmd-0.121/dmd/src/dmd/declaration.c --- dmd-0.120/dmd/src/dmd/declaration.c 2005-04-05 15:40:04.000000000 +0200 +++ dmd-0.121/dmd/src/dmd/declaration.c 2005-04-12 23:16:58.000000000 +0200 @@ -363,6 +363,7 @@ offset = 0; noauto = 0; nestedref = 0; + inuse = 0; } Dsymbol *VarDeclaration::syntaxCopy(Dsymbol *s) @@ -432,6 +433,10 @@ { error("override cannot be applied to variable"); } + else if (isAbstract()) + { + error("abstract cannot be applied to variable"); + } else { AnonymousAggregateDeclaration *aad = sc->anonAgg; @@ -582,7 +587,9 @@ { //printf("VarDeclaration::semantic2('%s')\n", toChars()); if (init && !sc->parent->isFuncDeclaration()) - { init = init->semantic(sc, type); + { inuse = 1; + init = init->semantic(sc, type); + inuse = 0; } } @@ -739,13 +746,62 @@ { } -/***************************** TypeInfoTypedefDeclaration ***********************/ +/***************************** TypeInfoTypedefDeclaration *********************/ TypeInfoTypedefDeclaration::TypeInfoTypedefDeclaration(Type *tinfo) : TypeInfoDeclaration(tinfo, 0) { } +/***************************** TypeInfoPointerDeclaration *********************/ + +TypeInfoPointerDeclaration::TypeInfoPointerDeclaration(Type *tinfo) + : TypeInfoDeclaration(tinfo, 0) +{ +} + +/***************************** TypeInfoArrayDeclaration ***********************/ + +TypeInfoArrayDeclaration::TypeInfoArrayDeclaration(Type *tinfo) + : TypeInfoDeclaration(tinfo, 0) +{ +} + +/***************************** TypeInfoStaticArrayDeclaration *****************/ + +TypeInfoStaticArrayDeclaration::TypeInfoStaticArrayDeclaration(Type *tinfo) + : TypeInfoDeclaration(tinfo, 0) +{ +} + +/***************************** TypeInfoAssociativeArrayDeclaration ************/ + +TypeInfoAssociativeArrayDeclaration::TypeInfoAssociativeArrayDeclaration(Type *tinfo) + : TypeInfoDeclaration(tinfo, 0) +{ +} + +/***************************** TypeInfoEnumDeclaration ***********************/ + +TypeInfoEnumDeclaration::TypeInfoEnumDeclaration(Type *tinfo) + : TypeInfoDeclaration(tinfo, 0) +{ +} + +/***************************** TypeInfoFunctionDeclaration ********************/ + +TypeInfoFunctionDeclaration::TypeInfoFunctionDeclaration(Type *tinfo) + : TypeInfoDeclaration(tinfo, 0) +{ +} + +/***************************** TypeInfoDelegateDeclaration ********************/ + +TypeInfoDelegateDeclaration::TypeInfoDelegateDeclaration(Type *tinfo) + : TypeInfoDeclaration(tinfo, 0) +{ +} + /********************************* ThisDeclaration ****************************/ // For the "this" parameter to member functions diff -uNr dmd-0.120/dmd/src/dmd/declaration.h dmd-0.121/dmd/src/dmd/declaration.h --- dmd-0.120/dmd/src/dmd/declaration.h 2005-04-05 15:32:28.000000000 +0200 +++ dmd-0.121/dmd/src/dmd/declaration.h 2005-04-12 23:16:00.000000000 +0200 @@ -151,6 +151,7 @@ unsigned offset; int noauto; // no auto semantics int nestedref; // referenced by a lexically nested function + int inuse; VarDeclaration(Loc loc, Type *t, Identifier *id, Initializer *init); Dsymbol *syntaxCopy(Dsymbol *); @@ -239,6 +240,55 @@ void toDt(dt_t **pdt); }; +struct TypeInfoPointerDeclaration : TypeInfoDeclaration +{ + TypeInfoPointerDeclaration(Type *tinfo); + + void toDt(dt_t **pdt); +}; + +struct TypeInfoArrayDeclaration : TypeInfoDeclaration +{ + TypeInfoArrayDeclaration(Type *tinfo); + + void toDt(dt_t **pdt); +}; + +struct TypeInfoStaticArrayDeclaration : TypeInfoDeclaration +{ + TypeInfoStaticArrayDeclaration(Type *tinfo); + + void toDt(dt_t **pdt); +}; + +struct TypeInfoAssociativeArrayDeclaration : TypeInfoDeclaration +{ + TypeInfoAssociativeArrayDeclaration(Type *tinfo); + + void toDt(dt_t **pdt); +}; + +struct TypeInfoEnumDeclaration : TypeInfoDeclaration +{ + TypeInfoEnumDeclaration(Type *tinfo); + + void toDt(dt_t **pdt); +}; + +struct TypeInfoFunctionDeclaration : TypeInfoDeclaration +{ + TypeInfoFunctionDeclaration(Type *tinfo); + + void toDt(dt_t **pdt); +}; + +struct TypeInfoDelegateDeclaration : TypeInfoDeclaration +{ + TypeInfoDelegateDeclaration(Type *tinfo); + + void toDt(dt_t **pdt); +}; + struct ThisDeclaration : VarDeclaration { ThisDeclaration(Type *t); diff -uNr dmd-0.120/dmd/src/dmd/dsymbol.c dmd-0.121/dmd/src/dmd/dsymbol.c --- dmd-0.120/dmd/src/dmd/dsymbol.c 2005-04-01 16:16:16.000000000 +0200 +++ dmd-0.121/dmd/src/dmd/dsymbol.c 2005-04-12 22:55:12.000000000 +0200 @@ -35,6 +35,7 @@ this->parent = NULL; this->csym = NULL; this->isym = NULL; + this->loc = 0; } Dsymbol::Dsymbol(Identifier *ident) @@ -45,6 +46,7 @@ this->parent = NULL; this->csym = NULL; this->isym = NULL; + this->loc = 0; } int Dsymbol::equals(Object *o) @@ -114,7 +116,7 @@ Module *m = getModule(); - if (m) + if (m && m->srcfile) loc.filename = m->srcfile->toChars(); return loc.toChars(); } @@ -636,10 +638,10 @@ Dsymbol *DsymbolTable::lookup(Identifier *ident) { StringValue *sv; -//#ifdef DEBUG +#ifdef DEBUG assert(ident); assert(tab); -//#endif +#endif sv = tab->lookup((char*)ident->string, ident->len); return (Dsymbol *)(sv ? sv->ptrvalue : NULL); } diff -uNr dmd-0.120/dmd/src/dmd/entity.c dmd-0.121/dmd/src/dmd/entity.c --- dmd-0.120/dmd/src/dmd/entity.c 2005-03-14 13:48:26.000000000 +0100 +++ dmd-0.121/dmd/src/dmd/entity.c 2005-04-13 00:53:58.000000000 +0200 @@ -293,7 +293,8 @@ for (i = 0; i < sizeof(names) / sizeof(names[0]); i++) { // Entries are case sensitive - if (memcmp(names[i].name, (char *)p, length) == 0) + if (memcmp(names[i].name, (char *)p, length) == 0 && + !names[i].name[length]) return names[i].value; } return -1; diff -uNr dmd-0.120/dmd/src/dmd/expression.c dmd-0.121/dmd/src/dmd/expression.c --- dmd-0.120/dmd/src/dmd/expression.c 2005-04-05 16:43:36.000000000 +0200 +++ dmd-0.121/dmd/src/dmd/expression.c 2005-04-14 21:38:30.000000000 +0200 @@ -1011,8 +1011,10 @@ Package *pkg; Type *t; - //printf("DsymbolExp:: '%s' is a symbol\n", toChars()); + //printf("DsymbolExp:: %p '%s' is a symbol\n", this, toChars()); //printf("s = '%s', s->kind = '%s'\n", s->toChars(), s->kind()); + if (type) + return this; if (!s->isFuncDeclaration()) // functions are checked after overloading checkDeprecated(sc, s); s = s->toAlias(); @@ -1052,6 +1054,12 @@ { if (v->init) { + if (v->inuse) + { + error("circular reference to '%s'", v->toChars()); + type = Type::tint32; + return this; + } ExpInitializer *ei = v->init->isExpInitializer(); if (ei) { @@ -2485,7 +2493,7 @@ } else if (e1->type->ty == Tpointer && ident != Id::size && ident != Id::init && ident != Id::__sizeof && - ident != Id::alignof) + ident != Id::alignof && ident != Id::offsetof) { e = new PtrExp(loc, e1); e->type = e1->type->next; @@ -2958,6 +2966,8 @@ if (!cd || !cd->baseClass || !sc->func->isCtorDeclaration()) { error("super class constructor call must be in a constructor"); + type = Type::terror; + return this; } else { @@ -3117,6 +3127,12 @@ { UnaExp::semantic(sc); e1 = e1->toLvalue(NULL); + if (!e1->type) + { + error("cannot take address of %s", e1->toChars()); + type = Type::tint32; + return this; + } type = e1->type->pointerTo(); // See if this should really be a delegate @@ -3552,12 +3568,12 @@ if (lwr) { lwr = lwr->semantic(sc); lwr = resolveProperties(sc, lwr); - lwr = lwr->castTo(Type::tindex); // BUG: implicitCast? + lwr = lwr->implicitCastTo(Type::tindex); } if (upr) { upr = upr->semantic(sc); upr = resolveProperties(sc, upr); - upr = upr->castTo(Type::tindex); + upr = upr->implicitCastTo(Type::tindex); } if (t->ty == Tsarray || t->ty == Tarray) @@ -4263,7 +4279,7 @@ } else { - error("Can only concatenate arrays"); + error("Can only concatenate arrays, not %s ~= %s", tb1->toChars(), tb2->toChars()); type = Type::tint32; e = this; } diff -uNr dmd-0.120/dmd/src/dmd/func.c dmd-0.121/dmd/src/dmd/func.c --- dmd-0.120/dmd/src/dmd/func.c 2005-04-01 16:09:12.000000000 +0200 +++ dmd-0.121/dmd/src/dmd/func.c 2005-04-14 22:12:18.000000000 +0200 @@ -133,9 +133,9 @@ { // Verify no constructors, destructors, etc. if (isCtorDeclaration() || - isDtorDeclaration() || - //isInvariantDeclaration() || - isUnitTestDeclaration() + isDtorDeclaration() + //|| isInvariantDeclaration() + //|| isUnitTestDeclaration() ) { error("special member functions not allowed for %ss", sd->kind()); @@ -215,6 +215,9 @@ } #endif + if (storage_class & STCabstract) + cd->isabstract = 1; + // if static function, do not put in vtbl[] if (!isVirtual()) return; @@ -565,9 +568,19 @@ if (isCtorDeclaration()) { // Call invariant directly only if it exists - if (ad->inv) + InvariantDeclaration *inv = ad->inv; + ClassDeclaration *cd = ad->isClassDeclaration(); + + while (!inv && cd) { - e = new DsymbolExp(0, ad->inv); + cd = cd->baseClass; + if (!cd) + break; + inv = cd->inv; + } + if (inv) + { + e = new DsymbolExp(0, inv); e = new CallExp(0, e); e = e->semantic(sc2); } @@ -711,7 +724,17 @@ if (isDtorDeclaration()) { // Call invariant directly only if it exists - if (ad->inv) + InvariantDeclaration *inv = ad->inv; + ClassDeclaration *cd = ad->isClassDeclaration(); + + while (!inv && cd) + { + cd = cd->baseClass; + if (!cd) + break; + inv = cd->inv; + } + if (inv) { e = new DsymbolExp(0, ad->inv); e = new CallExp(0, e); @@ -1660,7 +1683,13 @@ if (!ad) { error("invariants only are for struct/union/class definitions"); + return; + } + else if (ad->inv) + { + error("more than one invariant for %s", ad->toChars()); } + ad->inv = this; type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd); sc->incontract++; @@ -1696,7 +1725,7 @@ static int n; char buffer[8+3*4+1]; - sprintf(buffer,"unittest%d", n); + sprintf(buffer,"__unittest%d", n); n++; return Lexer::idPool(buffer); } diff -uNr dmd-0.120/dmd/src/dmd/idgen.c dmd-0.121/dmd/src/dmd/idgen.c --- dmd-0.120/dmd/src/dmd/idgen.c 2005-03-26 00:42:22.000000000 +0100 +++ dmd-0.121/dmd/src/dmd/idgen.c 2005-04-11 22:35:08.000000000 +0200 @@ -64,7 +64,14 @@ { "TypeInfo" }, { "TypeInfo_Class" }, { "TypeInfo_Struct" }, + { "TypeInfo_Enum" }, { "TypeInfo_Typedef" }, + { "TypeInfo_Pointer" }, + { "TypeInfo_Array" }, + { "TypeInfo_StaticArray" }, + { "TypeInfo_AssociativeArray" }, + { "TypeInfo_Function" }, + { "TypeInfo_Delegate" }, { "_arguments" }, { "_argptr" }, diff -uNr dmd-0.120/dmd/src/dmd/init.c dmd-0.121/dmd/src/dmd/init.c --- dmd-0.120/dmd/src/dmd/init.c 2005-02-12 11:23:36.000000000 +0100 +++ dmd-0.121/dmd/src/dmd/init.c 2005-04-13 15:37:54.000000000 +0200 @@ -120,7 +120,8 @@ } else { - s = ad->symtab->lookup(id); + //s = ad->symtab->lookup(id); + s = ad->search(id, 0); if (!s) { error("'%s' is not a member of '%s'", id->toChars(), t->toChars()); diff -uNr dmd-0.120/dmd/src/dmd/lexer.c dmd-0.121/dmd/src/dmd/lexer.c --- dmd-0.120/dmd/src/dmd/lexer.c 2005-04-02 12:07:48.000000000 +0200 +++ dmd-0.121/dmd/src/dmd/lexer.c 2005-04-08 21:06:48.000000000 +0200 @@ -48,6 +48,9 @@ extern int isUniAlpha(unsigned u); extern int HtmlNamedEntity(unsigned char *p, int length); +#define LS 0x2028 // UTF line separator +#define PS 0x2029 // UTF paragraph separator + /******************************************** * Do our own char maps */ @@ -504,7 +507,10 @@ default: if (c & 0x80) - decodeUTF(); + { unsigned u = decodeUTF(); + if (u == PS || u == LS) + loc.linnum++; + } p++; continue; } @@ -537,7 +543,10 @@ default: if (c & 0x80) - decodeUTF(); + { unsigned u = decodeUTF(); + if (u == PS || u == LS) + break; + } continue; } break; @@ -594,7 +603,10 @@ default: if (c & 0x80) - decodeUTF(); + { unsigned u = decodeUTF(); + if (u == PS || u == LS) + loc.linnum++; + } p++; continue; } @@ -846,9 +858,18 @@ { unsigned char c = *p; if (c & 0x80) - { // Check for start of unicode identifier - if (isUniAlpha(decodeUTF())) + { unsigned u = decodeUTF(); + + // Check for start of unicode identifier + if (isUniAlpha(u)) goto case_ident; + + if (u == PS || u == LS) + { + loc.linnum++; + p++; + continue; + } } if (isprint(c)) error("unsupported char '%c'", c); @@ -1025,6 +1046,13 @@ break; default: + if (c & 0x80) + { p--; + unsigned u = decodeUTF(); + p++; + if (u == PS || u == LS) + loc.linnum++; + } break; } stringbuffer.writeByte(c); @@ -1088,6 +1116,15 @@ c -= 'a' - 10; else if (c >= 'A' && c <= 'F') c -= 'A' - 10; + else if (c & 0x80) + { p--; + unsigned u = decodeUTF(); + p++; + if (u == PS || u == LS) + loc.linnum++; + else + error("non-hex character \\u%x", u); + } else error("non-hex character '%c'", c); if (n & 1) @@ -1163,6 +1200,10 @@ { p--; c = decodeUTF(); + if (c == LS || c == PS) + { c = '\n'; + loc.linnum++; + } p++; stringbuffer.writeUTF8(c); continue; @@ -1207,6 +1248,7 @@ break; case '\n': + L1: loc.linnum++; case '\r': case 0: @@ -1221,6 +1263,8 @@ p--; c = decodeUTF(); p++; + if (c == LS || c == PS) + goto L1; if (c < 0xD800 || (c >= 0xE000 && c < 0xFFFE)) tk = TOKwcharv; else @@ -1848,6 +1892,7 @@ case 0: case 0x1A: case '\n': + Lnewline: loc.linnum = linnum; return; @@ -1889,6 +1934,11 @@ break; default: + if (c & 0x80) + { unsigned u = decodeUTF(); + if (u == PS || u == LS) + goto Lerr; + } stringbuffer.writeByte(c); p++; continue; @@ -1898,6 +1948,11 @@ continue; default: + if (*p & 0x80) + { unsigned u = decodeUTF(); + if (u == PS || u == LS) + goto Lnewline; + } goto Lerr; } } diff -uNr dmd-0.120/dmd/src/dmd/mars.c dmd-0.121/dmd/src/dmd/mars.c --- dmd-0.120/dmd/src/dmd/mars.c 2005-03-22 10:59:52.000000000 +0100 +++ dmd-0.121/dmd/src/dmd/mars.c 2005-04-08 21:06:06.000000000 +0200 @@ -49,7 +49,7 @@ copyright = "Copyright (c) 1999-2005 by Digital Mars"; written = "written by Walter Bright"; - version = "v0.120"; + version = "v0.121"; global.structalign = 8; memset(¶ms, 0, sizeof(Param)); diff -uNr dmd-0.120/dmd/src/dmd/module.c dmd-0.121/dmd/src/dmd/module.c --- dmd-0.120/dmd/src/dmd/module.c 2005-03-05 10:22:46.000000000 +0100 +++ dmd-0.121/dmd/src/dmd/module.c 2005-04-06 23:13:56.000000000 +0200 @@ -64,6 +64,7 @@ stest = NULL; sfilename = NULL; importedFrom = this; + srcfile = NULL; debuglevel = 0; debugids = NULL; diff -uNr dmd-0.120/dmd/src/dmd/mtype.c dmd-0.121/dmd/src/dmd/mtype.c --- dmd-0.120/dmd/src/dmd/mtype.c 2005-04-05 21:01:30.000000000 +0200 +++ dmd-0.121/dmd/src/dmd/mtype.c 2005-04-14 21:26:04.000000000 +0200 @@ -62,6 +62,13 @@ ClassDeclaration *Type::typeinfoclass; ClassDeclaration *Type::typeinfostruct; ClassDeclaration *Type::typeinfotypedef; +ClassDeclaration *Type::typeinfopointer; +ClassDeclaration *Type::typeinfoarray; +ClassDeclaration *Type::typeinfostaticarray; +ClassDeclaration *Type::typeinfoassociativearray; +ClassDeclaration *Type::typeinfoenum; +ClassDeclaration *Type::typeinfofunction; +ClassDeclaration *Type::typeinfodelegate; Type *Type::basic[TMAX]; unsigned char Type::mangleChar[TMAX]; @@ -468,6 +475,9 @@ Expression *Type::getProperty(Loc loc, Identifier *ident) { Expression *e; +#if LOGDOTEXP + printf("Type::getProperty(type = '%s', ident = '%s')\n", toChars(), ident->toChars()); +#endif if (ident == Id::__sizeof) { e = new IntegerExp(loc, size(loc), Type::tsize_t); @@ -1277,6 +1287,11 @@ if (flags & TFLAGScomplex && !(tob->flags & TFLAGScomplex)) return MATCHnomatch; + // Allow implicit conversion of real or imaginary to complex + if (flags & (TFLAGSreal | TFLAGSimaginary) && + tob->flags & TFLAGScomplex) + return MATCHconvert; + // Disallow implicit conversion to-from real and imaginary if ((flags & (TFLAGSreal | TFLAGSimaginary)) != (tob->flags & (TFLAGSreal | TFLAGSimaginary))) @@ -2806,8 +2821,10 @@ Dsymbol *s; Dsymbol *scopesym; + //printf("TypeIdentifier::toDsymbol('%s')\n", toChars()); if (!sc) return NULL; + //printf("ident = '%s'\n", ident->toChars()); s = sc->search(ident, &scopesym); if (s) { @@ -2817,6 +2834,7 @@ Dsymbol *sm; id = (Identifier *)idents.data[i]; + //printf("\tid = '%s'\n", id->toChars()); if (id->dyncast() != DYNCAST_IDENTIFIER) { // It's a template instance @@ -3131,12 +3149,10 @@ } void TypeEnum::toDecoBuffer(OutBuffer *buf) -{ unsigned len; - char *name; +{ char *name; - name = sym->toChars(); - len = strlen(name); - buf->printf("%c%d%s", mangleChar[ty], len, name); + name = sym->mangle(); + buf->printf("%c%s", mangleChar[ty], name); } void TypeEnum::toTypeInfoBuffer(OutBuffer *buf) diff -uNr dmd-0.120/dmd/src/dmd/mtype.h dmd-0.121/dmd/src/dmd/mtype.h --- dmd-0.120/dmd/src/dmd/mtype.h 2005-03-25 20:28:32.000000000 +0100 +++ dmd-0.121/dmd/src/dmd/mtype.h 2005-04-11 22:36:54.000000000 +0200 @@ -151,6 +151,13 @@ static ClassDeclaration *typeinfoclass; static ClassDeclaration *typeinfostruct; static ClassDeclaration *typeinfotypedef; + static ClassDeclaration *typeinfopointer; + static ClassDeclaration *typeinfoarray; + static ClassDeclaration *typeinfostaticarray; + static ClassDeclaration *typeinfoassociativearray; + static ClassDeclaration *typeinfoenum; + static ClassDeclaration *typeinfofunction; + static ClassDeclaration *typeinfodelegate; static Type *basic[TMAX]; static unsigned char mangleChar[TMAX]; @@ -286,6 +293,7 @@ Expression *defaultInit(); dt_t **toDt(dt_t **pdt); MATCH deduceType(Type *tparam, Array *parameters, Array *atypes); + TypeInfoDeclaration *getTypeInfoDeclaration(); type *toCtype(); type *toCParamtype(); @@ -308,6 +316,7 @@ int implicitConvTo(Type *to); Expression *defaultInit(); int builtinTypeInfo(); + TypeInfoDeclaration *getTypeInfoDeclaration(); type *toCtype(); }; @@ -327,6 +336,7 @@ Expression *defaultInit(); MATCH deduceType(Type *tparam, Array *parameters, Array *atypes); int checkBoolean(); + TypeInfoDeclaration *getTypeInfoDeclaration(); // Back end Symbol *aaGetSymbol(char *func, int flags); @@ -345,6 +355,7 @@ int isscalar(); Expression *defaultInit(); int isZeroInit(); + TypeInfoDeclaration *getTypeInfoDeclaration(); type *toCtype(); }; @@ -379,6 +390,7 @@ void toCBuffer2(OutBuffer *buf, Identifier *ident); void argsToCBuffer(OutBuffer *buf); MATCH deduceType(Type *tparam, Array *parameters, Array *atypes); + TypeInfoDeclaration *getTypeInfoDeclaration(); int callMatch(Array *toargs); type *toCtype(); @@ -397,6 +409,7 @@ Expression *defaultInit(); int isZeroInit(); int checkBoolean(); + TypeInfoDeclaration *getTypeInfoDeclaration(); type *toCtype(); }; @@ -506,6 +519,7 @@ Expression *defaultInit(); int isZeroInit(); MATCH deduceType(Type *tparam, Array *parameters, Array *atypes); + TypeInfoDeclaration *getTypeInfoDeclaration(); type *toCtype(); }; diff -uNr dmd-0.120/dmd/src/dmd/opover.c dmd-0.121/dmd/src/dmd/opover.c --- dmd-0.120/dmd/src/dmd/opover.c 2005-02-10 02:10:42.000000000 +0100 +++ dmd-0.121/dmd/src/dmd/opover.c 2005-04-14 21:51:16.000000000 +0200 @@ -400,7 +400,9 @@ if (s) { Dsymbol *s2; + //printf("search_function: s = '%s'\n", s->kind()); s2 = s->toAlias(); + //printf("search_function: s2 = '%s'\n", s2->kind()); fd = s2->isFuncDeclaration(); if (fd && fd->type->ty == Tfunction) return fd; diff -uNr dmd-0.120/dmd/src/dmd/parse.c dmd-0.121/dmd/src/dmd/parse.c --- dmd-0.120/dmd/src/dmd/parse.c 2005-04-04 16:17:22.000000000 +0200 +++ dmd-0.121/dmd/src/dmd/parse.c 2005-04-12 22:25:20.000000000 +0200 @@ -335,7 +335,7 @@ a = NULL; else a = parseBlock(); - s = new PragmaDeclaration(ident, args, a); + s = new PragmaDeclaration(loc, ident, args, a); break; } @@ -818,7 +818,8 @@ } else { if (hasdefault) - error("default argument expected for parameter '%s'", ai->toChars()); + error("default argument expected for %s", + ai ? ai->toChars() : at->toChars()); ae = NULL; } a = new Argument(inout, at, ai, ae); diff -uNr dmd-0.120/dmd/src/dmd/statement.c dmd-0.121/dmd/src/dmd/statement.c --- dmd-0.120/dmd/src/dmd/statement.c 2005-04-05 15:50:48.000000000 +0200 +++ dmd-0.121/dmd/src/dmd/statement.c 2005-04-12 10:30:42.000000000 +0200 @@ -325,6 +325,7 @@ s = s->semantic(sc); statements->data[i + 1] = s; statements->setDim(i + 2); + break; } } } @@ -1141,7 +1142,7 @@ } Statement *PragmaStatement::semantic(Scope *sc) -{ +{ // Should be merged with PragmaDeclaration if (ident == Id::msg) { if (args) @@ -1157,11 +1158,25 @@ printf("%.*s", se->len, se->string); } else - error("string expected for pragma msg, not '%s'", e->toChars()); + error("string expected for message, not '%s'", e->toChars()); } printf("\n"); } } + else if (ident == Id::lib) + { + if (!args || args->dim != 1) + error("string expected for library name"); + else + { + Expression *e = (Expression *)args->data[0]; + + e = e->semantic(sc); + args->data[0] = (void *)e; + if (e->op != TOKstring) + error("string expected for library name, not '%s'", e->toChars()); + } + } else error("unrecognized pragma(%s)", ident->toChars()); @@ -1237,6 +1252,8 @@ Statement *SwitchStatement::semantic(Scope *sc) { + //printf("SwitchStatement::semantic(%p)\n", this); + assert(!cases); // ensure semantic() is only run once condition = condition->semantic(sc); condition = resolveProperties(sc, condition); if (condition->type->isString()) @@ -1445,7 +1462,9 @@ if (sc->sw) { if (sc->sw->sdefault) + { error("switch statement already has a default"); + } sc->sw->sdefault = this; } else diff -uNr dmd-0.120/dmd/src/dmd/struct.c dmd-0.121/dmd/src/dmd/struct.c --- dmd-0.120/dmd/src/dmd/struct.c 2005-04-01 16:16:00.000000000 +0200 +++ dmd-0.121/dmd/src/dmd/struct.c 2005-04-12 22:00:30.000000000 +0200 @@ -234,6 +234,8 @@ handle = type->pointerTo(); structalign = sc->structalign; assert(!isAnonymous()); + if (sc->stc & STCabstract) + error("structs, unions cannot be abstract"); if (sizeok == 0) // if not already done the addMember step { @@ -250,7 +252,7 @@ sc2->parent = this; if (isUnionDeclaration()) sc2->inunion = 1; - sc2->stc &= ~(STCauto | STCstatic); + sc2->stc = 0; int members_dim = members->dim; for (i = 0; i < members_dim; i++) { diff -uNr dmd-0.120/dmd/src/dmd/template.c dmd-0.121/dmd/src/dmd/template.c --- dmd-0.120/dmd/src/dmd/template.c 2005-04-04 17:11:18.000000000 +0200 +++ dmd-0.121/dmd/src/dmd/template.c 2005-04-14 22:01:14.000000000 +0200 @@ -1291,7 +1291,7 @@ semanticTiargs(sc); tempdecl = findTemplateDeclaration(sc); - if (!tempdecl) + if (!tempdecl || global.errors) { inst = this; return; // error recovery } diff -uNr dmd-0.120/dmd/src/dmd/tocsym.c dmd-0.121/dmd/src/dmd/tocsym.c --- dmd-0.120/dmd/src/dmd/tocsym.c 2005-04-01 16:14:58.000000000 +0200 +++ dmd-0.121/dmd/src/dmd/tocsym.c 2005-04-15 01:23:10.000000000 +0200 @@ -265,7 +265,8 @@ id = mangle(); #endif //printf("FuncDeclaration::toSymbol(%s)\n", toChars()); - //printf("id = '%s'\n", id); + //printf("\tid = '%s'\n", id); + //printf("\ttype = %s\n", type->toChars()); s = symbol_calloc(id); slist_add(s); @@ -282,7 +283,7 @@ t = type->toCtype(); } - assert(t->Tmangle == 0); + mangle_t msave = t->Tmangle; if (isMain()) { t->Tty = TYnfunc; @@ -317,6 +318,8 @@ assert(0); } } + if (msave) + assert(msave == t->Tmangle); //printf("Tty = %d, mangle = x%x\n", t->Tty, t->Tmangle); t->Tcount++; s->Stype = t; diff -uNr dmd-0.120/dmd/src/dmd/typinf.c dmd-0.121/dmd/src/dmd/typinf.c --- dmd-0.120/dmd/src/dmd/typinf.c 2005-03-26 00:30:20.000000000 +0100 +++ dmd-0.121/dmd/src/dmd/typinf.c 2005-04-15 01:28:40.000000000 +0200 @@ -1,5 +1,4 @@ - // Copyright (c) 1999-2005 by Digital Mars // All Rights Reserved // written by Walter Bright @@ -126,6 +125,26 @@ return new TypeInfoTypedefDeclaration(this); } +TypeInfoDeclaration *TypePointer::getTypeInfoDeclaration() +{ + return new TypeInfoPointerDeclaration(this); +} + +TypeInfoDeclaration *TypeDArray::getTypeInfoDeclaration() +{ + return new TypeInfoArrayDeclaration(this); +} + +TypeInfoDeclaration *TypeSArray::getTypeInfoDeclaration() +{ + return new TypeInfoStaticArrayDeclaration(this); +} + +TypeInfoDeclaration *TypeAArray::getTypeInfoDeclaration() +{ + return new TypeInfoAssociativeArrayDeclaration(this); +} + TypeInfoDeclaration *TypeStruct::getTypeInfoDeclaration() { return new TypeInfoStructDeclaration(this); @@ -136,6 +155,21 @@ return new TypeInfoClassDeclaration(this); } +TypeInfoDeclaration *TypeEnum::getTypeInfoDeclaration() +{ + return new TypeInfoEnumDeclaration(this); +} + +TypeInfoDeclaration *TypeFunction::getTypeInfoDeclaration() +{ + return new TypeInfoFunctionDeclaration(this); +} + +TypeInfoDeclaration *TypeDelegate::getTypeInfoDeclaration() +{ + return new TypeInfoDelegateDeclaration(this); +} + /**************************************************** */ @@ -158,9 +192,134 @@ assert(tinfo->ty == Ttypedef); TypeTypedef *tc = (TypeTypedef *)tinfo; + TypedefDeclaration *sd = tc->sym; + + /* Put out: + * TypeInfo base; + * char[] name; + */ + + sd->basetype->getTypeInfo(NULL); + dtxoff(pdt, sd->basetype->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for basetype + + char *name = sd->toPrettyChars(); + size_t namelen = strlen(name); + dtdword(pdt, namelen); + dtabytes(pdt, TYnptr, 0, namelen + 1, name); +} + +void TypeInfoEnumDeclaration::toDt(dt_t **pdt) +{ + //printf("TypeInfoEnumDeclaration::toDt()\n"); + dtxoff(pdt, Type::typeinfoenum->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Enum + dtdword(pdt, 0); // monitor + + assert(tinfo->ty == Tenum); + + TypeEnum *tc = (TypeEnum *)tinfo; + EnumDeclaration *sd = tc->sym; + + /* Put out: + * TypeInfo base; + * char[] name; + */ + + sd->memtype->getTypeInfo(NULL); + dtxoff(pdt, sd->memtype->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for enum members + + char *name = sd->toPrettyChars(); + size_t namelen = strlen(name); + dtdword(pdt, namelen); + dtabytes(pdt, TYnptr, 0, namelen + 1, name); +} + +void TypeInfoPointerDeclaration::toDt(dt_t **pdt) +{ + //printf("TypeInfoPointerDeclaration::toDt()\n"); + dtxoff(pdt, Type::typeinfopointer->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Pointer + dtdword(pdt, 0); // monitor + + assert(tinfo->ty == Tpointer); + + TypePointer *tc = (TypePointer *)tinfo; + + tc->next->getTypeInfo(NULL); + dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for type being pointed to +} + +void TypeInfoArrayDeclaration::toDt(dt_t **pdt) +{ + //printf("TypeInfoArrayDeclaration::toDt()\n"); + dtxoff(pdt, Type::typeinfoarray->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Array + dtdword(pdt, 0); // monitor + + assert(tinfo->ty == Tarray); + + TypeDArray *tc = (TypeDArray *)tinfo; + + tc->next->getTypeInfo(NULL); + dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type +} + +void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt) +{ + //printf("TypeInfoStaticArrayDeclaration::toDt()\n"); + dtxoff(pdt, Type::typeinfostaticarray->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_StaticArray + dtdword(pdt, 0); // monitor + + assert(tinfo->ty == Tsarray); + + TypeSArray *tc = (TypeSArray *)tinfo; + + tc->next->getTypeInfo(NULL); + dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type - tc->sym->basetype->getTypeInfo(NULL); - dtxoff(pdt, tc->sym->basetype->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for basetype + dtdword(pdt, tc->dim->toInteger()); // length +} + +void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) +{ + //printf("TypeInfoAssociativeArrayDeclaration::toDt()\n"); + dtxoff(pdt, Type::typeinfoassociativearray->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_AssociativeArray + dtdword(pdt, 0); // monitor + + assert(tinfo->ty == Taarray); + + TypeAArray *tc = (TypeAArray *)tinfo; + + tc->next->getTypeInfo(NULL); + dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type + + tc->index->getTypeInfo(NULL); + dtxoff(pdt, tc->index->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type +} + +void TypeInfoFunctionDeclaration::toDt(dt_t **pdt) +{ + //printf("TypeInfoFunctionDeclaration::toDt()\n"); + dtxoff(pdt, Type::typeinfofunction->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Function + dtdword(pdt, 0); // monitor + + assert(tinfo->ty == Tfunction); + + TypeFunction *tc = (TypeFunction *)tinfo; + + tc->next->getTypeInfo(NULL); + dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for function return value +} + +void TypeInfoDelegateDeclaration::toDt(dt_t **pdt) +{ + //printf("TypeInfoDelegateDeclaration::toDt()\n"); + dtxoff(pdt, Type::typeinfodelegate->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Delegate + dtdword(pdt, 0); // monitor + + assert(tinfo->ty == Tdelegate); + + TypeDelegate *tc = (TypeDelegate *)tinfo; + + tc->next->next->getTypeInfo(NULL); + dtxoff(pdt, tc->next->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for delegate return value } void TypeInfoStructDeclaration::toDt(dt_t **pdt) @@ -234,7 +393,8 @@ if (fd) dtxoff(pdt, fd->toSymbol(), 0, TYnptr); else - fdx->error("must be declared as extern (D) uint toHash()"); + //fdx->error("must be declared as extern (D) uint toHash()"); + dtdword(pdt, 0); } else dtdword(pdt, 0); @@ -247,7 +407,8 @@ if (fd) dtxoff(pdt, fd->toSymbol(), 0, TYnptr); else - fdx->error("must be declared as extern (D) int %s(%s*)", fdx->toChars(), sd->toChars()); + //fdx->error("must be declared as extern (D) int %s(%s*)", fdx->toChars(), sd->toChars()); + dtdword(pdt, 0); } else dtdword(pdt, 0); diff -uNr dmd-0.120/dmd/src/dmd/version.c dmd-0.121/dmd/src/dmd/version.c --- dmd-0.120/dmd/src/dmd/version.c 2005-04-01 16:14:30.000000000 +0200 +++ dmd-0.121/dmd/src/dmd/version.c 2005-04-12 23:32:20.000000000 +0200 @@ -30,6 +30,14 @@ this->level = level; } +Dsymbol *DebugSymbol::syntaxCopy(Dsymbol *s) +{ + assert(!s); + DebugSymbol *ds = new DebugSymbol(ident); + ds->level = level; + return ds; +} + void DebugSymbol::addMember(ScopeDsymbol *sd) { //printf("DebugSymbol::addMember('%s') %s\n", sd->toChars(), toChars()); @@ -92,6 +100,14 @@ this->level = level; } +Dsymbol *VersionSymbol::syntaxCopy(Dsymbol *s) +{ + assert(!s); + VersionSymbol *ds = new VersionSymbol(ident); + ds->level = level; + return ds; +} + void VersionSymbol::addMember(ScopeDsymbol *sd) { //printf("VersionSymbol::addMember('%s') %s\n", sd->toChars(), toChars()); diff -uNr dmd-0.120/dmd/src/dmd/version.h dmd-0.121/dmd/src/dmd/version.h --- dmd-0.120/dmd/src/dmd/version.h 2004-08-30 01:40:32.000000000 +0200 +++ dmd-0.121/dmd/src/dmd/version.h 2005-04-12 23:32:22.000000000 +0200 @@ -24,6 +24,7 @@ DebugSymbol(Identifier *ident); DebugSymbol(unsigned level); + Dsymbol *syntaxCopy(Dsymbol *); void addMember(ScopeDsymbol *s); void semantic(Scope *sc); @@ -37,6 +38,7 @@ VersionSymbol(Identifier *ident); VersionSymbol(unsigned level); + Dsymbol *syntaxCopy(Dsymbol *); void addMember(ScopeDsymbol *s); void semantic(Scope *sc); diff -uNr dmd-0.120/dmd/src/phobos/internal/arraycat.d dmd-0.121/dmd/src/phobos/internal/arraycat.d --- dmd-0.120/dmd/src/phobos/internal/arraycat.d 2005-04-06 12:26:42.000000000 +0200 +++ dmd-0.121/dmd/src/phobos/internal/arraycat.d 2005-04-15 14:30:50.000000000 +0200 @@ -83,6 +83,31 @@ return a; } +bit[] _d_arraycatb(bit[] x, bit[] y) +{ bit[] a; + uint a_length; + uint x_bytes; + + if (!x.length) + return y; + if (!y.length) + return x; + + a_length = x.length + y.length; + a = new bit[a_length]; + x_bytes = (x.length + 7) >> 3; + memcpy(a.ptr, x.ptr, x_bytes); + if ((x.length & 7) == 0) + memcpy(cast(void*)a.ptr + x_bytes, y.ptr, (y.length + 7) >> 3); + else + { uint x_length = x.length; + uint y_length = y.length; + for (uint i = 0; i < y_length; i++) + a[x_length + i] = y[i]; + } + return a; +} + byte[] _d_arraycopy(uint size, byte[] from, byte[] to) { //printf("f = %p,%d, t = %p,%d, size = %d\n", (void*)from, from.length, (void*)to, to.length, size); @@ -155,3 +180,15 @@ return ba; } + +bit[] _d_arraysetbit2(bit[] ba, bit value) +{ + //printf("_d_arraysetbit2(ba.ptr = %p, ba.length = %d, value = %d)\n", ba.ptr, ba.length, value); + size_t len = ba.length; + uint val = -cast(int)value; + memset(ba.ptr, val, len >> 3); + for (uint i = len & ~7; i < len; i++) + ba[i] = value; + return ba; +} + diff -uNr dmd-0.120/dmd/src/phobos/internal/gc/gc.d dmd-0.121/dmd/src/phobos/internal/gc/gc.d --- dmd-0.120/dmd/src/phobos/internal/gc/gc.d 2005-04-06 12:26:44.000000000 +0200 +++ dmd-0.121/dmd/src/phobos/internal/gc/gc.d 2005-04-15 14:30:52.000000000 +0200 @@ -550,9 +550,9 @@ extern (C) byte[] _d_arrayappendc(inout byte[] x, in uint size, ...) { - uint cap = _gc.capacity(x); - uint length = x.length; - uint newlength = length + 1; + size_t cap = _gc.capacity(x); + size_t length = x.length; + size_t newlength = length + 1; if (newlength * size > cap) { byte* newdata; @@ -563,7 +563,7 @@ } byte *argp = cast(byte *)(&size + 1); - *cast(int *)&x = newlength; + *cast(size_t *)&x = newlength; (cast(byte *)x)[length * size .. newlength * size] = argp[0 .. size]; return x; @@ -588,3 +588,17 @@ } +extern (C) +bit[] _d_arrayappendcb(inout bit[] x, bit b) +{ + if (x.length & 7) + { + *cast(size_t *)&x = x.length + 1; + } + else + { + x.length = x.length + 1; + } + x[x.length - 1] = b; + return x; +} diff -uNr dmd-0.120/dmd/src/phobos/internal/object.d dmd-0.121/dmd/src/phobos/internal/object.d --- dmd-0.120/dmd/src/phobos/internal/object.d 2005-04-06 12:26:42.000000000 +0200 +++ dmd-0.121/dmd/src/phobos/internal/object.d 2005-04-15 14:30:50.000000000 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004 by Digital Mars, www.digitalmars.com + * Copyright (C) 2004-2005 by Digital Mars, www.digitalmars.com * Written by Walter Bright * * This software is provided 'as-is', without any express or implied @@ -27,11 +27,12 @@ extern (C) { int printf(char *, ...); int memcmp(void *, void *, size_t); + void* memcpy(void *, void *, size_t); } alias bit bool; -version (AMD64) +version (X86_64) { alias ulong size_t; alias long ptrdiff_t; @@ -139,6 +140,7 @@ class TypeInfo_Typedef : TypeInfo { + char[] toString() { return name; } uint getHash(void *p) { return base.getHash(p); } int equals(void *p1, void *p2) { return base.equals(p1, p2); } int compare(void *p1, void *p2) { return base.compare(p1, p2); } @@ -146,6 +148,228 @@ void swap(void *p1, void *p2) { return base.swap(p1, p2); } TypeInfo base; + char[] name; +} + +class TypeInfo_Enum : TypeInfo_Typedef +{ +} + +class TypeInfo_Pointer : TypeInfo +{ + char[] toString() { return next.toString() ~ "*"; } + + uint getHash(void *p) + { + return cast(uint)*cast(void* *)p; + } + + int equals(void *p1, void *p2) + { + return *cast(void* *)p1 == *cast(void* *)p2; + } + + int compare(void *p1, void *p2) + { + return *cast(void* *)p1 - *cast(void* *)p2; + } + + int tsize() + { + return (void*).sizeof; + } + + void swap(void *p1, void *p2) + { void* tmp; + tmp = *cast(void**)p1; + *cast(void**)p1 = *cast(void**)p2; + *cast(void**)p2 = tmp; + } + + TypeInfo next; +} + +class TypeInfo_Array : TypeInfo +{ + char[] toString() { return next.toString() ~ "[]"; } + + uint getHash(void *p) + { size_t sz = next.tsize(); + uint hash = 0; + void[] a = *cast(void[]*)p; + for (size_t i = 0; i < a.length; i++) + hash += next.getHash(a.ptr + i * sz); + return hash; + } + + int equals(void *p1, void *p2) + { + void[] a1 = *cast(void[]*)p1; + void[] a2 = *cast(void[]*)p2; + if (a1.length != a2.length) + return 0; + size_t sz = next.tsize(); + for (size_t i = 0; i < a1.length; i++) + { + if (!next.equals(a1.ptr + i * sz, a2.ptr + i * sz)) + return 0; + } + return 1; + } + + int compare(void *p1, void *p2) + { + void[] a1 = *cast(void[]*)p1; + void[] a2 = *cast(void[]*)p2; + size_t sz = next.tsize(); + size_t len = a1.length; + + if (a2.length < len) + len = a2.length; + for (size_t u = 0; u < len; u++) + { + int result = next.compare(a1.ptr + u * sz, a2.ptr + u * sz); + if (result) + return result; + } + return cast(int)a1.length - cast(int)a2.length; + } + + int tsize() + { + return (void[]).sizeof; + } + + void swap(void *p1, void *p2) + { void[] tmp; + tmp = *cast(void[]*)p1; + *cast(void[]*)p1 = *cast(void[]*)p2; + *cast(void[]*)p2 = tmp; + } + + TypeInfo next; +} + +class TypeInfo_StaticArray : TypeInfo +{ + char[] toString() + { + return next.toString() ~ "[" ~ std.string.toString(len) ~ "]"; + } + + uint getHash(void *p) + { size_t sz = next.tsize(); + uint hash = 0; + for (size_t i = 0; i < len; i++) + hash += next.getHash(p + i * sz); + return hash; + } + + int equals(void *p1, void *p2) + { + size_t sz = next.tsize(); + + for (size_t u = 0; u < len; u++) + { + if (!next.equals(p1 + u * sz, p2 + u * sz)) + return 0; + } + return 1; + } + + int compare(void *p1, void *p2) + { + size_t sz = next.tsize(); + + for (size_t u = 0; u < len; u++) + { + int result = next.compare(p1 + u * sz, p2 + u * sz); + if (result) + return result; + } + return 0; + } + + int tsize() + { + return len * next.tsize(); + } + + void swap(void *p1, void *p2) + { ubyte* tmp; + size_t sz = next.tsize(); + ubyte[16] buffer; + ubyte* pbuffer; + + if (sz < buffer.sizeof) + tmp = buffer; + else + tmp = pbuffer = new ubyte[sz]; + + for (size_t u = 0; u < len; u += sz) + { size_t o = u * sz; + memcpy(tmp, p1 + o, sz); + memcpy(p1 + o, p2 + o, sz); + memcpy(p2 + o, tmp, sz); + } + if (pbuffer) + delete pbuffer; + } + + TypeInfo next; + size_t len; +} + +class TypeInfo_AssociativeArray : TypeInfo +{ + char[] toString() + { + return next.toString() ~ "[" ~ key.toString() ~ "]"; + } + + // BUG: need to add the rest of the functions + + int tsize() + { + return (void[]).sizeof; + } + + TypeInfo next; + TypeInfo key; +} + +class TypeInfo_Function : TypeInfo +{ + char[] toString() + { + return next.toString() ~ "()"; + } + + // BUG: need to add the rest of the functions + + int tsize() + { + return 0; // no size for functions + } + + TypeInfo next; +} + +class TypeInfo_Delegate : TypeInfo +{ + char[] toString() + { + return next.toString() ~ " delegate()"; + } + + // BUG: need to add the rest of the functions + + int tsize() + { alias int delegate() dg; + return dg.sizeof; + } + + TypeInfo next; } class TypeInfo_Class : TypeInfo @@ -283,7 +507,7 @@ void print() { - printf("%.*s\n", msg); + printf("%.*s\n", toString()); } char[] toString() { return msg; } diff -uNr dmd-0.120/dmd/src/phobos/object.d dmd-0.121/dmd/src/phobos/object.d --- dmd-0.120/dmd/src/phobos/object.d 2005-04-06 12:26:40.000000000 +0200 +++ dmd-0.121/dmd/src/phobos/object.d 2005-04-15 14:30:46.000000000 +0200 @@ -5,7 +5,7 @@ alias bit bool; -version (AMD64) +version (X86_64) { alias ulong size_t; alias long ptrdiff_t; @@ -66,6 +66,43 @@ class TypeInfo_Typedef : TypeInfo { TypeInfo base; + char[] name; +} + +class TypeInfo_Enum : TypeInfo_Typedef +{ +} + +class TypeInfo_Pointer : TypeInfo +{ + TypeInfo next; +} + +class TypeInfo_Array : TypeInfo +{ + TypeInfo next; +} + +class TypeInfo_StaticArray : TypeInfo +{ + TypeInfo next; + size_t len; +} + +class TypeInfo_AssociativeArray : TypeInfo +{ + TypeInfo next; + TypeInfo key; +} + +class TypeInfo_Function : TypeInfo +{ + TypeInfo next; +} + +class TypeInfo_Delegate : TypeInfo +{ + TypeInfo next; } class TypeInfo_Class : TypeInfo diff -uNr dmd-0.120/dmd/src/phobos/std/c/windows/windows.d dmd-0.121/dmd/src/phobos/std/c/windows/windows.d --- dmd-0.120/dmd/src/phobos/std/c/windows/windows.d 2005-04-06 12:26:44.000000000 +0200 +++ dmd-0.121/dmd/src/phobos/std/c/windows/windows.d 2005-04-15 14:30:50.000000000 +0200 @@ -61,6 +61,7 @@ typedef void *HANDLE; alias void *PVOID; alias HANDLE HGLOBAL; + alias HANDLE HLOCAL; alias LONG HRESULT; alias LONG SCODE; alias HANDLE HINSTANCE; @@ -370,6 +371,18 @@ DWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize); } +struct MEMORYSTATUS { + DWORD dwLength; + DWORD dwMemoryLoad; + DWORD dwTotalPhys; + DWORD dwAvailPhys; + DWORD dwTotalPageFile; + DWORD dwAvailPageFile; + DWORD dwTotalVirtual; + DWORD dwAvailVirtual; +}; +alias MEMORYSTATUS *LPMEMORYSTATUS; + export { @@ -695,6 +708,25 @@ export { + BOOL GlobalUnlock(HGLOBAL hMem); + HGLOBAL GlobalFree(HGLOBAL hMem); + UINT GlobalCompact(DWORD dwMinFree); + void GlobalFix(HGLOBAL hMem); + void GlobalUnfix(HGLOBAL hMem); + LPVOID GlobalWire(HGLOBAL hMem); + BOOL GlobalUnWire(HGLOBAL hMem); + void GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer); + HLOCAL LocalAlloc(UINT uFlags, UINT uBytes); + HLOCAL LocalReAlloc(HLOCAL hMem, UINT uBytes, UINT uFlags); + LPVOID LocalLock(HLOCAL hMem); + HLOCAL LocalHandle(LPCVOID pMem); + BOOL LocalUnlock(HLOCAL hMem); + UINT LocalSize(HLOCAL hMem); + UINT LocalFlags(HLOCAL hMem); + HLOCAL LocalFree(HLOCAL hMem); + UINT LocalShrink(HLOCAL hMem, UINT cbNewSize); + UINT LocalCompact(UINT uMinFree); + BOOL FlushInstructionCache(HANDLE hProcess, LPCVOID lpBaseAddress, DWORD dwSize); LPVOID VirtualAlloc(LPVOID lpAddress, DWORD dwSize, DWORD flAllocationType, DWORD flProtect); BOOL VirtualFree(LPVOID lpAddress, DWORD dwSize, DWORD dwFreeType); BOOL VirtualProtect(LPVOID lpAddress, DWORD dwSize, DWORD flNewProtect, PDWORD lpflOldProtect); @@ -753,6 +785,221 @@ export DWORD GetTickCount(); export BOOL SetSystemTimeAdjustment(DWORD dwTimeAdjustment, BOOL bTimeAdjustmentDisabled); export BOOL GetSystemTimeAdjustment(DWORD* lpTimeAdjustment, DWORD* lpTimeIncrement, BOOL* lpTimeAdjustmentDisabled); +export DWORD FormatMessageA(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPSTR lpBuffer, DWORD nSize, void* *Arguments);export DWORD FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, void* *Arguments); + +enum +{ + FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100, + FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200, + FORMAT_MESSAGE_FROM_STRING = 0x00000400, + FORMAT_MESSAGE_FROM_HMODULE = 0x00000800, + FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000, + FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000, + FORMAT_MESSAGE_MAX_WIDTH_MASK = 0x000000FF, +}; + + +// +// Language IDs. +// +// The following two combinations of primary language ID and +// sublanguage ID have special semantics: +// +// Primary Language ID Sublanguage ID Result +// ------------------- --------------- ------------------------ +// LANG_NEUTRAL SUBLANG_NEUTRAL Language neutral +// LANG_NEUTRAL SUBLANG_DEFAULT User default language +// LANG_NEUTRAL SUBLANG_SYS_DEFAULT System default language +// + +// +// Primary language IDs. +// + +enum +{ + LANG_NEUTRAL = 0x00, + + LANG_AFRIKAANS = 0x36, + LANG_ALBANIAN = 0x1c, + LANG_ARABIC = 0x01, + LANG_BASQUE = 0x2d, + LANG_BELARUSIAN = 0x23, + LANG_BULGARIAN = 0x02, + LANG_CATALAN = 0x03, + LANG_CHINESE = 0x04, + LANG_CROATIAN = 0x1a, + LANG_CZECH = 0x05, + LANG_DANISH = 0x06, + LANG_DUTCH = 0x13, + LANG_ENGLISH = 0x09, + LANG_ESTONIAN = 0x25, + LANG_FAEROESE = 0x38, + LANG_FARSI = 0x29, + LANG_FINNISH = 0x0b, + LANG_FRENCH = 0x0c, + LANG_GERMAN = 0x07, + LANG_GREEK = 0x08, + LANG_HEBREW = 0x0d, + LANG_HUNGARIAN = 0x0e, + LANG_ICELANDIC = 0x0f, + LANG_INDONESIAN = 0x21, + LANG_ITALIAN = 0x10, + LANG_JAPANESE = 0x11, + LANG_KOREAN = 0x12, + LANG_LATVIAN = 0x26, + LANG_LITHUANIAN = 0x27, + LANG_NORWEGIAN = 0x14, + LANG_POLISH = 0x15, + LANG_PORTUGUESE = 0x16, + LANG_ROMANIAN = 0x18, + LANG_RUSSIAN = 0x19, + LANG_SERBIAN = 0x1a, + LANG_SLOVAK = 0x1b, + LANG_SLOVENIAN = 0x24, + LANG_SPANISH = 0x0a, + LANG_SWEDISH = 0x1d, + LANG_THAI = 0x1e, + LANG_TURKISH = 0x1f, + LANG_UKRAINIAN = 0x22, + LANG_VIETNAMESE = 0x2a, +} +// +// Sublanguage IDs. +// +// The name immediately following SUBLANG_ dictates which primary +// language ID that sublanguage ID can be combined with to form a +// valid language ID. +// +enum +{ + SUBLANG_NEUTRAL = 0x00, // language neutral + SUBLANG_DEFAULT = 0x01, // user default + SUBLANG_SYS_DEFAULT = 0x02, // system default + + SUBLANG_ARABIC_SAUDI_ARABIA = 0x01, // Arabic (Saudi Arabia) + SUBLANG_ARABIC_IRAQ = 0x02, // Arabic (Iraq) + SUBLANG_ARABIC_EGYPT = 0x03, // Arabic (Egypt) + SUBLANG_ARABIC_LIBYA = 0x04, // Arabic (Libya) + SUBLANG_ARABIC_ALGERIA = 0x05, // Arabic (Algeria) + SUBLANG_ARABIC_MOROCCO = 0x06, // Arabic (Morocco) + SUBLANG_ARABIC_TUNISIA = 0x07, // Arabic (Tunisia) + SUBLANG_ARABIC_OMAN = 0x08, // Arabic (Oman) + SUBLANG_ARABIC_YEMEN = 0x09, // Arabic (Yemen) + SUBLANG_ARABIC_SYRIA = 0x0a, // Arabic (Syria) + SUBLANG_ARABIC_JORDAN = 0x0b, // Arabic (Jordan) + SUBLANG_ARABIC_LEBANON = 0x0c, // Arabic (Lebanon) + SUBLANG_ARABIC_KUWAIT = 0x0d, // Arabic (Kuwait) + SUBLANG_ARABIC_UAE = 0x0e, // Arabic (U.A.E) + SUBLANG_ARABIC_BAHRAIN = 0x0f, // Arabic (Bahrain) + SUBLANG_ARABIC_QATAR = 0x10, // Arabic (Qatar) + SUBLANG_CHINESE_TRADITIONAL = 0x01, // Chinese (Taiwan) + SUBLANG_CHINESE_SIMPLIFIED = 0x02, // Chinese (PR China) + SUBLANG_CHINESE_HONGKONG = 0x03, // Chinese (Hong Kong) + SUBLANG_CHINESE_SINGAPORE = 0x04, // Chinese (Singapore) + SUBLANG_DUTCH = 0x01, // Dutch + SUBLANG_DUTCH_BELGIAN = 0x02, // Dutch (Belgian) + SUBLANG_ENGLISH_US = 0x01, // English (USA) + SUBLANG_ENGLISH_UK = 0x02, // English (UK) + SUBLANG_ENGLISH_AUS = 0x03, // English (Australian) + SUBLANG_ENGLISH_CAN = 0x04, // English (Canadian) + SUBLANG_ENGLISH_NZ = 0x05, // English (New Zealand) + SUBLANG_ENGLISH_EIRE = 0x06, // English (Irish) + SUBLANG_ENGLISH_SOUTH_AFRICA = 0x07, // English (South Africa) + SUBLANG_ENGLISH_JAMAICA = 0x08, // English (Jamaica) + SUBLANG_ENGLISH_CARIBBEAN = 0x09, // English (Caribbean) + SUBLANG_ENGLISH_BELIZE = 0x0a, // English (Belize) + SUBLANG_ENGLISH_TRINIDAD = 0x0b, // English (Trinidad) + SUBLANG_FRENCH = 0x01, // French + SUBLANG_FRENCH_BELGIAN = 0x02, // French (Belgian) + SUBLANG_FRENCH_CANADIAN = 0x03, // French (Canadian) + SUBLANG_FRENCH_SWISS = 0x04, // French (Swiss) + SUBLANG_FRENCH_LUXEMBOURG = 0x05, // French (Luxembourg) + SUBLANG_GERMAN = 0x01, // German + SUBLANG_GERMAN_SWISS = 0x02, // German (Swiss) + SUBLANG_GERMAN_AUSTRIAN = 0x03, // German (Austrian) + SUBLANG_GERMAN_LUXEMBOURG = 0x04, // German (Luxembourg) + SUBLANG_GERMAN_LIECHTENSTEIN = 0x05, // German (Liechtenstein) + SUBLANG_ITALIAN = 0x01, // Italian + SUBLANG_ITALIAN_SWISS = 0x02, // Italian (Swiss) + SUBLANG_KOREAN = 0x01, // Korean (Extended Wansung) + SUBLANG_KOREAN_JOHAB = 0x02, // Korean (Johab) + SUBLANG_NORWEGIAN_BOKMAL = 0x01, // Norwegian (Bokmal) + SUBLANG_NORWEGIAN_NYNORSK = 0x02, // Norwegian (Nynorsk) + SUBLANG_PORTUGUESE = 0x02, // Portuguese + SUBLANG_PORTUGUESE_BRAZILIAN = 0x01, // Portuguese (Brazilian) + SUBLANG_SERBIAN_LATIN = 0x02, // Serbian (Latin) + SUBLANG_SERBIAN_CYRILLIC = 0x03, // Serbian (Cyrillic) + SUBLANG_SPANISH = 0x01, // Spanish (Castilian) + SUBLANG_SPANISH_MEXICAN = 0x02, // Spanish (Mexican) + SUBLANG_SPANISH_MODERN = 0x03, // Spanish (Modern) + SUBLANG_SPANISH_GUATEMALA = 0x04, // Spanish (Guatemala) + SUBLANG_SPANISH_COSTA_RICA = 0x05, // Spanish (Costa Rica) + SUBLANG_SPANISH_PANAMA = 0x06, // Spanish (Panama) + SUBLANG_SPANISH_DOMINICAN_REPUBLIC = 0x07, // Spanish (Dominican Republic) + SUBLANG_SPANISH_VENEZUELA = 0x08, // Spanish (Venezuela) + SUBLANG_SPANISH_COLOMBIA = 0x09, // Spanish (Colombia) + SUBLANG_SPANISH_PERU = 0x0a, // Spanish (Peru) + SUBLANG_SPANISH_ARGENTINA = 0x0b, // Spanish (Argentina) + SUBLANG_SPANISH_ECUADOR = 0x0c, // Spanish (Ecuador) + SUBLANG_SPANISH_CHILE = 0x0d, // Spanish (Chile) + SUBLANG_SPANISH_URUGUAY = 0x0e, // Spanish (Uruguay) + SUBLANG_SPANISH_PARAGUAY = 0x0f, // Spanish (Paraguay) + SUBLANG_SPANISH_BOLIVIA = 0x10, // Spanish (Bolivia) + SUBLANG_SPANISH_EL_SALVADOR = 0x11, // Spanish (El Salvador) + SUBLANG_SPANISH_HONDURAS = 0x12, // Spanish (Honduras) + SUBLANG_SPANISH_NICARAGUA = 0x13, // Spanish (Nicaragua) + SUBLANG_SPANISH_PUERTO_RICO = 0x14, // Spanish (Puerto Rico) + SUBLANG_SWEDISH = 0x01, // Swedish + SUBLANG_SWEDISH_FINLAND = 0x02, // Swedish (Finland) +} +// +// Sorting IDs. +// + +enum +{ + SORT_DEFAULT = 0x0, // sorting default + + SORT_JAPANESE_XJIS = 0x0, // Japanese XJIS order + SORT_JAPANESE_UNICODE = 0x1, // Japanese Unicode order + + SORT_CHINESE_BIG5 = 0x0, // Chinese BIG5 order + SORT_CHINESE_PRCP = 0x0, // PRC Chinese Phonetic order + SORT_CHINESE_UNICODE = 0x1, // Chinese Unicode order + SORT_CHINESE_PRC = 0x2, // PRC Chinese Stroke Count order + + SORT_KOREAN_KSC = 0x0, // Korean KSC order + SORT_KOREAN_UNICODE = 0x1, // Korean Unicode order + + SORT_GERMAN_PHONE_BOOK = 0x1, // German Phone Book order +} + +// end_r_winnt + +// +// A language ID is a 16 bit value which is the combination of a +// primary language ID and a secondary language ID. The bits are +// allocated as follows: +// +// +-----------------------+-------------------------+ +// | Sublanguage ID | Primary Language ID | +// +-----------------------+-------------------------+ +// 15 10 9 0 bit +// +// +// Language ID creation/extraction macros: +// +// MAKELANGID - construct language id from a primary language id and +// a sublanguage id. +// PRIMARYLANGID - extract primary language id from a language id. +// SUBLANGID - extract sublanguage id from a language id. +// + +int MAKELANGID(int p, int s) { return ((cast(WORD)s) << 10) | cast(WORD)p; } +WORD PRIMARYLANGID(int lgid) { return cast(WORD)lgid & 0x3ff; } +WORD SUBLANGID(int lgid) { return cast(WORD)lgid >> 10; } + struct FLOATING_SAVE_AREA { DWORD ControlWord; @@ -1741,10 +1988,10 @@ /* * Window Styles */ -enum +enum : uint { WS_OVERLAPPED = 0x00000000, - WS_POPUP = cast(int)0x80000000, + WS_POPUP = 0x80000000, WS_CHILD = 0x40000000, WS_MINIMIZE = 0x20000000, WS_VISIBLE = 0x10000000, diff -uNr dmd-0.120/dmd/src/phobos/std/file.d dmd-0.121/dmd/src/phobos/std/file.d --- dmd-0.120/dmd/src/phobos/std/file.d 2005-04-06 12:26:40.000000000 +0200 +++ dmd-0.121/dmd/src/phobos/std/file.d 2005-04-15 14:30:48.000000000 +0200 @@ -28,12 +28,28 @@ private import std.path; private import std.string; +/* =========================== Win32 ======================= */ + +version (Win32) +{ + +private import std.c.windows.windows; +private import std.utf; +private import std.windows.syserror; + +int useWfuncs = 1; + +static this() +{ + // Win 95, 98, ME do not implement the W functions + useWfuncs = (GetVersion() < 0x80000000); +} + /*********************************** */ class FileException : Exception { - private import std.syserror; uint errno; // operating system error code @@ -49,7 +65,7 @@ this(char[] name, uint errno) { - this(name, SysError.msg(errno)); + this(name, sysErrorString(errno)); this.errno = errno; } } @@ -58,22 +74,6 @@ * Basic File operations. */ -/* =========================== Win32 ======================= */ - -version (Win32) -{ - -private import std.c.windows.windows; -private import std.utf; - -int useWfuncs = 1; - -static this() -{ - // Win 95, 98, ME do not implement the W functions - useWfuncs = (GetVersion() < 0x80000000); -} - /******************************************** * Read a file. * Returns: @@ -563,6 +563,33 @@ private import std.c.linux.linux; +extern (C) char* strerror(int); + +/*********************************** + */ + +class FileException : Exception +{ + + uint errno; // operating system error code + + this(char[] name) + { + this(name, "file I/O"); + } + + this(char[] name, char[] message) + { + super(name ~ ": " ~ message); + } + + this(char[] name, uint errno) + { char* s = strerror(errno); + this(name, std.string.toString(s).dup); + this.errno = errno; + } +} + /******************************************** * Read a file. * Returns: diff -uNr dmd-0.120/dmd/src/phobos/std/loader.d dmd-0.121/dmd/src/phobos/std/loader.d --- dmd-0.120/dmd/src/phobos/std/loader.d 2005-04-06 12:26:40.000000000 +0200 +++ dmd-0.121/dmd/src/phobos/std/loader.d 2005-04-15 14:30:48.000000000 +0200 @@ -73,7 +73,6 @@ private import std.string; private import std.c.stdlib; private import std.c.stdio; -private import std.syserror; //import synsoft.types; /+ + These are borrowed from synsoft.types, until such time as something similar is in Phobos ++ @@ -86,7 +85,8 @@ version(Windows) { - import std.c.windows.windows; + private import std.c.windows.windows; + private import std.windows.syserror; extern(Windows) { @@ -105,6 +105,8 @@ int dlclose(HModule_ handle); void *dlsym(HModule_ handle, char *symbolName); char *dlerror(); + + char* strerror(int); } } else @@ -265,7 +267,7 @@ private char[] ExeModule_Error_() { - return SysError.msg(s_lastError); + return sysErrorString(s_lastError); } private char[] ExeModule_GetPath_(HXModule hModule) @@ -493,7 +495,7 @@ this(uint errcode) { - super(SysError.msg(errcode)); + super(std.string.toString(strerror(errcode)).dup); } } diff -uNr dmd-0.120/dmd/src/phobos/std/math.d dmd-0.121/dmd/src/phobos/std/math.d --- dmd-0.120/dmd/src/phobos/std/math.d 2005-04-06 12:26:40.000000000 +0200 +++ dmd-0.121/dmd/src/phobos/std/math.d 2005-04-15 14:30:46.000000000 +0200 @@ -578,7 +578,7 @@ [-1.0, -.5, 1], [2.0, .5, 2], [155.67e20, 0x1.A5F1C2EB3FE4Fp-1, 74], // normal - [1.0e-320, 0x1.FAp-1, -1063], + [1.0e-320, 0.98829225, -1063], [real.min, .5, -16381], [real.min/2.0L, .5, -16382], // denormal @@ -601,7 +601,7 @@ int eptr; real v = frexp(x, eptr); - //printf("frexp(%Lg) = %Lg, should be %Lg, eptr = %d, should be %d\n", x, v, e, eptr, exp); + //printf("frexp(%Lg) = %.8Lg, should be %.8Lg, eptr = %d, should be %d\n", x, v, e, eptr, exp); assert(mfeq(e, v, .0000001)); assert(exp == eptr); } diff -uNr dmd-0.120/dmd/src/phobos/std/outofmemory.d dmd-0.121/dmd/src/phobos/std/outofmemory.d --- dmd-0.120/dmd/src/phobos/std/outofmemory.d 2005-04-06 12:26:40.000000000 +0200 +++ dmd-0.121/dmd/src/phobos/std/outofmemory.d 2005-04-15 14:30:48.000000000 +0200 @@ -1,16 +1,25 @@ module std.outofmemory; -class OutOfMemory : Object +class OutOfMemoryException : Exception { - void print() + static char[] s = "Out of memory"; + + this() + { + super(s); + } + + char[] toString() { - printf("Out of memory\n"); + return s; } } extern (C) void _d_OutOfMemory() { - throw cast(OutOfMemory)cast(void *)OutOfMemory.classinfo.init; + throw cast(OutOfMemoryException) + cast(void *) + OutOfMemoryException.classinfo.init; } diff -uNr dmd-0.120/dmd/src/phobos/std/regexp.d dmd-0.121/dmd/src/phobos/std/regexp.d --- dmd-0.120/dmd/src/phobos/std/regexp.d 2005-04-06 12:26:40.000000000 +0200 +++ dmd-0.121/dmd/src/phobos/std/regexp.d 2005-04-15 14:30:48.000000000 +0200 @@ -1877,6 +1877,8 @@ case RS.rliteral: r.setbit2(c); break; + default: + break; } rs = RS.start; continue; diff -uNr dmd-0.120/dmd/src/phobos/std/stream.d dmd-0.121/dmd/src/phobos/std/stream.d --- dmd-0.120/dmd/src/phobos/std/stream.d 2005-04-06 12:26:40.000000000 +0200 +++ dmd-0.121/dmd/src/phobos/std/stream.d 2005-04-15 14:30:48.000000000 +0200 @@ -1027,20 +1027,38 @@ // creates a string in memory containing copy of stream data override char[] toString() { - if (!readable || !seekable) + if (!readable) return super.toString(); - ulong pos = position(); + size_t pos; + size_t rdlen; + size_t blockSize; char[] result; - result.length = size(); - position(0); - readBlock(result, result.length); - position(pos); - return result; + if (seekable) { + ulong orig_pos = position(); + position(0); + blockSize = size(); + result = new char[blockSize]; + while (blockSize > 0) { + rdlen = readBlock(&result[pos], blockSize); + pos += rdlen; + blockSize -= rdlen; + } + position(orig_pos); + } else { + blockSize = 4096; + result = new char[blockSize]; + while ((rdlen = readBlock(&result[pos], blockSize)) > 0) { + pos += rdlen; + result.length = result.length + blockSize; + blockSize += rdlen; + } + } + return result[0 .. pos]; } // calculates CRC-32 of data in stream override uint toHash() { - if (!readable) + if (!readable || !seekable) return super.toHash(); ulong pos = position(); uint crc = init_crc32 (); @@ -1398,7 +1416,10 @@ version (Win32) { private import std.c.windows.windows; - extern (Windows) void FlushFileBuffers(HANDLE hFile); + extern (Windows) { + void FlushFileBuffers(HANDLE hFile); + DWORD GetFileType(HANDLE hFile); + } } version (linux) { private import std.c.linux.linux; @@ -1432,6 +1453,12 @@ this.hFile = hFile; readable = cast(bit)(mode & FileMode.In); writeable = cast(bit)(mode & FileMode.Out); + version(Windows) { + seekable = GetFileType(hFile) == 1; // FILE_TYPE_DISK + } else { + ulong result = lseek(hFile, 0, 0); + seekable = (result != ~0); + } } // opens file in requested mode @@ -1578,9 +1605,11 @@ override ulong seek(long offset, SeekPos rel) { assertSeekable(); version (Win32) { - uint result = SetFilePointer(hFile, offset, null, rel); - if (result == 0xFFFFFFFF) + int hi = cast(int)((offset>>32) & 0xFFFFFFFF); + uint low = SetFilePointer(hFile, offset, &hi, rel); + if ((low == INVALID_SET_FILE_POINTER) && (GetLastError() != 0)) throw new SeekException("unable to move file pointer"); + ulong result = (cast(ulong)hi << 32) + low; } else version (linux) { ulong result = lseek(hFile, offset, rel); if (result == 0xFFFFFFFF) diff -uNr dmd-0.120/dmd/src/phobos/std/string.d dmd-0.121/dmd/src/phobos/std/string.d --- dmd-0.120/dmd/src/phobos/std/string.d 2005-04-06 12:26:40.000000000 +0200 +++ dmd-0.121/dmd/src/phobos/std/string.d 2005-04-15 14:30:46.000000000 +0200 @@ -595,8 +595,9 @@ return -1; i += j; if (icmp(s[i + 1 .. i + sublength], subn) == 0) - break; + return i; } + i = -1; } else { @@ -605,8 +606,9 @@ for (i = 0; i < imax; i++) { if (icmp(s[i .. i + sublength], sub) == 0) - break; + return i; } + i = -1; } return i; } @@ -646,6 +648,11 @@ assert(i == 41); i = ifind(sPlts, sPlts); assert(i == 0); + + // Thanks to Carlos Santander B. and zwang + i = ifind("sus mejores cortesanos. Se embarcaron en el puerto de Dubai y", + "page-break-before"); + assert(i == -1); } /************************************* diff -uNr dmd-0.120/dmd/src/phobos/std/syserror.d dmd-0.121/dmd/src/phobos/std/syserror.d --- dmd-0.120/dmd/src/phobos/std/syserror.d 2005-04-06 12:26:40.000000000 +0200 +++ dmd-0.121/dmd/src/phobos/std/syserror.d 2005-04-15 14:30:48.000000000 +0200 @@ -1,11 +1,13 @@ -// Copyright (c) 2001-2004 by Digital Mars -// www.digitalmars.com +// Placed in public domain. +// Written by Walter Bright // Convert Win32 error code to string module std.syserror; -class SysError +// Deprecated - instead use std.windows.syserror.sysErrorString() + +deprecated class SysError { private import std.c.stdio; private import std.string; diff -uNr dmd-0.120/dmd/src/phobos/std/typeinfo/ti_Awchar.d dmd-0.121/dmd/src/phobos/std/typeinfo/ti_Awchar.d --- dmd-0.120/dmd/src/phobos/std/typeinfo/ti_Awchar.d 2005-04-06 12:26:42.000000000 +0200 +++ dmd-0.121/dmd/src/phobos/std/typeinfo/ti_Awchar.d 2005-04-15 14:30:48.000000000 +0200 @@ -50,11 +50,11 @@ { wchar[] s1 = *cast(wchar[]*)p1; wchar[] s2 = *cast(wchar[]*)p2; - uint len = s1.length; + size_t len = s1.length; if (s2.length < len) len = s2.length; - for (uint u = 0; u < len; u++) + for (size_t u = 0; u < len; u++) { int result = s1[u] - s2[u]; if (result) diff -uNr dmd-0.120/dmd/src/phobos/std/windows/syserror.d dmd-0.121/dmd/src/phobos/std/windows/syserror.d --- dmd-0.120/dmd/src/phobos/std/windows/syserror.d 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.121/dmd/src/phobos/std/windows/syserror.d 2005-04-15 14:30:50.000000000 +0200 @@ -0,0 +1,33 @@ + +// Placed in public domain +// Convert Win32 error code to string +// Based on code written by Regan Heath + +module std.windows.syserror; + +private import std.c.windows.windows; + +char[] sysErrorString(uint errcode) +{ + char[] result; + char* buffer; + DWORD r; + + r = FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + null, + errcode, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + cast(LPTSTR)&buffer, + 0, + null); + + /* Remove \r\n from error string */ + if (r >= 2) + r -= 2; + result = buffer[0..r].dup; + LocalFree(cast(HLOCAL)buffer); + return result; +} diff -uNr dmd-0.120/dmd/src/phobos/win32.mak dmd-0.121/dmd/src/phobos/win32.mak --- dmd-0.120/dmd/src/phobos/win32.mak 2005-04-06 12:26:38.000000000 +0200 +++ dmd-0.121/dmd/src/phobos/win32.mak 2005-04-15 14:30:46.000000000 +0200 @@ -64,7 +64,7 @@ iunknown.obj crc32.obj conv.obj arraycast.obj utf.obj uri.obj \ Czlib.obj Dzlib.obj zip.obj process.obj registry.obj recls.obj \ socket.obj socketstream.obj loader.obj stdarg.obj format.obj stdio.obj \ - perf.obj openrj.obj uni.obj winsock.obj \ + perf.obj openrj.obj uni.obj winsock.obj oldsyserror.obj \ ti_Aa.obj ti_Ag.obj ti_C.obj ti_int.obj ti_char.obj \ ti_wchar.obj ti_uint.obj ti_short.obj ti_ushort.obj \ ti_byte.obj ti_ubyte.obj ti_long.obj ti_ulong.obj ti_ptr.obj \ @@ -129,7 +129,7 @@ internal\object.d internal\trace.d internal\qsort2.d SRC_STD_WIN= std\windows\registry.d \ - std\windows\iunknown.d + std\windows\iunknown.d std\windows\syserror.d SRC_STD_C_WIN= std\c\windows\windows.d std\c\windows\com.d \ std\c\windows\winsock.d @@ -523,8 +523,8 @@ switcherr.obj : std\switcherr.d $(DMD) -c $(DFLAGS) std\switcherr.d -syserror.obj : std\syserror.d - $(DMD) -c $(DFLAGS) std\syserror.d +oldsyserror.obj : std\syserror.d + $(DMD) -c $(DFLAGS) std\syserror.d -ofoldsyserror.obj system.obj : std\system.d $(DMD) -c $(DFLAGS) std\system.d @@ -555,6 +555,9 @@ registry.obj : std\windows\registry.d $(DMD) -c $(DFLAGS) std\windows\registry.d +syserror.obj : std\windows\syserror.d + $(DMD) -c $(DFLAGS) std\windows\syserror.d + ### std\c stdarg.obj : std\c\stdarg.d