Mercurial > projects > ddmd
annotate dmd/CompoundDeclarationStatement.d @ 187:b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author | Abscissa |
---|---|
date | Tue, 07 Jun 2011 23:37:34 -0400 |
parents | e3afd1303184 |
children |
rev | line source |
---|---|
0 | 1 module dmd.CompoundDeclarationStatement; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.CompoundStatement; |
5 import dmd.Loc; | |
174 | 6 import dmd.TOK; |
0 | 7 import dmd.ArrayTypes; |
174 | 8 import dmd.VarDeclaration; |
9 import dmd.AssignExp; | |
10 import dmd.ExpInitializer; | |
11 import dmd.Declaration; | |
12 import dmd.StorageClassDeclaration; | |
13 import dmd.DeclarationStatement; | |
14 import dmd.DeclarationExp; | |
0 | 15 import dmd.Statement; |
16 import dmd.OutBuffer; | |
17 import dmd.HdrGenState; | |
18 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
19 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
|
20 |
0 | 21 class CompoundDeclarationStatement : CompoundStatement |
22 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
23 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
|
24 |
0 | 25 this(Loc loc, Statements s) |
26 { | |
178 | 27 register(); |
0 | 28 super(loc, s); |
29 ///statements = s; | |
30 } | |
174 | 31 |
72 | 32 override Statement syntaxCopy() |
0 | 33 { |
51 | 34 Statements a = new Statements(); |
35 a.setDim(statements.dim); | |
36 for (size_t i = 0; i < statements.dim; i++) | |
174 | 37 { |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
38 Statement s = statements[i]; |
51 | 39 if (s) |
40 s = s.syntaxCopy(); | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
41 a[i] = s; |
51 | 42 } |
43 CompoundDeclarationStatement cs = new CompoundDeclarationStatement(loc, a); | |
44 return cs; | |
0 | 45 } |
174 | 46 |
72 | 47 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 48 { |
174 | 49 int nwritten = 0; |
50 foreach (Statement s; statements) | |
51 { | |
52 if (s) | |
53 { | |
54 DeclarationStatement ds = s.isDeclarationStatement(); | |
55 assert(ds); | |
56 DeclarationExp de = cast(DeclarationExp)ds.exp; | |
57 assert(de.op == TOKdeclaration); | |
58 Declaration d = de.declaration.isDeclaration(); | |
59 assert(d); | |
60 VarDeclaration v = d.isVarDeclaration(); | |
61 if (v) | |
62 { | |
63 /* This essentially copies the part of VarDeclaration.toCBuffer() | |
64 * that does not print the type. | |
65 * Should refactor this. | |
66 */ | |
67 if (nwritten) | |
68 { | |
69 buf.writeByte(','); | |
70 buf.writestring(v.ident.toChars()); | |
71 } | |
72 else | |
73 { | |
74 StorageClassDeclaration.stcToCBuffer(buf, v.storage_class); | |
75 if (v.type) | |
76 v.type.toCBuffer(buf, v.ident, hgs); | |
77 else | |
78 buf.writestring(v.ident.toChars()); | |
79 } | |
80 | |
81 if (v.init) | |
82 { | |
83 buf.writestring(" = "); | |
84 ///version (DMDV2) { | |
85 ExpInitializer ie = v.init.isExpInitializer(); | |
86 if (ie && (ie.exp.op == TOKconstruct || ie.exp.op == TOKblit)) | |
87 (cast(AssignExp)ie.exp).e2.toCBuffer(buf, hgs); | |
88 else | |
89 ///} | |
90 v.init.toCBuffer(buf, hgs); | |
91 } | |
92 } | |
93 else | |
94 d.toCBuffer(buf, hgs); | |
95 nwritten++; | |
96 } | |
97 } | |
98 buf.writeByte(';'); | |
99 if (!hgs.FLinit.init) | |
100 buf.writenl(); | |
0 | 101 } |
72 | 102 } |