Commit e5596bb3 authored by brendan%netscape.com's avatar brendan%netscape.com
Browse files

Checkpoint xpidl -m stub work.

parent b768f8a7
Loading
Loading
Loading
Loading
+5 −15
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ xpidl_usage(int argc, char *argv[])
    }
}

static char OOM[] = "ERROR: out of memory\n";
/* XXXbe static */ char OOM[] = "ERROR: out of memory\n";

void *
xpidl_malloc(size_t nbytes)
@@ -101,13 +101,6 @@ main(int argc, char *argv[])
    inc_head->next = NULL;
    inc_tail = &inc_head->next;

#if 0
    /* initialize mode factories */
    modes[0].factory = headerDispatch;
    modes[1].factory = typelibDispatch;
    modes[2].factory = docDispatch;
#endif

    for (i = 1; i < argc; i++) {
        if (argv[i][0] != '-')
            break;
@@ -130,14 +123,13 @@ main(int argc, char *argv[])
                return 1;
            }
            inc = xpidl_malloc(sizeof *inc);
            inc->directory = argv[i + 1];
            inc->directory = argv[++i];
#ifdef DEBUG_shaver_includes
            fprintf(stderr, "adding %s to include path\n", inc->directory);
#endif
            inc->next = NULL;
            *inc_tail = inc;
	    inc_tail = &inc->next;
            i++;
            break;
          case 'o':
            if (i == argc) {
@@ -163,7 +155,7 @@ main(int argc, char *argv[])
            }
            if (mode) {
                fprintf(stderr,
                        "ERROR: can only specify one mode "
                        "ERROR: must specify exactly one mode "
                        "(first \"%s\", now \"%s\")\n", mode->mode,
                        argv[i + 1]);
                xpidl_usage(argc, argv);
@@ -190,10 +182,8 @@ main(int argc, char *argv[])
        return 1;
    }

    for (idlfiles = 0; i < argc; i++) {
        if (argv[i][0])
    for (idlfiles = 0; i < argc; i++)
	idlfiles += xpidl_process_idl(argv[i], inc_head, basename, mode);
    }

    if (!idlfiles)
        return 1;
+14 −8
Original line number Diff line number Diff line
@@ -23,14 +23,14 @@
#ifndef __xpidl_h
#define __xpidl_h

#include <glib.h>
#include <assert.h>
#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <glib.h>
#include <libIDL/IDL.h>
#include <assert.h>
#include <stdlib.h>

/*
 * Internal operation flags.
@@ -49,10 +49,10 @@ typedef gboolean (*nodeHandler)(TreeState *);
/* Function that produces a table of nodeHandlers for a given mode */
typedef nodeHandler *(*nodeHandlerFactory)();

extern nodeHandler *xpidl_header_dispatch();
extern nodeHandler *xpidl_stub_dispatch();
extern nodeHandler *xpidl_typelib_dispatch();
extern nodeHandler *xpidl_doc_dispatch();
extern nodeHandler *xpidl_header_dispatch(void);
extern nodeHandler *xpidl_stub_dispatch(void);
extern nodeHandler *xpidl_typelib_dispatch(void);
extern nodeHandler *xpidl_doc_dispatch(void);

/*
 * nodeHandler that reports an error.
@@ -111,4 +111,10 @@ xpidl_strdup(const char *s);
gboolean
xpidl_process_node(TreeState *state);

/*
 * Dump a comment containing IDL source decompiled from state->tree.
 */
void
xpidl_dump_comment(TreeState *state, int indent);

#endif /* __xpidl_h */
+2 −1
Original line number Diff line number Diff line
@@ -22,7 +22,8 @@
 * Generates documentation from javadoc-style comments in XPIDL files.
 */

nodeHandler *xpidl_doc_dispatch()
nodeHandler *
xpidl_doc_dispatch(void)
{
    static nodeHandler table[IDLN_LAST];
    static gboolean initialized = FALSE;
+38 −146
Original line number Diff line number Diff line
@@ -38,21 +38,6 @@
			    (IDL_NODE_TYPE(node) == IDLN_IDENT &&             \
			     UP_IS_AGGREGATE(node)))

#define IDL_OUTPUT_FLAGS (IDLF_OUTPUT_NO_NEWLINES |                           \
                          IDLF_OUTPUT_NO_QUALIFY_IDENTS |                     \
                          IDLF_OUTPUT_PROPERTIES)

static void
dump_IDL(TreeState *state)
{
    IDL_tree_to_IDL(state->tree, state->ns, state->file, IDL_OUTPUT_FLAGS);
}

#define DUMP_IDL_COMMENT(state)                                               \
  fputs("\n  /* ", state->file);                                              \
  dump_IDL(state);                                                            \
  fputs(" */\n", state->file);

static void
write_header(gpointer key, gpointer value, gpointer user_data)
{
@@ -65,8 +50,8 @@ write_header(gpointer key, gpointer value, gpointer user_data)
static gboolean
pass_1(TreeState *state)
{
    if (state->tree) {
    char *define = g_basename(state->basename);
    if (state->tree) {
        fprintf(state->file, "/*\n * DO NOT EDIT.  THIS FILE IS GENERATED FROM"
                " %s.idl\n */\n", state->basename);
        fprintf(state->file, "\n#ifndef __gen_%s_h__\n"
@@ -77,7 +62,7 @@ pass_1(TreeState *state)
            fputc('\n', state->file);
        }
    } else {
        fprintf(state->file, "\n#endif /* __gen_%s_h__ */\n", state->basename);
        fprintf(state->file, "\n#endif /* __gen_%s_h__ */\n", define);
    }
    return TRUE;
}
@@ -168,7 +153,7 @@ list(TreeState *state)
    return TRUE;
}

static gboolean
/* XXXbe static */ gboolean
xpcom_type(TreeState *state)
{
    if (!state->tree) {
@@ -227,97 +212,6 @@ xpcom_type(TreeState *state)
    return TRUE;
}

static gboolean
type_integer(TreeState *state)
{
    IDL_tree p = state->tree;

    if (!IDL_TYPE_INTEGER(p).f_signed)
        fputs("unsigned ", state->file);

    switch(IDL_TYPE_INTEGER(p).f_type) {
      case IDL_INTEGER_TYPE_SHORT:
        printf("short");
        break;
      case IDL_INTEGER_TYPE_LONG:
        printf("long");
        break;
      case IDL_INTEGER_TYPE_LONGLONG:
        printf("long long");
        break;
    }
    return TRUE;
}

static gboolean
type(TreeState *state)
{
    if (!state->tree) {
        fputs("void", state->file);
        return TRUE;
    }

    switch(IDL_NODE_TYPE(state->tree)) {
      case IDLN_TYPE_INTEGER:
        return type_integer(state);
      case IDLN_TYPE_STRING:
        fputs("string", state->file);
        return TRUE;
      case IDLN_TYPE_WIDE_STRING:
        fputs("wstring", state->file);
        return TRUE;
      case IDLN_TYPE_CHAR:
        fputs("char", state->file);
        return TRUE;
      case IDLN_TYPE_WIDE_CHAR:
        fputs("wchar", state->file);
        return TRUE;
      case IDLN_TYPE_BOOLEAN:
        fputs("boolean", state->file);
        return TRUE;
      case IDLN_IDENT:
        fputs(IDL_IDENT(state->tree).str, state->file);
        break;
      default:
        fprintf(state->file, "unknown_type_%d", IDL_NODE_TYPE(state->tree));
        return TRUE;
    }

    return TRUE;
}

static gboolean
param_dcls(TreeState *state)
{
    IDL_tree iter;
    fputs("(", state->file);
    for (iter = state->tree; iter; iter = IDL_LIST(iter).next) {
        struct _IDL_PARAM_DCL decl = IDL_PARAM_DCL(IDL_LIST(iter).data);
        switch(decl.attr) {
          case IDL_PARAM_IN:
            fputs("in ", state->file);
            break;
          case IDL_PARAM_OUT:
            fputs("out ", state->file);
            break;
          case IDL_PARAM_INOUT:
            fputs("inout ", state->file);
            break;
          default:;
        }
        state->tree = (IDL_tree)decl.param_type_spec;
        if (!type(state))
            return FALSE;
        fputs(" ", state->file);
        state->tree = (IDL_tree)decl.simple_declarator;
        if (!xpidl_process_node(state))
            return FALSE;
        if (IDL_LIST(iter).next)
            fputs(", ", state->file);
    }
    return TRUE;
}

/*
 * An attribute declaration looks like:
 *
@@ -356,7 +250,7 @@ static gboolean
attr_dcl(TreeState *state)
{
    gboolean ro = IDL_ATTR_DCL(state->tree).f_readonly;
    DUMP_IDL_COMMENT(state);
    xpidl_dump_comment(state, 2);
    return attr_accessor(state, TRUE) && (ro || attr_accessor(state, FALSE));
}

@@ -412,7 +306,7 @@ do_typedef(TreeState *state)
 * inout string foo     -->     nsString **foo;
 */

static gboolean
/* XXXbe static */ gboolean
xpcom_param(TreeState *state)
{
    IDL_tree param = state->tree;
@@ -435,36 +329,36 @@ xpcom_param(TreeState *state)
static gboolean
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;

    DUMP_IDL_COMMENT(state);
    xpidl_dump_comment(state, 2);

    fprintf(state->file, "  NS_IMETHOD %s(", IDL_IDENT(op.ident).str);
    for (iter = op.parameter_dcls; iter; iter = IDL_LIST(iter).next) {
    fprintf(state->file, "  NS_IMETHOD %s(", IDL_IDENT(op->ident).str);
    for (iter = op->parameter_dcls; iter; iter = IDL_LIST(iter).next) {
        state->tree = IDL_LIST(iter).data;
        if (!xpcom_param(state))
            return FALSE;
        if (IDL_LIST(iter).next || op.op_type_spec || op.f_varargs)
        if (IDL_LIST(iter).next || op->op_type_spec || op->f_varargs)
            fputs(", ", state->file);
    }

    /* make IDL return value into trailing out argument */
    if (op.op_type_spec) {
    if (op->op_type_spec) {
        IDL_tree fake_param = IDL_param_dcl_new(IDL_PARAM_OUT,
                                                op.op_type_spec,
                                                op->op_type_spec,
                                                IDL_ident_new("_retval"));
        if (!fake_param)
            return FALSE;
        state->tree = fake_param;
        if (!xpcom_param(state))
            return FALSE;
        if (op.f_varargs)
        if (op->f_varargs)
            fputs(", ", state->file);
    }

    /* varargs go last */
    if (op.f_varargs) {
    if (op->f_varargs) {
        fputs("nsVarArgs *_varargs", state->file);
    }
    fputs(") = 0;\n", state->file);
@@ -491,22 +385,20 @@ codefrag(TreeState *state)
    return TRUE;
}

nodeHandler *xpidl_header_dispatch()
nodeHandler *
xpidl_header_dispatch(void)
{
    static nodeHandler table[IDLN_LAST];
    static gboolean initialized = FALSE;

    if (!initialized) {
    if (!table[IDLN_NONE]) {
        table[IDLN_NONE] = pass_1;
        table[IDLN_LIST] = list;
        table[IDLN_ATTR_DCL] = attr_dcl;
        table[IDLN_OP_DCL] = op_dcl;
        table[IDLN_PARAM_DCL] = param_dcls;
        table[IDLN_TYPE_ENUM] = do_enum;
        table[IDLN_INTERFACE] = interface;
        table[IDLN_CODEFRAG] = codefrag;
        table[IDLN_TYPE_DCL] = do_typedef;
        initialized = TRUE;
    }

    return table;
+34 −23
Original line number Diff line number Diff line
@@ -46,11 +46,11 @@ node_is_error(TreeState *state)
void
xpidl_list_foreach(IDL_tree p, IDL_tree_func foreach, gpointer user_data)
{
    IDL_tree iter;
    for (iter = p; iter; iter = IDL_LIST(iter).next) {
        if (!foreach(IDL_LIST(iter).data,
                     IDL_tree_get_scope(IDL_LIST(iter).data), user_data))
    while (p) {
	struct _IDL_LIST *list = &IDL_LIST(p);
        if (!foreach(list->data, IDL_tree_get_scope(list->data), user_data))
            return;
    	p = list->next;
    }
}

@@ -60,17 +60,17 @@ xpidl_list_foreach(IDL_tree p, IDL_tree_func foreach, gpointer user_data)
gboolean
xpidl_process_node(TreeState *state)
{
    nodeHandler *handlerp = state->dispatch, handler;
    gint type;
    assert(state->tree);
    nodeHandler *dispatch, handler;

    assert(state->tree);
    type = IDL_NODE_TYPE(state->tree);

    /*
     * type == 0 shouldn't ever happen for real, so we use that slot for
     * pass-1 processing
     */
    if (type && handlerp && (handler = handlerp[type]))
    if (type && (dispatch = state->dispatch) && (handler = dispatch[type]))
        return handler(state);
    return TRUE;
}
@@ -90,9 +90,7 @@ process_tree(TreeState *state)
    if (!xpidl_process_node(state))
        return FALSE;
    state->tree = NULL;
    if (!process_tree_pass1(state))
        return FALSE;
    return TRUE;
    return process_tree_pass1(state);
}

static int
@@ -138,25 +136,27 @@ static FILE *
fopen_from_includes(const char *filename, const char *mode,
                    IncludePathEntry *include_path)
{
    char *filebuf = NULL;
    FILE *file = NULL;
    char *pathname;
    FILE *file;
    if (!strcmp(filename, "-"))
        return stdin;

    for (; include_path && !file; include_path = include_path->next) {
        filebuf = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
    while (include_path) {
        pathname = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
				   include_path->directory, filename);
        if (!filebuf)
        if (!pathname)
            return NULL;
#ifdef DEBUG_shaver_bufmgmt
        fprintf(stderr, "looking for %s as %s\n", filename, filebuf);
        fprintf(stderr, "looking for %s as %s\n", filename, pathname);
#endif
        file = fopen(filebuf, mode);
        free(filebuf);
        file = fopen(pathname, mode);
        free(pathname);
	if (file)
	    return file;
    	include_path = include_path->next;
    }
    if (!file)
    fprintf(stderr, "can't open %s for reading\n", filename);
    return file;
    return NULL;
}

static struct input_callback_data *
@@ -233,7 +233,7 @@ input_callback(IDL_input_reason reason, union IDL_input_data *cb_data,
        /*
         * When we're stripping comments and processing #includes,
         * we need to be sure that we don't process anything inside
         * \n%{ and \n%}.  In order to simplify things, we only process
         * \n%{ and \n%}.  In order to simplify things, we process only
         * comment, include or raw-block stuff when they're at the
         * beginning of the block we're about to send (data->point).
         * This makes the processing much simpler, since we can skip
@@ -505,3 +505,14 @@ xpidl_process_idl(char *filename, IncludePathEntry *include_path,

    return 1;
}

void
xpidl_dump_comment(TreeState *state, int indent)
{
    fprintf(state->file, "\n%*s/* ", indent, "");
    IDL_tree_to_IDL(state->tree, state->ns, state->file,
    		    IDLF_OUTPUT_NO_NEWLINES |
		    IDLF_OUTPUT_NO_QUALIFY_IDENTS |
		    IDLF_OUTPUT_PROPERTIES);
    fputs(" */\n", state->file);
}
Loading