2010-07-14 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / mcs / context.cs
index e0f64bcd4c6707c7b17e9caeb0e33b021fce92aa..2d89d2b9a2eb03d42c3c9c42e6982e38deb9fb95 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,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);
+               ExtensionMethodGroupExpr LookupExtensionMethod (TypeSpec extensionType, string name, int arity, Location loc);
+               FullNamedExpression LookupNamespaceOrType (string name, int arity, Location loc, bool ignore_cs0104);
                FullNamedExpression LookupNamespaceAlias (string name);
 
                CompilerContext Compiler { get; }
@@ -61,7 +60,7 @@ namespace Mono.CSharp
 
                public TypeInferenceContext ReturnTypeInference;
 
-               Type return_type;
+               TypeSpec return_type;
 
                /// <summary>
                ///   The location where return has to jump to return the
@@ -74,7 +73,7 @@ namespace Mono.CSharp
                /// </summary>
                public bool HasReturnLabel;
 
-               public BlockContext (IMemberContext mc, ExplicitBlock block, Type returnType)
+               public BlockContext (IMemberContext mc, ExplicitBlock block, TypeSpec returnType)
                        : base (mc)
                {
                        if (returnType == null)
@@ -180,7 +179,7 @@ namespace Mono.CSharp
                                HasReturnLabel = true;
                }
 
-               public Type ReturnType {
+               public TypeSpec ReturnType {
                        get { return return_type; }
                }
        }
@@ -362,7 +361,7 @@ namespace Mono.CSharp
                        get { return CurrentAnonymousMethod as Iterator; }
                }
 
-               public Type CurrentType {
+               public TypeSpec CurrentType {
                        get { return MemberContext.CurrentType; }
                }
 
@@ -370,8 +369,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 +381,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,15 +402,8 @@ 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;
                }
 
@@ -451,14 +447,6 @@ namespace Mono.CSharp
                        return new FlagsHandle (this, options, enable ? options : 0);
                }
 
-               public FlagsHandle WithFlowAnalysis (bool do_flow_analysis, bool omit_struct_analysis)
-               {
-                       Options newflags =
-                               (do_flow_analysis ? Options.DoFlowAnalysis : 0) |
-                               (omit_struct_analysis ? Options.OmitStructFlowAnalysis : 0);
-                       return new FlagsHandle (this, Options.DoFlowAnalysis | Options.OmitStructFlowAnalysis, newflags);
-               }
-
                #region IMemberContext Members
 
                public string GetSignatureForError ()
@@ -481,14 +469,14 @@ namespace Mono.CSharp
                        get { return HasSet (Options.UnsafeScope) || MemberContext.IsUnsafe; }
                }
 
-               public ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
+               public ExtensionMethodGroupExpr LookupExtensionMethod (TypeSpec extensionType, string name, int arity, Location loc)
                {
-                       return MemberContext.LookupExtensionMethod (extensionType, name, loc);
+                       return MemberContext.LookupExtensionMethod (extensionType, name, arity, loc);
                }
 
-               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)
@@ -509,23 +497,22 @@ namespace Mono.CSharp
        //
        public class CloneContext
        {
-               Hashtable block_map = new Hashtable ();
-               Hashtable variable_map;
+               Dictionary<Block, Block> block_map = new Dictionary<Block, Block> ();
+               Dictionary<LocalInfo, LocalInfo> variable_map;
 
                public void AddBlockMap (Block from, Block to)
                {
-                       if (block_map.Contains (from))
+                       if (block_map.ContainsKey (from))
                                return;
                        block_map[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;
+                               block_map [from] = result;
                        }
 
                        return result;
@@ -536,8 +523,8 @@ 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;
@@ -546,21 +533,20 @@ namespace Mono.CSharp
                public void AddVariableMap (LocalInfo from, LocalInfo to)
                {
                        if (variable_map == null)
-                               variable_map = new Hashtable ();
-
-                       if (variable_map.Contains (from))
+                               variable_map = new Dictionary<LocalInfo, LocalInfo> ();
+                       else if (variable_map.ContainsKey (from))
                                return;
+
                        variable_map[from] = to;
                }
 
                public LocalInfo LookupVariable (LocalInfo from)
                {
-                       LocalInfo result = (LocalInfo) variable_map[from];
-
-                       if (result == null)
+                       try {
+                               return variable_map[from];
+                       } catch (KeyNotFoundException) {
                                throw new Exception ("LookupVariable: looking up a variable that has not been registered yet");
-
-                       return result;
+                       }
                }
        }