[HttpWebRequest] Support 4.0 Host property.
[mono.git] / mcs / mcs / typespec.cs
index 2eef4f276f8cf8958ad2583c2b26a2a475b7aab5..5751cab61d0a501461d184523242e137786af61b 100644 (file)
 using System;
 using System.Collections.Generic;
 using System.Text;
+
+#if STATIC
+using MetaType = IKVM.Reflection.Type;
+using IKVM.Reflection;
+#else
+using MetaType = System.Type;
 using System.Reflection;
+#endif
 
 namespace Mono.CSharp
 {
        public class TypeSpec : MemberSpec
        {
-               protected Type info;
+               protected MetaType info;
                protected MemberCache cache;
                protected IList<TypeSpec> ifaces;
                TypeSpec base_type;
@@ -26,6 +33,7 @@ namespace Mono.CSharp
 
                public static readonly TypeSpec[] EmptyTypes = new TypeSpec[0];
 
+#if !STATIC
                // Reflection Emit hacking
                static readonly Type TypeBuilder;
                static readonly Type GenericTypeBuilder;
@@ -38,8 +46,9 @@ namespace Mono.CSharp
                        if (GenericTypeBuilder == null)
                                GenericTypeBuilder = assembly.GetType ("System.Reflection.Emit.TypeBuilderInstantiation");
                }
+#endif
 
-               public TypeSpec (MemberKind kind, TypeSpec declaringType, ITypeDefinition definition, Type info, Modifiers modifiers)
+               public TypeSpec (MemberKind kind, TypeSpec declaringType, ITypeDefinition definition, MetaType info, Modifiers modifiers)
                        : base (kind, declaringType, definition, modifiers)
                {
                        this.declaringType = declaringType;
@@ -186,8 +195,12 @@ namespace Mono.CSharp
 
                public bool IsTypeBuilder {
                        get {
+#if STATIC
+                               return true;
+#else
                                var meta = GetMetaInfo().GetType ();
                                return meta == TypeBuilder || meta == GenericTypeBuilder;
+#endif
                        }
                }
 
@@ -268,7 +281,7 @@ namespace Mono.CSharp
                        return aua;
                }
 
-               public virtual Type GetMetaInfo ()
+               public virtual MetaType GetMetaInfo ()
                {
                        return info;
                }
@@ -420,7 +433,43 @@ namespace Mono.CSharp
                        return this;
                }
 
-               public void SetMetaInfo (Type info)
+               public override List<TypeSpec> ResolveMissingDependencies ()
+               {
+                       List<TypeSpec> missing = null;
+
+                       if (Kind == MemberKind.MissingType) {
+                               missing = new List<TypeSpec> ();
+                               missing.Add (this);
+                               return missing;
+                       }
+
+                       foreach (var targ in TypeArguments) {
+                               if (targ.Kind == MemberKind.MissingType) {
+                                       if (missing == null)
+                                               missing = new List<TypeSpec> ();
+
+                                       missing.Add (targ);
+                               }
+                       }
+
+                       if (Interfaces != null) {
+                               foreach (var iface in Interfaces) {
+                                       if (iface.Kind == MemberKind.MissingType) {
+                                               if (missing == null)
+                                                       missing = new List<TypeSpec> ();
+
+                                               missing.Add (iface);
+                                       }
+                               }
+                       }
+
+                       if (missing != null || BaseType == null)
+                               return missing;
+
+                       return BaseType.ResolveMissingDependencies ();
+               }
+
+               public void SetMetaInfo (MetaType info)
                {
                        if (this.info != null)
                                throw new InternalErrorException ("MetaInfo reset");
@@ -484,9 +533,6 @@ namespace Mono.CSharp
                public BuildinTypeSpec (MemberKind kind, string ns, string name, Type buildinKind)
                        : base (kind, null, null, null, Modifiers.PUBLIC)
                {
-                       if (kind == MemberKind.Struct)
-                               modifiers |= Modifiers.SEALED;
-
                        this.type = buildinKind;
                        this.ns = ns;
                        this.name = name;
@@ -495,8 +541,8 @@ namespace Mono.CSharp
                public BuildinTypeSpec (string name, Type buildinKind)
                        : this (MemberKind.InternalCompilerType, "", name, buildinKind)
                {
-                       // Make all internal types CLS-compliant, non-obsolete
-                       state = (state & ~(StateFlags.CLSCompliant_Undetected | StateFlags.Obsolete_Undetected)) | StateFlags.CLSCompliant;
+                       // Make all internal types CLS-compliant, non-obsolete, compact
+                       state = (state & ~(StateFlags.CLSCompliant_Undetected | StateFlags.Obsolete_Undetected | StateFlags.MissingDependency_Undetected)) | StateFlags.CLSCompliant;
                }
 
                #region Properties
@@ -560,10 +606,11 @@ namespace Mono.CSharp
                        return FullName;
                }
 
-               public void SetDefinition (ITypeDefinition td, System.Type type)
+               public void SetDefinition (ITypeDefinition td, MetaType type, Modifiers mod)
                {
                        this.definition = td;
                        this.info = type;
+                       this.modifiers |= (mod & ~Modifiers.AccessibilityMask);
                }
 
                public void SetDefinition (TypeSpec ts)
@@ -572,6 +619,7 @@ namespace Mono.CSharp
                        this.info = ts.GetMetaInfo ();
                        this.BaseType = ts.BaseType;
                        this.Interfaces = ts.Interfaces;
+                       this.modifiers = ts.Modifiers;
                }
        }
 
@@ -1089,7 +1137,7 @@ namespace Mono.CSharp
 
        public abstract class ElementTypeSpec : TypeSpec, ITypeDefinition
        {
-               protected ElementTypeSpec (MemberKind kind, TypeSpec element, Type info)
+               protected ElementTypeSpec (MemberKind kind, TypeSpec element, MetaType info)
                        : base (kind, element.DeclaringType, null, info, element.Modifiers)
                {
                        this.Element = element;
@@ -1269,7 +1317,7 @@ namespace Mono.CSharp
                {
                        var mb = RootContext.ToplevelTypes.Builder;
 
-                       var arg_types = new Type[rank];
+                       var arg_types = new MetaType[rank];
                        for (int i = 0; i < rank; i++)
                                arg_types[i] = TypeManager.int32_type.GetMetaInfo ();
 
@@ -1285,7 +1333,7 @@ namespace Mono.CSharp
                {
                        var mb = RootContext.ToplevelTypes.Builder;
 
-                       var arg_types = new Type[rank];
+                       var arg_types = new MetaType[rank];
                        for (int i = 0; i < rank; i++)
                                arg_types[i] = TypeManager.int32_type.GetMetaInfo ();
 
@@ -1301,7 +1349,7 @@ namespace Mono.CSharp
                {
                        var mb = RootContext.ToplevelTypes.Builder;
 
-                       var arg_types = new Type[rank];
+                       var arg_types = new MetaType[rank];
                        for (int i = 0; i < rank; i++)
                                arg_types[i] = TypeManager.int32_type.GetMetaInfo ();
 
@@ -1317,7 +1365,7 @@ namespace Mono.CSharp
                {
                        var mb = RootContext.ToplevelTypes.Builder;
 
-                       var arg_types = new Type[rank + 1];
+                       var arg_types = new MetaType[rank + 1];
                        for (int i = 0; i < rank; i++)
                                arg_types[i] = TypeManager.int32_type.GetMetaInfo ();
 
@@ -1331,7 +1379,7 @@ namespace Mono.CSharp
                        return set;
                }
 
-               public override Type GetMetaInfo ()
+               public override MetaType GetMetaInfo ()
                {
                        if (info == null) {
                                if (rank == 1)
@@ -1395,7 +1443,7 @@ namespace Mono.CSharp
                {
                }
 
-               public override Type GetMetaInfo ()
+               public override MetaType GetMetaInfo ()
                {
                        if (info == null) {
                                info = Element.GetMetaInfo ().MakeByRefType ();
@@ -1432,7 +1480,7 @@ namespace Mono.CSharp
                        state &= ~StateFlags.CLSCompliant_Undetected;
                }
 
-               public override Type GetMetaInfo ()
+               public override MetaType GetMetaInfo ()
                {
                        if (info == null) {
                                info = Element.GetMetaInfo ().MakePointerType ();