Mercurial > projects > ddmd
comparison dmd/CompileDeclaration.d @ 23:460959608115
Branch merge.
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Mon, 12 Apr 2010 17:00:08 +0100 |
parents | 427f8aa74d28 f2413c9183d1 |
children | 2e2a5c3f943a |
comparison
equal
deleted
inserted
replaced
13:427f8aa74d28 | 23:460959608115 |
---|---|
10 import dmd.Dsymbol; | 10 import dmd.Dsymbol; |
11 import dmd.Loc; | 11 import dmd.Loc; |
12 import dmd.Scope; | 12 import dmd.Scope; |
13 import dmd.OutBuffer; | 13 import dmd.OutBuffer; |
14 import dmd.HdrGenState; | 14 import dmd.HdrGenState; |
15 import dmd.TOK; | |
16 import dmd.WANT; | |
17 import dmd.StringExp; | |
18 import dmd.Parser; | |
15 | 19 |
16 // Mixin declarations | 20 // Mixin declarations |
17 | 21 |
18 class CompileDeclaration : AttribDeclaration | 22 class CompileDeclaration : AttribDeclaration |
19 { | 23 { |
20 Expression exp; | 24 Expression exp; |
21 ScopeDsymbol sd; | 25 ScopeDsymbol sd; |
22 bool compiled; | 26 bool compiled; |
23 | 27 |
24 this(Loc loc, Expression exp) | 28 this(Loc loc, Expression exp) |
25 { | 29 { |
26 super(null); | 30 super(null); |
27 //printf("CompileDeclaration(loc = %d)\n", loc.linnum); | 31 //printf("CompileDeclaration(loc = %d)\n", loc.linnum); |
28 this.loc = loc; | 32 this.loc = loc; |
29 this.exp = exp; | 33 this.exp = exp; |
30 this.sd = null; | 34 this.sd = null; |
31 this.compiled = false; | 35 this.compiled = false; |
32 } | 36 } |
33 | 37 |
34 Dsymbol syntaxCopy(Dsymbol s) | 38 Dsymbol syntaxCopy(Dsymbol s) |
35 { | 39 { |
36 assert(false); | 40 //printf("CompileDeclaration.syntaxCopy('%s')\n", toChars()); |
41 CompileDeclaration sc = new CompileDeclaration(loc, exp.syntaxCopy()); | |
42 return sc; | |
37 } | 43 } |
38 | 44 |
39 bool addMember(Scope sc, ScopeDsymbol sd, bool memnum) | 45 bool addMember(Scope sc, ScopeDsymbol sd, bool memnum) |
40 { | 46 { |
41 //printf("CompileDeclaration.addMember(sc = %p, memnum = %d)\n", sc, memnum); | 47 //printf("CompileDeclaration.addMember(sc = %p, memnum = %d)\n", sc, memnum); |
48 bool m = false; | |
42 this.sd = sd; | 49 this.sd = sd; |
43 if (!memnum) | 50 if (!memnum) |
44 { /* No members yet, so parse the mixin now | 51 { /* No members yet, so parse the mixin now |
45 */ | 52 */ |
46 compileIt(sc); | 53 compileIt(sc); |
48 compiled = true; | 55 compiled = true; |
49 } | 56 } |
50 return memnum; | 57 return memnum; |
51 } | 58 } |
52 | 59 |
53 void compileIt(Scope sc) | 60 void compileIt(Scope sc) |
54 { | 61 { |
55 //printf("CompileDeclaration.compileIt(loc = %d)\n", loc.linnum); | 62 //printf("CompileDeclaration.compileIt(loc = %d)\n", loc.linnum); |
56 exp = exp.semantic(sc); | 63 exp = exp.semantic(sc); |
57 exp = resolveProperties(sc, exp); | 64 exp = resolveProperties(sc, exp); |
58 exp = exp.optimize(WANTvalue | WANTinterpret); | 65 exp = exp.optimize(WANT.WANTvalue | WANT.WANTinterpret); |
59 if (exp.op != TOKstring) | 66 if (exp.op != TOK.TOKstring) |
60 { | 67 { exp.error("argument to mixin must be a string, not (%s)", exp.toChars()); |
61 exp.error("argument to mixin must be a string, not (%s)", exp.toChars()); | |
62 } | 68 } |
63 else | 69 else |
64 { | 70 { |
65 StringExp se = cast(StringExp)exp; | 71 StringExp se = cast(StringExp)exp; |
66 se = se.toUTF8(sc); | 72 se = se.toUTF8(sc); |
67 scope Parser p = new Parser(sc.module_, cast(ubyte*)se.string_, se.len, 0); | 73 scope Parser p = new Parser(sc.module_, cast(ubyte*)se.string_, se.len, 0); |
68 p.loc = loc; | 74 p.loc = loc; |
69 p.nextToken(); | 75 p.nextToken(); |
70 decl = p.parseDeclDefs(0); | 76 decl = p.parseDeclDefs(0); |
71 if (p.token.value != TOKeof) | 77 if (p.token.value != TOK.TOKeof) |
72 exp.error("incomplete mixin declaration (%s)", se.toChars()); | 78 exp.error("incomplete mixin declaration (%s)", se.toChars()); |
73 } | 79 } |
74 } | 80 } |
75 | 81 |
76 void semantic(Scope sc) | 82 void semantic(Scope sc) |
77 { | 83 { |
78 //printf("CompileDeclaration.semantic()\n"); | 84 //printf("CompileDeclaration.semantic()\n"); |
79 | 85 |
80 if (!compiled) | 86 if (!compiled) |
81 { | 87 { |
82 compileIt(sc); | 88 compileIt(sc); |
83 AttribDeclaration.addMember(sc, sd, false); | 89 AttribDeclaration.addMember(sc, sd, 0); |
84 compiled = true; | 90 compiled = 1; |
85 } | 91 } |
86 AttribDeclaration.semantic(sc); | 92 AttribDeclaration.semantic(sc); |
87 } | 93 } |
88 | 94 |
89 void toCBuffer(OutBuffer buf, HdrGenState* hgs) | 95 void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
90 { | 96 { |
91 assert(false); | 97 buf.writestring("mixin("); |
98 exp.toCBuffer(buf, hgs); | |
99 buf.writestring(");"); | |
100 buf.writenl(); | |
92 } | 101 } |
93 } | 102 } |