annotate dmd/LabelStatement.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 c77e9f4f1793
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.LabelStatement;
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.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.TryFinallyStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.ExpStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.InlineScanState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.LabelDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.CSX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.BE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21
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.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.backend.BC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 class LabelStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 Statement statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 TryFinallyStatement tf = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 block* lblock = null; // back end
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 int isReturnLabel = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 this(Loc loc, Identifier ident, Statement statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 this.ident = ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 this.statement = statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
42 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 LabelStatement s = new LabelStatement(loc, ident, statement.syntaxCopy());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
48 override Statement semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 LabelDsymbol ls;
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("LabelStatement.semantic()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 ls = fd.searchLabel(ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 if (ls.statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 error("Label '%s' already defined", ls.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 ls.statement = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 tf = sc.tf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 sc = sc.push();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 sc.scopesym = sc.enclosing.scopesym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 sc.callSuper |= CSXlabel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 sc.slabel = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 if (statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 statement = statement.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
70 override Statements flatten(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 Statements a = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 if (statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 a = statement.flatten(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 if (a)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 if (!a.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 a.push(cast(void*)new ExpStatement(loc, null));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 Statement s = cast(Statement)a.data[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 s = new LabelStatement(loc, ident, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 a.data[0] = cast(void*)s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 return a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
92 override bool usesEH()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 return statement ? statement.usesEH() : false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
97 override BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 //printf("LabelStatement.blockExit(%p)\n", this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 return statement ? statement.blockExit() : BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
103 override bool comeFrom()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 //printf("LabelStatement.comeFrom()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
109 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 assert(false);
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: 63
diff changeset
114 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 buf.writestring(ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 buf.writebyte(':');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 buf.writenl();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 if (statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 statement.toCBuffer(buf, hgs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
123 override Statement inlineScan(InlineScanState* iss)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 if (statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 statement = statement.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 return this;
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 toIR(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 //printf("LabelStatement.toIR() %p, statement = %p\n", this, statement);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 Blockx* blx = irs.blx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 block* bc = blx.curblock;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 IRState mystate = IRState(irs,this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 mystate.ident = ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 if (lblock)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 // We had made a guess about which tryblock the label is in.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 // Error if we guessed wrong.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 // BUG: should fix this
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 if (lblock.Btry != blx.tryblock)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 error("cannot goto forward into different try block level");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 lblock = block_calloc(blx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 block_next(blx,BCgoto,lblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 list_append(&bc.Bsucc,blx.curblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 if (statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 statement.toIR(&mystate);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
154 }