fix unwrap none bug in sv-parser
This commit is contained in:
parent
8ee9a361f7
commit
15bf62bc5b
@ -2,6 +2,7 @@ use std::fs::File;
|
||||
use std::io::BufRead;
|
||||
use std::{collections::HashMap, io::BufReader};
|
||||
use std::path::PathBuf;
|
||||
use anyhow::Error;
|
||||
use sv_parser::{parse_sv, unwrap_node, ConstantMintypmaxExpression, GateInstantiation, ListOfParameterAssignments, ListOfPortConnections, Locate, PackedDimensionRange, RefNode, SyntaxTree};
|
||||
|
||||
use super::fast_hdlparam::{FastHdlparam, Macro};
|
||||
@ -16,14 +17,15 @@ pub fn sv_parser(path: &str) -> Option<FastHdlparam> {
|
||||
|
||||
let result = parse_sv(&path, &defines, &includes, false, true);
|
||||
if let Ok((syntax_tree, _)) = result {
|
||||
let hdlparam = make_fast_from_syntaxtree(&syntax_tree, &path);
|
||||
if let Ok(hdlparam) = make_fast_from_syntaxtree(&syntax_tree, &path) {
|
||||
return Some(hdlparam);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn make_fast_from_syntaxtree(syntax_tree: &SyntaxTree, path: &PathBuf) -> FastHdlparam {
|
||||
pub fn make_fast_from_syntaxtree(syntax_tree: &SyntaxTree, path: &PathBuf) -> Result<FastHdlparam, Error> {
|
||||
let mut hdlparam = FastHdlparam {
|
||||
fast_macro: Macro {
|
||||
defines: Vec::new(),
|
||||
@ -96,9 +98,14 @@ pub fn make_fast_from_syntaxtree(syntax_tree: &SyntaxTree, path: &PathBuf) -> Fa
|
||||
let (mut end_line, mut end_character) = (id.line, start_character + id.len as u32);
|
||||
let net_type = match unwrap_node!(param_node, DataType) {
|
||||
Some(RefNode::DataType(data_type)) => {
|
||||
let id = get_identifier(unwrap_node!(data_type, SimpleIdentifier, Keyword).unwrap()).unwrap();
|
||||
let id = unwrap_node!(data_type, SimpleIdentifier, Keyword);
|
||||
if id == None {
|
||||
"wire"
|
||||
} else {
|
||||
let id = get_identifier(id.unwrap()).unwrap();
|
||||
syntax_tree.get_str(&id).unwrap()
|
||||
}
|
||||
}
|
||||
_ => "wire"
|
||||
};
|
||||
let init = match unwrap_node!(param_node, ConstantMintypmaxExpression).unwrap() {
|
||||
@ -129,8 +136,12 @@ pub fn make_fast_from_syntaxtree(syntax_tree: &SyntaxTree, path: &PathBuf) -> Fa
|
||||
|
||||
let net_type = match unwrap_node!(x, DataType, ImplicitDataType) {
|
||||
Some(RefNode::DataType(x)) => {
|
||||
let id = unwrap_node!(x, Keyword).unwrap();
|
||||
syntax_tree.get_str(&get_identifier(id).unwrap()).unwrap()
|
||||
let id = unwrap_node!(x, Keyword);
|
||||
if id != None {
|
||||
syntax_tree.get_str(&get_identifier(id.unwrap()).unwrap()).unwrap()
|
||||
} else {
|
||||
"unknown"
|
||||
}
|
||||
},
|
||||
Some(RefNode::ImplicitDataType(_)) => "wire",
|
||||
_ => "unknown"
|
||||
@ -180,8 +191,12 @@ pub fn make_fast_from_syntaxtree(syntax_tree: &SyntaxTree, path: &PathBuf) -> Fa
|
||||
} else {
|
||||
match unwrap_node!(x, DataType, ImplicitDataType) {
|
||||
Some(RefNode::DataType(x)) => {
|
||||
let id = unwrap_node!(x, Keyword).unwrap();
|
||||
syntax_tree.get_str(&get_identifier(id).unwrap()).unwrap()
|
||||
let id = unwrap_node!(x, Keyword);
|
||||
if id != None {
|
||||
syntax_tree.get_str(&get_identifier(id.unwrap()).unwrap()).unwrap()
|
||||
} else {
|
||||
"unknown"
|
||||
}
|
||||
},
|
||||
Some(RefNode::ImplicitDataType(_)) => "wire",
|
||||
_ => "unknown"
|
||||
@ -276,7 +291,7 @@ pub fn make_fast_from_syntaxtree(syntax_tree: &SyntaxTree, path: &PathBuf) -> Fa
|
||||
}
|
||||
}
|
||||
|
||||
hdlparam
|
||||
Ok(hdlparam)
|
||||
}
|
||||
|
||||
fn get_inst_param_last_locate(x: &ListOfParameterAssignments) -> Option<(Locate, Locate)> {
|
||||
|
@ -114,9 +114,10 @@ pub fn do_fast(path: String) -> Result<FastHdlparam> {
|
||||
);
|
||||
|
||||
if let Some(syntax_tree) = parse_result {
|
||||
let hdlparam = make_fast_from_syntaxtree(&syntax_tree, &path_buf);
|
||||
if let Ok(hdlparam) = make_fast_from_syntaxtree(&syntax_tree, &path_buf) {
|
||||
return Ok(hdlparam);
|
||||
}
|
||||
}
|
||||
|
||||
let api_error = tower_lsp::jsonrpc::Error {
|
||||
code: tower_lsp::jsonrpc::ErrorCode::ParseError,
|
||||
|
@ -239,7 +239,19 @@ impl Sources {
|
||||
// 计算 fast
|
||||
if let Some(syntax_tree) = &syntax_tree {
|
||||
let path = PathBuf::from(uri.path().to_string());
|
||||
let fast = make_fast_from_syntaxtree(&syntax_tree, &path);
|
||||
let fast = if let Ok(fast) = make_fast_from_syntaxtree(&syntax_tree, &path) {
|
||||
fast
|
||||
} else {
|
||||
crate::core::fast_hdlparam::FastHdlparam {
|
||||
fast_macro: crate::core::fast_hdlparam::Macro {
|
||||
defines: Vec::new(),
|
||||
errors: Vec::new(),
|
||||
includes: Vec::new(),
|
||||
invalid: Vec::new()
|
||||
},
|
||||
content: Vec::new()
|
||||
}
|
||||
};
|
||||
update_fast_to_client(backend.clone(), fast);
|
||||
}
|
||||
|
||||
|
8
testfiles/hierarchical_name_of_type.sv
Normal file
8
testfiles/hierarchical_name_of_type.sv
Normal file
@ -0,0 +1,8 @@
|
||||
module ibex_alu #(
|
||||
parameter ibex_pkg::rv32b_e RV32B = ibex_pkg::RV32BNone
|
||||
) (
|
||||
input ibex_pkg::alu_op_e operator_i,
|
||||
input logic[31:0] operand_a_i,
|
||||
input logic[31:0] operand_b_i
|
||||
);
|
||||
endmodule
|
Loading…
x
Reference in New Issue
Block a user