зеркало из https://github.com/mozilla/pjs.git
- Use write rather than dump consistently (dump has unfortunate connotations).
- Avoid gratuitous extra newlines in foo.h compiled from foo.idl. - Use do-while, not for or while, guarded by if that tests the loop condition. - Use NS_EXPORT to qualify static InitJSClass and GetJSObject method. - Turn enum declarations within interfaces into JS class constant numbers. - Defend against null return from JS_GetPrivate (prototype and user-constructed objects have no private data).
This commit is contained in:
Родитель
42895cb757
Коммит
920aee0dfe
|
@ -112,9 +112,10 @@ gboolean
|
||||||
xpidl_process_node(TreeState *state);
|
xpidl_process_node(TreeState *state);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Dump a comment containing IDL source decompiled from state->tree.
|
* Write a newline folllowed by an indented, one-line comment containing IDL
|
||||||
|
* source decompiled from state->tree.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
xpidl_dump_comment(TreeState *state, int indent);
|
xpidl_write_comment(TreeState *state, int indent);
|
||||||
|
|
||||||
#endif /* __xpidl_h */
|
#endif /* __xpidl_h */
|
||||||
|
|
|
@ -60,7 +60,6 @@ pass_1(TreeState *state)
|
||||||
if (g_hash_table_size(state->includes)) {
|
if (g_hash_table_size(state->includes)) {
|
||||||
fputc('\n', state->file);
|
fputc('\n', state->file);
|
||||||
g_hash_table_foreach(state->includes, write_header, state);
|
g_hash_table_foreach(state->includes, write_header, state);
|
||||||
fputc('\n', state->file);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(state->file, "\n#endif /* __gen_%s_h__ */\n", define);
|
fprintf(state->file, "\n#endif /* __gen_%s_h__ */\n", define);
|
||||||
|
@ -69,7 +68,7 @@ pass_1(TreeState *state)
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
output_classname_iid_define(FILE *file, const char *className)
|
write_classname_iid_define(FILE *file, const char *className)
|
||||||
{
|
{
|
||||||
const char *iidName;
|
const char *iidName;
|
||||||
if (className[0] == 'n' && className[1] == 's') {
|
if (className[0] == 'n' && className[1] == 's') {
|
||||||
|
@ -101,10 +100,10 @@ interface(TreeState *state)
|
||||||
/* XXX report error */
|
/* XXX report error */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
fprintf(state->file, "\n/* {%s} */\n#define ", iid);
|
fprintf(state->file, "\n/* {%s} */\n#define ", iid);
|
||||||
if (!output_classname_iid_define(state->file, className))
|
if (!write_classname_iid_define(state->file, className))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
fprintf(state->file, "_STR \"%s\"\n#define ", iid);
|
fprintf(state->file, "_STR \"%s\"\n#define ", iid);
|
||||||
if (!output_classname_iid_define(state->file, className))
|
if (!write_classname_iid_define(state->file, className))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
/* This is such a gross hack... */
|
/* This is such a gross hack... */
|
||||||
fprintf(state->file, " \\\n {0x%.8s, 0x%.4s, 0x%.4s, \\\n "
|
fprintf(state->file, " \\\n {0x%.8s, 0x%.4s, 0x%.4s, \\\n "
|
||||||
|
@ -116,12 +115,12 @@ interface(TreeState *state)
|
||||||
fprintf(state->file, "class %s", className);
|
fprintf(state->file, "class %s", className);
|
||||||
if ((iter = IDL_INTERFACE(iface).inheritance_spec)) {
|
if ((iter = IDL_INTERFACE(iface).inheritance_spec)) {
|
||||||
fputs(" : ", state->file);
|
fputs(" : ", state->file);
|
||||||
for (; iter; iter = IDL_LIST(iter).next) {
|
do {
|
||||||
fprintf(state->file, "public %s",
|
fprintf(state->file, "public %s",
|
||||||
IDL_IDENT(IDL_LIST(iter).data).str);
|
IDL_IDENT(IDL_LIST(iter).data).str);
|
||||||
if (IDL_LIST(iter).next)
|
if (IDL_LIST(iter).next)
|
||||||
fputs(", ", state->file);
|
fputs(", ", state->file);
|
||||||
}
|
} while ((iter = IDL_LIST(iter).next));
|
||||||
}
|
}
|
||||||
fputs(" {\n"
|
fputs(" {\n"
|
||||||
" public: \n", state->file);
|
" public: \n", state->file);
|
||||||
|
@ -129,7 +128,7 @@ interface(TreeState *state)
|
||||||
fputs(" static const nsIID& IID() {\n"
|
fputs(" static const nsIID& IID() {\n"
|
||||||
" static nsIID iid = ",
|
" static nsIID iid = ",
|
||||||
state->file);
|
state->file);
|
||||||
if (!output_classname_iid_define(state->file, className))
|
if (!write_classname_iid_define(state->file, className))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
fputs(";\n return iid;\n }\n", state->file);
|
fputs(";\n return iid;\n }\n", state->file);
|
||||||
}
|
}
|
||||||
|
@ -142,8 +141,8 @@ interface(TreeState *state)
|
||||||
/* XXXbe keep this statement until -m stub dies */
|
/* XXXbe keep this statement until -m stub dies */
|
||||||
fprintf(state->file,
|
fprintf(state->file,
|
||||||
"\n"
|
"\n"
|
||||||
" static JSObject *InitJSClass(JSContext *cx);\n"
|
" static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);\n"
|
||||||
" static JSObject *GetJSObject(JSContext *cx, %s *priv);\n",
|
" static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, %s *priv);\n",
|
||||||
className);
|
className);
|
||||||
|
|
||||||
fputs("};\n", state->file);
|
fputs("};\n", state->file);
|
||||||
|
@ -260,7 +259,7 @@ static gboolean
|
||||||
attr_dcl(TreeState *state)
|
attr_dcl(TreeState *state)
|
||||||
{
|
{
|
||||||
gboolean ro = IDL_ATTR_DCL(state->tree).f_readonly;
|
gboolean ro = IDL_ATTR_DCL(state->tree).f_readonly;
|
||||||
xpidl_dump_comment(state, 2);
|
xpidl_write_comment(state, 2);
|
||||||
return attr_accessor(state, TRUE) && (ro || attr_accessor(state, FALSE));
|
return attr_accessor(state, TRUE) && (ro || attr_accessor(state, FALSE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,9 +272,11 @@ do_enum(TreeState *state)
|
||||||
IDL_IDENT(IDL_TYPE_ENUM(enumb).ident).str);
|
IDL_IDENT(IDL_TYPE_ENUM(enumb).ident).str);
|
||||||
|
|
||||||
for (iter = IDL_TYPE_ENUM(enumb).enumerator_list;
|
for (iter = IDL_TYPE_ENUM(enumb).enumerator_list;
|
||||||
iter; iter = IDL_LIST(iter).next)
|
iter;
|
||||||
|
iter = IDL_LIST(iter).next) {
|
||||||
fprintf(state->file, " %s%s\n", IDL_IDENT(IDL_LIST(iter).data).str,
|
fprintf(state->file, " %s%s\n", IDL_IDENT(IDL_LIST(iter).data).str,
|
||||||
IDL_LIST(iter).next ? ",": "");
|
IDL_LIST(iter).next ? ",": "");
|
||||||
|
}
|
||||||
|
|
||||||
fputs("};\n\n", state->file);
|
fputs("};\n\n", state->file);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -356,7 +357,7 @@ op_dcl(TreeState *state)
|
||||||
struct _IDL_OP_DCL *op = &IDL_OP_DCL(state->tree);
|
struct _IDL_OP_DCL *op = &IDL_OP_DCL(state->tree);
|
||||||
IDL_tree iter;
|
IDL_tree iter;
|
||||||
|
|
||||||
xpidl_dump_comment(state, 2);
|
xpidl_write_comment(state, 2);
|
||||||
|
|
||||||
fprintf(state->file, " NS_IMETHOD %s(", IDL_IDENT(op->ident).str);
|
fprintf(state->file, " NS_IMETHOD %s(", IDL_IDENT(op->ident).str);
|
||||||
for (iter = op->parameter_dcls; iter; iter = IDL_LIST(iter).next) {
|
for (iter = op->parameter_dcls; iter; iter = IDL_LIST(iter).next) {
|
||||||
|
@ -390,7 +391,7 @@ op_dcl(TreeState *state)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dump_codefrag_line(gpointer data, gpointer user_data)
|
write_codefrag_line(gpointer data, gpointer user_data)
|
||||||
{
|
{
|
||||||
TreeState *state = (TreeState *)user_data;
|
TreeState *state = (TreeState *)user_data;
|
||||||
char *line = (char *)data;
|
char *line = (char *)data;
|
||||||
|
@ -403,7 +404,7 @@ codefrag(TreeState *state)
|
||||||
{
|
{
|
||||||
if (strcmp(IDL_CODEFRAG(state->tree).desc, "C++"))
|
if (strcmp(IDL_CODEFRAG(state->tree).desc, "C++"))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
g_slist_foreach(IDL_CODEFRAG(state->tree).lines, dump_codefrag_line,
|
g_slist_foreach(IDL_CODEFRAG(state->tree).lines, write_codefrag_line,
|
||||||
(gpointer)state);
|
(gpointer)state);
|
||||||
fputc('\n', state->file);
|
fputc('\n', state->file);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
|
@ -507,7 +507,7 @@ xpidl_process_idl(char *filename, IncludePathEntry *include_path,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
xpidl_dump_comment(TreeState *state, int indent)
|
xpidl_write_comment(TreeState *state, int indent)
|
||||||
{
|
{
|
||||||
fprintf(state->file, "\n%*s/* ", indent, "");
|
fprintf(state->file, "\n%*s/* ", indent, "");
|
||||||
IDL_tree_to_IDL(state->tree, state->ns, state->file,
|
IDL_tree_to_IDL(state->tree, state->ns, state->file,
|
||||||
|
|
|
@ -27,8 +27,8 @@ struct stub_private {
|
||||||
IDL_tree iface;
|
IDL_tree iface;
|
||||||
IDL_tree *funcs;
|
IDL_tree *funcs;
|
||||||
unsigned nfuncs;
|
unsigned nfuncs;
|
||||||
IDL_tree *const_dbls;
|
IDL_tree *enums;
|
||||||
unsigned nconst_dbls;
|
unsigned nenums;
|
||||||
IDL_tree *props;
|
IDL_tree *props;
|
||||||
unsigned nprops;
|
unsigned nprops;
|
||||||
};
|
};
|
||||||
|
@ -38,8 +38,8 @@ free_stub_private(struct stub_private *priv)
|
||||||
{
|
{
|
||||||
if (priv->funcs)
|
if (priv->funcs)
|
||||||
free(priv->funcs);
|
free(priv->funcs);
|
||||||
if (priv->const_dbls)
|
if (priv->enums)
|
||||||
free(priv->const_dbls);
|
free(priv->enums);
|
||||||
if (priv->props)
|
if (priv->props)
|
||||||
free(priv->props);
|
free(priv->props);
|
||||||
free(priv);
|
free(priv);
|
||||||
|
@ -149,15 +149,15 @@ js_convert_arguments_format(IDL_tree type)
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
emit_convert_result(TreeState *state, const char *from, const char *to,
|
emit_convert_result(TreeState *state, const char *from, const char *to,
|
||||||
const char *extra)
|
const char *extra_space)
|
||||||
{
|
{
|
||||||
switch (IDL_NODE_TYPE(state->tree)) {
|
switch (IDL_NODE_TYPE(state->tree)) {
|
||||||
case IDLN_TYPE_INTEGER:
|
case IDLN_TYPE_INTEGER:
|
||||||
fprintf(state->file,
|
fprintf(state->file,
|
||||||
"%s if (!JS_NewNumberValue(cx, (jsdouble) %s, %s))\n"
|
"%s if (!JS_NewNumberValue(cx, (jsdouble) %s, %s))\n"
|
||||||
"%s return JS_FALSE;\n",
|
"%s return JS_FALSE;\n",
|
||||||
extra, from, to,
|
extra_space, from, to,
|
||||||
extra);
|
extra_space);
|
||||||
break;
|
break;
|
||||||
case IDLN_TYPE_STRING:
|
case IDLN_TYPE_STRING:
|
||||||
/* XXXbe must free 'from' using priv's nsIAllocator iff not weak! */
|
/* XXXbe must free 'from' using priv's nsIAllocator iff not weak! */
|
||||||
|
@ -166,15 +166,15 @@ emit_convert_result(TreeState *state, const char *from, const char *to,
|
||||||
"%s if (!str)\n"
|
"%s if (!str)\n"
|
||||||
"%s return JS_FALSE;\n"
|
"%s return JS_FALSE;\n"
|
||||||
"%s *%s = STRING_TO_JSVAL(str);\n",
|
"%s *%s = STRING_TO_JSVAL(str);\n",
|
||||||
extra, from,
|
extra_space, from,
|
||||||
extra,
|
extra_space,
|
||||||
extra,
|
extra_space,
|
||||||
extra, to);
|
extra_space, to);
|
||||||
break;
|
break;
|
||||||
case IDLN_TYPE_BOOLEAN:
|
case IDLN_TYPE_BOOLEAN:
|
||||||
fprintf(state->file,
|
fprintf(state->file,
|
||||||
"%s *%s = BOOLEAN_TO_JSVAL(%s);\n",
|
"%s *%s = BOOLEAN_TO_JSVAL(%s);\n",
|
||||||
extra, to, from);
|
extra_space, to, from);
|
||||||
break;
|
break;
|
||||||
case IDLN_IDENT:
|
case IDLN_IDENT:
|
||||||
if (IDL_NODE_UP(state->tree) &&
|
if (IDL_NODE_UP(state->tree) &&
|
||||||
|
@ -182,14 +182,14 @@ emit_convert_result(TreeState *state, const char *from, const char *to,
|
||||||
/* XXXbe issue warning, method should have been noscript? */
|
/* XXXbe issue warning, method should have been noscript? */
|
||||||
fprintf(state->file,
|
fprintf(state->file,
|
||||||
"%s *%s = JSVAL_NULL;\n",
|
"%s *%s = JSVAL_NULL;\n",
|
||||||
extra, to);
|
extra_space, to);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fprintf(state->file,
|
fprintf(state->file,
|
||||||
"%s *%s = OBJECT_TO_JSVAL(%s::GetJSObject(cx, %s));\n"
|
"%s *%s = OBJECT_TO_JSVAL(%s::GetJSObject(cx, %s));\n"
|
||||||
"%s NS_RELEASE(%s);\n",
|
"%s NS_RELEASE(%s);\n",
|
||||||
extra, to, IDL_IDENT(state->tree).str, from,
|
extra_space, to, IDL_IDENT(state->tree).str, from,
|
||||||
extra, from);
|
extra_space, from);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(0); /* XXXbe */
|
assert(0); /* XXXbe */
|
||||||
|
@ -211,7 +211,7 @@ stub_op_dcl(TreeState *state)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
append_to_vector(&priv->funcs, &priv->nfuncs, method);
|
append_to_vector(&priv->funcs, &priv->nfuncs, method);
|
||||||
xpidl_dump_comment(state, 0);
|
xpidl_write_comment(state, 0);
|
||||||
|
|
||||||
assert(IDL_NODE_UP(IDL_NODE_UP(method)));
|
assert(IDL_NODE_UP(IDL_NODE_UP(method)));
|
||||||
iface = IDL_NODE_UP(IDL_NODE_UP(method));
|
iface = IDL_NODE_UP(IDL_NODE_UP(method));
|
||||||
|
@ -291,7 +291,9 @@ stub_op_dcl(TreeState *state)
|
||||||
static gboolean
|
static gboolean
|
||||||
stub_type_enum(TreeState *state)
|
stub_type_enum(TreeState *state)
|
||||||
{
|
{
|
||||||
fputs("XXXbe type_enum\n", state->file);
|
struct stub_private *priv = state->priv;
|
||||||
|
if (priv)
|
||||||
|
append_to_vector(&priv->enums, &priv->nenums, state->tree);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,6 +311,8 @@ emit_property_op(TreeState *state, const char *className, char which)
|
||||||
" return JS_TRUE;\n"
|
" return JS_TRUE;\n"
|
||||||
" nsresult result;\n"
|
" nsresult result;\n"
|
||||||
" %s *priv = (%s *)JS_GetPrivate(cx, obj);\n"
|
" %s *priv = (%s *)JS_GetPrivate(cx, obj);\n"
|
||||||
|
" if (!priv)\n"
|
||||||
|
" return JS_TRUE;\n"
|
||||||
" switch (JSVAL_TO_INT(id)) {\n",
|
" switch (JSVAL_TO_INT(id)) {\n",
|
||||||
className, which, className, className);
|
className, which, className, className);
|
||||||
|
|
||||||
|
@ -404,12 +408,22 @@ stub_interface(TreeState *state)
|
||||||
fputs(" {0}\n};\n", state->file);
|
fputs(" {0}\n};\n", state->file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priv->const_dbls) {
|
if (priv->enums) {
|
||||||
fprintf(state->file,
|
fprintf(state->file,
|
||||||
"\nstatic JSConstDoubleSpec %s_const_dbls[] = {\n",
|
"\nstatic JSConstDoubleSpec %s_const_dbls[] = {\n",
|
||||||
className);
|
className);
|
||||||
for (i = 0; i < priv->nconst_dbls; i++) {
|
for (i = 0; i < priv->nenums; i++) {
|
||||||
fprintf(state->file, " {%g, \"%s\"},\n", 0., "d'oh!");
|
unsigned j = 0;
|
||||||
|
IDL_tree iter;
|
||||||
|
for (iter = IDL_TYPE_ENUM(priv->enums[i]).enumerator_list;
|
||||||
|
iter;
|
||||||
|
iter = IDL_LIST(iter).next) {
|
||||||
|
fprintf(state->file,
|
||||||
|
" {%u, \"%s\"},\n",
|
||||||
|
j,
|
||||||
|
IDL_IDENT(IDL_LIST(iter).data).str);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fputs(" {0}\n};\n", state->file);
|
fputs(" {0}\n};\n", state->file);
|
||||||
|
|
||||||
|
@ -510,7 +524,7 @@ stub_interface(TreeState *state)
|
||||||
else
|
else
|
||||||
fputc('0', state->file);
|
fputc('0', state->file);
|
||||||
fputs( ", 0, 0);\n", state->file);
|
fputs( ", 0, 0);\n", state->file);
|
||||||
if (priv->const_dbls) {
|
if (priv->enums) {
|
||||||
fprintf(state->file,
|
fprintf(state->file,
|
||||||
" if (!proto)\n"
|
" if (!proto)\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
|
|
|
@ -112,9 +112,10 @@ gboolean
|
||||||
xpidl_process_node(TreeState *state);
|
xpidl_process_node(TreeState *state);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Dump a comment containing IDL source decompiled from state->tree.
|
* Write a newline folllowed by an indented, one-line comment containing IDL
|
||||||
|
* source decompiled from state->tree.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
xpidl_dump_comment(TreeState *state, int indent);
|
xpidl_write_comment(TreeState *state, int indent);
|
||||||
|
|
||||||
#endif /* __xpidl_h */
|
#endif /* __xpidl_h */
|
||||||
|
|
|
@ -60,7 +60,6 @@ pass_1(TreeState *state)
|
||||||
if (g_hash_table_size(state->includes)) {
|
if (g_hash_table_size(state->includes)) {
|
||||||
fputc('\n', state->file);
|
fputc('\n', state->file);
|
||||||
g_hash_table_foreach(state->includes, write_header, state);
|
g_hash_table_foreach(state->includes, write_header, state);
|
||||||
fputc('\n', state->file);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(state->file, "\n#endif /* __gen_%s_h__ */\n", define);
|
fprintf(state->file, "\n#endif /* __gen_%s_h__ */\n", define);
|
||||||
|
@ -69,7 +68,7 @@ pass_1(TreeState *state)
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
output_classname_iid_define(FILE *file, const char *className)
|
write_classname_iid_define(FILE *file, const char *className)
|
||||||
{
|
{
|
||||||
const char *iidName;
|
const char *iidName;
|
||||||
if (className[0] == 'n' && className[1] == 's') {
|
if (className[0] == 'n' && className[1] == 's') {
|
||||||
|
@ -101,10 +100,10 @@ interface(TreeState *state)
|
||||||
/* XXX report error */
|
/* XXX report error */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
fprintf(state->file, "\n/* {%s} */\n#define ", iid);
|
fprintf(state->file, "\n/* {%s} */\n#define ", iid);
|
||||||
if (!output_classname_iid_define(state->file, className))
|
if (!write_classname_iid_define(state->file, className))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
fprintf(state->file, "_STR \"%s\"\n#define ", iid);
|
fprintf(state->file, "_STR \"%s\"\n#define ", iid);
|
||||||
if (!output_classname_iid_define(state->file, className))
|
if (!write_classname_iid_define(state->file, className))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
/* This is such a gross hack... */
|
/* This is such a gross hack... */
|
||||||
fprintf(state->file, " \\\n {0x%.8s, 0x%.4s, 0x%.4s, \\\n "
|
fprintf(state->file, " \\\n {0x%.8s, 0x%.4s, 0x%.4s, \\\n "
|
||||||
|
@ -116,12 +115,12 @@ interface(TreeState *state)
|
||||||
fprintf(state->file, "class %s", className);
|
fprintf(state->file, "class %s", className);
|
||||||
if ((iter = IDL_INTERFACE(iface).inheritance_spec)) {
|
if ((iter = IDL_INTERFACE(iface).inheritance_spec)) {
|
||||||
fputs(" : ", state->file);
|
fputs(" : ", state->file);
|
||||||
for (; iter; iter = IDL_LIST(iter).next) {
|
do {
|
||||||
fprintf(state->file, "public %s",
|
fprintf(state->file, "public %s",
|
||||||
IDL_IDENT(IDL_LIST(iter).data).str);
|
IDL_IDENT(IDL_LIST(iter).data).str);
|
||||||
if (IDL_LIST(iter).next)
|
if (IDL_LIST(iter).next)
|
||||||
fputs(", ", state->file);
|
fputs(", ", state->file);
|
||||||
}
|
} while ((iter = IDL_LIST(iter).next));
|
||||||
}
|
}
|
||||||
fputs(" {\n"
|
fputs(" {\n"
|
||||||
" public: \n", state->file);
|
" public: \n", state->file);
|
||||||
|
@ -129,7 +128,7 @@ interface(TreeState *state)
|
||||||
fputs(" static const nsIID& IID() {\n"
|
fputs(" static const nsIID& IID() {\n"
|
||||||
" static nsIID iid = ",
|
" static nsIID iid = ",
|
||||||
state->file);
|
state->file);
|
||||||
if (!output_classname_iid_define(state->file, className))
|
if (!write_classname_iid_define(state->file, className))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
fputs(";\n return iid;\n }\n", state->file);
|
fputs(";\n return iid;\n }\n", state->file);
|
||||||
}
|
}
|
||||||
|
@ -142,8 +141,8 @@ interface(TreeState *state)
|
||||||
/* XXXbe keep this statement until -m stub dies */
|
/* XXXbe keep this statement until -m stub dies */
|
||||||
fprintf(state->file,
|
fprintf(state->file,
|
||||||
"\n"
|
"\n"
|
||||||
" static JSObject *InitJSClass(JSContext *cx);\n"
|
" static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);\n"
|
||||||
" static JSObject *GetJSObject(JSContext *cx, %s *priv);\n",
|
" static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, %s *priv);\n",
|
||||||
className);
|
className);
|
||||||
|
|
||||||
fputs("};\n", state->file);
|
fputs("};\n", state->file);
|
||||||
|
@ -260,7 +259,7 @@ static gboolean
|
||||||
attr_dcl(TreeState *state)
|
attr_dcl(TreeState *state)
|
||||||
{
|
{
|
||||||
gboolean ro = IDL_ATTR_DCL(state->tree).f_readonly;
|
gboolean ro = IDL_ATTR_DCL(state->tree).f_readonly;
|
||||||
xpidl_dump_comment(state, 2);
|
xpidl_write_comment(state, 2);
|
||||||
return attr_accessor(state, TRUE) && (ro || attr_accessor(state, FALSE));
|
return attr_accessor(state, TRUE) && (ro || attr_accessor(state, FALSE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,9 +272,11 @@ do_enum(TreeState *state)
|
||||||
IDL_IDENT(IDL_TYPE_ENUM(enumb).ident).str);
|
IDL_IDENT(IDL_TYPE_ENUM(enumb).ident).str);
|
||||||
|
|
||||||
for (iter = IDL_TYPE_ENUM(enumb).enumerator_list;
|
for (iter = IDL_TYPE_ENUM(enumb).enumerator_list;
|
||||||
iter; iter = IDL_LIST(iter).next)
|
iter;
|
||||||
|
iter = IDL_LIST(iter).next) {
|
||||||
fprintf(state->file, " %s%s\n", IDL_IDENT(IDL_LIST(iter).data).str,
|
fprintf(state->file, " %s%s\n", IDL_IDENT(IDL_LIST(iter).data).str,
|
||||||
IDL_LIST(iter).next ? ",": "");
|
IDL_LIST(iter).next ? ",": "");
|
||||||
|
}
|
||||||
|
|
||||||
fputs("};\n\n", state->file);
|
fputs("};\n\n", state->file);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -356,7 +357,7 @@ op_dcl(TreeState *state)
|
||||||
struct _IDL_OP_DCL *op = &IDL_OP_DCL(state->tree);
|
struct _IDL_OP_DCL *op = &IDL_OP_DCL(state->tree);
|
||||||
IDL_tree iter;
|
IDL_tree iter;
|
||||||
|
|
||||||
xpidl_dump_comment(state, 2);
|
xpidl_write_comment(state, 2);
|
||||||
|
|
||||||
fprintf(state->file, " NS_IMETHOD %s(", IDL_IDENT(op->ident).str);
|
fprintf(state->file, " NS_IMETHOD %s(", IDL_IDENT(op->ident).str);
|
||||||
for (iter = op->parameter_dcls; iter; iter = IDL_LIST(iter).next) {
|
for (iter = op->parameter_dcls; iter; iter = IDL_LIST(iter).next) {
|
||||||
|
@ -390,7 +391,7 @@ op_dcl(TreeState *state)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dump_codefrag_line(gpointer data, gpointer user_data)
|
write_codefrag_line(gpointer data, gpointer user_data)
|
||||||
{
|
{
|
||||||
TreeState *state = (TreeState *)user_data;
|
TreeState *state = (TreeState *)user_data;
|
||||||
char *line = (char *)data;
|
char *line = (char *)data;
|
||||||
|
@ -403,7 +404,7 @@ codefrag(TreeState *state)
|
||||||
{
|
{
|
||||||
if (strcmp(IDL_CODEFRAG(state->tree).desc, "C++"))
|
if (strcmp(IDL_CODEFRAG(state->tree).desc, "C++"))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
g_slist_foreach(IDL_CODEFRAG(state->tree).lines, dump_codefrag_line,
|
g_slist_foreach(IDL_CODEFRAG(state->tree).lines, write_codefrag_line,
|
||||||
(gpointer)state);
|
(gpointer)state);
|
||||||
fputc('\n', state->file);
|
fputc('\n', state->file);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
|
@ -507,7 +507,7 @@ xpidl_process_idl(char *filename, IncludePathEntry *include_path,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
xpidl_dump_comment(TreeState *state, int indent)
|
xpidl_write_comment(TreeState *state, int indent)
|
||||||
{
|
{
|
||||||
fprintf(state->file, "\n%*s/* ", indent, "");
|
fprintf(state->file, "\n%*s/* ", indent, "");
|
||||||
IDL_tree_to_IDL(state->tree, state->ns, state->file,
|
IDL_tree_to_IDL(state->tree, state->ns, state->file,
|
||||||
|
|
|
@ -27,8 +27,8 @@ struct stub_private {
|
||||||
IDL_tree iface;
|
IDL_tree iface;
|
||||||
IDL_tree *funcs;
|
IDL_tree *funcs;
|
||||||
unsigned nfuncs;
|
unsigned nfuncs;
|
||||||
IDL_tree *const_dbls;
|
IDL_tree *enums;
|
||||||
unsigned nconst_dbls;
|
unsigned nenums;
|
||||||
IDL_tree *props;
|
IDL_tree *props;
|
||||||
unsigned nprops;
|
unsigned nprops;
|
||||||
};
|
};
|
||||||
|
@ -38,8 +38,8 @@ free_stub_private(struct stub_private *priv)
|
||||||
{
|
{
|
||||||
if (priv->funcs)
|
if (priv->funcs)
|
||||||
free(priv->funcs);
|
free(priv->funcs);
|
||||||
if (priv->const_dbls)
|
if (priv->enums)
|
||||||
free(priv->const_dbls);
|
free(priv->enums);
|
||||||
if (priv->props)
|
if (priv->props)
|
||||||
free(priv->props);
|
free(priv->props);
|
||||||
free(priv);
|
free(priv);
|
||||||
|
@ -149,15 +149,15 @@ js_convert_arguments_format(IDL_tree type)
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
emit_convert_result(TreeState *state, const char *from, const char *to,
|
emit_convert_result(TreeState *state, const char *from, const char *to,
|
||||||
const char *extra)
|
const char *extra_space)
|
||||||
{
|
{
|
||||||
switch (IDL_NODE_TYPE(state->tree)) {
|
switch (IDL_NODE_TYPE(state->tree)) {
|
||||||
case IDLN_TYPE_INTEGER:
|
case IDLN_TYPE_INTEGER:
|
||||||
fprintf(state->file,
|
fprintf(state->file,
|
||||||
"%s if (!JS_NewNumberValue(cx, (jsdouble) %s, %s))\n"
|
"%s if (!JS_NewNumberValue(cx, (jsdouble) %s, %s))\n"
|
||||||
"%s return JS_FALSE;\n",
|
"%s return JS_FALSE;\n",
|
||||||
extra, from, to,
|
extra_space, from, to,
|
||||||
extra);
|
extra_space);
|
||||||
break;
|
break;
|
||||||
case IDLN_TYPE_STRING:
|
case IDLN_TYPE_STRING:
|
||||||
/* XXXbe must free 'from' using priv's nsIAllocator iff not weak! */
|
/* XXXbe must free 'from' using priv's nsIAllocator iff not weak! */
|
||||||
|
@ -166,15 +166,15 @@ emit_convert_result(TreeState *state, const char *from, const char *to,
|
||||||
"%s if (!str)\n"
|
"%s if (!str)\n"
|
||||||
"%s return JS_FALSE;\n"
|
"%s return JS_FALSE;\n"
|
||||||
"%s *%s = STRING_TO_JSVAL(str);\n",
|
"%s *%s = STRING_TO_JSVAL(str);\n",
|
||||||
extra, from,
|
extra_space, from,
|
||||||
extra,
|
extra_space,
|
||||||
extra,
|
extra_space,
|
||||||
extra, to);
|
extra_space, to);
|
||||||
break;
|
break;
|
||||||
case IDLN_TYPE_BOOLEAN:
|
case IDLN_TYPE_BOOLEAN:
|
||||||
fprintf(state->file,
|
fprintf(state->file,
|
||||||
"%s *%s = BOOLEAN_TO_JSVAL(%s);\n",
|
"%s *%s = BOOLEAN_TO_JSVAL(%s);\n",
|
||||||
extra, to, from);
|
extra_space, to, from);
|
||||||
break;
|
break;
|
||||||
case IDLN_IDENT:
|
case IDLN_IDENT:
|
||||||
if (IDL_NODE_UP(state->tree) &&
|
if (IDL_NODE_UP(state->tree) &&
|
||||||
|
@ -182,14 +182,14 @@ emit_convert_result(TreeState *state, const char *from, const char *to,
|
||||||
/* XXXbe issue warning, method should have been noscript? */
|
/* XXXbe issue warning, method should have been noscript? */
|
||||||
fprintf(state->file,
|
fprintf(state->file,
|
||||||
"%s *%s = JSVAL_NULL;\n",
|
"%s *%s = JSVAL_NULL;\n",
|
||||||
extra, to);
|
extra_space, to);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fprintf(state->file,
|
fprintf(state->file,
|
||||||
"%s *%s = OBJECT_TO_JSVAL(%s::GetJSObject(cx, %s));\n"
|
"%s *%s = OBJECT_TO_JSVAL(%s::GetJSObject(cx, %s));\n"
|
||||||
"%s NS_RELEASE(%s);\n",
|
"%s NS_RELEASE(%s);\n",
|
||||||
extra, to, IDL_IDENT(state->tree).str, from,
|
extra_space, to, IDL_IDENT(state->tree).str, from,
|
||||||
extra, from);
|
extra_space, from);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(0); /* XXXbe */
|
assert(0); /* XXXbe */
|
||||||
|
@ -211,7 +211,7 @@ stub_op_dcl(TreeState *state)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
append_to_vector(&priv->funcs, &priv->nfuncs, method);
|
append_to_vector(&priv->funcs, &priv->nfuncs, method);
|
||||||
xpidl_dump_comment(state, 0);
|
xpidl_write_comment(state, 0);
|
||||||
|
|
||||||
assert(IDL_NODE_UP(IDL_NODE_UP(method)));
|
assert(IDL_NODE_UP(IDL_NODE_UP(method)));
|
||||||
iface = IDL_NODE_UP(IDL_NODE_UP(method));
|
iface = IDL_NODE_UP(IDL_NODE_UP(method));
|
||||||
|
@ -291,7 +291,9 @@ stub_op_dcl(TreeState *state)
|
||||||
static gboolean
|
static gboolean
|
||||||
stub_type_enum(TreeState *state)
|
stub_type_enum(TreeState *state)
|
||||||
{
|
{
|
||||||
fputs("XXXbe type_enum\n", state->file);
|
struct stub_private *priv = state->priv;
|
||||||
|
if (priv)
|
||||||
|
append_to_vector(&priv->enums, &priv->nenums, state->tree);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,6 +311,8 @@ emit_property_op(TreeState *state, const char *className, char which)
|
||||||
" return JS_TRUE;\n"
|
" return JS_TRUE;\n"
|
||||||
" nsresult result;\n"
|
" nsresult result;\n"
|
||||||
" %s *priv = (%s *)JS_GetPrivate(cx, obj);\n"
|
" %s *priv = (%s *)JS_GetPrivate(cx, obj);\n"
|
||||||
|
" if (!priv)\n"
|
||||||
|
" return JS_TRUE;\n"
|
||||||
" switch (JSVAL_TO_INT(id)) {\n",
|
" switch (JSVAL_TO_INT(id)) {\n",
|
||||||
className, which, className, className);
|
className, which, className, className);
|
||||||
|
|
||||||
|
@ -404,12 +408,22 @@ stub_interface(TreeState *state)
|
||||||
fputs(" {0}\n};\n", state->file);
|
fputs(" {0}\n};\n", state->file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priv->const_dbls) {
|
if (priv->enums) {
|
||||||
fprintf(state->file,
|
fprintf(state->file,
|
||||||
"\nstatic JSConstDoubleSpec %s_const_dbls[] = {\n",
|
"\nstatic JSConstDoubleSpec %s_const_dbls[] = {\n",
|
||||||
className);
|
className);
|
||||||
for (i = 0; i < priv->nconst_dbls; i++) {
|
for (i = 0; i < priv->nenums; i++) {
|
||||||
fprintf(state->file, " {%g, \"%s\"},\n", 0., "d'oh!");
|
unsigned j = 0;
|
||||||
|
IDL_tree iter;
|
||||||
|
for (iter = IDL_TYPE_ENUM(priv->enums[i]).enumerator_list;
|
||||||
|
iter;
|
||||||
|
iter = IDL_LIST(iter).next) {
|
||||||
|
fprintf(state->file,
|
||||||
|
" {%u, \"%s\"},\n",
|
||||||
|
j,
|
||||||
|
IDL_IDENT(IDL_LIST(iter).data).str);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fputs(" {0}\n};\n", state->file);
|
fputs(" {0}\n};\n", state->file);
|
||||||
|
|
||||||
|
@ -510,7 +524,7 @@ stub_interface(TreeState *state)
|
||||||
else
|
else
|
||||||
fputc('0', state->file);
|
fputc('0', state->file);
|
||||||
fputs( ", 0, 0);\n", state->file);
|
fputs( ", 0, 0);\n", state->file);
|
||||||
if (priv->const_dbls) {
|
if (priv->enums) {
|
||||||
fprintf(state->file,
|
fprintf(state->file,
|
||||||
" if (!proto)\n"
|
" if (!proto)\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
|
|
Загрузка…
Ссылка в новой задаче