Skip to content

Commit cded313

Browse files
committed
Elaborate overloaded kind.
1 parent 8b19b79 commit cded313

File tree

5 files changed

+64
-33
lines changed

5 files changed

+64
-33
lines changed

vhdl_lang/src/analysis/declarative.rs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,17 @@ impl<'a> AnalyzeContext<'a> {
121121
}
122122

123123
let kind = {
124-
if signature.is_some() {
125-
NamedEntityKind::Overloaded
126-
} else if subtype_indication.is_some() {
124+
if subtype_indication.is_some() {
127125
NamedEntityKind::OtherAlias
128126
} else {
129-
let named_entity =
130-
resolved_name.and_then(|resolved| resolved.into_non_overloaded());
127+
let named_entity = if signature.is_some() {
128+
// @TODO use signature to select named entity
129+
resolved_name
130+
.and_then(|resolved| resolved.into_known())
131+
.map(|entities| entities.first().clone())
132+
} else {
133+
resolved_name.and_then(|resolved| resolved.into_non_overloaded())
134+
};
131135

132136
if let Some(named_entity) = named_entity {
133137
region.add_implicit_declaration_aliases(
@@ -195,7 +199,10 @@ impl<'a> AnalyzeContext<'a> {
195199
Declaration::SubprogramBody(ref mut body) => {
196200
region.add(
197201
body.specification.designator(),
198-
NamedEntityKind::Overloaded,
202+
match body.specification {
203+
SubprogramDeclaration::Procedure(..) => NamedEntityKind::Procedure,
204+
SubprogramDeclaration::Function(..) => NamedEntityKind::Function,
205+
},
199206
diagnostics,
200207
);
201208
let mut subpgm_region = region.nested();
@@ -220,7 +227,10 @@ impl<'a> AnalyzeContext<'a> {
220227
Declaration::SubprogramDeclaration(ref mut subdecl) => {
221228
region.add(
222229
subdecl.designator(),
223-
NamedEntityKind::Overloaded,
230+
match subdecl {
231+
SubprogramDeclaration::Procedure(..) => NamedEntityKind::Procedure,
232+
SubprogramDeclaration::Function(..) => NamedEntityKind::Function,
233+
},
224234
diagnostics,
225235
);
226236

@@ -266,7 +276,7 @@ impl<'a> AnalyzeContext<'a> {
266276
for literal in enumeration.iter() {
267277
let literal_ent = NamedEntity::new(
268278
literal.item.clone().into_designator(),
269-
NamedEntityKind::Overloaded,
279+
NamedEntityKind::EnumLiteral,
270280
Some(&literal.pos),
271281
);
272282
let literal_ent = Arc::new(literal_ent);
@@ -341,7 +351,14 @@ impl<'a> AnalyzeContext<'a> {
341351
ProtectedTypeDeclarativeItem::Subprogram(ref mut subprogram) => {
342352
region.add(
343353
subprogram.designator(),
344-
NamedEntityKind::Overloaded,
354+
match subprogram {
355+
SubprogramDeclaration::Procedure(..) => {
356+
NamedEntityKind::Procedure
357+
}
358+
SubprogramDeclaration::Function(..) => {
359+
NamedEntityKind::Function
360+
}
361+
},
345362
diagnostics,
346363
);
347364
let mut subpgm_region = region.nested();
@@ -467,7 +484,7 @@ impl<'a> AnalyzeContext<'a> {
467484
for name in names.iter() {
468485
let ent = NamedEntity::new(
469486
Designator::Identifier(self.symbol_utf8(name)),
470-
NamedEntityKind::Overloaded,
487+
NamedEntityKind::Procedure,
471488
None,
472489
);
473490
implicit.push(Arc::new(ent));
@@ -565,7 +582,10 @@ impl<'a> AnalyzeContext<'a> {
565582
subpgm_region.close(diagnostics);
566583
region.add(
567584
subpgm.designator(),
568-
NamedEntityKind::Overloaded,
585+
match subpgm {
586+
SubprogramDeclaration::Procedure(..) => NamedEntityKind::Procedure,
587+
SubprogramDeclaration::Function(..) => NamedEntityKind::Function,
588+
},
569589
diagnostics,
570590
);
571591
}

vhdl_lang/src/analysis/named_entity.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ pub enum NamedEntityKind {
1818
RecordField,
1919
Component,
2020
Attribute,
21-
Overloaded,
21+
Function,
22+
Procedure,
23+
EnumLiteral,
2224
// An optional list of implicit declarations
2325
TypeDeclaration(Vec<Arc<NamedEntity>>),
2426
Subtype(Subtype),
@@ -74,6 +76,17 @@ impl NamedEntityKind {
7476
}
7577
}
7678

79+
pub fn is_type(&self) -> bool {
80+
match self {
81+
NamedEntityKind::IncompleteType
82+
| NamedEntityKind::ProtectedType(..)
83+
| NamedEntityKind::InterfaceType
84+
| NamedEntityKind::Subtype(..)
85+
| NamedEntityKind::TypeDeclaration(..) => true,
86+
_ => false,
87+
}
88+
}
89+
7790
pub fn describe(&self) -> &str {
7891
use NamedEntityKind::*;
7992
match self {
@@ -84,7 +97,9 @@ impl NamedEntityKind {
8497
RecordField => "file",
8598
Component => "file",
8699
Attribute => "file",
87-
Overloaded => "file",
100+
Procedure => "procedure",
101+
Function => "function",
102+
EnumLiteral => "enum literal",
88103
TypeDeclaration(..) => "type",
89104
Subtype(..) => "subtype",
90105
IncompleteType => "type",
@@ -123,6 +138,7 @@ pub struct Subtype {
123138

124139
impl Subtype {
125140
pub fn new(base: Arc<NamedEntity>) -> Subtype {
141+
debug_assert!(base.actual_kind().is_type());
126142
Subtype { base }
127143
}
128144
}
@@ -201,10 +217,11 @@ impl NamedEntity {
201217
}
202218

203219
pub fn is_overloaded(&self) -> bool {
204-
if let NamedEntityKind::Overloaded = self.as_actual().kind {
205-
true
206-
} else {
207-
false
220+
match self.actual_kind() {
221+
NamedEntityKind::Procedure
222+
| NamedEntityKind::Function
223+
| NamedEntityKind::EnumLiteral => true,
224+
_ => false,
208225
}
209226
}
210227

@@ -216,6 +233,11 @@ impl NamedEntity {
216233
}
217234
}
218235

236+
/// Strip aliases and return reference to actual entity kind
237+
pub fn actual_kind(&self) -> &NamedEntityKind {
238+
self.as_actual().kind()
239+
}
240+
219241
/// Returns true if self is alias of other
220242
pub fn is_alias_of(&self, other: &NamedEntity) -> bool {
221243
match self.kind() {

vhdl_lang/src/analysis/region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl<'a> Region<'a> {
315315
ent: &NamedEntity,
316316
diagnostics: &mut dyn DiagnosticHandler,
317317
) {
318-
if let NamedEntityKind::TypeDeclaration(ref implicit) = ent.as_actual().kind() {
318+
if let NamedEntityKind::TypeDeclaration(ref implicit) = ent.actual_kind() {
319319
for entity in implicit.iter() {
320320
let entity = NamedEntity::new(
321321
entity.designator().clone(),

vhdl_lang/src/analysis/semantic.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub enum ResolvedName {
2020
}
2121

2222
impl ResolvedName {
23-
fn into_known(self) -> Option<NamedEntities> {
23+
pub fn into_known(self) -> Option<NamedEntities> {
2424
if let Self::Known(visible) = self {
2525
Some(visible)
2626
} else {
@@ -208,7 +208,7 @@ impl<'a> AnalyzeContext<'a> {
208208
.into_non_overloaded()
209209
{
210210
Ok(ent) => {
211-
if kind_ok(ent.as_actual().kind()) {
211+
if kind_ok(ent.actual_kind()) {
212212
Ok(ent)
213213
} else {
214214
let mut error = Diagnostic::error(
@@ -241,18 +241,7 @@ impl<'a> AnalyzeContext<'a> {
241241
region: &Region<'_>,
242242
type_mark: &mut WithPos<SelectedName>,
243243
) -> AnalysisResult<Arc<NamedEntity>> {
244-
fn is_type(kind: &NamedEntityKind) -> bool {
245-
match kind {
246-
NamedEntityKind::IncompleteType
247-
| NamedEntityKind::ProtectedType(..)
248-
| NamedEntityKind::InterfaceType
249-
| NamedEntityKind::Subtype(..)
250-
| NamedEntityKind::TypeDeclaration(..) => true,
251-
_ => false,
252-
}
253-
}
254-
255-
self.resolve_non_overloaded(region, type_mark, &is_type, "type")
244+
self.resolve_non_overloaded(region, type_mark, &NamedEntityKind::is_type, "type")
256245
}
257246

258247
fn analyze_attribute_name(

vhdl_lang/src/analysis/visibility.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ 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 NamedEntityKind::TypeDeclaration(ref implicit) = ent.as_actual().kind() {
93+
if let NamedEntityKind::TypeDeclaration(ref implicit) = ent.actual_kind() {
9494
// Add implicitic declarations when using type
9595
for entity in implicit.iter() {
9696
self.make_potentially_visible_with_name(

0 commit comments

Comments
 (0)