Skip to content

Commit

Permalink
Fix unexpected error
Browse files Browse the repository at this point in the history
  • Loading branch information
dalance committed Mar 28, 2024
1 parent 9e672b6 commit bdad003
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 20 deletions.
6 changes: 6 additions & 0 deletions crates/analyzer/src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,12 @@ fn check_multiple_assignment(
let mut ret = Vec::new();
let len = x_pos.0.len().min(y_pos.0.len());

let x_maybe = x_pos.0.last().unwrap().is_maybe();
let y_maybe = y_pos.0.last().unwrap().is_maybe();
if x_maybe || y_maybe {
return vec![];
}

for i in 0..len {
let x_type = &x_pos.0[i];
let y_type = &y_pos.0[i];
Expand Down
24 changes: 18 additions & 6 deletions crates/analyzer/src/assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,29 @@ pub enum AssignPositionType {
token: Token,
resettable: bool,
},
Connect {
token: Token,
maybe: bool,
},
}

impl AssignPositionType {
pub fn token(&self) -> &Token {
match self {
AssignPositionType::DeclarationBranch { token: x, .. } => x,
AssignPositionType::DeclarationBranchItem { token: x, .. } => x,
AssignPositionType::Declaration { token: x, .. } => x,
AssignPositionType::StatementBranch { token: x, .. } => x,
AssignPositionType::StatementBranchItem { token: x, .. } => x,
AssignPositionType::Statement { token: x, .. } => x,
AssignPositionType::DeclarationBranch { token, .. } => token,
AssignPositionType::DeclarationBranchItem { token, .. } => token,
AssignPositionType::Declaration { token, .. } => token,
AssignPositionType::StatementBranch { token, .. } => token,
AssignPositionType::StatementBranchItem { token, .. } => token,
AssignPositionType::Statement { token, .. } => token,
AssignPositionType::Connect { token, .. } => token,
}
}

pub fn is_maybe(&self) -> bool {
match self {
AssignPositionType::Connect { maybe, .. } => *maybe,
_ => false,
}
}
}
Expand Down
21 changes: 13 additions & 8 deletions crates/analyzer/src/handlers/check_assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,14 @@ impl<'a> VerylGrammarTrait for CheckAssignment<'a> {
}
}

for (name, target) in &x.connects {
self.assign_position.push(AssignPositionType::Declaration {
token: arg.inst.inst_token.token,
r#type: AssignDeclarationType::Inst,
});

for (token, target) in &x.connects {
if !target.is_empty() {
let dir_output = if let Some(dir) = dirs.get(name) {
let dir_output = if let Some(dir) = dirs.get(&token.text) {
matches!(
dir,
Direction::Ref | Direction::Inout | Direction::Output
Expand All @@ -438,12 +443,10 @@ impl<'a> VerylGrammarTrait for CheckAssignment<'a> {
if let Ok(x) =
symbol_table::resolve((target, &symbol.namespace))
{
self.assign_position.push(
AssignPositionType::Declaration {
token: arg.inst.inst_token.token,
r#type: AssignDeclarationType::Inst,
},
);
self.assign_position.push(AssignPositionType::Connect {
token: *token,
maybe: dir_unknown,
});
symbol_table::add_assign(
x.full_path,
&self.assign_position,
Expand All @@ -454,6 +457,8 @@ impl<'a> VerylGrammarTrait for CheckAssignment<'a> {
}
}
}

self.assign_position.pop();
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/analyzer/src/handlers/create_symbol_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct CreateSymbolTable<'a> {
struct_union_members: Vec<Option<SymbolId>>,
affiniation: Vec<VariableAffiniation>,
connect_targets: Vec<Vec<StrId>>,
connects: HashMap<StrId, Vec<StrId>>,
connects: HashMap<Token, Vec<StrId>>,
}

#[derive(Clone)]
Expand Down Expand Up @@ -377,11 +377,11 @@ impl<'a> VerylGrammarTrait for CreateSymbolTable<'a> {
match self.point {
HandlerPoint::Before => self.connect_targets.clear(),
HandlerPoint::After => {
let port = arg.identifier.identifier_token.token.text;
let port = arg.identifier.identifier_token.token;
let targets = if arg.inst_port_item_opt.is_some() {
self.connect_targets.drain(0..).collect()
} else {
vec![vec![port]]
vec![vec![port.text]]
};
for target in targets {
self.connects.insert(port, target);
Expand Down
2 changes: 1 addition & 1 deletion crates/analyzer/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ pub struct FunctionProperty {
#[derive(Debug, Clone)]
pub struct InstanceProperty {
pub type_name: Vec<StrId>,
pub connects: HashMap<StrId, Vec<StrId>>,
pub connects: HashMap<Token, Vec<StrId>>,
}

#[derive(Debug, Clone)]
Expand Down
4 changes: 2 additions & 2 deletions crates/parser/src/veryl_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use paste::paste;
use regex::Regex;
use std::fmt;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TokenSource {
File(PathId),
Builtin,
Expand All @@ -33,7 +33,7 @@ impl PartialEq<PathId> for TokenSource {
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Token {
pub id: TokenId,
pub text: StrId,
Expand Down

0 comments on commit bdad003

Please sign in to comment.