2 // tree.cs: keeps a tree representation of the generated code
4 // Author: Miguel de Icaza (miguel@gnu.org)
6 // Licensed under the terms of the GNU GPL
8 // (C) 2001 Ximian, Inc (http://www.ximian.com)
13 using System.Collections;
14 using System.Reflection;
15 using System.Reflection.Emit;
21 // A storage for temporary IL trees
25 TypeContainer root_types;
28 // Holds the Array of Assemblies that have been loaded
29 // (either because it is the default or the user used the
30 // -r command line option)
35 // This is used to map defined FQN to Types
40 // This maps source defined types that are defined
41 // in the source code to their object holders (Class, Struct,
42 // Interface) and that have not yet been made into real
45 Hashtable source_types;
47 AppDomain current_domain;
48 AssemblyBuilder assembly_builder;
49 ModuleBuilder module_builder;
53 root_types = new TypeContainer (null, "");
54 assemblies = new ArrayList ();
55 types = new Hashtable ();
56 source_types = new Hashtable ();
59 public int BuilderInit (string name, string output)
63 an = new AssemblyName ();
64 an.Name = "AssemblyName";
65 current_domain = AppDomain.CurrentDomain;
66 assembly_builder = current_domain.DefineDynamicAssembly (
67 an, AssemblyBuilderAccess.RunAndSave);
69 module_builder = assembly_builder.DefineDynamicModule (name, output);
74 public AssemblyBuilder AssemblyBuilder {
76 return assembly_builder;
80 public ModuleBuilder ModuleBuilder {
82 return module_builder;
86 public void RecordType (string name, DeclSpace decl)
88 source_types.Add (name, decl);
91 public TypeContainer Types {
97 public int ResolveTypeContainerTypes (TypeContainer type)
102 public int ResolveNames (TypeContainer types)
109 foreach (DictionaryEntry de in types.Types){
110 TypeContainer type = (TypeContainer) de.Value;
112 errors += ResolveTypeContainerTypes (type);
118 public Type ResolveType (string name)
120 Type t = (Type) types [name];
126 decl = (DeclSpace) source_types [name];
128 // FIXME: handle using here.
130 CSC.CSharpParser.error (234, "The type or namespace name '" + name
131 + "' does not exist in the current space");
135 return decl.Define (this);
138 int iscan_errors = 0;
139 void interface_scan (TypeContainer container, object data)
141 foreach (Interface iface in container.Interfaces){
142 Type t = ResolveType (iface.Name);
145 CSC.CSharpParser.error (101, "There is already a definition for " + iface.Name);
152 public int ResolveInterfaces (TypeContainer type)
154 TypeContainer.VisitContainer iscanner;
156 iscanner = new TypeContainer.VisitContainer (interface_scan);
157 type.VisitTypes (iscanner, this);
161 public int ResolveTypeContainerParents (TypeContainer type)
163 return type.ResolveParents (this);
166 public int Resolve ()
170 errors += ResolveInterfaces (root_types);
171 errors += ResolveTypeContainerParents (root_types);
175 public void AddAssembly (Assembly a)
178 foreach (Type t in a.GetExportedTypes ()){
179 types.Add (t.FullName, t);