Author: martin
Date: 2005-04-19 15:10:31 -0400 (Tue, 19 Apr 2005)
New Revision: 43284
Modified:
trunk/mcs/gmcs/ChangeLog
trunk/mcs/gmcs/attribute.cs
trunk/mcs/gmcs/class.cs
trunk/mcs/gmcs/codegen.cs
trunk/mcs/gmcs/decl.cs
trunk/mcs/gmcs/delegate.cs
trunk/mcs/gmcs/driver.cs
trunk/mcs/gmcs/enum.cs
trunk/mcs/gmcs/rootcontext.cs
trunk/mcs/gmcs/typemanager.cs
Log:
**** Merged r42916 from MCS ****
Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog 2005-04-19 19:09:54 UTC (rev 43283)
+++ trunk/mcs/gmcs/ChangeLog 2005-04-19 19:10:31 UTC (rev 43284)
@@ -1,3 +1,38 @@
+2005-04-13 Marek Safar <[EMAIL PROTECTED]>
+
+ C# 2.0 DefaultCharSetAttribute implementation
+
+ * attribute.cs (Attribute.ResolveAsTypeStep): New protected method
+ which allows us to set GlobalNamespace for every resolve.
+ (Attribute.ResolveArguments): Cut from Resolve.
+ (Attribute.GetCharSetValue): Returns CharSet named argument.
+ (Attribute.DefinePInvokeMethod): Gets default charset from
+ module settings.
+ (GlobalAttribute.ResolveAsTypeStep): Override.
+ (GlobalAttribute.ResolveArguments): Override.
+
+ * class.cs (TypeAttr): Is protected.
+
+ * codegen.cs (ModuleClass.DefaultCharSet): New member.
+ (ModuleClass.DefaultCharSetType): New memeber.
+ (ModuleClass.ResolveAttributes): Resolves DefaultCharSetAttribute.
+
+ * decl.cs (Decl.TypeAttr): New protected virtual. Returns default
+ charset from module.
+
+ * delegate.cs (TypeAttr): Override.
+ (Delegate.DefineType): Use this TypeAttr.
+
+ * driver.cs (Driver.MainDriver): Call Module.ResolveAttributes
+ at very early stage (before types are defined) to resolve model
+ module attributes. It will probably not work with corlib but it
+ should be ok.
+
+ * enum.cs (Enum.TypeAttr): New protected virtual. Returns default
+ charset from module.
+
+ * typemanager.cs (default_charset_type): New type.
+
2005-04-13 Raja R Harinath <[EMAIL PROTECTED]>
* decl.cs (MemberCache.AddMethods): Don't warn if
Modified: trunk/mcs/gmcs/attribute.cs
===================================================================
--- trunk/mcs/gmcs/attribute.cs 2005-04-19 19:09:54 UTC (rev 43283)
+++ trunk/mcs/gmcs/attribute.cs 2005-04-19 19:10:31 UTC (rev 43284)
@@ -85,8 +85,6 @@
static AttributeUsageAttribute DefaultUsageAttribute = new
AttributeUsageAttribute (AttributeTargets.All);
- CustomAttributeBuilder cb;
-
// non-null if named args present after Resolve () is called
PropertyInfo [] prop_info_arr;
FieldInfo [] field_info_arr;
@@ -156,6 +154,12 @@
"Could not find a constructor for this
argument list.");
}
+
+ protected virtual FullNamedExpression ResolveAsTypeStep
(Expression expr, EmitContext ec)
+ {
+ return expr.ResolveAsTypeStep (ec);
+ }
+
void ResolvePossibleAttributeTypes (EmitContext ec, out Type
t1, out Type t2)
{
t1 = null;
@@ -165,12 +169,12 @@
FullNamedExpression n2 = null;
string IdentifierAttribute = Identifier + "Attribute";
if (LeftExpr == null) {
- n1 = new SimpleName (Identifier,
Location).ResolveAsTypeStep (ec);
+ n1 = ResolveAsTypeStep (new SimpleName
(Identifier, Location), ec);
// FIXME: Shouldn't do this for quoted
attributes: [EMAIL PROTECTED]
- n2 = new SimpleName (IdentifierAttribute,
Location).ResolveAsTypeStep (ec);
+ n2 = ResolveAsTypeStep (new SimpleName
(IdentifierAttribute, Location), ec);
} else {
- FullNamedExpression l =
LeftExpr.ResolveAsTypeStep (ec);
+ FullNamedExpression l = ResolveAsTypeStep
(LeftExpr, ec);
if (l == null) {
Report.Error (246, Location, "Couldn't
find namespace or type '{0}'", LeftExpr);
return;
@@ -300,18 +304,19 @@
// Cache for parameter-less attributes
static PtrHashtable att_cache = new PtrHashtable ();
- public virtual CustomAttributeBuilder Resolve (EmitContext ec)
+ public CustomAttributeBuilder Resolve (EmitContext ec)
{
if (resolve_error)
return null;
resolve_error = true;
- if (Type == null)
+ if (Type == null) {
Type = CheckAttributeType (ec);
- if (Type == null)
- return null;
+ if (Type == null)
+ return null;
+ }
if (Type.IsAbstract) {
Report.Error (653, Location, "Cannot apply
attribute class '{0}' because it is abstract", Name);
@@ -326,6 +331,34 @@
}
}
+ ConstructorInfo ctor = ResolveArguments (ec);
+ CustomAttributeBuilder cb;
+
+ try {
+ if (prop_info_arr != null || field_info_arr !=
null) {
+ cb = new CustomAttributeBuilder (
+ ctor, pos_values,
+ prop_info_arr, prop_values_arr,
+ field_info_arr,
field_values_arr);
+ } else {
+ cb = new CustomAttributeBuilder (
+ ctor, pos_values);
+
+ if (pos_values.Length == 0)
+ att_cache.Add (Type, cb);
+ }
+ }
+ catch (Exception) {
+ Error_AttributeArgumentNotValid (Location);
+ return null;
+ }
+
+ resolve_error = false;
+ return cb;
+ }
+
+ protected virtual ConstructorInfo ResolveArguments (EmitContext
ec)
+ {
// Now we extract the positional and named arguments
ArrayList pos_args = null;
@@ -563,44 +596,20 @@
pos_values = new_pos_values;
}
- try {
- if (named_arg_count > 0) {
- prop_info_arr = new PropertyInfo
[prop_infos.Count];
- field_info_arr = new FieldInfo
[field_infos.Count];
- field_values_arr = new object
[field_values.Count];
- prop_values_arr = new object
[prop_values.Count];
+ if (named_arg_count > 0) {
+ prop_info_arr = new PropertyInfo
[prop_infos.Count];
+ field_info_arr = new FieldInfo
[field_infos.Count];
+ field_values_arr = new object
[field_values.Count];
+ prop_values_arr = new object
[prop_values.Count];
- field_infos.CopyTo (field_info_arr, 0);
- field_values.CopyTo (field_values_arr,
0);
+ field_infos.CopyTo (field_info_arr, 0);
+ field_values.CopyTo (field_values_arr, 0);
- prop_values.CopyTo (prop_values_arr,
0);
- prop_infos.CopyTo (prop_info_arr, 0);
+ prop_values.CopyTo (prop_values_arr, 0);
+ prop_infos.CopyTo (prop_info_arr, 0);
+ }
- cb = new CustomAttributeBuilder (
- (ConstructorInfo) constructor,
pos_values,
- prop_info_arr, prop_values_arr,
- field_info_arr,
field_values_arr);
- }
- else {
- cb = new CustomAttributeBuilder (
- (ConstructorInfo) constructor,
pos_values);
-
- if (pos_values.Length == 0)
- att_cache.Add (Type, cb);
- }
- } catch (Exception) {
- //
- // Sample:
- // using System.ComponentModel;
- // [DefaultValue (CollectionChangeAction.Add)]
- // class X { static void Main () {} }
- //
- Error_AttributeArgumentNotValid (Location);
- return null;
- }
-
- resolve_error = false;
- return cb;
+ return (ConstructorInfo) constructor;
}
/// <summary>
@@ -990,6 +999,11 @@
}
}
+ public CharSet GetCharSetValue ()
+ {
+ return (CharSet)System.Enum.Parse (typeof (CharSet),
pos_values [0].ToString ());
+ }
+
public MethodImplOptions GetMethodImplOptions ()
{
return (MethodImplOptions)System.Enum.Parse (typeof
(MethodImplOptions), pos_values [0].ToString ());
@@ -1092,7 +1106,7 @@
// Default settings
CallingConvention cc = CallingConvention.Winapi;
- CharSet charset = CharSet.Ansi;
+ CharSet charset = CodeGen.Module.DefaultCharSet;
bool preserve_sig = true;
string entry_point = name;
bool best_fit_mapping = false;
@@ -1240,20 +1254,26 @@
RootContext.Tree.Types.NamespaceEntry = null;
}
- public override Type ResolveType (EmitContext ec)
+ protected override FullNamedExpression ResolveAsTypeStep
(Expression expr, EmitContext ec)
{
- Enter ();
- Type retval = base.ResolveType (ec);
- Leave ();
- return retval;
+ try {
+ Enter ();
+ return base.ResolveAsTypeStep (expr, ec);
+ }
+ finally {
+ Leave ();
+ }
}
- public override CustomAttributeBuilder Resolve (EmitContext ec)
+ protected override ConstructorInfo ResolveArguments
(EmitContext ec)
{
- Enter ();
- CustomAttributeBuilder retval = base.Resolve (ec);
- Leave ();
- return retval;
+ try {
+ Enter ();
+ return base.ResolveArguments (ec);
+ }
+ finally {
+ Leave ();
+ }
}
}
Modified: trunk/mcs/gmcs/class.cs
===================================================================
--- trunk/mcs/gmcs/class.cs 2005-04-19 19:09:54 UTC (rev 43283)
+++ trunk/mcs/gmcs/class.cs 2005-04-19 19:10:31 UTC (rev 43284)
@@ -827,9 +827,9 @@
}
}
- public virtual TypeAttributes TypeAttr {
+ protected override TypeAttributes TypeAttr {
get {
- return Modifiers.TypeAttr (ModFlags, this);
+ return Modifiers.TypeAttr (ModFlags, this) |
base.TypeAttr;
}
}
@@ -2759,7 +2759,7 @@
return PendingImplementation.GetPendingImplementations
(this);
}
- public override TypeAttributes TypeAttr {
+ protected override TypeAttributes TypeAttr {
get {
return base.TypeAttr | DefaultTypeAttributes;
}
@@ -3020,7 +3020,7 @@
return tb;
}
- public override TypeAttributes TypeAttr {
+ protected override TypeAttributes TypeAttr {
get {
return base.TypeAttr | TypeAttributes.Abstract
| TypeAttributes.Sealed;
}
@@ -3121,7 +3121,7 @@
// FIXME: How do we deal with the user specifying a different
// layout?
//
- public override TypeAttributes TypeAttr {
+ protected override TypeAttributes TypeAttr {
get {
return base.TypeAttr | DefaultTypeAttributes;
}
@@ -3166,7 +3166,7 @@
// in some cases (Sealed for example is mandatory for a class,
// but what SequentialLayout can be changed
//
- public override TypeAttributes TypeAttr {
+ protected override TypeAttributes TypeAttr {
get {
return base.TypeAttr | DefaultTypeAttributes;
}
@@ -3212,7 +3212,7 @@
TypeAttributes.Abstract |
TypeAttributes.Interface;
- public override TypeAttributes TypeAttr {
+ protected override TypeAttributes TypeAttr {
get {
return base.TypeAttr | DefaultTypeAttributes;
}
Modified: trunk/mcs/gmcs/codegen.cs
===================================================================
--- trunk/mcs/gmcs/codegen.cs 2005-04-19 19:09:54 UTC (rev 43283)
+++ trunk/mcs/gmcs/codegen.cs 2005-04-19 19:10:31 UTC (rev 43284)
@@ -1067,7 +1067,7 @@
OptAttributes.Emit (ec, this);
}
- protected Attribute GetClsCompliantAttribute ()
+ protected Attribute ResolveAttribute (Type a_type)
{
if (OptAttributes == null)
return null;
@@ -1077,7 +1077,7 @@
return null;
EmitContext temp_ec = new EmitContext
(RootContext.Tree.Types, Mono.CSharp.Location.Null, null, null, 0, false);
- Attribute a = OptAttributes.Search
(TypeManager.cls_compliant_attribute_type, temp_ec);
+ Attribute a = OptAttributes.Search (a_type, temp_ec);
if (a != null) {
a.Resolve (temp_ec);
}
@@ -1120,7 +1120,7 @@
public void ResolveClsCompliance ()
{
- ClsCompliantAttribute = GetClsCompliantAttribute ();
+ ClsCompliantAttribute = ResolveAttribute
(TypeManager.cls_compliant_attribute_type);
if (ClsCompliantAttribute == null)
return;
@@ -1328,6 +1328,9 @@
public ModuleBuilder Builder;
bool m_module_is_unsafe;
+ public CharSet DefaultCharSet = CharSet.Ansi;
+ public TypeAttributes DefaultCharSetType =
TypeAttributes.AnsiClass;
+
static string[] attribute_targets = new string [] { "module" };
public ModuleClass (bool is_unsafe)
@@ -1377,6 +1380,33 @@
Builder.SetCustomAttribute (customBuilder);
}
+ /// <summary>
+ /// It is called very early therefore can resolve only
predefined attributes
+ /// </summary>
+ public void ResolveAttributes ()
+ {
+#if NET_2_0
+ Attribute a = ResolveAttribute
(TypeManager.default_charset_type);
+ if (a != null) {
+ DefaultCharSet = a.GetCharSetValue ();
+ switch (DefaultCharSet) {
+ case CharSet.Ansi:
+ case CharSet.None:
+ break;
+ case CharSet.Auto:
+ DefaultCharSetType =
TypeAttributes.AutoClass;
+ break;
+ case CharSet.Unicode:
+ DefaultCharSetType =
TypeAttributes.UnicodeClass;
+ break;
+ default:
+ Report.Error (1724, a.Location,
"Value specified for the argument to
'System.Runtime.InteropServices.DefaultCharSetAttribute' is not valid");
+ break;
+ }
+ }
+#endif
+ }
+
public override string[] ValidAttributeTargets {
get {
return attribute_targets;
Modified: trunk/mcs/gmcs/decl.cs
===================================================================
--- trunk/mcs/gmcs/decl.cs 2005-04-19 19:09:54 UTC (rev 43283)
+++ trunk/mcs/gmcs/decl.cs 2005-04-19 19:10:31 UTC (rev 43284)
@@ -765,6 +765,12 @@
}
}
+ protected virtual TypeAttributes TypeAttr {
+ get {
+ return CodeGen.Module.DefaultCharSetType;
+ }
+ }
+
/// <remarks>
/// Should be overriten by the appropriate declaration space
/// </remarks>
Modified: trunk/mcs/gmcs/delegate.cs
===================================================================
--- trunk/mcs/gmcs/delegate.cs 2005-04-19 19:09:54 UTC (rev 43283)
+++ trunk/mcs/gmcs/delegate.cs 2005-04-19 19:10:31 UTC (rev 43284)
@@ -87,9 +87,6 @@
return null;
}
- TypeAttributes attr = Modifiers.TypeAttr (ModFlags,
IsTopLevel) |
- TypeAttributes.Class | TypeAttributes.Sealed;
-
if (TypeManager.multicast_delegate_type == null &&
!RootContext.StdLib) {
Namespace system = Namespace.LookupNamespace
("System", true);
TypeExpr expr = system.Lookup (this,
"MulticastDelegate", Location) as TypeExpr;
@@ -109,13 +106,13 @@
ModuleBuilder builder = CodeGen.Module.Builder;
TypeBuilder = builder.DefineType (
- Name, attr,
TypeManager.multicast_delegate_type);
+ Name, TypeAttr,
TypeManager.multicast_delegate_type);
} else {
TypeBuilder builder = Parent.TypeBuilder;
string name = Name.Substring (1 +
Name.LastIndexOf ('.'));
TypeBuilder = builder.DefineNestedType (
- name, attr,
TypeManager.multicast_delegate_type);
+ name, TypeAttr,
TypeManager.multicast_delegate_type);
}
TypeManager.AddDelegateType (Name, TypeBuilder, this);
@@ -437,6 +434,14 @@
base.Emit ();
}
+ protected override TypeAttributes TypeAttr {
+ get {
+ return Modifiers.TypeAttr (ModFlags,
IsTopLevel) |
+ TypeAttributes.Class |
TypeAttributes.Sealed |
+ base.TypeAttr;
+ }
+ }
+
public override string[] ValidAttributeTargets {
get {
return attribute_targets;
Modified: trunk/mcs/gmcs/driver.cs
===================================================================
--- trunk/mcs/gmcs/driver.cs 2005-04-19 19:09:54 UTC (rev 43283)
+++ trunk/mcs/gmcs/driver.cs 2005-04-19 19:10:31 UTC (rev 43284)
@@ -1545,6 +1545,8 @@
if (timestamps)
ShowTime (" Core Types done");
+ CodeGen.Module.ResolveAttributes ();
+
//
// The second pass of the compiler
//
Modified: trunk/mcs/gmcs/enum.cs
===================================================================
--- trunk/mcs/gmcs/enum.cs 2005-04-19 19:09:54 UTC (rev 43283)
+++ trunk/mcs/gmcs/enum.cs 2005-04-19 19:10:31 UTC (rev 43284)
@@ -180,13 +180,9 @@
if (TypeBuilder != null)
return TypeBuilder;
- TypeAttributes attr = Modifiers.TypeAttr (ModFlags,
IsTopLevel);
-
ec = new EmitContext (this, this, Location, null, null,
ModFlags, false);
ec.InEnumContext = true;
- attr |= TypeAttributes.Class | TypeAttributes.Sealed;
-
if (!(BaseType is TypeLookupExpression)) {
Report.Error (1008, Location,
"Type byte, sbyte, short, ushort,
int, uint, " +
@@ -221,12 +217,12 @@
ModuleBuilder builder = CodeGen.Module.Builder;
- TypeBuilder = builder.DefineType (Name, attr,
TypeManager.enum_type);
+ TypeBuilder = builder.DefineType (Name,
TypeAttr, TypeManager.enum_type);
} else {
TypeBuilder builder = Parent.TypeBuilder;
TypeBuilder = builder.DefineNestedType (
- Basename, attr, TypeManager.enum_type);
+ Basename, TypeAttr,
TypeManager.enum_type);
}
ec.ContainerType = TypeBuilder;
@@ -729,6 +725,15 @@
}
}
+ protected override TypeAttributes TypeAttr {
+ get {
+ return Modifiers.TypeAttr (ModFlags,
IsTopLevel) |
+ TypeAttributes.Class | TypeAttributes.Sealed |
+ base.TypeAttr;
+ }
+ }
+
+
protected override void VerifyObsoleteAttribute()
{
// UnderlyingType is never obsolete
Modified: trunk/mcs/gmcs/rootcontext.cs
===================================================================
--- trunk/mcs/gmcs/rootcontext.cs 2005-04-19 19:09:54 UTC (rev 43283)
+++ trunk/mcs/gmcs/rootcontext.cs 2005-04-19 19:10:31 UTC (rev 43284)
@@ -399,6 +399,7 @@
"System.Runtime.InteropServices.OutAttribute",
"System.Runtime.InteropServices.StructLayoutAttribute",
"System.Runtime.InteropServices.FieldOffsetAttribute",
+
"System.Runtime.InteropServices.DefaultCharSetAttribute",
"System.InvalidOperationException",
"System.NotSupportedException",
"System.MarshalByRefObject",
Modified: trunk/mcs/gmcs/typemanager.cs
===================================================================
--- trunk/mcs/gmcs/typemanager.cs 2005-04-19 19:09:54 UTC (rev 43283)
+++ trunk/mcs/gmcs/typemanager.cs 2005-04-19 19:10:31 UTC (rev 43284)
@@ -104,6 +104,7 @@
///
static internal Type compiler_generated_attr_type;
static internal Type fixed_buffer_attr_type;
+ static internal Type default_charset_type;
//
// An empty array of types
@@ -1188,6 +1189,7 @@
//
compiler_generated_attr_type = CoreLookupType
("System.Runtime.CompilerServices.CompilerGeneratedAttribute");
fixed_buffer_attr_type = CoreLookupType
("System.Runtime.CompilerServices.FixedBufferAttribute");
+ default_charset_type = CoreLookupType
("System.Runtime.InteropServices.DefaultCharSetAttribute");
//
// When compiling corlib, store the "real" types here.
//
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches