+2004-05-07 Raja R Harinath <rharinath@novell.com>
+
+ * attribute.cs (Attribute.CheckAttributeType, Attribute.ResolveType):
+ Add a 'complain' parameter to silence errors.
+ (Attribute.Resolve): Update to changes. Put in sanity check to catch
+ silently overlooked type-resolutions.
+ (Attribute.ScanForIndexerName, Attribute.DefinePInvokeMethod): Update
+ to reflect changes.
+ (Attributes.Search): New function.
+ (Attributes.Contains, Attributes.GetClsCompliantAttribute): Use Search.
+ (Attributes.GetAttributeFullName): Remove hack.
+ * class.cs (MethodCore.LabelParameters, MethodData.ApplyAttributes):
+ Update to reflect changes.
+ * codegen.cs (CommonAssemblyModulClass.GetClsCompliantAttribute):
+ Use Attributes.Search instead of nested loops.
+
2004-05-07 Marek Safar <marek.safar@seznam.cz>
* decl.cs:
}
/// <summary>
- /// Tries to resolve the type of the attribute. Flags an error if it can't.
+ /// Tries to resolve the type of the attribute. Flags an error if it can't, and complain is true.
/// </summary>
- private Type CheckAttributeType (DeclSpace ds) {
+ private Type CheckAttributeType (DeclSpace ds, bool complain) {
Type t1 = RootContext.LookupType (ds, Name, true, Location);
// FIXME: Shouldn't do this for quoted attributes: [@A]
Report.Error (616, Location, err0616);
return null;
}
-
- Report.Error (
- 246, Location, "Could not find attribute '" + Name + "' (are you" +
- " missing a using directive or an assembly reference ?)");
+
+ if (complain)
+ Report.Error (246, Location,
+ "Could not find attribute '" + Name
+ + "' (are you missing a using directive or an assembly reference ?)");
return null;
}
- public Type ResolveType (DeclSpace ds)
+ public Type ResolveType (DeclSpace ds, bool complain)
{
if (Type == null)
- Type = CheckAttributeType (ds);
+ Type = CheckAttributeType (ds, complain);
return Type;
}
public CustomAttributeBuilder Resolve (EmitContext ec)
{
- ResolveType (ec.DeclSpace);
- if (Type == null)
+ Type oldType = Type;
+
+ // Sanity check.
+ Type = CheckAttributeType (ec.DeclSpace, true);
+ if (oldType == null && Type == null)
+ return null;
+ if (oldType != null && oldType != Type) {
+ Report.Error (-6, Location,
+ "Attribute {0} resolved to different types at different times: {1} vs. {2}",
+ Name, oldType, Type);
return null;
+ }
bool MethodImplAttr = false;
bool MarshalAsAttr = false;
continue;
foreach (Attribute a in asec.Attributes){
- if (a.ResolveType (ec.DeclSpace) == null)
+ if (a.ResolveType (ec.DeclSpace, true) == null)
return null;
if (a.Type != TypeManager.indexer_name_type)
return null;
}
- ResolveType (ec.DeclSpace);
+ ResolveType (ec.DeclSpace, true);
if (Type == null)
return null;
AttributeSections.Add (a);
}
- public bool Contains (Type t)
+ public Attribute Search (Type t, DeclSpace ds)
{
foreach (AttributeSection attr_section in AttributeSections){
foreach (Attribute a in attr_section.Attributes){
- if (a.Type == t)
- return true;
+ if (a.ResolveType (ds, false) == t)
+ return a;
}
}
-
- return false;
+ return null;
}
- public Attribute GetClsCompliantAttribute (DeclSpace ds)
+ public bool Contains (Type t, DeclSpace ds)
{
- foreach (AttributeSection attr_section in AttributeSections) {
- foreach (Attribute a in attr_section.Attributes) {
-
- // Unfortunately, we have also attributes that has not been resolved yet.
- // We need to simulate part of ApplyAttribute method.
- if (a.Type == null) {
- Type attr_type = RootContext.LookupType (ds, GetAttributeFullName (a.Name), true, a.Location);
- if (attr_type == TypeManager.cls_compliant_attribute_type)
- return a;
-
- continue;
- }
-
- if (a.Type == TypeManager.cls_compliant_attribute_type)
- return a;
- }
- }
- return null;
+ return Search (t, ds) != null;
}
- public static string GetAttributeFullName (string name)
+ public Attribute GetClsCompliantAttribute (DeclSpace ds)
{
- if (name.EndsWith ("Attribute"))
- return name;
- return name + "Attribute";
+ return Search (TypeManager.cls_compliant_attribute_type, ds);
}
}
Attribute.ApplyAttributes (ec, pb, p[i], attr);
if (par_attr == ParameterAttributes.Out){
- if (attr.Contains (TypeManager.in_attribute_type))
+ if (attr.Contains (TypeManager.in_attribute_type, ec.DeclSpace))
Report.Error (36, loc,
"Can not use [In] attribute on out parameter");
}
continue;
foreach (Attribute a in asec.Attributes) {
- Type attr_type = a.ResolveType (ds);
+ Type attr_type = a.ResolveType (ds, true);
if (attr_type == TypeManager.conditional_attribute_type) {
if (!ApplyConditionalAttribute (a))
return false;