Fixes cloning of a variable declarator.
[mono.git] / mcs / mcs / context.cs
index 2d89d2b9a2eb03d42c3c9c42e6982e38deb9fb95..33a003430be97e60c3f95d40b2046f0789e54ece 100644 (file)
@@ -44,7 +44,7 @@ namespace Mono.CSharp
 
                string GetSignatureForError ();
 
-               ExtensionMethodGroupExpr LookupExtensionMethod (TypeSpec extensionType, string name, int arity, Location loc);
+               IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceEntry scope);
                FullNamedExpression LookupNamespaceOrType (string name, int arity, Location loc, bool ignore_cs0104);
                FullNamedExpression LookupNamespaceAlias (string name);
 
@@ -58,8 +58,6 @@ namespace Mono.CSharp
        {
                FlowBranching current_flow_branching;
 
-               public TypeInferenceContext ReturnTypeInference;
-
                TypeSpec return_type;
 
                /// <summary>
@@ -73,6 +71,8 @@ namespace Mono.CSharp
                /// </summary>
                public bool HasReturnLabel;
 
+               public int FlowOffset;
+
                public BlockContext (IMemberContext mc, ExplicitBlock block, TypeSpec returnType)
                        : base (mc)
                {
@@ -85,6 +85,16 @@ namespace Mono.CSharp
                        CurrentBlock = block;
                }
 
+               public BlockContext (ResolveContext rc, ExplicitBlock block, TypeSpec returnType)
+                       : this (rc.MemberContext, block, returnType)
+               {
+                       if (rc.IsUnsafe)
+                               flags |= ResolveContext.Options.UnsafeScope;
+
+                       if (rc.HasSet (ResolveContext.Options.CheckedScope))
+                               flags |= ResolveContext.Options.CheckedScope;
+               }
+
                public override FlowBranching CurrentBranching {
                        get { return current_flow_branching; }
                }
@@ -132,14 +142,14 @@ namespace Mono.CSharp
                        return branching;
                }
 
-               public FlowBranchingIterator StartFlowBranching (Iterator iterator)
+               public FlowBranchingIterator StartFlowBranching (Iterator iterator, FlowBranching parent)
                {
-                       FlowBranchingIterator branching = new FlowBranchingIterator (CurrentBranching, iterator);
+                       FlowBranchingIterator branching = new FlowBranchingIterator (parent, iterator);
                        current_flow_branching = branching;
                        return branching;
                }
 
-               public FlowBranchingToplevel StartFlowBranching (ToplevelBlock stmt, FlowBranching parent)
+               public FlowBranchingToplevel StartFlowBranching (ParametersBlock stmt, FlowBranching parent)
                {
                        FlowBranchingToplevel branching = new FlowBranchingToplevel (parent, stmt);
                        current_flow_branching = branching;
@@ -238,6 +248,8 @@ namespace Mono.CSharp
 
                        ConstructorScope = 1 << 11,
 
+                       UsingInitializerScope = 1 << 12,
+
                        /// <summary>
                        ///   Whether control flow analysis is enabled
                        /// </summary>
@@ -300,7 +312,7 @@ namespace Mono.CSharp
                        }
                }
 
-               Options flags;
+               protected Options flags;
 
                //
                // Whether we are inside an anonymous method.
@@ -350,6 +362,12 @@ namespace Mono.CSharp
                        get { return MemberContext.Compiler; }
                }
 
+               public virtual ExplicitBlock ConstructorBlock {
+                       get {
+                               return CurrentBlock.Explicit;
+                       }
+               }
+
                public virtual FlowBranching CurrentBranching {
                        get { return null; }
                }
@@ -407,7 +425,7 @@ namespace Mono.CSharp
                        return my_this;
                }
 
-               public bool MustCaptureVariable (LocalInfo local)
+               public bool MustCaptureVariable (INamedBlockVariable local)
                {
                        if (CurrentAnonymousMethod == null)
                                return false;
@@ -417,7 +435,7 @@ namespace Mono.CSharp
                        if (CurrentAnonymousMethod.IsIterator)
                                return true;
 
-                       return local.Block.Toplevel != CurrentBlock.Toplevel;
+                       return local.Block.ParametersBlock != CurrentBlock.ParametersBlock.Original;
                }
 
                public bool HasSet (Options options)
@@ -457,7 +475,7 @@ namespace Mono.CSharp
                public bool IsObsolete {
                        get {
                                // Disables obsolete checks when probing is on
-                               return IsInProbingMode || MemberContext.IsObsolete;
+                               return MemberContext.IsObsolete;
                        }
                }
 
@@ -469,9 +487,9 @@ namespace Mono.CSharp
                        get { return HasSet (Options.UnsafeScope) || MemberContext.IsUnsafe; }
                }
 
-               public ExtensionMethodGroupExpr LookupExtensionMethod (TypeSpec extensionType, string name, int arity, Location loc)
+               public IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceEntry scope)
                {
-                       return MemberContext.LookupExtensionMethod (extensionType, name, arity, loc);
+                       return MemberContext.LookupExtensionMethod (extensionType, name, arity, ref scope);
                }
 
                public FullNamedExpression LookupNamespaceOrType (string name, int arity, Location loc, bool ignore_cs0104)
@@ -498,13 +516,10 @@ namespace Mono.CSharp
        public class CloneContext
        {
                Dictionary<Block, Block> block_map = new Dictionary<Block, Block> ();
-               Dictionary<LocalInfo, LocalInfo> variable_map;
 
                public void AddBlockMap (Block from, Block to)
                {
-                       if (block_map.ContainsKey (from))
-                               return;
-                       block_map[from] = to;
+                       block_map.Add (from, to);
                }
 
                public Block LookupBlock (Block from)
@@ -512,7 +527,6 @@ namespace Mono.CSharp
                        Block result;
                        if (!block_map.TryGetValue (from, out result)) {
                                result = (Block) from.Clone (this);
-                               block_map [from] = result;
                        }
 
                        return result;
@@ -529,25 +543,6 @@ namespace Mono.CSharp
 
                        return mapped_to;
                }
-
-               public void AddVariableMap (LocalInfo from, LocalInfo to)
-               {
-                       if (variable_map == null)
-                               variable_map = new Dictionary<LocalInfo, LocalInfo> ();
-                       else if (variable_map.ContainsKey (from))
-                               return;
-
-                       variable_map[from] = to;
-               }
-
-               public LocalInfo LookupVariable (LocalInfo from)
-               {
-                       try {
-                               return variable_map[from];
-                       } catch (KeyNotFoundException) {
-                               throw new Exception ("LookupVariable: looking up a variable that has not been registered yet");
-                       }
-               }
        }
 
        //
@@ -556,21 +551,44 @@ namespace Mono.CSharp
        public class CompilerContext
        {
                readonly Report report;
+               readonly ReflectionMetaImporter meta_importer;
+               readonly PredefinedAttributes attributes;
+               readonly GlobalRootNamespace root;
 
-               public CompilerContext (Report report)
+               public CompilerContext (ReflectionMetaImporter metaImporter, Report report)
                {
+                       this.meta_importer = metaImporter;
                        this.report = report;
+
+                       this.attributes = new PredefinedAttributes ();
+                       this.root = new GlobalRootNamespace ();
+               }
+
+               public GlobalRootNamespace GlobalRootNamespace {
+                       get {
+                               return root;
+                       }
                }
 
                public bool IsRuntimeBinder { get; set; }
 
-               public Report Report {
-                       get { return report; }
+               public ReflectionMetaImporter MetaImporter {
+                       get {
+                               return meta_importer;
+                       }
+               }
+
+               public PredefinedAttributes PredefinedAttributes {
+                       get {
+                               return attributes;
+                       }
                }
 
-               //public PredefinedAttributes PredefinedAttributes {
-               //    get { throw new NotImplementedException (); }
-               //}
+               public Report Report {
+                       get {
+                               return report;
+                       }
+               }
        }
 
        //