int CFCType_equals(CFCType *self, CFCType *other) { if ((CFCType_const(self) ^ CFCType_const(other)) || (CFCType_nullable(self) ^ CFCType_nullable(other)) || (CFCType_is_void(self) ^ CFCType_is_void(other)) || (CFCType_is_object(self) ^ CFCType_is_object(other)) || (CFCType_is_primitive(self) ^ CFCType_is_primitive(other)) || (CFCType_is_integer(self) ^ CFCType_is_integer(other)) || (CFCType_is_floating(self) ^ CFCType_is_floating(other)) || (CFCType_is_va_list(self) ^ CFCType_is_va_list(other)) || (CFCType_is_arbitrary(self) ^ CFCType_is_arbitrary(other)) || (CFCType_is_composite(self) ^ CFCType_is_composite(other)) || (CFCType_incremented(self) ^ CFCType_incremented(other)) || (CFCType_decremented(self) ^ CFCType_decremented(other)) || !!self->child ^ !!other->child || !!self->array ^ !!other->array ) { return false; } if (self->indirection != other->indirection) { return false; } if (strcmp(self->specifier, other->specifier) != 0) { return false; } if (self->child) { if (!CFCType_equals(self->child, other->child)) { return false; } } if (self->array) { if (strcmp(self->array, other->array) != 0) { return false; } } return true; }
int CFCType_similar(CFCType *self, CFCType *other) { if (!CFCType_is_object(self)) { CFCUtil_die("Attempt to call 'similar' on a non-object type"); } if ((CFCType_const(self) ^ CFCType_const(other)) || (CFCType_nullable(self) ^ CFCType_nullable(other)) || (CFCType_incremented(self) ^ CFCType_incremented(other)) || (CFCType_decremented(self) ^ CFCType_decremented(other)) || (CFCType_is_object(self) ^ CFCType_is_object(other)) ) { return false; } return true; }
static char* S_obj_callback_def(CFCMethod *method, const char *callback_params, const char *refcount_mods) { const char *override_sym = CFCMethod_full_override_sym(method); const char *params = CFCParamList_to_c(CFCMethod_get_param_list(method)); CFCType *return_type = CFCMethod_get_return_type(method); const char *ret_type_str = CFCType_to_c(return_type); const char *cb_func_name = CFCType_is_string_type(return_type) ? "cfish_Host_callback_str" : "cfish_Host_callback_obj"; char *nullable_check = CFCUtil_strdup(""); if (!CFCType_nullable(return_type)) { const char *macro_sym = CFCMethod_get_macro_sym(method); char pattern[] = "\n if (!retval) { CFISH_THROW(CFISH_ERR, " "\"%s() for class '%%o' cannot return NULL\", " "Cfish_Obj_Get_Class_Name((cfish_Obj*)self)); }"; size_t size = sizeof(pattern) + strlen(macro_sym) + 30; nullable_check = (char*)REALLOCATE(nullable_check, size); sprintf(nullable_check, pattern, macro_sym); } char pattern[] = "%s\n" "%s(%s) {\n" " %s retval = (%s)%s(%s);%s%s\n" " return retval;\n" "}\n"; size_t size = sizeof(pattern) + strlen(ret_type_str) + strlen(override_sym) + strlen(params) + strlen(ret_type_str) + strlen(ret_type_str) + strlen(cb_func_name) + strlen(callback_params) + strlen(nullable_check) + strlen(refcount_mods) + 30; char *callback_def = (char*)MALLOCATE(size); sprintf(callback_def, pattern, ret_type_str, override_sym, params, ret_type_str, ret_type_str, cb_func_name, callback_params, nullable_check, refcount_mods); FREEMEM(nullable_check); return callback_def; }
static char* S_gen_target(CFCVariable *var, const char *value) { CFCType *type = CFCVariable_get_type(var); const char *specifier = CFCType_get_specifier(type); const char *micro_sym = CFCVariable_get_name(var); const char *maybe_maybe = ""; const char *dest_name; char *var_name = NULL; if (CFCType_is_primitive(type)) { dest_name = CFCType_get_specifier(type); if (value != NULL) { maybe_maybe = "maybe_"; } var_name = CFCUtil_sprintf("%s_ARG", CFCVariable_get_name(var)); } else if (CFCType_is_object(type)) { if (CFCType_nullable(type) || (value && strcmp(value, "NULL") == 0) ) { maybe_maybe = "maybe_"; } if (strcmp(specifier, "cfish_String") == 0) { dest_name = "string"; var_name = CFCUtil_sprintf("%s_ARG", CFCVariable_get_name(var)); } else if (strcmp(specifier, "cfish_Hash") == 0) { dest_name = "hash"; var_name = CFCUtil_sprintf("%s_ARG", CFCVariable_get_name(var)); } else if (strcmp(specifier, "cfish_Vector") == 0) { dest_name = "vec"; var_name = CFCUtil_sprintf("%s_ARG", CFCVariable_get_name(var)); } else { dest_name = "obj"; var_name = CFCUtil_sprintf("wrap_arg_%s", micro_sym); } } else { dest_name = "INVALID"; } char *content = CFCUtil_sprintf(", CFBind_%sconvert_%s, &%s", maybe_maybe, dest_name, var_name); FREEMEM(var_name); return content; }
static char* S_build_pymeth_invocation(CFCMethod *method) { CFCType *return_type = CFCMethod_get_return_type(method); const char *micro_sym = CFCSymbol_get_name((CFCSymbol*)method); char *invocation = NULL; const char *ret_type_str = CFCType_to_c(return_type); if (CFCType_is_void(return_type)) { const char pattern[] = " CALL_PYMETH_VOID((PyObject*)self, \"%s\", cfcb_ARGS);"; invocation = CFCUtil_sprintf(pattern, micro_sym); } else if (CFCType_is_object(return_type)) { const char *nullable = CFCType_nullable(return_type) ? "true" : "false"; const char *ret_class = CFCType_get_class_var(return_type); const char pattern[] = " %s cfcb_RESULT = (%s)CALL_PYMETH_OBJ((PyObject*)self, \"%s\", cfcb_ARGS, %s, %s);"; invocation = CFCUtil_sprintf(pattern, ret_type_str, ret_type_str, micro_sym, ret_class, nullable); } else if (CFCType_is_primitive(return_type)) { char type_upcase[64]; if (strlen(ret_type_str) > 63) { CFCUtil_die("Unexpectedly long type name: %s", ret_type_str); } for (int i = 0, max = strlen(ret_type_str) + 1; i < max; i++) { type_upcase[i] = toupper(ret_type_str[i]); } const char pattern[] = " %s cfcb_RESULT = CALL_PYMETH_%s((PyObject*)self, \"%s\", cfcb_ARGS);"; invocation = CFCUtil_sprintf(pattern, ret_type_str, type_upcase, micro_sym); } else { CFCUtil_die("Unexpected return type: %s", CFCType_to_c(return_type)); } return invocation; }
static char* S_obj_callback_def(CFCMethod *method, const char *callback_start, const char *refcount_mods) { const char *override_sym = CFCMethod_full_override_sym(method); const char *params = CFCParamList_to_c(CFCMethod_get_param_list(method)); CFCType *return_type = CFCMethod_get_return_type(method); const char *ret_type_str = CFCType_to_c(return_type); const char *micro_sym = CFCMethod_micro_sym(method); const char *nullable = CFCType_nullable(return_type) ? "true" : "false"; char pattern[] = "%s\n" "%s(%s) {\n" "%s" " %s retval = (%s)S_finish_callback_obj(self, \"%s\", %s);%s\n" " return retval;\n" "}\n"; char *callback_def = CFCUtil_sprintf(pattern, ret_type_str, override_sym, params, callback_start, ret_type_str, ret_type_str, micro_sym, nullable, refcount_mods); return callback_def; }