a16db71a53f818fab9342a3af00fd9021c989fac
[mono.git] / mcs / mcs / rootcontext.cs
1 //
2 // rootcontext.cs: keeps track of our tree representation, and assemblies loaded.
3 //
4 // Author: Miguel de Icaza (miguel@gnu.org)
5 //
6 // Licensed under the terms of the GNU GPL
7 //
8 // (C) 2001 Ximian, Inc (http://www.ximian.com)
9
10 using System;
11 using System.Collections;
12 using System.Reflection;
13 using System.Reflection.Emit;
14
15 namespace CIR {
16
17         public class RootContext {
18
19                 //
20                 // Contains the parsed tree
21                 //
22                 Tree tree;
23
24                 //
25                 // Contains loaded assemblies and our generated code as we go.
26                 //
27                 TypeManager type_manager;
28
29                 //
30                 // The System.Reflection.Emit CodeGenerator
31                 //
32                 CilCodeGen cg;
33
34                 ModuleBuilder mb;
35                 
36                 public RootContext ()
37                 {
38                         tree = new Tree ();
39                         type_manager = new TypeManager ();
40                 }
41
42                 public TypeManager TypeManager {
43                         get {
44                                 return type_manager;
45                         }
46                 }
47
48                 public Tree Tree {
49                         get {
50                                 return tree;
51                         }
52                 }
53
54                 public CilCodeGen CodeGen {
55                         get {
56                                 return cg;
57                         }
58
59                         set {
60                                 //
61                                 // Temporary hack, we should probably
62                                 // intialize `cg' rather than depending on
63                                 // external initialization of it.
64                                 //
65                                 cg = value;
66                                 mb = cg.ModuleBuilder;
67                         }
68                 }
69
70                 //
71                 // Creates the Interface @iface using the ModuleBuilder
72                 //
73                 // TODO:
74                 //   Resolve recursively dependencies.
75                 //
76                 bool CreateInterface (Interface iface)
77                 {
78                         TypeBuilder tb;
79                         string name = iface.Name;
80
81                         if (iface.InTransit)
82                                 return false;
83                         
84                         iface.InTransit = true;
85                         tb = mb.DefineType (name,
86                                             TypeAttributes.Interface |
87                                             TypeAttributes.Public |
88                                             TypeAttributes.Abstract);
89                         tb.CreateType ();
90                         iface.Definition = tb;
91
92                         //
93                         // if Recursive_Def (child) == false
94                         //      error (child.Name recursive def with iface.Name)
95                         //
96                         type_manager.AddType (name, tb);
97
98                         iface.InTransit = false;
99                         return true;
100                 }
101                 
102                 public void ResolveInterfaceBases ()
103                 {
104                         ArrayList ifaces = tree.Interfaces;
105
106                         foreach (Interface iface in ifaces){
107                                 string name = iface.Name;
108
109                                 DefineInterface (iface);
110                         }
111                 }
112
113                 public void ResolveClassBases ()
114                 {
115                 }
116         }
117 }
118