示例#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;

            IList <ICommandOverloadType> InstancedOverloadList = new List <ICommandOverloadType>();

            foreach (ICommandOverloadType Overload in OverloadList)
            {
                ICommandOverloadType InstancedOverload = Overload;
                CommandOverloadType.InstanciateCommandOverloadType(instancingClassType, ref InstancedOverload);
                IsNewInstance |= InstancedOverload != Overload;

                InstancedOverloadList.Add(InstancedOverload);
            }

            if (IsNewInstance)
            {
                ISealableDictionary <ITypeName, ICompiledType> TypeTable = instancingClassType.GetTypeTable();
                ResolveType(TypeTable, InstancedBaseTypeName, (IObjectType)BaseType, (ICompiledTypeWithFeature)InstancedBaseType, InstancedOverloadList, out resolvedTypeName, out IProcedureType ResolvedProcedureType);
                resolvedType = ResolvedProcedureType;
            }
        }
示例#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;
            }
        }
示例#3
0
        /// <summary>
        /// Compares two types.
        /// </summary>
        /// <param name="type1">The first type.</param>
        /// <param name="type2">The second type.</param>
        public static bool TypesHaveIdenticalSignature(IProcedureType type1, IProcedureType type2)
        {
            bool IsIdentical = true;

            IsIdentical &= ObjectType.TypesHaveIdenticalSignature(type1.ResolvedBaseType.Item, type2.ResolvedBaseType.Item);
            IsIdentical &= type1.OverloadList.Count == type2.OverloadList.Count;

            foreach (ICommandOverloadType Overload1 in type1.OverloadList)
            {
                bool MatchingOverload = false;

                foreach (ICommandOverloadType Overload2 in type2.OverloadList)
                {
                    MatchingOverload |= CommandOverloadType.CommandOverloadsHaveIdenticalSignature(Overload1, Overload2);
                }

                IsIdentical &= MatchingOverload;
            }

            return(IsIdentical);
        }