Mercurial > projects > ddmd
annotate dmd/CompoundDeclarationStatement.d @ 174:af724d3510d7
lot os toCBuffer methods implemented
moved shared Type.* stuff into Global
author | korDen |
---|---|
date | Sun, 10 Oct 2010 03:47:23 +0400 |
parents | c77e9f4f1793 |
children | e3afd1303184 |
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 | |
19 class CompoundDeclarationStatement : CompoundStatement | |
20 { | |
21 this(Loc loc, Statements s) | |
22 { | |
23 super(loc, s); | |
24 ///statements = s; | |
25 } | |
174 | 26 |
72 | 27 override Statement syntaxCopy() |
0 | 28 { |
51 | 29 Statements a = new Statements(); |
30 a.setDim(statements.dim); | |
31 for (size_t i = 0; i < statements.dim; i++) | |
174 | 32 { |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
33 Statement s = statements[i]; |
51 | 34 if (s) |
35 s = s.syntaxCopy(); | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
36 a[i] = s; |
51 | 37 } |
38 CompoundDeclarationStatement cs = new CompoundDeclarationStatement(loc, a); | |
39 return cs; | |
0 | 40 } |
174 | 41 |
72 | 42 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 43 { |
174 | 44 int nwritten = 0; |
45 foreach (Statement s; statements) | |
46 { | |
47 if (s) | |
48 { | |
49 DeclarationStatement ds = s.isDeclarationStatement(); | |
50 assert(ds); | |
51 DeclarationExp de = cast(DeclarationExp)ds.exp; | |
52 assert(de.op == TOKdeclaration); | |
53 Declaration d = de.declaration.isDeclaration(); | |
54 assert(d); | |
55 VarDeclaration v = d.isVarDeclaration(); | |
56 if (v) | |
57 { | |
58 /* This essentially copies the part of VarDeclaration.toCBuffer() | |
59 * that does not print the type. | |
60 * Should refactor this. | |
61 */ | |
62 if (nwritten) | |
63 { | |
64 buf.writeByte(','); | |
65 buf.writestring(v.ident.toChars()); | |
66 } | |
67 else | |
68 { | |
69 StorageClassDeclaration.stcToCBuffer(buf, v.storage_class); | |
70 if (v.type) | |
71 v.type.toCBuffer(buf, v.ident, hgs); | |
72 else | |
73 buf.writestring(v.ident.toChars()); | |
74 } | |
75 | |
76 if (v.init) | |
77 { | |
78 buf.writestring(" = "); | |
79 ///version (DMDV2) { | |
80 ExpInitializer ie = v.init.isExpInitializer(); | |
81 if (ie && (ie.exp.op == TOKconstruct || ie.exp.op == TOKblit)) | |
82 (cast(AssignExp)ie.exp).e2.toCBuffer(buf, hgs); | |
83 else | |
84 ///} | |
85 v.init.toCBuffer(buf, hgs); | |
86 } | |
87 } | |
88 else | |
89 d.toCBuffer(buf, hgs); | |
90 nwritten++; | |
91 } | |
92 } | |
93 buf.writeByte(';'); | |
94 if (!hgs.FLinit.init) | |
95 buf.writenl(); | |
0 | 96 } |
72 | 97 } |