Beispiel #1
0
/*
 * Generate the XML for an overload.
 */
static int xmlOverload(sipSpec *pt, classDef *scope, memberDef *md,
        overDef *od, classDef *xtnds, int stat, int sec, int indent, FILE *fp)
{
    int a, need_sec, no_res;

    xmlIndent(indent++, fp);
    fprintf(fp, "<Function name=\"");
    prScopedPythonName(fp, scope, md->pyname->text);
    fprintf(fp, "\"");

    if (isAbstract(od))
        fprintf(fp, " abstract=\"1\"");

    if (stat)
        fprintf(fp, " static=\"1\"");

    if (isSlot(od))
    {
        fprintf(fp, " slot=\"");
        xmlCppSignature(fp, od);
        fprintf(fp, "\"");
    }

    if (xtnds != NULL)
    {
        fprintf(fp, " extends=\"");
        prScopedPythonName(fp, xtnds->ecd, xtnds->pyname->text);
        fprintf(fp, "\"");
    }

    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 FALSE;
    }

    fprintf(fp, ">\n");

    if (!no_res)
        xmlArgument(pt, &od->pysig.result, "out", isResultTransferredBack(od),
                FALSE, indent, fp);

    need_sec = FALSE;

    for (a = 0; a < od->pysig.nrArgs; ++a)
    {
        argDef *ad = &od->pysig.args[a];

        /* Ignore the first argument of number slots. */
        if (isNumberSlot(md) && a == 0 && od->pysig.nrArgs == 2)
            continue;

        xmlArgument(pt, ad, dirAttribute(ad), FALSE, sec, indent, fp);

        if (ad->atype == rxcon_type || ad->atype == rxdis_type)
            need_sec = TRUE;
    }

    xmlIndent(--indent, fp);
    fprintf(fp, "</Function>\n");

    return need_sec;
}
/*
 * 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);
}
Beispiel #3
0
/*
 * 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");
}