fn create_lang_marshall(ecx: &mut ExtCtxt,
                        original_name: Ident,
                        method_sig: &ast::MethodSig,
                        lang: &Language) -> ImplItem {
    let mut marshall_sig = method_sig.clone();

    // Replace old parameter types with the language-specific value type.
    marshall_sig.decl = util::replace_signature_types(marshall_sig.decl.clone(), lang.value_ty(ecx));

    let common_marshall_expr = config::common_marshall_expr(ecx, original_name, lang);
    // Create argument list.
    let args = method_sig.decl.inputs.iter().map(|arg| {
        if arg.is_self() {
            ecx.expr_self(DUMMY_SP)
        } else {
            match arg.pat.node {
                ast::PatKind::Ident(_, ident, _) => {
                    ecx.expr_ident(DUMMY_SP, ident.node)
                },
                _ => unimplemented!(),
            }
        }
    }).collect();

    let mut stmts = Vec::new();

    let call_expr = ecx.expr_call(DUMMY_SP, common_marshall_expr, args);
    let call_stmt = ecx.stmt_expr(call_expr);

    stmts.push(call_stmt);

    match method_sig.decl.output {
        // If we have no return type, but the language has a default value, use it.
        ast::FunctionRetTy::Default(..) => if let Some(default_retval) = lang.default_return_value(ecx) {
            let value_ty = lang.value_ty(ecx);

            marshall_sig.decl = util::set_return_type(marshall_sig.decl, value_ty);
            stmts.push(ecx.stmt_expr(default_retval));
        },
        ast::FunctionRetTy::Ty(..) => (),
    }

    let block = ecx.block(DUMMY_SP, stmts);

    ImplItem {
        id: DUMMY_NODE_ID,
        span: DUMMY_SP,
        ident: config::lang_marshall_name(original_name, lang),
        node: ImplItemKind::Method(marshall_sig, block),
        vis: ast::Visibility::Public,
        defaultness: ast::Defaultness::Final,
        attrs: Vec::new(),
        tokens: None,
    }
}
/// Creates a language-specific marshalling method that calls into the common one.
Creates a language-specific marshalling method that calls into the common one.
Creates a language - specific marshalling method that calls into the common one .
fn create_lang_marshall(ecx: &mut ExtCtxt,
                        original_name: Ident,
                        method_sig: &ast::MethodSig,
                        lang: &Language) -> ImplItem {
    let mut marshall_sig = method_sig.clone();
    // Replace old parameter types with the language-specific value type.
    marshall_sig.decl = util::replace_signature_types(marshall_sig.decl.clone(), lang.value_ty(ecx));
    let common_marshall_expr = config::common_marshall_expr(ecx, original_name, lang);
    // Create argument list.
    let args = method_sig.decl.inputs.iter().map(|arg| {
        if arg.is_self() {
            ecx.expr_self(DUMMY_SP)
        } else {
            match arg.pat.node {
                ast::PatKind::Ident(_, ident, _) => {
                    ecx.expr_ident(DUMMY_SP, ident.node)
                },
                _ => unimplemented!(),
            }
        }
    }).collect();
    let mut stmts = Vec::new();
    let call_expr = ecx.expr_call(DUMMY_SP, common_marshall_expr, args);
    let call_stmt = ecx.stmt_expr(call_expr);
    stmts.push(call_stmt);
    match method_sig.decl.output {
        // If we have no return type, but the language has a default value, use it.
        ast::FunctionRetTy::Default(..) => if let Some(default_retval) = lang.default_return_value(ecx) {
            let value_ty = lang.value_ty(ecx);
            marshall_sig.decl = util::set_return_type(marshall_sig.decl, value_ty);
            stmts.push(ecx.stmt_expr(default_retval));
        },
        ast::FunctionRetTy::Ty(..) => (),
    }
    let block = ecx.block(DUMMY_SP, stmts);
    ImplItem {
        id: DUMMY_NODE_ID,
        span: DUMMY_SP,
        ident: config::lang_marshall_name(original_name, lang),
        node: ImplItemKind::Method(marshall_sig, block),
        vis: ast::Visibility::Public,
        defaultness: ast::Defaultness::Final,
        attrs: Vec::new(),
        tokens: None,
    }
}
fn create_lang_marshall ( ecx : & mut ExtCtxt , original_name : Ident , method_sig : & ast :: MethodSig , lang : & Language ) -> ImplItem { let mut marshall_sig = method_sig . clone ( ) ; // Replace old parameter types with the language-specific value type. marshall_sig . decl = util :: replace_signature_types ( marshall_sig . decl . clone ( ) , lang . value_ty ( ecx ) ) ; let common_marshall_expr = config :: common_marshall_expr ( ecx , original_name , lang ) ; // Create argument list. let args = method_sig . decl . inputs . iter ( ) . map ( | arg | { if arg . is_self ( ) { ecx . expr_self ( DUMMY_SP ) } else { match arg . pat . node { ast :: PatKind :: Ident ( _ , ident , _ ) => { ecx . expr_ident ( DUMMY_SP , ident . node ) } , _ => unimplemented ! ( ) , } } } ) . collect ( ) ; let mut stmts = Vec :: new ( ) ; let call_expr = ecx . expr_call ( DUMMY_SP , common_marshall_expr , args ) ; let call_stmt = ecx . stmt_expr ( call_expr ) ; stmts . push ( call_stmt ) ; match method_sig . decl . output { // If we have no return type, but the language has a default value, use it. ast :: FunctionRetTy :: Default ( .. ) => if let Some ( default_retval ) = lang . default_return_value ( ecx ) { let value_ty = lang . value_ty ( ecx ) ; marshall_sig . decl = util :: set_return_type ( marshall_sig . decl , value_ty ) ; stmts . push ( ecx . stmt_expr ( default_retval ) ) ; } , ast :: FunctionRetTy :: Ty ( .. ) => ( ) , } let block = ecx . block ( DUMMY_SP , stmts ) ; ImplItem { id : DUMMY_NODE_ID , span : DUMMY_SP , ident : config :: lang_marshall_name ( original_name , lang ) , node : ImplItemKind :: Method ( marshall_sig , block ) , vis : ast :: Visibility :: Public , defaultness : ast :: Defaultness :: Final , attrs : Vec :: new ( ) , tokens : None , } }
Creates a language-specific marshalling method that calls into the common one.
Creates a language - specific marshalling method that calls into the common one .
ecx
&mut ExtCtxt
original_name
Ident
method_sig
&ast::MethodSig
lang
&Language
ecx
&mut ExtCtxt
original_name
Ident
method_sig
&ast::MethodSig
lang
&Language