/* * Generate a Python signature. */ int prPythonSignature(sipSpec *pt, FILE *fp, signatureDef *sd, int sec, int names, int defaults, int in_str) { int need_sec = FALSE, need_comma = FALSE, is_res, nr_out, a; fprintf(fp, "("); nr_out = 0; for (a = 0; a < sd->nrArgs; ++a) { argDef *ad = &sd->args[a]; if (isOutArg(ad)) ++nr_out; if (!isInArg(ad)) continue; need_comma = apiArgument(pt, ad, FALSE, need_comma, sec, names, defaults, in_str, fp); if (ad->atype == rxcon_type || ad->atype == rxdis_type) need_sec = TRUE; } fprintf(fp, ")"); is_res = !((sd->result.atype == void_type && sd->result.nrderefs == 0) || (sd->result.doctype != NULL && sd->result.doctype[0] == '\0')); if (is_res || nr_out > 0) { fprintf(fp, " -> "); if ((is_res && nr_out > 0) || nr_out > 1) fprintf(fp, "("); if (is_res) need_comma = apiArgument(pt, &sd->result, TRUE, FALSE, sec, FALSE, FALSE, in_str, fp); else need_comma = FALSE; for (a = 0; a < sd->nrArgs; ++a) { argDef *ad = &sd->args[a]; if (isOutArg(ad)) /* We don't want the name in the result tuple. */ need_comma = apiArgument(pt, ad, TRUE, need_comma, sec, FALSE, FALSE, in_str, fp); } if ((is_res && nr_out > 0) || nr_out > 1) fprintf(fp, ")"); } return need_sec; }
/* * Convert an arguments direction to an XML attribute value. */ static const char *dirAttribute(argDef *ad) { if (isInArg(ad)) { if (isOutArg(ad)) return "inout"; return NULL; } return "out"; }
/* * See if a signature has implicit overloads. */ int hasImplicitOverloads(signatureDef *sd) { int a; for (a = 0; a < sd->nrArgs; ++a) { argDef *ad = &sd->args[a]; if (!isInArg(ad)) continue; if (ad->atype == rxcon_type || ad->atype == rxdis_type) return TRUE; } return FALSE; }
/* * Generate the XML for a ctor. */ static void xmlCtor(sipSpec *pt, moduleDef *mod, classDef *scope, ctorDef *ct, int indent, FILE *fp) { int a; xmlIndent(indent++, fp); fprintf(fp, "<Function name=\""); prScopedPythonName(fp, scope, "__init__"); fprintf(fp, "\""); xmlRealScopedName(scope, "__init__", fp); if (hasCppSignature(ct->cppsig)) { fprintf(fp, " cppsig=\""); xmlCppSignature(fp, ct->cppsig, FALSE); fprintf(fp, "\""); } /* Handle the trivial case. */ if (ct->pysig.nrArgs == 0) { fprintf(fp, "/>\n"); return; } fprintf(fp, ">\n"); for (a = 0; a < ct->pysig.nrArgs; ++a) { argDef *ad = &ct->pysig.args[a]; if (isInArg(ad)) xmlArgument(pt, mod, ad, FALSE, ct->kwargs, FALSE, indent, fp); if (isOutArg(ad)) xmlArgument(pt, mod, ad, TRUE, ct->kwargs, FALSE, indent, fp); } xmlIndent(--indent, fp); fprintf(fp, "</Function>\n"); }
/* * Generate a Python signature. */ static void pyiPythonSignature(sipSpec *pt, moduleDef *mod, signatureDef *sd, int need_self, int sec, ifaceFileList *defined, KwArgs kwargs, int pep484, FILE *fp) { int void_return, need_comma, is_res, nr_out, a; if (need_self) { fprintf(fp, "(self"); need_comma = TRUE; } else { fprintf(fp, "("); need_comma = FALSE; } nr_out = 0; for (a = 0; a < sd->nrArgs; ++a) { argDef *ad = &sd->args[a]; if (isOutArg(ad)) ++nr_out; if (!isInArg(ad)) continue; need_comma = pyiArgument(pt, mod, ad, a, FALSE, need_comma, sec, TRUE, TRUE, defined, kwargs, pep484, fp); } fprintf(fp, ")"); /* An empty type hint specifies a void return. */ if (sd->result.typehint_out != NULL) void_return = (sd->result.typehint_out->raw_hint[0] == '\0'); else void_return = FALSE; is_res = !((sd->result.atype == void_type && sd->result.nrderefs == 0) || void_return); if (is_res || nr_out > 0) { fprintf(fp, " -> "); if ((is_res && nr_out > 0) || nr_out > 1) fprintf(fp, "%sTuple[", (pep484 ? "typing." : "")); if (is_res) need_comma = pyiArgument(pt, mod, &sd->result, -1, TRUE, FALSE, sec, FALSE, FALSE, defined, kwargs, pep484, fp); else need_comma = FALSE; for (a = 0; a < sd->nrArgs; ++a) { argDef *ad = &sd->args[a]; if (isOutArg(ad)) /* We don't want the name in the result tuple. */ need_comma = pyiArgument(pt, mod, ad, -1, TRUE, need_comma, sec, FALSE, FALSE, defined, kwargs, pep484, fp); } if ((is_res && nr_out > 0) || nr_out > 1) fprintf(fp, "]"); } else if (pep484) { fprintf(fp, " -> None"); } }
/* * Generate the XML for an overload. */ static void xmlOverload(sipSpec *pt, moduleDef *mod, classDef *scope, memberDef *md, overDef *od, classDef *xtnds, int stat, int indent, FILE *fp) { const char *name, *cppname = od->cppname; int a, no_res; xmlIndent(indent++, fp); fprintf(fp, "<Function name=\""); if (isReflected(od)) { if ((name = reflectedSlot(md->slot)) != NULL) cppname = name; else name = md->pyname->text; } else { name = md->pyname->text; } prScopedPythonName(fp, scope, name); fprintf(fp, "\""); xmlRealScopedName(scope, cppname, fp); if (hasCppSignature(od->cppsig)) { fprintf(fp, " cppsig=\""); xmlCppSignature(fp, od->cppsig, isConst(od)); fprintf(fp, "\""); } if (isAbstract(od)) fprintf(fp, " abstract=\"1\""); if (stat) fprintf(fp, " static=\"1\""); if (isSlot(od)) fprintf(fp, " slot=\"1\""); if (isVirtual(od)) { fprintf(fp, " virtual=\"1\""); } if (xtnds != NULL) { fprintf(fp, " extends=\""); prScopedPythonName(fp, xtnds->ecd, xtnds->pyname->text); fprintf(fp, "\""); } /* An empty type hint specifies a void return. */ if (od->pysig.result.typehint_out != NULL && od->pysig.result.typehint_out->raw_hint[0] == '\0') no_res = TRUE; else no_res = (od->pysig.result.atype == void_type && od->pysig.result.nrderefs == 0); /* Handle the trivial case. */ if (no_res && od->pysig.nrArgs == 0) { fprintf(fp, "/>\n"); return; } fprintf(fp, ">\n"); if (!no_res) xmlArgument(pt, mod, &od->pysig.result, TRUE, NoKwArgs, isResultTransferredBack(od), indent, fp); for (a = 0; a < od->pysig.nrArgs; ++a) { argDef *ad = &od->pysig.args[a]; /* * Ignore the first argument of non-reflected number slots and the * second argument of reflected number slots. */ if (isNumberSlot(md) && od->pysig.nrArgs == 2) if ((a == 0 && !isReflected(od)) || (a == 1 && isReflected(od))) continue; if (isInArg(ad)) xmlArgument(pt, mod, ad, FALSE, od->kwargs, FALSE, indent, fp); if (isOutArg(ad)) xmlArgument(pt, mod, ad, TRUE, od->kwargs, FALSE, indent, fp); } xmlIndent(--indent, fp); fprintf(fp, "</Function>\n"); }
/* * Generate a Python signature. */ static void exportPythonSignature(sipSpec *pt, FILE *fp, signatureDef *sd, int names, int defaults, int in_str, int is_signal) { int need_comma = FALSE, is_res, nr_out, a; if (is_signal) { if (sd->nrArgs != 0) fprintf(fp, "["); } else { fprintf(fp, "("); } nr_out = 0; for (a = 0; a < sd->nrArgs; ++a) { argDef *ad = &sd->args[a]; if (isOutArg(ad)) ++nr_out; if (!isInArg(ad)) continue; need_comma = apiArgument(pt, ad, FALSE, need_comma, names, defaults, in_str, fp); } if (is_signal) { if (sd->nrArgs != 0) fprintf(fp, "]"); } else { fprintf(fp, ")"); } is_res = !((sd->result.atype == void_type && sd->result.nrderefs == 0) || (sd->result.doctype != NULL && sd->result.doctype[0] == '\0')); if (is_res || nr_out > 0) { fprintf(fp, " -> "); if ((is_res && nr_out > 0) || nr_out > 1) fprintf(fp, "("); if (is_res) need_comma = apiArgument(pt, &sd->result, TRUE, FALSE, FALSE, FALSE, in_str, fp); else need_comma = FALSE; for (a = 0; a < sd->nrArgs; ++a) { argDef *ad = &sd->args[a]; if (isOutArg(ad)) /* We don't want the name in the result tuple. */ need_comma = apiArgument(pt, ad, TRUE, need_comma, FALSE, FALSE, in_str, fp); } if ((is_res && nr_out > 0) || nr_out > 1) fprintf(fp, ")"); } }