Skip to content

Commit

Permalink
More Refactor disconnect, package body and package declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris44442 committed Jun 4, 2024
1 parent 7416d11 commit 9cb1790
Show file tree
Hide file tree
Showing 11 changed files with 257 additions and 205 deletions.
24 changes: 23 additions & 1 deletion vhdl_lang/src/analysis/declarative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,12 +626,33 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
Declaration::Configuration(..) => {}
Declaration::Disconnection(ref mut disc) => {
let DisconnectionSpecification {
ident: _,
ident,
subtype_indication,
expression,
} = disc;
self.expr_with_ttyp(scope, self.time(), expression, diagnostics)?;
self.analyze_subtype_indication(scope, subtype_indication, diagnostics)?;

let subtype = as_fatal(self.resolve_subtype_indication(
scope,
subtype_indication,
diagnostics,
));
if let Ok(Some(subtype)) = subtype {
if let GuardedSignalList::Ident(ref mut ident) = ident {
scope.add(
self.arena.define(
self.ctx,
ident,
parent,
AnyEntKind::Disconnection(subtype),
src_span,
Some(self.source()),
),
diagnostics,
);
}
}
}
Declaration::View(view) => {
if let Some(view) = as_fatal(self.analyze_view_declaration(
Expand Down Expand Up @@ -1210,6 +1231,7 @@ fn get_entity_class(ent: EntRef) -> Option<EntityClass> {
Design::Context(_) => None,
},
AnyEntKind::View(_) => None,
AnyEntKind::Disconnection(_) => None,
}
}

Expand Down
2 changes: 2 additions & 0 deletions vhdl_lang/src/analysis/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ impl<'a> ResolvedName<'a> {
}),
AnyEntKind::Type(_) => ResolvedName::Type(TypeEnt::from_any(ent).unwrap()),
AnyEntKind::View(_) => ResolvedName::Final(ent),
AnyEntKind::Disconnection(_) => ResolvedName::Final(ent),
AnyEntKind::Overloaded(_) => {
return Err((
"Internal error. Unreachable as overloaded is handled outside".to_owned(),
Expand Down Expand Up @@ -258,6 +259,7 @@ impl<'a> ResolvedName<'a> {
}
AnyEntKind::File(_)
| AnyEntKind::View(_)
| AnyEntKind::Disconnection(_)
| AnyEntKind::InterfaceFile(_)
| AnyEntKind::Component(_)
| AnyEntKind::Concurrent(_)
Expand Down
3 changes: 3 additions & 0 deletions vhdl_lang/src/analysis/package_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
}
},
AnyEntKind::View(typ) => AnyEntKind::View(self.map_subtype(mapping, *typ)),
AnyEntKind::Disconnection(typ) => {
AnyEntKind::Disconnection(self.map_subtype(mapping, *typ))
}
})
}

Expand Down
21 changes: 14 additions & 7 deletions vhdl_lang/src/analysis/tests/declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2023, Olof Kraigher [email protected]
use crate::analysis::tests::{check_diagnostics, LibraryBuilder};
use crate::analysis::tests::{check_diagnostics, check_no_diagnostics, LibraryBuilder};
use crate::data::error_codes::ErrorCode;
use crate::Diagnostic;

Expand Down Expand Up @@ -116,7 +116,7 @@ begin
end arch;
",
);
check_diagnostics(builder.analyze(), vec![])
check_no_diagnostics(&builder.analyze())
}

#[test]
Expand Down Expand Up @@ -186,10 +186,17 @@ end arch;
);
check_diagnostics(
builder.analyze(),
vec![Diagnostic::new(
code.s1("bar"),
"No declaration of 'bar'",
ErrorCode::Unresolved,
)],
vec![
Diagnostic::new(
code.s1("bar"),
"No declaration of 'bar'",
ErrorCode::Unresolved,
),
Diagnostic::new(
code.s1("bar"),
"No declaration of 'bar'",
ErrorCode::Unresolved,
),
],
)
}
2 changes: 1 addition & 1 deletion vhdl_lang/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ pub struct ConfigurationSpecification {
pub enum GuardedSignalList {
All,
Others,
Ident(WithDecl<Ident>)
Ident(WithDecl<Ident>),
}

/// LRM 7.4 Disconnection specification
Expand Down
6 changes: 1 addition & 5 deletions vhdl_lang/src/ast/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,11 +1142,7 @@ impl Display for ConfigurationDeclaration {

impl Display for DisconnectionSpecification {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
if let Some(ident) = &self.ident {
write!(f, "disconnection {}", ident)
} else {
write!(f, "disconnection")
}
write!(f, "disconnection")
}
}

Expand Down
14 changes: 13 additions & 1 deletion vhdl_lang/src/ast/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub enum FoundDeclaration<'a> {
ConcurrentStatement(&'a LabeledConcurrentStatement),
SequentialStatement(&'a LabeledSequentialStatement),
View(&'a ModeViewDeclaration),
GuardedSignalListWithIdent(&'a WithDecl<Ident>),
}

pub trait Searcher {
Expand Down Expand Up @@ -1089,13 +1090,19 @@ impl Search for Declaration {
}
Declaration::Disconnection(disconnect) => {
let DisconnectionSpecification {
ident: _,
ident,
subtype_indication,
expression,
} = disconnect;
if let GuardedSignalList::Ident(ident) = ident {
return_if_found!(searcher
.search_decl(ctx, FoundDeclaration::GuardedSignalListWithIdent(ident))
.or_not_found());
}
return_if_found!(subtype_indication.search(ctx, searcher));
return_if_found!(expression.search(ctx, searcher));
}

Declaration::View(view) => {
return_if_found!(searcher
.search_decl(ctx, FoundDeclaration::View(view))
Expand Down Expand Up @@ -1710,6 +1717,7 @@ impl<'a> FoundDeclaration<'a> {
FoundDeclaration::SequentialStatement(..) => None,
FoundDeclaration::SubprogramInstantiation(_) => None,
FoundDeclaration::View(view) => view.end_ident_pos,
FoundDeclaration::GuardedSignalListWithIdent(..) => None,
}
}

Expand Down Expand Up @@ -1745,6 +1753,7 @@ impl<'a> FoundDeclaration<'a> {
FoundDeclaration::ConcurrentStatement(value) => &value.label.decl,
FoundDeclaration::SequentialStatement(value) => &value.label.decl,
FoundDeclaration::View(value) => &value.ident.decl,
FoundDeclaration::GuardedSignalListWithIdent(value) => &value.decl,
}
}
}
Expand Down Expand Up @@ -1852,6 +1861,9 @@ impl std::fmt::Display for FoundDeclaration<'_> {
FoundDeclaration::GenerateBody(value) => {
write!(f, "{value}")
}
FoundDeclaration::GuardedSignalListWithIdent(value) => {
write!(f, "{value}")
}
FoundDeclaration::ConcurrentStatement(value) => {
if let Some(ref label) = value.label.tree {
write!(f, "{label}")
Expand Down
15 changes: 10 additions & 5 deletions vhdl_lang/src/named_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use crate::ast::{
AliasDeclaration, AnyDesignUnit, AnyPrimaryUnit, AnySecondaryUnit, Attribute,
AttributeDeclaration, AttributeSpecification, ComponentDeclaration, Declaration, Designator,
DisconnectionSpecification, FileDeclaration, HasIdent, Ident, InterfaceFileDeclaration,
InterfacePackageDeclaration, ModeViewDeclaration, ObjectClass, ObjectDeclaration, PackageBody,
PackageDeclaration, PackageInstantiation, SubprogramBody, SubprogramInstantiation,
SubprogramSpecification, TypeDeclaration, WithDecl,
DisconnectionSpecification, FileDeclaration, GuardedSignalList, HasIdent, Ident,
InterfaceFileDeclaration, InterfacePackageDeclaration, ModeViewDeclaration, ObjectClass,
ObjectDeclaration, PackageBody, PackageDeclaration, PackageInstantiation, SubprogramBody,
SubprogramInstantiation, SubprogramSpecification, TypeDeclaration, WithDecl,
};
use crate::ast::{ExternalObjectClass, InterfaceDeclaration, InterfaceObjectDeclaration};
use crate::data::*;
Expand Down Expand Up @@ -66,6 +66,7 @@ pub enum AnyEntKind<'a> {
Library,
Design(Design<'a>),
View(Subtype<'a>),
Disconnection(Subtype<'a>),
}

impl<'a> AnyEntKind<'a> {
Expand Down Expand Up @@ -129,6 +130,7 @@ impl<'a> AnyEntKind<'a> {
Design(design) => design.describe(),
Type(typ) => typ.describe(),
View(..) => "view",
Disconnection(..) => "disconnection",
}
}
}
Expand Down Expand Up @@ -662,7 +664,10 @@ impl HasEntityId for PackageDeclaration {

impl HasEntityId for DisconnectionSpecification {
fn ent_id(&self) -> Option<EntityId> {
self.ident.as_ref().and_then(|ident| ident.decl.get())
match &self.ident {
GuardedSignalList::Ident(with_decl) => with_decl.decl.get(),
_ => None,
}
}
}

Expand Down
12 changes: 9 additions & 3 deletions vhdl_lang/src/syntax/declarative_part.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,15 @@ pub fn parse_declarative_part(
}

Disconnect => {
match parse_disconnection_specification(ctx).or_recover_until(ctx, is_recover_token)
{
Ok(decl) => declarations.push(decl.map_into(Declaration::Disconnection)),
let decls: ParseResult<Vec<WithTokenSpan<Declaration>>> =
parse_disconnection_specification(ctx).map(|decls| {
decls
.into_iter()
.map(|decl| decl.map_into(Declaration::Disconnection))
.collect()
});
match decls.or_recover_until(ctx, is_recover_token) {
Ok(ref mut decls) => declarations.append(decls),
Err(err) => {
ctx.diagnostics.push(err);
continue;
Expand Down
Loading

0 comments on commit 9cb1790

Please sign in to comment.