2006-03-03 Marek Safar <marek.safar@seznam.cz>
authorMarek Safar <marek.safar@gmail.com>
Fri, 3 Mar 2006 20:57:23 +0000 (20:57 -0000)
committerMarek Safar <marek.safar@gmail.com>
Fri, 3 Mar 2006 20:57:23 +0000 (20:57 -0000)
* attribute.cs (ResolveAsTypeTerminal): Removed.

* ecore.cs (Expression.ResolveAsTypeTerminal): Make virtual to allow
specialization for predefined types; 30% speed up.
Finally placed obsolete check to right place.
(Expression.ResolveType): Removed.

* enum.cs, expression.cs, parameter.cs, statement.cs, typemanager.cs:
Updated after ResolveType was removed.

* expression.cs (Cast.ctor): Check void cast.
(Binary.ResolveAsTypeTerminal): Is never type.
(Conditional.ResolveAsTypeTerminal): Is never type.

* rootcontext.cs (ResolveCore): Set base type to simplify some code later.

svn path=/trunk/mcs/; revision=57555

12 files changed:
mcs/mcs/ChangeLog
mcs/mcs/attribute.cs
mcs/mcs/class.cs
mcs/mcs/decl.cs
mcs/mcs/delegate.cs
mcs/mcs/ecore.cs
mcs/mcs/enum.cs
mcs/mcs/expression.cs
mcs/mcs/parameter.cs
mcs/mcs/rootcontext.cs
mcs/mcs/statement.cs
mcs/mcs/typemanager.cs

index a0ed7283a92e76d5820a001988fe4ff6d6f778b6..55335d6fa7d91692aa49c8ea29daae082d3d63b8 100644 (file)
@@ -1,3 +1,21 @@
+2006-03-03  Marek Safar  <marek.safar@seznam.cz>
+
+       * attribute.cs (ResolveAsTypeTerminal): Removed.
+
+       * ecore.cs (Expression.ResolveAsTypeTerminal): Make virtual to allow
+       specialization for predefined types; 30% speed up.
+       Finally placed obsolete check to right place.
+       (Expression.ResolveType): Removed.
+
+       * enum.cs, expression.cs, parameter.cs, statement.cs, typemanager.cs:
+       Updated after ResolveType was removed.
+
+       * expression.cs (Cast.ctor): Check void cast.
+       (Binary.ResolveAsTypeTerminal): Is never type.
+       (Conditional.ResolveAsTypeTerminal): Is never type.
+
+       * rootcontext.cs (ResolveCore): Set base type to simplify some code later.
+
 2006-03-01  Raja R Harinath  <rharinath@novell.com>
 
        Fix #77679.
index 2b8c8031ea49f232a8544b3ff9262a97d7dd10db..372ab9e3dd64061018d419ec394fc2d2dfda7820 100644 (file)
@@ -165,31 +165,22 @@ namespace Mono.CSharp {
                        Error_AttributeEmitError ("it is attached to invalid parent");
                }
 
-               protected virtual FullNamedExpression ResolveAsTypeTerminal (Expression expr, IResolveContext ec, bool silent)
+               protected virtual TypeExpr ResolveAsTypeTerminal (Expression expr, IResolveContext ec, bool silent)
                {
                        return expr.ResolveAsTypeTerminal (ec, silent);
                }
 
-               protected virtual FullNamedExpression ResolveAsTypeStep (Expression expr, IResolveContext ec, bool silent)
-               {
-                       return expr.ResolveAsTypeStep (ec, silent);
-               }
-
                Type ResolvePossibleAttributeType (string name, bool silent, ref bool is_attr)
                {
                        IResolveContext rc = owner.ResolveContext;
 
-                       FullNamedExpression fn;
+                       TypeExpr te;
                        if (LeftExpr == null) {
-                               fn = ResolveAsTypeTerminal (new SimpleName (name, Location), rc, silent);
+                               te = ResolveAsTypeTerminal (new SimpleName (name, Location), rc, silent);
                        } else {
-                               fn = ResolveAsTypeStep (LeftExpr, rc, silent);
-                               if (fn == null)
-                                       return null;
-                               fn = new MemberAccess (fn, name, Location).ResolveAsTypeTerminal (rc, silent);
+                               te = ResolveAsTypeTerminal (new MemberAccess (LeftExpr, name, Location), rc, silent);
                        }
 
-                       TypeExpr te = fn as TypeExpr;
                        if (te == null)
                                return null;
 
@@ -1332,19 +1323,7 @@ namespace Mono.CSharp {
                        RootContext.Tree.Types.NamespaceEntry = null;
                }
 
-               protected override FullNamedExpression ResolveAsTypeStep (Expression expr, IResolveContext ec, bool silent)
-               {
-                       try {
-                               Enter ();
-                               return base.ResolveAsTypeStep (expr, ec, silent);
-                       }
-                       finally {
-                               Leave ();
-                       }
-               }
-
-
-               protected override FullNamedExpression ResolveAsTypeTerminal (Expression expr, IResolveContext ec, bool silent)
+               protected override TypeExpr ResolveAsTypeTerminal (Expression expr, IResolveContext ec, bool silent)
                {
                        try {
                                Enter ();
index d98381da6c6a3e80a620c89143311826d63f5db5..68a79798a33484f6e6df0206b5f674dfbf4d0a8b 100644 (file)
@@ -1017,8 +1017,7 @@ namespace Mono.CSharp {
                        int start = 0, i, j;
 
                        if (Kind == Kind.Class){
-                               TypeExpr name = ResolveBaseTypeExpr (
-                                       (Expression) Bases [0]);
+                               TypeExpr name = ((Expression) Bases [0]).ResolveAsBaseTerminal (this, false);
 
                                if (name == null){
                                        return null;
@@ -1035,7 +1034,7 @@ namespace Mono.CSharp {
                        TypeExpr [] ifaces = new TypeExpr [count-start];
                        
                        for (i = start, j = 0; i < count; i++, j++){
-                               TypeExpr resolved = ResolveBaseTypeExpr ((Expression) Bases [i]);
+                               TypeExpr resolved = ((Expression) Bases [i]).ResolveAsTypeTerminal (this, false);
                                if (resolved == null) {
                                        return null;
                                }
@@ -1198,12 +1197,12 @@ namespace Mono.CSharp {
 
 
                        if (base_type != null) {
-                               base_type = base_type.ResolveAsTypeTerminal (this, false);
-                               if (base_type == null)
-                                       return false;
-
                                TypeBuilder.SetParent (base_type.Type);
-                               CheckObsoleteType (base_type);
+
+                               ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (base_type.Type);
+                               if (obsolete_attr != null && !IsInObsoleteScope) {
+                                       AttributeTester.Report_ObsoleteMessage (obsolete_attr, base_type.GetSignatureForError (), Location);
+                               }
                        }
 
                        if (!CheckRecursiveDefinition (this)) {
@@ -1212,7 +1211,7 @@ namespace Mono.CSharp {
 
                        // add interfaces that were not added at type creation
                        if (iface_exprs != null) {
-                               ifaces = TypeManager.ExpandInterfaces (this, iface_exprs);
+                               ifaces = TypeManager.ExpandInterfaces (iface_exprs);
                                if (ifaces == null) {
                                        return false;
                                }
@@ -4815,8 +4814,6 @@ namespace Mono.CSharp {
                        if (MemberType == null)
                                return false;
 
-                       CheckObsoleteType (Type);
-
                        if ((Parent.ModFlags & Modifiers.SEALED) != 0 && 
                                (ModFlags & (Modifiers.VIRTUAL|Modifiers.ABSTRACT)) != 0) {
                                        Report.Error (549, Location, "New virtual member `{0}' is declared in a sealed class `{1}'",
@@ -4863,7 +4860,7 @@ namespace Mono.CSharp {
                                if (texpr == null)
                                        return false;
 
-                               InterfaceType = texpr.ResolveType (this);
+                               InterfaceType = texpr.Type;
 
                                if (!InterfaceType.IsInterface) {
                                        Report.Error (538, Location, "`{0}' in explicit interface declaration is not an interface", TypeManager.CSharpName (InterfaceType));
@@ -5103,8 +5100,6 @@ namespace Mono.CSharp {
                        if (MemberType == null || Type == null)
                                return false;
 
-                       CheckObsoleteType (Type);
-
                        if (MemberType == TypeManager.void_type) {
                                Report.Error (1547, Location, "Keyword 'void' cannot be used in this context");
                                return false;
index 716dc15159b74c351e401cf699bb4259c7c2ec50..390de3690f3ed464322ddd4b1b30f628ed29114b 100644 (file)
@@ -378,18 +378,6 @@ namespace Mono.CSharp {
                        AttributeTester.Report_ObsoleteMessage (oa, GetSignatureForError (), loc);
                }
 
-               protected void CheckObsoleteType (Expression type)
-               {
-                       ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (type.Type);
-                       if (obsolete_attr == null)
-                               return;
-
-                       if (IsInObsoleteScope)
-                               return;
-
-                       AttributeTester.Report_ObsoleteMessage (obsolete_attr, TypeManager.CSharpName (type.Type), type.Location);
-               }
-
                /// <summary>
                /// Analyze whether CLS-Compliant verification must be execute for this MemberCore.
                /// </summary>
@@ -717,15 +705,6 @@ namespace Mono.CSharp {
                        // Parent.GetSignatureForError
                        return Name;
                }
-
-               // <summary>
-               //    Resolves the expression `e' for a type, and will recursively define
-               //    types.  This should only be used for resolving base types.
-               // </summary>
-               public TypeExpr ResolveBaseTypeExpr (Expression e)
-               {
-                       return e.ResolveAsTypeTerminal (this, false);
-               }
                
                public bool CheckAccessLevel (Type check_type)
                {
index 9c4cacdb403c494f09396052ddce8336f6eb0a11..cd2fed0677d80928efa27e92640de88f7f6448d0 100644 (file)
@@ -81,7 +81,7 @@ namespace Mono.CSharp {
                        if (TypeManager.multicast_delegate_type == null && !RootContext.StdLib) {
                                Namespace system = RootNamespace.Global.GetNamespace ("System", true);
                                TypeExpr expr = system.Lookup (this, "MulticastDelegate", Location) as TypeExpr;
-                               TypeManager.multicast_delegate_type = expr.ResolveType (this);
+                               TypeManager.multicast_delegate_type = expr.Type;
                        }
 
                        if (TypeManager.multicast_delegate_type == null)
@@ -176,8 +176,6 @@ namespace Mono.CSharp {
                        if (ret_type == null)
                                return false;
 
-                       CheckObsoleteType (ReturnType);
-
                        if (!Parent.AsAccessible (ret_type, ModFlags)) {
                                Report.Error (58, Location,
                                              "Inconsistent accessibility: return type `" +
index de19e0e434bd55432dd242361d040389c0d0ef0f..37d9adf56993096da4b72e1494b70773a2ca45b4 100644 (file)
@@ -235,7 +235,20 @@ namespace Mono.CSharp {
                // value will be returned if the expression is not a type
                // reference
                //
-               public TypeExpr ResolveAsTypeTerminal (IResolveContext ec, bool silent)
+               public virtual TypeExpr ResolveAsTypeTerminal (IResolveContext ec, bool silent)
+               {
+                       TypeExpr te = ResolveAsBaseTerminal (ec, silent);
+                       if (te == null)
+                               return null;
+
+                       ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (te.Type);
+                       if (obsolete_attr != null && !ec.IsInObsoleteScope) {
+                               AttributeTester.Report_ObsoleteMessage (obsolete_attr, GetSignatureForError (), Location);
+                       }
+                       return te;
+               }
+
+               public TypeExpr ResolveAsBaseTerminal (IResolveContext ec, bool silent)
                {
                        int errors = Report.Errors;
 
@@ -2161,20 +2174,6 @@ namespace Mono.CSharp {
 
                public abstract TypeExpr DoResolveAsTypeStep (IResolveContext ec);
 
-               public Type ResolveType (IResolveContext ec)
-               {
-                       TypeExpr t = ResolveAsTypeTerminal (ec, false);
-                       if (t == null)
-                               return null;
-
-                       ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (t.Type);
-                       if (obsolete_attr != null && !ec.IsInObsoleteScope) {
-                               AttributeTester.Report_ObsoleteMessage (obsolete_attr, Name, Location);
-                       }
-
-                       return t.Type;
-               }
-
                public abstract string Name {
                        get;
                }
@@ -2215,6 +2214,11 @@ namespace Mono.CSharp {
                        return this;
                }
 
+               public override TypeExpr ResolveAsTypeTerminal (IResolveContext ec, bool silent)
+               {
+                       return this;
+               }
+
                public override string Name {
                        get { return Type.ToString (); }
                }
@@ -2229,20 +2233,27 @@ namespace Mono.CSharp {
        ///   by the parser to setup the core types.  A TypeLookupExpression is always
        ///   classified as a type.
        /// </summary>
-       public class TypeLookupExpression : TypeExpr {
-               string name;
+       public sealed class TypeLookupExpression : TypeExpr {
+               readonly string name;
                
                public TypeLookupExpression (string name)
                {
                        this.name = name;
+                       eclass = ExprClass.Type;
+               }
+
+               public override TypeExpr ResolveAsTypeTerminal (IResolveContext ec, bool silent)
+               {
+                       // It's null for corlib compilation only
+                       if (type == null)
+                               return DoResolveAsTypeStep (ec);
+
+                       return this;
                }
 
                static readonly char [] dot_array = { '.' };
                public override TypeExpr DoResolveAsTypeStep (IResolveContext ec)
                {
-                       if (type != null)
-                               return this;
-
                        // If name is of the form `N.I', first lookup `N', then search a member `I' in it.
                        string rest = null;
                        string lookup_name = name;
@@ -2294,7 +2305,7 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       type = ((TypeExpr) resolved).ResolveType (ec);
+                       type = resolved.Type;
                        return this;
                }
 
@@ -2328,11 +2339,7 @@ namespace Mono.CSharp {
 
                public override TypeExpr DoResolveAsTypeStep (IResolveContext ec)
                {
-                       Type type = texpr.ResolveType (ec);
-                       if (type == null)
-                               return null;
-
-                       return new TypeExpression (type, loc);
+                       return texpr;
                }
 
                public override bool CheckAccessLevel (DeclSpace ds)
index c5bc35f8b166128accfc8cf396f9e6d4bbe65c87..5c41a73646e7178194e61ed4bec71db5b6223f63 100644 (file)
@@ -248,7 +248,7 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       TypeExpr ute = ResolveBaseTypeExpr (BaseType);
+                       TypeExpr ute = BaseType.ResolveAsTypeTerminal (this, false);
                        UnderlyingType = ute.Type;
 
                        if (UnderlyingType != TypeManager.int32_type &&
index 9311b31102357a0ad2eea9c4ed2f8cc1f81d4812..0a86f9ef0e4ef3dbba7335df95bb45c32929357d 100644 (file)
@@ -1049,7 +1049,8 @@ namespace Mono.CSharp {
                        TypeExpr texpr = ProbeType.ResolveAsTypeTerminal (ec, false);
                        if (texpr == null)
                                return null;
-                       probe_type = texpr.ResolveType (ec);
+
+                       probe_type = texpr.Type;
 
                        expr = expr.Resolve (ec);
                        if (expr == null)
@@ -1280,6 +1281,10 @@ namespace Mono.CSharp {
                        this.target_type = cast_type;
                        this.expr = expr;
                        this.loc = loc;
+
+                       if (target_type == TypeManager.system_void_expr) {
+                               Report.Error (1547, loc, "Keyword `void' cannot be used in this context");
+                       }
                }
 
                public Expression TargetType {
@@ -1321,7 +1326,7 @@ namespace Mono.CSharp {
                        if (target == null)
                                return null;
 
-                       type = target.ResolveType (ec);
+                       type = target.Type;
 
                        if (type.IsAbstract && type.IsSealed) {
                                Report.Error (716, loc, "Cannot convert to static type `{0}'", TypeManager.CSharpName (type));
@@ -2416,6 +2421,11 @@ namespace Mono.CSharp {
                        return ResolveOperator (ec);
                }
 
+               public override TypeExpr ResolveAsTypeTerminal (IResolveContext ec, bool silent)
+               {
+                       return null;
+               }
+
                private void CheckUselessComparison (Constant c, Type type)
                {
                        if (c == null || !IsTypeIntegral (type)
@@ -3349,6 +3359,11 @@ namespace Mono.CSharp {
                        return this;
                }
 
+               public override TypeExpr ResolveAsTypeTerminal (IResolveContext ec, bool silent)
+               {
+                       return null;
+               }
+
                public override void Emit (EmitContext ec)
                {
                        ILGenerator ig = ec.ig;
@@ -5645,7 +5660,7 @@ namespace Mono.CSharp {
                        if (texpr == null)
                                return null;
 
-                       type = texpr.ResolveType (ec);
+                       type = texpr.Type;
 
                        if (Arguments == null) {
                                Expression c = Constantify (type);
@@ -6087,7 +6102,7 @@ namespace Mono.CSharp {
                        if (array_type_expr == null)
                                return false;
 
-                       type = array_type_expr.ResolveType (ec);                
+                       type = array_type_expr.Type;
                        underlying_type = TypeManager.GetElementType (type);
                        dimensions = type.GetArrayRank ();
 
@@ -6816,7 +6831,7 @@ namespace Mono.CSharp {
                        if (texpr == null)
                                return null;
 
-                       typearg = texpr.ResolveType (ec);
+                       typearg = texpr.Type;
 
                        if (typearg == TypeManager.void_type) {
                                Error (673, "System.Void cannot be used from C#. Use typeof (void) to get the void type object");
@@ -6886,7 +6901,7 @@ namespace Mono.CSharp {
                        if (texpr == null)
                                return null;
 
-                       type_queried = texpr.ResolveType (ec);
+                       type_queried = texpr.Type;
 
                        int size_of = GetTypeSize (type_queried);
                        if (size_of > 0) {
@@ -7160,8 +7175,7 @@ namespace Mono.CSharp {
                                return null;
                        } 
 
-                       member_lookup = member_lookup.ResolveAsTypeTerminal (rc, silent);
-                       return (member_lookup as TypeExpr);
+                       return member_lookup.ResolveAsTypeTerminal (rc, silent);
                }
 
                public override void Emit (EmitContext ec)
@@ -8362,7 +8376,7 @@ namespace Mono.CSharp {
                        if (lexpr == null)
                                return null;
 
-                       Type ltype = lexpr.ResolveType (ec);
+                       Type ltype = lexpr.Type;
                        if ((ltype == TypeManager.void_type) && (dim != "*")) {
                                Report.Error (1547, Location,
                                              "Keyword 'void' cannot be used in this context");
@@ -8533,7 +8547,7 @@ namespace Mono.CSharp {
                        if (texpr == null)
                                return null;
 
-                       otype = texpr.ResolveType (ec);
+                       otype = texpr.Type;
 
                        if (!TypeManager.VerifyUnManaged (otype, loc))
                                return null;
index 481fd8b7f4a02aae4de96e5c1efb133e60dd89e0..c454d4e5c786b0969f910fa3d844c8e1db9ae245 100644 (file)
@@ -277,7 +277,7 @@ namespace Mono.CSharp {
                        if (texpr == null)
                                return false;
 
-                       parameter_type = texpr.ResolveType (ec);
+                       parameter_type = texpr.Type;
                        
                        if (parameter_type.IsAbstract && parameter_type.IsSealed) {
                                Report.Error (721, Location, "`{0}': static types cannot be used as parameters", GetSignatureForError ());
index 1f887a3694664ce0fb5c3bbe94c05e994c1bd2cb..f60dd38bdb9b27f21b637bd57837b109cd349c68 100644 (file)
@@ -296,7 +296,9 @@ namespace Mono.CSharp {
                        TypeContainer root = Tree.Types;
 
                        TypeManager.object_type = BootstrapCorlib_ResolveClass (root, "System.Object");
+                       TypeManager.system_object_expr.Type = TypeManager.object_type;
                        TypeManager.value_type = BootstrapCorlib_ResolveClass (root, "System.ValueType");
+                       TypeManager.system_valuetype_expr.Type = TypeManager.value_type;
                        TypeManager.attribute_type = BootstrapCorlib_ResolveClass (root, "System.Attribute");
                        TypeManager.indexer_name_type = BootstrapCorlib_ResolveClass (root, "System.Runtime.CompilerServices.IndexerNameAttribute");
                        
index 897b3ab1a14f091b971eec58a7e6ffead7ed00f6..88fd702a442108d5222a42f1cd3ac8822ccfd264 100644 (file)
@@ -1051,7 +1051,7 @@ namespace Mono.CSharp {
                                if (texpr == null)
                                        return false;
                                
-                               VariableType = texpr.ResolveType (ec);
+                               VariableType = texpr.Type;
                        }
 
                        if (VariableType == TypeManager.void_type) {
@@ -3364,7 +3364,7 @@ namespace Mono.CSharp {
                        if (texpr == null)
                                return false;
 
-                       expr_type = texpr.ResolveType (ec);
+                       expr_type = texpr.Type;
 
                        data = new Emitter [declarators.Count];
 
@@ -3589,7 +3589,7 @@ namespace Mono.CSharp {
                                        if (te == null)
                                                return false;
 
-                                       type = te.ResolveType (ec);
+                                       type = te.Type;
 
                                        if (type != TypeManager.exception_type && !type.IsSubclassOf (TypeManager.exception_type)){
                                                Error (155, "The type caught or thrown must be derived from System.Exception");
@@ -3828,7 +3828,7 @@ namespace Mono.CSharp {
                        if (texpr == null)
                                return false;
 
-                       expr_type = texpr.ResolveType (ec);
+                       expr_type = texpr.Type;
 
                        //
                        // The type must be an IDisposable or an implicit conversion
index eb918db625d7e9c3a5b7223e6b1b4d25c5121238..60fa07745d060a259abc3a8d4b554d26dea20f07 100644 (file)
@@ -1714,14 +1714,12 @@ public class TypeManager {
        ///   This expands in context like: IA; IB : IA; IC : IA, IB; the interface "IC" to
        ///   be IA, IB, IC.
        /// </remarks>
-       public static Type[] ExpandInterfaces (IResolveContext ec, TypeExpr [] base_interfaces)
+       public static Type[] ExpandInterfaces (TypeExpr [] base_interfaces)
        {
                ArrayList new_ifaces = new ArrayList ();
 
                foreach (TypeExpr iface in base_interfaces){
-                       Type itype = iface.ResolveType (ec);
-                       if (itype == null)
-                               return null;
+                       Type itype = iface.Type;
 
                        if (!new_ifaces.Contains (itype))
                                new_ifaces.Add (itype);