Exemple #1
0
char*
CFCPerlMethod_callback_def(CFCMethod *method) {
    CFCType *return_type = CFCMethod_get_return_type(method);
    char *start = S_callback_start(method);
    char *callback_def = NULL;
    char *refcount_mods = S_callback_refcount_mods(method);

    if (!start) {
        // Can't map vars, because there's at least one type in the argument
        // list we don't yet support.  Return a callback wrapper that throws
        // an error error.
        callback_def = S_invalid_callback_def(method);
    }
    else if (CFCType_is_void(return_type)) {
        callback_def = S_void_callback_def(method, start, refcount_mods);
    }
    else if (CFCType_is_object(return_type)) {
        callback_def = S_obj_callback_def(method, start, refcount_mods);
    }
    else if (CFCType_is_integer(return_type)
             || CFCType_is_floating(return_type)
        ) {
        callback_def = S_primitive_callback_def(method, start, refcount_mods);
    }
    else {
        // Can't map return type.
        callback_def = S_invalid_callback_def(method);
    }

    FREEMEM(start);
    FREEMEM(refcount_mods);
    return callback_def;
}
Exemple #2
0
char*
CFCBindMeth_callback_def(CFCMethod *method) {
    CFCType *return_type = CFCMethod_get_return_type(method);
    char *params = S_callback_params(method);
    char *callback_def = NULL;
    char *refcount_mods = S_callback_refcount_mods(method);

    if (!params) {
        // Can't map vars, because there's at least one type in the argument
        // list we don't yet support.  Return a callback wrapper that throws
        // an error error.
        callback_def = S_invalid_callback_def(method);
    }
    else if (CFCType_is_void(return_type)) {
        callback_def = S_void_callback_def(method, params, refcount_mods);
    }
    else if (CFCType_is_object(return_type)) {
        callback_def = S_obj_callback_def(method, params, refcount_mods);
    }
    else {
        callback_def = S_primitive_callback_def(method, params, refcount_mods);
    }

    FREEMEM(params);
    FREEMEM(refcount_mods);
    return callback_def;
}
Exemple #3
0
char*
CFCPyMethod_callback_def(CFCMethod *method, CFCClass *invoker) {
    CFCParamList *param_list   = CFCMethod_get_param_list(method);
    CFCVariable **vars         = CFCParamList_get_variables(param_list);
    CFCType      *return_type  = CFCMethod_get_return_type(method);
    const char   *ret_type_str = CFCType_to_c(return_type);
    const char   *params       = CFCParamList_to_c(param_list);
    char         *override_sym = CFCMethod_full_override_sym(method, invoker);
    char *content;

    if (CFCMethod_can_be_bound(method)) {
        char *py_args = S_build_py_args(param_list);
        char *invocation = S_build_pymeth_invocation(method);
        char *refcount_mods = S_callback_refcount_mods(param_list);
        const char *maybe_return = CFCType_is_void(return_type)
                                   ? ""
                                   : "    return cfcb_RESULT;\n";

        const char pattern[] =
            "%s\n"
            "%s(%s) {\n"
            "%s\n"
            "%s\n"
            "%s"
            "%s"
            "}\n";
        content = CFCUtil_sprintf(pattern, ret_type_str, override_sym, params,
                                  py_args, invocation, refcount_mods,
                                  maybe_return);
    }
    else {
        char *unused = S_build_unused_vars(vars);
        char *unreachable = S_maybe_unreachable(return_type);
        char *meth_sym = CFCMethod_full_method_sym(method, invoker);
        const char pattern[] =
            "%s\n"
            "%s(%s) {%s\n"
            "    CFISH_THROW(CFISH_ERR, \"Can't override %s via binding\");%s\n"
            "}\n";
        content = CFCUtil_sprintf(pattern, ret_type_str, override_sym,
                                  params, unused, meth_sym, unreachable);
        FREEMEM(meth_sym);
        FREEMEM(unused);
        FREEMEM(unreachable);
    }

    FREEMEM(override_sym);
    return content;
}