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