Mercurial > projects > ddmd
annotate dmd/CompileDeclaration.d @ 192:eb38fdcb3e62 default tip
updated to compile with dmd2.062
author | korDen |
---|---|
date | Sat, 02 Mar 2013 01:25:52 -0800 |
parents | b0d41ff5e0df |
children |
rev | line source |
---|---|
0 | 1 module dmd.CompileDeclaration; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.AttribDeclaration; |
13 | 5 import dmd.WANT; |
6 import dmd.TOK; | |
7 import dmd.StringExp; | |
8 import dmd.Parser; | |
0 | 9 import dmd.Expression; |
10 import dmd.ScopeDsymbol; | |
11 import dmd.Dsymbol; | |
12 import dmd.Loc; | |
13 import dmd.Scope; | |
14 import dmd.OutBuffer; | |
15 import dmd.HdrGenState; | |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
16 import dmd.TOK; |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
17 import dmd.WANT; |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
18 import dmd.StringExp; |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
19 import dmd.Parser; |
0 | 20 |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
21 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
22 |
0 | 23 // Mixin declarations |
24 | |
25 class CompileDeclaration : AttribDeclaration | |
26 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
27 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
28 |
0 | 29 Expression exp; |
13 | 30 ScopeDsymbol sd; |
31 bool compiled; | |
0 | 32 |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
33 this(Loc loc, Expression exp) |
0 | 34 { |
178 | 35 register(); |
36 | |
0 | 37 super(null); |
13 | 38 //printf("CompileDeclaration(loc = %d)\n", loc.linnum); |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
39 this.loc = loc; |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
40 this.exp = exp; |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
41 this.sd = null; |
13 | 42 this.compiled = false; |
0 | 43 } |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
44 |
72 | 45 override Dsymbol syntaxCopy(Dsymbol s) |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
46 { |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
47 //printf("CompileDeclaration.syntaxCopy('%s')\n", toChars()); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
48 CompileDeclaration sc = new CompileDeclaration(loc, exp.syntaxCopy()); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
49 return sc; |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
50 } |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
51 |
72 | 52 override bool addMember(Scope sc, ScopeDsymbol sd, bool memnum) |
0 | 53 { |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
54 //printf("CompileDeclaration.addMember(sc = %p, memnum = %d)\n", sc, memnum); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
55 bool m = false; |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
56 this.sd = sd; |
13 | 57 if (!memnum) |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
58 { /* No members yet, so parse the mixin now |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
59 */ |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
60 compileIt(sc); |
13 | 61 memnum = AttribDeclaration.addMember(sc, sd, memnum); |
62 compiled = true; | |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
63 } |
13 | 64 return memnum; |
0 | 65 } |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
66 |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
67 void compileIt(Scope sc) |
0 | 68 { |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
69 //printf("CompileDeclaration.compileIt(loc = %d)\n", loc.linnum); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
70 exp = exp.semantic(sc); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
71 exp = resolveProperties(sc, exp); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
72 exp = exp.optimize(WANT.WANTvalue | WANT.WANTinterpret); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
73 if (exp.op != TOK.TOKstring) |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
74 { exp.error("argument to mixin must be a string, not (%s)", exp.toChars()); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
75 } |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
76 else |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
77 { |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
78 StringExp se = cast(StringExp)exp; |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
79 se = se.toUTF8(sc); |
13 | 80 scope Parser p = new Parser(sc.module_, cast(ubyte*)se.string_, se.len, 0); |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
81 p.loc = loc; |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
82 p.nextToken(); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
83 decl = p.parseDeclDefs(0); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
84 if (p.token.value != TOK.TOKeof) |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
85 exp.error("incomplete mixin declaration (%s)", se.toChars()); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
86 } |
0 | 87 } |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
88 |
72 | 89 override void semantic(Scope sc) |
0 | 90 { |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
91 //printf("CompileDeclaration.semantic()\n"); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
92 |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
93 if (!compiled) |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
94 { |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
95 compileIt(sc); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
96 AttribDeclaration.addMember(sc, sd, 0); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
97 compiled = 1; |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
98 } |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
99 AttribDeclaration.semantic(sc); |
0 | 100 } |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
101 |
72 | 102 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 103 { |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
104 buf.writestring("mixin("); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
105 exp.toCBuffer(buf, hgs); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
106 buf.writestring(");"); |
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
107 buf.writenl(); |
0 | 108 } |
18
f2413c9183d1
Implemented CompileDeclaration, UAddExp, UnionDeclaration.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
109 } |