fn rewrite_expr(e: &Expr) -> Expr {
    use aast::Expr_::*;
    match &e.1 {
        // Convert `1` to `$v->intLiteral(1)`.
        Int(_) => meth_call("intLiteral", vec![e.clone()], &e.0),
        // Convert `"foo"` to `$v->stringLiteral("foo")`.
        String(_) => meth_call("stringLiteral", vec![e.clone()], &e.0),
        // Convert `true` to `$v->boolLiteral(true)`.
        True => meth_call("boolLiteral", vec![e.clone()], &e.0),
        False => meth_call("boolLiteral", vec![e.clone()], &e.0),
        // Convert `null` to `$v->nullLiteral()`.
        Null => meth_call("nullLiteral", vec![], &e.0),
        // Convert `$x` to `$v->localVar("$x")` (note the quoting).
        Lvar(lid) => meth_call("localVar", vec![string_literal(&((lid.1).1))], &e.0),
        Binop(bop) => match &**bop {
            // Convert `... + ...` to `$v->plus($v->..., $v->...)`.
            (Bop::Plus, lhs, rhs) => {
                meth_call("plus", vec![rewrite_expr(&lhs), rewrite_expr(&rhs)], &e.0)
            }
            // Convert `... = ...` to `$v->assign($v->..., $v->...)`.
            (Bop::Eq(None), lhs, rhs) => {
                meth_call("assign", vec![rewrite_expr(&lhs), rewrite_expr(&rhs)], &e.0)
            }
            _ => meth_call(
                "unsupportedSyntax",
                vec![string_literal("bad binary operator")],
                &e.0,
            ),
        },
        // Convert `foo(...)` to `$v->call('foo', vec[...])`.
        Call(call) => match &**call {
            (recv, _, args, _) => match &recv.1 {
                Id(sid) => {
                    let fn_name = string_literal(&*sid.1);
                    let desugared_args = vec![
                        fn_name,
                        vec_literal(args.iter().map(rewrite_expr).collect()),
                    ];
                    meth_call("call", desugared_args, &e.0)
                }
                _ => meth_call(
                    "unsupportedSyntax",
                    vec![string_literal("invalid function call")],
                    &e.0,
                ),
            },
        },
        // Convert `($x) ==> { ... }` to `$v->lambdaLiteral(vec["$x"], vec[...])`.
        Lfun(lf) => {
            let fun_ = &lf.0;
            let param_names = fun_
                .params
                .iter()
                .map(|p| string_literal(&p.name))
                .collect();
            let body_stmts = rewrite_stmts(&fun_.body.ast);

            meth_call(
                "lambdaLiteral",
                vec![vec_literal(param_names), vec_literal(body_stmts)],
                &e.0,
            )
        }
        // Convert anything else to $v->unsupportedSyntax().
        // Type checking should prevent us hitting these cases.
        _ => meth_call(
            "unsupportedSyntax",
            vec![string_literal(&format!("{:#?}", &e.1))],
            &e.0,
        ),
    }
}
/// Convert expression tree expressions to method calls.
Convert expression tree expressions to method calls.
Convert expression tree expressions to method calls .
fn rewrite_expr(e: &Expr) -> Expr {
    use aast::Expr_::*;
    match &e.1 {
        // Convert `1` to `$v->intLiteral(1)`.
        Int(_) => meth_call("intLiteral", vec![e.clone()], &e.0),
        // Convert `"foo"` to `$v->stringLiteral("foo")`.
        String(_) => meth_call("stringLiteral", vec![e.clone()], &e.0),
        // Convert `true` to `$v->boolLiteral(true)`.
        True => meth_call("boolLiteral", vec![e.clone()], &e.0),
        False => meth_call("boolLiteral", vec![e.clone()], &e.0),
        // Convert `null` to `$v->nullLiteral()`.
        Null => meth_call("nullLiteral", vec![], &e.0),
        // Convert `$x` to `$v->localVar("$x")` (note the quoting).
        Lvar(lid) => meth_call("localVar", vec![string_literal(&((lid.1).1))], &e.0),
        Binop(bop) => match &**bop {
            // Convert `... + ...` to `$v->plus($v->..., $v->...)`.
            (Bop::Plus, lhs, rhs) => {
                meth_call("plus", vec![rewrite_expr(&lhs), rewrite_expr(&rhs)], &e.0)
            }
            // Convert `... = ...` to `$v->assign($v->..., $v->...)`.
            (Bop::Eq(None), lhs, rhs) => {
                meth_call("assign", vec![rewrite_expr(&lhs), rewrite_expr(&rhs)], &e.0)
            }
            _ => meth_call(
                "unsupportedSyntax",
                vec![string_literal("bad binary operator")],
                &e.0,
            ),
        },
        // Convert `foo(...)` to `$v->call('foo', vec[...])`.
        Call(call) => match &**call {
            (recv, _, args, _) => match &recv.1 {
                Id(sid) => {
                    let fn_name = string_literal(&*sid.1);
                    let desugared_args = vec![
                        fn_name,
                        vec_literal(args.iter().map(rewrite_expr).collect()),
                    ];
                    meth_call("call", desugared_args, &e.0)
                }
                _ => meth_call(
                    "unsupportedSyntax",
                    vec![string_literal("invalid function call")],
                    &e.0,
                ),
            },
        },
        // Convert `($x) ==> { ... }` to `$v->lambdaLiteral(vec["$x"], vec[...])`.
        Lfun(lf) => {
            let fun_ = &lf.0;
            let param_names = fun_
                .params
                .iter()
                .map(|p| string_literal(&p.name))
                .collect();
            let body_stmts = rewrite_stmts(&fun_.body.ast);
            meth_call(
                "lambdaLiteral",
                vec![vec_literal(param_names), vec_literal(body_stmts)],
                &e.0,
            )
        }
        // Convert anything else to $v->unsupportedSyntax().
        // Type checking should prevent us hitting these cases.
        _ => meth_call(
            "unsupportedSyntax",
            vec![string_literal(&format!("{:#?}", &e.1))],
            &e.0,
        ),
    }
}
fn rewrite_expr ( e : & Expr ) -> Expr { use aast :: Expr_ :: * ; match & e . 1 { // Convert `1` to `$v->intLiteral(1)`. Int ( _ ) => meth_call ( " " , vec ! [ e clone ( ) ] , & e . 0 ) , // Convert `"foo"` to `$v->stringLiteral("foo")`. String ( _ ) => meth_call ( " " , vec ! [ e clone ( ) ] , & e . 0 ) , // Convert `true` to `$v->boolLiteral(true)`. True => meth_call ( " " , vec ! [ e clone ( ) ] , & e . 0 ) , False => meth_call ( " " , vec ! [ e clone ( ) ] , & e . 0 ) , // Convert `null` to `$v->nullLiteral()`. Null => meth_call ( " " , vec ! [ ] , & e . 0 ) , // Convert `$x` to `$v->localVar("$x")` (note the quoting). Lvar ( lid ) => meth_call ( " " , vec ! [ string_literal ( ( ( lid 1 ) 1 ) ) ] , & e . 0 ) , Binop ( bop ) => match & * * bop { // Convert `... + ...` to `$v->plus($v->..., $v->...)`. ( Bop :: Plus , lhs , rhs ) => { meth_call ( " " , vec ! [ rewrite_expr ( lhs ) rewrite_expr ( rhs ) ] , & e . 0 ) } // Convert `... = ...` to `$v->assign($v->..., $v->...)`. ( Bop :: Eq ( None ) , lhs , rhs ) => { meth_call ( " " , vec ! [ rewrite_expr ( lhs ) rewrite_expr ( rhs ) ] , & e . 0 ) } _ => meth_call ( " " , vec ! [ string_literal ( " " ) ] , & e . 0 , ) , } , // Convert `foo(...)` to `$v->call('foo', vec[...])`. Call ( call ) => match & * * call { ( recv , _ , args , _ ) => match & recv . 1 { Id ( sid ) => { let fn_name = string_literal ( & * sid . 1 ) ; let desugared_args = vec ! [ fn_name vec_literal ( args iter ( ) map ( rewrite_expr ) collect ( ) ) ] ; meth_call ( " " , desugared_args , & e . 0 ) } _ => meth_call ( " " , vec ! [ string_literal ( " " ) ] , & e . 0 , ) , } , } , // Convert `($x) ==> { ... }` to `$v->lambdaLiteral(vec["$x"], vec[...])`. Lfun ( lf ) => { let fun_ = & lf . 0 ; let param_names = fun_ . params . iter ( ) . map ( | p | string_literal ( & p . name ) ) . collect ( ) ; let body_stmts = rewrite_stmts ( & fun_ . body . ast ) ; meth_call ( " " , vec ! [ vec_literal ( param_names ) vec_literal ( body_stmts ) ] , & e . 0 , ) } // Convert anything else to $v->unsupportedSyntax(). // Type checking should prevent us hitting these cases. _ => meth_call ( " " , vec ! [ string_literal ( format ( " " e 1 ) ) ] , & e . 0 , ) , } }
Convert expression tree expressions to method calls.
Convert expression tree expressions to method calls .
e
&Expr