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; }
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; }
/* * 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; }
static gboolean attribute_declaration(TreeState *state) { gboolean read_only = IDL_ATTR_DCL(state->tree).f_readonly; char *attribute_name = ATTR_IDENT(state->tree).str; gboolean method_noscript = (IDL_tree_property_get(ATTR_PROPS(state->tree), "noscript") != NULL); gboolean method_notxpcom = (IDL_tree_property_get(ATTR_PROPS(state->tree), "notxpcom") != NULL); #if 0 /* * Disabled here because I can't verify this check against possible * users of the java xpidl backend. */ if (!verify_attribute_declaration(state->tree)) return FALSE; #endif /* Comment */ fputc('\n', state->file); xpidl_write_comment(state, 4); #if 1 /* * Write access permission ("public") */ fputs(" public ", state->file); #else if (method_notxpcom || method_noscript) return TRUE; /* * Write access permission ("public" unless nonscriptable) */ fputs(" ", state->file); if (!method_noscript) { fputs("public ", state->file); } #endif /* * Write the proper Java return value for the get operation */ if (!xpcom_to_java_type(state, ATTR_TYPE_DECL(state->tree))) { return FALSE; } /* * Write the name of the accessor ("get") method. */ fprintf(state->file, " get%c%s();\n", toupper(attribute_name[0]), attribute_name + 1); if (!read_only) { #if 1 fputs(" public ", state->file); #else /* Nonscriptable methods become package-protected */ fputs(" ", state->file); if (!method_noscript) { fputs("public ", state->file); } #endif /* * Write attribute access method name and return type */ fprintf(state->file, "void set%c%s(", toupper(attribute_name[0]), attribute_name+1); /* * Write the proper Java type for the set operation */ if (!xpcom_to_java_type(state, ATTR_TYPE_DECL(state->tree))) { return FALSE; } /* * Write the name of the formal parameter. */ fprintf(state->file, " a%c%s);\n", toupper(attribute_name[0]), attribute_name + 1); } return TRUE; }