Skip to content

Commit

Permalink
Add disconnect specification
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris44442 committed May 31, 2024
1 parent 1ab2839 commit 10cbd3d
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 1 deletion.
6 changes: 5 additions & 1 deletion vhdl_lang/src/analysis/declarative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl Declaration {
| PackageDeclaration(_)
| PackageBody(_)
| Configuration(_)
| Disconnection(_)
| View(_)
),
// LRM: configuration_declarative_item
Expand All @@ -65,6 +66,7 @@ impl Declaration {
| Package(_)
| PackageDeclaration(_)
| PackageBody(_)
| Disconnection(_)
| View(_)
),
// LRM: package_body_declarative_item
Expand All @@ -76,6 +78,7 @@ impl Declaration {
| Overloaded::UninstSubprogram(..),
)
| AnyEntKind::Concurrent(Some(Concurrent::Process))
// LRM protected type body declarative item
| AnyEntKind::Type(named_entity::Type::Protected(..)) => matches!(
self,
Object(ObjectDeclaration {
Expand Down Expand Up @@ -107,7 +110,7 @@ impl Declaration {
| Use(_)
| Package(_)
| PackageDeclaration(_)
| PackageBody(_)
| Disconnection(_)
| View(_)
),
_ => {
Expand Down Expand Up @@ -621,6 +624,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
self.analyze_package_body(unit, diagnostics)?;
}
Declaration::Configuration(..) => {}
Declaration::Disconnection(..) => {} // @TODO
Declaration::View(view) => {
if let Some(view) = as_fatal(self.analyze_view_declaration(
scope,
Expand Down
1 change: 1 addition & 0 deletions vhdl_lang/src/analysis/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,7 @@ impl Declaration {
Declaration::PackageDeclaration(_) => "package",
Declaration::PackageBody(_) => "package body",
Declaration::Configuration(_) => "configuration",
Declaration::Disconnection(_) => "disconnection",
Declaration::View(_) => "view",
}
}
Expand Down
5 changes: 5 additions & 0 deletions vhdl_lang/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ pub enum Declaration {
PackageDeclaration(PackageDeclaration),
PackageBody(PackageBody),
Configuration(ConfigurationSpecification),
Disconnection(DisconnectionSpecification),
View(ModeViewDeclaration),
}

Expand Down Expand Up @@ -1377,6 +1378,10 @@ pub struct ConfigurationSpecification {
pub vunit_bind_inds: Vec<VUnitBindingIndication>,
}

/// LRM 7.4 Disconnection specification
#[derive(PartialEq, Debug, Clone)]
pub struct DisconnectionSpecification {}

/// LRM 3.4 Configuration declarations
#[derive(PartialEq, Debug, Clone)]
pub enum ConfigurationDeclarativeItem {
Expand Down
3 changes: 3 additions & 0 deletions vhdl_lang/src/ast/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,9 @@ impl Search for Declaration {
Declaration::Configuration(_) => {
// @TODO
}
Declaration::Disconnection(_) => {
// @TODO
}
Declaration::View(view) => {
return_if_found!(searcher
.search_decl(ctx, FoundDeclaration::View(view))
Expand Down
1 change: 1 addition & 0 deletions vhdl_lang/src/named_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ impl HasEntityId for Declaration {
Declaration::PackageBody(pkg) => pkg.ent_id(),
Declaration::Use(_) => None,
Declaration::Configuration(_) => None,
Declaration::Disconnection(_) => None, // TODO
Declaration::View(decl) => decl.ent_id(),
}
}
Expand Down
1 change: 1 addition & 0 deletions vhdl_lang/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod configuration;
mod context;
mod declarative_part;
mod design_unit;
mod disconnection;
mod expression;
mod interface_declaration;
mod names;
Expand Down
26 changes: 26 additions & 0 deletions vhdl_lang/src/syntax/declarative_part.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use super::type_declaration::parse_type_declaration;
use crate::ast::token_range::WithTokenSpan;
use crate::ast::{ContextClause, Declaration, PackageInstantiation};
use crate::syntax::concurrent_statement::parse_map_aspect;
use crate::syntax::disconnection::parse_disconnection_specification;
use crate::syntax::view::parse_mode_view_declaration;
use vhdl_lang::syntax::parser::ParsingContext;

Expand Down Expand Up @@ -63,6 +64,7 @@ pub fn is_declarative_part(ctx: &mut ParsingContext) -> ParseResult<bool> {
| For
| View
| Begin
| Disconnect
))
}

Expand Down Expand Up @@ -93,6 +95,7 @@ pub fn parse_declarative_part(
| Alias
| Begin
| End
| Disconnect
)
}

Expand Down Expand Up @@ -186,6 +189,17 @@ 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)),
Err(err) => {
ctx.diagnostics.push(err);
continue;
}
}
}

_ => {
use crate::VHDLStandard::*;
let expected: &[Kind] = match ctx.standard {
Expand Down Expand Up @@ -341,4 +355,16 @@ var not_a_var: broken;
)],
)
}

#[test]
fn parse_declarative_part_with_disconnection() {
let code = Code::new(
"\
constant foo: real := 5.1;
disconnect my_signal : integer after 42 ms;
signal bar: std_logic;
",
);
code.with_stream_no_diagnostics(parse_declarative_part);
}
}
95 changes: 95 additions & 0 deletions vhdl_lang/src/syntax/disconnection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2018, Olof Kraigher [email protected]

use super::common::ParseResult;
use super::expression::parse_expression;
use super::names::parse_name;
use super::separated_list::parse_ident_list;
use super::tokens::{Kind::*, TokenSpan};
use crate::ast::token_range::WithTokenSpan;
use crate::ast::*;
use vhdl_lang::syntax::parser::ParsingContext;

/// LRM 7.4 Disconnection Specification
pub fn parse_disconnection_specification(
ctx: &mut ParsingContext<'_>,
) -> ParseResult<WithTokenSpan<DisconnectionSpecification>> {
let start_token = ctx.stream.expect_kind(Disconnect)?;
if ctx.stream.next_kind_is(Identifier) {
let _ = parse_ident_list(ctx);
} else if ctx.stream.next_kind_is(All) {
ctx.stream.expect_kind(All)?;
} else {
ctx.stream.expect_kind(Others)?;
}
ctx.stream.expect_kind(Colon)?;
let _ = parse_name(ctx);
ctx.stream.expect_kind(After)?;
let _ = parse_expression(ctx);
let end_token = ctx.stream.expect_kind(SemiColon)?;
Ok(WithTokenSpan::new(
DisconnectionSpecification {},
TokenSpan::new(start_token, end_token),
))
}

#[cfg(test)]
mod tests {
use super::*;
use crate::syntax::test::Code;

#[test]
fn disconnect_spec_with_scalar_or_composite_signal() {
let code = Code::new(
"\
disconnect S: T after 42 ms;
",
);
assert_eq!(
code.with_stream_no_diagnostics(parse_disconnection_specification),
WithTokenSpan::new(DisconnectionSpecification {}, code.token_span())
);
}

#[test]
fn disconnect_spec_with_scalar_or_composite_signal_variant() {
let code = Code::new(
"\
disconnect foo, bar, foobar : unsigned(3 downto 0) after CLK_PERIOD;
",
);
assert_eq!(
code.with_stream_no_diagnostics(parse_disconnection_specification),
WithTokenSpan::new(DisconnectionSpecification {}, code.token_span())
);
}

#[test]
fn disconnect_spec_explicit_with_others() {
let code = Code::new(
"\
disconnect others: std_logic after 42 ms;
",
);
assert_eq!(
code.with_stream_no_diagnostics(parse_disconnection_specification),
WithTokenSpan::new(DisconnectionSpecification {}, code.token_span())
);
}

#[test]
fn disconnect_spec_explicit_with_all() {
let code = Code::new(
"\
disconnect all : T after 42 ms;
",
);
assert_eq!(
code.with_stream_no_diagnostics(parse_disconnection_specification),
WithTokenSpan::new(DisconnectionSpecification {}, code.token_span())
);
}
}

0 comments on commit 10cbd3d

Please sign in to comment.