diff options
Diffstat (limited to 'crates/hir_def/src/body.rs')
-rw-r--r-- | crates/hir_def/src/body.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/crates/hir_def/src/body.rs b/crates/hir_def/src/body.rs index 19c4eb521..8bcc350ce 100644 --- a/crates/hir_def/src/body.rs +++ b/crates/hir_def/src/body.rs | |||
@@ -253,11 +253,18 @@ pub type LabelSource = InFile<LabelPtr>; | |||
253 | pub struct BodySourceMap { | 253 | pub struct BodySourceMap { |
254 | expr_map: FxHashMap<ExprSource, ExprId>, | 254 | expr_map: FxHashMap<ExprSource, ExprId>, |
255 | expr_map_back: ArenaMap<ExprId, Result<ExprSource, SyntheticSyntax>>, | 255 | expr_map_back: ArenaMap<ExprId, Result<ExprSource, SyntheticSyntax>>, |
256 | |||
256 | pat_map: FxHashMap<PatSource, PatId>, | 257 | pat_map: FxHashMap<PatSource, PatId>, |
257 | pat_map_back: ArenaMap<PatId, Result<PatSource, SyntheticSyntax>>, | 258 | pat_map_back: ArenaMap<PatId, Result<PatSource, SyntheticSyntax>>, |
259 | |||
258 | label_map: FxHashMap<LabelSource, LabelId>, | 260 | label_map: FxHashMap<LabelSource, LabelId>, |
259 | label_map_back: ArenaMap<LabelId, LabelSource>, | 261 | label_map_back: ArenaMap<LabelId, LabelSource>, |
260 | field_map: FxHashMap<(ExprId, usize), InFile<AstPtr<ast::RecordExprField>>>, | 262 | |
263 | /// We don't create explicit nodes for record fields (`S { record_field: 92 }`). | ||
264 | /// Instead, we use id of expression (`92`) to identify the field. | ||
265 | field_map: FxHashMap<InFile<AstPtr<ast::RecordExprField>>, ExprId>, | ||
266 | field_map_back: FxHashMap<ExprId, InFile<AstPtr<ast::RecordExprField>>>, | ||
267 | |||
261 | expansions: FxHashMap<InFile<AstPtr<ast::MacroCall>>, HirFileId>, | 268 | expansions: FxHashMap<InFile<AstPtr<ast::MacroCall>>, HirFileId>, |
262 | 269 | ||
263 | /// Diagnostics accumulated during body lowering. These contain `AstPtr`s and so are stored in | 270 | /// Diagnostics accumulated during body lowering. These contain `AstPtr`s and so are stored in |
@@ -337,6 +344,8 @@ impl Index<LabelId> for Body { | |||
337 | } | 344 | } |
338 | } | 345 | } |
339 | 346 | ||
347 | // FIXME: Change `node_` prefix to something more reasonable. | ||
348 | // Perhaps `expr_syntax` and `expr_id`? | ||
340 | impl BodySourceMap { | 349 | impl BodySourceMap { |
341 | pub fn expr_syntax(&self, expr: ExprId) -> Result<ExprSource, SyntheticSyntax> { | 350 | pub fn expr_syntax(&self, expr: ExprId) -> Result<ExprSource, SyntheticSyntax> { |
342 | self.expr_map_back[expr].clone() | 351 | self.expr_map_back[expr].clone() |
@@ -375,8 +384,12 @@ impl BodySourceMap { | |||
375 | self.label_map.get(&src).cloned() | 384 | self.label_map.get(&src).cloned() |
376 | } | 385 | } |
377 | 386 | ||
378 | pub fn field_syntax(&self, expr: ExprId, field: usize) -> InFile<AstPtr<ast::RecordExprField>> { | 387 | pub fn field_syntax(&self, expr: ExprId) -> InFile<AstPtr<ast::RecordExprField>> { |
379 | self.field_map[&(expr, field)].clone() | 388 | self.field_map_back[&expr].clone() |
389 | } | ||
390 | pub fn node_field(&self, node: InFile<&ast::RecordExprField>) -> Option<ExprId> { | ||
391 | let src = node.map(|it| AstPtr::new(it)); | ||
392 | self.field_map.get(&src).cloned() | ||
380 | } | 393 | } |
381 | 394 | ||
382 | pub(crate) fn add_diagnostics(&self, _db: &dyn DefDatabase, sink: &mut DiagnosticSink<'_>) { | 395 | pub(crate) fn add_diagnostics(&self, _db: &dyn DefDatabase, sink: &mut DiagnosticSink<'_>) { |