/*
 * Verify that a native declaration has an associated C++ expression, i.e. that
 * it's of the form native <idl-name>(<c++-name>)
 */
gboolean
check_native(TreeState *state)
{
    char *native_name;
    /* require that native declarations give a native type */
    if (IDL_NATIVE(state->tree).user_type) 
        return TRUE;
    native_name = IDL_IDENT(IDL_NATIVE(state->tree).ident).str;
    IDL_tree_error(state->tree,
                   "``native %s;'' needs C++ type: ``native %s(<C++ type>);''",
                   native_name, native_name);
    return FALSE;
}
static gboolean
fill_td_from_type(TreeState *state, XPTTypeDescriptor *td, IDL_tree type)
{
    IDL_tree up;
    int16 size_is_argnum;
    int16 length_is_argnum;
    gboolean has_size_is;
    gboolean has_length_is;
    gboolean is_array = FALSE;

    if (type) {

        /* deal with array */

        if (IDL_NODE_TYPE(state->tree) == IDLN_PARAM_DCL) {
            IDL_tree sd = IDL_PARAM_DCL(state->tree).simple_declarator;
            if (IDL_tree_property_get(sd, "array")) {

                is_array = TRUE;

                /* size_is is required! */
                if (!get_size_and_length(state, type, 
                                         &size_is_argnum, &length_is_argnum,
                                         &has_size_is, &has_length_is)) {
                    /* error was reported by helper function */
                    return FALSE;
                }

                if (!has_size_is) {
                   IDL_tree_error(state->tree, "[array] requires [size_is()]\n");
                    return FALSE;
                }

                td->prefix.flags = TD_ARRAY | XPT_TDP_POINTER;
                td->argnum = size_is_argnum;

                if (has_length_is)
                    td->argnum2 = length_is_argnum;
                else
                    td->argnum2 = size_is_argnum;

                /* 
                * XXX - NOTE - this will be broken for multidimensional 
                * arrays because of the realloc XPT_InterfaceDescriptorAddTypes
                * uses. The underlying 'td' can change as we recurse in to get
                * additional dimensions. Luckily, we don't yet support more
                * than on dimension in the arrays
                */
                /* setup the additional_type */                
                if (!XPT_InterfaceDescriptorAddTypes(ARENA(state), 
                                                     CURRENT(state), 1)) {
                    g_error("out of memory\n");
                    return FALSE;
                }
                td->type.additional_type = NEXT_TYPE(state);
                td = &CURRENT(state)->additional_types[NEXT_TYPE(state)];
                NEXT_TYPE(state)++ ;
            }
        }

handle_typedef:
        switch (IDL_NODE_TYPE(type)) {
          case IDLN_TYPE_INTEGER: {
              gboolean sign = IDL_TYPE_INTEGER(type).f_signed;
              switch(IDL_TYPE_INTEGER(type).f_type) {
                case IDL_INTEGER_TYPE_SHORT:
                  td->prefix.flags = sign ? TD_INT16 : TD_UINT16;
                  break;
                case IDL_INTEGER_TYPE_LONG:
                  td->prefix.flags = sign ? TD_INT32 : TD_UINT32;
                  break;
                case IDL_INTEGER_TYPE_LONGLONG:
                  td->prefix.flags = sign ? TD_INT64 : TD_UINT64;
                  break;
              }
              break;
          }
          case IDLN_TYPE_CHAR:
            td->prefix.flags = TD_CHAR;
            break;
          case IDLN_TYPE_WIDE_CHAR:
            td->prefix.flags = TD_WCHAR;
            break;
          case IDLN_TYPE_STRING:
            if (is_array) {
                td->prefix.flags = TD_PSTRING | XPT_TDP_POINTER;
            } else {
                if (!get_size_and_length(state, type, 
                                         &size_is_argnum, &length_is_argnum,
                                         &has_size_is, &has_length_is)) {
                    /* error was reported by helper function */
                    return FALSE;
                }
                if (has_size_is) {
                    td->prefix.flags = TD_PSTRING_SIZE_IS | XPT_TDP_POINTER;
                    td->argnum = size_is_argnum;
                    if (has_length_is)
                        td->argnum2 = length_is_argnum;
                    else
                        td->argnum2 = size_is_argnum;
                } else {
                    td->prefix.flags = TD_PSTRING | XPT_TDP_POINTER;
                }
            }
            break;
          case IDLN_TYPE_WIDE_STRING:
            if (is_array) {
                td->prefix.flags = TD_PWSTRING | XPT_TDP_POINTER;
            } else {
                if (!get_size_and_length(state, type, 
                                         &size_is_argnum, &length_is_argnum,
                                         &has_size_is, &has_length_is)) {
                    /* error was reported by helper function */
                    return FALSE;
                }
                if (has_size_is) {
                    td->prefix.flags = TD_PWSTRING_SIZE_IS | XPT_TDP_POINTER;
                    td->argnum = size_is_argnum;
                    if (has_length_is)
                        td->argnum2 = length_is_argnum;
                    else
                        td->argnum2 = size_is_argnum;
                } else {
                    td->prefix.flags = TD_PWSTRING | XPT_TDP_POINTER;
                }
            }
            break;
          case IDLN_TYPE_BOOLEAN:
            td->prefix.flags = TD_BOOL;
            break;
          case IDLN_TYPE_OCTET:
            td->prefix.flags = TD_UINT8;
            break;
          case IDLN_TYPE_FLOAT:
            switch (IDL_TYPE_FLOAT (type).f_type) {
              case IDL_FLOAT_TYPE_FLOAT:
                td->prefix.flags = TD_FLOAT;
                break;
              case IDL_FLOAT_TYPE_DOUBLE:
                td->prefix.flags = TD_DOUBLE;
                break;
              /* XXX 'long double' just ignored, or what? */
              default: break;
            }
            break;
          case IDLN_IDENT:
            if (!(up = IDL_NODE_UP(type))) {
                IDL_tree_error(state->tree,
                               "ERROR: orphan ident %s in param list\n",
                               IDL_IDENT(type).str);
                return FALSE;
            }
            switch (IDL_NODE_TYPE(up)) {
                /* This whole section is abominably ugly */
              case IDLN_FORWARD_DCL:
              case IDLN_INTERFACE: {
                XPTInterfaceDirectoryEntry *ide, *ides;
                uint16 num_ifaces;
                char *className;
                const char *iid_is;
handle_iid_is:
                ides = HEADER(state)->interface_directory;
                num_ifaces = HEADER(state)->num_interfaces;
                /* might get here via the goto, so re-check type */
                if (IDL_NODE_TYPE(up) == IDLN_INTERFACE)
                    className = IDL_IDENT(IDL_INTERFACE(up).ident).str;
                else if (IDL_NODE_TYPE(up) == IDLN_FORWARD_DCL)
                    className = IDL_IDENT(IDL_FORWARD_DCL(up).ident).str;
                else
                    className = IDL_IDENT(IDL_NATIVE(up).ident).str;
                iid_is = NULL;

                if (IDL_NODE_TYPE(state->tree) == IDLN_PARAM_DCL) {
                    iid_is =
                        IDL_tree_property_get(IDL_PARAM_DCL(state->tree).simple_declarator,
                                              "iid_is");
                }
                if (iid_is) {
                    int16 argnum;
                    if (!find_arg_with_name(state, iid_is, &argnum)) {
                        IDL_tree_error(state->tree,
                                       "can't find matching argument for "
                                       "[iid_is(%s)]\n", iid_is);
                        return FALSE;
                    }
                    td->prefix.flags = TD_INTERFACE_IS_TYPE | XPT_TDP_POINTER;
                    td->argnum = argnum;
                } else {
                    td->prefix.flags = TD_INTERFACE_TYPE | XPT_TDP_POINTER;
                    ide = FindInterfaceByName(ides, num_ifaces, className);
                    if (!ide || ide < ides || ide > ides + num_ifaces) {
                        IDL_tree_error(state->tree,
                                       "unknown iface %s in param\n",
                                       className);
                        return FALSE;
                    }
                    td->type.iface = ide - ides + 1;
#ifdef DEBUG_shaver_index
                    fprintf(stderr, "DBG: index %d for %s\n",
                            td->type.iface, className);
#endif
                }
                break;
              }
              case IDLN_NATIVE: {
                  char *ident;

                  /* jband - adding goto for iid_is when type is native */
                  if (IDL_NODE_TYPE(state->tree) == IDLN_PARAM_DCL &&
                      IDL_tree_property_get(IDL_PARAM_DCL(state->tree).simple_declarator,
                                              "iid_is"))
                      goto handle_iid_is;

                  ident = IDL_IDENT(type).str;
                  if (IDL_tree_property_get(type, "nsid")) {
                      td->prefix.flags = TD_PNSIID;
                      if (IDL_tree_property_get(type, "ref"))
                          td->prefix.flags |= XPT_TDP_POINTER | XPT_TDP_REFERENCE;
                      else if (IDL_tree_property_get(type,"ptr"))
                          td->prefix.flags |= XPT_TDP_POINTER;
                  } else if (IDL_tree_property_get(type, "domstring")) {
                      td->prefix.flags = TD_DOMSTRING | XPT_TDP_POINTER;
                      if (IDL_tree_property_get(type, "ref"))
                          td->prefix.flags |= XPT_TDP_REFERENCE;
                  } else if (IDL_tree_property_get(type, "astring")) {
                      td->prefix.flags = TD_ASTRING | XPT_TDP_POINTER;
                      if (IDL_tree_property_get(type, "ref"))
                          td->prefix.flags |= XPT_TDP_REFERENCE;
                  } else if (IDL_tree_property_get(type, "utf8string")) {
                      td->prefix.flags = TD_UTF8STRING | XPT_TDP_POINTER;
                      if (IDL_tree_property_get(type, "ref"))
                          td->prefix.flags |= XPT_TDP_REFERENCE;
                  } else if (IDL_tree_property_get(type, "cstring")) {
                      td->prefix.flags = TD_CSTRING | XPT_TDP_POINTER;
                      if (IDL_tree_property_get(type, "ref"))
                          td->prefix.flags |= XPT_TDP_REFERENCE;
                  } else if (IDL_tree_property_get(type, "jsval")) {
                      td->prefix.flags = TD_JSVAL;
                      if (IDL_tree_property_get(type, "ptr"))
                          td->prefix.flags |= XPT_TDP_POINTER;
                  } else {
                      td->prefix.flags = TD_VOID | XPT_TDP_POINTER;
                  }
                  break;
                }
              default:
                if (IDL_NODE_TYPE(IDL_NODE_UP(up)) == IDLN_TYPE_DCL) {
                    /* restart with the underlying type */
                    IDL_tree new_type;
                    new_type = IDL_TYPE_DCL(IDL_NODE_UP(up)).type_spec;
#ifdef DEBUG_shaver_misc
                    fprintf(stderr, "following %s typedef to %s\n",
                            IDL_IDENT(type).str, IDL_NODE_TYPE_NAME(new_type));
#endif
                    /* 
                    *  Do a nice messy goto rather than recursion so that
                    *  we can avoid screwing up the *array* information.
                    */
/*                    return fill_td_from_type(state, td, new_type); */
                    if (new_type) {
                        type = new_type;
                        goto handle_typedef;
                    } else {
                        /* do what we would do in recursion if !type */
                        td->prefix.flags = TD_VOID;
                        return TRUE;
                    }
                }
                IDL_tree_error(state->tree,
                               "can't handle %s ident in param list\n",
#ifdef DEBUG_shaver
                               /* XXX is this safe to use on Win now? */
                               IDL_NODE_TYPE_NAME(IDL_NODE_UP(type))
#else
                               "that type of"
#endif
                               );
#ifdef DEBUG_shaver
                XPT_ASSERT(0);
#endif
                return FALSE;
            }
            break;
          default:
            IDL_tree_error(state->tree, "can't handle %s in param list\n",
#ifdef DEBUG_shaver
                           /* XXX is this safe to use on Win now? */
                           IDL_NODE_TYPE_NAME(IDL_NODE_UP(type))
#else
                        "that type"
#endif
            );
            return FALSE;
        }
    } else {
        td->prefix.flags = TD_VOID;
    }

    return TRUE;
}
Example #3
0
/**
	This is a rather hairy function. Its purpose is to output the
	required number of *'s that indicate the amount of indirection
	for input, output, & input-output parameters, and return
	values.  We do this by having a table of the number of *'s for
	each type and purpose (nptrrefs_required), taken from 19.20
	of the CORBA 2.2 spec, and then having a table that translates
	from the IDLN_* enums into an index into nptrrefs_required (typeoffsets)
**/
gint
oidl_param_info(IDL_tree in_param, IDL_ParamRole role, gboolean *isSlice)
{
	IDL_tree param;
	const int * const typeoffsets = orte_cbe_get_typeoffsets_table ();
	const int nptrrefs_required[][4] = {
		{0,1,1,0} /* float */,
		{0,1,1,0} /* double */,
		{0,1,1,0} /* long double */,
		{1,1,1,0} /* fixed_d_s 3 */, 
		{0,1,1,0} /* boolean */,
		{0,1,1,0} /* char */,
		{0,1,1,0} /* wchar */,
		{0,1,1,0} /* octet */,
		{0,1,1,0} /* enum */,
		{0,1,1,0} /* objref */,
		{1,1,1,0} /* fixed struct 10 */,
		{1,1,1,0} /* fixed union */,
		{0,1,1,0} /* string */,
		{0,1,1,0} /* wstring */,
		{1,1,2,1} /* sequence */,
		{0,0,0,0} /* fixed array */,
		{1,1,2,1} /* any 16 */
	};
	int retval = 0;
	int typeidx;

	*isSlice = FALSE;

	if(!in_param)
		return 0; /* void */

	/* Now, how do we use this table? :) */
	param = orte_cbe_get_typespec (in_param);

	g_assert (param);

	switch (IDL_NODE_TYPE (param)) {
	case IDLN_TYPE_STRUCT:
	case IDLN_TYPE_UNION:
		if (((role == DATA_RETURN) || (role == DATA_OUT)) &&
		    !orte_cbe_type_is_fixed_length(param))
			retval++;
		break;

	case IDLN_TYPE_ARRAY:
		if ( role == DATA_RETURN ) {
			*isSlice = TRUE;
			retval = 1;

		} else if (role == DATA_OUT &&
			   !orte_cbe_type_is_fixed_length (param)) {
			*isSlice = TRUE;
			retval = 2;
		}
		break;

	case IDLN_NATIVE:
		if ( IDL_NATIVE (param).user_type
		     && strcmp (IDL_NATIVE (param).user_type,
				"IDL_variable_length_struct") == 0 )
			return role == DATA_OUT ? 2 : 1;
		break;

	case IDLN_EXCEPT_DCL:
		fprintf (stderr, "Error: exception declared at '%s:%d' cannot be "
			 "used as a method parameter\n", in_param->_file,
			 in_param->_line);
		exit (1);
		break;
	default:
		break;
	}

	/* ERROR ! */
	typeidx = typeoffsets [IDL_NODE_TYPE (param)];
	g_assert (typeidx >= 0);

	switch (role) {
	case DATA_IN:
		role = 0;
		break;
	case DATA_INOUT:
		role = 1;
		break;
	case DATA_OUT:
		role = 2;
		break;
	case DATA_RETURN:
		role = 3;
		break;
	default:
		g_assert_not_reached ();
		break;
	}

	retval += nptrrefs_required [typeidx] [role];

	return retval;
}
static gboolean
write_type(IDL_tree type_tree, gboolean is_out, FILE *outfile)
{
    if (!type_tree) {
        fputs("void", outfile);
        return TRUE;
    }

    switch (IDL_NODE_TYPE(type_tree)) {
      case IDLN_TYPE_INTEGER: {
        gboolean sign = IDL_TYPE_INTEGER(type_tree).f_signed;
        switch (IDL_TYPE_INTEGER(type_tree).f_type) {
          case IDL_INTEGER_TYPE_SHORT:
            fputs(sign ? "PRInt16" : "PRUint16", outfile);
            break;
          case IDL_INTEGER_TYPE_LONG:
            fputs(sign ? "PRInt32" : "PRUint32", outfile);
            break;
          case IDL_INTEGER_TYPE_LONGLONG:
            fputs(sign ? "PRInt64" : "PRUint64", outfile);
            break;
          default:
            g_error("Unknown integer type %d\n",
                    IDL_TYPE_INTEGER(type_tree).f_type);
            return FALSE;
        }
        break;
      }
      case IDLN_TYPE_CHAR:
        fputs("char", outfile);
        break;
      case IDLN_TYPE_WIDE_CHAR:
        fputs("PRUnichar", outfile); /* wchar_t? */
        break;
      case IDLN_TYPE_WIDE_STRING:
        fputs("PRUnichar *", outfile);
        break;
      case IDLN_TYPE_STRING:
        fputs("char *", outfile);
        break;
      case IDLN_TYPE_BOOLEAN:
        fputs("PRBool", outfile);
        break;
      case IDLN_TYPE_OCTET:
        fputs("PRUint8", outfile);
        break;
      case IDLN_TYPE_FLOAT:
        switch (IDL_TYPE_FLOAT(type_tree).f_type) {
          case IDL_FLOAT_TYPE_FLOAT:
            fputs("float", outfile);
            break;
          case IDL_FLOAT_TYPE_DOUBLE:
            fputs("double", outfile);
            break;
          /* XXX 'long double' just ignored, or what? */
          default:
            fprintf(outfile, "unknown_type_%d", IDL_NODE_TYPE(type_tree));
            break;
        }
        break;
      case IDLN_IDENT:
        if (UP_IS_NATIVE(type_tree)) {
            if (IDL_tree_property_get(type_tree, "domstring") ||
                IDL_tree_property_get(type_tree, "astring")) {
                fputs("nsAString", outfile);
            } else if (IDL_tree_property_get(type_tree, "utf8string")) {
                fputs("nsACString", outfile);
            } else if (IDL_tree_property_get(type_tree, "cstring")) {
                fputs("nsACString", outfile);
            } else {
                fputs(IDL_NATIVE(IDL_NODE_UP(type_tree)).user_type, outfile);
            }
            if (IDL_tree_property_get(type_tree, "ptr")) {
                fputs(" *", outfile);
            } else if (IDL_tree_property_get(type_tree, "ref")) {
                fputs(" &", outfile);
            }
        } else {
            fputs(IDL_IDENT(type_tree).str, outfile);
        }
        if (UP_IS_AGGREGATE(type_tree))
            fputs(" *", outfile);
        break;
      default:
        fprintf(outfile, "unknown_type_%d", IDL_NODE_TYPE(type_tree));
        break;
    }
    return TRUE;
}
static gboolean 
xpcom_to_java_type(TreeState *state, IDL_tree type) 
{
    IDL_tree real_type;
    IDL_tree up;

    if (!type) {
        fputs("Object", state->file);
        return TRUE;
    }

    /* Could be a typedef; try to map it to the real type */
    real_type = find_underlying_type(type);
    type = real_type ? real_type : type;

    switch(IDL_NODE_TYPE(type)) {

    case IDLN_TYPE_INTEGER: {

        switch(IDL_TYPE_INTEGER(type).f_type) {

        case IDL_INTEGER_TYPE_SHORT:
            fputs("short", state->file);
            break;

        case IDL_INTEGER_TYPE_LONG:
            fputs("int", state->file);
            break;

        case IDL_INTEGER_TYPE_LONGLONG:
            fputs("long", state->file);
            break;
	    
        default:
            g_error("   Unknown integer type: %d\n",
                    IDL_TYPE_INTEGER(type).f_type);
            return FALSE;

        }

        break;
    }

    case IDLN_TYPE_CHAR:
    case IDLN_TYPE_WIDE_CHAR:
        fputs("char", state->file);
        break;

    case IDLN_TYPE_WIDE_STRING:
    case IDLN_TYPE_STRING:
        fputs("String", state->file);
        break;

    case IDLN_TYPE_BOOLEAN:
        fputs("boolean", state->file);
        break;

    case IDLN_TYPE_OCTET:
        fputs("byte", state->file);
        break;

    case IDLN_TYPE_FLOAT:
        switch(IDL_TYPE_FLOAT(type).f_type) {

        case IDL_FLOAT_TYPE_FLOAT:
            fputs("float", state->file);
            break;

        case IDL_FLOAT_TYPE_DOUBLE:
            fputs("double", state->file);
            break;
	    
        default:
            g_error("    Unknown floating point typ: %d\n",
                    IDL_NODE_TYPE(type));
            break;
        }
        break;


    case IDLN_IDENT:
      if (!(up = IDL_NODE_UP(type))) {
          IDL_tree_error(state->tree,
                         "ERROR: orphan ident %s in param list\n",
                         IDL_IDENT(state->tree).str);
          return FALSE;
      }
      switch (IDL_NODE_TYPE(up)) {
        case IDLN_FORWARD_DCL:
        case IDLN_INTERFACE: {
          char *className;
          const char *iid_is;
handle_iid_is:
          /* might get here via the goto, so re-check type */
          if (IDL_NODE_TYPE(up) == IDLN_INTERFACE)
              className = IDL_IDENT(IDL_INTERFACE(up).ident).str;
          else if (IDL_NODE_TYPE(up) == IDLN_FORWARD_DCL)
              className = IDL_IDENT(IDL_FORWARD_DCL(up).ident).str;
          else
              className = IDL_IDENT(IDL_NATIVE(up).ident).str;
          iid_is = NULL;

          if (IDL_NODE_TYPE(state->tree) == IDLN_PARAM_DCL) {
              iid_is =
                  IDL_tree_property_get(IDL_PARAM_DCL(state->tree).simple_declarator,
                                        "iid_is");
          }
          if (iid_is) {
              fputs("nsISupports", state->file);
          } else {
              /* XXX How do we want to handle this? If it's an IDLN_INTERFACE,
               *  then we can just output the name of the class, since the IDL
               *  files exist for those classes.  However, if it's an
               *  IDLN_FORWARD_DCL, some of those interfaces are not defined in
               *  IDL files, so we get an error when trying to compile the java
               *  files.  So, for now, we just output them as the base iface
               *  (nsISupports). 
               */
              if (IDL_NODE_TYPE(up) == IDLN_FORWARD_DCL)
                  fputs("nsISupports", state->file);
              else
                  fprintf(state->file, "%s", className);
          }
          break;
        }
        case IDLN_NATIVE: {
            char *ident;

            /* jband - adding goto for iid_is when type is native */
            if (IDL_NODE_TYPE(state->tree) == IDLN_PARAM_DCL &&
                IDL_tree_property_get(IDL_PARAM_DCL(state->tree).simple_declarator,
                                        "iid_is"))
            {
                goto handle_iid_is;
/*                fputs("nsISupports", state->file); */
                break;
            }

            ident = IDL_IDENT(type).str;
            if (IDL_tree_property_get(type, "nsid")) {
                fputs("String", state->file);
            } else if (IDL_tree_property_get(type, "domstring")) {
                fputs("String", state->file);
            } else if (IDL_tree_property_get(type, "astring")) {
                fputs("String", state->file);
            } else if (IDL_tree_property_get(type, "utf8string")) {
                fputs("String", state->file);
            } else if (IDL_tree_property_get(type, "cstring")) {
                fputs("String", state->file);
            } else {
                const char* user_type = IDL_NATIVE(IDL_NODE_UP(type)).user_type;
                IDL_tree real_type = 
                    g_hash_table_lookup(TYPEDEFS(state), user_type);

                if (real_type) {
                    return xpcom_to_java_type(state, real_type);
                } else {
                    if (strcmp(user_type, "PRInt8") == 0 ||
                        strcmp(user_type, "PRUint8") == 0) {
                        fputs("byte", state->file);
                    } else if (strcmp(user_type, "PRInt16") == 0 ||
                               strcmp(user_type, "PRUint16") == 0) {
                        fputs("short", state->file);
                    } else if (strcmp(user_type, "PRInt32") == 0 ||
                               strcmp(user_type, "PRUint32") == 0 ||
                               strcmp(user_type, "int") == 0) {
                        fputs("int", state->file);
                    } else if (strcmp(user_type, "PRInt64") == 0 ||
                               strcmp(user_type, "PRUint64") == 0) {
                        fputs("long", state->file);
                    } else if (strcmp(user_type, "PRBool") == 0) {
                        fputs("boolean", state->file);
                    } else if (strncmp(user_type, "char", 4) == 0 ||
                               strncmp(user_type, "const char", 10) == 0 ||
                               strncmp(user_type, "unsigned char", 13) == 0) {
                        if (IDL_tree_property_get(type, "ptr")) {
                            fputs("byte[]", state->file);
                        } else {
                            fputs("char", state->file);
                        }
                    } else if (strcmp(user_type, "nsIID") == 0) {
                        fputs("String", state->file);
                    } else if (strcmp(user_type, "nsString") == 0 ||
                               strcmp(user_type, "nsAString") == 0 ||
                               strcmp(user_type, "nsACString") == 0) {
                        fputs("String", state->file);
                    } else {
                        fputs("int", state->file);
                    }
                }
            }
            break;
          }
        default:
          if (IDL_NODE_TYPE(IDL_NODE_UP(up)) == IDLN_TYPE_DCL) {
              /* restart with the underlying type */
              IDL_tree new_type;
              new_type = IDL_TYPE_DCL(IDL_NODE_UP(up)).type_spec;
              if (new_type) {
                  gboolean rc = xpcom_to_java_type(state, new_type);
                  return rc;
              } else {
                  /* do what we would do in recursion if !type */
                  fputs("Object", state->file);
                  return TRUE;
              }
          }
          IDL_tree_error(state->tree,
                         "can't handle %s ident in param list\n",
                         "that type of"
                         );
          return FALSE;
      }
      break;

    default:
      IDL_tree_error(state->tree, "can't handle %s in param list\n",
#ifdef DEBUG_shaver
                     /* XXX is this safe to use on Win now? */
                     IDL_NODE_TYPE_NAME(IDL_NODE_UP(type))
#else
                  "that type"
#endif
      );
      return FALSE;
    }

    return TRUE;

}
Example #6
0
static gboolean 
xpcom_to_java_type (TreeState *state) 
{
    IDL_tree real_type;

    if (!state->tree) {
        fputs("Object", FILENAME(state));
        return TRUE;
    }

    /* Could be a typedef; try to map it to the real type */

    real_type = find_underlying_type(state->tree);
    state->tree = real_type ? real_type : state->tree;

    switch(IDL_NODE_TYPE(state->tree)) {

    case IDLN_TYPE_INTEGER: {

        switch(IDL_TYPE_INTEGER(state->tree).f_type) {

        case IDL_INTEGER_TYPE_SHORT:
            fputs("short", FILENAME(state));
            break;

        case IDL_INTEGER_TYPE_LONG:
            fputs("int", FILENAME(state));
            break;

        case IDL_INTEGER_TYPE_LONGLONG:
            fputs("long", FILENAME(state));
            break;
	    
        default:
            g_error("   Unknown integer type: %d\n",
                    IDL_TYPE_INTEGER(state->tree).f_type);
            return FALSE;

        }

        break;
    }

    case IDLN_TYPE_CHAR:
    case IDLN_TYPE_WIDE_CHAR:
        fputs("char", FILENAME(state));
        break;

    case IDLN_TYPE_WIDE_STRING:
    case IDLN_TYPE_STRING:
        fputs("String", FILENAME(state));
        break;

    case IDLN_TYPE_BOOLEAN:
        fputs("boolean", FILENAME(state));
        break;

    case IDLN_TYPE_OCTET:
        fputs("byte", FILENAME(state));
        break;

    case IDLN_TYPE_FLOAT:
        switch(IDL_TYPE_FLOAT(state->tree).f_type) {

        case IDL_FLOAT_TYPE_FLOAT:
            fputs("float", FILENAME(state));
            break;

        case IDL_FLOAT_TYPE_DOUBLE:
            fputs("double", FILENAME(state));
            break;
	    
        default:
            g_error("    Unknown floating point typ: %d\n",
                    IDL_NODE_TYPE(state->tree));
            break;
        }
        break;


    case IDLN_IDENT:
        if (IDL_NODE_UP(state->tree) &&
            IDL_NODE_TYPE(IDL_NODE_UP(state->tree)) == IDLN_NATIVE) {
            const char *user_type = IDL_NATIVE(IDL_NODE_UP(state->tree)).user_type;
            const char *ident_str = IDL_IDENT(IDL_NATIVE(IDL_NODE_UP(state->tree)).ident).str;
            if (strcmp(user_type, "void") == 0) { /*it should not happend for scriptable methods*/
                fputs("Object", FILENAME(state));
            }
            /* XXX: s.b test for "id" attribute */
            /* XXX: special class for nsIDs */
            else if (strcmp(user_type, "nsID") == 0) {
                fputs("ID", FILENAME(state));
            } else if (strcmp(user_type, "nsIID") == 0) {
                fputs("IID", FILENAME(state));
            } else if (strcmp(user_type, "nsCID") == 0) { 
                fputs("CID", FILENAME(state));
            }
            else {
                /* XXX: special class for opaque types */
                /*it should not happend for scriptable methods*/
                fputs("OpaqueValue", FILENAME(state)); 
            }
        } else {
            const char *ident_str = IDL_IDENT(state->tree).str;

            /* XXX: big kludge; s.b. way to match to typedefs */
            if (strcmp(ident_str, "PRInt8") == 0 ||
                strcmp(ident_str, "PRUint8") == 0) {
                fputs("byte", FILENAME(state));
            }
            else if (strcmp(ident_str, "PRInt16") == 0 ||
                     strcmp(ident_str, "PRUint16") == 0) {
                fputs("short", FILENAME(state));
            }
            else if (strcmp(ident_str, "PRInt32") == 0 ||
                     strcmp(ident_str, "PRUint32") == 0) {
                fputs("int", FILENAME(state));
            }
            else if (strcmp(ident_str, "PRInt64") == 0 ||
                     strcmp(ident_str, "PRUint64") == 0) {
                fputs("long", FILENAME(state));
            }
            else if (strcmp(ident_str, "PRBool") == 0) {
                fputs("boolean", FILENAME(state));
            }
            else if (strcmp(ident_str, "nsrefcnt") == 0) {
                fputs("int", FILENAME(state));
            }
            else {
                IDL_tree real_type = 
                    g_hash_table_lookup(TYPEDEFS(state), ident_str);

                if (real_type) {
                    IDL_tree orig_tree = state->tree;
                    state->tree = real_type;
                    xpcom_to_java_type(state);

                    state->tree = orig_tree;
                }
                else {
                    fputs(subscriptIdentifier(state, (char*) ident_str), FILENAME(state));
                }
            }
        }

        break;

    case IDLN_TYPE_ENUM:
    case IDLN_TYPE_OBJECT:
    default:
        g_error("    Unknown type: %d\n",
                IDL_TYPE_FLOAT(state->tree).f_type);
        break;
    }

    return TRUE;

}