@@ -87,18 +87,17 @@ impl<'a> AnalyzeContext<'a> {
87
87
& self ,
88
88
scope : & Scope < ' a > ,
89
89
parent : EntRef < ' a > ,
90
- sroot : & SequentialRoot < ' a > ,
91
90
statement : & mut LabeledSequentialStatement ,
92
91
diagnostics : & mut dyn DiagnosticHandler ,
93
92
) -> FatalResult {
94
93
match statement. statement {
95
94
SequentialStatement :: Return ( ref mut ret) => {
96
95
let ReturnStatement { ref mut expression } = ret. item ;
97
96
98
- match sroot {
97
+ match SequentialRoot :: from ( parent ) {
99
98
SequentialRoot :: Function ( ttyp) => {
100
99
if let Some ( ref mut expression) = expression {
101
- self . expr_with_ttyp ( scope, * ttyp, expression, diagnostics) ?;
100
+ self . expr_with_ttyp ( scope, ttyp, expression, diagnostics) ?;
102
101
} else {
103
102
diagnostics. error ( & ret. pos , "Functions cannot return without a value" ) ;
104
103
}
@@ -186,10 +185,10 @@ impl<'a> AnalyzeContext<'a> {
186
185
for conditional in conditionals {
187
186
let Conditional { condition, item } = conditional;
188
187
self . boolean_expr ( scope, condition, diagnostics) ?;
189
- self . analyze_sequential_part ( scope, parent, sroot , item, diagnostics) ?;
188
+ self . analyze_sequential_part ( scope, parent, item, diagnostics) ?;
190
189
}
191
190
if let Some ( else_item) = else_item {
192
- self . analyze_sequential_part ( scope, parent, sroot , else_item, diagnostics) ?;
191
+ self . analyze_sequential_part ( scope, parent, else_item, diagnostics) ?;
193
192
}
194
193
}
195
194
SequentialStatement :: Case ( ref mut case_stmt) => {
@@ -203,7 +202,7 @@ impl<'a> AnalyzeContext<'a> {
203
202
for alternative in alternatives. iter_mut ( ) {
204
203
let Alternative { choices, item } = alternative;
205
204
self . choice_with_ttyp ( scope, ctyp, choices, diagnostics) ?;
206
- self . analyze_sequential_part ( scope, parent, sroot , item, diagnostics) ?;
205
+ self . analyze_sequential_part ( scope, parent, item, diagnostics) ?;
207
206
}
208
207
}
209
208
SequentialStatement :: Loop ( ref mut loop_stmt) => {
@@ -221,32 +220,14 @@ impl<'a> AnalyzeContext<'a> {
221
220
. define ( index, parent, AnyEntKind :: LoopParameter ( typ) ) ,
222
221
diagnostics,
223
222
) ;
224
- self . analyze_sequential_part (
225
- & region,
226
- parent,
227
- sroot,
228
- statements,
229
- diagnostics,
230
- ) ?;
223
+ self . analyze_sequential_part ( & region, parent, statements, diagnostics) ?;
231
224
}
232
225
Some ( IterationScheme :: While ( ref mut expr) ) => {
233
226
self . boolean_expr ( scope, expr, diagnostics) ?;
234
- self . analyze_sequential_part (
235
- scope,
236
- parent,
237
- sroot,
238
- statements,
239
- diagnostics,
240
- ) ?;
227
+ self . analyze_sequential_part ( scope, parent, statements, diagnostics) ?;
241
228
}
242
229
None => {
243
- self . analyze_sequential_part (
244
- scope,
245
- parent,
246
- sroot,
247
- statements,
248
- diagnostics,
249
- ) ?;
230
+ self . analyze_sequential_part ( scope, parent, statements, diagnostics) ?;
250
231
}
251
232
}
252
233
}
@@ -337,7 +318,6 @@ impl<'a> AnalyzeContext<'a> {
337
318
& self ,
338
319
scope : & Scope < ' a > ,
339
320
parent : EntRef < ' a > ,
340
- sroot : & SequentialRoot < ' a > ,
341
321
statements : & mut [ LabeledSequentialStatement ] ,
342
322
diagnostics : & mut dyn DiagnosticHandler ,
343
323
) -> FatalResult {
@@ -359,15 +339,37 @@ impl<'a> AnalyzeContext<'a> {
359
339
parent
360
340
} ;
361
341
362
- self . analyze_sequential_statement ( scope, parent, sroot , statement, diagnostics) ?;
342
+ self . analyze_sequential_statement ( scope, parent, statement, diagnostics) ?;
363
343
}
364
344
365
345
Ok ( ( ) )
366
346
}
367
347
}
368
348
369
- pub enum SequentialRoot < ' a > {
349
+ enum SequentialRoot < ' a > {
370
350
Process ,
371
351
Procedure ,
372
352
Function ( TypeEnt < ' a > ) ,
373
353
}
354
+
355
+ impl < ' a > From < EntRef < ' a > > for SequentialRoot < ' a > {
356
+ fn from ( value : EntRef < ' a > ) -> Self {
357
+ match value. kind ( ) {
358
+ AnyEntKind :: Overloaded ( overloaded) => {
359
+ if let Some ( return_type) = overloaded. signature ( ) . return_type ( ) {
360
+ SequentialRoot :: Function ( return_type)
361
+ } else {
362
+ SequentialRoot :: Procedure
363
+ }
364
+ }
365
+ AnyEntKind :: Label => {
366
+ if let Some ( parent) = value. parent {
367
+ SequentialRoot :: from ( parent)
368
+ } else {
369
+ SequentialRoot :: Process
370
+ }
371
+ }
372
+ _ => SequentialRoot :: Process ,
373
+ }
374
+ }
375
+ }
0 commit comments