Back to index

lightning-sunbird  0.9+nobinonly
Package Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
Mozilla.XPCOM.InterfaceGenerator Class Reference

List of all members.

Package Functions

 InterfaceGenerator (String name)
Assembly Generate ()

Private Member Functions

Type FixupInterfaceType (TypeInfo.ParamDescriptor desc)
void GenerateInterfaceMethod (TypeInfo.MethodDescriptor desc)

Static Private Member Functions

static InterfaceGenerator ()

Private Attributes

String typeName
TypeBuilder tb
const PropertyAttributes PROPERTY_ATTRS = PropertyAttributes.None
const MethodAttributes METHOD_ATTRS
PropertyBuilder lastProperty = null

Static Private Attributes

static ModuleBuilder module

Detailed Description

Definition at line 13 of file interface-generator.cs.


Constructor & Destructor Documentation

static Mozilla.XPCOM.InterfaceGenerator.InterfaceGenerator ( ) [inline, static, private]

Definition at line 17 of file interface-generator.cs.

    {
        AssemblyName an = new AssemblyName();
        an.Version = new Version(1, 0, 0, 0);
        an.Name = "Mozilla.XPCOM.Interfaces";

        AppDomain curDom = AppDomain.CurrentDomain;
        AssemblyBuilder ab =
            curDom.DefineDynamicAssembly(an, AssemblyBuilderAccess.Run);

        module = ab.DefineDynamicModule(an.Name);
    }

Here is the call graph for this function:

Definition at line 33 of file interface-generator.cs.

    {
        typeName = name;
    }

Member Function Documentation

Definition at line 43 of file interface-generator.cs.

    {
        try {
            return TypeInfo.TypeForIID(desc.GetIID());
        } catch (Exception e) {
            // Console.WriteLine(e);
            return typeof(object);
        }
    }

Here is the call graph for this function:

Assembly Mozilla.XPCOM.InterfaceGenerator.Generate ( ) [inline, package]

Definition at line 98 of file interface-generator.cs.

    {
        if (module.GetType(typeName) != null)
            return module.Assembly;

        String ifaceName = typeName.Replace("Mozilla.XPCOM.Interfaces.", "");
        TypeInfo.MethodDescriptor[] descs =
            TypeInfo.GetMethodData(ifaceName);

        ushort inheritedMethodCount;
        String parentName = TypeInfo.GetParentInfo(ifaceName,
                                                   out inheritedMethodCount);
        Type parentType;

        if (parentName != null) {
            parentName = "Mozilla.XPCOM.Interfaces." + parentName;
            parentType = module.Assembly.GetType(parentName);
            if (parentType == null) {
                InterfaceGenerator gen = new InterfaceGenerator(parentName);
                parentType = gen.Generate().GetType(parentName);
            }
        } else {
            parentType = typeof(object);
        }

        tb = module.DefineType(typeName,
                               TypeAttributes.Public | TypeAttributes.Interface,
                               parentType);

        for (int i = inheritedMethodCount; i < descs.Length; i++) {
            if (descs[i] != null)
                GenerateInterfaceMethod(descs[i]);
        }

        tb.CreateType();

        return module.Assembly;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 53 of file interface-generator.cs.

    {
        if (desc == null || !desc.IsVisible())
            return;

        MethodAttributes methodAttrs = METHOD_ATTRS;

        String methodName = desc.name;
        if (desc.IsGetter()) {
            methodName = "get_" + desc.name;
            methodAttrs |= MethodAttributes.SpecialName;
        } else if (desc.IsSetter()) {
            methodName = "set_" + desc.name;
            methodAttrs |= MethodAttributes.SpecialName;
        }
            
        // Fix up interface types in parameters
        Type ret = desc.resultType;
        if (ret == typeof(object))
            ret = FixupInterfaceType(desc.args[desc.args.Length - 1]);
        Type[] argTypes = (Type[])desc.argTypes.Clone();
        for (int i = 0; i < argTypes.Length; i++) {
            if (argTypes[i] == typeof(object))
                argTypes[i] = FixupInterfaceType(desc.args[i]);
        }
        MethodBuilder meth = tb.DefineMethod(methodName, methodAttrs, ret,
                                             desc.argTypes);

        if (desc.IsSetter()) {
            if (lastProperty != null && lastProperty.Name == desc.name) {
                lastProperty.SetSetMethod(meth);
            } else {
                tb.DefineProperty(desc.name, PROPERTY_ATTRS, desc.resultType,
                                  new Type[0]).SetSetMethod(meth);
            }
            lastProperty = null;
        } else if (desc.IsGetter()) {
            lastProperty = tb.DefineProperty(desc.name, PROPERTY_ATTRS,
                                             desc.resultType, new Type[0]);
            lastProperty.SetGetMethod(meth);
        } else {
            lastProperty = null;
        }
    }

Here is the call graph for this function:


Member Data Documentation

Definition at line 41 of file interface-generator.cs.

Initial value:
 MethodAttributes.Public |
            MethodAttributes.Abstract | MethodAttributes.Virtual

Definition at line 39 of file interface-generator.cs.

ModuleBuilder Mozilla.XPCOM.InterfaceGenerator.module [static, private]

Definition at line 15 of file interface-generator.cs.

const PropertyAttributes Mozilla.XPCOM.InterfaceGenerator.PROPERTY_ATTRS = PropertyAttributes.None [private]

Definition at line 38 of file interface-generator.cs.

TypeBuilder Mozilla.XPCOM.InterfaceGenerator.tb [private]

Definition at line 31 of file interface-generator.cs.

Definition at line 30 of file interface-generator.cs.


The documentation for this class was generated from the following file: