-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : namer for new architecture of semantic model (#762)
* feat : namer for new architecture of semantic model Signed-off-by: never <[email protected]> * feat: namer add symbol_db Signed-off-by: never <[email protected]> --------- Signed-off-by: never <[email protected]>
- Loading branch information
Showing
23 changed files
with
1,230 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod global_state; | ||
pub mod package; | ||
pub mod symbol; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} | ||
} |
Oops, something went wrong.