예제 #1
0
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);
}
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;
}
예제 #3
0
static void
cbe_tc_generate (OIDL_C_Info  *ci,
		 CBETCGenInfo *tci)
{
	CBETCGenInfo  subtci;
	IDL_tree      curitem;
	char         *ctmp;
	int           union_default_index = -1,
		      subnames_id  = random_id++,
		      subtypes_id  = random_id++,
		      sublabels_id = random_id++;

	if (strncmp (tci->structname, "anon", 4)) {
		fprintf (ci->fh, "#if ");
		orbit_cbe_id_cond_hack (ci->fh, "TC_IMPL",
					tci->structname, ci->c_base_name);
		fprintf (ci->fh, " && !defined(TC_DEF_%s)\n", tci->structname);
		fprintf (ci->fh, "#define TC_DEF_%s 1\n", tci->structname);
	}

	if (IDL_NODE_TYPE (tci->ts) == IDLN_TYPE_DCL) {
		subtci = *tci;

		curitem = IDL_TYPE_DCL (tci->ts).type_spec;
		subtci.substructname = ctmp = orbit_generate_tcstruct_name (curitem);

		/* 
		 * The only type not already defined elsewhere
		 * that can be in the left half of a TypeCode.
		 */
		if (IDL_NODE_TYPE (curitem) == IDLN_TYPE_SEQUENCE) {
			subtci.structname = ctmp;
			subtci.ts         = curitem;
			cbe_tc_generate (ci, &subtci);
		}

		for (curitem = IDL_TYPE_DCL (tci->ts).dcls; curitem;
		     curitem = IDL_LIST (curitem).next) {
			subtci.ts = IDL_LIST (curitem).data;

			if (IDL_NODE_TYPE (subtci.ts) == IDLN_TYPE_ARRAY)
				subtci.structname = orbit_generate_tcstruct_name (
							IDL_TYPE_ARRAY (subtci.ts).ident);
			else
				subtci.structname = orbit_generate_tcstruct_name (subtci.ts);

			cbe_tc_generate (ci, &subtci);
			g_free (subtci.structname);
		}

	g_free (ctmp);
	return;
	}

	/* Do magic here - nesting of typecodes for arrays */
	if (IDL_NODE_TYPE (tci->ts) == IDLN_TYPE_ARRAY && 
            (IDL_list_length (IDL_TYPE_ARRAY (tci->ts).size_list) > tci->array_gen_ctr)) {

		curitem = IDL_list_nth (IDL_TYPE_ARRAY (tci->ts).size_list,
					tci->array_gen_ctr - 1);

		subtci = *tci;
		subtci.structname = ctmp = orbit_generate_tcstruct_name (curitem);
		subtci.array_gen_ctr++;

		cbe_tc_generate (ci, &subtci);

		tci->substructname = ctmp; /* FIXME: memory leak */
	}

	orbit_output_tcstruct_anon_subnames_array  (ci->fh, tci->ts, subnames_id);
	orbit_output_tcstruct_anon_subtypes_array  (ci->fh, tci->ts, subtypes_id,
						    tci->substructname);

	union_default_index = orbit_output_tcstruct_anon_sublabels_array (
					ci->fh, tci->ts, sublabels_id);

	if (!strncmp (tci->structname, "anon", 4))
		fprintf (ci->fh, "static ");
	else {
		fprintf (ci->fh, "#ifdef ORBIT_IDL_C_IMODULE_%s\n",
			 ci->c_base_name);
		fprintf (ci->fh, "static\n");
		fprintf (ci->fh, "#endif\n");
	}

	fprintf (ci->fh, "ORBIT2_MAYBE_CONST struct CORBA_TypeCode_struct %s_struct = {\n",
				tci->structname);

	orbit_output_tcstruct_parent (ci->fh);

	fprintf (ci->fh, ",\n");

	orbit_output_tcstruct_kind (ci->fh, tci->ts, tci->array_gen_ctr);

	fprintf (ci->fh, ",\n");

	/* flags */
	fprintf (ci->fh, "0,\n");

	/* c_length */
	fprintf (ci->fh, "0,\n");

	orbit_output_tcstruct_c_align (ci->fh, tci->ts);

	fprintf (ci->fh, ",\n");

	orbit_output_tcstruct_length (ci->fh, tci->ts, tci->array_gen_ctr);

	fprintf (ci->fh, ",\n");

	orbit_output_tcstruct_sub_parts (ci->fh, tci->ts);

	fprintf (ci->fh, ",\n");

	orbit_output_tcstruct_subtypes (ci->fh, tci->ts, subtypes_id);

	fprintf (ci->fh, ",\n");

	orbit_output_tcstruct_discriminator (ci->fh, tci->ts);

	fprintf (ci->fh, ",\n");

	orbit_output_tcstruct_name (ci->fh, tci->ts, tci->array_gen_ctr);

	fprintf (ci->fh, ",\n");

	orbit_output_tcstruct_repo_id (ci->fh, tci->ts, tci->array_gen_ctr);

	fprintf (ci->fh, ",\n");

	orbit_output_tcstruct_subnames (ci->fh, tci->ts, subnames_id);

	fprintf (ci->fh, ",\n");

	orbit_output_tcstruct_sublabels (ci->fh, tci->ts, sublabels_id);

	fprintf (ci->fh, ",\n");

	orbit_output_tcstruct_default_index (ci->fh, union_default_index);

	fprintf (ci->fh, ",\n");

	orbit_output_tcstruct_recurse_depth (ci->fh);

	fprintf (ci->fh, ",\n");

	orbit_output_tcstruct_digits_scale (ci->fh, tci->ts);

	fprintf (ci->fh, "\n};\n");

	if (strncmp (tci->structname, "anon", 4))
		fprintf (ci->fh, "#endif\n");
}