Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions slicec/src/grammar/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

use super::attributes::AttributeKind;
use super::comments::DocComment;
use super::elements::{Attribute, Identifier, Integer, Module, TypeRef};
use super::util::Scope;
use super::elements::{Attribute, Identifier, Integer, TypeRef};
use super::wrappers::{AsEntities, AsTypes};
use crate::slice_file::Span;

Expand All @@ -18,8 +17,6 @@ pub trait Symbol: Element {
pub trait ScopedSymbol: Symbol {
fn parser_scope(&self) -> &str;
fn module_scope(&self) -> &str;
fn get_module(&self) -> &Module;
fn get_raw_scope(&self) -> &Scope;
}
Comment on lines 17 to 20

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It definitely is removed. Copilot is not reviewing the latest commit here? Idk.


pub trait NamedSymbol: Symbol + Attributable {
Expand Down Expand Up @@ -121,18 +118,7 @@ macro_rules! implement_Scoped_Symbol_for {
}

fn module_scope(&self) -> &str {
match &self.scope.module {
Some(module_ptr) => module_ptr.borrow().nested_module_identifier(),
None => "",
}
}

fn get_module(&self) -> &Module {
self.scope.module.as_ref().unwrap().borrow()
}

fn get_raw_scope(&self) -> &Scope {
&self.scope
&self.scope.module_scope
}
}
};
Expand Down
15 changes: 4 additions & 11 deletions slicec/src/grammar/util.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// Copyright (c) ZeroC, Inc.

use super::Module;
use crate::utils::ptr_util::WeakPtr;

#[derive(Clone, Debug, Default)]
pub struct Scope {
pub parser_scope: String,
pub module: Option<WeakPtr<Module>>,
pub module_scope: String,
}

impl Scope {
Expand All @@ -21,16 +18,12 @@ impl Scope {
if let Some(last_scope_index) = self.parser_scope.rfind("::") {
// Remove any characters after the last '::' in the string.
// We ensure that we're only removing additional parser scopes, and not any scopes that came from a module.
#[cfg(debug_assertions)]
{
let module_scope = self.module.as_ref().map(|m| m.borrow().nested_module_identifier());
debug_assert!(self.parser_scope.len() > module_scope.map_or(0, str::len))
}
debug_assert!(self.parser_scope.len() > self.module_scope.len());
self.parser_scope.truncate(last_scope_index);
} else {
// If the string doesn't contain '::', there's only a single scope. We pop it off by clearing the string.
// This is only possible if we're not in a module, otherwise we'd always have at least 1 module scope.
debug_assert!(self.module.is_none());
// This means the user forgot to write a module, which is an error. But we have to handle this gracefully.
debug_assert!(self.module_scope.is_empty());
self.parser_scope.clear();
}
}
Expand Down
11 changes: 5 additions & 6 deletions slicec/src/parsers/slice/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,14 @@ fn construct_module(
.push_into(parser.diagnostics);
}

let module_ptr = OwnedPtr::new(Module {
parser.current_scope.module_scope = identifier.value.clone();
parser.current_scope.parser_scope = identifier.value.clone();

OwnedPtr::new(Module {
identifier,
attributes,
span,
});

parser.current_scope.module = Some(module_ptr.downgrade());
parser.current_scope.parser_scope = module_ptr.borrow().nested_module_identifier().to_owned();
module_ptr
})
}

fn construct_struct(
Expand Down