X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fmcs%2Fattribute.cs;h=b939cf436ba46b09f46ef580e6a2f015cf3f41a5;hb=f282c09a4f474c0994bf739e0b300043fd342b80;hp=7f0cdca89b30950ee12ed988692bdd84f55b2e80;hpb=5ada64351649a4b75020572ce76a0c9567a8c83c;p=mono.git diff --git a/mcs/mcs/attribute.cs b/mcs/mcs/attribute.cs index 7f0cdca89b3..b939cf436ba 100644 --- a/mcs/mcs/attribute.cs +++ b/mcs/mcs/attribute.cs @@ -10,6 +10,7 @@ // using System; +using System.Diagnostics; using System.Collections; using System.Reflection; using System.Reflection.Emit; @@ -154,6 +155,7 @@ namespace Mono.CSharp { return null; e = a.Expr; + if (e is Constant) { pos_values [i] = ((Constant) e).GetValue (); } else if (e is TypeOf) { @@ -224,7 +226,9 @@ namespace Mono.CSharp { this.Inherited = (bool) o; } - } else { + } else if (e is TypeOf) { + prop_values.Add (((TypeOf) e).TypeArg); + } else { Error_AttributeArgumentNotValid (); return null; } @@ -247,7 +251,9 @@ namespace Mono.CSharp { object value = ((Constant) e).GetValue (); field_values.Add (value); - } else { + } else if (e is TypeOf) { + field_values.Add (((TypeOf) e).TypeArg); + } else { Error_AttributeArgumentNotValid (); return null; } @@ -272,6 +278,23 @@ namespace Mono.CSharp { Error_AttributeConstructorMismatch (Location); return null; } + + // + // Now we perform some checks on the positional args as they + // cannot be null for a constructor which expects a parameter + // of type object + // + + ParameterData pd = Invocation.GetParameterData (constructor); + + for (int j = 0; j < pos_arg_count; ++j) { + Argument a = (Argument) pos_args [j]; + + if (a.Expr is NullLiteral && pd.ParameterType (j) == TypeManager.object_type) { + Error_AttributeArgumentNotValid (); + return null; + } + } PropertyInfo [] prop_info_arr = new PropertyInfo [prop_infos.Count]; FieldInfo [] field_info_arr = new FieldInfo [field_infos.Count]; @@ -289,6 +312,13 @@ namespace Mono.CSharp { (ConstructorInfo) constructor, pos_values, prop_info_arr, prop_values_arr, field_info_arr, field_values_arr); + + } catch (NullReferenceException) { + // + // Don't know what to do here + // + Report.Warning ( + -100, Location, "NullReferenceException while trying to create attribute. Something's wrong!"); } catch { // // Sample: @@ -327,8 +357,10 @@ namespace Mono.CSharp { } foreach (System.Attribute tmp in attrs) - if (tmp is AttributeUsageAttribute) + if (tmp is AttributeUsageAttribute) { targets = ((AttributeUsageAttribute) tmp).ValidOn; + break; + } } else targets = a.Targets; @@ -535,7 +567,73 @@ namespace Mono.CSharp { } return null; } - + + // + // This pulls the condition name out of a Conditional attribute + // + public string Conditional_GetConditionName () + { + // + // So we have a Conditional, pull the data out. + // + if (Arguments == null || Arguments [0] == null){ + Error_AttributeConstructorMismatch (Location); + return null; + } + + ArrayList pos_args = (ArrayList) Arguments [0]; + if (pos_args.Count != 1){ + Error_AttributeConstructorMismatch (Location); + return null; + } + + Argument arg = (Argument) pos_args [0]; + if (!(arg.Expr is StringConstant)){ + Error_AttributeConstructorMismatch (Location); + return null; + } + + return ((StringConstant) arg.Expr).Value; + } + + // + // This pulls the obsolete message and error flag out of an Obsolete attribute + // + public string Obsolete_GetObsoleteMessage (out bool is_error) + { + is_error = false; + // + // So we have an Obsolete, pull the data out. + // + if (Arguments == null || Arguments [0] == null) + return ""; + + ArrayList pos_args = (ArrayList) Arguments [0]; + if (pos_args.Count == 0) + return ""; + else if (pos_args.Count > 2){ + Error_AttributeConstructorMismatch (Location); + return null; + } + + Argument arg = (Argument) pos_args [0]; + if (!(arg.Expr is StringConstant)){ + Error_AttributeConstructorMismatch (Location); + return null; + } + + if (pos_args.Count == 2){ + Argument arg2 = (Argument) pos_args [1]; + if (!(arg2.Expr is BoolConstant)){ + Error_AttributeConstructorMismatch (Location); + return null; + } + is_error = ((BoolConstant) arg2.Expr).Value; + } + + return ((StringConstant) arg.Expr).Value; + } + // // Applies the attributes to the `builder'. // @@ -634,6 +732,24 @@ namespace Mono.CSharp { "\tMicrosoft .NET runtime"); } + } else if (kind is Interface) { + Interface iface = (Interface) kind; + + if ((a.Type == TypeManager.default_member_type) && + (iface.InterfaceIndexers != null)) { + Report.Error ( + 646, loc, + "Cannot specify the DefaultMember attribute on" + + " a type containing an indexer"); + return; + } + + if (!CheckAttribute (a, kind)) { + Error_AttributeNotValidForElement (a, loc); + return; + } + + ((TypeBuilder) builder).SetCustomAttribute (cb); } else if (kind is AssemblyBuilder){ ((AssemblyBuilder) builder).SetCustomAttribute (cb); } else if (kind is ModuleBuilder) { @@ -744,8 +860,11 @@ namespace Mono.CSharp { } } + if (entry_point == null) + entry_point = name; + MethodBuilder mb = builder.DefinePInvokeMethod ( - name, dll_name, flags | MethodAttributes.HideBySig, + name, dll_name, entry_point, flags | MethodAttributes.HideBySig, CallingConventions.Standard, ret_type, param_types,