Procházet zdrojové kódy

Add new classes to get rid of the warnings being emitted by the
interpreter (although new warning are now there, we need to get the
Decimal internalcalls in place).

Implement some bits of CultureInfo, but it is yet far from finished.

svn path=/trunk/mcs/; revision=1205

Miguel de Icaza před 24 roky
rodič
revize
4cd8207aae
19 změnil soubory, kde provedl 670 přidání a 38 odebrání
  1. 8 0
      mcs/class/corlib/System.Globalization/ChangeLog
  2. 124 2
      mcs/class/corlib/System.Globalization/CultureInfo.cs
  3. 45 35
      mcs/class/corlib/System.Globalization/NumberFormatInfo.cs
  4. 19 0
      mcs/class/corlib/System.Runtime.Remoting.Activation/ActivatorLevel.cs
  5. 24 0
      mcs/class/corlib/System.Runtime.Remoting.Activation/IActivator.cs
  6. 36 0
      mcs/class/corlib/System.Runtime.Remoting.Activation/IConstructionCallMessage.cs
  7. 17 0
      mcs/class/corlib/System.Runtime.Remoting.Activation/IConstructionReturnMessage.cs
  8. 72 0
      mcs/class/corlib/System.Runtime.Remoting.Contexts/Context.cs
  9. 95 0
      mcs/class/corlib/System.Runtime.Remoting.Contexts/ContextAttribute.cs
  10. 20 0
      mcs/class/corlib/System.Runtime.Remoting.Contexts/IContextAttribute.cs
  11. 23 0
      mcs/class/corlib/System.Runtime.Remoting.Contexts/IContextProperty.cs
  12. 20 0
      mcs/class/corlib/System.Runtime.Remoting.Contexts/IDynamicMessageSink.cs
  13. 19 0
      mcs/class/corlib/System.Runtime.Remoting.Contexts/IDynamicProperty.cs
  14. 21 0
      mcs/class/corlib/System.Runtime.Remoting.Contexts/SynchronizationAttribute.cs
  15. 20 0
      mcs/class/corlib/System.Runtime.Remoting.Messaging/IMessage.cs
  16. 55 0
      mcs/class/corlib/System.Runtime.Remoting.Messaging/IMethodMessage.cs
  17. 22 0
      mcs/class/corlib/System.Runtime.Remoting.Messaging/IMethodReturnMessage.cs
  18. 23 0
      mcs/class/corlib/System/ContextBoundObject.cs
  19. 7 1
      mcs/class/corlib/System/Type.cs

+ 8 - 0
mcs/class/corlib/System.Globalization/ChangeLog

@@ -1,3 +1,11 @@
+2001-10-26  Miguel de Icaza  <[email protected]>
+
+	* NumberFormatInfo.cs: Provide an internal constructor that takes
+	as an argument a CultureInfo ID (LCID) so that we can construct
+	different ones here.
+
+	* CultureInfo.cs: Begun implementation.
+
 2001-10-09  Derek Holden  <[email protected]>
 
 	* NumberFormatInfo.cs: Small typo in PercentPositivePattern

+ 124 - 2
mcs/class/corlib/System.Globalization/CultureInfo.cs

@@ -1,12 +1,134 @@
 // System.Globalization.CultureInfo
 //
-// Sean MacIsaac (macisaac@ximian.com)
+// Miguel de Icaza (miguel@ximian.com)
 //
-// (C) Ximian, Inc. 2001
+// (C) Ximian, Inc. 2001 (http://www.ximian.com)
 
 namespace System.Globalization
 {
 	public class CultureInfo
 	{
+		static CultureInfo invariant_culture_info;
+		bool is_read_only;
+		int  lcid;
+		bool use_user_override;
+		NumberFormatInfo number_format;
+		
+		// <summary>
+		//   Returns the Invariant Culture Information ("iv")
+		// </summary>
+		static public CultureInfo InvariantCulture {
+			get {
+				if (invariant_culture_info != null)
+					return invariant_culture_info;
+				
+				invariant_culture_info = new CultureInfo (0x07f, false);
+				invariant_culture_info.is_read_only = true;
+				
+				return invariant_culture_info;
+			}
+		}
+
+		// <summary>
+		//   Creates a CultureInfo for a specific ID
+		// </summary>
+		public static CultureInfo CreateSpecificCulture (string name)
+		{
+			switch (name){
+			case "iv":
+				return InvariantCulture;
+
+			default:
+				throw new ArgumentException ("CreateSpecificCultureName");
+			}
+		}
+
+		public virtual int LCID {
+			get {
+				return lcid;
+			}
+		}
+
+		// <summary>
+		//   Gets the string-encoded name of the culture
+		// </summary>
+		public virtual string Name {
+			get {
+				switch (lcid){
+				case 0x007f:
+					return "iv";
+				}
+				throw new Exception ("Miss constructed object for LCID: " + lcid);
+			}
+		}
+
+		// <summary>
+		//   Returns whether the current culture is neutral (neutral cultures
+		//   only specify a language, not a country.
+		// </summary>
+		public virtual bool IsNeutralCulture {
+			get {
+				return (lcid & 0xff00) == 0;
+			}
+		}
+		// <summary>
+		//   Returns the NumberFormat for the current lcid
+		// </summary>
+		public virtual NumberFormatInfo NumberFormat {
+			get {
+				if (number_format == null){
+					lock (this){
+						if (number_format == null)
+							number_format = new NumberFormatInfo (lcid);
+					}
+				}
+
+				return number_format;
+			}
+
+			set {
+				if (is_read_only)
+					return;
+
+				if (value == null)
+					throw new ArgumentNullException ("NumberFormat");
+				
+				number_format = value;
+			}
+		}
+		
+		public CultureInfo (int code, bool use_user_override)
+		{
+			switch (lcid){
+			case 0x007f: // iv    Invariant
+			case 0x0036: // af    Afrikaans
+			case 0x0436: // af-ZA Afrikaans - South Africa
+			case 0x001c: // sq    Albanian
+			case 0x041c: // sq-AL Albanian  - Albania
+			case 0x0001: // ar    Arabic
+			case 0x1401: // ar-DZ Arabic    - Algeria
+			case 0x3c01: // ar-BH Arabic    - Barhain
+			case 0x0c01: // ar-EG Arabic    - Egypt
+			case 0x0801: // ar-IQ Arabic    - Iraq
+			case 0x2c01: // ar-JO Arabic    - Jordan
+			case 0x3401: // ar-KQ Arabic    - Kuwait
+			case 0x3001: // ar-LB Arabic    - Lebanon
+			case 0x1001: // ar-LY Arabic    - Libya
+			case 0x1801: // ar-MA Arabic    - Morocco
+			case 0x2001: // ar-OM Arabic    - Oman
+			case 0x4001: // ar-QA Arabic    - Qatar
+			case 0x0401: // ar-SA Arabic    - Saudi Arabia
+			case 0x2801: // ar-SY Arabic    - Syria
+			case 0x1c01: // ar-TN Arabic    - Tunisia
+			case 0x3801: // ar-AE Arabic    - United Arab Emirates
+			case 0x2401: // ar-YE Arabic    - Yemen
+				lcid = code;
+				this.use_user_override = use_user_override;
+				break;
+
+			default:
+				throw new ArgumentException ("CultureInfoCode");
+			}
+		}
 	}
 }

+ 45 - 35
mcs/class/corlib/System.Globalization/NumberFormatInfo.cs

@@ -56,42 +56,52 @@ namespace System.Globalization {
 		private string positiveInfinitySymbol;
 		private string positiveSign;
 
-		public NumberFormatInfo ()
+		internal NumberFormatInfo (int lcid)
+		{
+			switch (lcid){
+
+				// The Invariant Culture Info ID.
+			case 0x007f:
+				readOnly = false;
+				
+				// Currency Related Format Info
+				currencyDecimalDigits =       2;
+				currencyDecimalSeparator =    ".";
+				currencyGroupSeparator =      ",";
+				currencyGroupSizes =          new int[1] { 3 };
+				currencyNegativePattern =     0;
+				currencyPositivePattern =     0;
+				currencySymbol =              "$";
+				
+				naNSymbol =                   "NaN";
+				negativeInfinitySymbol =      "-Infinity";
+				negativeSign =                "-";
+				
+				// Number Related Format Info
+				numberDecimalDigits =         2;
+				numberDecimalSeparator =      ".";
+				numberGroupSeparator =        ",";
+				numberGroupSizes =            new int[1] { 3 };
+				numberNegativePattern =       0;
+				
+				// Percent Related Format Info
+				percentDecimalDigits =        2;
+				percentDecimalSeparator =     ".";
+				percentGroupSeparator =       ",";
+				percentGroupSizes =           new int[1] { 3 };
+				percentNegativePattern =      0;
+				percentPositivePattern =      0;
+				percentSymbol=                "%";
+				
+				perMilleSymbol =              "\u2030";
+				positiveInfinitySymbol =      "Infinity";
+				positiveSign =                "+";
+				break;
+			}
+		}
+		
+		public NumberFormatInfo () : this (0x007f)
 		{
-			readOnly = false;
-
-			// Currency Related Format Info
-			currencyDecimalDigits =       2;
-			currencyDecimalSeparator =    ".";
-			currencyGroupSeparator =      ",";
-			currencyGroupSizes =          new int[1] { 3 };
-			currencyNegativePattern =     0;
-			currencyPositivePattern =     0;
-			currencySymbol =              "$";
-
-			naNSymbol =                   "NaN";
-			negativeInfinitySymbol =      "-Infinity";
-			negativeSign =                "-";
-
-			// Number Related Format Info
-			numberDecimalDigits =         2;
-			numberDecimalSeparator =      ".";
-			numberGroupSeparator =        ",";
-			numberGroupSizes =            new int[1] { 3 };
-			numberNegativePattern =       0;
-
-			// Percent Related Format Info
-			percentDecimalDigits =        2;
-			percentDecimalSeparator =     ".";
-			percentGroupSeparator =       ",";
-			percentGroupSizes =           new int[1] { 3 };
-			percentNegativePattern =      0;
-			percentPositivePattern =      0;
-			percentSymbol=                "%";
-			
-			perMilleSymbol =              "\u2030";
-			positiveInfinitySymbol =      "Infinity";
-			positiveSign =                "+";
 		}
 				
 		// =========== Currency Format Properties =========== //

+ 19 - 0
mcs/class/corlib/System.Runtime.Remoting.Activation/ActivatorLevel.cs

@@ -0,0 +1,19 @@
+//
+// System.Runtime.Remoting.Contexts.ActivatorLevel..cs
+//
+// Author:
+//   Miguel de Icaza ([email protected])
+//
+// (C) Ximian, Inc.  http://www.ximian.com
+//
+
+namespace System.Runtime.Remoting.Activation {
+
+	public enum ActivatorLevel  {
+		Construction = 4,
+		Context = 8,
+		AppDomain = 12,
+		Process = 16,
+		Machine = 20,
+	}
+}

+ 24 - 0
mcs/class/corlib/System.Runtime.Remoting.Activation/IActivator.cs

@@ -0,0 +1,24 @@
+//
+// System.Runtime.Remoting.Contexts.IActivator..cs
+//
+// Author:
+//   Miguel de Icaza ([email protected])
+//
+// (C) Ximian, Inc.  http://www.ximian.com
+//
+
+namespace System.Runtime.Remoting.Activation {
+
+	public interface IActivator {
+		ActivatorLevel Level {
+			get;
+		}
+
+		IActivator NextActivator {
+			get; set;
+		}
+
+		IConstructionReturnMessage Activate (IConstructionCallMessage msg);
+	}
+}
+

+ 36 - 0
mcs/class/corlib/System.Runtime.Remoting.Activation/IConstructionCallMessage.cs

@@ -0,0 +1,36 @@
+//
+// System.Runtime.Remoting.Activation.IConstructionCallMessage.cs
+//
+// Author:
+//   Miguel de Icaza ([email protected])
+//
+// (C) Ximian, Inc.  http://www.ximian.com
+//
+
+using System.Collections;
+
+namespace System.Runtime.Remoting.Activation {
+
+	public interface IConstructionCallMessage {
+		Type ActivationType {
+			get;
+		}
+
+		string ActivationTypeName {
+			get;
+		}
+
+		IActivator Activator {
+			get;
+			set;
+		}
+
+		object [] CallSiteActivationAttributes {
+			get;
+		}
+
+		IList ContextProperties {
+			get;
+		}
+	}
+}

+ 17 - 0
mcs/class/corlib/System.Runtime.Remoting.Activation/IConstructionReturnMessage.cs

@@ -0,0 +1,17 @@
+//
+// System.Runtime.Remoting.Contexts.IConstructionReturnMessage..cs
+//
+// Author:
+//   Miguel de Icaza ([email protected])
+//
+// (C) Ximian, Inc.  http://www.ximian.com
+//
+
+using System.Runtime.Remoting.Messaging;
+
+namespace System.Runtime.Remoting.Activation {
+
+	public interface IConstructionReturnMessage :IMethodReturnMessage, IMethodMessage, IMessage {
+	}
+}
+

+ 72 - 0
mcs/class/corlib/System.Runtime.Remoting.Contexts/Context.cs

@@ -0,0 +1,72 @@
+//
+// System.Runtime.Remoting.Contexts.Context..cs
+//
+// Author:
+//   Miguel de Icaza ([email protected])
+//
+// (C) Ximian, Inc.  http://www.ximian.com
+//
+
+using System.Collections;
+
+namespace System.Runtime.Remoting.Contexts {
+
+	public class Context {
+		static Context default_context;
+		ArrayList context_properties;
+		int context_id;
+		bool frozen;
+		static int global_count;
+		
+		static Context ()
+		{
+			default_context = new Context ();
+			default_context.frozen = true;
+		}
+		
+		public Context ()
+		{
+			context_id = global_count++;
+		}
+
+		public static Context DefaultContext {
+			get {
+				return default_context;
+			}
+		}
+
+		public virtual int ContextID {
+			get {
+				return context_id;
+			}
+		}
+
+		public IContextProperty GetProperty (string name)
+		{
+			if (context_properties == null)
+				return null;
+
+			foreach (IContextProperty p in context_properties)
+				if (p.Name == name)
+					return p;
+			
+			return null;
+		}
+
+		public void SetProperty (IContextProperty prop)
+		{
+			if (prop == null)
+				throw new ArgumentNullException ("IContextProperty");
+			if (this == default_context)
+				throw new InvalidOperationException ("Can not add properties to " +
+								     "default context");
+			if (frozen)
+				throw new InvalidOperationException ("Context is Frozen");
+			
+			if (context_properties == null)
+				context_properties = new ArrayList ();
+
+			context_properties.Add (prop);
+		}
+	}
+}

+ 95 - 0
mcs/class/corlib/System.Runtime.Remoting.Contexts/ContextAttribute.cs

@@ -0,0 +1,95 @@
+//
+// System.Runtime.Remoting.Contexts.ContextAttribute..cs
+//
+// Author:
+//   Miguel de Icaza ([email protected])
+//
+// (C) Ximian, Inc.  http://www.ximian.com
+//
+
+using System.Runtime.Remoting.Activation;
+using System.Collections;
+
+namespace System.Runtime.Remoting.Contexts {
+
+	[AttributeUsage (AttributeTargets.Class)]
+	public class ContextAttribute : Attribute, IContextAttribute, IContextProperty {
+		protected string AttributeName;
+
+		public virtual string Name {
+			get {
+				return AttributeName;
+			}
+		}
+
+		public override bool Equals (object o)
+		{
+			if (o == null)
+				return false;
+
+			if (!(o is ContextAttribute))
+				return false;
+
+			ContextAttribute ca = (ContextAttribute) o;
+			
+			if (ca.AttributeName != AttributeName)
+				return false;
+
+			return true;
+		}
+
+		public virtual void Freeze (Context ctx)
+		{
+		}
+
+		public override int GetHashCode ()
+		{
+			if (AttributeName == null)
+				return 0;
+			
+			return AttributeName.GetHashCode ();
+		}
+
+		/// <summary>
+		///    Adds the current context property to the IConstructionCallMessage
+		/// </summary>
+		public void GetPropertiesForNewContext (IConstructionCallMessage msg)
+		{
+			if (msg == null)
+				throw new ArgumentNullException ("IConstructionCallMessage");
+
+			IList list = msg.ContextProperties;
+
+			list.Add (this);
+		}
+
+		// <summary>
+		//   True whether the context arguments satisfies the requirements
+		//   of the current context.
+		// </summary>
+		public bool IsContextOK (Context ctx, IConstructionCallMessage msg)
+		{
+			if (msg == null)
+				throw new ArgumentNullException ("IConstructionCallMessage");
+			if (ctx == null)
+				throw new ArgumentNullException ("Context");
+
+			if (!msg.ActivationType.IsContextful)
+				return true;
+
+			IContextProperty p = ctx.GetProperty (AttributeName);
+			if (p == null)
+				return false;
+
+			if (this != p)
+				return false;
+				
+			return true;
+		}
+
+		public bool IsNewContextOK (Context ctx)
+		{
+			return true;
+		}
+	}
+}

+ 20 - 0
mcs/class/corlib/System.Runtime.Remoting.Contexts/IContextAttribute.cs

@@ -0,0 +1,20 @@
+//
+// System.Runtime.Remoting.Contexts.IContextAttribute..cs
+//
+// Author:
+//   Miguel de Icaza ([email protected])
+//
+// (C) Ximian, Inc.  http://www.ximian.com
+//
+
+using System.Runtime.Remoting.Activation;
+
+namespace System.Runtime.Remoting.Contexts {
+
+	public interface IContextAttribute {
+
+		void GetPropertiesForNewContext (IConstructionCallMessage msg);
+
+		bool IsContextOK (Context ctx, IConstructionCallMessage msg);
+	}
+}

+ 23 - 0
mcs/class/corlib/System.Runtime.Remoting.Contexts/IContextProperty.cs

@@ -0,0 +1,23 @@
+//
+// System.Runtime.Remoting.Contexts.IContextProperty..cs
+//
+// Author:
+//   Miguel de Icaza ([email protected])
+//
+// (C) Ximian, Inc.  http://www.ximian.com
+//
+
+
+namespace System.Runtime.Remoting.Contexts {
+
+	public interface IContextProperty {
+
+		string Name {
+			get;
+		}
+
+		void Freeze (Context ctx);
+
+		bool IsNewContextOK (Context ctx);
+	}
+}

+ 20 - 0
mcs/class/corlib/System.Runtime.Remoting.Contexts/IDynamicMessageSink.cs

@@ -0,0 +1,20 @@
+//
+// System.Runtime.Remoting.Contexts.IDynamicMessageSink..cs
+//
+// Author:
+//   Miguel de Icaza ([email protected])
+//
+// (C) Ximian, Inc.  http://www.ximian.com
+//
+
+using System.Runtime.Remoting.Messaging;
+
+namespace System.Runtime.Remoting.Contexts {
+
+	public interface IDynamicMessageSink {
+
+		void ProcessMessageFinish (IMessage reply_msg, bool client_site, bool async);
+
+		void ProcessMessageStart  (IMessage req_msg, bool client_site, bool async);
+	}
+}

+ 19 - 0
mcs/class/corlib/System.Runtime.Remoting.Contexts/IDynamicProperty.cs

@@ -0,0 +1,19 @@
+//
+// System.Runtime.Remoting.Contexts.IDynamicProperty..cs
+//
+// Author:
+//   Miguel de Icaza ([email protected])
+//
+// (C) Ximian, Inc.  http://www.ximian.com
+//
+
+
+namespace System.Runtime.Remoting.Contexts {
+
+	public interface IDynamicProperty {
+
+		string Name {
+			get;
+		}
+	}
+}

+ 21 - 0
mcs/class/corlib/System.Runtime.Remoting.Contexts/SynchronizationAttribute.cs

@@ -0,0 +1,21 @@
+//
+// System.Runtime.Remoting.Contexts.SynchronizationAttribute..cs
+//
+// Author:
+//   Miguel de Icaza ([email protected])
+//
+// (C) Ximian, Inc.  http://www.ximian.com
+//
+
+
+using System.Runtime.Remoting.Messaging;
+
+namespace System.Runtime.Remoting.Contexts {
+
+	public interface SynchronizationAttribute {
+
+		void ProcessMessageFinish (IMessage reply_msg, bool client_site, bool async);
+
+		void ProcessMessageStart  (IMessage req_msg, bool client_site, bool async);
+	}
+}

+ 20 - 0
mcs/class/corlib/System.Runtime.Remoting.Messaging/IMessage.cs

@@ -0,0 +1,20 @@
+//
+// System.Runtime.Remoting.Messaging.IMessage.cs
+//
+// Author:
+//   Miguel de Icaza ([email protected])
+//
+// (C) Ximian, Inc.  http://www.ximian.com
+//
+
+using System.Collections;
+
+namespace System.Runtime.Remoting.Messaging {
+
+	public interface IMessage {
+
+		IDictionary Properties {
+			get;
+		}
+	}
+}

+ 55 - 0
mcs/class/corlib/System.Runtime.Remoting.Messaging/IMethodMessage.cs

@@ -0,0 +1,55 @@
+//
+// System.Runtime.Remoting.Messaging.IMethodMessage..cs
+//
+// Author:
+//   Miguel de Icaza ([email protected])
+//
+// (C) Ximian, Inc.  http://www.ximian.com
+//
+
+using System.Reflection;
+
+namespace System.Runtime.Remoting.Messaging {
+
+	public interface IMethodMessage {
+		int       ArgCount        {
+			get;
+		}
+		
+		object [] Args            {
+			get;
+		}
+		
+		bool      HasVarArgs      {
+			get;
+		}
+
+		LogicalCallContext LogicalCalLContext {
+			get;
+		}
+
+		MethodBase MethodBase {
+			get;
+		}
+
+		string MethodName {
+			get;
+		}
+
+		object MethodSignature {
+			get;
+		}
+
+		string TypeName {
+			get;
+		}
+
+		string Uri {
+			get;
+		}
+
+		object GetArg     (int arg_num);
+		string GetArgName (int arg_num);
+	}
+}
+

+ 22 - 0
mcs/class/corlib/System.Runtime.Remoting.Messaging/IMethodReturnMessage.cs

@@ -0,0 +1,22 @@
+//
+// System.Runtime.Remoting.Messaging.IMethodReturnMessage..cs
+//
+// Author:
+//   Miguel de Icaza ([email protected])
+//
+// (C) Ximian, Inc.  http://www.ximian.com
+//
+
+namespace System.Runtime.Remoting.Messaging {
+
+	public interface IMethodReturnMessage {
+
+		Exception Exception   { get; }
+		int       OutArgCount { get; }
+		object [] OutArgs     { get; }
+		object    ReturnValue { get; }
+
+		object GetOutArg      (int arg_num);
+		string GetOutArgName  (int arg_num);
+	}
+}

+ 23 - 0
mcs/class/corlib/System/ContextBoundObject.cs

@@ -0,0 +1,23 @@
+//
+// System.ContextBoundObject.cs
+//
+// Author:
+//   Miguel de Icaza ([email protected])
+//
+// (C) Ximian, Inc.  http://www.ximian.com
+//
+// TODO: Mucho left to implement.
+//
+
+namespace System {
+
+	/// <summary>
+	///   Base class for all the context-bound classes
+	/// </summary>
+	public abstract class ContextBoundObject {
+
+		protected ContextBoundObject ()
+		{
+		}
+	}
+}

+ 7 - 1
mcs/class/corlib/System/Type.cs

@@ -154,7 +154,7 @@ namespace System {
 		public virtual bool IsAssignableFrom (Type c)
 		{
 			// FIXME
-			return false;
+			return true;
 		}
 
 		public virtual int GetArrayRank ()
@@ -178,5 +178,11 @@ namespace System {
 				return false;
 			}
 		}
+
+		public bool IsContextful {
+			get {
+				return typeof (ContextBoundObject).IsAssignableFrom (this);
+			}
+		}
 	}
 }