Skip to content

Commit d54c3ab

Browse files
committed
Cleanup
1 parent 5979f0f commit d54c3ab

3 files changed

Lines changed: 25 additions & 22 deletions

File tree

vhdl_lang/src/analysis/association.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ pub(crate) struct ResolvedFormal<'a> {
3535
/// port map(to_slv(foo) => sig)
3636
is_converted: bool,
3737

38-
/// The type of the potentially partial or converted formal
38+
/// The type of the potentially partial or converted formal.
39+
/// `None`, if the formal does not have to a type (e.g., packages or subprograms).
3940
type_mark: Option<TypeEnt<'a>>,
4041
}
4142

@@ -50,7 +51,7 @@ impl<'a> ResolvedFormal<'a> {
5051
}
5152
}
5253

53-
fn convert(&self, into_type: TypeEnt<'a>) -> Self {
54+
fn convert(self, into_type: TypeEnt<'a>) -> Self {
5455
Self {
5556
idx: self.idx,
5657
iface: self.iface,
@@ -83,14 +84,13 @@ impl<'a> ResolvedFormal<'a> {
8384
}
8485

8586
pub fn require_type_mark(&self) -> Result<TypeEnt<'a>, Diagnostic> {
86-
match self.type_mark {
87-
None => Err(Diagnostic::invalid_formal(
87+
self.type_mark.ok_or_else(|| {
88+
Diagnostic::invalid_formal(
8889
self.iface
8990
.decl_pos()
90-
.expect("Interface ent must have a declaration position"),
91-
)),
92-
Some(type_mark) => Ok(type_mark),
93-
}
91+
.expect("InterfaceEnt must have a declaration position"),
92+
)
93+
})
9494
}
9595
}
9696

@@ -378,7 +378,8 @@ impl<'a> AnalyzeContext<'a, '_> {
378378
/// that are present at the call / instantiation site).
379379
/// The result is a vector of tuples where the first refers to the token span
380380
/// of the actual and the second to the resolved formal.
381-
/// If there is an extraneous argument, the resolved formal will be `None`.
381+
/// If there is are extraneous arguments, the resolved formals at that position
382+
/// will be `None`.
382383
pub fn combine_formal_with_actuals<'e>(
383384
&self,
384385
formal_region: &FormalRegion<'a>,
@@ -499,11 +500,11 @@ impl<'a> AnalyzeContext<'a, '_> {
499500
self.check_missing_and_duplicates(error_pos, resolved_pairs, formal_region, diagnostics)
500501
}
501502

502-
/// Checks associations irrelevant of the actual kind (i.e., can analyzes generic maps,
503+
/// Checks associations irrelevant of the actual kind (i.e., can analyze generic maps,
503504
/// port maps and subprogram calls).
504505
///
505506
/// * `error_pos` Position of the instance or call site
506-
/// * `formal_region` The formals, i.e., the declared elements
507+
/// * `formal_region` The formals (i.e., the declared elements)
507508
/// * `mapping` Maps generic types to their actual values. This is a mutable reference so that
508509
/// generic maps can populate the content appropriately while port maps and parameters will
509510
/// only read from it.
@@ -531,7 +532,7 @@ impl<'a> AnalyzeContext<'a, '_> {
531532
continue;
532533
};
533534
if formal_region.typ == InterfaceType::Parameter {
534-
self.check_parameter_interface(
535+
self.check_interface_mode_mismatch(
535536
resolved_formal,
536537
expr,
537538
scope,
@@ -684,9 +685,11 @@ impl<'a> AnalyzeContext<'a, '_> {
684685
Ok(())
685686
}
686687

687-
// LRM 4.2.2.1: In a subprogram, the interface mode must match the mode of the actual designator
688-
// when the interface mode is signal, variable or file. Furthermore, they must be a single name.
689-
fn check_parameter_interface(
688+
/// From LRM 4.2.2.1:
689+
/// In a subprogram, the interface mode must match the mode of the actual designator
690+
/// when the interface mode is signal, variable or file.
691+
/// Furthermore, they must be a single name.
692+
fn check_interface_mode_mismatch(
690693
&self,
691694
resolved_formal: &ResolvedFormal<'a>,
692695
expr: &mut Expression,
@@ -718,7 +721,6 @@ impl<'a> AnalyzeContext<'a, '_> {
718721
);
719722
}
720723
}
721-
ObjectClass::Constant => {}
722724
ObjectClass::Variable | ObjectClass::SharedVariable => {
723725
let Some(name) =
724726
as_fatal(self.expression_as_name(expr, scope, actual_pos, diagnostics))?
@@ -741,6 +743,7 @@ impl<'a> AnalyzeContext<'a, '_> {
741743
);
742744
}
743745
}
746+
ObjectClass::Constant => {}
744747
},
745748
InterfaceEnt::File(_) => {
746749
let Some(name) =

vhdl_lang/src/analysis/overloaded.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl<'a> AnalyzeContext<'a, '_> {
197197
) -> FatalResult {
198198
as_fatal(self.check_association(
199199
error_pos,
200-
FormalRegion::ref_from_param_ref(ent.formals()),
200+
ent.formals().as_formal_region(),
201201
&mut FnvHashMap::default(),
202202
scope,
203203
assocs,
@@ -224,7 +224,7 @@ impl<'a> AnalyzeContext<'a, '_> {
224224
for ent in candidates.iter() {
225225
if let Some(resolved) = as_fatal(self.resolve_association_formals(
226226
call_pos,
227-
FormalRegion::ref_from_param_ref(ent.formals()),
227+
ent.formals().as_formal_region(),
228228
scope,
229229
assocs,
230230
&mut NullDiagnostics,

vhdl_lang/src/named_entity/formal_region.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ impl<'a> FormalRegion<'a> {
198198
pub fn nth(&self, idx: usize) -> Option<InterfaceEnt<'a>> {
199199
self.entities.get(idx).cloned()
200200
}
201-
202-
pub fn ref_from_param_ref(parameter_region: &'a ParameterRegion<'a>) -> &'a FormalRegion<'a> {
203-
&parameter_region.0
204-
}
205201
}
206202

207203
#[derive(Clone, Debug)]
@@ -299,6 +295,10 @@ impl<'a> ParameterRegion<'a> {
299295
}
300296
}
301297

298+
pub fn as_formal_region(&self) -> &FormalRegion<'a> {
299+
&self.0
300+
}
301+
302302
pub fn iter(&self) -> impl ExactSizeIterator<Item = ParameterEnt<'a>> + '_ {
303303
self.0.iter().map(|ent| ParameterEnt(ent.inner()))
304304
}

0 commit comments

Comments
 (0)