static void MateCORBA_imodule_setup_label_any (CORBA_TypeCode tc, IDL_tree node, CORBA_any *label) { if (!node) { /* default case */ label->_type = TC_CORBA_octet; label->_value = MateCORBA_small_alloc (TC_CORBA_octet); *(CORBA_octet *) label->_value = -1; return; } label->_type = (CORBA_TypeCode) CORBA_Object_duplicate ( (CORBA_Object) tc, NULL); label->_value = MateCORBA_small_alloc (tc); switch (IDL_NODE_TYPE (node)) { case IDLN_BOOLEAN: case IDLN_CHAR: case IDLN_INTEGER: MateCORBA_imodule_jam_int (node, tc, label->_value); break; case IDLN_FLOAT: g_assert (tc->kind == CORBA_tk_float); *(CORBA_float *) label->_value = IDL_FLOAT (node).value; break; case IDLN_BINOP: /* drop through */ case IDLN_UNARYOP: { IDL_tree val; if (IDL_NODE_TYPE (node) == IDLN_BINOP) val = _IDL_binop_eval (IDL_BINOP (node).op, IDL_BINOP (node).left, IDL_BINOP (node).right); else val = _IDL_unaryop_eval (IDL_BINOP (node).op, IDL_UNARYOP (node).operand); MateCORBA_imodule_jam_int (val, tc, label->_value); IDL_tree_free (val); break; } case IDLN_IDENT: { CORBA_long val; g_assert (label->_type->kind == CORBA_tk_enum); for (val = 0; val < label->_type->sub_parts; val++) if (!strcmp (IDL_IDENT (node).str, label->_type->subnames [val])) break; g_assert (val < label->_type->sub_parts); *(CORBA_long *) label->_value = val; break; } default: g_assert_not_reached (); break; } }
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); }
static void cc_typecode_prep_sequence (IDL_tree tree, OIDL_C_Info *ci) { IDL_tree seq_type; IDL_tree fake_seq_type = NULL; char *type_str; char *seq_type_str; seq_type = orbit_cbe_get_typespec (IDL_TYPE_SEQUENCE (tree).simple_type_spec); if (IDL_NODE_TYPE (seq_type) != IDLN_INTERFACE) seq_type_str = orbit_cbe_get_typespec_str (seq_type); else { seq_type_str = g_strdup ("CORBA_Object"); fake_seq_type = IDL_type_object_new (); } type_str = orbit_cbe_get_typespec_str (IDL_TYPE_SEQUENCE (tree).simple_type_spec); if (strcmp (type_str, seq_type_str)) { IDL_tree fake_seq; fake_seq = IDL_type_sequence_new ( fake_seq_type ? fake_seq_type : seq_type, NULL); IDL_NODE_UP (fake_seq) = IDL_NODE_UP (tree); cc_output_typecodes (fake_seq, ci); IDL_TYPE_SEQUENCE (fake_seq).simple_type_spec = NULL; IDL_tree_free (fake_seq); } if (fake_seq_type) IDL_tree_free (fake_seq_type); g_free (type_str); g_free (seq_type_str); }
int xpidl_process_idl(char *filename, IncludePathEntry *include_path, char *file_basename, char* package, ModeData *mode) { char *tmp, *outname, *real_outname = NULL; IDL_tree top; TreeState state; int rv; input_callback_state callback_state; gboolean ok = TRUE; backend *emitter; memset(&state, 0, sizeof(state)); callback_state.input_stack = NULL; callback_state.base_includes = NULL; callback_state.include_path = include_path; callback_state.already_included = g_hash_table_new(g_str_hash, g_str_equal); if (!callback_state.already_included) { fprintf(stderr, "failed to create hashtable. out of memory?\n"); return 0; } state.basename = xpidl_strdup(filename); if (package) state.package = xpidl_strdup(package); /* if basename has an .extension, truncate it. */ tmp = strrchr(state.basename, '.'); if (tmp) *tmp = '\0'; if (!file_basename) outname = xpidl_strdup(state.basename); else outname = xpidl_strdup(file_basename); /* so we don't include it again! */ g_hash_table_insert(callback_state.already_included, xpidl_strdup(filename), (void *)TRUE); parsed_empty_file = FALSE; rv = IDL_parse_filename_with_input(filename, input_callback, &callback_state, msg_callback, &top, &state.ns, IDLF_IGNORE_FORWARDS | IDLF_XPIDL, enable_warnings ? IDL_WARNING1 : IDL_ERROR); if (parsed_empty_file) { /* * If we've detected (via hack in msg_callback) that libIDL returned * failure because it found a file with no IDL, set the parse tree to * null and proceed. Allowing this is useful to permit .idl files that * collect #includes. */ top = NULL; state.ns = NULL; } else if (rv != IDL_SUCCESS) { if (rv == -1) { g_warning("Parse of %s failed: %s", filename, g_strerror(errno)); } else { g_warning("Parse of %s failed", filename); } return 0; } state.basename = xpidl_strdup(filename); tmp = strrchr(state.basename, '.'); if (tmp) *tmp = '\0'; /* so xpidl_header.c can use it to generate a list of #include directives */ state.base_includes = callback_state.base_includes; emitter = mode->factory(); state.dispatch = emitter->dispatch_table; if (strcmp(outname, "-")) { const char *fopen_mode; const char *out_basename; /* explicit_output_filename can't be true without a filename */ if (explicit_output_filename) { real_outname = g_strdup(outname); } else { /* *This combination seems a little strange, what about OS/2? * Assume it's some build issue */ #if defined(XP_UNIX) || defined(XP_WIN) if (!file_basename) { out_basename = xpidl_basename(outname); } else { out_basename = outname; } #else out_basename = outname; #endif real_outname = g_strdup_printf("%s.%s", out_basename, mode->suffix); } /* don't create/open file here for Java */ if (strcmp(mode->mode, "java") == 0) { state.filename = real_outname; } else { /* Use binary write for typelib mode */ fopen_mode = (strcmp(mode->mode, "typelib")) ? "w" : "wb"; state.file = fopen(real_outname, fopen_mode); if (!state.file) { perror("error opening output file"); return 0; } } } else { state.file = stdout; } state.tree = top; if (emitter->emit_prolog) emitter->emit_prolog(&state); if (state.tree) /* Only if we have a tree to process. */ ok = xpidl_process_node(&state); if (emitter->emit_epilog) emitter->emit_epilog(&state); if (strcmp(mode->mode, "java") != 0) { if (state.file != stdout) fclose(state.file); } free(state.basename); free(state.package); free(outname); g_hash_table_foreach(callback_state.already_included, free_ghash_key, NULL); g_hash_table_destroy(callback_state.already_included); g_slist_foreach(callback_state.base_includes, free_gslist_data, NULL); if (state.ns) IDL_ns_free(state.ns); if (top) IDL_tree_free(top); if (real_outname != NULL) { /* * Delete partial output file on failure. (Mac does this in the plugin * driver code, if the compiler returns failure.) */ #if defined(XP_UNIX) || defined(XP_WIN) if (!ok) unlink(real_outname); #endif g_free(real_outname); } return ok; }
gchar *IDL_ns_ident_to_qstring (IDL_tree ns_ident, const char *join, int levels) { IDL_tree l, q; int len, joinlen; char *s; int count = 0, start_level; if (levels < 0 || levels > 64) return NULL; if (ns_ident == NULL) return NULL; if (IDL_NODE_TYPE (ns_ident) == IDLN_IDENT) ns_ident = IDL_IDENT_TO_NS (ns_ident); assert (IDL_NODE_TYPE (ns_ident) == IDLN_GENTREE); l = IDL_ns_qualified_ident_new (ns_ident); if (l == NULL) return NULL; if (join == NULL) join = ""; joinlen = strlen (join); for (len = 0, q = l; q != NULL; q = IDL_LIST (q).next) { IDL_tree i = IDL_LIST (q).data; assert (IDL_NODE_TYPE (q) == IDLN_LIST); assert (IDL_NODE_TYPE (i) == IDLN_IDENT); if (IDL_IDENT (i).str != NULL) len += strlen (IDL_IDENT (i).str) + joinlen; ++count; } if (levels == 0) start_level = 0; else start_level = count - levels; assert (start_level >= 0 && start_level < count); s = g_malloc (len + 1); if (s == NULL) { IDL_tree_free (l); return NULL; } s[0] = '\0'; for (q = l; q != NULL; q = IDL_LIST (q).next) { IDL_tree i = IDL_LIST (q).data; if (start_level > 0) { --start_level; continue; } if (s[0] != '\0') strcat (s, join); strcat (s, IDL_IDENT (i).str); } IDL_tree_free (l); return s; }