Skip to content

Commit

Permalink
ExprKind
Browse files Browse the repository at this point in the history
  • Loading branch information
csmoe authored and oli-obk committed Jul 16, 2018
1 parent 1d19e0c commit 6a16b38
Show file tree
Hide file tree
Showing 50 changed files with 666 additions and 667 deletions.
68 changes: 34 additions & 34 deletions src/librustc/cfg/construct.rs
Expand Up @@ -179,12 +179,12 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {

fn expr(&mut self, expr: &hir::Expr, pred: CFGIndex) -> CFGIndex {
match expr.node {
hir::ExprBlock(ref blk, _) => {
hir::ExprKind::Block(ref blk, _) => {
let blk_exit = self.block(&blk, pred);
self.add_ast_node(expr.hir_id.local_id, &[blk_exit])
}

hir::ExprIf(ref cond, ref then, None) => {
hir::ExprKind::If(ref cond, ref then, None) => {
//
// [pred]
// |
Expand All @@ -204,7 +204,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
self.add_ast_node(expr.hir_id.local_id, &[cond_exit, then_exit]) // 3,4
}

hir::ExprIf(ref cond, ref then, Some(ref otherwise)) => {
hir::ExprKind::If(ref cond, ref then, Some(ref otherwise)) => {
//
// [pred]
// |
Expand All @@ -225,7 +225,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
self.add_ast_node(expr.hir_id.local_id, &[then_exit, else_exit]) // 4, 5
}

hir::ExprWhile(ref cond, ref body, _) => {
hir::ExprKind::While(ref cond, ref body, _) => {
//
// [pred]
// |
Expand Down Expand Up @@ -267,7 +267,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
expr_exit
}

hir::ExprLoop(ref body, _, _) => {
hir::ExprKind::Loop(ref body, _, _) => {
//
// [pred]
// |
Expand Down Expand Up @@ -295,11 +295,11 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
expr_exit
}

hir::ExprMatch(ref discr, ref arms, _) => {
hir::ExprKind::Match(ref discr, ref arms, _) => {
self.match_(expr.hir_id.local_id, &discr, &arms, pred)
}

hir::ExprBinary(op, ref l, ref r) if op.node.is_lazy() => {
hir::ExprKind::Binary(op, ref l, ref r) if op.node.is_lazy() => {
//
// [pred]
// |
Expand All @@ -319,14 +319,14 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
self.add_ast_node(expr.hir_id.local_id, &[l_exit, r_exit]) // 3,4
}

hir::ExprRet(ref v) => {
hir::ExprKind::Ret(ref v) => {
let v_exit = self.opt_expr(v, pred);
let b = self.add_ast_node(expr.hir_id.local_id, &[v_exit]);
self.add_returning_edge(expr, b);
self.add_unreachable_node()
}

hir::ExprBreak(destination, ref opt_expr) => {
hir::ExprKind::Break(destination, ref opt_expr) => {
let v = self.opt_expr(opt_expr, pred);
let (target_scope, break_dest) =
self.find_scope_edge(expr, destination, ScopeCfKind::Break);
Expand All @@ -335,74 +335,74 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
self.add_unreachable_node()
}

hir::ExprContinue(destination) => {
hir::ExprKind::Continue(destination) => {
let (target_scope, cont_dest) =
self.find_scope_edge(expr, destination, ScopeCfKind::Continue);
let a = self.add_ast_node(expr.hir_id.local_id, &[pred]);
self.add_exiting_edge(expr, a, target_scope, cont_dest);
self.add_unreachable_node()
}

hir::ExprArray(ref elems) => {
hir::ExprKind::Array(ref elems) => {
self.straightline(expr, pred, elems.iter().map(|e| &*e))
}

hir::ExprCall(ref func, ref args) => {
hir::ExprKind::Call(ref func, ref args) => {
self.call(expr, pred, &func, args.iter().map(|e| &*e))
}

hir::ExprMethodCall(.., ref args) => {
hir::ExprKind::MethodCall(.., ref args) => {
self.call(expr, pred, &args[0], args[1..].iter().map(|e| &*e))
}

hir::ExprIndex(ref l, ref r) |
hir::ExprBinary(_, ref l, ref r) if self.tables.is_method_call(expr) => {
hir::ExprKind::Index(ref l, ref r) |
hir::ExprKind::Binary(_, ref l, ref r) if self.tables.is_method_call(expr) => {
self.call(expr, pred, &l, Some(&**r).into_iter())
}

hir::ExprUnary(_, ref e) if self.tables.is_method_call(expr) => {
hir::ExprKind::Unary(_, ref e) if self.tables.is_method_call(expr) => {
self.call(expr, pred, &e, None::<hir::Expr>.iter())
}

hir::ExprTup(ref exprs) => {
hir::ExprKind::Tup(ref exprs) => {
self.straightline(expr, pred, exprs.iter().map(|e| &*e))
}

hir::ExprStruct(_, ref fields, ref base) => {
hir::ExprKind::Struct(_, ref fields, ref base) => {
let field_cfg = self.straightline(expr, pred, fields.iter().map(|f| &*f.expr));
self.opt_expr(base, field_cfg)
}

hir::ExprAssign(ref l, ref r) |
hir::ExprAssignOp(_, ref l, ref r) => {
hir::ExprKind::Assign(ref l, ref r) |
hir::ExprKind::AssignOp(_, ref l, ref r) => {
self.straightline(expr, pred, [r, l].iter().map(|&e| &**e))
}

hir::ExprIndex(ref l, ref r) |
hir::ExprBinary(_, ref l, ref r) => { // NB: && and || handled earlier
hir::ExprKind::Index(ref l, ref r) |
hir::ExprKind::Binary(_, ref l, ref r) => { // NB: && and || handled earlier
self.straightline(expr, pred, [l, r].iter().map(|&e| &**e))
}

hir::ExprBox(ref e) |
hir::ExprAddrOf(_, ref e) |
hir::ExprCast(ref e, _) |
hir::ExprType(ref e, _) |
hir::ExprUnary(_, ref e) |
hir::ExprField(ref e, _) |
hir::ExprYield(ref e) |
hir::ExprRepeat(ref e, _) => {
hir::ExprKind::Box(ref e) |
hir::ExprKind::AddrOf(_, ref e) |
hir::ExprKind::Cast(ref e, _) |
hir::ExprKind::Type(ref e, _) |
hir::ExprKind::Unary(_, ref e) |
hir::ExprKind::Field(ref e, _) |
hir::ExprKind::Yield(ref e) |
hir::ExprKind::Repeat(ref e, _) => {
self.straightline(expr, pred, Some(&**e).into_iter())
}

hir::ExprInlineAsm(_, ref outputs, ref inputs) => {
hir::ExprKind::InlineAsm(_, ref outputs, ref inputs) => {
let post_outputs = self.exprs(outputs.iter().map(|e| &*e), pred);
let post_inputs = self.exprs(inputs.iter().map(|e| &*e), post_outputs);
self.add_ast_node(expr.hir_id.local_id, &[post_inputs])
}

hir::ExprClosure(..) |
hir::ExprLit(..) |
hir::ExprPath(_) => {
hir::ExprKind::Closure(..) |
hir::ExprKind::Lit(..) |
hir::ExprKind::Path(_) => {
self.straightline(expr, pred, None::<hir::Expr>.iter())
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/check_attr.rs
Expand Up @@ -283,7 +283,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {

fn check_expr_attributes(&self, expr: &hir::Expr) {
let target = match expr.node {
hir::ExprClosure(..) => Target::Closure,
hir::ExprKind::Closure(..) => Target::Closure,
_ => Target::Expression,
};
for attr in expr.attrs.iter() {
Expand Down
54 changes: 27 additions & 27 deletions src/librustc/hir/intravisit.rs
Expand Up @@ -963,17 +963,17 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
visitor.visit_id(expression.id);
walk_list!(visitor, visit_attribute, expression.attrs.iter());
match expression.node {
ExprBox(ref subexpression) => {
ExprKind::Box(ref subexpression) => {
visitor.visit_expr(subexpression)
}
ExprArray(ref subexpressions) => {
ExprKind::Array(ref subexpressions) => {
walk_list!(visitor, visit_expr, subexpressions);
}
ExprRepeat(ref element, ref count) => {
ExprKind::Repeat(ref element, ref count) => {
visitor.visit_expr(element);
visitor.visit_anon_const(count)
}
ExprStruct(ref qpath, ref fields, ref optional_base) => {
ExprKind::Struct(ref qpath, ref fields, ref optional_base) => {
visitor.visit_qpath(qpath, expression.id, expression.span);
for field in fields {
visitor.visit_id(field.id);
Expand All @@ -982,78 +982,78 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
}
walk_list!(visitor, visit_expr, optional_base);
}
ExprTup(ref subexpressions) => {
ExprKind::Tup(ref subexpressions) => {
walk_list!(visitor, visit_expr, subexpressions);
}
ExprCall(ref callee_expression, ref arguments) => {
ExprKind::Call(ref callee_expression, ref arguments) => {
visitor.visit_expr(callee_expression);
walk_list!(visitor, visit_expr, arguments);
}
ExprMethodCall(ref segment, _, ref arguments) => {
ExprKind::MethodCall(ref segment, _, ref arguments) => {
visitor.visit_path_segment(expression.span, segment);
walk_list!(visitor, visit_expr, arguments);
}
ExprBinary(_, ref left_expression, ref right_expression) => {
ExprKind::Binary(_, ref left_expression, ref right_expression) => {
visitor.visit_expr(left_expression);
visitor.visit_expr(right_expression)
}
ExprAddrOf(_, ref subexpression) | ExprUnary(_, ref subexpression) => {
ExprKind::AddrOf(_, ref subexpression) | ExprKind::Unary(_, ref subexpression) => {
visitor.visit_expr(subexpression)
}
ExprLit(_) => {}
ExprCast(ref subexpression, ref typ) | ExprType(ref subexpression, ref typ) => {
ExprKind::Lit(_) => {}
ExprKind::Cast(ref subexpression, ref typ) | ExprKind::Type(ref subexpression, ref typ) => {
visitor.visit_expr(subexpression);
visitor.visit_ty(typ)
}
ExprIf(ref head_expression, ref if_block, ref optional_else) => {
ExprKind::If(ref head_expression, ref if_block, ref optional_else) => {
visitor.visit_expr(head_expression);
visitor.visit_expr(if_block);
walk_list!(visitor, visit_expr, optional_else);
}
ExprWhile(ref subexpression, ref block, ref opt_label) => {
ExprKind::While(ref subexpression, ref block, ref opt_label) => {
walk_list!(visitor, visit_label, opt_label);
visitor.visit_expr(subexpression);
visitor.visit_block(block);
}
ExprLoop(ref block, ref opt_label, _) => {
ExprKind::Loop(ref block, ref opt_label, _) => {
walk_list!(visitor, visit_label, opt_label);
visitor.visit_block(block);
}
ExprMatch(ref subexpression, ref arms, _) => {
ExprKind::Match(ref subexpression, ref arms, _) => {
visitor.visit_expr(subexpression);
walk_list!(visitor, visit_arm, arms);
}
ExprClosure(_, ref function_declaration, body, _fn_decl_span, _gen) => {
ExprKind::Closure(_, ref function_declaration, body, _fn_decl_span, _gen) => {
visitor.visit_fn(FnKind::Closure(&expression.attrs),
function_declaration,
body,
expression.span,
expression.id)
}
ExprBlock(ref block, ref opt_label) => {
ExprKind::Block(ref block, ref opt_label) => {
walk_list!(visitor, visit_label, opt_label);
visitor.visit_block(block);
}
ExprAssign(ref left_hand_expression, ref right_hand_expression) => {
ExprKind::Assign(ref left_hand_expression, ref right_hand_expression) => {
visitor.visit_expr(right_hand_expression);
visitor.visit_expr(left_hand_expression)
}
ExprAssignOp(_, ref left_expression, ref right_expression) => {
ExprKind::AssignOp(_, ref left_expression, ref right_expression) => {
visitor.visit_expr(right_expression);
visitor.visit_expr(left_expression)
}
ExprField(ref subexpression, ident) => {
ExprKind::Field(ref subexpression, ident) => {
visitor.visit_expr(subexpression);
visitor.visit_ident(ident);
}
ExprIndex(ref main_expression, ref index_expression) => {
ExprKind::Index(ref main_expression, ref index_expression) => {
visitor.visit_expr(main_expression);
visitor.visit_expr(index_expression)
}
ExprPath(ref qpath) => {
ExprKind::Path(ref qpath) => {
visitor.visit_qpath(qpath, expression.id, expression.span);
}
ExprBreak(ref destination, ref opt_expr) => {
ExprKind::Break(ref destination, ref opt_expr) => {
if let Some(ref label) = destination.label {
visitor.visit_label(label);
match destination.target_id {
Expand All @@ -1063,7 +1063,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
}
walk_list!(visitor, visit_expr, opt_expr);
}
ExprContinue(ref destination) => {
ExprKind::Continue(ref destination) => {
if let Some(ref label) = destination.label {
visitor.visit_label(label);
match destination.target_id {
Expand All @@ -1072,18 +1072,18 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
};
}
}
ExprRet(ref optional_expression) => {
ExprKind::Ret(ref optional_expression) => {
walk_list!(visitor, visit_expr, optional_expression);
}
ExprInlineAsm(_, ref outputs, ref inputs) => {
ExprKind::InlineAsm(_, ref outputs, ref inputs) => {
for output in outputs {
visitor.visit_expr(output)
}
for input in inputs {
visitor.visit_expr(input)
}
}
ExprYield(ref subexpression) => {
ExprKind::Yield(ref subexpression) => {
visitor.visit_expr(subexpression);
}
}
Expand Down

0 comments on commit 6a16b38

Please sign in to comment.