diff -uNr dmd-0.106/dmd/src/dmd/attrib.c dmd-0.107/dmd/src/dmd/attrib.c --- dmd-0.106/dmd/src/dmd/attrib.c 2004-11-04 21:31:20.000000000 +0100 +++ dmd-0.107/dmd/src/dmd/attrib.c 2004-11-11 12:30:00.000000000 +0100 @@ -230,7 +230,9 @@ if (decl) { unsigned stc_save = sc->stc; - sc->stc = stc; + if (stc & (STCauto | STCstatic | STCextern)) + sc->stc &= ~(STCauto | STCstatic | STCextern); + sc->stc |= stc; for (unsigned i = 0; i < decl->dim; i++) { Dsymbol *s = (Dsymbol *)decl->data[i]; diff -uNr dmd-0.106/dmd/src/dmd/cast.c dmd-0.107/dmd/src/dmd/cast.c --- dmd-0.106/dmd/src/dmd/cast.c 2004-08-28 16:31:04.000000000 +0200 +++ dmd-0.107/dmd/src/dmd/cast.c 2004-11-29 15:02:14.000000000 +0100 @@ -62,15 +62,61 @@ } if (t->ty == Tbit && isBit()) return MATCHconvert; + Expression *e = optimize(WANTvalue | WANTflags); + if (e != this) + { //printf("optimzed to %s\n", e->toChars()); + return e->implicitConvTo(t); + } return type->implicitConvTo(t); } int IntegerExp::implicitConvTo(Type *t) { +#if 0 + printf("IntegerExp::implicitConvTo(this=%s, type=%s, t=%s)\n", + toChars(), type->toChars(), t->toChars()); +#endif if (type->equals(t)) return MATCHexact; + switch (type->toBasetype()->ty) + { + case Tbit: + value &= 1; + break; + + case Tint8: + value = (signed char)value; + break; + + case Tchar: + case Tuns8: + value &= 0xFF; + break; + + case Tint16: + value = (short)value; + break; + + case Tuns16: + case Twchar: + value &= 0xFFFF; + break; + + case Tint32: + value = (int)value; + break; + + case Tuns32: + case Tdchar: + value &= 0xFFFFFFFF; + break; + + default: + break; + } + // Only allow conversion if no change in value switch(t->ty) { @@ -84,8 +130,9 @@ goto Lno; goto Lyes; - case Tascii: + case Tchar: case Tuns8: + //printf("value = %llu %llu\n", (integer_t)(unsigned char)value, value); if ((unsigned char)value != value) goto Lno; goto Lyes; @@ -106,40 +153,74 @@ goto Lyes; case Tuns32: - case Tdchar: if ((unsigned)value != value) goto Lno; goto Lyes; + case Tdchar: + if (value > 0x10FFFFUL) + goto Lno; + goto Lyes; + case Twchar: - if ((wchar_t)value != value) + if ((unsigned short)value != value) goto Lno; goto Lyes; case Tfloat32: case Tcomplex32: { - volatile float f = (float)value; - if (f != value) - goto Lno; + volatile float f; + if (type->isunsigned()) + { + f = (float)value; + if (f != value) + goto Lno; + } + else + { + f = (float)(long long)value; + if (f != (long long)value) + goto Lno; + } goto Lyes; } case Tfloat64: case Tcomplex64: { - volatile double d = (double)value; - if (d != value) - goto Lno; + volatile double f; + if (type->isunsigned()) + { + f = (double)value; + if (f != value) + goto Lno; + } + else + { + f = (double)(long long)value; + if (f != (long long)value) + goto Lno; + } goto Lyes; } case Tfloat80: case Tcomplex80: { - volatile long double ld = (long double)value; - if (ld != value) - goto Lno; + volatile long double f; + if (type->isunsigned()) + { + f = (long double)value; + if (f != value) + goto Lno; + } + else + { + f = (long double)(long long)value; + if (f != (long long)value) + goto Lno; + } goto Lyes; } } @@ -297,6 +378,10 @@ { Expression *e; Type *tb; +#if 0 + printf("Expression::castTo(this=%s, type=%s, t=%s)\n", + toChars(), type->toChars(), t->toChars()); +#endif e = this; tb = t->toBasetype(); type = type->toBasetype(); @@ -750,17 +835,32 @@ } else if (t1->isintegral() && t2->isintegral()) { - if (t1->ty > t2->ty) + //printf("t1 = %s, t2 = %s\n", t1->toChars(), t2->toChars()); + int sz1 = t1->size(); + int sz2 = t2->size(); + int sign1 = t1->isunsigned() == 0; + int sign2 = t2->isunsigned() == 0; + + if (sign1 == sign2) + { + if (sz1 < sz2) + goto Lt2; + else + goto Lt1; + } + if (!sign1) { - if (t1->ty >= Tuns32) - e2 = e2->castTo(t1); + if (sz1 >= sz2) + goto Lt1; + else + goto Lt2; } else { - if (t2->ty >= Tuns32) - { e1 = e1->castTo(t2); - t = t2; - } + if (sz2 >= sz1) + goto Lt2; + else + goto Lt1; } } else if (t1->ty == Tpointer && t2->ty == Tpointer) @@ -801,13 +901,11 @@ } else if ((t1->ty == Tsarray || t1->ty == Tarray) && t1->implicitConvTo(t2)) { - e1 = e1->castTo(t2); - t = t2; + goto Lt2; } else if ((t2->ty == Tsarray || t2->ty == Tarray) && t2->implicitConvTo(t1)) { - e2 = e2->castTo(t1); - t = t1; + goto Lt1; } else if (t1->ty == Tclass || t2->ty == Tclass) { int i1; @@ -827,26 +925,22 @@ if (i2) { - e1 = e1->castTo(t2); - t = t2; + goto Lt2; } else if (i1) { - e2 = e2->castTo(t1); - t = t1; + goto Lt1; } else goto Lincompatible; } else if ((e1->op == TOKstring || e1->op == TOKnull) && e1->implicitConvTo(t2)) { - e1 = e1->castTo(t2); - t = t2; + goto Lt2; } else if ((e2->op == TOKstring || e2->op == TOKnull) && e2->implicitConvTo(t1)) { - e2 = e2->castTo(t1); - t = t1; + goto Lt1; } else if (t1->ty == Tsarray && t2->ty == Tsarray && e2->implicitConvTo(t1->next->arrayOf())) @@ -869,10 +963,22 @@ e1->toChars(), Token::toChars(op), e2->toChars(), t1->toChars(), t2->toChars()); } +Lret: if (!type) type = t; //dump(0); return this; + + +Lt1: + e2 = e2->castTo(t1); + t = t1; + goto Lret; + +Lt2: + e1 = e1->castTo(t2); + t = t2; + goto Lret; } /*********************************** @@ -895,7 +1001,7 @@ case Tint16: case Tuns16: case Tbit: - case Tascii: + case Tchar: case Twchar: e = e->castTo(Type::tint32); break; diff -uNr dmd-0.106/dmd/src/dmd/class.c dmd-0.107/dmd/src/dmd/class.c --- dmd-0.106/dmd/src/dmd/class.c 2004-11-05 01:26:32.000000000 +0100 +++ dmd-0.107/dmd/src/dmd/class.c 2004-11-27 00:00:38.000000000 +0100 @@ -287,7 +287,9 @@ alignsize = 4; } structsize = sc->offset; - for (i = 0; i < members->dim; i++) + Scope scsave = *sc; + int members_dim = members->dim; + for (i = 0; i < members_dim; i++) { Dsymbol *s = (Dsymbol *)members->data[i]; s->semantic(sc); @@ -318,11 +320,12 @@ // this() { } if (!ctor && baseClass && baseClass->ctor) { - //printf("Creating default this(){} for class %s\n", toChars()); + printf("Creating default this(){} for class %s\n", toChars()); ctor = new CtorDeclaration(0, 0, NULL, 0); ctor->fbody = new CompoundStatement(0, new Array()); members->push(ctor); ctor->addMember(this); + *sc = scsave; ctor->semantic(sc); } diff -uNr dmd-0.106/dmd/src/dmd/constfold.c dmd-0.107/dmd/src/dmd/constfold.c --- dmd-0.106/dmd/src/dmd/constfold.c 2004-11-04 00:45:08.000000000 +0100 +++ dmd-0.107/dmd/src/dmd/constfold.c 2004-11-29 01:43:50.000000000 +0100 @@ -27,27 +27,32 @@ int Expression::isConst() { //printf("Expression::isConst(): %s\n", toChars()); - return FALSE; + return 0; } int IntegerExp::isConst() { - return TRUE; + return 1; } int RealExp::isConst() { - return TRUE; + return 1; } int ImaginaryExp::isConst() { - return TRUE; + return 1; } int ComplexExp::isConst() { - return TRUE; + return 1; +} + +int SymOffExp::isConst() +{ + return 2; } /* ================================== constFold() ============================== */ @@ -123,7 +128,8 @@ return new ComplexExp(loc, e1->toComplex(), type); if (type->isscalar()) return new IntegerExp(loc, e1->toInteger(), type); - error("cannot cast %s to %s", e1->type->toChars(), type->toChars()); + if (type->toBasetype()->ty != Tvoid) + error("cannot cast %s to %s", e1->type->toChars(), type->toChars()); return this; } @@ -134,6 +140,8 @@ //printf("AddExp::constFold(%s)\n", toChars()); e1 = e1->constFold(); e2 = e2->constFold(); + if (e1->op == TOKsymoff && e2->op == TOKsymoff) + return this; if (type->isreal()) { e = new RealExp(loc, e1->toReal() + e2->toReal(), type); @@ -169,6 +177,8 @@ e1 = e1->constFold(); e2 = e2->constFold(); + if (e2->op == TOKsymoff) + return this; if (type->isreal()) { e = new RealExp(loc, e1->toReal() - e2->toReal(), type); @@ -188,7 +198,9 @@ e->type = type; } else + { e = new IntegerExp(loc, e1->toInteger() - e2->toInteger(), type); + } return e; } diff -uNr dmd-0.106/dmd/src/dmd/declaration.c dmd-0.107/dmd/src/dmd/declaration.c --- dmd-0.106/dmd/src/dmd/declaration.c 2004-11-04 21:01:42.000000000 +0100 +++ dmd-0.107/dmd/src/dmd/declaration.c 2004-11-28 01:59:40.000000000 +0100 @@ -368,6 +368,7 @@ sv = new VarDeclaration(loc, type->syntaxCopy(), ident, init); sv->storage_class = storage_class; + //sv->storage_class |= storage_class & STCauto; } return sv; } @@ -382,6 +383,7 @@ //printf("this = %p, parent = %p, '%s'\n", this, parent, parent->toChars()); protection = sc->protection; storage_class |= sc->stc; + //printf("sc->stc = %x\n", sc->stc); //printf("storage_class = %x\n", storage_class); Dsymbol *parent = toParent(); @@ -448,7 +450,7 @@ cd->alignsize = memalignsize; storage_class |= STCfield; - //printf("2 Adding '%s' to '%s'\n", this->toChars(), cd->toChars()); + //printf("2 Adding '%s' to '%s', offset %d\n", this->toChars(), cd->toChars(), offset); cd->fields.push(this); } @@ -727,6 +729,7 @@ void TypeInfoDeclaration::semantic(Scope *sc) { + assert(linkage == LINKc); } /***************************** TypeInfoClassDeclaration ***********************/ diff -uNr dmd-0.106/dmd/src/dmd/expression.c dmd-0.107/dmd/src/dmd/expression.c --- dmd-0.106/dmd/src/dmd/expression.c 2004-11-04 01:05:14.000000000 +0100 +++ dmd-0.107/dmd/src/dmd/expression.c 2004-11-29 01:42:08.000000000 +0100 @@ -77,7 +77,7 @@ } if (!fd->isThis()) - { printf("test2 '%s'\n", fd->toChars()); + { //printf("test2 '%s'\n", fd->toChars()); goto Lno; } @@ -391,7 +391,7 @@ integer_t Expression::toInteger() { //printf("Expression %s\n", Token::toChars(op)); -//*(char*)0=0; +*(char*)0=0; error("Integer constant expression expected instead of %s", toChars()); return 0; } @@ -1314,6 +1314,20 @@ this->committed = 0; } +int StringExp::equals(Object *o) +{ + //printf("StringExp::equals('%s')\n", o->toChars()); + if (o && o->dyncast() == DYNCAST_EXPRESSION) + { Expression *e = (Expression *)o; + + if (e->op == TOKstring) + { + return compare(o) == 0; + } + } + return FALSE; +} + char *StringExp::toChars() { OutBuffer buf; @@ -1359,10 +1373,32 @@ { case 1: return strcmp((char *)string, (char *)se2->string); + case 2: - return wcscmp((wchar_t *)string, (wchar_t *)se2->string); + { unsigned u; + d_wchar *s1 = (d_wchar *)string; + d_wchar *s2 = (d_wchar *)se2->string; + + for (u = 0; u < len; u++) + { + if (s1[u] != s2[u]) + return s1[u] - s2[u]; + } + } + case 4: - /* not implemented */ + { unsigned u; + d_dchar *s1 = (d_dchar *)string; + d_dchar *s2 = (d_dchar *)se2->string; + + for (u = 0; u < len; u++) + { + if (s1[u] != s2[u]) + return s1[u] - s2[u]; + } + } + break; + default: assert(0); } @@ -1748,6 +1784,11 @@ return this; } +int SymOffExp::isBool(int result) +{ + return result ? TRUE : FALSE; +} + void SymOffExp::toCBuffer(OutBuffer *buf) { if (offset) @@ -1756,11 +1797,6 @@ buf->printf("&%s", var->toChars()); } -int SymOffExp::isConst() -{ - return TRUE; -} - /******************************** VarExp **************************/ VarExp::VarExp(Loc loc, Declaration *var) @@ -2582,6 +2618,7 @@ #if LOGSEMANTIC printf("DotTypeExp::semantic('%s')\n", toChars()); #endif + UnaExp::semantic(sc); return this; } @@ -4928,11 +4965,12 @@ return this; BinExp::semanticp(sc); - type = Type::tboolean; + //type = Type::tboolean; Type *t2b = e2->type->toBasetype(); if (t2b->ty != Taarray) { error("rvalue of in expression must be an associative array, not %s", e2->type->toChars()); + type = Type::terror; } else { @@ -4940,13 +4978,16 @@ // Convert key to type of key e1 = e1->implicitCastTo(ta->index); + + // Return type is pointer to value + type = ta->next->pointerTo(); } return this; } int InExp::isBit() { - return TRUE; + return FALSE; } diff -uNr dmd-0.106/dmd/src/dmd/expression.h dmd-0.107/dmd/src/dmd/expression.h --- dmd-0.106/dmd/src/dmd/expression.h 2004-09-15 00:23:00.000000000 +0200 +++ dmd-0.107/dmd/src/dmd/expression.h 2004-11-29 01:50:10.000000000 +0100 @@ -259,6 +259,7 @@ unsigned char committed; // !=0 if type is committed StringExp(Loc loc, void *s, unsigned len); + int equals(Object *o); char *toChars(); Expression *semantic(Scope *sc); int implicitConvTo(Type *t); @@ -328,6 +329,8 @@ Expression *semantic(Scope *sc); void toCBuffer(OutBuffer *buf); int isConst(); + int isBool(int result); + Expression *doInline(InlineDoState *ids); elem *toElem(IRState *irs); dt_t **toDt(dt_t **pdt); @@ -878,6 +881,7 @@ AddExp(Loc loc, Expression *e1, Expression *e2); Expression *semantic(Scope *sc); Expression *constFold(); + Expression *optimize(int result); // For operator overloading int isCommutative(); @@ -892,6 +896,7 @@ MinExp(Loc loc, Expression *e1, Expression *e2); Expression *semantic(Scope *sc); Expression *constFold(); + Expression *optimize(int result); // For operator overloading Identifier *opId(); diff -uNr dmd-0.106/dmd/src/dmd/idgen.c dmd-0.107/dmd/src/dmd/idgen.c --- dmd-0.106/dmd/src/dmd/idgen.c 2004-11-05 01:25:56.000000000 +0100 +++ dmd-0.107/dmd/src/dmd/idgen.c 2004-11-23 14:53:54.000000000 +0100 @@ -44,7 +44,9 @@ { "__sizeof", "sizeof" }, { "alignof" }, { "length" }, + { "ptr" }, { "offset" }, + { "offsetof" }, { "ModuleInfo" }, { "ClassInfo" }, { "classinfo" }, diff -uNr dmd-0.106/dmd/src/dmd/impcnvgen.c dmd-0.107/dmd/src/dmd/impcnvgen.c --- dmd-0.106/dmd/src/dmd/impcnvgen.c 2002-04-22 23:14:26.000000000 +0200 +++ dmd-0.107/dmd/src/dmd/impcnvgen.c 2004-11-29 03:05:20.000000000 +0100 @@ -16,6 +16,22 @@ enum TY impcnvType1[TMAX][TMAX]; enum TY impcnvType2[TMAX][TMAX]; +int integral_promotion(int t) +{ + switch (t) + { + case Tchar: + case Twchar: + case Tbit: + case Tint8: + case Tuns8: + case Tint16: + case Tuns16: return Tint32; + case Tdchar: return Tuns32; + default: return t; + } +} + void init() { int i, j; @@ -40,9 +56,9 @@ X(Tbit,Tint16, Tint32,Tint32, Tint32) X(Tbit,Tuns16, Tint32,Tint32, Tint32) X(Tbit,Tint32, Tint32,Tint32, Tint32) - X(Tbit,Tuns32, Tint32,Tuns32, Tint32) + X(Tbit,Tuns32, Tuns32,Tuns32, Tuns32) X(Tbit,Tint64, Tint64,Tint64, Tint64) - X(Tbit,Tuns64, Tint64,Tuns64, Tint64) + X(Tbit,Tuns64, Tuns64,Tuns64, Tuns64) X(Tbit,Tfloat32, Tfloat32,Tfloat32, Tfloat32) X(Tbit,Tfloat64, Tfloat64,Tfloat64, Tfloat64) @@ -56,15 +72,14 @@ /* ======================= */ - X(Tint8,Tbit, Tint32,Tint32, Tint32) X(Tint8,Tint8, Tint32,Tint32, Tint32) X(Tint8,Tuns8, Tint32,Tint32, Tint32) X(Tint8,Tint16, Tint32,Tint32, Tint32) X(Tint8,Tuns16, Tint32,Tint32, Tint32) X(Tint8,Tint32, Tint32,Tint32, Tint32) - X(Tint8,Tuns32, Tint32,Tuns32, Tint32) + X(Tint8,Tuns32, Tuns32,Tuns32, Tuns32) X(Tint8,Tint64, Tint64,Tint64, Tint64) - X(Tint8,Tuns64, Tint64,Tuns64, Tint64) + X(Tint8,Tuns64, Tuns64,Tuns64, Tuns64) X(Tint8,Tfloat32, Tfloat32,Tfloat32, Tfloat32) X(Tint8,Tfloat64, Tfloat64,Tfloat64, Tfloat64) @@ -78,15 +93,13 @@ /* ======================= */ - X(Tuns8,Tbit, Tint32,Tint32, Tint32) - X(Tuns8,Tint8, Tint32,Tint32, Tint32) X(Tuns8,Tuns8, Tint32,Tint32, Tint32) X(Tuns8,Tint16, Tint32,Tint32, Tint32) X(Tuns8,Tuns16, Tint32,Tint32, Tint32) X(Tuns8,Tint32, Tint32,Tint32, Tint32) - X(Tuns8,Tuns32, Tint32,Tuns32, Tint32) + X(Tuns8,Tuns32, Tuns32,Tuns32, Tuns32) X(Tuns8,Tint64, Tint64,Tint64, Tint64) - X(Tuns8,Tuns64, Tint64,Tuns64, Tint64) + X(Tuns8,Tuns64, Tuns64,Tuns64, Tuns64) X(Tuns8,Tfloat32, Tfloat32,Tfloat32, Tfloat32) X(Tuns8,Tfloat64, Tfloat64,Tfloat64, Tfloat64) @@ -100,15 +113,12 @@ /* ======================= */ - X(Tint16,Tbit, Tint32,Tint32, Tint32) - X(Tint16,Tint8, Tint32,Tint32, Tint32) - X(Tint16,Tuns8, Tint32,Tint32, Tint32) X(Tint16,Tint16, Tint32,Tint32, Tint32) X(Tint16,Tuns16, Tint32,Tint32, Tint32) X(Tint16,Tint32, Tint32,Tint32, Tint32) - X(Tint16,Tuns32, Tint32,Tuns32, Tint32) + X(Tint16,Tuns32, Tuns32,Tuns32, Tuns32) X(Tint16,Tint64, Tint64,Tint64, Tint64) - X(Tint16,Tuns64, Tint64,Tuns64, Tint64) + X(Tint16,Tuns64, Tuns64,Tuns64, Tuns64) X(Tint16,Tfloat32, Tfloat32,Tfloat32, Tfloat32) X(Tint16,Tfloat64, Tfloat64,Tfloat64, Tfloat64) @@ -122,15 +132,11 @@ /* ======================= */ - X(Tuns16,Tbit, Tint32,Tint32, Tint32) - X(Tuns16,Tint8, Tint32,Tint32, Tint32) - X(Tuns16,Tuns8, Tint32,Tint32, Tint32) - X(Tuns16,Tint16, Tint32,Tint32, Tint32) X(Tuns16,Tuns16, Tint32,Tint32, Tint32) X(Tuns16,Tint32, Tint32,Tint32, Tint32) - X(Tuns16,Tuns32, Tint32,Tuns32, Tint32) + X(Tuns16,Tuns32, Tuns32,Tuns32, Tuns32) X(Tuns16,Tint64, Tint64,Tint64, Tint64) - X(Tuns16,Tuns64, Tint64,Tuns64, Tint64) + X(Tuns16,Tuns64, Tuns64,Tuns64, Tuns64) X(Tuns16,Tfloat32, Tfloat32,Tfloat32, Tfloat32) X(Tuns16,Tfloat64, Tfloat64,Tfloat64, Tfloat64) @@ -144,15 +150,10 @@ /* ======================= */ - X(Tint32,Tbit, Tint32,Tint32, Tint32) - X(Tint32,Tint8, Tint32,Tint32, Tint32) - X(Tint32,Tuns8, Tint32,Tint32, Tint32) - X(Tint32,Tint16, Tint32,Tint32, Tint32) - X(Tint32,Tuns16, Tint32,Tint32, Tint32) X(Tint32,Tint32, Tint32,Tint32, Tint32) - X(Tint32,Tuns32, Tint32,Tuns32, Tint32) + X(Tint32,Tuns32, Tuns32,Tuns32, Tuns32) X(Tint32,Tint64, Tint64,Tint64, Tint64) - X(Tint32,Tuns64, Tint64,Tuns64, Tint64) + X(Tint32,Tuns64, Tuns64,Tuns64, Tuns64) X(Tint32,Tfloat32, Tfloat32,Tfloat32, Tfloat32) X(Tint32,Tfloat64, Tfloat64,Tfloat64, Tfloat64) @@ -166,15 +167,9 @@ /* ======================= */ - X(Tuns32,Tbit, Tuns32,Tint32, Tint32) - X(Tuns32,Tint8, Tuns32,Tint32, Tint32) - X(Tuns32,Tuns8, Tuns32,Tint32, Tint32) - X(Tuns32,Tint16, Tuns32,Tint32, Tint32) - X(Tuns32,Tuns16, Tuns32,Tint32, Tint32) - X(Tuns32,Tint32, Tuns32,Tint32, Tint32) - X(Tuns32,Tuns32, Tuns32,Tuns32, Tint32) - X(Tuns32,Tint64, Tuns64,Tint64, Tint64) - X(Tuns32,Tuns64, Tuns64,Tuns64, Tint64) + X(Tuns32,Tuns32, Tuns32,Tuns32, Tuns32) + X(Tuns32,Tint64, Tint64,Tint64, Tint64) + X(Tuns32,Tuns64, Tuns64,Tuns64, Tuns64) X(Tuns32,Tfloat32, Tfloat32,Tfloat32, Tfloat32) X(Tuns32,Tfloat64, Tfloat64,Tfloat64, Tfloat64) @@ -188,15 +183,8 @@ /* ======================= */ - X(Tint64,Tbit, Tint64,Tint64, Tint64) - X(Tint64,Tint8, Tint64,Tint64, Tint64) - X(Tint64,Tuns8, Tint64,Tint64, Tint64) - X(Tint64,Tint16, Tint64,Tint64, Tint64) - X(Tint64,Tuns16, Tint64,Tint64, Tint64) - X(Tint64,Tint32, Tint64,Tint64, Tint64) - X(Tint64,Tuns32, Tint64,Tint64, Tint64) X(Tint64,Tint64, Tint64,Tint64, Tint64) - X(Tint64,Tuns64, Tint64,Tuns64, Tint64) + X(Tint64,Tuns64, Tuns64,Tuns64, Tuns64) X(Tint64,Tfloat32, Tfloat32,Tfloat32, Tfloat32) X(Tint64,Tfloat64, Tfloat64,Tfloat64, Tfloat64) @@ -210,14 +198,6 @@ /* ======================= */ - X(Tuns64,Tbit, Tuns64,Tint64, Tint64) - X(Tuns64,Tint8, Tuns64,Tint64, Tint64) - X(Tuns64,Tuns8, Tuns64,Tint64, Tint64) - X(Tuns64,Tint16, Tuns64,Tint64, Tint64) - X(Tuns64,Tuns16, Tuns64,Tint64, Tint64) - X(Tuns64,Tint32, Tuns64,Tint64, Tint64) - X(Tuns64,Tuns32, Tuns64,Tint64, Tint64) - X(Tuns64,Tint64, Tuns64,Tint64, Tint64) X(Tuns64,Tuns64, Tuns64,Tuns64, Tuns64) X(Tuns64,Tfloat32, Tfloat32,Tfloat32, Tfloat32) @@ -232,16 +212,6 @@ /* ======================= */ - X(Tfloat32,Tbit, Tfloat32,Tfloat32, Tfloat32) - X(Tfloat32,Tint8, Tfloat32,Tfloat32, Tfloat32) - X(Tfloat32,Tuns8, Tfloat32,Tfloat32, Tfloat32) - X(Tfloat32,Tint16, Tfloat32,Tfloat32, Tfloat32) - X(Tfloat32,Tuns16, Tfloat32,Tfloat32, Tfloat32) - X(Tfloat32,Tint32, Tfloat32,Tfloat32, Tfloat32) - X(Tfloat32,Tuns32, Tfloat32,Tfloat32, Tfloat32) - X(Tfloat32,Tint64, Tfloat32,Tfloat32, Tfloat32) - X(Tfloat32,Tuns64, Tfloat32,Tfloat32, Tfloat32) - X(Tfloat32,Tfloat32, Tfloat32,Tfloat32, Tfloat32) X(Tfloat32,Tfloat64, Tfloat64,Tfloat64, Tfloat64) X(Tfloat32,Tfloat80, Tfloat80,Tfloat80, Tfloat80) @@ -256,17 +226,6 @@ /* ======================= */ - X(Tfloat64,Tbit, Tfloat64,Tfloat64, Tfloat64) - X(Tfloat64,Tint8, Tfloat64,Tfloat64, Tfloat64) - X(Tfloat64,Tuns8, Tfloat64,Tfloat64, Tfloat64) - X(Tfloat64,Tint16, Tfloat64,Tfloat64, Tfloat64) - X(Tfloat64,Tuns16, Tfloat64,Tfloat64, Tfloat64) - X(Tfloat64,Tint32, Tfloat64,Tfloat64, Tfloat64) - X(Tfloat64,Tuns32, Tfloat64,Tfloat64, Tfloat64) - X(Tfloat64,Tint64, Tfloat64,Tfloat64, Tfloat64) - X(Tfloat64,Tuns64, Tfloat64,Tfloat64, Tfloat64) - - X(Tfloat64,Tfloat32, Tfloat64,Tfloat64, Tfloat64) X(Tfloat64,Tfloat64, Tfloat64,Tfloat64, Tfloat64) X(Tfloat64,Tfloat80, Tfloat80,Tfloat80, Tfloat80) @@ -280,18 +239,6 @@ /* ======================= */ - X(Tfloat80,Tbit, Tfloat80,Tfloat80, Tfloat80) - X(Tfloat80,Tint8, Tfloat80,Tfloat80, Tfloat80) - X(Tfloat80,Tuns8, Tfloat80,Tfloat80, Tfloat80) - X(Tfloat80,Tint16, Tfloat80,Tfloat80, Tfloat80) - X(Tfloat80,Tuns16, Tfloat80,Tfloat80, Tfloat80) - X(Tfloat80,Tint32, Tfloat80,Tfloat80, Tfloat80) - X(Tfloat80,Tuns32, Tfloat80,Tfloat80, Tfloat80) - X(Tfloat80,Tint64, Tfloat80,Tfloat80, Tfloat80) - X(Tfloat80,Tuns64, Tfloat80,Tfloat80, Tfloat80) - - X(Tfloat80,Tfloat32, Tfloat80,Tfloat80, Tfloat80) - X(Tfloat80,Tfloat64, Tfloat80,Tfloat80, Tfloat80) X(Tfloat80,Tfloat80, Tfloat80,Tfloat80, Tfloat80) X(Tfloat80,Timaginary32, Tfloat80,Timaginary80, Tfloat80) @@ -304,20 +251,6 @@ /* ======================= */ - X(Timaginary32,Tbit, Timaginary32,Tfloat32, Tfloat32) - X(Timaginary32,Tint8, Timaginary32,Tfloat32, Tfloat32) - X(Timaginary32,Tuns8, Timaginary32,Tfloat32, Tfloat32) - X(Timaginary32,Tint16, Timaginary32,Tfloat32, Tfloat32) - X(Timaginary32,Tuns16, Timaginary32,Tfloat32, Tfloat32) - X(Timaginary32,Tint32, Timaginary32,Tfloat32, Tfloat32) - X(Timaginary32,Tuns32, Timaginary32,Tfloat32, Tfloat32) - X(Timaginary32,Tint64, Timaginary32,Tfloat32, Tfloat32) - X(Timaginary32,Tuns64, Timaginary32,Tfloat32, Tfloat32) - - X(Timaginary32,Tfloat32, Timaginary32,Tfloat32, Tfloat32) - X(Timaginary32,Tfloat64, Timaginary64,Tfloat64, Tfloat64) - X(Timaginary32,Tfloat80, Timaginary80,Tfloat80, Tfloat80) - X(Timaginary32,Timaginary32, Timaginary32,Timaginary32, Timaginary32) X(Timaginary32,Timaginary64, Timaginary64,Timaginary64, Timaginary64) X(Timaginary32,Timaginary80, Timaginary80,Timaginary80, Timaginary80) @@ -328,21 +261,6 @@ /* ======================= */ - X(Timaginary64,Tbit, Timaginary64,Tfloat64, Tfloat64) - X(Timaginary64,Tint8, Timaginary64,Tfloat64, Tfloat64) - X(Timaginary64,Tuns8, Timaginary64,Tfloat64, Tfloat64) - X(Timaginary64,Tint16, Timaginary64,Tfloat64, Tfloat64) - X(Timaginary64,Tuns16, Timaginary64,Tfloat64, Tfloat64) - X(Timaginary64,Tint32, Timaginary64,Tfloat64, Tfloat64) - X(Timaginary64,Tuns32, Timaginary64,Tfloat64, Tfloat64) - X(Timaginary64,Tint64, Timaginary64,Tfloat64, Tfloat64) - X(Timaginary64,Tuns64, Timaginary64,Tfloat64, Tfloat64) - - X(Timaginary64,Tfloat32, Timaginary64,Tfloat64, Tfloat64) - X(Timaginary64,Tfloat64, Timaginary64,Tfloat64, Tfloat64) - X(Timaginary64,Tfloat80, Timaginary80,Tfloat80, Tfloat80) - - X(Timaginary64,Timaginary32, Timaginary64,Timaginary64, Timaginary64) X(Timaginary64,Timaginary64, Timaginary64,Timaginary64, Timaginary64) X(Timaginary64,Timaginary80, Timaginary80,Timaginary80, Timaginary80) @@ -352,22 +270,6 @@ /* ======================= */ - X(Timaginary80,Tbit, Timaginary80,Tfloat80, Tfloat80) - X(Timaginary80,Tint8, Timaginary80,Tfloat80, Tfloat80) - X(Timaginary80,Tuns8, Timaginary80,Tfloat80, Tfloat80) - X(Timaginary80,Tint16, Timaginary80,Tfloat80, Tfloat80) - X(Timaginary80,Tuns16, Timaginary80,Tfloat80, Tfloat80) - X(Timaginary80,Tint32, Timaginary80,Tfloat80, Tfloat80) - X(Timaginary80,Tuns32, Timaginary80,Tfloat80, Tfloat80) - X(Timaginary80,Tint64, Timaginary80,Tfloat80, Tfloat80) - X(Timaginary80,Tuns64, Timaginary80,Tfloat80, Tfloat80) - - X(Timaginary80,Tfloat32, Timaginary80,Tfloat80, Tfloat80) - X(Timaginary80,Tfloat64, Timaginary80,Tfloat80, Tfloat80) - X(Timaginary80,Tfloat80, Timaginary80,Tfloat80, Tfloat80) - - X(Timaginary80,Timaginary32, Timaginary80,Timaginary80, Timaginary80) - X(Timaginary80,Timaginary64, Timaginary80,Timaginary80, Timaginary80) X(Timaginary80,Timaginary80, Timaginary80,Timaginary80, Timaginary80) X(Timaginary80,Tcomplex32, Timaginary80,Tcomplex80, Tcomplex80) @@ -376,75 +278,29 @@ /* ======================= */ - X(Tcomplex32,Tbit, Tcomplex32,Tfloat32, Tcomplex32) - X(Tcomplex32,Tint8, Tcomplex32,Tfloat32, Tcomplex32) - X(Tcomplex32,Tuns8, Tcomplex32,Tfloat32, Tcomplex32) - X(Tcomplex32,Tint16, Tcomplex32,Tfloat32, Tcomplex32) - X(Tcomplex32,Tuns16, Tcomplex32,Tfloat32, Tcomplex32) - X(Tcomplex32,Tint32, Tcomplex32,Tfloat32, Tcomplex32) - X(Tcomplex32,Tuns32, Tcomplex32,Tfloat32, Tcomplex32) - X(Tcomplex32,Tint64, Tcomplex32,Tfloat32, Tcomplex32) - X(Tcomplex32,Tuns64, Tcomplex32,Tfloat32, Tcomplex32) - - X(Tcomplex32,Tfloat32, Tcomplex32,Tfloat32, Tcomplex32) - X(Tcomplex32,Tfloat64, Tcomplex64,Tfloat64, Tcomplex64) - X(Tcomplex32,Tfloat80, Tcomplex80,Tfloat80, Tcomplex80) - - X(Tcomplex32,Timaginary32, Tcomplex32,Timaginary32, Tcomplex32) - X(Tcomplex32,Timaginary64, Tcomplex64,Timaginary64, Tcomplex64) - X(Tcomplex32,Timaginary80, Tcomplex80,Timaginary80, Tcomplex80) - X(Tcomplex32,Tcomplex32, Tcomplex32,Tcomplex32, Tcomplex32) X(Tcomplex32,Tcomplex64, Tcomplex64,Tcomplex64, Tcomplex64) X(Tcomplex32,Tcomplex80, Tcomplex80,Tcomplex80, Tcomplex80) /* ======================= */ - X(Tcomplex64,Tbit, Tcomplex64,Tfloat64, Tcomplex64) - X(Tcomplex64,Tint8, Tcomplex64,Tfloat64, Tcomplex64) - X(Tcomplex64,Tuns8, Tcomplex64,Tfloat64, Tcomplex64) - X(Tcomplex64,Tint16, Tcomplex64,Tfloat64, Tcomplex64) - X(Tcomplex64,Tuns16, Tcomplex64,Tfloat64, Tcomplex64) - X(Tcomplex64,Tint32, Tcomplex64,Tfloat64, Tcomplex64) - X(Tcomplex64,Tuns32, Tcomplex64,Tfloat64, Tcomplex64) - X(Tcomplex64,Tint64, Tcomplex64,Tfloat64, Tcomplex64) - X(Tcomplex64,Tuns64, Tcomplex64,Tfloat64, Tcomplex64) - - X(Tcomplex64,Tfloat32, Tcomplex64,Tfloat64, Tcomplex64) - X(Tcomplex64,Tfloat64, Tcomplex64,Tfloat64, Tcomplex64) - X(Tcomplex64,Tfloat80, Tcomplex80,Tfloat80, Tcomplex80) - - X(Tcomplex64,Timaginary32, Tcomplex64,Timaginary64, Tcomplex64) - X(Tcomplex64,Timaginary64, Tcomplex64,Timaginary64, Tcomplex64) - X(Tcomplex64,Timaginary80, Tcomplex80,Timaginary80, Tcomplex80) - - X(Tcomplex64,Tcomplex32, Tcomplex64,Tcomplex64, Tcomplex64) X(Tcomplex64,Tcomplex64, Tcomplex64,Tcomplex64, Tcomplex64) X(Tcomplex64,Tcomplex80, Tcomplex80,Tcomplex80, Tcomplex80) /* ======================= */ - X(Tcomplex80,Tbit, Tcomplex80,Tfloat80, Tcomplex80) - X(Tcomplex80,Tint8, Tcomplex80,Tfloat80, Tcomplex80) - X(Tcomplex80,Tuns8, Tcomplex80,Tfloat80, Tcomplex80) - X(Tcomplex80,Tint16, Tcomplex80,Tfloat80, Tcomplex80) - X(Tcomplex80,Tuns16, Tcomplex80,Tfloat80, Tcomplex80) - X(Tcomplex80,Tint32, Tcomplex80,Tfloat80, Tcomplex80) - X(Tcomplex80,Tuns32, Tcomplex80,Tfloat80, Tcomplex80) - X(Tcomplex80,Tint64, Tcomplex80,Tfloat80, Tcomplex80) - X(Tcomplex80,Tuns64, Tcomplex80,Tfloat80, Tcomplex80) - - X(Tcomplex80,Tfloat32, Tcomplex80,Tfloat80, Tcomplex80) - X(Tcomplex80,Tfloat64, Tcomplex80,Tfloat80, Tcomplex80) - X(Tcomplex80,Tfloat80, Tcomplex80,Tfloat80, Tcomplex80) - - X(Tcomplex80,Timaginary32, Tcomplex80,Timaginary80, Tcomplex80) - X(Tcomplex80,Timaginary64, Tcomplex80,Timaginary80, Tcomplex80) - X(Tcomplex80,Timaginary80, Tcomplex80,Timaginary80, Tcomplex80) - - X(Tcomplex80,Tcomplex32, Tcomplex80,Tcomplex80, Tcomplex80) - X(Tcomplex80,Tcomplex64, Tcomplex80,Tcomplex80, Tcomplex80) X(Tcomplex80,Tcomplex80, Tcomplex80,Tcomplex80, Tcomplex80) + + for (i = 0; i < TMAX; i++) + for (j = 0; j < TMAX; j++) + { + if (impcnvResult[i][j] == Terror) + { + impcnvResult[i][j] = impcnvResult[j][i]; + impcnvType1[i][j] = impcnvType2[j][i]; + impcnvType2[i][j] = impcnvType1[j][i]; + } + } } int main() diff -uNr dmd-0.106/dmd/src/dmd/inline.c dmd-0.107/dmd/src/dmd/inline.c --- dmd-0.106/dmd/src/dmd/inline.c 2004-09-19 11:52:48.000000000 +0200 +++ dmd-0.107/dmd/src/dmd/inline.c 2004-11-25 02:04:56.000000000 +0100 @@ -353,6 +353,24 @@ return copy(); } +Expression *SymOffExp::doInline(InlineDoState *ids) +{ + int i; + + //printf("SymOffExp::doInline(%s)\n", toChars()); + for (i = 0; i < ids->from.dim; i++) + { + if (var == (Declaration *)ids->from.data[i]) + { + SymOffExp *se = (SymOffExp *)copy(); + + se->var = (Declaration *)ids->to.data[i]; + return se; + } + } + return this; +} + Expression *VarExp::doInline(InlineDoState *ids) { int i; @@ -986,6 +1004,8 @@ vto->storage_class |= vfrom->storage_class & (STCin | STCout); vto->linkage = vfrom->linkage; vto->parent = iss->fd; + //printf("vto = '%s', vto->storage_class = x%x\n", vto->toChars(), vto->storage_class); + //printf("vto->parent = '%s'\n", iss->fd->toChars()); ve = new VarExp(vto->loc, vto); ve->type = vto->type; diff -uNr dmd-0.106/dmd/src/dmd/lexer.c dmd-0.107/dmd/src/dmd/lexer.c --- dmd-0.106/dmd/src/dmd/lexer.c 2004-10-25 14:44:38.000000000 +0200 +++ dmd-0.107/dmd/src/dmd/lexer.c 2004-11-23 22:20:14.000000000 +0100 @@ -2074,8 +2074,8 @@ Token::tochars[TOKminusminus] = "--"; Token::tochars[TOKtype] = "type"; Token::tochars[TOKquestion] = "?"; - Token::tochars[TOKneg] = "neg"; - Token::tochars[TOKuadd] = "uadd"; + Token::tochars[TOKneg] = "-"; + Token::tochars[TOKuadd] = "+"; Token::tochars[TOKvar] = "var"; Token::tochars[TOKaddass] = "+="; Token::tochars[TOKminass] = "-="; diff -uNr dmd-0.106/dmd/src/dmd/mars.c dmd-0.107/dmd/src/dmd/mars.c --- dmd-0.106/dmd/src/dmd/mars.c 2004-11-03 15:47:38.000000000 +0100 +++ dmd-0.107/dmd/src/dmd/mars.c 2004-11-11 00:33:38.000000000 +0100 @@ -49,7 +49,7 @@ copyright = "Copyright (c) 1999-2004 by Digital Mars"; written = "written by Walter Bright"; - version = "v0.106"; + version = "v0.107"; global.structalign = 8; memset(¶ms, 0, sizeof(Param)); diff -uNr dmd-0.106/dmd/src/dmd/mars.h dmd-0.107/dmd/src/dmd/mars.h --- dmd-0.106/dmd/src/dmd/mars.h 2004-03-11 20:06:28.000000000 +0100 +++ dmd-0.107/dmd/src/dmd/mars.h 2004-11-24 20:23:10.000000000 +0100 @@ -120,8 +120,9 @@ typedef double d_float64; typedef long double d_float80; -// Note: this will be 2 bytes on Win32 systems, and 4 bytes under linux. -typedef wchar_t d_wchar; +typedef d_uns8 d_char; +typedef d_uns16 d_wchar; +typedef d_uns32 d_dchar; // Modify OutBuffer::writewchar to write the correct size of wchar #if _WIN32 diff -uNr dmd-0.106/dmd/src/dmd/module.c dmd-0.107/dmd/src/dmd/module.c --- dmd-0.106/dmd/src/dmd/module.c 2004-08-30 00:22:16.000000000 +0200 +++ dmd-0.107/dmd/src/dmd/module.c 2004-11-26 02:59:54.000000000 +0100 @@ -207,6 +207,7 @@ unsigned char *buf; unsigned buflen; unsigned le; + unsigned bom; //printf("Module::parse()\n"); @@ -227,6 +228,7 @@ * EF BB BF UTF-8 */ + bom = 1; // assume there's a BOM if (buf[0] == 0xFF && buf[1] == 0xFE) { if (buflen >= 4 && buf[2] == 0 && buf[3] == 0) @@ -244,7 +246,7 @@ } dbuf.reserve(buflen / 4); - while (++pu < pumax) + for (pu += bom; pu < pumax; pu++) { unsigned u; u = le ? readlongLE(pu) : readlongBE(pu); @@ -279,7 +281,7 @@ } dbuf.reserve(buflen / 2); - while (++pu < pumax) + for (pu += bom; pu < pumax; pu++) { unsigned u; u = le ? readwordLE(pu) : readwordBE(pu); @@ -340,6 +342,7 @@ * figure out the encoding. */ + bom = 0; if (buflen >= 4) { if (buf[1] == 0 && buf[2] == 0 && buf[3] == 0) { // UTF-32LE diff -uNr dmd-0.106/dmd/src/dmd/mtype.c dmd-0.107/dmd/src/dmd/mtype.c --- dmd-0.106/dmd/src/dmd/mtype.c 2004-11-04 21:54:30.000000000 +0100 +++ dmd-0.107/dmd/src/dmd/mtype.c 2004-11-23 14:54:22.000000000 +0100 @@ -496,6 +496,13 @@ { if (ident == Id::offset) { + if (!global.params.useDeprecated) + error(e->loc, ".offset deprecated, use .offsetof"); + goto Loffset; + } + else if (ident == Id::offsetof) + { + Loffset: if (v->storage_class & STCfield) { e = new IntegerExp(e->loc, v->offset, Type::tint32); @@ -1482,6 +1489,10 @@ { e = dim; } + else if (ident == Id::ptr) + { + e = e->castTo(next->pointerTo()); + } else { e = TypeArray::dotExp(sc, e, ident); @@ -1613,6 +1624,11 @@ e->type = Type::tsize_t; return e; } + else if (ident == Id::ptr) + { + e = e->castTo(next->pointerTo()); + return e; + } else { e = TypeArray::dotExp(sc, e, ident); diff -uNr dmd-0.106/dmd/src/dmd/optimize.c dmd-0.107/dmd/src/dmd/optimize.c --- dmd-0.106/dmd/src/dmd/optimize.c 2004-06-12 14:52:38.000000000 +0200 +++ dmd-0.107/dmd/src/dmd/optimize.c 2004-11-29 01:49:14.000000000 +0100 @@ -30,7 +30,7 @@ { Expression *e; e1 = e1->optimize(result); - if (e1->isConst()) + if (e1->isConst() == 1) e = constFold(); else e = this; @@ -150,6 +150,30 @@ e1 = e1->optimize(result); e2 = e2->optimize(result); + if (e1->isConst() == 1 && e2->isConst() == 1) + e = constFold(); + else + e = this; + return e; +} + +Expression *AddExp::optimize(int result) +{ Expression *e; + + e1 = e1->optimize(result); + e2 = e2->optimize(result); + if (e1->isConst() && e2->isConst()) + e = constFold(); + else + e = this; + return e; +} + +Expression *MinExp::optimize(int result) +{ Expression *e; + + e1 = e1->optimize(result); + e2 = e2->optimize(result); if (e1->isConst() && e2->isConst()) e = constFold(); else @@ -179,12 +203,12 @@ e1 = e1->optimize(WANTflags); e2 = e2->optimize(WANTflags); e = this; - if (e1->isConst()) + if (e1->isBool(FALSE)) + e = new IntegerExp(loc, 0, type); + else if (e1->isConst()) { if (e2->isConst()) e = constFold(); - else if (e1->isBool(FALSE)) - e = new IntegerExp(loc, 0, type); else if (e1->isBool(TRUE)) e = new BoolExp(loc, e2, type); } @@ -197,12 +221,12 @@ e1 = e1->optimize(WANTflags); e2 = e2->optimize(WANTflags); e = this; - if (e1->isConst()) + if (e1->isBool(TRUE)) + e = new IntegerExp(loc, 1, type); + else if (e1->isConst()) { if (e2->isConst()) e = constFold(); - else if (e1->isBool(TRUE)) - e = new IntegerExp(loc, 1, type); else if (e1->isBool(FALSE)) e = new BoolExp(loc, e2, type); } @@ -215,9 +239,7 @@ //printf("CatExp::optimize(%d)\n", result); e1 = e1->optimize(result); e2 = e2->optimize(result); - if (e1->isConst() && e2->isConst()) - e = constFold(); - else if (e1->op == TOKstring && e2->op == TOKstring) + if (e1->op == TOKstring && e2->op == TOKstring) { // Concatenate the strings void *s; diff -uNr dmd-0.106/dmd/src/dmd/statement.c dmd-0.107/dmd/src/dmd/statement.c --- dmd-0.106/dmd/src/dmd/statement.c 2004-11-02 22:41:26.000000000 +0100 +++ dmd-0.107/dmd/src/dmd/statement.c 2004-11-24 19:24:32.000000000 +0100 @@ -1249,6 +1249,7 @@ { CaseStatement *cs = (CaseStatement *)sw->cases->data[i]; + //printf("comparing '%s' with '%s'\n", exp->toChars(), cs->exp->toChars()); if (cs->exp->equals(exp)) { error("duplicate case %s in switch statement", exp->toChars()); break; diff -uNr dmd-0.106/dmd/src/dmd/struct.c dmd-0.107/dmd/src/dmd/struct.c --- dmd-0.106/dmd/src/dmd/struct.c 2004-11-04 20:56:48.000000000 +0100 +++ dmd-0.107/dmd/src/dmd/struct.c 2004-11-27 00:10:40.000000000 +0100 @@ -204,49 +204,56 @@ AggregateDeclaration *sd; - if (isAnonymous() && - (sd = isMember()) != NULL) + if (isAnonymous()) { // Anonymous structures aren't independent, all their members are // added to the enclosing struct. unsigned offset; int isunionsave; - // Align size of enclosing struct - sd->alignmember(structalign, alignsize, &sd->structsize); - - // Add members to enclosing struct - for (i = 0; i < members->dim; i++) + sd = isMember(); + if (!sd) { - Dsymbol *s = (Dsymbol *)members->data[i]; - VarDeclaration *vd = s->isVarDeclaration(); - if (vd && vd->storage_class & STCfield) + error("anonymous struct can only be member of an aggregate"); + } + else + { + // Align size of enclosing struct + sd->alignmember(structalign, alignsize, &sd->structsize); + + // Add members to enclosing struct + for (i = 0; i < members->dim; i++) { - vd->addMember(sd); - if (!sd->isUnionDeclaration()) - vd->offset += sd->structsize; - sd->fields.push(vd); - sd->members->push(s); + Dsymbol *s = (Dsymbol *)members->data[i]; + VarDeclaration *vd = s->isVarDeclaration(); + if (vd && vd->storage_class & STCfield) + { + vd->addMember(sd); + if (!sd->isUnionDeclaration()) + vd->offset += sd->structsize; + sd->fields.push(vd); + sd->members->push(s); + } + else if (!s->isAnonymous()) + { + sd->members->push(s); + } } - else if (!s->isAnonymous()) + + if (sd->isUnionDeclaration()) { - sd->members->push(s); + if (structsize > sd->structsize) + sd->structsize = structsize; + sc->offset = 0; + } + else + { + sd->structsize += structsize; + sc->offset = sd->structsize; } - } - if (sd->isUnionDeclaration()) - { - if (structsize > sd->structsize) - sd->structsize = structsize; - sc->offset = 0; + if (sd->alignsize < alignsize) + sd->alignsize = alignsize; } - else - { - sd->structsize += structsize; - sc->offset = sd->structsize; - } - - if (sd->alignsize < alignsize) - sd->alignsize = alignsize; } //printf("-StructDeclaration::semantic(this=%p, '%s')\n", this, toChars()); diff -uNr dmd-0.106/dmd/src/dmd/tocsym.c dmd-0.107/dmd/src/dmd/tocsym.c --- dmd-0.106/dmd/src/dmd/tocsym.c 2004-09-06 22:45:08.000000000 +0200 +++ dmd-0.107/dmd/src/dmd/tocsym.c 2004-11-28 02:07:28.000000000 +0100 @@ -155,6 +155,7 @@ t = type->toCParamtype(); else t = type->toCtype(); + t->Tcount++; if (isDataseg()) { @@ -214,7 +215,6 @@ assert(0); } type_setmangle(&t, m); - t->Tcount++; s->Stype = t; csym = s; @@ -243,7 +243,7 @@ Symbol *TypeInfoDeclaration::toSymbol() { - //printf("TypeInfoDeclaration::toSymbol(%s)\n", toChars()); + //printf("TypeInfoDeclaration::toSymbol(%s), linkage = %d\n", toChars(), linkage); return VarDeclaration::toSymbol(); } diff -uNr dmd-0.106/dmd/src/phobos/internal/aaA.d dmd-0.107/dmd/src/phobos/internal/aaA.d --- dmd-0.106/dmd/src/phobos/internal/aaA.d 2004-11-09 00:34:20.000000000 +0100 +++ dmd-0.107/dmd/src/phobos/internal/aaA.d 2004-11-29 18:01:34.000000000 +0100 @@ -234,17 +234,17 @@ /************************************************* * Determine if key is in aa. * Returns: - * 0 not in aa - * !=0 in aa + * null not in aa + * !=null in aa, return pointer to value */ -int _aaIn(aaA*[] aa, TypeInfo keyti, ...) +void* _aaIn(aaA*[] aa, TypeInfo keyti, ...) in { } out (result) { - assert(result == 0 || result == 1); + //assert(result == 0 || result == 1); } body { @@ -267,7 +267,7 @@ { c = keyti.compare(pkey, e + 1); if (c == 0) - return 1; + return cast(void *)(e + 1) + keyti.sizeof; } if (c < 0) @@ -278,7 +278,7 @@ } // Not found - return 0; + return null; } /************************************************* diff -uNr dmd-0.106/dmd/src/phobos/internal/gc/gcx.d dmd-0.107/dmd/src/phobos/internal/gc/gcx.d --- dmd-0.106/dmd/src/phobos/internal/gc/gcx.d 2004-11-09 00:34:22.000000000 +0100 +++ dmd-0.107/dmd/src/phobos/internal/gc/gcx.d 2004-11-29 18:01:36.000000000 +0100 @@ -203,14 +203,30 @@ } void *malloc(size_t size) + { void *p; + + if (std.thread.Thread.nthreads == 1) + { + /* The reason this works is because none of the gc code + * can start up a new thread from within mallocNoSync(). + * Skip the sync for speed reasons. + */ + return mallocNoSync(size); + } + else synchronized (gcLock) + { + p = mallocNoSync(size); + } + return p; + } + + void *mallocNoSync(size_t size) { void *p = null; Bins bin; //debug(PRINTF) printf("GC::malloc(size = %d, gcx = %p)\n", size, gcx); assert(gcx); //debug(PRINTF) printf("gcx.self = %x, pthread_self() = %x\n", gcx.self, pthread_self()); - synchronized (gcLock) - { if (size) { size += SENTINEL_EXTRA; @@ -225,7 +241,18 @@ { if (!gcx.allocPage(bin)) // try to find a new page { - if (!gcx.fullcollectshell()) // collect to find a new page + if (std.thread.Thread.nthreads == 1) + { + /* Then we haven't locked it yet. Be sure + * and lock for a collection, since a finalizer + * may start a new thread. + */ + synchronized (gcLock) + { + gcx.fullcollectshell(); + } + } + else if (!gcx.fullcollectshell()) // collect to find a new page { //gcx.newPool(1); } @@ -258,7 +285,6 @@ sentinel_init(p, size); gcx.log_malloc(p, size); } - } return p; } diff -uNr dmd-0.106/dmd/src/phobos/internal/object.d dmd-0.107/dmd/src/phobos/internal/object.d --- dmd-0.106/dmd/src/phobos/internal/object.d 2004-11-09 00:34:20.000000000 +0100 +++ dmd-0.107/dmd/src/phobos/internal/object.d 2004-11-29 18:01:34.000000000 +0100 @@ -3,7 +3,6 @@ extern (C) { int printf(char *, ...); - int wprintf(wchar *, ...); } alias bit bool; diff -uNr dmd-0.106/dmd/src/phobos/internal/switch.d dmd-0.107/dmd/src/phobos/internal/switch.d --- dmd-0.106/dmd/src/phobos/internal/switch.d 2004-11-09 00:34:20.000000000 +0100 +++ dmd-0.107/dmd/src/phobos/internal/switch.d 2004-11-29 18:01:34.000000000 +0100 @@ -273,3 +273,129 @@ } +/********************************** + * Same thing, but for wide chars. + */ + +int _d_switch_dstring(dchar[][] table, dchar[] ca) + in + { + //printf("in _d_switch_dstring()\n"); + assert(table.length >= 0); + assert(ca.length >= 0); + + // Make sure table[] is sorted correctly + int j; + + for (j = 1; j < table.length; j++) + { + int len1 = table[j - 1].length; + int len2 = table[j].length; + + assert(len1 <= len2); + if (len1 == len2) + { + int c; + + c = memcmp(table[j - 1], table[j], len1 * dchar.sizeof); + assert(c < 0); // c==0 means a duplicate + } + } + } + out (result) + { + int i; + int c; + + //printf("out _d_switch_string()\n"); + if (result == -1) + { + // Not found + for (i = 0; i < table.length; i++) + { + if (table[i].length == ca.length) + { c = memcmp(table[i], ca, ca.length * dchar.sizeof); + assert(c != 0); + } + } + } + else + { + assert(0 <= result && result < table.length); + for (i = 0; 1; i++) + { + assert(i < table.length); + if (table[i].length == ca.length) + { + c = memcmp(table[i], ca, ca.length * dchar.sizeof); + if (c == 0) + { + assert(i == result); + break; + } + } + } + } + } + body + { + //printf("body _d_switch_ustring()\n"); + int low; + int high; + int mid; + int c; + dchar[] pca; + + low = 0; + high = table.length; + + /* + // Print table + wprintf("ca[] = '%.*s'\n", ca); + for (mid = 0; mid < high; mid++) + { + pca = table[mid]; + wprintf("table[%d] = %d, '%.*s'\n", mid, pca.length, pca); + } + */ + + // Do binary search + while (low < high) + { + mid = (low + high) >> 1; + pca = table[mid]; + c = ca.length - pca.length; + if (c == 0) + { + c = memcmp(ca, pca, ca.length * dchar.sizeof); + if (c == 0) + { //printf("found %d\n", mid); + return mid; + } + } + if (c < 0) + { + high = mid; + } + else + { + low = mid + 1; + } + } + //printf("not found\n"); + return -1; // not found + } + + +unittest +{ + switch (cast(dchar []) "c") + { + case "coo": + default: + break; + } +} + + + diff -uNr dmd-0.106/dmd/src/phobos/linux.mak dmd-0.107/dmd/src/phobos/linux.mak --- dmd-0.106/dmd/src/phobos/linux.mak 2004-11-09 00:34:18.000000000 +0100 +++ dmd-0.107/dmd/src/phobos/linux.mak 2004-11-29 18:01:34.000000000 +0100 @@ -56,7 +56,7 @@ crc32.o conv.o arraycast.o errno.o alloca.o cmath2.o \ process.o syserror.o \ socket.o socketstream.o stdarg.o stdio.o format.o \ - perf.o \ + perf.o openrj.o \ ti_wchar.o ti_uint.o ti_short.o ti_ushort.o \ ti_byte.o ti_ubyte.o ti_long.o ti_ulong.o ti_ptr.o \ ti_float.o ti_double.o ti_real.o ti_delegate.o \ @@ -95,10 +95,10 @@ std/intrinsic.d std/array.d std/switcherr.d std/syserror.d \ std/regexp.d std/random.d std/stream.d std/process.d std/recls.d \ std/socket.d std/socketstream.d std/loader.d std/stdarg.d \ - std/stdio.d std/format.d std/perf.d + std/stdio.d std/format.d std/perf.d std/openrj.d SRC_STD_C= std/c/process.d std/c/stdlib.d std/c/time.d std/c/stdio.d \ - std/c/math.d std/c/stdarg.d + std/c/math.d std/c/stdarg.d std/c/stddef.d SRC_TI= \ std/typeinfo/ti_wchar.d std/typeinfo/ti_uint.d \ @@ -497,6 +497,9 @@ moduleinit.o : std/moduleinit.d $(DMD) -c $(DFLAGS) std/moduleinit.d +openrj.o : std/openrj.d + $(DMD) -c $(DFLAGS) std/openrj.d + outbuffer.o : std/outbuffer.d $(DMD) -c $(DFLAGS) std/outbuffer.d diff -uNr dmd-0.106/dmd/src/phobos/object.d dmd-0.107/dmd/src/phobos/object.d --- dmd-0.106/dmd/src/phobos/object.d 2004-11-09 00:34:18.000000000 +0100 +++ dmd-0.107/dmd/src/phobos/object.d 2004-11-29 18:01:34.000000000 +0100 @@ -3,11 +3,6 @@ module object; -extern (C) -{ int printf(char *, ...); - int wprintf(wchar *, ...); -} - alias bit bool; version (AMD64) @@ -15,11 +10,19 @@ alias ulong size_t; alias long ptrdiff_t; } -else +else version (X86) { alias uint size_t; alias int ptrdiff_t; } +else +{ + static assert(0); +} + +extern (C) +{ int printf(char *, ...); +} class Object { diff -uNr dmd-0.106/dmd/src/phobos/std/c/process.d dmd-0.107/dmd/src/phobos/std/c/process.d --- dmd-0.106/dmd/src/phobos/std/c/process.d 2004-11-09 00:34:18.000000000 +0100 +++ dmd-0.107/dmd/src/phobos/std/c/process.d 2004-11-29 18:01:34.000000000 +0100 @@ -4,6 +4,8 @@ module std.c.process; +import std.c.stddef; + extern (C): void exit(int); @@ -55,21 +57,21 @@ void _endthreadex(uint); -int _wsystem(wchar *); -int _wspawnl(int, wchar *, wchar *, ...); -int _wspawnle(int, wchar *, wchar *, ...); -int _wspawnlp(int, wchar *, wchar *, ...); -int _wspawnlpe(int, wchar *, wchar *, ...); -int _wspawnv(int, wchar *, wchar **); -int _wspawnve(int, wchar *, wchar **, wchar **); -int _wspawnvp(int, wchar *, wchar **); -int _wspawnvpe(int, wchar *, wchar **, wchar **); - -int _wexecl(wchar *, wchar *, ...); -int _wexecle(wchar *, wchar *, ...); -int _wexeclp(wchar *, wchar *, ...); -int _wexeclpe(wchar *, wchar *, ...); -int _wexecv(wchar *, wchar **); -int _wexecve(wchar *, wchar **, wchar **); -int _wexecvp(wchar *, wchar **); -int _wexecvpe(wchar *, wchar **, wchar **); +int _wsystem(wchar_t *); +int _wspawnl(int, wchar_t *, wchar_t *, ...); +int _wspawnle(int, wchar_t *, wchar_t *, ...); +int _wspawnlp(int, wchar_t *, wchar_t *, ...); +int _wspawnlpe(int, wchar_t *, wchar_t *, ...); +int _wspawnv(int, wchar_t *, wchar_t **); +int _wspawnve(int, wchar_t *, wchar_t **, wchar_t **); +int _wspawnvp(int, wchar_t *, wchar_t **); +int _wspawnvpe(int, wchar_t *, wchar_t **, wchar_t **); + +int _wexecl(wchar_t *, wchar_t *, ...); +int _wexecle(wchar_t *, wchar_t *, ...); +int _wexeclp(wchar_t *, wchar_t *, ...); +int _wexeclpe(wchar_t *, wchar_t *, ...); +int _wexecv(wchar_t *, wchar_t **); +int _wexecve(wchar_t *, wchar_t **, wchar_t **); +int _wexecvp(wchar_t *, wchar_t **); +int _wexecvpe(wchar_t *, wchar_t **, wchar_t **); diff -uNr dmd-0.106/dmd/src/phobos/std/c/stdarg.d dmd-0.107/dmd/src/phobos/std/c/stdarg.d --- dmd-0.106/dmd/src/phobos/std/c/stdarg.d 2004-11-09 00:34:18.000000000 +0100 +++ dmd-0.107/dmd/src/phobos/std/c/stdarg.d 2004-11-29 18:01:34.000000000 +0100 @@ -1,4 +1,3 @@ - /* * Placed in public domain. * Written by Hauke Duden and Walter Bright @@ -28,4 +27,10 @@ void va_end(va_list ap) { + +} + +void va_copy(out va_list dest, va_list src) +{ + dest = src; } diff -uNr dmd-0.106/dmd/src/phobos/std/c/stddef.d dmd-0.107/dmd/src/phobos/std/c/stddef.d --- dmd-0.106/dmd/src/phobos/std/c/stddef.d 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.107/dmd/src/phobos/std/c/stddef.d 2004-11-29 18:01:34.000000000 +0100 @@ -0,0 +1,19 @@ +/* + * Written by Walter Bright + * Digital Mars + * www.digitalmars.com + * Placed into Public Domain. + */ + +version (Win32) +{ + alias wchar wchar_t; +} +else version (linux) +{ + alias dchar wchar_t; +} +else +{ + static assert(0); +} diff -uNr dmd-0.106/dmd/src/phobos/std/c/stdio.d dmd-0.107/dmd/src/phobos/std/c/stdio.d --- dmd-0.106/dmd/src/phobos/std/c/stdio.d 2004-11-09 00:34:18.000000000 +0100 +++ dmd-0.107/dmd/src/phobos/std/c/stdio.d 2004-11-29 18:01:34.000000000 +0100 @@ -9,6 +9,7 @@ module std.c.stdio; +import std.c.stddef; private import std.c.stdarg; extern (C): @@ -236,38 +237,38 @@ int kbhit(); char * tempnam (char *dir, char *pfx); -wchar * _wtmpnam(wchar *); -FILE * _wfopen(wchar *, wchar *); -FILE * _wfsopen(wchar *, wchar *, int); -FILE * _wfreopen(wchar *, wchar *, FILE *); -wchar * fgetws(wchar *, int, FILE *); -int fputws(wchar *, FILE *); -wchar * _getws(wchar *); -int _putws(wchar *); -//int wprintf(wchar *, ...); -int fwprintf(FILE *, wchar *, ...); -int vwprintf(wchar *, va_list); -int vfwprintf(FILE *, wchar *, va_list); -int swprintf(wchar *, wchar *, ...); -int vswprintf(wchar *, wchar *, va_list); -int _snwprintf(wchar *, size_t, wchar *, ...); -int _vsnwprintf(wchar *, size_t, wchar *, va_list); -int wscanf(wchar *, ...); -int fwscanf(FILE *, wchar *, ...); -int swscanf(wchar *, wchar *, ...); -int _wremove(wchar *); -void _wperror(wchar *); -FILE * _wfdopen(int, wchar *); -wchar * _wtempnam(wchar *, wchar *); -wchar fgetwc(FILE *); -wchar _fgetwchar(); -wchar fputwc(wchar, FILE *); -wchar _fputwchar(wchar); -wchar ungetwc(wchar, FILE *); - -wchar getwchar() { return fgetwc(stdin); } -wchar putwchar(wchar c) { return fputwc(c,stdout); } -wchar getwc(FILE *fp) { return fgetwc(fp); } -wchar putwc(wchar c, FILE *fp) { return fputwc(c, fp); } +wchar_t * _wtmpnam(wchar_t *); +FILE * _wfopen(wchar_t *, wchar_t *); +FILE * _wfsopen(wchar_t *, wchar_t *, int); +FILE * _wfreopen(wchar_t *, wchar_t *, FILE *); +wchar_t * fgetws(wchar_t *, int, FILE *); +int fputws(wchar_t *, FILE *); +wchar_t * _getws(wchar_t *); +int _putws(wchar_t *); +//int wprintf(wchar_t *, ...); +int fwprintf(FILE *, wchar_t *, ...); +int vwprintf(wchar_t *, va_list); +int vfwprintf(FILE *, wchar_t *, va_list); +int swprintf(wchar_t *, wchar_t *, ...); +int vswprintf(wchar_t *, wchar_t *, va_list); +int _snwprintf(wchar_t *, size_t, wchar_t *, ...); +int _vsnwprintf(wchar_t *, size_t, wchar_t *, va_list); +int wscanf(wchar_t *, ...); +int fwscanf(FILE *, wchar_t *, ...); +int swscanf(wchar_t *, wchar_t *, ...); +int _wremove(wchar_t *); +void _wperror(wchar_t *); +FILE * _wfdopen(int, wchar_t *); +wchar_t * _wtempnam(wchar_t *, wchar_t *); +wchar_t fgetwc(FILE *); +wchar_t _fgetwchar_t(); +wchar_t fputwc(wchar_t, FILE *); +wchar_t _fputwchar_t(wchar_t); +wchar_t ungetwc(wchar_t, FILE *); + +wchar_t getwchar_t() { return fgetwc(stdin); } +wchar_t putwchar_t(wchar_t c) { return fputwc(c,stdout); } +wchar_t getwc(FILE *fp) { return fgetwc(fp); } +wchar_t putwc(wchar_t c, FILE *fp) { return fputwc(c, fp); } int fwide(FILE* fp, int mode); diff -uNr dmd-0.106/dmd/src/phobos/std/c/stdlib.d dmd-0.107/dmd/src/phobos/std/c/stdlib.d --- dmd-0.106/dmd/src/phobos/std/c/stdlib.d 2004-11-09 00:34:18.000000000 +0100 +++ dmd-0.107/dmd/src/phobos/std/c/stdlib.d 2004-11-29 18:01:34.000000000 +0100 @@ -12,6 +12,14 @@ _MAX_EXT = 256, } +struct div_t { int quot,rem; } +struct ldiv_t { int quot,rem; } +struct lldiv_t { long quot,rem; } + + div_t div(int,int); + ldiv_t ldiv(int,int); + lldiv_t lldiv(long, long); + const int EXIT_SUCCESS = 0; const int EXIT_FAILURE = 1; @@ -26,6 +34,8 @@ void *realloc(void *, uint); void free(void *); + void *bsearch(void *,void *,size_t,size_t, + int function(void *,void *)); void qsort(void *base, uint nelems, uint elemsize, int (*compare)(void *elem1, void *elem2)); @@ -39,3 +49,14 @@ int getErrno(); int setErrno(int); +double atof(char *); +int atoi(char *); +int atol(char *); +double strtod(char *,char **); +real strtold(char *,char **); +long strtol(char *,char **,int); +uint strtoul(char *,char **,int); +long atoll(char *); +long strtoll(char *,char **,int); +ulong strtoull(char *,char **,int); + diff -uNr dmd-0.106/dmd/src/phobos/std/c/time.d dmd-0.107/dmd/src/phobos/std/c/time.d --- dmd-0.106/dmd/src/phobos/std/c/time.d 2004-11-09 00:34:18.000000000 +0100 +++ dmd-0.107/dmd/src/phobos/std/c/time.d 2004-11-29 18:01:34.000000000 +0100 @@ -6,6 +6,8 @@ module std.c.time; +import std.c.stddef; + extern (C): version (Windows) @@ -64,8 +66,8 @@ void usleep(uint); void msleep(uint); -wchar *_wasctime(tm *); -wchar *_wctime(time_t *); -size_t wcsftime(wchar *, size_t, wchar *, tm *); -wchar *_wstrdate(wchar *); -wchar *_wstrtime(wchar *); +wchar_t *_wasctime(tm *); +wchar_t *_wctime(time_t *); +size_t wcsftime(wchar_t *, size_t, wchar_t *, tm *); +wchar_t *_wstrdate(wchar_t *); +wchar_t *_wstrtime(wchar_t *); diff -uNr dmd-0.106/dmd/src/phobos/std/openrj.d dmd-0.107/dmd/src/phobos/std/openrj.d --- dmd-0.106/dmd/src/phobos/std/openrj.d 1970-01-01 01:00:00.000000000 +0100 +++ dmd-0.107/dmd/src/phobos/std/openrj.d 2004-11-29 18:01:34.000000000 +0100 @@ -0,0 +1,66 @@ + +// openrj.d +// placed into Public Domain + +module std.openrj; + +import std.string; + +alias char[][] [char[]] [] openrj_t; + +class OpenrjException : Exception +{ + uint linnum; + + this(uint linnum, char[] msg) + { + this.linnum = linnum; + super(std.string.format("OpenrjException line %s: %s", linnum, msg)); + } +} + +openrj_t parse(char[] db) +{ + openrj_t rj; + char[][] lines; + char[][] [char[]] record; + + lines = std.string.splitlines(db); + + for (uint linnum = 0; linnum < lines.length; linnum++) + { + char[] line = lines[linnum]; + + // Splice lines ending with backslash + while (line.length && line[length - 1] == '\\') + { + if (++linnum == lines.length) + throw new OpenrjException(linnum, "no line after \\ line"); + line = line[0 .. length - 1] ~ lines[linnum]; + } + + if (line[0 .. 2] == "%%") + { + // Comment lines separate records + if (record) + rj ~= record; + record = null; + line = null; + continue; + } + + int colon = std.string.find(line, ':'); + if (colon == -1) + throw new OpenrjException(linnum, "'key : value' expected"); + + char[] key = std.string.strip(line[0 .. colon]); + char[] value = std.string.strip(line[colon + 1 .. length]); + + char[][] fields = record[key]; + fields ~= value; + record[key] = fields; + } + if (record) + rj ~= record; + return rj; +} diff -uNr dmd-0.106/dmd/src/phobos/std/socket.d dmd-0.107/dmd/src/phobos/std/socket.d --- dmd-0.106/dmd/src/phobos/std/socket.d 2004-11-09 00:34:18.000000000 +0100 +++ dmd-0.107/dmd/src/phobos/std/socket.d 2004-11-29 18:01:34.000000000 +0100 @@ -32,7 +32,7 @@ version(Win32) { - typedef uint socket_t = ~0; + typedef uint socket_t = ~0u; } else version(BsdSockets) { @@ -76,7 +76,7 @@ const int IOCPARM_MASK = 0x7f; const int IOC_IN = cast(int)0x80000000; - const int FIONBIO = IOC_IN | ((uint.sizeof & IOCPARM_MASK) << 16) | (102 << 8) | 126; + const int FIONBIO = cast(int)(IOC_IN | ((uint.sizeof & IOCPARM_MASK) << 16) | (102 << 8) | 126); const int SOL_SOCKET = 0xFFFF; const int SO_TYPE = 0x1008; @@ -543,7 +543,7 @@ public: const uint ADDR_ANY = 0; - const uint ADDR_NONE = cast(int)-1; + const uint ADDR_NONE = cast(uint)-1; const ushort PORT_ANY = 0; @@ -1356,7 +1356,7 @@ fe = checkError ? checkError.toFd_set() : null; } - int result = .select(socket_t.max - 1, fr, fw, fe, tv); + int result = .select(cast(int)(socket_t.max - 1), fr, fw, fe, tv); version(Win32) { diff -uNr dmd-0.106/dmd/src/phobos/std/stdio.d dmd-0.107/dmd/src/phobos/std/stdio.d --- dmd-0.106/dmd/src/phobos/std/stdio.d 2004-11-09 00:34:18.000000000 +0100 +++ dmd-0.107/dmd/src/phobos/std/stdio.d 2004-11-29 18:01:34.000000000 +0100 @@ -10,68 +10,110 @@ private import std.format; private import std.utf; +version (DigitalMars) +{ + version (Windows) + { + version = DIGITAL_MARS_STDIO; + } +} + + +version (DIGITAL_MARS_STDIO) +{ + extern (C) + { + int _fputc_nlock(int, FILE*); + int _fputwc_nlock(int, FILE*); + int __fp_lock(FILE*); + void __fp_unlock(FILE*); + } + alias _fputc_nlock FPUTC; + alias _fputwc_nlock FPUTWC; +} +else +{ + alias std.c.stdio.fputc FPUTC; + alias std.c.stdio.fputwc FPUTWC; + + int __fp_lock(FILE* fp) { return 0; } + void __fp_unlock(FILE* fp) { } +} + private void writex(FILE* fp, TypeInfo[] arguments, void* argptr, int newline) { int orientation; orientation = fwide(fp, 0); - if (orientation <= 0) // byte orientation or no orientation + try { - void putc(dchar c) - { - if (c <= 0x7F) - { - std.c.stdio.fputc(c, fp); - } - else - { char[4] buf; - char[] b; + /* Do the file stream locking at the outermost level + * rather than character by character. + */ + __fp_lock(fp); - b = std.utf.toUTF8(buf, c); - for (size_t i = 0; i < b.length; i++) - std.c.stdio.fputc(b[i], fp); - } - } - - std.format.doFormat(&putc, arguments, argptr); - if (newline) - std.c.stdio.fputc('\n', fp); - } - else if (orientation > 0) // wide orientation - { - version (Windows) + if (orientation <= 0) // byte orientation or no orientation { - void putcw(dchar c) + void putc(dchar c) { - assert(isValidDchar(c)); - if (c <= 0xFFFF) + if (c <= 0x7F) { - std.c.stdio.fputwc(c, fp); + FPUTC(c, fp); } else - { wchar[2] buf; + { char[4] buf; + char[] b; - buf[0] = (((c - 0x10000) >> 10) & 0x3FF) + 0xD800; - buf[1] = ((c - 0x10000) & 0x3FF) + 0xDC00; - std.c.stdio.fputwc(buf[0], fp); - std.c.stdio.fputwc(buf[1], fp); + b = std.utf.toUTF8(buf, c); + for (size_t i = 0; i < b.length; i++) + FPUTC(b[i], fp); } } + + std.format.doFormat(&putc, arguments, argptr); + if (newline) + FPUTC('\n', fp); } - else version (linux) + else if (orientation > 0) // wide orientation { - void putcw(dchar c) + version (Windows) { - std.c.stdio.fputwc(c, fp); + void putcw(dchar c) + { + assert(isValidDchar(c)); + if (c <= 0xFFFF) + { + FPUTWC(c, fp); + } + else + { wchar[2] buf; + + buf[0] = (((c - 0x10000) >> 10) & 0x3FF) + 0xD800; + buf[1] = ((c - 0x10000) & 0x3FF) + 0xDC00; + FPUTWC(buf[0], fp); + FPUTWC(buf[1], fp); + } + } + } + else version (linux) + { + void putcw(dchar c) + { + FPUTWC(c, fp); + } + } + else + { + static assert(0); } - } - else - { - static assert(0); - } - std.format.doFormat(&putcw, arguments, argptr); - if (newline) - std.c.stdio.fputwc('\n', fp); + std.format.doFormat(&putcw, arguments, argptr); + if (newline) + FPUTWC('\n', fp); + } + } + finally + { + __fp_unlock(fp); } } diff -uNr dmd-0.106/dmd/src/phobos/std/stream.d dmd-0.107/dmd/src/phobos/std/stream.d --- dmd-0.106/dmd/src/phobos/std/stream.d 2004-11-09 00:34:18.000000000 +0100 +++ dmd-0.107/dmd/src/phobos/std/stream.d 2004-11-29 18:01:34.000000000 +0100 @@ -1,7 +1,7 @@ /* * Copyright (c) 2001, 2002 * Pavel "EvilOne" Minayev - * with buffering added by Ben Hinkle + * with buffering and endian support added by Ben Hinkle * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -21,6 +21,7 @@ * File an OS file stream * BufferedStream a buffered stream wrapping another stream * BufferedFile a buffered File + * EndianStream a wrapper stream for swapping byte order and BOMs * MemoryStream a stream entirely stored in main memory * SliceStream a portion of another stream * TArrayStream a stream wrapping an array-like buffer @@ -68,7 +69,13 @@ alias std.format.va_list va_list; private import std.c.stdio; alias std.c.stdio.va_list c_va_list; -private import std.utf; + +private +{ + import std.system; // for Endian enumeration + import std.intrinsic; // for bswap + import std.utf; +} version (Windows) { @@ -99,10 +106,15 @@ void read(out float x); void read(out double x); void read(out real x); + void read(out ifloat x); + void read(out idouble x); void read(out ireal x); + void read(out cfloat x); + void read(out cdouble x); void read(out creal x); void read(out char x); void read(out wchar x); + void read(out dchar x); // reads a string, written earlier by write() void read(out char[] s); @@ -182,10 +194,15 @@ void write(float x); void write(double x); void write(real x); + void write(ifloat x); + void write(idouble x); void write(ireal x); + void write(cfloat x); + void write(cdouble x); void write(creal x); void write(char x); void write(wchar x); + void write(dchar x); // writes a string, together with its length void write(char[] s); @@ -267,10 +284,15 @@ void read(out float x) { readExact(&x, x.sizeof); } void read(out double x) { readExact(&x, x.sizeof); } void read(out real x) { readExact(&x, x.sizeof); } + void read(out ifloat x) { readExact(&x, x.sizeof); } + void read(out idouble x) { readExact(&x, x.sizeof); } void read(out ireal x) { readExact(&x, x.sizeof); } + void read(out cfloat x) { readExact(&x, x.sizeof); } + void read(out cdouble x) { readExact(&x, x.sizeof); } void read(out creal x) { readExact(&x, x.sizeof); } void read(out char x) { readExact(&x, x.sizeof); } void read(out wchar x) { readExact(&x, x.sizeof); } + void read(out dchar x) { readExact(&x, x.sizeof); } // reads a string, written earlier by write() void read(out char[] s) @@ -865,10 +887,15 @@ void write(float x) { writeExact(&x, x.sizeof); } void write(double x) { writeExact(&x, x.sizeof); } void write(real x) { writeExact(&x, x.sizeof); } + void write(ifloat x) { writeExact(&x, x.sizeof); } + void write(idouble x) { writeExact(&x, x.sizeof); } void write(ireal x) { writeExact(&x, x.sizeof); } + void write(cfloat x) { writeExact(&x, x.sizeof); } + void write(cdouble x) { writeExact(&x, x.sizeof); } void write(creal x) { writeExact(&x, x.sizeof); } void write(char x) { writeExact(&x, x.sizeof); } void write(wchar x) { writeExact(&x, x.sizeof); } + void write(dchar x) { writeExact(&x, x.sizeof); } // writes a string, together with its length void write(char[] s) @@ -1090,13 +1117,11 @@ return crc; } - } // A stream that wraps a source stream in a buffer class BufferedStream : Stream { - Stream s; // source stream ubyte[] buffer; // buffer, if any uint bufferCurPos; // current position in buffer @@ -1781,6 +1806,310 @@ } +enum BOM { UTF8, UTF16LE, UTF16BE, UTF32LE, UTF32BE } + +private const int NBOMS = 5; +Endian[NBOMS] BOMEndian = [std.system.endian, + Endian.LittleEndian, Endian.BigEndian, + Endian.LittleEndian, Endian.BigEndian]; + +ubyte[][NBOMS] ByteOrderMarks; +ubyte[3] BOM_UTF8_data = [0xEF, 0xBB, 0xBF]; +ubyte[2] BOM_UTF16LE_data = [0xFF, 0xFE]; +ubyte[2] BOM_UTF16BE_data = [0xFE, 0xFF]; +ubyte[4] BOM_UTF32LE_data = [0xFF, 0xFE, 0x00, 0x00]; +ubyte[4] BOM_UTF32BE_data = [0x00, 0x00, 0xFE, 0xFF]; + +// A stream that wraps a source stream with endian support +class EndianStream : Stream +{ + Stream s; // source stream + Endian endian; // endianness of the source stream + + // Construct an Endian stream with specified endianness, defaulting + // to the native endiannes. + this(Stream source, Endian end = std.system.endian) + { + super(); + s = source; + endian = end; + readable = s.readable; + writeable = s.writeable; + seekable = s.seekable; + isopen = s.isOpen(); + } + + /* Return -1 if no BOM and otherwise read the BOM and return it. + * If there is no BOM then the bytes read are pushed back onto + * the ungetc buffer or ungetcw buffer. Pass ungetCharSize == 2 + * to use ungetcw instead of ungetc. + */ + int readBOM(int ungetCharSize = 1) + { + ubyte[4] BOM_buffer; + int n = 0; // the number of read bytes + int result = -1; // the last match or -1 + for (int i=0; i < NBOMS; ++i) + { + int j; + ubyte[] bom = ByteOrderMarks[i]; + for (j=0; j < bom.length; ++j) + { + if (n <= j) // have to read more + { + if (eof()) + break; + readExact(&BOM_buffer[n++],1); + } + if (BOM_buffer[j] != bom[j]) + break; + } + if (j == bom.length) // found a match + result = i; + } + int m = 0; + if (result != -1) + { + endian = BOMEndian[result]; // set stream endianness + m = ByteOrderMarks[result].length; + } + if ((ungetCharSize == 1 && result == -1) || (result == BOM.UTF8)) + { + while (n-- > m) + ungetc(BOM_buffer[n]); + } + else // should eventually support unget for dchar as well + { + if (n & 1) // make sure we have an even number of bytes + readExact(&BOM_buffer[n++],1); + while (n > m) + { + n -= 2; + wchar cw = *(cast(wchar*)&BOM_buffer[n]); + fixBO(&cw,2); + ungetcw(cw); + } + } + return result; + } + + // Correct the byte order of buffer to match native endianness. + // size must be even + final void fixBO(void* buffer, uint size) + { + if (endian != std.system.endian) + { + ubyte* startb = cast(ubyte*)buffer; + uint* start = cast(uint*)buffer; + switch (size) + { + case 0: break; + case 2: + { + ubyte x = *startb; + *startb = *(startb+1); + *(startb+1) = x; + break; + } + case 4: + { + *start = bswap(*start); + break; + } + default: + { + uint* end = cast(uint*)(buffer + size - uint.sizeof); + while (start < end) + { + uint x = bswap(*start); + *start = bswap(*end); + *end = x; + ++start; + --end; + } + startb = cast(ubyte*)start; + ubyte* endb = cast(ubyte*)end; + int len = uint.sizeof - (startb - endb); + if (len > 0) + fixBO(startb,len); + } + } + } + } + + uint readBlock(void* buffer, uint size) + { + return s.readBlock(buffer,size); + } + + void read(out short x) { readExact(&x, x.sizeof); fixBO(&x,x.sizeof); } + void read(out ushort x) { readExact(&x, x.sizeof); fixBO(&x,x.sizeof); } + void read(out int x) { readExact(&x, x.sizeof); fixBO(&x,x.sizeof); } + void read(out uint x) { readExact(&x, x.sizeof); fixBO(&x,x.sizeof); } + void read(out long x) { readExact(&x, x.sizeof); fixBO(&x,x.sizeof); } + void read(out ulong x) { readExact(&x, x.sizeof); fixBO(&x,x.sizeof); } + void read(out float x) { readExact(&x, x.sizeof); fixBO(&x,x.sizeof); } + void read(out double x) { readExact(&x, x.sizeof); fixBO(&x,x.sizeof); } + void read(out real x) { readExact(&x, x.sizeof); fixBO(&x,x.sizeof); } + void read(out ifloat x) { readExact(&x, x.sizeof); fixBO(&x,x.sizeof); } + void read(out idouble x) { readExact(&x, x.sizeof); fixBO(&x,x.sizeof); } + void read(out ireal x) { readExact(&x, x.sizeof); fixBO(&x,x.sizeof); } + void read(out cfloat x) { readExact(&x, x.sizeof); fixBO(&x,x.sizeof); } + void read(out cdouble x) { readExact(&x, x.sizeof); fixBO(&x,x.sizeof); } + void read(out creal x) { readExact(&x, x.sizeof); fixBO(&x,x.sizeof); } + void read(out wchar x) { readExact(&x, x.sizeof); fixBO(&x,x.sizeof); } + void read(out dchar x) { readExact(&x, x.sizeof); fixBO(&x,x.sizeof); } + + wchar[] readStringW(uint length) + { + wchar[] result = new wchar[length]; + readExact(result, result.length * wchar.sizeof); + while (length--) + fixBO(&result[length],2); + return result; + } + + // Write the specified BOM to the source stream + void writeBOM(BOM b) + { + ubyte[] bom = ByteOrderMarks[b]; + writeBlock(bom,bom.length); + } + + uint writeBlock(void* buffer, uint size) + { + return s.writeBlock(buffer,size); + } + void write(short x) { fixBO(&x,x.sizeof); writeExact(&x, x.sizeof); } + void write(ushort x) { fixBO(&x,x.sizeof); writeExact(&x, x.sizeof); } + void write(int x) { fixBO(&x,x.sizeof); writeExact(&x, x.sizeof); } + void write(uint x) { fixBO(&x,x.sizeof); writeExact(&x, x.sizeof); } + void write(long x) { fixBO(&x,x.sizeof); writeExact(&x, x.sizeof); } + void write(ulong x) { fixBO(&x,x.sizeof); writeExact(&x, x.sizeof); } + void write(float x) { fixBO(&x,x.sizeof); writeExact(&x, x.sizeof); } + void write(double x) { fixBO(&x,x.sizeof); writeExact(&x, x.sizeof); } + void write(real x) { fixBO(&x,x.sizeof); writeExact(&x, x.sizeof); } + void write(ifloat x) { fixBO(&x,x.sizeof); writeExact(&x, x.sizeof); } + void write(idouble x) { fixBO(&x,x.sizeof); writeExact(&x, x.sizeof); } + void write(ireal x) { fixBO(&x,x.sizeof); writeExact(&x, x.sizeof); } + void write(cfloat x) { fixBO(&x,x.sizeof); writeExact(&x, x.sizeof); } + void write(cdouble x) { fixBO(&x,x.sizeof); writeExact(&x, x.sizeof); } + void write(creal x) { fixBO(&x,x.sizeof); writeExact(&x, x.sizeof); } + void write(wchar x) { fixBO(&x,x.sizeof); writeExact(&x, x.sizeof); } + void write(dchar x) { fixBO(&x,x.sizeof); writeExact(&x, x.sizeof); } + + void writeStringW(wchar[] str) + { + foreach(wchar cw;str) + { + fixBO(&cw,2); + s.writeExact(&cw, 2); + } + } + + // close stream + override void close() + { + if (isopen) { + s.close(); + isopen = false; + } + } + + override ulong seek(long offset, SeekPos whence) + { + return s.seek(offset,whence); + } + + override void flush() { super.flush(); s.flush(); } + override bit eof() { return s.eof(); } + override ulong size() { return s.size(); } + + unittest { + MemoryStream m; + m = new MemoryStream (); + EndianStream em = new EndianStream(m,Endian.BigEndian); + uint x = 0x11223344; + em.write(x); + assert( m.data[0] == 0x11 ); + assert( m.data[1] == 0x22 ); + assert( m.data[2] == 0x33 ); + assert( m.data[3] == 0x44 ); + em.position(0); + ushort x2 = 0x5566; + em.write(x2); + assert( m.data[0] == 0x55 ); + assert( m.data[1] == 0x66 ); + em.position(0); + static ubyte[12] x3 = [1,2,3,4,5,6,7,8,9,10,11,12]; + em.fixBO(x3,12); + if (std.system.endian == Endian.LittleEndian) { + assert( x3[0] == 12 ); + assert( x3[1] == 11 ); + assert( x3[2] == 10 ); + assert( x3[4] == 8 ); + assert( x3[5] == 7 ); + assert( x3[6] == 6 ); + assert( x3[8] == 4 ); + assert( x3[9] == 3 ); + assert( x3[10] == 2 ); + assert( x3[11] == 1 ); + } + em.endian = Endian.LittleEndian; + em.write(x); + assert( m.data[0] == 0x44 ); + assert( m.data[1] == 0x33 ); + assert( m.data[2] == 0x22 ); + assert( m.data[3] == 0x11 ); + em.position(0); + em.write(x2); + assert( m.data[0] == 0x66 ); + assert( m.data[1] == 0x55 ); + em.position(0); + em.fixBO(x3,12); + if (std.system.endian == Endian.BigEndian) { + assert( x3[0] == 12 ); + assert( x3[1] == 11 ); + assert( x3[2] == 10 ); + assert( x3[4] == 8 ); + assert( x3[5] == 7 ); + assert( x3[6] == 6 ); + assert( x3[8] == 4 ); + assert( x3[9] == 3 ); + assert( x3[10] == 2 ); + assert( x3[11] == 1 ); + } + em.writeBOM(BOM.UTF8); + assert( m.position() == 3 ); + assert( m.data[0] == 0xEF ); + assert( m.data[1] == 0xBB ); + assert( m.data[2] == 0xBF ); + em.writeString ("Hello, world"); + em.position(0); + assert( m.position() == 0 ); + assert( em.readBOM == BOM.UTF8 ); + assert( m.position() == 3 ); + assert( em.getc() == 'H' ); + em.position(0); + em.writeBOM(BOM.UTF16BE); + assert( m.data[0] == 0xFE ); + assert( m.data[1] == 0xFF ); + em.position(0); + em.writeBOM(BOM.UTF16LE); + assert( m.data[0] == 0xFF ); + assert( m.data[1] == 0xFE ); + em.position(0); + em.writeString ("Hello, world"); + em.position(0); + assert( em.readBOM == -1 ); + assert( em.getc() == 'H' ); + assert( em.getc() == 'e' ); + assert( em.getc() == 'l' ); + assert( em.getc() == 'l' ); + em.position(0); + } +} + // Parameterized stream class that wraps an array-like type. // The Buffer type must support .length, opIndex and opSlice class TArrayStream(Buffer): Stream @@ -2158,10 +2487,17 @@ static this() { + // init ByteOrderMarks + ByteOrderMarks[BOM.UTF8] = BOM_UTF8_data; + ByteOrderMarks[BOM.UTF16LE] = BOM_UTF16LE_data; + ByteOrderMarks[BOM.UTF16BE] = BOM_UTF16BE_data; + ByteOrderMarks[BOM.UTF32LE] = BOM_UTF32LE_data; + ByteOrderMarks[BOM.UTF32BE] = BOM_UTF32BE_data; + // open standard I/O devices - stdin = new File(GetStdHandle(-10), FileMode.In); - stdout = new File(GetStdHandle(-11), FileMode.Out); - stderr = new File(GetStdHandle(-12), FileMode.Out); + stdin = new File(GetStdHandle(cast(uint)-10), FileMode.In); + stdout = new File(GetStdHandle(cast(uint)-11), FileMode.Out); + stderr = new File(GetStdHandle(cast(uint)-12), FileMode.Out); } } @@ -2169,6 +2505,13 @@ { static this() { + // init ByteOrderMarks + ByteOrderMarks[BOM.UTF8] = BOM_UTF8_data; + ByteOrderMarks[BOM.UTF16LE] = BOM_UTF16LE_data; + ByteOrderMarks[BOM.UTF16BE] = BOM_UTF16BE_data; + ByteOrderMarks[BOM.UTF32LE] = BOM_UTF32LE_data; + ByteOrderMarks[BOM.UTF32BE] = BOM_UTF32BE_data; + // open standard I/O devices stdin = new File(0, FileMode.In); stdout = new File(1, FileMode.Out); @@ -2176,5 +2519,3 @@ } } -import std.string; -import std.file; diff -uNr dmd-0.106/dmd/src/phobos/std/string.d dmd-0.107/dmd/src/phobos/std/string.d --- dmd-0.106/dmd/src/phobos/std/string.d 2004-11-09 00:34:18.000000000 +0100 +++ dmd-0.107/dmd/src/phobos/std/string.d 2004-11-29 18:01:34.000000000 +0100 @@ -39,9 +39,6 @@ int memcmp(void *, void *, uint); int memicmp(char *, char *, uint); char *strcpy(char *, char *); - int atoi(char *); - long atoll(char *); - double atof(char *); char *strstr(char *, char *); char *strchr(char *, char); char *strrchr(char *, char); @@ -90,13 +87,13 @@ long atoi(char[] s) { - return atoi(toStringz(s)); + return std.c.stdlib.atoi(toStringz(s)); } real atof(char[] s) { // BUG: should implement atold() - return atof(toStringz(s)); + return std.c.stdlib.atof(toStringz(s)); } /********************************** diff -uNr dmd-0.106/dmd/src/phobos/win32.mak dmd-0.107/dmd/src/phobos/win32.mak --- dmd-0.106/dmd/src/phobos/win32.mak 2004-11-09 00:34:18.000000000 +0100 +++ dmd-0.107/dmd/src/phobos/win32.mak 2004-11-29 18:01:34.000000000 +0100 @@ -62,7 +62,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 \ + perf.obj openrj.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 \ @@ -85,10 +85,10 @@ std\intrinsic.d std\array.d std\switcherr.d std\syserror.d \ std\regexp.d std\random.d std\stream.d std\process.d std\recls.d \ std\socket.d std\socketstream.d std\loader.d std\stdarg.d std\format.d \ - std\stdio.d std\perf.d + std\stdio.d std\perf.d std\openrj.d SRC_STD_C= std\c\process.d std\c\stdlib.d std\c\time.d std\c\stdio.d \ - std\c\math.d std\c\stdarg.d + std\c\math.d std\c\stdarg.d std\c\stddef.d SRC_TI= \ std\typeinfo\ti_wchar.d std\typeinfo\ti_uint.d \ @@ -463,6 +463,9 @@ #object.obj : object.d # $(DMD) -c $(DFLAGS) object.d +openrj.obj : std\openrj.d + $(DMD) -c $(DFLAGS) std\openrj.d + outbuffer.obj : std\outbuffer.d $(DMD) -c $(DFLAGS) std\outbuffer.d