+2009-10-23 Marek Safar <marek.safar@gmail.com>
+
+ * typemanager.cs, eval.cs, decl.cs, roottypes.cs, context.cs,
+ anonymous.cs, expression.cs, rootcontext.cs, ecore.cs, class.cs,
+ flowanalysis.cs, cs-parser.jay, driver.cs, codegen.cs: Split
+ ModuleContainer. Add common unclosed member check routine.
+
2009-10-22 Marek Safar <marek.safar@gmail.com>
* argument.cs: Use literal flag for real literals only.
Type t = MutateGenericType (method.DeclaringType);
if (t != method.DeclaringType) {
method = (MethodInfo) TypeManager.DropGenericMethodArguments (method);
- if (method.Module == Module.Builder)
+ if (TypeManager.IsBeingCompiled (method))
method = TypeBuilder.GetMethod (t, method);
else
method = (MethodInfo) MethodInfo.GetMethodFromHandle (method.MethodHandle, t.TypeHandle);
Type t = MutateGenericType (ctor.DeclaringType);
if (t != ctor.DeclaringType) {
ctor = (ConstructorInfo) TypeManager.DropGenericMethodArguments (ctor);
- if (ctor.Module == Module.Builder)
+ if (TypeManager.IsBeingCompiled (ctor))
return TypeBuilder.GetConstructor (t, ctor);
return (ConstructorInfo) ConstructorInfo.GetMethodFromHandle (ctor.MethodHandle, t.TypeHandle);
Type t = MutateGenericType (field.DeclaringType);
if (t != field.DeclaringType) {
field = TypeManager.DropGenericTypeArguments (field.DeclaringType).GetField (field.Name, TypeManager.AllMembers);
- if (field.Module == Module.Builder)
+ if (TypeManager.IsBeingCompiled (field))
return TypeBuilder.GetField (t, field);
return FieldInfo.GetFieldFromHandle (field.FieldHandle, t.TypeHandle);
return false;
}
- ModuleBuilder builder = Module.Builder;
+ ModuleBuilder builder = Module.Compiled.Builder;
TypeBuilder = builder.DefineType (
Name, TypeAttr, default_parent, type_size);
} else {
// which has InternalsVisibleTo
//
if ((thisp & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem){
- return TypeManager.IsThisOrFriendAssembly (Parent.Module.Builder.Assembly, base_method.DeclaringType.Assembly);
+ return TypeManager.IsThisOrFriendAssembly (Parent.Module.Assembly, base_method.DeclaringType.Assembly);
} else if ((thisp & MethodAttributes.Family) != MethodAttributes.Family) {
//
// if it's not "protected internal", it must be "protected"
AssemblyName an = Assembly.GetAssemblyName (name, name);
Assembly.Builder = current_domain.DefineDynamicAssembly (an, AssemblyBuilderAccess.Run | COMPILER_ACCESS);
- RootContext.ToplevelTypes = new ModuleContainer (ctx, true);
+ RootContext.ToplevelTypes = new ModuleCompiled (ctx, true);
RootContext.ToplevelTypes.Builder = Assembly.Builder.DefineDynamicModule (Basename (name), false);
Assembly.Name = Assembly.Builder.GetName ();
}
public ResolveContext (IMemberContext mc)
{
+ if (mc == null)
+ throw new ArgumentNullException ();
+
MemberContext = mc;
//
return new FlagsHandle (this, options, enable ? options : 0);
}
}
-}
\ No newline at end of file
+}
if (global_attrs_enabled) {
if (current_attr_target == "module") {
- current_container.Module.AddAttributes (sect);
+ current_container.Module.Compiled.AddAttributes (sect);
$$ = null;
} else if (current_attr_target != null && current_attr_target.Length > 0) {
CodeGen.Assembly.AddAttributes (sect, current_namespace);
if (global_attrs_enabled) {
if (current_attr_target == "module") {
- current_container.Module.AddAttributes (sect);
+ current_container.Module.Compiled.AddAttributes (sect);
$$ = null;
} else if (current_attr_target == "assembly") {
CodeGen.Assembly.AddAttributes (sect, current_namespace);
switch (pAccess) {
case AccessLevel.Internal:
if (al == AccessLevel.Private || al == AccessLevel.Internal)
- same_access_restrictions = TypeManager.IsThisOrFriendAssembly (Parent.Module.Builder.Assembly, p.Assembly);
+ same_access_restrictions = TypeManager.IsThisOrFriendAssembly (Parent.Module.Assembly, p.Assembly);
break;
if (al == AccessLevel.Protected)
same_access_restrictions = mc.Parent.IsBaseType (p_parent);
else if (al == AccessLevel.Internal)
- same_access_restrictions = TypeManager.IsThisOrFriendAssembly (Parent.Module.Builder.Assembly, p.Assembly);
+ same_access_restrictions = TypeManager.IsThisOrFriendAssembly (Parent.Module.Assembly, p.Assembly);
else if (al == AccessLevel.ProtectedOrInternal)
same_access_restrictions = mc.Parent.IsBaseType (p_parent) &&
- TypeManager.IsThisOrFriendAssembly (Parent.Module.Builder.Assembly, p.Assembly);
+ TypeManager.IsThisOrFriendAssembly (Parent.Module.Assembly, p.Assembly);
break;
return true;
case TypeAttributes.NotPublic:
- return TypeManager.IsThisOrFriendAssembly (Module.Builder.Assembly, check_type.Assembly);
+ return TypeManager.IsThisOrFriendAssembly (Module.Assembly, check_type.Assembly);
case TypeAttributes.NestedPublic:
return CheckAccessLevel (check_type.DeclaringType);
return FamilyAccessible (tb, check_type);
case TypeAttributes.NestedFamANDAssem:
- return TypeManager.IsThisOrFriendAssembly (Module.Builder.Assembly, check_type.Assembly) &&
+ return TypeManager.IsThisOrFriendAssembly (Module.Assembly, check_type.Assembly) &&
FamilyAccessible (tb, check_type);
case TypeAttributes.NestedFamORAssem:
return FamilyAccessible (tb, check_type) ||
- TypeManager.IsThisOrFriendAssembly (Module.Builder.Assembly, check_type.Assembly);
+ TypeManager.IsThisOrFriendAssembly (Module.Assembly, check_type.Assembly);
case TypeAttributes.NestedAssembly:
- return TypeManager.IsThisOrFriendAssembly (Module.Builder.Assembly, check_type.Assembly);
+ return TypeManager.IsThisOrFriendAssembly (Module.Assembly, check_type.Assembly);
}
throw new NotImplementedException (check_attr.ToString ());
public bool Compile ()
{
// TODO: Should be passed to parser as an argument
- RootContext.ToplevelTypes = new ModuleContainer (ctx, RootContext.Unsafe);
+ RootContext.ToplevelTypes = new ModuleCompiled (ctx, RootContext.Unsafe);
Parse ();
if (Report.Errors > 0)
//
// This works only sometimes
//
- if (type.Module == RootContext.ToplevelTypes.Builder)
+ if (TypeManager.IsBeingCompiled (type))
return Child.GetValue ();
#endif
if (driver == null)
throw new Exception ("Failed to create compiler driver with the given arguments");
- RootContext.ToplevelTypes = new ModuleContainer (ctx, true);
+ RootContext.ToplevelTypes = new ModuleCompiled (ctx, true);
driver.ProcessDefaultConfig ();
startup_files.Add (file.Path);
CompilerCallableEntryPoint.Reset ();
- RootContext.ToplevelTypes = new ModuleContainer (ctx, true);
+ RootContext.ToplevelTypes = new ModuleCompiled (ctx, true);
driver.LoadReferences ();
RootContext.EvalMode = true;
new StreamReportPrinter (MessageOutput);
ctx = new CompilerContext (new Report (printer));
- RootContext.ToplevelTypes = new ModuleContainer (ctx, true);
+ RootContext.ToplevelTypes = new ModuleCompiled (ctx, true);
//
// PartialReset should not reset the core types, this is very redundant.
return false;
method = TypeManager.DropGenericMethodArguments (method);
- if (method.DeclaringType.Module == RootContext.ToplevelTypes.Builder) {
+ if (TypeManager.IsBeingCompiled (method)) {
IMethodData md = TypeManager.GetMethod (method);
if (md != null)
return md.IsExcluded ();
AnonymousTypeClass CreateAnonymousType (ResolveContext ec, ArrayList parameters)
{
- AnonymousTypeClass type = parent.Module.GetAnonymousType (parameters);
+ AnonymousTypeClass type = parent.Module.Compiled.GetAnonymousType (parameters);
if (type != null)
return type;
if (ec.Report.Errors == 0)
type.CloseType ();
- parent.Module.AddAnonymousType (type);
+ parent.Module.Compiled.AddAnonymousType (type);
return type;
}
field_type_hash.Add (type, this);
- if (type.Module == RootContext.ToplevelTypes.Builder) {
+ if (TypeManager.IsBeingCompiled (type)) {
TypeContainer tc = TypeManager.LookupTypeContainer (TypeManager.DropGenericTypeArguments (type));
ArrayList public_fields = new ArrayList ();
//
// Contains the parsed tree
//
- static ModuleContainer root;
+ static ModuleCompiled root;
//
// This hashtable contains all of the #definitions across the source code
return AllDefines.Contains (value);
}
- static public ModuleContainer ToplevelTypes {
+ static public ModuleCompiled ToplevelTypes {
get { return root; }
set { root = value; }
}
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;
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 (CompilerContext context, 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;
}
}
- Builder.SetCustomAttribute (cb);
+ builder.SetCustomAttribute (cb);
+ }
+
+ public ModuleBuilder Builder {
+ get {
+ return builder;
+ }
+
+ set {
+ builder = value;
+ assembly = builder.Assembly;
+ }
}
public override CompilerContext Compiler {
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))
public static MemberCache LookupMemberCache (Type t)
{
- if (t.Module == RootContext.ToplevelTypes.Builder) {
+ if (IsBeingCompiled (t)) {
DeclSpace container = (DeclSpace)builder_to_declspace [t];
if (container != null)
return container.MemberCache;
return t;
// TODO: All predefined imported types have to have correct signature
- if (t.Module != RootContext.ToplevelTypes.Builder)
+ if (!IsBeingCompiled (t))
return t;
DeclSpace ds = (DeclSpace)RootContext.ToplevelTypes.GetDefinition (t.FullName);
return cache.FindMembers (mt, bf, name, FilterWithClosure_delegate, null);
}
+ //
+ // Return true for SRE dynamic/unclosed members
+ //
+ public static bool IsBeingCompiled (MemberInfo mi)
+ {
+ return mi.Module.Assembly == RootContext.ToplevelTypes.Module.Assembly;
+ }
+
public static bool IsBuiltinType (Type t)
{
t = TypeToCoreType (t);
if (t != object_type)
return false;
- if (t.Module == RootContext.ToplevelTypes.Builder)
+ if (IsBeingCompiled (t))
return false;
PredefinedAttribute pa = PredefinedAttributes.Get.Dynamic;