Add initial reflection dependant code
[mono.git] / mcs / mcs / context.cs
index 4e02e315b4623166238974104027e8bc9b05b631..bdbbf885a0b736422ad0f199ae193e86600be807 100644 (file)
@@ -10,7 +10,7 @@
 //
 
 using System;
-using System.Collections;
+using System.Collections.Generic;
 using System.Reflection.Emit;
 
 namespace Mono.CSharp
@@ -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,22 @@ 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
+               // TODO: Obsolete it in this context, dynamic context cannot guarantee sensible value
                //
-               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 +60,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 +73,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 +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; }
                }
@@ -133,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;
@@ -180,7 +191,7 @@ namespace Mono.CSharp
                                HasReturnLabel = true;
                }
 
-               public Type ReturnType {
+               public TypeSpec ReturnType {
                        get { return return_type; }
                }
        }
@@ -239,6 +250,8 @@ namespace Mono.CSharp
 
                        ConstructorScope = 1 << 11,
 
+                       UsingInitializerScope = 1 << 12,
+
                        /// <summary>
                        ///   Whether control flow analysis is enabled
                        /// </summary>
@@ -301,7 +314,7 @@ namespace Mono.CSharp
                        }
                }
 
-               Options flags;
+               protected Options flags;
 
                //
                // Whether we are inside an anonymous method.
@@ -351,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; }
                }
@@ -362,7 +381,7 @@ namespace Mono.CSharp
                        get { return CurrentAnonymousMethod as Iterator; }
                }
 
-               public Type CurrentType {
+               public TypeSpec CurrentType {
                        get { return MemberContext.CurrentType; }
                }
 
@@ -370,8 +389,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 +401,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; }
                }
@@ -396,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;
@@ -421,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)
@@ -461,7 +469,7 @@ namespace Mono.CSharp
                public bool IsObsolete {
                        get {
                                // Disables obsolete checks when probing is on
-                               return IsInProbingMode || MemberContext.IsObsolete;
+                               return MemberContext.IsObsolete;
                        }
                }
 
@@ -473,14 +481,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)
@@ -501,23 +509,18 @@ namespace Mono.CSharp
        //
        public class CloneContext
        {
-               Hashtable block_map = new Hashtable ();
-               Hashtable variable_map;
+               Dictionary<Block, Block> block_map = new Dictionary<Block, Block> ();
 
                public void AddBlockMap (Block from, Block to)
                {
-                       if (block_map.Contains (from))
-                               return;
-                       block_map[from] = to;
+                       block_map.Add (from, to);
                }
 
                public Block LookupBlock (Block from)
                {
-                       Block result = (Block) block_map[from];
-
-                       if (result == null) {
+                       Block result;
+                       if (!block_map.TryGetValue (from, out result)) {
                                result = (Block) from.Clone (this);
-                               block_map[from] = result;
                        }
 
                        return result;
@@ -528,32 +531,12 @@ namespace Mono.CSharp
                ///
                public Block RemapBlockCopy (Block from)
                {
-                       Block mapped_to = (Block) block_map[from];
-                       if (mapped_to == null)
+                       Block mapped_to;
+                       if (!block_map.TryGetValue (from, out mapped_to))
                                return from;
 
                        return mapped_to;
                }
-
-               public void AddVariableMap (LocalInfo from, LocalInfo to)
-               {
-                       if (variable_map == null)
-                               variable_map = new Hashtable ();
-
-                       if (variable_map.Contains (from))
-                               return;
-                       variable_map[from] = to;
-               }
-
-               public LocalInfo LookupVariable (LocalInfo from)
-               {
-                       LocalInfo result = (LocalInfo) variable_map[from];
-
-                       if (result == null)
-                               throw new Exception ("LookupVariable: looking up a variable that has not been registered yet");
-
-                       return result;
-               }
        }
 
        //
@@ -562,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
        }
 
        //