/* ::cortex::lang::struct::compatible(type type) */ cx_bool cx_struct_compatible_v(cx_struct _this, cx_type type) { /* $begin(::cortex::lang::struct::compatible) */ cx_bool result; cx_assert(cx_class_instanceof(cx_struct_o, _this), "struct::compatible called on non-struct object."); result = FALSE; /* Call overloaded type::compatible function first to check for generic compatibility. */ if (!cx_type_compatible_v(cx_type(_this), type)) { /* Type must be at least struct for it to be compatible. */ if (cx_class_instanceof(cx_struct_o, type)) { cx_interface e; /* Check if '_this' is superclass of 'type' */ e = cx_interface(type); do { e = cx_interface(e)->base; }while(e && (e != cx_interface(_this))); result = (e == (cx_interface)_this); } } else { result = TRUE; } return result; /* $end */ }
static int cx_functionLookupWalk(cx_object o, void* userData) { cx_functionLookup_t* data; cx_int32 d; data = userData; if (o != data->f) { if ((cx_class_instanceof(cx_procedure_o, cx_typeof(o)))) { if (cx_overload(o, cx_nameof(data->f), &d, FALSE)) { data->error = TRUE; goto finish; } /* Check if function matches */ if (!d) { cx_id id, id2; cx_error("function '%s' conflicts with existing declaration '%s'", cx_fullname(data->f, id), cx_fullname(o, id2)); data->error = TRUE; goto finish; } else { cx_id id; /* Get name of function */ cx_signatureName(cx_nameof(o), id); /* Set overloading flags if a function with same name is found. */ if (!strcmp(data->name, id)) { cx_function(o)->overloaded = TRUE; data->f->overloaded = TRUE; } } } } return 1; finish: return 0; }
/* Build dependency-administration for object */ int cx_genDepBuildAction(cx_object o, void* userData) { g_itemWalk_t data; struct g_depWalk_t walkData; struct cx_serializer_s s; int result; cx_object parent = NULL; if (cx_checkAttr(o, CX_ATTR_SCOPED)) { parent = cx_parentof(o); } data = userData; /* If object is cortex_lang_o, signal that a bootstrap is found, indicating * that dependencies should be disregarded. */ if (o == cortex_lang_o) { data->bootstrap = TRUE; result = 0; } else { /* Insert type-dependency: object can be declared only after it's type is defined. */ if (g_mustParse(data->g, cx_typeof(o))) { cx_depresolver_depend(data->resolver, o, CX_DECLARED, cx_typeof(o), CX_DEFINED); } /* TODO: this is not nice */ if (cx_class_instanceof(cx_procedure_o, cx_typeof(o))) { /* Insert base-dependency: methods may only be declared after the base of a class has been defined. */ if (cx_typeof(o) != cx_type(cx_function_o)) { if (cx_class_instanceof(cx_class_o, parent) && cx_interface(parent)->base) { if (g_mustParse(data->g, cx_interface(parent)->base)) { cx_depresolver_depend(data->resolver, o, CX_DECLARED, cx_interface(parent)->base, CX_DEFINED); } } } /* Add dependencies on function parameters - types must be declared before function is declared. */ if (cx_genDepBuildProc(cx_function(o), data)) { goto error; } } /* Insert dependency on parent */ if (cx_checkAttr(o, CX_ATTR_SCOPED)) { if (parent != root_o) { /* Root is always available */ cx_int8 parentState = cx_type(cx_typeof(o))->parentState; cx_depresolver_depend(data->resolver, o, CX_DECLARED, parent, parentState); if (parentState == CX_DECLARED) { cx_depresolver_depend(data->resolver, parent, CX_DEFINED, o, CX_DEFINED); } } } /* Insert dependencies on references in the object-value */ walkData.o = o; walkData.data = data; s = cx_genDepSerializer(); if (cx_serialize(&s, o, &walkData)) { goto error; } result = 1; } return result; error: return 0; }