diff options
author | Aleksey Kladov <[email protected]> | 2019-04-13 09:29:47 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-04-13 09:29:47 +0100 |
commit | b260641e0caa3938151afe66fa3bf5691b8c3caa (patch) | |
tree | 5af23f20b86fcec3b13b1315237ba73ff9aa9dcd /crates/ra_hir/src/expr | |
parent | f9e825d95624129b66c34f25904f6ae46b9d5760 (diff) |
slight encapsulation
Diffstat (limited to 'crates/ra_hir/src/expr')
-rw-r--r-- | crates/ra_hir/src/expr/scope.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs index 090343d12..7f53f23aa 100644 --- a/crates/ra_hir/src/expr/scope.rs +++ b/crates/ra_hir/src/expr/scope.rs | |||
@@ -18,7 +18,7 @@ impl_arena_id!(ScopeId); | |||
18 | pub struct ExprScopes { | 18 | pub struct ExprScopes { |
19 | body: Arc<Body>, | 19 | body: Arc<Body>, |
20 | scopes: Arena<ScopeId, ScopeData>, | 20 | scopes: Arena<ScopeId, ScopeData>, |
21 | pub(crate) scope_for: FxHashMap<ExprId, ScopeId>, | 21 | scope_by_expr: FxHashMap<ExprId, ScopeId>, |
22 | } | 22 | } |
23 | 23 | ||
24 | #[derive(Debug, PartialEq, Eq)] | 24 | #[derive(Debug, PartialEq, Eq)] |
@@ -54,7 +54,7 @@ impl ExprScopes { | |||
54 | let mut scopes = ExprScopes { | 54 | let mut scopes = ExprScopes { |
55 | body: body.clone(), | 55 | body: body.clone(), |
56 | scopes: Arena::default(), | 56 | scopes: Arena::default(), |
57 | scope_for: FxHashMap::default(), | 57 | scope_by_expr: FxHashMap::default(), |
58 | }; | 58 | }; |
59 | let root = scopes.root_scope(); | 59 | let root = scopes.root_scope(); |
60 | scopes.add_params_bindings(root, body.params()); | 60 | scopes.add_params_bindings(root, body.params()); |
@@ -73,6 +73,14 @@ impl ExprScopes { | |||
73 | std::iter::successors(scope, move |&scope| self.scopes[scope].parent) | 73 | std::iter::successors(scope, move |&scope| self.scopes[scope].parent) |
74 | } | 74 | } |
75 | 75 | ||
76 | pub(crate) fn scope_for(&self, expr: ExprId) -> Option<ScopeId> { | ||
77 | self.scope_by_expr.get(&expr).map(|&scope| scope) | ||
78 | } | ||
79 | |||
80 | pub(crate) fn scope_by_expr(&self) -> &FxHashMap<ExprId, ScopeId> { | ||
81 | &self.scope_by_expr | ||
82 | } | ||
83 | |||
76 | fn root_scope(&mut self) -> ScopeId { | 84 | fn root_scope(&mut self) -> ScopeId { |
77 | self.scopes.alloc(ScopeData { parent: None, entries: vec![] }) | 85 | self.scopes.alloc(ScopeData { parent: None, entries: vec![] }) |
78 | } | 86 | } |
@@ -99,11 +107,7 @@ impl ExprScopes { | |||
99 | } | 107 | } |
100 | 108 | ||
101 | fn set_scope(&mut self, node: ExprId, scope: ScopeId) { | 109 | fn set_scope(&mut self, node: ExprId, scope: ScopeId) { |
102 | self.scope_for.insert(node, scope); | 110 | self.scope_by_expr.insert(node, scope); |
103 | } | ||
104 | |||
105 | pub(crate) fn scope_for(&self, expr: ExprId) -> Option<ScopeId> { | ||
106 | self.scope_for.get(&expr).map(|&scope| scope) | ||
107 | } | 111 | } |
108 | } | 112 | } |
109 | 113 | ||