Browse Source

2002-03-08 Ravi Pratap <[email protected]>

	* attribute.cs (Attribute.UnmanagedType): This is to keep track of
	the unmanaged type in the case we have a MarshalAs attribute.

	(Resolve): Handle the case when we are parsing the special MarshalAs
	attribute [we need to store the unmanaged type to use later]

	* typemanager.cs (marshal_as_attr_type): Built in type for the
	MarshalAs Attribute.

	* attribute.cs (ApplyAttributes): Recognize the MarshalAs attribute
	on parameters and accordingly set the marshalling info.

svn path=/trunk/mcs/; revision=3035
Ravi Pratap M 24 years ago
parent
commit
a4c4e548cc
4 changed files with 38 additions and 3 deletions
  1. 15 0
      mcs/mcs/ChangeLog
  2. 20 2
      mcs/mcs/attribute.cs
  3. 1 1
      mcs/mcs/class.cs
  4. 2 0
      mcs/mcs/typemanager.cs

+ 15 - 0
mcs/mcs/ChangeLog

@@ -1,3 +1,18 @@
+2002-03-08  Ravi Pratap  <[email protected]>
+
+	* attribute.cs (Attribute.UnmanagedType): This is to keep track of
+	the unmanaged type in the case we have a MarshalAs attribute.
+
+	(Resolve): Handle the case when we are parsing the special MarshalAs
+	attribute [we need to store the unmanaged type to use later]
+	
+	* typemanager.cs (marshal_as_attr_type): Built in type for the 
+	MarshalAs Attribute.
+
+	* attribute.cs (ApplyAttributes): Recognize the MarshalAs attribute 
+	on parameters and accordingly set the marshalling info.
+	
+
 2002-03-09  Miguel de Icaza  <[email protected]>
 
 	* class.cs: Optimizing slightly by removing redundant code after

+ 20 - 2
mcs/mcs/attribute.cs

@@ -38,6 +38,7 @@ namespace Mono.CSharp {
 		public bool UsageAttr = false;
 		
 		public MethodImplOptions ImplOptions;
+		public UnmanagedType     UnmanagedType;
 		
 		public Attribute (string name, ArrayList args, Location loc)
 		{
@@ -65,6 +66,7 @@ namespace Mono.CSharp {
 		{
 			string name = Name;
 			bool MethodImplAttr = false;
+			bool MarshalAsAttr = false;
 
 			UsageAttr = false;
 
@@ -86,6 +88,9 @@ namespace Mono.CSharp {
 				UsageAttr = true;
 			if (Type == TypeManager.methodimpl_attr_type)
 				MethodImplAttr = true;
+			if (Type == TypeManager.marshal_as_attr_type)
+				MarshalAsAttr = true;
+			
 
 			// Now we extract the positional and named arguments
 			
@@ -121,6 +126,9 @@ namespace Mono.CSharp {
 
 					if (MethodImplAttr)
 						this.ImplOptions = (MethodImplOptions) pos_values [0];
+
+					if (MarshalAsAttr)
+						this.UnmanagedType = (UnmanagedType) pos_values [0];
 					
 				} else { 
 					error182 ();
@@ -423,6 +431,7 @@ namespace Mono.CSharp {
 
 					
 					if (kind is Method || kind is Operator) {
+
 						if (a.Type == TypeManager.methodimpl_attr_type) {
 							if (a.ImplOptions == MethodImplOptions.InternalCall)
 								((MethodBuilder) builder).SetImplementationFlags (
@@ -430,6 +439,7 @@ namespace Mono.CSharp {
 									   MethodImplAttributes.Runtime);
 						} else if (a.Type != TypeManager.dllimport_type)
 							((MethodBuilder) builder).SetCustomAttribute (cb);
+
 					} else if (kind is Constructor) {
 						((ConstructorBuilder) builder).SetCustomAttribute (cb);
 					} else if (kind is Field) {
@@ -438,8 +448,16 @@ namespace Mono.CSharp {
 						((PropertyBuilder) builder).SetCustomAttribute (cb);
 					} else if (kind is Event) {
 						((EventBuilder) builder).SetCustomAttribute (cb);
-					} else if (kind is ParameterBuilder){
-						((ParameterBuilder) builder).SetCustomAttribute (cb);
+					} else if (kind is ParameterBuilder) {
+
+						if (a.Type == TypeManager.marshal_as_attr_type) {
+							UnmanagedMarshal marshal =
+								UnmanagedMarshal.DefineUnmanagedMarshal (a.UnmanagedType);
+							
+							((ParameterBuilder) builder).SetMarshal (marshal);
+						} else 
+							((ParameterBuilder) builder).SetCustomAttribute (cb);
+						
 					} else if (kind is Enum) {
 						((TypeBuilder) builder).SetCustomAttribute (cb); 
 

+ 1 - 1
mcs/mcs/class.cs

@@ -3148,7 +3148,7 @@ namespace Mono.CSharp {
 
 	/// </summary>
 	///  Gigantic workaround  for lameness in SRE follows :
-	///  This class derived from EventInfo and attempts to basically
+	///  This class derives from EventInfo and attempts to basically
 	///  wrap around the EventBuilder so that FindMembers can quickly
 	///  return this in it search for members
 	/// </summary>

+ 2 - 0
mcs/mcs/typemanager.cs

@@ -58,6 +58,7 @@ public class TypeManager {
 	static public Type dllimport_type;
 	static public Type unverifiable_code_type;
 	static public Type methodimpl_attr_type;
+	static public Type marshal_as_attr_type;
 	static public Type param_array_type;
 	static public Type void_ptr_type;
 
@@ -439,6 +440,7 @@ public class TypeManager {
 		attribute_usage_type = CoreLookupType ("System.AttributeUsageAttribute");
 		dllimport_type       = CoreLookupType ("System.Runtime.InteropServices.DllImportAttribute");
 		methodimpl_attr_type = CoreLookupType ("System.Runtime.CompilerServices.MethodImplAttribute");
+		marshal_as_attr_type  = CoreLookupType ("System.Runtime.InteropServices.MarshalAsAttribute");
 		param_array_type     = CoreLookupType ("System.ParamArrayAttribute");
 
 		unverifiable_code_type = CoreLookupType ("System.Security.UnverifiableCodeAttribute");