Skip to content

Commit

Permalink
rework: return concrete path type from symbols instead of opaque `&Sy…
Browse files Browse the repository at this point in the history
…mbolPath`
  • Loading branch information
SpontanCombust committed Aug 17, 2024
1 parent a917796 commit d4f00d6
Show file tree
Hide file tree
Showing 22 changed files with 167 additions and 108 deletions.
20 changes: 10 additions & 10 deletions crates/analysis/src/jobs/scan_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ impl SyntaxNodeVisitor for SymbolScannerVisitor<'_> {
.filter_map(|s| StructSpecifier::try_from(s).ok())
.collect();

sym.path().clone_into(&mut self.current_path);
sym.path_ref().clone_into(&mut self.current_path);
self.symtab.insert_primary_symbol(sym);

let constr_path = GlobalCallableSymbolPath::new(&struct_name);
Expand All @@ -383,7 +383,7 @@ impl SyntaxNodeVisitor for SymbolScannerVisitor<'_> {
});
constr_sym.parent_type_path = path;

self.current_constr_path = Some(constr_sym.path().to_owned());
self.current_constr_path = Some(constr_sym.path_ref().to_owned());
self.symtab.insert_primary_symbol(constr_sym);

traverse_definition = true;
Expand Down Expand Up @@ -418,7 +418,7 @@ impl SyntaxNodeVisitor for SymbolScannerVisitor<'_> {
label_range: name_node.range()
});

sym.path().clone_into(&mut self.current_path);
sym.path_ref().clone_into(&mut self.current_path);
self.symtab.insert_primary_symbol(sym);

traverse_definition = true;
Expand Down Expand Up @@ -488,7 +488,7 @@ impl SyntaxNodeVisitor for SymbolScannerVisitor<'_> {
if self.check_contains(&path, name_node.range(), SymbolType::MemberFunctionInjector) {
let sym = MemberFunctionInjectorSymbol::new(self.parse_member_function(n, path));

sym.path().clone_into(&mut self.current_path);
sym.path_ref().clone_into(&mut self.current_path);
self.symtab.insert_primary_symbol(sym);

traverse = true;
Expand All @@ -500,7 +500,7 @@ impl SyntaxNodeVisitor for SymbolScannerVisitor<'_> {
if self.check_contains(&path, name_node.range(), SymbolType::MemberFunctionReplacer) {
let sym = MemberFunctionReplacerSymbol::new(self.parse_member_function(n, path));

sym.path().clone_into(&mut self.current_path);
sym.path_ref().clone_into(&mut self.current_path);
self.symtab.insert_primary_symbol(sym);

traverse = true;
Expand All @@ -510,7 +510,7 @@ impl SyntaxNodeVisitor for SymbolScannerVisitor<'_> {
if self.check_contains(&path, name_node.range(), SymbolType::GlobalFunctionReplacer) {
let sym = GlobalFunctionReplacerSymbol::new(self.parse_global_function(n, path));

sym.path().clone_into(&mut self.current_path);
sym.path_ref().clone_into(&mut self.current_path);
self.symtab.insert_primary_symbol(sym);

traverse = true;
Expand All @@ -524,7 +524,7 @@ impl SyntaxNodeVisitor for SymbolScannerVisitor<'_> {
let wrapped_sym = WrappedMethodSymbol::new(&path);
let sym = MemberFunctionWrapperSymbol::new(self.parse_member_function(n, path));

sym.path().clone_into(&mut self.current_path);
sym.path_ref().clone_into(&mut self.current_path);
self.symtab.insert_primary_symbol(sym);
self.symtab.insert_symbol(wrapped_sym);

Expand All @@ -538,7 +538,7 @@ impl SyntaxNodeVisitor for SymbolScannerVisitor<'_> {
if self.check_contains(&path, name_node.range(), SymbolType::GlobalFunction) {
let sym = self.parse_global_function(n, path);

sym.path().clone_into(&mut self.current_path);
sym.path_ref().clone_into(&mut self.current_path);
self.symtab.insert_primary_symbol(sym);

traverse = true;
Expand Down Expand Up @@ -622,7 +622,7 @@ impl SyntaxNodeVisitor for SymbolScannerVisitor<'_> {
if self.check_contains(&path, name_node.range(), SymbolType::MemberFunction) {
let sym = self.parse_member_function(n, path);

sym.path().clone_into(&mut self.current_path);
sym.path_ref().clone_into(&mut self.current_path);
self.symtab.insert_symbol(sym);

traverse = true;
Expand Down Expand Up @@ -660,7 +660,7 @@ impl SyntaxNodeVisitor for SymbolScannerVisitor<'_> {
label_range: name_node.range()
});

sym.path().clone_into(&mut self.current_path);
sym.path_ref().clone_into(&mut self.current_path);
self.symtab.insert_symbol(sym);

traverse = true;
Expand Down
2 changes: 1 addition & 1 deletion crates/analysis/src/jobs/workspace_symbol_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn workspace_symbol_analysis(target_symtab: &SymbolTable, marcher: SymbolTab
.filter(|p| !matches!(p.typ(), SymbolType::MemberFunctionWrapper | SymbolType::MemberFunctionReplacer | SymbolType::GlobalFunctionReplacer))
.filter_map(|primary| {
let primary_loc = primary.location().unwrap(); // primary symbols always have location
if let Err(err) = marcher.test_contains_symbol(primary.path()) {
if let Err(err) = marcher.test_contains_symbol(primary.path_ref()) {
Some(LocatedDiagnostic {
path: primary_loc.abs_source_path(),
diagnostic: Diagnostic {
Expand Down
6 changes: 3 additions & 3 deletions crates/analysis/src/symbol_analysis/symbol_table/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'st, F> FilteredSymbolChildren<'st, F>
where F: ChildrenSymbolsFilter<'st> {
pub(super) fn new(symtab: &'st SymbolTable, symbol: &F) -> Self {
Self {
iter: SymbolChildren::new(symtab, symbol.path()),
iter: SymbolChildren::new(symtab, symbol.path_ref()),
filter_phantom: PhantomData
}
}
Expand Down Expand Up @@ -312,8 +312,8 @@ impl<'st> Iterator for FileSymbols<'st> {
// Their symbol paths can reference symbols from other source paths.
// We have to skip over them and all of their children.
if item.location().map(|loc| loc.local_source_path.as_ref() != self.local_source_path).unwrap_or(false) {
let injector_path = item.path().to_owned();
self.iter.find(|v| !v.path().starts_with(&injector_path))
let injector_path = item.path_ref().to_owned();
self.iter.find(|v| !v.path_ref().starts_with(&injector_path))
} else {
Some(item)
}
Expand Down
6 changes: 3 additions & 3 deletions crates/analysis/src/symbol_analysis/symbol_table/marcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<'a> SymbolTableMarcher<'a> {
#[inline]
pub fn find_table_with_symbol(&self, symvar: &SymbolVariant) -> Option<&'a SymbolTable> {
self.march(|masked| {
if masked.get_symbol(symvar.path()).filter(|v| v.location() == symvar.location()).is_some() {
if masked.get_symbol(symvar.path_ref()).filter(|v| v.location() == symvar.location()).is_some() {
Some(masked.symtab)
} else {
None
Expand Down Expand Up @@ -173,7 +173,7 @@ impl<'a> MaskedSymbolTable<'a> {
fn test_contains_symbol(&self, path: &SymbolPath) -> Result<(), PathOccupiedError> {
if let Some(occupying) = self.get_symbol(path) {
Err(PathOccupiedError {
occupied_path: occupying.path().to_sympath_buf(),
occupied_path: occupying.path_ref().to_sympath_buf(),
occupied_location: occupying.location().cloned(),
occupied_typ: occupying.typ()
})
Expand Down Expand Up @@ -288,7 +288,7 @@ impl<'a> Iterator for StateHierarchy<'a> {
'classes: for class in self.marcher.class_hierarchy(current_state_sym.parent_class_path()) {
for state in self.marcher.class_states(class.path()) {
if state.state_name() == base_state_name {
state.path().clone_into(&mut self.current_state_path);
state.path_ref().clone_into(&mut self.current_state_path);
break 'classes;
}
}
Expand Down
20 changes: 10 additions & 10 deletions crates/analysis/src/symbol_analysis/symbol_table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,25 @@ impl SymbolTable {

pub(crate) fn insert_symbol<S>(&mut self, sym: S)
where S: Symbol + Into<SymbolVariant> {
self.symbols.insert(sym.path().to_owned(), sym.into());
self.symbols.insert(sym.path_ref().to_owned(), sym.into());
}

pub(crate) fn insert_primary_symbol<S>(&mut self, sym: S)
where S: PrimarySymbol + LocatableSymbol + Into<SymbolVariant> {
self.source_path_assocs.entry(sym.location().local_source_path.clone())
.or_default()
.push(sym.path().to_owned());
.push(sym.path_ref().to_owned());

self.symbols.insert(sym.path().to_owned(), sym.into());
self.symbols.insert(sym.path_ref().to_owned(), sym.into());
}

pub(crate) fn insert_array_type_symbol(&mut self, sym: ArrayTypeSymbol, ref_local_source_path: &Path) {
self.array_type_refs
.entry(sym.path().to_owned())
.entry(sym.path_ref().to_owned())
.or_default()
.insert(ref_local_source_path.to_owned());

self.symbols.insert(sym.path().to_owned(), sym.into());
self.symbols.insert(sym.path_ref().to_owned(), sym.into());
}


Expand All @@ -97,7 +97,7 @@ impl SymbolTable {
pub fn test_contains_symbol(&self, path: &SymbolPath) -> Result<(), PathOccupiedError> {
if let Some(occupying) = self.symbols.get(path) {
Err(PathOccupiedError {
occupied_path: occupying.path().to_sympath_buf(),
occupied_path: occupying.path_ref().to_sympath_buf(),
occupied_location: occupying.location().cloned(),
occupied_typ: occupying.typ()
})
Expand All @@ -121,7 +121,7 @@ impl SymbolTable {
pub fn remove_symbols_for_source(&mut self, local_source_path: &Path) {
let for_removal: Vec<_> =
self.get_symbols_for_source(local_source_path)
.map(|sym| sym.path().to_owned())
.map(|sym| sym.path_ref().to_owned())
.collect();

for sympath in for_removal {
Expand All @@ -143,7 +143,7 @@ impl SymbolTable {
for (array_sympath, refs) in self.array_type_refs.iter() {
if refs.is_empty() {
for_removal.push(array_sympath.to_owned());
for_removal.extend(self.get_symbol_descendants(&array_sympath).map(|v| v.path().to_owned()));
for_removal.extend(self.get_symbol_descendants(&array_sympath).map(|v| v.path_ref().to_owned()));
}
}

Expand Down Expand Up @@ -212,13 +212,13 @@ impl SymbolTable {
if let Some(occupying_variant) = self.symbols.get(&incoming_sympath) {
incoming_sympath.clone_into(&mut sympath_to_skip);

if occupying_variant.is_array() || occupying_variant.path().has_missing() {
if occupying_variant.is_array() || occupying_variant.path_ref().has_missing() {
continue;
}

if let Some(incoming_location) = incoming_variant.location().cloned() {
errors.push(MergeConflictError {
occupied_path: occupying_variant.path().to_owned(),
occupied_path: occupying_variant.path_ref().to_owned(),
occupied_typ: occupying_variant.typ(),
occupied_location: occupying_variant.location().cloned(),
incoming_typ: incoming_variant.typ(),
Expand Down
25 changes: 18 additions & 7 deletions crates/analysis/src/symbol_analysis/symbols/annotated_symbols.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use witcherscript::ast::WRAPPED_METHOD_NAME;
use crate::symbol_analysis::symbol_path::SymbolPath;
use super::*;


Expand All @@ -10,11 +9,13 @@ pub struct MemberFunctionInjectorSymbol {
}

impl Symbol for MemberFunctionInjectorSymbol {
type PathType = MemberCallableSymbolPath;

fn typ(&self) -> SymbolType {
SymbolType::MemberFunctionInjector
}

fn path(&self) -> &SymbolPath {
fn path(&self) -> &Self::PathType {
&self.backer.path()
}
}
Expand Down Expand Up @@ -44,11 +45,13 @@ pub struct MemberFunctionReplacerSymbol {
}

impl Symbol for MemberFunctionReplacerSymbol {
type PathType = MemberCallableSymbolPath;

fn typ(&self) -> SymbolType {
SymbolType::MemberFunctionReplacer
}

fn path(&self) -> &SymbolPath {
fn path(&self) -> &Self::PathType {
&self.backer.path()
}
}
Expand Down Expand Up @@ -78,11 +81,13 @@ pub struct GlobalFunctionReplacerSymbol {
}

impl Symbol for GlobalFunctionReplacerSymbol {
type PathType = GlobalCallableSymbolPath;

fn typ(&self) -> SymbolType {
SymbolType::GlobalFunctionReplacer
}

fn path(&self) -> &SymbolPath {
fn path(&self) -> &Self::PathType {
&self.backer.path()
}
}
Expand Down Expand Up @@ -112,11 +117,13 @@ pub struct MemberFunctionWrapperSymbol {
}

impl Symbol for MemberFunctionWrapperSymbol {
type PathType = MemberCallableSymbolPath;

fn typ(&self) -> SymbolType {
SymbolType::MemberFunctionWrapper
}

fn path(&self) -> &SymbolPath {
fn path(&self) -> &Self::PathType {
&self.backer.path()
}
}
Expand Down Expand Up @@ -146,11 +153,13 @@ pub struct WrappedMethodSymbol {
}

impl Symbol for WrappedMethodSymbol {
type PathType = MemberCallableSymbolPath;

fn typ(&self) -> SymbolType {
SymbolType::WrappedMethod
}

fn path(&self) -> &SymbolPath {
fn path(&self) -> &Self::PathType {
&self.path
}
}
Expand All @@ -177,11 +186,13 @@ pub struct MemberVarInjectorSymbol {
}

impl Symbol for MemberVarInjectorSymbol {
type PathType = MemberDataSymbolPath;

fn typ(&self) -> SymbolType {
SymbolType::MemberVarInjector
}

fn path(&self) -> &SymbolPath {
fn path(&self) -> &Self::PathType {
&self.backer.path()
}
}
Expand Down
13 changes: 9 additions & 4 deletions crates/analysis/src/symbol_analysis/symbols/array_type_symbol.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::symbol_analysis::symbol_path::SymbolPath;
use super::*;


Expand All @@ -8,11 +7,13 @@ pub struct ArrayTypeSymbol {
}

impl Symbol for ArrayTypeSymbol {
type PathType = ArrayTypeSymbolPath;

fn typ(&self) -> SymbolType {
SymbolType::Array
}

fn path(&self) -> &SymbolPath {
fn path(&self) -> &Self::PathType {
&self.path
}
}
Expand Down Expand Up @@ -257,11 +258,13 @@ pub struct ArrayTypeFunctionSymbol {
}

impl Symbol for ArrayTypeFunctionSymbol {
type PathType = MemberCallableSymbolPath;

fn typ(&self) -> SymbolType {
SymbolType::MemberFunction
}

fn path(&self) -> &SymbolPath {
fn path(&self) -> &Self::PathType {
&self.path
}
}
Expand All @@ -282,11 +285,13 @@ pub struct ArrayTypeFunctionParameterSymbol {
}

impl Symbol for ArrayTypeFunctionParameterSymbol {
type PathType = MemberDataSymbolPath;

fn typ(&self) -> SymbolType {
SymbolType::Parameter
}

fn path(&self) -> &SymbolPath {
fn path(&self) -> &Self::PathType {
&self.path
}
}
Expand Down
Loading

0 comments on commit d4f00d6

Please sign in to comment.