@@ -87,18 +87,17 @@ impl<'a> AnalyzeContext<'a> {
8787 & self ,
8888 scope : & Scope < ' a > ,
8989 parent : EntRef < ' a > ,
90- sroot : & SequentialRoot < ' a > ,
9190 statement : & mut LabeledSequentialStatement ,
9291 diagnostics : & mut dyn DiagnosticHandler ,
9392 ) -> FatalResult {
9493 match statement. statement {
9594 SequentialStatement :: Return ( ref mut ret) => {
9695 let ReturnStatement { ref mut expression } = ret. item ;
9796
98- match sroot {
97+ match SequentialRoot :: from ( parent ) {
9998 SequentialRoot :: Function ( ttyp) => {
10099 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) ?;
102101 } else {
103102 diagnostics. error ( & ret. pos , "Functions cannot return without a value" ) ;
104103 }
@@ -186,10 +185,10 @@ impl<'a> AnalyzeContext<'a> {
186185 for conditional in conditionals {
187186 let Conditional { condition, item } = conditional;
188187 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) ?;
190189 }
191190 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) ?;
193192 }
194193 }
195194 SequentialStatement :: Case ( ref mut case_stmt) => {
@@ -203,7 +202,7 @@ impl<'a> AnalyzeContext<'a> {
203202 for alternative in alternatives. iter_mut ( ) {
204203 let Alternative { choices, item } = alternative;
205204 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) ?;
207206 }
208207 }
209208 SequentialStatement :: Loop ( ref mut loop_stmt) => {
@@ -221,32 +220,14 @@ impl<'a> AnalyzeContext<'a> {
221220 . define ( index, parent, AnyEntKind :: LoopParameter ( typ) ) ,
222221 diagnostics,
223222 ) ;
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) ?;
231224 }
232225 Some ( IterationScheme :: While ( ref mut expr) ) => {
233226 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) ?;
241228 }
242229 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) ?;
250231 }
251232 }
252233 }
@@ -337,7 +318,6 @@ impl<'a> AnalyzeContext<'a> {
337318 & self ,
338319 scope : & Scope < ' a > ,
339320 parent : EntRef < ' a > ,
340- sroot : & SequentialRoot < ' a > ,
341321 statements : & mut [ LabeledSequentialStatement ] ,
342322 diagnostics : & mut dyn DiagnosticHandler ,
343323 ) -> FatalResult {
@@ -359,15 +339,37 @@ impl<'a> AnalyzeContext<'a> {
359339 parent
360340 } ;
361341
362- self . analyze_sequential_statement ( scope, parent, sroot , statement, diagnostics) ?;
342+ self . analyze_sequential_statement ( scope, parent, statement, diagnostics) ?;
363343 }
364344
365345 Ok ( ( ) )
366346 }
367347}
368348
369- pub enum SequentialRoot < ' a > {
349+ enum SequentialRoot < ' a > {
370350 Process ,
371351 Procedure ,
372352 Function ( TypeEnt < ' a > ) ,
373353}
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