コード例 #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
        public static JsInterface Make(IType type)
        {
            var iface = type.Data as JsInterface;

            if (iface == null)
            {
                iface     = new JsInterface(type);
                type.Data = iface;
            }
            return(iface);
        }
コード例 #3
0
        internal JsNode CompileType(IType type)
        {
            if (type == null)
            {
                return(null);
            }

            if (type.IsInterface)
            {
                return(JsInterface.Make(type));
            }

            if (type.IsArray)
            {
                CompileType(type.GetElementType());
                return(CompileClass(SystemTypes.Array));
            }

            return(CompileClass(type));
        }