annotate dmd/DeclarationStatement.d @ 114:e28b18c23469

added a module dmd.common for commonly used stuff it currently holds code for consistency checking of predefined versions also added a VisualD project file
author Trass3r
date Wed, 01 Sep 2010 18:21:58 +0200
parents 2e2a5c3f943a
children e3afd1303184
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 class DeclarationStatement : ExpStatement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 // Doing declarations as an expression, rather than a statement,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 // makes inlining functions much easier.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 this(Loc loc, Dsymbol declaration)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 super(loc, new DeclarationExp(loc, declaration));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 this(Loc loc, Expression exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 super(loc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
31 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 DeclarationStatement ds = new DeclarationStatement(loc, exp.syntaxCopy());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 return ds;
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 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 exp.toCBuffer(buf, hgs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
42 override void scopeCode(Scope sc, Statement* sentry, Statement* sexception, Statement* sfinally)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 //printf("DeclarationStatement.scopeCode()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 //print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 *sentry = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 *sexception = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 *sfinally = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 if (exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 if (exp.op == TOK.TOKdeclaration)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 DeclarationExp de = cast(DeclarationExp)exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 VarDeclaration v = de.declaration.isVarDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 if (v)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 e = v.callAutoDtor(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 //printf("dtor is: "); e.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 if (v.type.toBasetype().ty == Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 /* Need a 'gate' to turn on/off destruction,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 * in case v gets moved elsewhere.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 Identifier id = Lexer.uniqueId("__runDtor");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 ExpInitializer ie = new ExpInitializer(loc, new IntegerExp(1));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 VarDeclaration rd = new VarDeclaration(loc, Type.tint32, id, ie);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 *sentry = new DeclarationStatement(loc, rd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 v.rundtor = rd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 /* Rewrite e as:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 * rundtor && e
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 Expression ve = new VarExp(loc, v.rundtor);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 e = new AndAndExp(loc, ve, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 e.type = Type.tbool;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 *sfinally = new ExpStatement(loc, e);
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
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
92 override DeclarationStatement isDeclarationStatement() { return this; }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
93 }