public SemanticTypeDefinitionMask_I Ensure(ILConversion conversion, TypeReference input, ConvertedTypeDefinition_I convertedDeclaringType) { if (input.FullName == //"Root.Testing.Resources.Models.E01D.Runtimic.Execution.Emitting.Conversion.Inputs.Types.GenericWithGenericMembers`1" "Root.Testing.Resources.Models.E01D.Runtimic.Execution.Emitting.Conversion.Inputs.Types.BaseClass" ) { } // Try to see if the model is already present if (Models.Types.TryGet(conversion.RuntimicSystem, 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. //--------------------------------- ConvertedTypeDefinition converted = Types.Creation.Create(conversion.RuntimicSystem, input); // Get the module to ensure that the type is part of the module. var semanticModule = Modules.Ensuring.EnsureAssignedModule(conversion, input); // If the input is converted, then the module needs to be convertible due to the need to have a module builder. if (!(semanticModule is ConvertedModule_I convertedModule)) { throw new Exception("The semantic model has deemed the type is convertible, but the module passed into the Ensure method is not convertible. The module " + "needs to be convertible due to the need of having a module builder."); } converted.Module = convertedModule; // Add the type instance to the model. Do not do any recursive calls till this methods is called. Types.Addition.Add(conversion, convertedModule, converted); Types.Building.NonGenericInstances.Phase1Initial.Build(conversion, converted, convertedDeclaringType); Types.Building.IfPossibleBuildPhase2(conversion, converted); return(converted); }
public void AssignTypeParameters(ILConversion conversion, ConvertedTypeDefinition type, List <ConvertedGenericParameterTypeDefinition> typeParameters) { if (!type.IsGeneric()) { return; } ConvertedTypeDefinitionWithTypeParameters_I generic = (ConvertedTypeDefinitionWithTypeParameters_I)type; Types.TypeParameters.Clear(conversion, generic); Types.TypeParameters.Add(conversion, generic, typeParameters); }
private void EnsureMembers(ILConversion conversion, ConvertedTypeDefinition input) { if (input.SourceTypeReference == null && input is SemanticGenericTypeDefinition_I genericTypeDefinition && genericTypeDefinition.GenericTypeDefinition != null) { return; } Fields.TypeScanning.EnsureTypes(conversion, input); Properties.TypeScanning.EnsureTypes(conversion, input); Events.TypeScanning.EnsureTypes(conversion, input); Methods.TypeScanning.EnsureTypes(conversion, input); }
public Type[] Build(ILConversion conversion, ConvertedTypeDefinition converted) { if (!converted.IsGeneric()) { return(Type.EmptyTypes); } GenericInstanceType inputType = (GenericInstanceType)converted.SourceTypeReference; var list = new List <SemanticTypeDefinitionMask_I>(); if (inputType.GenericArguments.Count <= 0) { return(Type.EmptyTypes); } Type[] types = new Type[inputType.GenericArguments.Count]; bool hasGenericParametersAsTypeArguments = false; for (var i = 0; i < inputType.GenericArguments.Count; i++) { var genericArgument = inputType.GenericArguments[i]; var semanticType = Execution.Types.Ensuring.Ensure(conversion, genericArgument, null, null); if (!(semanticType is BoundTypeDefinitionMask_I bound)) { throw new System.Exception("Semantic type needs to be a bound type."); } types[i] = bound.UnderlyingType; hasGenericParametersAsTypeArguments |= types[i].IsGenericParameter; list.Add(Models.Types.GetBoundTypeOrThrow(semanticType, false)); } ConvertedGenericTypeDefinition_I generic = (ConvertedGenericTypeDefinition_I)converted; generic.TypeArguments.All = list; //generic.TypeArguments.HasGenericParametersAsTypeArguments = hasGenericParametersAsTypeArguments; return(types); }
public void AssignInterfaces(ConvertedTypeDefinition target, List <SemanticTypeMask_I> interfaces) { if (target.SupportsInterfaceTypeList() && target is SemanticTypeWithInterfaceTypeList_I tewii) { tewii.Interfaces = new SemanticTypeDefinitionInterfaces(); for (var i = 0; i < interfaces.Count; i++) { var item = interfaces[i]; var resolutionName = Types.Naming.GetResolutionName(item); tewii.Interfaces.ByResolutionName.Add(resolutionName, (SemanticInterfaceTypeMask_I)item); Types.Dependencies.Add(target, item); } } }
public SemanticTypeDefinitionMask_I Ensure(ILConversion conversion, TypeReference input, SemanticTypeDefinitionMask_I declaringType) { ArrayType arrayType = (ArrayType)input; var elementType = Execution.Types.Ensuring.Ensure(conversion.Model, arrayType.ElementType, null, null); if (IfAlreadyCreatedReturn(elementType, arrayType.Rank, out SemanticArrayTypeDefinitionMask_I existing)) { return(existing); } ConvertedTypeDefinition converted = Types.Creation.Create(conversion, input); var arrayDef = (ConvertedArrayTypeDefinition_I)converted; elementType.Arrays.Add(arrayType.Rank, arrayDef); arrayDef.ElementType = elementType; converted.BaseType = (BoundTypeDefinitionMask_I)Execution.Types.Ensuring.Ensure(conversion.Model, typeof(System.Array)); if (!(arrayDef.ElementType is BoundTypeDefinitionMask_I boundElementType)) { throw new Exception("The element type is not a BoundTypeDefinitionMask_I. "); } if (arrayType.Rank == 1) { // Makes a vector converted.UnderlyingType = boundElementType.UnderlyingType.MakeArrayType(); } else { // Makes an multi-dimensional array converted.UnderlyingType = boundElementType.UnderlyingType.MakeArrayType(arrayType.Rank); } Types.Building.UpdateBuildPhase(converted, BuildPhaseKind.TypeCreated); return(converted); }
private void Converted_BuildPhase1(ILConversion conversion, StructuralTypeNode structuralInputTypeNode, ConvertedTypeDefinition converted, ConvertedTypeDefinition_I convertedDeclaringType) { var typeDefinition = (TypeDefinition)structuralInputTypeNode.CecilTypeReference; System.Reflection.TypeAttributes attributes = Cecil.Metadata.Members.Types.GetTypeAttributes(typeDefinition); var packingSize = Cecil.GetPackingSize(typeDefinition); if (converted is ConvertedTypeDefinitionWithDeclaringType_I withDeclaringType) { if (convertedDeclaringType == null ) // Can occur if passing in a single nested type or if a nested class gets processed before its parents gets // processed. { if (!(converted.SourceTypeReference is TypeDefinition)) { throw new Exception("Expected a type definition"); } var semanticDeclaringType = Execution.Types.Ensuring.Ensure(conversion, converted.SourceTypeReference.DeclaringType, null, null); if (!(semanticDeclaringType is ConvertedTypeDefinition_I producedDeclaringType)) { throw new Exception( $"Expected the declaring type of a nested class to be castable to {typeof(ConvertedTypeDefinition_I)}"); } convertedDeclaringType = producedDeclaringType; } withDeclaringType.DeclaringType = convertedDeclaringType; // The plus sign and the parent class name before it needs to be dropped from the full name prior to calling define nested class // as the type builder will automatically add them back on based upon the name of the declaring type. var fullName = Conversion.Metadata.Members.Types.Naming.GetTypeBuilderNestedClassFullName(converted.FullName); // The !IsEnum check prevents: [MD]: Error: ClassLayout has parent TypeDef token=0x02000036 marked AutoLayout. [token:0x00000001] // The Class or ValueType indexed by Parent shall be SequentialLayout or ExplicitLayout (§II.23.1.15). // That is, AutoLayout types shall not own any rows in the ClassLayout table. [ERROR] if (typeDefinition.IsValueType && !typeDefinition.IsEnum) { converted.TypeBuilder = convertedDeclaringType.TypeBuilder.DefineNestedType(converted.FullName, attributes, null, (PackingSize)typeDefinition.PackingSize, typeDefinition.ClassSize); } else { converted.TypeBuilder = convertedDeclaringType.TypeBuilder.DefineNestedType(fullName, attributes, null, packingSize); } } else { if (converted.FullName == "Root.Testing.Resources.Models.E01D.Runtimic.Execution.Emitting.Conversion.Inputs.Types.SimpleValueType") { } if (converted.FullName == "<Module>") { var x = converted.Module.ModuleBuilder.GetType("<Module>", true); } // The !IsEnum check prevents: [MD]: Error: ClassLayout has parent TypeDef token=0x02000036 marked AutoLayout. [token:0x00000001] // The Class or ValueType indexed by Parent shall be SequentialLayout or ExplicitLayout (§II.23.1.15). // That is, AutoLayout types shall not own any rows in the ClassLayout table. [ERROR] if (typeDefinition.IsValueType && !typeDefinition.IsEnum) { converted.TypeBuilder = converted.Module.ModuleBuilder.DefineType(converted.FullName, attributes, null, (PackingSize)typeDefinition.PackingSize, typeDefinition.ClassSize); } else { converted.TypeBuilder = converted.Module.ModuleBuilder.DefineType(converted.FullName, attributes, null, packingSize); } } converted.UnderlyingType = converted.TypeBuilder; //this.Unified.Types.ExtendWithCrossReference(conversion.Model, converted, // converted.UnderlyingType.AssemblyQualifiedName); Conversion.Metadata.Members.Types.Building.UpdateBuildPhase(converted, BuildPhaseKind.TypeDefined); }
public void AssignNestedTypes(ConvertedTypeDefinition createdType, Dictionary <string, SemanticTypeMask_I> nestedTypes) { }
public void AssignGenericBlueprint(ConvertedTypeDefinition createdType, SemanticTypeDefinitionMask_I genericBlueprint) { }