Mercurial > projects > ddmd
diff dmd/StructDeclaration.d @ 79:43073c7c7769
updated to 2.035
also implemented a few missing functions
still crashes in Import.importAll though
author | Trass3r |
---|---|
date | Mon, 30 Aug 2010 03:57:51 +0200 |
parents | ad4792a1cfd6 |
children | be2ab491772e b17640f0e4e8 |
line wrap: on
line diff
--- a/dmd/StructDeclaration.d Sun Aug 29 14:39:08 2010 +0100 +++ b/dmd/StructDeclaration.d Mon Aug 30 03:57:51 2010 +0200 @@ -322,28 +322,27 @@ // Determine if struct is all zeros or not zeroInit = true; - for (i = 0; i < fields.dim; i++) + foreach (Dsymbol s; fields) { - Dsymbol s = cast(Dsymbol)fields.data[i]; - VarDeclaration vd = s.isVarDeclaration(); - if (vd && !vd.isDataseg()) - { - if (vd.init) + VarDeclaration vd = s.isVarDeclaration(); + if (vd && !vd.isDataseg()) { - // Should examine init to see if it is really all 0's - zeroInit = false; - break; - } - else - { - if (!vd.type.isZeroInit(loc)) - { + if (vd.init) + { + // Should examine init to see if it is really all 0's zeroInit = false; break; - } + } + else + { + if (!vd.type.isZeroInit(loc)) + { + zeroInit = false; + break; + } + } } } - } /* Look for special member functions. */ @@ -396,9 +395,8 @@ /* If any of the fields need an opAssign, then we * need it too. */ - for (size_t i = 0; i < fields.dim; i++) + foreach (Dsymbol s; fields) { - Dsymbol s = cast(Dsymbol)fields.data[i]; VarDeclaration v = s.isVarDeclaration(); assert(v && v.storage_class & STC.STCfield); if (v.storage_class & STC.STCref) @@ -500,9 +498,8 @@ { /* Do memberwise copy */ //printf("\tmemberwise copy\n"); - for (size_t i = 0; i < fields.dim; i++) + foreach (Dsymbol s; fields) { - Dsymbol s = cast(Dsymbol)fields.data[i]; VarDeclaration v = s.isVarDeclaration(); assert(v && v.storage_class & STC.STCfield); // this.v = s.v; @@ -551,49 +548,48 @@ //printf("StructDeclaration.buildPostBlit() %s\n", toChars()); Expression e = null; - for (size_t i = 0; i < fields.dim; i++) + foreach (Dsymbol s; fields) { - Dsymbol s = cast(Dsymbol)fields.data[i]; - VarDeclaration v = s.isVarDeclaration(); - assert(v && v.storage_class & STC.STCfield); - if (v.storage_class & STC.STCref) - continue; - Type tv = v.type.toBasetype(); - size_t dim = 1; - while (tv.ty == TY.Tsarray) - { TypeSArray ta = cast(TypeSArray)tv; - dim *= (cast(TypeSArray)tv).dim.toInteger(); - tv = tv.nextOf().toBasetype(); - } - if (tv.ty == TY.Tstruct) - { TypeStruct ts = cast(TypeStruct)tv; - StructDeclaration sd = ts.sym; - if (sd.postblit) - { Expression ex; - - // this.v - ex = new ThisExp(Loc(0)); - ex = new DotVarExp(Loc(0), ex, v, 0); - - if (dim == 1) - { // this.v.postblit() - ex = new DotVarExp(Loc(0), ex, sd.postblit, 0); - ex = new CallExp(Loc(0), ex); + VarDeclaration v = s.isVarDeclaration(); + assert(v && v.storage_class & STC.STCfield); + if (v.storage_class & STC.STCref) + continue; + Type tv = v.type.toBasetype(); + size_t dim = 1; + while (tv.ty == TY.Tsarray) + { TypeSArray ta = cast(TypeSArray)tv; + dim *= (cast(TypeSArray)tv).dim.toInteger(); + tv = tv.nextOf().toBasetype(); } - else - { - // Typeinfo.postblit(cast(void*)&this.v); - Expression ea = new AddrExp(Loc(0), ex); - ea = new CastExp(Loc(0), ea, Type.tvoid.pointerTo()); - - Expression et = v.type.getTypeInfo(sc); - et = new DotIdExp(Loc(0), et, Id.postblit); - - ex = new CallExp(Loc(0), et, ea); + if (tv.ty == TY.Tstruct) + { TypeStruct ts = cast(TypeStruct)tv; + StructDeclaration sd = ts.sym; + if (sd.postblit) + { Expression ex; + + // this.v + ex = new ThisExp(Loc(0)); + ex = new DotVarExp(Loc(0), ex, v, 0); + + if (dim == 1) + { // this.v.postblit() + ex = new DotVarExp(Loc(0), ex, sd.postblit, 0); + ex = new CallExp(Loc(0), ex); + } + else + { + // Typeinfo.postblit(cast(void*)&this.v); + Expression ea = new AddrExp(Loc(0), ex); + ea = new CastExp(Loc(0), ea, Type.tvoid.pointerTo()); + + Expression et = v.type.getTypeInfo(sc); + et = new DotIdExp(Loc(0), et, Id.postblit); + + ex = new CallExp(Loc(0), et, ea); + } + e = Expression.combine(e, ex); // combine in forward order + } } - e = Expression.combine(e, ex); // combine in forward order - } - } } /* Build our own "postblit" which executes e @@ -787,16 +783,15 @@ void toDt(dt_t** pdt) { uint offset; - uint i; dt_t* dt; //printf("StructDeclaration.toDt(), this='%s'\n", toChars()); offset = 0; // Note equivalence of this loop to class's - for (i = 0; i < fields.dim; i++) + for (uint i = 0; i < fields.dim; i++) { - VarDeclaration v = cast(VarDeclaration)fields.data[i]; + VarDeclaration v = cast(VarDeclaration)fields[i]; //printf("\tfield '%s' voffset %d, offset = %d\n", v.toChars(), v.offset, offset); dt = null; int sz;