2 // rootcontext.cs: keeps track of our tree representation, and assemblies loaded.
4 // Author: Miguel de Icaza (miguel@ximian.com)
6 // Licensed under the terms of the GNU GPL
8 // (C) 2001 Ximian, Inc (http://www.ximian.com)
11 using System.Collections;
12 using System.Reflection;
13 using System.Reflection.Emit;
17 public class RootContext {
20 // Contains the parsed tree
25 // Contains loaded assemblies and our generated code as we go.
27 TypeManager type_manager;
30 // The System.Reflection.Emit CodeGenerator
41 type_manager = new TypeManager ();
42 report = new Report ();
45 public TypeManager TypeManager {
57 public CilCodeGen CodeGen {
64 // Temporary hack, we should probably
65 // intialize `cg' rather than depending on
66 // external initialization of it.
69 mb = cg.ModuleBuilder;
74 // Returns the list of interfaces that this interface implements
77 Type [] GetInterfaces (Interface iface, out bool error)
79 ArrayList bases = iface.Bases;
80 Hashtable source_ifaces;
81 int count = bases.Count;
89 tbases = new Type [bases.Count];
91 source_ifaces = tree.Interfaces;
93 foreach (string name in iface.Bases){
94 Type t = type_manager.LookupType (name);
101 parent = (Interface) source_ifaces [name];
104 report.Error (246, "Can not find type `"+name+"'");
107 t = CreateInterface (parent);
110 "Inherited interface `"+name+"' in `"+
111 iface.Name+"' is recursive");
122 // Creates the Interface @iface using the ModuleBuilder
125 // Resolve recursively dependencies.
127 TypeBuilder CreateInterface (Interface iface)
134 iface.InTransit = true;
136 string name = iface.Name;
137 Type [] ifaces = GetInterfaces (iface, out error);
142 tb = mb.DefineType (name,
143 TypeAttributes.Interface |
144 TypeAttributes.Public |
145 TypeAttributes.Abstract,
147 iface.Definition = tb;
150 // if Recursive_Def (child) == false
151 // error (child.Name recursive def with iface.Name)
153 type_manager.AddUserType (name, tb);
155 iface.InTransit = false;
159 public void ResolveInterfaceBases ()
161 Hashtable ifaces = tree.Interfaces;
166 foreach (Interface iface in ifaces){
167 string name = iface.Name;
169 CreateInterface (iface);
173 public void ResolveClassBases ()
178 // Closes all open types
182 // We usually use TypeBuilder types. When we are done
183 // creating the type (which will happen after we have addded
184 // methods, fields, etc) we need to "Define" them before we
185 // can save the Assembly
187 public void CloseTypes ()
189 foreach (TypeBuilder t in type_manager.UserTypes){