private ISealableDictionary <IFeatureName, IIdentifier> MergeExportClassIdentifiers(IClass node, IExport export, ISealableDictionary <IFeatureName, ISealableDictionary <string, IClass> > mergedExportTable, ref bool success)
        {
            IList <string> ListedClassList = new List <string>();
            ISealableDictionary <IFeatureName, IIdentifier> ListedExportList = new SealableDictionary <IFeatureName, IIdentifier>();

            for (int i = 0; i < export.ClassIdentifierList.Count; i++)
            {
                IIdentifier Identifier = export.ClassIdentifierList[i];

                Debug.Assert(Identifier.ValidText.IsAssigned);
                string ValidText = Identifier.ValidText.Item;

                if (ValidText.ToUpperInvariant() == LanguageClasses.Any.Name.ToUpperInvariant())
                {
                    ListedClassList.Add(LanguageClasses.Any.Name);
                }
                else if (node.ImportedClassTable.ContainsKey(ValidText))
                {
                    ListedClassList.Add(ValidText);
                }
                else if (FeatureName.TableContain(mergedExportTable, ValidText, out IFeatureName Key, out ISealableDictionary <string, IClass> Item))
                {
                    if (ListedExportList.ContainsKey(Key))
                    {
                        AddSourceError(new ErrorIdentifierAlreadyListed(Identifier, ValidText));
                        success = false;
                    }
                    else
                    {
                        ListedExportList.Add(Key, Identifier);
                    }
                }
        /// <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(IDiscrete node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            bool Success = true;

            data = null;

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

            if (FeatureName.TableContain(EmbeddingClass.LocalExportTable, ValidText, out Key, out ISealableDictionary <string, IClass> ExportTable))
            {
                AddSourceError(new ErrorDuplicateName(EntityName, ValidText));
                Success = false;
            }
            else if (FeatureName.TableContain(EmbeddingClass.LocalTypedefTable, ValidText, out Key, out ITypedefType TypedefType))
            {
                AddSourceError(new ErrorDuplicateName(EntityName, ValidText));
                Success = false;
            }
            else if (FeatureName.TableContain(EmbeddingClass.LocalDiscreteTable, ValidText, out Key, out IDiscrete Discrete))
            {
                AddSourceError(new ErrorDuplicateName(EntityName, ValidText));
                Success = false;
            }
            else if (FeatureName.TableContain(EmbeddingClass.LocalFeatureTable, ValidText, out Key, out IFeatureInstance FeatureInstance))
            {
                AddSourceError(new ErrorDuplicateName(EntityName, ValidText));
                Success = false;
            }

            return(Success);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Applies the rule.
        /// </summary>
        /// <param name="node">The node instance to modify.</param>
        /// <param name="data">Private data from CheckConsistency().</param>
        public override void Apply(ITypedef node, object data)
        {
            IObjectType DefinedTypeItem = (IObjectType)node.DefinedType;

            ITypeName     DefinedTypeName = DefinedTypeItem.ResolvedTypeName.Item;
            ICompiledType DefinedType     = DefinedTypeItem.ResolvedType.Item;

            node.ResolvedDefinedTypeName.Item = DefinedTypeName;
            node.ResolvedDefinedType.Item     = DefinedType;

            if (!DefinedType.OriginatingTypedef.IsAssigned)
            {
                DefinedType.OriginatingTypedef.Item = node;
            }

            IName  EntityName     = (IName)node.EntityName;
            IClass EmbeddingClass = node.EmbeddingClass;

            Debug.Assert(EntityName.ValidText.IsAssigned);
            string ValidText = EntityName.ValidText.Item;

            bool IsFound = FeatureName.TableContain(EmbeddingClass.LocalTypedefTable, ValidText, out IFeatureName Key, out ITypedefType ResolvedTypedefType);

            Debug.Assert(IsFound && ResolvedTypedefType != null);

            ResolvedTypedefType.ReferencedTypeName.Item = DefinedTypeName;
            ResolvedTypedefType.ReferencedType.Item     = DefinedType;

#if COVERAGE
            string TypeString = ResolvedTypedefType.ToString();
#endif
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the export status of a feature in the class that implements it.
        /// </summary>
        /// <param name="sourceClass">The class implementing the feature.</param>
        public virtual CSharpExports GetExportStatus(ICSharpClass sourceClass)
        {
            bool IsExportedToClient;

            IFeature AsFeature = Source as IFeature;

            Debug.Assert(AsFeature != null);

            IIdentifier Identifier       = (IIdentifier)AsFeature.ExportIdentifier;
            string      ExportIdentifier = Identifier.ValidText.Item;

            if (ExportIdentifier == "All")
            {
                IsExportedToClient = true;
            }

            else if (ExportIdentifier == "None" || ExportIdentifier == "Self")
            {
                IsExportedToClient = false;
            }

            else
            {
                FeatureName.TableContain(Owner.Source.ExportTable, ExportIdentifier, out IFeatureName ExportName, out ISealableDictionary <string, IClass> ExportList);
                Debug.Assert(ExportList.Count > 0);

                if (ExportList.Count > 1)
                {
                    IsExportedToClient = true;
                }
                else
                {
                    if (ExportList.ContainsKey(sourceClass.ValidClassName))
                    {
                        IsExportedToClient = false; // Export to self = self + descendant = protected
                    }
                    else
                    {
                        IsExportedToClient = true; // export to another = export to all = public
                    }
                }
            }

            if (IsExportedToClient)
            {
                return(CSharpExports.Public);
            }

            else if (AsFeature.Export == BaseNode.ExportStatus.Exported)
            {
                return(CSharpExports.Protected);
            }
            else
            {
                return(CSharpExports.Private);
            }
        }
Exemplo n.º 5
0
        private static CSharpExports GetExportStatus(IFeatureName name, IClass sourceClass, ISealableDictionary <IFeatureName, ISealableDictionary <string, IClass> > exportTable, IFeature sourceFeature)
        {
            bool IsExportedToClient;

            string FeatureExport = sourceFeature.ExportIdentifier.Text;

            if (FeatureExport == "All")
            {
                IsExportedToClient = true;
            }

            else if (FeatureExport == "None" || FeatureExport == "Self")
            {
                IsExportedToClient = false;
            }

            else
            {
                bool IsExported = FeatureName.TableContain(exportTable, FeatureExport, out IFeatureName ExportName, out ISealableDictionary <string, IClass> ExportList);
                Debug.Assert(IsExported);
                Debug.Assert(ExportList.Count > 0);

                if (ExportList.Count > 1)
                {
                    IsExportedToClient = true;
                }
                else
                {
                    if (ExportList.ContainsKey(sourceClass.ValidClassName))
                    {
                        IsExportedToClient = false; // Export to self = self + descendant = protected
                    }
                    else
                    {
                        IsExportedToClient = true; // export to another = export to all = public
                    }
                }
            }

            if (IsExportedToClient)
            {
                return(CSharpExports.Public);
            }

            else if (sourceFeature.Export == BaseNode.ExportStatus.Exported)
            {
                return(CSharpExports.Protected);
            }
            else
            {
                return(CSharpExports.Private);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Applies the rule.
        /// </summary>
        /// <param name="node">The node instance to modify.</param>
        /// <param name="data">Private data from CheckConsistency().</param>
        public override void Apply(TFeature node, object data)
        {
            IClass EmbeddingClass = node.EmbeddingClass;
            IName  EntityName     = (IName)node.EntityName;

            Debug.Assert(EntityName.ValidText.IsAssigned);
            string ValidText = EntityName.ValidText.Item;

            IFeatureName     FeatureEntityName = new FeatureName(ValidText);
            IFeatureInstance NewInstance       = new FeatureInstance(EmbeddingClass, node);

            node.ValidFeatureName.Item = FeatureEntityName;
            EmbeddingClass.LocalFeatureTable.Add(FeatureEntityName, NewInstance);
        }
        /// <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(IExport node, object data)
        {
            IClass EmbeddingClass = node.EmbeddingClass;
            IName  EntityName     = (IName)node.EntityName;

            Debug.Assert(EntityName.ValidText.IsAssigned);
            string ValidText = EntityName.ValidText.Item;

            IFeatureName ExportEntityName = new FeatureName(ValidText);
            ISealableDictionary <string, IClass> EmptyClassTable = new SealableDictionary <string, IClass>();

            Debug.Assert(!EmbeddingClass.LocalExportTable.IsSealed);
            EmbeddingClass.LocalExportTable.Add(ExportEntityName, EmptyClassTable);
            node.ValidExportName.Item = ExportEntityName;
        }
Exemplo n.º 8
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(IRaiseEventInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            data = null;
            bool Success = true;

            IIdentifier QueryIdentifier = (IIdentifier)node.QueryIdentifier;
            string      ValidText       = QueryIdentifier.ValidText.Item;
            IClass      EmbeddingClass  = node.EmbeddingClass;
            IClassType  BaseType        = EmbeddingClass.ResolvedClassType.Item;

            if (!FeatureName.TableContain(EmbeddingClass.FeatureTable, ValidText, out IFeatureName Key, out IFeatureInstance Instance))
            {
                AddSourceError(new ErrorUnknownIdentifier(QueryIdentifier, ValidText));
                Success = false;
            }
        /// <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(IDiscrete node, object data)
        {
            IClass EmbeddingClass = node.EmbeddingClass;
            IName  EntityName     = (IName)node.EntityName;
            string ValidText      = EntityName.ValidText.Item;

            IFeatureName DiscreteEntityName = new FeatureName(ValidText);

            EmbeddingClass.LocalDiscreteTable.Add(DiscreteEntityName, node);
            node.ValidDiscreteName.Item = DiscreteEntityName;

            if (node.NumericValue.IsAssigned)
            {
                EmbeddingClass.NodeWithDefaultList.Add((IExpression)node.NumericValue.Item);
                EmbeddingClass.NodeWithNumberConstantList.Add((IExpression)node.NumericValue.Item);
            }
        }
Exemplo n.º 10
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(IExport node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            bool Success = true;

            data = null;

            IClass EmbeddingClass = node.EmbeddingClass;
            IName  EntityName     = (IName)node.EntityName;

            Debug.Assert(EntityName.ValidText.IsAssigned);
            string ValidText = EntityName.ValidText.Item;

            IFeatureName Key;

            if (EmbeddingClass.ImportedClassTable.ContainsKey(ValidText))
            {
                AddSourceError(new ErrorDuplicateName(EntityName, ValidText));
                Success = false;
            }
            else if (FeatureName.TableContain(EmbeddingClass.LocalExportTable, ValidText, out Key, out ISealableDictionary <string, IClass> ExportTable))
            {
                AddSourceError(new ErrorDuplicateName(EntityName, ValidText));
                Success = false;
            }
            else if (FeatureName.TableContain(EmbeddingClass.LocalTypedefTable, ValidText, out Key, out ITypedefType TypedefType))
            {
                AddSourceError(new ErrorDuplicateName(EntityName, ValidText));
                Success = false;
            }
            else if (FeatureName.TableContain(EmbeddingClass.LocalDiscreteTable, ValidText, out Key, out IDiscrete Discrete))
            {
                AddSourceError(new ErrorDuplicateName(EntityName, ValidText));
                Success = false;
            }
            else if (FeatureName.TableContain(EmbeddingClass.LocalFeatureTable, ValidText, out Key, out IFeatureInstance FeatureInstance))
            {
                AddSourceError(new ErrorDuplicateName(EntityName, ValidText));
                Success = false;
            }

            // Ensured since the root is valid.
            Debug.Assert(node.ClassIdentifierList.Count > 0);

            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(ITypedef node, object data)
        {
            IName  EntityName     = (IName)node.EntityName;
            IClass EmbeddingClass = node.EmbeddingClass;

            Debug.Assert(EntityName.ValidText.IsAssigned);
            string ValidText = EntityName.ValidText.Item;

            IFeatureName ResolvedTypedefTypeName = new FeatureName(ValidText);
            ITypedefType ResolvedTypedefType     = new TypedefType();

            EmbeddingClass.LocalTypedefTable.Add(ResolvedTypedefTypeName, ResolvedTypedefType);
            node.ValidTypedefName.Item = ResolvedTypedefTypeName;

#if COVERAGE
            string NameString = ResolvedTypedefTypeName.ToString();
            string TypeString = ResolvedTypedefType.ToString();
#endif
        }
Exemplo n.º 12
0
        /// <summary>
        /// Checks if an intermediate step in a path to a target type is resolved.
        /// </summary>
        /// <param name="item">The current step.</param>
        /// <param name="nextItem">The step after <paramref name="item"/>.</param>
        /// <param name="localEntityList">The list of available local variables.</param>
        /// <param name="featureTable">The feature table to use.</param>
        /// <param name="errorList">The list of errors found.</param>
        /// <param name="isInterrupted">Set if an error is found.</param>
        /// <returns>False to stop; True to continue with the next step.</returns>
        public static bool IsPathItemReady(IIdentifier item, IIdentifier nextItem, ref List <IEntityDeclaration> localEntityList, ref ISealableDictionary <IFeatureName, IFeatureInstance> featureTable, IErrorList errorList, ref bool isInterrupted)
        {
            Debug.Assert(featureTable.IsSealed);
            Debug.Assert(item.ValidText.IsAssigned);

            string Text      = item.ValidText.Item;
            bool   IsLocal   = IsLocalEntity(Text, localEntityList, out IEntityDeclaration Entity);
            bool   IsFeature = FeatureName.TableContain(featureTable, Text, out IFeatureName ItemName, out IFeatureInstance ItemInstance);

            // Check that the name is known in the table of features for the current step.
            if (!IsLocal && !IsFeature)
            {
                errorList.AddError(new ErrorUnknownIdentifier(item, Text));
                isInterrupted = true;
                return(false);
            }

            bool          IsReady  = false;
            ICompiledType ItemType = null;

            if (IsLocal)
            {
                IsReady  = Entity.ValidEntity.IsAssigned && Entity.ValidEntity.Item.ResolvedEffectiveType.IsAssigned;
                ItemType = IsReady ? Entity.ValidEntity.Item.ResolvedEffectiveType.Item : null;
            }
            else
            {
                ICompiledFeature ItemFeature = ItemInstance.Feature;
                IsReady = IsPathGlobalItemReady(ItemFeature, nextItem, errorList, ref isInterrupted, out ItemType);
            }

            if (IsReady)
            {
                Debug.Assert(ItemType != null);
                featureTable = ItemType.FeatureTable;

                IsReady = featureTable.IsSealed;
            }

            return(IsReady);
        }
        /// <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(IClass node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            bool Success = true;

            data = null;

            IList <IIdentifier> ConversionList = node.ConversionList;
            ISealableDictionary <IFeatureName, IFeatureInstance> FeatureTable        = node.FeatureTable;
            ISealableDictionary <IFeatureName, ICreationFeature> ConversionFromTable = new SealableDictionary <IFeatureName, ICreationFeature>();
            ISealableDictionary <IFeatureName, IFunctionFeature> ConversionToTable   = new SealableDictionary <IFeatureName, IFunctionFeature>();

            foreach (IIdentifier Identifier in ConversionList)
            {
                Debug.Assert(Identifier.ValidText.IsAssigned);
                string ValidText = Identifier.ValidText.Item;

                if (!FeatureName.TableContain(FeatureTable, ValidText, out IFeatureName Key, out IFeatureInstance Instance))
                {
                    AddSourceError(new ErrorUnknownIdentifier(Identifier, ValidText));
                    Success = false;
                }
Exemplo n.º 14
0
        private static bool CheckRename(ICSharpClass cSharpClass, IErrorList errorList)
        {
            bool Result = true;

            foreach (IInheritance InheritanceItem in cSharpClass.Source.InheritanceList)
            {
                IClassType ParentType  = InheritanceItem.ResolvedClassParentType.Item;
                IClass     ParentClass = ParentType.BaseClass;

                bool BadRename = false;
                foreach (IRename RenameItem in InheritanceItem.RenameList)
                {
                    string ValidSourceText = RenameItem.ValidSourceText.Item;

                    if (!FeatureName.TableContain(ParentClass.FeatureTable, ValidSourceText, out IFeatureName Key, out IFeatureInstance Instance))
                    {
                        BadRename = true;
                        break;
                    }

                    IClass           SourceClass   = Instance.Owner;
                    ICompiledFeature SourceFeature = Instance.Feature;
                    CSharpExports    ExportStatus  = GetExportStatus(Key, SourceClass, cSharpClass.Source.ExportTable, (IFeature)SourceFeature);
                    if (ExportStatus == CSharpExports.Public && !(SourceFeature is ICreationFeature))
                    {
                        BadRename = true;
                        break;
                    }
                }

                if (BadRename)
                {
                    errorList.AddError(new ErrorInvalidRename(InheritanceItem));
                }

                Result &= !BadRename;
            }

            return(Result);
        }
        private bool GetCreatedEntity(ICreateInstruction node, out ITypeName attributeTypeName, out ICompiledType attributeType)
        {
            attributeTypeName = null;
            attributeType     = null;
            bool Success = false;

            IIdentifier EntityIdentifier = (IIdentifier)node.EntityIdentifier;
            string      ValidText        = EntityIdentifier.ValidText.Item;
            IClass      EmbeddingClass   = node.EmbeddingClass;
            IClassType  BaseType         = EmbeddingClass.ResolvedClassType.Item;
            ISealableDictionary <string, IScopeAttributeFeature> LocalScope = Scope.CurrentScope(node);

            if (LocalScope.ContainsKey(ValidText))
            {
                IScopeAttributeFeature CreatedFeature = LocalScope[ValidText];
                attributeTypeName = CreatedFeature.ResolvedEffectiveTypeName.Item;
                attributeType     = CreatedFeature.ResolvedEffectiveType.Item;
                Success           = true;
            }
            else if (FeatureName.TableContain(EmbeddingClass.FeatureTable, ValidText, out IFeatureName Key, out IFeatureInstance Instance))
            {
                if (Instance.Feature is IAttributeFeature AsAttributeFeature)
                {
                    attributeTypeName = AsAttributeFeature.ResolvedEntityTypeName.Item;
                    attributeType     = AsAttributeFeature.ResolvedEntityType.Item;
                    Success           = true;
                }
                else if (Instance.Feature is IPropertyFeature AsPropertyFeature)
                {
                    attributeTypeName = AsPropertyFeature.ResolvedEntityTypeName.Item;
                    attributeType     = AsPropertyFeature.ResolvedEntityType.Item;
                    Success           = true;
                }
                else
                {
                    AddSourceError(new ErrorCreatedFeatureNotAttributeOrProperty(EntityIdentifier, ValidText));
                }
            }
        private bool IsTypeReady(ISimpleType node, out object data)
        {
            data = null;
            bool IsReady = true;

            ITypeName     ValidTypeName = null;
            ICompiledType ValidType     = null;
            IError        Error         = null;

            IClass   EmbeddingClass   = node.EmbeddingClass;
            IFeature EmbeddingFeature = node.EmbeddingFeature;

            IIdentifier ClassIdentifier = (IIdentifier)node.ClassIdentifier;

            Debug.Assert(ClassIdentifier.ValidText.IsAssigned);
            string ValidIdentifier = ClassIdentifier.ValidText.Item;

            ISealableDictionary <string, IImportedClass> ImportedClassTable = EmbeddingClass.ImportedClassTable;
            ISealableDictionary <string, ICompiledType>  LocalGenericTable  = EmbeddingClass.LocalGenericTable;
            ISealableDictionary <IFeatureName, ISealableDictionary <string, IClass> > LocalExportTable = EmbeddingClass.LocalExportTable;
            ISealableDictionary <IFeatureName, ITypedefType>     LocalTypedefTable  = EmbeddingClass.LocalTypedefTable;
            ISealableDictionary <IFeatureName, IDiscrete>        LocalDiscreteTable = EmbeddingClass.LocalDiscreteTable;
            ISealableDictionary <IFeatureName, IFeatureInstance> LocalFeatureTable  = EmbeddingClass.LocalFeatureTable;

            IsReady &= ImportedClassTable.IsSealed;
            IsReady &= LocalGenericTable.IsSealed;
            IsReady &= LocalExportTable.IsSealed;
            IsReady &= LocalTypedefTable.IsSealed;
            IsReady &= LocalDiscreteTable.IsSealed;
            IsReady &= LocalFeatureTable.IsSealed;
            IsReady &= EmbeddingClass.ResolvedClassType.IsAssigned;

            if (IsReady)
            {
                if (ValidIdentifier.ToUpperInvariant() == LanguageClasses.Any.Name.ToUpperInvariant())
                {
                    GetBaseClassType(Class.ClassAny, out ValidTypeName, out ValidType);
                }
                else if (ValidIdentifier.ToUpperInvariant() == LanguageClasses.AnyReference.Name.ToUpperInvariant())
                {
                    GetBaseClassType(Class.ClassAnyReference, out ValidTypeName, out ValidType);
                }
                else if (ValidIdentifier.ToUpperInvariant() == LanguageClasses.AnyValue.Name.ToUpperInvariant())
                {
                    GetBaseClassType(Class.ClassAnyValue, out ValidTypeName, out ValidType);
                }
                else if (ImportedClassTable.ContainsKey(ValidIdentifier))
                {
                    IImportedClass Imported  = ImportedClassTable[ValidIdentifier];
                    IClass         BaseClass = Imported.Item;
                    IsReady = CheckValidityAsClass(BaseClass, out ValidTypeName, out ValidType, out bool IsInvalidGeneric);

                    if (IsInvalidGeneric)
                    {
                        Error = new ErrorGenericClass(ClassIdentifier, ValidIdentifier);
                    }
                }
                else if (LocalGenericTable.ContainsKey(ValidIdentifier))
                {
                    IFormalGenericType FormalGeneric = (IFormalGenericType)LocalGenericTable[ValidIdentifier];
                    GetGenericType(FormalGeneric, out ValidTypeName, out ValidType);
                }
                else if (FeatureName.TableContain(LocalTypedefTable, ValidIdentifier, out IFeatureName Key, out ITypedefType DefinedType))
                {
                    IsReady = CheckValidityAsTypedef(DefinedType, out ValidTypeName, out ValidType);
                }
                else
                {
                    Error = new ErrorUnknownIdentifier(ClassIdentifier, ValidIdentifier);
                }
            }
        /// <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(ITypedef node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            bool Success = true;

            data = null;

            IClass       EmbeddingClass = node.EmbeddingClass;
            IName        EntityName     = (IName)node.EntityName;
            IFeatureName Key;

            Debug.Assert(EntityName.ValidText.IsAssigned);
            string ValidText = EntityName.ValidText.Item;

            if (EmbeddingClass.ImportedClassTable.ContainsKey(ValidText))
            {
                AddSourceError(new ErrorDuplicateName(EntityName, ValidText));
                Success = false;
            }
            else if (EmbeddingClass.LocalGenericTable.ContainsKey(ValidText))
            {
                AddSourceError(new ErrorDuplicateName(EntityName, ValidText));
                Success = false;
            }
            else if (FeatureName.TableContain(EmbeddingClass.LocalExportTable, ValidText, out Key, out ISealableDictionary <string, IClass> Export))
            {
                AddSourceError(new ErrorDuplicateName(EntityName, ValidText));
                Success = false;
            }
            else if (FeatureName.TableContain(EmbeddingClass.LocalTypedefTable, ValidText, out Key, out ITypedefType TypedefType))
            {
                AddSourceError(new ErrorDuplicateName(EntityName, ValidText));
                Success = false;
            }
            else
            {
                // This is checked in the corresponding step of a discrete rule.
                bool IsDiscreteName = FeatureName.TableContain(EmbeddingClass.LocalDiscreteTable, ValidText, out Key, out IDiscrete Discrete);
                Debug.Assert(!IsDiscreteName);

                // This is checked in the corresponding step of a feature rule.
                bool IsFeatureName = FeatureName.TableContain(EmbeddingClass.LocalFeatureTable, ValidText, out Key, out IFeatureInstance Feature);
                Debug.Assert(!IsFeatureName);
            }

            if (node.DefinedType is IAnchoredType AsAnchoredType)
            {
                AddSourceError(new ErrorInvalidAnchoredType(AsAnchoredType));
                Success = false;
            }
            else if (node.DefinedType is IKeywordAnchoredType AsKeywordAnchoredType)
            {
                bool IsAllowed;
                switch (AsKeywordAnchoredType.Anchor)
                {
                case BaseNode.Keyword.True:
                case BaseNode.Keyword.False:
                case BaseNode.Keyword.Retry:
                case BaseNode.Keyword.Exception:
                    IsAllowed = true;
                    break;

                default:
                    IsAllowed = false;
                    break;
                }

                if (!IsAllowed)
                {
                    AddSourceError(new ErrorInvalidAnchoredType(AsKeywordAnchoredType));
                    Success = 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(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);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Checks if the last step in a path to a target type is resolved.
        /// </summary>
        /// <param name="item">The last step.</param>
        /// <param name="localEntityList">The list of available local variables.</param>
        /// <param name="featureTable">The feature table to use.</param>
        /// <param name="errorList">The list of errors found.</param>
        /// <param name="isInterrupted">Set if an error is found.</param>
        /// <param name="resolvedPathTypeName">The target type name upon return.</param>
        /// <param name="resolvedPathType">The target type upon return.</param>
        /// <returns>True if the path step could be resolved, or an error was found.</returns>
        public static bool IsLastPathItemReady(IIdentifier item, List <IEntityDeclaration> localEntityList, ISealableDictionary <IFeatureName, IFeatureInstance> featureTable, IErrorList errorList, ref bool isInterrupted, out ITypeName resolvedPathTypeName, out ICompiledType resolvedPathType)
        {
            Debug.Assert(featureTable.IsSealed);
            Debug.Assert(item.ValidText.IsAssigned);

            resolvedPathTypeName = null;
            resolvedPathType     = null;

            string Text      = item.ValidText.Item;
            bool   IsLocal   = IsLocalEntity(Text, localEntityList, out IEntityDeclaration Entity);
            bool   IsFeature = FeatureName.TableContain(featureTable, Text, out IFeatureName ItemName, out IFeatureInstance ItemInstance);

            // Check that the name is known in the table of features for the current step.
            if (!IsLocal && !IsFeature)
            {
                errorList.AddError(new ErrorUnknownIdentifier(item, Text));
                isInterrupted = true;
                return(false);
            }

            bool Result = false;

            if (IsLocal)
            {
                if (Entity.ValidEntity.IsAssigned && Entity.ValidEntity.Item.ResolvedEffectiveType.IsAssigned)
                {
                    resolvedPathTypeName = Entity.ValidEntity.Item.ResolvedEffectiveTypeName.Item;
                    resolvedPathType     = Entity.ValidEntity.Item.ResolvedEffectiveType.Item;
                    Result = true;
                }
            }
            else
            {
                ICompiledFeature ItemFeature = ItemInstance.Feature;
                bool             IsHandled   = false;

                switch (ItemFeature)
                {
                case IAttributeFeature AsAttributeFeature:
                    Result    = IsAttributeFeatureReady(AsAttributeFeature, out resolvedPathTypeName, out resolvedPathType);
                    IsHandled = true;
                    break;

                case IConstantFeature AsConstantFeature:
                    Result    = IsConstantFeatureReady(AsConstantFeature, out resolvedPathTypeName, out resolvedPathType);
                    IsHandled = true;
                    break;

                case ICreationFeature AsCreationFeature:
                case IProcedureFeature AsProcedureFeature:
                    errorList.AddError(new ErrorNotAnchor(item, Text));
                    isInterrupted = true;
                    return(false);

                case IFunctionFeature AsFunctionFeature:
                    Result    = IsFunctionFeatureReady(AsFunctionFeature, out resolvedPathTypeName, out resolvedPathType);
                    IsHandled = true;
                    break;

                case IPropertyFeature AsPropertyFeature:
                    Result    = IsPropertyFeatureReady(AsPropertyFeature, out resolvedPathTypeName, out resolvedPathType);
                    IsHandled = true;
                    break;

                case IIndexerFeature AsIndexerFeature:
                    Result    = IsIndexerFeatureReady(AsIndexerFeature, out resolvedPathTypeName, out resolvedPathType);
                    IsHandled = true;
                    break;
                }

                Debug.Assert(IsHandled);
            }

            return(Result);
        }