/// <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(ICommandOverload node, object data) { IClass EmbeddingClass = node.EmbeddingClass; ISealableDictionary <string, IScopeAttributeFeature> CheckedScope = ((Tuple <ISealableDictionary <string, IScopeAttributeFeature>, ISealableList <IParameter> >)data).Item1; ISealableList <IParameter> ParameterTable = ((Tuple <ISealableDictionary <string, IScopeAttributeFeature>, ISealableList <IParameter> >)data).Item2; node.ParameterTable.AddRange(ParameterTable); node.ParameterTable.Seal(); IBody CommandBody = (IBody)node.CommandBody; ICommandOverloadType AssociatedType = new CommandOverloadType(node.ParameterList, BaseNode.ParameterEndStatus.Closed, CommandBody.RequireList, CommandBody.EnsureList, CommandBody.ExceptionIdentifierList); AssociatedType.ParameterTable.AddRange(ParameterTable); AssociatedType.ParameterTable.Seal(); node.ResolvedAssociatedType.Item = AssociatedType; node.LocalScope.Merge(CheckedScope); node.LocalScope.Seal(); node.FullScope.Merge(node.LocalScope); ScopeHolder.RecursiveAdd(node.FullScope, node.InnerScopes); EmbeddingClass.BodyList.Add((IBody)node.CommandBody); EmbeddingClass.CommandOverloadList.Add(node); }
/// <summary> /// Checks for errors before applying a rule. /// </summary> /// <param name="node">The node instance to check.</param> /// <param name="dataList">Optional data collected during inspection of sources.</param> /// <param name="data">Private data to give to Apply() upon return.</param> /// <returns>True if an error occured.</returns> public override bool CheckConsistency(IAttachmentInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IExpression AttachmentSource = (IExpression)node.Source; IResultType SourceTypeList = AttachmentSource.ResolvedResult.Item; IClass EmbeddingClass = node.EmbeddingClass; IList <IList <ITypeName> > FullAttachmentTypeNameList = new List <IList <ITypeName> >(); IList <IList <ICompiledType> > FullAttachmentTypeList = new List <IList <ICompiledType> >(); if (SourceTypeList.Count < node.EntityNameList.Count) { AddSourceError(new ErrorInvalidInstruction(node)); Success = false; } else { for (int i = 0; i < node.EntityNameList.Count; i++) { IList <ITypeName> AttachmentTypeNameList = new List <ITypeName>(); IList <ICompiledType> AttachmentTypeList = new List <ICompiledType>(); FullAttachmentTypeNameList.Add(AttachmentTypeNameList); FullAttachmentTypeList.Add(AttachmentTypeList); } for (int i = 0; i < node.EntityNameList.Count; i++) { IExpressionType Item = SourceTypeList.At(i); IName ItemName = node.EntityNameList[i]; IList <ITypeName> AttachmentTypeNameList = FullAttachmentTypeNameList[i]; IList <ICompiledType> AttachmentTypeList = FullAttachmentTypeList[i]; foreach (IAttachment Attachment in node.AttachmentList) { IObjectType AttachedType = Attachment.AttachTypeList[i]; ISealableDictionary <string, IScopeAttributeFeature> CheckedScope = Attachment.FullScope; IList <IClass> AssignedSingleClassList = new List <IClass>(); IErrorList CheckErrorList = new ErrorList(); if (ScopeHolder.HasConflictingSingleAttributes(CheckedScope, node.InnerScopes, AssignedSingleClassList, node, CheckErrorList)) { AddSourceErrorList(CheckErrorList); Success = false; } AttachmentTypeNameList.Add(AttachedType.ResolvedTypeName.Item); AttachmentTypeList.Add(AttachedType.ResolvedType.Item); } } data = new Tuple <IList <IList <ITypeName> >, IList <IList <ICompiledType> > >(FullAttachmentTypeNameList, FullAttachmentTypeList); } return(Success); }
/// <summary> /// Checks for errors before applying a rule. /// </summary> /// <param name="node">The node instance to check.</param> /// <param name="dataList">Optional data collected during inspection of sources.</param> /// <param name="data">Private data to give to Apply() upon return.</param> /// <returns>True if an error occured.</returns> public override bool CheckConsistency(IForLoopInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; IClass EmbeddingClass = node.EmbeddingClass; ISealableDictionary <string, IScopeAttributeFeature> CheckedScope = new SealableDictionary <string, IScopeAttributeFeature>(); foreach (IEntityDeclaration Item in node.EntityDeclarationList) { IScopeAttributeFeature LocalEntity = Item.ValidEntity.Item; string ValidFeatureName = LocalEntity.ValidFeatureName.Item.Name; if (CheckedScope.ContainsKey(ValidFeatureName)) { AddSourceError(new ErrorVariableAlreadyDefined(Item, ValidFeatureName)); Success = false; } else { CheckedScope.Add(ValidFeatureName, LocalEntity); } } IList <string> ConflictList = new List <string>(); ScopeHolder.RecursiveCheck(CheckedScope, node.InnerScopes, ConflictList); foreach (IEntityDeclaration Item in node.EntityDeclarationList) { IScopeAttributeFeature LocalEntity = Item.ValidEntity.Item; string ValidFeatureName = LocalEntity.ValidFeatureName.Item.Name; if (ConflictList.Contains(ValidFeatureName)) { AddSourceError(new ErrorVariableAlreadyDefined(Item, ValidFeatureName)); Success = false; } } IList <IClass> AssignedSingleClassList = new List <IClass>(); IErrorList CheckErrorList = new ErrorList(); if (ScopeHolder.HasConflictingSingleAttributes(CheckedScope, node.InnerScopes, AssignedSingleClassList, node, CheckErrorList)) { AddSourceErrorList(CheckErrorList); Success = false; } if (Success) { data = CheckedScope; } return(Success); }
/// <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(IAttachment node, object data) { node.LocalScope.Seal(); node.FullScope.Merge(node.LocalScope); ScopeHolder.RecursiveAdd(node.FullScope, node.InnerScopes); IList <IScopeHolder> EmbeddingScopeList = ScopeHolder.EmbeddingScope(node); EmbeddingScopeList.Add(node); }
/// <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(IPrecursorIndexAssignmentInstruction node, object data) { node.LocalScope.Seal(); node.FullScope.Merge(node.LocalScope); ScopeHolder.RecursiveAdd(node.FullScope, node.InnerScopes); IList <IScopeHolder> EmbeddingScopeList = ScopeHolder.EmbeddingScope(node); EmbeddingScopeList.Add(node); }
/// <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(IScope node, object data) { ISealableDictionary <string, IScopeAttributeFeature> CheckedScope = (ISealableDictionary <string, IScopeAttributeFeature>)data; node.LocalScope.Merge(CheckedScope); node.LocalScope.Seal(); node.FullScope.Merge(node.LocalScope); ScopeHolder.RecursiveAdd(node.FullScope, node.InnerScopes); IList <IScopeHolder> EmbeddingScopeList = ScopeHolder.EmbeddingScope(node); EmbeddingScopeList.Add(node); }
/// <summary> /// Checks for errors before applying a rule. /// </summary> /// <param name="node">The node instance to check.</param> /// <param name="dataList">Optional data collected during inspection of sources.</param> /// <param name="data">Private data to give to Apply() upon return.</param> /// <returns>True if an error occured.</returns> public override bool CheckConsistency(ICommandOverload node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; ISealableDictionary <string, IScopeAttributeFeature> CheckedScope = new SealableDictionary <string, IScopeAttributeFeature>(); ISealableList <IParameter> ParameterTable = new SealableList <IParameter>(); foreach (EntityDeclaration Item in node.ParameterList) { IName SourceName = (IName)Item.EntityName; string ValidName = SourceName.ValidText.Item; if (CheckedScope.ContainsKey(ValidName)) { AddSourceError(new ErrorDuplicateName(SourceName, ValidName)); Success = false; } else { CheckedScope.Add(ValidName, Item.ValidEntity.Item); ParameterTable.Add(new Parameter(ValidName, Item.ValidEntity.Item)); } } IList <string> ConflictList = new List <string>(); ScopeHolder.RecursiveCheck(CheckedScope, node.InnerScopes, ConflictList); foreach (IEntityDeclaration Item in node.ParameterList) { IScopeAttributeFeature LocalEntity = Item.ValidEntity.Item; string ValidFeatureName = LocalEntity.ValidFeatureName.Item.Name; if (ConflictList.Contains(ValidFeatureName)) { AddSourceError(new ErrorVariableAlreadyDefined(Item, ValidFeatureName)); Success = false; } } if (Success) { data = new Tuple <ISealableDictionary <string, IScopeAttributeFeature>, ISealableList <IParameter> >(CheckedScope, ParameterTable); } return(Success); }
/// <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(IQueryOverload node, object data) { IClass EmbeddingClass = node.EmbeddingClass; IFeature EmbeddingFeature = node.EmbeddingFeature; ISealableDictionary <string, IScopeAttributeFeature> CheckedScope = (ISealableDictionary <string, IScopeAttributeFeature>)data; node.LocalScope.Merge(CheckedScope); node.LocalScope.Seal(); node.FullScope.Merge(node.LocalScope); ScopeHolder.RecursiveAdd(node.FullScope, node.InnerScopes); EmbeddingClass.BodyList.Add((IBody)node.QueryBody); EmbeddingClass.QueryOverloadList.Add(node); }
/// <summary> /// Checks for errors before applying a rule. /// </summary> /// <param name="node">The node instance to check.</param> /// <param name="dataList">Optional data collected during inspection of sources.</param> /// <param name="data">Private data to give to Apply() upon return.</param> /// <returns>True if an error occured.</returns> public override bool CheckConsistency(IOverLoopInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; ISealableDictionary <string, IScopeAttributeFeature> CheckedScope = new SealableDictionary <string, IScopeAttributeFeature>(); IClass EmbeddingClass = node.EmbeddingClass; foreach (IName Item in node.IndexerList) { Debug.Assert(Item.ValidText.IsAssigned); string ValidText = Item.ValidText.Item; if (CheckedScope.ContainsKey(ValidText)) { AddSourceError(new ErrorVariableAlreadyDefined(Item, ValidText)); Success = false; } else { IScopeAttributeFeature NewEntity = ScopeAttributeFeature.Create(Item, ValidText); CheckedScope.Add(ValidText, NewEntity); } } IList <string> ConflictList = new List <string>(); ScopeHolder.RecursiveCheck(CheckedScope, node.InnerScopes, ConflictList); foreach (KeyValuePair <string, IScopeAttributeFeature> Item in CheckedScope) { if (ConflictList.Contains(Item.Key)) { AddSourceError(new ErrorVariableAlreadyDefined(Item.Value.Location, Item.Key)); Success = false; } } if (Success) { data = CheckedScope; } return(Success); }
/// <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(IAttachmentInstruction node, object data) { IList <ISealableDictionary <string, IScopeAttributeFeature> > CheckedScopeList = (IList <ISealableDictionary <string, IScopeAttributeFeature> >)data; Debug.Assert(CheckedScopeList.Count == node.AttachmentList.Count); node.LocalScope.Seal(); for (int i = 0; i < node.AttachmentList.Count; i++) { IAttachment AttachmentItem = node.AttachmentList[i]; ISealableDictionary <string, IScopeAttributeFeature> CheckedScope = CheckedScopeList[i]; AttachmentItem.FullScope.Merge(CheckedScope); ScopeHolder.RecursiveAdd(CheckedScope, AttachmentItem.InnerScopes); } IList <IScopeHolder> EmbeddingScopeList = ScopeHolder.EmbeddingScope(node); EmbeddingScopeList.Add(node); }
private bool CheckResultValueConsistency(IIndexerFeature node, IDictionary <ISourceTemplate, object> dataList, IScopeAttributeFeature resultFeature, IScopeAttributeFeature valueFeature, out object data) { data = null; bool Success = true; ISealableDictionary <string, IScopeAttributeFeature> CheckedScope = new SealableDictionary <string, IScopeAttributeFeature>(); ISealableDictionary <string, IScopeAttributeFeature> CheckedGetScope = new SealableDictionary <string, IScopeAttributeFeature>(); ISealableDictionary <string, IScopeAttributeFeature> CheckedSetScope = new SealableDictionary <string, IScopeAttributeFeature>(); string NameResult = resultFeature.ValidFeatureName.Item.Name; string NameValue = valueFeature.ValidFeatureName.Item.Name; Success &= CheckParameters(node, resultFeature, valueFeature, CheckedScope); CheckedGetScope.Merge(CheckedScope); CheckedGetScope.Add(NameResult, resultFeature); CheckedSetScope.Merge(CheckedScope); CheckedSetScope.Add(NameValue, valueFeature); List <string> ConflictList = new List <string>(); ScopeHolder.RecursiveCheck(CheckedGetScope, node.InnerScopes, ConflictList); ScopeHolder.RecursiveCheck(CheckedSetScope, node.InnerScopes, ConflictList); Debug.Assert(node.InnerScopes.Count == 0); // This has been checked in another rule. Debug.Assert(!ConflictList.Contains(NameResult)); Debug.Assert(!ConflictList.Contains(NameValue)); Success &= CheckIndexerKind(node, out BaseNode.UtilityType IndexerKind); if (Success) { data = new Tuple <BaseNode.UtilityType, ISealableDictionary <string, IScopeAttributeFeature>, ISealableDictionary <string, IScopeAttributeFeature>, ISealableDictionary <string, IScopeAttributeFeature> >(IndexerKind, CheckedScope, CheckedGetScope, CheckedSetScope); } return(Success); }
/// <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> /// Checks for errors before applying a rule. /// </summary> /// <param name="node">The node instance to check.</param> /// <param name="dataList">Optional data collected during inspection of sources.</param> /// <param name="data">Private data to give to Apply() upon return.</param> /// <returns>True if an error occured.</returns> public override bool CheckConsistency(IQueryOverload node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; ISealableDictionary <string, IScopeAttributeFeature> CheckedScope = new SealableDictionary <string, IScopeAttributeFeature>(); Debug.Assert(node.ParameterTable.Count == node.ParameterList.Count); for (int i = 0; i < node.ParameterTable.Count; i++) { IParameter Parameter = node.ParameterTable[i]; IEntityDeclaration EntityDeclaration = node.ParameterList[i]; if (CheckedScope.ContainsKey(Parameter.Name)) { AddSourceError(new ErrorDuplicateName(EntityDeclaration, Parameter.Name)); Success = false; } else { CheckedScope.Add(Parameter.Name, EntityDeclaration.ValidEntity.Item); } } Debug.Assert(node.ResultTable.Count == node.ResultList.Count); for (int i = 0; i < node.ResultTable.Count; i++) { IParameter Result = node.ResultTable[i]; IEntityDeclaration EntityDeclaration = node.ResultList[i]; if (CheckedScope.ContainsKey(Result.Name)) { AddSourceError(new ErrorDuplicateName(EntityDeclaration, Result.Name)); Success = false; } else { CheckedScope.Add(Result.Name, EntityDeclaration.ValidEntity.Item); } } IList <string> ConflictList = new List <string>(); ScopeHolder.RecursiveCheck(CheckedScope, node.InnerScopes, ConflictList); foreach (IEntityDeclaration Item in node.ParameterList) { IScopeAttributeFeature LocalEntity = Item.ValidEntity.Item; string ValidFeatureName = LocalEntity.ValidFeatureName.Item.Name; if (ConflictList.Contains(ValidFeatureName)) { AddSourceError(new ErrorVariableAlreadyDefined(Item, ValidFeatureName)); Success = false; } } foreach (IEntityDeclaration Item in node.ResultList) { IScopeAttributeFeature LocalEntity = Item.ValidEntity.Item; string ValidFeatureName = LocalEntity.ValidFeatureName.Item.Name; if (ConflictList.Contains(ValidFeatureName)) { AddSourceError(new ErrorVariableAlreadyDefined(Item, ValidFeatureName)); Success = false; } } if (Success) { data = CheckedScope; } return(Success); }
/// <summary> /// Checks for errors before applying a rule. /// </summary> /// <param name="node">The node instance to check.</param> /// <param name="dataList">Optional data collected during inspection of sources.</param> /// <param name="data">Private data to give to Apply() upon return.</param> /// <returns>True if an error occured.</returns> public override bool CheckConsistency(IPropertyFeature node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IClass EmbeddingClass = node.EmbeddingClass; IObjectType TypeToResolve = (IObjectType)node.EntityType; IScopeAttributeFeature Result = ScopeAttributeFeature.CreateResultFeature(TypeToResolve, EmbeddingClass, node); IScopeAttributeFeature Value = ScopeAttributeFeature.CreateValueFeature(TypeToResolve, EmbeddingClass, node); string NameResult = Result.ValidFeatureName.Item.Name; string NameValue = Value.ValidFeatureName.Item.Name; ISealableDictionary <string, IScopeAttributeFeature> CheckedGetScope = new SealableDictionary <string, IScopeAttributeFeature>(); CheckedGetScope.Add(NameResult, Result); ISealableDictionary <string, IScopeAttributeFeature> CheckedSetScope = new SealableDictionary <string, IScopeAttributeFeature>(); CheckedSetScope.Add(NameValue, Value); IList <string> ConflictList = new List <string>(); ScopeHolder.RecursiveCheck(CheckedGetScope, node.InnerScopes, ConflictList); ScopeHolder.RecursiveCheck(CheckedSetScope, node.InnerScopes, ConflictList); // This has been checked in another rule. Debug.Assert(!ConflictList.Contains(NameResult)); Debug.Assert(!ConflictList.Contains(NameValue)); IName PropertyName = (IName)((IFeatureWithName)node).EntityName; if (node.GetterBody.IsAssigned && node.SetterBody.IsAssigned) { ICompiledBody AsCompiledGetter = (ICompiledBody)node.GetterBody.Item; ICompiledBody AsCompiledSetter = (ICompiledBody)node.SetterBody.Item; if (AsCompiledGetter.IsDeferredBody != AsCompiledSetter.IsDeferredBody) { AddSourceError(new ErrorBodyTypeMismatch(node, PropertyName.ValidText.Item)); Success = false; } if (node.PropertyKind != BaseNode.UtilityType.ReadWrite) { AddSourceError(new ErrorBodyTypeMismatch(node, PropertyName.ValidText.Item)); Success = false; } } else if (node.GetterBody.IsAssigned) { if (node.PropertyKind == BaseNode.UtilityType.WriteOnly) { AddSourceError(new ErrorBodyTypeMismatch(node, PropertyName.ValidText.Item)); Success = false; } } else if (node.SetterBody.IsAssigned) { if (node.PropertyKind == BaseNode.UtilityType.ReadOnly) { AddSourceError(new ErrorBodyTypeMismatch(node, PropertyName.ValidText.Item)); Success = false; } } if (Success) { data = new Tuple <IScopeAttributeFeature, IScopeAttributeFeature>(Result, Value); } return(Success); }
/// <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(IPropertyFeature node, object data) { IClass EmbeddingClass = node.EmbeddingClass; IObjectType TypeToResolve = (IObjectType)node.EntityType; ITypeName BaseTypeName = EmbeddingClass.ResolvedClassTypeName.Item; IClassType BaseType = EmbeddingClass.ResolvedClassType.Item; ITypeName EntityTypeName = TypeToResolve.ResolvedTypeName.Item; ICompiledType EntityType = TypeToResolve.ResolvedType.Item; 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.EnsureList) { GetEnsureList.Add(Item); } foreach (IIdentifier Item in GetterBody.ExceptionIdentifierList) { GetExceptionIdentifierList.Add(Item); } } IList <IAssertion> SetRequireList = 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 (IIdentifier Item in SetterBody.ExceptionIdentifierList) { SetExceptionIdentifierList.Add(Item); } } PropertyType.ResolveType(EmbeddingClass.TypeTable, BaseTypeName, BaseType.SourceType, BaseType, EntityTypeName, EntityType, node.PropertyKind, GetEnsureList, GetExceptionIdentifierList, SetRequireList, SetExceptionIdentifierList, out ITypeName ResolvedPropertyTypeName, out ICompiledType ResolvedPropertyType); #if COVERAGE Debug.Assert(!ResolvedPropertyType.IsReference); Debug.Assert(ResolvedPropertyType.IsValue); #endif node.ResolvedEntityTypeName.Item = EntityTypeName; node.ResolvedEntityType.Item = EntityType; node.ResolvedAgentTypeName.Item = ResolvedPropertyTypeName; node.ResolvedAgentType.Item = ResolvedPropertyType; node.ResolvedEffectiveTypeName.Item = EntityTypeName; node.ResolvedEffectiveType.Item = EntityType; if (node.GetterBody.IsAssigned) { EmbeddingClass.BodyList.Add((IBody)node.GetterBody.Item); } if (node.SetterBody.IsAssigned) { EmbeddingClass.BodyList.Add((IBody)node.SetterBody.Item); } IScopeAttributeFeature Result = ((Tuple <IScopeAttributeFeature, IScopeAttributeFeature>)data).Item1; IScopeAttributeFeature Value = ((Tuple <IScopeAttributeFeature, IScopeAttributeFeature>)data).Item2; node.LocalGetScope.Add(Result.ValidFeatureName.Item.Name, Result); node.LocalGetScope.Seal(); node.FullGetScope.Merge(node.LocalGetScope); node.LocalSetScope.Add(Value.ValidFeatureName.Item.Name, Value); 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 = ResolvedPropertyType.ToString(); #endif }
/// <summary> /// Checks for errors before applying a rule. /// </summary> /// <param name="node">The node instance to check.</param> /// <param name="dataList">Optional data collected during inspection of sources.</param> /// <param name="data">Private data to give to Apply() upon return.</param> /// <returns>True if an error occured.</returns> public override bool CheckConsistency(IAttachmentInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; IClass EmbeddingClass = node.EmbeddingClass; IList <ISealableDictionary <string, IScopeAttributeFeature> > CheckedScopeList = new List <ISealableDictionary <string, IScopeAttributeFeature> >(); for (int i = 0; i < node.AttachmentList.Count; i++) { CheckedScopeList.Add(new SealableDictionary <string, IScopeAttributeFeature>()); } for (int Index = 0; Index < node.EntityNameList.Count; Index++) { IName Item = node.EntityNameList[Index]; Debug.Assert(Item.ValidText.IsAssigned); string ValidText = Item.ValidText.Item; if (CheckedScopeList[0].ContainsKey(ValidText)) { AddSourceError(new ErrorVariableAlreadyDefined(Item, ValidText)); Success = false; continue; } for (int i = 0; i < node.AttachmentList.Count; i++) { Attachment AttachmentItem = (Attachment)node.AttachmentList[i]; ISealableDictionary <string, IScopeAttributeFeature> CheckedScope = CheckedScopeList[i]; Debug.Assert(Index < AttachmentItem.AttachTypeList.Count); IObjectType AttachedType = AttachmentItem.AttachTypeList[Index]; Debug.Assert(AttachedType.ResolvedTypeName.IsAssigned); Debug.Assert(AttachedType.ResolvedType.IsAssigned); IScopeAttributeFeature NewEntity = ScopeAttributeFeature.Create(Item, ValidText, AttachedType.ResolvedTypeName.Item, AttachedType.ResolvedType.Item); CheckedScope.Add(ValidText, NewEntity); } } IList <string> ConflictList = new List <string>(); for (int i = 0; i < node.AttachmentList.Count; i++) { IAttachment AttachmentItem = (Attachment)node.AttachmentList[i]; ISealableDictionary <string, IScopeAttributeFeature> CheckedScope = CheckedScopeList[i]; ScopeHolder.RecursiveCheck(CheckedScope, AttachmentItem.InnerScopes, ConflictList); } foreach (IName Item in node.EntityNameList) { Debug.Assert(Item.ValidText.IsAssigned); string ValidText = Item.ValidText.Item; if (ConflictList.Contains(ValidText)) { AddSourceError(new ErrorVariableAlreadyDefined(Item, ValidText)); Success = false; } } if (Success) { data = CheckedScopeList; } return(Success); }