// attribute.cs: Attribute Handler
//
// Author: Ravi Pratap (ravi@ximian.com)
+// Marek Safar (marek.safar@seznam.cz)
//
// Licensed under the terms of the GNU GPL
//
using System.Text;
namespace Mono.CSharp {
+
/// <summary>
/// Base class for objects that can have Attributes applied to them.
/// </summary>
}
set {
attributes = value;
+ if (attributes != null)
+ attributes.CheckTargets (ValidAttributeTargets);
}
}
public abstract bool IsClsCompliaceRequired (DeclSpace ds);
/// <summary>
- /// Gets list of valid attribute targets for explicit target declaration
+ /// Gets list of valid attribute targets for explicit target declaration.
+ /// The first array item is default target. Don't break this rule.
/// </summary>
protected abstract string[] ValidAttributeTargets { get; }
};
public class Attribute {
- public readonly string Target;
+ public string Target;
public readonly string Name;
public readonly ArrayList Arguments;
return usage_attribute;
}
}
-
+
MethodImplOptions ImplOptions;
UnmanagedType UnmanagedType;
CustomAttributeBuilder cb;
FieldInfo [] field_info_arr;
object [] field_values_arr;
object [] prop_values_arr;
-
- object [] pos_values;
+ object [] pos_values;
static PtrHashtable usage_attr_cache = new PtrHashtable ();
-
+
public Attribute (string target, string name, ArrayList args, Location loc)
{
Name = name;
"expression or array creation expression");
}
- void Error_AttributeConstructorMismatch ()
- {
- Report.Error (-6, Location,
- "Could not find a constructor for this argument list.");
- }
-
static void Error_TypeParameterInAttribute (Location loc)
{
Report.Error (
-202, loc, "Can not use a type parameter in an attribute");
}
+ void Error_AttributeConstructorMismatch ()
+ {
+ Report.Error (-6, Location,
+ "Could not find a constructor for this argument list.");
+ }
+
/// <summary>
/// Tries to resolve the type of the attribute. Flags an error if it can't, and complain is true.
/// </summary>
Report.Error(1614, Location, "'" + Name + "': is ambiguous; "
+ " use either '@" + Name + "' or '" + Name + "Attribute'");
return null;
- }
-
+ }
if (t1 != null)
return t1.ResolveType (ec);
if (t2 != null)
Report.Error (616, Location, err0616);
return null;
}
+
if (complain)
- Report.Error (
- 246, Location, "Could not find attribute '" + Name + "' (are you" +
- " missing a using directive or an assembly reference ?)");
+ Report.Error (246, Location,
+ "Could not find attribute '" + Name
+ + "' (are you missing a using directive or an assembly reference ?)");
return null;
}
}
}
+ string GetFullMemberName (string member)
+ {
+ return Type.FullName + '.' + member;
+ }
+
//
// Given an expression, if the expression is a valid attribute-argument-expression
// returns an object that can be used to encode it, or null on failure.
public CustomAttributeBuilder Resolve (EmitContext ec)
{
Type oldType = Type;
-
+
// Sanity check.
Type = CheckAttributeType (ec, true);
if (oldType == null && Type == null)
ArrayList field_values = null;
ArrayList prop_values = null;
- Hashtable seen_names = new Hashtable();
-
if (named_args.Count > 0) {
field_infos = new ArrayList ();
prop_infos = new ArrayList ();
field_values = new ArrayList ();
prop_values = new ArrayList ();
}
+
+ Hashtable seen_names = new Hashtable();
for (i = 0; i < named_args.Count; i++) {
DictionaryEntry de = (DictionaryEntry) named_args [i];
if (seen_names.Contains(member_name)) {
Report.Error(643, Location, "'" + member_name + "' duplicate named attribute argument");
return null;
- }
+ }
seen_names.Add(member_name, 1);
-
+
if (!a.Resolve (ec, Location))
return null;
BindingFlags.Public | BindingFlags.Instance,
Location);
+ if (member == null) {
+ member = Expression.MemberLookup (ec, Type, member_name,
+ MemberTypes.Field | MemberTypes.Property, BindingFlags.NonPublic | BindingFlags.Instance,
+ Location);
+
+ if (member != null) {
+ Report.Error_T (122, Location, GetFullMemberName (member_name));
+ return null;
+ }
+ }
+
if (member == null || !(member is PropertyExpr || member is FieldExpr)) {
Error_InvalidNamedArgument (member_name);
return null;
return null;
}
- if (e is Constant) {
- Constant c;
-
- if (e.Type != pi.PropertyType){
- c = Const.ChangeType (Location, (Constant) e, pi.PropertyType);
+ Constant c = e as Constant;
+ if (c != null) {
+ if (c.Type != pi.PropertyType) {
+ c = Const.ChangeType (Location, c, pi.PropertyType);
if (c == null)
return null;
- } else
- c = (Constant) e;
-
+ }
+
object o = c.GetValue ();
prop_values.Add (o);
//
// Handle charset here, and set the TypeAttributes
- if (e is Constant){
- Constant c = (Constant) e;;
-
+ Constant c = e as Constant;
+ if (c != null) {
if (c.Type != fi.FieldType){
- c = Const.ChangeType (Location, (Constant) e, fi.FieldType);
+ c = Const.ChangeType (Location, c, fi.FieldType);
if (c == null)
return null;
- }
-
+ }
+
object value = c.GetValue ();
field_values.Add (value);
} else if (e is TypeOf) {
int pc = pd.Count;
if (pc > 0 && pd.ParameterModifier (pc-1) == Parameter.Modifier.PARAMS)
group_in_params_array = pc-1;
-
+
for (int j = 0; j < pos_arg_count; ++j) {
Argument a = (Argument) pos_args [j];
// class X { static void Main () {} }
//
Report.Warning (
- -23, Location,
- "The compiler can not encode this attribute in .NET due to\n" +
- "\ta bug in the .NET runtime. Try the Mono runtime.\nThe error was: " + e.Message);
+ -23, Location, "The compiler can not encode this attribute in .NET due to a bug in the .NET runtime. Try the Mono runtime. The exception was: " + e.Message);
}
return cb;
}
- /// <summary>
- /// Get a string containing a list of valid targets for the attribute 'attr'
- /// </summary>
- static string GetValidTargets (Attribute attr)
+ /// <summary>
+ /// Get a string containing a list of valid targets for the attribute 'attr'
+ /// </summary>
+ public string GetValidTargets ()
{
StringBuilder sb = new StringBuilder ();
- AttributeTargets targets = attr.GetAttributeUsage ().ValidOn;
-
+ AttributeTargets targets = GetAttributeUsage ().ValidOn;
+
if ((targets & AttributeTargets.Assembly) != 0)
sb.Append ("'assembly' ");
}
- public static void Error_AttributeNotValidForElement (Attribute a, Location loc)
- {
- Report.Error (
- 592, loc, "Attribute '" + a.Name +
- "' is not valid on this declaration type. " +
- "It is valid on " + GetValidTargets (a) + "declarations only.");
- }
-
- /// <summary>
+ /// <summary>
/// Returns AttributeUsage attribute for this type
- /// </summary>
+ /// </summary>
public AttributeUsageAttribute GetAttributeUsage ()
{
AttributeUsageAttribute ua = usage_attr_cache [Type] as AttributeUsageAttribute;
usage_attr_cache.Add (Type, ua);
return ua;
}
-
+
return attr_class.AttributeUsage;
}
- //
- // This pulls the condition name out of a Conditional attribute
- //
- public string Conditional_GetConditionName ()
+ public string IndexerName_GetIndexerName (EmitContext ec)
{
- //
- // So we have a Conditional, pull the data out.
- //
if (Arguments == null || Arguments [0] == null){
Error_AttributeConstructorMismatch ();
return null;
}
-
ArrayList pos_args = (ArrayList) Arguments [0];
- if (pos_args.Count != 1){
+ if (pos_args.Count != 1) {
Error_AttributeConstructorMismatch ();
return null;
}
-
- Argument arg = (Argument) pos_args [0];
- if (!(arg.Expr is StringConstant)){
+
+ Argument arg = (Argument) pos_args [0];
+ if (!arg.Resolve (ec, Location))
+ return null;
+
+ StringConstant sc = arg.Expr as StringConstant;
+ if (sc == null){
Error_AttributeConstructorMismatch ();
return null;
}
-
- return ((StringConstant) arg.Expr).Value;
+
+ return sc.Value;
}
- //
- // This pulls the obsolete message and error flag out of an Obsolete attribute
- //
- public string Obsolete_GetObsoleteMessage (out bool is_error)
+ /// <summary>
+ /// Returns condition of ConditionalAttribute
+ /// </summary>
+ public string GetConditionalAttributeValue (DeclSpace ds)
{
- is_error = false;
- //
- // So we have an Obsolete, pull the data out.
- //
- if (Arguments == null || Arguments [0] == null)
- return "";
+ if (pos_values == null) {
+ EmitContext ec = new EmitContext (ds, ds, Location, null, null, 0, false);
- ArrayList pos_args = (ArrayList) Arguments [0];
- if (pos_args.Count == 0)
- return "";
- else if (pos_args.Count > 2){
- Error_AttributeConstructorMismatch ();
- return null;
+ // TODO: It is not neccessary to call whole Resolve (ApplyAttribute does it now) we need only ctor args.
+ // But because a lot of attribute class code must be rewritten will be better to wait...
+ Resolve (ec);
}
- Argument arg = (Argument) pos_args [0];
- if (!(arg.Expr is StringConstant)){
- Error_AttributeConstructorMismatch ();
+ // Some error occurred
+ if (pos_values [0] == null)
return null;
- }
- if (pos_args.Count == 2){
- Argument arg2 = (Argument) pos_args [1];
- if (!(arg2.Expr is BoolConstant)){
- Error_AttributeConstructorMismatch ();
- return null;
- }
- is_error = ((BoolConstant) arg2.Expr).Value;
- }
-
- return ((StringConstant) arg.Expr).Value;
+ return (string)pos_values [0];
}
- public string IndexerName_GetIndexerName (EmitContext ec)
+ /// <summary>
+ /// Creates the instance of ObsoleteAttribute from this attribute instance
+ /// </summary>
+ public ObsoleteAttribute GetObsoleteAttribute (DeclSpace ds)
{
- if (Arguments == null || Arguments [0] == null){
- Error_AttributeConstructorMismatch ();
- return null;
- }
- ArrayList pos_args = (ArrayList) Arguments [0];
- if (pos_args.Count != 1) {
- Error_AttributeConstructorMismatch ();
- return null;
+ if (pos_values == null) {
+ EmitContext ec = new EmitContext (ds, ds, Location, null, null, 0, false);
+
+ // TODO: It is not neccessary to call whole Resolve (ApplyAttribute does it now) we need only ctor args.
+ // But because a lot of attribute class code must be rewritten will be better to wait...
+ Resolve (ec);
}
- Argument arg = (Argument) pos_args [0];
- if (!arg.Resolve (ec, Location))
+ // Some error occurred
+ if (pos_values == null)
return null;
- StringConstant sc = arg.Expr as StringConstant;
- if (sc == null){
- Error_AttributeConstructorMismatch ();
- return null;
- }
+ if (pos_values.Length == 0)
+ return new ObsoleteAttribute ();
- return sc.Value;
+ if (pos_values.Length == 1)
+ return new ObsoleteAttribute ((string)pos_values [0]);
+
+ return new ObsoleteAttribute ((string)pos_values [0], (bool)pos_values [1]);
}
- /// <summary>
- /// Returns value of CLSCompliantAttribute contructor parameter but because the method can be called
- /// before ApplyAttribute. We need to resolve the arguments.
- /// This situation occurs when class deps is differs from Emit order.
- /// </summary>
- public bool GetClsCompliantAttributeValue (DeclSpace ds)
- {
- if (pos_values == null) {
- EmitContext ec = new EmitContext (ds, ds, Location, null, null, 0, false);
+ /// <summary>
+ /// Returns value of CLSCompliantAttribute contructor parameter but because the method can be called
+ /// before ApplyAttribute. We need to resolve the arguments.
+ /// This situation occurs when class deps is differs from Emit order.
+ /// </summary>
+ public bool GetClsCompliantAttributeValue (DeclSpace ds)
+ {
+ if (pos_values == null) {
+ EmitContext ec = new EmitContext (ds, ds, Location, null, null, 0, false);
// TODO: It is not neccessary to call whole Resolve (ApplyAttribute does it now) we need only ctor args.
- // But because a lot of attribute class code must be rewritten will be better to wait...
-
- Resolve (ec);
- }
+ // But because a lot of attribute class code must be rewritten will be better to wait...
+ Resolve (ec);
+ }
// Some error occurred
- if (pos_values [0] == null)
- return false;
+ if (pos_values [0] == null)
+ return false;
return (bool)pos_values [0];
- }
+ }
public object GetPositionalValue (int i)
{
}
public UnmanagedMarshal GetMarshal ()
- {
+ {
object o = GetFieldValue ("ArraySubType");
UnmanagedType array_sub_type = o == null ? UnmanagedType.I4 : (UnmanagedType) o;
+
switch (UnmanagedType) {
case UnmanagedType.CustomMarshaler:
MethodInfo define_custom = typeof (UnmanagedMarshal).GetMethod ("DefineCustom",
BindingFlags.Static | BindingFlags.Public);
if (define_custom == null)
return null;
-
+
object [] args = new object [4];
args [0] = GetFieldValue ("MarshalTypeRef");
args [1] = GetFieldValue ("MarshalCookie");
args [2] = GetFieldValue ("MarshalType");
args [3] = Guid.Empty;
return (UnmanagedMarshal) define_custom.Invoke (null, args);
-
+
case UnmanagedType.LPArray:
return UnmanagedMarshal.DefineLPArray (array_sub_type);
-
+
case UnmanagedType.SafeArray:
return UnmanagedMarshal.DefineSafeArray (array_sub_type);
-
+
case UnmanagedType.ByValArray:
return UnmanagedMarshal.DefineByValArray ((int) GetFieldValue ("SizeConst"));
-
+
case UnmanagedType.ByValTStr:
return UnmanagedMarshal.DefineByValTStr ((int) GetFieldValue ("SizeConst"));
-
+
default:
return UnmanagedMarshal.DefineUnmanagedMarshal (UnmanagedType);
}
get { return ImplOptions == MethodImplOptions.InternalCall; }
}
- protected virtual bool CanIgnoreInvalidAttribute (Attributable ias)
- {
- return false;
- }
-
- /// <summary>
+ /// <summary>
/// Emit attribute for Attributable symbol
- /// </summary>
+ /// </summary>
public void Emit (EmitContext ec, Attributable ias, ListDictionary emitted_attr)
{
CustomAttributeBuilder cb = Resolve (ec);
- if (cb == null)
+ if (cb == null)
return;
AttributeUsageAttribute usage_attr = GetAttributeUsage ();
if ((usage_attr.ValidOn & ias.AttributeTargets) == 0) {
- // The parser applies toplevel attributes both to the assembly and
- // to a top-level class, if any. So, be silent about them.
- if (! CanIgnoreInvalidAttribute (ias))
- Error_AttributeNotValidForElement (this, Location);
+ // "Attribute '{0}' is not valid on this declaration type. It is valid on {1} declarations only.";
+ Report.Error_T (592, Location, Name, GetValidTargets ());
return;
}
ias.ApplyAttributeBuilder (this, cb);
- // Because default target is null (we save some space). We need to transform it here
- // for distinction between "default" and "doesn't exist"
- string target = Target == null ? "default" : Target;
- string emitted = emitted_attr [Type] as string;
- if (emitted == target && !usage_attr.AllowMultiple) {
+ if (!usage_attr.AllowMultiple) {
+ ArrayList emitted_targets = (ArrayList)emitted_attr [Type];
+ if (emitted_targets == null) {
+ emitted_targets = new ArrayList ();
+ emitted_attr.Add (Type, emitted_targets);
+ } else if (emitted_targets.Contains (Target)) {
Report.Error (579, Location, "Duplicate '" + Name + "' attribute");
+ return;
+ }
+ emitted_targets.Add (Target);
}
- emitted_attr [Type] = target;
-
// Here we are testing attribute arguments for array usage (error 3016)
if (ias.IsClsCompliaceRequired (ec.DeclSpace)) {
if (Arguments == null)
return;
ArrayList pos_args = (ArrayList) Arguments [0];
-
if (pos_args != null) {
foreach (Argument arg in pos_args) {
// Type is undefined (was error 246)
}
}
}
-
+
if (Arguments.Count < 2)
return;
-
+
ArrayList named_args = (ArrayList) Arguments [1];
-
foreach (DictionaryEntry de in named_args) {
Argument arg = (Argument) de.Value;
}
public object GetValue (EmitContext ec, Constant c, Type target)
- {
- if (Convert.ImplicitConversionExists (ec, c, target))
- return c.GetValue ();
+ {
+ if (Convert.ImplicitConversionExists (ec, c, target))
+ return c.GetValue ();
Convert.Error_CannotImplicitConversion (Location, c.Type, target);
- return null;
+ return null;
}
-
+
public MethodBuilder DefinePInvokeMethod (EmitContext ec, TypeBuilder builder, string name,
MethodAttributes flags, Type ret_type, Type [] param_types)
{
if (a.Expr is Constant) {
Constant c = (Constant) a.Expr;
- try {
- if (member_name == "CallingConvention"){
- object val = GetValue (ec, c, typeof (CallingConvention));
+ try {
+ if (member_name == "CallingConvention"){
+ object val = GetValue (ec, c, typeof (CallingConvention));
if (val == null)
- return null;
- cc = (CallingConvention) val;
+ return null;
+ cc = (CallingConvention) val;
} else if (member_name == "CharSet"){
charset = (CharSet) c.GetValue ();
- } else if (member_name == "EntryPoint")
+ } else if (member_name == "EntryPoint")
entry_point = (string) c.GetValue ();
else if (member_name == "SetLastError")
set_last_err = (bool) c.GetValue ();
else if (member_name == "PreserveSig")
preserve_sig = (bool) c.GetValue ();
} catch (InvalidCastException){
- Error_InvalidNamedArgument (member_name);
- Error_AttributeArgumentNotValid (Location);
- }
+ Error_InvalidNamedArgument (member_name);
+ Error_AttributeArgumentNotValid (Location);
+ }
} else {
Error_AttributeArgumentNotValid (Location);
return null;
return mb;
}
- private Expression GetValue ()
- {
- if ((Arguments == null) || (Arguments.Count < 1))
- return null;
- ArrayList al = (ArrayList) Arguments [0];
+ private Expression GetValue ()
+ {
+ if ((Arguments == null) || (Arguments.Count < 1))
+ return null;
+ ArrayList al = (ArrayList) Arguments [0];
if ((al == null) || (al.Count < 1))
- return null;
- Argument arg = (Argument) al [0];
- if ((arg == null) || (arg.Expr == null))
- return null;
- return arg.Expr;
- }
+ return null;
+ Argument arg = (Argument) al [0];
+ if ((arg == null) || (arg.Expr == null))
+ return null;
+ return arg.Expr;
+ }
public string GetString ()
- {
- Expression e = GetValue ();
- if (e is StringLiteral)
- return (e as StringLiteral).Value;
- return null;
- }
+ {
+ Expression e = GetValue ();
+ if (e is StringLiteral)
+ return (e as StringLiteral).Value;
+ return null;
+ }
public bool GetBoolean ()
- {
- Expression e = GetValue ();
- if (e is BoolLiteral)
- return (e as BoolLiteral).Value;
- return false;
- }
+ {
+ Expression e = GetValue ();
+ if (e is BoolLiteral)
+ return (e as BoolLiteral).Value;
+ return false;
+ }
}
+
+ /// <summary>
/// For global attributes (assembly, module) we need special handling.
/// Attributes can be located in the several files
/// </summary>
ec.DeclSpace.NamespaceEntry = ns;
return base.CheckAttributeType (ec, complain);
}
-
- protected override bool CanIgnoreInvalidAttribute (Attributable ias)
- {
- // Ignore error if this attribute is shared between the Assembly
- // and a top-level class. The parser couldn't figure out which entity
- // this attribute belongs to. If this attribute is erroneous, it should
- // be caught when it is processed by the top-level class.
-
- return (Target == null && ias is CommonAssemblyModulClass);
- }
}
public class Attributes {
public void CheckTargets (string[] possible_targets)
{
foreach (Attribute a in Attrs) {
- if (a.Target == null)
+ if (a.Target == null) {
+ a.Target = possible_targets [0];
continue;
+ }
if (((IList) possible_targets).Contains (a.Target))
continue;
return Search (t, ec, true);
}
+ /// <summary>
+ /// Returns all attributes of type 't'. Use it when attribute is AllowMultiple = true
+ /// </summary>
+ public Attribute[] SearchMulti (Type t, EmitContext ec)
+ {
+ ArrayList ar = null;
+
+ foreach (Attribute a in Attrs) {
+ if (a.ResolveType (ec, false) == t) {
+ if (ar == null)
+ ar = new ArrayList ();
+ ar.Add (a);
+ }
+ }
+
+ return ar == null ? null : ar.ToArray (typeof (Attribute)) as Attribute[];
+ }
+
public void Emit (EmitContext ec, Attributable ias)
{
ListDictionary ld = new ListDictionary ();
- foreach (Attribute a in Attrs) {
+ foreach (Attribute a in Attrs)
a.Emit (ec, ias, ld);
- }
}
public bool Contains (Type t, EmitContext ec)
return a.IndexerName_GetIndexerName (ec);
}
- }
+
+ }
/// <summary>
/// Helper class for attribute verification routine.
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 ();
private AttributeTester ()
{
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 if (type.IsGenericParameter || type.IsGenericInstance)
+ return null;
+ 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>
+ public static ObsoleteAttribute GetMethodObsoleteAttribute (MethodBase mb)
+ {
+ IMethodData mc = TypeManager.GetMethod (mb);
+ if (mc != null)
+ return mc.GetObsoleteAttribute ();
+
+ return GetMemberObsoleteAttribute (mb);
+ }
+
+ /// <summary>
+ /// Returns instance of ObsoleteAttribute when member is obsolete
+ /// </summary>
+ public static ObsoleteAttribute GetMemberObsoleteAttribute (MemberInfo mi)
+ {
+ object type_obsolete = analyzed_member_obsolete [mi];
+ if (type_obsolete == FALSE)
+ return null;
+
+ if (type_obsolete != null)
+ return (ObsoleteAttribute)type_obsolete;
+
+ if ((mi.DeclaringType is TypeBuilder) || mi.DeclaringType.IsGenericInstance)
+ return null;
+
+ ObsoleteAttribute oa = System.Attribute.GetCustomAttribute (mi, TypeManager.obsolete_attribute_type, false) as ObsoleteAttribute;
+ analyzed_member_obsolete.Add (mi, oa == null ? FALSE : oa);
+ return oa;
+ }
+
+ /// <summary>
+ /// Common method for Obsolete error/warning reporting.
+ /// </summary>
+ public static void Report_ObsoleteMessage (ObsoleteAttribute oa, string member, Location loc)
+ {
+ if (oa.IsError) {
+ Report.Error_T (619, loc, member, oa.Message);
+ return;
+ }
+
+ if (oa.Message == null) {
+ Report.Warning_T (612, loc, member);
+ return;
+ }
+ Report.Warning_T (618, loc, member, oa.Message);
+ }
+
+ public static bool IsConditionalMethodExcluded (MethodBase mb)
+ {
+ object excluded = analyzed_method_excluded [mb];
+ if (excluded != null)
+ return excluded == TRUE ? true : false;
+
+ if (mb.Mono_IsInflatedMethod)
+ return false;
+
+ ConditionalAttribute[] attrs = mb.GetCustomAttributes (TypeManager.conditional_attribute_type, true) as ConditionalAttribute[];
+ if (attrs.Length == 0) {
+ analyzed_method_excluded.Add (mb, FALSE);
+ return false;
+ }
+
+ foreach (ConditionalAttribute a in attrs) {
+ if (RootContext.AllDefines.Contains (a.ConditionString)) {
+ analyzed_method_excluded.Add (mb, FALSE);
+ return false;
+ }
+ }
+ analyzed_method_excluded.Add (mb, TRUE);
+ return true;
+ }
}
}