annotate dmd/OnScopeStatement.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children 4ae0d790a452
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.OnScopeStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.BE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.ExpInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.AssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.NotExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.IfStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.DeclarationStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.ExpStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.Lexer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 class OnScopeStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 TOK tok;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 Statement statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 this(Loc loc, TOK tok, Statement statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 this.tok = tok;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 this.statement = statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 Statement syntaxCopy()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 BE blockExit()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 // At this point, this statement is just an empty placeholder
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 return BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 Statement semantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 /* semantic is called on results of scopeCode() */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 bool usesEH()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 void scopeCode(Scope sc, Statement* sentry, Statement* sexception, Statement* sfinally)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 //printf("OnScopeStatement::scopeCode()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 //print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 *sentry = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 *sexception = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 *sfinally = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 switch (tok)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 case TOKon_scope_exit:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 *sfinally = statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 case TOKon_scope_failure:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 *sexception = statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 case TOKon_scope_success:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 /* Create:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 * sentry: int x = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 * sexception: x = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 * sfinally: if (!x) statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 Identifier id = Lexer.uniqueId("__os");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 ExpInitializer ie = new ExpInitializer(loc, new IntegerExp(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 VarDeclaration v = new VarDeclaration(loc, Type.tint32, id, ie);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 *sentry = new DeclarationStatement(loc, v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 Expression e = new IntegerExp(1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 e = new AssignExp(Loc(0), new VarExp(Loc(0), v), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 *sexception = new ExpStatement(Loc(0), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 e = new VarExp(Loc(0), v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 e = new NotExp(Loc(0), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 *sfinally = new IfStatement(Loc(0), null, e, statement, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 void toIR(IRState* irs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 }