2001-07-17 Miguel de Icaza <miguel@ximian.com>
authorMiguel de Icaza <miguel@gnome.org>
Tue, 17 Jul 2001 22:36:02 +0000 (22:36 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Tue, 17 Jul 2001 22:36:02 +0000 (22:36 -0000)
* tree.cs: moved IGenerator interface and renamed it to ITreeDump
and put it here.

Get rid of old crufty code.

* rootcontext.cs: Use this to keep track of the parsed
representation and the defined types available to the program.

* gen-treedump.cs: adjust for new convention.

* type.cs: Split out the type manager, and the assembly builder
from here.

* typemanager.cs: the type manager will live here now.

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

13 files changed:
mcs/mcs/ChangeLog
mcs/mcs/cil-codegen.cs [new file with mode: 0755]
mcs/mcs/class.cs
mcs/mcs/decl.cs
mcs/mcs/driver.cs
mcs/mcs/enum.cs
mcs/mcs/gen-il.cs
mcs/mcs/gen-treedump.cs
mcs/mcs/interface.cs
mcs/mcs/makefile
mcs/mcs/rootcontext.cs [new file with mode: 0755]
mcs/mcs/tree.cs
mcs/mcs/typemanager.cs [new file with mode: 0755]

index ddcbc6114324444a9a5b7e3edf927c01365a1143..6f200aef3efe5d2497fb7cd27b7e3703c9e161b6 100755 (executable)
@@ -1,3 +1,22 @@
+2001-07-17  Miguel de Icaza  <miguel@ximian.com>
+
+       * tree.cs: moved IGenerator interface and renamed it to ITreeDump
+       and put it here.
+
+       Get rid of old crufty code.
+
+       * rootcontext.cs: Use this to keep track of the parsed
+       representation and the defined types available to the program. 
+
+       * gen-treedump.cs: adjust for new convention.
+
+       * type.cs: Split out the type manager, and the assembly builder
+       from here. 
+
+       * typemanager.cs: the type manager will live here now.
+
+       * cil-codegen.cs: And the code generator here. 
+
 2001-07-14  Sean MacIsaac  <macisaac@ximian.com>
 
        * makefile: Fixed up for easy making.
diff --git a/mcs/mcs/cil-codegen.cs b/mcs/mcs/cil-codegen.cs
new file mode 100755 (executable)
index 0000000..d4ed170
--- /dev/null
@@ -0,0 +1,44 @@
+//
+// cil-codegen.cs: The CIL code generation interface
+//
+// Author:
+//   Miguel de Icaza (miguel@ximian.com)
+//
+// (C) 2001 Ximian, Inc.
+//
+
+using System;
+using System.Reflection;
+using System.Reflection.Emit;
+
+public class CilCodeGen {
+       AppDomain current_domain;
+       AssemblyBuilder assembly_builder;
+       ModuleBuilder   module_builder;
+
+       public CilCodeGen (string name, string output)
+       {
+               AssemblyName an;
+               
+               an = new AssemblyName ();
+               an.Name = "AssemblyName";
+               current_domain = AppDomain.CurrentDomain;
+               assembly_builder = current_domain.DefineDynamicAssembly (
+                       an, AssemblyBuilderAccess.RunAndSave);
+               
+               module_builder = assembly_builder.DefineDynamicModule (name, output);
+       }
+       
+       public AssemblyBuilder AssemblyBuilder {
+               get {
+                       return assembly_builder;
+               }
+       }
+       
+       public ModuleBuilder ModuleBuilder {
+               get {
+                       return module_builder;
+               }
+       }
+       
+}
index 131f29a43b7a6dfcba100ad3c4ed41aa6804fa46..0e90e9d6271570544a8e22202b7048313f115dea 100755 (executable)
@@ -315,11 +315,6 @@ namespace CIR {
                        return 0;
                }
 
-               override public Type Define (Tree tree)
-               {
-                       return null;
-               }
-               
                public delegate void VisitContainer (TypeContainer container, object cback_data);
 
                void VisitTypesAt (TypeContainer root, VisitContainer visit, object cback)
index 36235f0f8fc26b9993a2c4df09114f9e3bb879ef..aa103c27bfeddf3bad3ecdc7756365c7eb11d5b5 100755 (executable)
@@ -121,7 +121,5 @@ namespace CIR {
                                in_transit = value;
                        }
                }
-
-               abstract public Type Define (Tree tree);
        }
 }
index c796d8b552e63cfeead0a352c9894d04fae1d4be..2ad082c5d1b6c32326bf10c6c8284157639d5cd9 100755 (executable)
@@ -20,7 +20,7 @@ namespace CSC
        using CSC;\r
 \r
        /// <summary>\r
-       ///    Summary description for Class1.\r
+       ///    The compiler driver.\r
        /// </summary>\r
        public class Driver\r
        {\r
@@ -32,9 +32,8 @@ namespace CSC
                // Lookup paths\r
                ArrayList link_paths;\r
 \r
-               // Our parser context.\r
-               Tree context;\r
-               \r
+               RootContext context; \r
+\r
                bool yacc_verbose = false;\r
 \r
                int error_count = 0;\r
@@ -75,12 +74,13 @@ namespace CSC
                        \r
                }\r
 \r
-               public IGenerator lookup_output (string name)\r
+               public ITreeDump lookup_dumper (string name)\r
                {\r
                        if (name == "tree")\r
                                return new Generator.TreeDump ();\r
-                       if (name == "il")\r
-                               return new MSIL.Generator ();\r
+                       \r
+                       //                      if (name == "il")\r
+                       // return new MSIL.Generator ();\r
                        \r
                        return null;\r
                }\r
@@ -127,11 +127,14 @@ namespace CSC
                                        return 1;\r
                                }\r
 \r
-                               context.AddAssembly (a);\r
+                               context.TypeManager.AddAssembly (a);\r
                        }\r
                        return 0;\r
                }\r
-               \r
+\r
+               // <summary>\r
+               //   Loads all assemblies referenced on the command line\r
+               // </summary>\r
                public int LoadReferences ()\r
                {\r
                        int errors = 0;\r
@@ -143,14 +146,20 @@ namespace CSC
                        return errors;\r
                }\r
 \r
-               \r
+               // <summary>\r
+               //    Parses the arguments, and drives the compilation\r
+               //    process.\r
+               //\r
+               //    TODO: Mostly structured to debug the compiler\r
+               //    now, needs to be turned into a real driver soon.\r
+               // </summary>\r
                public Driver (string [] args)\r
                {\r
                        Stream output_stream = Console.OpenStandardOutput ();\r
-                       IGenerator generator = null;\r
+                       ITreeDump generator = null;\r
                        int errors = 0, i;\r
 \r
-                       context = new Tree ();\r
+                       context = new RootContext ();\r
                        references = new ArrayList ();\r
                        link_paths = new ArrayList ();\r
 \r
@@ -170,7 +179,7 @@ namespace CSC
                                        }\r
 \r
                                        if (arg.StartsWith ("-t")){\r
-                                               generator = lookup_output (args [++i]);\r
+                                               generator = lookup_dumper (args [++i]);\r
                                                continue;\r
                                        }\r
 \r
@@ -211,7 +220,7 @@ namespace CSC
                                        continue;\r
                                }\r
 \r
-                               errors += parse (context, arg);\r
+                               errors += parse (context.Tree, arg);\r
                        }\r
                        if (errors > 0)\r
                                error ("// Parsing failed");\r
@@ -229,20 +238,17 @@ namespace CSC
                                notice ("// Assemblies loaded");\r
 \r
 \r
-                       errors += context.BuilderInit ("Module", "Module.exe");\r
-\r
                        //\r
-                       // Name resolution on the tree.\r
+                       // Dumping the parsed tree.\r
                        //\r
-                       errors += context.Resolve ();\r
-                                                  \r
-                       //\r
-                       // Code generation from the tree\r
+                       // This code generation interface is only here\r
+                       // for debugging purposes, it will change as we\r
+                       // move to the new tree. \r
                        //\r
                        if (generator != null){\r
                                StreamWriter output = new StreamWriter (output_stream);\r
                                \r
-                               errors += generator.GenerateFromTree (context, output);\r
+                               errors += generator.Dump (context.Tree, output);\r
 \r
                                if (errors > 0)\r
                                        error ("// Compilation failed");\r
@@ -251,7 +257,7 @@ namespace CSC
 \r
                                output.Flush ();\r
                                output.Close ();\r
-                       }\r
+                       } \r
 \r
                        error_count = errors;\r
                }\r
index 3278e6ef5e8c772e10860c4e85371f4ebf53abf8..0481a7eac87a7bbc04c2a6b581df409eec0e9f40 100755 (executable)
@@ -74,10 +74,5 @@ namespace CIR {
                                return (Expression) defined_names [name];
                        }
                }
-
-               public override Type Define (Tree tree)
-               {
-                       return null;
-               }
        }
 }
index d365441fb99d8b88b7d8972513fc195d92bb6b62..2dfeecc974c1e684326577139ef0c7504f360254 100755 (executable)
@@ -14,7 +14,7 @@ using CIR;
 
 namespace MSIL {
 
-       public class Generator : CIR.IGenerator {
+       public class Generator : CIR.ITreeDump {
                StreamWriter o;
                int indent = 0;
                
index b7a6bf1fc6c3363506ba64fb8828994329968c5c..42033f669b3a1c89e93f68179185ae80e2f1e8fa 100755 (executable)
@@ -18,7 +18,7 @@ using CIR;
 
 namespace Generator {
        
-       public class TreeDump : CIR.IGenerator {
+       public class TreeDump : CIR.ITreeDump {
                StreamWriter o;
                int indent;
                bool indented;
@@ -994,7 +994,7 @@ namespace Generator {
                        }
                }
                
-               public int GenerateFromTree (Tree tree, StreamWriter output)
+               public int Dump (Tree tree, StreamWriter output)
                {
                        this.o = output;
 
index 968fbfb11eb7c8b22d5211a9456e4c7fbf22ed54..f333fc706893ed018382d7b16453052abb3b2b51 100755 (executable)
@@ -141,36 +141,6 @@ namespace CIR {
                                bases = value;
                        }
                }
-
-               Type def;
-               bool in_transit = false;
-               public override Type Define (Tree tree)
-               {
-                       if (in_transit){
-                               CSC.CSharpParser.error (529, "There is a cycle in interface " + Name);
-                               return null;
-                       }
-                       in_transit = true;
-
-                       ModuleBuilder mb = tree.ModuleBuilder;
-
-                       if (bases != null){
-                               // FIXME: Go over each one of the TypeRefs
-                               // in Bases and resolve.
-                               Console.WriteLine ("Base interfaces not yet supported");
-                               return null;
-                       }
-
-                       TypeAttributes attr = TypeAttributes.Interface;
-
-                       attr |= Modifiers.TypeAttr (mod_flags);
-                       
-                       def = mb.DefineType (Name, attr);
-
-                       in_transit = false;
-
-                       return def;
-               }
        }
 
        public class InterfaceMemberBase {
index 2d3fea9f5813682a9c0b634e5526a34e0eb1fd5d..c431a0b89ec225f13bba8da227f34b4ca2f3377e 100755 (executable)
@@ -9,12 +9,11 @@ COMPILER_SOURCES = \
        assign.cs                       \
        driver.cs $(COMMON_SOURCES)     \
        class.cs                        \
+       cil-codegen.cs                  \
        constant.cs                     \
        decl.cs                         \
        enum.cs                         \
        expression.cs                   \
-       generator.cs                    \
-       gen-il.cs                       \
        gen-treedump.cs                 \
        interface.cs                    \
        literal.cs                      \
@@ -22,9 +21,11 @@ COMPILER_SOURCES = \
        namespace.cs                    \
        parameter.cs                    \
        parameterCollection.cs          \
+       rootcontext.cs                  \
        statement.cs                    \
        statementCollection.cs          \
-       type.cs
+       type.cs                         \
+       typemanager.cs
 
 TEST_TOKENIZER_SOURCES = test-token.cs $(COMMON_SOURCES)
 
diff --git a/mcs/mcs/rootcontext.cs b/mcs/mcs/rootcontext.cs
new file mode 100755 (executable)
index 0000000..8a65f02
--- /dev/null
@@ -0,0 +1,43 @@
+//
+// rootcontext.cs: keeps track of our tree representation, and assemblies loaded.
+//
+// Author: Miguel de Icaza (miguel@gnu.org)
+//
+// Licensed under the terms of the GNU GPL
+//
+// (C) 2001 Ximian, Inc (http://www.ximian.com)
+
+namespace CIR {
+
+       public class RootContext {
+
+               //
+               // Contains the parsed tree
+               //
+               Tree tree;
+
+               //
+               // Contains loaded assemblies and our generated code as we go.
+               //
+               TypeManager type_manager;
+
+               public RootContext ()
+               {
+                       tree = new Tree ();
+                       type_manager = new TypeManager ();
+               }
+
+               public TypeManager TypeManager {
+                       get {
+                               return type_manager;
+                       }
+               }
+
+               public Tree Tree {
+                       get {
+                               return tree;
+                       }
+               }
+       }
+}
+             
index f08c5a27dac898ea73cf24464708fd9ff265c4f6..3bbadf20c3cec9b85fcf0c0a2efaed630c669f26 100755 (executable)
@@ -13,29 +13,26 @@ using System;
 using System.Collections;
 using System.Reflection;
 using System.Reflection.Emit;
+using System.IO;
 
 namespace CIR
 {
 
+       public interface ITreeDump {
+               int  Dump (Tree tree, StreamWriter output);
+               void ParseOptions (string options);
+       }
+
        // <summary>
-       //   A storage for temporary IL trees
+       //   
+       //   We store here all the toplevel types that we have parsed,
+       //   this is the root of all information we have parsed.
+       // 
        // </summary>
        
        public class Tree {
                TypeContainer root_types;
 
-               // <summary>
-               //   Holds the Array of Assemblies that have been loaded
-               //   (either because it is the default or the user used the
-               //   -r command line option)
-               // </summary>
-               ArrayList assemblies;
-
-               // <summary>
-               //   This is used to map defined FQN to Types
-               // </summary>
-               Hashtable types;
-
                // <summary>
                //   This maps source defined types that are defined
                //   in the source code to their object holders (Class, Struct, 
@@ -44,44 +41,12 @@ namespace CIR
                // </summary>
                Hashtable source_types;
 
-               AppDomain current_domain;
-               AssemblyBuilder assembly_builder;
-               ModuleBuilder   module_builder;
-               
                public Tree ()
                {
                        root_types = new TypeContainer (null, "");
-                       assemblies = new ArrayList ();
-                       types = new Hashtable ();
                        source_types = new Hashtable ();
                }
 
-               public int BuilderInit (string name, string output)
-               {
-                       AssemblyName an;
-                       
-                       an = new AssemblyName ();
-                       an.Name = "AssemblyName";
-                       current_domain = AppDomain.CurrentDomain;
-                       assembly_builder = current_domain.DefineDynamicAssembly (
-                               an, AssemblyBuilderAccess.RunAndSave);
-
-                       module_builder = assembly_builder.DefineDynamicModule (name, output);
-
-                       return 0;
-               }
-
-               public AssemblyBuilder AssemblyBuilder {
-                       get {
-                               return assembly_builder;
-                       }
-               }
-
-               public ModuleBuilder ModuleBuilder {
-                       get {
-                               return module_builder;
-                       }
-               }
 
                public void RecordType (string name, DeclSpace decl)
                {
@@ -94,90 +59,5 @@ namespace CIR
                        }
                }
 
-               public int ResolveTypeContainerTypes (TypeContainer type)
-               {
-                       return 0;
-               }
-               
-               public int ResolveNames (TypeContainer types)
-               {
-                       int errors = 0;
-                       
-                       if (types == null)
-                               return 0;
-
-                       foreach (DictionaryEntry de in types.Types){
-                               TypeContainer type = (TypeContainer) de.Value;
-
-                               errors += ResolveTypeContainerTypes (type);
-                       }
-
-                       return errors;
-               }
-
-               public Type ResolveType (string name)
-               {
-                       Type t = (Type) types [name];
-                       
-                       if (t != null)
-                               return t;
-
-                       DeclSpace decl;
-                       decl = (DeclSpace) source_types [name];
-
-                       // FIXME: handle using here.
-                       if (decl == null){
-                               CSC.CSharpParser.error (234, "The type or namespace name '" + name
-                                                       + "' does not exist in the current space");
-                               return null;
-                       }
-
-                       return decl.Define (this);
-               }
-               
-               int iscan_errors = 0;
-               void interface_scan (TypeContainer container, object data)
-               {
-                       foreach (Interface iface in container.Interfaces){
-                               Type t = ResolveType (iface.Name);
-
-                               if (t != null){
-                                       CSC.CSharpParser.error (101, "There is already a definition for " + iface.Name);
-                                       iscan_errors++;
-                               }
-                               iface.Define (this);
-                       }
-               }
-
-               public int ResolveInterfaces (TypeContainer type)
-               {
-                       TypeContainer.VisitContainer iscanner;
-
-                       iscanner = new TypeContainer.VisitContainer (interface_scan);
-                       type.VisitTypes (iscanner, this);
-                       return iscan_errors;
-               }
-               
-               public int ResolveTypeContainerParents (TypeContainer type)
-               {
-                       return type.ResolveParents (this);
-               }
-
-               public int Resolve ()
-               {
-                       int errors = 0;
-
-                       errors += ResolveInterfaces (root_types);
-                       errors += ResolveTypeContainerParents (root_types);
-                       return 0;
-               }
-
-               public void AddAssembly (Assembly a)
-               {
-                       assemblies.Add (a);
-                       foreach (Type t in a.GetExportedTypes ()){
-                               types.Add (t.FullName, t);
-                       }
-               }
        }
 }
diff --git a/mcs/mcs/typemanager.cs b/mcs/mcs/typemanager.cs
new file mode 100755 (executable)
index 0000000..6293590
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// typegen.cs: type generation 
+//
+// Author: Miguel de Icaza (miguel@gnu.org)
+//
+// Licensed under the terms of the GNU GPL
+//
+// (C) 2001 Ximian, Inc (http://www.ximian.com)
+//
+//
+
+using System;
+using System.Collections;
+using System.Reflection;
+using System.Reflection.Emit;
+
+public class TypeManager {
+
+       // <summary>
+       //   Holds the Array of Assemblies that have been loaded
+       //   (either because it is the default or the user used the
+       //   -r command line option)
+       // </summary>
+       ArrayList assemblies;
+
+       // <summary>
+       //   This is used to map defined FQN to Types
+       // </summary>
+       Hashtable types;
+
+       public TypeManager ()
+       {
+               assemblies = new ArrayList ();
+               types = new Hashtable ();
+       }
+
+       // <summary>
+       //   Registers a single type with the Type Manager.  This is
+       //   an interface for our type builder. 
+       // </summary>
+       public void AddType (string name, Type t)
+       {
+               types.Add (t.FullName, t);
+       }
+
+       // <summary>
+       //   Registers an assembly to load types from.
+       // </summary>
+       public void AddAssembly (Assembly a)
+       {
+               assemblies.Add (a);
+               foreach (Type t in a.GetExportedTypes ()){
+                       AddType (t.FullName, t);
+               }
+       }
+
+       // <summary>
+       //   Returns the Type associated with @name
+       // </summary>
+       public Type LookupType (string name)
+       {
+               Type t = (Type) types [name];
+               
+               return t;
+       }
+}
+