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