Author: martin
Date: 2005-04-19 08:28:48 -0400 (Tue, 19 Apr 2005)
New Revision: 43246
Modified:
trunk/mcs/gmcs/ChangeLog
trunk/mcs/gmcs/class.cs
trunk/mcs/gmcs/expression.cs
trunk/mcs/gmcs/generic.cs
trunk/mcs/gmcs/typemanager.cs
Log:
**** Merged r42462 from MCS ****
Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog 2005-04-19 11:37:56 UTC (rev 43245)
+++ trunk/mcs/gmcs/ChangeLog 2005-04-19 12:28:48 UTC (rev 43246)
@@ -1,3 +1,24 @@
+2005-04-19 Martin Baulig <[EMAIL PROTECTED]>
+
+ Merged r42462 from MCS and made it work for GMCS.
+
+ * class.cs (MethodCore.ds): Moved this field to `MemberBase'.
+
+ * generic.cs (GenericMethod.Define): Removed `return_type' argument.
+
+2005-04-01 Raja R Harinath <[EMAIL PROTECTED]>
+
+ Fix #74232 and cs0208-3.cs.
+ * expression.cs (ComposedCast.DoResolveAsTypeStep): Add CS0208 check.
+ * typemanager.cs (IsUnmanagedType): Don't allow 'object' as an
+ unmanaged type. Don't use FieldBuilders when 't' is a
+ TypeBuilder. Use ModFlags and MemberType fields.
+ * class.cs (MemberBase.member_type): Rename from MemberType.
+ (MemberBase.MemberType): New property. Determines member_type on
+ demand.
+ (MemberBase.DoDefine): Don't initialize MemberType here.
+ (FieldMember.Define): Likewise.
+
2005-04-01 Marek Safar <[EMAIL PROTECTED]>
Fix #74241
Modified: trunk/mcs/gmcs/class.cs
===================================================================
--- trunk/mcs/gmcs/class.cs 2005-04-19 11:37:56 UTC (rev 43245)
+++ trunk/mcs/gmcs/class.cs 2005-04-19 12:28:48 UTC (rev 43246)
@@ -3203,7 +3203,6 @@
public abstract class MethodCore : MemberBase {
public readonly Parameters Parameters;
public readonly GenericMethod GenericMethod;
- public readonly DeclSpace ds;
protected ToplevelBlock block;
//
@@ -3226,17 +3225,12 @@
Expression type, int mod, int allowed_mod,
bool is_iface,
MemberName name, Attributes attrs,
Parameters parameters,
Location loc)
- : base (parent, type, mod, allowed_mod,
Modifiers.PRIVATE, name,
- attrs, loc)
+ : base (parent, generic != null ? generic : (DeclSpace)
parent,
+ type, mod, allowed_mod, Modifiers.PRIVATE,
name, attrs, loc)
{
Parameters = parameters;
IsInterface = is_iface;
this.GenericMethod = generic;
-
- if (generic != null)
- ds = generic;
- else
- ds = parent;
}
//
@@ -4055,11 +4049,11 @@
if (GenericMethod != null) {
string mname = MemberName.GetMethodName ();
mb = Parent.TypeBuilder.DefineGenericMethod
(mname, flags);
- if (!GenericMethod.Define (mb, ReturnType))
+ if (!GenericMethod.Define (mb))
return false;
}
- if (!DoDefine (ds))
+ if (!DoDefine ())
return false;
if (RootContext.StdLib && (ReturnType ==
TypeManager.arg_iterator_type || ReturnType ==
TypeManager.typed_reference_type)) {
@@ -5295,6 +5289,7 @@
public Expression Type;
public MethodAttributes flags;
+ public readonly DeclSpace ds;
protected readonly int explicit_mod_flags;
@@ -5312,8 +5307,22 @@
//
// The type of this property / indexer / event
//
- public Type MemberType;
+ protected Type member_type;
+ public Type MemberType {
+ get {
+ if (member_type == null && Type != null) {
+ EmitContext ec = ds.EmitContext;
+ bool old_unsafe = ec.InUnsafe;
+ ec.InUnsafe = InUnsafe;
+ Type = Type.ResolveAsTypeTerminal (ec);
+ ec.InUnsafe = old_unsafe;
+ member_type = Type == null ? null :
Type.Type;
+ }
+ return member_type;
+ }
+ }
+
//
// Whether this is an interface member.
//
@@ -5332,11 +5341,12 @@
//
// The constructor is only exposed to our children
//
- protected MemberBase (TypeContainer parent, Expression type,
int mod,
+ protected MemberBase (TypeContainer parent, DeclSpace ds,
Expression type, int mod,
int allowed_mod, int def_mod, MemberName
name,
Attributes attrs, Location loc)
: base (parent, name, attrs, loc)
{
+ this.ds = ds;
explicit_mod_flags = mod;
Type = type;
ModFlags = Modifiers.Check (allowed_mod, mod, def_mod,
loc);
@@ -5434,25 +5444,17 @@
return true;
}
- protected virtual bool DoDefine (DeclSpace decl)
+ protected virtual bool DoDefine ()
{
- EmitContext ec = decl.EmitContext;
+ EmitContext ec = ds.EmitContext;
if (ec == null)
throw new InternalErrorException
("MemberBase.DoDefine called too early");
ec.InUnsafe = InUnsafe;
- // Lookup Type, verify validity
- bool old_unsafe = ec.InUnsafe;
- ec.InUnsafe = InUnsafe;
- TypeExpr texpr = Type.ResolveAsTypeTerminal (ec);
- ec.InUnsafe = old_unsafe;
-
- if (texpr == null)
+ if (MemberType == null)
return false;
- MemberType = texpr.Type;
-
if ((Parent.ModFlags & Modifiers.SEALED) != 0){
if ((ModFlags &
(Modifiers.VIRTUAL|Modifiers.ABSTRACT)) != 0){
Report.Error (549, Location, "Virtual
method can not be contained in sealed class");
@@ -5578,7 +5580,7 @@
protected FieldBase (TypeContainer parent, Expression type, int
mod,
int allowed_mod, MemberName name, object
init,
Attributes attrs, Location loc)
- : base (parent, type, mod, allowed_mod,
Modifiers.PRIVATE,
+ : base (parent, parent, type, mod, allowed_mod,
Modifiers.PRIVATE,
name, attrs, loc)
{
this.init = init;
@@ -5681,9 +5683,9 @@
return true;
}
- protected override bool DoDefine (DeclSpace ds)
+ protected override bool DoDefine ()
{
- if (!base.DoDefine (ds))
+ if (!base.DoDefine ())
return false;
if (MemberType == TypeManager.void_type) {
@@ -5779,17 +5781,9 @@
if (ec == null)
throw new InternalErrorException
("FieldMember.Define called too early");
- bool old_unsafe = ec.InUnsafe;
- ec.InUnsafe = InUnsafe;
- TypeExpr texpr = Type.ResolveAsTypeTerminal (ec);
- ec.InUnsafe = old_unsafe;
- if (texpr == null)
+ if (MemberType == null)
return false;
- MemberType = texpr.Type;
-
- ec.InUnsafe = old_unsafe;
-
if (MemberType == TypeManager.void_type) {
Report.Error (1547, Location, "Keyword 'void'
cannot be used in this context");
return false;
@@ -6605,7 +6599,7 @@
public override bool Define ()
{
- if (!DoDefine (Parent))
+ if (!DoDefine ())
return false;
if (!IsTypePermitted ())
@@ -6614,9 +6608,9 @@
return true;
}
- protected override bool DoDefine (DeclSpace ds)
+ protected override bool DoDefine ()
{
- if (!base.DoDefine (ds))
+ if (!base.DoDefine ())
return false;
//
@@ -7348,7 +7342,7 @@
if (!DoDefineBase ())
return false;
- if (!DoDefine (Parent))
+ if (!DoDefine ())
return false;
if (init != null && ((ModFlags & Modifiers.ABSTRACT) !=
0)){
@@ -7836,7 +7830,7 @@
return false;
}
- if (!DoDefine (ds))
+ if (!DoDefine ())
return false;
if (MemberType == TypeManager.void_type) {
Modified: trunk/mcs/gmcs/expression.cs
===================================================================
--- trunk/mcs/gmcs/expression.cs 2005-04-19 11:37:56 UTC (rev 43245)
+++ trunk/mcs/gmcs/expression.cs 2005-04-19 12:28:48 UTC (rev 43246)
@@ -8785,6 +8785,11 @@
return nullable.ResolveAsTypeTerminal (ec);
}
+ if (dim == "*" && !TypeManager.IsUnmanagedType (ltype))
{
+ Report.Error (208, loc, "Cannot declare a
pointer to a managed type ('{0}')", ltype);
+ return null;
+ }
+
if (dim != "")
type = TypeManager.GetConstructedType (ltype,
dim);
else
Modified: trunk/mcs/gmcs/generic.cs
===================================================================
--- trunk/mcs/gmcs/generic.cs 2005-04-19 11:37:56 UTC (rev 43245)
+++ trunk/mcs/gmcs/generic.cs 2005-04-19 12:28:48 UTC (rev 43246)
@@ -1415,7 +1415,7 @@
return true;
}
- public bool Define (MethodBuilder mb, Type return_type)
+ public bool Define (MethodBuilder mb)
{
if (!Define ())
return false;
@@ -1426,8 +1426,7 @@
for (int i = 0; i < TypeParameters.Length; i++)
TypeParameters [i].Define (gen_params [i]);
- ec = new EmitContext (
- this, this, Location, null, return_type,
ModFlags, false);
+ ec = new EmitContext (this, this, Location, null, null,
ModFlags, false);
for (int i = 0; i < TypeParameters.Length; i++) {
if (!TypeParameters [i].ResolveType (ec))
Modified: trunk/mcs/gmcs/typemanager.cs
===================================================================
--- trunk/mcs/gmcs/typemanager.cs 2005-04-19 11:37:56 UTC (rev 43245)
+++ trunk/mcs/gmcs/typemanager.cs 2005-04-19 12:28:48 UTC (rev 43246)
@@ -1647,7 +1647,7 @@
//
public static bool IsUnmanagedType (Type t)
{
- if (IsBuiltinType (t) && t != TypeManager.string_type)
+ if (IsBuiltinType (t) && t != TypeManager.object_type && t !=
TypeManager.string_type)
return true;
if (IsEnumType (t))
@@ -1656,33 +1656,33 @@
if (t.IsPointer)
return true;
- if (IsValueType (t)){
- if (t is TypeBuilder){
- TypeContainer tc = LookupTypeContainer (t);
+ if (!IsValueType (t))
+ return false;
- if (tc.Fields != null){
- foreach (Field f in tc.Fields){
- if (f.FieldBuilder.IsStatic)
- continue;
- if (!IsUnmanagedType
(f.FieldBuilder.FieldType))
- return false;
- }
- } else
- return true;
- } else {
- FieldInfo [] fields = t.GetFields ();
-
- foreach (FieldInfo f in fields){
- if (f.IsStatic)
- continue;
- if (!IsUnmanagedType (f.FieldType))
- return false;
- }
+ if (t is TypeBuilder){
+ TypeContainer tc = LookupTypeContainer (t);
+
+ if (tc.Fields == null)
+ return true;
+ foreach (Field f in tc.Fields){
+ // Avoid using f.FieldBuilder: f.Define () may
not yet have been invoked.
+ if ((f.ModFlags & Modifiers.STATIC) != 0)
+ continue;
+ if (!IsUnmanagedType (f.MemberType))
+ return false;
}
return true;
}
-
- return false;
+
+ FieldInfo [] fields = t.GetFields ();
+
+ foreach (FieldInfo f in fields){
+ if (f.IsStatic)
+ continue;
+ if (!IsUnmanagedType (f.FieldType))
+ return false;
+ }
+ return true;
}
public static bool IsValueType (Type t)
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches