**** Merged from MCS ****
authorMartin Baulig <martin@novell.com>
Mon, 18 Oct 2004 18:05:39 +0000 (18:05 -0000)
committerMartin Baulig <martin@novell.com>
Mon, 18 Oct 2004 18:05:39 +0000 (18:05 -0000)
svn path=/trunk/mcs/; revision=35091

mcs/gmcs/ChangeLog
mcs/gmcs/class.cs
mcs/gmcs/cs-parser.jay
mcs/gmcs/decl.cs
mcs/gmcs/delegate.cs
mcs/gmcs/ecore.cs
mcs/gmcs/expression.cs
mcs/gmcs/statement.cs

index b912bbe8966e057e8f4bb0d8c994b39b0a6c1ab0..58675a1eeb016e3b7f71dd28f729546cf8a9cea2 100755 (executable)
@@ -1,3 +1,32 @@
+2004-10-07  Raja R Harinath  <rharinath@novell.com>
+
+       More DeclSpace.ResolveType avoidance.
+       * decl.cs (MemberCore.InUnsafe): New property.
+       * class.cs (MemberBase.DoDefine): Use ResolveAsTypeTerminal 
+       with newly created EmitContext.
+       (FieldMember.Define): Likewise.
+       * delegate.cs (Delegate.Define): Likewise.
+       * ecore.cs (SimpleName.ResolveAsTypeStep): Lookup with alias
+       only if normal name-lookup fails.
+       (TypeExpr.DoResolve): Enable error-checking.
+       * expression.cs (ArrayCreation.DoResolve): Use ResolveAsTypeTerminal.
+       (SizeOf.DoResolve): Likewise.
+       (ComposedCast.DoResolveAsTypeStep): Likewise.
+       (StackAlloc.DoResolve): Likewise.
+       * statement.cs (Block.Flags): Add new flag 'Unsafe'.
+       (Block.Unsafe): New property.
+       (Block.EmitMeta): Set ec.InUnsafe as appropriate.
+       (Unsafe): Set 'unsafe' flag of contained block.
+       (LocalInfo.Resolve): Use ResolveAsTypeTerminal.
+       (Fixed.Resolve): Likewise.
+       (Catch.Resolve): Likewise.
+       (Using.ResolveLocalVariableDecls): Likewise.
+       (Foreach.Resolve): Likewise.
+
+2004-10-05  John Luke <john.luke@gmail.com>
+
+       * cs-parser.jay: add location to error CS0175
+
 2004-10-04  Miguel de Icaza  <miguel@ximian.com>
 
        * ecore.cs (Expression.Constantity): Add support for turning null
index e746877aadf04496096983590d76b6938da6276b..61ac7b7261b5ccb0de5aa6b9233e1ec24124c94d 100755 (executable)
@@ -5111,6 +5111,9 @@ namespace Mono.CSharp {
 
                protected virtual bool DoDefineBase ()
                {
+                       EmitContext ec = new EmitContext (Parent, Location, null, null, 0);
+                       ec.InUnsafe = InUnsafe;
+
                        if (Name == null)
                                throw new InternalErrorException ();
 
@@ -5136,6 +5139,9 @@ namespace Mono.CSharp {
 
                protected virtual bool DoDefine (DeclSpace decl)
                {
+                       EmitContext ec = new EmitContext (Parent, Location, null, null, 0);
+                       ec.InUnsafe = InUnsafe;
+
                        // Lookup Type, verify validity
                        MemberType = decl.ResolveType (Type, false, Location);
                        if (MemberType == null)
@@ -5183,12 +5189,13 @@ namespace Mono.CSharp {
                                return false;
 
                        if (IsExplicitImpl) {
-                               Expression iface_expr = ExplicitInterfaceName.GetTypeExpression (Location);
-
-                               InterfaceType = Parent.ResolveType (iface_expr, false, Location);
-                               if (InterfaceType == null)
+                               Expression expr = ExplicitInterfaceName.GetTypeExpression (Location);
+                               expr = expr.ResolveAsTypeTerminal (ec, false);
+                               if (expr == null)
                                        return false;
 
+                               InterfaceType = expr.Type;
+
                                if (InterfaceType.IsClass) {
                                        Report.Error (538, Location, "'{0}' in explicit interface declaration is not an interface", ExplicitInterfaceName);
                                        return false;
@@ -5444,11 +5451,15 @@ namespace Mono.CSharp {
 
                public override bool Define()
                {
-                       MemberType = Parent.ResolveType (Type, false, Location);
+                       EmitContext ec = new EmitContext (Parent, Location, null, null, 0);
+                       ec.InUnsafe = InUnsafe;
                        
-                       if (MemberType == null)
+                       Type = Type.ResolveAsTypeTerminal (ec, false);
+                       if (Type == null)
                                return false;
 
+                       MemberType = Type.Type;
+
                        if (!CheckBase ())
                                return false;
                        
index 0ef010ac09f48a8d932098a89063d9965e4a7b02..df0a51d9e8ef372d286c90e16370502c91a795bb 100755 (executable)
@@ -2566,7 +2566,7 @@ base_access
                $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
          }
        | BASE error {
-               Report.Error (175, "Use of keyword `base' is not valid in this context");
+               Report.Error (175, lexer.Location, "Use of keyword `base' is not valid in this context");
                $$ = null;
          }
        ;
index 137ceec0f0f6aa61cd4a62848e1b99734f42f187..2b4a6dde5acb51e58aa59dafeac0762b67223586 100755 (executable)
@@ -311,6 +311,12 @@ namespace Mono.CSharp {
                        VerifyClsCompliance (Parent);
                }
 
+               public bool InUnsafe {
+                       get {
+                               return ((ModFlags & Modifiers.UNSAFE) != 0) || Parent.UnsafeContext;
+                       }
+               }
+
                // 
                // Whehter is it ok to use an unsafe pointer in this type container
                //
@@ -671,8 +677,9 @@ namespace Mono.CSharp {
                }
 
                // <summary>
-               //    Looks up the type, as parsed into the expression `e' 
+               //    Looks up the type, as parsed into the expression `e'.
                // </summary>
+               //[Obsolete ("This method is going away soon")]
                public Type ResolveType (Expression e, bool silent, Location loc)
                {
                        TypeExpr d = ResolveTypeExpr (e, silent, loc);
@@ -718,7 +725,7 @@ namespace Mono.CSharp {
 
                // <summary>
                //    Resolves the expression `e' for a type, and will recursively define
-               //    types. 
+               //    types.  This should only be used for resolving base types.
                // </summary>
                public TypeExpr ResolveTypeExpr (Expression e, bool silent, Location loc)
                {
index 617f4bc15610148790e2b615ab3890db215640bc..e29f5754564c102796a3d5ec9a5e648911290932 100644 (file)
@@ -213,7 +213,7 @@ namespace Mono.CSharp {
                                        return false;
                        }
                        
-                       ReturnType = ResolveTypeExpr (ReturnType, false, Location);
+                       ReturnType = ReturnType.ResolveAsTypeTerminal (ec, false);
                         if (ReturnType == null)
                             return false;
                         
index d6a77eabc5d37b0379a660445ccb259ee920a8a7..b33dbf950a5fd59f628bdecf929333871e993a11 100755 (executable)
@@ -2097,10 +2097,10 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       //
-                       // First, the using aliases
-                       //
-                       if (alias_value != null){
+                       if ((t = RootContext.LookupType (ds, Name, true, loc)) != null)
+                               return t;
+
+                       if (alias_value != null) {
                                if (alias_value.IsType)
                                        return alias_value.Type;
                                if ((t = RootContext.LookupType (ds, alias_value.Name, true, loc)) != null)
@@ -2110,14 +2110,6 @@ namespace Mono.CSharp {
                                return new SimpleName (alias_value.Name, loc);
                        }
 
-                       //
-                       // Stage 2: Lookup up if we are an alias to a type
-                       // or a namespace.
-                       //
-
-                       if ((t = RootContext.LookupType (ds, Name, true, loc)) != null)
-                               return t;
-                               
                        // No match, maybe our parent can compose us
                        // into something meaningful.
                        return this;
@@ -2339,7 +2331,7 @@ namespace Mono.CSharp {
 
                override public Expression DoResolve (EmitContext ec)
                {
-                       return ResolveAsTypeTerminal (ec, true);
+                       return ResolveAsTypeTerminal (ec, false);
                }
 
                override public void Emit (EmitContext ec)
index 72d437c0e45ce32c4c907e045f0b93e3fe15a863..db2585e571253dfe89c1fc86d0d7f4793d054524 100755 (executable)
@@ -6409,11 +6409,12 @@ namespace Mono.CSharp {
                        //
                        Expression array_type_expr;
                        array_type_expr = new ComposedCast (requested_base_type, array_qualifier.ToString (), loc);
-                       type = ec.DeclSpace.ResolveType (array_type_expr, false, loc);
-
-                       if (type == null)
+                       array_type_expr = array_type_expr.ResolveAsTypeTerminal (ec, false);
+                       if (array_type_expr == null)
                                return false;
 
+                       type = array_type_expr.Type;
+                       
                        if (!type.IsArray) {
                                Error (622, "Can only use array initializer expressions to assign to array types. Try using a new expression instead.");
                                return false;
@@ -7201,8 +7202,8 @@ namespace Mono.CSharp {
                                return null;
                        }
                                
-                       QueriedType = ec.DeclSpace.ResolveTypeExpr (QueriedType, false, loc);
-                       if (QueriedType == null || QueriedType.Type == null)
+                       QueriedType = QueriedType.ResolveAsTypeTerminal (ec, false);
+                       if (QueriedType == null)
                                return null;
 
                        if (QueriedType is TypeParameterExpr){
@@ -7211,8 +7212,6 @@ namespace Mono.CSharp {
                        }
 
                        type_queried = QueriedType.Type;
-                       if (type_queried == null)
-                               return null;
 
                        CheckObsoleteAttribute (type_queried);
 
@@ -8855,10 +8854,12 @@ namespace Mono.CSharp {
 
                public override TypeExpr DoResolveAsTypeStep (EmitContext ec)
                {
-                       Type ltype = ec.DeclSpace.ResolveType (left, false, loc);
-                       if (ltype == null)
+                       left = left.ResolveAsTypeTerminal (ec, false);
+                       if (left == null)
                                return null;
 
+                       Type ltype = left.Type;
+
                        if ((ltype == TypeManager.void_type) && (dim != "*")) {
                                Report.Error (1547, Location,
                                              "Keyword 'void' cannot be used in this context");
@@ -9050,11 +9051,12 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       otype = ec.DeclSpace.ResolveType (t, false, loc);
-
-                       if (otype == null)
+                       t = t.ResolveAsTypeTerminal (ec, false);
+                       if (t == null)
                                return null;
 
+                       otype = t.Type;
+
                        if (!TypeManager.VerifyUnManaged (otype, loc))
                                return null;
 
index 21588d856f16ad44c9a2e585803d78a692867504..25a918997d0b2b81e7fc46a142eb51b9ac38626c 100755 (executable)
@@ -1010,8 +1010,14 @@ namespace Mono.CSharp {
 
                public bool Resolve (EmitContext ec)
                {
-                       if (VariableType == null)
-                               VariableType = ec.DeclSpace.ResolveType (Type, false, Location);
+                       if (VariableType == null) {
+                               Type = Type.ResolveAsTypeTerminal (ec, false);
+
+                               if (Type == null)
+                                       return false;
+                               
+                               VariableType = Type.Type;
+                       }
 
                        if (VariableType == TypeManager.void_type) {
                                Report.Error (1547, Location,
@@ -1019,9 +1025,6 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       if (VariableType == null)
-                               return false;
-
                        if (VariableType.IsAbstract && VariableType.IsSealed) {
                                Report.Error (723, Location, "Cannot declare variable of static type '{0}'", TypeManager.CSharpName (VariableType));
                                return false;
@@ -1119,7 +1122,8 @@ namespace Mono.CSharp {
                        VariablesInitialized = 8,
                        HasRet = 16,
                        IsDestructor = 32,
-                       HasVarargs = 64 
+                       HasVarargs = 64,
+                       Unsafe = 128,
                }
                Flags flags;
 
@@ -1138,6 +1142,15 @@ namespace Mono.CSharp {
                        }
                }
 
+               public bool Unsafe {
+                       get {
+                               return (flags & Flags.Unsafe) != 0;
+                       }
+                       set {
+                               flags |= Flags.Unsafe;
+                       }
+               }
+
                public bool HasVarargs {
                        get {
                                if (Parent != null)
@@ -1642,6 +1655,12 @@ namespace Mono.CSharp {
                {
                        ILGenerator ig = ec.ig;
 
+                       bool old_unsafe = ec.InUnsafe;
+
+                       // If some parent block was unsafe, we remain unsafe even if this block
+                       // isn't explicitly marked as such.
+                       ec.InUnsafe |= Unsafe;
+
                        //
                        // Compute the VariableMap's.
                        //
@@ -1745,6 +1764,8 @@ namespace Mono.CSharp {
                                foreach (Block b in children)
                                        b.EmitMeta (ec, ip);
                        }
+
+                       ec.InUnsafe = old_unsafe;
                }
 
                void UsageWarning (FlowBranching.UsageVector vector)
@@ -2973,6 +2994,7 @@ namespace Mono.CSharp {
                public Unsafe (Block b)
                {
                        Block = b;
+                       Block.Unsafe = true;
                }
 
                public override bool Resolve (EmitContext ec)
@@ -3030,10 +3052,12 @@ namespace Mono.CSharp {
                                return false;
                        }
                        
-                       expr_type = ec.DeclSpace.ResolveType (type, false, loc);
-                       if (expr_type == null)
+                       type = type.ResolveAsTypeTerminal (ec, false);
+                       if (type == null)
                                return false;
 
+                       expr_type = type.Type;
+
                        CheckObsolete (expr_type);
 
                        if (ec.RemapToProxy){
@@ -3297,10 +3321,12 @@ namespace Mono.CSharp {
                public override bool Resolve (EmitContext ec)
                {
                        if (type_expr != null) {
-                               type = ec.DeclSpace.ResolveType (type_expr, false, loc);
-                               if (type == null)
+                               TypeExpr te = type_expr.ResolveAsTypeTerminal (ec, false);
+                               if (te == null)
                                        return false;
 
+                               type = te.Type;
+
                                CheckObsolete (type);
 
                                if (type != TypeManager.exception_type && !type.IsSubclassOf (TypeManager.exception_type)){
@@ -3499,12 +3525,14 @@ namespace Mono.CSharp {
                //
                bool ResolveLocalVariableDecls (EmitContext ec)
                {
-                       expr_type = ec.DeclSpace.ResolveType (expr, false, loc);
                        int i = 0;
 
-                       if (expr_type == null)
+                       expr = expr.ResolveAsTypeTerminal (ec, false);
+                       if (expr == null)
                                return false;
 
+                       expr_type = expr.Type;
+
                        //
                        // The type must be an IDisposable or an implicit conversion
                        // must exist.
@@ -3774,9 +3802,11 @@ namespace Mono.CSharp {
                        if (expr == null)
                                return false;
 
-                       var_type = ec.DeclSpace.ResolveType (type, false, loc);
-                       if (var_type == null)
+                       type = type.ResolveAsTypeTerminal (ec, false);
+                       if (type == null)
                                return false;
+
+                       var_type = type.Type;
                        
                        //
                        // We need an instance variable.  Not sure this is the best