Skip to content

Commit 95586ab

Browse files
committed
More Refactor disconnect, package body and package declaration
1 parent 7416d11 commit 95586ab

File tree

10 files changed

+244
-204
lines changed

10 files changed

+244
-204
lines changed

vhdl_lang/src/analysis/declarative.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,12 +626,33 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
626626
Declaration::Configuration(..) => {}
627627
Declaration::Disconnection(ref mut disc) => {
628628
let DisconnectionSpecification {
629-
ident: _,
629+
ident,
630630
subtype_indication,
631631
expression,
632632
} = disc;
633633
self.expr_with_ttyp(scope, self.time(), expression, diagnostics)?;
634634
self.analyze_subtype_indication(scope, subtype_indication, diagnostics)?;
635+
636+
let subtype = as_fatal(self.resolve_subtype_indication(
637+
scope,
638+
subtype_indication,
639+
diagnostics,
640+
));
641+
if let Ok(Some(subtype)) = subtype {
642+
if let GuardedSignalList::Ident(ref mut ident) = ident {
643+
scope.add(
644+
self.arena.define(
645+
self.ctx,
646+
ident,
647+
parent,
648+
AnyEntKind::Disconnection(subtype),
649+
src_span,
650+
Some(self.source()),
651+
),
652+
diagnostics,
653+
);
654+
}
655+
}
635656
}
636657
Declaration::View(view) => {
637658
if let Some(view) = as_fatal(self.analyze_view_declaration(
@@ -1210,6 +1231,7 @@ fn get_entity_class(ent: EntRef) -> Option<EntityClass> {
12101231
Design::Context(_) => None,
12111232
},
12121233
AnyEntKind::View(_) => None,
1234+
AnyEntKind::Disconnection(_) => None,
12131235
}
12141236
}
12151237

vhdl_lang/src/analysis/names.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ impl<'a> ResolvedName<'a> {
188188
}),
189189
AnyEntKind::Type(_) => ResolvedName::Type(TypeEnt::from_any(ent).unwrap()),
190190
AnyEntKind::View(_) => ResolvedName::Final(ent),
191+
AnyEntKind::Disconnection(_) => ResolvedName::Final(ent),
191192
AnyEntKind::Overloaded(_) => {
192193
return Err((
193194
"Internal error. Unreachable as overloaded is handled outside".to_owned(),
@@ -258,6 +259,7 @@ impl<'a> ResolvedName<'a> {
258259
}
259260
AnyEntKind::File(_)
260261
| AnyEntKind::View(_)
262+
| AnyEntKind::Disconnection(_)
261263
| AnyEntKind::InterfaceFile(_)
262264
| AnyEntKind::Component(_)
263265
| AnyEntKind::Concurrent(_)

vhdl_lang/src/analysis/package_instance.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,9 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
386386
}
387387
},
388388
AnyEntKind::View(typ) => AnyEntKind::View(self.map_subtype(mapping, *typ)),
389+
AnyEntKind::Disconnection(typ) => {
390+
AnyEntKind::Disconnection(self.map_subtype(mapping, *typ))
391+
}
389392
})
390393
}
391394

vhdl_lang/src/analysis/tests/declarations.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// You can obtain one at http://mozilla.org/MPL/2.0/.
44
//
55
// Copyright (c) 2023, Olof Kraigher [email protected]
6-
use crate::analysis::tests::{check_diagnostics, LibraryBuilder};
6+
use crate::analysis::tests::{check_diagnostics, check_no_diagnostics, LibraryBuilder};
77
use crate::data::error_codes::ErrorCode;
88
use crate::Diagnostic;
99

@@ -116,7 +116,7 @@ begin
116116
end arch;
117117
",
118118
);
119-
check_diagnostics(builder.analyze(), vec![])
119+
check_no_diagnostics(&builder.analyze())
120120
}
121121

122122
#[test]
@@ -186,10 +186,17 @@ end arch;
186186
);
187187
check_diagnostics(
188188
builder.analyze(),
189-
vec![Diagnostic::new(
190-
code.s1("bar"),
191-
"No declaration of 'bar'",
192-
ErrorCode::Unresolved,
193-
)],
189+
vec![
190+
Diagnostic::new(
191+
code.s1("bar"),
192+
"No declaration of 'bar'",
193+
ErrorCode::Unresolved,
194+
),
195+
Diagnostic::new(
196+
code.s1("bar"),
197+
"No declaration of 'bar'",
198+
ErrorCode::Unresolved,
199+
),
200+
],
194201
)
195202
}

vhdl_lang/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ pub struct ConfigurationSpecification {
13831383
pub enum GuardedSignalList {
13841384
All,
13851385
Others,
1386-
Ident(WithDecl<Ident>)
1386+
Ident(WithDecl<Ident>),
13871387
}
13881388

13891389
/// LRM 7.4 Disconnection specification

vhdl_lang/src/ast/display.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,11 +1142,7 @@ impl Display for ConfigurationDeclaration {
11421142

11431143
impl Display for DisconnectionSpecification {
11441144
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
1145-
if let Some(ident) = &self.ident {
1146-
write!(f, "disconnection {}", ident)
1147-
} else {
1148-
write!(f, "disconnection")
1149-
}
1145+
write!(f, "disconnection")
11501146
}
11511147
}
11521148

vhdl_lang/src/named_entity.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
use crate::ast::{
88
AliasDeclaration, AnyDesignUnit, AnyPrimaryUnit, AnySecondaryUnit, Attribute,
99
AttributeDeclaration, AttributeSpecification, ComponentDeclaration, Declaration, Designator,
10-
DisconnectionSpecification, FileDeclaration, HasIdent, Ident, InterfaceFileDeclaration,
11-
InterfacePackageDeclaration, ModeViewDeclaration, ObjectClass, ObjectDeclaration, PackageBody,
12-
PackageDeclaration, PackageInstantiation, SubprogramBody, SubprogramInstantiation,
13-
SubprogramSpecification, TypeDeclaration, WithDecl,
10+
DisconnectionSpecification, FileDeclaration, GuardedSignalList, HasIdent, Ident,
11+
InterfaceFileDeclaration, InterfacePackageDeclaration, ModeViewDeclaration, ObjectClass,
12+
ObjectDeclaration, PackageBody, PackageDeclaration, PackageInstantiation, SubprogramBody,
13+
SubprogramInstantiation, SubprogramSpecification, TypeDeclaration, WithDecl,
1414
};
1515
use crate::ast::{ExternalObjectClass, InterfaceDeclaration, InterfaceObjectDeclaration};
1616
use crate::data::*;
@@ -66,6 +66,7 @@ pub enum AnyEntKind<'a> {
6666
Library,
6767
Design(Design<'a>),
6868
View(Subtype<'a>),
69+
Disconnection(Subtype<'a>),
6970
}
7071

7172
impl<'a> AnyEntKind<'a> {
@@ -129,6 +130,7 @@ impl<'a> AnyEntKind<'a> {
129130
Design(design) => design.describe(),
130131
Type(typ) => typ.describe(),
131132
View(..) => "view",
133+
Disconnection(..) => "disconnection",
132134
}
133135
}
134136
}
@@ -662,7 +664,10 @@ impl HasEntityId for PackageDeclaration {
662664

663665
impl HasEntityId for DisconnectionSpecification {
664666
fn ent_id(&self) -> Option<EntityId> {
665-
self.ident.as_ref().and_then(|ident| ident.decl.get())
667+
match &self.ident {
668+
GuardedSignalList::Ident(with_decl) => with_decl.decl.get(),
669+
_ => None,
670+
}
666671
}
667672
}
668673

vhdl_lang/src/syntax/declarative_part.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,15 @@ pub fn parse_declarative_part(
190190
}
191191

192192
Disconnect => {
193-
match parse_disconnection_specification(ctx).or_recover_until(ctx, is_recover_token)
194-
{
195-
Ok(decl) => declarations.push(decl.map_into(Declaration::Disconnection)),
193+
let decls: ParseResult<Vec<WithTokenSpan<Declaration>>> =
194+
parse_disconnection_specification(ctx).map(|decls| {
195+
decls
196+
.into_iter()
197+
.map(|decl| decl.map_into(Declaration::Disconnection))
198+
.collect()
199+
});
200+
match decls.or_recover_until(ctx, is_recover_token) {
201+
Ok(ref mut decls) => declarations.append(decls),
196202
Err(err) => {
197203
ctx.diagnostics.push(err);
198204
continue;

0 commit comments

Comments
 (0)