Beispiel #1
0
 private void AddGenericArguments(InfrastructureRuntimicModelMask_I model, GenericInstanceMethod resolvedMethodReference, TypeReference[] typeArgumentReferences)
 {
     for (int i = 0; i < typeArgumentReferences.Length; i++)
     {
         resolvedMethodReference.GenericArguments.Add(typeArgumentReferences[i]);
     }
 }
        public ModuleDefinition GetModuleFromType(InfrastructureRuntimicModelMask_I semanticModel, string resolutionName)
        {
            throw new System.Exception("Debug");
            //         var node = Unified.Types.Get(semanticModel, resolutionName);

            //return node?.ModuleNode?.ModuleDefinition;
        }
Beispiel #3
0
        public void AddAssemblyEntry(InfrastructureRuntimicModelMask_I semanticModel, SemanticAssemblyMask_I entry)
        {
            throw new System.Exception("Not supported currently.");
            //semanticModel.Semantic.Assemblies.ByResolutionName.Add(entry.ResolutionName(), entry);

            //Infrastructure.Models.Structural.AddAssemblyDefinition(semanticModel, entry.AssemblyDefinition);
        }
Beispiel #4
0
        public MethodReference GetMethodReference(InfrastructureRuntimicModelMask_I model, Mono.Collections.Generic.Collection <MethodDefinition> methods, MethodInfo method)
        {
            //  DEBUGGING: This is the current issue
            var methodDefinition = Methods.Getting.FromMethodInfos.Definitions.GetMethodDefinition(model, methods, method);

            return(Methods.Building.MethodDefinitions.MakeGenericInstanceTypeMethodReference(model, methodDefinition, method.DeclaringType));
        }
        public BoundMethod BuildMethod(InfrastructureRuntimicModelMask_I model, BoundTypeDefinition_I input, MethodInfo method)
        {
            BoundMethod boundMethod;

            if (method.GetGenericArguments().Length > 0)
            {
                boundMethod = new BoundGenericInstanceMethod
                {
                    DeclaringType    = input,
                    MethodAttributes = method.Attributes,
                    Name             = method.Name,
                    UnderlyingMethod = method
                };
            }
            else
            {
                boundMethod = new BoundNonGenericInstanceMethod
                {
                    DeclaringType    = input,
                    MethodAttributes = method.Attributes,
                    Name             = method.Name,
                    UnderlyingMethod = method
                };
            }

            return(boundMethod);
        }
Beispiel #6
0
        public MethodReference MakeGenericInstanceMethod(InfrastructureRuntimicModelMask_I model, TypeReference declaringType, MethodReference methodReference, MethodInfo method)
        {
            Type[] typeArguments = method.GetGenericArguments();

            TypeReference[] typeArgumentReferences = ResolveGenericArguments(model, typeArguments);

            var resolvedMethodReference = new GenericInstanceMethod(methodReference)
            {
                ReturnType = ResolveTypeParameterIfPresent(model, methodReference.ReturnType, typeArgumentReferences),
            };

            AddGenericArguments(model, resolvedMethodReference, typeArgumentReferences);

            for (int i = 0; i < methodReference.Parameters.Count; i++)
            {
                var inputParameter = methodReference.Parameters[i];

                var inputParameterType = inputParameter.ParameterType;

                var outputParameterType = ResolveTypeParameterIfPresent(model, inputParameterType, typeArgumentReferences);

                var outputParameter = Parameters.Create(inputParameter, outputParameterType);

                if (inputParameter.IsOut != outputParameter.IsOut)
                {
                    throw new Exception("Did not make correctly");
                }

                resolvedMethodReference.Parameters.Add(outputParameter);
            }

            return(resolvedMethodReference);
        }
Beispiel #7
0
        public SemanticTypeDefinition CreateType(InfrastructureRuntimicModelMask_I model, SemanticModuleMask_I moduleEntry, System.Type typeReference)
        {
            //var convertedType = (SemanticTypeDefinition)this.Infrastructure.Semantic.Metadata.Members.Types.Creation.CreateType
            //<SemanticGenericArrayTypeDefinition,
            //    SemanticGenericStructTypeDefinition,
            //    SemanticGenericDelegateTypeDefinition,
            //    SemanticGenericClassTypeDefinition,
            //    SemanticGenericInterfaceTypeDefinition,
            //    SemanticGenericNestedStructTypeDefinition,
            //    SemanticGenericNestedDelegateTypeDefinition,
            //    SemanticGenericNestedArrayTypeDefinition,
            //    SemanticGenericNestedClassTypeDefinition,
            //    SemanticGenericNestedInterfaceTypeDefinition,
            //    SemanticNestedEnumTypeDefinition,
            //    SemanticNestedStructTypeDefinition,
            //    SemanticNestedDelegateTypeDefinition,
            //    SemanticNestedArrayTypeDefinition,
            //    SemanticNestedClassTypeDefinition,
            //    SemanticNestedInterfaceTypeDefinition,
            //    SemanticSimpleClTypeDefinition,
            //    SemanticEnumTypeDefinition,
            //    SemanticStructTypeDefinition,
            //    SemanticDelegateTypeDefinition,
            //    SemanticArrayTypeDefinition,
            //    SemanticClassTypeDefinition,
            //    SemanticInterfaceTypeDefinition>(model, moduleEntry, typeReference);



            throw new System.NotImplementedException();
        }
Beispiel #8
0
        public MethodReference GetMethodReference(InfrastructureRuntimicModelMask_I model, TypeReference typeReference, MethodInfo method)
        {
            // Get the type definition that corresponds to the type reference.  This will store all the methods that are available.
            var typeDefinition = Types.Getting.GetDefinition(model, typeReference);

            return(GetMethodReference(model, typeDefinition, method));
        }
 public BoundConstructorDefinition BuildConstructor(InfrastructureRuntimicModelMask_I model, BoundTypeDefinition_I input, ConstructorInfo constructor)
 {
     return(new BoundConstructorDefinition
     {
         DeclaringType = input,
         ConstructorAttributes = constructor.Attributes,
         Name = constructor.Name,
         UnderlyingConstructor = constructor
     });
 }
Beispiel #10
0
        public TypeReference ResolveTypeParameterIfPresent(InfrastructureRuntimicModelMask_I model, TypeReference typeReferenceToResolve, TypeReference[] parametersInOrder)
        {
            if (!typeReferenceToResolve.IsGenericParameter)
            {
                return(typeReferenceToResolve);
            }


            throw new NotImplementedException();
        }
Beispiel #11
0
        public SemanticTypeMask_I Get(InfrastructureRuntimicModelMask_I semanticModel, SemanticModuleMask_I module, TypeReference input)
        {
            string resolutionName = Types.Naming.GetResolutionName(input);

            if (!module.Types.ByResolutionName.TryGetValue(resolutionName, out SemanticTypeMask_I typeEntry))
            {
                return(null);
            }

            return(typeEntry);
        }
Beispiel #12
0
        public TypeReference ResolveTypeParameterIfPresent(InfrastructureRuntimicModelMask_I model, Type typeToResolve)
        {
            if (!typeToResolve.IsGenericParameter)
            {
                return(Types.Getting.GetInternalTypeReference(model, typeToResolve));
            }

            //var x = typeToResolve.GetType();

            throw new NotImplementedException();
        }
Beispiel #13
0
        private TypeReference[] ResolveGenericArguments(InfrastructureRuntimicModelMask_I model, Type[] typeArguments)
        {
            TypeReference[] references = new TypeReference[typeArguments.Length];

            for (int i = 0; i < typeArguments.Length; i++)
            {
                references[i] = ResolveTypeParameterIfPresent(model, typeArguments[i]);
            }

            return(references);
        }
Beispiel #14
0
        public TypeReference EnsureReference(InfrastructureRuntimicModelMask_I model, TypeReference inputReference, out UnifiedTypeNode unifiedNode)
        {
            //string resolutionName = Types.Naming.GetResolutionName(inputReference);

            //var result = Types.Getting.GetStoredTypeReference(model, resolutionName, out unifiedNode);

            //if (result != null) return result;

            //if (inputReference.IsGenericInstance)
            //{
            //	GenericInstanceType genericInstance = (GenericInstanceType) inputReference;

            //	var genericArguments = genericInstance.GenericArguments;

            //	var genericTypeDefinition = genericInstance.ElementType;

            //	var genericTypeDefinition1 = EnsureReference(model, genericTypeDefinition, out UnifiedTypeNode genericUnifiedNode);

            //	var genericArgumentReferences = new TypeReference[genericArguments.Count];

            //	for (int i = 0; i < genericArguments.Count; i++)
            //	{
            //		genericArgumentReferences[i] = EnsureReference(model, genericArguments[i]);
            //	}

            //	result = genericTypeDefinition1.MakeGenericInstanceType(genericArgumentReferences);

            //	var assemblyNode = Assemblies.Ensuring.Ensure(model, inputReference.Scope);

            //	//var moduleNode = Unified.Modules.Get(model, type.Module.Name);

            //	throw new Exception("Debug");

            //	//Unified.Types.Extend(model, assemblyNode, moduleNode, result);
            //}
            //else
            //{
            //	// This should load the assembly, module and types into the model.
            //	Assemblies.Ensuring.Ensure(model, inputReference.Scope);

            //	result = Types.Getting.GetStoredTypeReference(model, resolutionName, out unifiedNode);

            //	if (result == null)
            //	{
            //		throw new Exception($"Type definition for {resolutionName} is not loaded.");
            //	}
            //}

            //return result;

            throw new Exception("");
        }
        public void BuildMethods(InfrastructureRuntimicModelMask_I model, BoundTypeDefinition_I input)
        {
            if (!(input is BoundTypeDefinitionWithMethodsMask_I boundTypeWithMethods))
            {
                return;
            }

            if (input.FullName == "Root.Testing.Resources.Models.E01D.Runtimic.Execution.Emitting.Conversion.Inputs.Types.GenericClassWithMembersThatTakeInGenericClassParameters`1<T>")
            {
            }

            // Done on purpose to find errors
            var methods = input.UnderlyingType.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);

            List <BoundMethod> boundMethods = new List <BoundMethod>(methods.Length);

            for (int i = 0; i < methods.Length; i++)
            {
                var method = methods[i];

                var boundMethod = BuildMethod(model, input, method);

                if (!boundTypeWithMethods.Methods.ByName.TryGetValue(boundMethod.Name, out List <SemanticMethodMask_I> methodList))
                {
                    methodList = new List <SemanticMethodMask_I>();

                    boundTypeWithMethods.Methods.ByName.Add(boundMethod.Name, methodList);
                }

                methodList.Add(boundMethod);

                boundMethods.Add(boundMethod);

                // NULL CHECK: Possibly null if a generic instance
                input.Module?.MethodsByMetadataToken.Add(method.MetadataToken, boundMethod);
            }

            // Get the type definition that corresponds to the type reference.  This will store all the methods that are available.
            var declaringTypeDefinition = Cecil.Metadata.Members.Types.Getting.GetDefinition(model, input.SourceTypeReference);

            // Ensure all the methods are added to prevent this problem:
            #region

            #endregion
            for (int i = 0; i < boundMethods.Count; i++)
            {
                var boundMethod = boundMethods[i];

                // Search the declaring type definition for the method definition that matches the method info.
                boundMethod.MethodReference = Cecil.Metadata.Members.Methods.Getting.FromMethodInfos.References.GetMethodReference(model, declaringTypeDefinition.Methods, boundMethod.UnderlyingMethod);
            }
        }
Beispiel #16
0
        public SemanticFieldMask_I Get(InfrastructureRuntimicModelMask_I model, SemanticTypeDefinitionMask_I declaringType, string fieldName)
        {
            if (!(declaringType is SemanticTypeDefinitionWithFieldsMask_I typeWithFields))
            {
                throw new Exception("Trying to build a field on a type that does not support fields.");
            }

            if (typeWithFields.Fields.ByName.TryGetValue(fieldName, out SemanticFieldMask_I field))
            {
                return(field);
            }

            return(null);
        }
        public void BuildConstructors(InfrastructureRuntimicModelMask_I model, BoundTypeDefinition_I input)
        {
            if (!(input is BoundTypeDefinitionWithConstructorsMask_I boundTypeWithConstructors))
            {
                return;
            }

            if (input.FullName == "Root.Testing.Resources.Models.E01D.Runtimic.Execution.Emitting.Conversion.Inputs.Types.GenericClassWithMembersThatTakeInGenericClassParameters`1<T>")
            {
            }

            // Done on purpose to find errors
            var constructors = input.UnderlyingType.GetConstructors(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);

            List <BoundConstructorDefinition> boundConstructors = new List <BoundConstructorDefinition>(constructors.Length);

            for (int i = 0; i < constructors.Length; i++)
            {
                var constructor = constructors[i];

                var boundConstructor = BuildConstructor(model, input, constructor);

                boundTypeWithConstructors.Constructors.All.Add(boundConstructor);

                boundConstructors.Add(boundConstructor);

                input.Module.ConstructorsByMetadataToken.Add(constructor.MetadataToken, boundConstructor);
            }

            // Get the type definition that corresponds to the type reference.  This will store all the constructors that are available.
            var declaringTypeDefinition = Cecil.Metadata.Members.Types.Getting.GetDefinition(model, input.SourceTypeReference);

            // Ensure all the constructors are added to prevent this problem:
            #region

            #endregion
            for (int i = 0; i < boundConstructors.Count; i++)
            {
                var boundConstructor = boundConstructors[i];

                // Search the declaring type definition for the constructor definition that matches the constructor info.
                boundConstructor.MethodReference = Cecil.Metadata.Members.Constructors.Getting.FromConstructorInfos.References.GetMethodReference(model, declaringTypeDefinition, boundConstructor.UnderlyingConstructor);
            }
        }
Beispiel #18
0
        public CecilTypeReferenceSet EnsureReferences(InfrastructureRuntimicModelMask_I model, List <TypeReference> types)
        {
            throw new System.Exception("Debug");
            //var result = new CecilTypeReferenceSet();

            //for (int i = 0; i < types.Count; i++)
            //{
            //	EnsureReference(model, types[i], out UnifiedTypeNode unifiedNode);

            //	result.Types.Add(unifiedNode);

            //	if (!IsPresent(result, unifiedNode.AssemblyNode))
            //	{
            //		result.Assemblies.Add(unifiedNode.AssemblyNode);
            //	}
            //}

            //return result;
        }
Beispiel #19
0
        public BoundGenericParameterTypeDefinition CreateTypeParameter(InfrastructureRuntimicModelMask_I conversion, Type[] typeArguments, TypeReference inputType, GenericParameter typeParamterType)
        {
            var typeParameter = new BoundGenericParameterTypeDefinition
            {
                Attributes          = Cecil.Metadata.Members.GenericParameters.GetTypeParameterAttributes(typeParamterType),
                Name                = typeParamterType.Name,
                FullName            = typeParamterType.FullName,
                Position            = typeParamterType.Position,
                TypeParameterKind   = GetTypeParameterKind(typeParamterType.Type),
                Definition          = typeParamterType,
                SourceTypeReference = inputType
            };

            typeParameter.UnderlyingType = FindMatchingType(typeArguments, typeParamterType);



            return(typeParameter);
        }
Beispiel #20
0
        public MethodDefinition GetMethodDefinition(InfrastructureRuntimicModelMask_I model, Mono.Collections.Generic.Collection <MethodDefinition> methodDefinitions, MethodInfo method)
        {
            if (method.Module.Assembly.IsDynamic)
            {
                throw new Exception(
                          "Cannot be used for methods that orginate from dynamic assemblies as the metadata tokens will not match.");
            }

            for (int i = 0; i < methodDefinitions.Count; i++)
            {
                var methodDefinition = methodDefinitions[i];

                if (method.MetadataToken == methodDefinition.MetadataToken.ToInt32())
                {
                    return(methodDefinition);
                }
            }

            throw new Exception($"Could not find a method matching the method name {method.Name}.");
        }
Beispiel #21
0
        public FieldInfo GetFieldInfo(InfrastructureRuntimicModelMask_I model, SemanticTypeDefinitionMask_I declaringType, string fieldName)
        {
            // 1) First check the current type for the field.
            var result = Get(model, declaringType, fieldName);

            // 2.a) If not found, and is generic...
            if (result == null && declaringType is BoundGenericTypeDefinitionMask_I bound)
            {
                // 2.b) Check the blueprint for the field as it might take generic parameters.
                result = Get(model, bound.Blueprint, fieldName);
            }

            if (result == null)
            {
                return(null);
            }

            if (!(result is BoundFieldDefinitionMask_I field))
            {
                throw new Exception("Cannot get a field info from a field hat is not convertible to a BoundFieldMask_I.");
            }

            return(field.UnderlyingField);
        }
Beispiel #22
0
 public SemanticFieldMask_I Get(InfrastructureRuntimicModelMask_I model, SemanticTypeDefinitionMask_I declaringType, string fieldName)
 {
     return(Semantic.Metadata.Members.Fields.Get(model, declaringType, fieldName));
 }
Beispiel #23
0
        public TypeReference EnsureReference(InfrastructureRuntimicModelMask_I model, TypeReference inputReference)
        {
            //return EnsureReference(model, inputReference, out UnifiedTypeNode unifiedNode);

            throw new Exception("");
        }
        //public TypeReference GetTypeReference(InfrastructureRuntimicModelMask_I model, Type input)
        //{
        // string resolutionName = Binding.Metadata.Members.Types.Naming.GetResolutionName(input);

        //    TypeReference typeDefinition = Collection.GetStoredTypeReference(model, resolutionName);

        //    if (typeDefinition != null) return typeDefinition;

        //    if (!input.IsGenericType)
        //    {
        //        throw new Exception($"Type definition for {input.AssemblyQualifiedName} is not loaded.");
        //    }

        //    var genericArguments = input.GenericTypeArguments;

        //    if (genericArguments.Length < 1)
        //    {
        //        throw new Exception($"Type definition for {input.AssemblyQualifiedName} is not loaded.");
        //    }

        //    var genericTypeDefinition = input.GetGenericTypeDefinition();

        //    var genericTypeDefinition1 = GetTypeReference(model, genericTypeDefinition);

        //    var genericArgumentReferences = new TypeReference[genericArguments.Length];

        //    for (int i = 0; i < genericArguments.Length; i++)
        //    {
        //        genericArgumentReferences[i] = GetTypeReference(model, genericArguments[i]);
        //    }

        //    var result = genericTypeDefinition1.MakeGenericInstanceType(genericArgumentReferences);

        //    return result;
        //}

        public Type ResolveToType(InfrastructureRuntimicModelMask_I model, SemanticTypeDefinitionMask_I semanticType)
        {
            throw new Exception("resolving a semantic type to a run time is not supported.  A semantic type is designed to be used to create runtime type.  Right now automatic" +
                                "compile support is not present.");
        }
Beispiel #25
0
 public TypeReference EnsureReference(InfrastructureRuntimicModelMask_I model, Type type)
 {
     return(EnsureReference(model, type, out UnifiedTypeNode unifiedNode));
 }
Beispiel #26
0
 public MethodReference MakeGenericInstanceMethod(InfrastructureRuntimicModelMask_I model, TypeReference typeReference,
                                                  TypeDefinition typeDefinition, MethodReference methodReference, MethodInfo method)
 {
     throw new NotImplementedException();
 }
Beispiel #27
0
        public TypeReference EnsureReference(InfrastructureRuntimicModelMask_I model, Type type, out UnifiedTypeNode unifiedNode)
        {
            throw new System.Exception("Fix");

            //var metadataToken = type.MetadataToken;

            //// Ensure bound entry

            //// Ensure Cecil entry

            //// If a type is converted, then a seperate converted entry is created in a corresponding module. Types from different assemlibes cannot be combined
            //// without most likely making IL changes to support the additional types.

            //string resolutionName = Types.Naming.GetResolutionName(type);

            ////if (resolutionName == "Root.Testing.Resources.Models.E01D.Runtimic.Execution.Emitting.Conversion.Inputs.Types.ComplicatedGenericWithOneArgBaseConstructorCall`3, E01D.Pal.Apps.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")
            ////{

            ////}

            //TypeReference result = Types.Getting.GetStoredTypeReference(model, resolutionName, out unifiedNode);

            //if (result != null) return result;

            //if (type.IsGenericType && !type.IsGenericTypeDefinition)
            //{
            //	var genericArguments = type.GenericTypeArguments;

            //	var genericTypeDefinition = type.GetGenericTypeDefinition();

            //	var genericTypeDefinition1 = EnsureReference(model, genericTypeDefinition);

            //	var genericArgumentReferences = new TypeReference[genericArguments.Length];

            //	for (int i = 0; i < genericArguments.Length; i++)
            //	{
            //		genericArgumentReferences[i] = EnsureReference(model, genericArguments[i]);
            //	}

            //	result = genericTypeDefinition1.MakeGenericInstanceType(genericArgumentReferences);

            //	var assemblyNode = Assemblies.Ensuring.Ensure(model, type.Assembly);

            //	var moduleNode = Unified.Modules.Get(model, type.Module.Name);

            //	Unified.Types.Extend(model, assemblyNode, moduleNode, result);
            //}
            //else
            //{
            //	// This should load the assembly, module and types into the model.
            //	Assemblies.Ensuring.Ensure(model, type.Assembly);

            //	result = Types.Getting.GetStoredTypeReference(model, resolutionName, out unifiedNode);

            //	if (result == null)
            //	{
            //		throw new Exception($"Type definition for {type.AssemblyQualifiedName} is not loaded.");
            //	}
            //}

            //return result;
        }
Beispiel #28
0
        /// <summary>
        /// Gets the method definition that coresponds to the runtime method info.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="typeDefinition"></param>
        /// <param name="method"></param>
        /// <returns></returns>
        public MethodDefinition GetMethodDefinition(InfrastructureRuntimicModelMask_I model, TypeDefinition typeDefinition, MethodInfo method)
        {
            var methodDefinitions = typeDefinition.Methods;

            return(GetMethodDefinition(model, methodDefinitions, method));
        }
Beispiel #29
0
 public FieldInfo GetFieldInfo(InfrastructureRuntimicModelMask_I conversion, Type declaringType, FieldReference fieldReference)
 {
     return(declaringType.GetField(fieldReference.Name));
 }
Beispiel #30
0
        public BoundTypeDefinitionInterfaces GetInterfaces(InfrastructureRuntimicModelMask_I semanticModel, TypeDefinition typeDefinition)
        {
            BoundTypeDefinitionInterfaces all = new BoundTypeDefinitionInterfaces();

            return(all);
        }