Skip to content

Commit 44f4518

Browse files
committed
Skip passing SequentialRoot, build from parent
1 parent ea5f6c9 commit 44f4518

File tree

3 files changed

+33
-46
lines changed

3 files changed

+33
-46
lines changed

vhdl_lang/src/analysis/concurrent.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#![allow(clippy::unneeded_field_pattern)]
99

1010
use super::named_entity::*;
11-
use super::sequential::SequentialRoot;
1211
use super::*;
1312
use crate::ast::*;
1413
use crate::data::*;
@@ -121,13 +120,7 @@ impl<'a> AnalyzeContext<'a> {
121120
let nested = scope.nested();
122121
self.define_labels_for_sequential_part(scope, parent, statements, diagnostics)?;
123122
self.analyze_declarative_part(&nested, parent, decl, diagnostics)?;
124-
self.analyze_sequential_part(
125-
&nested,
126-
parent,
127-
&SequentialRoot::Process,
128-
statements,
129-
diagnostics,
130-
)?;
123+
self.analyze_sequential_part(&nested, parent, statements, diagnostics)?;
131124
}
132125
ConcurrentStatement::ForGenerate(ref mut gen) => {
133126
let ForGenerateStatement {

vhdl_lang/src/analysis/declarative.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use super::formal_region::FormalRegion;
88
use super::formal_region::RecordRegion;
99
use super::named_entity::*;
1010
use super::names::*;
11-
use super::sequential::SequentialRoot;
1211
use super::*;
1312
use crate::ast;
1413
use crate::ast::*;
@@ -494,12 +493,6 @@ impl<'a> AnalyzeContext<'a> {
494493
}
495494
};
496495

497-
let sroot = if let Some(return_type) = subpgm_ent.signature().return_type() {
498-
SequentialRoot::Function(return_type)
499-
} else {
500-
SequentialRoot::Procedure
501-
};
502-
503496
scope.add(subpgm_ent.into(), diagnostics);
504497

505498
self.define_labels_for_sequential_part(
@@ -518,7 +511,6 @@ impl<'a> AnalyzeContext<'a> {
518511
self.analyze_sequential_part(
519512
&subpgm_region,
520513
subpgm_ent.into(),
521-
&sroot,
522514
&mut body.statements,
523515
diagnostics,
524516
)?;

vhdl_lang/src/analysis/sequential.rs

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)