Skip to content

Commit a772d77

Browse files
committed
Ensure enum to_string is added to implicits
1 parent 1272d8a commit a772d77

File tree

6 files changed

+41
-41
lines changed

6 files changed

+41
-41
lines changed

vhdl_lang/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ rayon = "1"
2424
parking_lot = "0"
2525
dunce = "1"
2626
arc-swap = {version = "1", features = ["weak"]}
27-
either = "*"
2827

2928
[dev-dependencies]
3029
tempfile = "3"

vhdl_lang/src/analysis/declarative.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// Copyright (c) 2019, Olof Kraigher olof.kraigher@gmail.com
66

77
use super::formal_region::FormalRegion;
8-
use super::implicits::ImplicitMapBuilder;
98
use super::implicits::ImplicitVecBuilder;
109
use super::implicits::Implicits;
1110
use super::names::*;
@@ -439,11 +438,17 @@ impl<'a> AnalyzeContext<'a> {
439438
) -> FatalNullResult {
440439
match type_decl.def {
441440
TypeDefinition::Enumeration(ref mut enumeration) => {
442-
let implicit = ImplicitMapBuilder::default();
441+
let implicit = ImplicitVecBuilder::default();
443442
let enum_type = TypeEnt::define_with_opt_id(
444443
overwrite_id,
445444
&mut type_decl.ident,
446-
Type::Enum(implicit.inner()),
445+
Type::Enum(
446+
implicit.inner(),
447+
enumeration
448+
.iter()
449+
.map(|literal| literal.tree.item.clone().into_designator())
450+
.collect(),
451+
),
447452
);
448453

449454
let signature = Signature::new(FormalRegion::default(), Some(enum_type.clone()));
@@ -455,7 +460,7 @@ impl<'a> AnalyzeContext<'a> {
455460
Some(&literal.tree.pos),
456461
));
457462
literal.decl = Some(literal_ent.clone());
458-
implicit.insert(literal.tree.item.clone().into_designator(), &literal_ent);
463+
implicit.push(&literal_ent);
459464
parent.add(literal_ent, diagnostics);
460465
}
461466

@@ -465,8 +470,9 @@ impl<'a> AnalyzeContext<'a> {
465470
let standard = self.expect_standard_package_analysis().unwrap();
466471
let standard_region =
467472
StandardRegion::new(&self.root.symbols, &standard.result().region);
468-
469-
parent.add(standard_region.create_to_string(enum_type), diagnostics);
473+
let to_string = standard_region.create_to_string(enum_type);
474+
implicit.push(&to_string);
475+
parent.add(to_string, diagnostics);
470476
}
471477
}
472478
TypeDefinition::ProtectedBody(ref mut body) => {

vhdl_lang/src/analysis/implicits.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@
44
//
55
// Copyright (c) 2022, Olof Kraigher olof.kraigher@gmail.com
66

7-
use std::sync::{Arc, Weak};
8-
9-
use fnv::FnvHashMap;
10-
11-
use crate::ast::Designator;
12-
137
use super::NamedEntity;
8+
use std::sync::{Arc, Weak};
149

1510
/// Implicits typically contain self-references thus we use weak pointers
1611
/// Intialization is unsafe to be able to create the implicits after the type definition
@@ -19,9 +14,7 @@ use super::NamedEntity;
1914
#[derive(Clone, Default)]
2015
pub struct Implicits<T>(Arc<T>);
2116
pub type ImplicitVec = Implicits<Vec<Weak<NamedEntity>>>;
22-
pub type ImplicitMap = Implicits<FnvHashMap<Designator, Weak<NamedEntity>>>;
2317
pub type ImplicitVecBuilder = ImplicitsBuilder<Vec<Weak<NamedEntity>>>;
24-
pub type ImplicitMapBuilder = ImplicitsBuilder<FnvHashMap<Designator, Weak<NamedEntity>>>;
2518

2619
impl<T: Default> Implicits<T> {
2720
pub fn build() -> ImplicitsBuilder<T> {
@@ -43,12 +36,6 @@ impl ImplicitVec {
4336
}
4437
}
4538

46-
impl ImplicitMap {
47-
pub fn iter(&self) -> impl Iterator<Item = Arc<NamedEntity>> + '_ {
48-
self.0.values().filter_map(|weak_ent| weak_ent.upgrade())
49-
}
50-
}
51-
5239
#[derive(Default)]
5340
pub struct ImplicitsBuilder<T>(Arc<T>);
5441

@@ -70,11 +57,3 @@ impl ImplicitVecBuilder {
7057
}
7158
}
7259
}
73-
74-
impl ImplicitMapBuilder {
75-
pub fn insert(&self, designator: Designator, ent: &Arc<NamedEntity>) {
76-
unsafe {
77-
self.raw_mut().insert(designator, Arc::downgrade(ent));
78-
}
79-
}
80-
}

vhdl_lang/src/analysis/named_entity.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
// Copyright (c) 2022, Olof Kraigher olof.kraigher@gmail.com
66

77
use super::formal_region::FormalRegion;
8-
use super::implicits::ImplicitMap;
98
use super::implicits::ImplicitVec;
109
use super::region::Region;
1110
use crate::ast::*;
1211
use crate::data::*;
1312
use arc_swap::ArcSwapWeak;
13+
use fnv::FnvHashSet;
1414
use std::borrow::Borrow;
1515
use std::ops::Deref;
1616
use std::sync::atomic::{AtomicUsize, Ordering};
@@ -25,7 +25,7 @@ pub enum Type {
2525
indexes: Vec<Option<Arc<NamedEntity>>>,
2626
elem_type: TypeEnt,
2727
},
28-
Enum(ImplicitMap),
28+
Enum(ImplicitVec, FnvHashSet<Designator>),
2929
Integer(ImplicitVec),
3030
Physical(ImplicitVec),
3131
Access(Subtype, ImplicitVec),
@@ -44,12 +44,12 @@ pub enum Type {
4444
impl Type {
4545
pub fn implicit_declarations(&self) -> impl Iterator<Item = Arc<NamedEntity>> + '_ {
4646
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())),
47+
Type::Array { ref implicit, .. } => Some(implicit.iter()),
48+
Type::Enum(ref implicit, _) => Some(implicit.iter()),
49+
Type::Integer(ref implicit) => Some(implicit.iter()),
50+
Type::Physical(ref implicit) => Some(implicit.iter()),
51+
Type::File(ref implicit) => Some(implicit.iter()),
52+
Type::Access(.., ref implicit) => Some(implicit.iter()),
5353
Type::Incomplete(..)
5454
| Type::Interface
5555
| Type::Protected(..)

vhdl_lang/src/analysis/semantic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,8 +1023,8 @@ impl<'a> AnalyzeContext<'a> {
10231023
}
10241024
}
10251025
Literal::Character(char) => match target_base.kind() {
1026-
Type::Enum(literals) => {
1027-
if !literals.contains_key(&Designator::Character(*char)) {
1026+
Type::Enum(_, literals) => {
1027+
if !literals.contains(&Designator::Character(*char)) {
10281028
diagnostics.push(Diagnostic::error(
10291029
pos,
10301030
format!(
@@ -1050,10 +1050,10 @@ impl<'a> AnalyzeContext<'a> {
10501050
} => {
10511051
if indexes.len() == 1 {
10521052
match elem_type.base_type().kind() {
1053-
Type::Enum(literals) => {
1053+
Type::Enum(_, literals) => {
10541054
for chr in string_lit.chars() {
10551055
let chr = Designator::Character(*chr);
1056-
if !literals.contains_key(&chr) {
1056+
if !literals.contains(&chr) {
10571057
diagnostics.push(Diagnostic::error(
10581058
pos,
10591059
format!(

vhdl_lang/src/analysis/tests/implicit.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,22 @@ end package;
115115
);
116116
}
117117

118+
#[test]
119+
fn enum_implicit_function_is_added_on_use() {
120+
check_code_with_no_diagnostics(
121+
"
122+
package pkg1 is
123+
type enum_t is (alpha, beta);
124+
end package;
125+
126+
use work.pkg1.enum_t;
127+
package pkg is
128+
alias my_to_string is to_string[enum_t return string];
129+
end package;
130+
",
131+
);
132+
}
133+
118134
#[test]
119135
fn find_all_references_does_not_include_implicits() {
120136
let mut builder = LibraryBuilder::new();

0 commit comments

Comments
 (0)