Author: marek
Date: 2005-03-30 07:08:48 -0500 (Wed, 30 Mar 2005)
New Revision: 42367
Modified:
trunk/mcs/mcs/ChangeLog
trunk/mcs/mcs/attribute.cs
trunk/mcs/mcs/class.cs
Log:
2005-03-30 Marek Safar <[EMAIL PROTECTED]>
C# 2.0 Conditional attribute class implementation
* attribute.cs (AttributeTester.IsAttributeExcluded): New method.
Analyzes class whether it has attribute which has ConditionalAttribute
and its condition is not defined.
* class.cs (Class.ApplyAttributeBuilder): Add IsAttributeExcluded check.
(Class.IsExcluded): New method. Search for at least one defined
condition in ConditionalAttribute of attribute class.
Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog 2005-03-30 11:58:24 UTC (rev 42366)
+++ trunk/mcs/mcs/ChangeLog 2005-03-30 12:08:48 UTC (rev 42367)
@@ -1,3 +1,15 @@
+2005-03-30 Marek Safar <[EMAIL PROTECTED]>
+
+ C# 2.0 Conditional attribute class implementation
+
+ * attribute.cs (AttributeTester.IsAttributeExcluded): New method.
+ Analyzes class whether it has attribute which has ConditionalAttribute
+ and its condition is not defined.
+
+ * class.cs (Class.ApplyAttributeBuilder): Add IsAttributeExcluded check.
+ (Class.IsExcluded): New method. Search for at least one defined
+ condition in ConditionalAttribute of attribute class.
+
2005-03-30 Raja R Harinath <[EMAIL PROTECTED]>
* ecore.cs (PropertyExpr): Derive from Expression, not
Modified: trunk/mcs/mcs/attribute.cs
===================================================================
--- trunk/mcs/mcs/attribute.cs 2005-03-30 11:58:24 UTC (rev 42366)
+++ trunk/mcs/mcs/attribute.cs 2005-03-30 12:08:48 UTC (rev 42367)
@@ -989,6 +989,7 @@
}
catch (Exception e) {
Error_AttributeEmitError (e.Message);
+ Console.WriteLine (e.ToString ());
return;
}
@@ -1341,7 +1342,10 @@
static PtrHashtable analyzed_types_obsolete = new PtrHashtable
();
static PtrHashtable analyzed_member_obsolete = new PtrHashtable
();
static PtrHashtable analyzed_method_excluded = new PtrHashtable
();
+
+#if NET_2_0
static PtrHashtable fixed_buffer_cache = new PtrHashtable ();
+#endif
static object TRUE = new object ();
static object FALSE = new object ();
@@ -1657,5 +1661,30 @@
analyzed_method_excluded.Add (mb, TRUE);
return true;
}
+
+ /// <summary>
+ /// Analyzes class whether it has attribute which has
ConditionalAttribute
+ /// and its condition is not defined.
+ /// </summary>
+ public static bool IsAttributeExcluded (Type type)
+ {
+ if (!type.IsClass)
+ return false;
+
+ Class class_decl = TypeManager.LookupDeclSpace (type)
as Class;
+
+ // TODO: add caching
+ // TODO: merge all Type bases attribute caching to one
cache to save memory
+ if (class_decl == null) {
+ object[] attributes = type.GetCustomAttributes
(TypeManager.conditional_attribute_type, false);
+ foreach (ConditionalAttribute ca in attributes)
{
+ if (RootContext.AllDefines.Contains
(ca.ConditionString))
+ return false;
+ }
+ return attributes.Length > 0;
+ }
+
+ return class_decl.IsExcluded ();
+ }
}
}
Modified: trunk/mcs/mcs/class.cs
===================================================================
--- trunk/mcs/mcs/class.cs 2005-03-30 11:58:24 UTC (rev 42366)
+++ trunk/mcs/mcs/class.cs 2005-03-30 12:08:48 UTC (rev 42367)
@@ -2796,6 +2796,15 @@
}
}
+ if (a.Type == TypeManager.conditional_attribute_type &&
+ !(ptype == TypeManager.attribute_type ||
ptype.IsSubclassOf (TypeManager.attribute_type))) {
+ Report.Error (1689, a.Location, "Attribute
'System.Diagnostics.ConditionalAttribute' is only valid on methods or attribute
classes");
+ return;
+ }
+
+ if (AttributeTester.IsAttributeExcluded (a.Type))
+ return;
+
base.ApplyAttributeBuilder (a, cb);
}
@@ -2815,6 +2824,33 @@
return base.DefineType ();
}
+ /// Search for at least one defined condition in
ConditionalAttribute of attribute class
+ /// Valid only for attribute classes.
+ public bool IsExcluded ()
+ {
+ if ((caching_flags & Flags.Excluded_Undetected) == 0)
+ return (caching_flags & Flags.Excluded) != 0;
+
+ caching_flags &= ~Flags.Excluded_Undetected;
+
+ if (OptAttributes == null)
+ return false;
+
+ Attribute[] attrs = OptAttributes.SearchMulti
(TypeManager.conditional_attribute_type, ec);
+
+ if (attrs == null)
+ return false;
+
+ foreach (Attribute a in attrs) {
+ string condition =
a.GetConditionalAttributeValue (Parent.EmitContext);
+ if (RootContext.AllDefines.Contains (condition))
+ return false;
+ }
+
+ caching_flags |= Flags.Excluded;
+ return true;
+ }
+
//
// FIXME: How do we deal with the user specifying a different
// layout?
@@ -3569,7 +3605,7 @@
}
if (ReturnType != TypeManager.void_type) {
- Report.Error (578, Location,
"Conditional not valid on '{0}' because its return new ErrorData ( type is not
void", GetSignatureForError ());
+ Report.Error (578, Location,
"Conditional not valid on '{0}' because its return type is not void",
GetSignatureForError ());
return;
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches