Esempio n. 1
0
    Type complete_iface_type(iface_entry entry)
    {
        TypeBuilder type_builder = entry.m_type_builder;
        XInterfaceTypeDescription2 xType = entry.m_xType;

        XTypeDescription[] baseTypes = xType.getBaseTypes();
        if (baseTypes.Length != 0)
        {
            foreach (XTypeDescription td in baseTypes)
            {
                XInterfaceTypeDescription baseType = resolveInterfaceTypedef(td);

                if (!(baseType.getName() == "com.sun.star.uno.XInterface"))
                {
                    string basetype_name = to_cts_name(baseType.getName());
                    iface_entry base_entry =
                        m_incomplete_ifaces[basetype_name] as iface_entry;
                    if (base_entry != null)
                    {
                        // complete uncomplete base type first
                        complete_iface_type(base_entry);
                    }
                }
            }
        }

        foreach (XInterfaceMemberTypeDescription xMember in xType.getMembers())
        {
            MethodBuilder method_builder;

            const MethodAttributes c_method_attr = (MethodAttributes.Public |
                                                    MethodAttributes.Abstract |
                                                    MethodAttributes.Virtual |
                                                    MethodAttributes.NewSlot |
                                                    MethodAttributes.HideBySig /* |
                                                    MethodAttributes.Instance */ );

            if (xMember.getTypeClass() == TypeClass.INTERFACE_METHOD)
            {
                XInterfaceMethodTypeDescription xMethod =
                    (XInterfaceMethodTypeDescription) xMember;

                XMethodParameter[] parameters = xMethod.getParameters();
                Type[] param_types = new Type[parameters.Length];
                // first determine all types
                // Make the first param type the return type
                foreach (XMethodParameter xParam in parameters)
                {
                    Type param_type = get_type(xParam.getType());
                    if (xParam.isOut())
                    {
                        param_type = get_type(param_type.FullName + "&", true);
                    }
                    param_types[xParam.getPosition()] = param_type;
                }

                // create method
        //                 if (tb != null)
        //                     method_builder = type_builder.DefineMethod(
        //                         xMethod.getMemberName(), c_method_attr, tb, param_types);
        //                 else
                method_builder = type_builder.DefineMethod(
                    xMethod.getMemberName(), c_method_attr,
                    get_type(xMethod.getReturnType()), param_types);

                // then define parameter infos
                foreach (XMethodParameter xParam in parameters)
                {
                    ParameterAttributes param_flags = 0;
                    if (xParam.isIn())
                        param_flags |= ParameterAttributes.In;
                    if (xParam.isOut())
                        param_flags |= ParameterAttributes.Out;
                    Trace.Assert(param_flags != 0);
                    method_builder.DefineParameter(
                        xParam.getPosition() + 1, /* starts with 1 */
                        param_flags,
                        xParam.getName());
                }
                // Apply attribute TypeParametersAttribute to return
                // value if it is a parameterized Type. Currently only
                // structs can have parameters.
                CustomAttributeBuilder attrBuilder;
                XStructTypeDescription xReturnStruct =
                    xMethod.getReturnType() as XStructTypeDescription;

                if (xReturnStruct != null)
                {
                    XTypeDescription[] type_args =
                        xReturnStruct.getTypeArguments();
                    if (type_args.Length != 0)
                    {
                        // get the ctor of the attribute
                        Type[] ctor = new Type[] { Type.GetType("System.Type[]") };
                        ConstructorInfo info =
                            typeof(uno.TypeParametersAttribute)
                            .GetConstructor(ctor);
                        // Get the arguments for the attribute's ctor
                        Type[] ctsTypes = new Type[type_args.Length];
                        for (int i = 0; i < type_args.Length; ++i)
                            ctsTypes[i] = get_type(type_args[i]);

                        attrBuilder = new CustomAttributeBuilder(
                            info, ctsTypes);

                        method_builder.SetCustomAttribute(attrBuilder);
                    }
                }

                // define UNO exception attribute (exceptions)
                attrBuilder = get_iface_method_exception_attribute(xMethod);
                if (attrBuilder != null)
                    method_builder.SetCustomAttribute(attrBuilder);

                // oneway attribute
                if (xMethod.isOneway())
                {
                    Type[] ctorOneway = new Type[0];
                    object[] args = new object[0];
                    attrBuilder = new CustomAttributeBuilder(
                        typeof(uno.OnewayAttribute).GetConstructor(ctorOneway),
                        args);
                    method_builder.SetCustomAttribute(attrBuilder);
                }
            }
            else // attribute
            {
                Trace.Assert(xMember.getTypeClass() ==
                             TypeClass.INTERFACE_ATTRIBUTE);
                XInterfaceAttributeTypeDescription2 xAttribute =
                    (XInterfaceAttributeTypeDescription2) xMember;

                MethodAttributes c_property_method_attr =
                    c_method_attr | MethodAttributes.SpecialName;

                Type attribute_type = get_type(xAttribute.getType());
                Type[] parameters = new Type[0];

                PropertyBuilder property_builder =
                    type_builder.DefineProperty(
                        xAttribute.getMemberName(), PropertyAttributes.None,
                        attribute_type, parameters);

                // set BoundAttribute, if necessary
                if (xAttribute.isBound())
                {
                    ConstructorInfo ctorBoundAttr =
                        typeof(uno.BoundAttribute).GetConstructor(new Type[0]);
                    CustomAttributeBuilder attrBuilderBound =
                        new CustomAttributeBuilder(ctorBoundAttr, new object[0]);
                    property_builder.SetCustomAttribute(attrBuilderBound);
                }

                // getter
                method_builder = type_builder.DefineMethod(
                    "get_" + xAttribute.getMemberName(),
                    c_property_method_attr, attribute_type, parameters);

                // define UNO exception attribute (exceptions)
                CustomAttributeBuilder attrBuilder =
                    get_exception_attribute(xAttribute.getGetExceptions());
                if (attrBuilder != null)
                    method_builder.SetCustomAttribute(attrBuilder);

                property_builder.SetGetMethod(method_builder);

                if (!xAttribute.isReadOnly())
                {
                    // setter
                    parameters = new Type[] { attribute_type };
                    method_builder =
                        type_builder.DefineMethod(
                            "set_" + xAttribute.getMemberName(),
                            c_property_method_attr, null, parameters);
                    // define parameter info
                    method_builder.DefineParameter(
                        1 /* starts with 1 */, ParameterAttributes.In, "value");
                    // define UNO exception attribute (exceptions)
                    attrBuilder =
                        get_exception_attribute(xAttribute.getSetExceptions());
                    if (attrBuilder != null)
                        method_builder.SetCustomAttribute(attrBuilder);

                    property_builder.SetSetMethod(method_builder);
                }
            }
        }

        // remove from incomplete types map
        string cts_name = type_builder.FullName;
        m_incomplete_ifaces.Remove(cts_name);

        if (Climaker.g_verbose)
        {
            Console.WriteLine("> emitting interface type {0}", cts_name);
        }

        return type_builder.CreateType();
    }
Esempio n. 2
0
    Type get_type(XInterfaceTypeDescription2 xType)
    {
        if (xType.getName() == "com.sun.star.uno.XInterface")
        {
            return typeof(System.Object);
        }

        string cts_name = to_cts_name(xType.getName());
        Type ret_type = get_type(cts_name, false /* no exc */);
        if (ret_type == null)
        {
            TypeBuilder type_builder;

            TypeAttributes attr = (TypeAttributes.Public |
                                   TypeAttributes.Interface |
                                   TypeAttributes.Abstract |
                                   TypeAttributes.AnsiClass);

            ArrayList baseTypes = new ArrayList();
            if (xType.getBaseTypes().Length > 0)
            {
                foreach (XInterfaceTypeDescription2 xIfaceTd
                         in xType.getBaseTypes())
                {
                    if (!(xIfaceTd.getName() == "com.sun.star.uno.XInterface"))
                    {
                        baseTypes.Add(xIfaceTd);
                    }
                }

                Type[] base_interfaces = new Type[baseTypes.Count];

                int index = 0;
                for (IEnumerator iter = baseTypes.GetEnumerator(); iter.MoveNext();
                     index++)
                {
                    base_interfaces[index] =
                        get_type((XInterfaceTypeDescription2) iter.Current);
                }
                type_builder = m_module_builder.DefineType(
                    cts_name, attr, null, base_interfaces);
            }
            else
            {
                Console.WriteLine(
                    "warning: IDL interface {0} is not derived from " +
                    "com.sun.star.uno.XInterface!", xType.getName());
                type_builder = m_module_builder.DefineType(cts_name, attr);
            }

            // insert to be completed
            iface_entry entry = new iface_entry();
            entry.m_xType = xType;
            entry.m_type_builder = type_builder;
            m_incomplete_ifaces.Add(cts_name, entry);

            // type is incomplete
            ret_type = type_builder;
        }
        return ret_type;
    }