Beispiel #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 <IQueryOverloadType> InstancedOverloadList = new List <IQueryOverloadType>();

            foreach (IQueryOverloadType Overload in OverloadList)
            {
                IQueryOverloadType InstancedOverload = Overload;
                QueryOverloadType.InstanciateQueryOverloadType(instancingClassType, ref InstancedOverload);

                InstancedOverloadList.Add(InstancedOverload);
                IsNewInstance |= InstancedOverload != Overload;
            }

            if (IsNewInstance)
            {
                ISealableDictionary <ITypeName, ICompiledType> TypeTable = instancingClassType.GetTypeTable();
                ResolveType(TypeTable, InstancedBaseTypeName, (IObjectType)BaseType, (ICompiledTypeWithFeature)InstancedBaseType, InstancedOverloadList, out resolvedTypeName, out IFunctionType ResolvedFunctionType);
                resolvedType = ResolvedFunctionType;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Compares two types.
        /// </summary>
        /// <param name="type1">The first type.</param>
        /// <param name="type2">The second type.</param>
        public static bool TypesHaveIdenticalSignature(IFunctionType type1, IFunctionType type2)
        {
            bool IsIdentical = true;

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

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

                foreach (IQueryOverloadType Overload2 in type2.OverloadList)
                {
                    MatchingOverload |= QueryOverloadType.QueryOverloadsHaveIdenticalSignature(Overload1, Overload2);
                }

                IsIdentical &= MatchingOverload;
            }

            return(IsIdentical);
        }
Beispiel #3
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 InstanciateQueryOverloadType(ICompiledTypeWithFeature instancingClassType, ref IQueryOverloadType 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;
                }
            }

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

            foreach (IEntityDeclaration Result in instancedOverload.ResultList)
            {
                ITypeName     InstancedResultTypeName = Result.ValidEntity.Item.ResolvedEffectiveTypeName.Item;
                ICompiledType InstancedResultType     = Result.ValidEntity.Item.ResolvedEffectiveType.Item;
                InstancedResultType.InstanciateType(instancingClassType, ref InstancedResultTypeName, ref InstancedResultType);

                IEntityDeclaration InstancedResult = new EntityDeclaration(Result, InstancedResultTypeName, InstancedResultType);
                IName ResultName = (IName)Result.EntityName;

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

                InstancedResult.ValidEntity.Item = NewEntity;

                InstancedResultList.Add(InstancedResult);

                if (InstancedResultType != Result.ValidEntity.Item.ResolvedEffectiveType.Item)
                {
                    IsNewInstance = true;
                }
            }

            if (IsNewInstance)
            {
                IQueryOverloadType NewOverloadInstance = new QueryOverloadType(InstancedParameterList, instancedOverload.ParameterEnd, InstancedResultList, 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));
                }

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

                instancedOverload = NewOverloadInstance;
            }
        }