"expression or array creation expression");\r
}\r
\r
- static void Error_AttributeConstructorMismatch (Location loc)\r
+ void Error_AttributeConstructorMismatch ()\r
{\r
- Report.Error (-6, loc,\r
+ Report.Error (-6, Location,\r
"Could not find a constructor for this argument list.");\r
}\r
\r
Location);\r
\r
if (mg == null) {\r
- Error_AttributeConstructorMismatch (Location);\r
+ Error_AttributeConstructorMismatch ();\r
return null;\r
}\r
\r
ec, (MethodGroupExpr) mg, pos_args, false, Location);\r
\r
if (constructor == null) {\r
- Error_AttributeConstructorMismatch (Location);\r
+ Error_AttributeConstructorMismatch ();\r
return null;\r
}\r
\r
return attr_class.AttributeUsage;\r
}\r
\r
- //\r
- // This method should be invoked to pull the IndexerName attribute from an\r
- // Indexer if it exists.\r
- //\r
- public static string ScanForIndexerName (EmitContext ec, Attributes opt_attrs)\r
- {\r
- if (opt_attrs == null)\r
- return null;\r
- if (opt_attrs.AttributeSections == null)\r
- return null;\r
-\r
- foreach (Attribute a in opt_attrs.AttributeSections) {\r
- if (a.ResolveType (ec, true) == null)\r
- return null;\r
-\r
- if (a.Type != TypeManager.indexer_name_type)\r
- continue;\r
-\r
- //\r
- // So we have found an IndexerName, pull the data out.\r
- //\r
- if (a.Arguments == null || a.Arguments [0] == null){\r
- Error_AttributeConstructorMismatch (a.Location);\r
- return null;\r
- }\r
- ArrayList pos_args = (ArrayList) a.Arguments [0];\r
- if (pos_args.Count == 0){\r
- Error_AttributeConstructorMismatch (a.Location);\r
- return null;\r
- }\r
- \r
- Argument arg = (Argument) pos_args [0];\r
- if (!arg.Resolve (ec, a.Location))\r
- return null;\r
- \r
- Expression e = arg.Expr;\r
- if (!(e is StringConstant)){\r
- Error_AttributeConstructorMismatch (a.Location);\r
- return null;\r
- }\r
-\r
- //\r
- // Remove the attribute from the list\r
- //\r
-\r
- //TODO: It is very close to hack and it can crash here\r
- opt_attrs.AttributeSections.Remove (a);\r
-\r
- return (((StringConstant) e).Value);\r
- }\r
- return null;\r
- }\r
-\r
//\r
// This pulls the condition name out of a Conditional attribute\r
//\r
// So we have a Conditional, pull the data out.\r
//\r
if (Arguments == null || Arguments [0] == null){\r
- Error_AttributeConstructorMismatch (Location);\r
+ Error_AttributeConstructorMismatch ();\r
return null;\r
}\r
\r
ArrayList pos_args = (ArrayList) Arguments [0];\r
if (pos_args.Count != 1){\r
- Error_AttributeConstructorMismatch (Location);\r
+ Error_AttributeConstructorMismatch ();\r
return null;\r
}\r
\r
Argument arg = (Argument) pos_args [0]; \r
if (!(arg.Expr is StringConstant)){\r
- Error_AttributeConstructorMismatch (Location);\r
+ Error_AttributeConstructorMismatch ();\r
return null;\r
}\r
\r
if (pos_args.Count == 0)\r
return "";\r
else if (pos_args.Count > 2){\r
- Error_AttributeConstructorMismatch (Location);\r
+ Error_AttributeConstructorMismatch ();\r
return null;\r
}\r
\r
Argument arg = (Argument) pos_args [0]; \r
if (!(arg.Expr is StringConstant)){\r
- Error_AttributeConstructorMismatch (Location);\r
+ Error_AttributeConstructorMismatch ();\r
return null;\r
}\r
\r
if (pos_args.Count == 2){\r
Argument arg2 = (Argument) pos_args [1];\r
if (!(arg2.Expr is BoolConstant)){\r
- Error_AttributeConstructorMismatch (Location);\r
+ Error_AttributeConstructorMismatch ();\r
return null;\r
}\r
is_error = ((BoolConstant) arg2.Expr).Value;\r
return ((StringConstant) arg.Expr).Value;\r
}\r
\r
+ public string IndexerName_GetIndexerName (EmitContext ec)\r
+ {\r
+ if (Arguments == null || Arguments [0] == null){\r
+ Error_AttributeConstructorMismatch ();\r
+ return null;\r
+ }\r
+ ArrayList pos_args = (ArrayList) Arguments [0];\r
+ if (pos_args.Count != 1) {\r
+ Error_AttributeConstructorMismatch ();\r
+ return null;\r
+ }\r
+\r
+ Argument arg = (Argument) pos_args [0];\r
+ if (!arg.Resolve (ec, Location))\r
+ return null;\r
+\r
+ StringConstant sc = arg.Expr as StringConstant;\r
+ if (sc == null){\r
+ Error_AttributeConstructorMismatch ();\r
+ return null;\r
+ }\r
+\r
+ return sc.Value;\r
+ }\r
+\r
/// <summary>\r
/// Returns value of CLSCompliantAttribute contructor parameter but because the method can be called\r
/// before ApplyAttribute. We need to resolve the arguments.\r
get { return ImplOptions == MethodImplOptions.InternalCall; }\r
}\r
\r
+ protected virtual bool CanIgnoreInvalidAttribute (Attributable ias)\r
+ {\r
+ return false;\r
+ }\r
+\r
/// <summary>\r
/// Emit attribute for Attributable symbol\r
/// </summary>\r
\r
AttributeUsageAttribute usage_attr = GetAttributeUsage ();\r
if ((usage_attr.ValidOn & ias.AttributeTargets) == 0) {\r
- Error_AttributeNotValidForElement (this, Location);\r
+ // The parser applies toplevel attributes both to the assembly and\r
+ // to a top-level class, if any. So, be silent about them.\r
+ if (! CanIgnoreInvalidAttribute (ias))\r
+ Error_AttributeNotValidForElement (this, Location);\r
return;\r
}\r
\r
\r
protected override Type CheckAttributeType (EmitContext ec, bool complain)\r
{\r
- ec.DeclSpace.NamespaceEntry = ns;\r
+ NamespaceEntry old = ec.DeclSpace.NamespaceEntry;\r
+ if (old == null || old.NS == null || old.NS == Namespace.Root) \r
+ ec.DeclSpace.NamespaceEntry = ns;\r
return base.CheckAttributeType (ec, complain);\r
}\r
+\r
+ protected override bool CanIgnoreInvalidAttribute (Attributable ias)\r
+ {\r
+ // Ignore error if this attribute is shared between the Assembly\r
+ // and a top-level class. The parser couldn't figure out which entity\r
+ // this attribute belongs to. If this attribute is erroneous, it should\r
+ // be caught when it is processed by the top-level class.\r
+\r
+ return (Target == null && ias is CommonAssemblyModulClass);\r
+ }\r
}\r
\r
public class Attributes {\r
- public ArrayList AttributeSections;\r
+ public ArrayList Attrs;\r
\r
public Attributes (Attribute a)\r
{\r
- AttributeSections = new ArrayList ();\r
- AttributeSections.Add (a);\r
+ Attrs = new ArrayList ();\r
+ Attrs.Add (a);\r
}\r
\r
public Attributes (ArrayList attrs)\r
{\r
- AttributeSections = attrs;\r
+ Attrs = attrs;\r
}\r
\r
public void AddAttributes (ArrayList attrs)\r
{\r
- AttributeSections.AddRange (attrs);\r
+ Attrs.AddRange (attrs);\r
}\r
\r
/// <summary>\r
/// </summary>\r
public void CheckTargets (string[] possible_targets)\r
{\r
- foreach (Attribute a in AttributeSections) {\r
+ foreach (Attribute a in Attrs) {\r
if (a.Target == null)\r
continue;\r
\r
- bool valid_target = false;\r
- for (int i = 0; i < possible_targets.Length; ++i) {\r
- if (a.Target == possible_targets [i]) {\r
- valid_target = true;\r
- break;\r
- }\r
- }\r
-\r
- if (valid_target)\r
+ if (((IList) possible_targets).Contains (a.Target))\r
continue;\r
\r
StringBuilder sb = new StringBuilder ();\r
}\r
}\r
\r
- public Attribute Search (Type t, EmitContext ec)\r
+ private Attribute Search (Type t, EmitContext ec, bool complain)\r
{\r
- foreach (Attribute attr_section in AttributeSections) {\r
- if (attr_section.ResolveType (ec, false) == t)\r
- return attr_section;\r
+ foreach (Attribute a in Attrs) {\r
+ if (a.ResolveType (ec, false) == t)\r
+ return a;\r
}\r
return null;\r
}\r
\r
+ public Attribute Search (Type t, EmitContext ec)\r
+ {\r
+ return Search (t, ec, true);\r
+ }\r
+\r
public void Emit (EmitContext ec, Attributable ias)\r
{\r
ListDictionary ld = new ListDictionary ();\r
\r
- foreach (Attribute a in AttributeSections) {\r
+ foreach (Attribute a in Attrs) {\r
a.Emit (ec, ias, ld);\r
}\r
}\r
\r
public Attribute GetClsCompliantAttribute (EmitContext ec)\r
{\r
- return Search (TypeManager.cls_compliant_attribute_type, ec);\r
+ return Search (TypeManager.cls_compliant_attribute_type, ec, false);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Pulls the IndexerName attribute from an Indexer if it exists.\r
+ /// </summary>\r
+ public string ScanForIndexerName (EmitContext ec)\r
+ {\r
+ Attribute a = Search (TypeManager.indexer_name_type, ec);\r
+ if (a == null)\r
+ return null;\r
+\r
+ // Remove the attribute from the list\r
+ //TODO: It is very close to hack and it can crash here\r
+ Attrs.Remove (a);\r
+\r
+ return a.IndexerName_GetIndexerName (ec);\r
}\r
}\r
\r
}
base.ApplyAttributeBuilder (a, cb);
- }
+ }
public override AttributeTargets AttributeTargets {
get {
// Invariant maintained by AddIndexer(): All explicit interface indexers precede normal indexers
bool seen_normal_indexers = false;
foreach (Indexer i in Indexers) {
- if (i.MemberName.TypeName != null)
- seen_normal_indexers = true;
- else if (seen_normal_indexers)
- throw new Exception ("Internal Error: 'Indexers' array not sorted properly.");
- }
- foreach (Indexer i in Indexers){
string name;
i.Define (this);
name = i.IndexerName;
- if (i.InterfaceType != null)
+ if (i.InterfaceType != null) {
+ if (seen_normal_indexers)
+ throw new Exception ("Internal Error: 'Indexers' array not sorted properly.");
continue;
+ }
+
+ seen_normal_indexers = true;
- if (class_indexer_name == null){
+ if (class_indexer_name == null)
class_indexer_name = name;
- continue;
- }
-
- if (name == class_indexer_name)
- continue;
-
- Report.Error (
- 668, "Two indexers have different names, " +
- " you should use the same name for all your indexers");
+ else if (name != class_indexer_name)
+ Report.Error (668, "Two indexers have different names, " +
+ " you should use the same name for all your indexers");
}
if (seen_normal_indexers && class_indexer_name == null)
public virtual bool ApplyAttributes (Attributes opt_attrs, bool is_method, DeclSpace ds)
{
- if ((opt_attrs == null) || (opt_attrs.AttributeSections == null))
+ if ((opt_attrs == null) || (opt_attrs.Attrs == null))
return true;
- foreach (Attribute a in opt_attrs.AttributeSections) {
+ foreach (Attribute a in opt_attrs.Attrs) {
Type attr_type = a.ResolveType (ec, true);
if (attr_type == TypeManager.conditional_attribute_type) {
if (!ApplyConditionalAttribute (a))
public class SetMethod: PropertyMethod {
static string[] attribute_targets = new string [] { "method", "param", "return" };
- ParameterAtribute param_attr;
+ ImplicitParameter param_attr;
public SetMethod (MethodCore method, Accessor accessor):
base (method, accessor)
{
if (a.Target == "param") {
if (param_attr == null)
- param_attr = new ParameterAtribute (method_data.MethodBuilder);
+ param_attr = new ImplicitParameter (method_data.MethodBuilder);
param_attr.ApplyAttributeBuilder (a, cb);
return;
protected MethodData method_data;
Block block;
ReturnParameter return_attributes;
- ParameterAtribute param_attr;
+ ImplicitParameter param_attr;
static string[] attribute_targets = new string [] { "method", "param", "return" };
if (a.Target == "param") {
if (param_attr == null)
- param_attr = new ParameterAtribute (method_data.MethodBuilder);
+ param_attr = new ImplicitParameter (method_data.MethodBuilder);
param_attr.ApplyAttributeBuilder (a, cb);
return;
if (!DoDefine (container, container))
return false;
- IndexerName = Attribute.ScanForIndexerName (ec, OptAttributes);
+ if (OptAttributes != null)
+ IndexerName = OptAttributes.ScanForIndexerName (ec);
+
if (IndexerName == null)
IndexerName = "Item";
else {
if (IsExplicitImpl) {
Report.Error (592, Location,
- "Attribute 'IndexerName' is not valid on explicit " +
- "implementations.");
-
+ "Attribute 'IndexerName' is not valid on explicit implementations.");
return false;
}
}