/// <summary>
        /// Sets the <see cref="ICSharpOutputNode.WriteDown"/> flag.
        /// </summary>
        public override void SetWriteDown()
        {
            if (WriteDown)
            {
                return;
            }

            WriteDown = true;

            FeatureCall.SetWriteDown();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the <see cref="ICSharpOutputNode.WriteDown"/> flag.
        /// </summary>
        public override void SetWriteDown()
        {
            if (WriteDown)
            {
                return;
            }

            WriteDown = true;

            RightExpression.SetWriteDown();
            FeatureCall.SetWriteDown();
        }
        /// <summary>
        /// Sets the <see cref="ICSharpOutputNode.WriteDown"/> flag.
        /// </summary>
        public override void SetWriteDown()
        {
            if (WriteDown)
            {
                return;
            }

            WriteDown = true;

            if (Feature != null)
            {
                Feature.SetWriteDown();
                FeatureCall.SetWriteDown();
            }

            if (Discrete != null)
            {
                Discrete.SetWriteDown();
            }
        }
        /// <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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Checks for errors before applying a rule.
        /// </summary>
        /// <param name="node">The node instance to check.</param>
        /// <param name="dataList">Optional data collected during inspection of sources.</param>
        /// <param name="data">Private data to give to Apply() upon return.</param>
        /// <returns>True if an error occured.</returns>
        public override bool CheckConsistency(IPrecursorInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            data = null;
            bool Success = true;

            IClass     EmbeddingClass = node.EmbeddingClass;
            IClassType BaseType       = EmbeddingClass.ResolvedClassType.Item;
            ISealableDictionary <IFeatureName, IFeatureInstance> FeatureTable = EmbeddingClass.FeatureTable;
            IFeature InnerFeature = node.EmbeddingFeature;

            if (InnerFeature is IIndexerFeature AsIndexerFeature)
            {
                AddSourceError(new ErrorPrecursorNotAllowedInIndexer(node));
                return(false);
            }
            else
            {
                IFeature         AsNamedFeature = InnerFeature;
                IFeatureInstance Instance       = FeatureTable[AsNamedFeature.ValidFeatureName.Item];
                OnceReference <IFeatureInstance> SelectedPrecursor = new OnceReference <IFeatureInstance>();
                IList <IPrecursorInstance>       PrecursorList     = Instance.PrecursorList;

                if (node.AncestorType.IsAssigned)
                {
                    IObjectType DeclaredAncestor = (IObjectType)node.AncestorType.Item;

                    if (DeclaredAncestor.ResolvedType.Item is IClassType AsClassTypeAncestor)
                    {
                        foreach (IPrecursorInstance Item in PrecursorList)
                        {
                            if (Item.Ancestor.BaseClass == AsClassTypeAncestor.BaseClass)
                            {
                                SelectedPrecursor.Item = Item.Precursor;
                                break;
                            }
                        }
                    }

                    if (!SelectedPrecursor.IsAssigned)
                    {
                        AddSourceError(new ErrorInvalidPrecursor(DeclaredAncestor));
                        return(false);
                    }
                }
                else if (Instance.PrecursorList.Count > 1)
                {
                    AddSourceError(new ErrorInvalidPrecursor(node));
                    return(false);
                }
                else if (Instance.PrecursorList.Count == 0)
                {
                    AddSourceError(new ErrorNoPrecursor(node));
                    return(false);
                }
                else
                {
                    SelectedPrecursor.Item = Instance.PrecursorList[0].Precursor;
                }

                List <IExpressionType> MergedArgumentList = new List <IExpressionType>();
                if (!Argument.Validate(node.ArgumentList, MergedArgumentList, out TypeArgumentStyles TypeArgumentStyle, ErrorList))
                {
                    return(false);
                }

                IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >();

                ICompiledFeature           OperatorFeature = SelectedPrecursor.Item.Feature;
                ICompiledType              OperatorType    = OperatorFeature.ResolvedAgentType.Item;
                IList <IIdentifier>        PrecursorInstructionException = null;
                ISealableList <IParameter> SelectedParameterList         = null;

                // This has been checked in the type pass.
                IProcedureType AsProcedureType = OperatorType as IProcedureType;
                Debug.Assert(AsProcedureType != null);
                foreach (ICommandOverloadType Overload in AsProcedureType.OverloadList)
                {
                    ParameterTableList.Add(Overload.ParameterTable);
                }

                if (!Argument.ArgumentsConformToParameters(ParameterTableList, MergedArgumentList, TypeArgumentStyle, ErrorList, node, out int SelectedIndex))
                {
                    return(false);
                }

                ICommandOverloadType SelectedOverload = AsProcedureType.OverloadList[SelectedIndex];
                PrecursorInstructionException = SelectedOverload.ExceptionIdentifierList;
                SelectedParameterList         = SelectedOverload.ParameterTable;

                IResultException ResolvedException = new ResultException();

                foreach (IArgument Item in node.ArgumentList)
                {
                    ResultException.Merge(ResolvedException, Item.ResolvedException.Item);
                }

                ResultException.Merge(ResolvedException, PrecursorInstructionException);

                IFeatureCall FeatureCall = new FeatureCall(SelectedParameterList, new List <IParameter>(), node.ArgumentList, MergedArgumentList, TypeArgumentStyle);

                data = new Tuple <IResultException, IFeatureCall>(ResolvedException, FeatureCall);
            }

            return(Success);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Checks for errors before applying a rule.
        /// </summary>
        /// <param name="node">The node instance to check.</param>
        /// <param name="dataList">Optional data collected during inspection of sources.</param>
        /// <param name="data">Private data to give to Apply() upon return.</param>
        /// <returns>True if an error occured.</returns>
        public override bool CheckConsistency(ICommandInstruction node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            data = null;
            bool Success = true;

            IQualifiedName      Command   = (IQualifiedName)node.Command;
            IList <IIdentifier> ValidPath = Command.ValidPath.Item;
            IClass     EmbeddingClass     = node.EmbeddingClass;
            IClassType BaseType           = EmbeddingClass.ResolvedClassType.Item;

            ISealableDictionary <string, IScopeAttributeFeature> LocalScope = Scope.CurrentScope(node);

            if (!ObjectType.GetQualifiedPathFinalType(EmbeddingClass, BaseType, LocalScope, ValidPath, 0, ErrorList, out ICompiledFeature FinalFeature, out IDiscrete FinalDiscrete, out ITypeName FinalTypeName, out ICompiledType FinalType, out bool InheritBySideAttribute))
            {
                return(false);
            }

            Debug.Assert(FinalFeature != null);

            IList <IArgument>      ArgumentList       = node.ArgumentList;
            List <IExpressionType> MergedArgumentList = new List <IExpressionType>();

            if (!Argument.Validate(ArgumentList, MergedArgumentList, out TypeArgumentStyles ArgumentStyle, ErrorList))
            {
                return(false);
            }

            IList <ISealableList <IParameter> > ParameterTableList = new List <ISealableList <IParameter> >();
            ICommandOverloadType       SelectedOverload            = null;
            ISealableList <IParameter> SelectedParameterList       = null;
            IProcedureType             CommandFinalType            = null;
            bool IsHandled = false;

            switch (FinalType)
            {
            case IFunctionType AsFunctionType:
            case IPropertyType AsPropertyType:
                AddSourceError(new ErrorInvalidInstruction(node));
                Success   = false;
                IsHandled = true;
                break;

            case IProcedureType AsProcedureType:
                foreach (ICommandOverloadType Overload in AsProcedureType.OverloadList)
                {
                    ParameterTableList.Add(Overload.ParameterTable);
                }

                int SelectedIndex;
                if (!Argument.ArgumentsConformToParameters(ParameterTableList, MergedArgumentList, ArgumentStyle, ErrorList, node, out SelectedIndex))
                {
                    Success = false;
                }
                else
                {
                    SelectedOverload      = AsProcedureType.OverloadList[SelectedIndex];
                    SelectedParameterList = ParameterTableList[SelectedIndex];
                    CommandFinalType      = AsProcedureType;
                }
                IsHandled = true;
                break;
            }

            Debug.Assert(IsHandled);

            if (Success)
            {
                ObjectType.FillResultPath(EmbeddingClass, BaseType, LocalScope, ValidPath, 0, Command.ValidResultTypePath.Item);

                IResultException ResolvedException = new ResultException();

                foreach (IArgument Item in node.ArgumentList)
                {
                    ResultException.Merge(ResolvedException, Item.ResolvedException.Item);
                }

                IList <IIdentifier> CommandInstructionException = SelectedOverload.ExceptionIdentifierList;
                ResultException.Merge(ResolvedException, CommandInstructionException);

                IFeatureCall FeatureCall = new FeatureCall(SelectedParameterList, new List <IParameter>(), ArgumentList, MergedArgumentList, ArgumentStyle);

                data = new Tuple <IResultException, ICompiledFeature, ICommandOverloadType, IFeatureCall, IProcedureType>(ResolvedException, FinalFeature, SelectedOverload, FeatureCall, CommandFinalType);
            }

            return(Success);
        }