Author: martin
Date: 2005-03-22 05:18:00 -0500 (Tue, 22 Mar 2005)
New Revision: 42083
Modified:
trunk/mcs/gmcs/ChangeLog
trunk/mcs/gmcs/attribute.cs
trunk/mcs/gmcs/class.cs
trunk/mcs/gmcs/namespace.cs
trunk/mcs/gmcs/rootcontext.cs
Log:
**** Merged r40971 from MCS ****
Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog 2005-03-22 10:12:21 UTC (rev 42082)
+++ trunk/mcs/gmcs/ChangeLog 2005-03-22 10:18:00 UTC (rev 42083)
@@ -1,3 +1,23 @@
+2005-02-21 Marek Safar <[EMAIL PROTECTED]>
+
+ Fix #69949
+ * attribute.cs (Attribute.GetAttributeUsage): Add EmitContext
+ argument. Call ResolveAttributeUsage for unresolved.
+ when types doesn't match ctor arguments.
+
+ * class.cs (DoDefineMembers.TypeContainer): Removed safety check
+ for nested attribute classes.
+ (Class.attribute_usage): Removed.
+ (Class.ResolveAttributeUsage): Resolves AttributeUsageAttribute
+ for attribute class.
+
+ * namespace.cs (UsingEntry.Resolve): Don't destroy NamespaceEntry.
+
+ * rootcontext.cs (RegisterAttribute): Removed, attributes are
+ now normal types.
+ (attribute_types): Removed.
+ (EmitCode): Global attributes are emited as the latest.
+
2005-02-18 Marek Safar <[EMAIL PROTECTED]>
* class.cs (EmitFieldInitializers): Don't emit field initializer
Modified: trunk/mcs/gmcs/attribute.cs
===================================================================
--- trunk/mcs/gmcs/attribute.cs 2005-03-22 10:12:21 UTC (rev 42082)
+++ trunk/mcs/gmcs/attribute.cs 2005-03-22 10:18:00 UTC (rev 42083)
@@ -83,15 +83,9 @@
bool resolve_error;
- // Is non-null if type is AttributeUsageAttribute
- AttributeUsageAttribute usage_attribute;
+ public AttributeUsageAttribute UsageAttribute;
+ public static AttributeUsageAttribute DefaultUsageAttribute =
new AttributeUsageAttribute (AttributeTargets.All);
- public AttributeUsageAttribute UsageAttribute {
- get {
- return usage_attribute;
- }
- }
-
MethodImplOptions ImplOptions;
UnmanagedType UnmanagedType;
CustomAttributeBuilder cb;
@@ -318,7 +312,7 @@
Type oldType = Type;
// Sanity check.
- Type = CheckAttributeType (ec);
+ Type = CheckAttributeType (ec); // TODO: I really don't
think we need such expensive double check
if (oldType == null && Type == null)
return null;
@@ -399,7 +393,7 @@
Report.Error (591,
Location, "Invalid value for argument to 'System.AttributeUsage' attribute");
return null;
}
- usage_attribute = new
AttributeUsageAttribute ((AttributeTargets)val);
+ UsageAttribute = new
AttributeUsageAttribute ((AttributeTargets)val);
} else if (MethodImplAttr) {
this.ImplOptions =
(MethodImplOptions) val;
} else if (GuidAttr){
@@ -496,13 +490,13 @@
object value;
if (!GetAttributeArgumentExpression (e,
Location, pi.PropertyType, out value))
- return null;
-
- if (usage_attribute != null) {
- if (member_name ==
"AllowMultiple")
-
usage_attribute.AllowMultiple = (bool) value;
+ return null;
+
+ if (UsageAttribute != null) {
+ if (member_name ==
"AllowMultiple")
+
UsageAttribute.AllowMultiple = (bool) value;
if (member_name ==
"Inherited")
-
usage_attribute.Inherited = (bool) value;
+
UsageAttribute.Inherited = (bool) value;
}
prop_values.Add (value);
@@ -635,6 +629,10 @@
return null;
}
+ if (!usage_attr) {
+ UsageAttribute = DefaultUsageAttribute;
+ }
+
resolve_error = false;
return cb;
}
@@ -645,7 +643,7 @@
public string GetValidTargets ()
{
StringBuilder sb = new StringBuilder ();
- AttributeTargets targets = GetAttributeUsage ().ValidOn;
+ AttributeTargets targets = UsageAttribute.ValidOn;
if ((targets & AttributeTargets.Assembly) != 0)
sb.Append ("'assembly' ");
@@ -696,7 +694,7 @@
/// <summary>
/// Returns AttributeUsage attribute for this type
/// </summary>
- public AttributeUsageAttribute GetAttributeUsage ()
+ public AttributeUsageAttribute GetAttributeUsage (EmitContext
ec)
{
AttributeUsageAttribute ua = usage_attr_cache [Type] as
AttributeUsageAttribute;
if (ua != null)
@@ -710,8 +708,10 @@
usage_attr_cache.Add (Type, ua);
return ua;
}
-
- return attr_class.AttributeUsage;
+
+ ua = attr_class.ResolveAttributeUsage (ec);
+ usage_attr_cache.Add (Type, ua);
+ return ua;
}
/// <summary>
@@ -987,7 +987,7 @@
if (cb == null)
return;
- AttributeUsageAttribute usage_attr = GetAttributeUsage
();
+ AttributeUsageAttribute usage_attr = GetAttributeUsage
(ec);
if ((usage_attr.ValidOn & Target) == 0) {
Report.Error (592, Location, "Attribute '{0}'
is not valid on this declaration type. It is valid on {1} declarations only.",
Name, GetValidTargets ());
return;
Modified: trunk/mcs/gmcs/class.cs
===================================================================
--- trunk/mcs/gmcs/class.cs 2005-03-22 10:12:21 UTC (rev 42082)
+++ trunk/mcs/gmcs/class.cs 2005-03-22 10:18:00 UTC (rev 42083)
@@ -1376,9 +1376,7 @@
//
ec.ContainerType = TypeBuilder;
- if ((base_type != null) && base_type.IsAttribute) {
- RootContext.RegisterAttribute (this);
- } else if (!(this is Iterator))
+ if (!(this is Iterator))
RootContext.RegisterOrder (this);
if (!DefineNestedTypes ()) {
@@ -1482,26 +1480,18 @@
if ((ModFlags & Modifiers.NEW) != 0)
Error_KeywordNotAllowed (Location);
} else {
- // HACK: missing implemenation
- // This is not fully functional. Better way how
to handle this is to have recursive definition of containers
- // instead of flat as we have now.
- // Now we are not able to check inner attribute
class because its parent had not been defined.
+ MemberInfo conflict_symbol =
Parent.MemberCache.FindMemberWithSameName (Basename, false, TypeBuilder);
+ if (conflict_symbol == null) {
+ if ((RootContext.WarningLevel >= 4) &&
((ModFlags & Modifiers.NEW) != 0))
+ Report.Warning (109, Location,
"The member '{0}' does not hide an inherited member. The new keyword is not
required", GetSignatureForError ());
+ } else {
+ if ((ModFlags & Modifiers.NEW) == 0) {
+
Report.SymbolRelatedToPreviousError (conflict_symbol);
+ Report.Warning (108, Location,
"The keyword new is required on '{0}' because it hides inherited member",
GetSignatureForError ());
+ }
+ }
+ }
- // TODO: remove this if
- if (Parent.MemberCache != null) {
- MemberInfo conflict_symbol =
Parent.MemberCache.FindMemberWithSameName (Basename, false, TypeBuilder);
- if (conflict_symbol == null) {
- if ((RootContext.WarningLevel
>= 4) && ((ModFlags & Modifiers.NEW) != 0))
- Report.Warning (109,
Location, "The member '{0}' does not hide an inherited member. The new keyword
is not required", GetSignatureForError ());
- } else {
- if ((ModFlags & Modifiers.NEW)
== 0) {
-
Report.SymbolRelatedToPreviousError (conflict_symbol);
- Report.Warning (108,
Location, "The keyword new is required on '{0}' because it hides inherited
member", GetSignatureForError ());
- }
- }
- }
- }
-
DefineContainerMembers (constants);
DefineContainerMembers (fields);
@@ -3057,15 +3047,11 @@
Modifiers.SEALED |
Modifiers.UNSAFE;
- // Information in the case we are an attribute type
- AttributeUsageAttribute attribute_usage;
-
public Class (NamespaceEntry ns, TypeContainer parent,
MemberName name, int mod,
Attributes attrs, Location l)
: base (ns, parent, name, attrs, Kind.Class, l)
{
this.ModFlags = mod;
- attribute_usage = new AttributeUsageAttribute
(AttributeTargets.All);
}
virtual protected int AllowedModifiersProp {
@@ -3076,22 +3062,37 @@
public override void ApplyAttributeBuilder(Attribute a,
CustomAttributeBuilder cb)
{
- if (a.UsageAttribute != null) {
+ if (a.Type == TypeManager.attribute_usage_type) {
if (ptype != TypeManager.attribute_type &&
!ptype.IsSubclassOf
(TypeManager.attribute_type) &&
TypeBuilder.FullName != "System.Attribute")
{
Report.Error (641, a.Location,
"Attribute '{0}' is only valid on classes derived from System.Attribute",
a.Name);
}
- attribute_usage = a.UsageAttribute;
}
base.ApplyAttributeBuilder (a, cb);
}
- public AttributeUsageAttribute AttributeUsage {
- get {
- return attribute_usage;
- }
+ /// <summary>
+ /// Resolves AttributeUsageAttribute for attribute class
+ /// </summary>
+ public AttributeUsageAttribute ResolveAttributeUsage
(EmitContext ec)
+ {
+ if (OptAttributes == null)
+ return Attribute.DefaultUsageAttribute;
+
+ Attribute a = OptAttributes.Search
(TypeManager.attribute_usage_type, ec);
+ if (a == null)
+ return Attribute.DefaultUsageAttribute;
+
+ // Because our namespace model is so weird.
+ // When GlobalAttribute is resolved and it has
AttributeUsage attribute
+ // we need to switch from global namespace to local
+ DeclSpace old_ds = ec.DeclSpace;
+ ec.DeclSpace = this;
+ a.Resolve (ec);
+ ec.DeclSpace = old_ds;
+ return a.UsageAttribute;
}
public const TypeAttributes DefaultTypeAttributes =
Modified: trunk/mcs/gmcs/namespace.cs
===================================================================
--- trunk/mcs/gmcs/namespace.cs 2005-03-22 10:12:21 UTC (rev 42082)
+++ trunk/mcs/gmcs/namespace.cs 2005-03-22 10:18:00 UTC (rev 42083)
@@ -248,9 +248,10 @@
return resolved as Namespace;
DeclSpace root = RootContext.Tree.Types;
+ NamespaceEntry orig_ns = root.NamespaceEntry;
root.NamespaceEntry = NamespaceEntry;
resolved = Name.ResolveAsTypeStep
(root.EmitContext);
- root.NamespaceEntry = null;
+ root.NamespaceEntry = orig_ns;
return resolved as Namespace;
}
Modified: trunk/mcs/gmcs/rootcontext.cs
===================================================================
--- trunk/mcs/gmcs/rootcontext.cs 2005-03-22 10:12:21 UTC (rev 42082)
+++ trunk/mcs/gmcs/rootcontext.cs 2005-03-22 10:18:00 UTC (rev 42083)
@@ -54,7 +54,6 @@
// override).
//
static ArrayList type_container_resolve_order;
- static ArrayList attribute_types;
//
// Holds a reference to the Private Implementation Details
@@ -118,14 +117,6 @@
{
type_container_resolve_order.Add (tc);
}
-
- public static void RegisterAttribute (TypeContainer tc)
- {
- if (attribute_types == null)
- attribute_types = new ArrayList ();
-
- attribute_types.Add (tc);
- }
//
// The default compiler checked state
@@ -154,13 +145,6 @@
static public void ResolveTree ()
{
//
- // Process the attribute types separately and before
anything else
- //
- if (attribute_types != null)
- foreach (TypeContainer tc in attribute_types)
- tc.DefineType ();
-
- //
// Interfaces are processed next, as classes and
// structs might inherit from an object or implement
// a set of interfaces, we need to be able to tell
@@ -303,6 +287,7 @@
TypeManager.object_type = BootstrapCorlib_ResolveClass
(root, "System.Object");
TypeManager.value_type = BootstrapCorlib_ResolveClass
(root, "System.ValueType");
TypeManager.attribute_type =
BootstrapCorlib_ResolveClass (root, "System.Attribute");
+ TypeManager.indexer_name_type =
BootstrapCorlib_ResolveClass (root,
"System.Runtime.CompilerServices.IndexerNameAttribute");
string [] interfaces_first_stage = {
"System.IComparable", "System.ICloneable",
@@ -396,7 +381,6 @@
"System.CLSCompliantAttribute",
"System.Security.UnverifiableCodeAttribute",
"System.Security.Permissions.SecurityAttribute",
-
"System.Runtime.CompilerServices.IndexerNameAttribute",
"System.Runtime.CompilerServices.DecimalConstantAttribute",
"System.Runtime.InteropServices.InAttribute",
"System.Runtime.InteropServices.OutAttribute",
@@ -440,10 +424,6 @@
foreach (Enum en in root.Enums)
en.CloseType ();
- if (attribute_types != null)
- foreach (TypeContainer tc in attribute_types)
- tc.CloseType ();
-
//
// We do this in two passes, first we close the structs,
// then the classes, because it seems the code needs it
this
@@ -478,7 +458,6 @@
}
}
- attribute_types = null;
type_container_resolve_order = null;
helper_classes = null;
//tree = null;
@@ -517,6 +496,7 @@
PopulateCoreType (root, "System.Object");
PopulateCoreType (root, "System.ValueType");
PopulateCoreType (root, "System.Attribute");
+ PopulateCoreType (root,
"System.Runtime.CompilerServices.IndexerNameAttribute");
}
// <summary>
@@ -529,10 +509,6 @@
{
TypeContainer root = Tree.Types;
- if (attribute_types != null)
- foreach (TypeContainer tc in attribute_types)
- tc.DefineMembers (root);
-
if (type_container_resolve_order != null){
if (RootContext.StdLib){
foreach (TypeContainer tc in
type_container_resolve_order)
@@ -542,8 +518,9 @@
// When compiling corlib, these
types have already been
// populated from
BootCorlib_PopulateCoreTypes ().
if (((tc.Name ==
"System.Object") ||
- (tc.Name ==
"System.Attribute") ||
- (tc.Name ==
"System.ValueType")))
+ (tc.Name ==
"System.Attribute") ||
+ (tc.Name ==
"System.ValueType") ||
+ (tc.Name ==
"System.Runtime.CompilerServices.IndexerNameAttribute")))
continue;
tc.DefineMembers (root);
@@ -596,10 +573,6 @@
{
TypeContainer root = Tree.Types;
- if (attribute_types != null)
- foreach (TypeContainer tc in attribute_types)
- tc.Define ();
-
if (type_container_resolve_order != null){
foreach (TypeContainer tc in
type_container_resolve_order) {
// When compiling corlib, these types
have already been
@@ -607,7 +580,8 @@
if (!RootContext.StdLib &&
((tc.Name == "System.Object") ||
(tc.Name == "System.Attribute") ||
- (tc.Name == "System.ValueType")))
+ (tc.Name == "System.ValueType") ||
+ (tc.Name ==
"System.Runtime.CompilerServices.IndexerNameAttribute")))
continue;
if ((tc.ModFlags & Modifiers.NEW) == 0)
@@ -632,13 +606,6 @@
static public void EmitCode ()
{
- if (attribute_types != null)
- foreach (TypeContainer tc in attribute_types)
- tc.EmitType ();
-
- CodeGen.Assembly.Emit (Tree.Types);
- CodeGen.Module.Emit (Tree.Types);
-
if (Tree.Types.Enums != null) {
foreach (Enum e in Tree.Types.Enums)
e.Emit ();
@@ -660,6 +627,9 @@
if (EmitCodeHook != null)
EmitCodeHook ();
+
+ CodeGen.Assembly.Emit (Tree.Types);
+ CodeGen.Module.Emit (Tree.Types);
}
//
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches