2006-01-24 Jordi Mas i Hernandez <jordimash@gmail.com>
[mono.git] / mcs / mbas / rootcontext.cs
index 5086843849cc0ff30728d0b975ea62f54e57860e..086973b55347e4905dfae2ce858482987e3044f3 100644 (file)
@@ -14,7 +14,7 @@ using System.Reflection;
 using System.Reflection.Emit;
 using System.Diagnostics;
 
-namespace Mono.CSharp {
+namespace Mono.MonoBASIC {
 
        public class RootContext {
 
@@ -23,17 +23,17 @@ namespace Mono.CSharp {
                //
                static Tree tree;
 
+               //
+               // Tracks Imported namespaces
+               //
+               static SourceBeingCompiled sourceBeingCompiled = new SourceBeingCompiled();
+
                //
                // This hashtable contains all of the #definitions across the source code
                // it is used by the ConditionalAttribute handler.
                //
                public static Hashtable AllDefines = new Hashtable ();
                
-               //
-               // The list of global attributes (those that target the assembly)
-               //
-               static Hashtable global_attributes = new Hashtable ();
-               
                //
                // Whether we are being linked against the standard libraries.
                // This is only used to tell whether `System.Object' should
@@ -98,6 +98,21 @@ namespace Mono.CSharp {
                        attribute_types.Add (tc);
                }
                
+               public static void InitializeImports(ArrayList ImportsList)
+               {
+                       sourceBeingCompiled.InitializeImports (ImportsList);
+               }
+
+               public static SourceBeingCompiled SourceBeingCompiled
+               {
+                       get { return sourceBeingCompiled; }
+               }
+
+               public static void VerifyImports()
+               {
+                       sourceBeingCompiled.VerifyImports();
+               }
+
                // 
                // The default compiler checked state
                //
@@ -108,6 +123,9 @@ namespace Mono.CSharp {
                //
                static public bool Unsafe = false;
                
+               // Root namespace name (implicit namespace)
+               static public string RootNamespace = "";
+               
                static string MakeFQN (string nsn, string name)
                {
                        string prefix = (nsn == "" ? "" : nsn + ".");
@@ -382,7 +400,7 @@ namespace Mono.CSharp {
                {
                        TypeContainer root = Tree.Types;
                        
-                       ArrayList ifaces = root.Interfaces;
+                       //ArrayList ifaces = root.Interfaces;
 
                        if (root.Enums != null)
                                foreach (Enum en in root.Enums)
@@ -464,7 +482,7 @@ namespace Mono.CSharp {
                        //
                        // Try the aliases in the current namespace
                        //
-                       string alias = curr_ns.LookupAlias (name);
+                       string alias = sourceBeingCompiled.LookupAlias (name);
 
                        if (alias != null) {
                                t = TypeManager.LookupType (alias);
@@ -487,13 +505,15 @@ namespace Mono.CSharp {
                                //
                                // Then try with the using clauses
                                //
-                               ArrayList using_list = ns.UsingTable;
 
-                               if (using_list == null)
+                               ICollection imports_list = sourceBeingCompiled.ImportsTable;
+
+                               if (imports_list == null)
                                        continue;
 
                                Type match = null;
-                               foreach (Namespace.UsingEntry ue in using_list) {
+                               foreach (SourceBeingCompiled.ImportsEntry ue in imports_list) {
+                               //TODO: deal with standard modules
                                        match = TypeManager.LookupType (MakeFQN (ue.Name, name));
                                        if (match != null){
                                                if (t != null){
@@ -511,7 +531,7 @@ namespace Mono.CSharp {
                                //
                                // Try with aliases
                                //
-                               string a = ns.LookupAlias (name);
+                               string a = sourceBeingCompiled.LookupAlias (name);
                                if (a != null) {
                                        t = TypeManager.LookupType (a);
                                        if (t != null)
@@ -575,7 +595,7 @@ namespace Mono.CSharp {
                        }
 
                        if (!silent)
-                               Report.Error (246, loc, "Cannot find type `"+name+"'");
+                               Report.Error (30002, loc, "Cannot find type `"+name+"'");
                        
                        return null;
                }
@@ -731,28 +751,11 @@ namespace Mono.CSharp {
 
                static public void EmitCode ()
                {
-                       //
-                       // Because of the strange way in which we do things, global
-                       // attributes must be processed first.
-                       //
-                       if (global_attributes.Count > 0){
-                               AssemblyBuilder ab = CodeGen.AssemblyBuilder;
-                               TypeContainer dummy = new TypeContainer (null, "", new Location (-1));
-                               EmitContext temp_ec = new EmitContext (
-                                       dummy, Mono.CSharp.Location.Null, null, null, 0, false);
-                       
-                               foreach (DictionaryEntry de in global_attributes){
-                                       Namespace ns = (Namespace) de.Key;
-                                       Attributes attrs = (Attributes) de.Value;
-                                       
-                                       dummy.Namespace = ns;
-                                       Attribute.ApplyAttributes (temp_ec, ab, ab, attrs, attrs.Location);
-                               }
-                       }
-
                        if (attribute_types != null)
                                foreach (TypeContainer tc in attribute_types)
                                        tc.Emit ();
+
+                       CodeGen.EmitGlobalAttributes ();
                        
                        if (type_container_resolve_order != null) {
                                foreach (TypeContainer tc in type_container_resolve_order)
@@ -806,7 +809,7 @@ namespace Mono.CSharp {
                static public FieldBuilder MakeStaticData (byte [] data)
                {
                        FieldBuilder fb;
-                       int size = data.Length;
+                       //int size = data.Length;
                        
                        if (impl_details_class == null)
                                impl_details_class = CodeGen.ModuleBuilder.DefineType (
@@ -819,37 +822,5 @@ namespace Mono.CSharp {
                        return fb;
                }
 
-               //
-               // Adds a global attribute that was declared in `container', 
-               // the attribute is in `attr', and it was defined at `loc'
-               //
-               static public void AddGlobalAttribute (TypeContainer container,
-                                                      AttributeSection attr, Location loc)
-               {
-                       Namespace ns = container.Namespace;
-                       Attributes a = (Attributes) global_attributes [ns];
-
-                       if (a == null)
-                               global_attributes [ns] = new Attributes (attr, loc);
-                       else
-                               a.AddAttribute (attr);
-               }
-               
-               //
-               // Adds a global attribute that was declared in `container', 
-               // the attribute is in `attr', and it was defined at `loc'
-               //
-               static public void AddGlobalAttributeSection (TypeContainer container, AttributeSection attr)
-               {
-                       Namespace ns = container.Namespace;
-                       Attributes a = (Attributes) global_attributes [ns];
-
-                       if (a == null)
-                               global_attributes [ns] = new Attributes (attr, Location.Null);
-                       else
-                               a.AddAttributeSection (attr);
-               }               
        }
 }
-             
-