Skip to content

Commit 4f9caed

Browse files
authored
Merge pull request #361 from Schottkyc137/lint-sensitivity-lists
Add a linter for sensitivity lists
2 parents bd29fa3 + af95457 commit 4f9caed

File tree

11 files changed

+948
-21
lines changed

11 files changed

+948
-21
lines changed

vhdl_lang/src/ast/search.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,24 @@ impl Search for SensitivityList {
508508
}
509509
}
510510

511+
impl Search for ProcessStatement {
512+
fn search(&self, ctx: &dyn TokenAccess, searcher: &mut impl Searcher) -> SearchResult {
513+
let ProcessStatement {
514+
postponed: _,
515+
sensitivity_list,
516+
decl,
517+
statements,
518+
end_label_pos: _,
519+
..
520+
} = self;
521+
if let Some(sensitivity_list) = sensitivity_list {
522+
return_if_found!(sensitivity_list.item.search(ctx, searcher));
523+
}
524+
return_if_found!(decl.search(ctx, searcher));
525+
statements.search(ctx, searcher)
526+
}
527+
}
528+
511529
impl Search for LabeledConcurrentStatement {
512530
fn search(&self, ctx: &dyn TokenAccess, searcher: &mut impl Searcher) -> SearchResult {
513531
return_if_found!(searcher
@@ -523,19 +541,7 @@ impl Search for LabeledConcurrentStatement {
523541
return_if_found!(block.statements.search(ctx, searcher));
524542
}
525543
ConcurrentStatement::Process(ref process) => {
526-
let ProcessStatement {
527-
postponed: _,
528-
sensitivity_list,
529-
decl,
530-
statements,
531-
end_label_pos: _,
532-
..
533-
} = process;
534-
if let Some(sensitivity_list) = sensitivity_list {
535-
return_if_found!(sensitivity_list.item.search(ctx, searcher));
536-
}
537-
return_if_found!(decl.search(ctx, searcher));
538-
return_if_found!(statements.search(ctx, searcher));
544+
return_if_found!(process.search(ctx, searcher));
539545
}
540546
ConcurrentStatement::ForGenerate(ref gen) => {
541547
return_if_found!(searcher

vhdl_lang/src/ast/util.rs

+13
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,19 @@ impl Name {
339339
}
340340
}
341341

342+
/// Like [self.get_suffix_reference], but disregards final indexes, such as
343+
/// `foo.bar.baz(0)`
344+
pub fn get_suffix_reference_disregard_index(&self) -> Option<EntityId> {
345+
use Name::*;
346+
match self {
347+
Designator(suffix) => suffix.reference.get(),
348+
Selected(_, suffix) => suffix.item.reference.get(),
349+
Slice(name, _) => name.item.get_suffix_reference_disregard_index(),
350+
CallOrIndexed(coi) => coi.name.item.get_suffix_reference_disregard_index(),
351+
_ => None,
352+
}
353+
}
354+
342355
pub fn prefix(&self) -> Option<&Designator> {
343356
match self {
344357
Self::Attribute(attr) => attr.name.item.prefix(),

vhdl_lang/src/data/error_codes.rs

+30-1
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,33 @@ pub enum ErrorCode {
410410
/// ```
411411
UnassociatedContext,
412412

413+
/// A signal is missing in the sensitivity list
414+
///
415+
/// # Example
416+
/// ```vhdl
417+
/// foo: process(y) is
418+
/// begin
419+
/// bar <= x;
420+
/// end;
421+
/// ```
422+
///
423+
/// The signal `x` is read by the process `foo`, but it is not part
424+
/// of the sensitivity list.
425+
MissingInSensitivityList,
426+
427+
/// A signal is present in a sensitivity list, but never used
428+
///
429+
/// # Example
430+
/// ```vhdl
431+
/// foo: process(x, y) is
432+
/// begin
433+
/// bar <= x;
434+
/// end;
435+
/// ```
436+
///
437+
/// Both signals `x` and `y` are specified in the process, but only x is read.
438+
SuperfluousInSensitivityList,
439+
413440
// Misc
414441
/// An internal error that signifies that some precondition within vhdl_lang wasn't met.
415442
/// If an error with this error code occurs,
@@ -494,7 +521,9 @@ impl Default for SeverityMap {
494521
| InvalidCall => Some(Error),
495522
Unused
496523
| UnnecessaryWorkLibrary
497-
| UnassociatedContext => Some(Warning),
524+
| UnassociatedContext
525+
| MissingInSensitivityList
526+
| SuperfluousInSensitivityList => Some(Warning),
498527
Internal => Some(Error),
499528
Related => Some(Hint)
500529
};

vhdl_lang/src/lint.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
// Copyright (c) 2022, Olof Kraigher [email protected]
66

77
pub mod dead_code;
8+
pub mod sensitivity_list;

0 commit comments

Comments
 (0)