Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IndexerType"/> class.
        /// </summary>
        /// <param name="baseTypeName">The type name of the resolved base type.</param>
        /// <param name="baseType">The type of the resolved base type.</param>
        /// <param name="entityTypeName">The type name of the resolved result type.</param>
        /// <param name="entityType">The type of the resolved result type.</param>
        /// <param name="indexerKind">Type of indexer.</param>
        /// <param name="indexParameterList">The list of parameters.</param>
        /// <param name="parameterEnd">The indexer parameter end type.</param>
        /// <param name="getRequireList">The list of require assertions for the getter.</param>
        /// <param name="getEnsureList">The list of ensure assertions for the getter.</param>
        /// <param name="getExceptionIdentifierList">The list of known exceptions thrown for the getter.</param>
        /// <param name="setRequireList">The list of require assertions for the setter.</param>
        /// <param name="setEnsureList">The list of ensure assertions for the setter.</param>
        /// <param name="setExceptionIdentifierList">The list of known exceptions thrown for the setter.</param>
        public IndexerType(ITypeName baseTypeName, IClassType baseType, ITypeName entityTypeName, ICompiledType entityType, BaseNode.UtilityType indexerKind, IList <IEntityDeclaration> indexParameterList, BaseNode.ParameterEndStatus parameterEnd, IList <IAssertion> getRequireList, IList <IAssertion> getEnsureList, IList <IIdentifier> getExceptionIdentifierList, IList <IAssertion> setRequireList, IList <IAssertion> setEnsureList, IList <IIdentifier> setExceptionIdentifierList)
            : this()
        {
            BaseType     = baseType;
            EntityType   = null;
            ParameterEnd = parameterEnd;
            IndexerKind  = indexerKind;

            ResolvedBaseTypeName.Item   = baseTypeName;
            ResolvedBaseType.Item       = baseType;
            ResolvedEntityTypeName.Item = entityTypeName;
            ResolvedEntityType.Item     = entityType;
            IndexParameterList          = indexParameterList;
            GetRequireList             = getRequireList;
            GetEnsureList              = getEnsureList;
            GetExceptionIdentifierList = getExceptionIdentifierList;
            SetRequireList             = setRequireList;
            SetEnsureList              = setEnsureList;
            SetExceptionIdentifierList = setExceptionIdentifierList;

            foreach (IEntityDeclaration Item in indexParameterList)
            {
                IName  ParameterName = (IName)Item.EntityName;
                string ValidText     = ParameterName.ValidText.Item;
                IScopeAttributeFeature ParameterFeature = Item.ValidEntity.Item;
                ParameterTable.Add(new Parameter(ValidText, ParameterFeature));
            }
            ParameterTable.Seal();
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandOverloadType"/> class.
 /// </summary>
 /// <param name="parameterList">The list of parameters.</param>
 /// <param name="parameterEnd">The closed or open status.</param>
 /// <param name="requireList">The list of require assertions.</param>
 /// <param name="ensureList">The list of ensure assertions.</param>
 /// <param name="exceptionIdentifierList">The list of exceptions this overload can throw.</param>
 public CommandOverloadType(IList <IEntityDeclaration> parameterList, BaseNode.ParameterEndStatus parameterEnd, IList <IAssertion> requireList, IList <IAssertion> ensureList, IList <IIdentifier> exceptionIdentifierList)
 {
     ParameterList           = parameterList;
     ParameterEnd            = parameterEnd;
     RequireList             = requireList;
     EnsureList              = ensureList;
     ExceptionIdentifierList = exceptionIdentifierList;
 }
Esempio n. 3
0
        /// <summary>
        /// Applies the rule.
        /// </summary>
        /// <param name="node">The node instance to modify.</param>
        /// <param name="data">Private data from CheckConsistency().</param>
        public override void Apply(IIndexerFeature node, object data)
        {
            IClass      EmbeddingClass = node.EmbeddingClass;
            IObjectType TypeToResolve  = (IObjectType)node.EntityType;

            BaseNode.UtilityType IndexerKind = ((Tuple <BaseNode.UtilityType, ISealableDictionary <string, IScopeAttributeFeature>, ISealableDictionary <string, IScopeAttributeFeature>, ISealableDictionary <string, IScopeAttributeFeature> >)data).Item1;
            ISealableDictionary <string, IScopeAttributeFeature> CheckedScope    = ((Tuple <BaseNode.UtilityType, ISealableDictionary <string, IScopeAttributeFeature>, ISealableDictionary <string, IScopeAttributeFeature>, ISealableDictionary <string, IScopeAttributeFeature> >)data).Item2;
            ISealableDictionary <string, IScopeAttributeFeature> CheckedGetScope = ((Tuple <BaseNode.UtilityType, ISealableDictionary <string, IScopeAttributeFeature>, ISealableDictionary <string, IScopeAttributeFeature>, ISealableDictionary <string, IScopeAttributeFeature> >)data).Item3;
            ISealableDictionary <string, IScopeAttributeFeature> CheckedSetScope = ((Tuple <BaseNode.UtilityType, ISealableDictionary <string, IScopeAttributeFeature>, ISealableDictionary <string, IScopeAttributeFeature>, ISealableDictionary <string, IScopeAttributeFeature> >)data).Item4;

            ITypeName     BaseTypeName   = EmbeddingClass.ResolvedClassTypeName.Item;
            IClassType    BaseType       = EmbeddingClass.ResolvedClassType.Item;
            ITypeName     EntityTypeName = TypeToResolve.ResolvedTypeName.Item;
            ICompiledType EntityType     = TypeToResolve.ResolvedType.Item;

            List <IEntityDeclaration> IndexParameterList = new List <IEntityDeclaration>();

            foreach (IEntityDeclaration Item in node.IndexParameterList)
            {
                IndexParameterList.Add(Item);
            }

            BaseNode.ParameterEndStatus ParameterEnd = node.ParameterEnd;

            IList <IAssertion>  GetRequireList             = new List <IAssertion>();
            IList <IAssertion>  GetEnsureList              = new List <IAssertion>();
            IList <IIdentifier> GetExceptionIdentifierList = new List <IIdentifier>();

            if (node.GetterBody.IsAssigned)
            {
                IBody GetterBody = (IBody)node.GetterBody.Item;
                foreach (IAssertion Item in GetterBody.RequireList)
                {
                    GetRequireList.Add(Item);
                }
                foreach (IAssertion Item in GetterBody.EnsureList)
                {
                    GetEnsureList.Add(Item);
                }
                foreach (IIdentifier Item in GetterBody.ExceptionIdentifierList)
                {
                    GetExceptionIdentifierList.Add(Item);
                }
            }

            IList <IAssertion>  SetRequireList             = new List <IAssertion>();
            IList <IAssertion>  SetEnsureList              = new List <IAssertion>();
            IList <IIdentifier> SetExceptionIdentifierList = new List <IIdentifier>();

            if (node.SetterBody.IsAssigned)
            {
                IBody SetterBody = (IBody)node.SetterBody.Item;
                foreach (IAssertion Item in SetterBody.RequireList)
                {
                    SetRequireList.Add(Item);
                }
                foreach (IAssertion Item in SetterBody.EnsureList)
                {
                    SetEnsureList.Add(Item);
                }
                foreach (IIdentifier Item in SetterBody.ExceptionIdentifierList)
                {
                    SetExceptionIdentifierList.Add(Item);
                }
            }

            IndexerType.ResolveType(EmbeddingClass.TypeTable, BaseTypeName, BaseType, EntityTypeName, EntityType, IndexerKind, IndexParameterList, ParameterEnd, GetRequireList, GetEnsureList, GetExceptionIdentifierList, SetRequireList, SetEnsureList, SetExceptionIdentifierList, out ITypeName ResolvedIndexerTypeName, out ICompiledType ResolvedIndexerType);

            node.ResolvedEntityTypeName.Item    = EntityTypeName;
            node.ResolvedEntityType.Item        = EntityType;
            node.ResolvedAgentTypeName.Item     = ResolvedIndexerTypeName;
            node.ResolvedAgentType.Item         = ResolvedIndexerType;
            node.ResolvedEffectiveTypeName.Item = EntityTypeName;
            node.ResolvedEffectiveType.Item     = EntityType;

            foreach (KeyValuePair <string, IScopeAttributeFeature> Entry in CheckedScope)
            {
                node.ParameterTable.Add(new Parameter(Entry.Key, Entry.Value));
            }
            node.ParameterTable.Seal();

            if (node.GetterBody.IsAssigned)
            {
                EmbeddingClass.BodyList.Add((IBody)node.GetterBody.Item);
            }

            if (node.SetterBody.IsAssigned)
            {
                EmbeddingClass.BodyList.Add((IBody)node.SetterBody.Item);
            }

            node.LocalGetScope.Merge(CheckedGetScope);
            node.LocalGetScope.Seal();
            node.FullGetScope.Merge(node.LocalGetScope);

            node.LocalSetScope.Merge(CheckedSetScope);
            node.LocalSetScope.Seal();
            node.FullSetScope.Merge(node.LocalSetScope);

            node.LocalScope.Seal();
            node.FullScope.Merge(node.LocalScope);

            ScopeHolder.RecursiveAdd(node.FullGetScope, node.InnerGetScopes);
            ScopeHolder.RecursiveAdd(node.FullSetScope, node.InnerSetScopes);

            node.ResolvedFeature.Item = node;

#if COVERAGE
            string TypeString = ResolvedIndexerType.ToString();
#endif
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a function type with resolved arguments.
        /// </summary>
        /// <param name="baseTypeName">The type name of the resolved base type.</param>
        /// <param name="baseType">The type of the resolved base type.</param>
        /// <param name="entityTypeName">The type name of the resolved result type.</param>
        /// <param name="entityType">The type of the resolved result type.</param>
        /// <param name="indexerKind">Type of indexer.</param>
        /// <param name="indexParameterList">The list of parameters.</param>
        /// <param name="parameterEnd">The indexer parameter end type.</param>
        /// <param name="getRequireList">The list of require assertions for the getter.</param>
        /// <param name="getEnsureList">The list of ensure assertions for the getter.</param>
        /// <param name="getExceptionIdentifierList">The list of known exceptions thrown for the getter.</param>
        /// <param name="setRequireList">The list of require assertions for the setter.</param>
        /// <param name="setEnsureList">The list of ensure assertions for the setter.</param>
        /// <param name="setExceptionIdentifierList">The list of known exceptions thrown for the setter.</param>
        /// <param name="resolvedTypeName">The type name upon return.</param>
        /// <param name="resolvedType">The type upon return.</param>
        public static void BuildType(ITypeName baseTypeName, IClassType baseType, ITypeName entityTypeName, ICompiledType entityType, BaseNode.UtilityType indexerKind, IList <IEntityDeclaration> indexParameterList, BaseNode.ParameterEndStatus parameterEnd, IList <IAssertion> getRequireList, IList <IAssertion> getEnsureList, IList <IIdentifier> getExceptionIdentifierList, IList <IAssertion> setRequireList, IList <IAssertion> setEnsureList, IList <IIdentifier> setExceptionIdentifierList, out ITypeName resolvedTypeName, out ICompiledType resolvedType)
        {
            IIndexerType ResolvedIndexerType = new IndexerType(baseTypeName, baseType, entityTypeName, entityType, indexerKind, indexParameterList, parameterEnd, getRequireList, getEnsureList, getExceptionIdentifierList, setRequireList, setEnsureList, setExceptionIdentifierList);

#if COVERAGE
            string TypeString = ResolvedIndexerType.ToString();
            Debug.Assert(!ResolvedIndexerType.IsReference);
            Debug.Assert(ResolvedIndexerType.IsValue);
#endif

            resolvedTypeName = new TypeName(ResolvedIndexerType.TypeFriendlyName);
            resolvedType     = ResolvedIndexerType;
        }
Esempio n. 5
0
        private static bool IsSameParameters(IIndexerType indexerType, IList <IEntityDeclaration> indexParameterList, BaseNode.ParameterEndStatus parameterEnd)
        {
            bool IsSame = true;

            IsSame &= indexerType.IndexParameterList.Count == indexParameterList.Count;

            for (int i = 0; i < indexerType.IndexParameterList.Count && i < indexParameterList.Count; i++)
            {
                IsSame &= indexParameterList[i].ValidEntity.Item.ResolvedEffectiveType.Item == indexerType.IndexParameterList[i].ValidEntity.Item.ResolvedEffectiveType.Item;
            }

            IsSame &= indexerType.ParameterEnd == parameterEnd;

            return(IsSame);
        }
Esempio n. 6
0
        /// <summary>
        /// Checks if a matching function type exists in a type table.
        /// </summary>
        /// <param name="typeTable">The table of existing types.</param>
        /// <param name="baseType">The type of the resolved base type.</param>
        /// <param name="entityType">The type of the resolved result type.</param>
        /// <param name="indexerKind">Type of indexer.</param>
        /// <param name="indexParameterList">The list of parameters.</param>
        /// <param name="parameterEnd">The indexer parameter end type.</param>
        /// <param name="getRequireList">The list of require assertions for the getter.</param>
        /// <param name="getEnsureList">The list of ensure assertions for the getter.</param>
        /// <param name="getExceptionIdentifierList">The list of known exceptions thrown for the getter.</param>
        /// <param name="setRequireList">The list of require assertions for the setter.</param>
        /// <param name="setEnsureList">The list of ensure assertions for the setter.</param>
        /// <param name="setExceptionIdentifierList">The list of known exceptions thrown for the setter.</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, ICompiledType baseType, ICompiledType entityType, BaseNode.UtilityType indexerKind, IList <IEntityDeclaration> indexParameterList, BaseNode.ParameterEndStatus parameterEnd, IList <IAssertion> getRequireList, IList <IAssertion> getEnsureList, IList <IIdentifier> getExceptionIdentifierList, IList <IAssertion> setRequireList, IList <IAssertion> setEnsureList, IList <IIdentifier> setExceptionIdentifierList, out ITypeName resolvedTypeName, out ICompiledType resolvedType)
        {
            resolvedTypeName = null;
            resolvedType     = null;
            bool Result = false;

            foreach (KeyValuePair <ITypeName, ICompiledType> Entry in typeTable)
            {
                if (Entry.Value is IIndexerType AsIndexerType)
                {
                    bool IsSameIndexer = true;

                    IsSameIndexer &= IsSameTypes(AsIndexerType, baseType, entityType, indexerKind);
                    IsSameIndexer &= IsSameParameters(AsIndexerType, indexParameterList, parameterEnd);
                    IsSameIndexer &= IsSameContract(AsIndexerType, getRequireList, getEnsureList, getExceptionIdentifierList, setRequireList, setEnsureList, setExceptionIdentifierList);

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

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

            return(Result);
        }
Esempio n. 7
0
 /// <summary>
 /// Locates, or creates, a resolved function type.
 /// </summary>
 /// <param name="typeTable">The table of existing types.</param>
 /// <param name="baseTypeName">The type name of the resolved base type.</param>
 /// <param name="baseType">The type of the resolved base type.</param>
 /// <param name="entityTypeName">The type name of the resolved result type.</param>
 /// <param name="entityType">The type of the resolved result type.</param>
 /// <param name="indexerKind">Type of indexer.</param>
 /// <param name="indexParameterList">The list of parameters.</param>
 /// <param name="parameterEnd">The indexer parameter end type.</param>
 /// <param name="getRequireList">The list of require assertions for the getter.</param>
 /// <param name="getEnsureList">The list of ensure assertions for the getter.</param>
 /// <param name="getExceptionIdentifierList">The list of known exceptions thrown for the getter.</param>
 /// <param name="setRequireList">The list of require assertions for the setter.</param>
 /// <param name="setEnsureList">The list of ensure assertions for the setter.</param>
 /// <param name="setExceptionIdentifierList">The list of known exceptions thrown for the setter.</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, ITypeName baseTypeName, IClassType baseType, ITypeName entityTypeName, ICompiledType entityType, BaseNode.UtilityType indexerKind, IList <IEntityDeclaration> indexParameterList, BaseNode.ParameterEndStatus parameterEnd, IList <IAssertion> getRequireList, IList <IAssertion> getEnsureList, IList <IIdentifier> getExceptionIdentifierList, IList <IAssertion> setRequireList, IList <IAssertion> setEnsureList, IList <IIdentifier> setExceptionIdentifierList, out ITypeName resolvedTypeName, out ICompiledType resolvedType)
 {
     if (!TypeTableContaining(typeTable, baseType, entityType, indexerKind, indexParameterList, parameterEnd, getRequireList, getEnsureList, getExceptionIdentifierList, setRequireList, setEnsureList, setExceptionIdentifierList, out resolvedTypeName, out resolvedType))
     {
         BuildType(baseTypeName, baseType, entityTypeName, entityType, indexerKind, indexParameterList, parameterEnd, getRequireList, getEnsureList, getExceptionIdentifierList, setRequireList, setEnsureList, setExceptionIdentifierList, out resolvedTypeName, out resolvedType);
         typeTable.Add(resolvedTypeName, resolvedType);
     }
 }