示例#1
0
        public void CreatePost(ConvertedTypeDefinition converted, SemanticTypeInformation typeInformation)
        {
            if (converted.IsGeneric())
            {
                var generic = (ConvertedGenericTypeDefinition_I)converted;

                generic.GenericKind = typeInformation.GenericKind;

                generic.SourceGenericInstanceType = typeInformation.GenericInstanceType;

                if (typeInformation.GenericTypeDefinition == null)
                {
                    if (typeInformation.IsClosedGeneric && !typeInformation.IsAnonymousType)
                    {
                        throw new System.Exception("Expected a generic type definition");
                    }
                }
            }


            converted.AssemblyQualifiedName = Cecil.Metadata.Members.Types.Naming.GetAssemblyQualifiedName(typeInformation.TypeReference);
            converted.FullName            = typeInformation.FullName;
            converted.Name                = typeInformation.Name;
            converted.PackingSize         = typeInformation.PackingSize;
            converted.SourceTypeReference = typeInformation.TypeReference;
            converted.ResolutionName      = Types.Naming.GetResolutionName(converted);
            if (typeInformation.IsGlobal)
            {
                converted.TypeKind |= Enums.E01D.Runtimic.Infrastructure.Metadata.Members.Typal.TypeKind.Global;
            }
        }
示例#2
0
        public ConvertedTypeDefinition CreateFactory(SemanticTypeInformation typeInformation)
        {
            return((ConvertedTypeDefinition)this.Infrastructure.Semantic.Metadata.Members.Types.Creation.Factory.CreateType <
                       ConvertedGenericStructTypeDefinition,
                       ConvertedGenericDelegateTypeDefinition,
                       ConvertedGenericClassTypeDefinition,
                       ConvertedGenericInterfaceTypeDefinition,
                       ConvertedGenericNestedStructTypeDefinition,
                       ConvertedGenericNestedDelegateTypeDefinition,

                       ConvertedGenericNestedClassTypeDefinition,
                       ConvertedGenericNestedInterfaceTypeDefinition,
                       ConvertedNestedEnumTypeDefinition,
                       ConvertedNestedStructTypeDefinition,
                       ConvertedNestedDelegateTypeDefinition,

                       ConvertedNestedClassTypeDefinition,
                       ConvertedNestedInterfaceTypeDefinition,
                       ConvertedSimpleClTypeDefinition,
                       ConvertedEnumTypeDefinition,
                       ConvertedStructTypeDefinition,
                       ConvertedDelegateTypeDefinition,
                       ConvertedArrayTypeDefinition,
                       ConvertedClassTypeDefinition,
                       ConvertedInterfaceTypeDefinition,
                       ConvertedPointerTypeDefinition,
                       ConvertedRequiredModifierTypeDefinition>(typeInformation));
        }
示例#3
0
        public object CreateType
        <
            TGenericStructTypeDefinition,
            TGenericDelegateTypeDefinition,
            TGenericClassTypeDefinition,
            TGenericInterfaceTypeDefinition,
            TGenericNestedStructTypeDefinition,
            TGenericNestedDelegateTypeDefinition,

            TGenericNestedClassTypeDefinition,
            TGenericNestedInterfaceTypeDefinition,
            TNestedEnumTypeDefinition,
            TNestedStructTypeDefinition,
            TNestedDelegateTypeDefinition,

            TNestedClassTypeDefinition,
            TNestedInterfaceTypeDefinition,
            TSimpleClTypeDefinition,
            TEnumTypeDefinition,
            TStructTypeDefinition,
            TDelegateTypeDefinition,
            TArrayTypeDefinition,
            TClassTypeDefinition,
            TInterfaceTypeDefinition,
            TPointerTypeDefinition,
            TRequiredModifierTypeDefinition>(SemanticTypeInformation typeInformation)
            where TGenericNestedStructTypeDefinition :  new()
            where TGenericNestedDelegateTypeDefinition :   new()

            where TGenericNestedClassTypeDefinition :   new()
            where TGenericNestedInterfaceTypeDefinition :  new()

            where TGenericStructTypeDefinition :   new()
            where TGenericDelegateTypeDefinition :   new()
            where TGenericClassTypeDefinition :   new()
            where TGenericInterfaceTypeDefinition :   new()
            where TNestedEnumTypeDefinition :  new()
            where TNestedStructTypeDefinition :  new()
            where TNestedDelegateTypeDefinition :  new()

            where TNestedClassTypeDefinition :  new()
            where TNestedInterfaceTypeDefinition :  new()
            where TSimpleClTypeDefinition :  new()
            where TEnumTypeDefinition :  new()
            where TStructTypeDefinition :  new()
            where TDelegateTypeDefinition :  new()
            where TArrayTypeDefinition :  new()
            where TClassTypeDefinition :  new()
            where TInterfaceTypeDefinition :  new()
            where TPointerTypeDefinition : new()
            where TRequiredModifierTypeDefinition : new()

        {
            object boundTypeDefinition;

            if (typeInformation.IsGeneric)
            {
                if (typeInformation.IsNested)
                {
                    if (typeInformation.IsValueType) // needs to be before
                    {
                        if (IsSimpleType(typeInformation.FullName))
                        {
                            throw new System.Exception("There are no generic simple types.  This is not expected.");
                        }
                        if (typeInformation.IsEnum)
                        {
                            // Not really a generic, but this logic does occur.
                            boundTypeDefinition = new TNestedEnumTypeDefinition();
                        }
                        else
                        {
                            boundTypeDefinition = new TGenericNestedStructTypeDefinition();
                        }
                    }
                    else if (typeInformation.IsDelegate)//(typeDefinition.IsFunctionPointer || typeDefinition.BaseType?.FullName == "System.Delegate" || typeDefinition.BaseType?.FullName == "System.MulticastDelegate")
                    {
                        boundTypeDefinition = new TGenericNestedDelegateTypeDefinition();
                    }
                    else if (typeInformation.IsArray)
                    {
                        throw new System.Exception("Not supported");
                    }
                    else if (typeInformation.IsClass)
                    {
                        boundTypeDefinition = new TGenericNestedClassTypeDefinition();
                    }
                    else if (typeInformation.IsInterface)
                    {
                        boundTypeDefinition = new TGenericNestedInterfaceTypeDefinition();
                    }
                    else
                    {
                        throw new System.NotImplementedException();
                    }
                }
                else
                {
                    if (typeInformation.IsValueType) // needs to be before
                    {
                        if (IsSimpleType(typeInformation.FullName))
                        {
                            throw new System.Exception("Not implemented.");
                        }

                        else if (typeInformation.IsEnum)
                        {
                            throw new System.Exception("Not expected");
                        }
                        else
                        {
                            boundTypeDefinition = new TGenericStructTypeDefinition();
                        }
                    }
                    else if (typeInformation.IsDelegate)//(typeDefinition.IsFunctionPointer || typeDefinition.BaseType?.FullName == "System.Delegate" || typeDefinition.BaseType?.FullName == "System.MulticastDelegate")
                    {
                        boundTypeDefinition = new TGenericDelegateTypeDefinition();
                    }
                    else if (typeInformation.IsArray)
                    {
                        throw new System.Exception("Not supported");
                    }
                    else if (typeInformation.IsClass)
                    {
                        boundTypeDefinition = new TGenericClassTypeDefinition();
                    }
                    else if (typeInformation.IsInterface)
                    {
                        boundTypeDefinition = new TGenericInterfaceTypeDefinition();
                    }
                    else
                    {
                        throw new System.NotImplementedException();
                    }
                }
            }
            else
            {
                if (typeInformation.IsNested)
                {
                    if (typeInformation.IsValueType) // needs to be before
                    {
                        if (IsSimpleType(typeInformation.FullName))
                        {
                            throw new System.Exception("Not expected");
                        }
                        if (typeInformation.IsEnum)
                        {
                            boundTypeDefinition = new TNestedEnumTypeDefinition();
                        }
                        else
                        {
                            boundTypeDefinition = new TNestedStructTypeDefinition();
                        }
                    }
                    else if (typeInformation.IsDelegate)//(typeDefinition.IsFunctionPointer || typeDefinition.BaseType?.FullName == "System.Delegate" || typeDefinition.BaseType?.FullName == "System.MulticastDelegate")
                    {
                        boundTypeDefinition = new TNestedDelegateTypeDefinition();
                    }
                    else if (typeInformation.IsArray)
                    {
                        throw new System.Exception("Not supported");
                    }
                    else if (typeInformation.IsClass)
                    {
                        boundTypeDefinition = new TNestedClassTypeDefinition();
                    }
                    else if (typeInformation.IsInterface)
                    {
                        boundTypeDefinition = new TNestedInterfaceTypeDefinition();
                    }
                    else
                    {
                        throw new System.NotImplementedException();
                    }
                }
                else
                {
                    if (typeInformation.IsValueType) // needs to be before
                    {
                        if (IsSimpleType(typeInformation.FullName))
                        {
                            boundTypeDefinition = new TSimpleClTypeDefinition();
                        }

                        else if (typeInformation.IsEnum)
                        {
                            boundTypeDefinition = new TEnumTypeDefinition();
                        }
                        else
                        {
                            boundTypeDefinition = new TStructTypeDefinition();
                        }
                    }
                    else if (typeInformation.IsDelegate)
                    {
                        boundTypeDefinition = new TDelegateTypeDefinition();
                    }
                    else if (typeInformation.IsArray)
                    {
                        boundTypeDefinition = new TArrayTypeDefinition();
                    }
                    else if (typeInformation.IsClass)
                    {
                        boundTypeDefinition = new TClassTypeDefinition();
                    }
                    else if (typeInformation.IsInterface)
                    {
                        boundTypeDefinition = new TInterfaceTypeDefinition();
                    }
                    else if (typeInformation.IsPointer)
                    {
                        boundTypeDefinition = new TPointerTypeDefinition();
                    }
                    else if (typeInformation.IsRequiredModifier)
                    {
                        boundTypeDefinition = new TRequiredModifierTypeDefinition();
                    }
                    else
                    {
                        throw new Exception("Not expected.");
                    }
                }
            }



            return(boundTypeDefinition);
        }
示例#4
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);
        }
示例#5
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);
        }