annotate dmd/GotoStatement.d @ 191:52188e7e3fb5

Fixed deprecated features, now compiles with DMD2.058 Also changed Array allocation policy: Now doesn't reallocate but malloc's, followed by a memcpy (no free). (this fixes a crash while compiling druntime. Same bug in dmd)
author korDen@korDen-pc
date Sun, 25 Mar 2012 03:11:12 +0400
parents b0d41ff5e0df
children
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
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
26 import dmd.DDMDExtensions;
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
27
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 class GotoStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
30 mixin insertMemberExtension!(typeof(this));
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
31
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 LabelDsymbol label = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 TryFinallyStatement tf = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 this(Loc loc, Identifier ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 122
diff changeset
38 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 this.ident = ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
43 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 GotoStatement s = new GotoStatement(loc, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
49 override Statement semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 FuncDeclaration fd = sc.parent.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 //printf("GotoStatement.semantic()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 tf = sc.tf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 label = fd.searchLabel(ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 if (!label.statement && sc.fes)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 /* Either the goto label is forward referenced or it
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 * is in the function that the enclosing foreach is in.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 * Can't know yet, so wrap the goto in a compound statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 * so we can patch it later, and add it to a 'look at this later'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 * list.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 */
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
64 auto a = new Statements();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 Statement s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
67 a.push(this);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 s = new CompoundStatement(loc, a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 sc.fes.gotos.push(cast(void*)s); // 'look at this later' list
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 if (label.statement && label.statement.tf != sc.tf)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 error("cannot goto in or out of finally block");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
78 override BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 //printf("GotoStatement.blockExit(%p)\n", this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 return BE.BEgoto;
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 Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
89 override void toIR(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 block* b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 block* bdest;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 Blockx* blx = irs.blx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 if (!label.statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 error("label %s is undefined", label.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 if (tf !is label.statement.tf)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 error("cannot goto forward out of or into finally block");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 bdest = labelToBlock(loc, blx, label);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 if (!bdest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 b = blx.curblock;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 incUsage(irs, loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 // Adjust exception handler scope index if in different try blocks
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 if (b.Btry != bdest.Btry)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 // Check that bdest is in an enclosing try block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 for (block* bt = b.Btry; bt != bdest.Btry; bt = bt.Btry)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 if (!bt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 //printf("b.Btry = %p, bdest.Btry = %p\n", b.Btry, bdest.Btry);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 error("cannot goto into try block");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 //setScopeIndex(blx, b, bdest.Btry ? bdest.Btry.Bscope_index : -1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 list_append(&b.Bsucc,bdest);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 block_next(blx,BCgoto,null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
130 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 buf.writestring("goto ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 buf.writestring(ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 buf.writebyte(';');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 buf.writenl();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
138 override GotoStatement isGotoStatement() { return this; }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
139 }