annotate dmd/OnScopeStatement.d @ 174:af724d3510d7

lot os toCBuffer methods implemented moved shared Type.* stuff into Global
author korDen
date Sun, 10 Oct 2010 03:47:23 +0400
parents e28b18c23469
children e3afd1303184
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 class OnScopeStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 TOK tok;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 Statement statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 this(Loc loc, TOK tok, Statement statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 super(loc);
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
35
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 this.tok = tok;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 this.statement = statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
40 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 {
61
4ae0d790a452 OnScopeStatement.syntaxCopy
korDen
parents: 0
diff changeset
42 OnScopeStatement s = new OnScopeStatement(loc,
4ae0d790a452 OnScopeStatement.syntaxCopy
korDen
parents: 0
diff changeset
43 tok, statement.syntaxCopy());
4ae0d790a452 OnScopeStatement.syntaxCopy
korDen
parents: 0
diff changeset
44 return s;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
47 override BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 // At this point, this statement is just an empty placeholder
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 return BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
53 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 {
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
55 buf.writestring(Token.toChars(tok));
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
56 buf.writebyte(' ');
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
57 statement.toCBuffer(buf, hgs);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
60 override Statement semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 /* semantic is called on results of scopeCode() */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
66 override bool usesEH()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 assert(false);
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 void scopeCode(Scope sc, Statement* sentry, Statement* sexception, Statement* sfinally)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 //printf("OnScopeStatement::scopeCode()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 //print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 *sentry = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 *sexception = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 *sfinally = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 switch (tok)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 case TOKon_scope_exit:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 *sfinally = statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 case TOKon_scope_failure:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 *sexception = statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 case TOKon_scope_success:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 /* Create:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 * sentry: int x = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 * sexception: x = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 * sfinally: if (!x) statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 Identifier id = Lexer.uniqueId("__os");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 ExpInitializer ie = new ExpInitializer(loc, new IntegerExp(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 VarDeclaration v = new VarDeclaration(loc, Type.tint32, id, ie);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 *sentry = new DeclarationStatement(loc, v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 Expression e = new IntegerExp(1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 e = new AssignExp(Loc(0), new VarExp(Loc(0), v), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 *sexception = new ExpStatement(Loc(0), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 e = new VarExp(Loc(0), v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 e = new NotExp(Loc(0), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 *sfinally = new IfStatement(Loc(0), null, e, statement, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
117 override void toIR(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
120 }