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