This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mcs / gmcs / attribute.cs
1 //
2 // attribute.cs: Attribute Handler
3 //
4 // Author: Ravi Pratap (ravi@ximian.com)
5 //         Marek Safar (marek.safar@seznam.cz)
6 //
7 // Licensed under the terms of the GNU GPL
8 //
9 // (C) 2001 Ximian, Inc (http://www.ximian.com)
10 //
11 //
12
13 using System;
14 using System.Diagnostics;
15 using System.Collections;
16 using System.Collections.Specialized;
17 using System.Reflection;
18 using System.Reflection.Emit;
19 using System.Runtime.InteropServices;
20 using System.Runtime.CompilerServices;
21 using System.Text;
22
23 namespace Mono.CSharp {
24
25         /// <summary>
26         ///   Base class for objects that can have Attributes applied to them.
27         /// </summary>
28         public abstract class Attributable {
29                 /// <summary>
30                 ///   Attributes for this type
31                 /// </summary>
32                 Attributes attributes;
33
34                 public Attributable(Attributes attrs)
35                 {
36                         attributes = attrs;
37                         if (attributes != null)
38                                 attributes.CheckTargets (ValidAttributeTargets);
39                 }
40
41                 public Attributes OptAttributes 
42                 {
43                         get {
44                                 return attributes;
45                         }
46                         set {
47                                 attributes = value;
48                                 if (attributes != null)
49                                         attributes.CheckTargets (ValidAttributeTargets);
50                         }
51                 }
52
53                 /// <summary>
54                 /// Use member-specific procedure to apply attribute @a in @cb to the entity being built in @builder
55                 /// </summary>
56                 public abstract void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb);
57
58                 /// <summary>
59                 /// Returns combination of enabled AttributeTargets
60                 /// </summary>
61                 public abstract AttributeTargets AttributeTargets { get; }
62
63                 public abstract bool IsClsCompliaceRequired (DeclSpace ds);
64
65                 /// <summary>
66                 /// Gets list of valid attribute targets for explicit target declaration.
67                 /// The first array item is default target. Don't break this rule.
68                 /// </summary>
69                 protected abstract string[] ValidAttributeTargets { get; }
70         };
71
72         public class Attribute {
73                 public string Target;
74                 public readonly string    Name;
75                 public readonly ArrayList Arguments;
76
77                 public readonly Location Location;
78
79                 public Type Type;
80                 
81                 // Is non-null if type is AttributeUsageAttribute
82                 AttributeUsageAttribute usage_attribute;
83
84                 public AttributeUsageAttribute UsageAttribute {
85                         get {
86                                 return usage_attribute;
87                         }
88                 }
89                 
90                 MethodImplOptions ImplOptions;
91                 UnmanagedType     UnmanagedType;
92                 CustomAttributeBuilder cb;
93         
94                 // non-null if named args present after Resolve () is called
95                 PropertyInfo [] prop_info_arr;
96                 FieldInfo [] field_info_arr;
97                 object [] field_values_arr;
98                 object [] prop_values_arr;
99                 object [] pos_values;
100
101                 static PtrHashtable usage_attr_cache = new PtrHashtable ();
102                 
103                 public Attribute (string target, string name, ArrayList args, Location loc)
104                 {
105                         Name = name;
106                         Arguments = args;
107                         Location = loc;
108                         Target = target;
109                 }
110
111                 void Error_InvalidNamedArgument (string name)
112                 {
113                         Report.Error (617, Location, "'" + name + "' is not a valid named attribute " +
114                                       "argument. Named attribute arguments must be fields which are not " +
115                                       "readonly, static or const, or properties with a set accessor which "+
116                                       "are not static.");
117                 }
118
119                 static void Error_AttributeArgumentNotValid (Location loc)
120                 {
121                         Report.Error (182, loc,
122                                       "An attribute argument must be a constant expression, typeof " +
123                                       "expression or array creation expression");
124                 }
125
126                 static void Error_TypeParameterInAttribute (Location loc)
127                 {
128                         Report.Error (
129                                 -202, loc, "Can not use a type parameter in an attribute");
130                 }
131
132                 void Error_AttributeConstructorMismatch ()
133                 {
134                         Report.Error (-6, Location,
135                                       "Could not find a constructor for this argument list.");
136                 }
137
138                 /// <summary>
139                 ///   Tries to resolve the type of the attribute. Flags an error if it can't, and complain is true.
140                 /// </summary>
141                 protected virtual Type CheckAttributeType (EmitContext ec, bool complain)
142                 {
143                         TypeExpr t1 = RootContext.LookupType (ec.DeclSpace, Name, true, Location);
144                         // FIXME: Shouldn't do this for quoted attributes: [@A]
145                         TypeExpr t2 = RootContext.LookupType (ec.DeclSpace, Name + "Attribute", true, Location);
146
147                         String err0616 = null;
148                         if (t1 != null && ! t1.IsAttribute) {
149                                 t1 = null;
150                                 err0616 = "'" + Name + "': is not an attribute class";
151                         }
152                         if (t2 != null && ! t2.IsAttribute) {
153                                 t2 = null;
154                                 err0616 = (err0616 != null) 
155                                         ? "Neither '" + Name + "' nor '" + Name + "Attribute' is an attribute class"
156                                         : "'" + Name + "Attribute': is not an attribute class";
157                         }
158
159                         if (t1 != null && t2 != null) {
160                                 Report.Error(1614, Location, "'" + Name + "': is ambiguous; " 
161                                              + " use either '@" + Name + "' or '" + Name + "Attribute'");
162                                 return null;
163                         }
164                         if (t1 != null)
165                                 return t1.ResolveType (ec);
166                         if (t2 != null)
167                                 return t2.ResolveType (ec);
168                         if (err0616 != null) {
169                                 Report.Error (616, Location, err0616);
170                                 return null;
171                         }
172
173                         if (complain)
174                                 Report.Error (246, Location, 
175                                               "Could not find attribute '" + Name 
176                                               + "' (are you missing a using directive or an assembly reference ?)");
177                         return null;
178                 }
179
180                 public Type ResolveType (EmitContext ec, bool complain)
181                 {
182                         if (Type == null)
183                                 Type = CheckAttributeType (ec, complain);
184                         return Type;
185                 }
186
187                 /// <summary>
188                 ///   Validates the guid string
189                 /// </summary>
190                 bool ValidateGuid (string guid)
191                 {
192                         try {
193                                 new Guid (guid);
194                                 return true;
195                         } catch {
196                                 Report.Error (647, Location, "Format of GUID is invalid: " + guid);
197                                 return false;
198                         }
199                 }
200
201                 string GetFullMemberName (string member)
202                 {
203                         return Type.FullName + '.' + member;
204                 }
205
206                 //
207                 // Given an expression, if the expression is a valid attribute-argument-expression
208                 // returns an object that can be used to encode it, or null on failure.
209                 //
210                 public static bool GetAttributeArgumentExpression (Expression e, Location loc, out object result)
211                 {
212                         if (e is Constant) {
213                                 result = ((Constant) e).GetValue ();
214                                 return true;
215                         } else if (e is TypeOf) {
216                                 result = ((TypeOf) e).TypeArg;
217                                 return true;
218                         } else if (e is ArrayCreation){
219                                 result =  ((ArrayCreation) e).EncodeAsAttribute ();
220                                 if (result != null)
221                                         return true;
222                         } else if (e is EmptyCast) {
223                                 result = e;
224                                 if (((EmptyCast) e).Child is Constant) {
225                                         result = ((Constant) ((EmptyCast)e).Child).GetValue();
226                                 }
227                                 return true;
228                         }
229
230                         result = null;
231                         Error_AttributeArgumentNotValid (loc);
232                         return false;
233                 }
234                 
235                 public CustomAttributeBuilder Resolve (EmitContext ec)
236                 {
237                         Type oldType = Type;
238                         
239                         // Sanity check.
240                         Type = CheckAttributeType (ec, true);
241                         if (oldType == null && Type == null)
242                                 return null;
243                         if (oldType != null && oldType != Type) {
244                                 Report.Error (-6, Location,
245                                               "Attribute {0} resolved to different types at different times: {1} vs. {2}",
246                                               Name, oldType, Type);
247                                 return null;
248                         }
249
250                         bool MethodImplAttr = false;
251                         bool MarshalAsAttr = false;
252                         bool GuidAttr = false;
253                         bool usage_attr = false;
254
255                         bool DoCompares = true;
256
257                         //
258                         // If we are a certain special attribute, we
259                         // set the information accordingly
260                         //
261                         
262                         if (Type == TypeManager.attribute_usage_type)
263                                 usage_attr = true;
264                         else if (Type == TypeManager.methodimpl_attr_type)
265                                 MethodImplAttr = true;
266                         else if (Type == TypeManager.marshal_as_attr_type)
267                                 MarshalAsAttr = true;
268                         else if (Type == TypeManager.guid_attr_type)
269                                 GuidAttr = true;
270                         else
271                                 DoCompares = false;
272
273                         // Now we extract the positional and named arguments
274                         
275                         ArrayList pos_args = new ArrayList ();
276                         ArrayList named_args = new ArrayList ();
277                         int pos_arg_count = 0;
278                         
279                         if (Arguments != null) {
280                                 pos_args = (ArrayList) Arguments [0];
281                                 if (pos_args != null)
282                                         pos_arg_count = pos_args.Count;
283                                 if (Arguments.Count > 1)
284                                         named_args = (ArrayList) Arguments [1];
285                         }
286
287                         pos_values = new object [pos_arg_count];
288
289                         //
290                         // First process positional arguments 
291                         //
292
293                         int i;
294                         for (i = 0; i < pos_arg_count; i++) {
295                                 Argument a = (Argument) pos_args [i];
296                                 Expression e;
297
298                                 if (!a.Resolve (ec, Location))
299                                         return null;
300
301                                 e = a.Expr;
302
303                                 object val;
304                                 if (!GetAttributeArgumentExpression (e, Location, out val))
305                                         return null;
306                                 
307                                 pos_values [i] = val;
308                                 if (DoCompares){
309                                         if (usage_attr)
310                                                 usage_attribute = new AttributeUsageAttribute ((AttributeTargets) pos_values [0]);
311                                         else if (MethodImplAttr)
312                                                 this.ImplOptions = (MethodImplOptions) pos_values [0];
313                                         else if (GuidAttr){
314                                                 //
315                                                 // we will later check the validity of the type
316                                                 //
317                                                 if (pos_values [0] is string){
318                                                         if (!ValidateGuid ((string) pos_values [0]))
319                                                                 return null;
320                                                 }
321                                                 
322                                         } else if (MarshalAsAttr)
323                                                 this.UnmanagedType =
324                                                 (System.Runtime.InteropServices.UnmanagedType) pos_values [0];
325                                 }
326                         }
327
328                         //
329                         // Now process named arguments
330                         //
331
332                         ArrayList field_infos = null;
333                         ArrayList prop_infos  = null;
334                         ArrayList field_values = null;
335                         ArrayList prop_values = null;
336
337                         if (named_args.Count > 0) {
338                                 field_infos = new ArrayList ();
339                                 prop_infos  = new ArrayList ();
340                                 field_values = new ArrayList ();
341                                 prop_values = new ArrayList ();
342                         }
343
344                         Hashtable seen_names = new Hashtable();
345                         
346                         for (i = 0; i < named_args.Count; i++) {
347                                 DictionaryEntry de = (DictionaryEntry) named_args [i];
348                                 string member_name = (string) de.Key;
349                                 Argument a  = (Argument) de.Value;
350                                 Expression e;
351
352                                 if (seen_names.Contains(member_name)) {
353                                         Report.Error(643, Location, "'" + member_name + "' duplicate named attribute argument");
354                                         return null;
355                                 }                               
356                                 seen_names.Add(member_name, 1);
357                                 
358                                 if (!a.Resolve (ec, Location))
359                                         return null;
360
361                                 Expression member = Expression.MemberLookup (
362                                         ec, Type, member_name,
363                                         MemberTypes.Field | MemberTypes.Property,
364                                         BindingFlags.Public | BindingFlags.Instance,
365                                         Location);
366
367                                 if (member == null) {
368                                         member = Expression.MemberLookup (ec, Type, member_name,
369                                                 MemberTypes.Field | MemberTypes.Property, BindingFlags.NonPublic | BindingFlags.Instance,
370                                                 Location);
371
372                                         if (member != null) {
373                                                 Report.Error_T (122, Location, GetFullMemberName (member_name));
374                                                 return null;
375                                         }
376                                 }
377
378                                 if (member == null || !(member is PropertyExpr || member is FieldExpr)) {
379                                         Error_InvalidNamedArgument (member_name);
380                                         return null;
381                                 }
382
383                                 e = a.Expr;
384                                 if (e is TypeParameterExpr){
385                                         Error_TypeParameterInAttribute (Location);
386                                         return null;
387                                 }
388                                         
389                                 if (member is PropertyExpr) {
390                                         PropertyExpr pe = (PropertyExpr) member;
391                                         PropertyInfo pi = pe.PropertyInfo;
392
393                                         if (!pi.CanWrite) {
394                                                 Error_InvalidNamedArgument (member_name);
395                                                 return null;
396                                         }
397
398                                         Constant c = e as Constant;
399                                         if (c != null) {
400                                                 if (c.Type != pi.PropertyType) {
401                                                         c = Const.ChangeType (Location, c, pi.PropertyType);
402                                                         if (c == null)
403                                                                 return null;
404                                                 }
405                                                 
406                                                 object o = c.GetValue ();
407                                                 prop_values.Add (o);
408                                                 
409                                                 if (usage_attribute != null) {
410                                                         if (member_name == "AllowMultiple")
411                                                                 usage_attribute.AllowMultiple = (bool) o;
412                                                         if (member_name == "Inherited")
413                                                                 usage_attribute.Inherited = (bool) o;
414                                                 }
415                                                 
416                                         } else if (e is TypeOf) {
417                                                 prop_values.Add (((TypeOf) e).TypeArg);
418                                         } else if (e is ArrayCreation) {
419                                                 prop_values.Add (((ArrayCreation) e).EncodeAsAttribute());
420                                         } else {
421                                                 Error_AttributeArgumentNotValid (Location);
422                                                 return null;
423                                         }
424                                         
425                                         prop_infos.Add (pi);
426                                         
427                                 } else if (member is FieldExpr) {
428                                         FieldExpr fe = (FieldExpr) member;
429                                         FieldInfo fi = fe.FieldInfo;
430
431                                         if (fi.IsInitOnly) {
432                                                 Error_InvalidNamedArgument (member_name);
433                                                 return null;
434                                         }
435
436                                         //
437                                         // Handle charset here, and set the TypeAttributes
438                                         
439                                         Constant c = e as Constant;
440                                         if (c != null) {
441                                                 if (c.Type != fi.FieldType){
442                                                         c = Const.ChangeType (Location, c, fi.FieldType);
443                                                         if (c == null)
444                                                                 return null;
445                                                 } 
446                                                 
447                                                 object value = c.GetValue ();
448                                                 field_values.Add (value);
449                                         } else if (e is TypeOf) {
450                                                 field_values.Add (((TypeOf) e).TypeArg);
451                                         } else {
452                                                 Error_AttributeArgumentNotValid (Location);
453                                                 return null;
454                                         }
455                                         
456                                         field_infos.Add (fi);
457                                 }
458                         }
459
460                         Expression mg = Expression.MemberLookup (
461                                 ec, Type, ".ctor", MemberTypes.Constructor,
462                                 BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
463                                 Location);
464
465                         if (mg == null) {
466                                 Error_AttributeConstructorMismatch ();
467                                 return null;
468                         }
469
470                         MethodBase constructor = Invocation.OverloadResolve (
471                                 ec, (MethodGroupExpr) mg, pos_args, false, Location);
472
473                         if (constructor == null) {
474                                 Error_AttributeConstructorMismatch ();
475                                 return null;
476                         }
477
478                         //
479                         // Now we perform some checks on the positional args as they
480                         // cannot be null for a constructor which expects a parameter
481                         // of type object
482                         //
483
484                         ParameterData pd = Invocation.GetParameterData (constructor);
485
486                         int group_in_params_array = Int32.MaxValue;
487                         int pc = pd.Count;
488                         if (pc > 0 && pd.ParameterModifier (pc-1) == Parameter.Modifier.PARAMS)
489                                 group_in_params_array = pc-1;
490
491                         for (int j = 0; j < pos_arg_count; ++j) {
492                                 Argument a = (Argument) pos_args [j];
493                                 
494                                 if (a.Expr is NullLiteral && pd.ParameterType (j) == TypeManager.object_type) {
495                                         Error_AttributeArgumentNotValid (Location);
496                                         return null;
497                                 }
498
499                                 if (j < group_in_params_array)
500                                         continue;
501                                 
502                                 if (j == group_in_params_array){
503                                         object v = pos_values [j];
504                                         int count = pos_arg_count - j;
505
506                                         object [] array = new object [count];
507                                         pos_values [j] = array;
508                                         array [0] = v;
509                                 } else {
510                                         object [] array = (object []) pos_values [group_in_params_array];
511
512                                         array [j - group_in_params_array] = pos_values [j];
513                                 }
514                         }
515
516                         //
517                         // Adjust the size of the pos_values if it had params
518                         //
519                         if (group_in_params_array != Int32.MaxValue){
520                                 int argc = group_in_params_array+1;
521                                 object [] new_pos_values = new object [argc];
522
523                                 for (int p = 0; p < argc; p++)
524                                         new_pos_values [p] = pos_values [p];
525                                 pos_values = new_pos_values;
526                         }
527
528                         try {
529                                 if (named_args.Count > 0) {
530                                         prop_info_arr = new PropertyInfo [prop_infos.Count];
531                                         field_info_arr = new FieldInfo [field_infos.Count];
532                                         field_values_arr = new object [field_values.Count];
533                                         prop_values_arr = new object [prop_values.Count];
534
535                                         field_infos.CopyTo  (field_info_arr, 0);
536                                         field_values.CopyTo (field_values_arr, 0);
537
538                                         prop_values.CopyTo  (prop_values_arr, 0);
539                                         prop_infos.CopyTo   (prop_info_arr, 0);
540
541                                         cb = new CustomAttributeBuilder (
542                                                 (ConstructorInfo) constructor, pos_values,
543                                                 prop_info_arr, prop_values_arr,
544                                                 field_info_arr, field_values_arr);
545                                 }
546                                 else
547                                         cb = new CustomAttributeBuilder (
548                                                 (ConstructorInfo) constructor, pos_values);
549                         } catch (NullReferenceException) {
550                                 // 
551                                 // Don't know what to do here
552                                 //
553                                 Report.Warning (
554                                         -101, Location, "NullReferenceException while trying to create attribute." +
555                                         "Something's wrong!");
556                         } catch (Exception e) {
557                                 //
558                                 // Sample:
559                                 // using System.ComponentModel;
560                                 // [DefaultValue (CollectionChangeAction.Add)]
561                                 // class X { static void Main () {} }
562                                 //
563                                 Report.Warning (
564                                         -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);
565                         }
566                         
567                         return cb;
568                 }
569
570                 /// <summary>
571                 ///   Get a string containing a list of valid targets for the attribute 'attr'
572                 /// </summary>
573                 public string GetValidTargets ()
574                 {
575                         StringBuilder sb = new StringBuilder ();
576                         AttributeTargets targets = GetAttributeUsage ().ValidOn;
577
578                         if ((targets & AttributeTargets.Assembly) != 0)
579                                 sb.Append ("'assembly' ");
580
581                         if ((targets & AttributeTargets.Class) != 0)
582                                 sb.Append ("'class' ");
583
584                         if ((targets & AttributeTargets.Constructor) != 0)
585                                 sb.Append ("'constructor' ");
586
587                         if ((targets & AttributeTargets.Delegate) != 0)
588                                 sb.Append ("'delegate' ");
589
590                         if ((targets & AttributeTargets.Enum) != 0)
591                                 sb.Append ("'enum' ");
592
593                         if ((targets & AttributeTargets.Event) != 0)
594                                 sb.Append ("'event' ");
595
596                         if ((targets & AttributeTargets.Field) != 0)
597                                 sb.Append ("'field' ");
598
599                         if ((targets & AttributeTargets.Interface) != 0)
600                                 sb.Append ("'interface' ");
601
602                         if ((targets & AttributeTargets.Method) != 0)
603                                 sb.Append ("'method' ");
604
605                         if ((targets & AttributeTargets.Module) != 0)
606                                 sb.Append ("'module' ");
607
608                         if ((targets & AttributeTargets.Parameter) != 0)
609                                 sb.Append ("'parameter' ");
610
611                         if ((targets & AttributeTargets.Property) != 0)
612                                 sb.Append ("'property' ");
613
614                         if ((targets & AttributeTargets.ReturnValue) != 0)
615                                 sb.Append ("'return' ");
616
617                         if ((targets & AttributeTargets.Struct) != 0)
618                                 sb.Append ("'struct' ");
619
620                         return sb.ToString ();
621
622                 }
623
624                 /// <summary>
625                 /// Returns AttributeUsage attribute for this type
626                 /// </summary>
627                 public AttributeUsageAttribute GetAttributeUsage ()
628                 {
629                         AttributeUsageAttribute ua = usage_attr_cache [Type] as AttributeUsageAttribute;
630                         if (ua != null)
631                                 return ua;
632
633                         Class attr_class = TypeManager.LookupClass (Type);
634
635                         if (attr_class == null) {
636                                 object[] usage_attr = Type.GetCustomAttributes (TypeManager.attribute_usage_type, true);
637                                 ua = (AttributeUsageAttribute)usage_attr [0];
638                                 usage_attr_cache.Add (Type, ua);
639                                 return ua;
640                         }
641                 
642                         return attr_class.AttributeUsage;
643                 }
644
645                 public string IndexerName_GetIndexerName (EmitContext ec)
646                 {
647                         if (Arguments == null || Arguments [0] == null){
648                                 Error_AttributeConstructorMismatch ();
649                                 return null;
650                         }
651                         ArrayList pos_args = (ArrayList) Arguments [0];
652                         if (pos_args.Count != 1) {
653                                 Error_AttributeConstructorMismatch ();
654                                 return null;
655                         }
656                         
657                         Argument arg = (Argument) pos_args [0];
658                         if (!arg.Resolve (ec, Location))
659                                 return null;
660                         
661                         StringConstant sc = arg.Expr as StringConstant;
662                         if (sc == null){
663                                 Error_AttributeConstructorMismatch ();
664                                 return null;
665                         }
666                         
667                         return sc.Value;
668                 }
669
670                 /// <summary>
671                 /// Returns condition of ConditionalAttribute
672                 /// </summary>
673                 public string GetConditionalAttributeValue (DeclSpace ds)
674                 {
675                         if (pos_values == null) {
676                                 EmitContext ec = new EmitContext (ds, ds, Location, null, null, 0, false);
677
678                                 // TODO: It is not neccessary to call whole Resolve (ApplyAttribute does it now) we need only ctor args.
679                                 // But because a lot of attribute class code must be rewritten will be better to wait...
680                                 Resolve (ec);
681                         }
682
683                         // Some error occurred
684                         if (pos_values [0] == null)
685                                 return null;
686
687                         return (string)pos_values [0];
688                 }
689
690                 /// <summary>
691                 /// Creates the instance of ObsoleteAttribute from this attribute instance
692                 /// </summary>
693                 public ObsoleteAttribute GetObsoleteAttribute (DeclSpace ds)
694                 {
695                         if (pos_values == null) {
696                                 EmitContext ec = new EmitContext (ds, ds, Location, null, null, 0, false);
697
698                                 // TODO: It is not neccessary to call whole Resolve (ApplyAttribute does it now) we need only ctor args.
699                                 // But because a lot of attribute class code must be rewritten will be better to wait...
700                                 Resolve (ec);
701                         }
702
703                         // Some error occurred
704                         if (pos_values == null)
705                                 return null;
706
707                         if (pos_values.Length == 0)
708                                 return new ObsoleteAttribute ();
709
710                         if (pos_values.Length == 1)
711                                 return new ObsoleteAttribute ((string)pos_values [0]);
712
713                         return new ObsoleteAttribute ((string)pos_values [0], (bool)pos_values [1]);
714                 }
715
716                 /// <summary>
717                 /// Returns value of CLSCompliantAttribute contructor parameter but because the method can be called
718                 /// before ApplyAttribute. We need to resolve the arguments.
719                 /// This situation occurs when class deps is differs from Emit order.  
720                 /// </summary>
721                 public bool GetClsCompliantAttributeValue (DeclSpace ds)
722                 {
723                         if (pos_values == null) {
724                                 EmitContext ec = new EmitContext (ds, ds, Location, null, null, 0, false);
725
726                                 // TODO: It is not neccessary to call whole Resolve (ApplyAttribute does it now) we need only ctor args.
727                                 // But because a lot of attribute class code must be rewritten will be better to wait...
728                                 Resolve (ec);
729                         }
730
731                         // Some error occurred
732                         if (pos_values [0] == null)
733                                 return false;
734
735                         return (bool)pos_values [0];
736                 }
737
738                 public object GetPositionalValue (int i)
739                 {
740                         return (pos_values == null) ? null : pos_values[i];
741                 }
742
743                 object GetFieldValue (string name)
744                 {
745                         int i;
746                         if (field_info_arr == null)
747                                 return null;
748                         i = 0;
749                         foreach (FieldInfo fi in field_info_arr) {
750                                 if (fi.Name == name)
751                                         return field_values_arr [i];
752                                 i++;
753                         }
754                         return null;
755                 }
756
757                 public UnmanagedMarshal GetMarshal ()
758                 {
759                         object o = GetFieldValue ("ArraySubType");
760                         UnmanagedType array_sub_type = o == null ? UnmanagedType.I4 : (UnmanagedType) o;
761                         
762                         switch (UnmanagedType) {
763                         case UnmanagedType.CustomMarshaler:
764                                 MethodInfo define_custom = typeof (UnmanagedMarshal).GetMethod ("DefineCustom",
765                                                                        BindingFlags.Static | BindingFlags.Public);
766                                 if (define_custom == null)
767                                         return null;
768                                 
769                                 object [] args = new object [4];
770                                 args [0] = GetFieldValue ("MarshalTypeRef");
771                                 args [1] = GetFieldValue ("MarshalCookie");
772                                 args [2] = GetFieldValue ("MarshalType");
773                                 args [3] = Guid.Empty;
774                                 return (UnmanagedMarshal) define_custom.Invoke (null, args);
775                                 
776                         case UnmanagedType.LPArray:                             
777                                 return UnmanagedMarshal.DefineLPArray (array_sub_type);
778                         
779                         case UnmanagedType.SafeArray:
780                                 return UnmanagedMarshal.DefineSafeArray (array_sub_type);
781                         
782                         case UnmanagedType.ByValArray:
783                                 return UnmanagedMarshal.DefineByValArray ((int) GetFieldValue ("SizeConst"));
784                         
785                         case UnmanagedType.ByValTStr:
786                                 return UnmanagedMarshal.DefineByValTStr ((int) GetFieldValue ("SizeConst"));
787                         
788                         default:
789                                 return UnmanagedMarshal.DefineUnmanagedMarshal (UnmanagedType);
790                         }
791                 }
792
793                 public bool IsInternalCall
794                 {
795                         get { return ImplOptions == MethodImplOptions.InternalCall; }
796                 }
797
798                 /// <summary>
799                 /// Emit attribute for Attributable symbol
800                 /// </summary>
801                 public void Emit (EmitContext ec, Attributable ias, ListDictionary emitted_attr)
802                 {
803                         CustomAttributeBuilder cb = Resolve (ec);
804                         if (cb == null)
805                                 return;
806
807                         AttributeUsageAttribute usage_attr = GetAttributeUsage ();
808                         if ((usage_attr.ValidOn & ias.AttributeTargets) == 0) {
809                                 // "Attribute '{0}' is not valid on this declaration type. It is valid on {1} declarations only.";
810                                 Report.Error_T (592, Location, Name, GetValidTargets ());
811                                 return;
812                         }
813
814                         ias.ApplyAttributeBuilder (this, cb);
815
816                         if (!usage_attr.AllowMultiple) {
817                                 ArrayList emitted_targets = (ArrayList)emitted_attr [Type];
818                                 if (emitted_targets == null) {
819                                         emitted_targets = new ArrayList ();
820                                         emitted_attr.Add (Type, emitted_targets);
821                                 } else if (emitted_targets.Contains (Target)) {
822                                 Report.Error (579, Location, "Duplicate '" + Name + "' attribute");
823                                         return;
824                                 }
825                                 emitted_targets.Add (Target);
826                         }
827
828                         // Here we are testing attribute arguments for array usage (error 3016)
829                         if (ias.IsClsCompliaceRequired (ec.DeclSpace)) {
830                                 if (Arguments == null)
831                                         return;
832
833                                 ArrayList pos_args = (ArrayList) Arguments [0];
834                                 if (pos_args != null) {
835                                         foreach (Argument arg in pos_args) { 
836                                                 // Type is undefined (was error 246)
837                                                 if (arg.Type == null)
838                                                         return;
839
840                                                 if (arg.Type.IsArray) {
841                                                         Report.Error_T (3016, Location);
842                                                         return;
843                                                 }
844                                         }
845                                 }
846                         
847                                 if (Arguments.Count < 2)
848                                         return;
849                         
850                                 ArrayList named_args = (ArrayList) Arguments [1];
851                                 foreach (DictionaryEntry de in named_args) {
852                                         Argument arg  = (Argument) de.Value;
853
854                                         // Type is undefined (was error 246)
855                                         if (arg.Type == null)
856                                                 return;
857
858                                         if (arg.Type.IsArray) {
859                                                 Report.Error_T (3016, Location);
860                                                 return;
861                                         }
862                                 }
863                         }
864                 }
865
866                 public object GetValue (EmitContext ec, Constant c, Type target)
867                 {
868                         if (Convert.ImplicitConversionExists (ec, c, target))
869                                 return c.GetValue ();
870
871                         Convert.Error_CannotImplicitConversion (Location, c.Type, target);
872                         return null;
873                 }
874                 
875                 public MethodBuilder DefinePInvokeMethod (EmitContext ec, TypeBuilder builder, string name,
876                                                           MethodAttributes flags, Type ret_type, Type [] param_types)
877                 {
878                         //
879                         // We extract from the attribute the information we need 
880                         //
881
882                         if (Arguments == null) {
883                                 Console.WriteLine ("Internal error : this is not supposed to happen !");
884                                 return null;
885                         }
886
887                         ResolveType (ec, true);
888                         if (Type == null)
889                                 return null;
890                         
891                         ArrayList named_args = new ArrayList ();
892                         
893                         ArrayList pos_args = (ArrayList) Arguments [0];
894                         if (Arguments.Count > 1)
895                                 named_args = (ArrayList) Arguments [1];
896                         
897
898                         string dll_name = null;
899                         
900                         Argument tmp = (Argument) pos_args [0];
901
902                         if (!tmp.Resolve (ec, Location))
903                                 return null;
904                         
905                         if (tmp.Expr is Constant)
906                                 dll_name = (string) ((Constant) tmp.Expr).GetValue ();
907                         else { 
908                                 Error_AttributeArgumentNotValid (Location);
909                                 return null;
910                         }
911
912                         // Now we process the named arguments
913                         CallingConvention cc = CallingConvention.Winapi;
914                         CharSet charset = CharSet.Ansi;
915                         bool preserve_sig = true;
916 #if FIXME
917                         bool exact_spelling = false;
918 #endif
919                         bool set_last_err = false;
920                         string entry_point = null;
921
922                         for (int i = 0; i < named_args.Count; i++) {
923
924                                 DictionaryEntry de = (DictionaryEntry) named_args [i];
925
926                                 string member_name = (string) de.Key;
927                                 Argument a  = (Argument) de.Value;
928
929                                 if (!a.Resolve (ec, Location))
930                                         return null;
931
932                                 Expression member = Expression.MemberLookup (
933                                         ec, Type, member_name, 
934                                         MemberTypes.Field | MemberTypes.Property,
935                                         BindingFlags.Public | BindingFlags.Instance,
936                                         Location);
937
938                                 if (member == null || !(member is FieldExpr)) {
939                                         Error_InvalidNamedArgument (member_name);
940                                         return null;
941                                 }
942
943                                 if (member is FieldExpr) {
944                                         FieldExpr fe = (FieldExpr) member;
945                                         FieldInfo fi = fe.FieldInfo;
946
947                                         if (fi.IsInitOnly) {
948                                                 Error_InvalidNamedArgument (member_name);
949                                                 return null;
950                                         }
951
952                                         if (a.Expr is Constant) {
953                                                 Constant c = (Constant) a.Expr;
954
955                                                 try {
956                                                         if (member_name == "CallingConvention"){
957                                                                 object val = GetValue (ec, c, typeof (CallingConvention));
958                                                                 if (val == null)
959                                                                         return null;
960                                                                 cc = (CallingConvention) val;
961                                                         } else if (member_name == "CharSet"){
962                                                                 charset = (CharSet) c.GetValue ();
963                                                         } else if (member_name == "EntryPoint")
964                                                                 entry_point = (string) c.GetValue ();
965                                                         else if (member_name == "SetLastError")
966                                                                 set_last_err = (bool) c.GetValue ();
967 #if FIXME
968                                                         else if (member_name == "ExactSpelling")
969                                                                 exact_spelling = (bool) c.GetValue ();
970 #endif
971                                                         else if (member_name == "PreserveSig")
972                                                                 preserve_sig = (bool) c.GetValue ();
973                                                 } catch (InvalidCastException){
974                                                         Error_InvalidNamedArgument (member_name);
975                                                         Error_AttributeArgumentNotValid (Location);
976                                                 }
977                                         } else { 
978                                                 Error_AttributeArgumentNotValid (Location);
979                                                 return null;
980                                         }
981                                         
982                                 }
983                         }
984
985                         if (entry_point == null)
986                                 entry_point = name;
987                         if (set_last_err)
988                                 charset = (CharSet)((int)charset | 0x40);
989                         
990                         MethodBuilder mb = builder.DefinePInvokeMethod (
991                                 name, dll_name, entry_point, flags | MethodAttributes.HideBySig,
992                                 CallingConventions.Standard,
993                                 ret_type,
994                                 param_types,
995                                 cc,
996                                 charset);
997
998                         if (preserve_sig)
999                                 mb.SetImplementationFlags (MethodImplAttributes.PreserveSig);
1000                         
1001                         return mb;
1002                 }
1003
1004                 private Expression GetValue () 
1005                 {
1006                         if ((Arguments == null) || (Arguments.Count < 1))
1007                                 return null;
1008                         ArrayList al = (ArrayList) Arguments [0];
1009                         if ((al == null) || (al.Count < 1))
1010                                 return null;
1011                         Argument arg = (Argument) al [0];
1012                         if ((arg == null) || (arg.Expr == null))
1013                                 return null;
1014                         return arg.Expr;
1015                 }
1016
1017                 public string GetString () 
1018                 {
1019                         Expression e = GetValue ();
1020                         if (e is StringLiteral)
1021                                 return (e as StringLiteral).Value;
1022                         return null;
1023                 }
1024
1025                 public bool GetBoolean () 
1026                 {
1027                         Expression e = GetValue ();
1028                         if (e is BoolLiteral)
1029                                 return (e as BoolLiteral).Value;
1030                         return false;
1031                 }
1032         }
1033         
1034
1035         /// <summary>
1036         /// For global attributes (assembly, module) we need special handling.
1037         /// Attributes can be located in the several files
1038         /// </summary>
1039         public class GlobalAttribute: Attribute
1040         {
1041                 public readonly NamespaceEntry ns;
1042
1043                 public GlobalAttribute (TypeContainer container, string target, string name, ArrayList args, Location loc):
1044                         base (target, name, args, loc)
1045                 {
1046                         ns = container.NamespaceEntry;
1047                 }
1048
1049                 protected override Type CheckAttributeType (EmitContext ec, bool complain)
1050                 {
1051                         NamespaceEntry old = ec.DeclSpace.NamespaceEntry;
1052                         if (old == null || old.NS == null || old.NS == Namespace.Root) 
1053                                 ec.DeclSpace.NamespaceEntry = ns;
1054                         return base.CheckAttributeType (ec, complain);
1055                 }
1056         }
1057
1058         public class Attributes {
1059                 public ArrayList Attrs;
1060
1061                 public Attributes (Attribute a)
1062                 {
1063                         Attrs = new ArrayList ();
1064                         Attrs.Add (a);
1065                 }
1066
1067                 public Attributes (ArrayList attrs)
1068                 {
1069                         Attrs = attrs;
1070                 }
1071
1072                 public void AddAttributes (ArrayList attrs)
1073                 {
1074                         Attrs.AddRange (attrs);
1075                 }
1076
1077                 /// <summary>
1078                 /// Checks whether attribute target is valid for the current element
1079                 /// </summary>
1080                 public void CheckTargets (string[] possible_targets)
1081                 {
1082                         foreach (Attribute a in Attrs) {
1083                                 if (a.Target == null) {
1084                                         a.Target = possible_targets [0];
1085                                         continue;
1086                                 }
1087
1088                                 if (((IList) possible_targets).Contains (a.Target))
1089                                         continue;
1090
1091                                 StringBuilder sb = new StringBuilder ();
1092                                 foreach (string s in possible_targets) {
1093                                         sb.Append (s);
1094                                         sb.Append (", ");
1095                                 }
1096                                 sb.Remove (sb.Length - 2, 2);
1097                                 Report.Error_T (657, a.Location, a.Target, sb.ToString ());
1098                         }
1099                 }
1100
1101                 private Attribute Search (Type t, EmitContext ec, bool complain)
1102                 {
1103                         foreach (Attribute a in Attrs) {
1104                                 if (a.ResolveType (ec, false) == t)
1105                                         return a;
1106                         }
1107                         return null;
1108                 }
1109
1110                 public Attribute Search (Type t, EmitContext ec)
1111                 {
1112                         return Search (t, ec, true);
1113                 }
1114
1115                 /// <summary>
1116                 /// Returns all attributes of type 't'. Use it when attribute is AllowMultiple = true
1117                 /// </summary>
1118                 public Attribute[] SearchMulti (Type t, EmitContext ec)
1119                 {
1120                         ArrayList ar = null;
1121
1122                         foreach (Attribute a in Attrs) {
1123                                 if (a.ResolveType (ec, false) == t) {
1124                                         if (ar == null)
1125                                                 ar = new ArrayList ();
1126                                         ar.Add (a);
1127                                 }
1128                         }
1129
1130                         return ar == null ? null : ar.ToArray (typeof (Attribute)) as Attribute[];
1131                 }
1132
1133                 public void Emit (EmitContext ec, Attributable ias)
1134                 {
1135                         ListDictionary ld = new ListDictionary ();
1136
1137                         foreach (Attribute a in Attrs)
1138                                 a.Emit (ec, ias, ld);
1139                 }
1140
1141                 public bool Contains (Type t, EmitContext ec)
1142                 {
1143                         return Search (t, ec) != null;
1144                 }
1145
1146                 public Attribute GetClsCompliantAttribute (EmitContext ec)
1147                 {
1148                         return Search (TypeManager.cls_compliant_attribute_type, ec, false);
1149                 }
1150
1151                 /// <summary>
1152                 /// Pulls the IndexerName attribute from an Indexer if it exists.
1153                 /// </summary>
1154                 public string ScanForIndexerName (EmitContext ec)
1155                 {
1156                         Attribute a = Search (TypeManager.indexer_name_type, ec);
1157                         if (a == null)
1158                                 return null;
1159
1160                         // Remove the attribute from the list
1161                         //TODO: It is very close to hack and it can crash here
1162                         Attrs.Remove (a);
1163
1164                         return a.IndexerName_GetIndexerName (ec);
1165                 }
1166
1167         }
1168
1169         /// <summary>
1170         /// Helper class for attribute verification routine.
1171         /// </summary>
1172         sealed class AttributeTester
1173         {
1174                 static PtrHashtable analyzed_types = new PtrHashtable ();
1175                 static PtrHashtable analyzed_types_obsolete = new PtrHashtable ();
1176                 static PtrHashtable analyzed_member_obsolete = new PtrHashtable ();
1177                 static PtrHashtable analyzed_method_excluded = new PtrHashtable ();
1178
1179                 private AttributeTester ()
1180                 {
1181                 }
1182
1183                 /// <summary>
1184                 /// Returns true if parameters of two compared methods are CLS-Compliant.
1185                 /// It tests differing only in ref or out, or in array rank.
1186                 /// </summary>
1187                 public static bool AreOverloadedMethodParamsClsCompliant (Type[] types_a, Type[] types_b) 
1188                 {
1189                         if (types_a == null || types_b == null)
1190                                 return true;
1191
1192                         if (types_a.Length != types_b.Length)
1193                                 return true;
1194
1195                         for (int i = 0; i < types_b.Length; ++i) {
1196                                 Type aType = types_a [i];
1197                                 Type bType = types_b [i];
1198
1199                                 if (aType.IsArray && bType.IsArray && aType.GetArrayRank () != bType.GetArrayRank () && aType.GetElementType () == bType.GetElementType ()) {
1200                                         return false;
1201                                 }
1202
1203                                 Type aBaseType = aType;
1204                                 bool is_either_ref_or_out = false;
1205
1206                                 if (aType.IsByRef || aType.IsPointer) {
1207                                         aBaseType = aType.GetElementType ();
1208                                         is_either_ref_or_out = true;
1209                                 }
1210
1211                                 Type bBaseType = bType;
1212                                 if (bType.IsByRef || bType.IsPointer) 
1213                                 {
1214                                         bBaseType = bType.GetElementType ();
1215                                         is_either_ref_or_out = !is_either_ref_or_out;
1216                                 }
1217
1218                                 if (aBaseType != bBaseType)
1219                                         continue;
1220
1221                                 if (is_either_ref_or_out)
1222                                         return false;
1223                         }
1224                         return true;
1225                 }
1226
1227                 /// <summary>
1228                 /// Goes through all parameters and test if they are CLS-Compliant.
1229                 /// </summary>
1230                 public static bool AreParametersCompliant (Parameter[] fixedParameters, Location loc)
1231                 {
1232                         if (fixedParameters == null)
1233                                 return true;
1234
1235                         foreach (Parameter arg in fixedParameters) {
1236                                 if (!AttributeTester.IsClsCompliant (arg.ParameterType)) {
1237                                         Report.Error_T (3001, loc, arg.GetSignatureForError ());
1238                                         return false;
1239                                 }
1240                         }
1241                         return true;
1242                 }
1243
1244
1245                 /// <summary>
1246                 /// This method tests the CLS compliance of external types. It doesn't test type visibility.
1247                 /// </summary>
1248                 public static bool IsClsCompliant (Type type) 
1249                 {
1250                         if (type == null)
1251                                 return true;
1252
1253                         object type_compliance = analyzed_types[type];
1254                         if (type_compliance != null)
1255                                 return type_compliance == TRUE;
1256
1257                         if (type.IsPointer) {
1258                                 analyzed_types.Add (type, null);
1259                                 return false;
1260                         }
1261
1262                         bool result;
1263                         if (type.IsArray || type.IsByRef)       {
1264                                 result = IsClsCompliant (TypeManager.GetElementType (type));
1265                         } else {
1266                                 result = AnalyzeTypeCompliance (type);
1267                         }
1268                         analyzed_types.Add (type, result ? TRUE : FALSE);
1269                         return result;
1270                 }                
1271
1272                 static object TRUE = new object ();
1273                 static object FALSE = new object ();
1274
1275                 /// <summary>
1276                 /// Non-hierarchical CLS Compliance analyzer
1277                 /// </summary>
1278                 public static bool IsComplianceRequired (MemberInfo mi, DeclSpace ds)
1279                 {
1280                         DeclSpace temp_ds = TypeManager.LookupDeclSpace (mi.DeclaringType);
1281
1282                         // Type is external, we can get attribute directly
1283                         if (temp_ds == null) {
1284                                 object[] cls_attribute = mi.GetCustomAttributes (TypeManager.cls_compliant_attribute_type, false);
1285                                 return (cls_attribute.Length == 1 && ((CLSCompliantAttribute)cls_attribute[0]).IsCompliant);
1286                         }
1287
1288                         string tmp_name;
1289                         // Interface doesn't store full name
1290                         if (temp_ds is Interface)
1291                                 tmp_name = mi.Name;
1292                         else
1293                                 tmp_name = String.Concat (temp_ds.Name, ".", mi.Name);
1294
1295                         MemberCore mc = temp_ds.GetDefinition (tmp_name) as MemberCore;
1296                         return mc.IsClsCompliaceRequired (ds);
1297                 }
1298
1299                 public static void VerifyModulesClsCompliance ()
1300                 {
1301                         Module[] modules = TypeManager.Modules;
1302                         if (modules == null)
1303                                 return;
1304
1305                         // The first module is generated assembly
1306                         for (int i = 1; i < modules.Length; ++i) {
1307                                 Module module = modules [i];
1308                                 if (!IsClsCompliant (module)) {
1309                                         Report.Error_T (3013, module.Name);
1310                                         return;
1311                                 }
1312                         }
1313                 }
1314
1315                 static bool IsClsCompliant (ICustomAttributeProvider attribute_provider) 
1316                 {
1317                         object[] CompliantAttribute = attribute_provider.GetCustomAttributes (TypeManager.cls_compliant_attribute_type, false);
1318                         if (CompliantAttribute.Length == 0)
1319                                 return false;
1320
1321                         return ((CLSCompliantAttribute)CompliantAttribute[0]).IsCompliant;
1322                 }
1323
1324                 static bool AnalyzeTypeCompliance (Type type)
1325                 {
1326                         DeclSpace ds = TypeManager.LookupDeclSpace (type);
1327                         if (ds != null) {
1328                                 return ds.IsClsCompliaceRequired (ds.Parent);
1329                         }
1330
1331                         if (type.IsGenericParameter)
1332                                 return false;
1333
1334                         object[] CompliantAttribute = type.GetCustomAttributes (TypeManager.cls_compliant_attribute_type, false);
1335                         if (CompliantAttribute.Length == 0) 
1336                                 return IsClsCompliant (type.Assembly);
1337
1338                         return ((CLSCompliantAttribute)CompliantAttribute[0]).IsCompliant;
1339                 }
1340
1341                 /// <summary>
1342                 /// Returns instance of ObsoleteAttribute when type is obsolete
1343                 /// </summary>
1344                 public static ObsoleteAttribute GetObsoleteAttribute (Type type)
1345                 {
1346                         object type_obsolete = analyzed_types_obsolete [type];
1347                         if (type_obsolete == FALSE)
1348                                 return null;
1349
1350                         if (type_obsolete != null)
1351                                 return (ObsoleteAttribute)type_obsolete;
1352
1353                         ObsoleteAttribute result = null;
1354                         if (type.IsByRef || type.IsArray || type.IsPointer) {
1355                                 result = GetObsoleteAttribute (TypeManager.GetElementType (type));
1356                         } else if (type.IsGenericParameter || type.IsGenericInstance)
1357                                 return null;
1358                         else {
1359                                 DeclSpace type_ds = TypeManager.LookupDeclSpace (type);
1360
1361                                 // Type is external, we can get attribute directly
1362                                 if (type_ds == null) {
1363                                         object[] attribute = type.GetCustomAttributes (TypeManager.obsolete_attribute_type, false);
1364                                         if (attribute.Length == 1)
1365                                                 result = (ObsoleteAttribute)attribute [0];
1366                                 } else {
1367                                         result = type_ds.GetObsoleteAttribute (type_ds);
1368                                 }
1369                         }
1370
1371                         analyzed_types_obsolete.Add (type, result == null ? FALSE : result);
1372                         return result;
1373                 }
1374
1375                 /// <summary>
1376                 /// Returns instance of ObsoleteAttribute when method is obsolete
1377                 /// </summary>
1378                 public static ObsoleteAttribute GetMethodObsoleteAttribute (MethodBase mb)
1379                 {
1380                         IMethodData mc = TypeManager.GetMethod (mb);
1381                         if (mc != null) 
1382                                 return mc.GetObsoleteAttribute ();
1383
1384                         return GetMemberObsoleteAttribute (mb);
1385                 }
1386
1387                 /// <summary>
1388                 /// Returns instance of ObsoleteAttribute when member is obsolete
1389                 /// </summary>
1390                 public static ObsoleteAttribute GetMemberObsoleteAttribute (MemberInfo mi)
1391                 {
1392                         object type_obsolete = analyzed_member_obsolete [mi];
1393                         if (type_obsolete == FALSE)
1394                                 return null;
1395
1396                         if (type_obsolete != null)
1397                                 return (ObsoleteAttribute)type_obsolete;
1398
1399                         if ((mi.DeclaringType is TypeBuilder) || mi.DeclaringType.IsGenericInstance)
1400                                 return null;
1401
1402                         ObsoleteAttribute oa = System.Attribute.GetCustomAttribute (mi, TypeManager.obsolete_attribute_type, false) as ObsoleteAttribute;
1403                         analyzed_member_obsolete.Add (mi, oa == null ? FALSE : oa);
1404                         return oa;
1405                 }
1406
1407                 /// <summary>
1408                 /// Common method for Obsolete error/warning reporting.
1409                 /// </summary>
1410                 public static void Report_ObsoleteMessage (ObsoleteAttribute oa, string member, Location loc)
1411                 {
1412                         if (oa.IsError) {
1413                                 Report.Error_T (619, loc, member, oa.Message);
1414                                 return;
1415                         }
1416
1417                         if (oa.Message == null) {
1418                                 Report.Warning_T (612, loc, member);
1419                                 return;
1420                         }
1421                         Report.Warning_T (618, loc, member, oa.Message);
1422                 }
1423
1424                 public static bool IsConditionalMethodExcluded (MethodBase mb)
1425                 {
1426                         object excluded = analyzed_method_excluded [mb];
1427                         if (excluded != null)
1428                                 return excluded == TRUE ? true : false;
1429
1430                         if (mb.Mono_IsInflatedMethod)
1431                                 return false;
1432                         
1433                         ConditionalAttribute[] attrs = mb.GetCustomAttributes (TypeManager.conditional_attribute_type, true) as ConditionalAttribute[];
1434                         if (attrs.Length == 0) {
1435                                 analyzed_method_excluded.Add (mb, FALSE);
1436                                 return false;
1437                         }
1438
1439                         foreach (ConditionalAttribute a in attrs) {
1440                                 if (RootContext.AllDefines.Contains (a.ConditionString)) {
1441                                         analyzed_method_excluded.Add (mb, FALSE);
1442                                         return false;
1443                                 }
1444                         }
1445                         analyzed_method_excluded.Add (mb, TRUE);
1446                         return true;
1447                 }
1448         }
1449 }