Mercurial > projects > ddmd
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 |
rev | line source |
---|---|
0 | 1 module dmd.OnScopeStatement; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Statement; |
5 import dmd.OutBuffer; | |
6 import dmd.HdrGenState; | |
7 import dmd.Scope; | |
8 import dmd.IRState; | |
9 import dmd.TOK; | |
10 import dmd.Loc; | |
11 import dmd.BE; | |
12 import dmd.Identifier; | |
13 import dmd.ExpInitializer; | |
174 | 14 import dmd.Token; |
0 | 15 import dmd.IntegerExp; |
16 import dmd.VarDeclaration; | |
17 import dmd.Type; | |
18 import dmd.AssignExp; | |
19 import dmd.VarExp; | |
20 import dmd.NotExp; | |
21 import dmd.IfStatement; | |
22 import dmd.DeclarationStatement; | |
23 import dmd.ExpStatement; | |
24 import dmd.Expression; | |
25 import dmd.Lexer; | |
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 | 29 class OnScopeStatement : Statement |
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 | 33 TOK tok; |
34 Statement statement; | |
35 | |
36 this(Loc loc, TOK tok, Statement statement) | |
37 { | |
178 | 38 register(); |
0 | 39 super(loc); |
174 | 40 |
0 | 41 this.tok = tok; |
42 this.statement = statement; | |
43 } | |
44 | |
72 | 45 override Statement syntaxCopy() |
0 | 46 { |
61 | 47 OnScopeStatement s = new OnScopeStatement(loc, |
48 tok, statement.syntaxCopy()); | |
49 return s; | |
0 | 50 } |
51 | |
72 | 52 override BE blockExit() |
0 | 53 { |
54 // At this point, this statement is just an empty placeholder | |
55 return BE.BEfallthru; | |
56 } | |
57 | |
72 | 58 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 59 { |
174 | 60 buf.writestring(Token.toChars(tok)); |
61 buf.writebyte(' '); | |
62 statement.toCBuffer(buf, hgs); | |
0 | 63 } |
64 | |
72 | 65 override Statement semantic(Scope sc) |
0 | 66 { |
67 /* semantic is called on results of scopeCode() */ | |
68 return this; | |
69 } | |
70 | |
72 | 71 override bool usesEH() |
0 | 72 { |
73 assert(false); | |
74 } | |
75 | |
72 | 76 override void scopeCode(Scope sc, Statement* sentry, Statement* sexception, Statement* sfinally) |
0 | 77 { |
78 //printf("OnScopeStatement::scopeCode()\n"); | |
79 //print(); | |
80 *sentry = null; | |
81 *sexception = null; | |
82 *sfinally = null; | |
83 switch (tok) | |
84 { | |
85 case TOKon_scope_exit: | |
86 *sfinally = statement; | |
87 break; | |
88 | |
89 case TOKon_scope_failure: | |
90 *sexception = statement; | |
91 break; | |
92 | |
93 case TOKon_scope_success: | |
94 { | |
95 /* Create: | |
96 * sentry: int x = 0; | |
97 * sexception: x = 1; | |
98 * sfinally: if (!x) statement; | |
99 */ | |
100 Identifier id = Lexer.uniqueId("__os"); | |
101 | |
102 ExpInitializer ie = new ExpInitializer(loc, new IntegerExp(0)); | |
103 VarDeclaration v = new VarDeclaration(loc, Type.tint32, id, ie); | |
104 *sentry = new DeclarationStatement(loc, v); | |
105 | |
106 Expression e = new IntegerExp(1); | |
107 e = new AssignExp(Loc(0), new VarExp(Loc(0), v), e); | |
108 *sexception = new ExpStatement(Loc(0), e); | |
109 | |
110 e = new VarExp(Loc(0), v); | |
111 e = new NotExp(Loc(0), e); | |
112 *sfinally = new IfStatement(Loc(0), null, e, statement, null); | |
113 | |
114 break; | |
115 } | |
116 | |
117 default: | |
118 assert(0); | |
119 } | |
120 } | |
121 | |
72 | 122 override void toIR(IRState* irs) |
0 | 123 { |
124 } | |
72 | 125 } |