mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-03 02:23:20 +00:00
slight encapsulation
This commit is contained in:
parent
f9e825d956
commit
b260641e0c
@ -18,7 +18,7 @@ impl_arena_id!(ScopeId);
|
||||
pub struct ExprScopes {
|
||||
body: Arc<Body>,
|
||||
scopes: Arena<ScopeId, ScopeData>,
|
||||
pub(crate) scope_for: FxHashMap<ExprId, ScopeId>,
|
||||
scope_by_expr: FxHashMap<ExprId, ScopeId>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
@ -54,7 +54,7 @@ impl ExprScopes {
|
||||
let mut scopes = ExprScopes {
|
||||
body: body.clone(),
|
||||
scopes: Arena::default(),
|
||||
scope_for: FxHashMap::default(),
|
||||
scope_by_expr: FxHashMap::default(),
|
||||
};
|
||||
let root = scopes.root_scope();
|
||||
scopes.add_params_bindings(root, body.params());
|
||||
@ -73,6 +73,14 @@ impl ExprScopes {
|
||||
std::iter::successors(scope, move |&scope| self.scopes[scope].parent)
|
||||
}
|
||||
|
||||
pub(crate) fn scope_for(&self, expr: ExprId) -> Option<ScopeId> {
|
||||
self.scope_by_expr.get(&expr).map(|&scope| scope)
|
||||
}
|
||||
|
||||
pub(crate) fn scope_by_expr(&self) -> &FxHashMap<ExprId, ScopeId> {
|
||||
&self.scope_by_expr
|
||||
}
|
||||
|
||||
fn root_scope(&mut self) -> ScopeId {
|
||||
self.scopes.alloc(ScopeData { parent: None, entries: vec![] })
|
||||
}
|
||||
@ -99,11 +107,7 @@ impl ExprScopes {
|
||||
}
|
||||
|
||||
fn set_scope(&mut self, node: ExprId, scope: ScopeId) {
|
||||
self.scope_for.insert(node, scope);
|
||||
}
|
||||
|
||||
pub(crate) fn scope_for(&self, expr: ExprId) -> Option<ScopeId> {
|
||||
self.scope_for.get(&expr).map(|&scope| scope)
|
||||
self.scope_by_expr.insert(node, scope);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -368,7 +368,7 @@ fn scope_for_offset(
|
||||
offset: TextUnit,
|
||||
) -> Option<ScopeId> {
|
||||
scopes
|
||||
.scope_for
|
||||
.scope_by_expr()
|
||||
.iter()
|
||||
.filter_map(|(id, scope)| Some((source_map.expr_syntax(*id)?, scope)))
|
||||
// find containing scope
|
||||
@ -388,7 +388,7 @@ fn adjust(
|
||||
) -> Option<ScopeId> {
|
||||
let r = ptr.range();
|
||||
let child_scopes = scopes
|
||||
.scope_for
|
||||
.scope_by_expr()
|
||||
.iter()
|
||||
.filter_map(|(id, scope)| Some((source_map.expr_syntax(*id)?, scope)))
|
||||
.map(|(ptr, scope)| (ptr.range(), scope))
|
||||
|
Loading…
Reference in New Issue
Block a user