+2004-05-09 Miguel de Icaza <miguel@ximian.com>
+
+ * expression.cs (Binary.DoNumericPromotions): 0 long constant can
+ be implicitly converted to ulong.
+
+ * expression.cs: The logic for allowing operator &, | and ^ worked
+ was wrong, it worked before because we did not report an error in
+ an else branch. Fixes 57895.
+
+ * class.cs: Applied patch from iain@mccoy.id.au Iain McCoy to
+ allow volatile fields to be reference types.
+
+2004-05-07 Miguel de Icaza <miguel@ximian.com>
+
+ * driver.cs: Add support for /debug-
+
+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:
+ (MemberCore.Flags): Extended for caching presence of CLSCompliantAttribute.
+ (MemberCore.VerifyClsCompliance): Implemented CS3019 error report.
+ (DeclSpace.GetClsCompliantAttributeValue): Returns simple bool.
+
+ * report.cs: (Report.Warning): Renamed to Warning_T because of
+ parameter collision.
+
2004-05-05 Raja R Harinath <rharinath@novell.com>
* expression.cs (MemberAccess.ResolveMemberAccess):
}\r
\r
/// <summary>\r
- /// Tries to resolve the type of the attribute. Flags an error if it can't.\r
+ /// Tries to resolve the type of the attribute. Flags an error if it can't, and complain is true.\r
/// </summary>\r
- private Type CheckAttributeType (EmitContext ec) {\r
+ private Type CheckAttributeType (EmitContext ec, bool complain) {\r
TypeExpr t1 = RootContext.LookupType (ec.DeclSpace, Name, true, Location);\r
// FIXME: Shouldn't do this for quoted attributes: [@A]\r
TypeExpr t2 = RootContext.LookupType (ec.DeclSpace, Name + "Attribute", true, Location);\r
Report.Error (616, Location, err0616);\r
return null;\r
}\r
- Report.Error (\r
- 246, Location, "Could not find attribute '" + Name + "' (are you" +\r
- " missing a using directive or an assembly reference ?)");\r
+ if (complain)\r
+ Report.Error (\r
+ 246, Location, "Could not find attribute '" + Name + "' (are you" +\r
+ " missing a using directive or an assembly reference ?)");\r
return null;\r
}\r
\r
- public Type ResolveType (EmitContext ec)\r
+ public Type ResolveType (EmitContext ec, bool complain)\r
{\r
if (Type == null)\r
- Type = CheckAttributeType (ec);\r
+ Type = CheckAttributeType (ec, complain);\r
return Type;\r
}\r
\r
\r
public CustomAttributeBuilder Resolve (EmitContext ec)\r
{\r
- ResolveType (ec);\r
- if (Type == null)\r
+ Type oldType = Type;\r
+\r
+ // Sanity check.\r
+ Type = CheckAttributeType (ec, true);\r
+ if (oldType == null && Type == null)\r
return null;\r
+ if (oldType != null && oldType != Type) {\r
+ Report.Error (-6, Location,\r
+ "Attribute {0} resolved to different types at different times: {1} vs. {2}",\r
+ Name, oldType, Type);\r
+ return null;\r
+ }\r
\r
bool MethodImplAttr = false;\r
bool MarshalAsAttr = false;\r
continue;\r
\r
foreach (Attribute a in asec.Attributes){\r
- if (a.ResolveType (ec) == null)\r
+ if (a.ResolveType (ec, true) == null)\r
return null;\r
\r
if (a.Type != TypeManager.indexer_name_type)\r
return null;\r
}\r
\r
- ResolveType (ec);\r
+ ResolveType (ec, true);\r
if (Type == null)\r
return null;\r
\r
AttributeSections.Add (a);\r
}\r
\r
- public bool Contains (Type t)\r
+ public Attribute Search (Type t, EmitContext ec)\r
{\r
foreach (AttributeSection attr_section in AttributeSections){\r
foreach (Attribute a in attr_section.Attributes){\r
- if (a.Type == t)\r
- return true;\r
+ if (a.ResolveType (ec, false) == t)\r
+ return a;\r
}\r
}\r
- \r
- return false;\r
+ return null;\r
}\r
\r
- public Attribute GetClsCompliantAttribute (DeclSpace ds)\r
- {\r
- foreach (AttributeSection attr_section in AttributeSections) {\r
- foreach (Attribute a in attr_section.Attributes) {\r
- // Unfortunately, we have also attributes that has not been resolved yet.\r
- // We need to simulate part of ApplyAttribute method.\r
- if (a.Type == null) {\r
- TypeExpr attr_type = RootContext.LookupType (ds, GetAttributeFullName (a.Name), true, a.Location);\r
- if (attr_type != null && attr_type.Type == TypeManager.cls_compliant_attribute_type)\r
- return a;\r
-\r
- continue;\r
- }\r
-\r
- if (a.Type == TypeManager.cls_compliant_attribute_type)\r
- return a;\r
- }\r
- }\r
- return null;\r
- }\r
+ public bool Contains (Type t, EmitContext ec)\r
+ {\r
+ return Search (t, ec) != null;\r
+ }\r
\r
- public static string GetAttributeFullName (string name)\r
- {\r
- if (name.EndsWith ("Attribute"))\r
- return name;\r
- return name + "Attribute";\r
- }\r
+ public Attribute GetClsCompliantAttribute (EmitContext ec)\r
+ {\r
+ return Search (TypeManager.cls_compliant_attribute_type, ec);\r
+ }\r
}\r
\r
public interface IAttributeSupport\r
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))
Report.Error (36, loc,
"Can not use [In] attribute on out parameter");
}
protected override bool VerifyClsCompliance (DeclSpace ds)
{
- if (!base.VerifyClsCompliance (ds)) {
+ if (!base.VerifyClsCompliance (ds) || !IsExposedFromAssembly (ds)) {
return false;
}
continue;
foreach (Attribute a in asec.Attributes) {
- Type attr_type = a.ResolveType (ec);
+ Type attr_type = a.ResolveType (ec, true);
if (attr_type == TypeManager.conditional_attribute_type) {
if (!ApplyConditionalAttribute (a))
return false;
return true;
}
- if (IsInterface && HasClsCompliantAttribute (ds) && ds.IsClsCompliaceRequired (ds)) {
+ if (IsInterface && HasClsCompliantAttribute && ds.IsClsCompliaceRequired (ds)) {
Report.Error_T (3010, Location, GetSignatureForError ());
}
return false;
if (!((vt == TypeManager.bool_type) ||
(vt == TypeManager.sbyte_type) ||
(vt == TypeManager.byte_type) ||
- (vt == TypeManager.short_type) ||
+ (vt == TypeManager.short_type) ||
(vt == TypeManager.ushort_type) ||
- (vt == TypeManager.int32_type) ||
+ (vt == TypeManager.int32_type) ||
(vt == TypeManager.uint32_type) ||
- (vt == TypeManager.char_type) ||
- (vt == TypeManager.float_type))){
+ (vt == TypeManager.char_type) ||
+ (vt == TypeManager.float_type) ||
+ (!vt.IsValueType))){
Report.Error (
677, Location, container.MakeName (Name) +
" A volatile field can not be of type `" +
Attributes attrs = (Attributes) de.Value;
temp_ec.TypeContainer.NamespaceEntry = ns;
- foreach (AttributeSection attr_section in attrs.AttributeSections) {
- foreach (Attribute a in attr_section.Attributes) {
- TypeExpr attributeType = RootContext.LookupType (temp_ec.DeclSpace, Attributes.GetAttributeFullName (a.Name), true, Location.Null);
- if (attributeType != null && attributeType.Type == TypeManager.cls_compliant_attribute_type) {
- a.Resolve (temp_ec);
- return a;
- }
- }
- }
+ Attribute a = attrs.Search (TypeManager.cls_compliant_attribute_type, temp_ec);
+ if (a != null) {
+ a.Resolve (temp_ec);
+ return a;
+ }
}
return null;
}
Attribute a = GetClsCompliantAttribute ();
if (a != null) {
- Report.Warning (3012, a.Location);
+ Report.Warning_T (3012, a.Location);
}
if (!m_module_is_unsafe)
[Flags]
public enum Flags {
- Obsolete_Undetected = 1, // Obsolete attribute has not beed detected yet
+ Obsolete_Undetected = 1, // Obsolete attribute has not been detected yet
Obsolete = 1 << 1, // Type has obsolete attribute
ClsCompliance_Undetected = 1 << 2, // CLS Compliance has not been detected yet
ClsCompliant = 1 << 3, // Type is CLS Compliant
- CloseTypeCreated = 1 << 4 // Tracks whether we have Closed the type
+ CloseTypeCreated = 1 << 4, // Tracks whether we have Closed the type
+ HasCompliantAttribute_Undetected = 1 << 5, // Presence of CLSCompliantAttribute has not been detected
+ HasClsCompliantAttribute = 1 << 6, // Type has CLSCompliantAttribute
+ ClsCompliantAttributeTrue = 1 << 7, // Type has CLSCompliant (true)
}
/// <summary>
Name = name.GetName (!(this is GenericMethod) && !(this is Method));
MemberName = name;
Location = loc;
- caching_flags = Flags.Obsolete_Undetected | Flags.ClsCompliance_Undetected;
+ caching_flags = Flags.Obsolete_Undetected | Flags.ClsCompliance_Undetected | Flags.HasCompliantAttribute_Undetected;
}
public abstract bool Define (TypeContainer parent);
if ((caching_flags & Flags.ClsCompliance_Undetected) == 0)
return (caching_flags & Flags.ClsCompliant) != 0;
- if (!IsExposedFromAssembly (container) || !GetClsCompliantAttributeValue (container)) {
+ if (GetClsCompliantAttributeValue (container) && IsExposedFromAssembly (container)) {
caching_flags &= ~Flags.ClsCompliance_Undetected;
- return false;
+ caching_flags |= Flags.ClsCompliant;
+ return true;
}
caching_flags &= ~Flags.ClsCompliance_Undetected;
- caching_flags |= Flags.ClsCompliant;
- return true;
+ return false;
}
/// <summary>
/// Returns true when MemberCore is exposed from assembly.
/// </summary>
- protected virtual bool IsExposedFromAssembly (DeclSpace ds)
+ protected bool IsExposedFromAssembly (DeclSpace ds)
{
if ((ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
return false;
bool GetClsCompliantAttributeValue (DeclSpace ds)
{
if (OptAttributes != null) {
- Attribute cls_attribute = OptAttributes.GetClsCompliantAttribute (ds);
+ EmitContext ec = new EmitContext (ds.Parent, ds, ds.Location,
+ null, null, ds.ModFlags, false);
+ Attribute cls_attribute = OptAttributes.GetClsCompliantAttribute (ec);
if (cls_attribute != null) {
+ caching_flags |= Flags.HasClsCompliantAttribute;
return cls_attribute.GetClsCompliantAttributeValue (ds);
}
}
-
- return (ds.GetClsCompliantAttributeValue () & Flags.ClsCompliant) != 0;
+ return ds.GetClsCompliantAttributeValue ();
}
/// <summary>
/// Returns true if MemberCore is explicitly marked with CLSCompliantAttribute
/// </summary>
- protected bool HasClsCompliantAttribute (DeclSpace ds)
- {
- if (OptAttributes == null)
- return false;
-
- return OptAttributes.GetClsCompliantAttribute (ds) != null;
+ protected bool HasClsCompliantAttribute {
+ get {
+ return (caching_flags & Flags.HasClsCompliantAttribute) != 0;
+ }
}
/// <summary>
protected virtual bool VerifyClsCompliance (DeclSpace ds)
{
if (!IsClsCompliaceRequired (ds)) {
+ if (HasClsCompliantAttribute && !IsExposedFromAssembly (ds)) {
+ Report.Warning_T (3019, Location, GetSignatureForError ());
+ }
return false;
}
if (!CodeGen.Assembly.IsClsCompliant) {
- if (HasClsCompliantAttribute (ds)) {
+ if (HasClsCompliantAttribute) {
Report.Error_T (3014, Location, GetSignatureForError ());
}
}
/// Goes through class hierarchy and get value of first CLSCompliantAttribute that found.
/// If no is attribute exists then return assembly CLSCompliantAttribute.
/// </summary>
- public Flags GetClsCompliantAttributeValue ()
+ public bool GetClsCompliantAttributeValue ()
{
- if ((caching_flags & Flags.ClsCompliance_Undetected) == 0)
- return caching_flags;
+ if ((caching_flags & Flags.HasCompliantAttribute_Undetected) == 0)
+ return (caching_flags & Flags.ClsCompliantAttributeTrue) != 0;
- caching_flags &= ~Flags.ClsCompliance_Undetected;
+ caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
if (OptAttributes != null) {
- Attribute cls_attribute = OptAttributes.GetClsCompliantAttribute (this);
+ EmitContext ec = new EmitContext (parent, this, Location,
+ null, null, ModFlags, false);
+ Attribute cls_attribute = OptAttributes.GetClsCompliantAttribute (ec);
if (cls_attribute != null) {
+ caching_flags |= Flags.HasClsCompliantAttribute;
if (cls_attribute.GetClsCompliantAttributeValue (this)) {
- caching_flags |= Flags.ClsCompliant;
+ caching_flags |= Flags.ClsCompliantAttributeTrue;
+ return true;
}
- return caching_flags;
+ return false;
}
}
if (parent == null) {
- if (CodeGen.Assembly.IsClsCompliant)
- caching_flags |= Flags.ClsCompliant;
- return caching_flags;
+ if (CodeGen.Assembly.IsClsCompliant) {
+ caching_flags |= Flags.ClsCompliantAttributeTrue;
+ return true;
+ }
+ return false;
}
- caching_flags |= (parent.GetClsCompliantAttributeValue () & Flags.ClsCompliant);
- return caching_flags;
+ if (parent.GetClsCompliantAttributeValue ()) {
+ caching_flags |= Flags.ClsCompliantAttributeTrue;
+ return true;
+ }
+ return false;
}
link_paths.Add (dir);
return true;
}
+
+ case "/debug-":
+ want_debugging_support = false;
+ return true;
case "/debug":
case "/debug+":
} else if (right is LongConstant){
long ll = ((LongConstant) right).Value;
- if (ll > 0)
+ if (ll >= 0)
right = new ULongConstant ((ulong) ll);
} else {
e = Convert.ImplicitNumericConversion (ec, right, l, loc);
oper == Operator.BitwiseOr ||
oper == Operator.ExclusiveOr){
if (l == r){
- if (!((l == TypeManager.int32_type) ||
- (l == TypeManager.uint32_type) ||
- (l == TypeManager.short_type) ||
- (l == TypeManager.ushort_type) ||
- (l == TypeManager.int64_type) ||
- (l == TypeManager.uint64_type))){
+ if (((l == TypeManager.int32_type) ||
+ (l == TypeManager.uint32_type) ||
+ (l == TypeManager.short_type) ||
+ (l == TypeManager.ushort_type) ||
+ (l == TypeManager.int64_type) ||
+ (l == TypeManager.uint64_type))){
type = l;
+ } else {
+ Error_OperatorCannotBeApplied ();
+ return null;
}
} else {
Error_OperatorCannotBeApplied ();
Report.Error (177, loc, "The out parameter `" +
var.Name + "' must be " +
- "assigned before control leave the current method.");
+ "assigned before control leaves the current method.");
}
}
{
switch (warn_no) {
case 3012: return new WarningData (1, "You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking");
+ case 3019: return new WarningData (2, "CLS compliance checking will not be performed on '{0}' because it is private or internal");
}
throw new InternalErrorException (String.Format ("Wrong warning number '{0}'", warn_no));
/// <summary>
/// Method reports warning message. Only one reason why exist Warning and Report methods is beter code readability.
/// </summary>
- static public void Warning (int code, Location loc, params object[] args)
+ static public void Warning_T (int code, Location loc, params object[] args)
{
WarningData warning = GetWarningMsg (code);
if (warning.IsEnabled ())
"System.Security.UnverifiableCodeAttribute",
"System.Runtime.CompilerServices.IndexerNameAttribute",
"System.Runtime.InteropServices.InAttribute",
+ "System.Runtime.InteropServices.StructLayoutAttribute",
+ "System.Runtime.InteropServices.FieldOffsetAttribute",
"System.InvalidOperationException",
"System.MarshalByRefObject"
};
static public Type typed_reference_type;
static public Type arg_iterator_type;
static public Type mbr_type;
+ static public Type struct_layout_attribute_type;
+ static public Type field_offset_attribute_type;
//
// An empty array of types
obsolete_attribute_type = CoreLookupType ("System.ObsoleteAttribute");
conditional_attribute_type = CoreLookupType ("System.Diagnostics.ConditionalAttribute");
cls_compliant_attribute_type = CoreLookupType ("System.CLSCompliantAttribute");
+ struct_layout_attribute_type = CoreLookupType ("System.Runtime.InteropServices.StructLayoutAttribute");
+ field_offset_attribute_type = CoreLookupType ("System.Runtime.InteropServices.FieldOffsetAttribute");
//
// When compiling corlib, store the "real" types here.