Skip to content

Commit

Permalink
Fix: discrete ranges can be used as choice statements (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
Schottkyc137 authored Dec 9, 2024
1 parent 5cf0e4c commit 7ed5e78
Show file tree
Hide file tree
Showing 40 changed files with 375 additions and 223 deletions.
6 changes: 3 additions & 3 deletions vhdl_lang/src/analysis/assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::ast::*;
use crate::data::*;
use crate::named_entity::*;

impl<'a, 't> AnalyzeContext<'a, 't> {
impl<'a> AnalyzeContext<'a, '_> {
// @TODO maybe make generic function for expression/waveform.
// wait until type checking to see if it makes sense
pub fn analyze_expr_assignment(
Expand Down Expand Up @@ -55,7 +55,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
} in alternatives.iter_mut()
{
self.analyze_expression_for_target(scope, ttyp, item, diagnostics)?;
self.choice_with_ttyp(scope, ctyp, choices, diagnostics)?;
self.choices_with_ttyp(scope, ctyp, choices, diagnostics)?;
}
}
}
Expand Down Expand Up @@ -105,7 +105,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
} in alternatives.iter_mut()
{
self.analyze_waveform(scope, ttyp, item, diagnostics)?;
self.choice_with_ttyp(scope, ctyp, choices, diagnostics)?;
self.choices_with_ttyp(scope, ctyp, choices, diagnostics)?;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion vhdl_lang/src/analysis/association.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<'a> ResolvedFormal<'a> {
}
}

impl<'a, 't> AnalyzeContext<'a, 't> {
impl<'a> AnalyzeContext<'a, '_> {
fn resolve_formal(
&self,
formal_region: &FormalRegion<'a>,
Expand Down
4 changes: 2 additions & 2 deletions vhdl_lang/src/analysis/concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::named_entity::*;
use crate::{HasTokenSpan, TokenSpan};
use analyze::*;

impl<'a, 't> AnalyzeContext<'a, 't> {
impl<'a> AnalyzeContext<'a, '_> {
pub fn analyze_concurrent_part(
&self,
scope: &Scope<'a>,
Expand Down Expand Up @@ -188,7 +188,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
ref mut item,
span: _,
} = alternative;
self.choice_with_ttyp(scope, ctyp, choices, diagnostics)?;
self.choices_with_ttyp(scope, ctyp, choices, diagnostics)?;
let nested = scope.nested();
self.analyze_generate_body(&nested, parent, item, src_span, diagnostics)?;
}
Expand Down
2 changes: 1 addition & 1 deletion vhdl_lang/src/analysis/declarative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl Declaration {
}
}

impl<'a, 't> AnalyzeContext<'a, 't> {
impl<'a> AnalyzeContext<'a, '_> {
pub fn analyze_declarative_part(
&self,
scope: &Scope<'a>,
Expand Down
2 changes: 1 addition & 1 deletion vhdl_lang/src/analysis/design_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::named_entity::*;
use crate::HasTokenSpan;
use analyze::*;

impl<'a, 't> AnalyzeContext<'a, 't> {
impl<'a> AnalyzeContext<'a, '_> {
pub fn analyze_primary_unit(
&self,
unit: &mut AnyPrimaryUnit,
Expand Down
48 changes: 22 additions & 26 deletions vhdl_lang/src/analysis/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub(super) struct TypeMatcher<'c, 'a, 't> {
context: &'c AnalyzeContext<'a, 't>,
}

impl<'c, 'a, 't> TypeMatcher<'c, 'a, 't> {
impl<'a> TypeMatcher<'_, 'a, '_> {
// Returns true if the expression types is possible given the target type
pub fn is_possible(&self, types: &ExpressionType<'a>, ttyp: BaseType<'a>) -> bool {
if types.match_type(ttyp) {
Expand Down Expand Up @@ -213,6 +213,22 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
self.any_matcher().can_be_target_type(typ, ttyp)
}

pub fn check_type_mismatch(
&self,
typ: TypeEnt<'a>,
ttyp: TypeEnt<'a>,
pos: TokenSpan,
diagnostics: &mut dyn DiagnosticHandler,
) {
if !self.can_be_target_type(typ, ttyp.base()) {
diagnostics.push(Diagnostic::type_mismatch(
&pos.pos(self.ctx),
&typ.describe(),
ttyp,
));
}
}

pub fn expr_unknown_ttyp(
&self,
scope: &Scope<'a>,
Expand Down Expand Up @@ -684,7 +700,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
"Ambiguous use of implicit boolean conversion ??",
ErrorCode::AmbiguousCall,
);
diag.add_type_candididates("Could be", implicit_bool_types);
diag.add_type_candidates("Could be", implicit_bool_types);
diagnostics.push(diag);
}

Expand All @@ -697,7 +713,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
),
ErrorCode::AmbiguousExpression,
);
diag.add_type_candididates(
diag.add_type_candidates(
"Implicit boolean conversion operator ?? is not defined for",
types,
);
Expand Down Expand Up @@ -741,13 +757,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
if let Some(type_mark) =
as_fatal(self.analyze_qualified_expression(scope, qexpr, diagnostics))?
{
if !self.can_be_target_type(type_mark, target_base.base()) {
diagnostics.push(Diagnostic::type_mismatch(
&span.pos(self.ctx),
&type_mark.describe(),
target_type,
));
}
self.check_type_mismatch(type_mark, target_type, span, diagnostics);
}
}
Expression::Binary(ref mut op, ref mut left, ref mut right) => {
Expand All @@ -772,14 +782,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
))? {
Some(Disambiguated::Unambiguous(overloaded)) => {
let op_type = overloaded.return_type().unwrap();

if !self.can_be_target_type(op_type, target_type.base()) {
diagnostics.push(Diagnostic::type_mismatch(
&span.pos(self.ctx),
&op_type.describe(),
target_type,
));
}
self.check_type_mismatch(op_type, target_type, span, diagnostics);
}
Some(Disambiguated::Ambiguous(candidates)) => {
diagnostics.push(Diagnostic::ambiguous_op(
Expand Down Expand Up @@ -815,14 +818,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
))? {
Some(Disambiguated::Unambiguous(overloaded)) => {
let op_type = overloaded.return_type().unwrap();

if !self.can_be_target_type(op_type, target_type.base()) {
diagnostics.push(Diagnostic::type_mismatch(
&span.pos(self.ctx),
&op_type.describe(),
target_type,
));
}
self.check_type_mismatch(op_type, target_type, span, diagnostics);
}
Some(Disambiguated::Ambiguous(candidates)) => {
diagnostics.push(Diagnostic::ambiguous_op(
Expand Down
2 changes: 1 addition & 1 deletion vhdl_lang/src/analysis/literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::data::*;
use crate::named_entity::*;
use crate::TokenSpan;

impl<'a, 't> AnalyzeContext<'a, 't> {
impl<'a> AnalyzeContext<'a, '_> {
/// Analyze a string literal or expanded bit-string literal for type-matching
fn analyze_string_literal(
&self,
Expand Down
8 changes: 4 additions & 4 deletions vhdl_lang/src/analysis/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub struct ReadGuard<'a, T, R> {
guard: RwLockReadGuard<'a, AnalysisState<T, R>>,
}

impl<'a, T, R> ReadGuard<'a, T, R> {
impl<T, R> ReadGuard<'_, T, R> {
pub fn result(&self) -> &R {
self.guard.result.as_ref().unwrap()
}
Expand All @@ -122,7 +122,7 @@ impl<'a, T, R> ReadGuard<'a, T, R> {
}
}

impl<'a, T, R> std::ops::Deref for ReadGuard<'a, T, R> {
impl<T, R> std::ops::Deref for ReadGuard<'_, T, R> {
type Target = T;

fn deref(&self) -> &Self::Target {
Expand All @@ -148,15 +148,15 @@ impl<'a, T, R> WriteGuard<'a, T, R> {
}
}

impl<'a, T, R> std::ops::Deref for WriteGuard<'a, T, R> {
impl<T, R> std::ops::Deref for WriteGuard<'_, T, R> {
type Target = T;

fn deref(&self) -> &Self::Target {
&self.guard.data
}
}

impl<'a, T, R> std::ops::DerefMut for WriteGuard<'a, T, R> {
impl<T, R> std::ops::DerefMut for WriteGuard<'_, T, R> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.guard.data
}
Expand Down
Loading

0 comments on commit 7ed5e78

Please sign in to comment.