Mercurial > projects > ddmd
changeset 18:f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Mon, 05 Apr 2010 19:16:14 +0100 |
parents | ddae60498573 |
children | 01cadcfa4842 |
files | dmd/CompileDeclaration.d dmd/UAddExp.d dmd/UnionDeclaration.d |
diffstat | 3 files changed, 118 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/dmd/CompileDeclaration.d Mon Apr 05 03:24:08 2010 +0100 +++ b/dmd/CompileDeclaration.d Mon Apr 05 19:16:14 2010 +0100 @@ -8,44 +8,91 @@ 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; + Expression exp; - ScopeDsymbol *sd; - int compiled; + ScopeDsymbol sd; + int compiled; - this(Loc loc, Expression exp) + this(Loc loc, Expression exp) { - assert(false); super(null); + this.loc = loc; + this.exp = exp; + this.sd = null; + this.compiled = 0; } - - Dsymbol syntaxCopy(Dsymbol s) + + 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) { - assert(false); + //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; } - - bool addMember(Scope sc, ScopeDsymbol sd, int memnum) + + void compileIt(Scope sc) { - assert(false); - } - - void compileIt(Scope sc) - { - assert(false); + //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) + + void semantic(Scope sc) { - assert(false); + //printf("CompileDeclaration.semantic()\n"); + + if (!compiled) + { + compileIt(sc); + AttribDeclaration.addMember(sc, sd, 0); + compiled = 1; + } + AttribDeclaration.semantic(sc); } - - void toCBuffer(OutBuffer buf, HdrGenState* hgs) + + void toCBuffer(OutBuffer buf, HdrGenState* hgs) { - assert(false); + buf.writestring("mixin("); + exp.toCBuffer(buf, hgs); + buf.writestring(");"); + buf.writenl(); } -} \ No newline at end of file +}
--- a/dmd/UAddExp.d Mon Apr 05 03:24:08 2010 +0100 +++ b/dmd/UAddExp.d Mon Apr 05 19:16:14 2010 +0100 @@ -7,22 +7,34 @@ import dmd.Scope; import dmd.TOK; -class UAddExp : UnaExp -{ - this(Loc loc, Expression e) - { +class UAddExp : UnaExp +{ + this(Loc loc, Expression e) + { + super(loc, TOK.TOKuadd, this.sizeof, e); + } + + Expression semantic(Scope sc) + { + Expression e; + + version (LOGSEMANTIC) { + printf("UAddExp.semantic('%s')\n", toChars()); + } + assert(!type); + UnaExp.semantic(sc); + e1 = resolveProperties(sc, e1); + e = op_overload(sc); + if (e) + return e; + e1.checkNoBool(); + e1.checkArithmetic(); + return e1; + } + + Identifier opId() + { assert(false); - super(loc, TOK.init, 0, e); - } - - Expression semantic(Scope sc) - { - assert(false); - } - - Identifier opId() - { - assert(false); - } -} - + } +} +
--- a/dmd/UnionDeclaration.d Mon Apr 05 03:24:08 2010 +0100 +++ b/dmd/UnionDeclaration.d Mon Apr 05 19:16:14 2010 +0100 @@ -7,21 +7,27 @@ class UnionDeclaration : StructDeclaration { - this(Loc loc, Identifier id) + this(Loc loc, Identifier id) { - assert(false); super(loc, id); } - - Dsymbol syntaxCopy(Dsymbol s) + + Dsymbol syntaxCopy(Dsymbol s) { - assert(false); - } - - string kind() - { - assert(false); + UnionDeclaration ud; + + if (s) + ud = cast(UnionDeclaration)s; + else + ud = new UnionDeclaration(loc, ident); + StructDeclaration.syntaxCopy(ud); + return ud; } - UnionDeclaration isUnionDeclaration() { return this; } -} \ No newline at end of file + string kind() + { + return "union"; + } + + UnionDeclaration isUnionDeclaration() { return this; } +}