From b50a04827c13af00314eb9869d3cc125b2419971 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 19 Aug 2019 14:04:51 +0300 Subject: remove ast::*Kind from hir --- crates/ra_hir/src/expr.rs | 90 +++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 46 deletions(-) (limited to 'crates/ra_hir/src/expr.rs') diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index a16561d11..328d635d4 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -602,8 +602,8 @@ where fn collect_expr(&mut self, expr: ast::Expr) -> ExprId { let syntax_ptr = SyntaxNodePtr::new(expr.syntax()); - match expr.kind() { - ast::ExprKind::IfExpr(e) => { + match expr { + ast::Expr::IfExpr(e) => { let then_branch = self.collect_block_opt(e.then_branch()); let else_branch = e.else_branch().map(|b| match b { @@ -639,16 +639,16 @@ where self.alloc_expr(Expr::If { condition, then_branch, else_branch }, syntax_ptr) } - ast::ExprKind::TryBlockExpr(e) => { + ast::Expr::TryBlockExpr(e) => { let body = self.collect_block_opt(e.try_body()); self.alloc_expr(Expr::TryBlock { body }, syntax_ptr) } - ast::ExprKind::BlockExpr(e) => self.collect_block_opt(e.block()), - ast::ExprKind::LoopExpr(e) => { + ast::Expr::BlockExpr(e) => self.collect_block_opt(e.block()), + ast::Expr::LoopExpr(e) => { let body = self.collect_block_opt(e.loop_body()); self.alloc_expr(Expr::Loop { body }, syntax_ptr) } - ast::ExprKind::WhileExpr(e) => { + ast::Expr::WhileExpr(e) => { let body = self.collect_block_opt(e.loop_body()); let condition = match e.condition() { @@ -675,13 +675,13 @@ where self.alloc_expr(Expr::While { condition, body }, syntax_ptr) } - ast::ExprKind::ForExpr(e) => { + ast::Expr::ForExpr(e) => { let iterable = self.collect_expr_opt(e.iterable()); let pat = self.collect_pat_opt(e.pat()); let body = self.collect_block_opt(e.loop_body()); self.alloc_expr(Expr::For { iterable, pat, body }, syntax_ptr) } - ast::ExprKind::CallExpr(e) => { + ast::Expr::CallExpr(e) => { let callee = self.collect_expr_opt(e.expr()); let args = if let Some(arg_list) = e.arg_list() { arg_list.args().map(|e| self.collect_expr(e)).collect() @@ -690,7 +690,7 @@ where }; self.alloc_expr(Expr::Call { callee, args }, syntax_ptr) } - ast::ExprKind::MethodCallExpr(e) => { + ast::Expr::MethodCallExpr(e) => { let receiver = self.collect_expr_opt(e.expr()); let args = if let Some(arg_list) = e.arg_list() { arg_list.args().map(|e| self.collect_expr(e)).collect() @@ -704,7 +704,7 @@ where syntax_ptr, ) } - ast::ExprKind::MatchExpr(e) => { + ast::Expr::MatchExpr(e) => { let expr = self.collect_expr_opt(e.expr()); let arms = if let Some(match_arm_list) = e.match_arm_list() { match_arm_list @@ -723,30 +723,30 @@ where }; self.alloc_expr(Expr::Match { expr, arms }, syntax_ptr) } - ast::ExprKind::PathExpr(e) => { + ast::Expr::PathExpr(e) => { let path = e.path().and_then(Path::from_ast).map(Expr::Path).unwrap_or(Expr::Missing); self.alloc_expr(path, syntax_ptr) } - ast::ExprKind::ContinueExpr(_e) => { + ast::Expr::ContinueExpr(_e) => { // FIXME: labels self.alloc_expr(Expr::Continue, syntax_ptr) } - ast::ExprKind::BreakExpr(e) => { + ast::Expr::BreakExpr(e) => { let expr = e.expr().map(|e| self.collect_expr(e)); self.alloc_expr(Expr::Break { expr }, syntax_ptr) } - ast::ExprKind::ParenExpr(e) => { + ast::Expr::ParenExpr(e) => { let inner = self.collect_expr_opt(e.expr()); // make the paren expr point to the inner expression as well self.source_map.expr_map.insert(syntax_ptr, inner); inner } - ast::ExprKind::ReturnExpr(e) => { + ast::Expr::ReturnExpr(e) => { let expr = e.expr().map(|e| self.collect_expr(e)); self.alloc_expr(Expr::Return { expr }, syntax_ptr) } - ast::ExprKind::StructLit(e) => { + ast::Expr::StructLit(e) => { let path = e.path().and_then(Path::from_ast); let mut field_ptrs = Vec::new(); let struct_lit = if let Some(nfl) = e.named_field_list() { @@ -787,7 +787,7 @@ where } res } - ast::ExprKind::FieldExpr(e) => { + ast::Expr::FieldExpr(e) => { let expr = self.collect_expr_opt(e.expr()); let name = match e.field_access() { Some(kind) => kind.as_name(), @@ -795,25 +795,25 @@ where }; self.alloc_expr(Expr::Field { expr, name }, syntax_ptr) } - ast::ExprKind::AwaitExpr(e) => { + ast::Expr::AwaitExpr(e) => { let expr = self.collect_expr_opt(e.expr()); self.alloc_expr(Expr::Await { expr }, syntax_ptr) } - ast::ExprKind::TryExpr(e) => { + ast::Expr::TryExpr(e) => { let expr = self.collect_expr_opt(e.expr()); self.alloc_expr(Expr::Try { expr }, syntax_ptr) } - ast::ExprKind::CastExpr(e) => { + ast::Expr::CastExpr(e) => { let expr = self.collect_expr_opt(e.expr()); let type_ref = TypeRef::from_ast_opt(e.type_ref()); self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr) } - ast::ExprKind::RefExpr(e) => { + ast::Expr::RefExpr(e) => { let expr = self.collect_expr_opt(e.expr()); let mutability = Mutability::from_mutable(e.is_mut()); self.alloc_expr(Expr::Ref { expr, mutability }, syntax_ptr) } - ast::ExprKind::PrefixExpr(e) => { + ast::Expr::PrefixExpr(e) => { let expr = self.collect_expr_opt(e.expr()); if let Some(op) = e.op_kind() { self.alloc_expr(Expr::UnaryOp { expr, op }, syntax_ptr) @@ -821,7 +821,7 @@ where self.alloc_expr(Expr::Missing, syntax_ptr) } } - ast::ExprKind::LambdaExpr(e) => { + ast::Expr::LambdaExpr(e) => { let mut args = Vec::new(); let mut arg_types = Vec::new(); if let Some(pl) = e.param_list() { @@ -835,18 +835,18 @@ where let body = self.collect_expr_opt(e.body()); self.alloc_expr(Expr::Lambda { args, arg_types, body }, syntax_ptr) } - ast::ExprKind::BinExpr(e) => { + ast::Expr::BinExpr(e) => { let lhs = self.collect_expr_opt(e.lhs()); let rhs = self.collect_expr_opt(e.rhs()); let op = e.op_kind().map(BinaryOp::from); self.alloc_expr(Expr::BinaryOp { lhs, rhs, op }, syntax_ptr) } - ast::ExprKind::TupleExpr(e) => { + ast::Expr::TupleExpr(e) => { let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect(); self.alloc_expr(Expr::Tuple { exprs }, syntax_ptr) } - ast::ExprKind::ArrayExpr(e) => { + ast::Expr::ArrayExpr(e) => { let kind = e.kind(); match kind { @@ -865,7 +865,7 @@ where } } - ast::ExprKind::Literal(e) => { + ast::Expr::Literal(e) => { let lit = match e.kind() { LiteralKind::IntNumber { suffix } => { let known_name = suffix @@ -895,16 +895,16 @@ where }; self.alloc_expr(Expr::Literal(lit), syntax_ptr) } - ast::ExprKind::IndexExpr(e) => { + ast::Expr::IndexExpr(e) => { let base = self.collect_expr_opt(e.base()); let index = self.collect_expr_opt(e.index()); self.alloc_expr(Expr::Index { base, index }, syntax_ptr) } // FIXME implement HIR for these: - ast::ExprKind::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), - ast::ExprKind::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), - ast::ExprKind::MacroCall(e) => { + ast::Expr::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), + ast::Expr::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), + ast::Expr::MacroCall(e) => { let ast_id = self .db .ast_id_map(self.current_file_id) @@ -945,16 +945,14 @@ where fn collect_block(&mut self, block: ast::Block) -> ExprId { let statements = block .statements() - .map(|s| match s.kind() { - ast::StmtKind::LetStmt(stmt) => { + .map(|s| match s { + ast::Stmt::LetStmt(stmt) => { let pat = self.collect_pat_opt(stmt.pat()); let type_ref = stmt.ascribed_type().map(TypeRef::from_ast); let initializer = stmt.initializer().map(|e| self.collect_expr(e)); Statement::Let { pat, type_ref, initializer } } - ast::StmtKind::ExprStmt(stmt) => { - Statement::Expr(self.collect_expr_opt(stmt.expr())) - } + ast::Stmt::ExprStmt(stmt) => Statement::Expr(self.collect_expr_opt(stmt.expr())), }) .collect(); let tail = block.expr().map(|e| self.collect_expr(e)); @@ -970,33 +968,33 @@ where } fn collect_pat(&mut self, pat: ast::Pat) -> PatId { - let pattern = match pat.kind() { - ast::PatKind::BindPat(bp) => { + let pattern = match &pat { + ast::Pat::BindPat(bp) => { let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); let annotation = BindingAnnotation::new(bp.is_mutable(), bp.is_ref()); let subpat = bp.pat().map(|subpat| self.collect_pat(subpat)); Pat::Bind { name, mode: annotation, subpat } } - ast::PatKind::TupleStructPat(p) => { + ast::Pat::TupleStructPat(p) => { let path = p.path().and_then(Path::from_ast); let args = p.args().map(|p| self.collect_pat(p)).collect(); Pat::TupleStruct { path, args } } - ast::PatKind::RefPat(p) => { + ast::Pat::RefPat(p) => { let pat = self.collect_pat_opt(p.pat()); let mutability = Mutability::from_mutable(p.is_mut()); Pat::Ref { pat, mutability } } - ast::PatKind::PathPat(p) => { + ast::Pat::PathPat(p) => { let path = p.path().and_then(Path::from_ast); path.map(Pat::Path).unwrap_or(Pat::Missing) } - ast::PatKind::TuplePat(p) => { + ast::Pat::TuplePat(p) => { let args = p.args().map(|p| self.collect_pat(p)).collect(); Pat::Tuple(args) } - ast::PatKind::PlaceholderPat(_) => Pat::Wild, - ast::PatKind::StructPat(p) => { + ast::Pat::PlaceholderPat(_) => Pat::Wild, + ast::Pat::StructPat(p) => { let path = p.path().and_then(Path::from_ast); let field_pat_list = p.field_pat_list().expect("every struct should have a field list"); @@ -1022,8 +1020,8 @@ where } // FIXME: implement - ast::PatKind::LiteralPat(_) => Pat::Missing, - ast::PatKind::SlicePat(_) | ast::PatKind::RangePat(_) => Pat::Missing, + ast::Pat::LiteralPat(_) => Pat::Missing, + ast::Pat::SlicePat(_) | ast::Pat::RangePat(_) => Pat::Missing, }; let ptr = AstPtr::new(&pat); self.alloc_pat(pattern, Either::A(ptr)) -- cgit v1.2.3