Skip to content

Commit 3233a8d

Browse files
committed
Enable ports to lookup the types from generics
1 parent 482aa37 commit 3233a8d

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

vhdl_lang/src/analysis/association.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,18 +499,26 @@ impl<'a> AnalyzeContext<'a, '_> {
499499
self.check_missing_and_duplicates(error_pos, resolved_pairs, formal_region, diagnostics)
500500
}
501501

502+
/// Checks associations irrelevant of the actual kind (i.e., can analyzes generic maps,
503+
/// port maps and subprogram calls).
504+
///
505+
/// * `error_pos` Position of the instance or call site
506+
/// * `formal_region` The formals, i.e., the declared elements
507+
/// * `mapping` Maps generic types to their actual values. This is a mutable reference so that
508+
/// generic maps can populate the content appropriately while port maps and parameters will
509+
/// only read from it.
502510
pub fn check_association<'e>(
503511
&self,
504-
error_pos: &SrcPos, // The position of the instance/call-site
512+
error_pos: &SrcPos,
505513
formal_region: &FormalRegion<'a>,
514+
mapping: &mut FnvHashMap<EntityId, TypeEnt<'a>>,
506515
scope: &Scope<'a>,
507516
elems: &'e mut [AssociationElement],
508517
diagnostics: &mut dyn DiagnosticHandler,
509-
) -> EvalResult<FnvHashMap<EntityId, TypeEnt<'a>>> {
518+
) -> EvalResult {
510519
let resolved_pairs =
511520
self.combine_formal_with_actuals(formal_region, scope, elems, diagnostics)?;
512521

513-
let mut mapping = FnvHashMap::default();
514522
for (resolved_formal, actual) in resolved_pairs
515523
.iter()
516524
.map(|(_, resolved_formal)| resolved_formal)
@@ -673,7 +681,7 @@ impl<'a> AnalyzeContext<'a, '_> {
673681
}
674682
}
675683
self.check_missing_and_duplicates(error_pos, resolved_pairs, formal_region, diagnostics)?;
676-
Ok(mapping)
684+
Ok(())
677685
}
678686

679687
// LRM 4.2.2.1: In a subprogram, the interface mode must match the mode of the actual designator

vhdl_lang/src/analysis/concurrent.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::data::*;
1313
use crate::named_entity::*;
1414
use crate::{HasTokenSpan, TokenSpan};
1515
use analyze::*;
16+
use fnv::FnvHashMap;
1617

1718
impl<'a> AnalyzeContext<'a, '_> {
1819
pub fn analyze_concurrent_part(
@@ -408,10 +409,12 @@ impl<'a> AnalyzeContext<'a, '_> {
408409
) -> FatalResult {
409410
let (generic_region, port_region) = ent_region.to_entity_formal();
410411

412+
let mut mapping = FnvHashMap::default();
411413
as_fatal(
412414
self.check_association(
413415
&entity_name.pos(self.ctx),
414416
&generic_region,
417+
&mut mapping,
415418
scope,
416419
generic_map_aspect
417420
.map(|it| it.list.items.as_mut_slice())
@@ -423,6 +426,7 @@ impl<'a> AnalyzeContext<'a, '_> {
423426
self.check_association(
424427
&entity_name.pos(self.ctx),
425428
&port_region,
429+
&mut mapping,
426430
scope,
427431
port_map_aspect
428432
.map(|it| it.list.items.as_mut_slice())

vhdl_lang/src/analysis/overloaded.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// Copyright (c) 2023, Olof Kraigher [email protected]
66

7-
use fnv::FnvHashSet;
7+
use fnv::{FnvHashMap, FnvHashSet};
88
use vhdl_lang::TokenAccess;
99

1010
use super::analyze::*;
@@ -198,6 +198,7 @@ impl<'a> AnalyzeContext<'a, '_> {
198198
as_fatal(self.check_association(
199199
error_pos,
200200
FormalRegion::ref_from_param_ref(ent.formals()),
201+
&mut FnvHashMap::default(),
201202
scope,
202203
assocs,
203204
diagnostics,

vhdl_lang/src/analysis/package_instance.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ impl<'a> AnalyzeContext<'a, '_> {
5656
let nested = scope.nested().in_package_declaration();
5757
let (generics, other) = uninst_region.to_package_generic();
5858

59-
let mapping = if let Some(generic_map) = generic_map {
59+
let mut mapping = FnvHashMap::default();
60+
if let Some(generic_map) = generic_map {
6061
self.check_association(
6162
decl_pos,
6263
&generics,
64+
&mut mapping,
6365
&nested,
6466
generic_map.list.items.as_mut_slice(),
6567
diagnostics,
66-
)?
67-
} else {
68-
FnvHashMap::default()
69-
};
68+
)?;
69+
}
7070

7171
for uninst in other {
7272
match self.instantiate(Some(ent), &mapping, uninst, &nested) {

vhdl_lang/src/analysis/tests/association_formal.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,6 @@ end architecture;
787787
}
788788

789789
#[test]
790-
#[ignore]
791790
fn generic_type_from_port_in_map() {
792791
let mut builder = LibraryBuilder::new();
793792
builder.code(
@@ -809,7 +808,7 @@ end architecture;
809808
entity test is
810809
end entity test;
811810
812-
architecture rtl of te is
811+
architecture rtl of test is
813812
begin
814813
foo_inst: entity work.foo
815814
generic map(

0 commit comments

Comments
 (0)