namespace Mono.CSharp
{
+ //
+ // Module container, it can be used as a top-level type
+ //
+ public class ModuleContainer : TypeContainer
+ {
+ public CharSet DefaultCharSet = CharSet.Ansi;
+ public TypeAttributes DefaultCharSetType = TypeAttributes.AnsiClass;
+
+ protected Assembly assembly;
+
+ public ModuleContainer (Assembly assembly)
+ : base (null, null, MemberName.Null, null, Kind.Root)
+ {
+ this.assembly = assembly;
+ }
+
+ public Assembly Assembly {
+ get { return assembly; }
+ }
+
+ // FIXME: Remove this evil one day
+ public ModuleCompiled Compiled {
+ get { return (ModuleCompiled) this; }
+ }
+
+ public override ModuleContainer Module {
+ get {
+ return this;
+ }
+ }
+ }
+
//
// Compiled top-level types
//
- public sealed class ModuleContainer : TypeContainer
+ public class ModuleCompiled : ModuleContainer
{
// TODO: It'd be so nice to have generics
Hashtable anonymous_types;
- public ModuleBuilder Builder;
- bool is_unsafe;
+ readonly bool is_unsafe;
+ readonly CompilerContext context;
- bool has_default_charset;
+ ModuleBuilder builder;
- public CharSet DefaultCharSet = CharSet.Ansi;
- public TypeAttributes DefaultCharSetType = TypeAttributes.AnsiClass;
+ bool has_default_charset;
static readonly string[] attribute_targets = new string[] { "module" };
- public ModuleContainer (bool isUnsafe)
- : base (null, null, MemberName.Null, null, Kind.Root)
+ public ModuleCompiled (CompilerContext context, bool isUnsafe)
+ : base (null)
{
this.is_unsafe = isUnsafe;
+ this.context = context;
+
types = new ArrayList ();
anonymous_types = new Hashtable ();
}
}
}
- Builder.SetCustomAttribute (cb);
+ builder.SetCustomAttribute (cb);
+ }
+
+ public ModuleBuilder Builder {
+ get {
+ return builder;
+ }
+
+ set {
+ builder = value;
+ assembly = builder.Assembly;
+ }
+ }
+
+ public override CompilerContext Compiler {
+ get { return context; }
}
public override void Emit ()
OptAttributes.Emit ();
if (is_unsafe) {
- Type t = TypeManager.CoreLookupType ("System.Security", "UnverifiableCodeAttribute", Kind.Class, true);
+ Type t = TypeManager.CoreLookupType (context, "System.Security", "UnverifiableCodeAttribute", Kind.Class, true);
if (t != null) {
ConstructorInfo unverifiable_code_ctor = TypeManager.GetPredefinedConstructor (t, Location.Null, Type.EmptyTypes);
if (unverifiable_code_ctor != null)
- Builder.SetCustomAttribute (new CustomAttributeBuilder (unverifiable_code_ctor, new object [0]));
+ builder.SetCustomAttribute (new CustomAttributeBuilder (unverifiable_code_ctor, new object [0]));
}
}
}
return true;
}
- public override ModuleContainer Module {
- get {
- return this;
- }
- }
-
protected override bool AddMemberType (DeclSpace ds)
{
if (!AddToContainer (ds, ds.Name))
get { throw new InternalErrorException ("should not be called"); }
}
+ public override CompilerContext Compiler {
+ get {
+ return PartialContainer.Compiler;
+ }
+ }
+
public override string DocCommentHeader {
get { throw new InternalErrorException ("should not be called"); }
}