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