@@ -29,10 +29,10 @@ impl<'a> AnalyzeContext<'a> {
2929
3030 match statement. statement {
3131 SequentialStatement :: If ( ref mut ifstmt) => {
32- let IfStatement {
32+ let Conditionals {
3333 conditionals,
3434 else_item,
35- } = ifstmt;
35+ } = & mut ifstmt. conds ;
3636
3737 for conditional in conditionals {
3838 self . define_labels_for_sequential_part (
@@ -143,30 +143,36 @@ impl<'a> AnalyzeContext<'a> {
143143 SequentialStatement :: Exit ( ref mut exit_stmt) => {
144144 let ExitStatement {
145145 condition,
146- // @TODO loop label
147- ..
146+ loop_label,
148147 } = exit_stmt;
149148
149+ if let Some ( ref mut loop_label) = loop_label {
150+ self . check_loop_label ( scope, loop_label, diagnostics) ;
151+ }
152+
150153 if let Some ( expr) = condition {
151154 self . boolean_expr ( scope, expr, diagnostics) ?;
152155 }
153156 }
154157 SequentialStatement :: Next ( ref mut next_stmt) => {
155158 let NextStatement {
156159 condition,
157- // @TODO loop label
158- ..
160+ loop_label,
159161 } = next_stmt;
160162
163+ if let Some ( ref mut loop_label) = loop_label {
164+ self . check_loop_label ( scope, loop_label, diagnostics) ;
165+ }
166+
161167 if let Some ( expr) = condition {
162168 self . boolean_expr ( scope, expr, diagnostics) ?;
163169 }
164170 }
165171 SequentialStatement :: If ( ref mut ifstmt) => {
166- let IfStatement {
172+ let Conditionals {
167173 conditionals,
168174 else_item,
169- } = ifstmt;
175+ } = & mut ifstmt. conds ;
170176
171177 // @TODO write generic function for this
172178 for conditional in conditionals {
@@ -183,6 +189,7 @@ impl<'a> AnalyzeContext<'a> {
183189 is_matching : _,
184190 expression,
185191 alternatives,
192+ end_label_pos : _,
186193 } = case_stmt;
187194 let ctyp = as_fatal ( self . expr_unambiguous_type ( scope, expression, diagnostics) ) ?;
188195 for alternative in alternatives. iter_mut ( ) {
@@ -195,6 +202,7 @@ impl<'a> AnalyzeContext<'a> {
195202 let LoopStatement {
196203 iteration_scheme,
197204 statements,
205+ end_label_pos : _,
198206 } = loop_stmt;
199207 match iteration_scheme {
200208 Some ( IterationScheme :: For ( ref mut index, ref mut drange) ) => {
@@ -265,6 +273,39 @@ impl<'a> AnalyzeContext<'a> {
265273 Ok ( ( ) )
266274 }
267275
276+ fn check_loop_label (
277+ & self ,
278+ scope : & Scope < ' a > ,
279+ label : & mut WithRef < Ident > ,
280+ diagnostics : & mut dyn DiagnosticHandler ,
281+ ) {
282+ match scope. lookup (
283+ & label. item . pos ,
284+ & Designator :: Identifier ( label. item . item . clone ( ) ) ,
285+ ) {
286+ Ok ( NamedEntities :: Single ( ent) ) => {
287+ label. set_unique_reference ( ent) ;
288+ if !matches ! ( ent. kind( ) , AnyEntKind :: Label ) {
289+ // @TODO check that is actually a loop label and that we are inside the loop
290+ diagnostics. error (
291+ & label. item . pos ,
292+ format ! ( "Expected loop label, got {}" , ent. describe( ) ) ,
293+ ) ;
294+ }
295+ }
296+ Ok ( NamedEntities :: Overloaded ( _) ) => diagnostics. error (
297+ & label. item . pos ,
298+ format ! (
299+ "Expected loop label, got overloaded name {}" ,
300+ & label. item. item
301+ ) ,
302+ ) ,
303+ Err ( diag) => {
304+ diagnostics. push ( diag) ;
305+ }
306+ }
307+ }
308+
268309 pub fn analyze_sequential_part (
269310 & self ,
270311 scope : & Scope < ' a > ,
0 commit comments