예제 #1
0
파일: ns.c 프로젝트: AmaneKIRA2Misa/libIDL
int IDL_ns_prefix (IDL_ns ns, const char *s)
{
	char *r;
	int l;

	IDL_NS_ASSERTS;

	if (s == NULL)
		return FALSE;

	if (*s == '"')
		r = g_strdup (s + 1);
	else
		r = g_strdup (s);

	l = strlen (r);
	if (l && r[l - 1] == '"')
		r[l - 1] = 0;

	if (IDL_GENTREE (IDL_NS (ns).current)._cur_prefix)
		g_free (IDL_GENTREE (IDL_NS (ns).current)._cur_prefix);

	IDL_GENTREE (IDL_NS (ns).current)._cur_prefix = r;

	return TRUE;
}
예제 #2
0
파일: ns.c 프로젝트: AmaneKIRA2Misa/libIDL
int IDL_ns_scope_levels_from_here (IDL_ns ns, IDL_tree ident, IDL_tree parent)
{
	IDL_tree p, scope_here, scope_ident;
	int levels;

	g_return_val_if_fail (ns != NULL, 1);
	g_return_val_if_fail (ident != NULL, 1);

	while (parent && !IDL_NODE_IS_SCOPED (parent))
		parent = IDL_NODE_UP (parent);

	if (parent == NULL)
		return 1;

	if ((scope_here = IDL_tree_get_scope (parent)) == NULL ||
	    (scope_ident = IDL_tree_get_scope (ident)) == NULL)
		return 1;

	assert (IDL_NODE_TYPE (scope_here) == IDLN_GENTREE);
	assert (IDL_NODE_TYPE (scope_ident) == IDLN_GENTREE);

	for (levels = 1; scope_ident;
	     ++levels, scope_ident = IDL_NODE_UP (scope_ident)) {
		p = IDL_ns_resolve_this_scope_ident (
			ns, scope_here, IDL_GENTREE (scope_ident).data);
		if (p == scope_ident)
			return levels;
	}

	return 1;
}
예제 #3
0
파일: ns.c 프로젝트: AmaneKIRA2Misa/libIDL
static void insert_heap_cb (IDL_tree ident, IDL_tree p, InsertHeapData *data)
{
	if (!is_inheritance_conflict (p))
		return;

	if (!heap_insert_ident (
		data->interface_ident, data->ident_heap, IDL_GENTREE (p).data))
		data->insert_conflict = 1;
}
예제 #4
0
파일: ns.c 프로젝트: AmaneKIRA2Misa/libIDL
IDL_tree IDL_ns_lookup_this_scope (IDL_ns ns, IDL_tree scope, IDL_tree ident, gboolean *conflict)
{
	IDL_tree p, q;

	IDL_NS_ASSERTS;

	if (conflict)
		*conflict = TRUE;

	if (scope == NULL)
		return NULL;

	assert (IDL_NODE_TYPE (scope) == IDLN_GENTREE);

	/* Search this namespace */
	if (g_hash_table_lookup_extended (
		IDL_GENTREE (scope).children, ident, NULL, (gpointer)&p)) {
		assert (IDL_GENTREE (p).data != NULL);
		assert (IDL_NODE_TYPE (IDL_GENTREE (p).data) == IDLN_IDENT);
		return p;
	}

	/* If there are inherited namespaces, look in those before giving up */
	q = IDL_GENTREE (scope)._import;
	if (!q)
		return NULL;

	assert (IDL_NODE_TYPE (q) == IDLN_LIST);
	for (; q != NULL; q = IDL_LIST (q).next) {
		IDL_tree r;

		assert (IDL_LIST (q).data != NULL);
		assert (IDL_NODE_TYPE (IDL_LIST (q).data) == IDLN_IDENT);
		assert (IDL_IDENT_TO_NS (IDL_LIST (q).data) != NULL);
		assert (IDL_NODE_TYPE (IDL_IDENT_TO_NS (IDL_LIST (q).data)) == IDLN_GENTREE);

		/* Search imported namespace scope q */
		if (g_hash_table_lookup_extended (
			IDL_GENTREE (IDL_IDENT_TO_NS (IDL_LIST (q).data)).children,
			ident, NULL, (gpointer)&p)) {
			assert (IDL_GENTREE (p).data != NULL);
			assert (IDL_NODE_TYPE (IDL_GENTREE (p).data) == IDLN_IDENT);

			/* This needs more work, it won't do full ambiguity detection */
			if (conflict && !is_inheritance_conflict (p))
				*conflict = FALSE;

			return p;
		}

		/* Search up one level */
		if (IDL_NODE_TYPE (IDL_NODE_UP (IDL_LIST (q).data)) == IDLN_INTERFACE &&
		    (r = IDL_ns_lookup_this_scope (
			    ns, IDL_IDENT_TO_NS (IDL_LIST (q).data), ident, conflict)))
			return r;
	}

	return NULL;
}
예제 #5
0
파일: ns.c 프로젝트: AmaneKIRA2Misa/libIDL
IDL_tree IDL_ns_qualified_ident_new (IDL_tree nsid)
{
	IDL_tree l = NULL, item;

	while (nsid != NULL) {
		if (IDL_GENTREE (nsid).data == NULL) {
			nsid = IDL_NODE_UP (nsid);
			continue;
		}
		assert (IDL_GENTREE (nsid).data != NULL);
		assert (IDL_NODE_TYPE (IDL_GENTREE (nsid).data) == IDLN_IDENT);
		item = IDL_list_new (IDL_ident_new (
			g_strdup (IDL_IDENT (IDL_GENTREE (nsid).data).str)));
		l = IDL_list_concat (item, l);
		nsid = IDL_NODE_UP (nsid);
	}

	return l;
}
예제 #6
0
파일: ns.c 프로젝트: AmaneKIRA2Misa/libIDL
void IDL_ns_push_scope (IDL_ns ns, IDL_tree ns_ident)
{
	IDL_NS_ASSERTS;

	assert (IDL_NODE_TYPE (ns_ident) == IDLN_GENTREE);
	assert (IDL_NODE_TYPE (IDL_GENTREE (ns_ident).data) == IDLN_IDENT);
	assert (IDL_NS (ns).current == IDL_NODE_UP (ns_ident));

	IDL_NS (ns).current = ns_ident;
}
예제 #7
0
파일: ns.c 프로젝트: AmaneKIRA2Misa/libIDL
/* Return true if adds went okay */
static int IDL_ns_load_idents_to_tables (IDL_tree interface_ident, IDL_tree ident_scope,
					 GTree *ident_heap, GHashTable *visited_interfaces)
{
	IDL_tree q, scope;
	InsertHeapData data;

	assert (ident_scope != NULL);
	assert (IDL_NODE_TYPE (ident_scope) == IDLN_IDENT);

	scope = IDL_IDENT_TO_NS (ident_scope);

	if (!scope)
		return TRUE;

	assert (IDL_NODE_TYPE (scope) == IDLN_GENTREE);
	assert (IDL_GENTREE (scope).data != NULL);
	assert (IDL_NODE_TYPE (IDL_GENTREE (scope).data) == IDLN_IDENT);
	assert (IDL_NODE_UP (IDL_GENTREE (scope).data) != NULL);
	assert (IDL_NODE_TYPE (IDL_NODE_UP (IDL_GENTREE (scope).data)) == IDLN_INTERFACE);

	if (is_visited_interface (visited_interfaces, scope))
		return TRUE;

	/* Search this namespace */
	data.interface_ident = interface_ident;
	data.ident_heap = ident_heap;
	data.insert_conflict = 0;
	g_hash_table_foreach (IDL_GENTREE (scope).children, (GHFunc)insert_heap_cb, &data);

	/* If there are inherited namespaces, look in those before giving up */
	q = IDL_GENTREE (scope)._import;
	if (!q)
		data.insert_conflict = 0;
	else
		assert (IDL_NODE_TYPE (q) == IDLN_LIST);

	/* Add inherited namespace identifiers into heap */
	for (; q != NULL; q = IDL_LIST (q).next) {
		int r;

		assert (IDL_LIST (q).data != NULL);
		assert (IDL_NODE_TYPE (IDL_LIST (q).data) == IDLN_IDENT);
		assert (IDL_IDENT_TO_NS (IDL_LIST (q).data) != NULL);
		assert (IDL_NODE_TYPE (IDL_IDENT_TO_NS (IDL_LIST (q).data)) == IDLN_GENTREE);
		assert (IDL_NODE_TYPE (IDL_NODE_UP (IDL_LIST (q).data)) == IDLN_INTERFACE);

		if (!(r = IDL_ns_load_idents_to_tables (interface_ident, IDL_LIST (q).data,
							ident_heap, visited_interfaces)))
			data.insert_conflict = 1;
	}

	mark_visited_interface (visited_interfaces, scope);

	return data.insert_conflict == 0;
}
예제 #8
0
파일: ns.c 프로젝트: AmaneKIRA2Misa/libIDL
static int is_inheritance_conflict (IDL_tree p)
{
	if (IDL_GENTREE (p).data == NULL)
		return FALSE;

	assert (IDL_NODE_TYPE (IDL_GENTREE (p).data) == IDLN_IDENT);

	if (IDL_NODE_UP (IDL_GENTREE (p).data) == NULL)
		return FALSE;

	if (!(IDL_NODE_TYPE (IDL_NODE_UP (IDL_GENTREE (p).data)) == IDLN_OP_DCL ||
	      (IDL_NODE_UP (IDL_GENTREE (p).data) &&
	       IDL_NODE_TYPE (IDL_NODE_UP (IDL_NODE_UP (IDL_GENTREE (p).data))) == IDLN_ATTR_DCL)))
		return FALSE;

	return TRUE;
}
예제 #9
0
static gboolean
interface_declaration(TreeState *state) 
{

    char *outname;
    IDL_tree interface = state->tree;
    IDL_tree iterator = NULL;
    char *interface_name = 
        subscriptIdentifier(state, IDL_IDENT(IDL_INTERFACE(interface).ident).str);
    const char *iid = NULL;
    GSList *doc_comments = IDL_IDENT(IDL_INTERFACE(interface).ident).comments;
    char *prefix = IDL_GENTREE(IDL_NS(state->ns).current)._cur_prefix;

    /*
     * Each interface decl is a single file
     */
    outname = g_strdup_printf("%s.%s", interface_name, "java");
    FILENAME(state) =  fopen(outname, "w");
    if (!FILENAME(state)) {
        perror("error opening output file");
        return FALSE;
    }

    fputs("/*\n * ************* DO NOT EDIT THIS FILE ***********\n",
          FILENAME(state));
    
    fprintf(FILENAME(state), 
            " *\n * This file was automatically generated from %s.idl.\n", 
            state->basename);
    
    fputs(" */\n\n", FILENAME(state));
	
    if (prefix) {
        if (strlen(prefix))
            fprintf(FILENAME(state), "\npackage %s;\n\n", prefix);
        fputs("import org.mozilla.xpcom.*;\n\n", FILENAME(state));
    } else {
        fputs("\npackage org.mozilla.xpcom;\n\n", FILENAME(state));
    }

    /*
     * Write out JavaDoc comment
     */

    fprintf(FILENAME(state), "\n/**\n * Interface %s\n", interface_name);

#ifndef LIBIDL_MAJOR_VERSION
    iid = IDL_tree_property_get(interface, "uuid");
#else
    iid = IDL_tree_property_get(IDL_INTERFACE(interface).ident, "uuid");
#endif

    if (iid != NULL) {
        fprintf(FILENAME(state), " *\n * IID: 0x%s\n */\n\n", iid);
    } else {
        fputs(" */\n\n", FILENAME(state));
    }

    if (doc_comments != NULL)
        printlist(FILENAME(state), doc_comments);

    /*
     * Write "public interface <foo>"
     */

    fprintf(FILENAME(state), "public interface %s ", interface_name);

    /*
     * Check for inheritence, and iterator over the inherited names,
     * if any.
     */

    if ((iterator = IDL_INTERFACE(interface).inheritance_spec)) {
        fputs("extends ", FILENAME(state));

        do {

            fprintf(FILENAME(state), "%s", 
                    IDL_IDENT(IDL_LIST(iterator).data).str);
	    
            if (IDL_LIST(iterator).next) {
                fputs(", ", FILENAME(state));
            }
        } while ((iterator = IDL_LIST(iterator).next));

    }

    fputs("\n{\n", FILENAME(state));
    
    if (iid) {
        /*
         * Write interface constants for IID
         */

/*          fputs("    public static final String ", FILENAME(state)); */

        /* XXX s.b just "IID" ? */
/*          if (!write_classname_iid_define(FILENAME(state), interface_name)) { */
/*              return FALSE; */
/*          } */

/*          fprintf(FILENAME(state), "_STRING =\n        \"%s\";\n\n", iid); */

/*          fputs("    public static final nsID ", FILENAME(state)); */

        /* XXX s.b just "IID" ? */
/*          if (!write_classname_iid_define(FILENAME(state), interface_name)) { */
/*              return FALSE; */
/*          } */

/*          fprintf(FILENAME(state), " =\n        new nsID(\"%s\");\n\n", iid); */
        fprintf(FILENAME(state), "    public static final IID IID =\n       new IID(\"%s\");\n\n", iid);
    }

    /*
     * Advance the state of the tree, go on to process more
     */
    
    state->tree = IDL_INTERFACE(interface).body;

    if (state->tree && !xpidl_process_node(state)) {
        return FALSE;
    }


    fputs("\n}\n", FILENAME(state));
    fprintf(FILENAME(state), "\n/*\n * end\n */\n");
    fclose(FILENAME(state));
    free(outname);

    return TRUE;
}