Ejemplo n.º 1
0
static gboolean
typelib_attr_accessor(TreeState *state, XPTMethodDescriptor *meth,
                      gboolean getter, gboolean hidden, gboolean wantsJSContext)
{
    uint8 methflags = 0;
    uint8 pdflags = 0;

    methflags |= getter ? XPT_MD_GETTER : XPT_MD_SETTER;
    methflags |= hidden ? XPT_MD_HIDDEN : 0;
    methflags |= wantsJSContext ? XPT_MD_CONTEXT : 0;
    if (!XPT_FillMethodDescriptor(ARENA(state), meth, methflags,
                                  ATTR_IDENT(state->tree).str, 1))
        return FALSE;

    if (getter) {
        if (DIPPER_TYPE(ATTR_TYPE_DECL(state->tree))) {
            pdflags |= (XPT_PD_RETVAL | XPT_PD_IN | XPT_PD_DIPPER);
        } else {
            pdflags |= (XPT_PD_RETVAL | XPT_PD_OUT);
        }
    } else {
        pdflags |= XPT_PD_IN;
    }

    if (!fill_pd_from_type(state, meth->params, pdflags,
                           ATTR_TYPE_DECL(state->tree)))
        return FALSE;

    fill_pd_as_nsresult(meth->result);
    NEXT_METH(state)++;
    return TRUE;
}
Ejemplo n.º 2
0
static gboolean
write_attr_accessor(IDL_tree attr_tree, FILE * outfile,
                    gboolean getter, const char *className)
{
    char *attrname = ATTR_IDENT(attr_tree).str;

    fprintf(outfile, "function %cet%c%s(",
            getter ? 'G' : 'S',
            toupper(*attrname), attrname + 1);
    /* Setters for string, wstring, nsid, domstring, utf8string, 
     * cstring and astring get const. 
     */
    if (!getter &&
        (IDL_NODE_TYPE(ATTR_TYPE_DECL(attr_tree)) == IDLN_TYPE_STRING ||
         IDL_NODE_TYPE(ATTR_TYPE_DECL(attr_tree)) == IDLN_TYPE_WIDE_STRING ||
         IDL_tree_property_get(ATTR_TYPE_DECL(attr_tree), "nsid") ||
         IDL_tree_property_get(ATTR_TYPE_DECL(attr_tree), "domstring")  ||
         IDL_tree_property_get(ATTR_TYPE_DECL(attr_tree), "utf8string") ||
         IDL_tree_property_get(ATTR_TYPE_DECL(attr_tree), "cstring")    ||
         IDL_tree_property_get(ATTR_TYPE_DECL(attr_tree), "astring")))
    {
        fputs("const ", outfile);
    }

    fprintf(outfile, "%s",
            (getter && !DIPPER_TYPE(ATTR_TYPE_DECL(attr_tree)))? "out " : "");
    fprintf(outfile, "a%c%s", toupper(attrname[0]), attrname + 1);
    if (!interface_write_type(ATTR_TYPE_DECL(attr_tree), getter, FALSE, FALSE, FALSE, NULL, outfile))
        return FALSE;
    fputc(')', outfile);
    return TRUE;
}
Ejemplo n.º 3
0
/* If notype is true, just write the param name. */
static gboolean
write_param(IDL_tree param_tree, FILE *outfile)
{
    IDL_tree param_type_spec = IDL_PARAM_DCL(param_tree).param_type_spec;
    gboolean is_in = IDL_PARAM_DCL(param_tree).attr == IDL_PARAM_IN;
    /* in string, wstring, nsid, domstring, utf8string, cstring and 
     * astring any explicitly marked [const] are const 
     */

    if (is_in &&
        (IDL_NODE_TYPE(param_type_spec) == IDLN_TYPE_STRING ||
         IDL_NODE_TYPE(param_type_spec) == IDLN_TYPE_WIDE_STRING ||
         IDL_tree_property_get(IDL_PARAM_DCL(param_tree).simple_declarator,
                               "const") ||
         IDL_tree_property_get(param_type_spec, "nsid") ||
         IDL_tree_property_get(param_type_spec, "domstring")  ||
         IDL_tree_property_get(param_type_spec, "utf8string") ||
         IDL_tree_property_get(param_type_spec, "cstring")    ||
         IDL_tree_property_get(param_type_spec, "astring"))) {
        fputs("const ", outfile);
    }
    else if (IDL_PARAM_DCL(param_tree).attr == IDL_PARAM_OUT &&
             IDL_tree_property_get(IDL_PARAM_DCL(param_tree).simple_declarator, 
                                   "shared")) {
        fputs("const ", outfile);
    }

    if (!write_type(param_type_spec, !is_in, outfile))
        return FALSE;

    /* unless the type ended in a *, add a space */
    if (!STARRED_TYPE(param_type_spec))
        fputc(' ', outfile);

    /* out and inout params get a bonus '*' (unless this is type that has a 
     * 'dipper' class that is passed in to receive 'out' data) 
     */
    if (IDL_PARAM_DCL(param_tree).attr != IDL_PARAM_IN &&
        !DIPPER_TYPE(param_type_spec)) {
        fputc('*', outfile);
    }
    /* arrays get a bonus * too */
    /* XXX Should this be a leading '*' or a trailing "[]" ?*/
    if (IDL_tree_property_get(IDL_PARAM_DCL(param_tree).simple_declarator,
                              "array"))
        fputc('*', outfile);

    fputs(IDL_IDENT(IDL_PARAM_DCL(param_tree).simple_declarator).str, outfile);

    if (IDL_PARAM_DCL(param_tree).attr == IDL_PARAM_OUT) {
        fputs(" NS_OUTPARAM", outfile);
    } else if (IDL_PARAM_DCL(param_tree).attr == IDL_PARAM_INOUT) {
        fputs(" NS_INOUTPARAM", outfile);
    }

    return TRUE;
}
Ejemplo n.º 4
0
static gboolean
fill_pd_from_param(TreeState *state, XPTParamDescriptor *pd, IDL_tree tree)
{
    uint8 flags = 0;
    gboolean is_dipper_type = DIPPER_TYPE(IDL_PARAM_DCL(tree).param_type_spec);

    switch (IDL_PARAM_DCL(tree).attr) {
      case IDL_PARAM_IN:
        flags = XPT_PD_IN;
        break;
      case IDL_PARAM_OUT:
        flags = XPT_PD_OUT;
        break;
      case IDL_PARAM_INOUT:
        flags = XPT_PD_IN | XPT_PD_OUT;
        break;
    }

    if (IDL_tree_property_get(IDL_PARAM_DCL(tree).simple_declarator,
                              "retval")) {
        if (flags != XPT_PD_OUT) {
            IDL_tree_error(tree, "can't have [retval] with in%s param "
                           "(only out)\n",
                           flags & XPT_PD_OUT ? "out" : "");
            return FALSE;
        }
        flags |= XPT_PD_RETVAL;
    }

    if (is_dipper_type && (flags & XPT_PD_OUT)) {
        flags &= ~XPT_PD_OUT; 
        flags |= XPT_PD_IN | XPT_PD_DIPPER;
    }

    if (IDL_tree_property_get(IDL_PARAM_DCL(tree).simple_declarator,
                              "shared")) {
        if (flags & XPT_PD_IN) {
            IDL_tree_error(tree, "can't have [shared] with in%s param "
                           "(only out)\n",
                           flags & XPT_PD_OUT ? "out" : "");
            return FALSE;
        }
        flags |= XPT_PD_SHARED;
    }

    if (IDL_tree_property_get(IDL_PARAM_DCL(tree).simple_declarator,
                              "optional")) {
        flags |= XPT_PD_OPTIONAL;
    }

    /* stick param where we can see it later */
    state->tree = tree;
    return fill_pd_from_type(state, pd, flags,
                             IDL_PARAM_DCL(tree).param_type_spec);
}
Ejemplo n.º 5
0
/*
 *  AS_DECL writes 'NS_IMETHOD foo(string bar, long sil)'
 *  AS_IMPL writes 'NS_IMETHODIMP className::foo(string bar, long sil)'
 *  AS_CALL writes 'foo(bar, sil)'
 */
static gboolean
write_attr_accessor(IDL_tree attr_tree, FILE * outfile,
                    gboolean getter, int mode, const char *className)
{
    char *attrname = ATTR_IDENT(attr_tree).str;
    const char *binaryname;
    IDL_tree ident = IDL_LIST(IDL_ATTR_DCL(attr_tree).simple_declarations).data;

    if (mode == AS_DECL) {
        if (IDL_tree_property_get(ident, "deprecated"))
            fputs("NS_DEPRECATED ", outfile);
        if (is_method_scriptable(attr_tree, ident))
            fputs("NS_SCRIPTABLE ", outfile);

        fputs("NS_IMETHOD ", outfile);
    } else if (mode == AS_IMPL) {
        fprintf(outfile, "NS_IMETHODIMP %s::", className);
    }
    fprintf(outfile, "%cet",
            getter ? 'G' : 'S');
    binaryname = IDL_tree_property_get(ATTR_DECLS(attr_tree), "binaryname");
    if (binaryname) {
        fprintf(outfile, "%s(",
                binaryname);
    } else {
        fprintf(outfile, "%c%s(",
                toupper(*attrname),
                attrname + 1);
    }
    if (mode == AS_DECL || mode == AS_IMPL) {
        /* Setters for string, wstring, nsid, domstring, utf8string, 
         * cstring and astring get const. 
         */
        if (!getter &&
            (IDL_NODE_TYPE(ATTR_TYPE_DECL(attr_tree)) == IDLN_TYPE_STRING ||
             IDL_NODE_TYPE(ATTR_TYPE_DECL(attr_tree)) == IDLN_TYPE_WIDE_STRING ||
             IDL_tree_property_get(ATTR_TYPE_DECL(attr_tree), "nsid") ||
             IDL_tree_property_get(ATTR_TYPE_DECL(attr_tree), "domstring")  ||
             IDL_tree_property_get(ATTR_TYPE_DECL(attr_tree), "utf8string") ||
             IDL_tree_property_get(ATTR_TYPE_DECL(attr_tree), "cstring")    ||
             IDL_tree_property_get(ATTR_TYPE_DECL(attr_tree), "astring")))
        {
            fputs("const ", outfile);
        }

        if (!write_type(ATTR_TYPE_DECL(attr_tree), getter, outfile))
            return FALSE;
        fprintf(outfile, "%s%s",
                (STARRED_TYPE(attr_tree) ? "" : " "),
                (getter && !DIPPER_TYPE(ATTR_TYPE_DECL(attr_tree)))? "*" : "");
    }
    fprintf(outfile, "a%c%s)", toupper(attrname[0]), attrname + 1);
    return TRUE;
}
/*
 *  AS_DECL writes 'NS_IMETHOD foo(string bar, long sil)'
 *  AS_IMPL writes 'NS_IMETHODIMP className::foo(string bar, long sil)'
 *  AS_CALL writes 'foo(bar, sil)'
 */
static gboolean
write_attr_accessor(IDL_tree attr_tree, FILE * outfile,
                    gboolean getter, int mode, const char *className)
{
    char *attrname = ATTR_IDENT(attr_tree).str;

    if (mode == AS_DECL) {
        fputs("NS_IMETHOD ", outfile);
    } else if (mode == AS_IMPL) {
        fprintf(outfile, "NS_IMETHODIMP %s::", className);
    }
    fprintf(outfile, "%cet%c%s(",
            getter ? 'G' : 'S',
            toupper(*attrname), attrname + 1);
    if (mode == AS_DECL || mode == AS_IMPL) {
        /* Setters for string, wstring, nsid, domstring, utf8string, 
         * cstring and astring get const. 
         */
        if (!getter &&
            (IDL_NODE_TYPE(ATTR_TYPE_DECL(attr_tree)) == IDLN_TYPE_STRING ||
             IDL_NODE_TYPE(ATTR_TYPE_DECL(attr_tree)) == IDLN_TYPE_WIDE_STRING ||
             IDL_tree_property_get(ATTR_TYPE_DECL(attr_tree), "nsid") ||
             IDL_tree_property_get(ATTR_TYPE_DECL(attr_tree), "domstring")  ||
             IDL_tree_property_get(ATTR_TYPE_DECL(attr_tree), "utf8string") ||
             IDL_tree_property_get(ATTR_TYPE_DECL(attr_tree), "cstring")    ||
             IDL_tree_property_get(ATTR_TYPE_DECL(attr_tree), "astring")))
        {
            fputs("const ", outfile);
        }

        if (!write_type(ATTR_TYPE_DECL(attr_tree), getter, outfile))
            return FALSE;
        fprintf(outfile, "%s%s",
                (STARRED_TYPE(attr_tree) ? "" : " "),
                (getter && !DIPPER_TYPE(ATTR_TYPE_DECL(attr_tree)))? "*" : "");
    }
    fprintf(outfile, "a%c%s)", toupper(attrname[0]), attrname + 1);
    return TRUE;
}
Ejemplo n.º 7
0
static gboolean
typelib_op_dcl(TreeState *state)
{
    XPTInterfaceDescriptor *id = CURRENT(state);
    XPTMethodDescriptor *meth;
    struct _IDL_OP_DCL *op = &IDL_OP_DCL(state->tree);
    IDL_tree iter;
    uint16 num_args = 0;
    uint8 op_flags = 0;
    gboolean op_notxpcom = (IDL_tree_property_get(op->ident, "notxpcom")
                            != NULL);
    gboolean op_noscript = (IDL_tree_property_get(op->ident, "noscript")
                            != NULL);
    gboolean op_context = (IDL_tree_property_get(op->ident,
                                                 "implicit_jscontext") != NULL);
    gboolean op_opt_argc = (IDL_tree_property_get(op->ident, "optional_argc")
                            != NULL);

    if (!verify_method_declaration(state->tree))
        return FALSE;

    if (!XPT_InterfaceDescriptorAddMethods(ARENA(state), id, 1))
        return FALSE;

    meth = &id->method_descriptors[NEXT_METH(state)];

    for (iter = op->parameter_dcls; iter; iter = IDL_LIST(iter).next)
        num_args++;             /* count params */
    if (op->op_type_spec && !op_notxpcom)
        num_args++;             /* fake param for _retval */

    if (op_noscript)
        op_flags |= XPT_MD_HIDDEN;
    if (op_notxpcom)
        op_flags |= XPT_MD_NOTXPCOM;
    if (op_opt_argc)
        op_flags |= XPT_MD_OPT_ARGC;
    if (op_context)
        op_flags |= XPT_MD_CONTEXT;

    /* XXXshaver constructor? */

#ifdef DEBUG_shaver_method
    fprintf(stdout, "DBG: adding method %s (nargs %d)\n",
            IDL_IDENT(op->ident).str, num_args);
#endif
    if (!XPT_FillMethodDescriptor(ARENA(state), meth, op_flags, 
                                  IDL_IDENT(op->ident).str,
                                  (uint8) num_args))
        return FALSE;

    for (num_args = 0, iter = op->parameter_dcls; iter;
         iter = IDL_LIST(iter).next, num_args++) {
        XPTParamDescriptor *pd = &meth->params[num_args];
        if (!fill_pd_from_param(state, pd, IDL_LIST(iter).data))
            return FALSE;
    }

    /* stick retval param where we can see it later */
    state->tree = op->op_type_spec;

    /* XXX unless [notxpcom] */
    if (!op_notxpcom) {
        if (op->op_type_spec) {
            uint8 pdflags = DIPPER_TYPE(op->op_type_spec) ?
                                (XPT_PD_RETVAL | XPT_PD_IN | XPT_PD_DIPPER) :
                                (XPT_PD_RETVAL | XPT_PD_OUT);
    
            if (!fill_pd_from_type(state, &meth->params[num_args],
                                   pdflags, op->op_type_spec))
                return FALSE;
        }

        if (!fill_pd_as_nsresult(meth->result))
            return FALSE;
    } else {
#ifdef DEBUG_shaver_notxpcom
        fprintf(stderr, "%s is notxpcom\n", IDL_IDENT(op->ident).str);
#endif
        if (!fill_pd_from_type(state, meth->result, XPT_PD_RETVAL,
                               op->op_type_spec))
            return FALSE;
    }
    NEXT_METH(state)++;
    return TRUE;
}