Mercurial > projects > ddmd
view dmd/ConditionalDeclaration.d @ 0:10317f0c89a5
Initial commit
author | korDen |
---|---|
date | Sat, 24 Oct 2009 08:42:06 +0400 |
parents | |
children | 427f8aa74d28 01cadcfa4842 |
line wrap: on
line source
module dmd.ConditionalDeclaration; import dmd.AttribDeclaration; import dmd.Condition; import dmd.Array; import dmd.Dsymbol; import dmd.Scope; import dmd.ScopeDsymbol; import dmd.OutBuffer; import dmd.HdrGenState; class ConditionalDeclaration : AttribDeclaration { Condition condition; Array elsedecl; // array of Dsymbol's for else block this(Condition condition, Array decl, Array elsedecl) { super(decl); //printf("ConditionalDeclaration::ConditionalDeclaration()\n"); this.condition = condition; this.elsedecl = elsedecl; } Dsymbol syntaxCopy(Dsymbol s) { assert(false); } bool oneMember(Dsymbol* ps) { assert(false); } void emitComment(Scope sc) { assert(false); } // Decide if 'then' or 'else' code should be included Array include(Scope sc, ScopeDsymbol sd) { //printf("ConditionalDeclaration::include()\n"); assert(condition); return condition.include(sc, sd) ? decl : elsedecl; } void addComment(ubyte* comment) { /* Because addComment is called by the parser, if we called * include() it would define a version before it was used. * But it's no problem to drill down to both decl and elsedecl, * so that's the workaround. */ if (comment) { Array d = decl; for (int j = 0; j < 2; j++) { if (d) { for (uint i = 0; i < d.dim; i++) { Dsymbol s = cast(Dsymbol)d.data[i]; //printf("ConditionalDeclaration::addComment %s\n", s->toChars()); s.addComment(comment); } } d = elsedecl; } } } void toCBuffer(OutBuffer buf, HdrGenState* hgs) { assert(false); } }