annotate dmd/DeclarationStatement.d @ 0:10317f0c89a5

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