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

            // This list has been verified during the node tree check.
            Debug.Assert(node.DestinationList.Count > 0);

            IExpression SourceExpression = (IExpression)node.Source;
            IResultType SourceResult     = SourceExpression.ResolvedResult.Item;

            if (node.DestinationList.Count > SourceResult.Count)
            {
                AddSourceError(new ErrorAssignmentMismatch(node));
                Success = false;
            }
            else
            {
                IClass     EmbeddingClass = node.EmbeddingClass;
                IClassType BaseType       = EmbeddingClass.ResolvedClassType.Item;
                ISealableDictionary <IQualifiedName, ICompiledFeature> FinalFeatureTable = new SealableDictionary <IQualifiedName, ICompiledFeature>();

                for (int i = 0; i < node.DestinationList.Count; i++)
                {
                    IQualifiedName      Destination = (QualifiedName)node.DestinationList[i];
                    IList <IIdentifier> ValidPath   = Destination.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))
                    {
                        Success = false;
                    }
        /// <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(ITupleType node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            bool Success = true;

            data = null;

            ISealableDictionary <string, IScopeAttributeFeature> FieldTable = new SealableDictionary <string, IScopeAttributeFeature>();

            foreach (IEntityDeclaration Item in node.EntityDeclarationList)
            {
                IName FieldName = (IName)Item.EntityName;

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

                IScopeAttributeFeature FieldAttribute = Item.ValidEntity.Item;

                if (FieldTable.ContainsKey(ValidText))
                {
                    AddSourceError(new ErrorDuplicateName(FieldName, ValidText));
                    Success = false;
                }
                else
                {
                    FieldTable.Add(ValidText, FieldAttribute);
                }
            }

            if (Success)
            {
                data = FieldTable;
            }

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

            data = null;

            ISealableDictionary <string, IIdentifier> IdentifierTable = new SealableDictionary <string, IIdentifier>();

            foreach (IIdentifier Item in node.IdentifierList)
            {
                Debug.Assert(Item.ValidText.IsAssigned);
                string ValidText = Item.ValidText.Item;

                if (IdentifierTable.ContainsKey(ValidText))
                {
                    AddSourceError(new ErrorDuplicateName(Item, ValidText));
                    Success = false;
                }
                else
                {
                    IdentifierTable.Add(ValidText, Item);
                }
            }

            if (Success)
            {
                data = IdentifierTable;
            }

            return(Success);
        }
        /// <summary>
        /// Reset some intermediate results.
        /// </summary>
        /// <param name="ruleTemplateList">The list of rule templates that would read the properties to reset.</param>
        public void Reset(IRuleTemplateList ruleTemplateList)
        {
            bool IsHandled = false;

            if (ruleTemplateList == RuleTemplateSet.Identifiers)
            {
                IsHandled = true;
            }
            else if (ruleTemplateList == RuleTemplateSet.Types)
            {
                LocalScope  = new SealableDictionary <string, IScopeAttributeFeature>();
                InnerScopes = new List <IScopeHolder>();
                FullScope   = new SealableDictionary <string, IScopeAttributeFeature>();
                IsHandled   = true;
            }
            else if (ruleTemplateList == RuleTemplateSet.Contract)
            {
                AdditionalScope = new SealableDictionary <string, IScopeAttributeFeature>();
                AdditionalScope.Seal();
                ResolvedResult = new OnceReference <IResultType>();
                IsHandled      = true;
            }
            else if (ruleTemplateList == RuleTemplateSet.Body)
            {
                ResolvedType      = new OnceReference <ICompiledType>();
                ResolvedException = new OnceReference <IResultException>();
                FeatureCall       = new OnceReference <IFeatureCall>();
                IsHandled         = true;
            }

            Debug.Assert(IsHandled);
        }
        /// <summary>
        /// Reset some intermediate results.
        /// </summary>
        /// <param name="ruleTemplateList">The list of rule templates that would read the properties to reset.</param>
        public void Reset(IRuleTemplateList ruleTemplateList)
        {
            bool IsHandled = false;

            if (ruleTemplateList == RuleTemplateSet.Identifiers || ruleTemplateList == RuleTemplateSet.Contract || ruleTemplateList == RuleTemplateSet.Body)
            {
                IsHandled = true;
            }
            else if (ruleTemplateList == RuleTemplateSet.Types)
            {
                ResolvedBaseTypeName   = new OnceReference <ITypeName>();
                ResolvedBaseType       = new OnceReference <IClassType>();
                ResolvedEntityTypeName = new OnceReference <ITypeName>();
                ResolvedEntityType     = new OnceReference <ICompiledType>();
                ParameterTable         = new SealableList <IParameter>();
                ResolvedTypeName       = new OnceReference <ITypeName>();
                ResolvedType           = new OnceReference <ICompiledType>();
                DiscreteTable          = new SealableDictionary <IFeatureName, IDiscrete>();
                FeatureTable           = new SealableDictionary <IFeatureName, IFeatureInstance>();
                ExportTable            = new SealableDictionary <IFeatureName, ISealableDictionary <string, IClass> >();
                ConformanceTable       = new SealableDictionary <ITypeName, ICompiledType>();
                InstancingRecordList   = new List <TypeInstancingRecord>();
                OriginatingTypedef     = new OnceReference <ITypedef>();
                IsHandled = true;
            }

            Debug.Assert(IsHandled);
        }
        private bool ResolveClassTypeRenames(IClassType classType, IConstraint node, out ITypeName destinationTypeName, out ICompiledType destinationType)
        {
            bool Success = false;

            destinationType     = null;
            destinationTypeName = null;

            IClass EmbeddingClass = node.EmbeddingClass;
            ISealableDictionary <string, string> SourceIdentifierTable      = new SealableDictionary <string, string>(); // string (source) -> string (destination)
            ISealableDictionary <string, string> DestinationIdentifierTable = new SealableDictionary <string, string>(); // string (destination) -> string (source)
            ISealableDictionary <IFeatureName, ISealableDictionary <string, IClass> > RenamedExportTable = classType.ExportTable.CloneUnsealed();
            ISealableDictionary <IFeatureName, ITypedefType>     RenamedTypedefTable  = classType.TypedefTable.CloneUnsealed();
            ISealableDictionary <IFeatureName, IDiscrete>        RenamedDiscreteTable = classType.DiscreteTable.CloneUnsealed();
            ISealableDictionary <IFeatureName, IFeatureInstance> RenamedFeatureTable  = classType.FeatureTable.CloneUnsealed();

            bool AllRenameValid = true;

            foreach (KeyValuePair <IIdentifier, IIdentifier> Entry in node.RenameTable)
            {
                if (!CheckRename(Entry, new IDictionaryIndex <IFeatureName>[] { RenamedExportTable, RenamedTypedefTable, RenamedDiscreteTable, RenamedFeatureTable }, SourceIdentifierTable, DestinationIdentifierTable, (IFeatureName item) => item.Name, (string name) => new FeatureName(name)))
                {
                    AllRenameValid = false;
                }
            }

            if (AllRenameValid)
            {
                IClassType ClonedType = classType.CloneWithRenames(RenamedExportTable, RenamedTypedefTable, RenamedDiscreteTable, RenamedFeatureTable, EmbeddingClass.ResolvedClassType.Item);
                destinationType     = ClonedType;
                destinationTypeName = new TypeName(destinationType.TypeFriendlyName);
                Success             = true;
            }

            return(Success);
        }
        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>
        /// Creates a <see cref="ClassType"/>.
        /// </summary>
        /// <param name="baseClass">The class used to instanciate this type.</param>
        /// <param name="typeArgumentTable">Arguments if the class is generic.</param>
        /// <param name="instancingClassType">The class type if this instance is a derivation (such as renaming).</param>
        public static IClassType Create(IClass baseClass, ISealableDictionary <string, ICompiledType> typeArgumentTable, ICompiledTypeWithFeature instancingClassType)
        {
            ISealableDictionary <ITypeName, ICompiledType> ConformanceTable = new SealableDictionary <ITypeName, ICompiledType>();

            if (baseClass.ResolvedClassType.IsAssigned)
            {
                IClassType ResolvedClassType = baseClass.ResolvedClassType.Item;

                if (ResolvedClassType.ConformanceTable.IsSealed)
                {
                    foreach (IInheritance InheritanceItem in baseClass.InheritanceList)
                    {
                        if (InheritanceItem.Conformance == BaseNode.ConformanceType.Conformant)
                        {
                            ITypeName     ParentTypeName = InheritanceItem.ResolvedParentTypeName.Item;
                            ICompiledType ParentType     = InheritanceItem.ResolvedParentType.Item;
                            ParentType.InstanciateType(instancingClassType, ref ParentTypeName, ref ParentType);
                            ConformanceTable.Add(ParentTypeName, ParentType);
                        }
                    }

                    ConformanceTable.Seal();
                }
            }

            IClassType ClassType = new ClassType(baseClass, typeArgumentTable, instancingClassType, ConformanceTable);

            return(ClassType);
        }
        /// <summary>
        /// Reset some intermediate results.
        /// </summary>
        /// <param name="ruleTemplateList">The list of rule templates that would read the properties to reset.</param>
        public void Reset(IRuleTemplateList ruleTemplateList)
        {
            bool IsHandled = false;

            if (ruleTemplateList == RuleTemplateSet.Identifiers || ruleTemplateList == RuleTemplateSet.Types)
            {
                IsHandled = true;
            }
            else if (ruleTemplateList == RuleTemplateSet.Contract)
            {
                ResolvedTagTable                = new SealableDictionary <string, IExpression>();
                ResolvedResult                  = new OnceReference <IResultType>();
                ResolvedRequireList             = new OnceReference <IList <IAssertion> >();
                ResolvedEnsureList              = new OnceReference <IList <IAssertion> >();
                ResolvedExceptionIdentifierList = new OnceReference <IList <IIdentifier> >();
                IsHandled = true;
            }
            else if (ruleTemplateList == RuleTemplateSet.Body)
            {
                ResolvedInstructionList = new OnceReference <IList <IInstruction> >();
                IsHandled = true;
            }

            Debug.Assert(IsHandled);
        }
        /// <summary>
        /// Creates an instance of a class type, or reuse an existing instance.
        /// </summary>
        /// <param name="instancingClassType">The class type to instanciate.</param>
        /// <param name="resolvedTypeName">The proposed type instance name.</param>
        /// <param name="resolvedType">The proposed type instance.</param>
        public void InstanciateType(ICompiledTypeWithFeature instancingClassType, ref ITypeName resolvedTypeName, ref ICompiledType resolvedType)
        {
            bool IsNewInstance = false;

            ISealableDictionary <string, ICompiledType> InstancedTypeArgumentTable = new SealableDictionary <string, ICompiledType>();

            foreach (KeyValuePair <string, ICompiledType> TypeArgument in TypeArgumentTable)
            {
                ITypeName     InstancedTypeArgumentName = null;
                ICompiledType InstancedTypeArgument     = TypeArgument.Value;
                InstancedTypeArgument.InstanciateType(instancingClassType, ref InstancedTypeArgumentName, ref InstancedTypeArgument);

                InstancedTypeArgumentTable.Add(TypeArgument.Key, InstancedTypeArgument);

                if (InstancedTypeArgument != TypeArgument.Value)
                {
                    IsNewInstance = true;
                }
            }

            if (IsNewInstance)
            {
                ISealableDictionary <ITypeName, ICompiledType> InstancingTypeTable = instancingClassType.GetTypeTable();
                ResolveType(InstancingTypeTable, BaseClass, InstancedTypeArgumentTable, instancingClassType, out resolvedTypeName, out resolvedType);
            }
        }
Exemple #11
0
        /// <summary>
        /// Reset some intermediate results.
        /// </summary>
        /// <param name="ruleTemplateList">The list of rule templates that would read the properties to reset.</param>
        public void Reset(IRuleTemplateList ruleTemplateList)
        {
            bool IsHandled = false;

            if (ruleTemplateList == RuleTemplateSet.Identifiers || ruleTemplateList == RuleTemplateSet.Body)
            {
                IsHandled = true;
            }
            else if (ruleTemplateList == RuleTemplateSet.Types)
            {
                LocalScope             = new SealableDictionary <string, IScopeAttributeFeature>();
                InnerScopes            = new List <IScopeHolder>();
                FullScope              = new SealableDictionary <string, IScopeAttributeFeature>();
                ParameterTable         = new SealableList <IParameter>();
                ResolvedAssociatedType = new OnceReference <ICommandOverloadType>();
                IsHandled              = true;
            }
            else if (ruleTemplateList == RuleTemplateSet.Contract)
            {
                AdditionalScope = new SealableDictionary <string, IScopeAttributeFeature>();
                AdditionalScope.Seal();
                ResolvedBody = new OnceReference <ICompiledBody>();
                IsHandled    = true;
            }

            Debug.Assert(IsHandled);
        }
Exemple #12
0
        /// <summary>
        /// Reset some intermediate results.
        /// </summary>
        /// <param name="ruleTemplateList">The list of rule templates that would read the properties to reset.</param>
        public void Reset(IRuleTemplateList ruleTemplateList)
        {
            bool IsHandled = false;

            if (ruleTemplateList == RuleTemplateSet.Identifiers || ruleTemplateList == RuleTemplateSet.Types)
            {
                IsHandled = true;
            }
            else if (ruleTemplateList == RuleTemplateSet.Contract)
            {
                ResolvedResult        = new OnceReference <IResultType>();
                ConstantSourceList    = new SealableList <IExpression>();
                ExpressionConstant    = new OnceReference <ILanguageConstant>();
                ResolvedClassTypeName = new OnceReference <ITypeName>();
                ResolvedClassType     = new OnceReference <IClassType>();
                AssignedFeatureTable  = new SealableDictionary <string, ICompiledFeature>();
                IsHandled             = true;
            }
            else if (ruleTemplateList == RuleTemplateSet.Body)
            {
                ResolvedException = new OnceReference <IResultException>();
                IsHandled         = true;
            }

            Debug.Assert(IsHandled);
        }
Exemple #13
0
        /// <summary>
        /// Reset some intermediate results.
        /// </summary>
        /// <param name="ruleTemplateList">The list of rule templates that would read the properties to reset.</param>
        public void Reset(IRuleTemplateList ruleTemplateList)
        {
            bool IsHandled = false;

            if (ruleTemplateList == RuleTemplateSet.Identifiers)
            {
                IsHandled = true;
            }
            else if (ruleTemplateList == RuleTemplateSet.Types)
            {
                LocalScope  = new SealableDictionary <string, IScopeAttributeFeature>();
                InnerScopes = new List <IScopeHolder>();
                FullScope   = new SealableDictionary <string, IScopeAttributeFeature>();
                IsHandled   = true;
            }
            else if (ruleTemplateList == RuleTemplateSet.Contract)
            {
                AdditionalScope = new SealableDictionary <string, IScopeAttributeFeature>();
                AdditionalScope.Seal();
                ResolvedTagTable                = new SealableDictionary <string, IExpression>();
                ResolvedResult                  = new OnceReference <IResultType>();
                ResolvedRequireList             = new OnceReference <IList <IAssertion> >();
                ResolvedEnsureList              = new OnceReference <IList <IAssertion> >();
                ResolvedExceptionIdentifierList = new OnceReference <IList <IIdentifier> >();
                IsHandled = true;
            }
            else if (ruleTemplateList == RuleTemplateSet.Body)
            {
                ResolvedInstructionList = new OnceReference <IList <IInstruction> >();
                IsHandled = true;
            }

            Debug.Assert(IsHandled);
        }
        /// <summary>
        /// Reset some intermediate results.
        /// </summary>
        /// <param name="ruleTemplateList">The list of rule templates that would read the properties to reset.</param>
        public void Reset(IRuleTemplateList ruleTemplateList)
        {
            bool IsHandled = false;

            if (ruleTemplateList == RuleTemplateSet.Identifiers)
            {
                IsHandled = true;
            }
            else if (ruleTemplateList == RuleTemplateSet.Types)
            {
                InnerLoopScope = new SealableDictionary <string, IScopeAttributeFeature>();
                LocalScope     = new SealableDictionary <string, IScopeAttributeFeature>();
                InnerScopes    = new List <IScopeHolder>();
                FullScope      = new SealableDictionary <string, IScopeAttributeFeature>();
                IsHandled      = true;
            }
            else if (ruleTemplateList == RuleTemplateSet.Contract)
            {
                AdditionalScope    = new SealableDictionary <string, IScopeAttributeFeature>(); // Don't seal it yet, not until indexers are handled.
                ResolvedResult     = new OnceReference <IResultType>();
                ResolvedInitResult = new OnceReference <IResultType>();
                IsHandled          = true;
            }
            else if (ruleTemplateList == RuleTemplateSet.Body)
            {
                ResolvedException = new OnceReference <IResultException>();
                IsHandled         = true;
            }

            Debug.Assert(IsHandled);
        }
        /// <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>
        /// 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(IInheritance node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            bool Success = true;

            data = null;

            IClassType ParentTypeWithRename = null;
            IClassType ResolvedParent       = node.ResolvedClassParentType.Item;

            ISealableDictionary <string, string> SourceIdentifierTable      = new SealableDictionary <string, string>(); // string (source) -> string (destination)
            ISealableDictionary <string, string> DestinationIdentifierTable = new SealableDictionary <string, string>(); // string (destination) -> string (source)
            ISealableDictionary <IFeatureName, ISealableDictionary <string, IClass> > RenamedExportTable = ResolvedParent.ExportTable.CloneUnsealed();
            ISealableDictionary <IFeatureName, ITypedefType> RenamedTypedefTable  = ResolvedParent.TypedefTable.CloneUnsealed();
            ISealableDictionary <IFeatureName, IDiscrete>    RenamedDiscreteTable = ResolvedParent.DiscreteTable.CloneUnsealed();

            ISealableDictionary <IFeatureName, IFeatureInstance> RenamedFeatureTable = new SealableDictionary <IFeatureName, IFeatureInstance>();

            foreach (KeyValuePair <IFeatureName, IFeatureInstance> Entry in ResolvedParent.FeatureTable)
            {
                IFeatureName     AncestorFeatureName     = Entry.Key;
                IFeatureInstance AncestorFeatureInstance = Entry.Value;

                RenamedFeatureTable.Add(AncestorFeatureName, AncestorFeatureInstance.Clone(ResolvedParent));
            }

            foreach (IRename RenameItem in node.RenameList)
            {
                Success &= RenameItem.CheckGenericRename(new IDictionaryIndex <IFeatureName>[] { RenamedExportTable, RenamedTypedefTable, RenamedDiscreteTable, RenamedFeatureTable }, SourceIdentifierTable, DestinationIdentifierTable, (IFeatureName item) => item.Name, (string name) => new FeatureName(name), ErrorList);
            }

            if (Success)
            {
                Success &= ResolveInstancingAfterRename(node, RenamedExportTable, RenamedTypedefTable, RenamedDiscreteTable, RenamedFeatureTable);
                if (Success)
                {
                    IClass EmbeddingClass = node.EmbeddingClass;

                    ParentTypeWithRename = ClassType.Create(ResolvedParent.BaseClass, ResolvedParent.TypeArgumentTable, EmbeddingClass.ResolvedClassType.Item);
                    ParentTypeWithRename.ExportTable.Merge(RenamedExportTable);
                    ParentTypeWithRename.ExportTable.Seal();
                    ParentTypeWithRename.TypedefTable.Merge(RenamedTypedefTable);
                    ParentTypeWithRename.TypedefTable.Seal();
                    ParentTypeWithRename.DiscreteTable.Merge(RenamedDiscreteTable);
                    ParentTypeWithRename.DiscreteTable.Seal();
                    ParentTypeWithRename.FeatureTable.Merge(RenamedFeatureTable);
                    ParentTypeWithRename.FeatureTable.Seal();
                }
            }

            if (Success)
            {
                data = ParentTypeWithRename;
            }

            return(Success);
        }
Exemple #17
0
        private static bool ValidateAssignmentStyle(IList <IArgument> argumentList, List <IExpressionType> mergedArgumentList, IErrorList errorList)
        {
            ISealableDictionary <string, IArgument> DuplicateNameTable = new SealableDictionary <string, IArgument>();

            for (int i = 0; i < argumentList.Count; i++)
            {
                IAssignmentArgument Argument = argumentList[i] as IAssignmentArgument;
                Debug.Assert(Argument != null);
                IExpression         Source        = (IExpression)Argument.Source;
                IList <IIdentifier> ParameterList = Argument.ParameterList;

                if (ParameterList.Count > 1 && Argument.ResolvedResult.Item.Count == 1)
                {
                    IExpressionType Item = Argument.ResolvedResult.Item.At(0);

                    for (int j = 0; j < ParameterList.Count; j++)
                    {
                        IExpressionType ItemJ = new ExpressionType(Item.ValueTypeName, Item.ValueType, ParameterList[j].ValidText.Item);
                        ItemJ.SetSource(Source, 0);
                        mergedArgumentList.Add(ItemJ);
                    }
                }
                else
                {
                    for (int j = 0; j < Argument.ResolvedResult.Item.Count; j++)
                    {
                        IExpressionType Item = Argument.ResolvedResult.Item.At(j);
                        Item.SetName(ParameterList[j].ValidText.Item);

                        if (mergedArgumentList.Exists((IExpressionType other) => { return(Item.Name == other.Name); }))
                        {
                            if (!DuplicateNameTable.ContainsKey(Item.Name))
                            {
                                DuplicateNameTable.Add(Item.Name, Argument);
                            }
                        }

                        Item.SetSource(Source, j);
                        mergedArgumentList.Add(Item);
                    }
                }
            }

            if (DuplicateNameTable.Count > 0)
            {
                foreach (KeyValuePair <string, IArgument> Entry in DuplicateNameTable)
                {
                    errorList.AddError(new ErrorDuplicateName(Entry.Value, Entry.Key));
                }

                return(false);
            }

            return(true);
        }
        private void MergeInheritedFeatures(IClass item, ISealableDictionary <IFeatureName, InheritedInstanceInfo> byNameTable, out ISealableDictionary <IFeatureName, IFeatureInstance> mergedFeatureTable)
        {
            mergedFeatureTable = new SealableDictionary <IFeatureName, IFeatureInstance>();

            foreach (KeyValuePair <IFeatureName, InheritedInstanceInfo> ImportedEntry in byNameTable)
            {
                IFeatureName          ImportedKey      = ImportedEntry.Key;
                InheritedInstanceInfo ImportedInstance = ImportedEntry.Value;

                IFeatureInstance NewInstance = MergeCreateNewInstance(item, ImportedKey, ImportedInstance, out InstanceNameInfo SelectedInstanceInfo);

                StableReference <IPrecursorInstance> OriginalPrecursor = new StableReference <IPrecursorInstance>();
                IList <IPrecursorInstance>           PrecursorList     = new List <IPrecursorInstance>();
                foreach (InstanceNameInfo Item in ImportedInstance.PrecursorInstanceList)
                {
                    if (Item == SelectedInstanceInfo)
                    {
                        foreach (IPrecursorInstance PrecursorInstance in Item.Instance.PrecursorList)
                        {
                            PrecursorList.Add(PrecursorInstance);
                        }
                    }
                    else
                    {
                        IPrecursorInstance NewPrecursor = new PrecursorInstance(Item.Ancestor, Item.Instance);
                        PrecursorList.Add(NewPrecursor);
                    }

                    if (Item.Instance.OriginalPrecursor.IsAssigned)
                    {
                        OriginalPrecursor.Item = Item.Instance.OriginalPrecursor.Item;
                    }
                }

                if (OriginalPrecursor.IsAssigned)
                {
                    NewInstance.OriginalPrecursor.Item = OriginalPrecursor.Item;
                }
                else if (PrecursorList.Count > 0)
                {
                    NewInstance.OriginalPrecursor.Item = PrecursorList[0];
                }

                Debug.Assert(NewInstance.PrecursorList.Count == 0);
                foreach (IPrecursorInstance PrecursorInstance in PrecursorList)
                {
                    NewInstance.PrecursorList.Add(PrecursorInstance);
                }

                mergedFeatureTable.Add(ImportedKey, NewInstance);
            }
        }
Exemple #19
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(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);
        }
Exemple #20
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(IConstraint node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            bool Success = true;

            data = null;

            ISealableDictionary <IIdentifier, IIdentifier> RenameTable = new SealableDictionary <IIdentifier, IIdentifier>();
            ISealableDictionary <string, string>           SourceToDestinationTable = new SealableDictionary <string, string>();
            ISealableDictionary <string, string>           DestinationToSourceTable = new SealableDictionary <string, string>();

            foreach (IRename Item in node.RenameList)
            {
                IIdentifier SourceIdentifier = (IIdentifier)Item.SourceIdentifier;
                Debug.Assert(SourceIdentifier.ValidText.IsAssigned);
                string ValidSourceIdentifier = SourceIdentifier.ValidText.Item;
                Debug.Assert(Item.ValidSourceText.IsAssigned);
                Debug.Assert(Item.ValidSourceText.Item == ValidSourceIdentifier);

                IIdentifier DestinationIdentifier = (IIdentifier)Item.DestinationIdentifier;
                Debug.Assert(DestinationIdentifier.ValidText.IsAssigned);
                string ValidDestinationIdentifier = DestinationIdentifier.ValidText.Item;
                Debug.Assert(Item.ValidDestinationText.IsAssigned);
                Debug.Assert(Item.ValidDestinationText.Item == ValidDestinationIdentifier);

                if (SourceToDestinationTable.ContainsKey(ValidSourceIdentifier))
                {
                    ErrorList.AddError(new ErrorIdentifierAlreadyListed(SourceIdentifier, ValidSourceIdentifier));
                    Success = false;
                }
                else if (DestinationToSourceTable.ContainsKey(ValidDestinationIdentifier))
                {
                    ErrorList.AddError(new ErrorDoubleRename(Item, DestinationToSourceTable[ValidDestinationIdentifier], ValidDestinationIdentifier));
                    Success = false;
                }
                else
                {
                    SourceToDestinationTable.Add(ValidSourceIdentifier, ValidDestinationIdentifier);
                    DestinationToSourceTable.Add(ValidDestinationIdentifier, ValidSourceIdentifier);
                    RenameTable.Add(SourceIdentifier, DestinationIdentifier);
                }
            }

            if (Success)
            {
                data = RenameTable;
            }

            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(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;
        }
Exemple #22
0
        /// <summary>
        /// Check all rename clauses separately.
        /// </summary>
        /// <param name="importedClassTable">Table of imported classes.</param>
        /// <param name="errorList">List of errors found.</param>
        /// <returns>True if all rename clauses are valid.</returns>
        public virtual bool CheckRenames(ISealableDictionary <string, IImportedClass> importedClassTable, IErrorList errorList)
        {
            ISealableDictionary <string, string> SourceIdentifierTable      = new SealableDictionary <string, string>(); // string (source) -> string (destination)
            ISealableDictionary <string, string> DestinationIdentifierTable = new SealableDictionary <string, string>(); // string (destination) -> string (source)

            bool Success = true;

            foreach (IRename RenameItem in RenameList)
            {
                Success &= RenameItem.CheckGenericRename(new IDictionaryIndex <string>[] { importedClassTable }, SourceIdentifierTable, DestinationIdentifierTable, (string key) => key, (string s) => s, errorList);
            }

            Debug.Assert(Success || !errorList.IsEmpty);
            return(Success);
        }
Exemple #23
0
        /// <summary>
        /// Finds the matching nodes of a <see cref="IInitializedObjectExpression"/>.
        /// </summary>
        /// <param name="node">The agent expression to check.</param>
        /// <param name="errorList">The list of errors found.</param>
        /// <param name="resolvedResult">The expression result types upon return.</param>
        /// <param name="resolvedException">Exceptions the expression can throw upon return.</param>
        /// <param name="constantSourceList">Sources of the constant expression upon return, if any.</param>
        /// <param name="expressionConstant">The expression constant upon return.</param>
        /// <param name="initializedObjectTypeName">The initialized object type name upon return.</param>
        /// <param name="initializedObjectType">The initialized object type upon return.</param>
        /// <param name="assignedFeatureTable">The table of assigned values upon return.</param>
        public static bool ResolveCompilerReferences(IInitializedObjectExpression node, IErrorList errorList, out IResultType resolvedResult, out IResultException resolvedException, out ISealableList <IExpression> constantSourceList, out ILanguageConstant expressionConstant, out ITypeName initializedObjectTypeName, out IClassType initializedObjectType, out ISealableDictionary <string, ICompiledFeature> assignedFeatureTable)
        {
            resolvedResult            = null;
            resolvedException         = null;
            constantSourceList        = new SealableList <IExpression>();
            expressionConstant        = NeutralLanguageConstant.NotConstant;
            initializedObjectTypeName = null;
            initializedObjectType     = null;
            assignedFeatureTable      = new SealableDictionary <string, ICompiledFeature>();

            IIdentifier ClassIdentifier = (IIdentifier)node.ClassIdentifier;
            IList <IAssignmentArgument> AssignmentList = node.AssignmentList;
            IClass EmbeddingClass = node.EmbeddingClass;
            string ValidText      = ClassIdentifier.ValidText.Item;

            if (!EmbeddingClass.ImportedClassTable.ContainsKey(ValidText))
            {
                errorList.AddError(new ErrorUnknownIdentifier(ClassIdentifier, ValidText));
                return(false);
            }

            IClass BaseClass = EmbeddingClass.ImportedClassTable[ValidText].Item;

            Debug.Assert(BaseClass.ResolvedClassTypeName.IsAssigned);
            Debug.Assert(BaseClass.ResolvedClassType.IsAssigned);
            initializedObjectTypeName = BaseClass.ResolvedClassTypeName.Item;
            initializedObjectType     = BaseClass.ResolvedClassType.Item;

            if (!CheckAssignemntList(node, errorList, BaseClass.FeatureTable, constantSourceList, assignedFeatureTable))
            {
                return(false);
            }

            resolvedResult = new ResultType(initializedObjectTypeName, initializedObjectType, string.Empty);

            if (!ResolveObjectInitialization(node, errorList, assignedFeatureTable))
            {
                return(false);
            }

            resolvedException = new ResultException();

#if COVERAGE
            Debug.Assert(!node.IsComplex);
#endif

            return(true);
        }
Exemple #24
0
        /// <summary>
        /// Reset some intermediate results.
        /// </summary>
        /// <param name="ruleTemplateList">The list of rule templates that would read the properties to reset.</param>
        public void Reset(IRuleTemplateList ruleTemplateList)
        {
            bool IsHandled = false;

            if (ruleTemplateList == RuleTemplateSet.Identifiers)
            {
                IdentifierTable       = new SealableDictionary <string, IIdentifier>();
                ValidExportIdentifier = new OnceReference <string>();
                IsHandled             = true;
            }
            else if (ruleTemplateList == RuleTemplateSet.Types || ruleTemplateList == RuleTemplateSet.Contract || ruleTemplateList == RuleTemplateSet.Body)
            {
                IsHandled = true;
            }

            Debug.Assert(IsHandled);
        }
        /// <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(TBody node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            data = null;
            bool Success = true;

            ISealableDictionary <string, IExpression> ContractTable = new SealableDictionary <string, IExpression>();

            Success &= CheckTagConflict(ContractTable, node.RequireList);
            Success &= CheckTagConflict(ContractTable, node.EnsureList);

            if (Success)
            {
                data = ContractTable;
            }

            return(Success);
        }
Exemple #26
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);
        }
        /// <summary>
        /// Reset some intermediate results.
        /// </summary>
        /// <param name="ruleTemplateList">The list of rule templates that would read the properties to reset.</param>
        public void Reset(IRuleTemplateList ruleTemplateList)
        {
            bool IsHandled = false;

            if (ruleTemplateList == RuleTemplateSet.Identifiers)
            {
                IsHandled = true;
            }
            else if (ruleTemplateList == RuleTemplateSet.Types)
            {
                ResolvedAgentTypeName     = new OnceReference <ITypeName>();
                ResolvedAgentType         = new OnceReference <ICompiledType>();
                ResolvedEffectiveTypeName = new OnceReference <ITypeName>();
                ResolvedEffectiveType     = new OnceReference <ICompiledType>();
                ValidFeatureName          = new OnceReference <IFeatureName>();
                ResolvedFeature           = new OnceReference <ICompiledFeature>();
                ResolvedEntityTypeName    = new OnceReference <ITypeName>();
                ResolvedEntityType        = new OnceReference <ICompiledType>();
                ParameterTable            = new SealableList <IParameter>();
                LocalScope     = new SealableDictionary <string, IScopeAttributeFeature>();
                LocalGetScope  = new SealableDictionary <string, IScopeAttributeFeature>();
                LocalSetScope  = new SealableDictionary <string, IScopeAttributeFeature>();
                InnerScopes    = new List <IScopeHolder>();
                InnerGetScopes = new List <IScopeHolder>();
                InnerSetScopes = new List <IScopeHolder>();
                FullScope      = new SealableDictionary <string, IScopeAttributeFeature>();
                FullGetScope   = new SealableDictionary <string, IScopeAttributeFeature>();
                FullSetScope   = new SealableDictionary <string, IScopeAttributeFeature>();
                IsHandled      = true;
            }
            else if (ruleTemplateList == RuleTemplateSet.Contract)
            {
                AdditionalScope = new SealableDictionary <string, IScopeAttributeFeature>();
                AdditionalScope.Seal();
                IsHandled = true;
            }
            else if (ruleTemplateList == RuleTemplateSet.Body)
            {
                IsCallingPrecursor = false;
                IsHandled          = true;
            }

            Debug.Assert(IsHandled);
        }
        private bool ResolveIdentifierList(IList <IIdentifier> identifierList, out ISealableDictionary <string, IIdentifier> resultTable)
        {
            resultTable = new SealableDictionary <string, IIdentifier>();

            foreach (IIdentifier IdentifierItem in identifierList)
            {
                string ValidText = IdentifierItem.ValidText.Item;

                if (resultTable.ContainsKey(ValidText))
                {
                    AddSourceError(new ErrorIdentifierAlreadyListed(IdentifierItem, ValidText));
                    return(false);
                }

                resultTable.Add(ValidText, IdentifierItem);
            }

            return(true);
        }
        private void SortByFeatureAndByName(IList <AncestorFeatureInfo> featureTableList, out ISealableDictionary <ICompiledFeature, IList <InstanceNameInfo> > byFeatureTable, out ISealableDictionary <IFeatureName, InheritedInstanceInfo> byNameTable)
        {
            byFeatureTable = new SealableDictionary <ICompiledFeature, IList <InstanceNameInfo> >(); // ICompiledFeature -> List of InstanceNameInfo
            byNameTable    = new SealableDictionary <IFeatureName, InheritedInstanceInfo>();         // FeatureName -> InheritedInstanceInfo

            foreach (AncestorFeatureInfo FeatureInfoItem in featureTableList)
            {
                foreach (KeyValuePair <IFeatureName, IFeatureInstance> Entry in FeatureInfoItem.FeatureTable)
                {
                    IFeatureName     Key   = Entry.Key;
                    IFeatureInstance Value = Entry.Value;

                    Debug.Assert(Value.Feature != null);

                    CheckIfFeatureListed(byFeatureTable, FeatureInfoItem, Key, Value);
                    CheckIfFeatureNameListed(byNameTable, FeatureInfoItem, Key, Value);
                }
            }
        }
        private void CheckAllPrecursorSelectedInNameTable(ISealableDictionary <IFeatureName, InheritedInstanceInfo> byNameTable, IList <ISealableDictionary <IFeatureName, IList <ICompiledFeature> > > precursorSetList)
        {
            foreach (KeyValuePair <IFeatureName, InheritedInstanceInfo> Entry in byNameTable)
            {
                IFeatureName          Key   = Entry.Key;
                InheritedInstanceInfo Value = Entry.Value;

                IList <ICompiledFeature> PrecursorList = new List <ICompiledFeature>();
                foreach (InstanceNameInfo PrecursorItem in Value.PrecursorInstanceList)
                {
                    FillPrecursorList(PrecursorList, PrecursorItem.Instance);
                }

                bool FoundInSet = false;
                foreach (ISealableDictionary <IFeatureName, IList <ICompiledFeature> > PrecursorSet in precursorSetList)
                {
                    foreach (KeyValuePair <IFeatureName, IList <ICompiledFeature> > SetMemberEntry in PrecursorSet)
                    {
                        IFeatureName             SetMemberKey           = SetMemberEntry.Key;
                        IList <ICompiledFeature> SetMemberPrecursorList = SetMemberEntry.Value;

                        if (PrecursorListIntersect(PrecursorList, SetMemberPrecursorList))
                        {
                            PrecursorSet.Add(Key, PrecursorList);
                            FoundInSet = true;
                            break;
                        }
                    }
                    if (FoundInSet)
                    {
                        break;
                    }
                }

                if (!FoundInSet)
                {
                    ISealableDictionary <IFeatureName, IList <ICompiledFeature> > NewSet = new SealableDictionary <IFeatureName, IList <ICompiledFeature> >();
                    NewSet.Add(Key, PrecursorList);
                    precursorSetList.Add(NewSet);
                }
            }
        }