* enum.cs (Enum.DefineType): Set ec.InEnumContext and ec.ContainerType.
authorRaja R Harinath <harinath@hurrynot.org>
Fri, 25 Mar 2005 17:59:11 +0000 (17:59 -0000)
committerRaja R Harinath <harinath@hurrynot.org>
Fri, 25 Mar 2005 17:59:11 +0000 (17:59 -0000)
(Enum.current_ec): Remove.
(Enum.LookupEnumValue): Remove EmitContext argument.
Just uses the one created during DefineType.
(Enum.FindMembers): Update.
* expression.cs (MemberAccess.DoResolve): Update.

svn path=/trunk/mcs/; revision=42254

mcs/mcs/ChangeLog
mcs/mcs/enum.cs
mcs/mcs/expression.cs

index efca49fd9d64f45323cab0aee3aa45f3d481ce53..6f62fc9a02d96f43c599677884fc9552c1f388bc 100644 (file)
@@ -1,11 +1,21 @@
+2005-03-25  Raja R Harinath  <harinath@acm.org>
+
+       * enum.cs (Enum.DefineType): Set ec.InEnumContext and
+       ec.ContainerType.
+       (Enum.current_ec): Remove.
+       (Enum.LookupEnumValue): Remove EmitContext argument.
+       Just uses the one created during DefineType.
+       (Enum.FindMembers): Update.
+       * expression.cs (MemberAccess.DoResolve): Update.
+
 2005-03-22  Marek Safar  <marek.safar@seznam.cz>
 
        * assign.cs (Assign.DoResolve): Check for CS1717 when
        source and target are same (uses Equals).
-       
+
        * expression.cs (LocalVariableReference, ParameterReference,
        This): Implemented Equals, GetHashCode.
-       
+
        * statement.cs (Block.GetParameterReference): Removed useless
        local variable.
 
        blocks before deciding whether the error is cs0136 or cs0128.
 
        * cs-parser.jay: Pass MemberName to RootContext.Tree.RecordDecl.
-       (using_alias_directive, using_namespace_directive): Pass
-       MemberName, not an expression to Namespace.UsingAlias and 
+       (using_alias_directive, using_namespace_directive): Pass
+       MemberName, not an expression to Namespace.UsingAlias and
        Namespace.Using.
        (MakeName): Use the MemberName of the namespace.
        * namespace.cs (Namespace.MemberName): New.
        (UsingEntry.UsingEntry): Take a MemberName, not an expression.
-       (AliasEntry.AliasEntry, Namespace.Using, Namespace.UsingAlias): 
-       Likewise.       
+       (AliasEntry.AliasEntry, Namespace.Using, Namespace.UsingAlias):
+       Likewise.
        * decl.cs (MemberName.Name): Make readonly.
        (MemberName.FromDotted): New "constructor".
        (MemberName.Equals, MemberName.GetHashCode): Implement overrides.
@@ -67,7 +77,7 @@
        fixed buffer attribute (CS1716).
        (PropertyMethod.HasCustomAccessModifier): When property accessor
        has custom modifier.
-       
+
        * ecore (PropertyExpr.DoResolve): Add CS0271 for custom accessor
        modifiers.
        (PropertyExpr.DoResolveLValue): Add CS0272.
@@ -78,7 +88,7 @@
        or Conv.I depending on the source data type.
 
        * cs-tokenizer.cs: Make the size for large decimal constants,
-       fixes #72957. 
+       fixes #72957.
 
 2005-03-17  Martin Baulig  <martin@ximian.com>
 
 
        * delegate.cs (DelegateCreation.Error_NoMatchingMethodForDelegate):
        Added CS0407.
-       
+
        * expression.cs (ParameterReference.IsAssigned): Changed error to
        CS0269.
-       (Error_WrongNumArguments): Moved CS0245 detection here. 
-       
+       (Error_WrongNumArguments): Moved CS0245 detection here.
+
        * statement.cs (Return.Resolve): Add CS1622 report.
 
 2005-03-11  Marek Safar  <marek.safar@seznam.cz>
index 14ef649534e11c16cd1a387c01bacde4a9112280..1f8cd60f32542091b50cc106cd0d81349d717e63 100644 (file)
@@ -33,7 +33,7 @@ namespace Mono.CSharp {
                        this.Type = expr;
                }
 
-               public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
                {
                        if (a.Type == TypeManager.marshal_as_attr_type) {
                                UnmanagedMarshal marshal = a.GetMarshal (this);
@@ -214,6 +214,7 @@ namespace Mono.CSharp {
                        TypeAttributes attr = Modifiers.TypeAttr (ModFlags, IsTopLevel);
 
                        ec = new EmitContext (this, this, Location, null, null, ModFlags, false);
+                       ec.InEnumContext = true;
 
                        attr |= TypeAttributes.Class | TypeAttributes.Sealed;
 
@@ -256,6 +257,8 @@ namespace Mono.CSharp {
                                        Basename, attr, TypeManager.enum_type);
                        }
 
+                       ec.ContainerType = TypeBuilder;
+
                        //
                        // Call MapToInternalType for corlib
                        //
@@ -481,19 +484,14 @@ namespace Mono.CSharp {
                        return false;
                }
 
-               //
-               // Horrible, horrible.  But there is no other way we can pass the EmitContext
-               // to the recursive definition triggered by the evaluation of a forward
-               // expression
-               //
-               static EmitContext current_ec = null;
-               
                /// <summary>
                ///  This is used to lookup the value of an enum member. If the member is undefined,
                ///  it attempts to define it and return its value
                /// </summary>
-               public object LookupEnumValue (EmitContext ec, string name, Location loc)
+               public object LookupEnumValue (string name, Location loc)
                {
+                       if (ec == null)
+                               Report.Error (-1, loc, "Enum.LookupEnumValue () called too soon");
                        
                        object default_value = null;
                        Constant c = null;
@@ -534,14 +532,7 @@ namespace Mono.CSharp {
                                                Location m_loc = (Mono.CSharp.Location)
                                                        member_to_location [n];
                                                in_transit.Add (name, true);
-
-                                               EmitContext old_ec = current_ec;
-                                               current_ec = ec;
-                       
-                                               default_value = LookupEnumValue (ec, n, m_loc);
-
-                                               current_ec = old_ec;
-                                               
+                                               default_value = LookupEnumValue (n, m_loc);
                                                in_transit.Remove (name);
                                                if (default_value == null)
                                                        return null;
@@ -551,17 +542,12 @@ namespace Mono.CSharp {
                                }
                                
                        } else {
-                               bool old = ec.InEnumContext;
-                               ec.InEnumContext = true;
-                               in_transit.Add (name, true);
+                               if (!EmitContext.InEnumContext)
+                                       Report.Error (-1, loc, "foo");
 
-                               EmitContext old_ec = current_ec;
-                               current_ec = ec;
-                               val = val.Resolve (ec);
-                               current_ec = old_ec;
-                               
+                               in_transit.Add (name, true);
+                               val = val.Resolve (EmitContext);
                                in_transit.Remove (name);
-                               ec.InEnumContext = old;
 
                                if (val == null)
                                        return null;
@@ -626,7 +612,8 @@ namespace Mono.CSharp {
                        if (TypeBuilder == null)
                                return false;
 
-                       ec = new EmitContext (this, this, Location, null, UnderlyingType, ModFlags, false);
+                       if (ec == null)
+                               throw new InternalErrorException ("Enum.Define () called too soon");
                        
                        object default_value = 0;
                        
@@ -641,7 +628,7 @@ namespace Mono.CSharp {
                                Location loc = (Mono.CSharp.Location) member_to_location [name];
 
                                if (this [name] != null) {
-                                       default_value = LookupEnumValue (ec, name, loc);
+                                       default_value = LookupEnumValue (name, loc);
 
                                        if (default_value == null)
                                                return true;
@@ -744,10 +731,8 @@ namespace Mono.CSharp {
                        ArrayList members = new ArrayList ();
 
                        if ((mt & MemberTypes.Field) != 0) {
-                               if (criteria is string){
-                                       if (member_to_value [criteria] == null && current_ec != null){
-                                               LookupEnumValue (current_ec, (string) criteria, Location.Null);
-                                       }
+                               if (criteria is string && member_to_value [criteria] == null) {
+                                       LookupEnumValue ((string) criteria, Location.Null);
                                }
                                
                                foreach (FieldBuilder fb in field_builders)
index 4ca2c6b00fd209d19006aa342738fdc3a43d5256..eec3faf8e8440aabd9429df6e9c9aa17638b336d 100644 (file)
@@ -7498,7 +7498,7 @@ namespace Mono.CSharp {
                                        Enum en = TypeManager.LookupEnum (expr_type);
 
                                        if (en != null) {
-                                               object value = en.LookupEnumValue (ec, Identifier, loc);
+                                               object value = en.LookupEnumValue (Identifier, loc);
                                                
                                                if (value != null){
                                                        MemberCore mc = en.GetDefinition (Identifier);