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, 34 insertions, 15 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index 3e6578651..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,15 +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 repeat: Option<ExprId>,
244 },
245 Literal(Literal), 242 Literal(Literal),
246} 243}
247 244
248pub use ra_syntax::ast::PrefixOp as UnaryOp; 245pub use ra_syntax::ast::PrefixOp as UnaryOp;
249pub 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}
250 252
251#[derive(Debug, Clone, Eq, PartialEq)] 253#[derive(Debug, Clone, Eq, PartialEq)]
252pub struct MatchArm { 254pub struct MatchArm {
@@ -354,15 +356,17 @@ impl Expr {
354 f(*expr); 356 f(*expr);
355 } 357 }
356 } 358 }
357 Expr::Array { exprs, repeat } => { 359 Expr::Array(a) => match a {
358 for expr in exprs { 360 Array::ElementList(exprs) => {
359 f(*expr); 361 for expr in exprs {
362 f(*expr);
363 }
360 } 364 }
361 365 Array::Repeat { initializer, repeat } => {
362 if let Some(expr) = repeat { 366 f(*initializer);
363 f(*expr) 367 f(*repeat)
364 } 368 }
365 } 369 },
366 Expr::Literal(_) => {} 370 Expr::Literal(_) => {}
367 } 371 }
368 } 372 }
@@ -733,11 +737,26 @@ impl ExprCollector {
733 let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect(); 737 let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect();
734 self.alloc_expr(Expr::Tuple { exprs }, syntax_ptr) 738 self.alloc_expr(Expr::Tuple { exprs }, syntax_ptr)
735 } 739 }
740
736 ast::ExprKind::ArrayExpr(e) => { 741 ast::ExprKind::ArrayExpr(e) => {
737 let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect(); 742 let kind = e.kind();
738 let repeat = e.repeat().map(|e| self.collect_expr(e)); 743
739 self.alloc_expr(Expr::Array { exprs, repeat }, syntax_ptr) 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 }
740 } 758 }
759
741 ast::ExprKind::Literal(e) => { 760 ast::ExprKind::Literal(e) => {
742 let lit = match e.kind() { 761 let lit = match e.kind() {
743 LiteralKind::IntNumber { suffix } => { 762 LiteralKind::IntNumber { suffix } => {