private bool CheckIndexerKind(IIndexerFeature node, out BaseNode.UtilityType indexerKind) { bool Success = true; indexerKind = (BaseNode.UtilityType)(-1); if (node.GetterBody.IsAssigned && node.SetterBody.IsAssigned) { indexerKind = BaseNode.UtilityType.ReadWrite; ICompiledBody AsCompiledGetter = (ICompiledBody)node.GetterBody.Item; ICompiledBody AsCompiledSetter = (ICompiledBody)node.SetterBody.Item; if (AsCompiledGetter.IsDeferredBody != AsCompiledSetter.IsDeferredBody) { AddSourceError(new ErrorIndexerBodyTypeMismatch(node)); Success = false; } } else if (node.GetterBody.IsAssigned) { indexerKind = BaseNode.UtilityType.ReadOnly; } else if (node.SetterBody.IsAssigned) { indexerKind = BaseNode.UtilityType.WriteOnly; } else { AddSourceError(new ErrorIndexerMissingBody(node)); Success = false; } return(Success); }
/// <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(); }
/// <summary> /// Initializes a new instance of the <see cref="PropertyType"/> class. /// </summary> /// <param name="baseTypeName">The type name of the resolved base type.</param> /// <param name="baseType">The base type.</param> /// <param name="resolvedBaseType">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="propertyKind">The type of the property.</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="setExceptionIdentifierList">The list of known exceptions thrown for the setter.</param> public PropertyType(ITypeName baseTypeName, IObjectType baseType, ICompiledTypeWithFeature resolvedBaseType, ITypeName entityTypeName, ICompiledType entityType, BaseNode.UtilityType propertyKind, IList <IAssertion> getEnsureList, IList <IIdentifier> getExceptionIdentifierList, IList <IAssertion> setRequireList, IList <IIdentifier> setExceptionIdentifierList) : this() { BaseType = baseType; EntityType = null; PropertyKind = propertyKind; ResolvedBaseTypeName.Item = baseTypeName; ResolvedBaseType.Item = resolvedBaseType; ResolvedEntityTypeName.Item = entityTypeName; ResolvedEntityType.Item = entityType; GetEnsureList = getEnsureList; GetExceptionIdentifierList = getExceptionIdentifierList; SetRequireList = setRequireList; SetExceptionIdentifierList = setExceptionIdentifierList; }
/// <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 }
/// <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; }
private static bool IsSameTypes(IIndexerType indexerType, ICompiledType baseType, ICompiledType entityType, BaseNode.UtilityType indexerKind) { bool IsSame = true; IsSame &= indexerType.ResolvedBaseType.Item == baseType; IsSame &= indexerType.ResolvedEntityType.Item == entityType; IsSame &= indexerType.IndexerKind == indexerKind; return(IsSame); }
/// <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); }
/// <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); } }
/// <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 base type.</param> /// <param name="resolvedBaseType">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="propertyKind">The type of the property.</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="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, IObjectType baseType, ICompiledTypeWithFeature resolvedBaseType, ITypeName entityTypeName, ICompiledType entityType, BaseNode.UtilityType propertyKind, IList <IAssertion> getEnsureList, IList <IIdentifier> getExceptionIdentifierList, IList <IAssertion> setRequireList, IList <IIdentifier> setExceptionIdentifierList, out ITypeName resolvedTypeName, out ICompiledType resolvedType) { IPropertyType ResolvedPropertyType = new PropertyType(baseTypeName, baseType, resolvedBaseType, entityTypeName, entityType, propertyKind, getEnsureList, getExceptionIdentifierList, setRequireList, setExceptionIdentifierList); resolvedTypeName = new TypeName(ResolvedPropertyType.TypeFriendlyName); resolvedType = ResolvedPropertyType; }
/// <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="propertyKind">The type of the property.</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="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 propertyKind, IList <IAssertion> getEnsureList, IList <IIdentifier> getExceptionIdentifierList, IList <IAssertion> setRequireList, 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 IPropertyType AsPropertyType) { bool IsSame = true; IsSame &= AsPropertyType.ResolvedBaseType.Item == baseType; IsSame &= AsPropertyType.ResolvedEntityType.Item == entityType; IsSame &= AsPropertyType.PropertyKind == propertyKind; IsSame &= Assertion.IsAssertionListEqual(AsPropertyType.GetEnsureList, getEnsureList); IsSame &= ExceptionHandler.IdenticalExceptionSignature(AsPropertyType.GetExceptionIdentifierList, getExceptionIdentifierList); IsSame &= Assertion.IsAssertionListEqual(AsPropertyType.SetRequireList, setRequireList); IsSame &= ExceptionHandler.IdenticalExceptionSignature(AsPropertyType.SetExceptionIdentifierList, setExceptionIdentifierList); if (IsSame) { Debug.Assert(!Result); resolvedTypeName = Entry.Key; resolvedType = AsPropertyType; Result = true; } } } return(Result); }
/// <summary> /// Locates, or creates, a resolved property type. /// </summary> /// <param name="typeTable">The table of existing types.</param> /// <param name="baseTypeName">Name of the resolved base type.</param> /// <param name="baseType">The base type.</param> /// <param name="resolvedBaseType">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="propertyKind">The type of the property.</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="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, IObjectType baseType, ICompiledTypeWithFeature resolvedBaseType, ITypeName entityTypeName, ICompiledType entityType, BaseNode.UtilityType propertyKind, IList <IAssertion> getEnsureList, IList <IIdentifier> getExceptionIdentifierList, IList <IAssertion> setRequireList, IList <IIdentifier> setExceptionIdentifierList, out ITypeName resolvedTypeName, out ICompiledType resolvedType) { if (!TypeTableContaining(typeTable, resolvedBaseType, entityType, propertyKind, getEnsureList, getExceptionIdentifierList, setRequireList, setExceptionIdentifierList, out resolvedTypeName, out resolvedType)) { BuildType(baseTypeName, baseType, resolvedBaseType, entityTypeName, entityType, propertyKind, getEnsureList, getExceptionIdentifierList, setRequireList, setExceptionIdentifierList, out resolvedTypeName, out resolvedType); typeTable.Add(resolvedTypeName, resolvedType); } }