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