/* * Generate the XML for an argument. */ static void xmlArgument(sipSpec *pt, moduleDef *mod, argDef *ad, int out, KwArgs kwargs, int res_xfer, int indent, FILE *fp) { if (isArraySize(ad)) return; xmlIndent(indent, fp); fprintf(fp, "<%s", (out ? "Return" : "Argument")); xmlType(pt, mod, ad, out, kwargs, fp); if (!out) { if (isAllowNone(ad)) fprintf(fp, " allownone=\"1\""); if (isDisallowNone(ad)) fprintf(fp, " disallownone=\"1\""); if (isTransferred(ad)) fprintf(fp, " transfer=\"to\""); else if (isThisTransferred(ad)) fprintf(fp, " transfer=\"this\""); } if (res_xfer || isTransferredBack(ad)) fprintf(fp, " transfer=\"back\""); fprintf(fp, "/>\n"); }
/* * Generate the XML for an argument. */ static void xmlArgument(sipSpec *pt, argDef *ad, const char *dir, int res_xfer, int sec, int indent, FILE *fp) { if (isArraySize(ad)) return; if (sec && (ad->atype == slotcon_type || ad->atype == slotdis_type)) return; xmlIndent(indent, fp); fprintf(fp, "<Argument"); xmlType(pt, ad, sec, fp); if (dir != NULL) fprintf(fp, " dir=\"%s\"", dir); if (isAllowNone(ad)) fprintf(fp, " allownone=\"1\""); if (isDisallowNone(ad)) fprintf(fp, " disallownone=\"1\""); if (isTransferred(ad)) fprintf(fp, " transfer=\"to\""); else if (isThisTransferred(ad)) fprintf(fp, " transfer=\"this\""); else if (res_xfer || isTransferredBack(ad)) fprintf(fp, " transfer=\"back\""); /* * Handle the default value, but ignore it if it is an output only * argument. */ if (ad->defval && (dir == NULL || strcmp(dir, "out") != 0)) { prcode(fp, " default=\"%M"); exportDefaultValue(ad, FALSE, fp); prcode(fp, "%M\""); } fprintf(fp, "/>\n"); }
/* * Generate a Python argument. */ static int pyiArgument(sipSpec *pt, moduleDef *mod, argDef *ad, int arg_nr, int out, int need_comma, int sec, int names, int defaults, ifaceFileList *defined, KwArgs kwargs, int pep484, FILE *fp) { int optional, use_optional; if (isArraySize(ad)) return need_comma; if (sec && (ad->atype == slotcon_type || ad->atype == slotdis_type)) return need_comma; if (need_comma) fprintf(fp, ", "); optional = (defaults && ad->defval && !out); /* * We only show names for PEP 484 type hints and when they are part of the * API. */ if (names) names = (pep484 || kwargs == AllKwArgs || (kwargs == OptionalKwArgs && optional)); if (names && ad->atype != ellipsis_type) { if (ad->name != NULL) fprintf(fp, "%s%s: ", ad->name->text, (isPyKeyword(ad->name->text) ? "_" : "")); else fprintf(fp, "a%d: ", arg_nr); } use_optional = FALSE; if (optional && pep484) { /* Assume pointers can be None unless specified otherwise. */ if (isAllowNone(ad) || (!isDisallowNone(ad) && ad->nrderefs > 0)) { fprintf(fp, "typing.Optional["); use_optional = TRUE; } } pyiType(pt, mod, ad, out, sec, defined, pep484, fp); if (names && ad->atype == ellipsis_type) { if (ad->name != NULL) fprintf(fp, "%s%s", ad->name->text, (isPyKeyword(ad->name->text) ? "_" : "")); else fprintf(fp, "a%d", arg_nr); } if (optional) { if (use_optional) fprintf(fp, "]"); fprintf(fp, " = "); if (pep484) fprintf(fp, "..."); else prDefaultValue(ad, TRUE, fp); } return TRUE; }