using System.Reflection.Emit;
using System.Diagnostics;
-namespace Mono.CSharp {
+namespace Mono.MonoBASIC {
public class RootContext {
//
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
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
//
//
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 + ".");
// These are classes that depends on the core interfaces
//
string [] classes_second_stage = {
- "System.String", "System.Enum",
- "System.Array", "System.MulticastDelegate",
- "System.Delegate",
-
"System.Reflection.MemberInfo",
"System.Type",
+ "System.Exception",
//
// These are not really important in the order, but they
"System.Security.UnverifiableCodeAttribute",
"System.Runtime.CompilerServices.IndexerNameAttribute",
};
+
+ // We must store them here before calling BootstrapCorlib_ResolveDelegate.
+ TypeManager.string_type = BootstrapCorlib_ResolveClass (root, "System.String");
+ TypeManager.enum_type = BootstrapCorlib_ResolveClass (root, "System.Enum");
+ TypeManager.array_type = BootstrapCorlib_ResolveClass (root, "System.Array");
+ TypeManager.multicast_delegate_type = BootstrapCorlib_ResolveClass (root, "System.MulticastDelegate");
+ TypeManager.delegate_type = BootstrapCorlib_ResolveClass (root, "System.Delegate");
foreach (string cname in classes_second_stage)
BootstrapCorlib_ResolveClass (root, cname);
{
TypeContainer root = Tree.Types;
- ArrayList ifaces = root.Interfaces;
+ //ArrayList ifaces = root.Interfaces;
if (root.Enums != null)
foreach (Enum en in root.Enums)
if (root.Delegates != null)
foreach (Delegate d in root.Delegates)
- d.CloseDelegate ();
+ d.CloseType ();
//
return ns.Substring (0, i);
}
- static Type NamespaceLookup (Namespace curr_ns, string name)
+ static Type NamespaceLookup (Namespace curr_ns, string name, Location loc)
{
Type t;
//
// 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);
//
// 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;
- foreach (string n in using_list) {
- t = TypeManager.LookupType (MakeFQN (n, name));
- if (t != null)
- return t;
+ Type match = null;
+ 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){
+ DeclSpace.Error_AmbiguousTypeReference (loc, name, t, match);
+ return null;
+ }
+
+ t = match;
+ ue.Used = true;
+ }
}
+ if (t != null)
+ return t;
//
// Try with aliases
//
- string a = ns.LookupAlias (name);
+ string a = sourceBeingCompiled.LookupAlias (name);
if (a != null) {
t = TypeManager.LookupType (a);
if (t != null)
//
// nested class
//
- t = TypeManager.LookupType (current_type.FullName + "+" + name);
+ t = TypeManager.LookupType (current_type.FullName + "." + name);
if (t != null){
ds.Cache [name] = t;
return t;
containing_ds = containing_ds.Parent;
}
- t = NamespaceLookup (ds.Namespace, name);
+ t = NamespaceLookup (ds.Namespace, name, loc);
if (t != null){
ds.Cache [name] = t;
return t;
}
if (!silent)
- Report.Error (246, loc, "Cannot find type `"+name+"'");
+ Report.Error (30002, loc, "Cannot find type `"+name+"'");
return null;
}
{
DeclSpace ds = (DeclSpace) root.GetDefinition (name);
+ ds.DefineMembers (root);
ds.Define (root);
}
if (attribute_types != null)
foreach (TypeContainer tc in attribute_types)
- tc.Define (root);
+ tc.DefineMembers (root);
if (interface_resolve_order != null){
foreach (Interface iface in interface_resolve_order)
if ((iface.ModFlags & Modifiers.NEW) == 0)
- iface.Define (root);
+ iface.DefineMembers (root);
else
Report1530 (iface.Location);
}
if (type_container_resolve_order != null){
- foreach (TypeContainer tc in type_container_resolve_order)
+ foreach (TypeContainer tc in type_container_resolve_order) {
+ // When compiling corlib, these types have already been
+ // populated from BootCorlib_PopulateCoreTypes ().
+ if (!RootContext.StdLib &&
+ ((tc.Name == "System.Object") ||
+ (tc.Name == "System.Attribute") ||
+ (tc.Name == "System.ValueType")))
+ continue;
+
if ((tc.ModFlags & Modifiers.NEW) == 0)
- tc.Define (root);
+ tc.DefineMembers (root);
else
Report1530 (tc.Location);
+ }
}
ArrayList delegates = root.Delegates;
if (delegates != null){
foreach (Delegate d in delegates)
if ((d.ModFlags & Modifiers.NEW) == 0)
- d.Define (root);
+ d.DefineMembers (root);
else
Report1530 (d.Location);
}
if (enums != null){
foreach (Enum en in enums)
if ((en.ModFlags & Modifiers.NEW) == 0)
- en.Define (root);
+ en.DefineMembers (root);
else
Report1530 (en.Location);
}
}
- static public void EmitCode ()
+ static public void DefineTypes ()
{
- //
- // 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);
+ TypeContainer root = Tree.Types;
+
+ if (attribute_types != null)
+ foreach (TypeContainer tc in attribute_types)
+ tc.Define (root);
- 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 (interface_resolve_order != null){
+ foreach (Interface iface in interface_resolve_order)
+ if ((iface.ModFlags & Modifiers.NEW) == 0)
+ iface.Define (root);
+ }
+
+
+ if (type_container_resolve_order != null){
+ foreach (TypeContainer tc in type_container_resolve_order) {
+ // When compiling corlib, these types have already been
+ // populated from BootCorlib_PopulateCoreTypes ().
+ if (!RootContext.StdLib &&
+ ((tc.Name == "System.Object") ||
+ (tc.Name == "System.Attribute") ||
+ (tc.Name == "System.ValueType")))
+ continue;
+
+ if ((tc.ModFlags & Modifiers.NEW) == 0)
+ tc.Define (root);
}
}
-
+
+ ArrayList delegates = root.Delegates;
+ if (delegates != null){
+ foreach (Delegate d in delegates)
+ if ((d.ModFlags & Modifiers.NEW) == 0)
+ d.Define (root);
+ }
+
+ ArrayList enums = root.Enums;
+ if (enums != null){
+ foreach (Enum en in enums)
+ if ((en.ModFlags & Modifiers.NEW) == 0)
+ en.Define (root);
+ }
+ }
+
+ static public void EmitCode ()
+ {
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)
}
if (Unsafe) {
- ConstructorInfo ci = TypeManager.unverifiable_code_type.GetConstructor (new Type [0]);
-
- if (ci == null) {
- Console.WriteLine ("Internal error !");
+ if (TypeManager.unverifiable_code_ctor == null) {
+ Console.WriteLine ("Internal error ! Cannot set unverifiable code attribute.");
return;
}
- CustomAttributeBuilder cb = new CustomAttributeBuilder (ci, new object [0]);
+ CustomAttributeBuilder cb = new CustomAttributeBuilder (TypeManager.unverifiable_code_ctor, new object [0]);
CodeGen.ModuleBuilder.SetCustomAttribute (cb);
}
}
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 (
- "<PrivateImplementationDetails>", TypeAttributes.NotPublic);
+ "<PrivateImplementationDetails>", TypeAttributes.NotPublic, TypeManager.object_type);
fb = impl_details_class.DefineInitializedData (
"$$field-" + (field_count++), data,
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);
- }
}
}
-
-