void IDL_ns_pop_scope (IDL_ns ns) { IDL_NS_ASSERTS; if (IDL_NODE_UP (IDL_NS (ns).current) != NULL) IDL_NS (ns).current = IDL_NODE_UP (IDL_NS (ns).current); }
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; }
IDL_tree IDL_ns_place_new (IDL_ns ns, IDL_tree ident) { IDL_tree p, up_save; gboolean does_conflict; IDL_NS_ASSERTS; p = IDL_ns_lookup_cur_scope (ns, ident, &does_conflict); if (p != NULL && does_conflict) return NULL; /* The namespace tree is separate from the primary parse tree, so keep the primary tree node's parent the same */ up_save = IDL_NODE_UP (ident); p = IDL_gentree_chain_child (IDL_NS (ns).current, ident); IDL_NODE_UP (ident) = up_save; if (p == NULL) return NULL; assert (IDL_NODE_TYPE (p) == IDLN_GENTREE); IDL_IDENT_TO_NS (ident) = p; assert (IDL_NODE_UP (IDL_IDENT_TO_NS (ident)) == IDL_NS (ns).current); /* Generate default repository ID */ IDL_IDENT_REPO_ID (ident) = IDL_ns_ident_make_repo_id (__IDL_root_ns, p, NULL, NULL, NULL); return p; }
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; }
void IDL_ns_free (IDL_ns ns) { assert (ns != NULL); g_hash_table_foreach (IDL_NS (ns).inhibits, (GHFunc)IDL_tree_free, NULL); g_hash_table_destroy (IDL_NS (ns).inhibits); g_hash_table_foreach (IDL_NS (ns).filename_hash, (GHFunc) filename_hash_free, NULL); g_hash_table_destroy (IDL_NS (ns).filename_hash); IDL_tree_free (IDL_NS (ns).global); g_free (ns); }
void orte_idl_attr_fake_ops(IDL_tree attr, IDL_ns ns) { IDL_tree attr_name, ident, curnode, op1, op2, intf; GString *attrname; OIDL_Attr_Info *setme; g_assert(attr && IDL_NODE_TYPE(attr) == IDLN_ATTR_DCL); attrname = g_string_new(NULL); for(curnode = IDL_ATTR_DCL(attr).simple_declarations; curnode; curnode = IDL_LIST(curnode).next) { op1 = op2 = NULL; attr_name = IDL_LIST(curnode).data; g_string_printf(attrname, "_get_%s", IDL_IDENT(attr_name).str); ident = IDL_ident_new(g_strdup(attrname->str)); IDL_IDENT_TO_NS(ident) = IDL_IDENT_TO_NS(attr_name); op1 = IDL_op_dcl_new(0, IDL_ATTR_DCL(attr).param_type_spec, ident, NULL, NULL, NULL); IDL_NODE_UP(op1) = IDL_NODE_UP(attr); intf = IDL_NODE_UP (IDL_NODE_UP (op1)); IDL_NS(ns).current = IDL_IDENT_TO_NS (IDL_INTERFACE (intf).ident); IDL_ns_place_new(ns, ident); if(!IDL_ATTR_DCL(attr).f_readonly) { g_string_printf(attrname, "_set_%s", IDL_IDENT(attr_name).str); ident = IDL_ident_new(g_strdup(attrname->str)); IDL_IDENT_TO_NS(ident) = IDL_IDENT_TO_NS(attr_name); op2 = IDL_op_dcl_new(0, NULL, ident, NULL, NULL, NULL); IDL_NODE_UP(op2) = IDL_NODE_UP(attr); intf = IDL_NODE_UP (IDL_NODE_UP (op2)); IDL_NS(ns).current = IDL_IDENT_TO_NS (IDL_INTERFACE (intf).ident); IDL_ns_place_new(ns, ident); IDL_OP_DCL(op2).parameter_dcls = IDL_list_new( IDL_param_dcl_new(IDL_PARAM_IN, IDL_ATTR_DCL(attr).param_type_spec, IDL_ident_new(g_strdup("value")))); } setme = g_new0(OIDL_Attr_Info, 1); setme->op1 = op1; setme->op2 = op2; attr_name->data = setme; } g_string_free(attrname, TRUE); }
IDL_ns IDL_ns_new (void) { IDL_ns ns; ns = g_new0 (struct _IDL_ns, 1); if (ns == NULL) { yyerror ("IDL_ns_new: memory exhausted"); return NULL; } IDL_NS (ns).global = IDL_gentree_new (IDL_ident_hash, IDL_ident_equal, IDL_ident_new ("")); IDL_NS (ns).file = IDL_NS (ns).current = IDL_NS (ns).global; IDL_NS (ns).inhibits = g_hash_table_new (g_direct_hash, g_direct_equal); IDL_NS (ns).filename_hash = g_hash_table_new (g_str_hash, g_str_equal); return ns; }
IDL_tree IDL_ns_lookup_cur_scope (IDL_ns ns, IDL_tree ident, gboolean *conflict) { return IDL_ns_lookup_this_scope (ns, IDL_NS (ns).current, ident, conflict); }
IDL_tree IDL_ns_resolve_ident (IDL_ns ns, IDL_tree ident) { return IDL_ns_resolve_this_scope_ident (ns, IDL_NS (ns).current, ident); }
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; }