**** Merged from MCS ****
authorMartin Baulig <martin@novell.com>
Fri, 27 Feb 2004 07:36:00 +0000 (07:36 -0000)
committerMartin Baulig <martin@novell.com>
Fri, 27 Feb 2004 07:36:00 +0000 (07:36 -0000)
2004-02-26  Miguel de Icaza  <miguel@ximian.com>

* iterators.cs (IteratorHandler.IsIEnumerator, IsIEnumerable): New
routines to check if a type is an enumerable/enumerator allow
classes that implement the IEnumerable or IEnumerator interfaces.

* class.cs (Property, Operator): Implement IIteratorContainer, and
implement SetYields.

(Property.Define): Do the block swapping for get_methods in the
context of iterators.   We need to check if Properties also
include indexers or not.

(Operator): Assign the Block before invoking the
OperatorMethod.Define, so we can trigger the Iterator code
replacement.

* cs-parser.jay (SimpleIteratorContainer): new helper class.  Both
Property and Operator classes are not created when we parse the
declarator but until we have the block completed, so we use a
singleton SimpleIteratorContainer.Simple to flag whether the
SetYields has been invoked.

We propagate this setting then to the Property or the Operator to
allow the `yield' to function.

2004-02-25  Marek Safar  <marek.safar@seznam.cz>

* codegen.cs: Implemented attribute support for modules.
        New AssemblyClass, ModuleClass and CommonAssemblyModulClass for
        Assembly/Module functionality.

        * attribute.cs, class.cs, cs-parser.jay, delegate.cs, driver.cs, enum.cs
        interface.cs, rootcontext.cs, statement.cs, typemanager.cs:
        Updated dependencies on CodeGen.ModuleBuilder and CodeGen.AssemblyBuilder.

2004-02-16  Marek Safar  <marek.safar@seznam.cz>

* interface.cs (FindMembers): The operation is performed on all base
interfaces and not only on the first. It is required for future CLS Compliance patch.

2004-02-12 Ben Maurer  <bmaurer@users.sourceforge.net>

* statement.cs, codegen.cs:
This patch deals with patterns such as:

public class List : IEnumerable {

public MyEnumerator GetEnumerator () {
return new MyEnumerator(this);
}

IEnumerator IEnumerable.GetEnumerator () {
...
}

public struct MyEnumerator : IEnumerator {
...
}
}

Before, there were a few things we did wrong:
1) we would emit callvirt on a struct, which is illegal
2) we emited ldarg when we needed to emit ldarga
3) we would mistakenly call the interface methods on an enumerator
type that derived from IEnumerator and was in another assembly. For example:

public class MyEnumerator : IEnumerator

Would have the interface methods called, even if there were public impls of the
method. In a struct, this lead to invalid IL code.

2004-02-11  Marek Safar  <marek.safar@seznam.cz>

        * const.cs: Const is now derived from FieldBase. Method EmitConstant name
  renamed to Emit.

        * delegate.cs (Define): Fixed crash when delegate type is undefined.

2004-02-11  Miguel de Icaza  <miguel@ximian.com>

* cs-parser.jay: Fix small regression: we were not testing V2
compiler features correctly.

* interface.cs: If the emit context is null, then create one

2004-02-09  Marek Safar  <marek.safar@seznam.cz>

        * decl.cs (GetSignatureForError): New virtual method to get full name
  for error messages.

* attribute.cs (IAttributeSupport): New interface for attribute setting.
  Now it is possible to rewrite ApplyAttributes method to be less if/else.

        * interface.cs : All InterfaceXXX classes are now derived from MemberCore.
  Duplicated members and code in these classes has been removed.
  Better encapsulation in these classes.

2004-02-07  Miguel de Icaza  <miguel@ximian.com>

* assign.cs (Assign.DoResolve): When dealing with compound
assignments, there is a new rule in ECMA C# 2.4 (might have been
there before, but it is documented here) that states that in:

a op= b;

If b is of type int, and the `op' is a shift-operator, then the
above is evaluated as:

a = (int) a op b

* expression.cs (Binary.ResolveOperator): Instead of testing for
int/uint/long/ulong, try to implicitly convert to any of those
types and use that in pointer arithmetic.

* delegate.cs (Error_NoMatchingMethodForDelegate): Compute the
method to print information for from the type, not from the
null-method we were given.

2004-02-01  Duncan Mak  <duncan@ximian.com>

* cs-tokenizer.cs (get_cmd_arg): Skip over whitespace before
parsing for cmd, fixes bug #53694.

2004-02-04  Marek Safar  <marek.safar@seznam.cz>

* class.cs, decl.cs: Fixed problem where IndexerName attribute was ignored
        in the member name duplication tests. Property and operator name duplication
        was missing too (error tests cs0102-{2,3,4,5}.cs, cs0111-{3,4}.cs).

2004-02-03  Marek Safar  <marek.safar@seznam.cz>

* interface.cs (PopulateMethod): Fixed crash when interface method
returns not existing type (error test cs0246-3.cs).

2004-02-02  Ravi Pratap M <ravi@ximian.com>

* cs-parser.jay (interface_accessors): Re-write actions to also
store attributes attached to get and set methods. Fix spelling
while at it.

(inteface_property_declaration): Modify accordingly.

(InterfaceAccessorInfo): New helper class to store information to pass
around between rules that use interface_accessors.

* interface.cs (Emit): Apply attributes on the get and set
accessors of properties and indexers too.

* attribute.cs (ApplyAttributes): Modify accordingly to use the
right MethodBuilder when applying attributes to the get and set accessors.

2004-01-31  Miguel de Icaza  <miguel@ximian.com>

* cs-tokenizer.cs: Applied patch from Marek Safar to fix bug 53386

2004-01-26  Miguel de Icaza  <miguel@ximian.com>

* cs-tokenizer.cs: Handle #line hidden from PDC bits.

2004-01-25  Miguel de Icaza  <miguel@ximian.com>

* cs-parser.jay: Remove YIELD token, instead use the new grammar
changes that treat `yield' specially when present before `break'
or `return' tokens.

* cs-tokenizer.cs: yield is no longer a keyword.

2004-01-23  Marek Safar  <marek.safar@seznam.cz>

* cs-parser.jay, class.cs (DefineDefaultConstructor): Fixed ModFlags
        setting for default constructors.
For default constructors are almost every time set wrong Modifier. The
generated IL code has been alright. But inside mcs this values was
wrong and this was reason why several of my CLS Compliance tests
failed.

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

21 files changed:
mcs/gmcs/AssemblyInfo.cs
mcs/gmcs/ChangeLog
mcs/gmcs/Makefile
mcs/gmcs/assign.cs
mcs/gmcs/attribute.cs
mcs/gmcs/class.cs
mcs/gmcs/codegen.cs
mcs/gmcs/const.cs
mcs/gmcs/cs-parser.jay
mcs/gmcs/cs-tokenizer.cs
mcs/gmcs/decl.cs
mcs/gmcs/delegate.cs
mcs/gmcs/driver.cs
mcs/gmcs/enum.cs
mcs/gmcs/expression.cs
mcs/gmcs/interface.cs
mcs/gmcs/iterators.cs
mcs/gmcs/parameter.cs
mcs/gmcs/rootcontext.cs
mcs/gmcs/statement.cs
mcs/gmcs/typemanager.cs

index a80bb2813a07c57a32a57140f4729ba6d58e29cf..7a5cd5e4d533ddf37b0f6d3e2d4631496421e9fc 100644 (file)
@@ -1,7 +1,7 @@
 using System.Reflection;
 using System.Runtime.CompilerServices;
 
-[assembly: AssemblyVersion("0.29.99")]
+[assembly: AssemblyVersion("0.30.99")]
 [assembly: AssemblyTitle ("Mono C# Compiler")]
 [assembly: AssemblyDescription ("Mono C# Compiler with Generics")]
 [assembly: AssemblyCopyright ("2001, 2002, 2003 Ximian, Inc.")]
index 530578b638efa771b38f61d1ef8254b090be4baf..8491ac2da7166d728464dc08942f1ff0671bb4c8 100755 (executable)
@@ -1,3 +1,180 @@
+2004-02-26  Miguel de Icaza  <miguel@ximian.com>
+
+       * iterators.cs (IteratorHandler.IsIEnumerator, IsIEnumerable): New
+       routines to check if a type is an enumerable/enumerator allow
+       classes that implement the IEnumerable or IEnumerator interfaces.
+
+       * class.cs (Property, Operator): Implement IIteratorContainer, and
+       implement SetYields.
+
+       (Property.Define): Do the block swapping for get_methods in the
+       context of iterators.   We need to check if Properties also
+       include indexers or not.
+
+       (Operator): Assign the Block before invoking the
+       OperatorMethod.Define, so we can trigger the Iterator code
+       replacement. 
+
+       * cs-parser.jay (SimpleIteratorContainer): new helper class.  Both
+       Property and Operator classes are not created when we parse the
+       declarator but until we have the block completed, so we use a
+       singleton SimpleIteratorContainer.Simple to flag whether the
+       SetYields has been invoked.
+
+       We propagate this setting then to the Property or the Operator to
+       allow the `yield' to function.
+
+2004-02-25  Marek Safar  <marek.safar@seznam.cz>
+
+       * codegen.cs: Implemented attribute support for modules.
+        New AssemblyClass, ModuleClass and CommonAssemblyModulClass for
+        Assembly/Module functionality.
+        
+        * attribute.cs, class.cs, cs-parser.jay, delegate.cs, driver.cs, enum.cs
+        interface.cs, rootcontext.cs, statement.cs, typemanager.cs:
+        Updated dependencies on CodeGen.ModuleBuilder and CodeGen.AssemblyBuilder.
+
+2004-02-16  Marek Safar  <marek.safar@seznam.cz>
+
+       * interface.cs (FindMembers): The operation is performed on all base
+       interfaces and not only on the first. It is required for future CLS Compliance patch.
+
+2004-02-12 Ben Maurer  <bmaurer@users.sourceforge.net>
+
+       * statement.cs, codegen.cs:
+       This patch deals with patterns such as:
+
+       public class List : IEnumerable {
+
+               public MyEnumerator GetEnumerator () {
+                       return new MyEnumerator(this);
+               }
+       
+               IEnumerator IEnumerable.GetEnumerator () {
+                       ...
+               }
+               
+               public struct MyEnumerator : IEnumerator {
+                       ...
+               }
+       }
+
+       Before, there were a few things we did wrong:
+       1) we would emit callvirt on a struct, which is illegal
+       2) we emited ldarg when we needed to emit ldarga
+       3) we would mistakenly call the interface methods on an enumerator
+       type that derived from IEnumerator and was in another assembly. For example:
+
+       public class MyEnumerator : IEnumerator
+
+       Would have the interface methods called, even if there were public impls of the
+       method. In a struct, this lead to invalid IL code.
+       
+2004-02-11  Marek Safar  <marek.safar@seznam.cz>
+
+        * const.cs: Const is now derived from FieldBase. Method EmitConstant name
+         renamed to Emit.
+
+        * delegate.cs (Define): Fixed crash when delegate type is undefined.
+        
+2004-02-11  Miguel de Icaza  <miguel@ximian.com>
+
+       * cs-parser.jay: Fix small regression: we were not testing V2
+       compiler features correctly.
+
+       * interface.cs: If the emit context is null, then create one
+
+2004-02-09  Marek Safar  <marek.safar@seznam.cz>
+
+        * decl.cs (GetSignatureForError): New virtual method to get full name
+         for error messages.
+        
+       * attribute.cs (IAttributeSupport): New interface for attribute setting.
+         Now it is possible to rewrite ApplyAttributes method to be less if/else.
+
+        * interface.cs : All InterfaceXXX classes are now derived from MemberCore.
+         Duplicated members and code in these classes has been removed.
+         Better encapsulation in these classes.
+
+2004-02-07  Miguel de Icaza  <miguel@ximian.com>
+
+       * assign.cs (Assign.DoResolve): When dealing with compound
+       assignments, there is a new rule in ECMA C# 2.4 (might have been
+       there before, but it is documented here) that states that in:
+
+       a op= b;
+
+       If b is of type int, and the `op' is a shift-operator, then the
+       above is evaluated as:
+
+       a = (int) a op b 
+
+       * expression.cs (Binary.ResolveOperator): Instead of testing for
+       int/uint/long/ulong, try to implicitly convert to any of those
+       types and use that in pointer arithmetic.
+
+       * delegate.cs (Error_NoMatchingMethodForDelegate): Compute the
+       method to print information for from the type, not from the
+       null-method we were given.
+
+2004-02-01  Duncan Mak  <duncan@ximian.com>
+
+       * cs-tokenizer.cs (get_cmd_arg): Skip over whitespace before
+       parsing for cmd, fixes bug #53694.
+
+2004-02-04  Marek Safar  <marek.safar@seznam.cz>
+
+       * class.cs, decl.cs: Fixed problem where IndexerName attribute was ignored
+        in the member name duplication tests. Property and operator name duplication
+        was missing too (error tests cs0102-{2,3,4,5}.cs, cs0111-{3,4}.cs).
+
+2004-02-03  Marek Safar  <marek.safar@seznam.cz>
+
+       * interface.cs (PopulateMethod): Fixed crash when interface method
+       returns not existing type (error test cs0246-3.cs).
+
+2004-02-02  Ravi Pratap M <ravi@ximian.com>
+
+       * cs-parser.jay (interface_accessors): Re-write actions to also
+       store attributes attached to get and set methods. Fix spelling
+       while at it.
+
+       (inteface_property_declaration): Modify accordingly.
+
+       (InterfaceAccessorInfo): New helper class to store information to pass
+       around between rules that use interface_accessors.
+
+       * interface.cs (Emit): Apply attributes on the get and set
+       accessors of properties and indexers too.
+       
+       * attribute.cs (ApplyAttributes): Modify accordingly to use the
+       right MethodBuilder when applying attributes to the get and set accessors.
+
+2004-01-31  Miguel de Icaza  <miguel@ximian.com>
+
+       * cs-tokenizer.cs: Applied patch from Marek Safar to fix bug 53386
+
+2004-01-26  Miguel de Icaza  <miguel@ximian.com>
+
+       * cs-tokenizer.cs: Handle #line hidden from PDC bits.
+
+2004-01-25  Miguel de Icaza  <miguel@ximian.com>
+
+       * cs-parser.jay: Remove YIELD token, instead use the new grammar
+       changes that treat `yield' specially when present before `break'
+       or `return' tokens.
+
+       * cs-tokenizer.cs: yield is no longer a keyword.
+
+2004-01-23  Marek Safar  <marek.safar@seznam.cz>
+
+       * cs-parser.jay, class.cs (DefineDefaultConstructor): Fixed ModFlags
+        setting for default constructors.
+       For default constructors are almost every time set wrong Modifier. The
+       generated IL code has been alright. But inside mcs this values was
+       wrong and this was reason why several of my CLS Compliance tests
+       failed.
+
 2004-02-27  Martin Baulig  <martin@ximian.com>
 
        * generics.cs (ConstructedType.ResolveType): Make the nested type
index 97b722ba14247b1844754d0fafefb8669fbf7c2c..00728fa9f39125037fe20fb22a6a4168ab0e9d23 100644 (file)
@@ -89,6 +89,9 @@ mcs2.exe: gmcs.exe
 mcs3.exe: mcs2.exe
        $(TIME) $(RUNTIME) ./mcs2.exe $(USE_MCS_FLAGS) /target:exe /out:$@ $(all_sources)
 
+wc:
+       wc -l $(all_sources)
+
 ctest: 
        -rm mcs2.exe mcs3.exe
        make btest USE_MCS_FLAGS= 
index ff3521059bf7b1837cff438f5eabb38ba5682fe7..3f1827e5cfa224567e6d603db54f77fcd5552e22 100755 (executable)
@@ -295,11 +295,19 @@ namespace Mono.CSharp {
                                
                                        //
                                        // 2. and the original right side is implicitly convertible to
-                                       // the type of target_type.
+                                       // the type of target
                                        //
                                        if (Convert.ImplicitStandardConversionExists (a.original_source, target_type))
                                                return this;
 
+                                       //
+                                       // In the spec 2.4 they added: or if type of the target is int
+                                       // and the operator is a shift operator...
+                                       //
+                                       if (source_type == TypeManager.int32_type &&
+                                           (b.Oper == Binary.Operator.LeftShift || b.Oper == Binary.Operator.RightShift))
+                                               return this;
+
                                        Convert.Error_CannotImplicitConversion (loc, a.original_source.Type, target_type);
                                        return null;
                                }
index 0605282a645c22cdd4724f99349b95e47995031e..64de34bf0af3e13c914e5a5ae75a8f0adb893474 100644 (file)
@@ -631,16 +631,21 @@ namespace Mono.CSharp {
                                else\r
                                        return false;\r
                        } else if (element is Property || element is Indexer ||\r
-                                  element is InterfaceProperty || element is InterfaceIndexer) {\r
+                                  element is InterfaceProperty || element is InterfaceIndexer || element is InterfaceProperty.PropertyAccessor) {
                                if ((targets & AttributeTargets.Property) != 0)\r
                                        return true;\r
                                else\r
                                        return false;\r
-                       } else if (element is AssemblyBuilder){\r
+                       } else if (element is AssemblyClass){
                                if ((targets & AttributeTargets.Assembly) != 0)\r
                                        return true;\r
                                else\r
                                        return false;\r
+                       } else if (element is ModuleClass){
+                               if ((targets & AttributeTargets.Module) != 0)
+                                       return true;
+                               else
+                                       return false;
                        }\r
 \r
                        return false;\r
@@ -839,9 +844,6 @@ namespace Mono.CSharp {
                                if (asec.Attributes == null)\r
                                        continue;\r
 \r
-                               if (attr_target == "assembly" && !(builder is AssemblyBuilder))\r
-                                       continue;\r
-\r
                                if (attr_target == "return" && !(builder is ParameterBuilder))\r
                                        continue;\r
                                \r
@@ -869,7 +871,17 @@ namespace Mono.CSharp {
                                                return;\r
                                        }\r
 \r
-                                       if (kind is Method || kind is Operator || kind is InterfaceMethod ||\r
+                                       if (kind is IAttributeSupport) {
+                                               if (attr_type == TypeManager.methodimpl_attr_type && a.ImplOptions == MethodImplOptions.InternalCall) {
+                                                       ((MethodBuilder) builder).SetImplementationFlags (MethodImplAttributes.InternalCall | MethodImplAttributes.Runtime);
+                                               } 
+                                               else {
+                                                       IAttributeSupport attributeSupport = kind as IAttributeSupport;
+                                                       attributeSupport.SetCustomAttribute (cb);
+                                               }
+                                       }
+                                       else if (kind is Method || kind is Operator || kind is InterfaceMethod ||
+
                                            kind is Accessor) {\r
                                                if (attr_type == TypeManager.methodimpl_attr_type) {\r
                                                        if (a.ImplOptions == MethodImplOptions.InternalCall)\r
@@ -899,7 +911,15 @@ namespace Mono.CSharp {
                                                }\r
                                        } else if (kind is Property || kind is Indexer ||\r
                                                   kind is InterfaceProperty || kind is InterfaceIndexer) {\r
+
+                                                if (builder is PropertyBuilder) 
                                                ((PropertyBuilder) builder).SetCustomAttribute (cb);\r
+                                                //
+                                                // This is for the case we are setting attributes on
+                                                // the get and set accessors
+                                                //
+                                                else if (builder is MethodBuilder)
+                                                        ((MethodBuilder) builder).SetCustomAttribute (cb);
                                        } else if (kind is Event || kind is InterfaceEvent) {\r
                                                ((MyEventBuilder) builder).SetCustomAttribute (cb);\r
                                        } else if (kind is ParameterBuilder) {\r
@@ -1202,4 +1222,8 @@ namespace Mono.CSharp {
                        return false;\r
                }\r
        }\r
+
+       public interface IAttributeSupport {
+               void SetCustomAttribute (CustomAttributeBuilder customBuilder);
+       }
 }\r
index 585b1f15efcb39ec8bcf8179f64f188436987381..d9826277297703ecb4952d2d738b80384f6464d8 100755 (executable)
@@ -343,12 +343,20 @@ namespace Mono.CSharp {
                public AdditionResult AddProperty (Property prop)
                {
                        AdditionResult res;
-                       string basename = prop.Name;
-                       string fullname = Name + "." + basename;
 
-                       if ((res = IsValid (basename, fullname)) != AdditionResult.Success)
+                       if ((res = AddProperty (prop, prop.Name)) != AdditionResult.Success)
                                return res;
 
+                       if (prop.Get != null) {
+                               if ((res = AddProperty (prop, "get_" + prop.Name)) != AdditionResult.Success)
+                                       return res;
+                       }
+
+                       if (prop.Set != null) {
+                               if ((res = AddProperty (prop, "set_" + prop.Name)) != AdditionResult.Success)
+                               return res;
+                       }
+
                        if (properties == null)
                                properties = new ArrayList ();
 
@@ -356,6 +364,18 @@ namespace Mono.CSharp {
                                properties.Insert (0, prop);
                        else
                                properties.Add (prop);
+
+                       return AdditionResult.Success;
+               }
+
+               AdditionResult AddProperty (Property prop, string basename)
+               {
+                       AdditionResult res;
+                       string fullname = Name + "." + basename;
+
+                       if ((res = IsValid (basename, fullname)) != AdditionResult.Success)
+                               return res;
+
                        DefineName (fullname, prop);
 
                        return AdditionResult.Success;
@@ -379,7 +399,7 @@ namespace Mono.CSharp {
                        return AdditionResult.Success;
                }
 
-               public AdditionResult AddIndexer (Indexer i)
+               public void AddIndexer (Indexer i)
                {
                        if (indexers == null)
                                indexers = new ArrayList ();
@@ -388,8 +408,6 @@ namespace Mono.CSharp {
                                indexers.Insert (0, i);
                        else
                                indexers.Add (i);
-
-                       return AdditionResult.Success;
                }
 
                public AdditionResult AddOperator (Operator op)
@@ -399,6 +417,12 @@ namespace Mono.CSharp {
 
                        operators.Add (op);
 
+                       string basename = op.Name;
+                       string fullname = Name + "." + basename;
+                       if (!defined_names.Contains (fullname))
+                       {
+                               DefineName (fullname, op);
+                       }
                        return AdditionResult.Success;
                }
 
@@ -559,25 +583,23 @@ namespace Mono.CSharp {
                void DefineDefaultConstructor (bool is_static)
                {
                        Constructor c;
-                       int mods = 0;
 
-                       c = new Constructor (this, Basename, Parameters.EmptyReadOnlyParameters,
+                       // The default constructor is public
+                       // If the class is abstract, the default constructor is protected
+                       // The default static constructor is private
+
+                       int mods = Modifiers.PUBLIC;
+                       if (is_static)
+                               mods = Modifiers.STATIC | Modifiers.PRIVATE;
+                       else if ((ModFlags & Modifiers.ABSTRACT) != 0)
+                               mods = Modifiers.PROTECTED;
+
+                       c = new Constructor (this, Basename, mods, Parameters.EmptyReadOnlyParameters,
                                             new ConstructorBaseInitializer (
                                                     null, Parameters.EmptyReadOnlyParameters,
                                                     Location),
                                             Location);
                        
-                       if (is_static)
-                               mods = Modifiers.STATIC;
-
-                       //
-                       // If the class is abstract, the default constructor is protected
-                       //
-                       if ((ModFlags & Modifiers.ABSTRACT) != 0)
-                               mods |= Modifiers.PROTECTED;
-                       
-                       c.ModFlags = mods;
-
                        AddConstructor (c);
                        
                        c.Block = new ToplevelBlock (null, Location);
@@ -812,7 +834,7 @@ namespace Mono.CSharp {
                                        return null;
                                }
 
-                               ModuleBuilder builder = CodeGen.ModuleBuilder;
+                               ModuleBuilder builder = CodeGen.Module.Builder;
                                TypeBuilder = builder.DefineType (
                                        Name, type_attributes, ptype, null);
                                
@@ -1641,7 +1663,7 @@ namespace Mono.CSharp {
                {
                        if (constants != null)
                                foreach (Const con in constants)
-                                       con.EmitConstant (this);
+                                       con.Emit (this);
                        return;
                }
 
@@ -2464,6 +2486,7 @@ namespace Mono.CSharp {
                        Modifiers.OVERRIDE |
                        Modifiers.ABSTRACT |
                        Modifiers.UNSAFE |
+                       Modifiers.METHOD_YIELDS | 
                        Modifiers.EXTERN;
 
                //
@@ -2472,7 +2495,8 @@ namespace Mono.CSharp {
                public Method (DeclSpace ds, Expression return_type, int mod, string name,
                               Parameters parameters, Attributes attrs, Location l)
                        : base (ds, return_type, mod, AllowedModifiers, name, attrs, parameters, l)
-               { }
+               {
+               }
 
                public Method (GenericMethod generic, Expression return_type, int mod, string name,
                               Parameters parameters, Attributes attrs, Location l)
@@ -2839,9 +2863,9 @@ namespace Mono.CSharp {
                // The spec claims that static is not permitted, but
                // my very own code has static constructors.
                //
-               public Constructor (DeclSpace ds, string name, Parameters args,
+               public Constructor (DeclSpace ds, string name, int mod, Parameters args,
                                    ConstructorInitializer init, Location l)
-                       : base (ds, null, 0, AllowedModifiers, name, null, args, l)
+                       : base (ds, null, mod, AllowedModifiers, name, null, args, l)
                {
                        Initializer = init;
                }
@@ -4300,7 +4324,7 @@ namespace Mono.CSharp {
                }
        }
                        
-       public class Property : PropertyBase {
+       public class Property : PropertyBase, IIteratorContainer {
                const int AllowedModifiers =
                        Modifiers.NEW |
                        Modifiers.PUBLIC |
@@ -4313,6 +4337,7 @@ namespace Mono.CSharp {
                        Modifiers.ABSTRACT |
                        Modifiers.UNSAFE |
                        Modifiers.EXTERN |
+                       Modifiers.METHOD_YIELDS |
                        Modifiers.VIRTUAL;
 
                public Property (DeclSpace ds, Expression type, string name, int mod_flags,
@@ -4344,6 +4369,20 @@ namespace Mono.CSharp {
                                                          parameters, ip, CallingConventions.Standard,
                                                          Get.OptAttributes, ModFlags, flags, false);
 
+                               //
+                               // Setup iterator if we are one
+                               //
+                               if ((ModFlags & Modifiers.METHOD_YIELDS) != 0){
+                                       IteratorHandler ih = new  IteratorHandler (
+                                                                                  "get", container, MemberType,
+                                                                                  parameters, ip, ModFlags, Location);
+                                       
+                                       Block new_block = ih.Setup (block);
+                                       if (new_block == null)
+                                               return false;
+                                       block = new_block;
+                               }
+                               
                                if (!GetData.Define (container))
                                        return false;
 
@@ -4400,6 +4439,11 @@ namespace Mono.CSharp {
                        }
                        return true;
                }
+
+               public void SetYields ()
+               {
+                       ModFlags |= Modifiers.METHOD_YIELDS;
+               }
        }
 
        /// </summary>
@@ -4781,6 +4825,9 @@ namespace Mono.CSharp {
                                Name = ShortName;
                        }
 
+                       if (!CheckNameCollision (container))
+                               return false;
+
                        if (!CheckBase (container))
                                return false;
 
@@ -4894,9 +4941,53 @@ namespace Mono.CSharp {
 
                        return true;
                }
+
+               bool CheckNameCollision (TypeContainer container) {
+                       switch (VerifyName (container)){
+                               case DeclSpace.AdditionResult.NameExists:
+                                       Report.Error (102, Location, "The container '{0}' already contains a definition for '{1}'", container.GetSignatureForError (), Name);
+                                       return false;
+
+                               case DeclSpace.AdditionResult.Success:
+                                       return true;
+                       }
+                       throw new NotImplementedException ();
+               }
+
+               DeclSpace.AdditionResult VerifyName (TypeContainer container) {
+                       if (!AddIndexer (container, container.Name + "." + Name))
+                               return DeclSpace.AdditionResult.NameExists;
+
+                       if (Get != null) {
+                               if (!AddIndexer (container, container.Name + ".get_" + Name))
+                                       return DeclSpace.AdditionResult.NameExists;
+                       }
+
+                       if (Set != null) {
+                               if (!AddIndexer (container, container.Name + ".set_" + Name))
+                                       return DeclSpace.AdditionResult.NameExists;
+                       }
+                       return DeclSpace.AdditionResult.Success;
+               }
+
+               bool AddIndexer (TypeContainer container, string fullname)
+               {
+                       object value = container.GetDefinition (fullname);
+
+                       if (value != null) {
+                               return value.GetType () != GetType () ? false : true;
+                       }
+
+                       container.DefineName (fullname, this);
+                       return true;
+               }
+
+               public override string GetSignatureForError () {
+                       return TypeManager.CSharpSignature (PropertyBuilder, true);
+               }
        }
 
-       public class Operator : MemberBase {
+       public class Operator : MemberBase, IIteratorContainer {
 
                const int AllowedModifiers =
                        Modifiers.PUBLIC |
@@ -4963,6 +5054,7 @@ namespace Mono.CSharp {
                        : base (ret_type, mod_flags, AllowedModifiers, Modifiers.PUBLIC, "", attrs, loc)
                {
                        OperatorType = type;
+                       Name = "op_" + OperatorType;
                        ReturnType = ret_type;
                        FirstArgType = arg1type;
                        FirstArgName = arg1name;
@@ -5006,6 +5098,7 @@ namespace Mono.CSharp {
                                                     new Parameters (param_list, null, Location),
                                                     OptAttributes, Location);
 
+                       OperatorMethod.Block = Block;
                        OperatorMethod.IsOperator = true;                       
                        OperatorMethod.Define (container);
 
@@ -5120,7 +5213,6 @@ namespace Mono.CSharp {
                        if ((ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0)
                                return;
                        
-                       OperatorMethod.Block = Block;
                        OperatorMethod.Emit (container);
                        Block = null;
                }
@@ -5202,6 +5294,11 @@ namespace Mono.CSharp {
                                        GetName (OperatorType),
                                        param_types [0], param_types [1]);
                }
+
+               public void SetYields ()
+               {
+                       ModFlags |= Modifiers.METHOD_YIELDS;
+               }
        }
 
        //
@@ -5377,10 +5474,7 @@ namespace Mono.CSharp {
                        // If only accessible to the defining assembly or 
                        if (prot == MethodAttributes.FamANDAssem ||
                            prot == MethodAttributes.Assembly){
-                               if (m.DeclaringType.Assembly == CodeGen.AssemblyBuilder)
-                                       return true;
-                               else
-                                       return false;
+                               return m.DeclaringType.Assembly == CodeGen.Assembly.Builder;
                        }
 
                        // Anything else (FamOrAssembly and Public) is fine
index 6e97979afc57dc2d023e9d05a1ec116a5f9be3d5..86a9a5bb7db05c35720e60ac7b3c84309b3ffcf2 100755 (executable)
@@ -20,11 +20,17 @@ namespace Mono.CSharp {
        /// </summary>
        public class CodeGen {
                static AppDomain current_domain;
-               public static AssemblyBuilder AssemblyBuilder;
-               public static ModuleBuilder   ModuleBuilder;
-
                static public SymbolWriter SymbolWriter;
 
+               public static AssemblyClass Assembly;
+               public static ModuleClass Module;
+
+               static CodeGen ()
+               {
+                       Assembly = new AssemblyClass ();
+                       Module = new ModuleClass (RootContext.Unsafe);
+               }
+
                public static string Basename (string name)
                {
                        int pos = name.LastIndexOf ('/');
@@ -67,7 +73,7 @@ namespace Mono.CSharp {
                //
                static void InitializeSymbolWriter ()
                {
-                       SymbolWriter = SymbolWriter.GetSymbolWriter (ModuleBuilder);
+                       SymbolWriter = SymbolWriter.GetSymbolWriter (Module.Builder);
 
                        //
                        // If we got an ISymbolWriter instance, initialize it.
@@ -91,7 +97,7 @@ namespace Mono.CSharp {
                        an.Name = Path.GetFileNameWithoutExtension (name);
                        
                        current_domain = AppDomain.CurrentDomain;
-                       AssemblyBuilder = current_domain.DefineDynamicAssembly (
+                       Assembly.Builder = current_domain.DefineDynamicAssembly (
                                an, AssemblyBuilderAccess.Save, Dirname (name));
 
                        //
@@ -102,7 +108,7 @@ namespace Mono.CSharp {
                        // If the third argument is true, the ModuleBuilder will dynamically
                        // load the default symbol writer.
                        //
-                       ModuleBuilder = AssemblyBuilder.DefineDynamicModule (
+                       Module.Builder = Assembly.Builder.DefineDynamicModule (
                                Basename (name), Basename (output), want_debugging_support);
 
                        if (want_debugging_support)
@@ -112,7 +118,7 @@ namespace Mono.CSharp {
                static public void Save (string name)
                {
                        try {
-                               AssemblyBuilder.Save (Basename (name));
+                               Assembly.Builder.Save (Basename (name));
                        } catch (System.IO.IOException io){
                                Report.Error (16, "Could not write to file `"+name+"', cause: " + io.Message);
                        }
@@ -163,6 +169,33 @@ namespace Mono.CSharp {
                        else 
                                ig.Emit (OpCodes.Ldfld, fb);
                }
+               
+               public void EmitCall (MethodInfo mi)
+               {
+                       // FIXME : we should handle a call like tostring
+                       // here, where boxing is needed. However, we will
+                       // never encounter that with the current usage.
+                       
+                       bool value_type_call;
+                       EmitThis ();
+                       if (fb == null) {
+                               value_type_call = local.LocalType.IsValueType;
+                               
+                               if (value_type_call)
+                                       ig.Emit (OpCodes.Ldloca, local);
+                               else
+                                       ig.Emit (OpCodes.Ldloc, local);
+                       } else {
+                               value_type_call = fb.FieldType.IsValueType;
+                               
+                               if (value_type_call)
+                                       ig.Emit (OpCodes.Ldflda, fb);
+                               else
+                                       ig.Emit (OpCodes.Ldfld, fb);
+                       }
+                       
+                       ig.Emit (value_type_call ? OpCodes.Call : OpCodes.Callvirt, mi);
+               }
        }
        
        /// <summary>
@@ -692,4 +725,111 @@ namespace Mono.CSharp {
                        return my_this;
                }
        }
+
+
+       public abstract class CommonAssemblyModulClass: IAttributeSupport {
+               Hashtable m_attributes;
+
+               protected CommonAssemblyModulClass () 
+               {
+                       m_attributes = new Hashtable ();
+               }
+
+               //
+               // Adds a global attribute that was declared in `container', 
+               // the attribute is in `attr', and it was defined at `loc'
+               //                
+               public void AddAttribute (TypeContainer container, AttributeSection attr)
+               {
+                       NamespaceEntry ns = container.NamespaceEntry;
+                       Attributes a = (Attributes) m_attributes [ns];
+
+                       if (a == null) {
+                               m_attributes [ns] = new Attributes (attr);
+                               return;
+                       }
+
+                       a.AddAttributeSection (attr);
+               }
+
+               public virtual void Emit () 
+               {
+                       if (m_attributes.Count < 1)
+                               return;
+
+                       TypeContainer dummy = new TypeContainer ();
+                       EmitContext temp_ec = new EmitContext (dummy, Mono.CSharp.Location.Null, null, null, 0, false);
+                       
+                       foreach (DictionaryEntry de in m_attributes)
+                       {
+                               NamespaceEntry ns = (NamespaceEntry) de.Key;
+                               Attributes attrs = (Attributes) de.Value;
+                               
+                               dummy.NamespaceEntry = ns;
+                               Attribute.ApplyAttributes (temp_ec, null, this, attrs);
+                       }
+               }
+                
+               #region IAttributeSupport Members
+               public abstract void SetCustomAttribute(CustomAttributeBuilder customBuilder);
+               #endregion
+
+       }
+       
+
+       public class AssemblyClass: CommonAssemblyModulClass {
+               // TODO: make it private and move all builder based methods here
+               public AssemblyBuilder Builder;
+                    
+               bool m_is_cls_compliant;
+
+               public AssemblyClass (): base ()
+               {
+                       m_is_cls_compliant = false;
+               }
+
+               public bool IsClsCompliant {
+                       get {
+                               return m_is_cls_compliant;
+                       }
+               }
+
+               public override void SetCustomAttribute(CustomAttributeBuilder customBuilder)
+               {
+                       Builder.SetCustomAttribute (customBuilder);
+               }
+       }
+
+       public class ModuleClass: CommonAssemblyModulClass {
+               // TODO: make it private and move all builder based methods here
+               public ModuleBuilder Builder;
+            
+               bool m_module_is_unsafe;
+
+               public ModuleClass (bool is_unsafe)
+               {
+                       m_module_is_unsafe = is_unsafe;
+               }
+
+               public override void Emit () 
+               {
+                       base.Emit ();
+
+                       if (!m_module_is_unsafe)
+                               return;
+
+                       if (TypeManager.unverifiable_code_ctor == null) {
+                               Console.WriteLine ("Internal error ! Cannot set unverifiable code attribute.");
+                               return;
+                       }
+                               
+                       SetCustomAttribute (new CustomAttributeBuilder (TypeManager.unverifiable_code_ctor, new object [0]));
+               }
+                
+               public override void SetCustomAttribute(CustomAttributeBuilder customBuilder)
+               {
+                       Builder.SetCustomAttribute (customBuilder);
+               }
+       }
+
 }
index 97f1e5a76d52796be57c4e98f557dc6da52a082c..738071da5f36d1dcf73af284bd7335f9c1e100e3 100755 (executable)
@@ -24,10 +24,8 @@ namespace Mono.CSharp {
        using System.Reflection.Emit;
        using System.Collections;
 
-       public class Const : MemberBase {
-               public Expression ConstantType;
+       public class Const : FieldBase {
                public Expression Expr;
-               public FieldBuilder FieldBuilder;
                EmitContext const_ec;
 
                object ConstantValue = null;
@@ -44,10 +42,8 @@ namespace Mono.CSharp {
 
                public Const (Expression constant_type, string name, Expression expr, int mod_flags,
                              Attributes attrs, Location loc)
-                       : base (constant_type, mod_flags, AllowedModifiers, Modifiers.PRIVATE, name, attrs, loc)
+                       : base (constant_type, mod_flags, AllowedModifiers, name, null, attrs, loc)
                {
-                       ConstantType = constant_type;
-                       Name = name;
                        Expr = expr;
                }
 
@@ -75,7 +71,7 @@ namespace Mono.CSharp {
                /// </summary>
                public override bool Define (TypeContainer parent)
                {
-                       type = parent.ResolveType (ConstantType, false, Location);
+                       type = parent.ResolveType (Type, false, Location);
 
                        if (type == null)
                                return false;
@@ -259,7 +255,7 @@ namespace Mono.CSharp {
                /// <summary>
                ///  Emits the field value by evaluating the expression
                /// </summary>
-               public void EmitConstant (TypeContainer parent)
+               public void Emit (TypeContainer parent)
                {
                        LookupConstantValue ();
                        
index 08fb5e43e95e2ac3551a404916e6e51d9b8d251b..1f3286cba89ad65d21a625f0431c89754c70e68c 100755 (executable)
@@ -188,9 +188,6 @@ namespace Mono.CSharp
 %token WHERE
 %token WHILE   
 
-/* v2 tokens */
-%token YIELD
-
 /* C# keywords which are not really keywords */
 %token GET           "get"
 %token SET           "set"
@@ -348,7 +345,7 @@ namespace_declaration
                if (attrs != null) {
                        foreach (AttributeSection asec in attrs.AttributeSections)
                                if (asec.Target == "assembly")
-                                       RootContext.AddGlobalAttributeSection (current_container, asec);
+                                       CodeGen.Assembly.AddAttribute (current_container, asec);
                                else
                                        Report.Error(1518, Lexer.Location,
                                        "Attributes cannot be applied to namespaces."
@@ -468,7 +465,11 @@ attribute_sections
                AttributeSection sect = (AttributeSection) $1;
 
                if (sect.Target == "assembly") {
-                       RootContext.AddGlobalAttributeSection (current_container, sect);
+                       CodeGen.Assembly.AddAttribute (current_container, sect);
+                       $$ = null;
+               }
+               else if (sect.Target == "module") {
+                       CodeGen.Module.AddAttribute (current_container, sect);
                        $$ = null;
                }
                else
@@ -480,8 +481,12 @@ attribute_sections
                AttributeSection sect = (AttributeSection) $2;
 
                if (sect.Target == "assembly") {
-                       RootContext.AddGlobalAttributeSection (current_container, sect);
-               } else {
+                       CodeGen.Assembly.AddAttribute (current_container, sect);
+               }
+               else if (sect.Target == "module") {
+                       CodeGen.Module.AddAttribute (current_container, sect);
+               }
+               else {
                        if (attrs == null)
                                attrs = new Attributes (sect);
                        else
@@ -1116,6 +1121,8 @@ property_declaration
                lexer.PropertyParsing = true;
 
                $$ = lexer.Location;
+
+               iterator_container = SimpleIteratorContainer.GetSimple ();
          }
          accessor_declarations 
          {
@@ -1131,9 +1138,12 @@ property_declaration
                Location loc = (Location) $6;
                prop = new Property (current_container, (Expression) $3, (string) $4, (int) $2,
                                     get_block, set_block, (Attributes) $1, loc);
+               if (SimpleIteratorContainer.Simple.Yields)
+                       prop.SetYields ();
                
                CheckDef (current_container.AddProperty (prop), prop.Name, loc);
                implicit_value_parameter_type = null;
+               iterator_container = null;
          }
        ;
 
@@ -1368,14 +1378,15 @@ interface_property_declaration
          type IDENTIFIER 
          OPEN_BRACE 
          { lexer.PropertyParsing = true; }
-         interface_accesors 
+         interface_accessors 
          { lexer.PropertyParsing = false; }
          CLOSE_BRACE
          {
-               int gs = (int) $7;
+                InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
 
                $$ = new InterfaceProperty ((Expression) $3, (string) $4, (bool) $2, 
-                                           (gs & 1) == 1, (gs & 2) == 2, (Attributes) $1,
+                                           pinfo.has_get, pinfo.has_set, (Attributes) $1,
+                                            pinfo.get_attrs, pinfo.set_attrs,
                                            lexer.Location);
          }
        | opt_attributes
@@ -1386,13 +1397,13 @@ interface_property_declaration
          }
        ;
 
-interface_accesors
-       : opt_attributes GET SEMICOLON          { $$ = 1; }
-       | opt_attributes SET SEMICOLON          { $$ = 2; }
+interface_accessors
+       : opt_attributes GET SEMICOLON          { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null); }
+       | opt_attributes SET SEMICOLON          { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1); }
        | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON 
-         { $$ = 3; }
+         { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $3); }
        | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
-         { $$ = 3; }
+         { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $3, (Attributes) $1); }
        ;
 
 interface_event_declaration
@@ -1420,32 +1431,41 @@ interface_indexer_declaration
          OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
          OPEN_BRACE 
          { lexer.PropertyParsing = true; }
-         interface_accesors 
+         interface_accessors 
          { lexer.PropertyParsing = false; }
          CLOSE_BRACE
          {
-               int a_flags = (int) $10;
+               InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
 
-               bool do_get = (a_flags & 1) == 1;
-               bool do_set = (a_flags & 2) == 2;
+               bool do_get = info.has_get;
+               bool do_set = info.has_set;
 
                $$ = new InterfaceIndexer ((Expression) $3, (Parameters) $6, do_get, do_set,
-                                          (bool) $2, (Attributes) $1, lexer.Location);
+                                          (bool) $2, (Attributes) $1, (Attributes) info.get_attrs,
+                                           (Attributes) info.set_attrs, lexer.Location);
          }
        ;
 
 operator_declaration
-       : opt_attributes opt_modifiers operator_declarator operator_body
+       : opt_attributes opt_modifiers operator_declarator 
+         {
+               iterator_container = SimpleIteratorContainer.GetSimple ();
+         }
+         operator_body
          {
                OperatorDeclaration decl = (OperatorDeclaration) $3;
                
                Operator op = new Operator (decl.optype, decl.ret_type, (int) $2, decl.arg1type, decl.arg1name,
-                                           decl.arg2type, decl.arg2name, (Block) $4, (Attributes) $1, decl.location);
+                                           decl.arg2type, decl.arg2name, (Block) $5, (Attributes) $1, decl.location);
+
+               if (SimpleIteratorContainer.Simple.Yields)
+                       op.SetYields ();
 
                // Note again, checking is done in semantic analysis
                current_container.AddOperator (op);
 
                current_local_parameters = null;
+               iterator_container = null;
          }
        ;
 
@@ -1616,7 +1636,7 @@ constructor_declarator
          opt_constructor_initializer
          {
                Location l = (Location) oob_stack.Pop ();
-               $$ = new Constructor (current_container, (string) $1, (Parameters) $3,
+               $$ = new Constructor (current_container, (string) $1, 0, (Parameters) $3,
                                      (ConstructorInitializer) $6, l);
          }
        ;
@@ -3772,8 +3792,17 @@ throw_statement
        ;
 
 yield_statement 
-       : YIELD RETURN expression SEMICOLON
+       : IDENTIFIER RETURN expression SEMICOLON
          {
+               string s = (string) $1;
+               if (s != "yield"){
+                       Report.Error (1003, lexer.Location, "; expected");
+                       $$ = null;
+               }
+               if (!RootContext.V2){
+                       Report.Error (-222, lexer.Location, "yield statement only available in C# 2.0 mode");
+                       $$ = null;
+               }
                if (iterator_container == null){
                        Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
                        $$ = null;
@@ -3782,18 +3811,17 @@ yield_statement
                        $$ = new Yield ((Expression) $3, lexer.Location); 
                }
          }
-       | YIELD expression SEMICOLON 
+       | IDENTIFIER BREAK SEMICOLON
          {
-               if (iterator_container == null){
-                       Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
+               string s = (string) $1;
+               if (s != "yield"){
+                       Report.Error (1003, lexer.Location, "; expected");
+                       $$ = null;
+               }
+               if (!RootContext.V2){
+                       Report.Error (-222, lexer.Location, "yield statement only available in C# 2.0 mode");
                        $$ = null;
-               } else {
-                       iterator_container.SetYields ();
-                       $$ = new Yield ((Expression) $2, lexer.Location);
                }
-         }
-       | YIELD BREAK SEMICOLON
-         {
                if (iterator_container == null){
                        Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
                        $$ = null;
@@ -4120,6 +4148,27 @@ public class VariableDeclaration {
        }
 }
 
+/// <summary>
+///  Used to pass around interface property information
+/// </summary>
+public class InterfaceAccessorInfo {
+
+        public bool has_get;
+        public bool has_set;
+        public Attributes get_attrs;
+        public Attributes set_attrs;
+
+        public InterfaceAccessorInfo (bool has_get, bool has_set,
+                                      Attributes get_attrs, Attributes set_attrs)
+        {
+                this.has_get = has_get;
+                this.has_set = has_set;
+                this.get_attrs = get_attrs;
+                this.set_attrs = set_attrs;
+        }
+}
+
+
 // <summary>
 //   A class used to hold info about an indexer declarator
 // </summary>
@@ -4136,6 +4185,25 @@ public class IndexerDeclaration {
        }
 }
 
+//
+// We use this when we do not have an object in advance that is an IIteratorContainer
+//
+public class SimpleIteratorContainer : IIteratorContainer {
+       public bool Yields;
+
+       public static SimpleIteratorContainer Simple = new SimpleIteratorContainer ();
+
+       //
+       // Reset and return
+       //
+       public static SimpleIteratorContainer GetSimple () { 
+               Simple.Yields = false;
+               return Simple;
+       }
+
+       public void SetYields () { Yields = true; } 
+}
+
 // <summary>
 //  A class used to hold info about an operator declarator
 // </summary>
@@ -4324,7 +4392,7 @@ void CheckAttributeTarget (string a)
 {
        switch (a) {
 
-       case "assembly" : case "field" : case "method" : case "param" : case "property" : case "type" :
+       case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
                return;
                
        default :
index 946242000fe86fb7e24e4dea1ab4041936f10cc9..548fa287d26279535c2381605b2a78531fa741d0 100755 (executable)
@@ -301,11 +301,6 @@ namespace Mono.CSharp
                        AddKeyword ("volatile", Token.VOLATILE);\r
                        AddKeyword ("where", Token.WHERE);\r
                        AddKeyword ("while", Token.WHILE);\r
-\r
-                       if (RootContext.V2){\r
-                               AddKeyword ("__yield", Token.YIELD);\r
-                               AddKeyword ("yield", Token.YIELD);\r
-                       }\r
                }\r
 \r
                //\r
@@ -1191,9 +1186,14 @@ namespace Mono.CSharp
                        tokens_seen = false;\r
                        arg = "";\r
                        static_cmd_arg.Length = 0;\r
+\r
+                       // skip over white space\r
+                       while ((c = getChar ()) != -1 && (c != '\n') && ((c == '\r') || (c == ' ') || (c == '\t')))\r
+                               ;\r
                                \r
-                       while ((c = getChar ()) != -1 && (c != '\n') && (c != ' ') && (c != '\t') && (c != '\r')){\r
+                       while ((c != -1) && (c != '\n') && (c != ' ') && (c != '\t') && (c != '\r')){\r
                                static_cmd_arg.Append ((char) c);\r
+                                c = getChar ();\r
                        }\r
 \r
                        cmd = static_cmd_arg.ToString ();\r
@@ -1246,6 +1246,11 @@ namespace Mono.CSharp
                                ref_name = file_name;\r
                                Location.Push (ref_name);\r
                                return true;\r
+                       } else if (arg == "hidden"){\r
+                               //\r
+                               // We ignore #line hidden\r
+                               //\r
+                               return true;\r
                        }\r
                        \r
                        try {\r
@@ -1793,10 +1798,26 @@ namespace Mono.CSharp
                        val = null;\r
                        // optimization: eliminate col and implement #directive semantic correctly.\r
                        for (;(c = getChar ()) != -1; col++) {\r
-                               if (c == ' ' || c == '\t' || c == '\f' || c == '\v' || c == '\r' || c == 0xa0){\r
-                                       \r
-                                       if (c == '\t')\r
-                                               col = (((col + 8) / 8) * 8) - 1;\r
+                               if (c == ' ')\r
+                                       continue;\r
+                               \r
+                               if (c == '\t') {\r
+                                       col = (((col + 8) / 8) * 8) - 1;\r
+                                       continue;\r
+                               }\r
+                               \r
+                               if (c == ' ' || c == '\f' || c == '\v' || c == 0xa0)\r
+                                       continue;\r
+\r
+                               if (c == '\r') {\r
+                                       if (peekChar () == '\n')\r
+                                               getChar ();\r
+\r
+                                       line++;\r
+                                       ref_line++;\r
+                                       col = 0;\r
+                                       any_token_seen |= tokens_seen;\r
+                                       tokens_seen = false;\r
                                        continue;\r
                                }\r
 \r
index fc4a448600f6c464d865b402f5233f29965956da..d909ff060d0a702c67fe140151d548ab14572a9b 100755 (executable)
@@ -52,6 +52,13 @@ namespace Mono.CSharp {
 
                public abstract bool Define (TypeContainer parent);
 
+               // 
+               // Returns full member name for error message
+               //
+               public virtual string GetSignatureForError () {
+                       return Name;
+               }
+
                public Attributes OptAttributes 
                {
                        get {
@@ -224,7 +231,7 @@ namespace Mono.CSharp {
                ///   associates it with the object @o.  Note that for
                ///   methods this will just point to the first method. o
                /// </summary>
-               protected void DefineName (string name, object o)
+               public void DefineName (string name, object o)
                {
                        defined_names.Add (name, o);
 
index 024d5da673aab0ddf9a412190ed7a27f1c403890..336f585b14ca7cd9441a8aa7c4161613b49e362f 100644 (file)
@@ -69,7 +69,7 @@ namespace Mono.CSharp {
                                if (TypeManager.NamespaceClash (Name, Location))\r
                                        return null;\r
                                \r
-                               ModuleBuilder builder = CodeGen.ModuleBuilder;\r
+                               ModuleBuilder builder = CodeGen.Module.Builder;
 \r
                                TypeBuilder = builder.DefineType (\r
                                        Name, attr, TypeManager.multicast_delegate_type);\r
@@ -164,6 +164,9 @@ namespace Mono.CSharp {
                        }\r
                        \r
                        ReturnType = ResolveTypeExpr (ReturnType, false, Location);\r
+                        if (ReturnType == null)
+                            return false;
+                        
                        ret_type = ReturnType.Type;\r
                        if (ret_type == null)\r
                                return false;\r
@@ -580,7 +583,7 @@ namespace Mono.CSharp {
 \r
                public DelegateCreation () {}\r
 \r
-               public static void Error_NoMatchingMethodForDelegate (MethodGroupExpr mg, Type t, MethodBase method, Location loc)\r
+               public static void Error_NoMatchingMethodForDelegate (EmitContext ec, MethodGroupExpr mg, Type type, Location loc)
                {\r
                        string method_desc;\r
 \r
@@ -588,9 +591,13 @@ namespace Mono.CSharp {
                                method_desc = mg.Methods [0].Name;\r
                        else\r
                                method_desc = Invocation.FullMethodDesc (mg.Methods [0]);\r
-\r
-                       ParameterData param = Invocation.GetParameterData (method);\r
-                       string delegate_desc = Delegate.FullDelegateDesc (t, method, param);\r
+
+                       Expression invoke_method = Expression.MemberLookup (
+                               ec, type, "Invoke", MemberTypes.Method,
+                               Expression.AllBindingFlags, loc);
+                       MethodBase method = ((MethodGroupExpr) invoke_method).Methods [0];
+                       ParameterData param = Invocation.GetParameterData (method);\r
+                       string delegate_desc = Delegate.FullDelegateDesc (type, method, param);
 \r
                        Report.Error (123, loc, "Method '" + method_desc + "' does not " +\r
                                      "match delegate '" + delegate_desc + "'");\r
@@ -636,7 +643,7 @@ namespace Mono.CSharp {
                                }\r
                                        \r
                                if (delegate_method == null) {\r
-                               Error_NoMatchingMethodForDelegate (mg, type, delegate_method, loc);\r
+                                       Error_NoMatchingMethodForDelegate (ec, mg, type, loc);
                                        return null;\r
                                }\r
 \r
index 120c295f41d72d56619eb02154934b17b627d895..766305e35c767f3ff463f5539c451226732d2949 100755 (executable)
@@ -324,7 +324,7 @@ namespace Mono.CSharp
 
                        try {
                                try {
-                                       m = (Module)adder_method.Invoke (CodeGen.AssemblyBuilder, new object [] { module });
+                                       m = (Module)adder_method.Invoke (CodeGen.Assembly.Builder, new object [] { module });
                                }
                                catch (TargetInvocationException ex) {
                                        throw ex.InnerException;
@@ -340,7 +340,7 @@ namespace Mono.CSharp
 
                                        try {
                                                try {
-                                                       m = (Module)adder_method.Invoke (CodeGen.AssemblyBuilder, new object [] { full_path });
+                                                       m = (Module)adder_method.Invoke (CodeGen.Assembly.Builder, new object [] { full_path });
                                                }
                                                catch (TargetInvocationException ex) {
                                                        throw ex.InnerException;
@@ -1373,10 +1373,10 @@ namespace Mono.CSharp
                                        Environment.Exit (1);
                                }
 
-                               module_only.SetValue (CodeGen.AssemblyBuilder, true, null);
+                               module_only.SetValue (CodeGen.Assembly.Builder, true, null);
                        }
 
-                       TypeManager.AddModule (CodeGen.ModuleBuilder);
+                       TypeManager.AddModule (CodeGen.Module.Builder);
 
                        if (modules.Count > 0) {
                                MethodInfo adder_method = typeof (AssemblyBuilder).GetMethod ("AddModule", BindingFlags.Instance|BindingFlags.NonPublic);
@@ -1475,7 +1475,7 @@ namespace Mono.CSharp
                                        return false;
                                }
                                
-                               CodeGen.AssemblyBuilder.SetEntryPoint (ep, k);
+                               CodeGen.Assembly.Builder.SetEntryPoint (ep, k);
                        } else if (RootContext.MainClass != null) {
                                Report.Error (2017, "Can not specify -main: when building module or library");
                        }
@@ -1495,7 +1495,7 @@ namespace Mono.CSharp
                                        } else
                                                file = res = spec;
 
-                                       CodeGen.AssemblyBuilder.AddResourceFile (res, file);
+                                       CodeGen.Assembly.Builder.AddResourceFile (res, file);
                                }
                        }
                        
@@ -1519,7 +1519,7 @@ namespace Mono.CSharp
                                                        margs [0] = margs [1] = spec;
 
                                                if (File.Exists ((string) margs [1]))
-                                                       embed_res.Invoke (CodeGen.AssemblyBuilder, margs);
+                                                       embed_res.Invoke (CodeGen.Assembly.Builder, margs);
                                                else {
                                                        Report.Error (1566, "Can not find the resource " + margs [1]);
                                                }
@@ -1531,11 +1531,11 @@ namespace Mono.CSharp
                        // Add Win32 resources
                        //
 
-                       CodeGen.AssemblyBuilder.DefineVersionInfoResource ();
+                       CodeGen.Assembly.Builder.DefineVersionInfoResource ();
 
                        if (win32ResourceFile != null) {
                                try {
-                                       CodeGen.AssemblyBuilder.DefineUnmanagedResource (win32ResourceFile);
+                                       CodeGen.Assembly.Builder.DefineUnmanagedResource (win32ResourceFile);
                                }
                                catch (ArgumentException) {
                                        Report.Warning (0, new Location (-1), "Cannot embed win32 resources on this runtime: try the Mono runtime instead.");
@@ -1547,7 +1547,7 @@ namespace Mono.CSharp
                                if (define_icon == null) {
                                        Report.Warning (0, new Location (-1), "Cannot embed icon resource on this runtime: try the Mono runtime instead.");
                                }
-                               define_icon.Invoke (CodeGen.AssemblyBuilder, new object [] { win32IconFile });
+                               define_icon.Invoke (CodeGen.Assembly.Builder, new object [] { win32IconFile });
                        }
 
                        if (Report.Errors > 0)
index e8e7dd3cb768f13f5e33c1da53802c918e65df65..f2970053b63b327239a8b1fe0ee0bb8c6395a786 100755 (executable)
@@ -154,7 +154,7 @@ namespace Mono.CSharp {
                                if (TypeManager.NamespaceClash (Name, Location))
                                        return null;
                                
-                               ModuleBuilder builder = CodeGen.ModuleBuilder;
+                               ModuleBuilder builder = CodeGen.Module.Builder;
 
                                TypeBuilder = builder.DefineType (Name, attr, TypeManager.enum_type);
                        } else {
index 0815f78739d7670a8d789c2713aa3204d804c8a7..1b94afa21dcddb2150ef07009774c55909369182 100755 (executable)
@@ -4,8 +4,8 @@
 // Author:
 //   Miguel de Icaza (miguel@ximian.com)
 //
-// (C) 2001 Ximian, Inc.
-//
+// (C) 2001, 2002, 2003 Ximian, Inc.
+// (C) 2003, 2004 Novell, Inc.
 //
 #define USE_OLD
 
@@ -2201,12 +2201,6 @@ namespace Mono.CSharp {
                        Error_OperatorCannotBeApplied (loc, OperName (oper), left.Type, right.Type);
                }
 
-               static bool is_32_or_64 (Type t)
-               {
-                       return (t == TypeManager.int32_type || t == TypeManager.uint32_type ||
-                               t == TypeManager.int64_type || t == TypeManager.uint64_type);
-               }
-
                static bool is_unsigned (Type t)
                {
                        return (t == TypeManager.uint32_type || t == TypeManager.uint64_type ||
@@ -2221,6 +2215,28 @@ namespace Mono.CSharp {
                        else
                                return false;
                }
+
+               Expression Make32or64 (EmitContext ec, Expression e)
+               {
+                       Type t= e.Type;
+                       
+                       if (t == TypeManager.int32_type || t == TypeManager.uint32_type ||
+                           t == TypeManager.int64_type || t == TypeManager.uint64_type)
+                               return e;
+                       Expression ee = Convert.ImplicitConversion (ec, e, TypeManager.int32_type, loc);
+                       if (ee != null)
+                               return ee;
+                       ee = Convert.ImplicitConversion (ec, e, TypeManager.uint32_type, loc);
+                       if (ee != null)
+                               return ee;
+                       ee = Convert.ImplicitConversion (ec, e, TypeManager.int64_type, loc);
+                       if (ee != null)
+                               return ee;
+                       ee = Convert.ImplicitConversion (ec, e, TypeManager.uint64_type, loc);
+                       if (ee != null)
+                               return ee;
+                       return null;
+               }
                                        
                Expression CheckShiftArguments (EmitContext ec)
                {
@@ -2543,12 +2559,16 @@ namespace Mono.CSharp {
                                                        return new PointerArithmetic (
                                                                false, left, right, TypeManager.int64_type,
                                                                loc);
-                                       } else if (is_32_or_64 (r))
-                                               return new PointerArithmetic (
-                                                       oper == Operator.Addition, left, right, l, loc);
-                               } else if (r.IsPointer && is_32_or_64 (l) && oper == Operator.Addition)
-                                       return new PointerArithmetic (
-                                               true, right, left, r, loc);
+                                       } else {
+                                               Expression t = Make32or64 (ec, right);
+                                               if (t != null)
+                                                       return new PointerArithmetic (oper == Operator.Addition, left, t, l, loc);
+                                       }
+                               } else if (r.IsPointer && oper == Operator.Addition){
+                                       Expression t = Make32or64 (ec, left);
+                                       if (t != null)
+                                               return new PointerArithmetic (true, right, t, r, loc);
+                               }
                        }
                        
                        //
@@ -5906,7 +5926,7 @@ namespace Mono.CSharp {
                                eclass = ExprClass.Value;
                                return this;
                        } else {
-                               ModuleBuilder mb = CodeGen.ModuleBuilder;
+                               ModuleBuilder mb = CodeGen.Module.Builder;
                                ArrayList args = new ArrayList ();
                                
                                if (arguments != null) {
@@ -6122,7 +6142,7 @@ namespace Mono.CSharp {
                        if (dims != 1){
                                Type [] args;
                                ModuleBuilder mb = null;
-                               mb = CodeGen.ModuleBuilder;
+                               mb = CodeGen.Module.Builder;
                                args = new Type [dims + 1];
 
                                int j;
@@ -7323,7 +7343,7 @@ namespace Mono.CSharp {
 
                MethodInfo FetchGetMethod ()
                {
-                       ModuleBuilder mb = CodeGen.ModuleBuilder;
+                       ModuleBuilder mb = CodeGen.Module.Builder;
                        int arg_count = ea.Arguments.Count;
                        Type [] args = new Type [arg_count];
                        MethodInfo get;
@@ -7344,7 +7364,7 @@ namespace Mono.CSharp {
 
                MethodInfo FetchAddressMethod ()
                {
-                       ModuleBuilder mb = CodeGen.ModuleBuilder;
+                       ModuleBuilder mb = CodeGen.Module.Builder;
                        int arg_count = ea.Arguments.Count;
                        Type [] args = new Type [arg_count];
                        MethodInfo address;
@@ -7467,7 +7487,7 @@ namespace Mono.CSharp {
                        if (rank == 1)
                                EmitStoreOpcode (ig, t);
                        else {
-                               ModuleBuilder mb = CodeGen.ModuleBuilder;
+                               ModuleBuilder mb = CodeGen.Module.Builder;
                                int arg_count = ea.Arguments.Count;
                                Type [] args = new Type [arg_count + 1];
                                MethodInfo set;
index 86ccb282628d74456a09005ade5315a98a48c54f..426995a48ee4955775ed6d9f073dcddb39e9e23f 100755 (executable)
@@ -36,6 +36,7 @@ namespace Mono.CSharp {
                        MethodAttributes.Virtual;
                
                ArrayList bases;
+               Type[] baseTypes;
                
                ArrayList defined_method;
                ArrayList defined_indexer;
@@ -279,13 +280,10 @@ namespace Mono.CSharp {
                                                members.Add (eb);
                        }
 
-                       if (((bf & BindingFlags.DeclaredOnly) == 0) && (TypeBuilder.BaseType != null)) {
-                               MemberList parent_mi;
-                               
-                               parent_mi = TypeContainer.FindMembers (
-                                       TypeBuilder.BaseType, mt, bf, filter, criteria);
-
-                               members.AddRange (parent_mi);
+                       if (((bf & BindingFlags.DeclaredOnly) == 0) && (baseTypes != null)) {
+                               foreach (Type baseType in baseTypes) {
+                                       members.AddRange (TypeContainer.FindMembers (baseType, mt, bf, filter, criteria));
+                               }
                        }
 
                        return new MemberList (members);
@@ -302,6 +300,9 @@ namespace Mono.CSharp {
                //
                void PopulateMethod (TypeContainer parent, DeclSpace decl_space, InterfaceMethod im)
                {
+                       if (im.ReturnType == null)
+                               return;
+
                        Type return_type = im.ReturnType.Type;
                        if (return_type == null)
                                return_type = this.ResolveType (im.ReturnType, false, im.Location);
@@ -348,7 +349,7 @@ namespace Mono.CSharp {
                         // removing the old code here.
                         //
                         
-                        im.Builder = mb;
+                        im.SetBuilder (mb);
                         
                 }
 
@@ -358,12 +359,12 @@ namespace Mono.CSharp {
                void PopulateProperty (TypeContainer parent, DeclSpace decl_space, InterfaceProperty ip)
                {
                        PropertyBuilder pb;
-                       MethodBuilder get = null, set = null;
-                       ip.Type = this.ResolveTypeExpr (ip.Type, false, ip.Location);
-                       if (ip.Type == null)
+
+                       ip.ReturnType = this.ResolveTypeExpr (ip.ReturnType, false, ip.Location);
+                       if (ip.ReturnType == null)
                                return;
                        
-                       Type prop_type = ip.Type.Type;
+                       Type prop_type = ip.ReturnType.Type;
                        Type [] setter_args = new Type [1];
 
                        if (prop_type == null)
@@ -382,6 +383,8 @@ namespace Mono.CSharp {
                                ip.Name, PropertyAttributes.None,
                                prop_type, null);
 
+                        MethodBuilder get = null, set = null;
+                        
                        if (ip.HasGet){
                                get = TypeBuilder.DefineMethod (
                                        "get_" + ip.Name, property_attributes ,
@@ -416,7 +419,7 @@ namespace Mono.CSharp {
                                // HACK because System.Reflection.Emit is lame
                                //
                                Parameter [] parms = new Parameter [1];
-                               parms [0] = new Parameter (ip.Type, "value", Parameter.Modifier.NONE, null);
+                               parms [0] = new Parameter (ip.ReturnType, "value", Parameter.Modifier.NONE, null);
                                InternalParameters ipp = new InternalParameters (
                                        this, new Parameters (parms, null, Location.Null));
                                        
@@ -428,7 +431,7 @@ namespace Mono.CSharp {
 
                        TypeManager.RegisterProperty (pb, get, set);
                        property_builders.Add (pb);
-                        ip.Builder = pb;
+                       ip.SetBuilders (pb, get, set);
                }
 
                //
@@ -442,11 +445,11 @@ namespace Mono.CSharp {
                        //
                        MyEventBuilder eb;
                        MethodBuilder add = null, remove = null;
-                       ie.Type = this.ResolveTypeExpr (ie.Type, false, ie.Location);
-                       if (ie.Type == null)
+                       ie.ReturnType = this.ResolveTypeExpr (ie.ReturnType, false, ie.Location);
+                       if (ie.ReturnType == null)
                                return;
                        
-                       Type event_type = ie.Type.Type;
+                       Type event_type = ie.ReturnType.Type;
 
                        if (event_type == null)
                                return;
@@ -477,7 +480,7 @@ namespace Mono.CSharp {
                        eb.SetRemoveOnMethod (remove);
 
                        Parameter [] parms = new Parameter [1];
-                       parms [0] = new Parameter (ie.Type, "value", Parameter.Modifier.NONE, null);
+                       parms [0] = new Parameter (ie.ReturnType, "value", Parameter.Modifier.NONE, null);
                        InternalParameters ip = new InternalParameters (
                                this, new Parameters (parms, null, Location.Null));
 
@@ -494,7 +497,7 @@ namespace Mono.CSharp {
                        TypeManager.RegisterEvent (eb, add, remove);
                        event_builders.Add (eb);
 
-                        ie.Builder = eb;
+                        ie.SetBuilder (eb);
                }
 
                //
@@ -503,11 +506,11 @@ namespace Mono.CSharp {
                void PopulateIndexer (TypeContainer parent, DeclSpace decl_space, InterfaceIndexer ii)
                {
                        PropertyBuilder pb;
-                       ii.Type = this.ResolveTypeExpr (ii.Type, false, ii.Location);
-                       if (ii.Type == null)
+                       ii.ReturnType = this.ResolveTypeExpr (ii.ReturnType, false, ii.Location);
+                       if (ii ==null || ii.ReturnType == null)
                                return;
                        
-                       Type prop_type = ii.Type.Type;
+                       Type prop_type = ii.ReturnType.Type;
                        Type [] arg_types = ii.ParameterTypes (this);
                        Type [] value_arg_types;
 
@@ -582,7 +585,7 @@ namespace Mono.CSharp {
                                
                                pv = new Parameter [p.Length + 1];
                                p.CopyTo (pv, 0);
-                               pv [p.Length] = new Parameter (ii.Type, "value", Parameter.Modifier.NONE, null);
+                               pv [p.Length] = new Parameter (ii.ReturnType, "value", Parameter.Modifier.NONE, null);
                                Parameters value_params = new Parameters (pv, null, Location.Null);
                                value_params.GetParameterInfo (decl_space);
                                
@@ -612,7 +615,7 @@ namespace Mono.CSharp {
 
                        property_builders.Add (pb);
 
-                        ii.Builder = pb;
+                       ii.SetBuilders (pb, get_item, set_item);
                }
 
                /// <summary>
@@ -753,7 +756,7 @@ namespace Mono.CSharp {
                                if (TypeManager.NamespaceClash (Name, Location))
                                        return null;
                                
-                               ModuleBuilder builder = CodeGen.ModuleBuilder;
+                               ModuleBuilder builder = CodeGen.Module.Builder;
 
                                TypeBuilder = builder.DefineType (
                                        Name,
@@ -786,9 +789,11 @@ namespace Mono.CSharp {
                        }
 
                        if (ifaces != null) {
-                               foreach (TypeExpr iface in ifaces) {
-                                       Type itype = iface.ResolveType (ec);
+                               baseTypes = new Type[ifaces.Length];
+                               for (int i = 0; i < ifaces.Length; ++i) {
+                                       Type itype = ifaces [i].ResolveType (ec);
                                        TypeBuilder.AddInterfaceImplementation (itype);
+                                       baseTypes [i] = itype;
                                }
                        }
 
@@ -895,50 +900,26 @@ namespace Mono.CSharp {
                 /// <summary>
                ///   Applies all the attributes.
                /// </summary>
-                public void Emit (TypeContainer tc)
-                {
+               public void Emit (TypeContainer tc) {
                         if (OptAttributes != null) {
-                               EmitContext ec = new EmitContext (tc, this, Location, null, null,
-                                                                 ModFlags, false);
+                               EmitContext ec = new EmitContext (tc, this, Location, null, null, ModFlags, false);
                                Attribute.ApplyAttributes (ec, TypeBuilder, this, OptAttributes);
                        }
 
-                        // Now emit attributes for each interface member
-                        if (defined_method != null) {
-                                foreach (InterfaceMethod im in defined_method) {
-                                        EmitContext ec = new EmitContext (tc, this, Location, null,
-                                                                          im.ReturnType.Type, ModFlags, false);
-  
-                                        MethodCore.LabelParameters (ec, im.Builder,
-                                                                    im.Parameters,
-                                                                    im.OptAttributes,
-                                                                    Location);
-                                        
-                                        if (im.OptAttributes != null)
-                                               Attribute.ApplyAttributes (ec, im.Builder,
-                                                                           im, im.OptAttributes);
-                                        
-                                }
-                        }
-
-                        if (defined_properties != null) {
-                                foreach (InterfaceProperty ip in defined_properties) {
-                                        EmitContext ec = new EmitContext (tc, this, Location, null,
-                                                                          null, ModFlags, false);
-                                        
-                                        if (ip.OptAttributes != null)
-                                               Attribute.ApplyAttributes (ec, ip.Builder, ip, ip.OptAttributes);
-                                }
-                        }
+                       EmitSubType (tc, defined_method);
+                       EmitSubType (tc, defined_properties);
+                       EmitSubType (tc, defined_indexer);
+                       EmitSubType (tc, defined_events);
+               }
 
-                        if (defined_events != null) {
-                                foreach (InterfaceEvent ie in defined_events) {
-                                        EmitContext ec = new EmitContext (tc, this, Location, null,
-                                                                          null, ModFlags, false);
+               void EmitSubType (TypeContainer tc, ArrayList subType) {
+                       if (subType == null)
+                               return;
                                         
-                                        if (ie.OptAttributes != null)
-                                               Attribute.ApplyAttributes (ec, ie.Builder, ie, ie.OptAttributes);
-                                }
+                       foreach (InterfaceMemberBase imb in subType) {
+                               //TODO: set it somewhere earlier
+                               imb.ModFlags = ModFlags;
+                               imb.Emit (tc, this);
                         }
                 }
 
@@ -954,11 +935,6 @@ namespace Mono.CSharp {
                                                                 BindingFlags.Public | BindingFlags.Instance,
                                                                 Location.Null);
                        
-                       if (!(ml is MethodGroupExpr)) {
-                               Console.WriteLine ("Internal error !!!!");
-                               return null;
-                       }
-                       
                        MethodGroupExpr mg = (MethodGroupExpr) ml;
 
                        MethodBase constructor = mg.Methods [0];
@@ -1038,65 +1014,149 @@ namespace Mono.CSharp {
                }
        }
 
-       public class InterfaceMemberBase {
-               public readonly string Name;
+       public abstract class InterfaceMemberBase: MemberCore, IAttributeSupport {
                public readonly bool IsNew;
-               public Attributes OptAttributes;
+                // Why is not readonly
+               public Expression ReturnType;
                
-               public InterfaceMemberBase (string name, bool is_new, Attributes attrs)
+               public InterfaceMemberBase (Expression type, string name, bool is_new, Attributes attrs, Location loc):
+                       base (name, attrs, loc)
                {
-                       Name = name;
+                       ReturnType = type;
                        IsNew = is_new;
-                       OptAttributes = attrs;
                }
-       }
+
+               public virtual EmitContext Emit (TypeContainer tc, DeclSpace ds) {
+                       EmitContext ec = null;
+                       if (OptAttributes != null) {
+                               ec = new EmitContext (tc, ds, Location, null, null, ModFlags, false);
+
+                               Attribute.ApplyAttributes (ec, null, this, OptAttributes);
+                       }
+
+                       return ec;
+               }
+
+               #region IAttributeSupport Members
+               public abstract void SetCustomAttribute (CustomAttributeBuilder customBuilder);
+               #endregion
        
-       public class InterfaceProperty : InterfaceMemberBase {
+               public override bool Define (TypeContainer parent) {
+                       throw new NotImplementedException ();
+               }
+       }
+
+       abstract public class InterfaceSetGetBase: InterfaceMemberBase 
+       {
+               internal sealed class PropertyAccessor: IAttributeSupport 
+               {
+                       Attributes m_attrs;
+                       MethodBuilder m_builder;
+
+                       public PropertyAccessor (Attributes attrs) {
+                               m_attrs = attrs;
+                       }
+                        
+                       public MethodBuilder Builder {
+                               set {
+                                       m_builder = value;
+                               }
+                       }
+                        
+                       public void Emit (EmitContext ec) {
+                               if (m_attrs != null) {
+                                       Attribute.ApplyAttributes (ec, this, this, m_attrs);
+                                }
+                       }
+                                       
+                       public void SetCustomAttribute (CustomAttributeBuilder customAttribute) {
+                               m_builder.SetCustomAttribute (customAttribute);
+                       }
+               }
+            
+
+               PropertyAccessor m_get;
+               PropertyAccessor m_set;
+               protected PropertyBuilder Builder;
+
                public readonly bool HasSet;
                public readonly bool HasGet;
-               public readonly Location Location;
-               public Expression Type;
-                public PropertyBuilder Builder;
                
-               public InterfaceProperty (Expression type, string name,
-                                         bool is_new, bool has_get, bool has_set,
-                                         Attributes attrs, Location loc)
-                       : base (name, is_new, attrs)
+               public InterfaceSetGetBase (Expression type, string name, bool is_new,
+                                               bool has_get, bool has_set, Attributes prop_attrs, Attributes get_attrs,
+                        Attributes set_attrs, Location loc)
+                       :base (type, name, is_new, prop_attrs, loc)
                {
-                       Type = type;
                        HasGet = has_get;
                        HasSet = has_set;
-                       Location = loc;
+                       m_get = new PropertyAccessor (get_attrs);
+                       m_set = new PropertyAccessor (set_attrs);
+                       ReturnType = type;
                }
+
+               public override EmitContext Emit (TypeContainer tc, DeclSpace ds) {
+                       EmitContext ec = base.Emit (tc, ds);
+                       if (ec == null)
+                               ec = new EmitContext (tc, ds, Location, null, null, ModFlags, false);
+
+                       m_get.Emit (ec);
+                       m_set.Emit (ec);
+                       return ec;
+               }
+
+               // TODO: It would be nice to have this method private
+               public void SetBuilders (PropertyBuilder pb, MethodBuilder gb, MethodBuilder sb) {
+                       Builder = pb;
+                       m_get.Builder = gb;
+                       m_set.Builder = sb;
+               }
+
+               public override void SetCustomAttribute (CustomAttributeBuilder customBuilder) {
+                       Builder.SetCustomAttribute (customBuilder);
+               }
+
        }
 
        public class InterfaceEvent : InterfaceMemberBase {
-               public readonly Location Location;
-               public Expression Type;
-                public MyEventBuilder Builder;
+               MyEventBuilder Builder;
                 
                public InterfaceEvent (Expression type, string name, bool is_new, Attributes attrs,
                                       Location loc)
-                       : base (name, is_new, attrs)
+                       : base (type, name, is_new, attrs, loc)
                {
-                       Type = type;
-                       Location = loc;
+               }
+
+               public override string GetSignatureForError () {
+                       return TypeManager.GetFullNameSignature (Builder);
+               }
+
+               public void SetBuilder (MyEventBuilder eb) {
+                       Builder = eb;
+               }
+
+               public override void SetCustomAttribute (CustomAttributeBuilder customBuilder) {
+                       Builder.SetCustomAttribute (customBuilder);
                }
        }
        
        public class InterfaceMethod : InterfaceMemberBase {
-               public Expression ReturnType;
                public readonly Parameters Parameters;
-               public readonly Location Location;
-                public MethodBuilder Builder;
+               MethodBuilder Builder;
                 
                public InterfaceMethod (Expression return_type, string name, bool is_new, Parameters args,
                                        Attributes attrs, Location l)
-                       : base (name, is_new, attrs)
+                       : base (return_type, name, is_new, attrs, l)
                {
-                       this.ReturnType = return_type;
                        this.Parameters = args;
-                       Location = l;
+               }
+
+               public override EmitContext Emit(TypeContainer tc, DeclSpace ds) {
+                       EmitContext ec = base.Emit(tc, ds);
+                       if (ec == null) 
+                               ec = new EmitContext (tc, ds, Location, null, null, ModFlags, false);
+
+                       MethodCore.LabelParameters (ec, Builder, Parameters, OptAttributes, Location);
+                       return ec;
                }
 
                /// <summary>
@@ -1117,32 +1177,55 @@ namespace Mono.CSharp {
                        return (IsNew ? "new-" : "") + ret.FullName + "(" + args + ")";
                }
 
+               public override string GetSignatureForError () {
+                       return TypeManager.CSharpSignature (Builder);
+               }
+
                public Type [] ParameterTypes (DeclSpace ds)
                {
                        return Parameters.GetParameterInfo (ds);
                }
+
+               public void SetBuilder (MethodBuilder mb) {
+                       Builder = mb;
+               }
+
+               public override void SetCustomAttribute(CustomAttributeBuilder customBuilder) {
+                       Builder.SetCustomAttribute (customBuilder);
+               }
+       }
+
+       public class InterfaceProperty : InterfaceSetGetBase 
+       {
+               public InterfaceProperty (Expression type, string name,
+                       bool is_new, bool has_get, bool has_set,
+                       Attributes prop_attrs, Attributes get_attrs,
+                       Attributes set_attrs, Location loc)
+                       : base (type, name, is_new, has_get, has_set, prop_attrs, get_attrs, set_attrs, loc)
+               {
+               }
+
+               public override string GetSignatureForError () {
+                       return TypeManager.CSharpSignature (Builder, false);
+               }       
        }
 
-       public class InterfaceIndexer : InterfaceMemberBase {
-               public readonly bool HasGet, HasSet;
+       public class InterfaceIndexer : InterfaceSetGetBase {
                public readonly Parameters Parameters;
-               public readonly Location Location;
-               public Expression Type;
-                public PropertyBuilder Builder;
-               
+                
                public InterfaceIndexer (Expression type, Parameters args, bool do_get, bool do_set,
-                                        bool is_new, Attributes attrs, Location loc)
-                       : base ("", is_new, attrs)
+                                        bool is_new, Attributes attrs, Attributes get_attrs, Attributes set_attrs,
+                                         Location loc)
+                       : base (type, "Item", is_new, do_get, do_set, attrs, get_attrs, set_attrs, loc)
                {
-                       Type = type;
                        Parameters = args;
-                       HasGet = do_get;
-                       HasSet = do_set;
-                       Location = loc;
                }
 
-               public Type [] ParameterTypes (DeclSpace ds)
-               {
+               public override string GetSignatureForError() {
+                       return TypeManager.CSharpSignature (Builder, true);
+               }
+
+               public Type [] ParameterTypes (DeclSpace ds) {
                        return Parameters.GetParameterInfo (ds);
                }
        }
index decfd4612b814e4b41f94110f26c70dbe93c18c8..8beb54506631f158a0cc13a523cdd0e5ba3aad89 100644 (file)
@@ -66,6 +66,7 @@ namespace Mono.CSharp {
                                return false;
                        if (!CheckContext (ec, loc))
                                return false;
+
                        
                        Type iterator_type = IteratorHandler.Current.IteratorType;
                        if (expr.Type != iterator_type){
@@ -563,7 +564,7 @@ namespace Mono.CSharp {
                        Create_Current ();
                        Create_Dispose ();
 
-                       if (return_type == TypeManager.ienumerable_type){
+                       if (IsIEnumerable (return_type)){
                                Create_GetEnumerator ();
                                RootContext.RegisterHelperClass (enumerable_proxy_class);
                        }
@@ -617,7 +618,7 @@ namespace Mono.CSharp {
                                // Create the proxy class type.
                                handler.MakeEnumeratorProxy ();
 
-                               if (handler.return_type == TypeManager.ienumerable_type)
+                               if (IsIEnumerable (handler.return_type))
                                        handler.MakeEnumerableProxy ();
 
                                type = handler.return_type;
@@ -633,7 +634,7 @@ namespace Mono.CSharp {
                        {
                                handler.LoadArgs (ec.ig);
                                
-                               if (handler.return_type == TypeManager.ienumerable_type)
+                               if (IsIEnumerable (handler.return_type))
                                        ec.ig.Emit (OpCodes.Newobj, (ConstructorInfo) handler.enumerable_proxy_constructor);
                                else 
                                        ec.ig.Emit (OpCodes.Newobj, (ConstructorInfo) handler.enumerator_proxy_constructor);
@@ -658,18 +659,27 @@ namespace Mono.CSharp {
                                return ret_val;
                        }
                }
+
+               static bool IsIEnumerable (Type t)
+               {
+                       return t == TypeManager.ienumerable_type || TypeManager.ImplementsInterface (t, TypeManager.ienumerable_type);
+               }
+
+               static bool IsIEnumerator (Type t)
+               {
+                       return t == TypeManager.ienumerator_type || TypeManager.ImplementsInterface (t, TypeManager.ienumerator_type);
+               }
                
                //
                // Returns the new block for the method, or null on failure
                //
                public Block Setup (Block block)
                {
-                       if (return_type != TypeManager.ienumerator_type &&
-                           return_type != TypeManager.ienumerable_type){
+                       if (!(IsIEnumerator (return_type) || IsIEnumerable (return_type))){
                                Report.Error (
                                        -205, loc, String.Format (
-                                               "The method `{0}' contains a yield statement, but has an invalid return type for an iterator",
-                                               name));
+                                               "The method `{0}' contains a yield statement, but has an invalid return type for an iterator `{1}'",
+                                               name, TypeManager.CSharpName (return_type)));
                                return null;
                        }
 
index c220b951512d84a4e3edf8e72c979094dbd28875..bbe5e526314012c3fe674dbcce5b5a43832c1bc6 100755 (executable)
@@ -35,7 +35,7 @@ namespace Mono.CSharp {
                public readonly Modifier ModFlags;
                public Attributes OptAttributes;
                public readonly string Name;
-               public Type parameter_type;
+               Type parameter_type;
                
                public Parameter (Expression type, string name, Modifier mod, Attributes attrs)
                {
index e3c1e323ab8cd9fa28e7fe68ea6714c6dcf4f5f0..d1963c494ffa609154accd1e14b4ce8fac83a378 100755 (executable)
@@ -29,11 +29,6 @@ namespace Mono.CSharp {
                //
                public static Hashtable AllDefines = new Hashtable ();
                
-               //
-               // The list of global attributes (those that target the assembly)
-               //
-               static Hashtable global_attributes = new Hashtable ();
-               
                //
                // Whether we are being linked against the standard libraries.
                // This is only used to tell whether `System.Object' should
@@ -715,20 +710,8 @@ namespace Mono.CSharp {
                        // Because of the strange way in which we do things, global
                        // attributes must be processed first.
                        //
-                       if (global_attributes.Count > 0){
-                               AssemblyBuilder ab = CodeGen.AssemblyBuilder;
-                               TypeContainer dummy = new TypeContainer ();
-                               EmitContext temp_ec = new EmitContext (
-                                       dummy, Mono.CSharp.Location.Null, null, null, 0, false);
-                       
-                               foreach (DictionaryEntry de in global_attributes){
-                                       NamespaceEntry ns = (NamespaceEntry) de.Key;
-                                       Attributes attrs = (Attributes) de.Value;
-                                       
-                                       dummy.NamespaceEntry = ns;
-                                       Attribute.ApplyAttributes (temp_ec, ab, ab, attrs);
-                               }
-                       }
+                       CodeGen.Assembly.Emit ();
+                       CodeGen.Module.Emit ();
                         
                        if (attribute_types != null)
                                foreach (TypeContainer tc in attribute_types)
@@ -754,18 +737,6 @@ namespace Mono.CSharp {
 
                        if (EmitCodeHook != null)
                                EmitCodeHook ();
-
-                       
-                       if (Unsafe) {
-                               if (TypeManager.unverifiable_code_ctor == null) {
-                                       Console.WriteLine ("Internal error ! Cannot set unverifiable code attribute.");
-                                       return;
-                               }
-                               
-                               CustomAttributeBuilder cb = new CustomAttributeBuilder (TypeManager.unverifiable_code_ctor,
-                                                                                       new object [0]);
-                               CodeGen.ModuleBuilder.SetCustomAttribute (cb);
-                       }
                }
                
                //
@@ -803,7 +774,7 @@ namespace Mono.CSharp {
                        FieldBuilder fb;
                        
                        if (impl_details_class == null){
-                               impl_details_class = CodeGen.ModuleBuilder.DefineType (
+                               impl_details_class = CodeGen.Module.Builder.DefineType (
                                        "<PrivateImplementationDetails>",
                                         TypeAttributes.NotPublic,
                                         TypeManager.object_type);
@@ -817,21 +788,6 @@ namespace Mono.CSharp {
                        
                        return fb;
                }
-
-               //
-               // Adds a global attribute that was declared in `container', 
-               // the attribute is in `attr', and it was defined at `loc'
-               //
-               static public void AddGlobalAttributeSection (TypeContainer container, AttributeSection attr)
-               {
-                       NamespaceEntry ns = container.NamespaceEntry;
-                       Attributes a = (Attributes) global_attributes [ns];
-
-                       if (a == null)
-                               global_attributes [ns] = new Attributes (attr);
-                       else
-                               a.AddAttributeSection (attr);
-               }
        }
 }
              
index b4ff47366bd1219670567d972b7b7b96bdd718ec..61bb4297b5f1ee739d4b3d2af943a930e6273327 100755 (executable)
@@ -3543,7 +3543,7 @@ namespace Mono.CSharp {
                                if (hm == null){
                                        error1579 (expr.Type);
                                        return false;
-                               }
+                               }                       
 
                                array_type = expr.Type;
                                element_type = hm.element_type;
@@ -3724,30 +3724,51 @@ namespace Mono.CSharp {
                        // Ok, we can access it, now make sure that we can do something
                        // with this `GetEnumerator'
                        //
-
+                       
+                       Type return_type = mi.ReturnType;
                        if (mi.ReturnType == TypeManager.ienumerator_type ||
-                           TypeManager.ienumerator_type.IsAssignableFrom (mi.ReturnType) ||
-                           (!RootContext.StdLib && TypeManager.ImplementsInterface (mi.ReturnType, TypeManager.ienumerator_type))) {
-                               if (declaring != TypeManager.string_type) {
+                           TypeManager.ienumerator_type.IsAssignableFrom (return_type) ||
+                           (!RootContext.StdLib && TypeManager.ImplementsInterface (return_type, TypeManager.ienumerator_type))) {
+                               
+                               //
+                               // If it is not an interface, lets try to find the methods ourselves.
+                               // For example, if we have:
+                               // public class Foo : IEnumerator { public bool MoveNext () {} public int Current { get {}}}
+                               // We can avoid the iface call. This is a runtime perf boost.
+                               // even bigger if we have a ValueType, because we avoid the cost
+                               // of boxing.
+                               //
+                               // We have to make sure that both methods exist for us to take
+                               // this path. If one of the methods does not exist, we will just
+                               // use the interface. Sadly, this complex if statement is the only
+                               // way I could do this without a goto
+                               //
+                               
+                               if (return_type.IsInterface ||
+                                   (hm.move_next = FetchMethodMoveNext (return_type)) == null ||
+                                   (hm.get_current = FetchMethodGetCurrent (return_type)) == null) {
+                                       
                                        hm.move_next = TypeManager.bool_movenext_void;
                                        hm.get_current = TypeManager.object_getcurrent_void;
-                                       return true;
+                                       return true;    
                                }
-                       }
 
-                       //
-                       // Ok, so they dont return an IEnumerable, we will have to
-                       // find if they support the GetEnumerator pattern.
-                       //
-                       Type return_type = mi.ReturnType;
-
-                       hm.move_next = FetchMethodMoveNext (return_type);
-                       if (hm.move_next == null)
-                               return false;
-                       hm.get_current = FetchMethodGetCurrent (return_type);
-                       if (hm.get_current == null)
-                               return false;
+                       } else {
 
+                               //
+                               // Ok, so they dont return an IEnumerable, we will have to
+                               // find if they support the GetEnumerator pattern.
+                               //
+                               
+                               hm.move_next = FetchMethodMoveNext (return_type);
+                               if (hm.move_next == null)
+                                       return false;
+                               
+                               hm.get_current = FetchMethodGetCurrent (return_type);
+                               if (hm.get_current == null)
+                                       return false;
+                       }
+                       
                        hm.element_type = hm.get_current.ReturnType;
                        hm.enumerator_type = return_type;
                        hm.is_disposable = !hm.enumerator_type.IsSealed ||
@@ -3876,14 +3897,14 @@ namespace Mono.CSharp {
                        Label end_try = ig.DefineLabel ();
                        
                        ig.MarkLabel (ec.LoopBegin);
-                       enumerator.EmitLoad ();
-                       ig.Emit (OpCodes.Callvirt, hm.move_next);
+                       
+                       enumerator.EmitCall (hm.move_next);
+                       
                        ig.Emit (OpCodes.Brfalse, end_try);
                        if (ec.InIterator)
                                ec.EmitThis ();
                        
-                       enumerator.EmitLoad ();
-                       ig.Emit (OpCodes.Callvirt, hm.get_current);
+                       enumerator.EmitCall (hm.get_current);
 
                        if (ec.InIterator){
                                conv.Emit (ec);
@@ -4046,7 +4067,7 @@ namespace Mono.CSharp {
                                for (int i = 0; i < rank; i++)
                                        args [i] = TypeManager.int32_type;
 
-                               ModuleBuilder mb = CodeGen.ModuleBuilder;
+                               ModuleBuilder mb = CodeGen.Module.Builder;
                                get = mb.GetArrayMethod (
                                        array_type, "Get",
                                        CallingConventions.HasThis| CallingConventions.Standard,
index 7d042bf7b6847011a2c98ae5152d1d55d6bc5a3c..9c808accf068d3d75bb55245753e6f5cdbe54630 100755 (executable)
@@ -569,7 +569,7 @@ public class TypeManager {
                //
                if (ret == null){
                        if (pointers [t] == null)
-                               pointers [t] = CodeGen.ModuleBuilder.GetType (tname);
+                               pointers [t] = CodeGen.Module.Builder.GetType (tname);
                        
                        ret = (Type) pointers [t];
                }
@@ -1054,7 +1054,7 @@ public class TypeManager {
                                args [2] = enum_type;
                                args [3] = void_type;
                                
-                               set_corlib_type_builders.Invoke (CodeGen.AssemblyBuilder, args);
+                               set_corlib_type_builders.Invoke (CodeGen.Assembly.Builder, args);
                        } else {
                                // Compatibility for an older version of the class libs.
                                set_corlib_type_builders = GetMethod (
@@ -1071,7 +1071,7 @@ public class TypeManager {
                                args [1] = value_type;
                                args [2] = enum_type;
                                
-                               set_corlib_type_builders.Invoke (CodeGen.AssemblyBuilder, args);
+                               set_corlib_type_builders.Invoke (CodeGen.Assembly.Builder, args);
                        }
                }