예제 #1
0
        /// <summary>
        /// Creates an instance of a class type, or reuse an existing instance.
        /// </summary>
        /// <param name="instancingClassType">The class type to instanciate.</param>
        /// <param name="resolvedTypeName">The proposed type instance name.</param>
        /// <param name="resolvedType">The proposed type instance.</param>
        public void InstanciateType(ICompiledTypeWithFeature instancingClassType, ref ITypeName resolvedTypeName, ref ICompiledType resolvedType)
        {
            bool IsNewInstance = false;

            ITypeName InstancedBaseTypeName = ResolvedBaseTypeName.Item;

            ICompiledType InstancedBaseType = ResolvedBaseType.Item;

            InstancedBaseType.InstanciateType(instancingClassType, ref InstancedBaseTypeName, ref InstancedBaseType);
            IsNewInstance |= InstancedBaseType != ResolvedBaseType.Item;

            ITypeName     InstancedEntityTypeName = ResolvedEntityTypeName.Item;
            ICompiledType InstancedEntityType     = ResolvedEntityType.Item;

            InstancedEntityType.InstanciateType(instancingClassType, ref InstancedEntityTypeName, ref InstancedEntityType);
            IsNewInstance |= InstancedEntityType != ResolvedEntityType.Item;

            IList <IEntityDeclaration> InstancedIndexParameterList = new List <IEntityDeclaration>();

            foreach (IEntityDeclaration Parameter in IndexParameterList)
            {
                ITypeName     InstancedParameterTypeName = Parameter.ValidEntity.Item.ResolvedEffectiveTypeName.Item;
                ICompiledType InstancedParameterType     = Parameter.ValidEntity.Item.ResolvedEffectiveType.Item;
                InstancedParameterType.InstanciateType(instancingClassType, ref InstancedParameterTypeName, ref InstancedParameterType);

                IEntityDeclaration InstancedParameter = new EntityDeclaration(Parameter, InstancedParameterTypeName, InstancedParameterType);
                IName ParameterName = (Name)Parameter.EntityName;

                IScopeAttributeFeature NewEntity;
                if (Parameter.DefaultValue.IsAssigned)
                {
                    // The default value has already been checked and validated.
                    bool IsCreated = ScopeAttributeFeature.Create(Parameter, ParameterName.ValidText.Item, InstancedParameterTypeName, InstancedParameterType, (IExpression)Parameter.DefaultValue.Item, ErrorList.Ignored, out NewEntity);
                    Debug.Assert(IsCreated);
                }
                else
                {
                    NewEntity = ScopeAttributeFeature.Create(Parameter, ParameterName.ValidText.Item, InstancedParameterTypeName, InstancedParameterType);
                }

                IsNewInstance |= InstancedParameterType != Parameter.ValidEntity.Item.ResolvedEffectiveType.Item;

                InstancedParameter.ValidEntity.Item = NewEntity;
                InstancedIndexParameterList.Add(InstancedParameter);
            }

            if (IsNewInstance)
            {
                ISealableDictionary <ITypeName, ICompiledType> TypeTable = instancingClassType.GetTypeTable();
                ResolveType(TypeTable, InstancedBaseTypeName, (IClassType)InstancedBaseType, InstancedEntityTypeName, InstancedEntityType, IndexerKind, InstancedIndexParameterList, ParameterEnd, GetRequireList, GetEnsureList, GetExceptionIdentifierList, SetRequireList, SetEnsureList, SetExceptionIdentifierList, out resolvedTypeName, out resolvedType);
            }
        }
예제 #2
0
        /// <summary>
        /// Finds or creates an overload type with the corresponding parameters.
        /// </summary>
        /// <param name="instancingClassType">The type attempting to find the overload type.</param>
        /// <param name="instancedOverload">The new overload type upon return if not found.</param>
        public static void InstanciateCommandOverloadType(ICompiledTypeWithFeature instancingClassType, ref ICommandOverloadType instancedOverload)
        {
            bool IsNewInstance = false;

            IList <IEntityDeclaration> InstancedParameterList = new List <IEntityDeclaration>();

            foreach (IEntityDeclaration Parameter in instancedOverload.ParameterList)
            {
                ITypeName     InstancedParameterTypeName = Parameter.ValidEntity.Item.ResolvedEffectiveTypeName.Item;
                ICompiledType InstancedParameterType     = Parameter.ValidEntity.Item.ResolvedEffectiveType.Item;
                InstancedParameterType.InstanciateType(instancingClassType, ref InstancedParameterTypeName, ref InstancedParameterType);

                IEntityDeclaration InstancedParameter = new EntityDeclaration(Parameter, InstancedParameterTypeName, InstancedParameterType);
                IName ParameterName = (IName)Parameter.EntityName;

                IScopeAttributeFeature NewEntity;
                if (Parameter.DefaultValue.IsAssigned)
                {
                    // The default value has already been checked and validated.
                    bool IsCreated = ScopeAttributeFeature.Create(Parameter, ParameterName.ValidText.Item, InstancedParameterTypeName, InstancedParameterType, (IExpression)Parameter.DefaultValue.Item, ErrorList.Ignored, out NewEntity);
                    Debug.Assert(IsCreated);
                }
                else
                {
                    NewEntity = ScopeAttributeFeature.Create(Parameter, ParameterName.ValidText.Item, InstancedParameterTypeName, InstancedParameterType);
                }

                InstancedParameter.ValidEntity.Item = NewEntity;

                InstancedParameterList.Add(InstancedParameter);

                if (InstancedParameterType != Parameter.ValidEntity.Item.ResolvedEffectiveType.Item)
                {
                    IsNewInstance = true;
                }
            }

            if (IsNewInstance)
            {
                ICommandOverloadType NewOverloadInstance = new CommandOverloadType(InstancedParameterList, instancedOverload.ParameterEnd, instancedOverload.RequireList, instancedOverload.EnsureList, instancedOverload.ExceptionIdentifierList);

                foreach (IEntityDeclaration Item in InstancedParameterList)
                {
                    string ValidName = Item.ValidEntity.Item.ValidFeatureName.Item.Name;
                    NewOverloadInstance.ParameterTable.Add(new Parameter(ValidName, Item.ValidEntity.Item));
                }

                instancedOverload = NewOverloadInstance;
            }
        }