/// <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) { data = null; bool Success = true; IExpression OverList = (IExpression)node.OverList; IResultType OverTypeList = OverList.ResolvedResult.Item; IScope LoopInstructions = (IScope)node.LoopInstructions; IClass EmbeddingClass = node.EmbeddingClass; bool IsOverLoopSourceTypeAvailable = Expression.IsLanguageTypeAvailable(LanguageClasses.OverLoopSource.Guid, node, out ITypeName OverLoopSourceTypeName, out ICompiledType OverLoopSourceType); bool IsNumberTypeAvailable = Expression.IsLanguageTypeAvailable(LanguageClasses.Number.Guid, node, out ITypeName NumberTypeName, out ICompiledType NumberType); foreach (IExpressionType Item in OverTypeList) { ICompiledType ResultType = Item.ValueType; IErrorList OverSourceErrorList = new ErrorList(); bool IsConformantToEnumerable = false; bool IsConformantToNumericIndexer = false; if (IsOverLoopSourceTypeAvailable && ObjectType.TypeConformToBase(ResultType, OverLoopSourceType, isConversionAllowed: true)) { IsConformantToEnumerable = true; } if (IsNumberTypeAvailable && ResultType.FeatureTable.ContainsKey(FeatureName.IndexerFeatureName)) { IFeatureInstance IndexerInstance = ResultType.FeatureTable[FeatureName.IndexerFeatureName]; IIndexerFeature IndexerFeature = IndexerInstance.Feature as IIndexerFeature; Debug.Assert(IndexerFeature != null); if (IndexerFeature.IndexParameterList.Count == 1) { IEntityDeclaration IndexParameterDeclaration = IndexerFeature.IndexParameterList[0]; if (IndexParameterDeclaration.ValidEntity.Item.ResolvedEffectiveType.Item == NumberType) { IsConformantToNumericIndexer = true; } } } Debug.Assert(IsConformantToEnumerable != IsConformantToNumericIndexer); } IResultException ResolvedException = new ResultException(); ResultException.Merge(ResolvedException, OverList.ResolvedException.Item); ResultException.Merge(ResolvedException, LoopInstructions.ResolvedException.Item); foreach (IAssertion Item in node.InvariantList) { ResultException.Merge(ResolvedException, Item.ResolvedException.Item); } data = ResolvedException; 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) { data = null; bool Success = true; IExpression WhileCondition = (IExpression)node.WhileCondition; IResultType ResolvedResult = WhileCondition.ResolvedResult.Item; IClass EmbeddingClass = node.EmbeddingClass; if (ResolvedResult.Count > 1) { AddSourceError(new ErrorInvalidExpression(WhileCondition)); Success = false; } else if (!IsForLoopTypeAvailable(node)) { Success = false; } else { IResultException ResolvedException = new ResultException(); foreach (IInstruction Item in node.InitInstructionList) { ResultException.Merge(ResolvedException, Item.ResolvedException.Item); } ResultException.Merge(ResolvedException, WhileCondition.ResolvedException.Item); foreach (IInstruction Item in node.LoopInstructionList) { ResultException.Merge(ResolvedException, Item.ResolvedException.Item); } foreach (IInstruction Item in node.IterationInstructionList) { ResultException.Merge(ResolvedException, Item.ResolvedException.Item); } foreach (Assertion Item in node.InvariantList) { ResultException.Merge(ResolvedException, Item.ResolvedException.Item); } if (node.Variant.IsAssigned) { IExpression Variant = (IExpression)node.Variant.Item; ResultException.Merge(ResolvedException, Variant.ResolvedException.Item); } data = ResolvedException; } 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(IPrecursorIndexAssignmentInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IExpression SourceExpression = (IExpression)node.Source; IResultType SourceResult = SourceExpression.ResolvedResult.Item; IClass EmbeddingClass = node.EmbeddingClass; ISealableDictionary <string, IImportedClass> ClassTable = EmbeddingClass.ImportedClassTable; ISealableDictionary <IFeatureName, IFeatureInstance> FeatureTable = EmbeddingClass.FeatureTable; IFeature InnerFeature = node.EmbeddingFeature; if (InnerFeature is IIndexerFeature AsIndexerFeature) { IFeatureInstance Instance = FeatureTable[AsIndexerFeature.ValidFeatureName.Item]; if (!Instance.FindPrecursor(node.AncestorType, ErrorList, node, out IFeatureInstance SelectedPrecursor)) { return(false); } IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >(); IList <ISealableList <IParameter> > ResultTableList = new List <ISealableList <IParameter> >(); ICompiledFeature OperatorFeature = SelectedPrecursor.Feature; IIndexerType AsIndexerType = OperatorFeature.ResolvedAgentType.Item as IIndexerType; Debug.Assert(AsIndexerType != null); ParameterTableList.Add(AsIndexerType.ParameterTable); ResultTableList.Add(new SealableList <IParameter>()); if (!Argument.CheckAssignmentConformance(ParameterTableList, ResultTableList, node.ArgumentList, SourceExpression, AsIndexerType.ResolvedEntityType.Item, ErrorList, node, out IFeatureCall FeatureCall)) { return(false); } IResultException ResolvedException = new ResultException(); ResultException.Merge(ResolvedException, SourceExpression.ResolvedException.Item); foreach (IArgument Item in node.ArgumentList) { ResultException.Merge(ResolvedException, Item.ResolvedException.Item); } ResultException.Merge(ResolvedException, AsIndexerType.SetExceptionIdentifierList); data = new Tuple <IResultException, IFeatureCall>(ResolvedException, FeatureCall); } else { AddSourceError(new ErrorInvalidInstruction(node)); return(false); } 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(IInspectInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; IExpression Source = (IExpression)node.Source; IResultType ResolvedResult = Source.ResolvedResult.Item; IClass EmbeddingClass = node.EmbeddingClass; if (ResolvedResult.Count > 1) { AddSourceError(new ErrorInvalidExpression(Source)); return(false); } ICompiledType ValueType = ResolvedResult.At(0).ValueType; ISealableDictionary <IFeatureName, IDiscrete> EnforcedDiscreteTable = null; if (ValueType is IClassType AsClassType) { if (!CheckConsistencyClassType(node, AsClassType, ref EnforcedDiscreteTable)) { return(false); } } else { AddSourceError(new ErrorInvalidExpression(Source)); return(false); } if (!CheckConsistencyRange(node, EnforcedDiscreteTable)) { return(false); } IResultException ResolvedException = new ResultException(); ResultException.Merge(ResolvedException, Source.ResolvedException.Item); foreach (IWith Item in node.WithList) { ResultException.Merge(ResolvedException, Item.ResolvedException.Item); } if (node.ElseInstructions.IsAssigned) { IScope ElseInstructions = (IScope)node.ElseInstructions.Item; ResultException.Merge(ResolvedException, ElseInstructions.ResolvedException.Item); } data = ResolvedException; return(true); }
/// <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(IDebugInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IScope Instructions = (IScope)node.Instructions; IResultException ResolvedException = new ResultException(); ResultException.Merge(ResolvedException, Instructions.ResolvedException); data = ResolvedException; 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(IConditional node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IExpression BooleanExpression = (IExpression)node.BooleanExpression; IScope Instructions = (IScope)node.Instructions; IResultType ResolvedResult = BooleanExpression.ResolvedResult.Item; IClass EmbeddingClass = node.EmbeddingClass; if (ResolvedResult.Count > 1) { AddSourceError(new ErrorInvalidExpression(BooleanExpression)); Success = false; } else { bool IsBooleanTypeAvailable = Expression.IsLanguageTypeAvailable(LanguageClasses.Boolean.Guid, node, out ITypeName BooleanTypeName, out ICompiledType BooleanType); bool IsEventTypeAvailable = Expression.IsLanguageTypeAvailable(LanguageClasses.Event.Guid, node, out ITypeName EventTypeName, out ICompiledType EventType); if (!IsBooleanTypeAvailable && !IsEventTypeAvailable) { AddSourceError(new ErrorBooleanTypeMissing(node)); Success = false; } else { ICompiledType ContractType = ResolvedResult.At(0).ValueType; if (!IsValidType(ContractType, IsBooleanTypeAvailable, BooleanType) && !IsValidType(ContractType, IsEventTypeAvailable, EventType)) { AddSourceError(new ErrorInvalidExpression(BooleanExpression)); Success = false; } else { IResultException ResolvedException = new ResultException(); ResultException.Merge(ResolvedException, BooleanExpression.ResolvedException.Item); ResultException.Merge(ResolvedException, Instructions.ResolvedException.Item); data = ResolvedException; } } } 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(IScope node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IResultException ResolvedException = new ResultException(); foreach (IInstruction Item in node.InstructionList) { ResultException.Merge(ResolvedException, Item.ResolvedException.Item); } data = ResolvedException; 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(IRange node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IExpression LeftExpression = (IExpression)node.LeftExpression; IResultException ResolvedException = new ResultException(); ResultException.Merge(ResolvedException, LeftExpression.ResolvedException.Item); if (node.RightExpression.IsAssigned) { IExpression RightExpression = (IExpression)node.RightExpression.Item; ResultException.Merge(ResolvedException, RightExpression.ResolvedException.Item); } data = ResolvedException; 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(IIfThenElseInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IResultException ResolvedException = new ResultException(); foreach (IConditional Item in node.ConditionalList) { ResultException.Merge(ResolvedException, Item.ResolvedException); } if (node.ElseInstructions.IsAssigned) { IScope ElseInstructions = (IScope)node.ElseInstructions.Item; ResultException.Merge(ResolvedException, ElseInstructions.ResolvedException); } data = ResolvedException; 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(IWith node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IScope Instructions = (IScope)node.Instructions; // This is enforced when the root node is validated. Debug.Assert(node.RangeList.Count > 0); IResultException ResolvedException = new ResultException(); foreach (IRange Item in node.RangeList) { ResultException.Merge(ResolvedException, Item.ResolvedException.Item); } ResultException.Merge(ResolvedException, Instructions.ResolvedException.Item); data = ResolvedException; 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(IThrowInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IObjectType ThrowExceptionType = (IObjectType)node.ExceptionType; ICompiledType ResolvedType = ThrowExceptionType.ResolvedType.Item; IIdentifier CreationRoutine = (IIdentifier)node.CreationRoutine; string ValidText = CreationRoutine.ValidText.Item; IClass EmbeddingClass = node.EmbeddingClass; if (!Expression.IsLanguageTypeAvailable(LanguageClasses.Exception.Guid, node, out ITypeName ExceptionTypeName, out ICompiledType ExceptionType)) { AddSourceError(new ErrorExceptionTypeMissing(node)); return(false); } if (!ObjectType.TypeConformToBase(ResolvedType, ExceptionType, isConversionAllowed: true)) { AddSourceError(new ErrorExceptionTypeRequired(node)); return(false); } if (!FeatureName.TableContain(ResolvedType.FeatureTable, ValidText, out IFeatureName Key, out IFeatureInstance Value)) { AddSourceError(new ErrorUnknownIdentifier(CreationRoutine, ValidText)); return(false); } if (Value.Feature is CreationFeature AsCreationFeature) { List <IExpressionType> MergedArgumentList = new List <IExpressionType>(); if (!Argument.Validate(node.ArgumentList, MergedArgumentList, out TypeArgumentStyles TypeArgumentStyle, ErrorList)) { return(false); } IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >(); Debug.Assert(AsCreationFeature.ResolvedAgentType.IsAssigned); ICompiledType FinalType = AsCreationFeature.ResolvedAgentType.Item; IProcedureType AsProcedureType = FinalType as IProcedureType; Debug.Assert(AsProcedureType != null); foreach (ICommandOverloadType Overload in AsProcedureType.OverloadList) { ParameterTableList.Add(Overload.ParameterTable); } if (!Argument.ArgumentsConformToParameters(ParameterTableList, MergedArgumentList, TypeArgumentStyle, ErrorList, node, out int SelectedIndex)) { return(false); } ICommandOverloadType SelectedOverload = AsProcedureType.OverloadList[SelectedIndex]; IResultException ResolvedException = new ResultException(); ResolvedException.Add(ValidText); Debug.Assert(ResolvedException.At(0).Text == ValidText); Debug.Assert(ResolvedException.At(0).ValidText.IsAssigned); Debug.Assert(ResolvedException.At(0).ValidText.Item == ValidText); foreach (IArgument Item in node.ArgumentList) { ResultException.Merge(ResolvedException, Item.ResolvedException.Item); } ResultException.Merge(ResolvedException, SelectedOverload.ExceptionIdentifierList); IFeatureCall FeatureCall = new FeatureCall(SelectedOverload.ParameterTable, new List <IParameter>(), node.ArgumentList, MergedArgumentList, TypeArgumentStyle); data = new Tuple <ICompiledType, IResultException, IFeatureCall>(ResolvedType, ResolvedException, FeatureCall); } else { AddSourceError(new ErrorCreationFeatureRequired(CreationRoutine, ValidText)); return(false); } 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(ICreateInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IIdentifier EntityIdentifier = (IIdentifier)node.EntityIdentifier; string ValidText = EntityIdentifier.ValidText.Item; IClass EmbeddingClass = node.EmbeddingClass; IClassType BaseType = EmbeddingClass.ResolvedClassType.Item; if (!GetCreatedEntity(node, out ITypeName AttributeTypeName, out ICompiledType AttributeType)) { return(false); } Debug.Assert(AttributeType.IsReference); IList <IClassType> ConstraintClassTypeList = new List <IClassType>(); if (!CheckConstraints(node, AttributeType, ConstraintClassTypeList)) { return(false); } if (!CheckCreationRoutine(node, ConstraintClassTypeList, out ICreationFeature CreationFeature)) { return(false); } if (!CheckCall(node, AttributeTypeName, AttributeType, CreationFeature, out ICommandOverloadType SelectedOverload, out IFeatureCall FeatureCall)) { return(false); } ITypeName CreatedObjectTypeName = AttributeTypeName; ICompiledType CreatedObjectType = AttributeType; if (node.Processor.IsAssigned) { IQualifiedName Processor = (IQualifiedName)node.Processor.Item; IList <IIdentifier> ValidPath = Processor.ValidPath.Item; ISealableDictionary <string, IScopeAttributeFeature> LocalScope = Scope.CurrentScope(node); if (!ObjectType.GetQualifiedPathFinalType(EmbeddingClass, BaseType, LocalScope, ValidPath, 0, ErrorList, out ICompiledFeature FinalFeature, out IDiscrete FinalDiscrete, out ITypeName FinalTypeName, out ICompiledType FinalType, out bool InheritBySideAttribute)) { return(false); } } IResultException ResolvedException = new ResultException(); foreach (IArgument Item in node.ArgumentList) { ResultException.Merge(ResolvedException, Item.ResolvedException.Item); } ResultException.Merge(ResolvedException, SelectedOverload.ExceptionIdentifierList); data = new Tuple <IResultException, ICommandOverloadType, IFeatureCall, ITypeName, ICompiledType>(ResolvedException, SelectedOverload, FeatureCall, CreatedObjectTypeName, CreatedObjectType); 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(IPrecursorInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IClass EmbeddingClass = node.EmbeddingClass; IClassType BaseType = EmbeddingClass.ResolvedClassType.Item; ISealableDictionary <IFeatureName, IFeatureInstance> FeatureTable = EmbeddingClass.FeatureTable; IFeature InnerFeature = node.EmbeddingFeature; if (InnerFeature is IIndexerFeature AsIndexerFeature) { AddSourceError(new ErrorPrecursorNotAllowedInIndexer(node)); return(false); } else { IFeature AsNamedFeature = InnerFeature; IFeatureInstance Instance = FeatureTable[AsNamedFeature.ValidFeatureName.Item]; OnceReference <IFeatureInstance> SelectedPrecursor = new OnceReference <IFeatureInstance>(); IList <IPrecursorInstance> PrecursorList = Instance.PrecursorList; if (node.AncestorType.IsAssigned) { IObjectType DeclaredAncestor = (IObjectType)node.AncestorType.Item; if (DeclaredAncestor.ResolvedType.Item is IClassType AsClassTypeAncestor) { foreach (IPrecursorInstance Item in PrecursorList) { if (Item.Ancestor.BaseClass == AsClassTypeAncestor.BaseClass) { SelectedPrecursor.Item = Item.Precursor; break; } } } if (!SelectedPrecursor.IsAssigned) { AddSourceError(new ErrorInvalidPrecursor(DeclaredAncestor)); return(false); } } else if (Instance.PrecursorList.Count > 1) { AddSourceError(new ErrorInvalidPrecursor(node)); return(false); } else if (Instance.PrecursorList.Count == 0) { AddSourceError(new ErrorNoPrecursor(node)); return(false); } else { SelectedPrecursor.Item = Instance.PrecursorList[0].Precursor; } List <IExpressionType> MergedArgumentList = new List <IExpressionType>(); if (!Argument.Validate(node.ArgumentList, MergedArgumentList, out TypeArgumentStyles TypeArgumentStyle, ErrorList)) { return(false); } IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >(); ICompiledFeature OperatorFeature = SelectedPrecursor.Item.Feature; ICompiledType OperatorType = OperatorFeature.ResolvedAgentType.Item; IList <IIdentifier> PrecursorInstructionException = null; ISealableList <IParameter> SelectedParameterList = null; // This has been checked in the type pass. IProcedureType AsProcedureType = OperatorType as IProcedureType; Debug.Assert(AsProcedureType != null); foreach (ICommandOverloadType Overload in AsProcedureType.OverloadList) { ParameterTableList.Add(Overload.ParameterTable); } if (!Argument.ArgumentsConformToParameters(ParameterTableList, MergedArgumentList, TypeArgumentStyle, ErrorList, node, out int SelectedIndex)) { return(false); } ICommandOverloadType SelectedOverload = AsProcedureType.OverloadList[SelectedIndex]; PrecursorInstructionException = SelectedOverload.ExceptionIdentifierList; SelectedParameterList = SelectedOverload.ParameterTable; IResultException ResolvedException = new ResultException(); foreach (IArgument Item in node.ArgumentList) { ResultException.Merge(ResolvedException, Item.ResolvedException.Item); } ResultException.Merge(ResolvedException, PrecursorInstructionException); IFeatureCall FeatureCall = new FeatureCall(SelectedParameterList, new List <IParameter>(), node.ArgumentList, MergedArgumentList, TypeArgumentStyle); data = new Tuple <IResultException, IFeatureCall>(ResolvedException, FeatureCall); } 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(IAttachmentInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IExpression SourceExpression = (IExpression)node.Source; IResultType SourceResult = SourceExpression.ResolvedResult.Item; IClass EmbeddingClass = node.EmbeddingClass; int MaxAttachmentCount = 0; foreach (IAttachment AttachmentItem in node.AttachmentList) { if (AttachmentItem.AttachTypeList.Count > SourceResult.Count) { AddSourceError(new ErrorInvalidAttachment(AttachmentItem)); return(false); } else if (MaxAttachmentCount < AttachmentItem.AttachTypeList.Count) { MaxAttachmentCount = AttachmentItem.AttachTypeList.Count; } } for (int i = 0; i < node.AttachmentList.Count; i++) { IAttachment Attachment = node.AttachmentList[i]; bool ConformanceError = true; for (int j = 0; j < MaxAttachmentCount; j++) { if (j < Attachment.AttachTypeList.Count) { ICompiledType SourceType = SourceResult.At(j).ValueType; IObjectType AttachType = Attachment.AttachTypeList[j]; ICompiledType DestinationType = AttachType.ResolvedType.Item; if (!ObjectType.TypesHaveCommonDescendant(EmbeddingClass, DestinationType, SourceType)) { AddSourceError(new ErrorInvalidAttachment(Attachment)); return(false); } else { ConformanceError &= CheckConsistencyTyped(node, i, j, DestinationType); } } } if (ConformanceError) { AddSourceError(new ErrorInvalidAttachment(Attachment)); return(false); } } if (Success) { IResultException ResolvedException = new ResultException(); ResultException.Merge(ResolvedException, SourceExpression.ResolvedException.Item); foreach (IAttachment Item in node.AttachmentList) { ResultException.Merge(ResolvedException, Item.ResolvedException.Item); } if (node.ElseInstructions.IsAssigned) { IScope ElseInstructions = (IScope)node.ElseInstructions.Item; ResultException.Merge(ResolvedException, ElseInstructions.ResolvedException.Item); } data = ResolvedException; } 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(ICommandInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IQualifiedName Command = (IQualifiedName)node.Command; IList <IIdentifier> ValidPath = Command.ValidPath.Item; IClass EmbeddingClass = node.EmbeddingClass; IClassType BaseType = EmbeddingClass.ResolvedClassType.Item; ISealableDictionary <string, IScopeAttributeFeature> LocalScope = Scope.CurrentScope(node); if (!ObjectType.GetQualifiedPathFinalType(EmbeddingClass, BaseType, LocalScope, ValidPath, 0, ErrorList, out ICompiledFeature FinalFeature, out IDiscrete FinalDiscrete, out ITypeName FinalTypeName, out ICompiledType FinalType, out bool InheritBySideAttribute)) { return(false); } Debug.Assert(FinalFeature != null); IList <IArgument> ArgumentList = node.ArgumentList; List <IExpressionType> MergedArgumentList = new List <IExpressionType>(); if (!Argument.Validate(ArgumentList, MergedArgumentList, out TypeArgumentStyles ArgumentStyle, ErrorList)) { return(false); } IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >(); ICommandOverloadType SelectedOverload = null; ISealableList <IParameter> SelectedParameterList = null; IProcedureType CommandFinalType = null; bool IsHandled = false; switch (FinalType) { case IFunctionType AsFunctionType: case IPropertyType AsPropertyType: AddSourceError(new ErrorInvalidInstruction(node)); Success = false; IsHandled = true; break; case IProcedureType AsProcedureType: foreach (ICommandOverloadType Overload in AsProcedureType.OverloadList) { ParameterTableList.Add(Overload.ParameterTable); } int SelectedIndex; if (!Argument.ArgumentsConformToParameters(ParameterTableList, MergedArgumentList, ArgumentStyle, ErrorList, node, out SelectedIndex)) { Success = false; } else { SelectedOverload = AsProcedureType.OverloadList[SelectedIndex]; SelectedParameterList = ParameterTableList[SelectedIndex]; CommandFinalType = AsProcedureType; } IsHandled = true; break; } Debug.Assert(IsHandled); if (Success) { ObjectType.FillResultPath(EmbeddingClass, BaseType, LocalScope, ValidPath, 0, Command.ValidResultTypePath.Item); IResultException ResolvedException = new ResultException(); foreach (IArgument Item in node.ArgumentList) { ResultException.Merge(ResolvedException, Item.ResolvedException.Item); } IList <IIdentifier> CommandInstructionException = SelectedOverload.ExceptionIdentifierList; ResultException.Merge(ResolvedException, CommandInstructionException); IFeatureCall FeatureCall = new FeatureCall(SelectedParameterList, new List <IParameter>(), ArgumentList, MergedArgumentList, ArgumentStyle); data = new Tuple <IResultException, ICompiledFeature, ICommandOverloadType, IFeatureCall, IProcedureType>(ResolvedException, FinalFeature, SelectedOverload, FeatureCall, CommandFinalType); } 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(IIndexAssignmentInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data) { data = null; bool Success = true; IQualifiedName Destination = (IQualifiedName)node.Destination; IExpression Source = (IExpression)node.Source; IList <IIdentifier> ValidPath = Destination.ValidPath.Item; IClass EmbeddingClass = node.EmbeddingClass; IClassType BaseType = EmbeddingClass.ResolvedClassType.Item; ISealableDictionary <string, IScopeAttributeFeature> LocalScope = Scope.CurrentScope(node); if (!ObjectType.GetQualifiedPathFinalType(EmbeddingClass, BaseType, LocalScope, ValidPath, 0, ErrorList, out ICompiledFeature FinalFeature, out IDiscrete FinalDiscrete, out ITypeName FinalTypeName, out ICompiledType FinalType, out bool InheritBySideAttribute)) { return(false); } Debug.Assert(FinalFeature != null); FinalType = FinalFeature.ResolvedEffectiveType.Item; if (FinalType is IClassType AsClassType) { IClass IndexedBaseClass = AsClassType.BaseClass; ISealableDictionary <IFeatureName, IFeatureInstance> IndexedFeatureTable = IndexedBaseClass.FeatureTable; if (!IndexedFeatureTable.ContainsKey(FeatureName.IndexerFeatureName)) { AddSourceError(new ErrorMissingIndexer(node)); return(false); } IFeatureInstance IndexerInstance = IndexedFeatureTable[FeatureName.IndexerFeatureName]; IIndexerFeature Indexer = (IndexerFeature)IndexerInstance.Feature; IIndexerType AsIndexerType = (IndexerType)Indexer.ResolvedAgentType.Item; bool IsReadOnlyIndexer = Indexer.GetterBody.IsAssigned && !Indexer.SetterBody.IsAssigned; bool IsReadOnlyIndexerType = AsIndexerType.IndexerKind == BaseNode.UtilityType.ReadOnly; Debug.Assert(IsReadOnlyIndexerType == IsReadOnlyIndexer); if (IsReadOnlyIndexer) { AddSourceError(new ErrorInvalidInstruction(node)); return(false); } else { IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >(); ParameterTableList.Add(AsIndexerType.ParameterTable); IList <ISealableList <IParameter> > ResultTableList = new List <ISealableList <IParameter> >(); ResultTableList.Add(new SealableList <IParameter>()); ICompiledType DestinationType = AsIndexerType.ResolvedEntityType.Item; if (!Argument.CheckAssignmentConformance(ParameterTableList, ResultTableList, node.ArgumentList, Source, DestinationType, ErrorList, node, out IFeatureCall FeatureCall)) { return(false); } ObjectType.FillResultPath(EmbeddingClass, BaseType, LocalScope, ValidPath, 0, Destination.ValidResultTypePath.Item); IResultException ResolvedException = new ResultException(); ResultException.Merge(ResolvedException, AsIndexerType.SetExceptionIdentifierList); foreach (IArgument Item in node.ArgumentList) { ResultException.Merge(ResolvedException, Item.ResolvedException.Item); } data = new Tuple <IResultException, IFeatureCall>(ResolvedException, FeatureCall); } } else { AddSourceError(new ErrorInvalidInstruction(node)); return(false); } return(Success); }