/* * Export the default value of an argument. */ static void exportDefaultValue(argDef *ad, int in_str, FILE *fp) { /* Use any explicitly provided documentation. */ if (ad->docval != NULL) { prcode(fp, "%s", ad->docval); return; } /* Translate some special cases. */ if (ad->defval->next == NULL && ad->defval->vtype == numeric_value) { if (ad->nrderefs > 0 && ad->defval->u.vnum == 0) { prcode(fp, "None"); return; } if (ad->atype == bool_type || ad->atype == cbool_type) { prcode(fp, ad->defval->u.vnum ? "True" : "False"); return; } } generateExpression(ad->defval, in_str, fp); }
/* * Generate the default value of an argument. */ void prDefaultValue(argDef *ad, int in_str, FILE *fp) { /* Use any explicitly provided documentation. */ if (ad->typehint_value != NULL) { fprintf(fp, "%s", ad->typehint_value); return; } /* Translate some special cases. */ if (ad->defval->next == NULL && ad->defval->vtype == numeric_value) { if (ad->nrderefs > 0 && ad->defval->u.vnum == 0) { fprintf(fp, "None"); return; } if (ad->atype == bool_type || ad->atype == cbool_type) { fprintf(fp, ad->defval->u.vnum ? "True" : "False"); return; } } /* SIP v5 won't need this. */ prcode(fp, "%M"); generateExpression(ad->defval, in_str, fp); prcode(fp, "%M"); }
/* * 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 the API for an argument. */ static int apiArgument(sipSpec *pt, argDef *ad, int out, int need_comma, int sec, int names, int defaults, int in_str, FILE *fp) { const char *tname; classDef *tscope; if (isArraySize(ad)) return need_comma; if (sec && (ad->atype == slotcon_type || ad->atype == slotdis_type)) return need_comma; if ((tname = pyType(pt, ad, sec, &tscope)) == NULL) return need_comma; if (need_comma) fprintf(fp, ", "); prScopedPythonName(fp, tscope, tname); /* * Handle the default value is required, but ignore it if it is an output * only argument. */ if (defaults && ad->defval && !out) { if (names && ad->name != NULL) fprintf(fp, " %s", ad->name->text); fprintf(fp, "="); prcode(fp, "%M"); exportDefaultValue(ad, in_str, fp); prcode(fp, "%M"); } return TRUE; }
/* * Generate the XML for a C++ signature. */ static void xmlCppSignature(FILE *fp, signatureDef *sd, int is_const) { int a; prcode(fp, "%M"); normaliseArgs(sd); prcode(fp, "("); for (a = 0; a < sd->nrArgs; ++a) { argDef *ad = &sd->args[a]; if (a > 0) prcode(fp, ","); generateBaseType(NULL, ad, TRUE, STRIP_GLOBAL, fp); } prcode(fp, ")%s", (is_const ? " const" : "")); restoreArgs(sd); prcode(fp, "%M"); }
/* * Generate the XML for a type. */ static void xmlType(sipSpec *pt, argDef *ad, int sec, FILE *fp) { const char *type_type = NULL, *type_name; classDef *type_scope; fprintf(fp, " typename=\""); switch (ad->atype) { case class_type: type_type = (isOpaque(ad->u.cd) ? "opaque" : "class"); break; case enum_type: if (ad->u.ed->pyname != NULL) type_type = "enum"; break; case rxcon_type: case rxdis_type: if (!sec) type_type = "class"; break; case qobject_type: type_type = "class"; break; case slotcon_type: case slotdis_type: { int a; prcode(fp, "SLOT("); for (a = 0; a < ad->u.sa->nrArgs; ++a) { if (a > 0) prcode(fp, ", "); prcode(fp, "%M%B%M", &ad->u.sa->args[a]); } prcode(fp, ")"); } break; case mapped_type: type_type = "mappedtype"; break; } if ((type_name = pyType(pt, ad, sec, &type_scope)) != NULL) prScopedPythonName(fp, type_scope, type_name); fprintf(fp, "\""); if (type_type != NULL) fprintf(fp, " typetype=\"%s\"", type_type); if (ad->name != NULL) fprintf(fp, " name=\"%s\"", ad->name->text); }
/* * Generate the XML for a C++ signature. */ static void xmlCppSignature(FILE *fp, overDef *od) { prcode(fp, "%M"); prOverloadDecl(fp, NULL, od, TRUE); prcode(fp, "%M"); }