annotate dmd/OnScopeStatement.d @ 187:b0d41ff5e0df

Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author Abscissa
date Tue, 07 Jun 2011 23:37:34 -0400
parents e3afd1303184
children
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
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.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.BE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.ExpInitializer;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
14 import dmd.Token;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.AssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.NotExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.IfStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.DeclarationStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.ExpStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.Lexer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
27 import dmd.DDMDExtensions;
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
28
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 class OnScopeStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
31 mixin insertMemberExtension!(typeof(this));
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
32
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 TOK tok;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 Statement statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 this(Loc loc, TOK tok, Statement statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
38 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 super(loc);
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
40
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 this.tok = tok;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 this.statement = statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
45 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 {
61
4ae0d790a452 OnScopeStatement.syntaxCopy
korDen
parents: 0
diff changeset
47 OnScopeStatement s = new OnScopeStatement(loc,
4ae0d790a452 OnScopeStatement.syntaxCopy
korDen
parents: 0
diff changeset
48 tok, statement.syntaxCopy());
4ae0d790a452 OnScopeStatement.syntaxCopy
korDen
parents: 0
diff changeset
49 return s;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
52 override BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 // At this point, this statement is just an empty placeholder
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 return BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
58 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 {
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
60 buf.writestring(Token.toChars(tok));
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
61 buf.writebyte(' ');
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
62 statement.toCBuffer(buf, hgs);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
65 override Statement semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 /* semantic is called on results of scopeCode() */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
71 override bool usesEH()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
76 override void scopeCode(Scope sc, Statement* sentry, Statement* sexception, Statement* sfinally)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 //printf("OnScopeStatement::scopeCode()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 //print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 *sentry = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 *sexception = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 *sfinally = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 switch (tok)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 case TOKon_scope_exit:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 *sfinally = statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 case TOKon_scope_failure:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 *sexception = statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 case TOKon_scope_success:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 /* Create:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 * sentry: int x = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 * sexception: x = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 * sfinally: if (!x) statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 Identifier id = Lexer.uniqueId("__os");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 ExpInitializer ie = new ExpInitializer(loc, new IntegerExp(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 VarDeclaration v = new VarDeclaration(loc, Type.tint32, id, ie);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 *sentry = new DeclarationStatement(loc, v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 Expression e = new IntegerExp(1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 e = new AssignExp(Loc(0), new VarExp(Loc(0), v), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 *sexception = new ExpStatement(Loc(0), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 e = new VarExp(Loc(0), v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 e = new NotExp(Loc(0), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 *sfinally = new IfStatement(Loc(0), null, e, statement, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
122 override void toIR(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
125 }