Skip to content

Commit

Permalink
extend goto/implementation to find architectures of entities (#230)
Browse files Browse the repository at this point in the history
* extend goto/implementation to find architectures of entities

update the find_implementation function to also search for architectures
if the base designator is an entity

* optimize comparison in find_implementation

compare entity and entity of the architecture by their ids

* run cargo fmt
  • Loading branch information
kernmatthias authored Nov 29, 2023
1 parent 01750e3 commit aac4c7e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
16 changes: 12 additions & 4 deletions vhdl_lang/src/analysis/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,14 +457,22 @@ impl DesignRoot {
return vec![design.into()];
}
}
// Find all components with same name as entity in the library
// Find components and architectures to entity
AnyEntKind::Design(Design::Entity(..)) => {
let mut searcher = FindAllEnt::new(self, |ent| {
matches!(ent.kind(), AnyEntKind::Component(_))
&& matches!(
let ent_id = ent.id;
let mut searcher = FindAllEnt::new(self, |ent| match ent.kind() {
// Find all components with same name as entity in the library
AnyEntKind::Component(_) => {
matches!(
ent.designator(),
Designator::Identifier(comp_ident) if comp_ident == ident
)
}
// Find all architectures which implement the entity
AnyEntKind::Design(Design::Architecture(ent_of_arch)) => {
ent_of_arch.id == ent_id
}
_ => false,
});

let _ = self.search_library(library_name, &mut searcher);
Expand Down
5 changes: 4 additions & 1 deletion vhdl_lang/src/analysis/tests/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,14 @@ end architecture;
let ent = root
.search_reference(code.source(), code.s1("ent0").start())
.unwrap();
let arch = root
.search_reference(code.source(), code.s1("a ").start())
.unwrap();
let comp = root
.search_reference(code.source(), code.sa("component ", "ent0").start())
.unwrap();

assert_eq!(root.find_implementation(ent), vec![comp]);
assert_eq!(root.find_implementation(ent), vec![arch, comp]);
assert_eq!(root.find_implementation(comp), vec![ent]);
}

Expand Down

0 comments on commit aac4c7e

Please sign in to comment.