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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.DeclarationStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 72
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.ExpStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.DeclarationExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 class DeclarationStatement : ExpStatement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 // Doing declarations as an expression, rather than a statement,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 // makes inlining functions much easier.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 this(Loc loc, Dsymbol declaration)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 114
diff changeset
27 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 super(loc, new DeclarationExp(loc, declaration));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 this(Loc loc, Expression exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 114
diff changeset
33 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 super(loc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
37 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 DeclarationStatement ds = new DeclarationStatement(loc, exp.syntaxCopy());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 return ds;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
43 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 exp.toCBuffer(buf, hgs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
48 override void scopeCode(Scope sc, Statement* sentry, Statement* sexception, Statement* sfinally)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 //printf("DeclarationStatement.scopeCode()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 //print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 *sentry = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 *sexception = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 *sfinally = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 if (exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 if (exp.op == TOK.TOKdeclaration)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 DeclarationExp de = cast(DeclarationExp)exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 VarDeclaration v = de.declaration.isVarDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 if (v)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 e = v.callAutoDtor(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 //printf("dtor is: "); e.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 if (v.type.toBasetype().ty == Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 /* Need a 'gate' to turn on/off destruction,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 * in case v gets moved elsewhere.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 Identifier id = Lexer.uniqueId("__runDtor");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 ExpInitializer ie = new ExpInitializer(loc, new IntegerExp(1));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 VarDeclaration rd = new VarDeclaration(loc, Type.tint32, id, ie);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 *sentry = new DeclarationStatement(loc, rd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 v.rundtor = rd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 /* Rewrite e as:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 * rundtor && e
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 Expression ve = new VarExp(loc, v.rundtor);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 e = new AndAndExp(loc, ve, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 e.type = Type.tbool;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 *sfinally = new ExpStatement(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
98 override DeclarationStatement isDeclarationStatement() { return this; }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
99 }