Beispiel #1
0
		public void BeginCatchBlock (TypeSpec type)
		{
			if (IsAnonymousStoreyMutateRequired)
				type = CurrentAnonymousMethod.Storey.Mutator.Mutate (type);

			ig.BeginCatchBlock (type.GetMetaInfo ());
		}
Beispiel #2
0
		public LocalBuilder DeclareLocal (TypeSpec type, bool pinned)
		{
			if (IsAnonymousStoreyMutateRequired)
				type = CurrentAnonymousMethod.Storey.Mutator.Mutate (type);

			return ig.DeclareLocal (type.GetMetaInfo (), pinned);
		}
Beispiel #3
0
		public void AddTypeForwarder (TypeSpec type, Location loc)
		{
			try {
				if (add_type_forwarder == null) {
					add_type_forwarder = typeof (AssemblyBuilder).GetMethod ("AddTypeForwarder", BindingFlags.NonPublic | BindingFlags.Instance);
				}

				add_type_forwarder.Invoke (builder, new object[] { type.GetMetaInfo () });
			} catch {
				ctx.Report.RuntimeMissingSupport (loc, "TypeForwardedToAttribute");
			}
		}
Beispiel #4
0
	// TODO: Implement correctly
	public static bool ContainsGenericParameters (TypeSpec type)
	{
		return type.GetMetaInfo ().ContainsGenericParameters;
	}
Beispiel #5
0
		//
		// The stack contains the pointer and the value of type `type'
		//
		public void EmitStoreFromPtr (TypeSpec type)
		{
			if (type.IsEnum)
				type = EnumSpec.GetUnderlyingType (type);

			if (type == TypeManager.int32_type || type == TypeManager.uint32_type)
				ig.Emit (OpCodes.Stind_I4);
			else if (type == TypeManager.int64_type || type == TypeManager.uint64_type)
				ig.Emit (OpCodes.Stind_I8);
			else if (type == TypeManager.char_type || type == TypeManager.short_type ||
				 type == TypeManager.ushort_type)
				ig.Emit (OpCodes.Stind_I2);
			else if (type == TypeManager.float_type)
				ig.Emit (OpCodes.Stind_R4);
			else if (type == TypeManager.double_type)
				ig.Emit (OpCodes.Stind_R8);
			else if (type == TypeManager.byte_type || type == TypeManager.sbyte_type ||
				 type == TypeManager.bool_type)
				ig.Emit (OpCodes.Stind_I1);
			else if (type == TypeManager.intptr_type)
				ig.Emit (OpCodes.Stind_I);
			else if (TypeManager.IsStruct (type) || TypeManager.IsGenericParameter (type))
				ig.Emit (OpCodes.Stobj, type.GetMetaInfo ());
			else
				ig.Emit (OpCodes.Stind_Ref);
		}
Beispiel #6
0
		public void BeginCatchBlock (TypeSpec type)
		{
			ig.BeginCatchBlock (type.GetMetaInfo ());
		}
Beispiel #7
0
		public void EncodeTypeName (TypeSpec type)
		{
			var old_type = type.GetMetaInfo ();
			Encode (type.MemberDefinition.IsImported ? old_type.AssemblyQualifiedName : old_type.FullName);
		}
Beispiel #8
0
 //
 // Gets the reference to T version of the Type (T&)
 //
 public static Type GetReferenceType(TypeSpec t)
 {
     return t.GetMetaInfo ().MakeByRefType ();
 }
Beispiel #9
0
		public LocalBuilder DeclareLocal (TypeSpec type, bool pinned)
		{
			if (IsAnonymousStoreyMutateRequired)
				type = CurrentAnonymousMethod.Storey.Mutator.Mutate (type);

			if (pinned) {
				//
				// This is for .net compatibility. I am not sure why pinned
				// pointer temps are converted to & even if they are pointers to
				// pointers.
				//
				var pt = type as PointerContainer;
				if (pt != null) {
					type = pt.Element;
					if (type.Kind == MemberKind.Void)
						type = Module.Compiler.BuiltinTypes.IntPtr;
					
					return ig.DeclareLocal (type.GetMetaInfo ().MakeByRefType (), true);
				}
			}

			return ig.DeclareLocal (type.GetMetaInfo (), pinned);
		}
Beispiel #10
0
		static string GetSignatureForDoc (TypeSpec type)
		{
			var tp = type as TypeParameterSpec;
			if (tp != null) {
				int c = 0;
				type = type.DeclaringType;
				while (type != null && type.DeclaringType != null) {
					type = type.DeclaringType;
					c += type.MemberDefinition.TypeParametersCount;
				}
				var prefix = tp.IsMethodOwned ? "``" : "`";
				return prefix + (c + tp.DeclaredPosition);
			}

			var pp = type as PointerContainer;
			if (pp != null)
				return GetSignatureForDoc (pp.Element) + "*";

			ArrayContainer ap = type as ArrayContainer;
			if (ap != null)
				return GetSignatureForDoc (ap.Element) +
					ArrayContainer.GetPostfixSignature (ap.Rank);

			if (TypeManager.IsGenericType (type)) {
				string g = type.MemberDefinition.Namespace;
				if (g != null && g.Length > 0)
					g += '.';
				int idx = type.Name.LastIndexOf ('`');
				g += (idx < 0 ? type.Name : type.Name.Substring (0, idx)) + '{';
				int argpos = 0;
				foreach (TypeSpec t in TypeManager.GetTypeArguments (type))
					g += (argpos++ > 0 ? "," : String.Empty) + GetSignatureForDoc (t);
				g += '}';
				return g;
			}

			string name = type.GetMetaInfo ().FullName != null ? type.GetMetaInfo ().FullName : type.Name;
			return name.Replace ("+", ".").Replace ('&', '@');
		}
Beispiel #11
0
		//
		// 26.3.3.8 Exact Inference
		//
		public int ExactInference (TypeSpec u, TypeSpec v)
		{
			// If V is an array type
			if (v.IsArray) {
				if (!u.IsArray)
					return 0;

				// TODO MemberCache: GetMetaInfo ()
				if (u.GetMetaInfo ().GetArrayRank () != v.GetMetaInfo ().GetArrayRank ())
					return 0;

				return ExactInference (TypeManager.GetElementType (u), TypeManager.GetElementType (v));
			}

			// If V is constructed type and U is constructed type
			if (TypeManager.IsGenericType (v)) {
				if (!TypeManager.IsGenericType (u))
					return 0;

				TypeSpec [] ga_u = TypeManager.GetTypeArguments (u);
				TypeSpec [] ga_v = TypeManager.GetTypeArguments (v);
				if (ga_u.Length != ga_v.Length)
					return 0;

				int score = 0;
				for (int i = 0; i < ga_u.Length; ++i)
					score += ExactInference (ga_u [i], ga_v [i]);

				return score > 0 ? 1 : 0;
			}

			// If V is one of the unfixed type arguments
			int pos = IsUnfixed (v);
			if (pos == -1)
				return 0;

			AddToBounds (new BoundInfo (u, BoundKind.Exact), pos);
			return 1;
		}
Beispiel #12
0
		//
		// Load the object from the pointer.  
		//
		public void EmitLoadFromPtr (TypeSpec type)
		{
			if (type.Kind == MemberKind.Enum)
				type = EnumSpec.GetUnderlyingType (type);

			switch (type.BuiltinType) {
			case BuiltinTypeSpec.Type.Int:
				ig.Emit (OpCodes.Ldind_I4);
				break;
			case BuiltinTypeSpec.Type.UInt:
				ig.Emit (OpCodes.Ldind_U4);
				break;
			case BuiltinTypeSpec.Type.Short:
				ig.Emit (OpCodes.Ldind_I2);
				break;
			case BuiltinTypeSpec.Type.UShort:
			case BuiltinTypeSpec.Type.Char:
				ig.Emit (OpCodes.Ldind_U2);
				break;
			case BuiltinTypeSpec.Type.Byte:
				ig.Emit (OpCodes.Ldind_U1);
				break;
			case BuiltinTypeSpec.Type.SByte:
			case BuiltinTypeSpec.Type.Bool:
				ig.Emit (OpCodes.Ldind_I1);
				break;
			case BuiltinTypeSpec.Type.ULong:
			case BuiltinTypeSpec.Type.Long:
				ig.Emit (OpCodes.Ldind_I8);
				break;
			case BuiltinTypeSpec.Type.Float:
				ig.Emit (OpCodes.Ldind_R4);
				break;
			case BuiltinTypeSpec.Type.Double:
				ig.Emit (OpCodes.Ldind_R8);
				break;
			case BuiltinTypeSpec.Type.IntPtr:
				ig.Emit (OpCodes.Ldind_I);
				break;
			default:
				switch (type.Kind) {
				case MemberKind.Struct:
				case MemberKind.TypeParameter:
					if (IsAnonymousStoreyMutateRequired)
						type = CurrentAnonymousMethod.Storey.Mutator.Mutate (type);

					ig.Emit (OpCodes.Ldobj, type.GetMetaInfo ());
					break;
				case MemberKind.PointerType:
					ig.Emit (OpCodes.Ldind_I);
					break;
				default:
					ig.Emit (OpCodes.Ldind_Ref);
					break;
				}
				break;
			}

			if (TrackStackTypes) {
				// TODO: test for async when `this' can be used inside structs
				SetStackType (type);
			}
		}
Beispiel #13
0
		public void Emit (OpCode opcode, TypeSpec type)
		{
			if (IsAnonymousStoreyMutateRequired)
				type = CurrentAnonymousMethod.Storey.Mutator.Mutate (type);

			ig.Emit (opcode, type.GetMetaInfo ());

			if (TrackStackTypes) {
				switch (opcode.StackBehaviourPush) {
				case StackBehaviour.Push0:
					// Nothing
					break;
				case StackBehaviour.Pushi:
					SetStackType (ReferenceContainer.MakeType (Module, type));
					break;
				case StackBehaviour.Push1:
					SetStackType (type);
					break;
				default:
					if (opcode == OpCodes.Box) {
						SetStackType (Module.Compiler.BuiltinTypes.Object);
					} else if (opcode == OpCodes.Castclass) {
						SetStackType (type);
					} else {
						throw new NotImplementedException (opcode.Name);
					}
					break;
				}
			}
		}
Beispiel #14
0
		public void Emit (OpCode opcode, TypeSpec type)
		{
			if (IsAnonymousStoreyMutateRequired)
				type = CurrentAnonymousMethod.Storey.Mutator.Mutate (type);

			ig.Emit (opcode, type.GetMetaInfo ());
		}
Beispiel #15
0
        static string GetSignatureForDoc(TypeSpec type)
        {
            var tp = type as TypeParameterSpec;
            if (tp != null) {
                var prefix = tp.IsMethodOwned ? "``" : "`";
                return prefix + tp.DeclaredPosition;
            }

            if (TypeManager.IsGenericType (type)) {
                string g = type.MemberDefinition.Namespace;
                if (g != null && g.Length > 0)
                    g += '.';
                int idx = type.Name.LastIndexOf ('`');
                g += (idx < 0 ? type.Name : type.Name.Substring (0, idx)) + '{';
                int argpos = 0;
                foreach (TypeSpec t in TypeManager.GetTypeArguments (type))
                    g += (argpos++ > 0 ? "," : String.Empty) + GetSignatureForDoc (t);
                g += '}';
                return g;
            }

            string name = type.GetMetaInfo ().FullName != null ? type.GetMetaInfo ().FullName : type.Name;
            return name.Replace ("+", ".").Replace ('&', '@');
        }
Beispiel #16
0
		//
		// The stack contains the pointer and the value of type `type'
		//
		public void EmitStoreFromPtr (TypeSpec type)
		{
			if (type.IsEnum)
				type = EnumSpec.GetUnderlyingType (type);

			switch (type.BuiltinType) {
			case BuiltinTypeSpec.Type.Int:
			case BuiltinTypeSpec.Type.UInt:
				ig.Emit (OpCodes.Stind_I4);
				return;
			case BuiltinTypeSpec.Type.Long:
			case BuiltinTypeSpec.Type.ULong:
				ig.Emit (OpCodes.Stind_I8);
				return;
			case BuiltinTypeSpec.Type.Char:
			case BuiltinTypeSpec.Type.Short:
			case BuiltinTypeSpec.Type.UShort:
				ig.Emit (OpCodes.Stind_I2);
				return;
			case BuiltinTypeSpec.Type.Float:
				ig.Emit (OpCodes.Stind_R4);
				return;
			case BuiltinTypeSpec.Type.Double:
				ig.Emit (OpCodes.Stind_R8);
				return;
			case BuiltinTypeSpec.Type.Byte:
			case BuiltinTypeSpec.Type.SByte:
			case BuiltinTypeSpec.Type.Bool:
				ig.Emit (OpCodes.Stind_I1);
				return;
			case BuiltinTypeSpec.Type.IntPtr:
				ig.Emit (OpCodes.Stind_I);
				return;
			}

			switch (type.Kind) {
			case MemberKind.Struct:
			case MemberKind.TypeParameter:
				if (IsAnonymousStoreyMutateRequired)
					type = CurrentAnonymousMethod.Storey.Mutator.Mutate (type);

				ig.Emit (OpCodes.Stobj, type.GetMetaInfo ());
				break;
			default:
				ig.Emit (OpCodes.Stind_Ref);
				break;
			}
		}
Beispiel #17
0
        public bool EncodeTypeName(TypeSpec type)
        {
            //			if (TypeManager.ContainsGenericParameters (type) && !TypeManager.IsGenericTypeDefinition (type))
            //				return false;

            var old_type = type.GetMetaInfo ();
            Encode (type.MemberDefinition.IsImported ? old_type.AssemblyQualifiedName : old_type.FullName);
            return true;
        }