2009-08-18 Marek Safar <marek.safar@gmail.com>
authorMarek Safar <marek.safar@gmail.com>
Tue, 18 Aug 2009 16:23:08 +0000 (16:23 -0000)
committerMarek Safar <marek.safar@gmail.com>
Tue, 18 Aug 2009 16:23:08 +0000 (16:23 -0000)
* *.cs: Add IResolveContext::IsStatic.

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

mcs/mcs/ChangeLog
mcs/mcs/anonymous.cs
mcs/mcs/assign.cs
mcs/mcs/class.cs
mcs/mcs/codegen.cs
mcs/mcs/decl.cs
mcs/mcs/ecore.cs
mcs/mcs/expression.cs
mcs/mcs/namespace.cs

index 3de4e672387788fc11b6a3102d11e0c9f3b2d35b..79d05bf461bf77c02fdfd66479992c6fb3f4641f 100644 (file)
@@ -1,3 +1,7 @@
+2009-08-18  Marek Safar  <marek.safar@gmail.com>
+
+       * *.cs: Add IResolveContext::IsStatic.
+
 2009-08-18  Marek Safar  <marek.safar@gmail.com>
 
        * *.cs: Moved TopBlock's methods from EmitContext to TopBlock.
index 9df82e265059509188ab644a290d2f8cff3489a1..35a336ed9aae7e731f2a249ca1d1f0600d0429bb 100644 (file)
@@ -1223,7 +1223,7 @@ namespace Mono.CSharp {
                        {
                                EmitContext aec = AnonymousMethod.aec;
                                aec.ig = ig;
-                               aec.IsStatic = (ModFlags & Modifiers.STATIC) != 0;
+                               aec.AnonymousStatic = (ModFlags & Modifiers.STATIC) != 0;
                                return aec;
                        }
 
@@ -1303,7 +1303,6 @@ namespace Mono.CSharp {
                                (ec.InUnsafe ? Modifiers.UNSAFE : 0), /* No constructor */ false);
 
                        aec.CurrentAnonymousMethod = this;
-                       aec.IsStatic = ec.IsStatic;
 
                        IDisposable aec_dispose = null;
                        EmitContext.Flags flags = 0;
index 537bc0e8505af92414250df9e365c11996349197..de5c2c68dcce19440c551798f209ecba9cff7111 100644 (file)
@@ -487,7 +487,6 @@ namespace Mono.CSharp {
 
                                // TODO: Use ResolveContext only
                                EmitContext f_ec = new EmitContext (rc, rc.GenericDeclContainer, null, TypeManager.void_type, 0, true);
-                               f_ec.IsStatic = ec.IsStatic;
                                f_ec.CurrentBlock = ec.CurrentBlock;
 
                                EmitContext.Flags flags = EmitContext.Flags.InFieldInitializer;
index a92660ae43cd38b87daf7c7bd2569b64df4ae389..e606c18031eff7ee36bc560574c421aa8aab12ef 100644 (file)
@@ -194,6 +194,10 @@ namespace Mono.CSharp {
                                get { return tc.IsInUnsafeScope; }
                        }
 
+                       public bool IsStatic {
+                               get { return tc.IsStatic; }
+                       }
+
                        public ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
                        {
                                return null;
@@ -2954,12 +2958,6 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               bool IsStatic {
-                       get {
-                               return (ModFlags & Modifiers.STATIC) != 0;
-                       }
-               }
-
                //
                // FIXME: How do we deal with the user specifying a different
                // layout?
@@ -4508,9 +4506,9 @@ namespace Mono.CSharp {
                                //
                                // Spec mandates that constructor initializer will not have `this' access
                                //
-                               ec.IsStatic = true;
-                               argument_list.Resolve (ec, out dynamic);
-                               ec.IsStatic = false;
+                               using (ec.Set (EmitContext.Flags.BaseInitializer)) {
+                                       argument_list.Resolve (ec, out dynamic);
+                               }
 
                                if (dynamic) {
                                        SimpleName ctor = new SimpleName (ConstructorBuilder.ConstructorName, loc);
index 39a0cf21724d01f181d83966c894c2a72f81bb6d..b6ac98c401d3211bb5d47e4217bbec887501701f 100644 (file)
@@ -273,6 +273,7 @@ namespace Mono.CSharp {
 
                bool IsInObsoleteScope { get; }
                bool IsInUnsafeScope { get; }
+               bool IsStatic { get; }
 
                ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc);
                FullNamedExpression LookupNamespaceOrType (string name, Location loc, bool ignore_cs0104);
@@ -358,16 +359,13 @@ namespace Mono.CSharp {
                        
                        InCompoundAssignment = 1 << 10,
 
-                       OmitDebuggingInfo = 1 << 11
+                       OmitDebuggingInfo = 1 << 11,
+
+                       BaseInitializer = 1 << 12
                }
 
                Flags flags;
 
-               /// <summary>
-               ///   Whether we are emitting code inside a static or instance method
-               /// </summary>
-               public bool IsStatic;
-
                /// <summary>
                ///   The value that is allowed to be returned or NULL if there is no
                ///   return type.
@@ -454,7 +452,6 @@ namespace Mono.CSharp {
                        if (return_type == null)
                                throw new ArgumentNullException ("return_type");
 
-                       IsStatic = (code_flags & Modifiers.STATIC) != 0;
                        ReturnType = return_type;
                        IsConstructor = is_constructor;
                }
@@ -590,6 +587,12 @@ namespace Mono.CSharp {
                        get { return (flags & Flags.InUnsafe) != 0 || ResolveContext.IsInUnsafeScope; }
                }
 
+               // TODO: Hopefully temporary hack for anonyous methods, ResolveContext != EmitContext
+               public object AnonymousStatic;
+               public bool IsStatic {
+                       get { return AnonymousStatic != null ? (bool) AnonymousStatic : ResolveContext.IsStatic; }
+               }
+
                public bool IsAnonymousMethodAllowed {
                        get { return isAnonymousMethodAllowed; }
                        set { isAnonymousMethodAllowed = value; }
@@ -598,6 +601,10 @@ namespace Mono.CSharp {
                public bool IsInFieldInitializer {
                        get { return (flags & Flags.InFieldInitializer) != 0; }
                }
+
+               public bool IsBaseInitializer {
+                       get { return (flags & Flags.BaseInitializer) != 0; }
+               }
                
                public bool IsInCompoundAssignment {
                        get { return (flags & Flags.InCompoundAssignment) != 0; }
@@ -953,6 +960,10 @@ namespace Mono.CSharp {
                        get { return false; }
                }
 
+               public bool IsStatic {
+                       get { return false; }
+               }
+
                public ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
                {
                        throw new NotImplementedException ();
index a139ca85058f901c03249f0e823d16454d3d3f12..d5f99de68ff996e9ee38952b3cfe712db41ff214 100644 (file)
@@ -858,6 +858,10 @@ namespace Mono.CSharp {
                        }
                }
 
+               public bool IsStatic {
+                       get { return (ModFlags & Modifiers.STATIC) != 0; }
+               }
+
                #endregion
        }
 
index 55fda9b9df90621f27a0092d1259907bb810c1d4..a1c865d46d564e42eb5a2b03e6262ce3377fa16e 100644 (file)
@@ -2766,7 +2766,7 @@ namespace Mono.CSharp {
 
                                Expression left;
                                if (me.IsInstance) {
-                                       if (ec.IsStatic || ec.IsInFieldInitializer) {
+                                       if (ec.IsStatic || ec.IsInFieldInitializer || ec.IsBaseInitializer) {
                                                //
                                                // Note that an MemberExpr can be both IsInstance and IsStatic.
                                                // An unresolved MethodGroupExpr can contain both kinds of methods
index 596eadb273ab7beb2b4dd41a91a2d1980d2d04ed..babf7f3e81e7ac28b8c0078b4b9ce86fd4c795d6 100644 (file)
@@ -6583,7 +6583,7 @@ namespace Mono.CSharp {
 
                public static bool IsThisAvailable (EmitContext ec)
                {
-                       if (ec.IsStatic || ec.IsInFieldInitializer)
+                       if (ec.IsStatic || ec.IsInFieldInitializer || ec.IsBaseInitializer)
                                return false;
 
                        if (ec.CurrentAnonymousMethod == null)
@@ -6606,10 +6606,12 @@ namespace Mono.CSharp {
                        if (!IsThisAvailable (ec)) {
                                if (ec.IsStatic) {
                                        Error (26, "Keyword `this' is not valid in a static property, static method, or static field initializer");
-                               } else {
+                               } else if (ec.CurrentAnonymousMethod != null) {
                                        Report.Error (1673, loc,
                                                "Anonymous methods inside structs cannot access instance members of `this'. " +
                                                "Consider copying `this' to a local variable outside the anonymous method and using the local instead");
+                               } else {
+                                       Error (27, "Keyword `this' is not available in the current context");
                                }
                        }
 
@@ -6653,15 +6655,7 @@ namespace Mono.CSharp {
                
                public override Expression DoResolve (EmitContext ec)
                {
-                       if (!ResolveBase (ec))
-                               return null;
-
-
-                       if (ec.IsInFieldInitializer) {
-                               Error (27, "Keyword `this' is not available in the current context");
-                               return null;
-                       }
-                       
+                       ResolveBase (ec);
                        return this;
                }
 
index 37acce92fe30bbd6b7399a9f36bea837acc8a7d7..d1bbf22cd3826dd7afeaee03d4ee07b152bb6e1e 100644 (file)
@@ -1335,6 +1335,10 @@ namespace Mono.CSharp {
                        get { return SlaveDeclSpace.IsInUnsafeScope; }
                }
 
+               public bool IsStatic {
+                       get { return SlaveDeclSpace.IsStatic; }
+               }
+
                public DeclSpace GenericDeclContainer {
                        get { return SlaveDeclSpace; }
                }