From b52d69bdbb39e22ecd0d05043878630054ce944c Mon Sep 17 00:00:00 2001 From: light-ly <1505507717@qq.com> Date: Tue, 3 Dec 2024 17:24:01 +0800 Subject: [PATCH] fix new fast: stage --- Cargo.lock | 1 - src/core/vhdl_parser.rs | 23 ++++++- src/sources.rs | 140 +++++++++++++++++++++------------------- vhdl-parser | 2 +- 4 files changed, 97 insertions(+), 69 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4542a3c..d6cd34b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1416,7 +1416,6 @@ dependencies = [ name = "sv-parser" version = "0.13.3" dependencies = [ - "log", "nom", "nom-greedyerror", "sv-parser-error", diff --git a/src/core/vhdl_parser.rs b/src/core/vhdl_parser.rs index 925f6c5..ae37dec 100644 --- a/src/core/vhdl_parser.rs +++ b/src/core/vhdl_parser.rs @@ -1,7 +1,7 @@ use std::collections::HashSet; use std::path::PathBuf; use log::info; -use vhdl_lang::ast::DesignFile; +use vhdl_lang::ast::{AnyDesignUnit, DesignFile}; use vhdl_lang::{kind_str, Token, VHDLParser, VHDLStandard}; use super::hdlparam::*; @@ -53,6 +53,27 @@ pub fn vhdl_parse_str(path: &PathBuf, code: &str) -> Option { None } +pub fn new_make_fast_from_design_file(units: Vec<(AnyDesignUnit, Vec)>, design_file: &DesignFile) -> Option { + let mut hdlparam = FastHdlparam { + fast_macro: Macro { + defines: Vec::new(), + errors: Vec::new(), + includes: Vec::new(), + invalid: Vec::new() + }, + content: Vec::new(), + file_type: "common".to_string() + }; + + + info!("get units {:#?}", units); + // for (tokens, design_unit) in &design_file.design_units { + + // } + + Some(hdlparam) +} + pub fn make_fast_from_design_file(design_file: &DesignFile) -> Option { let mut hdlparam = FastHdlparam { fast_macro: Macro { diff --git a/src/sources.rs b/src/sources.rs index 52cfcfd..ce648e0 100644 --- a/src/sources.rs +++ b/src/sources.rs @@ -2,6 +2,7 @@ use crate::core::hdlparam::HdlParam; use crate::core::primitive_parser::PrimitiveText; use crate::core::sv_parser::make_fast_from_syntaxtree; use crate::core::vhdl_parser::make_fast_from_design_file; +use crate::core::vhdl_parser::new_make_fast_from_design_file; use crate::core::vhdl_parser::vhdl_parse_str; use crate::definition::def_types::*; use crate::definition::get_scopes_from_syntax_tree; @@ -768,70 +769,6 @@ pub fn vhdl_parser_pipeline( configure.extension_path.to_string() }; - let mut file = source_handle.write().unwrap(); - let text = doc.to_string(); - let mut scope_tree = if let Some(design_file) = vhdl_parse_str(&escape_path, &text) { - if let Some(mut fast) = make_fast_from_design_file(&design_file) { - let parse_ir = ParseIR::DesignFile(design_file); - file.parse_ir = Some(parse_ir); - - for module in &fast.content { - info!("parse port number: {:?}", module.ports.len()); - } - - let file_type = { - let fast_map = hdl_param_handle.path_to_hdl_file.read().unwrap(); - if let Some(hdl_file) = fast_map.get(escape_path_string) { - hdl_file.fast.file_type.to_string() - } else { - if let Some(relative_path) = escape_path_string.strip_prefix(&extension_path) { - if relative_path.starts_with("/user/ip") || relative_path.starts_with("user/ip") { - "ip".to_string() - } else { - "common".to_string() - } - } else { - "common".to_string() - } - } - }; - - fast.file_type = file_type; - hdl_param_handle.update_fast(escape_path_string.to_string(), fast.clone()); - let scope_tree = get_scopes_from_vhdl_fast(&fast, doc, uri); - scope_tree - } else { - None - } - } else { - file.parse_ir = None; - None - }; - drop(file); - - - info!("finish parse {:?}", uri.to_string()); - - // 更新 global_scope,用于 sv 的解析 - // global_scope 为全局最大的那个 scope,它的 scopes 和 defs 下的元素和每一个文件一一对应 - let mut global_scope = scope_handle.write().unwrap(); - match &mut *global_scope { - Some(scope) => match &mut scope_tree { - Some(tree) => { - // 更新所有 uri 为当前 uri 的文件结构 - scope.defs.retain(|x| &x.url() != uri); - scope.scopes.retain(|x| &x.url() != uri); - - scope.defs.append(&mut tree.defs); - scope.scopes.append(&mut tree.scopes); - } - None => (), - }, - // 使用 scope_tree 来更新全局的 scope - None => *global_scope = scope_tree, - } - // eprintln!("{:#?}", *global_scope); - let mut global_project = project_handle.write().unwrap(); match &mut *global_project { Some(vhdl_project) => { @@ -858,7 +795,7 @@ pub fn vhdl_parser_pipeline( } } None => { - let std_cfg_path = match PathBuf::from_str(&(extension_path + "/resources/dide-lsp/static/vhdl_std_lib/vhdl_ls.toml")) { + let std_cfg_path = match PathBuf::from_str(&(extension_path.clone() + "/resources/dide-lsp/static/vhdl_std_lib/vhdl_ls.toml")) { Ok(path) => path, Err(e) => { info!("error happen in : {:?}", e); @@ -890,7 +827,78 @@ pub fn vhdl_parser_pipeline( } drop(global_project); - drop(global_scope); + let mut global_project = project_handle.write().unwrap(); + match &mut *global_project { + Some(vhdl_project) => { + let mut file = source_handle.write().unwrap(); + let text = doc.to_string(); + let mut scope_tree = if let Some(design_file) = vhdl_parse_str(&escape_path, &text) { + let units_in_file = vhdl_project.project.get_analyzed_units(&escape_path); + if let Some(mut fast) = new_make_fast_from_design_file(units_in_file, &design_file) { + let parse_ir = ParseIR::DesignFile(design_file); + file.parse_ir = Some(parse_ir); + + for module in &fast.content { + info!("parse port number: {:?}", module.ports.len()); + } + + let file_type = { + let fast_map = hdl_param_handle.path_to_hdl_file.read().unwrap(); + if let Some(hdl_file) = fast_map.get(escape_path_string) { + hdl_file.fast.file_type.to_string() + } else { + if let Some(relative_path) = escape_path_string.strip_prefix(&extension_path) { + if relative_path.starts_with("/user/ip") || relative_path.starts_with("user/ip") { + "ip".to_string() + } else { + "common".to_string() + } + } else { + "common".to_string() + } + } + }; + + fast.file_type = file_type; + hdl_param_handle.update_fast(escape_path_string.to_string(), fast.clone()); + let scope_tree = get_scopes_from_vhdl_fast(&fast, doc, uri); + scope_tree + } else { + None + } + } else { + file.parse_ir = None; + None + }; + drop(file); + + + info!("finish parse {:?}", uri.to_string()); + + // 更新 global_scope,用于 sv 的解析 + // global_scope 为全局最大的那个 scope,它的 scopes 和 defs 下的元素和每一个文件一一对应 + let mut global_scope = scope_handle.write().unwrap(); + match &mut *global_scope { + Some(scope) => match &mut scope_tree { + Some(tree) => { + // 更新所有 uri 为当前 uri 的文件结构 + scope.defs.retain(|x| &x.url() != uri); + scope.scopes.retain(|x| &x.url() != uri); + + scope.defs.append(&mut tree.defs); + scope.scopes.append(&mut tree.scopes); + } + None => (), + }, + // 使用 scope_tree 来更新全局的 scope + None => *global_scope = scope_tree, + } + // eprintln!("{:#?}", *global_scope); + + drop(global_scope); + } + _ => () + } } //TODO: add bounds checking for utf8<->utf16 conversions diff --git a/vhdl-parser b/vhdl-parser index 2446bd0..efa2b48 160000 --- a/vhdl-parser +++ b/vhdl-parser @@ -1 +1 @@ -Subproject commit 2446bd0a812d1667ad7033f10cd27a03967fa15e +Subproject commit efa2b481aafda0f8361dac8456ab35bda93bfe01