/* * Generate the API file. */ void generateAPI(sipSpec *pt, moduleDef *mod, const char *apiFile) { overDef *od; classDef *cd; FILE *fp; /* Generate the file. */ if ((fp = fopen(apiFile, "w")) == NULL) fatal("Unable to create file \"%s\"\n", apiFile); apiEnums(pt, mod, NULL, fp); apiVars(pt, mod, NULL, fp); for (od = mod->overs; od != NULL; od = od->next) { if (od->common->module != mod) continue; if (od->common->slot != no_slot) continue; apiOverload(pt, mod, NULL, od, fp); } for (cd = pt->classes; cd != NULL; cd = cd->next) { ctorDef *ct; if (cd->iff->module != mod) continue; if (isExternal(cd)) continue; apiEnums(pt, mod, cd, fp); apiVars(pt, mod, cd, fp); for (ct = cd->ctors; ct != NULL; ct = ct->next) { if (isPrivateCtor(ct)) continue; apiCtor(pt, mod, cd, ct, fp); } for (od = cd->overs; od != NULL; od = od->next) { if (isPrivate(od)) continue; if (od->common->slot != no_slot) continue; apiOverload(pt, mod, cd, od, fp); } } fclose(fp); }
/* * Generate the type hints for a class. */ static void pyiClass(sipSpec *pt, moduleDef *mod, classDef *cd, ifaceFileList **defined, int indent, FILE *fp) { int first, no_body, nr_overloads; classDef *nested; ctorDef *ct; memberDef *md; separate(TRUE, indent, fp); prIndent(indent, fp); fprintf(fp, "class %s(", cd->pyname->text); if (cd->supers != NULL) { classList *cl; for (cl = cd->supers; cl != NULL; cl = cl->next) { if (cl != cd->supers) fprintf(fp, ", "); prClassRef(cl->cd, mod, *defined, TRUE, fp); } } else if (cd->supertype != NULL) { fprintf(fp, "%s", cd->supertype->text); } else if (cd->iff->type == namespace_iface) { fprintf(fp, "sip.simplewrapper"); } else { fprintf(fp, "sip.wrapper"); } /* See if there is anything in the class body. */ nr_overloads = 0; for (ct = cd->ctors; ct != NULL; ct = ct->next) { if (isPrivateCtor(ct)) continue; if (ct->no_typehint) continue; if (!inDefaultAPI(pt, ct->api_range)) continue; ++nr_overloads; } no_body = (cd->typehintcode == NULL && nr_overloads == 0); if (no_body) { overDef *od; for (od = cd->overs; od != NULL; od = od->next) { if (isPrivate(od)) continue; if (od->no_typehint) continue; if (inDefaultAPI(pt, od->api_range)) { no_body = FALSE; break; } } } if (no_body) { enumDef *ed; for (ed = pt->enums; ed != NULL; ed = ed->next) { if (ed->no_typehint) continue; if (ed->ecd == cd) { no_body = FALSE; break; } } } if (no_body) { for (nested = pt->classes; nested != NULL; nested = nested->next) { if (nested->no_typehint) continue; if (nested->ecd == cd) { no_body = FALSE; break; } } } if (no_body) { varDef *vd; for (vd = pt->vars; vd != NULL; vd = vd->next) { if (vd->no_typehint) continue; if (vd->ecd == cd) { no_body = FALSE; break; } } } fprintf(fp, "):%s\n", (no_body ? " ..." : "")); ++indent; pyiTypeHintCode(cd->typehintcode, indent, fp); pyiEnums(pt, mod, cd->iff, *defined, indent, fp); /* Handle any nested classes. */ for (nested = pt->classes; nested != NULL; nested = nested->next) { classDef *impl = getClassImplementation(pt, nested); if (impl != NULL && impl->ecd == cd && !impl->no_typehint) pyiClass(pt, mod, impl, defined, indent, fp); } pyiVars(pt, mod, cd, *defined, indent, fp); first = TRUE; for (ct = cd->ctors; ct != NULL; ct = ct->next) { int implicit_overloads, overloaded; if (isPrivateCtor(ct)) continue; if (ct->no_typehint) continue; if (!inDefaultAPI(pt, ct->api_range)) continue; implicit_overloads = hasImplicitOverloads(&ct->pysig); overloaded = (implicit_overloads || nr_overloads > 1); first = separate(first, indent, fp); pyiCtor(pt, mod, NULL, ct, overloaded, FALSE, *defined, indent, fp); if (implicit_overloads) pyiCtor(pt, mod, NULL, ct, overloaded, TRUE, *defined, indent, fp); } first = TRUE; for (md = cd->members; md != NULL; md = md->next) { /* * Ignore slots which can return Py_NotImplemented as code may be * correctly handled elsewhere. We also have to include the sequence * slots because they can't be distinguished from the number slots of * the same name. */ if (isNumberSlot(md) || isInplaceNumberSlot(md) || isRichCompareSlot(md) || md->slot == concat_slot || md->slot == iconcat_slot || md->slot == repeat_slot || md->slot == irepeat_slot) continue; first = separate(first, indent, fp); pyiCallable(pt, mod, md, cd->overs, TRUE, *defined, indent, fp); } /* * Keep track of what has been defined so that forward references are no * longer required. */ appendToIfaceFileList(defined, cd->iff); }
/* * Generate the XML for a class. */ static void xmlClass(sipSpec *pt, moduleDef *mod, classDef *cd, FILE *fp) { int indent = 1; ctorDef *ct; memberDef *md; if (isOpaque(cd)) { xmlIndent(indent, fp); fprintf(fp, "<OpaqueClass name=\""); prScopedPythonName(fp, cd->ecd, cd->pyname->text); fprintf(fp, "\"/>\n"); return; } xmlIndent(indent++, fp); fprintf(fp, "<Class name=\""); prScopedPythonName(fp, cd->ecd, cd->pyname->text); fprintf(fp, "\""); if (cd->picklecode != NULL) fprintf(fp, " pickle=\"1\""); if (cd->convtocode != NULL) fprintf(fp, " convert=\"1\""); if (cd->convfromcode != NULL) fprintf(fp, " convertfrom=\"1\""); if (cd->real != NULL) fprintf(fp, " extends=\"%s\"", cd->real->iff->module->name); if (cd->supers != NULL) { classList *cl; fprintf(fp, " inherits=\""); for (cl = cd->supers; cl != NULL; cl = cl->next) { if (cl != cd->supers) fprintf(fp, " "); prScopedPythonName(fp, cl->cd->ecd, cl->cd->pyname->text); } fprintf(fp, "\""); } fprintf(fp, ">\n"); xmlEnums(pt, mod, cd, indent, fp); xmlVars(pt, mod, cd, indent, fp); for (ct = cd->ctors; ct != NULL; ct = ct->next) { if (isPrivateCtor(ct)) continue; if (xmlCtor(pt, cd, ct, FALSE, indent, fp)) xmlCtor(pt, cd, ct, TRUE, indent, fp); } for (md = cd->members; md != NULL; md = md->next) xmlFunction(pt, cd, md, cd->overs, indent, fp); xmlIndent(--indent, fp); fprintf(fp, "</Class>\n"); }
/* * Generate the XML for a class. */ static void xmlClass(sipSpec *pt, moduleDef *mod, classDef *cd, FILE *fp) { int indent = 1; ctorDef *ct; memberDef *md; if (isOpaque(cd)) { xmlIndent(indent, fp); fprintf(fp, "<OpaqueClass name=\""); prScopedPythonName(fp, cd->ecd, cd->pyname->text); fprintf(fp, "\"/>\n"); return; } if (!isHiddenNamespace(cd)) { xmlIndent(indent++, fp); fprintf(fp, "<Class name=\""); prScopedPythonName(fp, cd->ecd, cd->pyname->text); fprintf(fp, "\""); xmlRealName(classFQCName(cd), NULL, fp); if (cd->picklecode != NULL) fprintf(fp, " pickle=\"1\""); if (cd->convtocode != NULL) fprintf(fp, " convert=\"1\""); if (cd->convfromcode != NULL) fprintf(fp, " convertfrom=\"1\""); if (cd->real != NULL) fprintf(fp, " extends=\"%s\"", cd->real->iff->module->name); if (cd->pyqt_flags_enums != NULL) { const char *sep; stringList *sl; fprintf(fp, " flagsenums=\""); sep = ""; for (sl = cd->pyqt_flags_enums; sl != NULL; sl = sl->next) { fprintf(fp, "%s%s", sep, sl->s); sep = " "; } fprintf(fp, "\""); } if (cd->supers != NULL) { classList *cl; fprintf(fp, " inherits=\""); for (cl = cd->supers; cl != NULL; cl = cl->next) { if (cl != cd->supers) fprintf(fp, " "); restPyClass(cl->cd, fp); } fprintf(fp, "\""); } fprintf(fp, ">\n"); } for (ct = cd->ctors; ct != NULL; ct = ct->next) { if (isPrivateCtor(ct)) continue; xmlCtor(pt, mod, cd, ct, indent, fp); } xmlEnums(pt, mod, cd, indent, fp); xmlVars(pt, mod, cd, indent, fp); for (md = cd->members; md != NULL; md = md->next) xmlFunction(pt, mod, cd, md, cd->overs, indent, fp); if (!isHiddenNamespace(cd)) { xmlIndent(--indent, fp); fprintf(fp, "</Class>\n"); } }