コード例 #1
0
        private async Task add(T value, IAccessContext <CSScope> context)
        {
            await TaskCollector.With(async tc =>
            {
                CSScope pessimisticScope =
                    new CSScope(RWScope.ReadWrite,
                                InfiniteIntervalScope.Create(
                                    RWScope.ReadWrite, 0, null),
                                $"pessimistic scope for add-{value}");

                await context.InChildWithin(pessimisticScope,
                                            async childContext =>
                {
                    Tuple <node, int> lastNodeInfo =
                        await getLastNode(childContext);

                    /* At this point, we don’t require write access
                     * to the nodes from 0 to count - 1 anymore,
                     * but IInfiniteIntervalScope is not granular enough
                     * to represent that.
                     * Read tasks for lower indexes could proceed. */

                    node newNode = new node
                    {
                        Successor = null,
                        Value     = value
                    };

                    tc.Add(appendToLastNode(
                               newNode, lastNodeInfo, childContext));
                });
            });
        }
コード例 #2
0
        // e.g. literalExpressionOwner = "InvokeRepeating"
        // targetType = "MyMonoBehaviour"
        public UnityEventFunctionReference(ITypeElement targetType, ILiteralExpression literal, MethodSignature methodSignature)
            : base(literal)
        {
            myTargetType    = targetType;
            MethodSignature = methodSignature;

            // All Unity event functions are instance methods, but handle the method signature
            if (methodSignature.IsStatic == null)
            {
                myAccessContext = new DefaultAccessContext(myOwner);
            }
            else if (methodSignature.IsStatic == true)
            {
                myAccessContext = new StaticAccessContext(myOwner);
            }
            else
            {
                myAccessContext = new NonStaticAccessContext(myOwner);
            }

            myMethodFilter             = new InvokableMethodFilter();
            myStaticFilter             = new StaticFilter(myAccessContext);
            myMethodSignatureFilter    = new MethodSignatureFilter(UnityResolveErrorType.UNITY_STRING_LITERAL_REFERENCE_INCORRECT_SIGNATURE_WARNING, MethodSignature);
            myUserCodeCompletionFilter = new UserCodeCompletionFilter();
        }
コード例 #3
0
 private async Task <Tuple <node, int> > getLastNode(
     IAccessContext <CSScope> context,
     node startNode = null, int startIndex = -1)
 {
     if (startNode == null)
     {
         startIndex = -1;
     }
     return(await context.InChild(new CSScope(
                                      valueScope : InfiniteIntervalScope.Create(
                                          RWScope.Read, startIndex + 1, null),
                                      name : "scope for getLastNode"),
                                  async subContext =>
     {
         if (startNode == null)
         {
             node firstNode = await getFirstNode(subContext);
             if (firstNode == null)
             {
                 return null;
             }
             startNode = firstNode;
             startIndex = 0;
         }
         var t = getLastNode(startNode, startIndex, subContext);
         subContext.Dispose();
         return await t;
     }));
 }
コード例 #4
0
        public async Task DoC(string name)
        {
            Console.WriteLine($"{name} created");

            // calculate accessScope
            long accessScope = 3;

            using (IAccessContext <long> q
                       = Context.CreateChild(accessScope))
            {
                char contextName = NewContextName();

                await q.UntilAvailable();

                await Task.Run(() =>
                {
                    for (int i = 0; i < 5; i++)
                    {
                        work(q, name, contextName, "DoC");
                    }

                    q.RequiredScope = 1;

                    // perform something here
                    for (int i = 0; i < 6; i++)
                    {
                        work(q, name, contextName, "DoC");
                    }
                });
            }
        }
コード例 #5
0
        private async Task <Tuple <node, int> > getLastNode(
            node startNode, int startIndex, IAccessContext <CSScope> context)
        {
            return(await context.InChild(
                       new CSScope(valueScope : InfiniteIntervalScope.Create(
                                       RWScope.Read, startIndex + 1, null)),
                       async subContext =>
            {
                node currentNode = startNode;
                for (int index = startIndex + 1; ; index++)
                {
                    /* read the node at position index */

                    await subContext.UntilAvailable(new CSScope(valueScope:
                                                                InfiniteIntervalScope.Create(
                                                                    RWScope.Read, index, index + 1)));

                    if (currentNode.Successor == null)
                    {
                        return Tuple.Create(currentNode, index - 1);
                    }
                    currentNode = currentNode.Successor;
                    subContext.RequiredScope = new CSScope(valueScope:
                                                           InfiniteIntervalScope.Create(
                                                               RWScope.Read, index + 1, null));
                }
            }));
        }
コード例 #6
0
        private async Task <node> getNodeAt(
            long index, IAccessContext <CSScope> context)
        {
            return(await context.InChild(
                       new CSScope(valueScope : InfiniteIntervalScope.Create(
                                       RWScope.Read, 0, index + 1),
                                   name : $"scope for getNodeAt {index}"),
                       async subContext =>
            {
                await subContext.UntilAvailable(new CSScope(valueScope :
                                                            InfiniteIntervalScope.Create(RWScope.Read, 0, 1),
                                                            name : $"UntilAvailable scope in getNodeAt {index}"));

                node currentNode = state.FirstNode;

                for (long i = 1; i <= index; i++)
                {
                    await subContext.UntilAvailable(new CSScope(
                                                        valueScope: InfiniteIntervalScope.Create(
                                                            RWScope.Read, i, i + 1),
                                                        name: "UntilAvailable scope in " +
                                                        $"getNodeAt {index}"));

                    currentNode = currentNode.Successor;
                }

                return currentNode;
            }));
        }
コード例 #7
0
        protected override ITypeElement GetTypeElement(out bool?isStaticReference)
        {
            isStaticReference = false;
            var referenceNode = _error.Reference.GetTreeNode() as IReferenceExpression;

            if (referenceNode != null && referenceNode.QualifierExpression != null)
            {
                var targetReference = referenceNode.QualifierExpression as IReferenceExpression;

                if (targetReference != null)
                {
                    var completableReference = targetReference.Reference;
                    _accessContext = completableReference.GetAccessContext();

                    var declaredElement = completableReference.Resolve().DeclaredElement;
                    var typeElement     = declaredElement as ITypeElement;

                    if (typeElement == null)
                    {
                        typeElement = declaredElement.Type().GetTypeElement <ITypeElement>();
                    }
                    else
                    {
                        isStaticReference = true;
                    }

                    return(typeElement);
                }
            }

            return(null);
        }
コード例 #8
0
 private void work(
     IAccessContext <long> context, string name, char contextName,
     string methodname)
 {
     Thread.Sleep(250);
     connection(ScopeToString(context.RequiredScope, contextName)
                + " " + name + " " + methodname);
 }
コード例 #9
0
            private async Task <long> readNextIndex(
                IAccessContext <enumeratorScope> subContext)
            {
                await subContext.UntilAvailable(
                    new enumeratorScope(nextIndex : RWScope.Read));

                return(nextIndex);
            }
コード例 #10
0
            private async Task <node> readCurrentNode(
                IAccessContext <enumeratorScope> subContext)
            {
                await subContext.UntilAvailable(
                    new enumeratorScope(RWScope.Read));

                return(currentNode);
            }
コード例 #11
0
            private async Task setCurrentNode(
                node value, IAccessContext <enumeratorScope> subContext)
            {
                await subContext.UntilAvailable(
                    new enumeratorScope(RWScope.ReadWrite));

                currentNode = value;
            }
コード例 #12
0
        /// <remarks>
        /// No child context of <paramref name="context"/>
        /// may be created und employed before
        /// the invocation of this method because
        /// this method itself does not create an own child context.
        /// </remarks>
        private async Task <node> getFirstNode(IAccessContext <CSScope> context)
        {
            await context.UntilAvailable(new CSScope(
                                             valueScope : InfiniteIntervalScope.Create(
                                                 RWScope.Read, 0, 1)));

            return(state.FirstNode);
        }
コード例 #13
0
            public IReactive <bool> MoveNextAsync()
            {
                return(Reactive.From <bool>(async resultResolver =>
                {
                    await TaskCollector.With(async tc =>
                    {
                        using (ContextualStream <T> childStream =
                                   stream.CreateChildWithin(new CSScope(valueScope:
                                                                        InfiniteIntervalScope.Create(
                                                                            RWScope.Read, 0, null))))
                            using (IAccessContext <enumeratorScope> childEnumContext
                                       = context.CreateChild(new enumeratorScope(
                                                                 RWScope.ReadWrite, RWScope.ReadWrite)))
                            {
                                long curNextIndex =
                                    await readNextIndex(childEnumContext);
                                CSScope readNextNodeScope = new CSScope(valueScope:
                                                                        InfiniteIntervalScope.Create(RWScope.Read,
                                                                                                     curNextIndex, curNextIndex + 1));
                                childStream.Context.RequiredScope =
                                    readNextNodeScope;

                                node nextNode;

                                if (curNextIndex == 0)
                                {
                                    /* Erste Iteration. */
                                    tc.Add(incrementNextIndex(childEnumContext));
                                    nextNode = await childStream.getFirstNode(
                                        childStream.Context);
                                }
                                else
                                {
                                    node curCurrentNode =
                                        await readCurrentNode(childEnumContext);

                                    if (curCurrentNode == null)
                                    {
                                        throw new InvalidOperationException(
                                            "The stream has already " +
                                            "been iterated through.");
                                    }
                                    tc.Add(incrementNextIndex(childEnumContext));
                                    await childStream.Context.UntilAvailable();
                                    nextNode = curCurrentNode.Successor;
                                }
                                resultResolver.Resolve(nextNode != null);
                                childStream.Dispose();
                                tc.Add(setCurrentNode(nextNode, childEnumContext));
                            }
                    });
                }));
            }
コード例 #14
0
 private async Task incrementNextIndex(
     IAccessContext <enumeratorScope> subContext)
 {
     /* These two statemets (InChild and UntilAvailable)
      * could possibly be combined to a single
      * (extension) method for AccessContext. */
     await subContext.InChild(new enumeratorScope(
                                  nextIndex : RWScope.ReadWrite), async c =>
     {
         await subContext.UntilAvailable();
         nextIndex++;
     });
 }
コード例 #15
0
        private async Task appendToLastNode(
            node newNode, Tuple <node, int> lastNodeInfo,
            IAccessContext <CSScope> context)
        {
            await context.InChildWithin(async childContext =>
            {
                if (lastNodeInfo == null)
                {
                    /* Setting first node */

                    /* Requires an IInfiniteIntervalScope from 0 to infinity,
                     * because setting the first node determines
                     * could also change all other nodes. */

                    var scope = new CSScope(
                        RWScope.ReadWrite,
                        InfiniteIntervalScope.Create(
                            RWScope.ReadWrite, 0, 1),
                        $"scope for appendToLastNode {newNode.Value}");

                    /* TRAP: Using context instead of childContext here
                     * may easily lead to a deadlock. */
                    childContext.RequiredScope = scope;

                    /* Wait for all required scope before writing. */
                    await childContext.UntilAvailable();

                    state.FirstNode = newNode;
                }
                else
                {
                    /* Set the new node */

                    int newIndex = lastNodeInfo.Item2 + 1;

                    var scope = new CSScope(
                        RWScope.ReadWrite,
                        InfiniteIntervalScope.Create(
                            RWScope.ReadWrite, newIndex, newIndex + 1));
                    childContext.RequiredScope = scope;
                    await childContext.UntilAvailable();

                    lastNodeInfo.Item1.Successor = newNode;
                }
                state.Count++;
            });
        }
コード例 #16
0
            public IReactive <T> GetCurrentAsync()
            {
                return(Reactive.From <T>(async resultResolver =>
                {
                    using (ContextualStream <T> childStream =
                               stream.CreateChildWithin(new CSScope(valueScope:
                                                                    InfiniteIntervalScope.Create(
                                                                        RWScope.Read, 0, null))))
                        using (IAccessContext <enumeratorScope> childEnumContext =
                                   context.CreateChildWithin(new enumeratorScope(
                                                                 RWScope.Read,
                                                                 RWScope.Read)))
                        {
                            long curNextIndex =
                                await readNextIndex(childEnumContext);
                            childEnumContext.RequiredScope =
                                new enumeratorScope(RWScope.Read);
                            CSScope readValueScope = new CSScope(valueScope:
                                                                 InfiniteIntervalScope.Create(
                                                                     RWScope.Read, curNextIndex - 1, curNextIndex));
                            childStream.Context.RequiredScope = readValueScope;

                            node curNode =
                                await readCurrentNode(childEnumContext);
                            childEnumContext.Dispose();

                            if (curNode == null)
                            {
                                throw new InvalidOperationException(
                                    "The enumerator is already disposed.");
                            }

                            await childStream.Context.UntilAvailable(
                                readValueScope);
                            resultResolver.Resolve(curNode.Value);
                        }
                }));
            }
コード例 #17
0
 private asyncBox(
     asyncBox <T> parent, IAccessContext <RWScope> context)
     : base(context, childFactory)
 {
     state = parent.state;
 }
コード例 #18
0
ファイル: ReferenceName.cs プロジェクト: willrawls/arp
        public ResolveResult Resolve(ISymbolTable table, IAccessContext context, out IResolveInfo resolveInfo)
        {
            // TODO check this code
            if (table == EmptySymbolTable.INSTANCE)
            {
                resolveInfo = ResolveErrorType.NOT_RESOLVED;
                return ResolveResult.EMPTY;
            }

            #region Filtered table FIX: if filter set is empty it work incorrect

            int mustRun = 0;
            ISymbolFilter[] filters = GetSymbolFilters(out mustRun);

            if (mustRun == 0 && (filters == null || filters.Length == 0))
                return GetResolveResult(table, out resolveInfo);

            #endregion

            return CheckedReferenceImplUtil.Resolve(this, table, out resolveInfo);
        }
コード例 #19
0
 public MyComponent Create(MyComponent parentContextual,
                           IAccessContext <long> childContext)
 {
     return(new MyComponent(
                parentContextual.connection, childContext));
 }
コード例 #20
0
 private MyComponent(
     Action <string> connection, IAccessContext <long> context)
     : base(context, factory.Default)
 {
     this.connection = connection;
 }
コード例 #21
0
 public override ResolveResultWithInfo Resolve(ISymbolTable symbolTable, IAccessContext context)
 {
     return(WebPathReferenceUtil.CheckResolveResult(this, base.Resolve(symbolTable, context)));
 }
コード例 #22
0
        /* Private methods may get the surrounding context to spare
         * the creation of a new Contextual instance. */

        /// <remarks>
        /// No child context of <paramref name="context"/>
        /// may be created und employed before
        /// the invocation of this method because
        /// this method itself does not create an own child context.
        /// </remarks>
        private async Task <long> getCount(IAccessContext <CSScope> context)
        {
            await context.UntilAvailable(new CSScope(RWScope.Read));

            return(state.Count);
        }
コード例 #23
0
ファイル: ReferenceName.cs プロジェクト: willrawls/arp
 public ResolveResult Resolve(ISymbolTable table, IAccessContext context, out ResolveInfo resolveInfo)
 {
     // TODO check this code
     if (table == EmptySymbolTable.INSTANCE)
     {
         resolveInfo = ResolveErrorType.NOT_RESOLVED;
         return ResolveResult.EMPTY;
     }
     return CheckedReferenceImplUtil.Resolve(this, table, out resolveInfo);
 }
コード例 #24
0
 private ContextualStream(ContextualStream <T> parentContextual,
                          IAccessContext <CSScope> context)
     : base(context, factory)
 {
     state = parentContextual.state;
 }