Mercurial > projects > ddmd
diff dmd/CompoundDeclarationStatement.d @ 174:af724d3510d7
lot os toCBuffer methods implemented
moved shared Type.* stuff into Global
author | korDen |
---|---|
date | Sun, 10 Oct 2010 03:47:23 +0400 |
parents | c77e9f4f1793 |
children | e3afd1303184 |
line wrap: on
line diff
--- a/dmd/CompoundDeclarationStatement.d Sun Oct 10 01:55:35 2010 +0400 +++ b/dmd/CompoundDeclarationStatement.d Sun Oct 10 03:47:23 2010 +0400 @@ -3,7 +3,15 @@ import dmd.common; import dmd.CompoundStatement; import dmd.Loc; +import dmd.TOK; import dmd.ArrayTypes; +import dmd.VarDeclaration; +import dmd.AssignExp; +import dmd.ExpInitializer; +import dmd.Declaration; +import dmd.StorageClassDeclaration; +import dmd.DeclarationStatement; +import dmd.DeclarationExp; import dmd.Statement; import dmd.OutBuffer; import dmd.HdrGenState; @@ -15,13 +23,13 @@ super(loc, s); ///statements = s; } - + override Statement syntaxCopy() { Statements a = new Statements(); a.setDim(statements.dim); for (size_t i = 0; i < statements.dim; i++) - { + { Statement s = statements[i]; if (s) s = s.syntaxCopy(); @@ -30,9 +38,60 @@ CompoundDeclarationStatement cs = new CompoundDeclarationStatement(loc, a); return cs; } - + override void toCBuffer(OutBuffer buf, HdrGenState* hgs) { - assert(false); + int nwritten = 0; + foreach (Statement s; statements) + { + if (s) + { + DeclarationStatement ds = s.isDeclarationStatement(); + assert(ds); + DeclarationExp de = cast(DeclarationExp)ds.exp; + assert(de.op == TOKdeclaration); + Declaration d = de.declaration.isDeclaration(); + assert(d); + VarDeclaration v = d.isVarDeclaration(); + if (v) + { + /* This essentially copies the part of VarDeclaration.toCBuffer() + * that does not print the type. + * Should refactor this. + */ + if (nwritten) + { + buf.writeByte(','); + buf.writestring(v.ident.toChars()); + } + else + { + StorageClassDeclaration.stcToCBuffer(buf, v.storage_class); + if (v.type) + v.type.toCBuffer(buf, v.ident, hgs); + else + buf.writestring(v.ident.toChars()); + } + + if (v.init) + { + buf.writestring(" = "); +///version (DMDV2) { + ExpInitializer ie = v.init.isExpInitializer(); + if (ie && (ie.exp.op == TOKconstruct || ie.exp.op == TOKblit)) + (cast(AssignExp)ie.exp).e2.toCBuffer(buf, hgs); + else +///} + v.init.toCBuffer(buf, hgs); + } + } + else + d.toCBuffer(buf, hgs); + nwritten++; + } + } + buf.writeByte(';'); + if (!hgs.FLinit.init) + buf.writenl(); } }