Mercurial > projects > ddmd
annotate dmd/DeclarationStatement.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.DeclarationStatement; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Loc; |
5 import dmd.ExpStatement; | |
6 import dmd.Dsymbol; | |
7 import dmd.Expression; | |
8 import dmd.Statement; | |
9 import dmd.OutBuffer; | |
10 import dmd.HdrGenState; | |
11 import dmd.Scope; | |
12 import dmd.DeclarationExp; | |
13 import dmd.TOK; | |
14 import dmd.VarDeclaration; | |
15 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
16 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
|
17 |
0 | 18 class DeclarationStatement : ExpStatement |
19 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
20 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
|
21 |
0 | 22 // Doing declarations as an expression, rather than a statement, |
23 // makes inlining functions much easier. | |
24 | |
25 this(Loc loc, Dsymbol declaration) | |
26 { | |
178 | 27 register(); |
0 | 28 super(loc, new DeclarationExp(loc, declaration)); |
29 } | |
30 | |
31 this(Loc loc, Expression exp) | |
32 { | |
178 | 33 register(); |
0 | 34 super(loc, exp); |
35 } | |
36 | |
72 | 37 override Statement syntaxCopy() |
0 | 38 { |
39 DeclarationStatement ds = new DeclarationStatement(loc, exp.syntaxCopy()); | |
40 return ds; | |
41 } | |
42 | |
72 | 43 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 44 { |
45 exp.toCBuffer(buf, hgs); | |
46 } | |
47 | |
72 | 48 override void scopeCode(Scope sc, Statement* sentry, Statement* sexception, Statement* sfinally) |
0 | 49 { |
50 //printf("DeclarationStatement.scopeCode()\n"); | |
51 //print(); | |
52 | |
53 *sentry = null; | |
54 *sexception = null; | |
55 *sfinally = null; | |
56 | |
57 if (exp) | |
58 { | |
59 if (exp.op == TOK.TOKdeclaration) | |
60 { | |
61 DeclarationExp de = cast(DeclarationExp)exp; | |
62 VarDeclaration v = de.declaration.isVarDeclaration(); | |
63 if (v) | |
64 { | |
65 Expression e; | |
66 | |
67 e = v.callAutoDtor(sc); | |
68 if (e) | |
69 { | |
70 //printf("dtor is: "); e.print(); | |
71 static if (false) { | |
72 if (v.type.toBasetype().ty == Tstruct) | |
73 { | |
74 /* Need a 'gate' to turn on/off destruction, | |
75 * in case v gets moved elsewhere. | |
76 */ | |
77 Identifier id = Lexer.uniqueId("__runDtor"); | |
78 ExpInitializer ie = new ExpInitializer(loc, new IntegerExp(1)); | |
79 VarDeclaration rd = new VarDeclaration(loc, Type.tint32, id, ie); | |
80 *sentry = new DeclarationStatement(loc, rd); | |
81 v.rundtor = rd; | |
82 | |
83 /* Rewrite e as: | |
84 * rundtor && e | |
85 */ | |
86 Expression ve = new VarExp(loc, v.rundtor); | |
87 e = new AndAndExp(loc, ve, e); | |
88 e.type = Type.tbool; | |
89 } | |
90 } | |
91 *sfinally = new ExpStatement(loc, e); | |
92 } | |
93 } | |
94 } | |
95 } | |
96 } | |
97 | |
72 | 98 override DeclarationStatement isDeclarationStatement() { return this; } |
99 } |