Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -5109,13 +5109,21 @@ Replace `parameter` keyword with `localparam`.

In a package, `localparam` properly describes the non-overridable semantics.

### Pass Example (1 of 1)
### Pass Example (1 of 2)
```systemverilog
package P;
localparam int A = 1;
endpackage
```

### Pass Example (2 of 2)
```systemverilog
package foo;
class bar #( parameter int baz );
endclass
endpackage
```

### Fail Example (1 of 1)
```systemverilog
package P;
Expand Down
38 changes: 19 additions & 19 deletions src/syntaxrules/parameter_in_package.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::config::ConfigOption;
use crate::linter::{SyntaxRule, SyntaxRuleResult};
use sv_parser::{unwrap_locate, unwrap_node, NodeEvent, RefNode, SyntaxTree};
use sv_parser::{unwrap_locate, NodeEvent, RefNode, SyntaxTree};

#[derive(Default)]
pub struct ParameterInPackage;
pub struct ParameterInPackage {
inside_param_port_list : bool,
}

impl SyntaxRule for ParameterInPackage {
fn check(
Expand All @@ -12,24 +14,22 @@ impl SyntaxRule for ParameterInPackage {
event: &NodeEvent,
_option: &ConfigOption,
) -> SyntaxRuleResult {
let node = match event {
NodeEvent::Enter(x) => x,
NodeEvent::Leave(_) => {
return SyntaxRuleResult::Pass;
}
};
match node {
RefNode::PackageDeclaration(x) => {
let param = unwrap_node!(*x, ParameterDeclaration);
if let Some(param) = param {
let param_locate = unwrap_locate!(param).unwrap();
SyntaxRuleResult::FailLocate(*param_locate)
} else {
SyntaxRuleResult::Pass
match event {
NodeEvent::Enter(RefNode::ParameterPortList(_)) => {
self.inside_param_port_list = true;
},
NodeEvent::Leave(RefNode::ParameterPortList(_)) => {
self.inside_param_port_list = false;
},
NodeEvent::Enter(RefNode::ParameterDeclaration(&ref x)) => {
if !self.inside_param_port_list {
let param_locate = unwrap_locate!(x).unwrap();
return SyntaxRuleResult::FailLocate(*param_locate)
}
}
_ => SyntaxRuleResult::Pass,
}
},
_ => {}
};
return SyntaxRuleResult::Pass
}

fn name(&self) -> String {
Expand Down
5 changes: 5 additions & 0 deletions testcases/syntaxrules/pass/parameter_in_package.sv
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package P;
localparam int A = 1;
endpackage
////////////////////////////////////////////////////////////////////////////////
package foo;
class bar #( parameter int baz );
endclass
endpackage
Loading