0
|
1 module dmd.ScopeStatement;
|
|
2
|
|
3 import dmd.Statement;
|
|
4 import dmd.Loc;
|
|
5 import dmd.Scope;
|
|
6 import dmd.OutBuffer;
|
|
7 import dmd.HdrGenState;
|
|
8 import dmd.Expression;
|
|
9 import dmd.InterState;
|
|
10 import dmd.InlineScanState;
|
|
11 import dmd.ScopeDsymbol;
|
|
12 import dmd.ArrayTypes;
|
|
13 import dmd.CompoundStatement;
|
|
14 import dmd.IRState;
|
|
15 import dmd.BE;
|
|
16
|
|
17 import dmd.backend.Blockx;
|
|
18 import dmd.backend.BC;
|
|
19 import dmd.backend.Util;
|
|
20
|
|
21 class ScopeStatement : Statement
|
|
22 {
|
|
23 Statement statement;
|
|
24
|
|
25 this(Loc loc, Statement s)
|
|
26 {
|
|
27 super(loc);
|
|
28 this.statement = s;
|
|
29 }
|
|
30
|
|
31 Statement syntaxCopy()
|
|
32 {
|
|
33 Statement s = statement ? statement.syntaxCopy() : null;
|
|
34 s = new ScopeStatement(loc, s);
|
|
35 return s;
|
|
36 }
|
|
37
|
|
38 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
|
39 {
|
|
40 buf.writeByte('{');
|
|
41 buf.writenl();
|
|
42
|
|
43 if (statement)
|
|
44 statement.toCBuffer(buf, hgs);
|
|
45
|
|
46 buf.writeByte('}');
|
|
47 buf.writenl();
|
|
48 }
|
|
49
|
|
50 ScopeStatement isScopeStatement() { return this; }
|
|
51
|
|
52 Statement semantic(Scope sc)
|
|
53 {
|
|
54 ScopeDsymbol sym;
|
|
55
|
|
56 //printf("ScopeStatement.semantic(sc = %p)\n", sc);
|
|
57 if (statement)
|
|
58 {
|
|
59 Statements a;
|
|
60
|
|
61 sym = new ScopeDsymbol();
|
|
62 sym.parent = sc.scopesym;
|
|
63 sc = sc.push(sym);
|
|
64
|
|
65 a = statement.flatten(sc);
|
|
66 if (a)
|
|
67 {
|
|
68 statement = new CompoundStatement(loc, a);
|
|
69 }
|
|
70
|
|
71 statement = statement.semantic(sc);
|
|
72 if (statement)
|
|
73 {
|
|
74 Statement sentry;
|
|
75 Statement sexception;
|
|
76 Statement sfinally;
|
|
77
|
|
78 statement.scopeCode(sc, &sentry, &sexception, &sfinally);
|
|
79 if (sfinally)
|
|
80 {
|
|
81 //printf("adding sfinally\n");
|
|
82 statement = new CompoundStatement(loc, statement, sfinally);
|
|
83 }
|
|
84 }
|
|
85
|
|
86 sc.pop();
|
|
87 }
|
|
88 return this;
|
|
89 }
|
|
90
|
|
91 bool hasBreak()
|
|
92 {
|
|
93 //printf("ScopeStatement.hasBreak() %s\n", toChars());
|
|
94 return statement ? statement.hasBreak() : false;
|
|
95 }
|
|
96
|
|
97 bool hasContinue()
|
|
98 {
|
|
99 return statement ? statement.hasContinue() : false;
|
|
100 }
|
|
101
|
|
102 bool usesEH()
|
|
103 {
|
|
104 return statement ? statement.usesEH() : false;
|
|
105 }
|
|
106
|
|
107 BE blockExit()
|
|
108 {
|
|
109 //printf("ScopeStatement::blockExit(%p)\n", statement);
|
|
110 return statement ? statement.blockExit() : BE.BEfallthru;
|
|
111 }
|
|
112
|
|
113 bool comeFrom()
|
|
114 {
|
|
115 //printf("ScopeStatement.comeFrom()\n");
|
|
116 return statement ? statement.comeFrom() : false;
|
|
117 }
|
|
118
|
|
119 bool isEmpty()
|
|
120 {
|
|
121 //printf("ScopeStatement::isEmpty() %d\n", statement ? statement->isEmpty() : TRUE);
|
|
122 return statement ? statement.isEmpty() : true;
|
|
123 }
|
|
124
|
63
|
125 Expression interpret(InterState istate)
|
0
|
126 {
|
|
127 assert(false);
|
|
128 }
|
|
129
|
|
130 Statement inlineScan(InlineScanState* iss)
|
|
131 {
|
|
132 if (statement)
|
|
133 statement = statement.inlineScan(iss);
|
|
134 return this;
|
|
135 }
|
|
136
|
|
137 void toIR(IRState* irs)
|
|
138 {
|
|
139 if (statement)
|
|
140 {
|
|
141 Blockx* blx = irs.blx;
|
|
142 IRState mystate = IRState(irs,this);
|
|
143
|
|
144 if (mystate.prev.ident)
|
|
145 mystate.ident = mystate.prev.ident;
|
|
146
|
|
147 statement.toIR(&mystate);
|
|
148
|
|
149 if (mystate.breakBlock)
|
|
150 block_goto(blx, BC.BCgoto, mystate.breakBlock);
|
|
151 }
|
|
152 }
|
|
153 } |