Fixes cloning of a variable declarator.
[mono.git] / mcs / mcs / context.cs
index 8a56cdcfb4953552dea7e1a60947d7206f286eb0..33a003430be97e60c3f95d40b2046f0789e54ece 100644 (file)
@@ -24,7 +24,7 @@ namespace Mono.CSharp
                //
                // A scope type context, it can be inflated for generic types
                //
-               Type CurrentType { get; }
+               TypeSpec CurrentType { get; }
 
                //
                // A scope type parameters either VAR or MVAR
@@ -32,21 +32,20 @@ namespace Mono.CSharp
                TypeParameter[] CurrentTypeParameters { get; }
 
                //
-               // A type definition of the type context. For partial types definition use
+               // A member definition of the context. For partial types definition use
                // CurrentTypeDefinition.PartialContainer otherwise the context is local
                //
-               // TODO: CurrentType.Definition
-               //
-               TypeContainer CurrentTypeDefinition { get; }
+               MemberCore CurrentMemberDefinition { get; }
 
                bool IsObsolete { get; }
                bool IsUnsafe { get; }
                bool IsStatic { get; }
+               bool HasUnresolvedConstraints { get; }
 
                string GetSignatureForError ();
 
-               ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc);
-               FullNamedExpression LookupNamespaceOrType (string name, Location loc, bool ignore_cs0104);
+               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);
 
                CompilerContext Compiler { get; }
@@ -59,9 +58,7 @@ namespace Mono.CSharp
        {
                FlowBranching current_flow_branching;
 
-               public TypeInferenceContext ReturnTypeInference;
-
-               Type return_type;
+               TypeSpec return_type;
 
                /// <summary>
                ///   The location where return has to jump to return the
@@ -74,7 +71,9 @@ namespace Mono.CSharp
                /// </summary>
                public bool HasReturnLabel;
 
-               public BlockContext (IMemberContext mc, ExplicitBlock block, Type returnType)
+               public int FlowOffset;
+
+               public BlockContext (IMemberContext mc, ExplicitBlock block, TypeSpec returnType)
                        : base (mc)
                {
                        if (returnType == null)
@@ -86,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; }
                }
@@ -133,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;
@@ -180,7 +189,7 @@ namespace Mono.CSharp
                                HasReturnLabel = true;
                }
 
-               public Type ReturnType {
+               public TypeSpec ReturnType {
                        get { return return_type; }
                }
        }
@@ -239,6 +248,8 @@ namespace Mono.CSharp
 
                        ConstructorScope = 1 << 11,
 
+                       UsingInitializerScope = 1 << 12,
+
                        /// <summary>
                        ///   Whether control flow analysis is enabled
                        /// </summary>
@@ -301,7 +312,7 @@ namespace Mono.CSharp
                        }
                }
 
-               Options flags;
+               protected Options flags;
 
                //
                // Whether we are inside an anonymous method.
@@ -351,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; }
                }
@@ -362,7 +379,7 @@ namespace Mono.CSharp
                        get { return CurrentAnonymousMethod as Iterator; }
                }
 
-               public Type CurrentType {
+               public TypeSpec CurrentType {
                        get { return MemberContext.CurrentType; }
                }
 
@@ -370,8 +387,8 @@ namespace Mono.CSharp
                        get { return MemberContext.CurrentTypeParameters; }
                }
 
-               public TypeContainer CurrentTypeDefinition {
-                       get { return MemberContext.CurrentTypeDefinition; }
+               public MemberCore CurrentMemberDefinition {
+                       get { return MemberContext.CurrentMemberDefinition; }
                }
 
                public bool ConstantCheckState {
@@ -382,6 +399,10 @@ namespace Mono.CSharp
                        get { return (flags & Options.DoFlowAnalysis) != 0; }
                }
 
+               public bool HasUnresolvedConstraints {
+                       get { return false; }
+               }
+
                public bool IsInProbingMode {
                        get { return (flags & Options.ProbingMode) != 0; }
                }
@@ -399,19 +420,12 @@ namespace Mono.CSharp
                // TODO: Merge with CompilerGeneratedThis
                public Expression GetThis (Location loc)
                {
-                       This my_this;
-                       if (CurrentBlock != null)
-                               my_this = new This (CurrentBlock, loc);
-                       else
-                               my_this = new This (loc);
-
-                       if (!my_this.ResolveBase (this))
-                               my_this = null;
-
+                       This my_this = new This (loc);
+                       my_this.ResolveBase (this);
                        return my_this;
                }
 
-               public bool MustCaptureVariable (LocalInfo local)
+               public bool MustCaptureVariable (INamedBlockVariable local)
                {
                        if (CurrentAnonymousMethod == null)
                                return false;
@@ -421,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)
@@ -461,7 +475,7 @@ namespace Mono.CSharp
                public bool IsObsolete {
                        get {
                                // Disables obsolete checks when probing is on
-                               return IsInProbingMode || MemberContext.IsObsolete;
+                               return MemberContext.IsObsolete;
                        }
                }
 
@@ -473,14 +487,14 @@ namespace Mono.CSharp
                        get { return HasSet (Options.UnsafeScope) || MemberContext.IsUnsafe; }
                }
 
-               public ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
+               public IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceEntry scope)
                {
-                       return MemberContext.LookupExtensionMethod (extensionType, name, loc);
+                       return MemberContext.LookupExtensionMethod (extensionType, name, arity, ref scope);
                }
 
-               public FullNamedExpression LookupNamespaceOrType (string name, Location loc, bool ignore_cs0104)
+               public FullNamedExpression LookupNamespaceOrType (string name, int arity, Location loc, bool ignore_cs0104)
                {
-                       return MemberContext.LookupNamespaceOrType (name, loc, ignore_cs0104);
+                       return MemberContext.LookupNamespaceOrType (name, arity, loc, ignore_cs0104);
                }
 
                public FullNamedExpression LookupNamespaceAlias (string name)
@@ -502,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)
@@ -516,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;
@@ -533,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");
-                       }
-               }
        }
 
        //
@@ -560,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;
+                       }
+               }
        }
 
        //