annotate dmd/OnScopeStatement.d @ 61:4ae0d790a452

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