예제 #1
0
        internal JsClass CompileClass(IType type)
        {
            if (type == null || type.IsExcluded())
            {
                return(null);
            }

            var klass = type.Data as JsClass;

            if (klass != null)
            {
                return(klass);
            }

            if (type.IsEnum && type.ValueType.IsInt64())
            {
                CompileClass(type.ValueType);
            }

            var baseType  = type.BaseType;
            var baseClass = CompileClass(baseType.Is(SystemTypeCode.ValueType) || type.IsEnum ? SystemTypes.Object : baseType);

            var ns = string.IsNullOrEmpty(type.Namespace) ? "$global" : type.Namespace;

            _program.DefineNamespace(ns);

            klass = new JsClass(type, baseType.Is(SystemTypeCode.ValueType) || type.IsString() ? null : baseClass);

            type.Data = klass;

            if (baseClass != null)
            {
                baseClass.Subclasses.Add(klass);
            }

            foreach (var iface in type.Interfaces)
            {
                JsInterface.Make(iface).Implementations.Add(klass);
            }

            _program.Add(klass);

            switch (type.TypeKind)
            {
            case TypeKind.Struct:
                JsStruct.CompileCopy(klass);
                break;

            case TypeKind.Delegate:
                JsDelegate.CreateInstanceImpl(klass);
                break;
            }

            CompileImpls(klass, type);

            return(klass);
        }
예제 #2
0
        private JsClass CompileClass(IType type)
        {
            var klass = _host.CompileClass(type);

            _host.CompileFields(type, false);

            if (type.IsNullableInstance())
            {
                JsStruct.CompileCopy(klass);
            }

            return(klass);
        }