Mercurial > projects > ddmd
diff dmd/Expression.d @ 55:8c2c7b7579f8
Expression.toMangleBuffer
Expression.toDelegate
Expression.scanForNestedRef
TypeStruct.deduceType
TypeStruct.toChars
DefaultInitExp wrong TOK bug fixed
author | korDen |
---|---|
date | Sat, 21 Aug 2010 13:28:16 +0400 |
parents | a8b50ff7f201 |
children | efb1e5bdf63c |
line wrap: on
line diff
--- a/dmd/Expression.d Sat Aug 21 12:51:02 2010 +0400 +++ b/dmd/Expression.d Sat Aug 21 13:28:16 2010 +0400 @@ -31,6 +31,12 @@ import dmd.CommaExp; import dmd.NullExp; import dmd.AddrExp; +import dmd.LINK; +import dmd.FuncExp; +import dmd.ReturnStatement; +import dmd.Statement; +import dmd.FuncLiteralDeclaration; +import dmd.TypeFunction; import dmd.ErrorExp; import dmd.TypeStruct; import dmd.CastExp; @@ -348,7 +354,11 @@ void toMangleBuffer(OutBuffer buf) { + error("expression %s is not a valid template value argument", toChars()); assert(false); +version (DEBUG) { + dump(0); +} } int isLvalue() @@ -772,14 +782,38 @@ return e; } + /******************************************** + * Convert from expression to delegate that returns the expression, + * i.e. convert: + * expr + * to: + * t delegate() { return expr; } + */ Expression toDelegate(Scope sc, Type t) { - assert(false); + //printf("Expression.toDelegate(t = %s) %s\n", t.toChars(), toChars()); + TypeFunction tf = new TypeFunction(null, t, 0, LINKd); + FuncLiteralDeclaration fld = new FuncLiteralDeclaration(loc, loc, tf, TOKdelegate, null); + Expression e; + static if (true) { + sc = sc.push(); + sc.parent = fld; // set current function to be the delegate + e = this; + e.scanForNestedRef(sc); + sc = sc.pop(); + } else { + e = this.syntaxCopy(); + } + Statement s = new ReturnStatement(loc, e); + fld.fbody = s; + e = new FuncExp(loc, fld); + e = e.semantic(sc); + return e; } void scanForNestedRef(Scope sc) { - assert(false); + //printf("Expression.scanForNestedRef(%s)\n", toChars()); } Expression optimize(int result)