Mercurial > projects > ddmd
diff dmd/VarDeclaration.d @ 98:5c859d5fbe27
and more
author | Trass3r |
---|---|
date | Tue, 31 Aug 2010 03:53:49 +0200 |
parents | 23280d154c5b |
children | e6090d1aea7c |
line wrap: on
line diff
--- a/dmd/VarDeclaration.d Tue Aug 31 02:12:15 2010 +0200 +++ b/dmd/VarDeclaration.d Tue Aug 31 03:53:49 2010 +0200 @@ -74,7 +74,8 @@ uint offset; bool noauto; // no auto semantics version (DMDV2) { - FuncDeclarations nestedrefs; // referenced by these lexically nested functions + FuncDeclarations nestedrefs; // referenced by these lexically nested functions + bool isargptr = false; // if parameter that _argptr points to } else { int nestedref; // referenced by a lexically nested function } @@ -95,7 +96,8 @@ { super(id); -debug { +debug +{ if (!type && !init) { writef("VarDeclaration('%s')\n", id.toChars()); @@ -105,8 +107,24 @@ assert(type || init); this.type = type; this.init = init; +version(_DH) +{ + this.htype = null; + this.hinit = null; +} this.loc = loc; + /* TODO: + #if DMDV1 + nestedref = 0; + #endif + ctorinit = 0; + aliassym = NULL; + onstack = 0; + canassign = 0; + value = NULL; + rundtor = NULL; + */ nestedrefs = new FuncDeclarations(); } @@ -521,10 +539,12 @@ else if (t.ty == TY.Tstruct) { ei.exp = ei.exp.semantic(sc); -version (DMDV2) { + ei.exp = resolveProperties(sc, ei.exp); + StructDeclaration sd = (cast(TypeStruct)t).sym; +version (DMDV2) +{ /* Look to see if initializer is a call to the constructor */ - StructDeclaration sd = (cast(TypeStruct)t).sym; if (sd.ctor && // there are constructors ei.exp.type.ty == TY.Tstruct && // rvalue is the same struct (cast(TypeStruct)ei.exp.type).sym == sd && @@ -562,10 +582,22 @@ } if (!ei.exp.implicitConvTo(type)) { + Type *ti = ei.exp.type.toBasetype(); + // Look for constructor first + if (sd.ctor && + /* Initializing with the same type is done differently + */ + !(ti.ty == Tstruct && t.toDsymbol(sc) == ti.toDsymbol(sc))) + { + // Rewrite as e1.ctor(arguments) + Expression ector = new DotIdExp(loc, e1, Id.ctor); + ei.exp = new CallExp(loc, ector, ei.exp); + } + else /* Look for opCall * See bugzilla 2702 for more discussion */ - Type ti = ei.exp.type.toBasetype(); + // Don't cast away invariant or mutability in initializer if (search_function(sd, Id.call) && /* Initializing with the same type is done differently @@ -590,7 +622,8 @@ } } else if (storage_class & (STC.STCconst | STC.STCimmutable | STC.STCmanifest) || - type.isConst() || type.isInvariant()) + type.isConst() || type.isInvariant() || + parent.isAggregateDeclaration()) { /* Because we may need the results of a const declaration in a * subsequent type, such as an array dimension, before semantic2()