From ec959f16bb5ed69f5185590a49495de0e51bbecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E5=8D=9A=E6=96=87?= Date: Sat, 9 Nov 2024 00:05:14 +0800 Subject: [PATCH] refactor: Use Arc instead of Rc --- lib/src/ast/declaration_statement.rs | 10 ++-- lib/src/ast/function_declaration.rs | 8 ++-- lib/src/ast/global_variable_declaration.rs | 8 ++-- lib/src/ast/mod.rs | 53 ++++++++++++++++------ lib/src/ast/types.rs | 27 ++++++----- lib/src/ast/variable.rs | 12 ++--- lib/src/context/module_context.rs | 33 +++++++------- lib/src/context/scope.rs | 8 ++-- lib/src/context/units_manager.rs | 7 ++- lib/src/parser/default_impl/mod.rs | 19 ++++---- lib/src/parser/lalrpop_impl/st.lalrpop | 24 +++++----- lib/src/utils/attrmap.rs | 2 +- lsp/src/lsp.rs | 3 ++ 13 files changed, 120 insertions(+), 94 deletions(-) diff --git a/lib/src/ast/declaration_statement.rs b/lib/src/ast/declaration_statement.rs index ff94918..40827e3 100644 --- a/lib/src/ast/declaration_statement.rs +++ b/lib/src/ast/declaration_statement.rs @@ -1,9 +1,9 @@ use crate::ast::*; use crate::parser::TokenKind; use crate::utils::HasAttribute; -use std::rc::Rc; +use std::sync::Arc; -const EMPTY_VARIABLES: &[Rc] = &[]; +const EMPTY_VARIABLES: &[Arc] = &[]; #[derive(Debug)] pub enum DeclKind { @@ -88,7 +88,7 @@ impl Declaration { } #[inline] - pub fn variables(&self) -> &[Rc] { + pub fn variables(&self) -> &[Arc] { match self.kind { DeclKind::Fun(ref f) => f.parameters(), DeclKind::Struct(ref s) => s.variables(), @@ -125,7 +125,7 @@ impl Declaration { } #[inline] - pub fn new_struct(name: StString, variables: SmallVec8>) -> Self { + pub fn new_struct(name: StString, variables: SmallVec8>) -> Self { Self::struct_(Box::new(StructDeclare::new(name, variables))) } @@ -137,7 +137,7 @@ impl Declaration { } #[inline] - pub fn new_enum(name: StString, ty: Option, fields: SmallVec8>) -> Self { + pub fn new_enum(name: StString, ty: Option, fields: SmallVec8>) -> Self { Self::enum_(Box::new(EnumDeclare::new(name, ty, fields))) } diff --git a/lib/src/ast/function_declaration.rs b/lib/src/ast/function_declaration.rs index dfcab28..14a9d91 100644 --- a/lib/src/ast/function_declaration.rs +++ b/lib/src/ast/function_declaration.rs @@ -2,14 +2,14 @@ use crate::impl_ast_display; use crate::impl_has_attribute; use crate::prelude::*; use crate::utils::AttrMap8; -use std::rc::Rc; +use std::sync::Arc; #[derive(Debug)] pub struct FunctionDeclare { name: StString, decl_class: DeclareClass, return_type: Option, - parameters: SmallVec8>, + parameters: SmallVec8>, attributes: AttrMap8, } @@ -21,7 +21,7 @@ impl FunctionDeclare { name: StString, class: DeclareClass, ty: Option, - variables: SmallVec8>, + variables: SmallVec8>, ) -> Self { Self { name, @@ -44,7 +44,7 @@ impl FunctionDeclare { &self.return_type } - pub fn parameters(&self) -> &[Rc] { + pub fn parameters(&self) -> &[Arc] { self.parameters.as_slice() } } diff --git a/lib/src/ast/global_variable_declaration.rs b/lib/src/ast/global_variable_declaration.rs index fe2b39f..31c8cdf 100644 --- a/lib/src/ast/global_variable_declaration.rs +++ b/lib/src/ast/global_variable_declaration.rs @@ -2,19 +2,19 @@ use crate::ast::{SmallVec8, Variable}; use crate::impl_has_attribute; use crate::parser::StString; use crate::utils::AttrMap8; -use std::rc::Rc; +use std::sync::Arc; #[derive(Debug)] pub struct GlobalVariableDeclare { name: StString, - variables: SmallVec8>, + variables: SmallVec8>, attributes: AttrMap8, } impl_has_attribute!(GlobalVariableDeclare, attributes); impl GlobalVariableDeclare { - pub fn new(name: Option, variables: SmallVec8>) -> Self { + pub fn new(name: Option, variables: SmallVec8>) -> Self { Self { name: name.unwrap_or(StString::empty()), variables, @@ -26,7 +26,7 @@ impl GlobalVariableDeclare { &self.name } - pub fn variables(&self) -> &[Rc] { + pub fn variables(&self) -> &[Arc] { self.variables.as_slice() } } diff --git a/lib/src/ast/mod.rs b/lib/src/ast/mod.rs index 24f3218..faaa084 100644 --- a/lib/src/ast/mod.rs +++ b/lib/src/ast/mod.rs @@ -1,11 +1,9 @@ +use crate::parser::{LiteralValue, Operator, StString}; use bitflags::bitflags; use smallvec::SmallVec; -use std::cell::RefCell; use std::fmt::{self, Debug, Display, Formatter}; use std::hash::{Hash, Hasher}; -use std::rc::Rc; - -use crate::parser::{LiteralValue, Operator, StString}; +use std::sync::{Arc, RwLock}; mod message; pub use message::*; @@ -131,13 +129,13 @@ impl_into_expression!(LiteralValue, |x| Expression::literal(Box::new( #[derive(Clone, Debug)] pub struct Type { - inner: Rc, + inner: Arc, } impl Type { pub fn from_class(class: TypeClass) -> Self { Self { - inner: Rc::new(TypeInner { class }), + inner: Arc::new(TypeInner { class }), } } @@ -288,7 +286,7 @@ pub enum UserTypeClass { Union, } -#[derive(Debug, Eq, PartialEq, Clone)] +#[derive(Debug, Clone)] pub enum TypeClass { /// 'BIT', one bit type Bit, @@ -317,11 +315,36 @@ pub enum TypeClass { /// 'STRING' string type String, /// UserType - UserType(RefCell), + UserType(Arc>), /// ArrayType - Array(RefCell), + Array(Arc>), +} + +impl PartialEq for TypeClass { + fn eq(&self, other: &Self) -> bool { + match (self, other) { + (Self::Int, Self::Int) => true, + (Self::Bit, Self::Bit) => true, + (Self::Bool, Self::Bool) => true, + (Self::SInt, Self::SInt) => true, + (Self::Byte, Self::Byte) => true, + (Self::UInt, Self::UInt) => true, + (Self::UDInt, Self::UDInt) => true, + (Self::ULInt, Self::ULInt) => true, + (Self::Real, Self::Real) => true, + (Self::LReal, Self::LReal) => true, + (Self::String, Self::String) => true, + (Self::UserType(a), Self::UserType(b)) => { + a.read().unwrap().name() == b.read().unwrap().name() + } + (Self::Array(a), Self::Array(b)) => false, + _ => false, + } + } } +impl Eq for TypeClass {} + impl Hash for TypeClass { fn hash(&self, state: &mut H) { let tag = match self { @@ -338,11 +361,13 @@ impl Hash for TypeClass { // TODO: incomplete implements match self { TypeClass::UserType(user_type) => { - user_type.borrow().name().hash(state); + // user_type.borrow().name().hash(state); + user_type.read().unwrap().name().hash(state); } TypeClass::Array(array_type) => { - let array_type = array_type.borrow(); - let base_type = array_type.base_type().borrow(); + // let array_type = array_type.borrow(); + let array_type = array_type.read().unwrap(); + let base_type = array_type.base_type().read().unwrap(); base_type.type_class().hash(state); } _ => {} @@ -366,8 +391,8 @@ impl Display for TypeClass { TypeClass::Real => write!(f, "REAL"), TypeClass::LReal => write!(f, "LREAL"), TypeClass::String => write!(f, "STRING"), - TypeClass::UserType(u) => write!(f, "{}", u.borrow()), - TypeClass::Array(arr) => write!(f, "{}", arr.borrow()), + TypeClass::UserType(u) => write!(f, "{}", u.read().unwrap()), + TypeClass::Array(arr) => write!(f, "{}", arr.read().unwrap()), } } } diff --git a/lib/src/ast/types.rs b/lib/src/ast/types.rs index 1ddafed..6973eab 100644 --- a/lib/src/ast/types.rs +++ b/lib/src/ast/types.rs @@ -1,6 +1,5 @@ -use std::rc::Rc; - use crate::{ast::*, impl_has_attribute, utils::AttrMap8}; +use std::sync::Arc; macro_rules! builtin_type_impl { (struct $name:ident, $class:expr) => { @@ -60,7 +59,7 @@ impl UserType { impl From for Type { fn from(value: UserType) -> Self { - let class = TypeClass::UserType(RefCell::new(value)); + let class = TypeClass::UserType(Arc::new(RwLock::new(value))); Type::from_class(class) } @@ -76,14 +75,14 @@ impl Display for UserType { pub struct EnumDeclare { name: StString, ty: Option, - fields: SmallVec8>, + fields: SmallVec8>, attributes: AttrMap8, } impl_has_attribute!(EnumDeclare, attributes); impl EnumDeclare { - pub fn new(name: StString, ty: Option, fields: SmallVec8>) -> Self { + pub fn new(name: StString, ty: Option, fields: SmallVec8>) -> Self { Self { name, ty, @@ -100,7 +99,7 @@ impl EnumDeclare { &self.ty } - pub fn fields(&self) -> &[Rc] { + pub fn fields(&self) -> &[Arc] { &self.fields } } @@ -143,14 +142,14 @@ impl AliasDeclare { #[derive(Debug)] pub struct StructDeclare { name: StString, - variables: SmallVec8>, + variables: SmallVec8>, attributes: AttrMap8, } impl_has_attribute!(StructDeclare, attributes); impl StructDeclare { - pub fn new(name: StString, variables: SmallVec8>) -> Self { + pub fn new(name: StString, variables: SmallVec8>) -> Self { Self { name, variables, @@ -162,11 +161,11 @@ impl StructDeclare { &self.name } - pub fn variables(&self) -> &[Rc] { + pub fn variables(&self) -> &[Arc] { self.variables.as_slice() } - pub fn variables_mut(&mut self) -> &mut [Rc] { + pub fn variables_mut(&mut self) -> &mut [Arc] { self.variables.as_mut_slice() } } @@ -179,20 +178,20 @@ impl StructDeclare { #[derive(Debug)] pub struct ArrayType { - base_type: RefCell, + base_type: Arc>, dimensions: SmallVec3, } impl ArrayType { pub fn new(base: Type, dimensions: SmallVec3) -> Self { Self { - base_type: RefCell::new(base), + base_type: Arc::new(RwLock::new(base)), dimensions, } } #[inline] - pub fn base_type(&self) -> &RefCell { + pub fn base_type(&self) -> &Arc> { &self.base_type } } @@ -220,7 +219,7 @@ impl Clone for ArrayType { impl From for Type { fn from(value: ArrayType) -> Self { - let class = TypeClass::Array(RefCell::new(value)); + let class = TypeClass::Array(Arc::new(RwLock::new(value))); Type::from_class(class) } diff --git a/lib/src/ast/variable.rs b/lib/src/ast/variable.rs index 093bf62..19803d8 100644 --- a/lib/src/ast/variable.rs +++ b/lib/src/ast/variable.rs @@ -3,7 +3,7 @@ use crate::impl_has_attribute; use crate::parser::StString; use crate::utils::AttrMap8; use std::default::Default; -use std::rc::Rc; +use std::sync::Arc; #[derive(Debug)] pub struct Variable { @@ -42,10 +42,10 @@ impl Variable { pub fn multiple_variable_with_type( names: SmallVec8, ty: Type, - ) -> SmallVec8> { + ) -> SmallVec8> { names .iter() - .map(|x| Rc::new(Self::with_type(x.clone(), ty.clone()))) + .map(|x| Arc::new(Self::with_type(x.clone(), ty.clone()))) .collect() } @@ -109,10 +109,10 @@ pub struct VariableDeclareGroup; impl VariableDeclareGroup { pub fn from_variables( flags: VariableFlags, - mut vars: SmallVec8>, - ) -> SmallVec8> { + mut vars: SmallVec8>, + ) -> SmallVec8> { for v in vars.iter_mut() { - Rc::get_mut(v).unwrap().set_flags(flags); + Arc::get_mut(v).unwrap().set_flags(flags); } vars diff --git a/lib/src/context/module_context.rs b/lib/src/context/module_context.rs index 2fa30d7..1835de4 100644 --- a/lib/src/context/module_context.rs +++ b/lib/src/context/module_context.rs @@ -12,9 +12,8 @@ use std::collections::{HashMap, HashSet}; use std::fmt::{Display, Formatter}; use std::hash::{Hash, Hasher}; use std::ops::Deref; -use std::rc::Rc; use std::sync::atomic::{AtomicUsize, Ordering}; -use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}; +use std::sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard}; use uuid::Uuid; static CONTEXT_ID: Lazy = Lazy::new(|| AtomicUsize::new(0)); @@ -30,7 +29,7 @@ fn get_next_declaration_id() -> usize { #[derive(Clone)] pub struct Prototype { - inner: Rc>, + inner: Arc>, } impl PartialEq for Prototype { @@ -48,7 +47,7 @@ impl Hash for Prototype { } impl Deref for Prototype { - type Target = Rc>; + type Target = Arc>; fn deref(&self) -> &Self::Target { &self.inner @@ -58,24 +57,24 @@ impl Deref for Prototype { impl Prototype { fn new(decl: Declaration) -> Self { Self { - inner: Rc::new(RwLock::new(PrototypeImpl::new(decl))), + inner: Arc::new(RwLock::new(PrototypeImpl::new(decl))), } } fn with_object_id(decl: Declaration, id: Uuid) -> Self { Self { - inner: Rc::new(RwLock::new(PrototypeImpl::with_object_id(decl, id))), + inner: Arc::new(RwLock::new(PrototypeImpl::with_object_id(decl, id))), } } } #[derive(Clone)] pub struct Function { - inner: Rc>, + inner: Arc>, } impl Deref for Function { - type Target = Rc>; + type Target = Arc>; fn deref(&self) -> &Self::Target { &self.inner @@ -85,13 +84,13 @@ impl Deref for Function { impl Function { fn new(decl_id: usize, function: Statement) -> Self { Self { - inner: Rc::new(RwLock::new(FunctionImpl::new(decl_id, function))), + inner: Arc::new(RwLock::new(FunctionImpl::new(decl_id, function))), } } fn with_prototype(proto: &Prototype, function: Statement) -> Self { Self { - inner: Rc::new(RwLock::new(FunctionImpl::with_prototype(proto, function))), + inner: Arc::new(RwLock::new(FunctionImpl::with_prototype(proto, function))), } } @@ -143,7 +142,7 @@ impl PrototypeImpl { self.decl.identifier() } - pub fn variables(&self) -> &[Rc] { + pub fn variables(&self) -> &[Arc] { self.decl.variables() } @@ -159,7 +158,7 @@ impl PrototypeImpl { } /// Get return value of prototype - pub fn return_value(&self) -> Option<&Rc> { + pub fn return_value(&self) -> Option<&Arc> { self.variables().iter().find(|x| x.name() == self.name()) } @@ -284,7 +283,7 @@ impl FunctionImpl { #[derive(Clone)] pub struct ModuleContext { - inner: Rc>, + inner: Arc>, } impl PartialEq for ModuleContext { @@ -298,7 +297,7 @@ impl Eq for ModuleContext {} impl ModuleContext { pub fn new(kind: ModuleKind) -> Self { Self { - inner: Rc::new(RwLock::new(ModuleContextImpl { + inner: Arc::new(RwLock::new(ModuleContextImpl { id: get_next_context_id(), kind, declaration_id_map: IndexMap::new(), @@ -424,13 +423,13 @@ impl ModuleContextImpl { } #[inline] - pub fn find_toplevel_global_variable(&self, ident: &StString) -> Option> { + pub fn find_toplevel_global_variable(&self, ident: &StString) -> Option> { self.find_toplevel_global_variable_map(|x| x.name() == ident) } - pub fn find_toplevel_global_variable_map(&self, f: F) -> Option> + pub fn find_toplevel_global_variable_map(&self, f: F) -> Option> where - F: Fn(&Rc) -> bool, + F: Fn(&Arc) -> bool, { for decl in self.toplevel_global_variable_declarations.iter() { let decl = decl.read().unwrap(); diff --git a/lib/src/context/scope.rs b/lib/src/context/scope.rs index 71087de..dee40b5 100644 --- a/lib/src/context/scope.rs +++ b/lib/src/context/scope.rs @@ -1,7 +1,7 @@ use crate::ast::Variable; use crate::context::{ModuleContext, Prototype, UnitsManager}; use crate::parser::StString; -use std::rc::Rc; +use std::sync::Arc; #[derive(Clone, Default)] pub struct Scope { @@ -51,19 +51,19 @@ impl Scope { } } - pub fn find_variable(&self, ident: &StString) -> Option> { + pub fn find_variable(&self, ident: &StString) -> Option> { self.find_local_variable(ident) .or_else(|| self.find_global_variable(ident)) } - pub fn find_local_variable(&self, ident: &StString) -> Option> { + pub fn find_local_variable(&self, ident: &StString) -> Option> { self.local_declaration.as_ref().and_then(|decl| { let decl = decl.read().unwrap(); decl.variables().iter().find(|x| x.name() == ident).cloned() }) } - pub fn find_global_variable(&self, ident: &StString) -> Option> { + pub fn find_global_variable(&self, ident: &StString) -> Option> { self.local_context .as_ref() .and_then(|ctx| ctx.read().find_toplevel_global_variable(ident)) diff --git a/lib/src/context/units_manager.rs b/lib/src/context/units_manager.rs index 43cf216..c2ebc88 100644 --- a/lib/src/context/units_manager.rs +++ b/lib/src/context/units_manager.rs @@ -1,13 +1,12 @@ use crate::context::ModuleContext; use crate::prelude::Scope; use indexmap::IndexMap; -use std::rc::Rc; -use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}; +use std::sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard}; /// Program Organization Units Manager #[derive(Clone)] pub struct UnitsManager { - inner: Rc>, + inner: Arc>, } impl UnitsManager { @@ -38,7 +37,7 @@ impl Default for UnitsManager { let mgr = UnitsManagerImpl::new(); Self { - inner: Rc::new(RwLock::new(mgr)), + inner: Arc::new(RwLock::new(mgr)), } } } diff --git a/lib/src/parser/default_impl/mod.rs b/lib/src/parser/default_impl/mod.rs index 3197bfe..9c99383 100644 --- a/lib/src/parser/default_impl/mod.rs +++ b/lib/src/parser/default_impl/mod.rs @@ -4,6 +4,7 @@ use crate::parser::*; use smallvec::smallvec; use std::rc::Rc; +use std::sync::Arc; /// /// A -> Aα | β @@ -366,13 +367,13 @@ impl> DefaultParserImpl { Err(ParseError::UnexpectedToken(0, vec![format!("{:?}", tok)])) } - fn parse_enum_field_decl(&mut self) -> ParseResult> { + fn parse_enum_field_decl(&mut self) -> ParseResult> { let field_name = self.except_identifier()?; let pos = self.next; if matches!(*self.next_kind()?, TokenKind::Assign) { if let TokenKind::Literal(literal) = self.next_kind()? { - return Ok(Some(Rc::new(Variable::with_initial( + return Ok(Some(Arc::new(Variable::with_initial( field_name, Box::new(Expression::new_literal(literal.clone())), )))); @@ -380,10 +381,10 @@ impl> DefaultParserImpl { } self.next = pos; - Ok(Some(Rc::new(Variable::new(field_name)))) + Ok(Some(Arc::new(Variable::new(field_name)))) } - fn parse_global_variable_declare_factor(&mut self) -> ParseResult>> { + fn parse_global_variable_declare_factor(&mut self) -> ParseResult>> { let mut v = smallvec![]; loop { if !self.has_next() { @@ -401,7 +402,7 @@ impl> DefaultParserImpl { Ok(Some(v)) } - fn parse_global_variable_group(&mut self) -> ParseResult>> { + fn parse_global_variable_group(&mut self) -> ParseResult>> { let pos = self.next; let tok = self.next_kind()?; @@ -420,7 +421,7 @@ impl> DefaultParserImpl { ))) } - fn parse_variable_declare_factor(&mut self) -> ParseResult>> { + fn parse_variable_declare_factor(&mut self) -> ParseResult>> { let mut v = SmallVec8::new(); while let Some(mut x) = self.parse_variable_group()? { v.append(&mut x); @@ -429,7 +430,7 @@ impl> DefaultParserImpl { Ok(Some(v)) } - fn parse_variable_group(&mut self) -> ParseResult>> { + fn parse_variable_group(&mut self) -> ParseResult>> { let pos = self.next; let group_type = match self.parse_variable_group_start()? { Some(x) => x, @@ -487,7 +488,7 @@ impl> DefaultParserImpl { Ok(Some(y)) } - fn except_variable_declare_list(&mut self) -> Result>, ParseError> { + fn except_variable_declare_list(&mut self) -> Result>, ParseError> { let mut variables = smallvec![]; while let Some(mut v) = self.expect_single_line_variable_declare()? { @@ -497,7 +498,7 @@ impl> DefaultParserImpl { Ok(variables) } - fn expect_single_line_variable_declare(&mut self) -> ParseResult>> { + fn expect_single_line_variable_declare(&mut self) -> ParseResult>> { let pos = self.next; let mut name_list = match self.next_kind()? { TokenKind::Identifier(s) => smallvec![s.to_owned()], diff --git a/lib/src/parser/lalrpop_impl/st.lalrpop b/lib/src/parser/lalrpop_impl/st.lalrpop index 07f7521..62f8f1e 100644 --- a/lib/src/parser/lalrpop_impl/st.lalrpop +++ b/lib/src/parser/lalrpop_impl/st.lalrpop @@ -1,6 +1,6 @@ use crate::ast::*; use crate::parser::*; -use std::rc::Rc; +use std::sync::Arc; use smallvec::smallvec; grammar; @@ -277,9 +277,9 @@ TypeDeclaration: Declaration = { ":" "STRUCT" "END_STRUCT" => Declaration::struct_(Box::new(StructDeclare::new(<>))), } -EnumFieldDecl: Rc = { - => Rc::new(Variable::new(name)), - ":=" => Rc::new(Variable::with_initial(name, Box::new(value.into_expression()))), +EnumFieldDecl: Arc = { + => Arc::new(Variable::new(name)), + ":=" => Arc::new(Variable::with_initial(name, Box::new(value.into_expression()))), } /// Type @@ -303,23 +303,23 @@ RangeExpr: RangeExpression = { } /// Variable declare groups flat -VariableDeclareFactor: SmallVec8> = { +VariableDeclareFactor: SmallVec8> = { VariableDeclareGroup, => { v.append(&mut e); v } } -GlobalVarDeclareFactor: SmallVec8> = { +GlobalVarDeclareFactor: SmallVec8> = { GlobalVarDeclGroup, => { v.append(&mut e); v } } /// Single variable declare group, constain a list of same scope variable -VariableDeclareGroup: SmallVec8> = { +VariableDeclareGroup: SmallVec8> = { VariableDeclareGroupStart VariableDeclareGroupAnnotation? "END_VAR" => smallvec![], "END_VAR" => VariableDeclareGroup::from_variables(anno.unwrap_or(VariableFlags::NONE) | g, v), } -GlobalVarDeclGroup: SmallVec8> = { +GlobalVarDeclGroup: SmallVec8> = { "VAR_GLOBAL" VariableDeclareGroupAnnotation? "END_VAR" => smallvec![], "VAR_GLOBAL" "END_VAR" => VariableDeclareGroup::from_variables(anno.unwrap_or(VariableFlags::NONE) | VariableFlags::GLOBAL, v), } @@ -341,7 +341,7 @@ VariableDeclareGroupAnnotation: VariableFlags = { } /// A list of same scope varaible -VariableDeclareList: SmallVec8> = { +VariableDeclareList: SmallVec8> = { MultiVariableDeclareStatement, VariableDeclareStatement => smallvec![<>], => { v.push(e); v }, @@ -349,11 +349,11 @@ VariableDeclareList: SmallVec8> = { } /// Single variable declare -VariableDeclareStatement: Rc = { - ":" ";" => Rc::new(Variable::with_type(<>)), +VariableDeclareStatement: Arc = { + ":" ";" => Arc::new(Variable::with_type(<>)), } /// Multiple variable declare in one statement -MultiVariableDeclareStatement: SmallVec8> = { +MultiVariableDeclareStatement: SmallVec8> = { > ":" ";" => Variable::multiple_variable_with_type(<>), } \ No newline at end of file diff --git a/lib/src/utils/attrmap.rs b/lib/src/utils/attrmap.rs index edbad1a..61983b4 100644 --- a/lib/src/utils/attrmap.rs +++ b/lib/src/utils/attrmap.rs @@ -1,4 +1,4 @@ -use once_cell::unsync::Lazy; +use once_cell::sync::Lazy; use smallmap::Map; use crate::prelude::StString; diff --git a/lsp/src/lsp.rs b/lsp/src/lsp.rs index f84131d..13919a7 100644 --- a/lsp/src/lsp.rs +++ b/lsp/src/lsp.rs @@ -3,6 +3,7 @@ use dashmap::DashMap; use ropey::Rope; use serde_json::Value; use stc::parser::{StLexerBuilder, TokenKind}; +use stc::prelude::UnitsManager; use strum::IntoEnumIterator; use tower_lsp::jsonrpc::Result; use tower_lsp::lsp_types::*; @@ -32,6 +33,7 @@ fn semantic_token_type_id(tok: &TokenKind) -> (u32, u32) { pub struct StcLsp { client: Client, src_mgr: DashMap, + units_mgr: UnitsManager, } impl StcLsp { @@ -39,6 +41,7 @@ impl StcLsp { Self { client: c, src_mgr: DashMap::new(), + units_mgr: UnitsManager::new(), } } }