Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
nblei committed Jun 5, 2024
2 parents a5022ac + 85fa44c commit 25e3627
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ similar = {version = "2.5.0", features = ["text", "inline"]}
strnum_bitwidth = "0.1.2"
tempfile = "3.10"
thiserror = "1.0"
tokio = {version = "1.37.0", features = ["full"]}
tokio = {version = "1.38.0", features = ["full"]}
toml = "0.7.8"
url = {version = "2.5", features = ["serde"]}

Expand Down
23 changes: 23 additions & 0 deletions crates/analyzer/src/analyzer_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,21 @@ pub enum AnalyzerError {
error_location: SourceSpan,
},

#[diagnostic(
severity(Error),
code(sv_keyword_usage),
help("Change the identifier to a non-SystemVerilog keyword"),
url("")
)]
#[error("SystemVerilog keyword may not be used as identifier")]
SvKeywordUsage {
identifier: String,
#[source_code]
input: NamedSource,
#[label("Error location")]
error_location: SourceSpan,
},

#[diagnostic(
severity(Error),
code(too_large_enum_variant),
Expand Down Expand Up @@ -1085,6 +1100,14 @@ impl AnalyzerError {
}
}

pub fn sv_keyword_usage(identifier: &str, source: &str, token: &TokenRange) -> Self {
AnalyzerError::SvKeywordUsage {
identifier: identifier.to_string(),
input: AnalyzerError::named_source(source, token),
error_location: token.into(),
}
}

pub fn too_large_enum_variant(
identifier: &str,
value: isize,
Expand Down
21 changes: 21 additions & 0 deletions crates/analyzer/src/handlers/check_identifier.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::analyzer_error::AnalyzerError;
use crate::symbol::Direction as SymDirection;
use crate::symbol_table::is_sv_keyword;
use inflector::cases::{
camelcase::is_camel_case, pascalcase::is_pascal_case,
screamingsnakecase::is_screaming_snake_case, snakecase::is_snake_case,
Expand Down Expand Up @@ -35,6 +36,7 @@ enum Kind {
Reg,
Struct,
Union,
Var,
Wire,
}

Expand Down Expand Up @@ -69,6 +71,7 @@ impl<'a> CheckIdentifier<'a> {
Kind::Reg => &opt.prefix_reg,
Kind::Struct => &opt.prefix_struct,
Kind::Union => &opt.prefix_union,
Kind::Var => &opt.prefix_var,
Kind::Wire => &opt.prefix_wire,
};

Expand All @@ -88,6 +91,7 @@ impl<'a> CheckIdentifier<'a> {
Kind::Reg => &opt.case_reg,
Kind::Struct => &opt.case_struct,
Kind::Union => &opt.case_union,
Kind::Var => &opt.case_var,
Kind::Wire => &opt.case_wire,
};

Expand All @@ -107,6 +111,7 @@ impl<'a> CheckIdentifier<'a> {
Kind::Reg => &opt.re_required_reg,
Kind::Struct => &opt.re_required_struct,
Kind::Union => &opt.re_required_union,
Kind::Var => &opt.re_required_var,
Kind::Wire => &opt.re_required_wire,
};

Expand All @@ -126,6 +131,7 @@ impl<'a> CheckIdentifier<'a> {
Kind::Reg => &opt.re_forbidden_reg,
Kind::Struct => &opt.re_forbidden_struct,
Kind::Union => &opt.re_forbidden_union,
Kind::Var => &opt.re_forbidden_var,
Kind::Wire => &opt.re_forbidden_wire,
};

Expand All @@ -139,6 +145,14 @@ impl<'a> CheckIdentifier<'a> {
));
}

if is_sv_keyword(&identifier) {
self.errors.push(AnalyzerError::sv_keyword_usage(
&identifier,
self.text,
&token.into(),
))
}

if let Some(prefix) = prefix {
if !identifier.starts_with(prefix) {
self.errors.push(AnalyzerError::invalid_identifier(
Expand Down Expand Up @@ -337,4 +351,11 @@ impl<'a> VerylGrammarTrait for CheckIdentifier<'a> {
}
Ok(())
}

fn var_declaration(&mut self, arg: &VarDeclaration) -> Result<(), ParolError> {
if let HandlerPoint::Before = self.point {
self.check(&arg.identifier.identifier_token.token, Kind::Var)
}
Ok(())
}
}
Loading

0 comments on commit 25e3627

Please sign in to comment.