gboolean verify_const_declaration(IDL_tree const_tree) { struct _IDL_CONST_DCL *dcl = &IDL_CONST_DCL(const_tree); const char *name = IDL_IDENT(dcl->ident).str; IDL_tree real_type; /* const -> list -> interface */ if (!IDL_NODE_UP(IDL_NODE_UP(const_tree)) || IDL_NODE_TYPE(IDL_NODE_UP(IDL_NODE_UP(const_tree))) != IDLN_INTERFACE) { IDL_tree_error(const_tree, "const declaration \'%s\' outside interface", name); return FALSE; } /* Could be a typedef; try to map it to the real type. */ real_type = find_underlying_type(dcl->const_type); real_type = real_type ? real_type : dcl->const_type; if (IDL_NODE_TYPE(real_type) == IDLN_TYPE_INTEGER && (IDL_TYPE_INTEGER(real_type).f_type == IDL_INTEGER_TYPE_SHORT || IDL_TYPE_INTEGER(real_type).f_type == IDL_INTEGER_TYPE_LONG)) { if (!IDL_TYPE_INTEGER(real_type).f_signed && IDL_INTEGER(dcl->const_exp).value < 0) { #ifndef G_HAVE_GINT64 /* * For platforms without longlong support turned on we can get * confused by the high bit of the long value and think that it * represents a negative value in an unsigned declaration. * In that case we don't know if it is the programmer who is * confused or the compiler. So we issue a warning instead of * an error. */ if (IDL_TYPE_INTEGER(real_type).f_type == IDL_INTEGER_TYPE_LONG) { XPIDL_WARNING((const_tree, IDL_WARNING1, "unsigned const declaration \'%s\' " "initialized with (possibly) negative constant", name)); return TRUE; } #endif IDL_tree_error(const_tree, "unsigned const declaration \'%s\' initialized with " "negative constant", name); return FALSE; } } else { IDL_tree_error(const_tree, "const declaration \'%s\' must be of type short or long", name); return FALSE; } return TRUE; }
static void orbit_output_tcstruct_digits_scale (FILE *fh, IDL_tree node) { if (IDL_NODE_TYPE (node) == IDLN_TYPE_FIXED) { fprintf (fh, "%" IDL_LL "d, %" IDL_LL "d" , IDL_INTEGER (IDL_TYPE_FIXED (node).positive_int_const).value, IDL_INTEGER (IDL_TYPE_FIXED (node).integer_lit).value); } else fprintf (fh, "0, 0"); }
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 is_signed; GSList *doc_comments = IDL_IDENT(dcl->ident).comments; IDL_tree real_type; const char *const_format; if (!verify_const_declaration(state->tree)) return FALSE; if (doc_comments != NULL) { write_indent(state->file); printlist(state->file, doc_comments); } /* Could be a typedef; try to map it to the real type. */ real_type = find_underlying_type(dcl->const_type); real_type = real_type ? real_type : dcl->const_type; is_signed = IDL_TYPE_INTEGER(real_type).f_signed; const_format = is_signed ? "%" IDL_LL "d" : "%" IDL_LL "uU"; write_indent(state->file); fprintf(state->file, "enum { %s = ", name); fprintf(state->file, const_format, IDL_INTEGER(dcl->const_exp).value); fprintf(state->file, " };\n\n"); return TRUE; }
static gboolean do_typedef(TreeState *state) { IDL_tree type = IDL_TYPE_DCL(state->tree).type_spec; IDL_tree dcls = IDL_TYPE_DCL(state->tree).dcls; IDL_tree complex; GSList *doc_comments; if (IDL_NODE_TYPE(type) == IDLN_TYPE_SEQUENCE) { XPIDL_WARNING((state->tree, IDL_WARNING1, "sequences not supported, ignored")); } else { if (IDL_NODE_TYPE(complex = IDL_LIST(dcls).data) == IDLN_TYPE_ARRAY) { IDL_tree dim = IDL_TYPE_ARRAY(complex).size_list; doc_comments = IDL_IDENT(IDL_TYPE_ARRAY(complex).ident).comments; if (doc_comments != NULL) printlist(state->file, doc_comments); fputs("typedef ", state->file); if (!write_type(type, FALSE, state->file)) return FALSE; fputs(" ", state->file); fprintf(state->file, "%s", IDL_IDENT(IDL_TYPE_ARRAY(complex).ident).str); do { fputc('[', state->file); if (IDL_LIST(dim).data) { fprintf(state->file, "%ld", (long)IDL_INTEGER(IDL_LIST(dim).data).value); } fputc(']', state->file); } while ((dim = IDL_LIST(dim).next) != NULL); } else { doc_comments = IDL_IDENT(IDL_LIST(dcls).data).comments; if (doc_comments != NULL) printlist(state->file, doc_comments); fputs("typedef ", state->file); if (!write_type(type, FALSE, state->file)) return FALSE; fputs(" ", state->file); fputs(IDL_IDENT(IDL_LIST(dcls).data).str, state->file); } fputs(";\n\n", state->file); } return TRUE; }
static void orbit_output_tcstruct_length (FILE *fh, IDL_tree node, int array_gen_ctr) { int length = 0; switch (IDL_NODE_TYPE (node)) { case IDLN_TYPE_SEQUENCE: if (IDL_TYPE_SEQUENCE (node).positive_int_const) length = IDL_INTEGER (IDL_TYPE_SEQUENCE (node).positive_int_const).value; break; case IDLN_TYPE_STRING: if (IDL_TYPE_STRING (node).positive_int_const) length = IDL_INTEGER (IDL_TYPE_STRING (node).positive_int_const).value; break; case IDLN_TYPE_WIDE_STRING: if (IDL_TYPE_WIDE_STRING (node).positive_int_const) length = IDL_INTEGER (IDL_TYPE_STRING (node).positive_int_const).value; break; case IDLN_TYPE_ARRAY: if (array_gen_ctr) { IDL_tree sizer; sizer = IDL_list_nth (IDL_TYPE_ARRAY (node).size_list, array_gen_ctr - 1); g_assert (IDL_NODE_TYPE (IDL_LIST (sizer).data) == IDLN_INTEGER); length = IDL_INTEGER (IDL_LIST (sizer).data).value; } break; default: length = 0; break; } fprintf (fh, "%d", length); }
static gboolean typelib_const_dcl(TreeState *state) { struct _IDL_CONST_DCL *dcl = &IDL_CONST_DCL(state->tree); const char *name = IDL_IDENT(dcl->ident).str; gboolean is_long; gboolean sign; IDL_tree real_type; XPTInterfaceDescriptor *id; XPTConstDescriptor *cd; IDL_longlong_t value; if (!verify_const_declaration(state->tree)) return FALSE; /* Could be a typedef; try to map it to the real type. */ real_type = find_underlying_type(dcl->const_type); real_type = real_type ? real_type : dcl->const_type; is_long = (IDL_TYPE_INTEGER(real_type).f_type == IDL_INTEGER_TYPE_LONG); id = CURRENT(state); if (!XPT_InterfaceDescriptorAddConsts(ARENA(state), id, 1)) return FALSE; cd = &id->const_descriptors[NEXT_CONST(state)]; cd->name = IDL_IDENT(dcl->ident).str; #ifdef DEBUG_shaver_const fprintf(stderr, "DBG: adding const %s\n", cd->name); #endif if (!fill_td_from_type(state, &cd->type, dcl->const_type)) return FALSE; value = IDL_INTEGER(dcl->const_exp).value; sign = IDL_TYPE_INTEGER(dcl->const_type).f_signed; if (is_long) { if (sign) cd->value.i32 = value; else cd->value.ui32 = value; } else { if (sign) cd->value.i16 = value; else cd->value.ui16 = value; } NEXT_CONST(state)++; return TRUE; }
static void MateCORBA_imodule_jam_int (IDL_tree src, CORBA_TypeCode tc, gpointer dest) { CORBA_long val = 0; switch (IDL_NODE_TYPE (src)) { case IDLN_BOOLEAN: val = IDL_BOOLEAN (src).value ? 1 : 0; break; case IDLN_CHAR: val = IDL_CHAR (src).value [0]; break; case IDLN_INTEGER: val = IDL_INTEGER (src).value; break; default: g_assert_not_reached (); break; } switch (tc->kind) { case CORBA_tk_boolean: case CORBA_tk_char: case CORBA_tk_octet: *(CORBA_boolean *) dest = val; break; case CORBA_tk_short: case CORBA_tk_ushort: *(CORBA_short *) dest = val; break; case CORBA_tk_long: case CORBA_tk_ulong: *(CORBA_long *) dest = val; break; default: g_assert_not_reached (); break; } }
void orte_idl_print_node(IDL_tree node, int indent_level) { IDL_tree curnode; char *s; do_indent(indent_level); if(node == NULL) { g_print("(null)\n"); return; } g_print("[%d] ", IDL_NODE_REFS(node)); switch(IDL_NODE_TYPE(node)) { case IDLN_NONE: g_print("NONE\n"); break; case IDLN_LIST: g_print("LIST:\n"); for(curnode = node; curnode; curnode = IDL_LIST(curnode).next) { orte_idl_print_node(IDL_LIST(curnode).data, indent_level + INDENT_INCREMENT_1); } break; case IDLN_GENTREE: break; case IDLN_INTEGER: g_print("INTEGER: %" IDL_LL "d\n", IDL_INTEGER(node).value); break; case IDLN_STRING: g_print("STRING: %s\n", IDL_STRING(node).value); break; case IDLN_WIDE_STRING: g_print("WIDE STRING: %ls\n", IDL_WIDE_STRING(node).value); break; case IDLN_CHAR: g_print("CHAR: %s\n", IDL_CHAR(node).value); break; case IDLN_WIDE_CHAR: g_print("WIDE CHAR: %ls\n", IDL_WIDE_CHAR(node).value); break; case IDLN_FIXED: g_print("FIXED: %s\n", IDL_FIXED(node).value); break; case IDLN_FLOAT: g_print("FLOAT: %f\n", IDL_FLOAT(node).value); break; case IDLN_BOOLEAN: g_print("BOOLEAN: %s\n", (IDL_BOOLEAN(node).value)?"True":"False"); break; case IDLN_IDENT: s = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(node), "_", 0); g_print("IDENT: %s NSQ: %s RID: \"%s\"\n", IDL_IDENT(node).str, s, IDL_IDENT_REPO_ID(node) ? IDL_IDENT_REPO_ID(node) : ""); g_free(s); break; case IDLN_TYPE_DCL: g_print("TYPE DCL:\n"); orte_idl_print_node(IDL_TYPE_DCL(node).type_spec, indent_level + INDENT_INCREMENT_1); do_indent(indent_level + INDENT_INCREMENT_1); g_print("decls:\n"); orte_idl_print_node(IDL_TYPE_DCL(node).dcls, indent_level + INDENT_INCREMENT_2); break; case IDLN_CONST_DCL: g_print("CONST DCL:\n"); orte_idl_print_node(IDL_CONST_DCL(node).const_type, indent_level + INDENT_INCREMENT_1); do_indent(indent_level + INDENT_INCREMENT_1); g_print("ident:\n"); orte_idl_print_node(IDL_CONST_DCL(node).ident, indent_level + INDENT_INCREMENT_2); do_indent(indent_level + INDENT_INCREMENT_1); g_print("const_exp:\n"); orte_idl_print_node(IDL_CONST_DCL(node).const_exp, indent_level + INDENT_INCREMENT_2); break; case IDLN_EXCEPT_DCL: g_print("EXCEPT DCL:\n"); orte_idl_print_node(IDL_EXCEPT_DCL(node).ident, indent_level + INDENT_INCREMENT_1); do_indent(indent_level + INDENT_INCREMENT_1); g_print("members:\n"); orte_idl_print_node(IDL_EXCEPT_DCL(node).members, indent_level + INDENT_INCREMENT_2); break; case IDLN_ATTR_DCL: g_print("ATTR_DCL (%s):\n", (IDL_ATTR_DCL(node).f_readonly)?"readonly":"rw"); orte_idl_print_node(IDL_ATTR_DCL(node).param_type_spec, indent_level + INDENT_INCREMENT_1); do_indent(indent_level + INDENT_INCREMENT_1); g_print("simple_declarations:\n"); orte_idl_print_node(IDL_ATTR_DCL(node).simple_declarations, indent_level + INDENT_INCREMENT_2); break; case IDLN_OP_DCL: g_print("OP DCL (%s):\n", (IDL_OP_DCL(node).f_oneway)?"oneway":"normal"); orte_idl_print_node(IDL_OP_DCL(node).ident, indent_level + INDENT_INCREMENT_1); do_indent(indent_level + INDENT_INCREMENT_1); g_print("op_type_spec:\n"); orte_idl_print_node(IDL_OP_DCL(node).op_type_spec, indent_level + INDENT_INCREMENT_2); do_indent(indent_level + INDENT_INCREMENT_1); g_print("parameter_dcls:\n"); orte_idl_print_node(IDL_OP_DCL(node).parameter_dcls, indent_level + INDENT_INCREMENT_2); do_indent(indent_level + INDENT_INCREMENT_1); g_print("raises_expr:\n"); orte_idl_print_node(IDL_OP_DCL(node).raises_expr, indent_level + INDENT_INCREMENT_2); do_indent(indent_level + INDENT_INCREMENT_1); g_print("context_expr:\n"); orte_idl_print_node(IDL_OP_DCL(node).context_expr, indent_level + INDENT_INCREMENT_2); break; case IDLN_PARAM_DCL: g_print("PARAM DCL: "); switch(IDL_PARAM_DCL(node).attr) { case IDL_PARAM_IN: g_print("(in)\n"); break; case IDL_PARAM_OUT: g_print("(out)\n"); break; case IDL_PARAM_INOUT: g_print("(inout)\n"); break; } orte_idl_print_node(IDL_PARAM_DCL(node).param_type_spec, indent_level + INDENT_INCREMENT_1); do_indent(indent_level + INDENT_INCREMENT_1); g_print("simple_declarator:\n"); orte_idl_print_node(IDL_PARAM_DCL(node).simple_declarator, indent_level + INDENT_INCREMENT_2); break; case IDLN_FORWARD_DCL: g_print("FORWARD DCL:\n"); orte_idl_print_node(IDL_FORWARD_DCL(node).ident, indent_level + INDENT_INCREMENT_1); break; case IDLN_INTERFACE: g_print("INTERFACE:\n"); orte_idl_print_node(IDL_INTERFACE(node).ident, indent_level + INDENT_INCREMENT_1); do_indent(indent_level + INDENT_INCREMENT_1); g_print("inheritance_spec:\n"); orte_idl_print_node(IDL_INTERFACE(node).inheritance_spec, indent_level + INDENT_INCREMENT_2); do_indent(indent_level + INDENT_INCREMENT_1); g_print("body:\n"); orte_idl_print_node(IDL_INTERFACE(node).body, indent_level + INDENT_INCREMENT_2); break; case IDLN_MODULE: g_print("MODULE:\n"); orte_idl_print_node(IDL_MODULE(node).ident, indent_level + INDENT_INCREMENT_1); do_indent(indent_level + INDENT_INCREMENT_1); g_print("definition_list:\n"); orte_idl_print_node(IDL_MODULE(node).definition_list, indent_level + INDENT_INCREMENT_2); break; case IDLN_TYPE_INTEGER: if(!IDL_TYPE_INTEGER(node).f_signed) g_print("TYPE unsigned "); switch(IDL_TYPE_INTEGER(node).f_type) { case IDL_INTEGER_TYPE_SHORT: g_print("short\n"); break; case IDL_INTEGER_TYPE_LONG: g_print("long\n"); break; case IDL_INTEGER_TYPE_LONGLONG: g_print("long long\n"); break; } break; case IDLN_TYPE_FLOAT: switch(IDL_TYPE_FLOAT(node).f_type) { case IDL_FLOAT_TYPE_FLOAT: g_print("TYPE float\n"); break; case IDL_FLOAT_TYPE_DOUBLE: g_print("TYPE double\n"); break; case IDL_FLOAT_TYPE_LONGDOUBLE: g_print("TYPE long double\n"); break; } break; case IDLN_TYPE_FIXED: g_print("TYPE fixed:\n"); orte_idl_print_node(IDL_TYPE_FIXED(node).positive_int_const, indent_level + INDENT_INCREMENT_1); orte_idl_print_node(IDL_TYPE_FIXED(node).integer_lit, indent_level + INDENT_INCREMENT_1); break; case IDLN_TYPE_STRING: g_print("TYPE string:\n"); orte_idl_print_node(IDL_TYPE_STRING(node).positive_int_const, indent_level + INDENT_INCREMENT_1); break; case IDLN_TYPE_WIDE_STRING: g_print("TYPE wide string:\n"); orte_idl_print_node(IDL_TYPE_WIDE_STRING(node).positive_int_const, indent_level + INDENT_INCREMENT_1); break; case IDLN_TYPE_ENUM: g_print("TYPE enum:\n"); orte_idl_print_node(IDL_TYPE_ENUM(node).ident, indent_level + INDENT_INCREMENT_1); do_indent(indent_level + INDENT_INCREMENT_1); g_print("enumerator_list:\n"); orte_idl_print_node(IDL_TYPE_ENUM(node).enumerator_list, indent_level + INDENT_INCREMENT_2); break; case IDLN_TYPE_ARRAY: g_print("TYPE array:\n"); orte_idl_print_node(IDL_TYPE_ARRAY(node).ident, indent_level + INDENT_INCREMENT_1); do_indent(indent_level + INDENT_INCREMENT_1); g_print("size_list:\n"); orte_idl_print_node(IDL_TYPE_ARRAY(node).size_list, indent_level + INDENT_INCREMENT_2); break; case IDLN_TYPE_SEQUENCE: g_print("TYPE sequence:\n"); orte_idl_print_node(IDL_TYPE_SEQUENCE(node).simple_type_spec, indent_level + INDENT_INCREMENT_1); do_indent(indent_level + INDENT_INCREMENT_1); g_print("positive_int_const:\n"); orte_idl_print_node(IDL_TYPE_SEQUENCE(node).positive_int_const, indent_level + INDENT_INCREMENT_2); break; case IDLN_TYPE_STRUCT: g_print("TYPE struct:\n"); orte_idl_print_node(IDL_TYPE_STRUCT(node).ident, indent_level + INDENT_INCREMENT_1); do_indent(indent_level + INDENT_INCREMENT_1); g_print("member_list:\n"); orte_idl_print_node(IDL_TYPE_STRUCT(node).member_list, indent_level + INDENT_INCREMENT_2); break; case IDLN_TYPE_UNION: g_print("TYPE union:\n"); orte_idl_print_node(IDL_TYPE_UNION(node).ident, indent_level + INDENT_INCREMENT_1); do_indent(indent_level + INDENT_INCREMENT_1); g_print("switch_type_spec:\n"); orte_idl_print_node(IDL_TYPE_UNION(node).switch_type_spec, indent_level + INDENT_INCREMENT_2); do_indent(indent_level + INDENT_INCREMENT_1); g_print("switch_body:\n"); orte_idl_print_node(IDL_TYPE_UNION(node).switch_body, indent_level + INDENT_INCREMENT_2); break; case IDLN_MEMBER: g_print("MEMBER:\n"); orte_idl_print_node(IDL_MEMBER(node).type_spec, indent_level + INDENT_INCREMENT_1); do_indent(indent_level + INDENT_INCREMENT_1); g_print("dcls:\n"); orte_idl_print_node(IDL_MEMBER(node).dcls, indent_level + INDENT_INCREMENT_2); break; case IDLN_CASE_STMT: g_print("CASE_STMT:\n"); orte_idl_print_node(IDL_CASE_STMT(node).labels, indent_level + INDENT_INCREMENT_1); do_indent(indent_level + INDENT_INCREMENT_1); g_print("element_spec:\n"); orte_idl_print_node(IDL_CASE_STMT(node).element_spec, indent_level + INDENT_INCREMENT_2); break; case IDLN_BINOP: g_print("BINOP "); switch(IDL_BINOP(node).op) { case IDL_BINOP_OR: g_print("or:\n"); break; case IDL_BINOP_XOR: g_print("xor:\n"); break; case IDL_BINOP_AND: g_print("and:\n"); break; case IDL_BINOP_SHR: g_print("shr:\n"); break; case IDL_BINOP_SHL: g_print("shl:\n"); break; case IDL_BINOP_ADD: g_print("add:\n"); break; case IDL_BINOP_SUB: g_print("sub:\n"); break; case IDL_BINOP_MULT: g_print("mult:\n"); break; case IDL_BINOP_DIV: g_print("div:\n"); break; case IDL_BINOP_MOD: g_print("mod:\n"); break; } do_indent(indent_level + INDENT_INCREMENT_1); g_print("left:\n"); orte_idl_print_node(IDL_BINOP(node).left, indent_level + INDENT_INCREMENT_2); do_indent(indent_level + INDENT_INCREMENT_1); g_print("right:\n"); orte_idl_print_node(IDL_BINOP(node).right, indent_level + INDENT_INCREMENT_2); break; case IDLN_UNARYOP: g_print("UNARYOP "); switch(IDL_UNARYOP(node).op) { case IDL_UNARYOP_PLUS: g_print("plus:\n"); break; case IDL_UNARYOP_MINUS: g_print("minus:\n"); break; case IDL_UNARYOP_COMPLEMENT: g_print("complement:\n"); break; } orte_idl_print_node(IDL_UNARYOP(node).operand, indent_level + INDENT_INCREMENT_1); break; case IDLN_TYPE_CHAR: g_print("TYPE char\n"); break; case IDLN_TYPE_WIDE_CHAR: g_print("TYPE wide char\n"); break; case IDLN_TYPE_BOOLEAN: g_print("TYPE boolean\n"); break; case IDLN_TYPE_OCTET: g_print("TYPE octet\n"); break; case IDLN_TYPE_OBJECT: g_print("TYPE object\n"); break; case IDLN_TYPE_ANY: g_print("TYPE any\n"); break; case IDLN_TYPE_TYPECODE: g_print("TYPE TypeCode\n"); break; case IDLN_CODEFRAG: g_print("CODEFRAG\n"); break; default: g_print("unhandled %d\n", IDL_NODE_TYPE(node)); } }
CORBA_TypeCode MateCORBA_imodule_get_typecode (GHashTable *typecodes, IDL_tree tree) { CORBA_Environment env; CORBA_TypeCode retval = CORBA_OBJECT_NIL; if (!tree) return CORBA_OBJECT_NIL; CORBA_exception_init (&env); switch (IDL_NODE_TYPE (tree)) { case IDLN_MEMBER: retval = MateCORBA_imodule_get_typecode ( typecodes, IDL_MEMBER (tree).type_spec); break; case IDLN_TYPE_ANY: retval = (CORBA_TypeCode) CORBA_Object_duplicate ( (CORBA_Object) TC_CORBA_any, NULL); break; case IDLN_TYPE_FLOAT: switch (IDL_TYPE_FLOAT (tree).f_type) { case IDL_FLOAT_TYPE_FLOAT: retval = TC_CORBA_float; break; case IDL_FLOAT_TYPE_DOUBLE: retval = TC_CORBA_double; break; case IDL_FLOAT_TYPE_LONGDOUBLE: retval = TC_CORBA_long_double; break; } break; case IDLN_TYPE_FIXED: retval = CORBA_ORB_create_fixed_tc (NULL, IDL_INTEGER (IDL_TYPE_FIXED (tree).positive_int_const).value, IDL_INTEGER (IDL_TYPE_FIXED (tree).integer_lit).value, &env); break; case IDLN_TYPE_INTEGER: if (!IDL_TYPE_INTEGER (tree).f_signed) switch (IDL_TYPE_INTEGER (tree).f_type) { case IDL_INTEGER_TYPE_SHORT: retval = TC_CORBA_unsigned_short; break; case IDL_INTEGER_TYPE_LONGLONG: retval = TC_CORBA_unsigned_long_long; break; case IDL_INTEGER_TYPE_LONG: retval = TC_CORBA_unsigned_long; break; default: g_assert_not_reached (); } else switch (IDL_TYPE_INTEGER (tree).f_type) { case IDL_INTEGER_TYPE_SHORT: retval = TC_CORBA_short; break; case IDL_INTEGER_TYPE_LONGLONG: retval = TC_CORBA_long_long; break; case IDL_INTEGER_TYPE_LONG: retval = TC_CORBA_long; break; default: g_assert_not_reached (); } break; case IDLN_TYPE_STRING: retval = (CORBA_TypeCode) CORBA_Object_duplicate ( (CORBA_Object) TC_CORBA_string, NULL); break; case IDLN_TYPE_WIDE_STRING: retval = (CORBA_TypeCode) CORBA_Object_duplicate ( (CORBA_Object) TC_CORBA_wstring, NULL); break; case IDLN_TYPE_OCTET: retval = (CORBA_TypeCode) CORBA_Object_duplicate ( (CORBA_Object) TC_CORBA_octet, NULL); break; case IDLN_TYPE_CHAR: retval = (CORBA_TypeCode) CORBA_Object_duplicate ( (CORBA_Object) TC_CORBA_char, NULL); break; case IDLN_TYPE_WIDE_CHAR: retval = (CORBA_TypeCode) CORBA_Object_duplicate ( (CORBA_Object) TC_CORBA_wchar, NULL); break; case IDLN_TYPE_BOOLEAN: retval = (CORBA_TypeCode) CORBA_Object_duplicate ( (CORBA_Object) TC_CORBA_boolean, NULL); break; case IDLN_TYPE_STRUCT: retval = MateCORBA_imodule_lookup_typecode ( typecodes, IDL_IDENT (IDL_TYPE_STRUCT (tree).ident).repo_id); if (!retval) { CORBA_StructMemberSeq *members; members = MateCORBA_imodule_get_struct_members ( typecodes, tree, &env); retval = CORBA_ORB_create_struct_tc (NULL, IDL_IDENT (IDL_TYPE_STRUCT (tree).ident).repo_id, IDL_IDENT (IDL_TYPE_STRUCT (tree).ident).str, members, &env); MateCORBA_imodule_register_typecode ( typecodes, IDL_IDENT (IDL_TYPE_STRUCT (tree).ident).repo_id, retval); CORBA_free (members); } break; case IDLN_EXCEPT_DCL: retval = MateCORBA_imodule_lookup_typecode ( typecodes, IDL_IDENT (IDL_EXCEPT_DCL (tree).ident).repo_id); if (!retval) { CORBA_StructMemberSeq *members; members = MateCORBA_imodule_get_struct_members ( typecodes, tree, &env); retval = CORBA_ORB_create_exception_tc (NULL, IDL_IDENT (IDL_EXCEPT_DCL (tree).ident).repo_id, IDL_IDENT (IDL_EXCEPT_DCL (tree).ident).str, members, &env); MateCORBA_imodule_register_typecode ( typecodes, IDL_IDENT (IDL_EXCEPT_DCL (tree).ident).repo_id, retval); CORBA_free (members); } break; case IDLN_TYPE_ARRAY: { CORBA_TypeCode subtc; IDL_tree sizer; IDL_tree type_dcl; sizer = IDL_list_nth (IDL_TYPE_ARRAY (tree).size_list, IDL_list_length (IDL_TYPE_ARRAY (tree).size_list) - 1); g_assert (IDL_NODE_TYPE (IDL_LIST (sizer).data) == IDLN_INTEGER); type_dcl = IDL_NODE_UP (IDL_NODE_UP (tree)); g_assert (IDL_NODE_TYPE (type_dcl) == IDLN_TYPE_DCL); subtc = MateCORBA_imodule_get_typecode ( typecodes, IDL_TYPE_DCL (type_dcl).type_spec), retval = CORBA_ORB_create_array_tc (NULL, IDL_INTEGER (IDL_LIST (sizer).data).value, subtc, &env); retval->c_align = subtc->c_align; CORBA_Object_release ((CORBA_Object) subtc, NULL); for (sizer = IDL_LIST (sizer).prev; sizer; sizer = IDL_LIST (sizer).prev) { subtc = retval; retval = CORBA_ORB_create_array_tc (NULL, IDL_INTEGER (IDL_LIST (sizer).data).value, subtc, &env); retval->c_align = subtc->c_align; CORBA_Object_release ((CORBA_Object) subtc, NULL); } subtc = retval; retval = MateCORBA_imodule_create_alias_typecode ( typecodes, IDL_TYPE_ARRAY (tree).ident, subtc); CORBA_Object_release ((CORBA_Object) subtc, NULL); } break; case IDLN_TYPE_UNION: retval = MateCORBA_imodule_lookup_typecode ( typecodes, IDL_IDENT (IDL_TYPE_UNION (tree).ident).repo_id); if (!retval) { CORBA_UnionMemberSeq *members; CORBA_TypeCode switchtc; switchtc = MateCORBA_imodule_get_typecode ( typecodes, IDL_TYPE_UNION (tree).switch_type_spec); members = MateCORBA_imodule_get_union_members ( typecodes, tree, switchtc, &env); retval = CORBA_ORB_create_union_tc (NULL, IDL_IDENT (IDL_TYPE_UNION (tree).ident).repo_id, IDL_IDENT (IDL_TYPE_UNION (tree).ident).str, switchtc, members, &env); CORBA_Object_release ((CORBA_Object) switchtc, NULL); MateCORBA_imodule_register_typecode ( typecodes, IDL_IDENT (IDL_TYPE_UNION (tree).ident).repo_id, retval); CORBA_free (members); } break; case IDLN_TYPE_ENUM: retval = MateCORBA_imodule_lookup_typecode ( typecodes, IDL_IDENT (IDL_TYPE_ENUM (tree).ident).repo_id); if (!retval) { CORBA_EnumMemberSeq *members; members = MateCORBA_imodule_get_enum_members (tree, &env); retval = CORBA_ORB_create_enum_tc (NULL, IDL_IDENT (IDL_TYPE_ENUM (tree).ident).repo_id, IDL_IDENT (IDL_TYPE_ENUM (tree).ident).str, members, &env); MateCORBA_imodule_register_typecode ( typecodes, IDL_IDENT (IDL_TYPE_ENUM (tree).ident).repo_id, retval); CORBA_free (members); } break; case IDLN_IDENT: retval = MateCORBA_imodule_lookup_typecode ( typecodes, IDL_IDENT (tree).repo_id); g_assert (retval != NULL); break; case IDLN_TYPE_SEQUENCE: { CORBA_TypeCode subtc; int bound = 0; if (IDL_TYPE_SEQUENCE (tree).positive_int_const) bound = IDL_INTEGER (IDL_TYPE_SEQUENCE (tree).positive_int_const).value; subtc = MateCORBA_imodule_get_typecode ( typecodes, IDL_TYPE_SEQUENCE (tree).simple_type_spec), retval = CORBA_ORB_create_sequence_tc (NULL, bound, subtc, &env); CORBA_Object_release ((CORBA_Object) subtc, NULL); /* * FIXME: and what about recursive sequences? */ } break; case IDLN_FORWARD_DCL: case IDLN_INTERFACE: retval = MateCORBA_imodule_lookup_typecode ( typecodes, IDL_IDENT (IDL_TYPE_ENUM (tree).ident).repo_id); if (!retval) { retval = CORBA_ORB_create_interface_tc (NULL, IDL_IDENT (IDL_TYPE_ENUM (tree).ident).repo_id, IDL_IDENT (IDL_TYPE_ENUM (tree).ident).str, &env); MateCORBA_imodule_register_typecode ( typecodes, IDL_IDENT (IDL_TYPE_ENUM (tree).ident).repo_id, retval); } break; case IDLN_TYPE_OBJECT: retval = (CORBA_TypeCode) CORBA_Object_duplicate ( (CORBA_Object) TC_CORBA_Object, NULL); break; case IDLN_TYPE_TYPECODE: retval = (CORBA_TypeCode) CORBA_Object_duplicate ( (CORBA_Object) TC_CORBA_TypeCode, NULL); break; default: g_error ("We were asked to get a typecode for a %s", IDL_tree_type_names [IDL_NODE_TYPE (tree)]); break; } if (retval && retval->c_align == 0) retval->c_align = MateCORBA_imodule_find_c_align (tree); if (env._major != CORBA_NO_EXCEPTION) g_warning ("MateCORBA_imodule_get_typecode: exception %s", env._id); CORBA_exception_free (&env); return retval; }
static gboolean constant_declaration(TreeState *state) { /* * The C++ header XPIDL module only allows for shorts and longs (ints) * to be constants, so we will follow the same convention */ struct _IDL_CONST_DCL *declaration = &IDL_CONST_DCL(state->tree); const char *name = IDL_IDENT(declaration->ident).str; IDL_tree real_type; gboolean success; gboolean isshort = FALSE; if (!verify_const_declaration(state->tree)) return FALSE; /* Could be a typedef; try to map it to the real type. */ real_type = find_underlying_type(declaration->const_type); real_type = real_type ? real_type : declaration->const_type; /* * Consts must be in an interface */ if (!IDL_NODE_UP(IDL_NODE_UP(state->tree)) || IDL_NODE_TYPE(IDL_NODE_UP(IDL_NODE_UP(state->tree))) != IDLN_INTERFACE) { XPIDL_WARNING((state->tree, IDL_WARNING1, "A constant \"%s\" was declared outside an interface." " It was ignored.", name)); return TRUE; } /* * Make sure this is a numeric short or long constant. */ success = (IDLN_TYPE_INTEGER == IDL_NODE_TYPE(real_type)); if (success) { /* * We aren't successful yet, we know it's an integer, but what *kind* * of integer? */ switch(IDL_TYPE_INTEGER(real_type).f_type) { case IDL_INTEGER_TYPE_SHORT: /* * We're OK */ isshort = TRUE; break; case IDL_INTEGER_TYPE_LONG: /* * We're OK */ break; default: /* * Whoops, it's some other kind of number */ success = FALSE; } } else { IDL_tree_error(state->tree, "const declaration \'%s\' must be of type short or long", name); return FALSE; } /* if (doc_comments != NULL) { fputs(" ", state->file); printlist(state->file, doc_comments); } */ if (success) { /* Since Java does not have any concept of 'unsigned short', we need * to check that the value is in the proper range. If not, promote * it to an 'int'. */ int value = (int) IDL_INTEGER(declaration->const_exp).value; if (isshort && (value < -32768 || value > 32767)) isshort = FALSE; fputc('\n', state->file); xpidl_write_comment(state, 4); /* write_comment(state); */ fprintf(state->file, " public static final %s %s = %d;\n", (isshort ? "short" : "int"), subscriptIdentifier(state, (char*) name), (int) IDL_INTEGER(declaration->const_exp).value); } else { XPIDL_WARNING((state->tree, IDL_WARNING1, "A constant \"%s\" was not of type short or long." " It was ignored.", name)); } return TRUE; }
/** Gets the "type" of {tree} as known in C. The return value was alloc'd via g_malloc, and must be g_free'd. **/ gulong orbit_cbe_get_typespec_size(IDL_tree tree) { gulong retval=0; if(!tree) { return 0; } switch(IDL_NODE_TYPE(tree)) { #if 0 case IDLN_MEMBER: return orbit_cbe_get_typespec_str(IDL_MEMBER(tree).type_spec); break; case IDLN_TYPE_ANY: retval = sizeof(CORBA_any); break; #endif case IDLN_TYPE_FLOAT: switch(IDL_TYPE_FLOAT(tree).f_type) { case IDL_FLOAT_TYPE_FLOAT: retval = sizeof(CORBA_float); break; case IDL_FLOAT_TYPE_DOUBLE: retval = sizeof(CORBA_double); break; case IDL_FLOAT_TYPE_LONGDOUBLE: retval = sizeof(CORBA_long_double); break; } break; #if 0 case IDLN_TYPE_FIXED: return g_strdup_printf( "CORBA_fixed_%" IDL_LL "d_%" IDL_LL "d", IDL_INTEGER(IDL_TYPE_FIXED(tree).positive_int_const).value, IDL_INTEGER(IDL_TYPE_FIXED(tree).integer_lit).value); break; #endif case IDLN_TYPE_INTEGER: if(!IDL_TYPE_INTEGER(tree).f_signed) { /* unsigned types */ switch(IDL_TYPE_INTEGER(tree).f_type) { case IDL_INTEGER_TYPE_SHORT: retval=sizeof(CORBA_unsigned_short); break; case IDL_INTEGER_TYPE_LONGLONG: retval=sizeof(CORBA_unsigned_long_long); break; case IDL_INTEGER_TYPE_LONG: retval=sizeof(CORBA_unsigned_long); break; } } else{ switch(IDL_TYPE_INTEGER(tree).f_type) { /* signed types */ case IDL_INTEGER_TYPE_SHORT: retval=sizeof(CORBA_short); break; case IDL_INTEGER_TYPE_LONGLONG: retval=sizeof(CORBA_long_long); break; case IDL_INTEGER_TYPE_LONG: retval=sizeof(CORBA_long); break; } } break; case IDLN_TYPE_OCTET: retval = sizeof(CORBA_octet); break; case IDLN_TYPE_STRING: retval = sizeof(CORBA_string); /* this is non-standard! */ break; case IDLN_TYPE_BOOLEAN: retval = sizeof(CORBA_boolean); break; case IDLN_TYPE_CHAR: retval = sizeof(CORBA_char); break; case IDLN_TYPE_OBJECT: retval = sizeof(CORBA_Object); break; case IDLN_NATIVE: retval = sizeof(gpointer); break; #if 0 case IDLN_TYPE_WIDE_STRING: retval = "CORBA_wstring"; /* this is non-standard! */ break; case IDLN_TYPE_WIDE_CHAR: retval = "CORBA_wchar"; break; case IDLN_TYPE_STRUCT: return orbit_cbe_get_typespec_str(IDL_TYPE_STRUCT(tree).ident); case IDLN_EXCEPT_DCL: return orbit_cbe_get_typespec_str(IDL_EXCEPT_DCL(tree).ident); case IDLN_TYPE_ARRAY: return orbit_cbe_get_typespec_str(IDL_TYPE_ARRAY(tree).ident); case IDLN_TYPE_UNION: return orbit_cbe_get_typespec_str(IDL_TYPE_UNION(tree).ident); case IDLN_TYPE_ENUM: return orbit_cbe_get_typespec_str(IDL_TYPE_ENUM(tree).ident); case IDLN_IDENT: return IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(tree), "_", 0); case IDLN_PARAM_DCL: return orbit_cbe_get_typespec_str(IDL_PARAM_DCL(tree).param_type_spec); case IDLN_TYPE_SEQUENCE: { IDL_tree subtype = IDL_TYPE_SEQUENCE(tree).simple_type_spec; char *ctmp, *base; ctmp = orbit_cbe_get_typespec_str(subtype); /* We should have built-in alias to make this next line not needed */ base = orbit_cbe_type_is_builtin(subtype) ? ctmp + strlen("CORBA_") : ctmp; retval = g_strdup_printf( "CORBA_sequence_%s", base); g_free(ctmp); return retval; } break; case IDLN_FORWARD_DCL: case IDLN_INTERFACE: return orbit_cbe_get_typespec_str(IDL_INTERFACE(tree).ident); case IDLN_TYPE_TYPECODE: retval = "CORBA_TypeCode"; break; #endif default: // retval=sizeof(gpointer); // g_error("We were asked to get a typesize for a %s (%s, %s line %d)", // IDL_tree_type_names[IDL_NODE_TYPE(tree)], __FILE__, __FUNCTION__, __LINE__); g_print("We were asked to get a typesize for a %s -> %s (%s line %d)\n", IDL_tree_type_names[IDL_NODE_TYPE(tree)], IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(tree), "_", 0), __FUNCTION__, __LINE__); g_print("HACK: Returning sizeof(gpointer) now...\n", IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(tree), "_", 0)); retval=sizeof(gpointer); break; } return retval; }
/* Writes the value of the constant in 'tree' to file handle 'of' */ static char * orbit_cbe_get_const(IDL_tree tree) { char *opc = NULL, *retval, *ctmp; GString *tmpstr = g_string_new(NULL); switch(IDL_NODE_TYPE(tree)) { case IDLN_BOOLEAN: g_string_printf(tmpstr, "%s", IDL_BOOLEAN(tree).value?"CORBA_TRUE":"CORBA_FALSE"); break; case IDLN_CHAR: g_string_printf(tmpstr, "'\\x%X'", *(unsigned char *)IDL_CHAR(tree).value); break; case IDLN_FLOAT: g_string_printf(tmpstr, "%f", IDL_FLOAT(tree).value); break; case IDLN_INTEGER: g_string_printf(tmpstr, "%" IDL_LL "d", IDL_INTEGER(tree).value); break; case IDLN_STRING: g_string_printf(tmpstr, "\"%s\"", IDL_STRING(tree).value); break; case IDLN_WIDE_CHAR: g_string_printf(tmpstr, "L'%ls'", IDL_WIDE_CHAR(tree).value); break; case IDLN_WIDE_STRING: g_string_printf(tmpstr, "L\"%ls\"", IDL_WIDE_STRING(tree).value); break; case IDLN_BINOP: g_string_printf(tmpstr, "("); ctmp = orbit_cbe_get_const(IDL_BINOP(tree).left); g_string_append(tmpstr, ctmp); g_free(ctmp); switch(IDL_BINOP(tree).op) { case IDL_BINOP_OR: opc = "|"; break; case IDL_BINOP_XOR: opc = "^"; break; case IDL_BINOP_AND: opc = "&"; break; case IDL_BINOP_SHR: opc = ">>"; break; case IDL_BINOP_SHL: opc = "<<"; break; case IDL_BINOP_ADD: opc = "+"; break; case IDL_BINOP_SUB: opc = "-"; break; case IDL_BINOP_MULT: opc = "*"; break; case IDL_BINOP_DIV: opc = "/"; break; case IDL_BINOP_MOD: opc = "%"; break; } g_string_append_printf(tmpstr, " %s ", opc); ctmp = orbit_cbe_get_const(IDL_BINOP(tree).right); g_string_append_printf(tmpstr, "%s)", ctmp); g_free(ctmp); break; case IDLN_UNARYOP: switch(IDL_UNARYOP(tree).op) { case IDL_UNARYOP_PLUS: opc = "+"; break; case IDL_UNARYOP_MINUS: opc = "-"; break; case IDL_UNARYOP_COMPLEMENT: opc = "~"; break; } ctmp = orbit_cbe_get_const(IDL_UNARYOP(tree).operand); g_string_printf(tmpstr, "%s%s", opc, ctmp); g_free(ctmp); break; case IDLN_IDENT: { char *id; id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(tree), "_", 0); g_string_printf(tmpstr, "%s", id); g_free(id); } break; default: g_error("We were asked to print a constant for %s", IDL_tree_type_names[tree->_type]); break; } retval = tmpstr->str; g_string_free(tmpstr, FALSE); return retval; }
/** Gets the "type" of {tree} as known in C. The return value was alloc'd via g_malloc, and must be g_free'd. **/ char * orbit_cbe_get_typespec_str(IDL_tree tree) { char *retval = NULL; GString *tmpstr = NULL; if(!tree) { return g_strdup("void"); } switch(IDL_NODE_TYPE(tree)) { case IDLN_MEMBER: return orbit_cbe_get_typespec_str(IDL_MEMBER(tree).type_spec); break; case IDLN_TYPE_ANY: retval = "CORBA_any"; break; case IDLN_TYPE_FLOAT: switch(IDL_TYPE_FLOAT(tree).f_type) { case IDL_FLOAT_TYPE_FLOAT: retval = "CORBA_float"; break; case IDL_FLOAT_TYPE_DOUBLE: retval = "CORBA_double"; break; case IDL_FLOAT_TYPE_LONGDOUBLE: retval = "CORBA_long_double"; break; } break; case IDLN_TYPE_FIXED: return g_strdup_printf( "CORBA_fixed_%" IDL_LL "d_%" IDL_LL "d", IDL_INTEGER(IDL_TYPE_FIXED(tree).positive_int_const).value, IDL_INTEGER(IDL_TYPE_FIXED(tree).integer_lit).value); break; case IDLN_TYPE_INTEGER: tmpstr = g_string_new(NULL); g_string_append(tmpstr, "CORBA_"); if(!IDL_TYPE_INTEGER(tree).f_signed) g_string_append(tmpstr, "unsigned_"); switch(IDL_TYPE_INTEGER(tree).f_type) { case IDL_INTEGER_TYPE_SHORT: g_string_append(tmpstr, "short"); break; case IDL_INTEGER_TYPE_LONGLONG: g_string_append(tmpstr, "long_"); /* FALLTHROUGH */ case IDL_INTEGER_TYPE_LONG: g_string_append(tmpstr, "long"); break; } break; case IDLN_TYPE_STRING: retval = "CORBA_string"; /* this is non-standard! */ break; case IDLN_TYPE_OCTET: retval = "CORBA_octet"; break; case IDLN_TYPE_WIDE_STRING: retval = "CORBA_wstring"; /* this is non-standard! */ break; case IDLN_TYPE_CHAR: retval = "CORBA_char"; break; case IDLN_TYPE_WIDE_CHAR: retval = "CORBA_wchar"; break; case IDLN_TYPE_BOOLEAN: retval = "CORBA_boolean"; break; case IDLN_TYPE_STRUCT: return orbit_cbe_get_typespec_str(IDL_TYPE_STRUCT(tree).ident); case IDLN_EXCEPT_DCL: return orbit_cbe_get_typespec_str(IDL_EXCEPT_DCL(tree).ident); case IDLN_TYPE_ARRAY: return orbit_cbe_get_typespec_str(IDL_TYPE_ARRAY(tree).ident); case IDLN_TYPE_UNION: return orbit_cbe_get_typespec_str(IDL_TYPE_UNION(tree).ident); case IDLN_TYPE_ENUM: return orbit_cbe_get_typespec_str(IDL_TYPE_ENUM(tree).ident); case IDLN_IDENT: return IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(tree), "_", 0); case IDLN_PARAM_DCL: return orbit_cbe_get_typespec_str(IDL_PARAM_DCL(tree).param_type_spec); case IDLN_TYPE_SEQUENCE: { IDL_tree subtype = IDL_TYPE_SEQUENCE(tree).simple_type_spec; char *ctmp, *base; ctmp = orbit_cbe_get_typespec_str(subtype); /* We should have built-in alias to make this next line not needed */ base = orbit_cbe_type_is_builtin(subtype) ? ctmp + strlen("CORBA_") : ctmp; retval = g_strdup_printf( "CORBA_sequence_%s", base); g_free(ctmp); return retval; } break; case IDLN_NATIVE: retval = "gpointer"; break; case IDLN_FORWARD_DCL: case IDLN_INTERFACE: return orbit_cbe_get_typespec_str(IDL_INTERFACE(tree).ident); case IDLN_TYPE_OBJECT: retval = "CORBA_Object"; break; case IDLN_TYPE_TYPECODE: retval = "CORBA_TypeCode"; break; default: g_error("We were asked to get a typename for a %s", IDL_tree_type_names[IDL_NODE_TYPE(tree)]); break; } if (retval) return g_strdup (retval); else return g_string_free (tmpstr, FALSE); }