Exemple #1
0
        /// <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(IEntityDeclaration node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            bool Success = true;

            data = null;

            IName  EntityName     = (IName)node.EntityName;
            string ValidText      = EntityName.ValidText.Item;
            IClass EmbeddingClass = node.EmbeddingClass;

            IObjectType   FieldType     = (IObjectType)node.EntityType;
            ITypeName     ValidTypeName = FieldType.ResolvedTypeName.Item;
            ICompiledType ValidType     = FieldType.ResolvedType.Item;

            IScopeAttributeFeature NewEntity;

            if (node.DefaultValue.IsAssigned)
            {
                Success = ScopeAttributeFeature.Create(node, ValidText, FieldType.ResolvedTypeName.Item, FieldType.ResolvedType.Item, (IExpression)node.DefaultValue.Item, ErrorList, out NewEntity);
            }
            else
            {
                NewEntity = ScopeAttributeFeature.Create(node, ValidText, FieldType.ResolvedTypeName.Item, FieldType.ResolvedType.Item);
            }

            if (Success)
            {
                data = NewEntity;
            }

            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(IConstantFeature node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            data = null;
            bool Success = true;

            IName       EntityName     = (IName)((IFeatureWithName)node).EntityName;
            IObjectType TypeToResolve  = (IObjectType)node.EntityType;
            IClass      EmbeddingClass = node.EmbeddingClass;

            if (TypeToResolve.ResolvedType.Item is IClassType AsClassType)
            {
                if (AsClassType.BaseClass.Cloneable == BaseNode.CloneableStatus.Single)
                {
                    AddSourceError(new ErrorSingleTypeNotAllowed(node, EntityName.ValidText.Item));
                    Success = false;
                }
            }

            if (Success)
            {
                IScopeAttributeFeature NewEntity = ScopeAttributeFeature.CreateResultFeature(TypeToResolve, EmbeddingClass, node);
                data = NewEntity;
            }

            return(Success);
        }
Exemple #3
0
        /// <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(IAttributeFeature node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            IObjectType TypeToResolve  = (IObjectType)node.EntityType;
            IClass      EmbeddingClass = node.EmbeddingClass;

            IScopeAttributeFeature ResultFeature = ScopeAttributeFeature.CreateResultFeature(TypeToResolve, EmbeddingClass, node);

            data = ResultFeature;

            return(true);
        }
Exemple #4
0
        /// <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(IIndexerFeature node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            data = null;
            bool Success = true;

            IClass      EmbeddingClass = node.EmbeddingClass;
            IObjectType TypeToResolve  = (IObjectType)node.EntityType;

            IScopeAttributeFeature ResultFeature = ScopeAttributeFeature.CreateResultFeature(TypeToResolve, EmbeddingClass, node);
            IScopeAttributeFeature ValueFeature  = ScopeAttributeFeature.CreateValueFeature(TypeToResolve, EmbeddingClass, node);

            Success = CheckResultValueConsistency(node, dataList, ResultFeature, ValueFeature, out data);

            return(Success);
        }
Exemple #5
0
        /// <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);
        }
Exemple #6
0
        /// <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);
        }
Exemple #7
0
        /// <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);
        }