Mercurial > projects > ddmd
comparison dmd/OnScopeStatement.d @ 0:10317f0c89a5
Initial commit
author | korDen |
---|---|
date | Sat, 24 Oct 2009 08:42:06 +0400 |
parents | |
children | 4ae0d790a452 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:10317f0c89a5 |
---|---|
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 { | |
40 assert(false); | |
41 } | |
42 | |
43 BE blockExit() | |
44 { | |
45 // At this point, this statement is just an empty placeholder | |
46 return BE.BEfallthru; | |
47 } | |
48 | |
49 void toCBuffer(OutBuffer buf, HdrGenState* hgs) | |
50 { | |
51 assert(false); | |
52 } | |
53 | |
54 Statement semantic(Scope sc) | |
55 { | |
56 /* semantic is called on results of scopeCode() */ | |
57 return this; | |
58 } | |
59 | |
60 bool usesEH() | |
61 { | |
62 assert(false); | |
63 } | |
64 | |
65 void scopeCode(Scope sc, Statement* sentry, Statement* sexception, Statement* sfinally) | |
66 { | |
67 //printf("OnScopeStatement::scopeCode()\n"); | |
68 //print(); | |
69 *sentry = null; | |
70 *sexception = null; | |
71 *sfinally = null; | |
72 switch (tok) | |
73 { | |
74 case TOKon_scope_exit: | |
75 *sfinally = statement; | |
76 break; | |
77 | |
78 case TOKon_scope_failure: | |
79 *sexception = statement; | |
80 break; | |
81 | |
82 case TOKon_scope_success: | |
83 { | |
84 /* Create: | |
85 * sentry: int x = 0; | |
86 * sexception: x = 1; | |
87 * sfinally: if (!x) statement; | |
88 */ | |
89 Identifier id = Lexer.uniqueId("__os"); | |
90 | |
91 ExpInitializer ie = new ExpInitializer(loc, new IntegerExp(0)); | |
92 VarDeclaration v = new VarDeclaration(loc, Type.tint32, id, ie); | |
93 *sentry = new DeclarationStatement(loc, v); | |
94 | |
95 Expression e = new IntegerExp(1); | |
96 e = new AssignExp(Loc(0), new VarExp(Loc(0), v), e); | |
97 *sexception = new ExpStatement(Loc(0), e); | |
98 | |
99 e = new VarExp(Loc(0), v); | |
100 e = new NotExp(Loc(0), e); | |
101 *sfinally = new IfStatement(Loc(0), null, e, statement, null); | |
102 | |
103 break; | |
104 } | |
105 | |
106 default: | |
107 assert(0); | |
108 } | |
109 } | |
110 | |
111 void toIR(IRState* irs) | |
112 { | |
113 } | |
114 } |