aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/expr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/expr.rs')
-rw-r--r--crates/ra_hir/src/expr.rs49
1 files changed, 41 insertions, 8 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index b2a237ece..589a9b2db 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -6,7 +6,7 @@ use rustc_hash::FxHashMap;
6use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap}; 6use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap};
7use ra_syntax::{ 7use ra_syntax::{
8 SyntaxNodePtr, AstPtr, AstNode, 8 SyntaxNodePtr, AstPtr, AstNode,
9 ast::{self, LoopBodyOwner, ArgListOwner, NameOwner, LiteralKind, TypeAscriptionOwner} 9 ast::{self, LoopBodyOwner, ArgListOwner, NameOwner, LiteralKind,ArrayExprKind, TypeAscriptionOwner}
10}; 10};
11 11
12use crate::{ 12use crate::{
@@ -238,14 +238,17 @@ pub enum Expr {
238 Tuple { 238 Tuple {
239 exprs: Vec<ExprId>, 239 exprs: Vec<ExprId>,
240 }, 240 },
241 Array { 241 Array(Array),
242 exprs: Vec<ExprId>,
243 },
244 Literal(Literal), 242 Literal(Literal),
245} 243}
246 244
247pub use ra_syntax::ast::PrefixOp as UnaryOp; 245pub use ra_syntax::ast::PrefixOp as UnaryOp;
248pub use ra_syntax::ast::BinOp as BinaryOp; 246pub use ra_syntax::ast::BinOp as BinaryOp;
247#[derive(Debug, Clone, Eq, PartialEq)]
248pub enum Array {
249 ElementList(Vec<ExprId>),
250 Repeat { initializer: ExprId, repeat: ExprId },
251}
249 252
250#[derive(Debug, Clone, Eq, PartialEq)] 253#[derive(Debug, Clone, Eq, PartialEq)]
251pub struct MatchArm { 254pub struct MatchArm {
@@ -348,11 +351,22 @@ impl Expr {
348 | Expr::UnaryOp { expr, .. } => { 351 | Expr::UnaryOp { expr, .. } => {
349 f(*expr); 352 f(*expr);
350 } 353 }
351 Expr::Tuple { exprs } | Expr::Array { exprs } => { 354 Expr::Tuple { exprs } => {
352 for expr in exprs { 355 for expr in exprs {
353 f(*expr); 356 f(*expr);
354 } 357 }
355 } 358 }
359 Expr::Array(a) => match a {
360 Array::ElementList(exprs) => {
361 for expr in exprs {
362 f(*expr);
363 }
364 }
365 Array::Repeat { initializer, repeat } => {
366 f(*initializer);
367 f(*repeat)
368 }
369 },
356 Expr::Literal(_) => {} 370 Expr::Literal(_) => {}
357 } 371 }
358 } 372 }
@@ -671,7 +685,10 @@ impl ExprCollector {
671 } 685 }
672 ast::ExprKind::FieldExpr(e) => { 686 ast::ExprKind::FieldExpr(e) => {
673 let expr = self.collect_expr_opt(e.expr()); 687 let expr = self.collect_expr_opt(e.expr());
674 let name = e.name_ref().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); 688 let name = match e.field_access() {
689 Some(kind) => kind.as_name(),
690 _ => Name::missing(),
691 };
675 self.alloc_expr(Expr::Field { expr, name }, syntax_ptr) 692 self.alloc_expr(Expr::Field { expr, name }, syntax_ptr)
676 } 693 }
677 ast::ExprKind::TryExpr(e) => { 694 ast::ExprKind::TryExpr(e) => {
@@ -720,10 +737,26 @@ impl ExprCollector {
720 let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect(); 737 let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect();
721 self.alloc_expr(Expr::Tuple { exprs }, syntax_ptr) 738 self.alloc_expr(Expr::Tuple { exprs }, syntax_ptr)
722 } 739 }
740
723 ast::ExprKind::ArrayExpr(e) => { 741 ast::ExprKind::ArrayExpr(e) => {
724 let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect(); 742 let kind = e.kind();
725 self.alloc_expr(Expr::Array { exprs }, syntax_ptr) 743
744 match kind {
745 ArrayExprKind::ElementList(e) => {
746 let exprs = e.map(|expr| self.collect_expr(expr)).collect();
747 self.alloc_expr(Expr::Array(Array::ElementList(exprs)), syntax_ptr)
748 }
749 ArrayExprKind::Repeat { initializer, repeat } => {
750 let initializer = self.collect_expr_opt(initializer);
751 let repeat = self.collect_expr_opt(repeat);
752 self.alloc_expr(
753 Expr::Array(Array::Repeat { initializer, repeat }),
754 syntax_ptr,
755 )
756 }
757 }
726 } 758 }
759
727 ast::ExprKind::Literal(e) => { 760 ast::ExprKind::Literal(e) => {
728 let lit = match e.kind() { 761 let lit = match e.kind() {
729 LiteralKind::IntNumber { suffix } => { 762 LiteralKind::IntNumber { suffix } => {