annotate dmd/OnScopeStatement.d @ 114:e28b18c23469

added a module dmd.common for commonly used stuff it currently holds code for consistency checking of predefined versions also added a VisualD project file
author Trass3r
date Wed, 01 Sep 2010 18:21:58 +0200
parents 2e2a5c3f943a
children af724d3510d7
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;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.AssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.NotExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.IfStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.DeclarationStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.ExpStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.Lexer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 class OnScopeStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 TOK tok;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 Statement statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 this(Loc loc, TOK tok, Statement statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 this.tok = tok;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 this.statement = statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
39 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 {
61
4ae0d790a452 OnScopeStatement.syntaxCopy
korDen
parents: 0
diff changeset
41 OnScopeStatement s = new OnScopeStatement(loc,
4ae0d790a452 OnScopeStatement.syntaxCopy
korDen
parents: 0
diff changeset
42 tok, statement.syntaxCopy());
4ae0d790a452 OnScopeStatement.syntaxCopy
korDen
parents: 0
diff changeset
43 return s;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
46 override BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 // At this point, this statement is just an empty placeholder
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 return BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
52 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
57 override Statement semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 /* semantic is called on results of scopeCode() */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
63 override bool usesEH()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
68 override void scopeCode(Scope sc, Statement* sentry, Statement* sexception, Statement* sfinally)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 //printf("OnScopeStatement::scopeCode()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 //print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 *sentry = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 *sexception = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 *sfinally = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 switch (tok)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 case TOKon_scope_exit:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 *sfinally = statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 case TOKon_scope_failure:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 *sexception = statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 case TOKon_scope_success:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 /* Create:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 * sentry: int x = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 * sexception: x = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 * sfinally: if (!x) statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 Identifier id = Lexer.uniqueId("__os");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 ExpInitializer ie = new ExpInitializer(loc, new IntegerExp(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 VarDeclaration v = new VarDeclaration(loc, Type.tint32, id, ie);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 *sentry = new DeclarationStatement(loc, v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 Expression e = new IntegerExp(1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 e = new AssignExp(Loc(0), new VarExp(Loc(0), v), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 *sexception = new ExpStatement(Loc(0), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 e = new VarExp(Loc(0), v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 e = new NotExp(Loc(0), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 *sfinally = new IfStatement(Loc(0), null, e, statement, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 61
diff changeset
114 override void toIR(IRState* irs)
0
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 }