+2004-05-31 Marek Safar <marek.safar@seznam.cz>
+
+ * attribute.cs
+ (AttributeTester.GetObsoleteAttribute): Returns instance of
+ ObsoleteAttribute when type is obsolete.
+
+ * class.cs
+ (TypeContainer.VerifyObsoleteAttribute): Override.
+ (Method.GetSignatureForError): New method for usage when MethodBuilder is null.
+ (MethodCode.VerifyObsoleteAttribute): Override.
+ (MemberBase.VerifyObsoleteAttribute): Override.
+
+ * decl.cs
+ (MemberCore.CheckUsageOfObsoleteAttribute): Tests presence of ObsoleteAttribute
+ and report proper error.
+
+ *delegate.cs
+ (Delegate.VerifyObsoleteAttribute): Override.
+
+ * ecore.cs
+ (Expression.CheckObsoleteAttribute): Tests presence of ObsoleteAttribute
+ and report proper error.
+ (FieldExpr.DoResolve): Added tests for ObsoleteAttribute.
+
+ * enum.cs
+ (Enum.GetObsoleteAttribute): Returns ObsoleteAttribute for both enum type
+ and enum member.
+
+ * expression.cs
+ (Probe.DoResolve, Cast.DoResolve, LocalVariableReference.DoResolve,
+ New.DoResolve, SizeOf.DoResolve, TypeOf.DoResolce, MemberAccess.DoResolve):
+ Added test for ObsoleteAttribute.
+
+ * statement.cs
+ (Catch): Derived from Statement.
+
2004-05-31 Marek Safar <marek.safar@seznam.cz>
* attribute.cs
don't have any dots. Fixes #52622, added cs0246-8.cs.
* namespace.cs (NamespaceEntry.Lookup): Likewise.
-
+
2004-05-23 Marek Safar <marek.safar@seznam.cz>
* class.cs (MemberBase.Define): Reuse MemberType member for
sealed class AttributeTester
{
static PtrHashtable analyzed_types = new PtrHashtable ();
+ static PtrHashtable analyzed_types_obsolete = new PtrHashtable ();
static PtrHashtable analyzed_member_obsolete = new PtrHashtable ();
static PtrHashtable analyzed_method_excluded = new PtrHashtable ();
return ((CLSCompliantAttribute)CompliantAttribute[0]).IsCompliant;
}
+ /// <summary>
+ /// Returns instance of ObsoleteAttribute when type is obsolete
+ /// </summary>
+ public static ObsoleteAttribute GetObsoleteAttribute (Type type)
+ {
+ object type_obsolete = analyzed_types_obsolete [type];
+ if (type_obsolete == FALSE)
+ return null;
+
+ if (type_obsolete != null)
+ return (ObsoleteAttribute)type_obsolete;
+
+ ObsoleteAttribute result = null;
+ if (type.IsByRef || type.IsArray || type.IsPointer) {
+ result = GetObsoleteAttribute (TypeManager.GetElementType (type));
+ } else {
+ DeclSpace type_ds = TypeManager.LookupDeclSpace (type);
+
+ // Type is external, we can get attribute directly
+ if (type_ds == null) {
+ object[] attribute = type.GetCustomAttributes (TypeManager.obsolete_attribute_type, false);
+ if (attribute.Length == 1)
+ result = (ObsoleteAttribute)attribute [0];
+ } else {
+ result = type_ds.GetObsoleteAttribute (type_ds);
+ }
+ }
+
+ analyzed_types_obsolete.Add (type, result == null ? FALSE : result);
+ return result;
+ }
+
/// <summary>
/// Returns instance of ObsoleteAttribute when method is obsolete
/// </summary>
return true;
}
+ protected override void VerifyObsoleteAttribute()
+ {
+ CheckUsageOfObsoleteAttribute (base_class_type);
+
+ if (ifaces == null)
+ return;
+
+ foreach (TypeExpr expr in ifaces) {
+ CheckUsageOfObsoleteAttribute (expr.Type);
+ }
+ }
+
+
//
// IMemberContainer
//
return cc;
}
+
+ protected override void VerifyObsoleteAttribute()
+ {
+ base.VerifyObsoleteAttribute ();
+
+ if (parameter_types == null)
+ return;
+
+ foreach (Type type in parameter_types) {
+ CheckUsageOfObsoleteAttribute (type);
+ }
+ }
}
public class Method : MethodCore, IIteratorContainer, IMethodData {
return TypeManager.CSharpSignature (MethodBuilder);
}
+ /// <summary>
+ /// Use this method when MethodBuilder is null
+ /// </summary>
+ public string GetSignatureForError (TypeContainer tc)
+ {
+ System.Text.StringBuilder args = new System.Text.StringBuilder ("");
+ if (parameter_info.Parameters.FixedParameters != null) {
+ for (int i = 0; i < parameter_info.Parameters.FixedParameters.Length; ++i) {
+ Parameter p = parameter_info.Parameters.FixedParameters [i];
+ args.Append (p.GetSignatureForError ());
+
+ if (i < parameter_info.Parameters.FixedParameters.Length - 1)
+ args.Append (',');
+ }
+ }
+
+ return String.Concat (tc.Name, ".", Name, "(", args.ToString (), ")");
+ }
+
void DuplicateEntryPoint (MethodInfo b, Location location)
{
Report.Error (
return false;
}
}
+
+ ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (parent_method);
+ if (oa != null) {
+ Report.SymbolRelatedToPreviousError (parent_method);
+ Report.Warning_T (672, Location, GetSignatureForError (container));
+ }
} else {
if (!OverridesSomething && ((ModFlags & Modifiers.NEW) != 0))
WarningNotHiding (container);
return false;
}
-
+ protected override void VerifyObsoleteAttribute()
+ {
+ CheckUsageOfObsoleteAttribute (MemberType);
+ }
}
//
caching_flags = Flags.Obsolete_Undetected | Flags.ClsCompliance_Undetected | Flags.HasCompliantAttribute_Undetected | Flags.Excluded_Undetected;
}
+ /// <summary>
+ /// Tests presence of ObsoleteAttribute and report proper error
+ /// </summary>
+ protected void CheckUsageOfObsoleteAttribute (Type type)
+ {
+ if (type == null)
+ return;
+
+ ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (type);
+ if (obsolete_attr == null)
+ return;
+
+ AttributeTester.Report_ObsoleteMessage (obsolete_attr, type.FullName, Location);
+ }
+
public abstract bool Define (TypeContainer parent);
//
/// </summary>
public virtual void Emit (TypeContainer container)
{
+ VerifyObsoleteAttribute ();
+
if (!RootContext.VerifyClsCompliance)
return;
return true;
}
+ protected abstract void VerifyObsoleteAttribute ();
+
}
/// <summary>
return AttributeTargets.Delegate | AttributeTargets.ReturnValue;
}
}
+
+ protected override void VerifyObsoleteAttribute()
+ {
+ CheckUsageOfObsoleteAttribute (ret_type);
+
+ foreach (Type type in param_types) {
+ CheckUsageOfObsoleteAttribute (type);
+ }
+ }
}
//
Warning (warning, s);
}
+ /// <summary>
+ /// Tests presence of ObsoleteAttribute and report proper error
+ /// </summary>
+ protected void CheckObsoleteAttribute (Type type)
+ {
+ ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (type);
+ if (obsolete_attr == null)
+ return;
+
+ AttributeTester.Report_ObsoleteMessage (obsolete_attr, type.FullName, loc);
+ }
+
/// <summary>
/// Performs semantic analysis on the Expression
/// </summary>
return null;
}
+ ObsoleteAttribute oa;
+ FieldBase f = TypeManager.GetField (FieldInfo);
+ if (f != null) {
+ oa = f.GetObsoleteAttribute (ec.DeclSpace);
+ if (oa != null)
+ AttributeTester.Report_ObsoleteMessage (oa, f.GetSignatureForError (), loc);
+ } else {
+ oa = AttributeTester.GetMemberObsoleteAttribute (FieldInfo);
+ if (oa != null)
+ AttributeTester.Report_ObsoleteMessage (oa, TypeManager.GetFullNameSignature (FieldInfo), loc);
+ }
+
// If the instance expression is a local variable or parameter.
IVariable var = instance_expr as IVariable;
if ((var == null) || (var.VariableInfo == null))
namespace Mono.CSharp {
+ // Maybe can be usefull to derive from MemberCore
class EnumMember: Attributable {
string name;
Enum parent;
OptAttributes.Emit (ec, this);
}
+ // TODO: caching would be usefull
+ public ObsoleteAttribute GetObsoleteAttribute (EmitContext ec)
+ {
+ if (OptAttributes == null)
+ return null;
+
+ Attribute obsolete_attr = OptAttributes.Search (TypeManager.obsolete_attribute_type, ec);
+ if (obsolete_attr == null)
+ return null;
+
+ ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute (ec.DeclSpace);
+ if (obsolete == null)
+ return null;
+
+ return obsolete;
+ }
+
protected override string[] ValidAttributeTargets {
get {
return attribute_targets;
}
}
+ protected override void VerifyObsoleteAttribute()
+ {
+ // UnderlyingType is never obsolete
+ }
+
+ /// <summary>
+ /// Returns ObsoleteAttribute for both enum type and enum member
+ /// </summary>
+ public ObsoleteAttribute GetObsoleteAttribute (EmitContext ec, string identifier)
+ {
+ if ((caching_flags & Flags.Obsolete_Undetected) == 0 && (caching_flags & Flags.Obsolete) == 0) {
+ return null;
+ }
+
+ ObsoleteAttribute oa = GetObsoleteAttribute (ec.DeclSpace);
+ if (oa != null)
+ return oa;
+
+ EnumMember em = (EnumMember)name_to_member [identifier];
+ oa = em.GetObsoleteAttribute (ec);
+
+ if (oa == null)
+ return null;
+
+ caching_flags |= Flags.Obsolete;
+ return oa;
+ }
}
}
if (probe_type == null)
return null;
+ CheckObsoleteAttribute (probe_type);
+
expr = expr.Resolve (ec);
if (expr == null)
return null;
if (type == null)
return null;
+ CheckObsoleteAttribute (type);
+
eclass = ExprClass.Value;
if (expr is Constant){
return null;
}
+ CheckObsoleteAttribute (e.Type);
+
if (local_info.LocalBuilder == null)
return ec.RemapLocalLValue (local_info, right_side);
if (oa != null)
AttributeTester.Report_ObsoleteMessage (oa, TypeManager.CSharpSignature (method), loc);
+ oa = AttributeTester.GetObsoleteAttribute (method.DeclaringType);
+ if (oa != null) {
+ AttributeTester.Report_ObsoleteMessage (oa, method.DeclaringType.FullName, loc);
+ }
+
//
// This checks the `ConditionalAttribute' on the method
//
if (type == null)
return null;
+ CheckObsoleteAttribute (type);
+
bool IsDelegate = TypeManager.IsDelegateType (type);
if (IsDelegate){
return null;
}
+ CheckObsoleteAttribute (typearg);
+
type = TypeManager.type_type;
eclass = ExprClass.Type;
return this;
if (type_queried == null)
return null;
+ CheckObsoleteAttribute (type_queried);
+
if (!TypeManager.IsUnmanagedType (type_queried)){
Report.Error (208, loc, "Cannot take the size of an unmanaged type (" + TypeManager.CSharpName (type_queried) + ")");
return null;
object value = en.LookupEnumValue (ec, Identifier, loc);
if (value != null){
+ ObsoleteAttribute oa = en.GetObsoleteAttribute (ec, Identifier);
+ if (oa != null) {
+ AttributeTester.Report_ObsoleteMessage (oa, en.GetSignatureForError (), Location);
+ }
+
Constant c = Constantify (value, en.UnderlyingType);
return new EnumConstant (c, expr_type);
}
+ } else {
+ CheckObsoleteAttribute (expr_type);
+
+ FieldInfo fi = expr_type.GetField (Identifier);
+ if (fi != null) {
+ ObsoleteAttribute oa = AttributeTester.GetMemberObsoleteAttribute (fi);
+ if (oa != null)
+ AttributeTester.Report_ObsoleteMessage (oa, TypeManager.GetFullNameSignature (fi), Location);
+ }
}
}
}
return true;
}
+ protected void CheckObsolete (Type type)
+ {
+ ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (type);
+ if (obsolete_attr == null)
+ return;
+
+ AttributeTester.Report_ObsoleteMessage (obsolete_attr, type.FullName, loc);
+ }
+
/// <summary>
/// Return value indicates whether all code paths emitted return.
/// </summary>
if (expr_type == null)
return false;
+ CheckObsolete (expr_type);
+
if (ec.RemapToProxy){
Report.Error (-210, loc, "Fixed statement not allowed in iterators");
return false;
}
}
- public class Catch {
+ public class Catch: Statement {
public readonly string Name;
public readonly Block Block;
- public readonly Location Location;
Expression type_expr;
Type type;
type_expr = type;
Name = name;
Block = block;
- Location = l;
+ loc = l;
}
public Type CatchType {
}
}
- public bool Resolve (EmitContext ec)
+ protected override void DoEmit(EmitContext ec)
+ {
+ }
+
+ public override bool Resolve (EmitContext ec)
{
if (type_expr != null) {
- type = ec.DeclSpace.ResolveType (type_expr, false, Location);
+ type = ec.DeclSpace.ResolveType (type_expr, false, loc);
if (type == null)
return false;
+ CheckObsolete (type);
+
if (type != TypeManager.exception_type && !type.IsSubclassOf (TypeManager.exception_type)){
- Report.Error (155, Location,
- "The type caught or thrown must be derived " +
- "from System.Exception");
+ Error (155, "The type caught or thrown must be derived from System.Exception");
return false;
}
} else
Type resolvedType = c.CatchType;
for (int ii = 0; ii < last_index; ++ii) {
if (resolvedType.IsSubclassOf (prevCatches [ii])) {
- Report.Error_T (160, c.Location, prevCatches [ii].FullName);
+ Report.Error_T (160, c.loc, prevCatches [ii].FullName);
return false;
}
}