annotate dmd/GotoStatement.d @ 161:584dc990e12f

type fixed
author korDen
date Mon, 20 Sep 2010 01:19:36 +0400
parents c77e9f4f1793
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.GotoStatement;
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.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.CompoundStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.LabelDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.TryFinallyStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.BE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.codegen.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.backend.block;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.backend.Blockx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.backend.BC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 class GotoStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 LabelDsymbol label = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 TryFinallyStatement tf = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 this(Loc loc, Identifier ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 this.ident = ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
38 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 GotoStatement s = new GotoStatement(loc, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
44 override Statement semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 FuncDeclaration fd = sc.parent.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 //printf("GotoStatement.semantic()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 tf = sc.tf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 label = fd.searchLabel(ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 if (!label.statement && sc.fes)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 /* Either the goto label is forward referenced or it
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 * is in the function that the enclosing foreach is in.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 * Can't know yet, so wrap the goto in a compound statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 * so we can patch it later, and add it to a 'look at this later'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 * list.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 */
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
59 auto a = new Statements();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 Statement s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
62 a.push(this);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 s = new CompoundStatement(loc, a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 sc.fes.gotos.push(cast(void*)s); // 'look at this later' list
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 if (label.statement && label.statement.tf != sc.tf)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 error("cannot goto in or out of finally block");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
73 override BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 //printf("GotoStatement.blockExit(%p)\n", this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 return BE.BEgoto;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
79 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
84 override void toIR(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 block* b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 block* bdest;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 Blockx* blx = irs.blx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 if (!label.statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 error("label %s is undefined", label.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 if (tf !is label.statement.tf)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 error("cannot goto forward out of or into finally block");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 bdest = labelToBlock(loc, blx, label);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 if (!bdest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 b = blx.curblock;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 incUsage(irs, loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 // Adjust exception handler scope index if in different try blocks
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 if (b.Btry != bdest.Btry)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 // Check that bdest is in an enclosing try block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 for (block* bt = b.Btry; bt != bdest.Btry; bt = bt.Btry)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 if (!bt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 //printf("b.Btry = %p, bdest.Btry = %p\n", b.Btry, bdest.Btry);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 error("cannot goto into try block");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 //setScopeIndex(blx, b, bdest.Btry ? bdest.Btry.Bscope_index : -1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 list_append(&b.Bsucc,bdest);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 block_next(blx,BCgoto,null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
125 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 buf.writestring("goto ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 buf.writestring(ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 buf.writebyte(';');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 buf.writenl();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
133 override GotoStatement isGotoStatement() { return this; }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
134 }