예제 #1
0
 internal static Method CreateMethod(Class declaringType, string name, NativeFunction function, int vtableSlot)
 {
     Method method = new Method();
     method.Name = name;
     method.Function = function;
     method.VTableSlot = vtableSlot;
     if (function != null)
     {
         function["m"] = var.Cast<Method>(method);
     }
     method.DeclaringClass = declaringType;
     declaringType.Methods.Push(method);
     return method;
 }
예제 #2
0
 internal static Property CreateProperty(Class declaringType, string name, Method getMethod, Method setMethod)
 {
     Property property = new Property();
     property.DeclaringClass = declaringType;
     property.Name = name;
     property.GetMethod = getMethod;
     property.SetMethod = setMethod;
     declaringType.Properties.Push(property);
     return property;
 }
예제 #3
0
 internal static Class CreateClass(
     string ns, string name, Assembly assembly, UIntPtr vtableDataPointer,
     Class elementClass,
     bool isInterface, bool isArray
     )
 {
     Class klass = new Class();
     klass.Name = name;
     klass.Namespace = ns;
     klass.Assembly = assembly;
     klass.VTableDataPointer = vtableDataPointer;
     VTable vtable = GenerateCodeToDereferenceVTableDataPointer(vtableDataPointer);
     klass.VTable = vtable;
     vtable.Class = klass;
     klass.ElementClass = elementClass;
     klass.IsInterface = isInterface;
     klass.IsArray = isArray;
     assembly.Classes.Push(klass);
     return klass;
 }
예제 #4
0
 internal static Constructor CreateConstructor(Class declaringType, string name, NativeFunction function)
 {
     Constructor ctor = new Constructor();
     ctor.Name = name;
     ctor.Function = function;
     if (function != null)
     {
         function["m"] = var.Cast<Constructor>(ctor);
     }
     ctor.DeclaringClass = declaringType;
     declaringType.Constructors.Push(ctor);
     return ctor;
 }
예제 #5
0
        private static RuntimeType GetTypeFromClass(Class klass)
        {
            // check cache. if not there, create the runtime type and save to cache
            if (!_runtimeTypeCache.ContainsKey(klass))
            {
                RuntimeType declaringType;
                if (klass.DeclaringClass != null)
                {
                    declaringType = GetTypeFromClass(klass.DeclaringClass);
                }
                else
                {
                    declaringType = null;
                }
                RuntimeType runtimeType = new RuntimeType(klass, declaringType);
                _runtimeTypeCache[klass] = runtimeType;
            }

            return _runtimeTypeCache[klass];
        }
예제 #6
0
        private static Constructor GetDefaultConstructor(Class klass)
        {
            NativeArray<Constructor> constructors = klass.Constructors;
            for (int i = 0; i < constructors.Length; i++)
            {
                Constructor constructor = constructors[i];
                if (constructor.Parameters.Length == 0)
                {
                    return constructor;
                }
            }

            return null;
        }
예제 #7
0
        private static object CreateInstance(Class klass)
        {
            // check for default constructor
            Constructor defaultConstructor = GetDefaultConstructor(klass);

            if (defaultConstructor == null)
            {
                // TODO: Throw MissingMethodException
                throw new ExecutionEngineException("No default constructor found in type " + klass);
            }

            return CreateInstance(defaultConstructor);
        }
예제 #8
0
        // TODO: This method is not code generated correctly
        // root cause is likely the conditional expression
        // the arguments to RuntimeType::.ctor are reversed!
        private static RuntimeType BrokenGetTypeFromClass(Class klass)
        {
            // check cache. if not there, create the runtime type and save to cache
            if (!_runtimeTypeCache.ContainsKey(klass))
            {
                RuntimeType runtimeType = new RuntimeType(klass, klass.DeclaringClass != null ? GetTypeFromClass(klass.DeclaringClass) : null);
                _runtimeTypeCache[klass] = runtimeType;
            }

            return _runtimeTypeCache[klass];
        }
예제 #9
0
 public RuntimeType(Class klass, RuntimeType declaringType)
     : base((RuntimeTypeHandle)klass.VTable)
 {
     _class = klass;
 }