Mercurial > projects > ddmd
view dmd/CompileDeclaration.d @ 18:f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Mon, 05 Apr 2010 19:16:14 +0100 |
parents | 10317f0c89a5 |
children | 460959608115 |
line wrap: on
line source
module dmd.CompileDeclaration; import dmd.AttribDeclaration; import dmd.Expression; import dmd.ScopeDsymbol; import dmd.Dsymbol; import dmd.Loc; import dmd.Scope; import dmd.OutBuffer; import dmd.HdrGenState; import dmd.TOK; import dmd.WANT; import dmd.StringExp; import dmd.Parser; // Mixin declarations class CompileDeclaration : AttribDeclaration { Expression exp; ScopeDsymbol sd; int compiled; this(Loc loc, Expression exp) { super(null); this.loc = loc; this.exp = exp; this.sd = null; this.compiled = 0; } Dsymbol syntaxCopy(Dsymbol s) { //printf("CompileDeclaration.syntaxCopy('%s')\n", toChars()); CompileDeclaration sc = new CompileDeclaration(loc, exp.syntaxCopy()); return sc; } bool addMember(Scope sc, ScopeDsymbol sd, int memnum) { //printf("CompileDeclaration.addMember(sc = %p, memnum = %d)\n", sc, memnum); bool m = false; this.sd = sd; if (memnum == 0) { /* No members yet, so parse the mixin now */ compileIt(sc); m |= AttribDeclaration.addMember(sc, sd, memnum); compiled = 1; } return m; } void compileIt(Scope sc) { //printf("CompileDeclaration.compileIt(loc = %d)\n", loc.linnum); exp = exp.semantic(sc); exp = resolveProperties(sc, exp); exp = exp.optimize(WANT.WANTvalue | WANT.WANTinterpret); if (exp.op != TOK.TOKstring) { exp.error("argument to mixin must be a string, not (%s)", exp.toChars()); } else { StringExp se = cast(StringExp)exp; se = se.toUTF8(sc); Parser p = new Parser(sc.module_, cast(ubyte *)se.string_, se.len, 0); p.loc = loc; p.nextToken(); decl = p.parseDeclDefs(0); if (p.token.value != TOK.TOKeof) exp.error("incomplete mixin declaration (%s)", se.toChars()); } } void semantic(Scope sc) { //printf("CompileDeclaration.semantic()\n"); if (!compiled) { compileIt(sc); AttribDeclaration.addMember(sc, sd, 0); compiled = 1; } AttribDeclaration.semantic(sc); } void toCBuffer(OutBuffer buf, HdrGenState* hgs) { buf.writestring("mixin("); exp.toCBuffer(buf, hgs); buf.writestring(");"); buf.writenl(); } }