Add initial reflection dependant code
[mono.git] / mcs / mcs / context.cs
index 006c66cb60cf72a175c595df8cc7b8486bf82c41..bdbbf885a0b736422ad0f199ae193e86600be807 100644 (file)
@@ -35,6 +35,8 @@ namespace Mono.CSharp
                // A member definition of the context. For partial types definition use
                // CurrentTypeDefinition.PartialContainer otherwise the context is local
                //
+               // TODO: Obsolete it in this context, dynamic context cannot guarantee sensible value
+               //
                MemberCore CurrentMemberDefinition { get; }
 
                bool IsObsolete { get; }
@@ -44,7 +46,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 +60,6 @@ namespace Mono.CSharp
        {
                FlowBranching current_flow_branching;
 
-               public TypeInferenceContext ReturnTypeInference;
-
                TypeSpec return_type;
 
                /// <summary>
@@ -73,6 +73,8 @@ namespace Mono.CSharp
                /// </summary>
                public bool HasReturnLabel;
 
+               public int FlowOffset;
+
                public BlockContext (IMemberContext mc, ExplicitBlock block, TypeSpec returnType)
                        : base (mc)
                {
@@ -85,6 +87,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 +144,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 +250,8 @@ namespace Mono.CSharp
 
                        ConstructorScope = 1 << 11,
 
+                       UsingInitializerScope = 1 << 12,
+
                        /// <summary>
                        ///   Whether control flow analysis is enabled
                        /// </summary>
@@ -300,7 +314,7 @@ namespace Mono.CSharp
                        }
                }
 
-               Options flags;
+               protected Options flags;
 
                //
                // Whether we are inside an anonymous method.
@@ -350,6 +364,12 @@ namespace Mono.CSharp
                        get { return MemberContext.Compiler; }
                }
 
+               public virtual ExplicitBlock ConstructorBlock {
+                       get {
+                               return CurrentBlock.Explicit;
+                       }
+               }
+
                public virtual FlowBranching CurrentBranching {
                        get { return null; }
                }
@@ -399,22 +419,7 @@ namespace Mono.CSharp
                        get { return (flags & Options.OmitStructFlowAnalysis) != 0; }
                }
 
-               // 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;
-
-                       return my_this;
-               }
-
-               public bool MustCaptureVariable (LocalInfo local)
+               public bool MustCaptureVariable (INamedBlockVariable local)
                {
                        if (CurrentAnonymousMethod == null)
                                return false;
@@ -424,7 +429,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)
@@ -464,7 +469,7 @@ namespace Mono.CSharp
                public bool IsObsolete {
                        get {
                                // Disables obsolete checks when probing is on
-                               return IsInProbingMode || MemberContext.IsObsolete;
+                               return MemberContext.IsObsolete;
                        }
                }
 
@@ -476,9 +481,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)
@@ -505,13 +510,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)
@@ -519,7 +521,6 @@ namespace Mono.CSharp
                        Block result;
                        if (!block_map.TryGetValue (from, out result)) {
                                result = (Block) from.Clone (this);
-                               block_map [from] = result;
                        }
 
                        return result;
@@ -536,25 +537,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");
-                       }
-               }
        }
 
        //
@@ -563,21 +545,35 @@ namespace Mono.CSharp
        public class CompilerContext
        {
                readonly Report report;
+               readonly PredefinedAttributes attributes;
 
                public CompilerContext (Report report)
                {
                        this.report = report;
+
+                       this.attributes = new PredefinedAttributes ();
                }
 
+               #region Properties
+
+               // TODO: Obsolete, it has to go
+               public RootNamespace GlobalRootNamespace { get; set; }
+
                public bool IsRuntimeBinder { get; set; }
 
+               public PredefinedAttributes PredefinedAttributes {
+                       get {
+                               return attributes;
+                       }
+               }
+
                public Report Report {
-                       get { return report; }
+                       get {
+                               return report;
+                       }
                }
 
-               //public PredefinedAttributes PredefinedAttributes {
-               //    get { throw new NotImplementedException (); }
-               //}
+               #endregion
        }
 
        //