add inner parameter parse for sv

This commit is contained in:
light-ly 2024-10-01 16:23:15 +08:00
parent e289d8089f
commit 701617dd66

View File

@ -157,6 +157,55 @@ pub fn make_fast_from_syntaxtree(syntax_tree: &SyntaxTree, path: &PathBuf) -> Re
} }
} }
} }
RefNode::ParameterDeclaration(x) => {
if let Some(id) = unwrap_node!(x, ParameterIdentifier) {
let id = get_identifier(id).unwrap();
let name = syntax_tree.get_str(&id).unwrap();
match unwrap_node!(x, ParameterDeclarationParam, ParameterPortDeclarationParamList) {
Some(RefNode::ParameterDeclarationParam(param_node)) => {
// println!("{:?}", param_node);
let keyword_locate = param_node.nodes.0.nodes.0;
// println!("keyword {:#?}", keyword_locate);
let (start_line, start_character) = (id.line, get_column_by_offset(&content, keyword_locate.offset) as u32);
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 = 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 = if let Some(init) = unwrap_node!(param_node, ConstantMintypmaxExpression) {
match init {
RefNode::ConstantMintypmaxExpression(expression) => {
// println!("expression {:?}", x);
let param_init = sv_parser::NeedParseExpression::Parameter(expression.clone());
let (exp, last_locate) = parse_expression(&syntax_tree, &param_init);
(end_line, end_character) = if last_locate != None {
// println!("param {:?} lastlocate {:?}", name, last_locate);
(last_locate.unwrap().line, (get_column_by_offset(&content, last_locate.unwrap().offset) + last_locate.unwrap().len) as u32)
} else {
(end_line, end_character)
};
// println!("end pos {} {}", end_line, end_character);
exp
}
_ => "unknown".to_string()
}
} else {
"unknown".to_string()
};
hdlparam.add_parameter(name, net_type, init.as_str(), start_line, start_character, end_line, end_character);
}
_ => ()
}
}
}
RefNode::PortDeclaration(x) => { RefNode::PortDeclaration(x) => {
if let Some(id) = unwrap_node!(x, InputDeclaration, OutputDeclaration, InoutDeclaration) { if let Some(id) = unwrap_node!(x, InputDeclaration, OutputDeclaration, InoutDeclaration) {
let id = get_identifier(id).unwrap(); let id = get_identifier(id).unwrap();