示例#1
0
        public SemanticTypeMask_I Get(RuntimicSystemModel semanticModel, TypeReference input)
        {
            string resolutionName = Types.Naming.GetResolutionName(input);

            return(Get(semanticModel, resolutionName));
        }
示例#2
0
        public TypeDefinition GetElementType(RuntimicSystemModel semanticModel, SemanticTypeDefinitionMask_I bound)
        {
            var genericInstanceType = (GenericInstanceType)bound.SourceTypeReference;

            return(GetElementType(semanticModel, genericInstanceType));
        }
示例#3
0
 public StructuralModuleNode Ensure(RuntimicSystemModel runtimicSystem, StructuralAssemblyNode structuralAssemblyNode, Guid versionId)
 {
     throw new NotImplementedException();
 }
示例#4
0
 public TypeReference GetTypeReference(RuntimicSystemModel model, Type input, out SemanticTypeDefinitionMask_I possibleSemanticType)
 {
     return(Infrastructure.Models.Semantic.Types.GetTypeReference(model, input, out possibleSemanticType));
 }
示例#5
0
 public System.Type GetValueType(RuntimicSystemModel model)
 {
     return(GetBoundUnderlyingTypeOrThrow(model, typeof(ValueType).AssemblyQualifiedName));
 }
示例#6
0
 public BoundModuleNode Get(RuntimicSystemModel model, Guid moduleMvid)
 {
     return(model.TypeSystems.Bound.Modules.ByVersionId[moduleMvid]);
 }
示例#7
0
        public bool Ensure(RuntimicSystemModel model, StructuralModuleNode structuralModuleNode, int typeMetadataToken, out StructuralTypeNode structuralTypeNode)
        {
            //model.TypeSystems.Structural.Types.

            throw new Exception("");
        }
示例#8
0
        public StructuralAssemblyNode Ensure(RuntimicSystemModel semanticModel, IMetadataScope scope)
        {
            string fullName = Assemblies.Naming.GetAssemblyName(scope);

            return(Ensure(semanticModel, fullName));
        }
示例#9
0
        public ConstructorInfo GetConstructorInfo(RuntimicSystemModel conversionModel, MemberReference memberReference)
        {
            var declaringBound = Members.GetDeclaringType(conversionModel, memberReference);

            return((ConstructorInfo)FindConstructorBySignature(conversionModel, declaringBound, memberReference));
        }
示例#10
0
        public bool TryGet(RuntimicSystemModel model, TypeReference input, out SemanticTypeDefinitionMask_I typeEntry)
        {
            string resolutionName = Types.Naming.GetResolutionName(input);

            return(TryGet(model, resolutionName, out typeEntry));
        }
示例#11
0
 public StructuralAssemblyNode Ensure(RuntimicSystemModel model, TypeReference typeReference)
 {
     return(Ensure(model, typeReference.Scope));
 }
示例#12
0
        public bool TryGet(RuntimicSystemModel model, string resolutionName, out SemanticTypeDefinitionMask_I typeEntry)
        {
            typeEntry = Get(model, resolutionName);

            return(typeEntry != null);
        }
示例#13
0
        public SemanticTypeMask_I GetOrThrow(RuntimicSystemModel model, TypeDefinition typeDefinition)
        {
            string resolutionName = Types.Naming.GetResolutionName(typeDefinition);

            return(GetOrThrow(model, resolutionName));
        }
示例#14
0
 public SemanticTypeDefinitionMask_I Get(RuntimicSystemModel semanticModel, string resolutionName)
 {
     throw new System.NotImplementedException();
     //return Unified.Types.Get(semanticModel, resolutionName)?.SemanticType;
 }
示例#15
0
        public SemanticTypeInformation CreateTypeInformation(RuntimicSystemModel model, TypeReference typeReference)
        {
            //if (typeReference.FullName ==
            //    "Root.Testing.Resources.Models.E01D.Runtimic.Execution.Emitting.Conversion.Inputs.Types.GenericClassWithMethods`1"
            //)
            //{

            //}
            string fullName = Cecil.Types.Naming.GetCliFullName(typeReference);

            var typeInformation = new SemanticTypeInformation
            {
                Name          = typeReference.Name,
                FullName      = fullName,
                TypeReference = typeReference
            };

            if (typeReference.IsDefinition)
            {
                var typeDefinition = (TypeDefinition)typeReference;
                typeInformation.IsDelegate  = typeDefinition.BaseType?.FullName == "System.Delegate" || typeDefinition.BaseType?.FullName == "System.MulticastDelegate";
                typeInformation.IsArray     = typeDefinition.IsArray;
                typeInformation.IsClass     = typeDefinition.IsClass;
                typeInformation.IsInterface = typeDefinition.IsInterface;
                typeInformation.IsEnum      = typeDefinition.IsEnum;
                typeInformation.IsGlobal    = typeDefinition.MetadataToken.RID == 1;
                typeInformation.IsNested    = typeDefinition.IsNested;
                typeInformation.IsValueType = typeDefinition.IsValueType;

                typeInformation.IsOpenGeneric = typeDefinition.GenericParameters.Count > 0;

                if (typeInformation.IsOpenGeneric)
                {
                    typeInformation.GenericKind |= GenericTypeKind.Open;
                }

                if (typeDefinition.GenericParameters.Count > 0)
                {
                    typeInformation.GenericKind |= GenericTypeKind.HasTypeParameters;
                }

                typeInformation.IsGeneric = typeInformation.IsOpenGeneric || typeInformation.IsClosedGeneric;

                typeInformation.IsAnonymousType = IsAnonymousType(typeInformation.IsGeneric, typeDefinition.Name, typeDefinition.Attributes);
            }
            else if (typeReference.IsPointer)
            {
                var pointerDefinition = (PointerType)typeReference;
                typeInformation.IsPointer   = true;
                typeInformation.IsDelegate  = false;
                typeInformation.IsArray     = pointerDefinition.IsArray;
                typeInformation.IsClass     = false;
                typeInformation.IsInterface = false;
                typeInformation.IsEnum      = false;
                typeInformation.IsGlobal    = pointerDefinition.MetadataToken.RID == 1;
                typeInformation.IsNested    = pointerDefinition.IsNested;
                typeInformation.IsValueType = pointerDefinition.IsValueType;

                typeInformation.IsOpenGeneric = pointerDefinition.GenericParameters.Count > 0;

                if (typeInformation.IsOpenGeneric)
                {
                    typeInformation.GenericKind |= GenericTypeKind.Open;
                }

                if (pointerDefinition.GenericParameters.Count > 0)
                {
                    typeInformation.GenericKind |= GenericTypeKind.HasTypeParameters;
                }

                typeInformation.IsGeneric = typeInformation.IsOpenGeneric || typeInformation.IsClosedGeneric;

                typeInformation.IsAnonymousType = false;
            }
            else if (typeReference.IsRequiredModifier)
            {
                var requiredModifierDefinition = (RequiredModifierType)typeReference;
                typeInformation.IsRequiredModifier = true;
                typeInformation.IsDelegate         = false;
                typeInformation.IsArray            = requiredModifierDefinition.IsArray;
                typeInformation.IsClass            = false;
                typeInformation.IsInterface        = false;
                typeInformation.IsEnum             = false;
                typeInformation.IsGlobal           = requiredModifierDefinition.MetadataToken.RID == 1;
                typeInformation.IsNested           = requiredModifierDefinition.IsNested;
                typeInformation.IsValueType        = requiredModifierDefinition.IsValueType;

                typeInformation.IsOpenGeneric = requiredModifierDefinition.GenericParameters.Count > 0;

                if (typeInformation.IsOpenGeneric)
                {
                    typeInformation.GenericKind |= GenericTypeKind.Open;
                }

                if (requiredModifierDefinition.GenericParameters.Count > 0)
                {
                    typeInformation.GenericKind |= GenericTypeKind.HasTypeParameters;
                }

                typeInformation.IsGeneric = typeInformation.IsOpenGeneric || typeInformation.IsClosedGeneric;

                typeInformation.IsAnonymousType = false;
            }
            else if (typeReference.IsArray)
            {
                typeInformation.IsDelegate      = false;
                typeInformation.IsArray         = true;
                typeInformation.IsClass         = false;
                typeInformation.IsInterface     = false;
                typeInformation.IsEnum          = false;
                typeInformation.IsGlobal        = false;
                typeInformation.IsNested        = false;
                typeInformation.IsValueType     = false;
                typeInformation.IsOpenGeneric   = false;
                typeInformation.IsAnonymousType = false;
            }
            else if (typeReference.IsGenericInstance)
            {
                var genericInstanceType = (GenericInstanceType)typeReference;
                typeInformation.IsArray = genericInstanceType.IsArray;


                typeInformation.IsGlobal        = genericInstanceType.MetadataToken.RID == 1;
                typeInformation.IsNested        = genericInstanceType.IsNested;
                typeInformation.IsValueType     = genericInstanceType.IsValueType;
                typeInformation.IsOpenGeneric   = genericInstanceType.GenericParameters.Count > 0;
                typeInformation.IsClosedGeneric = genericInstanceType.GenericArguments.Count > 0 && !(genericInstanceType.GenericParameters.Count > 0);



                TypeDefinition elementTypeReference = Types.GenericInstances.GetElementType(model, genericInstanceType);
                typeInformation.IsDelegate  = elementTypeReference.BaseType?.FullName == "System.Delegate" || elementTypeReference.BaseType?.FullName == "System.MulticastDelegate";
                typeInformation.IsArray     = genericInstanceType.IsArray;
                typeInformation.IsClass     = elementTypeReference.IsClass;
                typeInformation.IsInterface = elementTypeReference.IsInterface;
                typeInformation.IsEnum      = elementTypeReference.IsEnum;

                if (typeInformation.IsOpenGeneric)
                {
                    typeInformation.GenericKind |= GenericTypeKind.Open;
                }

                if (typeInformation.IsClosedGeneric)
                {
                    typeInformation.GenericKind |= GenericTypeKind.Closed;
                }

                if (genericInstanceType.GenericArguments.Count > 0)
                {
                    typeInformation.GenericKind |= GenericTypeKind.HasTypeArguments;
                }

                if (genericInstanceType.GenericParameters.Count > 0)
                {
                    typeInformation.GenericKind |= GenericTypeKind.HasTypeParameters;
                }

                typeInformation.IsGeneric = typeInformation.IsOpenGeneric || typeInformation.IsClosedGeneric;

                typeInformation.IsAnonymousType = IsAnonymousType(typeInformation.IsGeneric, genericInstanceType.Name, elementTypeReference.Attributes);

                // Add the type information before any
                //model.Types.TypeInformations.Add(inputType.FullName, typeInformation);
                if (genericInstanceType.GenericArguments.Count > 0)
                {
                    var blueprint = genericInstanceType.ElementType;

                    typeInformation.GenericTypeDefinition = blueprint;
                }
                else
                {
                    throw new System.Exception("Not expected");
                }
            }
            else
            {
                throw new System.Exception("Not expected");
            }

            return(typeInformation);
        }
示例#16
0
        public SemanticTypeDefinitionMask_I Ensure(RuntimicSystemModel boundModel, ExecutionEnsureContext context)

        {
            GenericParameter parameter = (GenericParameter)context.TypeReference;

            if (parameter.DeclaringType != null)
            {
                SemanticTypeMask_I semanticDeclaringType;

                if (context.DeclaringType != null)
                {
                    semanticDeclaringType = context.DeclaringType;
                }
                else
                {
                    var resolutionName = Types.Naming.GetResolutionName(parameter.DeclaringType);

                    semanticDeclaringType = Models.Types.GetOrThrow(boundModel, resolutionName);
                }

                if (!(semanticDeclaringType is SemanticGenericTypeDefinitionMask_I genericDeclaringType))
                {
                    throw new Exception($"Expected the resolved semantic type to be a generic type of {typeof(SemanticGenericTypeDefinitionMask_I)}.");
                }

                if (genericDeclaringType.TypeParameters.ByName.TryGetValue(parameter.Name, out SemanticGenericParameterTypeDefinitionMask_I semanticTypeParameter))
                {
                    if (!semanticTypeParameter.IsBound())
                    {
                        throw new Exception("Expected the generic parameter type to be a bound type.");
                    }

                    return((BoundTypeDefinitionMask_I)semanticTypeParameter);
                }

                var typeParameter = CreateGenericParameter(genericDeclaringType);

                typeParameter.Attributes          = Cecil.Metadata.Members.GenericParameters.GetTypeParameterAttributes(parameter);
                typeParameter.Name                = parameter.Name;
                typeParameter.FullName            = parameter.FullName;
                typeParameter.Position            = parameter.Position;
                typeParameter.TypeParameterKind   = GetTypeParameterKind(parameter.Type);
                typeParameter.Definition          = parameter;
                typeParameter.SourceTypeReference = parameter;

                //typeParameter.ResolutionName = Cecil.Types.Naming.GetResolutionName(parameter);

                return(typeParameter);
            }
            else
            {
                if (!(parameter.DeclaringMethod is MethodDefinition methodDefinition))
                {
                    throw new Exception("Expected a method definition");
                }

                TypeReference declaringType;

                if (methodDefinition.DeclaringType != null)
                {
                    declaringType = methodDefinition.DeclaringType;
                }
                else
                {
                    if (context.MethodReference == null)
                    {
                    }

                    declaringType = context.MethodReference.DeclaringType;
                }


                var resolutionName = Types.Naming.GetResolutionName(declaringType);

                var semanticType = Models.Types.GetOrThrow(boundModel, resolutionName);

                if (!(semanticType is BoundTypeDefinitionWithMethodsMask_I convertedTypeWithMethods))
                {
                    throw new Exception("Trying to add a method to a type that does not support methods.");
                }

                var method = Bound.Metadata.Members.Methods.Getting.FindMethodByDefinition(boundModel, convertedTypeWithMethods, methodDefinition);

                if (method.TypeParameters.ByName.TryGetValue(parameter.Name, out SemanticGenericParameterTypeDefinitionMask_I semanticTypeParameter))
                {
                    if (!semanticTypeParameter.IsBound())
                    {
                        throw new Exception("Expected the generic parameter type to be a bound type.");
                    }

                    return((BoundTypeDefinitionMask_I)semanticTypeParameter);
                }

                var typeParameter = CreateGenericParameter(semanticType);

                typeParameter.Attributes                   = Cecil.Metadata.Members.GenericParameters.GetTypeParameterAttributes(parameter);
                typeParameter.Name                         = parameter.Name;
                typeParameter.FullName                     = parameter.FullName;
                typeParameter.Position                     = parameter.Position;
                typeParameter.TypeParameterKind            = GetTypeParameterKind(parameter.Type);
                typeParameter.Definition                   = parameter;
                typeParameter.SourceTypeReference          = parameter;
                typeParameter.DeclaringTypeDefinitionEntry = convertedTypeWithMethods;
                typeParameter.ResolutionName               = Cecil.Types.Naming.GetResolutionName(parameter);

                //method.TypeParameters.ByName.Add(parameter.Name, typeParameter);

                return(typeParameter);
            }
        }
示例#17
0
        public SemanticModuleMask_I Get(RuntimicSystemModel model, System.Type type)     // BELONGS HERE Because it takes in a TYPE
        {
            TypeReference typeReference = Models.Types.GetTypeReference(model, type);

            return(Get(model, typeReference));
        }
示例#18
0
 public void Ensure(RuntimicSystemModel semanticModel, AssemblyDefinition assemblyDefinition, ModuleDefinition module, TypeDefinition typeDefinition)
 {
     Infrastructure.Models.Structural.Ensure(semanticModel, assemblyDefinition, module, typeDefinition);
 }
示例#19
0
 public bool ContainsGenericMethodParameters(RuntimicSystemModel boundModel, GenericInstanceType genericInstance)
 {
     throw new System.NotImplementedException();
 }
示例#20
0
 public void AddAssemblyDefinition(RuntimicSystemModel semanticModel, AssemblyDefinition assemblyDefinition)
 {
     Infrastructure.Models.Structural.AddAssemblyDefinition(semanticModel, assemblyDefinition);
 }
示例#21
0
 public TypeReference GetTypeReference(RuntimicSystemModel model, Type input)
 {
     return(Infrastructure.Models.Semantic.Types.GetTypeReference(model, input));
 }
示例#22
0
 public Type ResolveToType(RuntimicSystemModel 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.");
 }
示例#23
0
 public TypeDefinition Resolve(RuntimicSystemModel model, Type genericTypeDefinitionType)
 {
     throw new Exception("Fix");
     //return (TypeDefinition)Cecil.Types.Getting.GetStoredTypeReference(model, genericTypeDefinitionType);
 }
示例#24
0
 public TypeReference GetTypeReference(RuntimicSystemModel model, Type input)
 {
     return(GetTypeReference(model, input, out SemanticTypeDefinitionMask_I semanticType));
 }
示例#25
0
        public System.Type GetBoundUnderlyingTypeOrThrow(RuntimicSystemModel model, string resolutionName)
        {
            var semanticType = Collection.GetOrThrow(model, resolutionName);

            return(GetBoundUnderlyingTypeOrThrow(semanticType));
        }
示例#26
0
 public SemanticAssemblyMask_I GetAssembly(RuntimicSystemModel model, AssemblyDefinition assemblyDefinition)
 {
     return(GetAssembly(model, assemblyDefinition.FullName));
 }
示例#27
0
 public void Extend(RuntimicSystemModel model, UnifiedAssemblyNode assemblyNode)
 {
     Extend(model, assemblyNode, null);
 }
示例#28
0
        /// <summary>
        /// Creates a SemanticTypeInformation instance from a System.Type.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="inputType"></param>
        /// <returns></returns>
        public SemanticTypeInformation CreateTypeInformation(RuntimicSystemModel model, System.Type inputType)
        {
            if (inputType?.FullName == null)
            {
                return(null);
            }



            var typeInformation = new SemanticTypeInformation
            {
                Name            = inputType.Name,
                FullName        = inputType.FullName,
                IsDelegate      = inputType.BaseType?.FullName == "System.Delegate" || inputType.BaseType?.FullName == "System.MulticastDelegate",
                IsArray         = inputType.IsArray,
                IsClass         = inputType.IsClass,
                IsInterface     = inputType.IsInterface,
                IsEnum          = inputType.IsEnum,
                IsOpenGeneric   = inputType.ContainsGenericParameters,
                IsClosedGeneric = inputType.GenericTypeArguments.Length > 0 && !inputType.ContainsGenericParameters,
                IsGlobal        = inputType.MetadataToken == 1,
                IsNested        = inputType.IsNested,
                IsValueType     = inputType.IsValueType,
            };

            typeInformation.IsGeneric = typeInformation.IsOpenGeneric || typeInformation.IsClosedGeneric;

            typeInformation.IsAnonymousType = IsAnonymousType(inputType);

            if (typeInformation.IsOpenGeneric)
            {
                typeInformation.GenericKind |= GenericTypeKind.Open;
            }

            if (typeInformation.IsClosedGeneric)
            {
                typeInformation.GenericKind |= GenericTypeKind.Closed;
            }

            if (inputType.GenericTypeArguments.Length > 0)
            {
                typeInformation.GenericKind |= GenericTypeKind.HasTypeArguments;
            }

            if (inputType.ContainsGenericParameters)
            {
                typeInformation.GenericKind |= GenericTypeKind.HasTypeParameters;
            }


            // Add the type information before any
            //model.Types.TypeInformations.Add(inputType.FullName, typeInformation);
            if (inputType.GenericTypeArguments.Length > 0)
            {
                var blueprint = inputType.GetGenericTypeDefinition();

                typeInformation.GenericTypeDefinition = Cecil.Types.Getting.GetStoredTypeReference(model, blueprint);
            }
            else
            {
                typeInformation.TypeReference = Cecil.Types.Getting.GetStoredTypeReference(model, inputType);
            }

            //// The issue is that type arguments can be generics themselves.
            //// The issue also is that arguments could have already been created.
            //typeInformation.TypeArguments = GetTypeParameters(model, inputType);
            //typeInformation.Interfaces = GetInterfaces(model, inputType);

            return(typeInformation);
        }
示例#29
0
        /// <summary>
        /// Resolves a type parameter for when a generic instance method is being created.
        /// This should not be used for resolving generic instance methods that are instructions as
        /// generic instance method arguments are not resolved.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="genericInstanceTypeArguments"></param>
        /// <param name="typeToResolve"></param>
        /// <returns></returns>
        public TypeReference ResolveTypeParameterIfPresent(RuntimicSystemModel model, TypeReference[] genericInstanceTypeArguments, TypeReference typeToResolve)
        {
            if (typeToResolve.IsByReference)
            {
                var inputByReferenceType = (ByReferenceType)typeToResolve;

                var inputByReferenceTypeElement = inputByReferenceType.ElementType;

                var result = ResolveTypeParameterIfPresent(model, genericInstanceTypeArguments, inputByReferenceTypeElement);

                return(new ByReferenceType(result));
            }

            if (typeToResolve.IsArray)
            {
                var arrayType = (ArrayType)typeToResolve;

                var rank = arrayType.Rank;

                var arrayElementType = arrayType.ElementType;

                var arrayElementReferenceType = ResolveTypeParameterIfPresent(model, genericInstanceTypeArguments, arrayElementType);

                if (rank == 1)
                {
                    return(new ArrayType(arrayElementReferenceType));
                }
                else
                {
                    return(new ArrayType(arrayElementReferenceType, rank));
                }
            }

            if (typeToResolve.IsGenericInstance)
            {
                GenericInstanceType genericInstanceType = (GenericInstanceType)typeToResolve;

                var genericInstanceTypeDef = ResolveTypeParameterIfPresent(model, genericInstanceTypeArguments, genericInstanceType.ElementType);

                TypeReference[] arguments = new TypeReference[genericInstanceType.GenericArguments.Count];

                for (int i = 0; i < genericInstanceType.GenericArguments.Count; i++)
                {
                    arguments[i] = ResolveTypeParameterIfPresent(model, genericInstanceTypeArguments,
                                                                 genericInstanceType.GenericArguments[i]);
                }

                return(genericInstanceTypeDef.MakeGenericInstanceType(arguments));
            }

            if (!typeToResolve.IsGenericParameter)
            {
                return(Infrastructure.Structural.Types.Ensure(model, typeToResolve).CecilTypeReference);
            }

            var genericParameter = (GenericParameter)typeToResolve;

            if (genericParameter.Type == GenericParameterType.Type)
            {
                // Becauase there is different generic instance type is created for each set of type arguments, generic parameters that are
                // type arguments can be replaced.
                return(genericInstanceTypeArguments[genericParameter.Position]);
            }
            else
            {
                // This method is called when creating method references for all instructions that might encounter this method reference.
                // When this method is built, there is no way to know ahead of time what instructions might be calling it.  Thus, this needs to
                // return just the method type parameter.
                return(typeToResolve);
            }
        }
示例#30
0
 public System.Type EnsureToType(RuntimicSystemModel model, TypeReference typeReference, out BoundTypeDefinitionMask_I boundType)
 {
     return(EnsureToType(model, typeReference, null, out boundType));
 }