Share more code between class/interface/delegate and enum.
authorMiguel de Icaza <miguel@gnome.org>
Sun, 31 Mar 2002 02:46:48 +0000 (02:46 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Sun, 31 Mar 2002 02:46:48 +0000 (02:46 -0000)
Simplify the recursive toplevel definition process.
Initial steps to fix the toplevel delegate type reference declarations.

2002-03-30  Miguel de Icaza  <miguel@ximian.com>

* expression.cs (Unary): Optimize - - expr into expr.
(Binary): Optimize a + (-b) into a -b.

* codegen.cs (CodeGen): Made all methods static.

2002-03-29  Miguel de Icaza  <miguel@ximian.com>

* rootcontext.cs:

* decl.cs: Rename `definition' into `TypeBuilder' and drop the
TypeBuilder property.

* cs-parser.jay: Drop the use of RecordXXX and use RecordDecl
instead.

* tree.cs: Removed the various RecordXXXX, and replaced with a
single RecordDecl.  Removed all the accessor methods, and just
left a single access point Type

* enum.cs: Rename DefineEnum to DefineType.

* decl.cs: New abstract method `DefineType' used to unify the
Defines for Enumerations, Interfaces, TypeContainers and
Delegates.

(FindType): Moved LookupInterfaceOrClass here.  Moved the
LookupBaseClasses method that used to live in class.cs and
interface.cs here, and renamed to FindType.

* delegate.cs: Implement DefineType.  Take advantage of the
refactored pattern for locating the parent builder without taking
the parent_builder argument (which we know does not work if we are
nested, and triggering a toplevel definition).

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

17 files changed:
mcs/mcs/ChangeLog
mcs/mcs/TODO
mcs/mcs/class.cs
mcs/mcs/codegen.cs
mcs/mcs/cs-parser.jay
mcs/mcs/decl.cs
mcs/mcs/delegate.cs
mcs/mcs/driver.cs
mcs/mcs/enum.cs
mcs/mcs/expression.cs
mcs/mcs/interface.cs
mcs/mcs/location.cs
mcs/mcs/makefile
mcs/mcs/parameter.cs
mcs/mcs/rootcontext.cs
mcs/mcs/statement.cs
mcs/mcs/tree.cs

index 776d2f65a1c900cfaabe0b628ab7db6bf60c4817..df5855fe2b76b289b4c0177e4ed6f1cabe0c5ee1 100755 (executable)
@@ -1,3 +1,39 @@
+2002-03-30  Miguel de Icaza  <miguel@ximian.com>
+
+       * expression.cs (Unary): Optimize - - expr into expr.
+       (Binary): Optimize a + (-b) into a -b.
+
+       * codegen.cs (CodeGen): Made all methods static.
+
+2002-03-29  Miguel de Icaza  <miguel@ximian.com>
+
+       * rootcontext.cs: 
+
+       * decl.cs: Rename `definition' into `TypeBuilder' and drop the
+       TypeBuilder property.
+
+       * cs-parser.jay: Drop the use of RecordXXX and use RecordDecl
+       instead. 
+
+       * tree.cs: Removed the various RecordXXXX, and replaced with a
+       single RecordDecl.  Removed all the accessor methods, and just
+       left a single access point Type 
+
+       * enum.cs: Rename DefineEnum to DefineType.
+
+       * decl.cs: New abstract method `DefineType' used to unify the
+       Defines for Enumerations, Interfaces, TypeContainers and
+       Delegates.
+
+       (FindType): Moved LookupInterfaceOrClass here.  Moved the
+       LookupBaseClasses method that used to live in class.cs and
+       interface.cs here, and renamed to FindType.
+       
+       * delegate.cs: Implement DefineType.  Take advantage of the
+       refactored pattern for locating the parent builder without taking
+       the parent_builder argument (which we know does not work if we are
+       nested, and triggering a toplevel definition).
+
 2002-03-28  Miguel de Icaza  <miguel@ximian.com>
 
        * decl.cs (MemberCore.CheckMethodAgainstBase): Test if the
index d9bb58408401001708dd585c347c6d0a2e0e4eea..dc99a79dbe4a3f640023990179dc081b00529458 100644 (file)
@@ -172,7 +172,7 @@ PENDING TASKS
 OPTIMIZATIONS
 -------------
 
-* Make the CodeGen fields static (like SymbolWriter, which gets used a lot)
+* Implement loop inversion for our loops
 
 * Add test case for destructors
 
@@ -207,18 +207,6 @@ OPTIMIZATIONS
        It could be static for all we care, and just use it for making
        sure that there are no recursive invocations on it.
 
-* Static-ization
-
-       Since AppDomain exists, maybe we can get rid of all the stuff
-       that is part of the `compiler instance' and just use globals
-       everywhere.
-
-
-* Constructors
-
-       Currently it calls the parent constructor before initializing fields.
-       It should do it the other way around.
-
 * Use of EmitBranchable
 
        Currently I use brfalse/brtrue in the code for statements, instead of
@@ -248,7 +236,6 @@ OPTIMIZATIONS
        in the stack, so that later a Store can be emitted using that
        this pointer (consider Property++ or Indexer++)
 
-
 * Optimizations: variable allocation.
 
        When local variables of a type are required, we should request
index 46aced7ebe5fe1f95f20aef4c91b134e20f43d76..263c9e0bc62db77d83ba8f0bb313e237c28d1c42 100755 (executable)
@@ -726,151 +726,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               public static string MakeFQN (string nsn, string name)
-               {
-                       string prefix = (nsn == "" ? "" : nsn + ".");
-
-                       return prefix + name;
-               }
-                      
-               Type LookupInterfaceOrClass (string ns, string name, bool is_class, out bool error)
-               {
-                       TypeContainer parent;
-                       Type t;
-
-                       error = false;
-                       name = MakeFQN (ns, name);
-                       
-                       t  = TypeManager.LookupType (name);
-                       if (t != null)
-                               return t;
-
-                       if (is_class)
-                               parent = (Class) RootContext.Tree.Classes [name];
-                       else 
-                               parent = (Struct) RootContext.Tree.Structs [name];
-
-                       if (parent == null) {
-                               Enum en = null;
-                               
-                               if (RootContext.Tree.Enums != null)
-                                       en = (Enum) RootContext.Tree.Enums [name];
-                               
-                               if (en != null) {
-                                       t = en.DefineEnum ();
-                                       
-                                       if (t != null)
-                                               return t;
-                               }
-                       }
-                       
-                       if (parent != null){
-                               t = parent.DefineType ();
-                               if (t == null){
-                                       Report.Error (146, "Class definition is circular: `"+name+"'");
-                                       error = true;
-                                       return null;
-                               }
-
-                               return t;
-                       }
-
-                       return null;
-               }
-               
-               //
-               // returns the type for an interface or a class, this will recursively
-               // try to define the types that it depends on.
-               //
-               Type GetInterfaceOrClass (string name, bool is_class)
-               {
-                       Type t;
-                       bool error;
-
-                       //
-                       // For the case the type we are looking for is nested within this one
-                       // or is in any base class
-                       //
-                       DeclSpace containing_ds = this;
-
-                       while (containing_ds != null){
-                               Type current_type = containing_ds.TypeBuilder;
-
-                               while (current_type != null) {
-                                       string pre = current_type.FullName;
-                                       
-                                       t = LookupInterfaceOrClass (pre, name, is_class, out error);
-                                       if (error)
-                                               return null;
-                               
-                                       if (t != null) 
-                                               return t;
-
-                                       current_type = current_type.BaseType;
-                               }
-                               containing_ds = containing_ds.Parent;
-                       }
-                       
-                       //
-                       // Attempt to lookup the class on our namespace and all it's implicit parents
-                       //
-                       for (string ns = Namespace.Name; ns != null; ns = RootContext.ImplicitParent (ns)) {
-
-                               t = LookupInterfaceOrClass (ns, name, is_class, out error);
-                               if (error)
-                                       return null;
-                               
-                               if (t != null) 
-                                       return t;
-                       }
-                       
-                       //
-                       // Attempt to do a direct unqualified lookup
-                       //
-                       t = LookupInterfaceOrClass ("", name, is_class, out error);
-                       if (error)
-                               return null;
-                       
-                       if (t != null)
-                               return t;
-                       
-                       //
-                       // Attempt to lookup the class on any of the `using'
-                       // namespaces
-                       //
-
-                       for (Namespace ns = Namespace; ns != null; ns = ns.Parent){
-
-                               t = LookupInterfaceOrClass (ns.Name, name, is_class, out error);
-                               if (error)
-                                       return null;
-
-                               if (t != null)
-                                       return t;
-
-                               //
-                               // Now check the using clause list
-                               //
-                               ArrayList using_list = ns.UsingTable;
-                               
-                               if (using_list == null)
-                                       continue;
-
-                               foreach (string n in using_list){
-                                       t = LookupInterfaceOrClass (n, name, is_class, out error);
-                                       if (error)
-                                               return null;
-
-                                       if (t != null)
-                                               return t;
-                               }
-                               
-                       }
-
-                       Report.Error (246, Location, "Can not find type `"+name+"'");
-                       return null;
-               }
-
                /// <summary>
                ///   This function computes the Base class and also the
                ///   list of interfaces that the class or struct @c implements.
@@ -920,7 +775,7 @@ namespace Mono.CSharp {
 
                        if (is_class){
                                string name = (string) bases [0];
-                               Type first = GetInterfaceOrClass (name, is_class);
+                               Type first = FindType (name);
 
                                if (first == null){
                                        error = true;
@@ -942,7 +797,7 @@ namespace Mono.CSharp {
                        
                        for (i = start, j = 0; i < count; i++, j++){
                                string name = (string) bases [i];
-                               Type t = GetInterfaceOrClass (name, is_class);
+                               Type t = FindType (name);
                                
                                if (t == null){
                                        error = true;
@@ -987,7 +842,7 @@ namespace Mono.CSharp {
                //
                // Defines the type in the appropriate ModuleBuilder or TypeBuilder.
                //
-               public TypeBuilder DefineType ()
+               public override TypeBuilder DefineType ()
                {
                        Type parent;
                        Type [] ifaces;
@@ -1012,7 +867,7 @@ namespace Mono.CSharp {
                        if (error)
                                return null;
 
-                       if (this is Class && parent != null){
+                       if (is_class && parent != null){
                                if (parent == TypeManager.enum_type ||
                                    (parent == TypeManager.value_type && RootContext.StdLib) ||
                                    parent == TypeManager.delegate_type ||
@@ -1026,7 +881,7 @@ namespace Mono.CSharp {
 
                        // if (parent_builder is ModuleBuilder) {
                        if (IsTopLevel){
-                               ModuleBuilder builder = RootContext.ModuleBuilder;
+                               ModuleBuilder builder = CodeGen.ModuleBuilder;
                                
                                //
                                // Structs with no fields need to have a ".size 1"
@@ -1074,7 +929,7 @@ namespace Mono.CSharp {
 
                        if (Interfaces != null){
                                foreach (Interface iface in Interfaces)
-                                       iface.DefineInterface ();
+                                       iface.DefineType ();
                        }
                        
                        if (Types != null) {
@@ -1084,12 +939,12 @@ namespace Mono.CSharp {
 
                        if (Delegates != null) {
                                foreach (Delegate d in Delegates)
-                                       d.DefineDelegate (TypeBuilder);
+                                       d.DefineType ();
                        }
 
                        if (Enums != null) {
                                foreach (Enum en in Enums)
-                                       en.DefineEnum ();
+                                       en.DefineType ();
                        }
 
                        InTransit = false;
@@ -2209,7 +2064,7 @@ namespace Mono.CSharp {
                {
                        Report.Error (
                                17, Location,
-                               "Program `" + RootContext.CodeGen.FileName +
+                               "Program `" + CodeGen.FileName +
                                "'  has more than one entry point defined: `" +
                                b.DeclaringType.Name + "." + b.Name + "'");
                }
@@ -2496,7 +2351,7 @@ namespace Mono.CSharp {
                        if (Name == "Finalize" && type_return_type == TypeManager.void_type)
                                EmitDestructor (ec);
                        else {
-                               ISymbolWriter sw = RootContext.CodeGen.SymbolWriter;
+                               ISymbolWriter sw = CodeGen.SymbolWriter;
 
                                if ((sw != null) && (!Location.IsNull (Location))) {
                                        MethodToken token = MethodBuilder.GetToken ();
index 69aceb59da62a5b9a1ef8562e40324e3fc2a4499..2006f49ee1c0d9c88236de4a6d52edc9b7bfbf6d 100755 (executable)
@@ -19,11 +19,11 @@ namespace Mono.CSharp {
        ///    Code generator class.
        /// </summary>
        public class CodeGen {
-               AppDomain current_domain;
-               AssemblyBuilder assembly_builder;
-               ModuleBuilder   module_builder;
+               static AppDomain current_domain;
+               static AssemblyBuilder assembly_builder;
+               static ModuleBuilder   module_builder;
 
-               public ISymbolWriter SymbolWriter;
+               static public ISymbolWriter SymbolWriter;
 
                public static string Basename (string name)
                {
@@ -39,19 +39,19 @@ namespace Mono.CSharp {
                        return name;
                }
 
-               string TrimExt (string name)
+               static string TrimExt (string name)
                {
                        int pos = name.LastIndexOf (".");
 
                        return name.Substring (0, pos);
                }
 
-               public string FileName;
+               static public string FileName;
 
                //
                // This routine initializes the Mono runtime SymbolWriter.
                //
-               void InitMonoSymbolWriter (string basename)
+               static void InitMonoSymbolWriter (string basename)
                {
                        string symbol_output = basename + "-debug.s";
 
@@ -65,7 +65,7 @@ namespace Mono.CSharp {
                //
                // Initializes the symbol writer
                //
-               void InitializeSymbolWriter (string basename)
+               static void InitializeSymbolWriter (string basename)
                {
                        SymbolWriter = module_builder.GetSymWriter ();
 
@@ -98,8 +98,11 @@ namespace Mono.CSharp {
                                break;
                        }
                }
-               
-               public CodeGen (string name, string output, bool want_debugging_support)
+
+               //
+               // Initializes the code generator variables
+               //
+               static public void Init (string name, string output, bool want_debugging_support)
                {
                        AssemblyName an;
 
@@ -125,19 +128,19 @@ namespace Mono.CSharp {
                                InitializeSymbolWriter (an.Name);
                }
 
-               public AssemblyBuilder AssemblyBuilder {
+               static public AssemblyBuilder AssemblyBuilder {
                        get {
                                return assembly_builder;
                        }
                }
                
-               public ModuleBuilder ModuleBuilder {
+               static public ModuleBuilder ModuleBuilder {
                        get {
                                return module_builder;
                        }
                }
 
-               public void Save (string name)
+               static public void Save (string name)
                {
                        try {
                                assembly_builder.Save (Basename (name));
@@ -146,7 +149,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               public void SaveSymbols ()
+               static public void SaveSymbols ()
                {
                        if (SymbolWriter != null) {
                                // If we have a symbol writer, call its Close() method to write
@@ -304,7 +307,7 @@ namespace Mono.CSharp {
 
 //                     Console.WriteLine ("Emitting: " + loc);
 
-                       if (RootContext.CodeGen.SymbolWriter != null)
+                       if (CodeGen.SymbolWriter != null)
                                Mark (loc);
 
                        if (block != null){
index 27470079b4db9e0665b1a911fbe54ce05e0cf571..53cd4f8184824a9272137a9c838d21cb351f9146 100755 (executable)
@@ -621,7 +621,7 @@ struct_declaration
                                         (Attributes) $1, lexer.Location);
                current_container = new_struct;
                current_container.Namespace = current_namespace;
-               RootContext.Tree.RecordStruct (full_struct_name, new_struct);
+               RootContext.Tree.RecordDecl (full_struct_name, new_struct);
          }
          opt_struct_interfaces
          struct_body
@@ -1077,7 +1077,7 @@ interface_declaration
                }
                current_interface = new_interface;
                new_interface.Namespace = current_namespace;
-               RootContext.Tree.RecordInterface (full_interface_name, new_interface);
+               RootContext.Tree.RecordDecl (full_interface_name, new_interface);
          }
          opt_interface_base
          interface_body opt_semicolon
@@ -1649,7 +1649,7 @@ enum_declaration
                e.Namespace = current_namespace;
 
                CheckDef (current_container.AddEnum (e), full_name, enum_location);
-               RootContext.Tree.RecordEnum (full_name, e);
+               RootContext.Tree.RecordDecl (full_name, e);
 
          }
        ;
@@ -1718,7 +1718,7 @@ delegate_declaration
                                             MakeName ((string) $5), (Parameters) $7, 
                                             (Attributes) $1, l);
                  
-
+               del.Namespace = current_namespace;
                CheckDef (current_container.AddDelegate (del), del.Name, l);
          }     
        | opt_attributes
@@ -1735,6 +1735,7 @@ delegate_declaration
                        "System.Void", (int) $2, MakeName ((string) $5), (Parameters) $7, 
                        (Attributes) $1, l);
 
+               del.Namespace = current_namespace;
                CheckDef (current_container.AddDelegate (del), del.Name, l);
          }
        ;
@@ -2585,7 +2586,7 @@ class_declaration
                                       (Attributes) $1, lexer.Location);
                current_container = new_class;
                current_container.Namespace = current_namespace;
-               RootContext.Tree.RecordClass (name, new_class);
+               RootContext.Tree.RecordDecl (name, new_class);
          }
          opt_class_base
          class_body 
index 3804c13f66d0b84a30d878d66aa49c8f78e4b6e3..4927f760e6576c5c1d27b8e954255b89c3734f28 100755 (executable)
@@ -206,7 +206,7 @@ namespace Mono.CSharp {
                ///   this points to the actual definition that is being
                ///   created with System.Reflection.Emit
                /// </summary>
-               TypeBuilder definition;
+               public TypeBuilder TypeBuilder;
 
                /// <summary>
                ///   This variable tracks whether we have Closed the type
@@ -286,16 +286,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               public TypeBuilder TypeBuilder {
-                       get {
-                               return definition;
-                       }
-
-                       set {
-                               definition = value;
-                       }
-               }
-
                public TypeContainer Parent {
                        get {
                                return parent;
@@ -321,7 +311,7 @@ namespace Mono.CSharp {
                {
                        if (!Created){
                                try {
-                                       definition.CreateType ();
+                                       TypeBuilder.CreateType ();
                                } catch {
                                        //
                                        // The try/catch is needed because
@@ -338,6 +328,11 @@ namespace Mono.CSharp {
                        }
                }
 
+               /// <remarks>
+               ///  Should be overriten by the appropriate declaration space
+               /// <remarks>
+               public abstract TypeBuilder DefineType ();
+               
                //
                // Whether this is an `unsafe context'
                //
@@ -351,5 +346,137 @@ namespace Mono.CSharp {
                        }
                }
 
+               public static string MakeFQN (string nsn, string name)
+               {
+                       string prefix = (nsn == "" ? "" : nsn + ".");
+
+                       return prefix + name;
+               }
+
+               Type LookupInterfaceOrClass (string ns, string name, out bool error)
+               {
+                       DeclSpace parent;
+                       Type t;
+
+                       error = false;
+                       name = MakeFQN (ns, name);
+                       
+                       t  = TypeManager.LookupType (name);
+                       if (t != null)
+                               return t;
+
+                       parent = (DeclSpace) RootContext.Tree.Decls [name];
+                       if (parent == null)
+                               return null;
+                       
+                       t = parent.DefineType ();
+                       if (t == null){
+                               Report.Error (146, "Class definition is circular: `"+name+"'");
+                               error = true;
+                               return null;
+                       }
+                       return t;
+               }
+               
+               /// <summary>
+               ///   GetType is used to resolve type names at the DeclSpace level.
+               ///   Use this to lookup class/struct bases, interface bases or 
+               ///   delegate type references
+               /// </summary>
+               ///
+               /// <remarks>
+               ///   Contrast this to LookupType which is used inside method bodies to 
+               ///   lookup types that have already been defined.  GetType is used
+               ///   during the tree resolution process and potentially define
+               ///   recursively the type
+               /// </remarks>
+               public Type FindType (string name)
+               {
+                       Type t;
+                       bool error;
+
+                       //
+                       // For the case the type we are looking for is nested within this one
+                       // or is in any base class
+                       //
+                       DeclSpace containing_ds = this;
+
+                       while (containing_ds != null){
+                               Type current_type = containing_ds.TypeBuilder;
+
+                               while (current_type != null) {
+                                       string pre = current_type.FullName;
+                                       
+                                       t = LookupInterfaceOrClass (pre, name, out error);
+                                       if (error)
+                                               return null;
+                               
+                                       if (t != null) 
+                                               return t;
+
+                                       current_type = current_type.BaseType;
+                               }
+                               containing_ds = containing_ds.Parent;
+                       }
+                       
+                       //
+                       // Attempt to lookup the class on our namespace and all it's implicit parents
+                       //
+                       for (string ns = Namespace.Name; ns != null; ns = RootContext.ImplicitParent (ns)) {
+
+                               t = LookupInterfaceOrClass (ns, name, out error);
+                               if (error)
+                                       return null;
+                               
+                               if (t != null) 
+                                       return t;
+                       }
+                       
+                       //
+                       // Attempt to do a direct unqualified lookup
+                       //
+                       t = LookupInterfaceOrClass ("", name, out error);
+                       if (error)
+                               return null;
+                       
+                       if (t != null)
+                               return t;
+                       
+                       //
+                       // Attempt to lookup the class on any of the `using'
+                       // namespaces
+                       //
+
+                       for (Namespace ns = Namespace; ns != null; ns = ns.Parent){
+
+                               t = LookupInterfaceOrClass (ns.Name, name, out error);
+                               if (error)
+                                       return null;
+
+                               if (t != null)
+                                       return t;
+
+                               //
+                               // Now check the using clause list
+                               //
+                               ArrayList using_list = ns.UsingTable;
+                               
+                               if (using_list == null)
+                                       continue;
+
+                               foreach (string n in using_list){
+                                       t = LookupInterfaceOrClass (n, name, out error);
+                                       if (error)
+                                               return null;
+
+                                       if (t != null)
+                                               return t;
+                               }
+                               
+                       }
+
+                       Report.Error (246, Location, "Can not find type `"+name+"'");
+                       return null;
+               }
        }
 }
index 16f68fc2879a3bdc9512a6d4063bcfaa6665332b..f601b9fdd36658b2071d5bd431e50488c238459a 100644 (file)
@@ -55,24 +55,23 @@ namespace Mono.CSharp {
                        OptAttributes   = attrs;\r
                }\r
 \r
-               public void DefineDelegate (object parent_builder)\r
+               public override TypeBuilder DefineType ()\r
                {\r
                        TypeAttributes attr;\r
 \r
                        if (TypeBuilder != null)\r
-                               return;\r
+                               return TypeBuilder;\r
                        \r
                        string name = Name.Substring (1 + Name.LastIndexOf ('.'));\r
 \r
-                       if (parent_builder is ModuleBuilder) {\r
-                               ModuleBuilder builder = (ModuleBuilder) parent_builder;\r
+                       if (IsTopLevel) {\r
+                               ModuleBuilder builder = CodeGen.ModuleBuilder;\r
                                attr = TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Sealed;\r
 \r
                                TypeBuilder = builder.DefineType (\r
                                        name, attr, TypeManager.multicast_delegate_type);\r
                        } else {\r
-                               // FIXME: We could just use TypeBuilder here.\r
-                               TypeBuilder builder = (System.Reflection.Emit.TypeBuilder) parent_builder;\r
+                               TypeBuilder builder = Parent.TypeBuilder;\r
                                attr = TypeAttributes.NestedPublic | TypeAttributes.Class |\r
                                        TypeAttributes.Sealed;\r
 \r
@@ -81,6 +80,8 @@ namespace Mono.CSharp {
                        }\r
 \r
                        TypeManager.AddDelegateType (Name, TypeBuilder, this);\r
+\r
+                       return TypeBuilder;\r
                }\r
 \r
                public override bool Define (TypeContainer parent)\r
@@ -120,22 +121,29 @@ namespace Mono.CSharp {
                                \r
                        \r
                        ConstructorBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);\r
-                       \r
-                       // Here the various methods like Invoke, BeginInvoke etc are defined\r
 \r
                        //\r
-                       // Invoke method\r
+                       // Here the various methods like Invoke, BeginInvoke etc are defined\r
                        //\r
-                       param_types = Parameters.GetParameterInfo (parent);\r
+                       // First, call the `out of band' special method for\r
+                       // defining recursively any types we need:\r
+                       Parameters.ComputeAndDefineParameterTypes (this);\r
+                       \r
+                       param_types = Parameters.GetParameterInfo (this);\r
                        if (param_types == null)\r
                                return false;\r
 \r
+\r
+                       //\r
+                       // Invoke method\r
+                       //\r
+                       \r
                        // Check accessibility\r
                        foreach (Type partype in param_types)\r
                                if (!TypeContainer.AsAccessible (partype, ModFlags))\r
                                        return false;\r
                        \r
-                       ret_type = RootContext.LookupType (parent, ReturnType, false, Location);\r
+                       ret_type = FindType (ReturnType);\r
                        if (ret_type == null)\r
                                return false;\r
 \r
index 4d3d42061ff5c382686743700b47c5fab17c5aff..9d67a3631b598fc11738e35648b5739b5496b9eb 100755 (executable)
@@ -803,10 +803,9 @@ namespace Mono.CSharp
                                        output_file = first_source + target_ext;
                        }
 
-                       RootContext.CodeGen = new CodeGen (output_file, output_file,
-                                                          want_debugging_support);
+                       CodeGen.Init (output_file, output_file, want_debugging_support);
 
-                       TypeManager.AddModule (RootContext.CodeGen.ModuleBuilder);
+                       TypeManager.AddModule (CodeGen.ModuleBuilder);
 
                        //
                        // Before emitting, we need to get the core
@@ -880,7 +879,7 @@ namespace Mono.CSharp
                                        return;
                                }
                                
-                               RootContext.CodeGen.AssemblyBuilder.SetEntryPoint (ep, k);
+                               CodeGen.AssemblyBuilder.SetEntryPoint (ep, k);
                        }
 
                        //
@@ -888,15 +887,15 @@ namespace Mono.CSharp
                        //
                        if (resources != null){
                                foreach (string file in resources)
-                                       RootContext.CodeGen.AssemblyBuilder.AddResourceFile (file, file);
+                                       CodeGen.AssemblyBuilder.AddResourceFile (file, file);
                        }
                        
-                       RootContext.CodeGen.Save (output_file);
+                       CodeGen.Save (output_file);
                        if (timestamps)
                                ShowTime ("Saved output");
 
                        if (want_debugging_support) {
-                               RootContext.CodeGen.SaveSymbols ();
+                               CodeGen.SaveSymbols ();
                                if (timestamps)
                                        ShowTime ("Saved symbols");
                        }
index a16955a4352ed3f8464b6c2e9acadb6830fead06..f15909342486cad890902b4b0723d7a78c33e790 100755 (executable)
@@ -73,7 +73,7 @@ namespace Mono.CSharp {
                        return AdditionResult.Success;
                }
 
-               public Type DefineEnum ()
+               public override TypeBuilder DefineType ()
                {
                        if (TypeBuilder != null)
                                return TypeBuilder;
@@ -97,7 +97,7 @@ namespace Mono.CSharp {
                        }
 
                        if (IsTopLevel) {
-                               ModuleBuilder builder = RootContext.ModuleBuilder;
+                               ModuleBuilder builder = CodeGen.ModuleBuilder;
 
                                if ((ModFlags & Modifiers.PUBLIC) != 0)
                                        attr |= TypeAttributes.Public;
index 2f90c9b3a5cf7e3ca585a05ee8e794dc25c9e62f..6890f31c9ea5a7c3957f40520baa7f1e86dad0f8 100755 (executable)
@@ -91,37 +91,17 @@ namespace Mono.CSharp {
                        Indirection, AddressOf,  TOP
                }
 
-               Operator   oper;
-               Expression expr;
+               public Operator Oper;
+               public Expression Expr;
                Location   loc;
                
                public Unary (Operator op, Expression expr, Location loc)
                {
-                       this.oper = op;
-                       this.expr = expr;
+                       this.Oper = op;
+                       this.Expr = expr;
                        this.loc = loc;
                }
 
-               public Expression Expr {
-                       get {
-                               return expr;
-                       }
-
-                       set {
-                               expr = value;
-                       }
-               }
-
-               public Operator Oper {
-                       get {
-                               return oper;
-                       }
-
-                       set {
-                               oper = value;
-                       }
-               }
-
                /// <summary>
                ///   Returns a stringified representation of the Operator
                /// </summary>
@@ -162,7 +142,7 @@ namespace Mono.CSharp {
                void Error23 (Type t)
                {
                        Report.Error (
-                               23, loc, "Operator " + OperName (oper) +
+                               23, loc, "Operator " + OperName (Oper) +
                                " cannot be applied to operand of type `" +
                                TypeManager.CSharpName (t) + "'");
                }
@@ -193,7 +173,6 @@ namespace Mono.CSharp {
                                e = new IntConstant (-((ShortConstant) expr).Value);
                        else if (expr is UShortConstant)
                                e = new IntConstant (-((UShortConstant) expr).Value);
-
                        return e;
                }
                
@@ -201,7 +180,7 @@ namespace Mono.CSharp {
                {
                        Type expr_type = e.Type;
                        
-                       switch (oper){
+                       switch (Oper){
                        case Operator.UnaryPlus:
                                return e;
                                
@@ -252,7 +231,7 @@ namespace Mono.CSharp {
 
                Expression ResolveOperator (EmitContext ec)
                {
-                       Type expr_type = expr.Type;
+                       Type expr_type = Expr.Type;
 
                        //
                        // Step 1: Perform Operator Overload location
@@ -260,13 +239,13 @@ namespace Mono.CSharp {
                        Expression mg;
                        string op_name;
                        
-                       op_name = oper_names [(int) oper];
+                       op_name = oper_names [(int) Oper];
 
                        mg = MemberLookup (ec, expr_type, op_name, MemberTypes.Method, AllBindingFlags, loc);
                        
                        if (mg != null) {
                                Expression e = StaticCallExpr.MakeSimpleCall (
-                                       ec, (MethodGroupExpr) mg, expr, loc);
+                                       ec, (MethodGroupExpr) mg, Expr, loc);
 
                                if (e == null){
                                        Error23 (expr_type);
@@ -285,12 +264,12 @@ namespace Mono.CSharp {
                        //
                        // Step 2: Default operations on CLI native types.
                        //
-                       if (expr is Constant)
-                               return Reduce (ec, expr);
+                       if (Expr is Constant)
+                               return Reduce (ec, Expr);
 
-                       if (oper == Operator.LogicalNot){
+                       if (Oper == Operator.LogicalNot){
                                if (expr_type != TypeManager.bool_type) {
-                                       Error23 (expr.Type);
+                                       Error23 (Expr.Type);
                                        return null;
                                }
                                
@@ -298,24 +277,24 @@ namespace Mono.CSharp {
                                return this;
                        }
 
-                       if (oper == Operator.OnesComplement) {
+                       if (Oper == Operator.OnesComplement) {
                                if (!((expr_type == TypeManager.int32_type) ||
                                      (expr_type == TypeManager.uint32_type) ||
                                      (expr_type == TypeManager.int64_type) ||
                                      (expr_type == TypeManager.uint64_type) ||
                                      (expr_type.IsSubclassOf (TypeManager.enum_type)))){
-                                       Error23 (expr.Type);
+                                       Error23 (Expr.Type);
                                        return null;
                                }
                                type = expr_type;
                                return this;
                        }
 
-                       if (oper == Operator.UnaryPlus) {
+                       if (Oper == Operator.UnaryPlus) {
                                //
                                // A plus in front of something is just a no-op, so return the child.
                                //
-                               return expr;
+                               return Expr;
                        }
 
                        //
@@ -326,9 +305,19 @@ namespace Mono.CSharp {
                        // double  operator- (double d)
                        // decimal operator- (decimal d)
                        //
-                       if (oper == Operator.UnaryNegation){
+                       if (Oper == Operator.UnaryNegation){
                                Expression e = null;
 
+                               //
+                               // transform - - expr into expr
+                               //
+                               if (Expr is Unary){
+                                       Unary unary = (Unary) Expr;
+
+                                       if (unary.Oper == Operator.UnaryNegation)
+                                               return unary.Expr;
+                               }
+
                                //
                                // perform numeric promotions to int,
                                // long, double.
@@ -347,7 +336,7 @@ namespace Mono.CSharp {
                                        // bt wrote as a decimal interger literal
                                        //
                                        type = TypeManager.int64_type;
-                                       expr = ConvertImplicit (ec, expr, type, loc);
+                                       Expr = ConvertImplicit (ec, Expr, type, loc);
                                        return this;
                                }
 
@@ -366,23 +355,23 @@ namespace Mono.CSharp {
                                        return this;
                                }
                                
-                               e = ConvertImplicit (ec, expr, TypeManager.int32_type, loc);
+                               e = ConvertImplicit (ec, Expr, TypeManager.int32_type, loc);
                                if (e != null){
-                                       expr = e;
+                                       Expr = e;
                                        type = e.Type;
                                        return this;
                                } 
 
-                               e = ConvertImplicit (ec, expr, TypeManager.int64_type, loc);
+                               e = ConvertImplicit (ec, Expr, TypeManager.int64_type, loc);
                                if (e != null){
-                                       expr = e;
+                                       Expr = e;
                                        type = e.Type;
                                        return this;
                                }
 
-                               e = ConvertImplicit (ec, expr, TypeManager.double_type, loc);
+                               e = ConvertImplicit (ec, Expr, TypeManager.double_type, loc);
                                if (e != null){
-                                       expr = e;
+                                       Expr = e;
                                        type = e.Type;
                                        return this;
                                }
@@ -391,8 +380,8 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       if (oper == Operator.AddressOf){
-                               if (expr.eclass != ExprClass.Variable){
+                       if (Oper == Operator.AddressOf){
+                               if (Expr.eclass != ExprClass.Variable){
                                        Error (211, loc, "Cannot take the address of non-variables");
                                        return null;
                                }
@@ -402,7 +391,7 @@ namespace Mono.CSharp {
                                        return null;
                                }
 
-                               if (!TypeManager.VerifyUnManaged (expr.Type, loc)){
+                               if (!TypeManager.VerifyUnManaged (Expr.Type, loc)){
                                        return null;
                                }
                                
@@ -411,15 +400,15 @@ namespace Mono.CSharp {
                                // are not known by Type.GetType, so we have to try then to use
                                // ModuleBuilder.GetType.
                                //
-                               string ptr_type_name = expr.Type.FullName + "*";
+                               string ptr_type_name = Expr.Type.FullName + "*";
                                type = Type.GetType (ptr_type_name);
                                if (type == null)
-                                       type = RootContext.ModuleBuilder.GetType (ptr_type_name);
+                                       type = CodeGen.ModuleBuilder.GetType (ptr_type_name);
                                
                                return this;
                        }
 
-                       if (oper == Operator.Indirection){
+                       if (Oper == Operator.Indirection){
                                if (!ec.InUnsafe){
                                        UnsafeError (loc);
                                        return null;
@@ -436,19 +425,19 @@ namespace Mono.CSharp {
                                // We create an Indirection expression, because
                                // it can implement the IMemoryLocation.
                                // 
-                               return new Indirection (expr);
+                               return new Indirection (Expr);
                        }
                        
-                       Error (187, loc, "No such operator '" + OperName (oper) + "' defined for type '" +
+                       Error (187, loc, "No such operator '" + OperName (Oper) + "' defined for type '" +
                               TypeManager.CSharpName (expr_type) + "'");
                        return null;
                }
 
                public override Expression DoResolve (EmitContext ec)
                {
-                       expr = expr.Resolve (ec);
+                       Expr = Expr.Resolve (ec);
                        
-                       if (expr == null)
+                       if (Expr == null)
                                return null;
 
                        eclass = ExprClass.Value;
@@ -458,35 +447,35 @@ namespace Mono.CSharp {
                public override void Emit (EmitContext ec)
                {
                        ILGenerator ig = ec.ig;
-                       Type expr_type = expr.Type;
+                       Type expr_type = Expr.Type;
                        
-                       switch (oper) {
+                       switch (Oper) {
                        case Operator.UnaryPlus:
                                throw new Exception ("This should be caught by Resolve");
                                
                        case Operator.UnaryNegation:
-                               expr.Emit (ec);
+                               Expr.Emit (ec);
                                ig.Emit (OpCodes.Neg);
                                break;
                                
                        case Operator.LogicalNot:
-                               expr.Emit (ec);
+                               Expr.Emit (ec);
                                ig.Emit (OpCodes.Ldc_I4_0);
                                ig.Emit (OpCodes.Ceq);
                                break;
                                
                        case Operator.OnesComplement:
-                               expr.Emit (ec);
+                               Expr.Emit (ec);
                                ig.Emit (OpCodes.Not);
                                break;
                                
                        case Operator.AddressOf:
-                               ((IMemoryLocation)expr).AddressOf (ec, AddressOp.LoadStore);
+                               ((IMemoryLocation)Expr).AddressOf (ec, AddressOp.LoadStore);
                                break;
                                
                        default:
                                throw new Exception ("This should not happen: Operator = "
-                                                    + oper.ToString ());
+                                                    + Oper.ToString ());
                        }
                }
 
@@ -496,15 +485,15 @@ namespace Mono.CSharp {
                /// </summary>
                public void EmitLogicalNot (EmitContext ec)
                {
-                       if (oper != Operator.LogicalNot)
+                       if (Oper != Operator.LogicalNot)
                                throw new Exception ("EmitLogicalNot can only be called with !expr");
 
-                       expr.Emit (ec);
+                       Expr.Emit (ec);
                }
 
                public override string ToString ()
                {
-                       return "Unary (" + oper + ", " + expr + ")";
+                       return "Unary (" + Oper + ", " + Expr + ")";
                }
                
        }
@@ -1729,6 +1718,18 @@ namespace Mono.CSharp {
 
                                        return this;
                                }
+
+                               //
+                               // Transform a + ( - b) into a - b
+                               //
+                               if (right is Unary){
+                                       Unary right_unary = (Unary) right;
+
+                                       if (right_unary.Oper == Unary.Operator.UnaryNegation){
+                                               oper = Operator.Subtraction;
+                                               right = right_unary.Expr;
+                                       }
+                               }
                        }
 
                        if (oper == Operator.Addition || oper == Operator.Subtraction) {
@@ -4214,7 +4215,7 @@ namespace Mono.CSharp {
                                
                        } else {
 
-                               ModuleBuilder mb = RootContext.ModuleBuilder;
+                               ModuleBuilder mb = CodeGen.ModuleBuilder;
 
                                ArrayList args = new ArrayList ();
                                if (Arguments != null){
@@ -4410,7 +4411,7 @@ namespace Mono.CSharp {
                        if (dims != 1){
                                Type [] args;
                                ModuleBuilder mb = null;
-                               mb = RootContext.ModuleBuilder;
+                               mb = CodeGen.ModuleBuilder;
                                args = new Type [dims + 1];
 
                                int j;
@@ -5312,7 +5313,7 @@ namespace Mono.CSharp {
 
                MethodInfo FetchGetMethod ()
                {
-                       ModuleBuilder mb = RootContext.ModuleBuilder;
+                       ModuleBuilder mb = CodeGen.ModuleBuilder;
                        int arg_count = ea.Arguments.Count;
                        Type [] args = new Type [arg_count];
                        MethodInfo get;
@@ -5333,7 +5334,7 @@ namespace Mono.CSharp {
 
                MethodInfo FetchAddressMethod ()
                {
-                       ModuleBuilder mb = RootContext.ModuleBuilder;
+                       ModuleBuilder mb = CodeGen.ModuleBuilder;
                        int arg_count = ea.Arguments.Count;
                        Type [] args = new Type [arg_count];
                        MethodInfo address;
@@ -5411,7 +5412,7 @@ namespace Mono.CSharp {
                        if (rank == 1)
                                EmitStoreOpcode (ig, t);
                        else {
-                               ModuleBuilder mb = RootContext.ModuleBuilder;
+                               ModuleBuilder mb = CodeGen.ModuleBuilder;
                                int arg_count = ea.Arguments.Count;
                                Type [] args = new Type [arg_count + 1];
                                MethodInfo set;
@@ -5848,7 +5849,7 @@ namespace Mono.CSharp {
                        
                        type = Type.GetType (array_ptr_type_name);
                        if (type == null){
-                               ModuleBuilder mb = RootContext.ModuleBuilder;
+                               ModuleBuilder mb = CodeGen.ModuleBuilder;
                                
                                type = mb.GetType (array_ptr_type_name);
                        }
@@ -5951,7 +5952,7 @@ namespace Mono.CSharp {
                        string ptr_name = otype.FullName + "*";
                        type = Type.GetType (ptr_name);
                        if (type == null){
-                               ModuleBuilder mb = RootContext.ModuleBuilder;
+                               ModuleBuilder mb = CodeGen.ModuleBuilder;
                                
                                type = mb.GetType (ptr_name);
                        }
index 58323c0bd2f964901069e08a829a6a4bebc040fb..621f7181cad149ac5f31625a754e107010de2180 100755 (executable)
@@ -538,137 +538,28 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               //
-               // Returns the Type that represents the interface whose name
-               // is `name'.
-               //
-               
-               Type LookupInterfaceByName (string ns, string name, out bool error)
-               {
-                       Interface parent;
-                       Type t;
-
-                       error = false;
-                       name = TypeContainer.MakeFQN (ns, name);
-                       t = TypeManager.LookupType (name);
-                       
-                       if (t != null) {
-                               if (t.IsInterface)
-                                       return t;
-                               
-                               string cause;
-                               
-                               if (t.IsValueType)
-                                       cause = "is a struct";
-                               else if (t.IsClass) 
-                                       cause = "is a class";
-                               else
-                                       cause = "Should not happen.";
-
-                               error = true;
-                               Report.Error (527, Location, "`"+name+"' " + cause +
-                                             ", need an interface instead");
-                               
-                               return null;
-                       }
-
-                       Tree tree = RootContext.Tree;
-                       parent = (Interface) tree.Interfaces [name];
-                       if (parent == null)
-                               return null;
-                       
-                       t = parent.DefineInterface ();
-                       if (t == null){
-                               Report.Error (529,
-                                             "Inherited interface `"+name+"' is circular");
-                               error = true;
-                               return null;
-                       }
-
-                       return t;
-               }
-
                Type GetInterfaceTypeByName (string name)
                {
-                       //
-                       // For the case the type we are looking for is nested within this one
-                       // or is in any base class
-                       //
-                       DeclSpace containing_ds = this;
-                       bool error = false;
-                       Type t;
-                       
-                       while (containing_ds != null){
-                               Type current_type = containing_ds.TypeBuilder;
-
-                               while (current_type != null) {
-                                       string pre = current_type.FullName;
-                                       
-                                       t = LookupInterfaceByName (pre, name, out error);
-                                       if (error)
-                                               return null;
-                               
-                                       if (t != null) 
-                                               return t;
-
-                                       current_type = current_type.BaseType;
-                               }
-                               containing_ds = containing_ds.Parent;
-                       }
+                       Type t = FindType (name);
 
-                       //
-                       // Attempt to lookup the class on our namespace and all it's implicit parents
-                       //
-                       for (string ns = Namespace.Name; ns != null; ns = RootContext.ImplicitParent (ns)){
-                               t = LookupInterfaceByName (ns, name, out error);
-                               if (error)
-                                       return null;
-                               if (t != null)
-                                       return t;
-                       }
-
-                       //
-                       // Attempt to do a direct unqualified lookup
-                       //
-                       t = LookupInterfaceByName ("", name, out error);
-                       if (error)
+                       if (t == null)
                                return null;
                        
-                       if (t != null)
+                       if (t.IsInterface)
                                return t;
-                       
-                       //
-                       // Attempt to lookup the class on any of the `using'
-                       // namespaces
-                       //
-
-                       for (Namespace ns = Namespace; ns != null; ns = ns.Parent){
-                               t = LookupInterfaceByName (ns.Name, name, out error);
-                               if (error)
-                                       return null;
-
-                               if (t != null)
-                                       return t;
-
-                               //
-                               // Now check the using clause list
-                               //
-                               ArrayList using_list = ns.UsingTable;
                                
-                               if (using_list == null)
-                                       continue;
-
-                               foreach (string n in using_list){
-                                       t = LookupInterfaceByName (n, name, out error);
-                                       if (error)
-                                               return null;
-
-                                       if (t != null)
-                                               return t;
-                               }
-                       }
-
-                       Report.Error (246, Location, "Can not find type `"+name+"'");
+                       string cause;
+                       
+                       if (t.IsValueType)
+                               cause = "is a struct";
+                       else if (t.IsClass) 
+                               cause = "is a class";
+                       else
+                               cause = "Should not happen.";
+                       
+                       Report.Error (527, Location, "`"+name+"' " + cause +
+                                     ", need an interface instead");
+                       
                        return null;
                }
                
@@ -692,7 +583,7 @@ namespace Mono.CSharp {
 
                        foreach (string name in Bases){
                                Type t;
-                               
+
                                t = GetInterfaceTypeByName (name);
                                if (t == null){
                                        error = true;
@@ -709,12 +600,13 @@ namespace Mono.CSharp {
                // <summary>
                //  Defines the Interface in the appropriate ModuleBuilder or TypeBuilder
                // </summary>
+               //
                // TODO:
                //   Rework the way we recurse, because for recursive
                //   definitions of interfaces (A:B and B:A) we report the
                //   error twice, rather than once.  
                
-               public TypeBuilder DefineInterface ()
+               public override TypeBuilder DefineType ()
                {
                        Type [] ifaces;
                        bool error;
@@ -733,7 +625,7 @@ namespace Mono.CSharp {
                                return null;
 
                        if (IsTopLevel) {
-                               ModuleBuilder builder = RootContext.ModuleBuilder;
+                               ModuleBuilder builder = CodeGen.ModuleBuilder;
 
                                TypeBuilder = builder.DefineType (
                                        Name,
index 2106e3493f8c29a6ca0a6b57a5849d19df4633f6..1b32f32de6e26126fb4dd22566d7569d7fdd3584 100644 (file)
@@ -120,7 +120,7 @@ namespace Mono.CSharp {
                // If we don't have a symbol writer, this property is always null.
                public ISymbolDocumentWriter SymbolDocument {
                        get {
-                               ISymbolWriter sw = RootContext.CodeGen.SymbolWriter;
+                               ISymbolWriter sw = CodeGen.SymbolWriter;
                                ISymbolDocumentWriter doc;
 
                                if (token < 0)
index 357416b1e4c972b84edf81a2988863839ecf12c6..751fcdf8554cfa6fc28a47ec94dab998626fb67c 100755 (executable)
@@ -43,13 +43,13 @@ res:
        echo --target exe -o mcs2.exe $(COMPILER_SOURCES) > response
 
 dum: cs-parser.cs
-       ./mcs --fatal --target exe -o mcs2.exe $(COMPILER_SOURCES)
+       $(TIME) ./mcs --fatal --target exe -o mcs2.exe $(COMPILER_SOURCES)
 
 mcs2.exe: mcs.exe
-       ./mcs $(XFLAGS) --target exe -o mcs2.exe $(COMPILER_SOURCES)
+       $(TIME) ./mcs $(XFLAGS) --target exe -o mcs2.exe $(COMPILER_SOURCES)
 
 mcs3.exe: mcs2.exe
-       ./mcs2 --target exe -o mcs3.exe $(COMPILER_SOURCES)
+       $(TIME) ./mcs2 --target exe -o mcs3.exe $(COMPILER_SOURCES)
 
 mm:
        mint $(MINTFLAGS) ./mcs.exe $(MCSFLAGS) --target exe -o mcs4.exe $(COMPILER_SOURCES)
index 843028f920886c087b0e12e95aae2cad8e6501cb..ec065a52c363cb9bfeaf4983c38ddecfeb40501e 100755 (executable)
@@ -43,12 +43,25 @@ namespace Mono.CSharp {
                        OptAttributes = attrs;
                }
 
+               // <summary>
+               //   Resolve is used in method definitions
+               // </summary>
                public bool Resolve (DeclSpace ds, Location l)
                {
                        ParameterType = RootContext.LookupType (ds, TypeName, false, l);
                        return ParameterType != null;
                }
 
+               // <summary>
+               //   ResolveAndDefine is used by delegate declarations, because
+               //   they happen during the initial tree resolution process
+               // </summary>
+               public bool ResolveAndDefine (DeclSpace ds)
+               {
+                       ParameterType = ds.FindType (TypeName);
+                       return ParameterType != null;
+               }
+               
                public Type ExternalType (DeclSpace ds, Location l)
                {
                        if ((ModFlags & (Parameter.Modifier.REF | Parameter.Modifier.OUT)) != 0){
@@ -260,6 +273,48 @@ namespace Mono.CSharp {
 
                        return true;
                }
+
+               //
+               // This variant is used by Delegates, because they need to
+               // resolve/define names, instead of the plain LookupType
+               //
+               public bool ComputeAndDefineParameterTypes (DeclSpace ds)
+               {
+                       int extra = (ArrayParameter != null) ? 1 : 0;
+                       int i = 0;
+                       int pc;
+
+                       if (FixedParameters == null)
+                               pc = extra;
+                       else
+                               pc = extra + FixedParameters.Length;
+                       
+                       types = new Type [pc];
+                       
+                       if (!VerifyArgs ()){
+                               FixedParameters = null;
+                               return false;
+                       }
+
+                       if (FixedParameters != null){
+                               foreach (Parameter p in FixedParameters){
+                                       Type t = null;
+                                       
+                                       if (p.ResolveAndDefine (ds))
+                                               t = p.ExternalType (ds, loc);
+                                       
+                                       types [i] = t;
+                                       i++;
+                               }
+                       }
+                       
+                       if (extra > 0){
+                               if (ArrayParameter.ResolveAndDefine (ds))
+                                       types [i] = ArrayParameter.ExternalType (ds, loc);
+                       }
+
+                       return true;
+               }
                
                /// <summary>
                ///   Returns the argument types as an array
index 8753f23271dad0d4cfebfeac27cd3c5ad5ffcefa..95ababea49ce5a5f997db89c555e14883b6de9a7 100755 (executable)
@@ -22,18 +22,8 @@ namespace Mono.CSharp {
                //
                static Tree tree;
 
-               //
-               // The System.Reflection.Emit CodeGenerator
-               //
-               static CodeGen cg;
-
                static public bool Optimize;
                
-               //
-               // The module builder pointer.
-               //
-               static ModuleBuilder mb;
-
                //
                // The list of global attributes (those that target the assembly)
                //
@@ -84,22 +74,6 @@ namespace Mono.CSharp {
 
                static public string MainClass;
                
-               static public CodeGen CodeGen {
-                       get {
-                               return cg;
-                       }
-
-                       set {
-                               //
-                               // Temporary hack, we should probably
-                               // intialize `cg' rather than depending on
-                               // external initialization of it.
-                               //
-                               cg = value;
-                               mb = cg.ModuleBuilder;
-                       }
-               }
-
                public static void RegisterOrder (Interface iface)
                {
                        interface_resolve_order.Add (iface);
@@ -148,7 +122,7 @@ namespace Mono.CSharp {
                        ArrayList ifaces = root.Interfaces;
                        if (ifaces != null){
                                foreach (Interface i in ifaces) 
-                                       i.DefineInterface ();
+                                       i.DefineType ();
                        }
                                                
                        foreach (TypeContainer tc in root.Types) 
@@ -156,11 +130,11 @@ namespace Mono.CSharp {
 
                        if (root.Delegates != null)
                                foreach (Delegate d in root.Delegates) 
-                                       d.DefineDelegate (mb);
+                                       d.DefineType ();
 
                        if (root.Enums != null)
                                foreach (Enum e in root.Enums)
-                                       e.DefineEnum ();
+                                       e.DefineType ();
                        
                }
 
@@ -198,7 +172,7 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       ((TypeContainer) o).DefineType ();
+                       ((DeclSpace) o).DefineType ();
                }
 
                //
@@ -223,7 +197,7 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       ((TypeContainer) o).DefineType ();
+                       ((DeclSpace) o).DefineType ();
                }
 
                //
@@ -248,7 +222,7 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       ((Interface) o).DefineInterface ();
+                       ((DeclSpace) o).DefineType ();
                }
 
                //
@@ -267,7 +241,7 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       ((Delegate) o).DefineDelegate (mb);
+                       ((DeclSpace) o).DefineType ();
                }
                
 
@@ -495,6 +469,9 @@ namespace Mono.CSharp {
                                Type current_type = containing_ds.TypeBuilder;
 
                                while (current_type != null) {
+                                       //
+                                       // nested class
+                                       //
                                        t = TypeManager.LookupType (current_type.FullName + "+" + name);
                                        if (t != null)
                                                return t;
@@ -602,7 +579,7 @@ namespace Mono.CSharp {
                        if (global_attributes != null){
                                EmitContext ec = new EmitContext (
                                        tree.Types, Mono.CSharp.Location.Null, null, null, 0, false);
-                               AssemblyBuilder ab = cg.AssemblyBuilder;
+                               AssemblyBuilder ab = CodeGen.AssemblyBuilder;
 
                                Attribute.ApplyAttributes (ec, ab, ab, global_attributes,
                                                           global_attributes.Location);
@@ -617,16 +594,10 @@ namespace Mono.CSharp {
                                }
                                
                                CustomAttributeBuilder cb = new CustomAttributeBuilder (ci, new object [0]);
-                               mb.SetCustomAttribute (cb);
+                               CodeGen.ModuleBuilder.SetCustomAttribute (cb);
                        }
                }
                
-               static public ModuleBuilder ModuleBuilder {
-                       get {
-                               return mb;
-                       }
-               }
-
                //
                // Public Field, used to track which method is the public entry
                // point.
@@ -658,7 +629,7 @@ namespace Mono.CSharp {
                        int size = data.Length;
                        
                        if (impl_details_class == null)
-                               impl_details_class = mb.DefineType (
+                               impl_details_class = CodeGen.ModuleBuilder.DefineType (
                                        "<PrivateImplementationDetails>", TypeAttributes.NotPublic);
 
                        fb = impl_details_class.DefineInitializedData (
index 8f3e847c09d4e16983ee3dfed45ff2bdd3333c5a..0f90674ede047088a2db24c90ee15e272d73f651 100755 (executable)
@@ -46,7 +46,7 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       if (RootContext.CodeGen.SymbolWriter != null)
+                       if (CodeGen.SymbolWriter != null)
                                ec.Mark (loc);
 
                        bool invert = false;
@@ -980,7 +980,7 @@ namespace Mono.CSharp {
                                        vi.VariableType = t;
                                        vi.LocalBuilder = ig.DeclareLocal (t);
 
-                                       if (RootContext.CodeGen.SymbolWriter != null)
+                                       if (CodeGen.SymbolWriter != null)
                                                vi.LocalBuilder.SetLocalSymInfo (name);
 
                                        if (constants == null)
@@ -1053,7 +1053,7 @@ namespace Mono.CSharp {
 
                        ec.CurrentBlock = this;
 
-                       if (RootContext.CodeGen.SymbolWriter != null) {
+                       if (CodeGen.SymbolWriter != null) {
                                ec.Mark (StartLocation);
 
                                foreach (Statement s in Statements) {
@@ -2576,7 +2576,7 @@ namespace Mono.CSharp {
                                for (int i = 0; i < rank; i++)
                                        args [i] = TypeManager.int32_type;
 
-                               ModuleBuilder mb = RootContext.ModuleBuilder;
+                               ModuleBuilder mb = CodeGen.ModuleBuilder;
                                get = mb.GetArrayMethod (
                                        array_type, "Get",
                                        CallingConventions.HasThis| CallingConventions.Standard,
index 066330d5c3ed8a170da7a80511fcfdea74b5ba0a..2cf5be8ca5ccd62f38949affa188485e8866f9b0 100755 (executable)
@@ -33,87 +33,40 @@ namespace Mono.CSharp
        public class Tree {
                TypeContainer root_types;
 
-               // <summary>
-               //   Keeps track of the interfaces defined in the source code
-               // </summary>
-               Hashtable ifaces;
-
-               // <summary>
-               //   Keeps track of the structs defined in the source code
-               // </summary>
-               Hashtable structs;
-
-               // <summary>
-               //   Keeps track of the classes defined in the source code
-               // </summary>
-               Hashtable classes;
-
                // <summary>
                //  Keeps track of namespaces defined in the source code
                // </summary>
                Hashtable namespaces;
 
                // <summary>
-               //  Keeps track of enums defined
+               //   Keeps track of all the types definied (classes, structs, ifaces, enums)
                // </summary>
-               Hashtable enums;
+               Hashtable decls;
                
                public Tree ()
                {
                        root_types = new TypeContainer (null, "", new Location (-1));
+
+                       decls = new Hashtable ();
+                       namespaces = new Hashtable ();
                }
 
-               void RecordDecl (Hashtable decl, string name, DeclSpace ds)
+               public void RecordDecl (string name, DeclSpace ds)
                {
-                       if (decl.Contains (name)){
+                       if (decls.Contains (name)){
                                Report.Error (
                                        101, ds.Location,
                                        "There is already a definition for `" + name + "'");
-                               DeclSpace other = (DeclSpace) decl [name];
+                               DeclSpace other = (DeclSpace) decls [name];
                                Report.Error (0,
                                        other.Location, "(Location of symbol related to previous error)");
                                return;
                        }
-                       decl.Add (name, ds);
+                       decls.Add (name, ds);
                }
                
-               public void RecordInterface (string name, Interface iface)
-               {
-                       if (ifaces == null)
-                               ifaces = new Hashtable ();
-
-                       RecordDecl (ifaces, name, iface);
-               }
-               
-               public void RecordStruct (string name, Struct s)
-               {
-                       if (structs == null)
-                               structs = new Hashtable ();
-
-                       RecordDecl (structs, name, s);
-               }
-               
-               public void RecordClass (string name, Class c)
-               {
-                       if (classes == null)
-                               classes = new Hashtable ();
-
-                       RecordDecl (classes, name, c);
-               }
-
-               public void RecordEnum (string name, Enum e)
-               {
-                       if (enums == null)
-                               enums = new Hashtable ();
-
-                       RecordDecl (enums, name, e);
-               }
-
                public Namespace RecordNamespace (Namespace parent, string file, string name)
                {
-                       if (namespaces == null)
-                               namespaces = new Hashtable ();
-                                                                                                    
                        Namespace ns = new Namespace (parent, name);
 
                        if (namespaces.Contains (file)){
@@ -131,28 +84,19 @@ namespace Mono.CSharp
 
                        return ns;
                }
-               
-               public TypeContainer Types {
-                       get {
-                               return root_types;
-                       }
-               }
-
-               public Hashtable Interfaces {
-                       get {
-                               return ifaces;
-                       }
-               }
 
-               public Hashtable Classes {
-                       get {
-                               return classes;
-                       }
-               }
+               //
+               // FIXME: Why are we using Types?
+               //
+                public TypeContainer Types {
+                        get {
+                                return root_types;
+                        }
+                }
 
-               public Hashtable Structs {
+               public Hashtable Decls {
                        get {
-                               return structs;
+                               return decls;
                        }
                }
 
@@ -161,11 +105,5 @@ namespace Mono.CSharp
                                return namespaces;
                        }
                }
-
-               public Hashtable Enums {
-                       get {
-                               return enums;
-                       }
-               }
        }
 }