Skip to content

Commit

Permalink
feat : namer for new architecture of semantic model
Browse files Browse the repository at this point in the history
Signed-off-by: never <[email protected]>
  • Loading branch information
NeverRaR committed Oct 13, 2023
1 parent 93eb9d7 commit 4495df4
Show file tree
Hide file tree
Showing 18 changed files with 1,071 additions and 9 deletions.
10 changes: 10 additions & 0 deletions kclvm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions kclvm/sema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
generational-arena = "0.2.9"
phf = { version = "0.9", features = ["macros"] }
ahash = "0.7.2"
indexmap = "1.0"
Expand All @@ -20,22 +21,21 @@ regex = "1.7.0"
lazy_static = "1.4.0"
pcre2 = "*"

kclvm-ast = {path = "../ast"}
kclvm-ast-pretty = {path = "../ast_pretty"}
kclvm-runtime = {path = "../runtime"}
kclvm-error = {path = "../error"}
kclvm-span = {path = "../span"}
compiler_base_span = {path = "../../compiler_base/span", version = "0.0.2"}
compiler_base_session = {path = "../../compiler_base/session"}
kclvm-ast = { path = "../ast" }
kclvm-ast-pretty = { path = "../ast_pretty" }
kclvm-runtime = { path = "../runtime" }
kclvm-error = { path = "../error" }
kclvm-span = { path = "../span" }
compiler_base_span = { path = "../../compiler_base/span", version = "0.0.2" }
compiler_base_session = { path = "../../compiler_base/session" }
compiler_base_macros = "0.0.1"
compiler_base_error = "0.0.8"
suggestions = "0.1.1"

[dev-dependencies]
kclvm-parser = {path = "../parser"}
kclvm-parser = { path = "../parser" }
criterion = "0.3"

[[bench]]
name = "my_benchmark"
harness = false

29 changes: 29 additions & 0 deletions kclvm/sema/src/core/global_state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use super::{package::PackageDB, symbol::KCLSymbolData};

#[derive(Default, Debug)]
pub struct GlobalState {
symbols: KCLSymbolData,
packages: PackageDB,
}

impl GlobalState {
pub fn get_symbols(&self) -> &KCLSymbolData {
&self.symbols
}

pub fn get_symbols_mut(&mut self) -> &mut KCLSymbolData {
&mut self.symbols
}

pub fn get_packages(&self) -> &PackageDB {
&self.packages
}

pub fn get_packages_mut(&mut self) -> &mut PackageDB {
&mut self.packages
}

pub fn resolve_symbols(&mut self) {
self.symbols.replace_unresolved_symbol(&self.packages)
}
}
3 changes: 3 additions & 0 deletions kclvm/sema/src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod global_state;
pub mod package;
pub mod symbol;
89 changes: 89 additions & 0 deletions kclvm/sema/src/core/package.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
use indexmap::IndexMap;

#[derive(Default, Debug)]
pub struct PackageDB {
pub(crate) package_info: IndexMap<String, PackageInfo>,
}

impl PackageDB {
pub fn add_package(&mut self, info: PackageInfo) {
self.package_info
.insert(info.fully_qualified_name.clone(), info);
}

pub fn remove_package_info(&mut self, name: &str) {
self.package_info.remove(name);
}

pub fn get_package_info(&self, name: &str) -> Option<&PackageInfo> {
self.package_info.get(name)
}

pub fn get_package_info_mut(&mut self, name: &str) -> Option<&mut PackageInfo> {
self.package_info.get_mut(name)
}
}
#[derive(Debug)]
pub struct PackageInfo {
pub(crate) fully_qualified_name: String,
pub(crate) modules: IndexMap<String, ModuleInfo>,
pub(crate) imports: IndexMap<String, ImportInfo>,
}

impl PackageInfo {
pub fn new(fully_qualified_name: String) -> Self {
Self {
fully_qualified_name,
modules: IndexMap::default(),
imports: IndexMap::default(),
}
}

pub fn add_import_info(&mut self, info: ImportInfo) {
self.imports.insert(info.fully_qualified_name.clone(), info);
}

pub fn remove_import_info(&mut self, name: &str) {
self.imports.remove(name);
}

pub fn get_import_info(&self, name: &str) -> Option<&ImportInfo> {
self.imports.get(name)
}

pub fn add_module_info(&mut self, info: ModuleInfo) {
self.modules.insert(info.filename.clone(), info);
}

pub fn remove_module_info(&mut self, name: &str) {
self.modules.remove(name);
}

pub fn get_module_info(&self, name: &str) -> Option<&ModuleInfo> {
self.modules.get(name)
}
}
#[derive(Debug)]
pub struct ImportInfo {
pub(crate) unqualified_name: String,
pub(crate) fully_qualified_name: String,
}

impl ImportInfo {
pub fn new(unqualified_name: String, fully_qualified_name: String) -> Self {
Self {
unqualified_name,
fully_qualified_name,
}
}
}
#[derive(Debug)]
pub struct ModuleInfo {
pub(crate) filename: String,
}

impl ModuleInfo {
pub fn new(filename: String) -> Self {
Self { filename }
}
}
Loading

0 comments on commit 4495df4

Please sign in to comment.