Skip to content

Commit 6724e2c

Browse files
committed
Flatten implicit declarations
1 parent 91d4883 commit 6724e2c

File tree

3 files changed

+29
-33
lines changed

3 files changed

+29
-33
lines changed

vhdl_lang/src/analysis/named_entity.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,23 @@ pub enum Type {
4242
}
4343

4444
impl Type {
45-
pub fn implicit_declarations(&self) -> Option<impl Iterator<Item = Arc<NamedEntity>> + '_> {
46-
let implicit = match self {
47-
Type::Array { ref implicit, .. } => implicit,
48-
Type::Enum(ref implicit) => return Some(either::Either::Left(implicit.iter())),
49-
Type::Integer(ref implicit) => implicit,
50-
Type::Physical(ref implicit) => implicit,
51-
Type::File(ref implicit) => implicit,
52-
Type::Access(.., ref implicit) => implicit,
45+
pub fn implicit_declarations(&self) -> impl Iterator<Item = Arc<NamedEntity>> + '_ {
46+
match self {
47+
Type::Array { ref implicit, .. } => Some(either::Either::Right(implicit.iter())),
48+
Type::Enum(ref implicit) => Some(either::Either::Left(implicit.iter())),
49+
Type::Integer(ref implicit) => Some(either::Either::Right(implicit.iter())),
50+
Type::Physical(ref implicit) => Some(either::Either::Right(implicit.iter())),
51+
Type::File(ref implicit) => Some(either::Either::Right(implicit.iter())),
52+
Type::Access(.., ref implicit) => Some(either::Either::Right(implicit.iter())),
5353
Type::Incomplete(..)
5454
| Type::Interface
5555
| Type::Protected(..)
5656
| Type::Record(..)
5757
| Type::Subtype(..)
58-
| Type::Alias(..) => {
59-
return None;
60-
}
61-
};
62-
63-
Some(either::Either::Right(implicit.iter()))
58+
| Type::Alias(..) => None,
59+
}
60+
.into_iter()
61+
.flatten()
6462
}
6563

6664
pub fn describe(&self) -> &str {
@@ -141,11 +139,13 @@ impl NamedEntityKind {
141139
matches!(self, NamedEntityKind::Type(..))
142140
}
143141

144-
pub fn implicit_declarations(&self) -> Option<impl Iterator<Item = Arc<NamedEntity>> + '_> {
142+
pub fn implicit_declarations(&self) -> impl Iterator<Item = Arc<NamedEntity>> + '_ {
145143
match self {
146-
NamedEntityKind::Type(typ) => typ.implicit_declarations(),
144+
NamedEntityKind::Type(typ) => Some(typ.implicit_declarations()),
147145
_ => None,
148146
}
147+
.into_iter()
148+
.flatten()
149149
}
150150

151151
pub fn describe(&self) -> &str {

vhdl_lang/src/analysis/region.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -400,15 +400,13 @@ impl<'a> Region<'a> {
400400
ent: &NamedEntity,
401401
diagnostics: &mut dyn DiagnosticHandler,
402402
) {
403-
if let Some(implicit) = ent.actual_kind().implicit_declarations() {
404-
for entity in implicit {
405-
let entity = NamedEntity::implicit(
406-
entity.designator().clone(),
407-
NamedEntityKind::NonObjectAlias(entity.clone()),
408-
ent.decl_pos(),
409-
);
410-
self.add(Arc::new(entity), diagnostics);
411-
}
403+
for entity in ent.actual_kind().implicit_declarations() {
404+
let entity = NamedEntity::implicit(
405+
entity.designator().clone(),
406+
NamedEntityKind::NonObjectAlias(entity.clone()),
407+
ent.decl_pos(),
408+
);
409+
self.add(Arc::new(entity), diagnostics);
412410
}
413411
}
414412

vhdl_lang/src/analysis/visibility.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,12 @@ impl Visibility {
9090
) {
9191
// Add implicit declarations when using declaration
9292
// For example all enum literals are made implicititly visible when using an enum type
93-
if let Some(implicit) = ent.actual_kind().implicit_declarations() {
94-
for entity in implicit {
95-
self.make_potentially_visible_with_name(
96-
visible_pos,
97-
entity.designator().clone(),
98-
entity.clone(),
99-
);
100-
}
93+
for entity in ent.actual_kind().implicit_declarations() {
94+
self.make_potentially_visible_with_name(
95+
visible_pos,
96+
entity.designator().clone(),
97+
entity.clone(),
98+
);
10199
}
102100

103101
let visible_ent = VisibleEntity {

0 commit comments

Comments
 (0)