1998-12-03 09:33:59 +03:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
1998-11-28 19:52:24 +03:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generate XPCOM headers from XPIDL.
|
|
|
|
*/
|
|
|
|
|
1998-11-24 00:02:31 +03:00
|
|
|
#include "xpidl.h"
|
1999-02-08 20:47:44 +03:00
|
|
|
#include <ctype.h>
|
1998-11-24 00:02:31 +03:00
|
|
|
|
1998-11-28 19:52:24 +03:00
|
|
|
/* is this node from an aggregate type (interface)? */
|
1999-02-08 20:47:44 +03:00
|
|
|
#define UP_IS_AGGREGATE(node) \
|
|
|
|
(IDL_NODE_UP(node) && \
|
1999-04-15 07:32:18 +04:00
|
|
|
(IDL_NODE_TYPE(IDL_NODE_UP(node)) == IDLN_INTERFACE || \
|
|
|
|
IDL_NODE_TYPE(IDL_NODE_UP(node)) == IDLN_FORWARD_DCL))
|
1998-11-28 19:52:24 +03:00
|
|
|
|
1999-02-08 20:47:44 +03:00
|
|
|
#define UP_IS_NATIVE(node) \
|
|
|
|
(IDL_NODE_UP(node) && \
|
|
|
|
IDL_NODE_TYPE(IDL_NODE_UP(node)) == IDLN_NATIVE)
|
|
|
|
|
1998-11-27 00:03:03 +03:00
|
|
|
/* is this type output in the form "<foo> *"? */
|
1999-02-08 20:47:44 +03:00
|
|
|
#define STARRED_TYPE(node) (IDL_NODE_TYPE(node) == IDLN_TYPE_STRING || \
|
1999-02-18 01:13:32 +03:00
|
|
|
IDL_NODE_TYPE(node) == IDLN_TYPE_WIDE_STRING || \
|
|
|
|
(IDL_NODE_TYPE(node) == IDLN_IDENT && \
|
|
|
|
UP_IS_AGGREGATE(node)))
|
1999-01-11 19:56:45 +03:00
|
|
|
|
1998-11-27 00:03:03 +03:00
|
|
|
static void
|
|
|
|
write_header(gpointer key, gpointer value, gpointer user_data)
|
|
|
|
{
|
1998-12-06 21:41:44 +03:00
|
|
|
char *ident = (char *)value;
|
1998-11-27 00:03:03 +03:00
|
|
|
TreeState *state = (TreeState *)user_data;
|
|
|
|
fprintf(state->file, "#include \"%s.h\" /* interface %s */\n",
|
1998-12-03 09:33:59 +03:00
|
|
|
ident, ident);
|
1998-11-27 00:03:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
pass_1(TreeState *state)
|
|
|
|
{
|
1999-02-17 04:17:52 +03:00
|
|
|
char *define = g_basename(state->basename);
|
1998-12-06 21:41:44 +03:00
|
|
|
if (state->tree) {
|
|
|
|
fprintf(state->file, "/*\n * DO NOT EDIT. THIS FILE IS GENERATED FROM"
|
|
|
|
" %s.idl\n */\n", state->basename);
|
1999-01-11 19:56:45 +03:00
|
|
|
fprintf(state->file, "\n#ifndef __gen_%s_h__\n"
|
1999-02-18 22:59:11 +03:00
|
|
|
"#define __gen_%s_h__\n",
|
1999-02-09 18:30:31 +03:00
|
|
|
define, define);
|
1998-12-06 22:52:21 +03:00
|
|
|
if (g_hash_table_size(state->includes)) {
|
1999-02-18 22:59:11 +03:00
|
|
|
fputc('\n', state->file);
|
1998-12-06 22:52:21 +03:00
|
|
|
g_hash_table_foreach(state->includes, write_header, state);
|
|
|
|
}
|
1999-04-10 10:17:49 +04:00
|
|
|
if (emit_js_stub_decls) {
|
|
|
|
fputs("\n"
|
|
|
|
"#ifdef XPIDL_JS_STUBS\n"
|
|
|
|
"#include \"jsapi.h\"\n"
|
|
|
|
"#endif\n",
|
|
|
|
state->file);
|
|
|
|
}
|
1998-12-06 21:41:44 +03:00
|
|
|
} else {
|
1999-02-17 04:17:52 +03:00
|
|
|
fprintf(state->file, "\n#endif /* __gen_%s_h__ */\n", define);
|
1998-12-06 21:41:44 +03:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
1999-02-22 03:24:34 +03:00
|
|
|
write_classname_iid_define(FILE *file, const char *className)
|
1998-12-06 21:41:44 +03:00
|
|
|
{
|
|
|
|
const char *iidName;
|
|
|
|
if (className[0] == 'n' && className[1] == 's') {
|
|
|
|
/* backcompat naming styles */
|
|
|
|
fputs("NS_", file);
|
|
|
|
iidName = className + 2;
|
|
|
|
} else {
|
|
|
|
iidName = className;
|
|
|
|
}
|
|
|
|
while (*iidName)
|
|
|
|
fputc(toupper(*iidName++), file);
|
|
|
|
fputs("_IID", file);
|
1998-11-27 00:03:03 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
1998-11-24 00:02:31 +03:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
interface(TreeState *state)
|
|
|
|
{
|
1998-11-27 00:03:03 +03:00
|
|
|
IDL_tree iface = state->tree, iter;
|
1998-12-03 09:33:59 +03:00
|
|
|
char *className = IDL_IDENT(IDL_INTERFACE(iface).ident).str;
|
|
|
|
const char *iid;
|
1999-03-29 02:01:33 +04:00
|
|
|
const char *name_space;
|
1998-11-27 00:03:03 +03:00
|
|
|
|
1999-03-29 02:01:33 +04:00
|
|
|
fprintf(state->file, "\n/* starting interface: %s */\n",
|
1998-12-03 09:33:59 +03:00
|
|
|
className);
|
1999-03-29 02:01:33 +04:00
|
|
|
|
1999-02-23 18:28:58 +03:00
|
|
|
#ifndef LIBIDL_MAJOR_VERSION
|
|
|
|
/* pre-VERSIONing libIDLs put the attributes on the interface */
|
1999-03-29 02:01:33 +04:00
|
|
|
name_space = IDL_tree_property_get(iface, "namespace");
|
1998-12-09 16:08:29 +03:00
|
|
|
iid = IDL_tree_property_get(iface, "uuid");
|
1999-02-23 18:28:58 +03:00
|
|
|
#else
|
|
|
|
/* post-VERSIONing (>= 0.5.11) put the attributes on the ident */
|
1999-03-29 02:01:33 +04:00
|
|
|
name_space = IDL_tree_property_get(IDL_INTERFACE(iface).ident, "namespace");
|
1999-02-23 18:28:58 +03:00
|
|
|
iid = IDL_tree_property_get(IDL_INTERFACE(iface).ident, "uuid");
|
|
|
|
#endif
|
1999-03-29 02:01:33 +04:00
|
|
|
|
|
|
|
if (name_space) {
|
|
|
|
fprintf(state->file, "/* namespace: %s */\n",
|
|
|
|
name_space);
|
|
|
|
fprintf(state->file, "/* fully qualified name: %s.%s */\n",
|
|
|
|
name_space,className);
|
|
|
|
}
|
|
|
|
|
1998-12-03 09:33:59 +03:00
|
|
|
if (iid) {
|
|
|
|
/* XXX use nsID parsing routines to validate? */
|
|
|
|
if (strlen(iid) != 36)
|
|
|
|
/* XXX report error */
|
|
|
|
return FALSE;
|
1998-12-14 21:47:39 +03:00
|
|
|
fprintf(state->file, "\n/* {%s} */\n#define ", iid);
|
1999-02-22 03:24:34 +03:00
|
|
|
if (!write_classname_iid_define(state->file, className))
|
1998-12-06 21:41:44 +03:00
|
|
|
return FALSE;
|
1998-12-14 21:47:39 +03:00
|
|
|
fprintf(state->file, "_STR \"%s\"\n#define ", iid);
|
1999-02-22 03:24:34 +03:00
|
|
|
if (!write_classname_iid_define(state->file, className))
|
1998-12-06 21:41:44 +03:00
|
|
|
return FALSE;
|
1998-12-03 09:33:59 +03:00
|
|
|
/* This is such a gross hack... */
|
1998-12-06 21:41:44 +03:00
|
|
|
fprintf(state->file, " \\\n {0x%.8s, 0x%.4s, 0x%.4s, \\\n "
|
1998-12-03 09:33:59 +03:00
|
|
|
"{ 0x%.2s, 0x%.2s, 0x%.2s, 0x%.2s, "
|
|
|
|
"0x%.2s, 0x%.2s, 0x%.2s, 0x%.2s }}\n\n",
|
|
|
|
iid, iid + 9, iid + 14, iid + 19, iid + 21, iid + 24,
|
|
|
|
iid + 26, iid + 28, iid + 30, iid + 32, iid + 34);
|
|
|
|
}
|
|
|
|
fprintf(state->file, "class %s", className);
|
1998-11-27 00:03:03 +03:00
|
|
|
if ((iter = IDL_INTERFACE(iface).inheritance_spec)) {
|
1998-12-03 09:33:59 +03:00
|
|
|
fputs(" : ", state->file);
|
1999-02-22 03:24:34 +03:00
|
|
|
do {
|
1999-01-11 19:56:45 +03:00
|
|
|
fprintf(state->file, "public %s",
|
|
|
|
IDL_IDENT(IDL_LIST(iter).data).str);
|
1998-12-03 09:33:59 +03:00
|
|
|
if (IDL_LIST(iter).next)
|
|
|
|
fputs(", ", state->file);
|
1999-02-22 03:24:34 +03:00
|
|
|
} while ((iter = IDL_LIST(iter).next));
|
1998-11-27 00:03:03 +03:00
|
|
|
}
|
1998-12-14 21:47:39 +03:00
|
|
|
fputs(" {\n"
|
1999-02-18 20:43:38 +03:00
|
|
|
" public: \n", state->file);
|
|
|
|
if (iid) {
|
1999-04-10 10:17:49 +04:00
|
|
|
fputs(" NS_DEFINE_STATIC_IID_ACCESSOR(", state->file);
|
|
|
|
if (!write_classname_iid_define(state->file, className))
|
|
|
|
return FALSE;
|
|
|
|
fputs(")\n", state->file);
|
|
|
|
/* XX remove this old code... emitting the macro instead */
|
|
|
|
/*
|
1999-03-03 22:48:57 +03:00
|
|
|
fputs(" static const nsIID& GetIID() {\n"
|
1999-02-18 20:43:38 +03:00
|
|
|
" static nsIID iid = ",
|
|
|
|
state->file);
|
1999-02-22 03:24:34 +03:00
|
|
|
if (!write_classname_iid_define(state->file, className))
|
1999-02-18 20:43:38 +03:00
|
|
|
return FALSE;
|
|
|
|
fputs(";\n return iid;\n }\n", state->file);
|
1999-04-10 10:17:49 +04:00
|
|
|
*/
|
1999-02-18 20:43:38 +03:00
|
|
|
}
|
1998-12-14 21:47:39 +03:00
|
|
|
|
1998-11-27 00:03:03 +03:00
|
|
|
state->tree = IDL_INTERFACE(iface).body;
|
1998-11-25 02:16:49 +03:00
|
|
|
|
1999-02-16 08:10:40 +03:00
|
|
|
if (state->tree && !xpidl_process_node(state))
|
1998-12-03 09:33:59 +03:00
|
|
|
return FALSE;
|
1998-11-25 02:16:49 +03:00
|
|
|
|
1999-02-23 18:28:58 +03:00
|
|
|
/*
|
|
|
|
* XXXbe keep this statement until -m stub dies
|
|
|
|
* shaver sez: use the #ifdef to prevent pollution of non-stubbed headers.
|
|
|
|
*
|
|
|
|
* IMPORTANT: Only _static_ things can go here (inside the
|
|
|
|
* #ifdef), or you lose the vtable invariance upon which so much
|
|
|
|
* of (XP)COM is based.
|
|
|
|
*/
|
1999-04-10 10:17:49 +04:00
|
|
|
if (emit_js_stub_decls) {
|
|
|
|
fprintf(state->file,
|
1999-02-18 22:59:11 +03:00
|
|
|
"\n"
|
1999-02-23 18:28:58 +03:00
|
|
|
"#ifdef XPIDL_JS_STUBS\n"
|
1999-02-22 03:24:34 +03:00
|
|
|
" static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);\n"
|
1999-02-23 18:28:58 +03:00
|
|
|
" static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, %s *priv);\n"
|
|
|
|
"#endif\n",
|
1999-02-18 22:59:11 +03:00
|
|
|
className);
|
1999-04-10 10:17:49 +04:00
|
|
|
}
|
1998-12-14 21:47:39 +03:00
|
|
|
fputs("};\n", state->file);
|
1998-11-25 02:16:49 +03:00
|
|
|
|
|
|
|
return TRUE;
|
1998-11-24 00:02:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
list(TreeState *state)
|
|
|
|
{
|
|
|
|
IDL_tree iter;
|
|
|
|
for (iter = state->tree; iter; iter = IDL_LIST(iter).next) {
|
1998-12-03 09:33:59 +03:00
|
|
|
state->tree = IDL_LIST(iter).data;
|
1999-02-16 08:10:40 +03:00
|
|
|
if (!xpidl_process_node(state))
|
1998-12-03 09:33:59 +03:00
|
|
|
return FALSE;
|
1998-11-24 00:02:31 +03:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1999-02-17 04:17:52 +03:00
|
|
|
/* XXXbe static */ gboolean
|
1998-11-25 02:16:49 +03:00
|
|
|
xpcom_type(TreeState *state)
|
|
|
|
{
|
|
|
|
if (!state->tree) {
|
1998-12-03 09:33:59 +03:00
|
|
|
fputs("void", state->file);
|
|
|
|
return TRUE;
|
1998-11-25 02:16:49 +03:00
|
|
|
}
|
|
|
|
|
1999-02-17 04:17:52 +03:00
|
|
|
switch (IDL_NODE_TYPE(state->tree)) {
|
1998-11-25 02:16:49 +03:00
|
|
|
case IDLN_TYPE_INTEGER: {
|
1999-02-18 01:13:32 +03:00
|
|
|
gboolean sign = IDL_TYPE_INTEGER(state->tree).f_signed;
|
|
|
|
switch (IDL_TYPE_INTEGER(state->tree).f_type) {
|
|
|
|
case IDL_INTEGER_TYPE_SHORT:
|
|
|
|
fputs(sign ? "PRInt16" : "PRUint16", state->file);
|
|
|
|
break;
|
|
|
|
case IDL_INTEGER_TYPE_LONG:
|
|
|
|
fputs(sign ? "PRInt32" : "PRUint32", state->file);
|
|
|
|
break;
|
|
|
|
case IDL_INTEGER_TYPE_LONGLONG:
|
|
|
|
fputs(sign ? "PRInt64" : "PRUint64", state->file);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_error("Unknown integer type %d\n",
|
|
|
|
IDL_TYPE_INTEGER(state->tree).f_type);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
break;
|
1998-11-25 02:16:49 +03:00
|
|
|
}
|
1998-11-25 22:12:50 +03:00
|
|
|
case IDLN_TYPE_CHAR:
|
1998-12-03 09:33:59 +03:00
|
|
|
fputs("char", state->file);
|
|
|
|
break;
|
1998-11-25 22:12:50 +03:00
|
|
|
case IDLN_TYPE_WIDE_CHAR:
|
1999-05-05 00:03:43 +04:00
|
|
|
fputs("PRUnichar", state->file); /* wchar_t? */
|
1998-12-03 09:33:59 +03:00
|
|
|
break;
|
1998-11-25 22:12:50 +03:00
|
|
|
case IDLN_TYPE_WIDE_STRING:
|
1998-12-03 09:33:59 +03:00
|
|
|
fputs("PRUnichar *", state->file);
|
|
|
|
break;
|
1998-11-25 02:16:49 +03:00
|
|
|
case IDLN_TYPE_STRING:
|
1998-12-03 09:33:59 +03:00
|
|
|
fputs("char *", state->file);
|
|
|
|
break;
|
1998-11-25 02:16:49 +03:00
|
|
|
case IDLN_TYPE_BOOLEAN:
|
1998-12-03 09:33:59 +03:00
|
|
|
fputs("PRBool", state->file);
|
|
|
|
break;
|
1999-03-14 05:59:43 +03:00
|
|
|
case IDLN_TYPE_OCTET:
|
|
|
|
fputs("PRUint8", state->file);
|
|
|
|
break;
|
1999-03-13 04:43:19 +03:00
|
|
|
case IDLN_TYPE_FLOAT:
|
|
|
|
switch (IDL_TYPE_FLOAT(state->tree).f_type) {
|
1999-03-29 02:01:33 +04:00
|
|
|
case IDL_FLOAT_TYPE_FLOAT:
|
1999-03-13 04:43:19 +03:00
|
|
|
fputs("float", state->file);
|
|
|
|
break;
|
1999-03-29 02:01:33 +04:00
|
|
|
case IDL_FLOAT_TYPE_DOUBLE:
|
1999-03-13 04:43:19 +03:00
|
|
|
fputs("double", state->file);
|
|
|
|
break;
|
|
|
|
/* XXX 'long double' just ignored, or what? */
|
|
|
|
default:
|
|
|
|
fprintf(state->file, "unknown_type_%d", IDL_NODE_TYPE(state->tree));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1998-11-25 02:16:49 +03:00
|
|
|
case IDLN_IDENT:
|
1999-02-08 20:47:44 +03:00
|
|
|
if (UP_IS_NATIVE(state->tree)) {
|
|
|
|
fputs(IDL_NATIVE(IDL_NODE_UP(state->tree)).user_type, state->file);
|
1999-03-29 02:01:33 +04:00
|
|
|
if (IDL_tree_property_get(state->tree, "ptr")) {
|
|
|
|
fputs(" *", state->file);
|
|
|
|
} else if (IDL_tree_property_get(state->tree, "ref")) {
|
|
|
|
fputs(" &", state->file);
|
|
|
|
}
|
1999-02-08 20:47:44 +03:00
|
|
|
} else {
|
|
|
|
fputs(IDL_IDENT(state->tree).str, state->file);
|
|
|
|
}
|
1998-12-03 09:33:59 +03:00
|
|
|
if (UP_IS_AGGREGATE(state->tree))
|
|
|
|
fputs(" *", state->file);
|
|
|
|
break;
|
1998-11-25 02:16:49 +03:00
|
|
|
default:
|
1998-12-03 09:33:59 +03:00
|
|
|
fprintf(state->file, "unknown_type_%d", IDL_NODE_TYPE(state->tree));
|
|
|
|
break;
|
1998-11-25 02:16:49 +03:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* An attribute declaration looks like:
|
|
|
|
*
|
|
|
|
* [ IDL_ATTR_DCL]
|
|
|
|
* - param_type_spec [IDL_TYPE_* or NULL for void]
|
|
|
|
* - simple_declarations [IDL_LIST]
|
|
|
|
* - data [IDL_IDENT]
|
|
|
|
* - next [IDL_LIST or NULL if no more idents]
|
|
|
|
* - data [IDL_IDENT]
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define ATTR_IDENT(tree) (IDL_IDENT(IDL_LIST(IDL_ATTR_DCL(tree).simple_declarations).data))
|
|
|
|
#define ATTR_TYPE_DECL(tree) (IDL_ATTR_DCL(tree).param_type_spec)
|
|
|
|
#define ATTR_TYPE(tree) (IDL_NODE_TYPE(ATTR_TYPE_DECL(tree)))
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
attr_accessor(TreeState *state, gboolean getter)
|
|
|
|
{
|
|
|
|
char *attrname = ATTR_IDENT(state->tree).str;
|
1999-03-06 22:26:40 +03:00
|
|
|
IDL_tree orig = state->tree;
|
|
|
|
fprintf(state->file, " NS_IMETHOD %cet%c%s(",
|
|
|
|
getter ? 'G' : 'S',
|
|
|
|
toupper(attrname[0]), attrname + 1);
|
|
|
|
state->tree = ATTR_TYPE_DECL(state->tree);
|
|
|
|
if (!xpcom_type(state))
|
|
|
|
return FALSE;
|
|
|
|
state->tree = orig;
|
|
|
|
fprintf(state->file, "%s%sa%c%s) = 0;\n",
|
|
|
|
(STARRED_TYPE(orig) ? "" : " "),
|
|
|
|
getter ? "*" : "",
|
|
|
|
toupper(attrname[0]), attrname + 1);
|
1998-11-24 00:02:31 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
attr_dcl(TreeState *state)
|
|
|
|
{
|
1998-11-25 02:16:49 +03:00
|
|
|
gboolean ro = IDL_ATTR_DCL(state->tree).f_readonly;
|
1999-02-22 03:24:34 +03:00
|
|
|
xpidl_write_comment(state, 2);
|
1998-11-25 02:16:49 +03:00
|
|
|
return attr_accessor(state, TRUE) && (ro || attr_accessor(state, FALSE));
|
1998-11-24 00:02:31 +03:00
|
|
|
}
|
|
|
|
|
1998-11-28 19:52:24 +03:00
|
|
|
static gboolean
|
|
|
|
do_enum(TreeState *state)
|
|
|
|
{
|
1999-03-29 02:01:33 +04:00
|
|
|
IDL_tree_warning(state->tree, IDL_WARNING1,
|
|
|
|
"enums not supported, enum \'%s\' ignored",
|
|
|
|
IDL_IDENT(IDL_TYPE_ENUM(state->tree).ident).str);
|
|
|
|
return TRUE;
|
|
|
|
#if 0
|
1998-11-28 19:52:24 +03:00
|
|
|
IDL_tree enumb = state->tree, iter;
|
1999-02-16 08:10:40 +03:00
|
|
|
|
1998-12-06 22:52:21 +03:00
|
|
|
fprintf(state->file, "enum %s {\n",
|
1998-12-03 09:33:59 +03:00
|
|
|
IDL_IDENT(IDL_TYPE_ENUM(enumb).ident).str);
|
1998-11-28 19:52:24 +03:00
|
|
|
|
|
|
|
for (iter = IDL_TYPE_ENUM(enumb).enumerator_list;
|
1999-02-22 03:24:34 +03:00
|
|
|
iter;
|
|
|
|
iter = IDL_LIST(iter).next) {
|
1998-12-03 09:33:59 +03:00
|
|
|
fprintf(state->file, " %s%s\n", IDL_IDENT(IDL_LIST(iter).data).str,
|
|
|
|
IDL_LIST(iter).next ? ",": "");
|
1999-02-22 03:24:34 +03:00
|
|
|
}
|
1998-11-28 19:52:24 +03:00
|
|
|
|
1998-12-06 22:52:21 +03:00
|
|
|
fputs("};\n\n", state->file);
|
1998-11-28 19:52:24 +03:00
|
|
|
return TRUE;
|
1999-03-29 02:01:33 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
do_const_dcl(TreeState *state)
|
|
|
|
{
|
|
|
|
struct _IDL_CONST_DCL *dcl = &IDL_CONST_DCL(state->tree);
|
|
|
|
const char *name = IDL_IDENT(dcl->ident).str;
|
|
|
|
gboolean success;
|
|
|
|
|
|
|
|
/* const -> list -> interface */
|
|
|
|
if (!IDL_NODE_UP(IDL_NODE_UP(state->tree)) ||
|
|
|
|
IDL_NODE_TYPE(IDL_NODE_UP(IDL_NODE_UP(state->tree)))
|
|
|
|
!= IDLN_INTERFACE) {
|
|
|
|
IDL_tree_warning(state->tree, IDL_WARNING1,
|
|
|
|
"const decl \'%s\' not inside interface, ignored",
|
|
|
|
name);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
success = (IDLN_TYPE_INTEGER == IDL_NODE_TYPE(dcl->const_type));
|
|
|
|
if(success) {
|
|
|
|
switch(IDL_TYPE_INTEGER(dcl->const_type).f_type) {
|
|
|
|
case IDL_INTEGER_TYPE_SHORT:
|
|
|
|
case IDL_INTEGER_TYPE_LONG:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
success = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(success) {
|
1999-04-10 10:17:49 +04:00
|
|
|
fprintf(state->file, "\n enum { %s = %d };\n",
|
1999-03-29 02:01:33 +04:00
|
|
|
name, (int) IDL_INTEGER(dcl->const_exp).value);
|
|
|
|
} else {
|
|
|
|
IDL_tree_warning(state->tree, IDL_WARNING1,
|
|
|
|
"const decl \'%s\' was not of type short or long, ignored", name);
|
|
|
|
}
|
|
|
|
return TRUE;
|
1998-11-28 19:52:24 +03:00
|
|
|
}
|
|
|
|
|
1999-01-11 19:56:45 +03:00
|
|
|
static gboolean
|
|
|
|
do_typedef(TreeState *state)
|
|
|
|
{
|
|
|
|
IDL_tree type = IDL_TYPE_DCL(state->tree).type_spec,
|
|
|
|
dcls = IDL_TYPE_DCL(state->tree).dcls,
|
|
|
|
complex;
|
|
|
|
|
|
|
|
if (IDL_NODE_TYPE(type) == IDLN_TYPE_SEQUENCE) {
|
1999-03-29 02:01:33 +04:00
|
|
|
IDL_tree_warning(state->tree, IDL_WARNING1,
|
|
|
|
"sequences not supported, ignored");
|
1999-01-11 19:56:45 +03:00
|
|
|
} else {
|
|
|
|
state->tree = type;
|
1999-03-30 02:33:38 +04:00
|
|
|
fputs("typedef ", state->file);
|
1999-01-11 19:56:45 +03:00
|
|
|
if (!xpcom_type(state))
|
|
|
|
return FALSE;
|
1999-02-23 18:28:58 +03:00
|
|
|
fputs(" ", state->file);
|
1999-01-11 19:56:45 +03:00
|
|
|
if (IDL_NODE_TYPE(complex = IDL_LIST(dcls).data) == IDLN_TYPE_ARRAY) {
|
1999-02-08 20:47:44 +03:00
|
|
|
fprintf(state->file, "%s[%ld]",
|
1999-01-11 19:56:45 +03:00
|
|
|
IDL_IDENT(IDL_TYPE_ARRAY(complex).ident).str,
|
1999-02-08 20:47:44 +03:00
|
|
|
(long)IDL_INTEGER(IDL_LIST(IDL_TYPE_ARRAY(complex).size_list).
|
1999-01-11 19:56:45 +03:00
|
|
|
data).value);
|
|
|
|
} else {
|
1999-02-23 05:38:16 +03:00
|
|
|
fputs(" ", state->file);
|
1999-01-11 19:56:45 +03:00
|
|
|
fputs(IDL_IDENT(IDL_LIST(dcls).data).str, state->file);
|
|
|
|
}
|
1999-03-29 02:01:33 +04:00
|
|
|
fputs(";\n", state->file);
|
1999-01-11 19:56:45 +03:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1998-11-25 07:19:59 +03:00
|
|
|
/*
|
|
|
|
* param generation:
|
1999-02-18 01:13:32 +03:00
|
|
|
* in string foo --> nsString *foo
|
1998-12-03 09:33:59 +03:00
|
|
|
* out string foo --> nsString **foo;
|
|
|
|
* inout string foo --> nsString **foo;
|
1998-11-25 07:19:59 +03:00
|
|
|
*/
|
|
|
|
|
1999-02-17 04:17:52 +03:00
|
|
|
/* XXXbe static */ gboolean
|
1998-11-25 07:19:59 +03:00
|
|
|
xpcom_param(TreeState *state)
|
|
|
|
{
|
|
|
|
IDL_tree param = state->tree;
|
|
|
|
state->tree = IDL_PARAM_DCL(param).param_type_spec;
|
1998-11-27 00:03:03 +03:00
|
|
|
|
1999-05-05 00:03:43 +04:00
|
|
|
/* in string, wstring, nsid, and any explicitly marked [const] are const */
|
1999-03-06 23:59:41 +03:00
|
|
|
if (IDL_PARAM_DCL(param).attr == IDL_PARAM_IN &&
|
|
|
|
(IDL_NODE_TYPE(state->tree) == IDLN_TYPE_STRING ||
|
1999-03-29 02:01:33 +04:00
|
|
|
IDL_NODE_TYPE(state->tree) == IDLN_TYPE_WIDE_STRING ||
|
1999-05-12 11:42:32 +04:00
|
|
|
IDL_tree_property_get(IDL_PARAM_DCL(param).simple_declarator,
|
|
|
|
"const") ||
|
1999-03-29 02:01:33 +04:00
|
|
|
IDL_tree_property_get(state->tree, "nsid"))) {
|
1999-03-06 23:59:41 +03:00
|
|
|
fputs("const ", state->file);
|
1999-03-29 02:01:33 +04:00
|
|
|
}
|
1999-05-05 00:03:43 +04:00
|
|
|
else if (IDL_PARAM_DCL(param).attr == IDL_PARAM_OUT &&
|
1999-05-12 11:42:32 +04:00
|
|
|
IDL_tree_property_get(IDL_PARAM_DCL(param).simple_declarator,
|
|
|
|
"shared")) {
|
1999-05-05 00:03:43 +04:00
|
|
|
fputs("const ", state->file);
|
|
|
|
}
|
1999-03-06 23:59:41 +03:00
|
|
|
|
1998-11-25 07:19:59 +03:00
|
|
|
if (!xpcom_type(state))
|
1998-12-03 09:33:59 +03:00
|
|
|
return FALSE;
|
1999-03-06 23:59:41 +03:00
|
|
|
|
|
|
|
/* unless the type ended in a *, add a space */
|
|
|
|
if (!STARRED_TYPE(state->tree))
|
|
|
|
fputc(' ', state->file);
|
|
|
|
|
|
|
|
/* out and inout params get a bonus *! */
|
|
|
|
if (IDL_PARAM_DCL(param).attr != IDL_PARAM_IN)
|
|
|
|
fputc('*', state->file);
|
|
|
|
|
|
|
|
fputs(IDL_IDENT(IDL_PARAM_DCL(param).simple_declarator).str, state->file);
|
1998-11-25 07:19:59 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1999-02-18 20:43:38 +03:00
|
|
|
/*
|
|
|
|
* A forward declaration, usually an interface.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
forward_dcl(TreeState *state)
|
|
|
|
{
|
|
|
|
IDL_tree iface = state->tree;
|
|
|
|
char *className = IDL_IDENT(IDL_FORWARD_DCL(iface).ident).str;
|
|
|
|
if (!className)
|
|
|
|
return FALSE;
|
|
|
|
fprintf(state->file, "class %s; /* forward decl */\n", className);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1998-11-24 00:02:31 +03:00
|
|
|
/*
|
|
|
|
* A method is an `operation', therefore a method decl is an `op dcl'.
|
|
|
|
* I blame Elliot.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
op_dcl(TreeState *state)
|
|
|
|
{
|
1999-02-17 04:17:52 +03:00
|
|
|
struct _IDL_OP_DCL *op = &IDL_OP_DCL(state->tree);
|
1999-02-23 18:28:58 +03:00
|
|
|
gboolean op_notxpcom =
|
|
|
|
(IDL_tree_property_get(op->ident, "notxpcom") != NULL);
|
1998-11-25 07:19:59 +03:00
|
|
|
IDL_tree iter;
|
1999-01-11 19:56:45 +03:00
|
|
|
|
1999-02-22 03:24:34 +03:00
|
|
|
xpidl_write_comment(state, 2);
|
1998-11-25 07:19:59 +03:00
|
|
|
|
1999-02-23 18:28:58 +03:00
|
|
|
fputs(" ", state->file);
|
|
|
|
if (op_notxpcom) {
|
|
|
|
state->tree = op->op_type_spec;
|
|
|
|
fputs("NS_IMETHOD_(", state->file);
|
|
|
|
if (!xpcom_type(state))
|
|
|
|
return FALSE;
|
|
|
|
fputc(')', state->file);
|
|
|
|
} else {
|
|
|
|
fputs("NS_IMETHOD", state->file);
|
1999-03-29 02:01:33 +04:00
|
|
|
}
|
1999-02-23 18:28:58 +03:00
|
|
|
fprintf(state->file, " %s(", IDL_IDENT(op->ident).str);
|
1999-02-17 04:17:52 +03:00
|
|
|
for (iter = op->parameter_dcls; iter; iter = IDL_LIST(iter).next) {
|
1998-12-03 09:33:59 +03:00
|
|
|
state->tree = IDL_LIST(iter).data;
|
|
|
|
if (!xpcom_param(state))
|
|
|
|
return FALSE;
|
1999-05-12 06:13:40 +04:00
|
|
|
if ((IDL_LIST(iter).next ||
|
|
|
|
(!op_notxpcom && op->op_type_spec) || op->f_varargs))
|
1998-12-03 09:33:59 +03:00
|
|
|
fputs(", ", state->file);
|
1998-11-25 07:19:59 +03:00
|
|
|
}
|
1998-12-06 22:52:21 +03:00
|
|
|
|
|
|
|
/* make IDL return value into trailing out argument */
|
1999-02-23 18:28:58 +03:00
|
|
|
if (op->op_type_spec && !op_notxpcom) {
|
1998-12-06 22:52:21 +03:00
|
|
|
IDL_tree fake_param = IDL_param_dcl_new(IDL_PARAM_OUT,
|
1999-02-17 04:17:52 +03:00
|
|
|
op->op_type_spec,
|
1998-12-06 22:52:21 +03:00
|
|
|
IDL_ident_new("_retval"));
|
|
|
|
if (!fake_param)
|
|
|
|
return FALSE;
|
|
|
|
state->tree = fake_param;
|
|
|
|
if (!xpcom_param(state))
|
|
|
|
return FALSE;
|
1999-02-17 04:17:52 +03:00
|
|
|
if (op->f_varargs)
|
1998-12-06 22:52:21 +03:00
|
|
|
fputs(", ", state->file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* varargs go last */
|
1999-02-17 04:17:52 +03:00
|
|
|
if (op->f_varargs) {
|
1999-01-11 19:56:45 +03:00
|
|
|
fputs("nsVarArgs *_varargs", state->file);
|
1998-12-06 22:52:21 +03:00
|
|
|
}
|
1998-11-25 22:12:50 +03:00
|
|
|
fputs(") = 0;\n", state->file);
|
1998-11-24 00:02:31 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1998-12-14 21:47:39 +03:00
|
|
|
static void
|
1999-02-22 03:24:34 +03:00
|
|
|
write_codefrag_line(gpointer data, gpointer user_data)
|
1998-12-14 21:47:39 +03:00
|
|
|
{
|
|
|
|
TreeState *state = (TreeState *)user_data;
|
|
|
|
char *line = (char *)data;
|
|
|
|
fputs(line, state->file);
|
|
|
|
fputc('\n', state->file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
codefrag(TreeState *state)
|
|
|
|
{
|
|
|
|
if (strcmp(IDL_CODEFRAG(state->tree).desc, "C++"))
|
|
|
|
return TRUE;
|
1999-02-22 03:24:34 +03:00
|
|
|
g_slist_foreach(IDL_CODEFRAG(state->tree).lines, write_codefrag_line,
|
1998-12-14 21:47:39 +03:00
|
|
|
(gpointer)state);
|
|
|
|
fputc('\n', state->file);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1999-02-17 04:17:52 +03:00
|
|
|
nodeHandler *
|
|
|
|
xpidl_header_dispatch(void)
|
1998-12-02 22:53:27 +03:00
|
|
|
{
|
1998-12-03 09:33:59 +03:00
|
|
|
static nodeHandler table[IDLN_LAST];
|
|
|
|
|
1999-02-17 04:17:52 +03:00
|
|
|
if (!table[IDLN_NONE]) {
|
1998-12-03 09:33:59 +03:00
|
|
|
table[IDLN_NONE] = pass_1;
|
|
|
|
table[IDLN_LIST] = list;
|
|
|
|
table[IDLN_ATTR_DCL] = attr_dcl;
|
|
|
|
table[IDLN_OP_DCL] = op_dcl;
|
1999-02-18 20:43:38 +03:00
|
|
|
table[IDLN_FORWARD_DCL] = forward_dcl;
|
1998-12-03 09:33:59 +03:00
|
|
|
table[IDLN_TYPE_ENUM] = do_enum;
|
|
|
|
table[IDLN_INTERFACE] = interface;
|
1998-12-14 21:47:39 +03:00
|
|
|
table[IDLN_CODEFRAG] = codefrag;
|
1999-01-11 19:56:45 +03:00
|
|
|
table[IDLN_TYPE_DCL] = do_typedef;
|
1999-03-29 02:01:33 +04:00
|
|
|
table[IDLN_CONST_DCL] = do_const_dcl;
|
1998-12-03 09:33:59 +03:00
|
|
|
}
|
1999-02-16 08:10:40 +03:00
|
|
|
|
|
|
|
return table;
|
1998-12-02 22:53:27 +03:00
|
|
|
}
|