Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TupleType"/> class.
        /// </summary>
        /// <param name="entityDeclarationList">The resolved list of fields.</param>
        /// <param name="sharing">The type sharing.</param>
        /// <param name="renamedFieldTable">The list of fields to rename.</param>
        public TupleType(IList <IEntityDeclaration> entityDeclarationList, BaseNode.SharingType sharing, ISealableDictionary <IFeatureName, IFeatureInstance> renamedFieldTable)
        {
            EntityDeclarationList = entityDeclarationList;
            Sharing = sharing;

            FeatureTable.Merge(renamedFieldTable);
            FeatureTable.Seal();
            DiscreteTable.Seal();
            ConformanceTable.Seal();
            ExportTable.Seal();
        }
Beispiel #2
0
        /// <summary>
        /// Checks if a matching tuple type exists in a type table.
        /// </summary>
        /// <param name="typeTable">The table of existing types.</param>
        /// <param name="entityDeclarationList">The resolved list of fields.</param>
        /// <param name="sharing">The type sharing.</param>
        /// <param name="resolvedTypeName">The type name upon return.</param>
        /// <param name="resolvedType">The type upon return.</param>
        public static bool TypeTableContaining(ISealableDictionary <ITypeName, ICompiledType> typeTable, IList <IEntityDeclaration> entityDeclarationList, BaseNode.SharingType sharing, out ITypeName resolvedTypeName, out ICompiledType resolvedType)
        {
            resolvedTypeName = null;
            resolvedType     = null;
            bool Result = false;

            foreach (KeyValuePair <ITypeName, ICompiledType> Entry in typeTable)
            {
                if (Entry.Value is ITupleType AsTupleType)
                {
                    if (AsTupleType.EntityDeclarationList.Count == entityDeclarationList.Count && AsTupleType.Sharing == sharing)
                    {
                        bool AllFieldsEqual = true;
                        for (int i = 0; i < entityDeclarationList.Count; i++)
                        {
                            Debug.Assert(entityDeclarationList[i].ValidEntity.IsAssigned);
                            Debug.Assert(entityDeclarationList[i].ValidEntity.Item.ResolvedEffectiveType.IsAssigned);
                            Debug.Assert(AsTupleType.EntityDeclarationList[i].ValidEntity.IsAssigned);
                            Debug.Assert(AsTupleType.EntityDeclarationList[i].ValidEntity.Item.ResolvedEffectiveType.IsAssigned);

                            AllFieldsEqual &= entityDeclarationList[i].ValidEntity.Item.ResolvedEffectiveType.Item == AsTupleType.EntityDeclarationList[i].ValidEntity.Item.ResolvedEffectiveType.Item;
                        }

                        if (AllFieldsEqual)
                        {
                            Debug.Assert(!Result);

                            resolvedTypeName = Entry.Key;
                            resolvedType     = AsTupleType;
                            Result           = true;
                        }
                    }
                }
            }

            return(Result);
        }
Beispiel #3
0
        /// <summary>
        /// Creates a tuple type with resolved arguments.
        /// </summary>
        /// <param name="entityDeclarationList">The resolved list of fields.</param>
        /// <param name="sharing">The type sharing.</param>
        /// <param name="resolvedTypeName">The type name upon return.</param>
        /// <param name="resolvedType">The type upon return.</param>
        public static void BuildType(IList <IEntityDeclaration> entityDeclarationList, BaseNode.SharingType sharing, out ITypeName resolvedTypeName, out ICompiledType resolvedType)
        {
            ISealableDictionary <IFeatureName, IFeatureInstance> FeatureTable = new SealableDictionary <IFeatureName, IFeatureInstance>();

            foreach (IEntityDeclaration Item in entityDeclarationList)
            {
                Debug.Assert(Item.ValidEntity.IsAssigned);
                IScopeAttributeFeature ValidEntity = Item.ValidEntity.Item;

                Debug.Assert(ValidEntity.ValidFeatureName.IsAssigned);
                IFeatureName FeatureName = ValidEntity.ValidFeatureName.Item;

                IClass           EmbeddingClass  = Item.EmbeddingClass;
                IFeatureInstance FeatureInstance = new FeatureInstance(EmbeddingClass, ValidEntity);

                FeatureTable.Add(FeatureName, FeatureInstance);
            }

            ITupleType ResolvedTupleType = new TupleType(entityDeclarationList, sharing, FeatureTable);

            resolvedTypeName = new TypeName(ResolvedTupleType.TypeFriendlyName);
            resolvedType     = ResolvedTupleType;
        }
Beispiel #4
0
 /// <summary>
 /// Locates, or creates, a resolved tuple type.
 /// </summary>
 /// <param name="typeTable">The table of existing types.</param>
 /// <param name="entityDeclarationList">The resolved list of fields.</param>
 /// <param name="sharing">The type sharing.</param>
 /// <param name="resolvedTypeName">The type name upon return.</param>
 /// <param name="resolvedType">The type upon return.</param>
 public static void ResolveType(ISealableDictionary <ITypeName, ICompiledType> typeTable, IList <IEntityDeclaration> entityDeclarationList, BaseNode.SharingType sharing, out ITypeName resolvedTypeName, out ICompiledType resolvedType)
 {
     if (!TypeTableContaining(typeTable, entityDeclarationList, sharing, out resolvedTypeName, out resolvedType))
     {
         BuildType(entityDeclarationList, sharing, out resolvedTypeName, out resolvedType);
         typeTable.Add(resolvedTypeName, resolvedType);
     }
 }