Mercurial > projects > ddmd
view dmd/NewAnonClassExp.d @ 177:1475fd394c9e
bug fixes
author | korDen |
---|---|
date | Sun, 10 Oct 2010 10:38:55 +0400 |
parents | 14feb7ae01a6 |
children | e3afd1303184 |
line wrap: on
line source
module dmd.NewAnonClassExp; import dmd.common; import dmd.Expression; import dmd.OutBuffer; import dmd.Loc; import dmd.Scope; import dmd.ClassDeclaration; import dmd.DeclarationExp; import dmd.NewExp; import dmd.CommaExp; import dmd.PREC; import dmd.HdrGenState; import dmd.ArrayTypes; import dmd.TOK; import dmd.expression.Util; class NewAnonClassExp : Expression { /* thisexp.new(newargs) class baseclasses { } (arguments) */ Expression thisexp; // if !NULL, 'this' for class being allocated Expressions newargs; // Array of Expression's to call new operator ClassDeclaration cd; // class being instantiated Expressions arguments; // Array of Expression's to call class constructor this(Loc loc, Expression thisexp, Expressions newargs, ClassDeclaration cd, Expressions arguments) { super(loc, TOKnewanonclass, NewAnonClassExp.sizeof); this.thisexp = thisexp; this.newargs = newargs; this.cd = cd; this.arguments = arguments; } override Expression syntaxCopy() { return new NewAnonClassExp(loc, thisexp ? thisexp.syntaxCopy() : null, arraySyntaxCopy(newargs), cast(ClassDeclaration)cd.syntaxCopy(null), arraySyntaxCopy(arguments)); } override Expression semantic(Scope sc) { version (LOGSEMANTIC) { printf("NewAnonClassExp.semantic() %s\n", toChars()); //printf("thisexp = %p\n", thisexp); //printf("type: %s\n", type.toChars()); } Expression d = new DeclarationExp(loc, cd); d = d.semantic(sc); Expression n = new NewExp(loc, thisexp, newargs, cd.type, arguments); Expression c = new CommaExp(loc, d, n); return c.semantic(sc); } override bool checkSideEffect(int flag) { return true; } override void toCBuffer(OutBuffer buf, HdrGenState* hgs) { if (thisexp) { expToCBuffer(buf, hgs, thisexp, PREC.PREC_primary); buf.writeByte('.'); } buf.writestring("new"); if (newargs && newargs.dim) { buf.writeByte('('); argsToCBuffer(buf, newargs, hgs); buf.writeByte(')'); } buf.writestring(" class "); if (arguments && arguments.dim) { buf.writeByte('('); argsToCBuffer(buf, arguments, hgs); buf.writeByte(')'); } //buf.writestring(" { }"); if (cd) { cd.toCBuffer(buf, hgs); } } override bool canThrow() { return true; } }