/* * Return TRUE if a version range includes the default API. */ int inDefaultAPI(sipSpec *pt, apiVersionRangeDef *range) { int def_api; /* Handle the trivial case. */ if (range == NULL) return TRUE; /* Get the default API. */ def_api = findAPI(pt, range->api_name->text)->from; if (range->from > 0 && range->from > def_api) return FALSE; if (range->to > 0 && range->to <= def_api) return FALSE; return TRUE; }
/* * Get the implementation (if there is one) for a type for the default API * version. */ void getDefaultImplementation(sipSpec *pt, argType atype, classDef **cdp, mappedTypeDef **mtdp) { classDef *cd; mappedTypeDef *mtd; ifaceFileDef *iff; if (atype == class_type) { cd = *cdp; mtd = NULL; iff = cd->iff; } else { cd = NULL; mtd = *mtdp; iff = mtd->iff; } /* See if there is more than one implementation. */ if (iff->api_range != NULL) { int def_api; cd = NULL; mtd = NULL; /* Find the default implementation. */ def_api = findAPI(pt, iff->api_range->api_name->text)->from; for (iff = iff->first_alt; iff != NULL; iff = iff->next_alt) { apiVersionRangeDef *avd = iff->api_range; if (avd->from > 0 && avd->from > def_api) continue; if (avd->to > 0 && avd->to <= def_api) continue; /* It's within range. */ if (iff->type == class_iface) { for (cd = pt->classes; cd != NULL; cd = cd->next) if (cd->iff == iff) break; } else { for (mtd = pt->mappedtypes; mtd != NULL; mtd = mtd->next) if (mtd->iff == iff) break; } break; } } *cdp = cd; *mtdp = mtd; }
/* * Get the Python representation of a type. */ static const char *pyType(sipSpec *pt, argDef *ad, int sec, classDef **scope) { const char *type_name; *scope = NULL; /* Use any explicit documented type. */ if (ad->doctype != NULL) return ad->doctype; /* For classes and mapped types we need the default implementation. */ if (ad->atype == class_type || ad->atype == mapped_type) { classDef *def_cd = NULL; mappedTypeDef *def_mtd = NULL; ifaceFileDef *iff; if (ad->atype == class_type) { iff = ad->u.cd->iff; if (iff->api_range == NULL) { /* There is only one implementation. */ def_cd = ad->u.cd; iff = NULL; } } else { iff = ad->u.mtd->iff; if (iff->api_range == NULL) { /* There is only one implementation. */ def_mtd = ad->u.mtd; iff = NULL; } } if (iff != NULL) { int def_api; /* Find the default implementation. */ def_api = findAPI(pt, iff->api_range->api_name->text)->from; for (iff = iff->first_alt; iff != NULL; iff = iff->next_alt) { apiVersionRangeDef *avd = iff->api_range; if (avd->from > 0 && avd->from > def_api) continue; if (avd->to > 0 && avd->to <= def_api) continue; /* It's within range. */ break; } /* Find the corresponding class or mapped type. */ for (def_cd = pt->classes; def_cd != NULL; def_cd = def_cd->next) if (def_cd->iff == iff) break; if (def_cd == NULL) for (def_mtd = pt->mappedtypes; def_mtd != NULL; def_mtd = def_mtd->next) if (def_mtd->iff == iff) break; } /* Now handle the correct implementation. */ if (def_cd != NULL) { *scope = def_cd->ecd; type_name = def_cd->pyname->text; } else { /* * Give a hint that /DocType/ should be used, or there is no * default implementation. */ type_name = "unknown-type"; if (def_mtd != NULL) { if (def_mtd->doctype != NULL) type_name = def_mtd->doctype; else if (def_mtd->pyname != NULL) type_name = def_mtd->pyname->text; } } return type_name; } switch (ad->atype) { case capsule_type: type_name = scopedNameTail(ad->u.cap); break; case struct_type: case void_type: type_name = "sip.voidptr"; break; case enum_type: if (ad->u.ed->pyname != NULL) { type_name = ad->u.ed->pyname->text; *scope = ad->u.ed->ecd; } else type_name = "int"; break; case signal_type: type_name = "SIGNAL()"; break; case slot_type: type_name = "SLOT()"; break; case rxcon_type: case rxdis_type: if (sec) type_name = "callable"; else type_name = "QObject"; break; case qobject_type: type_name = "QObject"; break; case ustring_type: case string_type: case sstring_type: case wstring_type: case ascii_string_type: case latin1_string_type: case utf8_string_type: type_name = "str"; break; case byte_type: case sbyte_type: case ubyte_type: case ushort_type: case uint_type: case long_type: case longlong_type: case ulong_type: case ulonglong_type: case short_type: case int_type: case cint_type: type_name = "int"; break; case float_type: case cfloat_type: case double_type: case cdouble_type: type_name = "float"; break; case bool_type: case cbool_type: type_name = "bool"; break; case pyobject_type: type_name = "object"; break; case pytuple_type: type_name = "tuple"; break; case pylist_type: type_name = "list"; break; case pydict_type: type_name = "dict"; break; case pycallable_type: type_name = "callable"; break; case pyslice_type: type_name = "slice"; break; case pytype_type: type_name = "type"; break; case pybuffer_type: type_name = "buffer"; break; case ellipsis_type: type_name = "..."; break; case slotcon_type: case anyslot_type: type_name = "SLOT()"; break; default: type_name = NULL; } return type_name; }