TypeSpecification GetTypeSpec (TypeSpecification original, ImportContext context)
		{
			TypeSpecification typeSpec;

			TypeReference elementType = ImportTypeReference (original.ElementType, context);
			if (original is PointerType) {
				typeSpec = new PointerType (elementType);
			} else if (original is ArrayType) { // deal with complex arrays
				typeSpec = new ArrayType (elementType);
			} else if (original is ReferenceType) {
				typeSpec = new ReferenceType (elementType);
			} else if (original is GenericInstanceType) {
				GenericInstanceType git = original as GenericInstanceType;
				GenericInstanceType genElemType = new GenericInstanceType (elementType);

				context.GenericContext.CheckProvider (genElemType.GetOriginalType (), git.GenericArguments.Count);
				foreach (TypeReference arg in git.GenericArguments)
					genElemType.GenericArguments.Add (ImportTypeReference (arg, context));

				typeSpec = genElemType;
			} else if (original is ModifierOptional) {
				TypeReference mt = (original as ModifierOptional).ModifierType;
				typeSpec = new ModifierOptional (elementType, ImportTypeReference (mt, context));
			} else if (original is ModifierRequired) {
				TypeReference mt = (original as ModifierRequired).ModifierType;
				typeSpec = new ModifierRequired (elementType, ImportTypeReference (mt, context));
			} else if (original is SentinelType) {
				typeSpec = new SentinelType (elementType);
			} else if (original is FunctionPointerType) {
				FunctionPointerType ori = original as FunctionPointerType;

				FunctionPointerType fnptr = new FunctionPointerType (
					ori.HasThis,
					ori.ExplicitThis,
					ori.CallingConvention,
					new MethodReturnType (ImportTypeReference (ori.ReturnType.ReturnType, context)));

				foreach (ParameterDefinition parameter in ori.Parameters)
					fnptr.Parameters.Add (new ParameterDefinition (ImportTypeReference (parameter.ParameterType, context)));

				typeSpec = fnptr;
			} else
				throw new ReflectionException ("Unknown element type: {0}", original.GetType ().Name);

			return typeSpec;
		}
		public override void VisitVariableDefinitionCollection (VariableDefinitionCollection variables)
		{
			MethodBody body = variables.Container as MethodBody;
			if (body == null || body.LocalVarToken == 0)
				return;

			StandAloneSigTable sasTable = m_reflectReader.TableReader.GetStandAloneSigTable ();
			StandAloneSigRow sasRow = sasTable [(int) GetRid (body.LocalVarToken) - 1];
			LocalVarSig sig = m_reflectReader.SigReader.GetLocalVarSig (sasRow.Signature);
			for (int i = 0; i < sig.Count; i++) {
				LocalVarSig.LocalVariable lv = sig.LocalVariables [i];
				TypeReference varType = m_reflectReader.GetTypeRefFromSig (
					lv.Type, new GenericContext (body.Method));

				if (lv.ByRef)
					varType = new ReferenceType (varType);
				if ((lv.Constraint & Constraint.Pinned) != 0)
					varType = new PinnedType (varType);

				varType = m_reflectReader.GetModifierType (lv.CustomMods, varType);

				body.Variables.Add (new VariableDefinition (
						string.Concat ("V_", i), i, body.Method, varType));
			}
		}
Example #3
0
		TypeReference GetTypeSpec (Type t, ImportContext context)
		{
			Stack s = new Stack ();
			while (t.HasElementType || IsGenericTypeSpec (t)) {
				s.Push (t);
				if (t.HasElementType)
					t = t.GetElementType ();
				else if (IsGenericTypeSpec (t)) {
					t = (Type) t.GetType ().GetMethod ("GetGenericTypeDefinition").Invoke (t, null);
					break;
				}
			}

			TypeReference elementType = ImportSystemType (t, context);
			while (s.Count > 0) {
				t = (Type) s.Pop ();
				if (t.IsPointer)
					elementType = new PointerType (elementType);
				else if (t.IsArray)
					elementType = new ArrayType (elementType, t.GetArrayRank ());
				else if (t.IsByRef)
					elementType = new ReferenceType (elementType);
				else if (IsGenericTypeSpec (t))
					elementType = GetGenericType (t, elementType, context);
				else
					throw new ReflectionException ("Unknown element type");
			}

			return elementType;
		}
Example #4
0
        public MethodReturnType GetMethodReturnType(MethodSig msig, GenericContext context)
        {
            TypeReference retType;
            if (msig.RetType.Void)
                retType = SearchCoreType (Constants.Void);
            else if (msig.RetType.ByRef)
                retType = new ReferenceType (GetTypeRefFromSig (msig.RetType.Type, context));
            else if (msig.RetType.TypedByRef)
                retType = SearchCoreType (Constants.TypedReference);
            else
                retType = GetTypeRefFromSig (msig.RetType.Type, context);

            retType = GetModifierType (msig.RetType.CustomMods, retType);

            return new MethodReturnType (retType);
        }
Example #5
0
        void CompleteParameter(ParameterDefinition parameter, Param signature, GenericContext context)
        {
            TypeReference paramType;

            if (signature.ByRef)
                paramType = new ReferenceType (GetTypeRefFromSig (signature.Type, context));
            else if (signature.TypedByRef)
                paramType = SearchCoreType (Constants.TypedReference);
            else
                paramType = GetTypeRefFromSig (signature.Type, context);

            paramType = GetModifierType (signature.CustomMods, paramType);

            parameter.ParameterType = paramType;
        }
Example #6
0
        TypeSpecification GetTypeSpec(TypeSpecification original, ImportContext context)
        {
            TypeSpecification typeSpec;

            TypeReference elementType = ImportTypeReference(original.ElementType, context);

            if (original is PointerType)
            {
                typeSpec = new PointerType(elementType);
            }
            else if (original is ArrayType)                 // deal with complex arrays
            {
                typeSpec = new ArrayType(elementType);
            }
            else if (original is ReferenceType)
            {
                typeSpec = new ReferenceType(elementType);
            }
            else if (original is GenericInstanceType)
            {
                GenericInstanceType git         = original as GenericInstanceType;
                GenericInstanceType genElemType = new GenericInstanceType(elementType);

                context.GenericContext.CheckProvider(genElemType.GetOriginalType(), git.GenericArguments.Count);
                foreach (TypeReference arg in git.GenericArguments)
                {
                    genElemType.GenericArguments.Add(ImportTypeReference(arg, context));
                }

                typeSpec = genElemType;
            }
            else if (original is ModifierOptional)
            {
                TypeReference mt = (original as ModifierOptional).ModifierType;
                typeSpec = new ModifierOptional(elementType, ImportTypeReference(mt, context));
            }
            else if (original is ModifierRequired)
            {
                TypeReference mt = (original as ModifierRequired).ModifierType;
                typeSpec = new ModifierRequired(elementType, ImportTypeReference(mt, context));
            }
            else if (original is SentinelType)
            {
                typeSpec = new SentinelType(elementType);
            }
            else if (original is FunctionPointerType)
            {
                FunctionPointerType ori = original as FunctionPointerType;

                FunctionPointerType fnptr = new FunctionPointerType(
                    ori.HasThis,
                    ori.ExplicitThis,
                    ori.CallingConvention,
                    new MethodReturnType(ImportTypeReference(ori.ReturnType.ReturnType, context)));

                foreach (ParameterDefinition parameter in ori.Parameters)
                {
                    fnptr.Parameters.Add(new ParameterDefinition(ImportTypeReference(parameter.ParameterType, context)));
                }

                typeSpec = fnptr;
            }
            else
            {
                throw new ReflectionException("Unknown element type: {0}", original.GetType().Name);
            }

            return(typeSpec);
        }
Example #7
0
        TypeReference GetTypeSpec(TypeReference t, ImportContext context)
        {
            Stack s = new Stack ();
            while (t is TypeSpecification) {
                s.Push (t);
                t = (t as TypeSpecification).ElementType;
            }

            TypeReference elementType = ImportTypeReference (t, context);
            while (s.Count > 0) {
                t = s.Pop () as TypeReference;
                if (t is PointerType)
                    elementType = new PointerType (elementType);
                else if (t is ArrayType) // deal with complex arrays
                    elementType = new ArrayType (elementType);
                else if (t is ReferenceType)
                    elementType = new ReferenceType (elementType);
                else if (t is GenericInstanceType) {
                    GenericInstanceType git = t as GenericInstanceType;
                    GenericInstanceType genElemType = new GenericInstanceType (elementType);
                    foreach (TypeReference arg in git.GenericArguments)
                        genElemType.GenericArguments.Add (ImportTypeReference (arg, context));

                    elementType = genElemType;
                } else
                    throw new ReflectionException ("Unknown element type: {0}", t.GetType ().Name);
            }

            return elementType;
        }