Exemplo n.º 1
0
        public ExecutionTypeNode_I Ensure(ExecutionEnsureContext context)
        {
            ArrayType arrayType = (ArrayType)context.TypeReference;

            var arrayStemType = Execution.Types.Ensuring.Ensure(new ExecutionEnsureContext()
            {
                Conversion              = context.Conversion,
                RuntimicSystem          = context.RuntimicSystem,
                StructuralInputTypeNode = context.StructuralInputTypeNode.StemType
            });

            if (CheckForBranch(arrayStemType, arrayType, out ExecutionTypeNode_I ensure))
            {
                return(ensure);
            }


            ExecutionArrayTypeDefinition_I bound;

            ExecutionTypeNode_I node;


            if (arrayStemType.Type.IsConverted())
            {
                // Converted multi-dimemsinal arrays do have constructors that need to come from a different source
                // than bound multi-dimemsinal arrays
                bound = (ExecutionArrayTypeDefinition_I)Conversion.Metadata.Members.Types.Creation.Create(context.RuntimicSystem, context.TypeReference);

                Conversion.Metadata.Members.Types.Building.UpdateBuildPhase((ConvertedTypeDefinition_I)bound, BuildPhaseKind.TypeCreated);

                node = new ConversionTypeNode()
                {
                    IsArrayType         = true,
                    StemType            = arrayStemType,
                    IsDerived           = true,
                    InputStructuralNode = context.StructuralInputTypeNode,
                    Type = (ConvertedTypeDefinition_I)bound,
                    Rank = arrayType.Rank
                };
            }
            else
            {
                bound = (ExecutionArrayTypeDefinition_I)Bound.Metadata.Members.Types.Creation.Create(context.RuntimicSystem, context.TypeReference, null);

                bound.UnderlyingType = context.UnderlyingType;

                node = new BoundTypeNode()
                {
                    IsArrayType         = true,
                    StemType            = arrayStemType,
                    IsDerived           = true,
                    InputStructuralNode = context.StructuralInputTypeNode,
                    Type = (BoundTypeDefinition)bound,
                    Rank = arrayType.Rank
                };
            }

            bound.SourceTypeReference = context.TypeReference;
//		    bound.BaseType = (BoundTypeDefinitionMask_I)Execution.Types.Ensuring.Ensure(semanticModel, typeof(System.Array));
            bound.ElementType = arrayStemType.Type;

            if (bound.UnderlyingType == null)
            {
                var elementType = arrayStemType.Type;


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

            SetNode(arrayStemType, node);

            return(node);
        }
Exemplo n.º 2
0
        public ExecutionTypeNode_I Ensure(ExecutionEnsureContext context)
        {
            if (!context.IsConverted.HasValue)
            {
                throw new Exception("Expected conversion to be figured out.");
            }

            if (context.StructuralInputTypeNode.CecilTypeReference.IsNested && context.DeclaringType == null)
            {
                context.DeclaringType = Execution.Types.Ensuring.EnsureBound(context,
                                                                             context.StructuralInputTypeNode.CecilTypeReference.DeclaringType, cloneContext: true);
            }

            if (context.IsConverted.Value)
            {
                var conversion = context.Conversion;

                var structuralInputTypeNode = context.StructuralInputTypeNode;

                var metadataToken = structuralInputTypeNode.MetadataToken;

                var structuralAssembly = Conversion.Metadata.Assemblies.EnsureNode(context.Conversion, structuralInputTypeNode.Module.Assembly);

                var convertedModuleNode = Conversion.Metadata.Modules.Ensure(context.Conversion, structuralAssembly, structuralInputTypeNode.Module);

                var tableId = (int)(metadataToken & 0xFF000000);

                if (!convertedModuleNode.Tables.TryGetValue(tableId, out ConvertedTypeTable table))
                {
                    table = new ConvertedTypeTable();

                    convertedModuleNode.Tables.Add(tableId, table);
                }

                if (table.ByRow.TryGetValue((uint)context.RowId, out ConversionTypeNode conversionTypeNode))
                {
                    return(conversionTypeNode);
                }



                var converted = Conversion.Metadata.Members.Types.Creation.Create(conversion.RuntimicSystem, structuralInputTypeNode.CecilTypeReference);

                converted.Module = convertedModuleNode.ConvertedModule;

                conversionTypeNode = new ConversionTypeNode()
                {
                    Assembly        = structuralAssembly,
                    ByReferenceType = null,
                    Id = 0,
                    InputStructuralNode = structuralInputTypeNode,
                    IsByReferenceType   = false,
                    IsDerived           = false,
                    IsPointerType       = false,
                    MetadataToken       = metadataToken,
                    Module      = convertedModuleNode,
                    PointerType = null,
                    Type        = converted
                };

                table.ByRow.Add((uint)context.RowId, conversionTypeNode);

                var convertedDeclaringType = context.ConvertedDeclaringType;

                Converted_BuildPhase1(conversion, structuralInputTypeNode, converted, convertedDeclaringType);

                Conversion.Metadata.Members.Types.Building.IfPossibleBuildPhase2(conversion, converted);

                return(conversionTypeNode);
            }
            else
            {
                var structuralInputTypeNode = context.StructuralInputTypeNode;

                if (structuralInputTypeNode.FullName == "Root.Code.Containers.E01D.Sorting.SortingContainer_I`1")
                {
                }

                var metadataToken = structuralInputTypeNode.MetadataToken;

                var boundAssembly = Bound.Metadata.Assemblies.EnsureNode(context.RuntimicSystem, structuralInputTypeNode.Module.Assembly);

                var boundModuleNode = Bound.Metadata.Modules.Ensuring.EnsureNode(context.RuntimicSystem, boundAssembly, structuralInputTypeNode.Module);

                var tableId = (int)(metadataToken & 0xFF000000);

                if (!boundModuleNode.Tables.TryGetValue(tableId, out BoundTypeTable table))
                {
                    table = new BoundTypeTable();

                    boundModuleNode.Tables.Add(tableId, table);
                }

                if (table.ByRow.TryGetValue((uint)context.RowId, out BoundTypeNode boundTypeNode))
                {
                    return(boundTypeNode);
                }
                //---------------------------------
                // Conversion is going to occur.
                //---------------------------------

                if (context.UnderlyingType == null)
                {
                    context.UnderlyingType = Cecil.GetUnderlyingType(structuralInputTypeNode.CecilTypeReference);

                    if (context.UnderlyingType == null)
                    {
                        throw new Exception("Null type");
                    }
                }

                var bound = Bound.Metadata.Members.Types.Creation.Create(context.RuntimicSystem, context.StructuralInputTypeNode.CecilTypeReference, context.UnderlyingType);

                boundTypeNode = new BoundTypeNode()
                {
                    Assembly        = boundAssembly,
                    ByReferenceType = null,
                    Id = 0,
                    InputStructuralNode = structuralInputTypeNode,
                    IsByReferenceType   = false,
                    IsDerived           = false,
                    IsPointerType       = false,
                    MetadataToken       = metadataToken,
                    Module      = boundModuleNode,
                    PointerType = null,
                    Type        = bound
                };


                bound.Module = boundModuleNode.BoundModule;

                //// Add the type instance to the model.  Do not do any recursive calls till this methods is called.
                table.ByRow.Add((uint)context.RowId, boundTypeNode);



                //Types.Addition.Add(semanticModel, boundModule, bound);

                Bound.Metadata.Members.Types.Building.NonGenericInstances.Phase1Initial.Build(context.RuntimicSystem, bound, context.UnderlyingType, context.DeclaringType);

                return(boundTypeNode);
            }
        }