/// <summary>
        /// Checks if a node source is ready.
        /// </summary>
        /// <param name="node">The node for which the value is checked.</param>
        /// <param name="data">Optional data returned to the caller.</param>
        public override bool IsReady(TSource node, out object data)
        {
            data = null;
            bool Result = false;

            IOptionalReference OptionalValue = GetSourceObject(node, out bool IsInterrupted);

            if (!IsInterrupted)
            {
                if (OptionalValue.IsAssigned)
                {
                    TRef Value = (TRef)OptionalValue.Item;
                    OnceReference <TValue> Reference = ItemProperty.GetValue(Value) as OnceReference <TValue>;
                    Debug.Assert(Reference != null);
                    if (Reference.IsAssigned)
                    {
                        data   = Reference.Item;
                        Result = true;
                    }
                }
                else
                {
                    Result = true;
                }
            }

            return(Result);
        }
示例#2
0
        /// <summary>
        /// Checks if a node source is ready.
        /// </summary>
        /// <param name="node">The node for which the value is checked.</param>
        /// <param name="data">Optional data returned to the caller.</param>
        public override bool IsReady(TSource node, out object data)
        {
            data = null;
            bool Result = false;

            IOptionalReference OptionalValue = GetSourceObject(node, out bool IsInterrupted);

            if (!IsInterrupted)
            {
                if (OptionalValue.IsAssigned)
                {
                    TRef Value = (TRef)OptionalValue.Item;
                    ISealableDictionary <TKey, TValue> ValueTable = ItemProperty.GetValue(Value) as ISealableDictionary <TKey, TValue>;
                    Debug.Assert(ValueTable != null);
                    if (ValueTable.IsSealed)
                    {
                        data   = ValueTable;
                        Result = true;
                    }
                }
                else
                {
                    Result = true;
                }
            }

            return(Result);
        }
示例#3
0
        /// <summary>
        /// Builds the cell view tree for this view.
        /// </summary>
        /// <param name="context">Context used to build the cell view tree.</param>
        public virtual void BuildRootCellView(IFrameCellViewTreeContext context)
        {
            Debug.Assert(context.StateView == this);

            IOptionalReference Optional = State.Optional;

            Debug.Assert(Optional != null);

            InitCellViewTable(true);

            Debug.Assert(RootCellView == null);

            IFrameCellView CellView;

            if (Optional.IsAssigned)
            {
                IFrameNodeTemplate NodeTemplate = Template as IFrameNodeTemplate;
                Debug.Assert(NodeTemplate != null);

                CellView = NodeTemplate.BuildNodeCells(context);
            }
            else
            {
                IFrameEmptyCellView EmptyCellView = CreateEmptyCellView(this, null);
                ValidateEmptyCellView(context, EmptyCellView);

                CellView = EmptyCellView;
            }

            SetRootCellView(CellView);
            SealCellViewTable();
        }
        private static bool CheckGetterConsistency(ISource source, IOptionalReference <BaseNode.IBody> optionalGetter, IErrorList errorList)
        {
            if (source.EmbeddingBody is IBody AsBody)
            {
                if (optionalGetter.IsAssigned && AsBody == optionalGetter.Item)
                {
                    return(true);
                }
            }

            errorList.AddError(new ErrorResultUsedOutsideGetter(source));
            return(false);
        }
示例#5
0
        /*
         * Two precursor index expressions cannot be compared because it happens only when comparing different features, and there can be only one indexer.
         * public static bool IsExpressionEqual(IPrecursorIndexExpression expression1, IPrecursorIndexExpression expression2)
         * {
         *  bool Result = true;
         *
         *  if (expression1.AncestorType.IsAssigned && expression2.AncestorType.IsAssigned)
         *  {
         *      IObjectType AncestorType1 = (IObjectType)expression1.AncestorType;
         *      IObjectType AncestorType2 = (IObjectType)expression2.AncestorType;
         *
         *      Debug.Assert(AncestorType1.ResolvedType.IsAssigned);
         *      Debug.Assert(AncestorType2.ResolvedType.IsAssigned);
         *
         *      Result &= AncestorType1.ResolvedType.Item == AncestorType2.ResolvedType.Item;
         *  }
         *
         *  Result &= expression1.AncestorType.IsAssigned == expression2.AncestorType.IsAssigned;
         *  Result &= Argument.IsArgumentListEqual(expression1.ArgumentList, expression2.ArgumentList);
         *
         *  return Result;
         * }
         */

        /// <summary>
        /// Finds the matching nodes of a <see cref="IPrecursorIndexExpression"/>.
        /// </summary>
        /// <param name="node">The agent expression to check.</param>
        /// <param name="errorList">The list of errors found.</param>
        /// <param name="resolvedExpression">The result of the search.</param>
        public static bool ResolveCompilerReferences(IPrecursorIndexExpression node, IErrorList errorList, out ResolvedExpression resolvedExpression)
        {
            resolvedExpression = new ResolvedExpression();

            IOptionalReference <BaseNode.IObjectType> AncestorType = node.AncestorType;
            IList <IArgument> ArgumentList   = node.ArgumentList;
            IClass            EmbeddingClass = node.EmbeddingClass;

            ISealableDictionary <string, IImportedClass>         ClassTable   = EmbeddingClass.ImportedClassTable;
            ISealableDictionary <IFeatureName, IFeatureInstance> FeatureTable = EmbeddingClass.FeatureTable;
            IFeature InnerFeature = node.EmbeddingFeature;

            if (InnerFeature is IIndexerFeature AsIndexerFeature)
            {
                IFeatureInstance Instance = FeatureTable[FeatureName.IndexerFeatureName];

                if (!Instance.FindPrecursor(node.AncestorType, errorList, node, out IFeatureInstance SelectedPrecursor))
                {
                    return(false);
                }

                resolvedExpression.SelectedPrecursor = SelectedPrecursor;

                if (!ResolveSelectedPrecursor(node, SelectedPrecursor, errorList, ref resolvedExpression))
                {
                    return(false);
                }
            }
            else
            {
                errorList.AddError(new ErrorIndexPrecursorNotAllowedOutsideIndexer(node));
                return(false);
            }

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

            return(true);
        }
示例#6
0
        /// <summary>
        /// Find the precursor, either the only one or the selected one.
        /// </summary>
        /// <param name="ancestorType">The optionally selected precursor.</param>
        /// <param name="errorList">The list of errors found.</param>
        /// <param name="source">The source to use when reporting errors.</param>
        /// <param name="selectedPrecursor">The selected precursor upon return if successful.</param>
        public bool FindPrecursor(IOptionalReference <BaseNode.IObjectType> ancestorType, IErrorList errorList, ISource source, out IFeatureInstance selectedPrecursor)
        {
            selectedPrecursor = null;

            if (ancestorType.IsAssigned)
            {
                IObjectType AssignedAncestorType = (IObjectType)ancestorType.Item;
                IClassType  Ancestor             = AssignedAncestorType.ResolvedType.Item as IClassType;
                Debug.Assert(Ancestor != null);

                foreach (IPrecursorInstance PrecursorItem in PrecursorList)
                {
                    if (PrecursorItem.Ancestor.BaseClass == Ancestor.BaseClass)
                    {
                        selectedPrecursor = PrecursorItem.Precursor;
                        break;
                    }
                }

                if (selectedPrecursor == null)
                {
                    errorList.AddError(new ErrorInvalidPrecursor(AssignedAncestorType));
                }
            }
            else if (PrecursorList.Count == 0)
            {
                errorList.AddError(new ErrorNoPrecursor(source));
            }
            else if (PrecursorList.Count > 1)
            {
                errorList.AddError(new ErrorInvalidPrecursor(source));
            }
            else
            {
                selectedPrecursor = PrecursorList[0].Precursor;
            }

            return(selectedPrecursor != null);
        }
示例#7
0
        public void Update(Body body)
        {
            switch (body)
            {
            case EffectiveBody AsEffective:
                Documentation             = AsEffective.Documentation;
                RequireBlocks             = AsEffective.RequireBlocks;
                EnsureBlocks              = AsEffective.EnsureBlocks;
                ExceptionIdentifierBlocks = AsEffective.ExceptionIdentifierBlocks;
                EntityDeclarationBlocks   = AsEffective.EntityDeclarationBlocks;
                BodyInstructionBlocks     = AsEffective.BodyInstructionBlocks;
                ExceptionHandlerBlocks    = AsEffective.ExceptionHandlerBlocks;
                break;

            case DeferredBody AsDeferred:
                Documentation             = AsDeferred.Documentation;
                RequireBlocks             = AsDeferred.RequireBlocks;
                EnsureBlocks              = AsDeferred.EnsureBlocks;
                ExceptionIdentifierBlocks = AsDeferred.ExceptionIdentifierBlocks;
                break;

            case ExternBody AsExtern:
                Documentation             = AsExtern.Documentation;
                RequireBlocks             = AsExtern.RequireBlocks;
                EnsureBlocks              = AsExtern.EnsureBlocks;
                ExceptionIdentifierBlocks = AsExtern.ExceptionIdentifierBlocks;
                break;

            case PrecursorBody AsPrecursor:
                Documentation             = AsPrecursor.Documentation;
                RequireBlocks             = AsPrecursor.RequireBlocks;
                EnsureBlocks              = AsPrecursor.EnsureBlocks;
                ExceptionIdentifierBlocks = AsPrecursor.ExceptionIdentifierBlocks;
                AncestorType              = AsPrecursor.AncestorType;
                break;
            }
        }
示例#8
0
        /// <summary></summary>
        protected override void AddNextNodeToCycle(IFocusCyclableNodeState state)
        {
            IFocusInsertionChildNodeIndexList CycleIndexList = state.CycleIndexList;
            INode       ParentNode = state.ParentState.Node;
            IFocusIndex NodeIndex  = state.ParentIndex;

            IDocument Documentation = null;
            IBlockList <IAssertion, Assertion>   RequireBlocks                         = null;
            IBlockList <IAssertion, Assertion>   EnsureBlocks                          = null;
            IBlockList <IIdentifier, Identifier> ExceptionIdentifierBlocks             = null;
            IBlockList <IEntityDeclaration, EntityDeclaration> EntityDeclarationBlocks = null;
            IBlockList <IInstruction, Instruction>             BodyInstructionBlocks   = null;
            IBlockList <IExceptionHandler, ExceptionHandler>   ExceptionHandlerBlocks  = null;
            IOptionalReference <IObjectType> AncestorType = null;

            List <Type> BodyTypeList = new List <Type>()
            {
                typeof(EffectiveBody), typeof(DeferredBody), typeof(ExternBody), typeof(PrecursorBody)
            };

            foreach (IFocusInsertionChildNodeIndex Index in CycleIndexList)
            {
                IBody Body = Index.Node as IBody;
                Debug.Assert(Body != null);

                if (BodyTypeList.Contains(Body.GetType()))
                {
                    BodyTypeList.Remove(Body.GetType());
                }

                switch (Body)
                {
                case IEffectiveBody AsEffective:
                    Documentation             = AsEffective.Documentation;
                    RequireBlocks             = AsEffective.RequireBlocks;
                    EnsureBlocks              = AsEffective.EnsureBlocks;
                    ExceptionIdentifierBlocks = AsEffective.ExceptionIdentifierBlocks;
                    EntityDeclarationBlocks   = AsEffective.EntityDeclarationBlocks;
                    BodyInstructionBlocks     = AsEffective.BodyInstructionBlocks;
                    ExceptionHandlerBlocks    = AsEffective.ExceptionHandlerBlocks;
                    break;

                case IDeferredBody AsDeferred:
                    Documentation             = AsDeferred.Documentation;
                    RequireBlocks             = AsDeferred.RequireBlocks;
                    EnsureBlocks              = AsDeferred.EnsureBlocks;
                    ExceptionIdentifierBlocks = AsDeferred.ExceptionIdentifierBlocks;
                    break;

                case IExternBody AsExtern:
                    Documentation             = AsExtern.Documentation;
                    RequireBlocks             = AsExtern.RequireBlocks;
                    EnsureBlocks              = AsExtern.EnsureBlocks;
                    ExceptionIdentifierBlocks = AsExtern.ExceptionIdentifierBlocks;
                    break;

                case IPrecursorBody AsPrecursor:
                    Documentation             = AsPrecursor.Documentation;
                    RequireBlocks             = AsPrecursor.RequireBlocks;
                    EnsureBlocks              = AsPrecursor.EnsureBlocks;
                    ExceptionIdentifierBlocks = AsPrecursor.ExceptionIdentifierBlocks;
                    AncestorType              = AsPrecursor.AncestorType;
                    break;
                }
            }

            // If the list is full, no need to add more nodes to the cycle.
            if (BodyTypeList.Count > 0)
            {
                Type NodeType = BodyTypeList[0];

                INode NewBody = NodeHelper.CreateInitializedBody(NodeType, Documentation, RequireBlocks, EnsureBlocks, ExceptionIdentifierBlocks, EntityDeclarationBlocks, BodyInstructionBlocks, ExceptionHandlerBlocks, AncestorType);

                IFocusBrowsingInsertableIndex InsertableNodeIndex = NodeIndex as IFocusBrowsingInsertableIndex;
                Debug.Assert(InsertableNodeIndex != null);
                IFocusInsertionChildNodeIndex InsertionIndex = InsertableNodeIndex.ToInsertionIndex(ParentNode, NewBody) as IFocusInsertionChildNodeIndex;
                Debug.Assert(InsertionIndex != null);

                CycleIndexList.Add(InsertionIndex);
            }
        }
        /// <summary></summary>
        protected override void AddNextNodeToCycle(IFocusCyclableNodeState state)
        {
            IFocusInsertionChildNodeIndexList CycleIndexList = state.CycleIndexList;
            INode           ParentNode = state.ParentState.Node;
            IFocusNodeIndex NodeIndex  = state.ParentIndex as IFocusNodeIndex;

            IDocument    Documentation    = null;
            IIdentifier  ExportIdentifier = null;
            ExportStatus Export           = ExportStatus.Exported;
            IName        EntityName       = null;
            IObjectType  EntityType       = null;
            IBlockList <IAssertion, Assertion> EnsureBlocks = null;
            IExpression ConstantValue = null;
            IBlockList <ICommandOverload, CommandOverload> CommandOverloadBlocks = null;
            OnceChoice Once = OnceChoice.Normal;
            IBlockList <IQueryOverload, QueryOverload> QueryOverloadBlocks = null;
            UtilityType PropertyKind = UtilityType.ReadWrite;
            IBlockList <IIdentifier, Identifier> ModifiedQueryBlocks = null;
            IOptionalReference <IBody>           GetterBody          = null;
            IOptionalReference <IBody>           SetterBody          = null;
            IBlockList <IEntityDeclaration, EntityDeclaration> IndexParameterBlocks = null;
            ParameterEndStatus ParameterEnd = ParameterEndStatus.Closed;

            List <Type> FeatureTypeList = new List <Type>()
            {
                typeof(AttributeFeature), typeof(ConstantFeature), typeof(CreationFeature), typeof(FunctionFeature), typeof(ProcedureFeature), typeof(PropertyFeature), typeof(IndexerFeature)
            };

            foreach (IFocusInsertionChildNodeIndex Index in CycleIndexList)
            {
                IFeature Feature = Index.Node as IFeature;
                Debug.Assert(Feature != null);

                if (FeatureTypeList.Contains(Feature.GetType()))
                {
                    FeatureTypeList.Remove(Feature.GetType());
                }

                switch (Feature)
                {
                case IAttributeFeature AsAttribute:
                    Documentation    = AsAttribute.Documentation;
                    ExportIdentifier = AsAttribute.ExportIdentifier;
                    Export           = AsAttribute.Export;
                    EntityName       = AsAttribute.EntityName;
                    EntityType       = AsAttribute.EntityType;
                    EnsureBlocks     = AsAttribute.EnsureBlocks;
                    break;

                case IConstantFeature AsConstant:
                    Documentation    = AsConstant.Documentation;
                    ExportIdentifier = AsConstant.ExportIdentifier;
                    Export           = AsConstant.Export;
                    EntityName       = AsConstant.EntityName;
                    EntityType       = AsConstant.EntityType;
                    ConstantValue    = AsConstant.ConstantValue;
                    break;

                case ICreationFeature AsCreation:
                    Documentation         = AsCreation.Documentation;
                    ExportIdentifier      = AsCreation.ExportIdentifier;
                    Export                = AsCreation.Export;
                    EntityName            = AsCreation.EntityName;
                    CommandOverloadBlocks = AsCreation.OverloadBlocks;
                    break;

                case IFunctionFeature AsFunction:
                    Documentation       = AsFunction.Documentation;
                    ExportIdentifier    = AsFunction.ExportIdentifier;
                    Export              = AsFunction.Export;
                    EntityName          = AsFunction.EntityName;
                    Once                = AsFunction.Once;
                    QueryOverloadBlocks = AsFunction.OverloadBlocks;
                    break;

                case IProcedureFeature AsProcedure:
                    Documentation         = AsProcedure.Documentation;
                    ExportIdentifier      = AsProcedure.ExportIdentifier;
                    Export                = AsProcedure.Export;
                    EntityName            = AsProcedure.EntityName;
                    CommandOverloadBlocks = AsProcedure.OverloadBlocks;
                    break;

                case IPropertyFeature AsProperty:
                    Documentation       = AsProperty.Documentation;
                    ExportIdentifier    = AsProperty.ExportIdentifier;
                    Export              = AsProperty.Export;
                    EntityName          = AsProperty.EntityName;
                    EntityType          = AsProperty.EntityType;
                    PropertyKind        = AsProperty.PropertyKind;
                    ModifiedQueryBlocks = AsProperty.ModifiedQueryBlocks;
                    GetterBody          = AsProperty.GetterBody;
                    SetterBody          = AsProperty.SetterBody;
                    break;

                case IIndexerFeature AsIndexer:
                    Documentation        = AsIndexer.Documentation;
                    ExportIdentifier     = AsIndexer.ExportIdentifier;
                    Export               = AsIndexer.Export;
                    EntityType           = AsIndexer.EntityType;
                    IndexParameterBlocks = AsIndexer.IndexParameterBlocks;
                    ParameterEnd         = AsIndexer.ParameterEnd;
                    ModifiedQueryBlocks  = AsIndexer.ModifiedQueryBlocks;
                    GetterBody           = AsIndexer.GetterBody;
                    SetterBody           = AsIndexer.SetterBody;
                    break;
                }

                Debug.Assert(CommandOverloadBlocks == null || CommandOverloadBlocks.NodeBlockList.Count > 0);
                Debug.Assert(QueryOverloadBlocks == null || QueryOverloadBlocks.NodeBlockList.Count > 0);
                Debug.Assert(IndexParameterBlocks == null || IndexParameterBlocks.NodeBlockList.Count > 0);
            }

            // If the list is full, no need to add more nodes to the cycle.
            if (FeatureTypeList.Count > 0)
            {
                Type NodeType = FeatureTypeList[0];

                INode NewFeature = NodeHelper.CreateInitializedFeature(NodeType, Documentation, ExportIdentifier, Export, EntityName, EntityType, EnsureBlocks, ConstantValue, CommandOverloadBlocks, Once, QueryOverloadBlocks, PropertyKind, ModifiedQueryBlocks, GetterBody, SetterBody, IndexParameterBlocks, ParameterEnd);

                IFocusInsertionChildNodeIndex InsertionIndex = (IFocusInsertionChildNodeIndex)((IFocusBrowsingInsertableIndex)NodeIndex).ToInsertionIndex(ParentNode, NewFeature);
                CycleIndexList.Add(InsertionIndex);
            }
        }
示例#10
0
 private static bool IsDefaultValueMatching(IOptionalReference <IExpression> value1, IOptionalReference <IExpression> value2)
 {
     return((!value1.IsAssigned && !value2.IsAssigned) || (value1.IsAssigned && value2.IsAssigned && Expression.IsExpressionEqual(value1.Item, value2.Item)));
 }
        /// <summary>
        /// Finds the matching nodes of a <see cref="IPrecursorExpression"/>.
        /// </summary>
        /// <param name="node">The agent expression to check.</param>
        /// <param name="errorList">The list of errors found.</param>
        /// <param name="resolvedExpression">The result of the search.</param>
        public static bool ResolveCompilerReferences(IPrecursorExpression node, IErrorList errorList, out ResolvedExpression resolvedExpression)
        {
            resolvedExpression = new ResolvedExpression();

            IOptionalReference <BaseNode.IObjectType> AncestorType = node.AncestorType;
            IList <IArgument> ArgumentList   = node.ArgumentList;
            IClass            EmbeddingClass = node.EmbeddingClass;
            ISealableDictionary <string, IImportedClass>         ClassTable   = EmbeddingClass.ImportedClassTable;
            ISealableDictionary <IFeatureName, IFeatureInstance> FeatureTable = EmbeddingClass.FeatureTable;
            IFeature InnerFeature = node.EmbeddingFeature;

            if (InnerFeature is IndexerFeature)
            {
                errorList.AddError(new ErrorPrecursorNotAllowedInIndexer(node));
                return(false);
            }

            IFeature         AsNamedFeature = InnerFeature;
            IFeatureInstance Instance       = FeatureTable[AsNamedFeature.ValidFeatureName.Item];

            if (!Instance.FindPrecursor(node.AncestorType, errorList, node, out IFeatureInstance SelectedPrecursor))
            {
                return(false);
            }

            resolvedExpression.SelectedPrecursor = SelectedPrecursor;

            List <IExpressionType> MergedArgumentList = new List <IExpressionType>();

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

            if (!ResolveCall(node, SelectedPrecursor, MergedArgumentList, TypeArgumentStyle, errorList, ref resolvedExpression, out ISealableList <IParameter> SelectedParameterList, out ISealableList <IParameter> SelectedResultList, out List <IExpressionType> ResolvedArgumentList))
            {
                return(false);
            }

            resolvedExpression.FeatureCall = new FeatureCall(SelectedParameterList, SelectedResultList, ArgumentList, ResolvedArgumentList, TypeArgumentStyle);

            bool IsHandled = false;

            switch (SelectedPrecursor.Feature)
            {
            case IConstantFeature AsConstantFeature:
                IExpression ConstantValue = (IExpression)AsConstantFeature.ConstantValue;
                resolvedExpression.ConstantSourceList.Add(ConstantValue);
                IsHandled = true;
                break;

            case IFunctionFeature AsFunctionFeature:
                Argument.AddConstantArguments(node, resolvedExpression.ResolvedResult, ArgumentList, resolvedExpression.ConstantSourceList, out ILanguageConstant ExpressionConstant);
                resolvedExpression.ExpressionConstant = ExpressionConstant;
                IsHandled = true;
                break;

            case IPropertyFeature AsPropertyFeature:
                resolvedExpression.ExpressionConstant = Expression.GetDefaultConstant(node, resolvedExpression.ResolvedResult);
                IsHandled = true;
                break;
            }

            Debug.Assert(IsHandled);

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

            return(true);
        }