コード例 #1
0
ファイル: GettingApi.cs プロジェクト: Evobolics/EvoAssembly
        public List <BoundMethodDefinitionMask_I> GetMethods(BoundTypeDefinitionMask_I inputBlueprint)
        {
            if (!(inputBlueprint is BoundTypeDefinitionWithMethodsMask_I withMethods))
            {
                throw new System.Exception("GenericClassDefinition should have methods if this type has methods.");
            }

            var collection = withMethods.Methods.ByName.Values.ToList();

            List <BoundMethodDefinitionMask_I> methods = new List <BoundMethodDefinitionMask_I>();

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

                for (int j = 0; j < semanticList.Count; j++)
                {
                    var semantic = semanticList[j];

                    if (!(semantic is BoundMethodDefinitionMask_I bound))
                    {
                        throw new System.Exception("Semantic method should be a bound method to use it in conversion.");
                    }

                    methods.Add(bound);
                }
            }

            return(methods);
        }
コード例 #2
0
ファイル: PropertyApi.cs プロジェクト: Evobolics/EvoAssembly
        public BoundPropertyDefinitionMask_I GetBoundProperty(BoundTypeDefinitionMask_I converted, string namedArgumentName)
        {
            if (!(converted is BoundTypeDefinitionWithPropertiesMask_I withProperties))
            {
                throw new System.Exception($"Expected converted to be of type {typeof(BoundTypeDefinitionWithPropertiesMask_I)}");
            }

            if (!withProperties.Properties.ByName.TryGetValue(namedArgumentName, out List <SemanticPropertyMask_I> list))
            {
                throw new System.Exception($"Expected a single property named {namedArgumentName}");
            }

            if (list.Count == 0)
            {
                throw new System.Exception($"Expected a single property named {namedArgumentName}.  List was empty.");
            }

            if (list.Count > 1)
            {
                throw new System.Exception($"Expected a single property named {namedArgumentName}.  Found more than one.");
            }

            if (!(list[0] is BoundPropertyDefinitionMask_I boundProperty))
            {
                throw new System.Exception($"Expected property to be of type {typeof(BoundPropertyDefinitionMask_I)}");
            }

            return(boundProperty);
        }
コード例 #3
0
ファイル: EnsuringApi.cs プロジェクト: Evobolics/EvoAssembly
        public System.Type EnsureToType(BoundTypeDefinitionMask_I boundType)
        {
            var underlyingType = boundType.UnderlyingType;

            if (underlyingType == null)
            {
                throw new System.Exception("Expected the underlying type to be filled in with a instance of a runtime type.");
            }

            return(underlyingType);
        }
コード例 #4
0
ファイル: BuildingApi.cs プロジェクト: Evobolics/EvoAssembly
        public MethodInfo MakeArrayMethod(ILConversion conversion, ConvertedTypeDefinitionMask_I callingType,
                                          BoundTypeDefinitionMask_I declaringType, MethodReference methodReference)
        {
            var systemParameters = Parameters.GetSystemParameterTypes(conversion, methodReference.Parameters);

            var returnType = Execution.Types.Ensuring.EnsureToType(conversion, methodReference.ReturnType);

            var callingConventions = Methods.GetCallingConventions(methodReference);

            return(callingType.Module.ModuleBuilder.GetArrayMethod(declaringType.UnderlyingType, methodReference.Name, callingConventions, returnType, systemParameters));
        }
コード例 #5
0
ファイル: EnsuringApi.cs プロジェクト: Evobolics/EvoAssembly
        public System.Type EnsureToType(SemanticTypeDefinitionMask_I semanticType, out BoundTypeDefinitionMask_I resultingBound)
        {
            // Can only build and bake types that are definitions.  References cannot be turned into full types.
            if (!(semanticType is BoundTypeDefinitionMask_I bound))
            {
                throw new Exception("A semantic type must be a bound type to be resolved to a runtime type.");
            }

            resultingBound = bound;

            return(EnsureToType(bound));
        }
コード例 #6
0
ファイル: GettingApi.cs プロジェクト: Evobolics/EvoAssembly
        public MethodInfo[] GetMethodInfos(BoundTypeDefinitionMask_I inputBlueprint)
        {
            var methodEntries = GetMethods(inputBlueprint);

            var methods = new MethodInfo[methodEntries.Count];

            for (int i = 0; i < methodEntries.Count; i++)
            {
                methods[i] = methodEntries[i].UnderlyingMethod;
            }

            return(methods);
        }
コード例 #7
0
ファイル: EnsuringApi.cs プロジェクト: Evobolics/EvoAssembly
        public ExecutionTypeDefinitionMask_I Ensure(RuntimicSystemModel runtimicModel, TypeReference typeReference,
                                                    System.Type underlyingType, BoundTypeDefinitionMask_I declaringType)
        {
            var context = new ExecutionEnsureContext()
            {
                UnderlyingType = underlyingType,
                TypeReference  = typeReference,
                DeclaringType  = declaringType,
                RuntimicSystem = runtimicModel
            };

            return(Ensure(context).Type);
        }
コード例 #8
0
ファイル: EnsuringApi.cs プロジェクト: Evobolics/EvoAssembly
        public ExecutionTypeDefinitionMask_I Ensure(ILConversion conversion, TypeReference typeReference,
                                                    System.Type underlyingType, BoundTypeDefinitionMask_I declaringType)
        {
            var context = new ExecutionEnsureContext()
            {
                UnderlyingType = underlyingType,
                TypeReference  = typeReference,
                DeclaringType  = declaringType,
                RuntimicSystem = conversion.RuntimicSystem,
                Conversion     = conversion
            };

            return(Ensure(context).Type);
        }
コード例 #9
0
        public MethodInfo GetMethodInfoOrThrow(ILConversion conversion, ConvertedTypeDefinitionMask_I typeBeingBuilt,
                                               ConvertedRoutine methodBeingBuilt, BoundTypeDefinitionMask_I methodReferenceDeclaringType, MethodReference methodReference)
        {
            //var declaringType = Execution.Types.Ensuring.EnsureBound(conversion.Model, methodReference.DeclaringType);

            if (!(methodReferenceDeclaringType is BoundTypeDefinitionWithMethodsMask_I declaringTypeWithMethods))
            {
                throw new System.Exception("Expected a type with methods declared.");
            }

            var methodInfo = GetMethodOrThrow_Internal(conversion, typeBeingBuilt, declaringTypeWithMethods, methodReference);

            if (methodInfo == null)
            {
                throw new System.Exception("Could not locate a MethodInfo.");
            }

            if (!methodReference.IsGenericInstance)
            {
                return(methodInfo);
            }

            if (!methodInfo.IsGenericMethod)
            {
                throw new System.Exception("Did not find a generic method");
            }

            var genericInstanceMethod = (GenericInstanceMethod)methodReference;

            var typeArguments = new Type[genericInstanceMethod.GenericArguments.Count];

            for (var i = 0; i < typeArguments.Length; i++)
            {
                var typeArgumentReference = genericInstanceMethod.GenericArguments[i];

                var semanticTypeNode = Execution.Types.Ensuring.Ensure(new ExecutionEnsureContext()
                {
                    Conversion      = conversion,
                    RuntimicSystem  = conversion.RuntimicSystem,
                    TypeReference   = typeArgumentReference,
                    MethodReference = methodBeingBuilt.MethodReference
                });



                typeArguments[i] = semanticTypeNode.Type.UnderlyingType;
            }

            return(methodInfo.MakeGenericMethod(typeArguments));
        }
コード例 #10
0
        public ConstructorInfo FindConstructorBySignature(RuntimicSystemModel boundModel,
                                                          BoundTypeDefinitionMask_I methodReferenceDeclaringType, MethodReference methodReference)
        {
            // NOTE - This version of the method cannot access constructor builders, which are neccessary when building
            //        constructor calls for a converted classes instructions.

            var parameterTypes = Parameters.GetSystemParameterTypes(boundModel, methodReferenceDeclaringType.SourceTypeReference, methodReference);

            //if (methodReferenceDeclaringType.SourceTypeReference.IsGenericInstance)
            //{
            //    GenericInstanceType genericInstance = (GenericInstanceType)methodReferenceDeclaringType.SourceTypeReference;

            //    if (Execution.Types.IsConverted(boundModel, methodReference.DeclaringType) && Cecil.Types.ContainsGenericMethodParameters(genericInstance))
            //    {
            //        var dictionaryType = methodReferenceDeclaringType.UnderlyingType.GetGenericTypeDefinition();
            //        var x = dictionaryType.GetConstructor(parameterTypes);
            //        var y = TypeBuilder.GetConstructor(methodReferenceDeclaringType.UnderlyingType, x);

            //        return y;
            //    }
            //}

            //if (declaringType.FullName == "System.Collections.Generic.Dictionary`2<System.String,T1>")
            //{
            //    var generic = declaringType.UnderlyingType.GetGenericTypeDefinition();

            //    var x1 = (TypeBuilder) declaringType.UnderlyingType;

            //    var x = generic.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            //    var y = generic.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            //    var result = TypeBuilder.GetConstructor(generic, x[0]);
            //}

            // Using the BindingFlags.Instance is important as certain constructors (like System.Attribute) will not show up without it.
            var constructor = methodReferenceDeclaringType.UnderlyingType.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, parameterTypes, null);

            if (constructor == null)
            {
                throw new System.Exception("Could not find constructor.");
            }

            return(constructor);
        }
コード例 #11
0
        public BoundFieldDefinitionMask_I GetBoundField(BoundTypeDefinitionMask_I converted, string namedArgumentName)
        {
            if (!(converted is BoundTypeDefinitionWithFieldsMask_I withFields))
            {
                throw new System.Exception($"Expected converted to be of type {typeof(BoundTypeDefinitionWithFieldsMask_I)}");
            }

            if (!withFields.Fields.ByName.TryGetValue(namedArgumentName, out SemanticFieldMask_I semanticField))
            {
                throw new System.Exception($"Expected a single field named {namedArgumentName}");
            }

            if (!(semanticField is BoundFieldDefinitionMask_I boundField))
            {
                throw new System.Exception($"Expected field to be of type {typeof(BoundFieldDefinitionMask_I)}");
            }

            return(boundField);
        }
コード例 #12
0
ファイル: GatheringApi.cs プロジェクト: Evobolics/EvoAssembly
        public BoundTypeDefinitionMask_I EnsureBaseType(ILConversion conversion, ConvertedTypeDefinition_I converted)
        {
            var baseTypeReference = Infrastructure.Structural.Cecil.GetBaseType(converted.SourceTypeReference);

            BoundTypeDefinitionMask_I boundBaseType = null;

            if (baseTypeReference != null)
            {
                var result = Execution.Types.Ensuring.Ensure(conversion, baseTypeReference, null, converted);

                if (!(result is BoundTypeDefinitionMask_I boundBaseType1))
                {
                    throw new Exception("When creating a conversion model, the base type needs to be a bound type.");
                }

                boundBaseType = boundBaseType1;

                converted.BaseType = boundBaseType;
            }

            System.Type baseType;

            if (converted.IsStruct())
            {
                baseType = boundBaseType?.UnderlyingType ?? GetValueType(conversion);
            }
            else
            {
                baseType = boundBaseType?.UnderlyingType ?? (converted.IsClassType() ? GetObjectType(conversion) : null);
            }

            if (baseType == null && (converted.IsClassType() || converted.IsStruct()))
            {
                throw new Exception("The bound's undelrying type cannot be null.  The converted type is a class or struct, and in either case requires a base class of either System.Object or System.ValueType.");
            }

            converted.TypeBuilder.SetParent(baseType);

            return(boundBaseType);
        }
コード例 #13
0
ファイル: MemberApi.cs プロジェクト: Evobolics/EvoAssembly
        public bool GetMemberInfo(ILConversion conversion, ConvertedTypeDefinitionMask_I typeBeingBuilt,
                                  ConvertedRoutine routineBeingBuilt,
                                  BoundTypeDefinitionMask_I methodReferenceDeclaringType,
                                  MethodReference methodReference, out MemberInfo memberInfo)
        {
            if (methodReference == null)
            {
                throw new System.Exception($"Member reference is null. Cannot resolve member info.");
            }



            // If a constructor
            if (methodReference.Name == ConstructorInfo.ConstructorName)
            {
                return(Constructors.Getting.GetConstructor(conversion, typeBeingBuilt, methodReferenceDeclaringType, methodReference, out memberInfo));
            }

            memberInfo = Methods.Getting.GetMethodInfoOrThrow(conversion, typeBeingBuilt, routineBeingBuilt, methodReferenceDeclaringType, methodReference);

            return(memberInfo != null);
        }
コード例 #14
0
ファイル: BuildingApi.cs プロジェクト: Evobolics/EvoAssembly
        public BoundTypeDefinitionMask_I[] Build(RuntimicSystemModel semanticModel, GenericInstanceType inputType)
        {
            if (inputType.GenericArguments.Count <= 0)
            {
                return(new BoundTypeDefinitionMask_I[0]);
            }

            var types = new BoundTypeDefinitionMask_I[inputType.GenericArguments.Count];

            for (var i = 0; i < inputType.GenericArguments.Count; i++)
            {
                var genericArgument = inputType.GenericArguments[i];

                types[i] = Execution.Types.Ensuring.EnsureBound(semanticModel, genericArgument, null);

                if (types[i].SourceTypeReference == null)
                {
                    throw new Exception("null type reference");
                }
            }

            return(types);
        }
コード例 #15
0
        //public new UnifiedApi_I<TContainer> Unified { get; set; }

        //UnifiedApiMask_I EnsuringApiMask_I.Unified => Unified;

        #endregion



        public bool EnsurePhase3Type(ILConversion conversion,
                                     ConvertedTypeDefinitionMask_I routineDeclaringType,
                                     MethodDefinition methodDefinition,
                                     TypeReference typeReference,
                                     out BoundTypeDefinitionMask_I type)
        {
            type = Execution.Types.Ensuring.EnsureBound(new ExecutionEnsureContext()
            {
                RuntimicSystem       = conversion.RuntimicSystem,
                Conversion           = conversion,
                TypeReference        = typeReference,
                MethodReference      = methodDefinition,
                RoutineDeclaringType = routineDeclaringType
            });

            if ((type is ConvertedTypeDefinition_I convertedType))
            {
                if (Types.Building.CheckForPhase3Dependency(convertedType, (ConvertedTypeDefinition_I)routineDeclaringType, true))
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #16
0
 public TypeDefinition GetElementType(RuntimicSystemModel semanticModel, BoundTypeDefinitionMask_I bound)
 {
     return(Infrastructure.Semantic.Metadata.Members.Types.GenericInstances.GetElementType(semanticModel, bound));
 }
コード例 #17
0
        public SemanticTypeDefinitionMask_I Ensure(RuntimicSystemModel semanticModel, GenericInstanceType input, BoundTypeDefinitionMask_I declaringType)
        {
            var typeArguments = Members.TypeArguments.Building.Build(semanticModel, input);

            var blueprint = (BoundGenericTypeDefinitionMask_I)Execution.Types.Ensuring.EnsureBound(semanticModel, input.ElementType, null);

            if (IfAlreadyCreatedReturn(blueprint, typeArguments, out SemanticTypeDefinitionMask_I ensure))
            {
                return(ensure);
            }

            var typeArgumentTypes = GetTypes(typeArguments, out bool hasGenericParameters);

            var underlyingType = Bound.MakeGenericType(blueprint, typeArgumentTypes);

            var bound = (BoundGenericTypeDefinition_I)Types.Creation.Create(semanticModel, input, underlyingType);

            for (var j = 0; j < typeArguments.Length; j++)
            {
                var currentTypeArgument = typeArguments[j];

                bound.TypeArguments.All.Add(currentTypeArgument);
            }

            bound.Blueprint = blueprint;

            blueprint.Instances.Add(bound);



            if (input.IsGenericInstance && underlyingType.IsGenericTypeDefinition)
            {
                //throw new Exception("Semantic types that are generic instances but treated as a genreic type definition are not directly supported yet.");
            }

            if (hasGenericParameters && underlyingType.IsGenericTypeDefinition)
            {
                // Check to see if effectively is a generic type definition.
                // A) Do not try to get methods for types that are generic type definitions
            }
            else
            {
                Fields.Building.Generic.BuildFields(semanticModel, bound);

                Constructors.Building.BuildConstructors(semanticModel, bound);

                Methods.Building.BuildMethods(semanticModel, bound);
            }
            //      //Fields.Building.Generic.BuildFields_WithGenericTypeParameters(semanticModel, bound, blueprint);

            //	// Check to see if effectively is a generic type definition.
            //	// A) Do not try to get methods for types that are generic type definitions
            //	// B) Do not try to get methods for typee that are effectively generic type definitions becuase they contain
            //	//    unbound method generic parameters which can only become bound when the method arguments are filled in with
            //	//    non-geneic parameters or generic type parmeters (not method parameters)
            //	//
            //	//    Notes:
            //	//    The issue is not creating the type, the issue is creating the methods.  The runtime does not allow you to
            //	//    ask for a list of runtime methods that have open type parameters becuase they are not invokeable.  It will give
            //	//    you the type to use as you mgiht need the type for declaring method return types or parameter types.
            //	//
            //	//var containsGenericMethodParameters = Cecil.Types.ContainsGenericMethodParameters(input);

            //       if (!underlyingType.IsGenericTypeDefinition
            //		//&& !containsGenericMethodParameters
            //		)
            //       {
            //	Fields.Building.Generic.BuildFields(semanticModel, bound);

            //        Methods.Building.BuildMethods(semanticModel, bound);
            //}

            //      else
            //      {
            //       Fields.Building.Generic.BuildFields(semanticModel, bound);

            //	Methods.Building.BuildMethods(semanticModel, bound);
            //}

            //



            return(bound);
        }
コード例 #18
0
ファイル: PointerApi.cs プロジェクト: Evobolics/EvoAssembly
        public SemanticTypeDefinitionMask_I Ensure(BoundRuntimicModelMask_I semanticModel, TypeReference input, BoundTypeDefinitionMask_I declaringType, System.Type underlyingType)
        {
            string resolutionName = Cecil.Types.Naming.GetPointerElementName(input);

            var node = Unified.Types.Get(semanticModel, resolutionName);

            if (node.PointerType != null)
            {
                return(node.PointerType);
            }

            var bound = Types.Creation.Create(semanticModel, input, underlyingType);

            // Add the type instance to the model.  Do not do any recursive calls till this methods is called.
            node.PointerType = bound;


            if (bound.IsNestedType())
            {
                if (declaringType == null)
                {
                    throw new Exception("Declaring type is null.  Cannot create a nested type.");
                }

                var nestedType = (BoundTypeDefinitionWithDeclaringType_I)bound;

                nestedType.DeclaringType = declaringType;
            }


            bound.UnderlyingType = underlyingType;

            Members.TypeParameters.Building.EnsureTypeParametersIfAny(semanticModel, bound);

            return(bound);
        }
コード例 #19
0
        public SemanticTypeDefinitionMask_I Ensure(RuntimicSystemModel semanticModel, TypeReference input, BoundTypeDefinitionMask_I declaringType, System.Type underlyingType)
        {
            throw new Exception("Fix");

            ////  Try to see if the model is already present
            //if (Models.Types.Collection.TryGet(semanticModel, input, out SemanticTypeDefinitionMask_I maskedType))
            //{
            //	if (!(maskedType is BoundTypeDefinitionMask_I boundType))
            //	{
            //		throw new System.Exception(
            //			$"The type {input.FullName} was found in the conversion model, but it is not a bound type definition.  " +
            //			$"A bound type is required due to the need for a underlying type when creating type builders.");
            //	}

            //	return boundType;
            //}

            ////---------------------------------
            //// Conversion is going to occur.
            ////---------------------------------

            //var bound = Types.Creation.Create(semanticModel, input, underlyingType);



            //// Add the type instance to the model.  Do not do any recursive calls till this methods is called.
            ////Types.Addition.Add(semanticModel, boundModule, bound);

            //// Done on purpose to find errors
            //var requiredModifierType = (RequiredModifierType)input;



            //if (bound.IsNestedType())
            //{
            //	if (declaringType == null)
            //	{
            //		throw new Exception("Declaring type is null.  Cannot create a nested type.");
            //	}

            //	var nestedType = (BoundTypeDefinitionWithDeclaringType_I)bound;

            //	nestedType.DeclaringType = declaringType;
            //}


            //bound.UnderlyingType = underlyingType;

            //Members.TypeParameters.Building.EnsureTypeParametersIfAny(semanticModel, bound);



            //return bound;
        }
コード例 #20
0
ファイル: EnsuringApi.cs プロジェクト: Evobolics/EvoAssembly
        public Type EnsureToType(ILConversion conversion, TypeReference typeReference, out BoundTypeDefinitionMask_I boundType)
        {
            var context = new ExecutionEnsureContext()
            {
                Conversion     = conversion,
                RuntimicSystem = conversion.RuntimicSystem,
                TypeReference  = typeReference
            };

            return(EnsureToType(context, out boundType));
        }
コード例 #21
0
        public BoundTypeDefinition Build(RuntimicSystemModel semanticModel, BoundTypeDefinition bound, Type underlyingType, BoundTypeDefinitionMask_I declaringType)
        {
            if (bound.IsNestedType())
            {
                if (declaringType == null)
                {
                    throw new Exception("Declaring type is null.  Cannot create a nested type.");
                }

                var nestedType = (BoundTypeDefinitionWithDeclaringType_I)bound;

                nestedType.DeclaringType = declaringType;
            }

            bound.UnderlyingType = underlyingType;

            if (underlyingType == null)
            {
                return(bound);
            }

            Members.TypeParameters.Building.EnsureTypeParametersIfAny(semanticModel, bound);

            Fields.Building.NonGeneric.BuildFields(semanticModel, bound);

            Constructors.Building.BuildConstructors(semanticModel, bound);

            Methods.Building.BuildMethods(semanticModel, bound);

            return(bound);
        }
コード例 #22
0
 public int GetToken(BoundTypeDefinitionMask_I boundType)
 {
     throw new System.NotImplementedException();
 }
コード例 #23
0
ファイル: EnsuringApi.cs プロジェクト: Evobolics/EvoAssembly
        public System.Type EnsureToType(ExecutionEnsureContext context, out BoundTypeDefinitionMask_I boundType)
        {
            boundType = EnsureBound(context);

            return(EnsureToType(boundType));
        }
コード例 #24
0
        public MemberInfo FindConstructorBySignature(RuntimicSystemModel conversionModel, BoundTypeDefinitionMask_I typeEntry, MemberReference memberReference)
        {
            switch (memberReference.MetadataToken.TokenType)
            {
            case TokenType.Method:
            case TokenType.MemberRef:
            {
                return(FindConstructorBySignature(conversionModel, typeEntry, (MethodReference)memberReference));
            }

            case TokenType.MethodSpec:
            {
                throw new System.Exception("Not handled");
            }

            default:
            {
                throw new System.Exception("Not handled");
            }
            }
        }
コード例 #25
0
ファイル: EnsuringApi.cs プロジェクト: Evobolics/EvoAssembly
        public System.Type EnsureToType(RuntimicSystemModel model, TypeReference typeReference, System.Type underlyingType, out BoundTypeDefinitionMask_I boundType)
        {
            var context = new ExecutionEnsureContext()
            {
                RuntimicSystem = model,
                UnderlyingType = underlyingType,
                TypeReference  = typeReference
            };

            return(EnsureToType(context, out boundType));
        }
コード例 #26
0
ファイル: EnsuringApi.cs プロジェクト: Evobolics/EvoAssembly
 // TODO: Rename to GetRuntimeType
 public System.Type EnsureToType(ILConversion conversion, BoundTypeDefinitionMask_I semanticType)
 {
     return(Bound.Models.Types.ResolveToType(conversion.Model, semanticType));
 }
コード例 #27
0
        public SemanticTypeDefinitionMask_I Ensure(BoundRuntimicModelMask_I semanticModel, TypeReference input, BoundTypeDefinitionMask_I declaringType, System.Type underlyingType)
        {
            ArrayType arrayType = (ArrayType)input;

            SemanticTypeDefinitionMask_I elementType;


            if (underlyingType == null)
            {
                elementType = Execution.Types.Ensuring.Ensure(semanticModel, arrayType.ElementType, null, null);
            }
            else
            {
                elementType = Execution.Types.Ensuring.Ensure(semanticModel, arrayType.ElementType, underlyingType.GetElementType(), null);
            }

            if (IfAlreadyCreatedReturn(elementType, arrayType.Rank, out SemanticArrayTypeDefinitionMask_I existing))
            {
                return(existing);
            }

            var bound = Types.Creation.Create(semanticModel, input, null);

            bound.SourceTypeReference = input;

            var arrayDef = (BoundArrayTypeDefinition_I)bound;

            elementType.Arrays.Add(arrayType.Rank, arrayDef);

            arrayDef.ElementType = elementType;

            bound.BaseType = Execution.Types.Ensuring.Ensure(semanticModel, typeof(System.Array));

            if (!arrayDef.ElementType.IsBound())
            {
                throw new System.Exception("Expected the element type to be a bound type. Cannot create the undelrying array type without a runtime type.");
            }

            var arrayElementType = (BoundTypeDefinitionMask_I)arrayDef.ElementType;

            var arrayElementUndelryingType = arrayElementType.UnderlyingType;

            if (arrayType.Rank == 1)
            {
                // Makes a vector
                bound.UnderlyingType = arrayElementUndelryingType.MakeArrayType();
            }
            else
            {
                // Makes an multi-dimensional array
                bound.UnderlyingType = arrayElementUndelryingType.MakeArrayType(arrayType.Rank);
            }

            return(bound);
        }
コード例 #28
0
        public SemanticTypeDefinitionMask_I Ensure(RuntimicSystemModel semanticModel, TypeReference input, BoundTypeDefinitionMask_I declaringType, System.Type underlyingType)
        {
            throw new Exception("Fix");

            //   //  Try to see if the model is already present
            //   if (Models.Types.Collection.TryGet(semanticModel, input, out SemanticTypeDefinitionMask_I maskedType))
            //   {
            //    if (!(maskedType is BoundTypeDefinitionMask_I boundType))
            //    {
            //	    throw new System.Exception(
            //		    $"The type {input.FullName} was found in the conversion model, but it is not a bound type definition.  " +
            //		    $"A bound type is required due to the need for a underlying type when creating type builders.");
            //    }

            //    return boundType;
            //   }

            //      if (input.FullName == "System.Collections.Generic.Dictionary`2/ValueCollection/Enumerator")
            //      {
            //      }

            ////---------------------------------
            //// Conversion is going to occur.
            ////---------------------------------



            //var bound = Types.Creation.Create(semanticModel, input, underlyingType);

            //      // Get the module to ensure that the type is part of the module.
            //      var semanticModule = Modules.Getting.Get(semanticModel, input);

            //      if (!(semanticModule is BoundModuleMask_I boundModule))
            //      {
            //       var result = Semantic.Metadata.Members.Types.Ensuring.Ensure(semanticModel, semanticModule, input);

            //       throw new Exception("Need to fix return type.");
            //      }

            //      bound.Module = boundModule;


            //// Add the type instance to the model.  Do not do any recursive calls till this methods is called.
            //Types.Addition.Add(semanticModel, boundModule, bound);

            //         return Types.Building.NonGenericInstances.Phase1Initial.Build(semanticModel, bound, underlyingType, declaringType);
        }
コード例 #29
0
        public bool GetConstructor(ILConversion conversion, ConvertedTypeDefinitionMask_I callingType, BoundTypeDefinitionMask_I declaringBound, MethodReference methodReference, out MemberInfo memberInfo)
        {
            memberInfo = null;



            if (!declaringBound.IsConverted())
            {
                // NOTE - This call can only be used when accessing types that fully built.
                memberInfo = Bound.Metadata.Members.Constructors.FindConstructorBySignature(conversion.RuntimicSystem, declaringBound, methodReference);
            }
            else
            {
                if (declaringBound.SourceTypeReference.IsArray)
                {
                    memberInfo = Methods.Building.MakeArrayMethod(conversion, callingType, declaringBound, methodReference);

                    return(true);
                }

                // This method HAS to be used for accessing constructors of types that are not fullying built.
                var withConstructors = (BoundTypeDefinitionWithConstructorsMask_I)declaringBound;

                var semanticConstructor = GetConstructor(conversion, withConstructors, methodReference);

                if (semanticConstructor == null)
                {
                    return(false);
                }

                if (!(semanticConstructor is BoundConstructorDefinitionMask_I boundConstructor))
                {
                    throw new Exception("Semantic constructor is not a bound constructor.  Cannot return a constructor info from a non-executive type.");
                }

                memberInfo = boundConstructor.UnderlyingConstructor;
            }

            return(memberInfo != null);
        }
コード例 #30
0
ファイル: EnsuringApi.cs プロジェクト: Evobolics/EvoAssembly
 public System.Type EnsureToType(RuntimicSystemModel model, TypeReference typeReference, out BoundTypeDefinitionMask_I boundType)
 {
     return(EnsureToType(model, typeReference, null, out boundType));
 }