//
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
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, 0)
+ {
+ this.assembly = assembly;
+ }
+
+ public override 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;
+ Dictionary<int, List<AnonymousTypeClass>> anonymous_types;
+ 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;
- types = new ArrayList ();
- anonymous_types = new Hashtable ();
+ this.context = context;
+
+ types = new List<TypeContainer> ();
+ anonymous_types = new Dictionary<int, List<AnonymousTypeClass>> ();
}
public override AttributeTargets AttributeTargets {
public void AddAnonymousType (AnonymousTypeClass type)
{
- ArrayList existing = (ArrayList)anonymous_types [type.Parameters.Count];
+ List<AnonymousTypeClass> existing;
+ if (!anonymous_types.TryGetValue (type.Parameters.Count, out existing))
if (existing == null) {
- existing = new ArrayList ();
+ existing = new List<AnonymousTypeClass> ();
anonymous_types.Add (type.Parameters.Count, existing);
}
+
existing.Add (type);
}
- public void AddAttributes (ArrayList attrs)
+ public void AddAttributes (List<Attribute> attrs)
{
foreach (Attribute a in attrs)
a.AttachTo (this, CodeGen.Assembly);
return AddPartial (nextPart, nextPart.Name);
}
- public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb, PredefinedAttributes pa)
+ public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{
if (a.Type == pa.CLSCompliant) {
if (CodeGen.Assembly.ClsCompliantAttribute == null) {
}
}
- Builder.SetCustomAttribute (cb);
+ builder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
+ }
+
+ 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);
+ TypeSpec t = TypeManager.CoreLookupType (context, "System.Security", "UnverifiableCodeAttribute", MemberKind.Class, true);
if (t != null) {
- ConstructorInfo unverifiable_code_ctor = TypeManager.GetPredefinedConstructor (t, Location.Null, Type.EmptyTypes);
+ var unverifiable_code_ctor = TypeManager.GetPredefinedConstructor (t, Location.Null, TypeSpec.EmptyTypes);
if (unverifiable_code_ctor != null)
- Builder.SetCustomAttribute (new CustomAttributeBuilder (unverifiable_code_ctor, new object [0]));
+ builder.SetCustomAttribute (new CustomAttributeBuilder ((ConstructorInfo) unverifiable_code_ctor.GetMetaInfo (), new object[0]));
}
}
}
- public AnonymousTypeClass GetAnonymousType (ArrayList parameters)
+ public AnonymousTypeClass GetAnonymousType (IList<AnonymousTypeParameter> parameters)
{
- ArrayList candidates = (ArrayList) anonymous_types [parameters.Count];
- if (candidates == null)
+ List<AnonymousTypeClass> candidates;
+ if (!anonymous_types.TryGetValue (parameters.Count, out candidates))
return null;
int i;
return null;
}
- public override bool GetClsCompliantAttributeValue ()
- {
- return CodeGen.Assembly.IsClsCompliant;
- }
-
public bool HasDefaultCharSet {
get {
return has_default_charset;
public override bool IsClsComplianceRequired ()
{
- return true;
- }
-
- public override ModuleContainer Module {
- get {
- return this;
- }
+ return CodeGen.Assembly.IsClsCompliant;
}
- protected override bool AddMemberType (DeclSpace ds)
+ protected override bool AddMemberType (TypeContainer ds)
{
if (!AddToContainer (ds, ds.Name))
return false;
- ds.NamespaceEntry.NS.AddDeclSpace (ds.Basename, ds);
+ ds.NamespaceEntry.NS.AddType (ds.Definition);
return true;
}
}
}
- class RootDeclSpace : DeclSpace {
+ class RootDeclSpace : TypeContainer {
public RootDeclSpace (NamespaceEntry ns)
- : base (ns, null, MemberName.Null, null)
+ : base (ns, null, MemberName.Null, null, 0)
{
PartialContainer = RootContext.ToplevelTypes;
}
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"); }
}
- public override bool Define ()
- {
- throw new InternalErrorException ("should not be called");
- }
+ //public override bool Define ()
+ //{
+ // throw new InternalErrorException ("should not be called");
+ //}
public override TypeBuilder DefineType ()
{
throw new InternalErrorException ("should not be called");
}
- public override MemberCache MemberCache {
- get { return PartialContainer.MemberCache; }
- }
-
public override ModuleContainer Module {
get {
return PartialContainer.Module;
}
}
- public override bool GetClsCompliantAttributeValue ()
- {
- return PartialContainer.GetClsCompliantAttributeValue ();
- }
-
public override bool IsClsComplianceRequired ()
{
return PartialContainer.IsClsComplianceRequired ();